Merge "Introduce BugReportPreferenceControllerV2"
diff --git a/res/xml/development_prefs.xml b/res/xml/development_prefs.xml
index dec5482..a49cfff 100644
--- a/res/xml/development_prefs.xml
+++ b/res/xml/development_prefs.xml
@@ -467,6 +467,11 @@
             android:title="@string/force_resizable_activities"
             android:summary="@string/force_resizable_activities_summary"/>
 
+        <SwitchPreference
+                android:key="enable_freeform_support"
+                android:title="@string/enable_freeform_support"
+                android:summary="@string/enable_freeform_support_summary"/>
+
         <Preference
             android:key="reset_shortcut_manager_throttling"
             android:title="@string/reset_shortcut_manager_throttling" />
diff --git a/src/com/android/settings/dashboard/DashboardAdapter.java b/src/com/android/settings/dashboard/DashboardAdapter.java
index 600b23b..9c61873 100644
--- a/src/com/android/settings/dashboard/DashboardAdapter.java
+++ b/src/com/android/settings/dashboard/DashboardAdapter.java
@@ -601,6 +601,9 @@
         }
 
         public Drawable getIcon(Icon icon) {
+            if (icon == null) {
+                return null;
+            }
             Drawable drawable = mMap.get(icon);
             if (drawable == null) {
                 drawable = icon.loadDrawable(mContext);
diff --git a/src/com/android/settings/dashboard/suggestions/SuggestionAdapter.java b/src/com/android/settings/dashboard/suggestions/SuggestionAdapter.java
index 38b9d28..de266e1 100644
--- a/src/com/android/settings/dashboard/suggestions/SuggestionAdapter.java
+++ b/src/com/android/settings/dashboard/suggestions/SuggestionAdapter.java
@@ -96,8 +96,7 @@
         //                  itemView));
         //        } else
         {
-            // TODO: Add icon field in Suggestion, and enable this.
-            //            holder.icon.setImageDrawable(mCache.getIcon(suggestion.icon));
+            holder.icon.setImageDrawable(mCache.getIcon(suggestion.getIcon()));
             holder.title.setText(suggestion.getTitle());
             final CharSequence summary = suggestion.getSummary();
             if (!TextUtils.isEmpty(summary)) {
diff --git a/src/com/android/settings/development/DevelopmentSettings.java b/src/com/android/settings/development/DevelopmentSettings.java
index bd3f33b..980d976 100644
--- a/src/com/android/settings/development/DevelopmentSettings.java
+++ b/src/com/android/settings/development/DevelopmentSettings.java
@@ -167,6 +167,7 @@
     private static final String TETHERING_HARDWARE_OFFLOAD = "tethering_hardware_offload";
     private static final String KEY_COLOR_MODE = "picture_color_mode";
     private static final String FORCE_RESIZABLE_KEY = "force_resizable_activities";
+    private static final String ENABLE_FREEFORM_SUPPORT_KEY = "enable_freeform_support";
     private static final String COLOR_TEMPERATURE_KEY = "color_temperature";
 
     private static final String BLUETOOTH_SHOW_DEVICES_WITHOUT_NAMES_KEY =
@@ -312,6 +313,8 @@
 
     private SwitchPreference mForceResizable;
 
+    private SwitchPreference mEnableFreeformSupport;
+
     private SwitchPreference mColorTemperaturePreference;
 
     private final ArrayList<Preference> mAllPrefs = new ArrayList<>();
@@ -495,6 +498,8 @@
         mSimulateColorSpace = addListPreference(SIMULATE_COLOR_SPACE);
         mUSBAudio = findAndInitSwitchPref(USB_AUDIO_KEY);
         mForceResizable = findAndInitSwitchPref(FORCE_RESIZABLE_KEY);
+        mEnableFreeformSupport = findAndInitSwitchPref(ENABLE_FREEFORM_SUPPORT_KEY);
+        removePreferenceForProduction(mEnableFreeformSupport);
 
         mImmediatelyDestroyActivities = (SwitchPreference) findPreference(
                 IMMEDIATELY_DESTROY_ACTIVITIES_KEY);
@@ -612,7 +617,16 @@
     }
 
     private void removePreference(Preference preference) {
-        getPreferenceScreen().removePreference(preference);
+        if (preference == null) {
+            return;
+        }
+
+        final PreferenceGroup parent = preference.getParent();
+
+        if (parent != null) {
+            parent.removePreference(preference);
+        }
+
         mAllPrefs.remove(preference);
         mResetSwitchPrefs.remove(preference);
     }
@@ -823,6 +837,7 @@
         updateSimulateColorSpace();
         updateUSBAudioOptions();
         updateForceResizableOptions();
+        updateEnableFreeformWindowsSupportOptions();
         Preference webViewAppPref = findPreference(mWebViewAppPrefController.getPreferenceKey());
         mWebViewAppPrefController.updateState(webViewAppPref);
         updateOemUnlockOptions();
@@ -1421,6 +1436,17 @@
                 mForceResizable.isChecked() ? 1 : 0);
     }
 
+    private void updateEnableFreeformWindowsSupportOptions() {
+        updateSwitchPreference(mEnableFreeformSupport, Settings.Global.getInt(getContentResolver(),
+                Settings.Global.DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT, 0) != 0);
+    }
+
+    private void writeEnableFreeformWindowsSupportOptions() {
+        Settings.Global.putInt(getContentResolver(),
+                Settings.Global.DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT,
+                mEnableFreeformSupport.isChecked() ? 1 : 0);
+    }
+
     private void updateForceRtlOptions() {
         updateSwitchPreference(mForceRtlLayout,
                 Settings.Global.getInt(getActivity().getContentResolver(),
@@ -2329,6 +2355,8 @@
             writeUSBAudioOptions();
         } else if (preference == mForceResizable) {
             writeForceResizableOptions();
+        } else if (preference == mEnableFreeformSupport){
+            writeEnableFreeformWindowsSupportOptions();
         } else if (preference == mBluetoothShowDevicesWithoutNames) {
             writeBluetoothShowDevicesWithoutUserFriendlyNameOptions();
         } else if (preference == mBluetoothDisableAbsVolume) {
diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
index e71c500..767c7ca 100644
--- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
+++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
@@ -252,7 +252,7 @@
         controllers.add(new BluetoothSnoopLogPreferenceController(context));
         controllers.add(new OemUnlockPreferenceController(context, activity, fragment));
         // running services
-        // convert to file encryption
+        controllers.add(new FileEncryptionPreferenceController(context));
         controllers.add(new PictureColorModePreferenceController(context, lifecycle));
         controllers.add(new WebViewAppPreferenceControllerV2(context));
         controllers.add(new CoolColorTemperaturePreferenceController(context));
@@ -320,7 +320,7 @@
         // inactive apps
         controllers.add(new AllowAppsOnExternalPreferenceController(context));
         controllers.add(new ResizableActivityPreferenceController(context));
-        // reset shortcutmanager rate-limiting
+        controllers.add(new ShortcutManagerThrottlingPreferenceController(context));
         return controllers;
     }
 
diff --git a/src/com/android/settings/development/FileEncryptionPreferenceController.java b/src/com/android/settings/development/FileEncryptionPreferenceController.java
new file mode 100644
index 0000000..463bb70
--- /dev/null
+++ b/src/com/android/settings/development/FileEncryptionPreferenceController.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.development;
+
+import android.content.Context;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.SystemProperties;
+import android.os.storage.IStorageManager;
+import android.support.annotation.VisibleForTesting;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+import android.text.TextUtils;
+
+import com.android.settings.R;
+
+public class FileEncryptionPreferenceController extends DeveloperOptionsPreferenceController {
+
+    private static final String KEY_CONVERT_FBE = "convert_to_file_encryption";
+    private static final String KEY_STORAGE_MANAGER = "mount";
+
+    @VisibleForTesting
+    static final String FILE_ENCRYPTION_PROPERTY_KEY = "ro.crypto.type";
+
+    private final IStorageManager mStorageManager;
+
+    private Preference mPreference;
+
+    public FileEncryptionPreferenceController(Context context) {
+        super(context);
+
+        mStorageManager = getStorageManager();
+    }
+
+    @Override
+    public boolean isAvailable() {
+        if (mStorageManager == null) {
+            return false;
+        }
+
+        try {
+            return mStorageManager.isConvertibleToFBE();
+        } catch (RemoteException e) {
+            return false;
+        }
+    }
+
+    @Override
+    public String getPreferenceKey() {
+        return KEY_CONVERT_FBE;
+    }
+
+    @Override
+    public void displayPreference(PreferenceScreen screen) {
+        super.displayPreference(screen);
+
+        mPreference = screen.findPreference(getPreferenceKey());
+    }
+
+    @Override
+    public void updateState(Preference preference) {
+        if (!TextUtils.equals("file",
+                SystemProperties.get(FILE_ENCRYPTION_PROPERTY_KEY, "none" /* default */))) {
+            return;
+        }
+
+        mPreference.setEnabled(false);
+        mPreference.setSummary(
+                mContext.getResources().getString(R.string.convert_to_file_encryption_done));
+    }
+
+    @Override
+    protected void onDeveloperOptionsSwitchEnabled() {
+        // intentional no-op
+    }
+
+    @Override
+    protected void onDeveloperOptionsSwitchDisabled() {
+        // intentional no-op
+    }
+
+    private IStorageManager getStorageManager() {
+        try {
+            return IStorageManager.Stub.asInterface(
+                    ServiceManager.getService(KEY_STORAGE_MANAGER));
+        } catch (VerifyError e) {
+            // Used for tests since Robolectric cannot initialize this class.
+            return null;
+        }
+    }
+}
\ No newline at end of file
diff --git a/src/com/android/settings/development/ShortcutManagerThrottlingPreferenceController.java b/src/com/android/settings/development/ShortcutManagerThrottlingPreferenceController.java
new file mode 100644
index 0000000..c8fdaec
--- /dev/null
+++ b/src/com/android/settings/development/ShortcutManagerThrottlingPreferenceController.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.development;
+
+import android.content.Context;
+import android.content.pm.IShortcutService;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.support.v7.preference.Preference;
+import android.text.TextUtils;
+import android.util.Log;
+import android.widget.Toast;
+
+import com.android.settings.R;
+
+public class ShortcutManagerThrottlingPreferenceController extends
+        DeveloperOptionsPreferenceController {
+
+    private static final String TAG = "ShortcutMgrPrefCtrl";
+
+    private static final String SHORTCUT_MANAGER_RESET_KEY = "reset_shortcut_manager_throttling";
+
+    private final IShortcutService mShortcutService;
+
+    public ShortcutManagerThrottlingPreferenceController(Context context) {
+        super(context);
+
+        mShortcutService = getShortCutService();
+    }
+
+    @Override
+    public String getPreferenceKey() {
+        return SHORTCUT_MANAGER_RESET_KEY;
+    }
+
+    @Override
+    public boolean handlePreferenceTreeClick(Preference preference) {
+        if (!TextUtils.equals(SHORTCUT_MANAGER_RESET_KEY, preference.getKey())) {
+            return false;
+        }
+        resetShortcutManagerThrottling();
+        return true;
+    }
+
+    @Override
+    protected void onDeveloperOptionsSwitchEnabled() {
+        // intentional no-op
+    }
+
+    @Override
+    protected void onDeveloperOptionsSwitchDisabled() {
+        // intentional no-op
+    }
+
+    private void resetShortcutManagerThrottling() {
+        if (mShortcutService == null) {
+            return;
+        }
+        try {
+            mShortcutService.resetThrottling();
+            Toast.makeText(mContext, R.string.reset_shortcut_manager_throttling_complete,
+                    Toast.LENGTH_SHORT).show();
+        } catch (RemoteException e) {
+            Log.e(TAG, "Failed to reset rate limiting", e);
+        }
+    }
+
+    private IShortcutService getShortCutService() {
+        try {
+            return IShortcutService.Stub.asInterface(
+                    ServiceManager.getService(Context.SHORTCUT_SERVICE));
+        } catch (VerifyError e) {
+            // Used for tests since Robolectric cannot initialize this class.
+            return null;
+        }
+    }
+}
diff --git a/src/com/android/settings/fingerprint/FingerprintAuthenticateSidecar.java b/src/com/android/settings/fingerprint/FingerprintAuthenticateSidecar.java
index b419b72..d649c0b 100644
--- a/src/com/android/settings/fingerprint/FingerprintAuthenticateSidecar.java
+++ b/src/com/android/settings/fingerprint/FingerprintAuthenticateSidecar.java
@@ -117,12 +117,12 @@
     public void setListener(Listener listener) {
         if (mListener == null && listener != null) {
             if (mAuthenticationResult != null) {
-                mListener.onAuthenticationSucceeded(mAuthenticationResult);
+                listener.onAuthenticationSucceeded(mAuthenticationResult);
                 mAuthenticationResult = null;
             }
             if (mAuthenticationError != null &&
                     mAuthenticationError.error != FingerprintManager.FINGERPRINT_ERROR_CANCELED) {
-                mListener.onAuthenticationError(mAuthenticationError.error,
+                listener.onAuthenticationError(mAuthenticationError.error,
                         mAuthenticationError.errorString);
                 mAuthenticationError = null;
             }
diff --git a/src/com/android/settings/support/SupportDashboardActivity.java b/src/com/android/settings/support/SupportDashboardActivity.java
index 819d5f7..d3fcf9a 100644
--- a/src/com/android/settings/support/SupportDashboardActivity.java
+++ b/src/com/android/settings/support/SupportDashboardActivity.java
@@ -47,8 +47,8 @@
             supportFeatureProvider.startSupportV2(this);
         } else {
             startActivity(new Intent(this, LegacySupportActivity.class));
-            finish();
         }
+        finish();
     }
 
     /**
diff --git a/tests/robotests/src/android/service/settings/suggestions/Suggestion.java b/tests/robotests/src/android/service/settings/suggestions/Suggestion.java
index 2bb6192..750bc05 100644
--- a/tests/robotests/src/android/service/settings/suggestions/Suggestion.java
+++ b/tests/robotests/src/android/service/settings/suggestions/Suggestion.java
@@ -17,13 +17,16 @@
 package android.service.settings.suggestions;
 
 import android.app.PendingIntent;
+import android.graphics.drawable.Icon;
 import android.os.Parcel;
 import android.text.TextUtils;
+import android.widget.RemoteViews;
 
 public class Suggestion {
     private final String mId;
     private final CharSequence mTitle;
     private final CharSequence mSummary;
+    private final Icon mIcon;
     private final PendingIntent mPendingIntent;
 
     /**
@@ -48,6 +51,13 @@
     }
 
     /**
+     * Optional icon for this suggestion.
+     */
+    public Icon getIcon() {
+        return mIcon;
+    }
+
+    /**
      * The Intent to launch when the suggestion is activated.
      */
     public PendingIntent getPendingIntent() {
@@ -57,17 +67,11 @@
     private Suggestion(Builder builder) {
         mTitle = builder.mTitle;
         mSummary = builder.mSummary;
+        mIcon = builder.mIcon;
         mPendingIntent = builder.mPendingIntent;
         mId = builder.mId;
     }
 
-    private Suggestion(Parcel in) {
-        mId = in.readString();
-        mTitle = in.readCharSequence();
-        mSummary = in.readCharSequence();
-        mPendingIntent = in.readParcelable(PendingIntent.class.getClassLoader());
-    }
-
     /**
      * Builder class for {@link Suggestion}.
      */
@@ -75,6 +79,7 @@
         private final String mId;
         private CharSequence mTitle;
         private CharSequence mSummary;
+        private Icon mIcon;
         private PendingIntent mPendingIntent;
 
         public Builder(String id) {
@@ -102,6 +107,14 @@
         }
 
         /**
+         * Sets icon for the suggestion.
+         */
+        public Builder setIcon(Icon icon) {
+            mIcon = icon;
+            return this;
+        }
+
+        /**
          * Sets suggestion intent
          */
         public Builder setPendingIntent(PendingIntent pendingIntent) {
diff --git a/tests/robotests/src/com/android/settings/development/FileEncryptionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/FileEncryptionPreferenceControllerTest.java
new file mode 100644
index 0000000..1810b11
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/development/FileEncryptionPreferenceControllerTest.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.development;
+
+import static com.android.settings.development.FileEncryptionPreferenceController
+        .FILE_ENCRYPTION_PROPERTY_KEY;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.os.RemoteException;
+import android.os.SystemProperties;
+import android.os.storage.IStorageManager;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
+
+import org.junit.After;
+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.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH,
+        sdk = TestConfig.SDK_VERSION,
+        shadows = {SettingsShadowSystemProperties.class})
+public class FileEncryptionPreferenceControllerTest {
+
+    @Mock
+    private Preference mPreference;
+    @Mock
+    private PreferenceScreen mPreferenceScreen;
+    @Mock
+    private IStorageManager mStorageManager;
+
+    private Context mContext;
+    private FileEncryptionPreferenceController mController;
+
+    @Before
+    public void setup() {
+        MockitoAnnotations.initMocks(this);
+        mContext = RuntimeEnvironment.application;
+        mController = new FileEncryptionPreferenceController(mContext);
+        when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(
+                mPreference);
+    }
+
+    @After
+    public void teardown() {
+        SettingsShadowSystemProperties.clear();
+    }
+
+    @Test
+    public void isAvailable_storageManagerNull_shouldBeFalse() {
+        ReflectionHelpers.setField(mController, "mStorageManager", null);
+
+        assertThat(mController.isAvailable()).isFalse();
+    }
+
+    @Test
+    public void isAvailable_notConvertibleToFBE_shouldBeFalse() throws RemoteException {
+        ReflectionHelpers.setField(mController, "mStorageManager", mStorageManager);
+        when(mStorageManager.isConvertibleToFBE()).thenReturn(false);
+
+        assertThat(mController.isAvailable()).isFalse();
+    }
+
+    @Test
+    public void isAvailable_convertibleToFBE_shouldBeTrue() throws RemoteException {
+        ReflectionHelpers.setField(mController, "mStorageManager", mStorageManager);
+        when(mStorageManager.isConvertibleToFBE()).thenReturn(true);
+
+        assertThat(mController.isAvailable()).isTrue();
+    }
+
+    @Test
+    public void updateState_settingIsNotFile_shouldDoNothing() throws RemoteException {
+        ReflectionHelpers.setField(mController, "mStorageManager", mStorageManager);
+        when(mStorageManager.isConvertibleToFBE()).thenReturn(true);
+        mController.displayPreference(mPreferenceScreen);
+        SystemProperties.set(FILE_ENCRYPTION_PROPERTY_KEY, "foobar");
+
+        mController.updateState(mPreference);
+
+        verify(mPreference, never()).setEnabled(anyBoolean());
+        verify(mPreference, never()).setSummary(anyString());
+    }
+
+    @Test
+    public void updateState_settingIsFile_shouldSetSummaryAndDisablePreference()
+            throws RemoteException {
+        ReflectionHelpers.setField(mController, "mStorageManager", mStorageManager);
+        when(mStorageManager.isConvertibleToFBE()).thenReturn(true);
+        mController.displayPreference(mPreferenceScreen);
+        SystemProperties.set(FILE_ENCRYPTION_PROPERTY_KEY, "file");
+
+        mController.updateState(mPreference);
+
+        verify(mPreference).setEnabled(false);
+        verify(mPreference).setSummary(
+                mContext.getResources().getString(R.string.convert_to_file_encryption_done));
+    }
+}
+
+
diff --git a/tests/robotests/src/com/android/settings/development/ShortcutManagerThrottlingPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/ShortcutManagerThrottlingPreferenceControllerTest.java
new file mode 100644
index 0000000..0a189cb
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/development/ShortcutManagerThrottlingPreferenceControllerTest.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.development;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.pm.IShortcutService;
+import android.os.RemoteException;
+import android.support.v14.preference.SwitchPreference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.TestConfig;
+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.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class ShortcutManagerThrottlingPreferenceControllerTest {
+
+    @Mock
+    private SwitchPreference mPreference;
+    @Mock
+    private PreferenceScreen mPreferenceScreen;
+    @Mock
+    private IShortcutService mShortcutService;
+
+    private Context mContext;
+    private ShortcutManagerThrottlingPreferenceController mController;
+
+    @Before
+    public void setup() {
+        MockitoAnnotations.initMocks(this);
+        mContext = RuntimeEnvironment.application;
+        mController = new ShortcutManagerThrottlingPreferenceController(mContext);
+        ReflectionHelpers.setField(mController, "mShortcutService", mShortcutService);
+        when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(
+                mPreference);
+        mController.displayPreference(mPreferenceScreen);
+    }
+
+    @Test
+    public void handlePreferenceTreeClick_differentPreferenceKey_shouldReturnFalse() {
+        when(mPreference.getKey()).thenReturn("SomeRandomKey");
+
+        assertThat(mController.handlePreferenceTreeClick(mPreference)).isFalse();
+    }
+
+    @Test
+    public void handlePreferenceTreeClick_correctPreferenceKey_shouldResetThrottling()
+            throws RemoteException {
+        when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
+
+        final boolean handled = mController.handlePreferenceTreeClick(mPreference);
+
+        assertThat(handled).isTrue();
+        verify(mShortcutService).resetThrottling();
+    }
+}