Merge "[NFC] Disable contactless payments when no payment application installed" into rvc-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 07bc06c..b494d35 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -3107,6 +3107,19 @@
                        android:value="true"/>
         </service>
 
+        <service
+            android:name=".development.qstile.DevelopmentTiles$WirelessDebugging"
+            android:label="@string/enable_adb_wireless"
+            android:icon="@drawable/tile_icon_debugging_wireless"
+            android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
+            android:enabled="false">
+            <intent-filter>
+                <action android:name="android.service.quicksettings.action.QS_TILE" />
+            </intent-filter>
+            <meta-data android:name="android.service.quicksettings.TOGGLEABLE_TILE"
+                       android:value="true"/>
+        </service>
+
         <activity
             android:name=".HelpTrampoline"
             android:exported="true"
diff --git a/res/drawable/tile_icon_debugging_wireless.xml b/res/drawable/tile_icon_debugging_wireless.xml
new file mode 100644
index 0000000..4f0f56c
--- /dev/null
+++ b/res/drawable/tile_icon_debugging_wireless.xml
@@ -0,0 +1,28 @@
+<!--
+    Copyright (C) 2020 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.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="24dp"
+    android:height="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24"
+    android:tint="?android:attr/colorControlNormal">
+  <path
+      android:fillColor="#FFFFFFFF"
+      android:pathData="M19,10.3L19,16A7,7 0,0 1,5 16L5,10.3ZM7.5,14.5l0.8,0.8a5.3,5.3 0,0 1,7.4 0l0.8,-0.8A6.3,6.3 0,0 0,7.5 14.5ZM10.8,17.8L12,19l1.2,-1.2A1.6,1.6 0,0 0,10.8 17.8ZM9.1,16.1l0.9,0.9a2.7,2.7 0,0 1,4 0l0.9,-0.9A4.3,4.3 0,0 0,9.1 16.1Z"/>
+  <path
+      android:fillColor="#FFFFFFFF"
+      android:pathData="M15.6,3.9l1.1,-2c0.1,-0.2 0.1,-0.4 -0.1,-0.5a0.5,0.5 0,0 0,-0.6 0.1L14.8,3.6a6.8,6.8 0,0 0,-5.6 0L8,1.5a0.5,0.5 0,0 0,-0.6 -0.1c-0.2,0.1 -0.2,0.3 -0.1,0.5l1.1,2A7.1,7.1 0,0 0,5 9.3L19,9.3A7.1,7.1 0,0 0,15.6 3.9ZM8.8,7.6A0.9,0.9 0,0 1,8 6.8,0.9 0.9,0 0,1 8.8,6a0.8,0.8 0,1 1,0 1.6ZM15.2,7.6a0.8,0.8 0,1 1,0 -1.6,0.9 0.9,0 0,1 0.8,0.8A0.9,0.9 0,0 1,15.2 7.6Z"/>
+</vector>
diff --git a/res/layout/zen_mode_settings_button.xml b/res/layout/zen_mode_settings_button.xml
index 291e319..f234a89 100644
--- a/res/layout/zen_mode_settings_button.xml
+++ b/res/layout/zen_mode_settings_button.xml
@@ -27,12 +27,14 @@
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginStart="@dimen/screen_margin_sides"
+        android:layout_marginEnd="@dimen/description_margin_sides"
         android:layout_marginTop="@dimen/zen_mode_settings_button_margin_vertical"/>
 
     <Button
         android:id="@+id/zen_mode_settings_turn_on_button"
         style="@style/ActionPrimaryButton"
         android:layout_marginStart="@dimen/screen_margin_sides"
+        android:layout_marginEnd="@dimen/description_margin_sides"
         android:layout_marginTop="@dimen/zen_mode_settings_button_margin_vertical"
         android:layout_marginBottom="@dimen/zen_mode_settings_button_margin_vertical"
         android:text="@string/zen_mode_button_turn_on"
@@ -44,6 +46,7 @@
         android:id="@+id/zen_mode_settings_turn_off_button"
         style="@style/ActionSecondaryButton"
         android:layout_marginStart="@dimen/screen_margin_sides"
+        android:layout_marginEnd="@dimen/description_margin_sides"
         android:layout_marginTop="@dimen/zen_mode_settings_button_margin_vertical"
         android:layout_marginBottom="@dimen/zen_mode_settings_button_margin_vertical"
         android:text="@string/zen_mode_button_turn_off"
diff --git a/src/com/android/settings/accessibility/AccessibilityControlTimeoutPreferenceFragment.java b/src/com/android/settings/accessibility/AccessibilityControlTimeoutPreferenceFragment.java
index 0550908..1e2a2b4 100644
--- a/src/com/android/settings/accessibility/AccessibilityControlTimeoutPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/AccessibilityControlTimeoutPreferenceFragment.java
@@ -32,7 +32,8 @@
 import java.util.ArrayList;
 import java.util.List;
 
-@SearchIndexable
+/** Settings fragment containing accessibility control timeout preference. */
+@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
 public final class AccessibilityControlTimeoutPreferenceFragment extends DashboardFragment
         implements AccessibilityTimeoutController.OnChangeListener {
 
diff --git a/src/com/android/settings/accessibility/AccessibilitySettings.java b/src/com/android/settings/accessibility/AccessibilitySettings.java
index 1e3944e..3b3c2c5 100644
--- a/src/com/android/settings/accessibility/AccessibilitySettings.java
+++ b/src/com/android/settings/accessibility/AccessibilitySettings.java
@@ -65,10 +65,8 @@
 import java.util.Map;
 import java.util.Set;
 
-/**
- * Activity with the accessibility settings.
- */
-@SearchIndexable
+/** Activity with the accessibility settings. */
+@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
 public class AccessibilitySettings extends DashboardFragment {
 
     private static final String TAG = "AccessibilitySettings";
diff --git a/src/com/android/settings/accessibility/CaptionAppearanceFragment.java b/src/com/android/settings/accessibility/CaptionAppearanceFragment.java
index 6c2b593..d780ac5 100644
--- a/src/com/android/settings/accessibility/CaptionAppearanceFragment.java
+++ b/src/com/android/settings/accessibility/CaptionAppearanceFragment.java
@@ -44,10 +44,8 @@
 import java.util.List;
 import java.util.Locale;
 
-/**
- * Settings fragment containing font style of captioning properties.
- */
-@SearchIndexable
+/** Settings fragment containing font style of captioning properties. */
+@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
 public class CaptionAppearanceFragment extends SettingsPreferenceFragment
         implements OnPreferenceChangeListener, OnValueChangedListener {
     private static final String PREF_CAPTION_PREVIEW = "caption_preview";
diff --git a/src/com/android/settings/accessibility/CaptionMoreOptionsFragment.java b/src/com/android/settings/accessibility/CaptionMoreOptionsFragment.java
index d3fd407..8ac82e5 100644
--- a/src/com/android/settings/accessibility/CaptionMoreOptionsFragment.java
+++ b/src/com/android/settings/accessibility/CaptionMoreOptionsFragment.java
@@ -30,10 +30,8 @@
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settingslib.search.SearchIndexable;
 
-/**
- * Settings fragment containing more options of captioning properties.
- */
-@SearchIndexable
+/** Settings fragment containing more options of captioning properties. */
+@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
 public class CaptionMoreOptionsFragment extends SettingsPreferenceFragment
         implements Preference.OnPreferenceChangeListener {
     private static final String PREF_LOCALE = "captioning_locale";
diff --git a/src/com/android/settings/accessibility/CaptionPropertiesFragment.java b/src/com/android/settings/accessibility/CaptionPropertiesFragment.java
index 43539fd..40eb2cd 100644
--- a/src/com/android/settings/accessibility/CaptionPropertiesFragment.java
+++ b/src/com/android/settings/accessibility/CaptionPropertiesFragment.java
@@ -37,10 +37,8 @@
 import java.util.ArrayList;
 import java.util.List;
 
-/**
- * Settings fragment containing captioning properties.
- */
-@SearchIndexable
+/** Settings fragment containing captioning properties. */
+@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
 public class CaptionPropertiesFragment extends SettingsPreferenceFragment
         implements OnPreferenceChangeListener {
     private static final String PREF_SWITCH = "captioning_preference_switch";
diff --git a/src/com/android/settings/accessibility/MagnificationPreferenceFragment.java b/src/com/android/settings/accessibility/MagnificationPreferenceFragment.java
index 4c7d2a4..0e6d3be 100644
--- a/src/com/android/settings/accessibility/MagnificationPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/MagnificationPreferenceFragment.java
@@ -39,12 +39,11 @@
 
 import java.util.List;
 
-@SearchIndexable
+/** Settings fragment containing magnification preference. */
+@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
 public final class MagnificationPreferenceFragment extends DashboardFragment {
-    @VisibleForTesting
-    static final int ON = 1;
-    @VisibleForTesting
-    static final int OFF = 0;
+    @VisibleForTesting static final int ON = 1;
+    @VisibleForTesting static final int OFF = 0;
 
     private static final String TAG = "MagnificationPreferenceFragment";
 
@@ -169,4 +168,4 @@
                     return isApplicable(context.getResources());
                 }
             };
-}
\ No newline at end of file
+}
diff --git a/src/com/android/settings/accessibility/MagnificationSettingsFragment.java b/src/com/android/settings/accessibility/MagnificationSettingsFragment.java
index 0e766b4..04e8036 100644
--- a/src/com/android/settings/accessibility/MagnificationSettingsFragment.java
+++ b/src/com/android/settings/accessibility/MagnificationSettingsFragment.java
@@ -40,7 +40,7 @@
 import java.lang.annotation.RetentionPolicy;
 
 /** Settings page for magnification. */
-@SearchIndexable
+@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
 public class MagnificationSettingsFragment extends DashboardFragment {
 
     private static final String TAG = "MagnificationSettingsFragment";
diff --git a/src/com/android/settings/accessibility/ToggleAutoclickPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleAutoclickPreferenceFragment.java
index 6624457..11fe80e 100644
--- a/src/com/android/settings/accessibility/ToggleAutoclickPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleAutoclickPreferenceFragment.java
@@ -43,7 +43,7 @@
  * Fragment for preference screen for settings related to Automatically click after mouse stops
  * feature.
  */
-@SearchIndexable
+@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
 public class ToggleAutoclickPreferenceFragment extends DashboardFragment
         implements ToggleAutoclickPreferenceController.OnChangeListener {
 
diff --git a/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java
index 833c9f1..07ff720 100644
--- a/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java
@@ -39,7 +39,7 @@
 import java.util.List;
 
 /** Settings page for color inversion. */
-@SearchIndexable
+@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
 public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePreferenceFragment {
 
     private static final String ENABLED = Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED;
diff --git a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
index 9b8b117..5b9c55b 100644
--- a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
@@ -44,7 +44,8 @@
 import java.util.ArrayList;
 import java.util.List;
 
-@SearchIndexable
+/** Settings for daltonizer. */
+@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
 public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePreferenceFragment
         implements DaltonizerRadioButtonPreferenceController.OnChangeListener {
 
diff --git a/src/com/android/settings/accessibility/VibrationSettings.java b/src/com/android/settings/accessibility/VibrationSettings.java
index cfa70b6..90ee11c 100644
--- a/src/com/android/settings/accessibility/VibrationSettings.java
+++ b/src/com/android/settings/accessibility/VibrationSettings.java
@@ -23,10 +23,8 @@
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settingslib.search.SearchIndexable;
 
-/**
- * Accessibility settings for the vibration.
- */
-@SearchIndexable
+/** Accessibility settings for the vibration. */
+@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
 public class VibrationSettings extends DashboardFragment {
 
     private static final String TAG = "VibrationSettings";
diff --git a/src/com/android/settings/connecteddevice/BluetoothDashboardFragment.java b/src/com/android/settings/connecteddevice/BluetoothDashboardFragment.java
index 27b5c4a..3e64de5 100644
--- a/src/com/android/settings/connecteddevice/BluetoothDashboardFragment.java
+++ b/src/com/android/settings/connecteddevice/BluetoothDashboardFragment.java
@@ -35,7 +35,7 @@
  * Dedicated screen for allowing the user to toggle bluetooth which displays relevant information to
  * the user based on related settings such as bluetooth scanning.
  */
-@SearchIndexable(forTarget = SearchIndexable.ALL)
+@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
 public class BluetoothDashboardFragment extends DashboardFragment {
 
     private static final String TAG = "BluetoothDashboardFrag";
diff --git a/src/com/android/settings/development/WirelessDebuggingPreferenceController.java b/src/com/android/settings/development/WirelessDebuggingPreferenceController.java
index 55fd074..a3daede 100644
--- a/src/com/android/settings/development/WirelessDebuggingPreferenceController.java
+++ b/src/com/android/settings/development/WirelessDebuggingPreferenceController.java
@@ -135,7 +135,10 @@
         ((MasterSwitchPreference) preference).setChecked(enabled);
     }
 
-    static boolean isWifiConnected(Context context) {
+    /**
+     * Returns true if connected to Wi-Fi network.
+     */
+    public static boolean isWifiConnected(Context context) {
         ConnectivityManager cm = (ConnectivityManager) context.getSystemService(
                 Context.CONNECTIVITY_SERVICE);
         if (cm != null) {
diff --git a/src/com/android/settings/development/qstile/DevelopmentTiles.java b/src/com/android/settings/development/qstile/DevelopmentTiles.java
index 8f06750..916c6c9 100644
--- a/src/com/android/settings/development/qstile/DevelopmentTiles.java
+++ b/src/com/android/settings/development/qstile/DevelopmentTiles.java
@@ -16,13 +16,21 @@
 
 package com.android.settings.development.qstile;
 
+import static com.android.settings.development.AdbPreferenceController.ADB_SETTING_OFF;
+import static com.android.settings.development.AdbPreferenceController.ADB_SETTING_ON;
+
+import android.app.KeyguardManager;
 import android.app.settings.SettingsEnums;
 import android.content.ComponentName;
 import android.content.Context;
+import android.content.Intent;
 import android.content.pm.PackageManager;
+import android.database.ContentObserver;
 import android.hardware.SensorPrivacyManager;
-import android.app.KeyguardManager;
+import android.net.Uri;
+import android.os.Handler;
 import android.os.IBinder;
+import android.os.Looper;
 import android.os.Parcel;
 import android.os.RemoteException;
 import android.os.ServiceManager;
@@ -41,6 +49,8 @@
 
 import com.android.internal.app.LocalePicker;
 import com.android.internal.statusbar.IStatusBarService;
+import com.android.settings.R;
+import com.android.settings.development.WirelessDebuggingPreferenceController;
 import com.android.settings.overlay.FeatureFactory;
 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
 import com.android.settingslib.development.DevelopmentSettingsEnabler;
@@ -349,4 +359,77 @@
             mSensorPrivacyManager.setSensorPrivacy(isEnabled);
         }
     }
+
+    /**
+     * Tile to control the "Wireless debugging" developer setting
+     */
+    public static class WirelessDebugging extends DevelopmentTiles {
+        private Context mContext;
+        private KeyguardManager mKeyguardManager;
+        private Toast mToast;
+        private final Handler mHandler = new Handler(Looper.getMainLooper());
+        private final ContentObserver mSettingsObserver = new ContentObserver(mHandler) {
+            @Override
+            public void onChange(boolean selfChange, Uri uri) {
+                refresh();
+            }
+        };
+
+        @Override
+        public void onCreate() {
+            super.onCreate();
+            mContext = getApplicationContext();
+            mKeyguardManager = (KeyguardManager) mContext.getSystemService(
+                    Context.KEYGUARD_SERVICE);
+            mToast = Toast.makeText(mContext, R.string.adb_wireless_no_network_msg,
+                    Toast.LENGTH_LONG);
+        }
+
+        @Override
+        public void onStartListening() {
+            super.onStartListening();
+            getContentResolver().registerContentObserver(
+                    Settings.Global.getUriFor(Settings.Global.ADB_WIFI_ENABLED), false,
+                    mSettingsObserver);
+        }
+
+        @Override
+        public void onStopListening() {
+            super.onStopListening();
+            getContentResolver().unregisterContentObserver(mSettingsObserver);
+        }
+
+        @Override
+        protected boolean isEnabled() {
+            return isAdbWifiEnabled();
+        }
+
+        @Override
+        public void setIsEnabled(boolean isEnabled) {
+            // Don't allow Wireless Debugging to be enabled from the lock screen.
+            if (isEnabled && mKeyguardManager.isKeyguardLocked()) {
+                return;
+            }
+
+            // Show error toast if not connected to Wi-Fi
+            if (isEnabled && !WirelessDebuggingPreferenceController.isWifiConnected(mContext)) {
+                // Close quick shade
+                sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
+                mToast.show();
+                return;
+            }
+
+            writeAdbWifiSetting(isEnabled);
+        }
+
+        private boolean isAdbWifiEnabled() {
+            return Settings.Global.getInt(getContentResolver(), Settings.Global.ADB_WIFI_ENABLED,
+                    ADB_SETTING_OFF) != ADB_SETTING_OFF;
+        }
+
+        protected void writeAdbWifiSetting(boolean enabled) {
+            Settings.Global.putInt(getContentResolver(), Settings.Global.ADB_WIFI_ENABLED,
+                    enabled ? ADB_SETTING_ON : ADB_SETTING_OFF);
+        }
+    }
 }
diff --git a/src/com/android/settings/system/ResetDashboardFragment.java b/src/com/android/settings/system/ResetDashboardFragment.java
index 5e0ead4..024db14 100644
--- a/src/com/android/settings/system/ResetDashboardFragment.java
+++ b/src/com/android/settings/system/ResetDashboardFragment.java
@@ -18,14 +18,12 @@
 
 import android.app.settings.SettingsEnums;
 import android.content.Context;
-import android.provider.SearchIndexableResource;
 
 import com.android.settings.R;
 import com.android.settings.applications.manageapplications.ResetAppPrefPreferenceController;
 import com.android.settings.dashboard.DashboardFragment;
 import com.android.settings.network.NetworkResetPreferenceController;
 import com.android.settings.search.BaseSearchIndexProvider;
-import com.android.settingslib.search.Indexable;
 import com.android.settingslib.core.AbstractPreferenceController;
 import com.android.settingslib.core.lifecycle.Lifecycle;
 import com.android.settingslib.search.SearchIndexable;
@@ -33,7 +31,8 @@
 import java.util.ArrayList;
 import java.util.List;
 
-@SearchIndexable
+/** Settings fragment containing reset options. */
+@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
 public class ResetDashboardFragment extends DashboardFragment {
 
     private static final String TAG = "ResetDashboardFragment";
diff --git a/tests/robotests/src/com/android/settings/development/qstile/WirelessDebuggingTest.java b/tests/robotests/src/com/android/settings/development/qstile/WirelessDebuggingTest.java
new file mode 100644
index 0000000..9230ca8
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/development/qstile/WirelessDebuggingTest.java
@@ -0,0 +1,220 @@
+/*
+ * Copyright (C) 2020 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.development.qstile;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import android.app.KeyguardManager;
+import android.content.Context;
+import android.content.Intent;
+import android.provider.Settings.Global;
+import android.widget.Toast;
+
+import com.android.settings.testutils.shadow.ShadowWirelessDebuggingPreferenceController;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
+
+@RunWith(RobolectricTestRunner.class)
+@Config(shadows = {ShadowWirelessDebuggingPreferenceController.class})
+public class WirelessDebuggingTest {
+    @Mock
+    private Toast mToast;
+    @Mock
+    private KeyguardManager mKeyguardManager;
+
+    private Context mContext;
+    private DevelopmentTiles.WirelessDebugging mWirelessDebugging;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        mContext = RuntimeEnvironment.application;
+        mWirelessDebugging = spy(new DevelopmentTiles.WirelessDebugging());
+        doReturn(mContext.getContentResolver()).when(mWirelessDebugging).getContentResolver();
+        ReflectionHelpers.setField(mWirelessDebugging, "mKeyguardManager", mKeyguardManager);
+        ReflectionHelpers.setField(mWirelessDebugging, "mToast", mToast);
+    }
+
+    @After
+    public void tearDown() {
+        ShadowWirelessDebuggingPreferenceController.reset();
+    }
+
+    @Test
+    public void adbWifiEnabled_shouldReturnEnabled() {
+        Global.putInt(mContext.getContentResolver(),
+                Global.ADB_WIFI_ENABLED, 1 /* setting enabled */);
+
+        assertThat(mWirelessDebugging.isEnabled()).isTrue();
+    }
+
+    @Test
+    public void adbWifiDisabled_shouldReturnDisabled() {
+        Global.putInt(mContext.getContentResolver(),
+                Global.ADB_WIFI_ENABLED, 0 /* setting disabled */);
+
+        assertThat(mWirelessDebugging.isEnabled()).isFalse();
+    }
+
+    @Test
+    public void setIsEnabled_false_keyguardUnlocked_WifiDisconnected_shouldDisableAdbWifi() {
+        // Precondition: set the tile to enabled
+        Global.putInt(mContext.getContentResolver(),
+                Global.ADB_WIFI_ENABLED, 1 /* setting enabled */);
+        // Unlocked keyguard
+        doReturn(false).when(mKeyguardManager).isKeyguardLocked();
+        // Wifi disconnected
+        ShadowWirelessDebuggingPreferenceController.setIsWifiConnected(false);
+
+        mWirelessDebugging.setIsEnabled(false);
+
+        assertThat(mWirelessDebugging.isEnabled()).isFalse();
+    }
+
+    @Test
+    public void setIsEnabled_false_keyguardLocked_WifiDisconnected_shouldDisableAdbWifi() {
+        // Precondition: set the tile to enabled
+        Global.putInt(mContext.getContentResolver(),
+                Global.ADB_WIFI_ENABLED, 1 /* setting enabled */);
+        // Locked keyguard
+        doReturn(true).when(mKeyguardManager).isKeyguardLocked();
+        // Wifi disconnected
+        ShadowWirelessDebuggingPreferenceController.setIsWifiConnected(false);
+
+        mWirelessDebugging.setIsEnabled(false);
+
+        assertThat(mWirelessDebugging.isEnabled()).isFalse();
+    }
+
+    @Test
+    public void setIsEnabled_false_keyguardUnlocked_WifiConnected_shouldDisableAdbWifi() {
+        // Precondition: set the tile to enabled
+        Global.putInt(mContext.getContentResolver(),
+                Global.ADB_WIFI_ENABLED, 1 /* setting enabled */);
+        // Unlocked keyguard
+        doReturn(false).when(mKeyguardManager).isKeyguardLocked();
+        // Wifi connected
+        ShadowWirelessDebuggingPreferenceController.setIsWifiConnected(true);
+
+        mWirelessDebugging.setIsEnabled(false);
+
+        assertThat(mWirelessDebugging.isEnabled()).isFalse();
+    }
+
+    @Test
+    public void setIsEnabled_false_keyguardLocked_WifiConnected_shouldDisableAdbWifi() {
+        // Precondition: set the tile to enabled
+        Global.putInt(mContext.getContentResolver(),
+                Global.ADB_WIFI_ENABLED, 1 /* setting enabled */);
+        // Locked keyguard
+        doReturn(true).when(mKeyguardManager).isKeyguardLocked();
+        // Wifi connected
+        ShadowWirelessDebuggingPreferenceController.setIsWifiConnected(true);
+
+        mWirelessDebugging.setIsEnabled(false);
+
+        assertThat(mWirelessDebugging.isEnabled()).isFalse();
+    }
+
+    @Test
+    public void setIsEnabled_true_keyguardUnlocked_WifiDisconnected_shouldDisableAdbWifi() {
+        ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
+        doNothing().when(mWirelessDebugging).sendBroadcast(intentCaptor.capture());
+        // Precondition: set the tile to disabled
+        Global.putInt(mContext.getContentResolver(),
+                Global.ADB_WIFI_ENABLED, 0 /* setting enabled */);
+        // Unlocked keyguard
+        doReturn(false).when(mKeyguardManager).isKeyguardLocked();
+        // Wifi disconnected
+        ShadowWirelessDebuggingPreferenceController.setIsWifiConnected(false);
+
+        mWirelessDebugging.setIsEnabled(true);
+
+        assertThat(mWirelessDebugging.isEnabled()).isFalse();
+        // The notification shade should be hidden by sending a broadcast to SysUI
+        // so the toast can be seen
+        verify(mWirelessDebugging, times(1)).sendBroadcast(eq(intentCaptor.getValue()));
+        assertThat(intentCaptor.getValue().getAction())
+            .isEqualTo(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
+        // Should also get a toast that wifi is not connected
+        verify(mToast).show();
+    }
+
+    @Test
+    public void setIsEnabled_true_keyguardLocked_WifiDisconnected_shouldDisableAdbWifi() {
+        // Precondition: set the tile to disabled
+        Global.putInt(mContext.getContentResolver(),
+                Global.ADB_WIFI_ENABLED, 0 /* setting enabled */);
+        // Locked keyguard
+        doReturn(true).when(mKeyguardManager).isKeyguardLocked();
+        // Wifi disconnected
+        ShadowWirelessDebuggingPreferenceController.setIsWifiConnected(false);
+
+        mWirelessDebugging.setIsEnabled(true);
+
+        // Shouldn't be able to enable wireless debugging from locked screen
+        assertThat(mWirelessDebugging.isEnabled()).isFalse();
+    }
+
+    @Test
+    public void setIsEnabled_true_keyguardUnlocked_WifiConnected_shouldDisableAdbWifi() {
+        // Precondition: set the tile to disabled
+        Global.putInt(mContext.getContentResolver(),
+                Global.ADB_WIFI_ENABLED, 0 /* setting enabled */);
+        // Unlocked keyguard
+        doReturn(false).when(mKeyguardManager).isKeyguardLocked();
+        // Wifi connected
+        ShadowWirelessDebuggingPreferenceController.setIsWifiConnected(true);
+
+        mWirelessDebugging.setIsEnabled(true);
+
+        assertThat(mWirelessDebugging.isEnabled()).isTrue();
+    }
+
+    @Test
+    public void setIsEnabled_true_keyguardLocked_WifiConnected_shouldDisableAdbWifi() {
+        // Precondition: set the tile to disabled
+        Global.putInt(mContext.getContentResolver(),
+                Global.ADB_WIFI_ENABLED, 0 /* setting enabled */);
+        // Locked keyguard
+        doReturn(true).when(mKeyguardManager).isKeyguardLocked();
+        // Wifi connected
+        ShadowWirelessDebuggingPreferenceController.setIsWifiConnected(true);
+
+        mWirelessDebugging.setIsEnabled(true);
+
+        // Shouldn't be able to enable wireless debugging from locked screen
+        assertThat(mWirelessDebugging.isEnabled()).isFalse();
+    }
+}