Merge "Add DnD as a special case Slice" into pi-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 5dd22c2..74a18ea 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -3137,6 +3137,8 @@
                        android:value="com.android.settings.accounts.AccountDashboardFragment"/>
             <meta-data android:name="com.android.settings.category"
                        android:value="com.android.settings.category.ia.homepage"/>
+            <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
+                       android:value="true" />
         </activity>
 
         <activity
diff --git a/res/layout/condition_header.xml b/res/layout/condition_header.xml
index 2551b65..f214319 100644
--- a/res/layout/condition_header.xml
+++ b/res/layout/condition_header.xml
@@ -71,7 +71,7 @@
             android:singleLine="true"
             android:ellipsize="end"
             android:textAppearance="@style/TextAppearance.SuggestionTitle"
-            android:textColor="?android:attr/colorAccent" />
+            android:textColor="?android:attr/textColorPrimary" />
 
         <LinearLayout
             android:id="@+id/additional_icons"
diff --git a/res/layout/ownerinfo.xml b/res/layout/ownerinfo.xml
index c5eaff5..29e0840 100644
--- a/res/layout/ownerinfo.xml
+++ b/res/layout/ownerinfo.xml
@@ -25,6 +25,7 @@
         android:id="@+id/owner_info_edit_text"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:minHeight="@dimen/min_tap_target_size"
         android:gravity="top"
         android:hint="@string/owner_info_settings_edit_text_hint"
         android:inputType="textMultiLine|textCapSentences"
diff --git a/res/layout/wifi_dialog.xml b/res/layout/wifi_dialog.xml
index 16c8c22..fe891e1 100644
--- a/res/layout/wifi_dialog.xml
+++ b/res/layout/wifi_dialog.xml
@@ -291,7 +291,6 @@
                         android:layout_width="match_parent"
                         android:layout_height="wrap_content"
                         style="@style/wifi_item_content"
-                        android:textSize="14sp"
                         android:text="@string/wifi_show_password" />
             </LinearLayout>
         </LinearLayout>
diff --git a/res/values/config.xml b/res/values/config.xml
index e3ec74f..e204b7f 100755
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -131,4 +131,7 @@
     <!-- List of a11y components on the device allowed to be enabled by Settings Slices -->
     <string-array name="config_settings_slices_accessibility_components" translatable="false"/>
 
+    <!-- Whether or not to show the night light suggestion. -->
+    <bool name="config_night_light_suggestion_enabled">true</bool>
+
 </resources>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 763d8fa..8052616 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -200,6 +200,7 @@
         <item name="android:textAlignment">viewStart</item>
         <item name="android:textAppearance">@android:style/TextAppearance.Material.Subhead</item>
         <item name="android:textColor">?android:attr/textColorPrimary</item>
+        <item name="android:minHeight">@dimen/min_tap_target_size</item>
     </style>
 
     <style name="wifi_item_spinner" parent="wifi_item_content">
@@ -219,6 +220,7 @@
         <item name="android:layout_marginStart">4dip</item>
         <item name="android:textSize">18sp</item>
         <item name="android:textAlignment">viewStart</item>
+        <item name="android:minHeight">@dimen/min_tap_target_size</item>
     </style>
 
     <style name="wifi_section">
@@ -285,6 +287,7 @@
         <item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
         <item name="android:singleLine">true</item>
         <item name="android:textAlignment">viewStart</item>
+        <item name="android:minHeight">@dimen/min_tap_target_size</item>
     </style>
 
     <style name="vpn_warning">
diff --git a/res/values/themes.xml b/res/values/themes.xml
index 762b434..8c38649 100644
--- a/res/values/themes.xml
+++ b/res/values/themes.xml
@@ -284,6 +284,7 @@
     <style name="Widget.SwitchBar.Switch" parent="@android:style/Widget.Material.CompoundButton.Switch">
         <item name="android:trackTint">@color/switchbar_switch_track_tint</item>
         <item name="android:thumbTint">@color/switchbar_switch_thumb_tint</item>
+        <item name="android:minHeight">@dimen/min_tap_target_size</item>
     </style>
 
     <style name="Theme.CryptKeeper" parent="@android:style/Theme.Material.NoActionBar">
diff --git a/res/xml/connected_devices.xml b/res/xml/connected_devices.xml
index 75f9988..54de927 100644
--- a/res/xml/connected_devices.xml
+++ b/res/xml/connected_devices.xml
@@ -46,7 +46,8 @@
         android:title="@string/connected_device_previously_connected_title"
         android:icon="@drawable/ic_devices_other_black"
         android:fragment="com.android.settings.connecteddevice.PreviouslyConnectedDeviceDashboardFragment"
-        settings:allowDividerAbove="true"/>
+        settings:allowDividerAbove="true"
+        settings:controller="com.android.settings.connecteddevice.PreviouslyConnectedDevicePreferenceController"/>
 
     <Preference
         android:key="connection_preferences"
diff --git a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
index 3dc1437..26ff930 100644
--- a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
+++ b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
@@ -64,6 +64,7 @@
         super.onAttach(context);
         use(AvailableMediaDeviceGroupController.class).init(this);
         use(ConnectedDeviceGroupController.class).init(this);
+        use(PreviouslyConnectedDevicePreferenceController.class).init(this);
     }
 
     @VisibleForTesting
diff --git a/src/com/android/settings/connecteddevice/PreviouslyConnectedDevicePreferenceController.java b/src/com/android/settings/connecteddevice/PreviouslyConnectedDevicePreferenceController.java
new file mode 100644
index 0000000..ba3ee1f
--- /dev/null
+++ b/src/com/android/settings/connecteddevice/PreviouslyConnectedDevicePreferenceController.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright 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.connecteddevice;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.support.annotation.VisibleForTesting;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import android.util.Log;
+import com.android.settings.bluetooth.BluetoothDeviceUpdater;
+import com.android.settings.bluetooth.SavedBluetoothDeviceUpdater;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.dashboard.DashboardFragment;
+
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnStart;
+import com.android.settingslib.core.lifecycle.events.OnStop;
+import com.android.settingslib.utils.ThreadUtils;
+
+public class PreviouslyConnectedDevicePreferenceController extends BasePreferenceController
+        implements LifecycleObserver, OnStart, OnStop, DevicePreferenceCallback {
+
+    private Preference mPreference;
+    private BluetoothDeviceUpdater mBluetoothDeviceUpdater;
+    private int mPreferenceSize;
+
+    public PreviouslyConnectedDevicePreferenceController(Context context, String preferenceKey) {
+        super(context, preferenceKey);
+    }
+
+    @Override
+    public int getAvailabilityStatus() {
+        return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)
+                ? AVAILABLE
+                : CONDITIONALLY_UNAVAILABLE;
+    }
+
+    @Override
+    public void displayPreference(PreferenceScreen screen) {
+        super.displayPreference(screen);
+        if (isAvailable()) {
+            mPreference = screen.findPreference(getPreferenceKey());
+            mBluetoothDeviceUpdater.setPrefContext(screen.getContext());
+        }
+    }
+
+    @Override
+    public void onStart() {
+        mBluetoothDeviceUpdater.registerCallback();
+        updatePreferenceOnSizeChanged();
+    }
+
+    @Override
+    public void onStop() {
+        mBluetoothDeviceUpdater.unregisterCallback();
+    }
+
+    public void init(DashboardFragment fragment) {
+        mBluetoothDeviceUpdater = new SavedBluetoothDeviceUpdater(fragment.getContext(),
+                fragment, PreviouslyConnectedDevicePreferenceController.this);
+    }
+
+    @Override
+    public void onDeviceAdded(Preference preference) {
+        mPreferenceSize++;
+        updatePreferenceOnSizeChanged();
+    }
+
+    @Override
+    public void onDeviceRemoved(Preference preference) {
+        mPreferenceSize--;
+        updatePreferenceOnSizeChanged();
+    }
+
+    @VisibleForTesting
+    void setBluetoothDeviceUpdater(BluetoothDeviceUpdater bluetoothDeviceUpdater) {
+        mBluetoothDeviceUpdater = bluetoothDeviceUpdater;
+    }
+
+    @VisibleForTesting
+    void setPreferenceSize(int size) {
+        mPreferenceSize = size;
+    }
+
+    @VisibleForTesting
+    void setPreference(Preference preference) {
+        mPreference = preference;
+    }
+
+    private void updatePreferenceOnSizeChanged() {
+        if (isAvailable()) {
+            mPreference.setEnabled(mPreferenceSize != 0);
+        }
+    }
+}
\ No newline at end of file
diff --git a/src/com/android/settings/display/NightDisplayPreferenceController.java b/src/com/android/settings/display/NightDisplayPreferenceController.java
index 5e8dfe0..0bbab93 100644
--- a/src/com/android/settings/display/NightDisplayPreferenceController.java
+++ b/src/com/android/settings/display/NightDisplayPreferenceController.java
@@ -18,6 +18,7 @@
 import com.android.internal.app.ColorDisplayController;
 import com.android.settings.core.PreferenceControllerMixin;
 import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settings.R;
 
 public class NightDisplayPreferenceController extends AbstractPreferenceController implements
         PreferenceControllerMixin {
@@ -29,6 +30,12 @@
     }
 
     public static boolean isSuggestionComplete(Context context) {
+        final boolean isEnabled = context.getResources().getBoolean(
+                R.bool.config_night_light_suggestion_enabled);
+        // The suggestion is always complete if not enabled.
+        if (!isEnabled) {
+            return true;
+        }
         final ColorDisplayController controller = new ColorDisplayController(context);
         return controller.getAutoMode() != ColorDisplayController.AUTO_MODE_DISABLED;
     }
diff --git a/src/com/android/settings/search/DeviceIndexFeatureProvider.java b/src/com/android/settings/search/DeviceIndexFeatureProvider.java
index 8e64d79..bf75ee8 100644
--- a/src/com/android/settings/search/DeviceIndexFeatureProvider.java
+++ b/src/com/android/settings/search/DeviceIndexFeatureProvider.java
@@ -24,8 +24,10 @@
 import android.net.Uri;
 import android.os.Build;
 import android.provider.Settings;
+import android.util.Log;
 
 import com.android.settings.R;
+import com.android.settings.Utils;
 import com.android.settings.slices.SettingsSliceProvider;
 
 import java.util.List;
@@ -48,6 +50,12 @@
 
     default void updateIndex(Context context, boolean force) {
         if (!isIndexingEnabled()) {
+            Log.w(TAG, "Skipping: device index is not enabled");
+            return;
+        }
+
+        if (!Utils.isDeviceProvisioned(context)) {
+            Log.w(TAG, "Skipping: device is not provisioned");
             return;
         }
 
diff --git a/src/com/android/settings/slices/SliceDeepLinkSpringBoard.java b/src/com/android/settings/slices/SliceDeepLinkSpringBoard.java
index d02431c..7f1a0f3 100644
--- a/src/com/android/settings/slices/SliceDeepLinkSpringBoard.java
+++ b/src/com/android/settings/slices/SliceDeepLinkSpringBoard.java
@@ -45,7 +45,11 @@
                 // This shouldn't matter since the slice is shown instead of the device
                 // index caring about the launch uri.
                 Uri slice = Uri.parse(intent.getStringExtra(EXTRA_SLICE));
-                Log.e(TAG, "Slice intent launched: " + slice);
+                SlicesDatabaseAccessor slicesDatabaseAccessor = new SlicesDatabaseAccessor(this);
+                // Sadly have to block here because we don't know where to go.
+                final SliceData sliceData = slicesDatabaseAccessor.getSliceDataFromUri(slice);
+                Intent launchIntent = SliceBuilderUtils.getContentIntent(this, sliceData);
+                startActivity(launchIntent);
             } else {
                 startActivity(intent);
             }
diff --git a/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java b/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java
index 1d9d3cd..9764a45 100644
--- a/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java
+++ b/src/com/android/settings/wifi/tether/WifiTetherPreferenceController.java
@@ -44,6 +44,7 @@
     private static final String WIFI_TETHER_SETTINGS = "wifi_tether";
     private static final IntentFilter AIRPLANE_INTENT_FILTER = new IntentFilter(
             Intent.ACTION_AIRPLANE_MODE_CHANGED);
+    private static final int ID_NULL = -1;
 
     private final ConnectivityManager mConnectivityManager;
     private final String[] mWifiRegexs;
@@ -152,7 +153,7 @@
         public void onReceive(Context context, Intent intent) {
             String action = intent.getAction();
             if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(action)) {
-                clearSummaryForAirplaneMode();
+                clearSummaryForAirplaneMode(R.string.wifi_hotspot_off_subtext);
             }
         }
     };
@@ -194,10 +195,16 @@
     }
 
     private void clearSummaryForAirplaneMode() {
+        clearSummaryForAirplaneMode(ID_NULL);
+    }
+
+    private void clearSummaryForAirplaneMode(int defaultId) {
         boolean isAirplaneMode = Settings.Global.getInt(mContext.getContentResolver(),
                 Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
         if (isAirplaneMode) {
             mPreference.setSummary(R.string.wifi_tether_disabled_by_airplane);
+        } else if (defaultId != ID_NULL){
+            mPreference.setSummary(defaultId);
         }
     }
     //
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/PreviouslyConnectedDevicePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/PreviouslyConnectedDevicePreferenceControllerTest.java
new file mode 100644
index 0000000..444728a
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/connecteddevice/PreviouslyConnectedDevicePreferenceControllerTest.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright 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.connecteddevice;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+
+import android.support.v7.preference.Preference;
+
+import com.android.settings.bluetooth.BluetoothDeviceUpdater;
+import com.android.settings.dashboard.DashboardFragment;
+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 static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.*;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class PreviouslyConnectedDevicePreferenceControllerTest {
+
+    private final String KEY = "test_key";
+
+    @Mock
+    private DashboardFragment mDashboardFragment;
+    @Mock
+    private BluetoothDeviceUpdater mBluetoothDeviceUpdater;
+    @Mock
+    private PackageManager mPackageManager;
+
+    private Context mContext;
+    private PreviouslyConnectedDevicePreferenceController mPreConnectedDeviceController;
+    private Preference mPreference;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        mContext = spy(RuntimeEnvironment.application);
+        doReturn(mContext).when(mDashboardFragment).getContext();
+        doReturn(mPackageManager).when(mContext).getPackageManager();
+        mPreConnectedDeviceController =
+                new PreviouslyConnectedDevicePreferenceController(mContext, KEY);
+        mPreConnectedDeviceController.setBluetoothDeviceUpdater(mBluetoothDeviceUpdater);
+
+        mPreference = new Preference(mContext);
+        mPreConnectedDeviceController.setPreference(mPreference);
+    }
+
+    @Test
+    public void callbackCanRegisterAndUnregister() {
+        // register the callback in onStart()
+        mPreConnectedDeviceController.onStart();
+        verify(mBluetoothDeviceUpdater).registerCallback();
+
+        // unregister the callback in onStop()
+        mPreConnectedDeviceController.onStop();
+        verify(mBluetoothDeviceUpdater).unregisterCallback();
+    }
+
+    @Test
+    public void getAvailabilityStatus_noBluetoothFeature_returnUnSupported() {
+        doReturn(false).when(mPackageManager).hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);
+        assertThat(mPreConnectedDeviceController.getAvailabilityStatus()).isEqualTo(
+                CONDITIONALLY_UNAVAILABLE);
+    }
+    @Test
+    public void getAvailabilityStatus_hasBluetoothFeature_returnSupported() {
+        doReturn(true).when(mPackageManager).hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);
+        assertThat(mPreConnectedDeviceController.getAvailabilityStatus()).isEqualTo(
+                AVAILABLE);
+    }
+
+    @Test
+    public void onDeviceAdded_addFirstDevice_preferenceIsEnable() {
+        doReturn(true).when(mPackageManager).hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);
+        mPreConnectedDeviceController.setPreferenceSize(0);
+        mPreConnectedDeviceController.onDeviceAdded(mPreference);
+
+        assertThat(mPreference.isEnabled()).isTrue();
+    }
+
+    @Test
+    public void onDeviceRemoved_removeLastDevice_preferenceIsDisable() {
+        doReturn(true).when(mPackageManager).hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);
+        mPreConnectedDeviceController.setPreferenceSize(1);
+        mPreConnectedDeviceController.onDeviceRemoved(mPreference);
+
+        assertThat(mPreference.isEnabled()).isFalse();
+    }
+}
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 bb68c0d..c62f63d 100644
--- a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java
@@ -163,13 +163,6 @@
     }
 
     @Test
-    public void nightDisplaySuggestion_isNotCompleted_byDefault() {
-        final ComponentName componentName =
-                new ComponentName(mContext, NightDisplaySuggestionActivity.class);
-        assertThat(mProvider.isSuggestionComplete(mContext, componentName)).isFalse();
-    }
-
-    @Test
     public void testGetSmartSuggestionEnabledTaggedData_disabled() {
         assertThat(mProvider.getLoggingTaggedData(mContext)).asList().containsExactly(
                 Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0));
diff --git a/tests/robotests/src/com/android/settings/display/NightDisplayPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/NightDisplayPreferenceControllerTest.java
index 3bc7d52..7440f63 100644
--- a/tests/robotests/src/com/android/settings/display/NightDisplayPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/NightDisplayPreferenceControllerTest.java
@@ -6,15 +6,22 @@
 import android.content.ComponentName;
 import android.provider.Settings.Secure;
 import com.android.internal.app.ColorDisplayController;
+import com.android.settings.R;
 import com.android.settings.Settings.NightDisplaySuggestionActivity;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.SettingsShadowResources;
+
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.robolectric.annotation.Config;
 import org.robolectric.RuntimeEnvironment;
 
 @RunWith(SettingsRobolectricTestRunner.class)
+@Config(shadows = {
+        SettingsShadowResources.class
+})
 public class NightDisplayPreferenceControllerTest {
 
   private NightDisplayPreferenceController mPreferenceController;
@@ -27,6 +34,7 @@
   @After
   public void tearDown() {
     mPreferenceController = null;
+    SettingsShadowResources.reset();
   }
 
   @Test
@@ -58,4 +66,16 @@
         new ComponentName(context, NightDisplaySuggestionActivity.class);
     assertThat(mPreferenceController.isSuggestionComplete(context)).isTrue();
   }
+
+  @Test
+  public void nightDisplaySuggestion_isCompleted_ifDisabled() {
+    final Application context = RuntimeEnvironment.application;
+    Secure.putInt(context.getContentResolver(),
+            Secure.NIGHT_DISPLAY_AUTO_MODE, ColorDisplayController.AUTO_MODE_DISABLED);
+    SettingsShadowResources.overrideResource(R.bool.config_night_light_suggestion_enabled, false);
+
+    final ComponentName componentName =
+            new ComponentName(context, NightDisplaySuggestionActivity.class);
+    assertThat(mPreferenceController.isSuggestionComplete(context)).isTrue();
+  }
 }
diff --git a/tests/robotests/src/com/android/settings/search/DeviceIndexFeatureProviderTest.java b/tests/robotests/src/com/android/settings/search/DeviceIndexFeatureProviderTest.java
index 26c2830..d4c1580 100644
--- a/tests/robotests/src/com/android/settings/search/DeviceIndexFeatureProviderTest.java
+++ b/tests/robotests/src/com/android/settings/search/DeviceIndexFeatureProviderTest.java
@@ -15,7 +15,6 @@
 package com.android.settings.search;
 
 import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.atLeastOnce;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.spy;
@@ -24,6 +23,7 @@
 
 import android.app.Activity;
 import android.app.job.JobScheduler;
+import android.provider.Settings;
 
 import com.android.settings.testutils.FakeFeatureFactory;
 import com.android.settings.testutils.SettingsRobolectricTestRunner;
@@ -47,7 +47,7 @@
     }
 
     @Test
-    public void verifyDisabled() {
+    public void updateIndex_disabled_shouldDoNothing() {
         when(mProvider.isIndexingEnabled()).thenReturn(false);
 
         mProvider.updateIndex(mActivity, false);
@@ -55,7 +55,20 @@
     }
 
     @Test
-    public void verifyIndexing() {
+    public void updateIndex_enabled_unprovisioned_shouldDoNothing() {
+        when(mProvider.isIndexingEnabled()).thenReturn(true);
+        Settings.Global.putInt(mActivity.getContentResolver(),
+                Settings.Global.DEVICE_PROVISIONED, 0);
+
+        mProvider.updateIndex(mActivity, false);
+
+        verify(mProvider, never()).index(any(), any(), any(), any(), any());
+    }
+
+    @Test
+    public void updateIndex_enabled_provisioned_shouldIndex() {
+        Settings.Global.putInt(mActivity.getContentResolver(),
+                Settings.Global.DEVICE_PROVISIONED, 1);
         JobScheduler jobScheduler = mock(JobScheduler.class);
         when(mProvider.isIndexingEnabled()).thenReturn(true);
         when(mActivity.getSystemService(JobScheduler.class)).thenReturn(jobScheduler);
diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java
index b5d0f9d..149cd22 100644
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java
@@ -123,7 +123,7 @@
     }
 
     @Test
-    public void testReceiver_goingToAirplaneMode_shouldClearPreferenceSummary() {
+    public void testReceiver_turnOnAirplaneMode_clearPreferenceSummary() {
         final ContentResolver cr = mock(ContentResolver.class);
         when(mContext.getContentResolver()).thenReturn(cr);
         Settings.Global.putInt(cr, Settings.Global.AIRPLANE_MODE_ON, 1);
@@ -138,6 +138,21 @@
     }
 
     @Test
+    public void testReceiver_turnOffAirplaneMode_displayOffSummary() {
+        final ContentResolver cr = mock(ContentResolver.class);
+        when(mContext.getContentResolver()).thenReturn(cr);
+        Settings.Global.putInt(cr, Settings.Global.AIRPLANE_MODE_ON, 0);
+        mController.displayPreference(mScreen);
+        final BroadcastReceiver receiver = ReflectionHelpers.getField(mController, "mReceiver");
+        final Intent broadcast = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
+
+        receiver.onReceive(RuntimeEnvironment.application, broadcast);
+
+        assertThat(mPreference.getSummary().toString()).isEqualTo(
+                "Not sharing internet or content with other devices");
+    }
+
+    @Test
     public void testHandleWifiApStateChanged_stateEnabling_showEnablingSummary() {
         mController.handleWifiApStateChanged(WifiManager.WIFI_AP_STATE_ENABLING, 0 /* reason */);