Merge "Inline slider with header" into pi-dev
diff --git a/res/drawable/ic_photo_library.xml b/res/drawable/ic_photo_library.xml
index 732a348..a1a58c2 100644
--- a/res/drawable/ic_photo_library.xml
+++ b/res/drawable/ic_photo_library.xml
@@ -21,5 +21,5 @@
         android:tint="?android:attr/colorControlNormal">
     <path
         android:fillColor="#FF000000"
-        android:pathData="M22,16V4c0,-1.11 -0.9,-2 -2,-2H8C6.89,2 6,2.89 6,4v12c0,1.1 0.89,2 2,2h12C21.1,18 22,17.1 22,16zM11,12l2.03,2.71L16,11l4,5H8L11,12zM2,7v13c0,1.1 0.9,2 2,2h13c0.55,0 1,-0.45 1,-1v0c0,-0.55 -0.45,-1 -1,-1H4.5C4.22,20 4,19.78 4,19.5V7c0,-0.55 -0.45,-1 -1,-1h0C2.45,6 2,6.45 2,7z"/>
+        android:pathData="M20,4v12H8V4H20M20,2H8C6.9,2 6,2.9 6,4v12c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2V4C22,2.9 21.1,2 20,2L20,2zM2,6v14c0,1.1 0.9,2 2,2h14v-2H4V6H2zM15.67,11l-2.5,2.98L11.5,11.8L9,15h10L15.67,11z"/>
 </vector>
diff --git a/res/drawable/ic_settings_accessibility.xml b/res/drawable/ic_settings_accessibility.xml
index 67b6c9a..d5c89b9 100644
--- a/res/drawable/ic_settings_accessibility.xml
+++ b/res/drawable/ic_settings_accessibility.xml
@@ -20,5 +20,8 @@
         android:viewportHeight="24.0">
     <path
         android:fillColor="#FFFFFFFF"
-        android:pathData="M20.75,6.99c-0.14,-0.55 -0.69,-0.87 -1.24,-0.75C17.13,6.77 14.48,7 12,7S6.87,6.77 4.49,6.24c-0.55,-0.12 -1.1,0.2 -1.24,0.75l0,0C3.11,7.55 3.45,8.12 4,8.25C5.61,8.61 7.35,8.86 9,9v12c0,0.55 0.45,1 1,1h0c0.55,0 1,-0.45 1,-1v-5h2v5c0,0.55 0.45,1 1,1h0c0.55,0 1,-0.45 1,-1V9c1.65,-0.14 3.39,-0.39 5,-0.75C20.55,8.12 20.89,7.55 20.75,6.99L20.75,6.99zM12,6c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2s-2,0.9 -2,2S10.9,6 12,6z"/>
+        android:pathData="M20.5,4c-2.61,0.7 -5.67,1 -8.5,1S6.11,4.7 3.5,4L3,6c1.86,0.5 4,0.83 6,1v13h2v-6h2v6h2V7c2,-0.17 4.14,-0.5 6,-1L20.5,4zM12,4c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2s-2,0.9 -2,2S10.9,4 12,4z"/>
+    <path
+        android:fillColor="#FFFFFFFF"
+        android:pathData="M7,24h2v-2H7V24zM11,24h2v-2h-2V24zM15,24h2v-2h-2V24z"/>
 </vector>
diff --git a/res/drawable/ic_settings_memory.xml b/res/drawable/ic_settings_memory.xml
index 830dfc9..78a6b8d 100644
--- a/res/drawable/ic_settings_memory.xml
+++ b/res/drawable/ic_settings_memory.xml
@@ -20,19 +20,6 @@
         android:viewportHeight="24.0"
         android:tint="?android:attr/colorControlNormal">
     <path
-        android:pathData="M6.0,4.0l0.0,16.0 12.0,0.0 0.0,-16.0 -12.0,0.0z
-        M6.0,5.25l0,1.5 -3,0 0,-1.5 3,0z
-        M6.0,9.25l0,1.5 -3,0 0,-1.5 3,0z
-        M6.0,13.25l0,1.5 -3,0 0,-1.5 3,0z
-        M6.0,17.25l0,1.5 -3,0 0,-1.5 3,0z
-        M21.0,5.25l0,1.5 -3,0 0,-1.5 3,0z
-        M21.0,9.25l0,1.5 -3,0 0,-1.5 3,0z
-        M21.0,13.25l0,1.5 -3,0 0,-1.5 3,0z
-        M21.0,17.25l0,1.5 -3,0 0,-1.5 3,0z
-
-        M11.5,14.5l1,0 0,3 -1,0 0,-3z
-        M13.25,14.5l1,0 0,3 -1,0 0,-3z
-        M15.0,14.5l1,0 0,3 -1,0 0,-3z
-        "
-        android:fillColor="@android:color/black" />
+        android:fillColor="@android:color/black"
+        android:pathData="M15,9H9v6h6V9zM21,11V9h-2V7c0,-1.1 -0.9,-2 -2,-2h-2V3h-2v2h-2V3H9v2H7C5.9,5 5,5.9 5,7v2H3v2h2v2H3v2h2v2c0,1.1 0.9,2 2,2h2v2h2v-2h2v2h2v-2h2c1.1,0 2,-0.9 2,-2v-2h2v-2h-2v-2H21zM17,17H7V7h10V17z"/>
 </vector>
diff --git a/res/drawable/ic_settings_sim.xml b/res/drawable/ic_settings_sim.xml
index d083c9d..3edda49 100644
--- a/res/drawable/ic_settings_sim.xml
+++ b/res/drawable/ic_settings_sim.xml
@@ -16,13 +16,30 @@
 -->
 
 <vector xmlns:android="http://schemas.android.com/apk/res/android"
-        android:width="24.0dp"
-        android:height="24.0dp"
+        android:width="24dp"
+        android:height="24dp"
         android:viewportWidth="24.0"
         android:viewportHeight="24.0"
         android:tint="?android:attr/colorControlNormal">
     <path
         android:fillColor="#FFFFFFFF"
-        android:pathData="M19.99 4c0-1.1-.89-2-1.99-2h-8L4 8v12c0 1.1.9 2 2 2h12.01c1.1 0 1.99-.9 1.99-2l-.01-16zM9 19H7v-2h2v2zm8 0h-2v-2h2v2zm-8-4H7v-4h2v4zm4 4h-2v-4h2v4zm0-6h-2v-2h2v2zm4 2h-2v-4h2v4z"/>
-      <path android:pathData="M0 0h24v24H0z"/>
+        android:pathData="M18,2h-8L4,8v12c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2V4C20,2.9 19.1,2 18,2zM18,4v16H6V8.83L10.83,4L18,4L18,4z"/>
+    <path
+        android:fillColor="#FFFFFFFF"
+        android:pathData="M7,17h2v2h-2z"/>
+    <path
+        android:fillColor="#FFFFFFFF"
+        android:pathData="M15,17h2v2h-2z"/>
+    <path
+        android:fillColor="#FFFFFFFF"
+        android:pathData="M7,11h2v4h-2z"/>
+    <path
+        android:fillColor="#FFFFFFFF"
+        android:pathData="M11,15h2v4h-2z"/>
+    <path
+        android:fillColor="#FFFFFFFF"
+        android:pathData="M11,11h2v2h-2z"/>
+    <path
+        android:fillColor="#FFFFFFFF"
+        android:pathData="M15,11h2v4h-2z"/>
 </vector>
diff --git a/res/drawable/ic_warning_24dp.xml b/res/drawable/ic_warning_24dp.xml
index 8e9fee3..2ca48e0 100644
--- a/res/drawable/ic_warning_24dp.xml
+++ b/res/drawable/ic_warning_24dp.xml
@@ -1,5 +1,5 @@
 <!--
-Copyright (C) 2015 The Android Open Source Project
+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.
@@ -16,9 +16,15 @@
 <vector xmlns:android="http://schemas.android.com/apk/res/android"
         android:width="24dp"
         android:height="24dp"
-        android:viewportWidth="48.0"
-        android:viewportHeight="48.0">
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
     <path
         android:fillColor="#FF000000"
-        android:pathData="M2 42h44L24 4 2 42zm24,-6h-4v-4h4v4zm0,-8h-4v-8h4v8z"/>
+        android:pathData="M12,5.99L19.53,19H4.47L12,5.99M12,2L1,21h22L12,2L12,2z"/>
+    <path
+        android:fillColor="#FF000000"
+        android:pathData="M13,16l-2,0l0,2l2,0l0,-2z"/>
+    <path
+        android:fillColor="#FF000000"
+        android:pathData="M13,10l-2,0l0,4l2,0l0,-4z"/>
 </vector>
diff --git a/res/layout/wifi_dialog.xml b/res/layout/wifi_dialog.xml
index fe891e1..2330727 100644
--- a/res/layout/wifi_dialog.xml
+++ b/res/layout/wifi_dialog.xml
@@ -604,6 +604,7 @@
             <LinearLayout android:id="@+id/hidden_settings_field"
                           android:layout_width="match_parent"
                           android:layout_height="wrap_content"
+                          android:visibility="gone"
                           style="@style/wifi_item">
 
                 <TextView android:id="@+id/hidden_settings_title"
diff --git a/res/xml/battery_saver_settings.xml b/res/xml/battery_saver_settings.xml
index 116079d..0460459 100644
--- a/res/xml/battery_saver_settings.xml
+++ b/res/xml/battery_saver_settings.xml
@@ -18,32 +18,35 @@
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:settings="http://schemas.android.com/apk/res-auto"
     android:title="@string/battery_saver"
-    android:key="battery_saver">
+    android:key="battery_saver_page">
 
     <!-- Turn on automatically -->
     <SwitchPreference
         android:key="auto_battery_saver"
         android:title="@string/battery_saver_auto_title"
-        settings:controller="com.android.settings.fuelgauge.batterysaver.AutoBatterySaverPreferenceController"/>
+        settings:controller="com.android.settings.fuelgauge.batterysaver.AutoBatterySaverPreferenceController" />
 
     <com.android.settings.widget.SeekBarPreference
         android:key="battery_saver_seek_bar"
         android:title="@string/battery_saver_seekbar_title_placeholder"
         android:max="75"
-        android:min="5"/>
+        android:min="5" />
 
     <com.android.settings.widget.TwoStateButtonPreference
-        android:key="battery_saver_button_container"
+        android:key="battery_saver"
+        android:title="@string/battery_saver"
         android:selectable="false"
         settings:textOn="@string/battery_saver_button_turn_on"
-        settings:textOff="@string/battery_saver_button_turn_off"/>
+        settings:textOff="@string/battery_saver_button_turn_off"
+        settings:platform_slice="true"
+        settings:controller="com.android.settings.fuelgauge.batterysaver.BatterySaverButtonPreferenceController" />
 
     <PreferenceCategory
         android:key="battery_saver_footer">
         <com.android.settingslib.widget.FooterPreference
             android:key="battery_saver_footer_preference"
             android:title="@*android:string/battery_saver_description"
-            android:selectable="false"/>
+            android:selectable="false" />
     </PreferenceCategory>
 
 </PreferenceScreen>
diff --git a/src/com/android/settings/bluetooth/BluetoothSliceBuilder.java b/src/com/android/settings/bluetooth/BluetoothSliceBuilder.java
index e6452de..da759a3 100644
--- a/src/com/android/settings/bluetooth/BluetoothSliceBuilder.java
+++ b/src/com/android/settings/bluetooth/BluetoothSliceBuilder.java
@@ -17,6 +17,8 @@
 
 import static android.app.slice.Slice.EXTRA_TOGGLE_STATE;
 
+import static androidx.slice.builders.ListBuilder.ICON_IMAGE;
+
 import android.annotation.ColorInt;
 import android.app.PendingIntent;
 import android.bluetooth.BluetoothAdapter;
diff --git a/src/com/android/settings/fuelgauge/batterysaver/BatterySaverButtonPreferenceController.java b/src/com/android/settings/fuelgauge/batterysaver/BatterySaverButtonPreferenceController.java
index b23a5f0..9485868 100644
--- a/src/com/android/settings/fuelgauge/batterysaver/BatterySaverButtonPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/batterysaver/BatterySaverButtonPreferenceController.java
@@ -18,12 +18,12 @@
 
 import android.content.Context;
 import android.os.PowerManager;
-import android.support.annotation.VisibleForTesting;
 import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
 
+import com.android.settings.core.TogglePreferenceController;
 import com.android.settings.fuelgauge.BatterySaverReceiver;
-import com.android.settings.widget.TwoStateButtonPreferenceController;
-import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settings.widget.TwoStateButtonPreference;
 import com.android.settingslib.core.lifecycle.LifecycleObserver;
 import com.android.settingslib.core.lifecycle.events.OnStart;
 import com.android.settingslib.core.lifecycle.events.OnStop;
@@ -33,21 +33,29 @@
  * Controller to update the battery saver button
  */
 public class BatterySaverButtonPreferenceController extends
-        TwoStateButtonPreferenceController implements
+        TogglePreferenceController implements
         LifecycleObserver, OnStart, OnStop, BatterySaverReceiver.BatterySaverListener {
-    private static final String KEY = "battery_saver_button_container";
-    private BatterySaverReceiver mBatterySaverReceiver;
-    @VisibleForTesting
-    PowerManager mPowerManager;
 
-    public BatterySaverButtonPreferenceController(Context context, Lifecycle lifecycle) {
-        super(context, KEY);
+    private final BatterySaverReceiver mBatterySaverReceiver;
+    private final PowerManager mPowerManager;
+
+    private TwoStateButtonPreference mPreference;
+
+    public BatterySaverButtonPreferenceController(Context context, String key) {
+        super(context, key);
         mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
         mBatterySaverReceiver = new BatterySaverReceiver(context);
         mBatterySaverReceiver.setBatterySaverListener(this);
-        if (lifecycle != null) {
-            lifecycle.addObserver(this);
-        }
+    }
+
+    @Override
+    public int getAvailabilityStatus() {
+        return AVAILABLE;
+    }
+
+    @Override
+    public boolean isSliceable() {
+        return true;
     }
 
     @Override
@@ -61,29 +69,43 @@
     }
 
     @Override
+    public void displayPreference(PreferenceScreen screen) {
+        super.displayPreference(screen);
+        mPreference = (TwoStateButtonPreference) screen.findPreference(getPreferenceKey());
+    }
+
+    @Override
+    public boolean isChecked() {
+        return mPowerManager.isPowerSaveMode();
+    }
+
+    @Override
+    public boolean setChecked(boolean stateOn) {
+        // This screen already shows a warning, so we don't need another warning.
+        return BatterySaverUtils.setPowerSaveMode(mContext, stateOn,
+                false /* needFirstTimeWarning */);
+    }
+
+    @Override
     public void updateState(Preference preference) {
         super.updateState(preference);
-        setButtonVisibility(!mPowerManager.isPowerSaveMode());
-    }
-
-    @Override
-    public int getAvailabilityStatus() {
-        return AVAILABLE;
-    }
-
-    @Override
-    public void onButtonClicked(boolean stateOn) {
-        // This screen already shows a warning, so we don't need another warning.
-        BatterySaverUtils.setPowerSaveMode(mContext,  stateOn, /*needFirstTimeWarning*/ false);
+        if (mPreference != null) {
+            mPreference.setChecked(isChecked());
+        }
     }
 
     @Override
     public void onPowerSaveModeChanged() {
-        setButtonVisibility(!mPowerManager.isPowerSaveMode());
+        final boolean isChecked = isChecked();
+        if (mPreference != null && mPreference.isChecked() != isChecked) {
+            mPreference.setChecked(isChecked);
+        }
     }
 
     @Override
     public void onBatteryChanged(boolean pluggedIn) {
-        setButtonEnabled(!pluggedIn);
+        if (mPreference != null) {
+            mPreference.setButtonEnabled(!pluggedIn);
+        }
     }
 }
diff --git a/src/com/android/settings/fuelgauge/batterysaver/BatterySaverSettings.java b/src/com/android/settings/fuelgauge/batterysaver/BatterySaverSettings.java
index 8009e95..26f9e17 100644
--- a/src/com/android/settings/fuelgauge/batterysaver/BatterySaverSettings.java
+++ b/src/com/android/settings/fuelgauge/batterysaver/BatterySaverSettings.java
@@ -73,7 +73,6 @@
         final List<AbstractPreferenceController> controllers = new ArrayList<>();
         controllers.add(new AutoBatterySaverPreferenceController(context));
         controllers.add(new AutoBatterySeekBarPreferenceController(context, lifecycle));
-        controllers.add(new BatterySaverButtonPreferenceController(context, lifecycle));
         return controllers;
     }
 
diff --git a/src/com/android/settings/location/LocationSliceBuilder.java b/src/com/android/settings/location/LocationSliceBuilder.java
new file mode 100644
index 0000000..e69ccfb
--- /dev/null
+++ b/src/com/android/settings/location/LocationSliceBuilder.java
@@ -0,0 +1,94 @@
+/*
+ * 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.location;
+
+import static android.provider.SettingsSlicesContract.KEY_LOCATION;
+
+import static androidx.slice.builders.ListBuilder.ICON_IMAGE;
+
+import android.annotation.ColorInt;
+import android.app.PendingIntent;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+import android.provider.SettingsSlicesContract;
+
+import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.settings.R;
+import com.android.settings.SubSettings;
+import com.android.settings.Utils;
+import com.android.settings.search.DatabaseIndexingUtils;
+
+import androidx.slice.Slice;
+import androidx.slice.builders.ListBuilder;
+import androidx.slice.builders.SliceAction;
+
+import android.support.v4.graphics.drawable.IconCompat;
+
+/**
+ * Utility class to build an intent-based Location Slice.
+ */
+public class LocationSliceBuilder {
+
+    /**
+     * Backing Uri for the Location Slice.
+     */
+    public static final Uri LOCATION_URI = new Uri.Builder()
+            .scheme(ContentResolver.SCHEME_CONTENT)
+            .authority(SettingsSlicesContract.AUTHORITY)
+            .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
+            .appendPath(KEY_LOCATION)
+            .build();
+
+    private LocationSliceBuilder() {
+    }
+
+    /**
+     * Return a Location Slice bound to {@link #LOCATION_URI}.
+     */
+    public static Slice getSlice(Context context) {
+        final IconCompat icon = IconCompat.createWithResource(context,
+                R.drawable.ic_signal_location);
+        final String title = context.getString(R.string.location_settings_title);
+        @ColorInt final int color = Utils.getColorAccent(context);
+        final PendingIntent primaryAction = getPrimaryAction(context);
+        final SliceAction primarySliceAction = new SliceAction(primaryAction, icon, title);
+
+        return new ListBuilder(context, LOCATION_URI, ListBuilder.INFINITY)
+                .setAccentColor(color)
+                .addRow(b -> b
+                        .setTitle(title)
+                        .setTitleItem(icon, ICON_IMAGE)
+                        .setPrimaryAction(primarySliceAction))
+                .build();
+    }
+
+    private static PendingIntent getPrimaryAction(Context context) {
+        final String screenTitle = context.getText(R.string.location_settings_title).toString();
+        final Uri contentUri = new Uri.Builder().appendPath(KEY_LOCATION).build();
+        final Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(context,
+                LocationSettings.class.getName(), KEY_LOCATION, screenTitle,
+                MetricsEvent.LOCATION)
+                .setClassName(context.getPackageName(), SubSettings.class.getName())
+                .setData(contentUri);
+
+        return PendingIntent.getActivity(context, 0 /* requestCode */,
+                intent, 0 /* flags */);
+    }
+}
diff --git a/src/com/android/settings/notification/NotificationPreferenceController.java b/src/com/android/settings/notification/NotificationPreferenceController.java
index 1e477c4..0c5dc0e 100644
--- a/src/com/android/settings/notification/NotificationPreferenceController.java
+++ b/src/com/android/settings/notification/NotificationPreferenceController.java
@@ -83,28 +83,6 @@
         return true;
     }
 
-    /**
-     * Displays or removes preference in this controller.
-     */
-    @Override
-    public void displayPreference(PreferenceScreen screen) {
-        if (isAvailable()) {
-            final Preference preference = screen.findPreference(getPreferenceKey());
-            if (mPreference != null && preference == null) {
-                screen.addPreference(mPreference);
-            }
-            if (preference != null) {
-                mPreference = preference;
-            }
-            if (mPreference != null && this instanceof Preference.OnPreferenceChangeListener) {
-                mPreference.setOnPreferenceChangeListener(
-                        (Preference.OnPreferenceChangeListener) this);
-            }
-        } else {
-            findAndRemovePreference(screen, getPreferenceKey());
-        }
-    }
-
     // finds the preference recursively and removes it from its parent
     private void findAndRemovePreference(PreferenceGroup prefGroup, String key) {
         final int preferenceCount = prefGroup.getPreferenceCount();
diff --git a/src/com/android/settings/notification/ZenModeSliceBuilder.java b/src/com/android/settings/notification/ZenModeSliceBuilder.java
index 0edf214..aedd0b3 100644
--- a/src/com/android/settings/notification/ZenModeSliceBuilder.java
+++ b/src/com/android/settings/notification/ZenModeSliceBuilder.java
@@ -18,6 +18,8 @@
 
 import static android.app.slice.Slice.EXTRA_TOGGLE_STATE;
 
+import static androidx.slice.builders.ListBuilder.ICON_IMAGE;
+
 import android.annotation.ColorInt;
 import android.app.NotificationManager;
 import android.app.PendingIntent;
diff --git a/src/com/android/settings/search/DeviceIndexFeatureProvider.java b/src/com/android/settings/search/DeviceIndexFeatureProvider.java
index bf75ee8..1c25399 100644
--- a/src/com/android/settings/search/DeviceIndexFeatureProvider.java
+++ b/src/com/android/settings/search/DeviceIndexFeatureProvider.java
@@ -31,6 +31,7 @@
 import com.android.settings.slices.SettingsSliceProvider;
 
 import java.util.List;
+import java.util.Locale;
 import java.util.Objects;
 
 public interface DeviceIndexFeatureProvider {
@@ -39,15 +40,21 @@
     String TAG = "DeviceIndex";
 
     String INDEX_VERSION = "settings:index_version";
+    String INDEX_LANGUAGE = "settings:language";
 
     // Increment when new items are added to ensure they get pushed to the device index.
     String VERSION = Build.FINGERPRINT;
 
+    // When the device language changes, re-index so Slices trigger in device language.
+    Locale LANGUAGE = Locale.getDefault();
+
     boolean isIndexingEnabled();
 
     void index(Context context, CharSequence title, Uri sliceUri, Uri launchUri,
             List<String> keywords);
 
+    void clearIndex(Context context);
+
     default void updateIndex(Context context, boolean force) {
         if (!isIndexingEnabled()) {
             Log.w(TAG, "Skipping: device index is not enabled");
@@ -59,12 +66,14 @@
             return;
         }
 
-        if (!force && Objects.equals(
-                Settings.Secure.getString(context.getContentResolver(), INDEX_VERSION), VERSION)) {
+        if (!force && skipIndex(context)) {
             // No need to update.
             return;
         }
 
+        // Prevent scheduling multiple jobs
+        setIndexState(context);
+
         final ComponentName jobComponent = new ComponentName(context.getPackageName(),
                 DeviceIndexUpdateJobService.class.getName());
         final int jobId = context.getResources().getInteger(R.integer.device_index_update);
@@ -77,7 +86,6 @@
                         .setOverrideDeadline(1)
                         .build());
 
-        Settings.Secure.putString(context.getContentResolver(), INDEX_VERSION, VERSION);
     }
 
     static Uri createDeepLink(String s) {
@@ -86,4 +94,18 @@
                 .appendQueryParameter(INTENT, s)
                 .build();
     }
+
+    static boolean skipIndex(Context context) {
+        final boolean isSameVersion = Objects.equals(
+                Settings.Secure.getString(context.getContentResolver(), INDEX_VERSION), VERSION);
+        final boolean isSameLanguage = Objects.equals(
+                Settings.Secure.getString(context.getContentResolver(), INDEX_LANGUAGE), LANGUAGE);
+        return isSameLanguage && isSameVersion;
+    }
+
+    static void setIndexState(Context context) {
+        Settings.Secure.putString(context.getContentResolver(), INDEX_VERSION, VERSION);
+        Settings.Secure.putString(context.getContentResolver(), INDEX_LANGUAGE,
+                LANGUAGE.toString());
+    }
 }
diff --git a/src/com/android/settings/search/DeviceIndexFeatureProviderImpl.java b/src/com/android/settings/search/DeviceIndexFeatureProviderImpl.java
index 7a11bd4..087ecf8 100644
--- a/src/com/android/settings/search/DeviceIndexFeatureProviderImpl.java
+++ b/src/com/android/settings/search/DeviceIndexFeatureProviderImpl.java
@@ -31,4 +31,9 @@
             List<String> keywords) {
         // Not enabled by default.
     }
+
+    @Override
+    public void clearIndex(Context context) {
+        // Not enabled by default.
+    }
 }
diff --git a/src/com/android/settings/search/DeviceIndexUpdateJobService.java b/src/com/android/settings/search/DeviceIndexUpdateJobService.java
index 19b7d5e..97b0a61 100644
--- a/src/com/android/settings/search/DeviceIndexUpdateJobService.java
+++ b/src/com/android/settings/search/DeviceIndexUpdateJobService.java
@@ -25,6 +25,7 @@
 import android.content.Intent;
 import android.net.Uri;
 import android.net.Uri.Builder;
+import android.provider.SettingsSlicesContract;
 import android.util.Log;
 
 import com.android.internal.annotations.VisibleForTesting;
@@ -84,11 +85,19 @@
                 .scheme(ContentResolver.SCHEME_CONTENT)
                 .authority(SettingsSliceProvider.SLICE_AUTHORITY)
                 .build();
+        final Uri platformBaseUri = new Builder()
+                .scheme(ContentResolver.SCHEME_CONTENT)
+                .authority(SettingsSlicesContract.AUTHORITY)
+                .build();
         final Collection<Uri> slices = manager.getSliceDescendants(baseUri);
+        slices.addAll(manager.getSliceDescendants(platformBaseUri));
+
         if (DEBUG) {
             Log.d(TAG, "Indexing " + slices.size() + " slices");
         }
 
+        indexProvider.clearIndex(this /* context */);
+
         for (Uri slice : slices) {
             if (!mRunningJob) {
                 return;
diff --git a/src/com/android/settings/slices/SettingsSliceProvider.java b/src/com/android/settings/slices/SettingsSliceProvider.java
index 3ed6185..557ecad 100644
--- a/src/com/android/settings/slices/SettingsSliceProvider.java
+++ b/src/com/android/settings/slices/SettingsSliceProvider.java
@@ -33,6 +33,7 @@
 import android.util.Log;
 import android.util.Pair;
 
+import com.android.settings.location.LocationSliceBuilder;
 import com.android.settings.overlay.FeatureFactory;
 import com.android.settings.core.BasePreferenceController;
 import com.android.settings.wifi.WifiSliceBuilder;
@@ -188,6 +189,8 @@
             return ZenModeSliceBuilder.getSlice(getContext());
         } else if (BluetoothSliceBuilder.BLUETOOTH_URI.equals(sliceUri)) {
             return BluetoothSliceBuilder.getSlice(getContext());
+        } else if (LocationSliceBuilder.LOCATION_URI.equals(sliceUri)) {
+            return LocationSliceBuilder.getSlice(getContext());
         }
 
         SliceData cachedSliceData = mSliceWeakDataCache.get(sliceUri);
@@ -289,10 +292,17 @@
     void loadSlice(Uri uri) {
         long startBuildTime = System.currentTimeMillis();
 
-        final SliceData sliceData = mSlicesDatabaseAccessor.getSliceDataFromUri(uri);
+        final SliceData sliceData;
+        try {
+            sliceData = mSlicesDatabaseAccessor.getSliceDataFromUri(uri);
+        } catch (IllegalStateException e) {
+            Log.e(TAG, "Could not get slice data for uri: " + uri, e);
+            return;
+        }
 
         final BasePreferenceController controller = SliceBuilderUtils.getPreferenceController(
                 getContext(), sliceData);
+
         final IntentFilter filter = controller.getIntentFilter();
         if (filter != null) {
             registerIntentToUri(filter, uri);
@@ -336,7 +346,8 @@
     private List<Uri> getSpecialCasePlatformUris() {
         return Arrays.asList(
                 WifiSliceBuilder.WIFI_URI,
-                BluetoothSliceBuilder.BLUETOOTH_URI
+                BluetoothSliceBuilder.BLUETOOTH_URI,
+                LocationSliceBuilder.LOCATION_URI
         );
     }
 
diff --git a/src/com/android/settings/slices/SliceBuilderUtils.java b/src/com/android/settings/slices/SliceBuilderUtils.java
index 43216f8..be433b7 100644
--- a/src/com/android/settings/slices/SliceBuilderUtils.java
+++ b/src/com/android/settings/slices/SliceBuilderUtils.java
@@ -86,8 +86,13 @@
         FeatureFactory.getFactory(context).getMetricsFeatureProvider()
                 .action(context, MetricsEvent.ACTION_SETTINGS_SLICE_REQUESTED, sliceNamePair);
 
-        if (controller.getAvailabilityStatus() != AVAILABLE) {
-            return buildUnavailableSlice(context, sliceData, controller);
+        if (!controller.isAvailable()) {
+            // Cannot guarantee setting page is accessible, let the presenter handle error case.
+            return null;
+        }
+
+        if (controller.getAvailabilityStatus() == DISABLED_DEPENDENT_SETTING) {
+            return buildUnavailableSlice(context, sliceData);
         }
 
         switch (sliceData.getSliceType()) {
@@ -177,14 +182,6 @@
     }
 
     /**
-     * @return {@link PendingIntent} to the Settings home page.
-     */
-    public static PendingIntent getSettingsIntent(Context context) {
-        final Intent intent = new Intent(Settings.ACTION_SETTINGS);
-        return PendingIntent.getActivity(context, 0 /* requestCode */, intent, 0 /* flags */);
-    }
-
-    /**
      * @return the summary text for a {@link Slice} built for {@param sliceData}.
      */
     public static CharSequence getSubtitleText(Context context,
@@ -358,40 +355,20 @@
         return keywords;
     }
 
-    private static Slice buildUnavailableSlice(Context context, SliceData data,
-            BasePreferenceController controller) {
+    private static Slice buildUnavailableSlice(Context context, SliceData data) {
         final String title = data.getTitle();
         final List<String> keywords = buildSliceKeywords(data);
         @ColorInt final int color = Utils.getColorAccent(context);
-        final String summary;
-        final SliceAction primaryAction;
+        final CharSequence summary = context.getText(R.string.disabled_dependent_setting_summary);
         final IconCompat icon = IconCompat.createWithResource(context, data.getIconResource());
-
-        switch (controller.getAvailabilityStatus()) {
-            case UNSUPPORTED_ON_DEVICE:
-                summary = context.getString(R.string.unsupported_setting_summary);
-                primaryAction = new SliceAction(getSettingsIntent(context), icon, title);
-                break;
-            case DISABLED_FOR_USER:
-                summary = context.getString(R.string.disabled_for_user_setting_summary);
-                primaryAction = new SliceAction(getContentPendingIntent(context, data), icon,
-                        title);
-                break;
-            case DISABLED_DEPENDENT_SETTING:
-                summary = context.getString(R.string.disabled_dependent_setting_summary);
-                primaryAction = new SliceAction(getContentPendingIntent(context, data), icon,
-                        title);
-                break;
-            case CONDITIONALLY_UNAVAILABLE:
-            default:
-                summary = context.getString(R.string.unknown_unavailability_setting_summary);
-                primaryAction = new SliceAction(getSettingsIntent(context), icon, title);
-        }
+        final SliceAction primaryAction = new SliceAction(getContentPendingIntent(context, data),
+                icon, title);
 
         return new ListBuilder(context, data.getUri(), ListBuilder.INFINITY)
                 .setAccentColor(color)
                 .addRow(builder -> builder
                         .setTitle(title)
+                        .setTitleItem(icon)
                         .setSubtitle(summary)
                         .setPrimaryAction(primaryAction))
                 .setKeywords(keywords)
diff --git a/src/com/android/settings/widget/TwoStateButtonPreference.java b/src/com/android/settings/widget/TwoStateButtonPreference.java
index 6b5fbbb..78d4874 100644
--- a/src/com/android/settings/widget/TwoStateButtonPreference.java
+++ b/src/com/android/settings/widget/TwoStateButtonPreference.java
@@ -18,8 +18,10 @@
 
 import android.content.Context;
 import android.content.res.TypedArray;
+import android.support.annotation.VisibleForTesting;
 import android.support.v4.content.res.TypedArrayUtils;
 import android.util.AttributeSet;
+import android.view.View;
 import android.widget.Button;
 
 import com.android.settings.R;
@@ -28,12 +30,21 @@
 /**
  * Preference that presents a button with two states(On vs Off)
  */
-public class TwoStateButtonPreference extends LayoutPreference {
+public class TwoStateButtonPreference extends LayoutPreference implements
+        View.OnClickListener {
+
+    private boolean mIsChecked;
+    private final Button mButtonOn;
+    private final Button mButtonOff;
+
     public TwoStateButtonPreference(Context context, AttributeSet attrs) {
         super(context, attrs, TypedArrayUtils.getAttr(
                 context, R.attr.twoStateButtonPreferenceStyle, android.R.attr.preferenceStyle));
 
-        if (attrs != null) {
+        if (attrs == null) {
+            mButtonOn = null;
+            mButtonOff = null;
+        } else {
             final TypedArray styledAttrs = context.obtainStyledAttributes(attrs,
                     R.styleable.TwoStateButtonPreference);
             final int textOnId = styledAttrs.getResourceId(
@@ -44,19 +55,52 @@
                     R.string.summary_placeholder);
             styledAttrs.recycle();
 
-            final Button buttonOn = getStateOnButton();
-            buttonOn.setText(textOnId);
-            final Button buttonOff = getStateOffButton();
-            buttonOff.setText(textOffId);
+            mButtonOn = findViewById(R.id.state_on_button);
+            mButtonOn.setText(textOnId);
+            mButtonOn.setOnClickListener(this);
+            mButtonOff = findViewById(R.id.state_off_button);
+            mButtonOff.setText(textOffId);
+            mButtonOff.setOnClickListener(this);
+            setChecked(isChecked());
         }
     }
 
-    public Button getStateOnButton() {
-        return findViewById(R.id.state_on_button);
+    @Override
+    public void onClick(View v) {
+        final boolean stateOn = v.getId() == R.id.state_on_button;
+        setChecked(stateOn);
+        callChangeListener(stateOn);
     }
 
+    public void setChecked(boolean checked) {
+        // Update state
+        mIsChecked = checked;
+        // And update UI
+        if (checked) {
+            mButtonOn.setVisibility(View.GONE);
+            mButtonOff.setVisibility(View.VISIBLE);
+        } else {
+            mButtonOn.setVisibility(View.VISIBLE);
+            mButtonOff.setVisibility(View.GONE);
+        }
+    }
 
+    public boolean isChecked() {
+        return mIsChecked;
+    }
+
+    public void setButtonEnabled(boolean enabled) {
+        mButtonOn.setEnabled(enabled);
+        mButtonOff.setEnabled(enabled);
+    }
+
+    @VisibleForTesting
+    public Button getStateOnButton() {
+        return mButtonOn;
+    }
+
+    @VisibleForTesting
     public Button getStateOffButton() {
-        return findViewById(R.id.state_off_button);
+        return mButtonOff;
     }
 }
\ No newline at end of file
diff --git a/src/com/android/settings/widget/TwoStateButtonPreferenceController.java b/src/com/android/settings/widget/TwoStateButtonPreferenceController.java
deleted file mode 100644
index 47699ef..0000000
--- a/src/com/android/settings/widget/TwoStateButtonPreferenceController.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * 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.widget;
-
-import android.content.Context;
-import android.support.v7.preference.PreferenceScreen;
-import android.view.View;
-import android.widget.Button;
-
-import com.android.settings.R;
-import com.android.settings.core.BasePreferenceController;
-
-/**
- * Controller to update the button with two states(On vs Off).
- */
-public abstract class TwoStateButtonPreferenceController extends BasePreferenceController
-        implements View.OnClickListener {
-    private Button mButtonOn;
-    private Button mButtonOff;
-
-    public TwoStateButtonPreferenceController(Context context, String key) {
-        super(context, key);
-    }
-
-    @Override
-    public void displayPreference(PreferenceScreen screen) {
-        super.displayPreference(screen);
-        final TwoStateButtonPreference preference =
-                (TwoStateButtonPreference) screen.findPreference(getPreferenceKey());
-        mButtonOn = preference.getStateOnButton();
-        mButtonOn.setOnClickListener(this);
-        mButtonOff = preference.getStateOffButton();
-        mButtonOff.setOnClickListener(this);
-    }
-
-    protected void setButtonVisibility(boolean stateOn) {
-        if (stateOn) {
-            mButtonOff.setVisibility(View.GONE);
-            mButtonOn.setVisibility(View.VISIBLE);
-        } else {
-            mButtonOff.setVisibility(View.VISIBLE);
-            mButtonOn.setVisibility(View.GONE);
-        }
-    }
-
-    protected void setButtonEnabled(boolean enabled) {
-        mButtonOn.setEnabled(enabled);
-        mButtonOff.setEnabled(enabled);
-    }
-
-    @Override
-    public void onClick(View v) {
-        final boolean stateOn = v.getId() == R.id.state_on_button;
-        onButtonClicked(stateOn);
-    }
-
-    /**
-     * Callback when button is clicked
-     *
-     * @param stateOn {@code true} if stateOn button is clicked, otherwise it means stateOff
-     *                button is clicked
-     */
-    public abstract void onButtonClicked(boolean stateOn);
-}
\ No newline at end of file
diff --git a/src/com/android/settings/wifi/WifiConfigController.java b/src/com/android/settings/wifi/WifiConfigController.java
index 79196f1..26e7b57 100644
--- a/src/com/android/settings/wifi/WifiConfigController.java
+++ b/src/com/android/settings/wifi/WifiConfigController.java
@@ -220,8 +220,6 @@
         mMeteredSettingsSpinner = mView.findViewById(R.id.metered_settings);
         mHiddenSettingsSpinner = mView.findViewById(R.id.hidden_settings);
         mHiddenSettingsSpinner.setOnItemSelectedListener(this);
-        mHiddenSettingsSpinner.setVisibility(View.GONE);
-        mHiddenSettingsSpinner.setEnabled(false);
         mHiddenWarningView = mView.findViewById(R.id.hidden_settings_warning);
         mHiddenWarningView.setVisibility(
                 mHiddenSettingsSpinner.getSelectedItemPosition() == NOT_HIDDEN_NETWORK
@@ -241,8 +239,7 @@
             showProxyFields();
             mView.findViewById(R.id.wifi_advanced_toggle).setVisibility(View.VISIBLE);
             // Hidden option can be changed only when the user adds a network manually.
-            mHiddenSettingsSpinner.setVisibility(View.VISIBLE);
-            mHiddenSettingsSpinner.setEnabled(true);
+            mView.findViewById(R.id.hidden_settings_field).setVisibility(View.VISIBLE);
             ((CheckBox) mView.findViewById(R.id.wifi_advanced_togglebox))
                     .setOnCheckedChangeListener(this);
 
diff --git a/src/com/android/settings/wifi/WifiSliceBuilder.java b/src/com/android/settings/wifi/WifiSliceBuilder.java
index 96d1b82..7df7f19 100644
--- a/src/com/android/settings/wifi/WifiSliceBuilder.java
+++ b/src/com/android/settings/wifi/WifiSliceBuilder.java
@@ -19,6 +19,8 @@
 import static android.app.slice.Slice.EXTRA_TOGGLE_STATE;
 import static android.provider.SettingsSlicesContract.KEY_WIFI;
 
+import static androidx.slice.builders.ListBuilder.ICON_IMAGE;
+
 import android.annotation.ColorInt;
 import android.app.PendingIntent;
 import android.content.ContentResolver;
diff --git a/src/com/android/settings/wifi/calling/WifiCallingSliceHelper.java b/src/com/android/settings/wifi/calling/WifiCallingSliceHelper.java
index a554e74..cec8545 100644
--- a/src/com/android/settings/wifi/calling/WifiCallingSliceHelper.java
+++ b/src/com/android/settings/wifi/calling/WifiCallingSliceHelper.java
@@ -25,6 +25,7 @@
 import android.content.Intent;
 import android.net.Uri;
 import android.os.PersistableBundle;
+import android.provider.Settings;
 import android.support.v4.graphics.drawable.IconCompat;
 import android.telephony.CarrierConfigManager;
 import android.telephony.SubscriptionManager;
@@ -121,7 +122,7 @@
             return getNonActionableWifiCallingSlice(
                     mContext.getString(R.string.wifi_calling_settings_title),
                     mContext.getString(R.string.wifi_calling_not_supported, carrierName),
-                    sliceUri, SliceBuilderUtils.getSettingsIntent(mContext));
+                    sliceUri, getSettingsIntent(mContext));
         }
 
         final ImsManager imsManager = getImsManager(subId);
@@ -132,7 +133,7 @@
             return getNonActionableWifiCallingSlice(
                     mContext.getString(R.string.wifi_calling_settings_title),
                     mContext.getString(R.string.wifi_calling_not_supported, carrierName),
-                    sliceUri, SliceBuilderUtils.getSettingsIntent(mContext));
+                    sliceUri, getSettingsIntent(mContext));
         }
 
         try {
@@ -338,6 +339,14 @@
         return intent;
     }
 
+    /**
+     * @return {@link PendingIntent} to the Settings home page.
+     */
+    public static PendingIntent getSettingsIntent(Context context) {
+        final Intent intent = new Intent(Settings.ACTION_SETTINGS);
+        return PendingIntent.getActivity(context, 0 /* requestCode */, intent, 0 /* flags */);
+    }
+
     private PendingIntent getBroadcastIntent(String action) {
         final Intent intent = new Intent(action);
         intent.setClass(mContext, SliceBroadcastReceiver.class);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterysaver/BatterySaverButtonPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterysaver/BatterySaverButtonPreferenceControllerTest.java
index 14f6533..641a15f 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterysaver/BatterySaverButtonPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterysaver/BatterySaverButtonPreferenceControllerTest.java
@@ -21,17 +21,13 @@
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.spy;
 
-import android.arch.lifecycle.LifecycleOwner;
 import android.content.Context;
 import android.os.PowerManager;
 import android.support.v7.preference.PreferenceScreen;
-import android.view.View;
 import android.widget.Button;
 
-import com.android.settings.R;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.widget.TwoStateButtonPreference;
-import com.android.settingslib.core.lifecycle.Lifecycle;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -41,6 +37,7 @@
 import org.robolectric.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
 import org.robolectric.shadows.ShadowPowerManager;
+import org.robolectric.util.ReflectionHelpers;
 
 @RunWith(SettingsRobolectricTestRunner.class)
 @Config(shadows = ShadowPowerManager.class)
@@ -48,67 +45,58 @@
 
     private BatterySaverButtonPreferenceController mController;
     private Context mContext;
-    private Lifecycle mLifecycle;
-    private LifecycleOwner mLifecycleOwner;
     private Button mButtonOn;
     private Button mButtonOff;
     private PowerManager mPowerManager;
-    @Mock
     private TwoStateButtonPreference mPreference;
+
     @Mock
     private PreferenceScreen mPreferenceScreen;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-
-        mLifecycleOwner = () -> mLifecycle;
-        mLifecycle = new Lifecycle(mLifecycleOwner);
         mContext = spy(RuntimeEnvironment.application);
+        mButtonOn = new Button(mContext);
+        mButtonOff = new Button(mContext);
         mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
+        mPreference = spy(new TwoStateButtonPreference(mContext, null /* AttributeSet */));
+        ReflectionHelpers.setField(mPreference, "mButtonOn", mButtonOn);
+        ReflectionHelpers.setField(mPreference, "mButtonOff", mButtonOff);
         doReturn(mPreference).when(mPreferenceScreen).findPreference(anyString());
 
-        mButtonOn = new Button(mContext);
-        mButtonOn.setId(R.id.state_on_button);
-        doReturn(mButtonOn).when(mPreference).getStateOnButton();
-        mButtonOff = new Button(mContext);
-        mButtonOff.setId(R.id.state_off_button);
-        doReturn(mButtonOff).when(mPreference).getStateOffButton();
-
-        mController = new BatterySaverButtonPreferenceController(mContext, mLifecycle);
+        mController = new BatterySaverButtonPreferenceController(mContext, "test_key");
         mController.displayPreference(mPreferenceScreen);
     }
 
     @Test
-    public void testUpdateState_lowPowerOn_displayButtonOff() {
+    public void updateState_lowPowerOn_preferenceIsChecked() {
         mPowerManager.setPowerSaveMode(true);
 
         mController.updateState(mPreference);
 
-        assertThat(mButtonOn.getVisibility()).isEqualTo(View.GONE);
-        assertThat(mButtonOff.getVisibility()).isEqualTo(View.VISIBLE);
+        assertThat(mPreference.isChecked()).isTrue();
     }
 
     @Test
-    public void testUpdateState_lowPowerOff_displayButtonOn() {
+    public void testUpdateState_lowPowerOff_preferenceIsUnchecked() {
         mPowerManager.setPowerSaveMode(false);
 
         mController.updateState(mPreference);
 
-        assertThat(mButtonOn.getVisibility()).isEqualTo(View.VISIBLE);
-        assertThat(mButtonOff.getVisibility()).isEqualTo(View.GONE);
+        assertThat(mPreference.isChecked()).isFalse();
     }
 
     @Test
-    public void testOnClick_clickButtonOn_setPowerSaveMode() {
-        mController.onClick(mButtonOn);
+    public void setChecked_on_setPowerSaveMode() {
+        mController.setChecked(true);
 
         assertThat(mPowerManager.isPowerSaveMode()).isTrue();
     }
 
     @Test
-    public void testOnClick_clickButtonOff_clearPowerSaveMode() {
-        mController.onClick(mButtonOff);
+    public void setChecked_off_unsetPowerSaveMode() {
+        mController.setChecked(false);
 
         assertThat(mPowerManager.isPowerSaveMode()).isFalse();
     }
diff --git a/tests/robotests/src/com/android/settings/location/LocationSliceBuilderTest.java b/tests/robotests/src/com/android/settings/location/LocationSliceBuilderTest.java
new file mode 100644
index 0000000..22928bf
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/location/LocationSliceBuilderTest.java
@@ -0,0 +1,65 @@
+package com.android.settings.location;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.support.v4.graphics.drawable.IconCompat;
+
+import com.android.settings.R;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.SliceTester;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
+
+import java.util.List;
+
+import androidx.slice.Slice;
+import androidx.slice.SliceItem;
+import androidx.slice.SliceMetadata;
+import androidx.slice.SliceProvider;
+import androidx.slice.core.SliceAction;
+import androidx.slice.widget.SliceLiveData;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class LocationSliceBuilderTest {
+
+    private Context mContext;
+
+    @Before
+    public void setUp() {
+        mContext = spy(RuntimeEnvironment.application);
+
+        // Prevent crash in SliceMetadata.
+        Resources resources = spy(mContext.getResources());
+        doReturn(60).when(resources).getDimensionPixelSize(anyInt());
+        doReturn(resources).when(mContext).getResources();
+
+        // Set-up specs for SliceMetadata.
+        SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
+    }
+
+    @Test
+    public void getLocationSlice_correctSliceContent() {
+        final Slice LocationSlice = LocationSliceBuilder.getSlice(mContext);
+        final SliceMetadata metadata = SliceMetadata.from(mContext, LocationSlice);
+
+        final List<SliceAction> toggles = metadata.getToggles();
+        assertThat(toggles).isEmpty();
+
+        final SliceAction primaryAction = metadata.getPrimaryAction();
+        final IconCompat expectedToggleIcon = IconCompat.createWithResource(mContext,
+                R.drawable.ic_signal_location);
+        assertThat(primaryAction.getIcon().toString()).isEqualTo(expectedToggleIcon.toString());
+
+        final List<SliceItem> sliceItems = LocationSlice.getItems();
+        SliceTester.assertTitle(sliceItems, mContext.getString(R.string.location_settings_title));
+    }
+}
diff --git a/tests/robotests/src/com/android/settings/search/DeviceIndexFeatureProviderTest.java b/tests/robotests/src/com/android/settings/search/DeviceIndexFeatureProviderTest.java
index d4c1580..a900db0 100644
--- a/tests/robotests/src/com/android/settings/search/DeviceIndexFeatureProviderTest.java
+++ b/tests/robotests/src/com/android/settings/search/DeviceIndexFeatureProviderTest.java
@@ -23,6 +23,7 @@
 
 import android.app.Activity;
 import android.app.job.JobScheduler;
+import android.os.Build;
 import android.provider.Settings;
 
 import com.android.settings.testutils.FakeFeatureFactory;
@@ -76,4 +77,51 @@
         mProvider.updateIndex(mActivity, false);
         verify(jobScheduler).schedule(any());
     }
+
+    @Test
+    public void updateIndex_enabled_provisioned_newBuild_shouldIndex() {
+        Settings.Global.putInt(mActivity.getContentResolver(),
+                Settings.Global.DEVICE_PROVISIONED, 1);
+        DeviceIndexFeatureProvider.setIndexState(mActivity);
+        Settings.Global.putString(mActivity.getContentResolver(),
+                DeviceIndexFeatureProvider.INDEX_VERSION, "new version");
+        Settings.Global.putString(mActivity.getContentResolver(),
+                DeviceIndexFeatureProvider.LANGUAGE.toString(),
+                DeviceIndexFeatureProvider.INDEX_LANGUAGE);
+        JobScheduler jobScheduler = mock(JobScheduler.class);
+        when(mProvider.isIndexingEnabled()).thenReturn(true);
+        when(mActivity.getSystemService(JobScheduler.class)).thenReturn(jobScheduler);
+
+        mProvider.updateIndex(mActivity, false);
+        verify(jobScheduler).schedule(any());
+    }
+
+    @Test
+    public void updateIndex_enabled_provisioned_newIndex_shouldIndex() {
+        Settings.Global.putInt(mActivity.getContentResolver(),
+                Settings.Global.DEVICE_PROVISIONED, 1);
+        DeviceIndexFeatureProvider.setIndexState(mActivity);
+        Settings.Global.putString(mActivity.getContentResolver(),
+                DeviceIndexFeatureProvider.INDEX_LANGUAGE, "new language");
+        JobScheduler jobScheduler = mock(JobScheduler.class);
+        when(mProvider.isIndexingEnabled()).thenReturn(true);
+        when(mActivity.getSystemService(JobScheduler.class)).thenReturn(jobScheduler);
+
+        mProvider.updateIndex(mActivity, false);
+        verify(jobScheduler).schedule(any());
+    }
+
+    @Test
+    public void updateIndex_enabled_provisioned_sameBuild_sameLang_shouldNotIndex() {
+        Settings.Global.putInt(mActivity.getContentResolver(),
+                Settings.Global.DEVICE_PROVISIONED, 1);
+        DeviceIndexFeatureProvider.setIndexState(mActivity);
+        JobScheduler jobScheduler = mock(JobScheduler.class);
+        when(mProvider.isIndexingEnabled()).thenReturn(true);
+        when(mActivity.getSystemService(JobScheduler.class)).thenReturn(jobScheduler);
+
+        mProvider.updateIndex(mActivity, false);
+
+        verify(mProvider, never()).index(any(), any(), any(), any(), any());
+    }
 }
diff --git a/tests/robotests/src/com/android/settings/search/DeviceIndexUpdateJobServiceTest.java b/tests/robotests/src/com/android/settings/search/DeviceIndexUpdateJobServiceTest.java
index ec16893..b5de973 100644
--- a/tests/robotests/src/com/android/settings/search/DeviceIndexUpdateJobServiceTest.java
+++ b/tests/robotests/src/com/android/settings/search/DeviceIndexUpdateJobServiceTest.java
@@ -124,6 +124,7 @@
 
         DeviceIndexFeatureProvider indexFeatureProvider = FakeFeatureFactory.getFactory(mActivity)
                 .getDeviceIndexFeatureProvider();
+        verify(indexFeatureProvider).clearIndex(any());
         verify(indexFeatureProvider, times(1)).index(any(), any(), any(), any(), any());
     }
 
diff --git a/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java b/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java
index 722f481..bb064d1 100644
--- a/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java
+++ b/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java
@@ -28,6 +28,7 @@
 import static org.mockito.Mockito.when;
 
 import android.app.slice.SliceManager;
+import android.content.ContentResolver;
 import android.content.ContentValues;
 import android.content.Context;
 import android.database.sqlite.SQLiteDatabase;
@@ -35,6 +36,7 @@
 import android.os.StrictMode;
 import android.provider.SettingsSlicesContract;
 
+import com.android.settings.location.LocationSliceBuilder;
 import com.android.settings.wifi.WifiSliceBuilder;
 import com.android.settings.bluetooth.BluetoothSliceBuilder;
 import com.android.settings.notification.ZenModeSliceBuilder;
@@ -81,7 +83,8 @@
 
     private static final List<Uri> SPECIAL_CASE_PLATFORM_URIS = Arrays.asList(
             WifiSliceBuilder.WIFI_URI,
-            BluetoothSliceBuilder.BLUETOOTH_URI
+            BluetoothSliceBuilder.BLUETOOTH_URI,
+            LocationSliceBuilder.LOCATION_URI
     );
 
     private static final List<Uri> SPECIAL_CASE_OEM_URIS = Arrays.asList(
@@ -401,6 +404,18 @@
         assertThat(wifiSlice.getUri()).isEqualTo(WifiSliceBuilder.WIFI_URI);
     }
 
+    @Test
+    public void onSlicePinned_noIntentRegistered_specialCaseUri_doesNotCrash() {
+        final Uri uri = new Uri.Builder()
+                .scheme(ContentResolver.SCHEME_CONTENT)
+                .authority(SettingsSlicesContract.AUTHORITY)
+                .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
+                .appendPath(SettingsSlicesContract.KEY_LOCATION)
+                .build();
+
+        mProvider.onSlicePinned(uri);
+    }
+
     private void insertSpecialCase(String key) {
         insertSpecialCase(key, true);
     }
diff --git a/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java b/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java
index 00e8fe1..96e475e 100644
--- a/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/slices/SliceBuilderUtilsTest.java
@@ -336,7 +336,7 @@
 
         final Slice slice = SliceBuilderUtils.buildSlice(mContext, data);
 
-        SliceTester.testSettingsUnavailableSlice(mContext, slice, data);
+        assertThat(slice).isNull();
     }
 
     @Test
@@ -349,7 +349,7 @@
 
         final Slice slice = SliceBuilderUtils.buildSlice(mContext, data);
 
-        SliceTester.testSettingsUnavailableSlice(mContext, slice, data);
+        assertThat(slice).isNull();
     }
 
     @Test
@@ -394,7 +394,7 @@
                 .isEqualTo(MetricsEvent.FIELD_SETTINGS_PREFERENCE_CHANGE_NAME);
         assertThat(capturedLoggingPair.second)
                 .isEqualTo(data.getKey());
-        SliceTester.testSettingsUnavailableSlice(mContext, slice, data);
+        assertThat(slice).isNull();
     }
 
     @Test
@@ -408,16 +408,6 @@
         assertThat(intentData).isEqualTo(expectedUri);
     }
 
-    @Test
-    public void getSettingsIntent_createsIntentToSettings() {
-        final Intent intent = new Intent(Settings.ACTION_SETTINGS);
-        final PendingIntent expectedIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
-
-        final PendingIntent settingsIntent = SliceBuilderUtils.getSettingsIntent(mContext);
-
-        assertThat(expectedIntent).isEqualTo(settingsIntent);
-    }
-
     private SliceData getDummyData() {
         return getDummyData(TOGGLE_CONTROLLER, SUMMARY, SliceData.SliceType.SWITCH, SCREEN_TITLE);
     }
diff --git a/tests/robotests/src/com/android/settings/testutils/SliceTester.java b/tests/robotests/src/com/android/settings/testutils/SliceTester.java
index 870adae..7dd22aa 100644
--- a/tests/robotests/src/com/android/settings/testutils/SliceTester.java
+++ b/tests/robotests/src/com/android/settings/testutils/SliceTester.java
@@ -194,20 +194,8 @@
         assertThat(toggles).isEmpty();
 
         final PendingIntent primaryPendingIntent = metadata.getPrimaryAction().getAction();
-        final int availabilityStatus = SliceBuilderUtils.getPreferenceController(context,
-                sliceData).getAvailabilityStatus();
-        switch (availabilityStatus) {
-            case UNSUPPORTED_ON_DEVICE:
-            case CONDITIONALLY_UNAVAILABLE:
-                assertThat(primaryPendingIntent).isEqualTo(
-                        SliceBuilderUtils.getSettingsIntent(context));
-                break;
-            case DISABLED_FOR_USER:
-            case DISABLED_DEPENDENT_SETTING:
-                assertThat(primaryPendingIntent).isEqualTo(
-                        SliceBuilderUtils.getContentPendingIntent(context, sliceData));
-                break;
-        }
+        assertThat(primaryPendingIntent).isEqualTo(SliceBuilderUtils.getContentPendingIntent(
+                context, sliceData));
 
         final List<SliceItem> sliceItems = slice.getItems();
         assertTitle(sliceItems, sliceData.getTitle());
diff --git a/tests/robotests/src/com/android/settings/widget/TwoStateButtonPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/widget/TwoStateButtonPreferenceTest.java
similarity index 60%
rename from tests/robotests/src/com/android/settings/widget/TwoStateButtonPreferenceControllerTest.java
rename to tests/robotests/src/com/android/settings/widget/TwoStateButtonPreferenceTest.java
index d6df25d..c88e7f8 100644
--- a/tests/robotests/src/com/android/settings/widget/TwoStateButtonPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/widget/TwoStateButtonPreferenceTest.java
@@ -17,34 +17,27 @@
 package com.android.settings.widget;
 
 import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
 
 import android.content.Context;
-import android.support.v7.preference.PreferenceScreen;
 import android.view.View;
 import android.widget.Button;
 
+import com.android.settings.R;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.RuntimeEnvironment;
+import org.robolectric.util.ReflectionHelpers;
 
 @RunWith(SettingsRobolectricTestRunner.class)
-public class TwoStateButtonPreferenceControllerTest {
+public class TwoStateButtonPreferenceTest {
 
-    private static final String KEY = "pref_key";
-
-    @Mock
-    private PreferenceScreen mPreferenceScreen;
-    @Mock
     private TwoStateButtonPreference mPreference;
-    private TwoStateButtonPreferenceController mController;
     private Context mContext;
     private Button mButtonOn;
     private Button mButtonOff;
@@ -53,35 +46,34 @@
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         mContext = spy(RuntimeEnvironment.application);
-        doReturn(mPreference).when(mPreferenceScreen).findPreference(anyString());
+        mPreference = spy(new TwoStateButtonPreference(mContext, null /* AttributeSet */));
         mButtonOn = new Button(mContext);
-        doReturn(mButtonOn).when(mPreference).getStateOnButton();
+        mButtonOn.setId(R.id.state_on_button);
         mButtonOff = new Button(mContext);
-        doReturn(mButtonOff).when(mPreference).getStateOffButton();
-
-        mController = new TestButtonsPreferenceController(mContext, KEY);
-        mController.displayPreference(mPreferenceScreen);
+        mButtonOff.setId(R.id.state_off_button);
+        ReflectionHelpers.setField(mPreference, "mButtonOn", mButtonOn);
+        ReflectionHelpers.setField(mPreference, "mButtonOff", mButtonOff);
     }
 
     @Test
     public void testSetButtonVisibility_stateOn_onlyShowButtonOn() {
-        mController.setButtonVisibility(true /* stateOn */);
-
-        assertThat(mButtonOn.getVisibility()).isEqualTo(View.VISIBLE);
-        assertThat(mButtonOff.getVisibility()).isEqualTo(View.GONE);
-    }
-
-    @Test
-    public void testSetButtonVisibility_stateOff_onlyShowButtonOff() {
-        mController.setButtonVisibility(false /* stateOn */);
+        mPreference.setChecked(true /* stateOn */);
 
         assertThat(mButtonOn.getVisibility()).isEqualTo(View.GONE);
         assertThat(mButtonOff.getVisibility()).isEqualTo(View.VISIBLE);
     }
 
     @Test
+    public void testSetButtonVisibility_stateOff_onlyShowButtonOff() {
+        mPreference.setChecked(false /* stateOn */);
+
+        assertThat(mButtonOn.getVisibility()).isEqualTo(View.VISIBLE);
+        assertThat(mButtonOff.getVisibility()).isEqualTo(View.GONE);
+    }
+
+    @Test
     public void testSetButtonEnabled_enabled_buttonEnabled() {
-        mController.setButtonEnabled(true /* enabled */);
+        mPreference.setButtonEnabled(true /* enabled */);
 
         assertThat(mButtonOn.isEnabled()).isTrue();
         assertThat(mButtonOff.isEnabled()).isTrue();
@@ -89,30 +81,18 @@
 
     @Test
     public void testSetButtonEnabled_disabled_buttonDisabled() {
-        mController.setButtonEnabled(false /* enabled */);
+        mPreference.setButtonEnabled(false /* enabled */);
 
         assertThat(mButtonOn.isEnabled()).isFalse();
         assertThat(mButtonOff.isEnabled()).isFalse();
     }
 
-    /**
-     * Controller to test methods in {@link TwoStateButtonPreferenceController}
-     */
-    public static class TestButtonsPreferenceController
-        extends TwoStateButtonPreferenceController {
+    @Test
+    public void onClick_shouldPropagateChangeToListener() {
+        mPreference.onClick(mButtonOn);
+        verify(mPreference).callChangeListener(true);
 
-        TestButtonsPreferenceController(Context context, String key) {
-            super(context, key);
-        }
-
-        @Override
-        public void onButtonClicked(boolean stateOn) {
-            //do nothing
-        }
-
-        @Override
-        public int getAvailabilityStatus() {
-            return AVAILABLE;
-        }
+        mPreference.onClick(mButtonOff);
+        verify(mPreference).callChangeListener(false);
     }
 }
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java
index ddbc851..43e87d8 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java
@@ -259,26 +259,13 @@
     }
 
     @Test
-    public void hiddenView_isDisabledWhenAppropriate() {
-        View hiddenSpinner = mView.findViewById(R.id.hidden_settings);
-        assertThat(hiddenSpinner.isEnabled()).isFalse();
+    public void hiddenField_visibilityUpdatesCorrectly() {
+        View hiddenField = mView.findViewById(R.id.hidden_settings_field);
+        assertThat(hiddenField.getVisibility()).isEqualTo(View.GONE);
 
         mController = new TestWifiConfigController(mConfigUiBase, mView, null /* accessPoint */,
                 WifiConfigUiBase.MODE_CONNECT);
-        assertThat(hiddenSpinner.isEnabled()).isTrue();
-    }
-
-
-    @Test
-    public void hiddenSpinner_visibilityUpdatesCorrectly() {
-        View hiddenSpinner = mView.findViewById(R.id.hidden_settings);
-        assertThat(hiddenSpinner.isEnabled()).isFalse();
-        assertThat(hiddenSpinner.getVisibility()).isEqualTo(View.GONE);
-
-        mController = new TestWifiConfigController(mConfigUiBase, mView, null /* accessPoint */,
-                WifiConfigUiBase.MODE_CONNECT);
-        assertThat(hiddenSpinner.isEnabled()).isTrue();
-        assertThat(hiddenSpinner.getVisibility()).isEqualTo(View.VISIBLE);
+        assertThat(hiddenField.getVisibility()).isEqualTo(View.VISIBLE);
     }
 
     public class TestWifiConfigController extends WifiConfigController {
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiSliceBuilderTest.java b/tests/robotests/src/com/android/settings/wifi/WifiSliceBuilderTest.java
index 865785f..605a661 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiSliceBuilderTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiSliceBuilderTest.java
@@ -26,7 +26,6 @@
 import android.content.Context;
 
 import com.android.settings.R;
-import com.android.settings.wifi.WifiSliceBuilder;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
 import com.android.settings.testutils.SliceTester;
 
diff --git a/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSliceHelperTest.java b/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSliceHelperTest.java
index ac3ff3f..21f6daa 100644
--- a/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSliceHelperTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSliceHelperTest.java
@@ -114,7 +114,7 @@
         final Slice slice = mWfcSliceHelper.createWifiCallingSlice(mWfcURI);
 
         testWifiCallingSettingsUnavailableSlice(slice, null,
-                SliceBuilderUtils.getSettingsIntent(mContext));
+                WifiCallingSliceHelper.getSettingsIntent(mContext));
     }
 
     @Test
@@ -125,7 +125,7 @@
 
         assertThat(mWfcSliceHelper.getDefaultVoiceSubId()).isEqualTo(1);
         testWifiCallingSettingsUnavailableSlice(slice, null,
-                SliceBuilderUtils.getSettingsIntent(mContext));
+                WifiCallingSliceHelper.getSettingsIntent(mContext));
     }
 
     @Test