From: Fan Zhang Date: Thu, 17 Nov 2016 00:59:49 +0000 (-0800) Subject: Add dynamic tiles to development settings. X-Git-Tag: android-x86-8.1-r1~1344^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=ee904e89f2b41bedd731b032c5bf4330679b76b2;p=android-x86%2Fpackages-apps-Settings.git Add dynamic tiles to development settings. Remove static preference for MemorySettings and change it to dynamic using manifest metadata. Bug: 32623105 Test: RunSettingsRoboTests Change-Id: Id224eb8a25fea03c75b8fb0b16842bc5b427897a --- diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 4fb17f7172..e1f2cd7491 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -3316,6 +3316,17 @@ android:value="true" /> + + + + + + + + diff --git a/res/xml/development_prefs.xml b/res/xml/development_prefs.xml index e6fc5218f0..d84b0084ec 100644 --- a/res/xml/development_prefs.xml +++ b/res/xml/development_prefs.xml @@ -63,12 +63,6 @@ android:summary="@string/runningservices_settings_summary" android:fragment="com.android.settings.applications.RunningServices" /> - - mAllPrefs = new ArrayList(); @@ -326,6 +329,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment private boolean mLogpersistCleared; private Dialog mLogpersistClearDialog; + private DashboardFeatureProvider mDashboardFeatureProvider; public DevelopmentSettings() { super(UserManager.DISALLOW_DEBUGGING_FEATURES); @@ -337,19 +341,26 @@ public class DevelopmentSettings extends RestrictedSettingsFragment } @Override + public void onAttach(Context context) { + super.onAttach(context); + mDashboardFeatureProvider = FeatureFactory.getFactory(context) + .getDashboardFeatureProvider(context); + } + + @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); mWindowManager = IWindowManager.Stub.asInterface(ServiceManager.getService("window")); mBackupManager = IBackupManager.Stub.asInterface( ServiceManager.getService(Context.BACKUP_SERVICE)); - mWebViewUpdateService = - IWebViewUpdateService.Stub.asInterface(ServiceManager.getService("webviewupdate")); - mOemUnlockManager = (PersistentDataBlockManager)getActivity() + mWebViewUpdateService = + IWebViewUpdateService.Stub.asInterface(ServiceManager.getService("webviewupdate")); + mOemUnlockManager = (PersistentDataBlockManager) getActivity() .getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE); mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); - mDpm = (DevicePolicyManager)getActivity().getSystemService(Context.DEVICE_POLICY_SERVICE); + mDpm = (DevicePolicyManager) getActivity().getSystemService(Context.DEVICE_POLICY_SERVICE); mUm = (UserManager) getSystemService(Context.USER_SERVICE); mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); @@ -362,12 +373,9 @@ public class DevelopmentSettings extends RestrictedSettingsFragment setPreferenceScreen(new PreferenceScreen(getPrefContext(), null)); return; } - mProcessStatsPreferenceController = new ProcessStatsPreferenceController(getActivity()); addPreferencesFromResource(R.xml.development_prefs); - mProcessStatsPreferenceController.displayPreference(getPreferenceScreen()); - final PreferenceGroup debugDebuggingCategory = (PreferenceGroup) findPreference(DEBUG_DEBUGGING_CATEGORY_KEY); mEnableAdb = findAndInitSwitchPref(ENABLE_ADB); @@ -485,7 +493,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment } PreferenceScreen convertFbePreference = - (PreferenceScreen) findPreference(KEY_CONVERT_FBE); + (PreferenceScreen) findPreference(KEY_CONVERT_FBE); try { IBinder service = ServiceManager.getService("mount"); @@ -495,9 +503,9 @@ public class DevelopmentSettings extends RestrictedSettingsFragment } else if ("file".equals(SystemProperties.get("ro.crypto.type", "none"))) { convertFbePreference.setEnabled(false); convertFbePreference.setSummary(getResources() - .getString(R.string.convert_to_file_encryption_done)); + .getString(R.string.convert_to_file_encryption_done)); } - } catch(RemoteException e) { + } catch (RemoteException e) { removePreference(KEY_CONVERT_FBE); } @@ -519,6 +527,20 @@ public class DevelopmentSettings extends RestrictedSettingsFragment removePreference(COLOR_TEMPERATURE_KEY); mColorTemperaturePreference = null; } + + addDashboardCategoryPreferences(); + } + + @VisibleForTesting + void addDashboardCategoryPreferences() { + final PreferenceScreen screen = getPreferenceScreen(); + final List tilePrefs = mDashboardFeatureProvider.getPreferencesForCategory( + getActivity(), getPrefContext(), CategoryKey.CATEGORY_SYSTEM_DEVELOPMENT); + if (tilePrefs != null) { + for (Preference preference : tilePrefs) { + screen.addPreference(preference); + } + } } private ListPreference addListPreference(String prefKey) { @@ -552,7 +574,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment final SettingsActivity activity = (SettingsActivity) getActivity(); mSwitchBar = activity.getSwitchBar(); - if (mUnavailable) { + if (mUnavailable) { mSwitchBar.setEnabled(false); return; } @@ -736,7 +758,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment private void resetDangerousOptions() { mDontPokeProperties = true; - for (int i=0; i< mResetSwitchPrefs.size(); i++) { + for (int i = 0; i < mResetSwitchPrefs.size(); i++) { SwitchPreference cb = mResetSwitchPrefs.get(i); if (cb.isChecked()) { cb.setChecked(false); @@ -770,7 +792,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment } ArrayList options = new ArrayList(); ArrayList values = new ArrayList(); - for(int n = 0; n < providers.length; n++) { + for (int n = 0; n < providers.length; n++) { if (Utils.isPackageEnabled(getActivity(), providers[n].packageName)) { options.add(providers[n].description); values.add(providers[n].packageName); @@ -790,7 +812,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment return; } } - } catch(RemoteException e) { + } catch (RemoteException e) { } } @@ -809,7 +831,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment String wv_package = mWebViewUpdateService.getCurrentWebViewPackageName(); ActivityManager.getService().killPackageDependents( wv_package, UserHandle.USER_ALL); - } catch(RemoteException e) { + } catch (RemoteException e) { } } @@ -858,7 +880,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment newValue == null ? "" : newValue.toString()); updateWebViewProviderOptions(); return newValue != null && newValue.equals(updatedProvider); - } catch(RemoteException e) { + } catch (RemoteException e) { } return false; } @@ -866,7 +888,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment private void writeDebuggerOptions() { try { ActivityManager.getService().setDebugApp( - mDebugApp, mWaitForDebugger.isChecked(), true); + mDebugApp, mWaitForDebugger.isChecked(), true); } catch (RemoteException ex) { } } @@ -972,8 +994,9 @@ public class DevelopmentSettings extends RestrictedSettingsFragment } private void updateVerifyAppsOverUsbOptions() { - updateSwitchPreference(mVerifyAppsOverUsb, Settings.Global.getInt(getActivity().getContentResolver(), - Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1) != 0); + updateSwitchPreference(mVerifyAppsOverUsb, + Settings.Global.getInt(getActivity().getContentResolver(), + Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1) != 0); mVerifyAppsOverUsb.setEnabled(enableVerifierSetting()); } @@ -1328,7 +1351,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment /** * @return true if the color space preference is currently - * controlled by development settings + * controlled by development settings */ private boolean usingDevelopmentColorSpace() { final ContentResolver cr = getContentResolver(); @@ -1488,7 +1511,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment } if (mLogpersist != null) { String currentLogpersistEnable - = SystemProperties.get(ACTUAL_LOGPERSIST_PROPERTY_ENABLE); + = SystemProperties.get(ACTUAL_LOGPERSIST_PROPERTY_ENABLE); if ((currentLogpersistEnable == null) || !currentLogpersistEnable.equals("true") || currentValue.equals(SELECT_LOGD_OFF_SIZE_MARKER_VALUE)) { @@ -1525,7 +1548,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment private void writeLogdSizeOption(Object newValue) { boolean disable = (newValue != null) && - (newValue.toString().equals(SELECT_LOGD_OFF_SIZE_MARKER_VALUE)); + (newValue.toString().equals(SELECT_LOGD_OFF_SIZE_MARKER_VALUE)); String currentTag = SystemProperties.get(SELECT_LOGD_TAG_PROPERTY); if (currentTag == null) { currentTag = ""; @@ -1558,7 +1581,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment } String defaultValue = defaultLogdSizeValue(); final String size = ((newValue != null) && (newValue.toString().length() != 0)) ? - newValue.toString() : defaultValue; + newValue.toString() : defaultValue; SystemProperties.set(SELECT_LOGD_SIZE_PROPERTY, defaultValue.equals(size) ? "" : size); SystemProperties.set("ctl.start", "logd-reinit"); pokeSystemProperties(); @@ -1588,7 +1611,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment currentBuffers.contains("kernel")) { index = 2; if (!currentBuffers.contains("default")) { - String[] contains = { "main", "events", "system", "crash" }; + String[] contains = {"main", "events", "system", "crash"}; for (int i = 0; i < contains.length; i++) { if (!currentBuffers.contains(contains[i])) { index = 1; @@ -1598,8 +1621,10 @@ public class DevelopmentSettings extends RestrictedSettingsFragment } } } - mLogpersist.setValue(getResources().getStringArray(R.array.select_logpersist_values)[index]); - mLogpersist.setSummary(getResources().getStringArray(R.array.select_logpersist_summaries)[index]); + mLogpersist.setValue( + getResources().getStringArray(R.array.select_logpersist_values)[index]); + mLogpersist.setSummary( + getResources().getStringArray(R.array.select_logpersist_summaries)[index]); mLogpersist.setOnPreferenceChangeListener(this); if (index != 0) { mLogpersistCleared = false; @@ -1617,7 +1642,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment SystemProperties.set(ACTUAL_LOGPERSIST_PROPERTY_BUFFER, ""); SystemProperties.set(SELECT_LOGPERSIST_PROPERTY, ""); SystemProperties.set(ACTUAL_LOGPERSIST_PROPERTY, - update ? "" : SELECT_LOGPERSIST_PROPERTY_STOP); + update ? "" : SELECT_LOGPERSIST_PROPERTY_STOP); pokeSystemProperties(); if (update) { updateLogpersistValues(); @@ -1710,7 +1735,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment } private void writeUsbConfigurationOption(Object newValue) { - UsbManager manager = (UsbManager)getActivity().getSystemService(Context.USB_SERVICE); + UsbManager manager = (UsbManager) getActivity().getSystemService(Context.USB_SERVICE); String function = newValue.toString(); if (function.equals("none")) { manager.setCurrentFunction(function, false); @@ -1729,7 +1754,8 @@ public class DevelopmentSettings extends RestrictedSettingsFragment private void updateImmediatelyDestroyActivitiesOptions() { updateSwitchPreference(mImmediatelyDestroyActivities, Settings.Global.getInt( - getActivity().getContentResolver(), Settings.Global.ALWAYS_FINISH_ACTIVITIES, 0) != 0); + getActivity().getContentResolver(), Settings.Global.ALWAYS_FINISH_ACTIVITIES, 0) + != 0); } private void updateAnimationScaleValue(int which, ListPreference pref) { @@ -1739,7 +1765,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment mHaveDebugSettings = true; } CharSequence[] values = pref.getEntryValues(); - for (int i=0; i= limit) { if (i != 0) { @@ -1844,15 +1870,16 @@ public class DevelopmentSettings extends RestrictedSettingsFragment } }; - DialogInterface.OnDismissListener onDismissListener = new DialogInterface.OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialog) { - if (getActivity() == null) { - return; - } - updateAllOptions(); - } - }; + DialogInterface.OnDismissListener onDismissListener = + new DialogInterface.OnDismissListener() { + @Override + public void onDismiss(DialogInterface dialog) { + if (getActivity() == null) { + return; + } + updateAllOptions(); + } + }; new AlertDialog.Builder(getActivity()) .setTitle(R.string.confirm_enable_oem_unlock_title) @@ -1945,10 +1972,10 @@ public class DevelopmentSettings extends RestrictedSettingsFragment } else if (preference == mClearAdbKeys) { if (mAdbKeysDialog != null) dismissDialogs(); mAdbKeysDialog = new AlertDialog.Builder(getActivity()) - .setMessage(R.string.adb_keys_warning_message) - .setPositiveButton(android.R.string.ok, this) - .setNegativeButton(android.R.string.cancel, null) - .show(); + .setMessage(R.string.adb_keys_warning_message) + .setPositiveButton(android.R.string.ok, this) + .setNegativeButton(android.R.string.cancel, null) + .show(); } else if (preference == mEnableTerminal) { final PackageManager pm = getActivity().getPackageManager(); pm.setApplicationEnabledSetting(TERMINAL_APP_PACKAGE, @@ -2275,8 +2302,8 @@ public class DevelopmentSettings extends RestrictedSettingsFragment private boolean isShowingDeveloperOptions(Context context) { return context.getSharedPreferences(DevelopmentSettings.PREF_FILE, Context.MODE_PRIVATE).getBoolean( - DevelopmentSettings.PREF_SHOW, - android.os.Build.TYPE.equals("eng")); + DevelopmentSettings.PREF_SHOW, + android.os.Build.TYPE.equals("eng")); } @Override @@ -2333,7 +2360,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment // the device hasn't been able to confirm which restrictions (SIM-lock or otherwise) // apply. oemUnlockSummary = - R.string.oem_unlock_enable_disabled_summary_connectivity_or_locked; + R.string.oem_unlock_enable_disabled_summary_connectivity_or_locked; } mEnableOemUnlock.setSummary(getString(oemUnlockSummary)); } diff --git a/src/com/android/settings/applications/ProcessStatsPreferenceController.java b/src/com/android/settings/applications/ProcessStatsPreferenceController.java deleted file mode 100644 index 3ba2caf80c..0000000000 --- a/src/com/android/settings/applications/ProcessStatsPreferenceController.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2016 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.applications; - -import android.content.Context; -import android.support.v7.preference.Preference; - -import com.android.settings.core.PreferenceController; -import com.android.settings.dashboard.DashboardFeatureProvider; -import com.android.settings.overlay.FeatureFactory; - -public class ProcessStatsPreferenceController extends PreferenceController { - - private final DashboardFeatureProvider mDashboardFeatureProvider; - - public ProcessStatsPreferenceController(Context context) { - super(context); - mDashboardFeatureProvider = FeatureFactory.getFactory(context) - .getDashboardFeatureProvider(context); - } - - @Override - public boolean isAvailable() { - return mDashboardFeatureProvider.isEnabled(); - } - - @Override - public boolean handlePreferenceTreeClick(Preference preference) { - return false; - } - - @Override - public String getPreferenceKey() { - return "process_stats"; - } -} diff --git a/tests/robotests/src/com/android/settings/DevelopmentSettingsTest.java b/tests/robotests/src/com/android/settings/DevelopmentSettingsTest.java new file mode 100644 index 0000000000..e51862092b --- /dev/null +++ b/tests/robotests/src/com/android/settings/DevelopmentSettingsTest.java @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2016 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; + +import android.app.Activity; +import android.content.Context; +import android.support.v7.preference.Preference; +import android.support.v7.preference.PreferenceManager; +import android.support.v7.preference.PreferenceScreen; + +import com.android.settings.testutils.FakeFeatureFactory; +import com.android.settingslib.drawer.CategoryKey; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Answers; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.robolectric.annotation.Config; +import org.robolectric.shadows.ShadowApplication; + +import java.util.ArrayList; +import java.util.List; + +import static org.mockito.Answers.RETURNS_DEEP_STUBS; +import static org.mockito.Matchers.any; +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 static org.mockito.Mockito.when; + +@RunWith(SettingsRobolectricTestRunner.class) +@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) +public class DevelopmentSettingsTest { + + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + private Context mContext; + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + private Activity mActivity; + @Mock(answer = RETURNS_DEEP_STUBS) + private PreferenceScreen mScreen; + @Mock + private PreferenceManager mPreferenceManager; + + private FakeFeatureFactory mFeatureFactory; + private DevelopmentSettings mSettings; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + FakeFeatureFactory.setupForTest(mContext); + mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext); + mSettings = spy(new DevelopmentSettings()); + } + + @Test + public void addDashboardCategoryPreference_shouldAddToScreen() { + final List preferences = new ArrayList<>(); + preferences.add(new Preference(ShadowApplication.getInstance().getApplicationContext())); + preferences.add(new Preference(ShadowApplication.getInstance().getApplicationContext())); + doReturn(mScreen).when(mSettings).getPreferenceScreen(); + doReturn(mPreferenceManager).when(mSettings).getPreferenceManager(); + doReturn(mActivity).when(mSettings).getActivity(); + when(mPreferenceManager.getContext()).thenReturn(mContext); + when(mFeatureFactory.dashboardFeatureProvider.getPreferencesForCategory( + mActivity, mContext, CategoryKey.CATEGORY_SYSTEM_DEVELOPMENT)) + .thenReturn(preferences); + + mSettings.onAttach(mContext); + mSettings.addDashboardCategoryPreferences(); + + verify(mScreen, times(2)).addPreference(any(Preference.class)); + } +} diff --git a/tests/robotests/src/com/android/settings/applications/ProcessStatsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/ProcessStatsPreferenceControllerTest.java deleted file mode 100644 index d4df28c9c4..0000000000 --- a/tests/robotests/src/com/android/settings/applications/ProcessStatsPreferenceControllerTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2016 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.applications; - -import android.content.Context; - -import com.android.settings.SettingsRobolectricTestRunner; -import com.android.settings.TestConfig; -import com.android.settings.testutils.FakeFeatureFactory; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Answers; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.robolectric.annotation.Config; - -import static com.google.common.truth.Truth.assertThat; -import static org.mockito.Mockito.when; - -@RunWith(SettingsRobolectricTestRunner.class) -@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) -public class ProcessStatsPreferenceControllerTest { - @Mock(answer = Answers.RETURNS_DEEP_STUBS) - private Context mContext; - - private FakeFeatureFactory mFactory; - private ProcessStatsPreferenceController mController; - - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - FakeFeatureFactory.setupForTest(mContext); - - mFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext); - - mController = new ProcessStatsPreferenceController(mContext); - } - - @Test - public void testIsAvailble_dashboardFeatureEnabled_shouldReturnTrue() { - when(mFactory.dashboardFeatureProvider.isEnabled()).thenReturn(true); - - assertThat(mController.isAvailable()).isTrue(); - } - - @Test - public void testIsAvailble_dashboardFeatureDisabled_shouldReturnFalse() { - when(mFactory.dashboardFeatureProvider.isEnabled()).thenReturn(false); - - assertThat(mController.isAvailable()).isFalse(); - } -}