Merge "Notification settings updates"
diff --git a/res/layout/search_icon_view.xml b/res/layout/search_icon_view.xml
index ef99bee..aa0bf02 100644
--- a/res/layout/search_icon_view.xml
+++ b/res/layout/search_icon_view.xml
@@ -18,7 +18,7 @@
 <ImageView
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@android:id/icon"
-    android:layout_width="@dimen/dashboard_tile_image_size"
+    android:layout_width="@dimen/dashboard_tile_foreground_image_size"
     android:layout_height="match_parent"
     android:scaleType="centerInside"
     android:layout_marginStart="@dimen/dashboard_tile_image_margin"
diff --git a/res/layout/search_saved_query_item.xml b/res/layout/search_saved_query_item.xml
deleted file mode 100644
index f8c239a..0000000
--- a/res/layout/search_saved_query_item.xml
+++ /dev/null
@@ -1,44 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-  Copyright (C) 2017 The Android Open Source Project
-
-  Licensed under the Apache License, Version 2.0 (the "License");
-  you may not use this file except in compliance with the License.
-  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
-  -->
-
-<LinearLayout
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:orientation="horizontal"
-    android:layout_width="match_parent"
-    android:layout_height="wrap_content"
-    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
-    android:background="?android:attr/selectableItemBackground"
-    android:minHeight="?android:attr/listPreferredItemHeight"
-    android:gravity="center_vertical">
-
-    <ImageView
-        android:id="@android:id/icon"
-        android:layout_width="@dimen/dashboard_tile_image_size"
-        android:layout_height="@dimen/dashboard_tile_image_size"
-        android:scaleType="centerInside"
-        android:layout_marginStart="@dimen/dashboard_tile_image_margin"
-        android:layout_marginEnd="@dimen/dashboard_tile_image_margin"
-        android:src="@drawable/ic_restore" />
-
-    <TextView
-        android:id="@android:id/title"
-        android:layout_height="match_parent"
-        android:layout_width="match_parent"
-        android:gravity="center_vertical"
-        android:textAppearance="?android:attr/textAppearanceListItem" />
-
-</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/suggestion_tile_with_button_v2.xml b/res/layout/suggestion_tile_with_button_v2.xml
index bedc6da..7042341 100644
--- a/res/layout/suggestion_tile_with_button_v2.xml
+++ b/res/layout/suggestion_tile_with_button_v2.xml
@@ -80,6 +80,7 @@
         <Button
             android:id="@android:id/primary"
             style="@style/ActionPrimaryButton"
+            android:layout_gravity="center"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_marginTop="12dp"
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index f9ab821..d6f3cb5 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -110,7 +110,7 @@
     <dimen name="dashboard_tile_foreground_image_inset">6dp</dimen>
 
     <!-- Dashboard tile image margin start / end -->
-    <dimen name="dashboard_tile_image_margin">24dp</dimen>
+    <dimen name="dashboard_tile_image_margin">18dp</dimen>
 
     <!-- SwitchBar sub settings margin start / end -->
     <dimen name="switchbar_subsettings_margin_start">72dp</dimen>
diff --git a/src/com/android/settings/dashboard/DashboardSummary.java b/src/com/android/settings/dashboard/DashboardSummary.java
index fc82d41..f86867b 100644
--- a/src/com/android/settings/dashboard/DashboardSummary.java
+++ b/src/com/android/settings/dashboard/DashboardSummary.java
@@ -39,6 +39,7 @@
 import com.android.settings.dashboard.conditional.FocusRecyclerView;
 import com.android.settings.dashboard.conditional.FocusRecyclerView.FocusListener;
 import com.android.settings.dashboard.suggestions.SuggestionDismissController;
+import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
 import com.android.settings.overlay.FeatureFactory;
 import com.android.settings.widget.ActionBarShadowController;
 import com.android.settingslib.drawer.CategoryKey;
@@ -86,10 +87,14 @@
     public void onAttach(Context context) {
         super.onAttach(context);
         Log.d(TAG, "Creating SuggestionControllerMixin");
-        mSuggestionControllerMixin = new SuggestionControllerMixin(context, this /* host */,
-                getLifecycle(), FeatureFactory.getFactory(context)
-                                    .getSuggestionFeatureProvider(context)
-                                    .getSuggestionServiceComponent());
+        final SuggestionFeatureProvider suggestionFeatureProvider = FeatureFactory
+                .getFactory(context)
+                .getSuggestionFeatureProvider(context);
+        if (suggestionFeatureProvider.isSuggestionEnabled(context)) {
+            mSuggestionControllerMixin = new SuggestionControllerMixin(context, this /* host */,
+                    getLifecycle(), suggestionFeatureProvider
+                    .getSuggestionServiceComponent());
+        }
     }
 
     @Override
@@ -202,12 +207,12 @@
         mDashboard.setItemAnimator(new DashboardItemAnimator());
         if (mDashboardFeatureProvider.useSuggestionUiV2()) {
             mAdapterV2 = new DashboardAdapterV2(getContext(), bundle,
-                mConditionManager.getConditions(), mSuggestionControllerMixin, getLifecycle());
+                    mConditionManager.getConditions(), mSuggestionControllerMixin, getLifecycle());
             mDashboard.setAdapter(mAdapterV2);
             mSummaryLoader.setSummaryConsumer(mAdapterV2);
         } else {
             mAdapter = new DashboardAdapter(getContext(), bundle, mConditionManager.getConditions(),
-                mSuggestionControllerMixin, this /* SuggestionDismissController.Callback */);
+                    mSuggestionControllerMixin, this /* SuggestionDismissController.Callback */);
             mDashboard.setAdapter(mAdapter);
             mSummaryLoader.setSummaryConsumer(mAdapter);
         }
@@ -302,6 +307,9 @@
                 CategoryKey.CATEGORY_HOMEPAGE);
         mSummaryLoader.updateSummaryToCache(category);
         mStagingCategory = category;
+        if (mSuggestionControllerMixin == null) {
+            return;
+        }
         if (mSuggestionControllerMixin.isSuggestionLoaded()) {
             Log.d(TAG, "Suggestion has loaded, setting suggestion/category");
             ThreadUtils.postOnMainThread(() -> {
@@ -321,7 +329,7 @@
             Log.d(TAG, "Suggestion NOT loaded, delaying setCategory by " + MAX_WAIT_MILLIS + "ms");
             if (mDashboardFeatureProvider.useSuggestionUiV2()) {
                 mHandler.postDelayed(()
-                    -> mAdapterV2.setCategory(mStagingCategory), MAX_WAIT_MILLIS);
+                        -> mAdapterV2.setCategory(mStagingCategory), MAX_WAIT_MILLIS);
             } else {
                 mHandler.postDelayed(() -> mAdapter.setCategory(mStagingCategory), MAX_WAIT_MILLIS);
             }
diff --git a/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProvider.java b/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProvider.java
index b700049..f913085 100644
--- a/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProvider.java
+++ b/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProvider.java
@@ -34,7 +34,7 @@
     /**
      * Whether or not the whole suggestion feature is enabled.
      */
-    boolean isSuggestionV2Enabled(Context context);
+    boolean isSuggestionEnabled(Context context);
 
     /**
      * Returns the component name for SuggestionService.
diff --git a/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImpl.java b/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImpl.java
index 4e5f688..8523273 100644
--- a/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImpl.java
+++ b/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImpl.java
@@ -54,7 +54,7 @@
     private final MetricsFeatureProvider mMetricsFeatureProvider;
 
     @Override
-    public boolean isSuggestionV2Enabled(Context context) {
+    public boolean isSuggestionEnabled(Context context) {
         final ActivityManager am =
                 (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
         return !am.isLowRamDevice();
diff --git a/src/com/android/settings/system/SystemDashboardFragment.java b/src/com/android/settings/system/SystemDashboardFragment.java
index 323a2d4..88cafb0 100644
--- a/src/com/android/settings/system/SystemDashboardFragment.java
+++ b/src/com/android/settings/system/SystemDashboardFragment.java
@@ -17,7 +17,6 @@
 
 import android.content.Context;
 import android.os.Bundle;
-import android.os.UserManager;
 import android.provider.SearchIndexableResource;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceGroup;
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardSummaryTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardSummaryTest.java
index 59823ec..2a7b829 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardSummaryTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardSummaryTest.java
@@ -16,6 +16,7 @@
 
 package com.android.settings.dashboard;
 
+import static com.google.common.truth.Truth.assertThat;
 import static org.mockito.ArgumentMatchers.nullable;
 import static org.mockito.Mockito.any;
 import static org.mockito.Mockito.doNothing;
@@ -34,9 +35,11 @@
 import com.android.settings.TestConfig;
 import com.android.settings.dashboard.conditional.ConditionManager;
 import com.android.settings.dashboard.conditional.FocusRecyclerView;
+import com.android.settings.testutils.FakeFeatureFactory;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settingslib.drawer.CategoryKey;
 import com.android.settingslib.drawer.DashboardCategory;
+import com.android.settingslib.suggestions.SuggestionControllerMixin;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -67,10 +70,12 @@
 
     private Context mContext;
     private DashboardSummary mSummary;
+    private FakeFeatureFactory mFeatureFactory;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
+        mFeatureFactory = FakeFeatureFactory.setupForTest();
         mContext = RuntimeEnvironment.application;
         mSummary = spy(new DashboardSummary());
         ReflectionHelpers.setField(mSummary, "mAdapter", mAdapter);
@@ -83,6 +88,28 @@
     }
 
     @Test
+    public void onAttach_suggestionDisabled_shouldNotStartSuggestionControllerMixin() {
+        when(mFeatureFactory.suggestionsFeatureProvider.isSuggestionEnabled(any(Context.class)))
+                .thenReturn(false);
+
+        mSummary.onAttach(mContext);
+        final SuggestionControllerMixin mixin = ReflectionHelpers
+                .getField(mSummary, "mSuggestionControllerMixin");
+        assertThat(mixin).isNull();
+    }
+
+    @Test
+    public void onAttach_suggestionEnabled_shouldStartSuggestionControllerMixin() {
+        when(mFeatureFactory.suggestionsFeatureProvider.isSuggestionEnabled(any(Context.class)))
+                .thenReturn(true);
+
+        mSummary.onAttach(mContext);
+        final SuggestionControllerMixin mixin = ReflectionHelpers
+                .getField(mSummary, "mSuggestionControllerMixin");
+        assertThat(mixin).isNotNull();
+    }
+
+    @Test
     public void updateCategory_shouldGetCategoryFromFeatureProvider() {
         doReturn(mock(Activity.class)).when(mSummary).getActivity();
         mSummary.onAttach(mContext);
diff --git a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java
index 54af308..e9c8805 100644
--- a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java
@@ -114,13 +114,13 @@
     public void isSuggestionEnabled_isLowMemoryDevice_shouldReturnFalse() {
         when(mActivityManager.isLowRamDevice()).thenReturn(true);
 
-        assertThat(mProvider.isSuggestionV2Enabled(mContext)).isFalse();
+        assertThat(mProvider.isSuggestionEnabled(mContext)).isFalse();
     }
 
     @Test
     public void isSuggestionV2Enabled_isNotLowMemoryDevice_shouldReturnTrue() {
         when(mActivityManager.isLowRamDevice()).thenReturn(false);
-        assertThat(mProvider.isSuggestionV2Enabled(mContext)).isTrue();
+        assertThat(mProvider.isSuggestionEnabled(mContext)).isTrue();
     }
 
     @Test
diff --git a/tests/uitests/src/com/android/settings/ui/BatterySettingsUITest.java b/tests/uitests/src/com/android/settings/ui/BatterySettingsUITest.java
new file mode 100644
index 0000000..8b34fff
--- /dev/null
+++ b/tests/uitests/src/com/android/settings/ui/BatterySettingsUITest.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.ui;
+
+import android.content.Intent;
+import android.os.RemoteException;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.MediumTest;
+import android.support.test.runner.AndroidJUnit4;
+import android.support.test.uiautomator.UiDevice;
+import android.system.helpers.SettingsHelper;
+
+import com.android.settings.ui.testutils.SettingsTestUtils;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@MediumTest
+@RunWith(AndroidJUnit4.class)
+public class BatterySettingsUITest {
+    // Items we really want to always show
+    private static final String[] CATEGORIES = new String[] {
+            "Battery Saver",
+            "Battery percentage",
+            "Battery usage data is approximate and can change based on usage",
+    };
+
+    private UiDevice mDevice;
+    private SettingsHelper mHelper;
+
+    @Before
+    public void setUp() throws Exception {
+        mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
+        mHelper = SettingsHelper.getInstance();
+        try {
+            mDevice.setOrientationNatural();
+        } catch (RemoteException e) {
+            throw new RuntimeException("failed to freeze device orientaion", e);
+        }
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        // Go back to home for next test.
+        mDevice.pressHome();
+    }
+
+    @Test
+    public void launchSecuritySettings() throws Exception {
+        // Launch Settings
+        SettingsHelper.launchSettingsPage(
+                InstrumentationRegistry.getTargetContext(), Intent.ACTION_POWER_USAGE_SUMMARY);
+        mHelper.scrollVert(false);
+        for (String category : CATEGORIES) {
+            SettingsTestUtils.assertTitleMatch(mDevice, category);
+        }
+    }
+}
diff --git a/tests/uitests/src/com/android/settings/ui/WirelessNetworkSettingsAdditionalTests.java b/tests/uitests/src/com/android/settings/ui/MoreWirelessSettingsTest2.java
similarity index 99%
rename from tests/uitests/src/com/android/settings/ui/WirelessNetworkSettingsAdditionalTests.java
rename to tests/uitests/src/com/android/settings/ui/MoreWirelessSettingsTest2.java
index 4ed2a1d..971c7d7 100644
--- a/tests/uitests/src/com/android/settings/ui/WirelessNetworkSettingsAdditionalTests.java
+++ b/tests/uitests/src/com/android/settings/ui/MoreWirelessSettingsTest2.java
@@ -38,7 +38,7 @@
 /**
  * Additional tests for Wifi Settings.
  */
-public class WirelessNetworkSettingsAdditionalTests extends InstrumentationTestCase {
+public class MoreWirelessSettingsTest2 extends InstrumentationTestCase {
     // These back button presses are performed in tearDown() to exit Wifi
     // Settings sub-menus that a test might finish in. This number should be
     // high enough to account for the deepest sub-menu a test might enter.
diff --git a/tests/uitests/src/com/android/settings/ui/StorageSettingsUITest.java b/tests/uitests/src/com/android/settings/ui/StorageSettingsUITest.java
new file mode 100644
index 0000000..a301cc3
--- /dev/null
+++ b/tests/uitests/src/com/android/settings/ui/StorageSettingsUITest.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.ui;
+
+import android.os.RemoteException;
+import android.provider.Settings;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.runner.AndroidJUnit4;
+import android.support.test.uiautomator.UiDevice;
+import android.system.helpers.SettingsHelper;
+import android.test.suitebuilder.annotation.MediumTest;
+
+import com.android.settings.ui.testutils.SettingsTestUtils;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+@MediumTest
+public class StorageSettingsUITest {
+
+    private static final String[] TITLES = {
+            "Photos & videos",
+            "Music & audio",
+            "Games",
+            "Movie & TV apps",
+            "Other apps",
+            "Files",
+            "System",
+    };
+    private UiDevice mDevice;
+    private SettingsHelper mHelper;
+
+
+    @Before
+    public void setUp() throws Exception {
+        mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
+        mHelper = SettingsHelper.getInstance();
+
+        try {
+            mDevice.setOrientationNatural();
+        } catch (RemoteException e) {
+            throw new RuntimeException("failed to freeze device orientation", e);
+        }
+    }
+
+    @After
+    public void tearDown() {
+        mDevice.pressHome();
+    }
+
+    @Test
+    public void launchStorageSettings() throws Exception {
+        // Launch Settings
+        SettingsHelper.launchSettingsPage(
+                InstrumentationRegistry.getTargetContext(),
+                Settings.ACTION_INTERNAL_STORAGE_SETTINGS);
+        mHelper.scrollVert(false);
+        for (String category : TITLES) {
+            SettingsTestUtils.assertTitleMatch(mDevice, category);
+        }
+    }
+}
diff --git a/tests/uitests/src/com/android/settings/ui/WirelessNetworkSettingsTests.java b/tests/uitests/src/com/android/settings/ui/WirelessNetworkSettingsTests.java
index 64fa5fd..dd700ac 100644
--- a/tests/uitests/src/com/android/settings/ui/WirelessNetworkSettingsTests.java
+++ b/tests/uitests/src/com/android/settings/ui/WirelessNetworkSettingsTests.java
@@ -61,7 +61,6 @@
 
     @Before
     public void setUp() throws Exception {
-
         mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
         try {
             mDevice.setOrientationNatural();