2 * Copyright (C) 2008 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.settings;
19 import android.Manifest;
20 import android.app.Activity;
21 import android.app.ActivityManagerNative;
22 import android.app.AlertDialog;
23 import android.app.AppOpsManager;
24 import android.app.AppOpsManager.PackageOps;
25 import android.app.Dialog;
26 import android.app.admin.DevicePolicyManager;
27 import android.app.backup.IBackupManager;
28 import android.bluetooth.BluetoothAdapter;
29 import android.content.BroadcastReceiver;
30 import android.content.ComponentName;
31 import android.content.ContentResolver;
32 import android.content.Context;
33 import android.content.DialogInterface;
34 import android.content.Intent;
35 import android.content.IntentFilter;
36 import android.content.pm.ApplicationInfo;
37 import android.content.pm.IShortcutService;
38 import android.content.pm.PackageManager;
39 import android.content.pm.PackageManager.NameNotFoundException;
40 import android.content.pm.ResolveInfo;
41 import android.content.res.Resources;
42 import android.hardware.usb.IUsbManager;
43 import android.hardware.usb.UsbManager;
44 import android.net.wifi.WifiManager;
45 import android.os.AsyncTask;
46 import android.os.BatteryManager;
47 import android.os.Build;
48 import android.os.Bundle;
49 import android.os.IBinder;
50 import android.os.Parcel;
51 import android.os.RemoteException;
52 import android.os.ServiceManager;
53 import android.os.StrictMode;
54 import android.os.SystemProperties;
55 import android.os.UserHandle;
56 import android.service.persistentdata.PersistentDataBlockManager;
57 import android.os.UserManager;
58 import android.os.storage.IMountService;
59 import android.provider.SearchIndexableResource;
60 import android.provider.Settings;
61 import android.support.v14.preference.SwitchPreference;
62 import android.support.v7.preference.ListPreference;
63 import android.support.v7.preference.Preference;
64 import android.support.v7.preference.Preference.OnPreferenceChangeListener;
65 import android.support.v7.preference.PreferenceGroup;
66 import android.support.v7.preference.PreferenceScreen;
67 import android.text.TextUtils;
68 import android.util.Log;
69 import android.view.ThreadedRenderer;
70 import android.view.IWindowManager;
71 import android.view.LayoutInflater;
72 import android.view.View;
73 import android.view.ViewGroup;
74 import android.view.accessibility.AccessibilityManager;
75 import android.webkit.IWebViewUpdateService;
76 import android.webkit.WebViewProviderInfo;
77 import android.widget.Switch;
78 import android.widget.Toast;
80 import com.android.internal.app.LocalePicker;
81 import com.android.internal.logging.MetricsProto.MetricsEvent;
82 import com.android.settings.applications.BackgroundCheckSummary;
83 import com.android.settings.fuelgauge.InactiveApps;
84 import com.android.settings.search.BaseSearchIndexProvider;
85 import com.android.settings.search.Indexable;
86 import com.android.settings.widget.SwitchBar;
87 import com.android.settingslib.RestrictedLockUtils;
88 import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
89 import com.android.settingslib.RestrictedSwitchPreference;
91 import java.util.ArrayList;
92 import java.util.Arrays;
93 import java.util.HashSet;
94 import java.util.List;
97 * Displays preferences for application developers.
99 public class DevelopmentSettings extends RestrictedSettingsFragment
100 implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener,
101 OnPreferenceChangeListener, SwitchBar.OnSwitchChangeListener, Indexable {
102 private static final String TAG = "DevelopmentSettings";
105 * Preference file were development settings prefs are stored.
107 public static final String PREF_FILE = "development";
110 * Whether to show the development settings to the user. Default is false.
112 public static final String PREF_SHOW = "show";
114 private static final String ENABLE_ADB = "enable_adb";
115 private static final String CLEAR_ADB_KEYS = "clear_adb_keys";
116 private static final String ENABLE_TERMINAL = "enable_terminal";
117 private static final String KEEP_SCREEN_ON = "keep_screen_on";
118 private static final String BT_HCI_SNOOP_LOG = "bt_hci_snoop_log";
119 private static final String WEBVIEW_PROVIDER_KEY = "select_webview_provider";
120 private static final String WEBVIEW_MULTIPROCESS_KEY = "enable_webview_multiprocess";
121 private static final String ENABLE_OEM_UNLOCK = "oem_unlock_enable";
122 private static final String HDCP_CHECKING_KEY = "hdcp_checking";
123 private static final String HDCP_CHECKING_PROPERTY = "persist.sys.hdcp_checking";
124 private static final String LOCAL_BACKUP_PASSWORD = "local_backup_password";
125 private static final String HARDWARE_UI_PROPERTY = "persist.sys.ui.hw";
126 private static final String MSAA_PROPERTY = "debug.egl.force_msaa";
127 private static final String BUGREPORT = "bugreport";
128 private static final String BUGREPORT_IN_POWER_KEY = "bugreport_in_power";
129 private static final String OPENGL_TRACES_PROPERTY = "debug.egl.trace";
130 private static final String TUNER_UI_KEY = "tuner_ui";
131 private static final String COLOR_TEMPERATURE_PROPERTY = "persist.sys.debug.color_temp";
133 private static final String DEBUG_APP_KEY = "debug_app";
134 private static final String WAIT_FOR_DEBUGGER_KEY = "wait_for_debugger";
135 private static final String MOCK_LOCATION_APP_KEY = "mock_location_app";
136 private static final String VERIFY_APPS_OVER_USB_KEY = "verify_apps_over_usb";
137 private static final String DEBUG_VIEW_ATTRIBUTES = "debug_view_attributes";
138 private static final String FORCE_ALLOW_ON_EXTERNAL_KEY = "force_allow_on_external";
139 private static final String STRICT_MODE_KEY = "strict_mode";
140 private static final String POINTER_LOCATION_KEY = "pointer_location";
141 private static final String SHOW_TOUCHES_KEY = "show_touches";
142 private static final String SHOW_SCREEN_UPDATES_KEY = "show_screen_updates";
143 private static final String DISABLE_OVERLAYS_KEY = "disable_overlays";
144 private static final String SIMULATE_COLOR_SPACE = "simulate_color_space";
145 private static final String USB_AUDIO_KEY = "usb_audio";
146 private static final String SHOW_CPU_USAGE_KEY = "show_cpu_usage";
147 private static final String FORCE_HARDWARE_UI_KEY = "force_hw_ui";
148 private static final String FORCE_MSAA_KEY = "force_msaa";
149 private static final String TRACK_FRAME_TIME_KEY = "track_frame_time";
150 private static final String SHOW_NON_RECTANGULAR_CLIP_KEY = "show_non_rect_clip";
151 private static final String SHOW_HW_SCREEN_UPDATES_KEY = "show_hw_screen_udpates";
152 private static final String SHOW_HW_LAYERS_UPDATES_KEY = "show_hw_layers_udpates";
153 private static final String DEBUG_HW_OVERDRAW_KEY = "debug_hw_overdraw";
154 private static final String DEBUG_LAYOUT_KEY = "debug_layout";
155 private static final String FORCE_RTL_LAYOUT_KEY = "force_rtl_layout_all_locales";
156 private static final String WINDOW_ANIMATION_SCALE_KEY = "window_animation_scale";
157 private static final String TRANSITION_ANIMATION_SCALE_KEY = "transition_animation_scale";
158 private static final String ANIMATOR_DURATION_SCALE_KEY = "animator_duration_scale";
159 private static final String OVERLAY_DISPLAY_DEVICES_KEY = "overlay_display_devices";
160 private static final String DEBUG_DEBUGGING_CATEGORY_KEY = "debug_debugging_category";
161 private static final String SELECT_LOGD_SIZE_KEY = "select_logd_size";
162 private static final String SELECT_LOGD_SIZE_PROPERTY = "persist.logd.size";
163 private static final String SELECT_LOGD_TAG_PROPERTY = "persist.log.tag";
164 // Tricky, isLoggable only checks for first character, assumes silence
165 private static final String SELECT_LOGD_TAG_SILENCE = "Settings";
166 private static final String SELECT_LOGD_SNET_TAG_PROPERTY = "persist.log.tag.snet_event_log";
167 private static final String SELECT_LOGD_RUNTIME_SNET_TAG_PROPERTY = "log.tag.snet_event_log";
168 private static final String SELECT_LOGD_DEFAULT_SIZE_PROPERTY = "ro.logd.size";
169 private static final String SELECT_LOGD_DEFAULT_SIZE_VALUE = "262144";
170 private static final String SELECT_LOGD_SVELTE_DEFAULT_SIZE_VALUE = "65536";
171 // 32768 is merely a menu marker, 64K is our lowest log buffer size we replace it with.
172 private static final String SELECT_LOGD_MINIMUM_SIZE_VALUE = "65536";
173 private static final String SELECT_LOGD_OFF_SIZE_MARKER_VALUE = "32768";
175 private static final String WIFI_DISPLAY_CERTIFICATION_KEY = "wifi_display_certification";
176 private static final String WIFI_VERBOSE_LOGGING_KEY = "wifi_verbose_logging";
177 private static final String WIFI_AGGRESSIVE_HANDOVER_KEY = "wifi_aggressive_handover";
178 private static final String WIFI_ALLOW_SCAN_WITH_TRAFFIC_KEY = "wifi_allow_scan_with_traffic";
179 private static final String USB_CONFIGURATION_KEY = "select_usb_configuration";
180 private static final String MOBILE_DATA_ALWAYS_ON = "mobile_data_always_on";
181 private static final String KEY_COLOR_MODE = "color_mode";
182 private static final String FORCE_RESIZABLE_KEY = "force_resizable_activities";
183 private static final String COLOR_TEMPERATURE_KEY = "color_temperature";
185 private static final String BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_KEY =
186 "bluetooth_disable_absolute_volume";
187 private static final String BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_PROPERTY =
188 "persist.bluetooth.disableabsvol";
190 private static final String INACTIVE_APPS_KEY = "inactive_apps";
192 private static final String IMMEDIATELY_DESTROY_ACTIVITIES_KEY
193 = "immediately_destroy_activities";
194 private static final String APP_PROCESS_LIMIT_KEY = "app_process_limit";
196 private static final String BACKGROUND_CHECK_KEY = "background_check";
198 private static final String SHOW_ALL_ANRS_KEY = "show_all_anrs";
200 private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive";
202 private static final String TERMINAL_APP_PACKAGE = "com.android.terminal";
204 private static final String KEY_CONVERT_FBE = "convert_to_file_encryption";
206 private static final String OTA_DISABLE_AUTOMATIC_UPDATE_KEY = "ota_disable_automatic_update";
208 private static final String LOCATION_DOGFOOD_TOOLS_KEY = "location_dogfood_tools";
210 private static final int RESULT_DEBUG_APP = 1000;
211 private static final int RESULT_MOCK_LOCATION_APP = 1001;
213 private static final String PERSISTENT_DATA_BLOCK_PROP = "ro.frp.pst";
214 private static final String FLASH_LOCKED_PROP = "ro.boot.flash.locked";
216 private static final String SHORTCUT_MANAGER_RESET_KEY = "reset_shortcut_manager_throttling";
218 private static final int REQUEST_CODE_ENABLE_OEM_UNLOCK = 0;
220 private static final int[] MOCK_LOCATION_APP_OPS = new int[] {AppOpsManager.OP_MOCK_LOCATION};
222 private IWindowManager mWindowManager;
223 private IBackupManager mBackupManager;
224 private IWebViewUpdateService mWebViewUpdateService;
225 private DevicePolicyManager mDpm;
226 private UserManager mUm;
227 private WifiManager mWifiManager;
228 private PersistentDataBlockManager mOemUnlockManager;
230 private SwitchBar mSwitchBar;
231 private boolean mLastEnabledState;
232 private boolean mHaveDebugSettings;
233 private boolean mDontPokeProperties;
235 private SwitchPreference mEnableAdb;
236 private Preference mClearAdbKeys;
237 private SwitchPreference mEnableTerminal;
238 private Preference mBugreport;
239 private SwitchPreference mBugreportInPower;
240 private RestrictedSwitchPreference mKeepScreenOn;
241 private SwitchPreference mBtHciSnoopLog;
242 private SwitchPreference mEnableOemUnlock;
243 private SwitchPreference mDebugViewAttributes;
244 private SwitchPreference mForceAllowOnExternal;
246 private PreferenceScreen mPassword;
247 private String mDebugApp;
248 private Preference mDebugAppPref;
250 private String mMockLocationApp;
251 private Preference mMockLocationAppPref;
252 private Preference mLocationDogfoodTools;
254 private SwitchPreference mWaitForDebugger;
255 private SwitchPreference mVerifyAppsOverUsb;
256 private SwitchPreference mWifiDisplayCertification;
257 private SwitchPreference mWifiVerboseLogging;
258 private SwitchPreference mWifiAggressiveHandover;
259 private SwitchPreference mMobileDataAlwaysOn;
260 private SwitchPreference mBluetoothDisableAbsVolume;
261 private SwitchPreference mOtaDisableAutomaticUpdate;
263 private SwitchPreference mWifiAllowScansWithTraffic;
264 private SwitchPreference mStrictMode;
265 private SwitchPreference mPointerLocation;
266 private SwitchPreference mShowTouches;
267 private SwitchPreference mShowScreenUpdates;
268 private SwitchPreference mDisableOverlays;
269 private SwitchPreference mShowCpuUsage;
270 private SwitchPreference mForceHardwareUi;
271 private SwitchPreference mForceMsaa;
272 private SwitchPreference mShowHwScreenUpdates;
273 private SwitchPreference mShowHwLayersUpdates;
274 private SwitchPreference mDebugLayout;
275 private SwitchPreference mForceRtlLayout;
276 private ListPreference mDebugHwOverdraw;
277 private ListPreference mLogdSize;
278 private ListPreference mUsbConfiguration;
279 private ListPreference mTrackFrameTime;
280 private ListPreference mShowNonRectClip;
281 private ListPreference mWindowAnimationScale;
282 private ListPreference mTransitionAnimationScale;
283 private ListPreference mAnimatorDurationScale;
284 private ListPreference mOverlayDisplayDevices;
286 private SwitchPreference mWebViewMultiprocess;
287 private ListPreference mWebViewProvider;
289 private ListPreference mSimulateColorSpace;
291 private SwitchPreference mUSBAudio;
292 private SwitchPreference mImmediatelyDestroyActivities;
294 private ListPreference mAppProcessLimit;
296 private SwitchPreference mShowAllANRs;
298 private ColorModePreference mColorModePreference;
300 private SwitchPreference mForceResizable;
302 private SwitchPreference mColorTemperaturePreference;
304 private final ArrayList<Preference> mAllPrefs = new ArrayList<Preference>();
306 private final ArrayList<SwitchPreference> mResetSwitchPrefs
307 = new ArrayList<SwitchPreference>();
309 private final HashSet<Preference> mDisabledPrefs = new HashSet<Preference>();
310 // To track whether a confirmation dialog was clicked.
311 private boolean mDialogClicked;
312 private Dialog mEnableDialog;
313 private Dialog mAdbDialog;
315 private Dialog mAdbKeysDialog;
316 private boolean mUnavailable;
318 public DevelopmentSettings() {
319 super(UserManager.DISALLOW_DEBUGGING_FEATURES);
323 protected int getMetricsCategory() {
324 return MetricsEvent.DEVELOPMENT;
328 public void onCreate(Bundle icicle) {
329 super.onCreate(icicle);
331 mWindowManager = IWindowManager.Stub.asInterface(ServiceManager.getService("window"));
332 mBackupManager = IBackupManager.Stub.asInterface(
333 ServiceManager.getService(Context.BACKUP_SERVICE));
334 mWebViewUpdateService =
335 IWebViewUpdateService.Stub.asInterface(ServiceManager.getService("webviewupdate"));
336 mOemUnlockManager = (PersistentDataBlockManager)getActivity()
337 .getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
339 mDpm = (DevicePolicyManager)getActivity().getSystemService(Context.DEVICE_POLICY_SERVICE);
340 mUm = (UserManager) getSystemService(Context.USER_SERVICE);
342 mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
344 setIfOnlyAvailableForAdmins(true);
345 if (isUiRestricted() || !Utils.isDeviceProvisioned(getActivity())) {
346 // Block access to developer options if the user is not the owner, if user policy
347 // restricts it, or if the device has not been provisioned
349 setPreferenceScreen(new PreferenceScreen(getPrefContext(), null));
353 addPreferencesFromResource(R.xml.development_prefs);
355 final PreferenceGroup debugDebuggingCategory = (PreferenceGroup)
356 findPreference(DEBUG_DEBUGGING_CATEGORY_KEY);
357 mEnableAdb = findAndInitSwitchPref(ENABLE_ADB);
358 mClearAdbKeys = findPreference(CLEAR_ADB_KEYS);
359 if (!SystemProperties.getBoolean("ro.adb.secure", false)) {
360 if (debugDebuggingCategory != null) {
361 debugDebuggingCategory.removePreference(mClearAdbKeys);
364 mAllPrefs.add(mClearAdbKeys);
365 mEnableTerminal = findAndInitSwitchPref(ENABLE_TERMINAL);
366 if (!isPackageInstalled(getActivity(), TERMINAL_APP_PACKAGE)) {
367 debugDebuggingCategory.removePreference(mEnableTerminal);
368 mEnableTerminal = null;
371 mBugreport = findPreference(BUGREPORT);
372 mBugreportInPower = findAndInitSwitchPref(BUGREPORT_IN_POWER_KEY);
373 mKeepScreenOn = (RestrictedSwitchPreference) findAndInitSwitchPref(KEEP_SCREEN_ON);
374 mBtHciSnoopLog = findAndInitSwitchPref(BT_HCI_SNOOP_LOG);
375 mEnableOemUnlock = findAndInitSwitchPref(ENABLE_OEM_UNLOCK);
376 if (!showEnableOemUnlockPreference()) {
377 removePreference(mEnableOemUnlock);
378 mEnableOemUnlock = null;
381 mDebugViewAttributes = findAndInitSwitchPref(DEBUG_VIEW_ATTRIBUTES);
382 mForceAllowOnExternal = findAndInitSwitchPref(FORCE_ALLOW_ON_EXTERNAL_KEY);
383 mPassword = (PreferenceScreen) findPreference(LOCAL_BACKUP_PASSWORD);
384 mAllPrefs.add(mPassword);
386 if (!mUm.isAdminUser()) {
387 disableForUser(mEnableAdb);
388 disableForUser(mClearAdbKeys);
389 disableForUser(mEnableTerminal);
390 disableForUser(mPassword);
393 mDebugAppPref = findPreference(DEBUG_APP_KEY);
394 mAllPrefs.add(mDebugAppPref);
395 mWaitForDebugger = findAndInitSwitchPref(WAIT_FOR_DEBUGGER_KEY);
397 mMockLocationAppPref = findPreference(MOCK_LOCATION_APP_KEY);
398 mAllPrefs.add(mMockLocationAppPref);
400 mLocationDogfoodTools = findPreference(LOCATION_DOGFOOD_TOOLS_KEY);
401 mAllPrefs.add(mLocationDogfoodTools);
403 mVerifyAppsOverUsb = findAndInitSwitchPref(VERIFY_APPS_OVER_USB_KEY);
404 if (!showVerifierSetting()) {
405 if (debugDebuggingCategory != null) {
406 debugDebuggingCategory.removePreference(mVerifyAppsOverUsb);
408 mVerifyAppsOverUsb.setEnabled(false);
411 mStrictMode = findAndInitSwitchPref(STRICT_MODE_KEY);
412 mPointerLocation = findAndInitSwitchPref(POINTER_LOCATION_KEY);
413 mShowTouches = findAndInitSwitchPref(SHOW_TOUCHES_KEY);
414 mShowScreenUpdates = findAndInitSwitchPref(SHOW_SCREEN_UPDATES_KEY);
415 mDisableOverlays = findAndInitSwitchPref(DISABLE_OVERLAYS_KEY);
416 mShowCpuUsage = findAndInitSwitchPref(SHOW_CPU_USAGE_KEY);
417 mForceHardwareUi = findAndInitSwitchPref(FORCE_HARDWARE_UI_KEY);
418 mForceMsaa = findAndInitSwitchPref(FORCE_MSAA_KEY);
419 mTrackFrameTime = addListPreference(TRACK_FRAME_TIME_KEY);
420 mShowNonRectClip = addListPreference(SHOW_NON_RECTANGULAR_CLIP_KEY);
421 mShowHwScreenUpdates = findAndInitSwitchPref(SHOW_HW_SCREEN_UPDATES_KEY);
422 mShowHwLayersUpdates = findAndInitSwitchPref(SHOW_HW_LAYERS_UPDATES_KEY);
423 mDebugLayout = findAndInitSwitchPref(DEBUG_LAYOUT_KEY);
424 mForceRtlLayout = findAndInitSwitchPref(FORCE_RTL_LAYOUT_KEY);
425 mDebugHwOverdraw = addListPreference(DEBUG_HW_OVERDRAW_KEY);
426 mWifiDisplayCertification = findAndInitSwitchPref(WIFI_DISPLAY_CERTIFICATION_KEY);
427 mWifiVerboseLogging = findAndInitSwitchPref(WIFI_VERBOSE_LOGGING_KEY);
428 mWifiAggressiveHandover = findAndInitSwitchPref(WIFI_AGGRESSIVE_HANDOVER_KEY);
429 mWifiAllowScansWithTraffic = findAndInitSwitchPref(WIFI_ALLOW_SCAN_WITH_TRAFFIC_KEY);
430 mMobileDataAlwaysOn = findAndInitSwitchPref(MOBILE_DATA_ALWAYS_ON);
431 mLogdSize = addListPreference(SELECT_LOGD_SIZE_KEY);
432 mUsbConfiguration = addListPreference(USB_CONFIGURATION_KEY);
433 mWebViewProvider = addListPreference(WEBVIEW_PROVIDER_KEY);
434 mWebViewMultiprocess = findAndInitSwitchPref(WEBVIEW_MULTIPROCESS_KEY);
435 mBluetoothDisableAbsVolume = findAndInitSwitchPref(BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_KEY);
437 mWindowAnimationScale = addListPreference(WINDOW_ANIMATION_SCALE_KEY);
438 mTransitionAnimationScale = addListPreference(TRANSITION_ANIMATION_SCALE_KEY);
439 mAnimatorDurationScale = addListPreference(ANIMATOR_DURATION_SCALE_KEY);
440 mOverlayDisplayDevices = addListPreference(OVERLAY_DISPLAY_DEVICES_KEY);
441 mSimulateColorSpace = addListPreference(SIMULATE_COLOR_SPACE);
442 mUSBAudio = findAndInitSwitchPref(USB_AUDIO_KEY);
443 mForceResizable = findAndInitSwitchPref(FORCE_RESIZABLE_KEY);
445 mImmediatelyDestroyActivities = (SwitchPreference) findPreference(
446 IMMEDIATELY_DESTROY_ACTIVITIES_KEY);
447 mAllPrefs.add(mImmediatelyDestroyActivities);
448 mResetSwitchPrefs.add(mImmediatelyDestroyActivities);
450 mAppProcessLimit = addListPreference(APP_PROCESS_LIMIT_KEY);
452 mShowAllANRs = (SwitchPreference) findPreference(
454 mAllPrefs.add(mShowAllANRs);
455 mResetSwitchPrefs.add(mShowAllANRs);
457 Preference hdcpChecking = findPreference(HDCP_CHECKING_KEY);
458 if (hdcpChecking != null) {
459 mAllPrefs.add(hdcpChecking);
460 removePreferenceForProduction(hdcpChecking);
463 PreferenceScreen convertFbePreference =
464 (PreferenceScreen) findPreference(KEY_CONVERT_FBE);
467 IBinder service = ServiceManager.getService("mount");
468 IMountService mountService = IMountService.Stub.asInterface(service);
469 if (!mountService.isConvertibleToFBE()) {
470 removePreference(KEY_CONVERT_FBE);
471 } else if ("file".equals(SystemProperties.get("ro.crypto.type", "none"))) {
472 convertFbePreference.setEnabled(false);
473 convertFbePreference.setSummary(getResources()
474 .getString(R.string.convert_to_file_encryption_done));
476 } catch(RemoteException e) {
477 removePreference(KEY_CONVERT_FBE);
480 mOtaDisableAutomaticUpdate = findAndInitSwitchPref(OTA_DISABLE_AUTOMATIC_UPDATE_KEY);
482 mColorModePreference = (ColorModePreference) findPreference(KEY_COLOR_MODE);
483 mColorModePreference.updateCurrentAndSupported();
484 if (mColorModePreference.getTransformsCount() < 2) {
485 removePreference(KEY_COLOR_MODE);
486 mColorModePreference = null;
488 updateWebViewProviderOptions();
490 mColorTemperaturePreference = (SwitchPreference) findPreference(COLOR_TEMPERATURE_KEY);
491 if (getResources().getBoolean(R.bool.config_enableColorTemperature)) {
492 mAllPrefs.add(mColorTemperaturePreference);
493 mResetSwitchPrefs.add(mColorTemperaturePreference);
495 removePreference(COLOR_TEMPERATURE_KEY);
496 mColorTemperaturePreference = null;
500 private ListPreference addListPreference(String prefKey) {
501 ListPreference pref = (ListPreference) findPreference(prefKey);
503 pref.setOnPreferenceChangeListener(this);
507 private void disableForUser(Preference pref) {
509 pref.setEnabled(false);
510 mDisabledPrefs.add(pref);
514 private SwitchPreference findAndInitSwitchPref(String key) {
515 SwitchPreference pref = (SwitchPreference) findPreference(key);
517 throw new IllegalArgumentException("Cannot find preference with key = " + key);
520 mResetSwitchPrefs.add(pref);
525 public void onActivityCreated(Bundle savedInstanceState) {
526 super.onActivityCreated(savedInstanceState);
528 final SettingsActivity activity = (SettingsActivity) getActivity();
530 mSwitchBar = activity.getSwitchBar();
532 mSwitchBar.setEnabled(false);
536 mSwitchBar.addOnSwitchChangeListener(this);
539 private boolean removePreferenceForProduction(Preference preference) {
540 if ("user".equals(Build.TYPE)) {
541 removePreference(preference);
547 private void removePreference(Preference preference) {
548 getPreferenceScreen().removePreference(preference);
549 mAllPrefs.remove(preference);
550 mResetSwitchPrefs.remove(preference);
553 private void setPrefsEnabledState(boolean enabled) {
554 for (int i = 0; i < mAllPrefs.size(); i++) {
555 Preference pref = mAllPrefs.get(i);
556 pref.setEnabled(enabled && !mDisabledPrefs.contains(pref));
562 public void onResume() {
566 // Show error message
567 if (!isUiRestrictedByOnlyAdmin()) {
568 getEmptyTextView().setText(R.string.development_settings_not_available);
570 getPreferenceScreen().removeAll();
574 // A DeviceAdmin has specified a maximum time until the device
575 // will lock... in this case we can't allow the user to turn
576 // on "stay awake when plugged in" because that would defeat the
578 final EnforcedAdmin admin = RestrictedLockUtils.checkIfMaximumTimeToLockIsSet(
580 mKeepScreenOn.setDisabledByAdmin(admin);
582 mDisabledPrefs.remove(mKeepScreenOn);
584 mDisabledPrefs.add(mKeepScreenOn);
587 final ContentResolver cr = getActivity().getContentResolver();
588 mLastEnabledState = Settings.Global.getInt(cr,
589 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
590 mSwitchBar.setChecked(mLastEnabledState);
591 setPrefsEnabledState(mLastEnabledState);
593 if (mHaveDebugSettings && !mLastEnabledState) {
594 // Overall debugging is disabled, but there are some debug
595 // settings that are enabled. This is an invalid state. Switch
596 // to debug settings being enabled, so the user knows there is
597 // stuff enabled and can turn it all off if they want.
598 Settings.Global.putInt(getActivity().getContentResolver(),
599 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
600 mLastEnabledState = true;
601 mSwitchBar.setChecked(mLastEnabledState);
602 setPrefsEnabledState(mLastEnabledState);
606 if (mColorModePreference != null) {
607 mColorModePreference.startListening();
608 mColorModePreference.updateCurrentAndSupported();
613 public void onPause() {
615 if (mColorModePreference != null) {
616 mColorModePreference.stopListening();
621 public View onCreateView(LayoutInflater inflater, ViewGroup container,
622 Bundle savedInstanceState) {
623 IntentFilter filter = new IntentFilter();
624 filter.addAction(UsbManager.ACTION_USB_STATE);
625 if (getActivity().registerReceiver(mUsbReceiver, filter) == null) {
626 updateUsbConfigurationValues();
628 return super.onCreateView(inflater, container, savedInstanceState);
632 public void onDestroyView() {
633 super.onDestroyView();
638 mSwitchBar.removeOnSwitchChangeListener(this);
640 getActivity().unregisterReceiver(mUsbReceiver);
643 void updateSwitchPreference(SwitchPreference switchPreference, boolean value) {
644 switchPreference.setChecked(value);
645 mHaveDebugSettings |= value;
648 private void updateAllOptions() {
649 final Context context = getActivity();
650 final ContentResolver cr = context.getContentResolver();
651 mHaveDebugSettings = false;
652 updateSwitchPreference(mEnableAdb, Settings.Global.getInt(cr,
653 Settings.Global.ADB_ENABLED, 0) != 0);
654 if (mEnableTerminal != null) {
655 updateSwitchPreference(mEnableTerminal,
656 context.getPackageManager().getApplicationEnabledSetting(TERMINAL_APP_PACKAGE)
657 == PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
659 updateSwitchPreference(mBugreportInPower, Settings.Secure.getInt(cr,
660 Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0);
661 updateSwitchPreference(mKeepScreenOn, Settings.Global.getInt(cr,
662 Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0) != 0);
663 updateSwitchPreference(mBtHciSnoopLog, Settings.Secure.getInt(cr,
664 Settings.Secure.BLUETOOTH_HCI_LOG, 0) != 0);
665 if (mEnableOemUnlock != null) {
666 updateSwitchPreference(mEnableOemUnlock, Utils.isOemUnlockEnabled(getActivity()));
668 updateSwitchPreference(mDebugViewAttributes, Settings.Global.getInt(cr,
669 Settings.Global.DEBUG_VIEW_ATTRIBUTES, 0) != 0);
670 updateSwitchPreference(mForceAllowOnExternal, Settings.Global.getInt(cr,
671 Settings.Global.FORCE_ALLOW_ON_EXTERNAL, 0) != 0);
673 updatePasswordSummary();
674 updateDebuggerOptions();
675 updateMockLocation();
676 updateStrictModeVisualOptions();
677 updatePointerLocationOptions();
678 updateShowTouchesOptions();
679 updateFlingerOptions();
680 updateCpuUsageOptions();
681 updateHardwareUiOptions();
683 updateTrackFrameTimeOptions();
684 updateShowNonRectClipOptions();
685 updateShowHwScreenUpdatesOptions();
686 updateShowHwLayersUpdatesOptions();
687 updateDebugHwOverdrawOptions();
688 updateDebugLayoutOptions();
689 updateAnimationScaleOptions();
690 updateOverlayDisplayDevicesOptions();
691 updateImmediatelyDestroyActivitiesOptions();
692 updateAppProcessLimitOptions();
693 updateShowAllANRsOptions();
694 updateVerifyAppsOverUsbOptions();
695 updateOtaDisableAutomaticUpdateOptions();
696 updateBugreportOptions();
697 updateForceRtlOptions();
698 updateLogdSizeValues();
699 updateWifiDisplayCertificationOptions();
700 updateWifiVerboseLoggingOptions();
701 updateWifiAggressiveHandoverOptions();
702 updateWifiAllowScansWithTrafficOptions();
703 updateMobileDataAlwaysOnOptions();
704 updateSimulateColorSpace();
705 updateUSBAudioOptions();
706 updateForceResizableOptions();
707 updateWebViewMultiprocessOptions();
708 updateWebViewProviderOptions();
709 updateOemUnlockOptions();
710 if (mColorTemperaturePreference != null) {
711 updateColorTemperature();
713 updateBluetoothDisableAbsVolumeOptions();
716 private void resetDangerousOptions() {
717 mDontPokeProperties = true;
718 for (int i=0; i< mResetSwitchPrefs.size(); i++) {
719 SwitchPreference cb = mResetSwitchPrefs.get(i);
720 if (cb.isChecked()) {
721 cb.setChecked(false);
722 onPreferenceTreeClick(cb);
725 resetDebuggerOptions();
726 writeLogdSizeOption(null);
727 writeAnimationScaleOption(0, mWindowAnimationScale, null);
728 writeAnimationScaleOption(1, mTransitionAnimationScale, null);
729 writeAnimationScaleOption(2, mAnimatorDurationScale, null);
730 // Only poke the color space setting if we control it.
731 if (usingDevelopmentColorSpace()) {
732 writeSimulateColorSpace(-1);
734 writeOverlayDisplayDevicesOptions(null);
735 writeAppProcessLimitOptions(null);
736 mHaveDebugSettings = false;
738 mDontPokeProperties = false;
739 pokeSystemProperties();
742 private void updateWebViewProviderOptions() {
744 WebViewProviderInfo[] providers = mWebViewUpdateService.getValidWebViewPackages();
745 if (providers == null) {
746 Log.e(TAG, "No WebView providers available");
749 ArrayList<String> options = new ArrayList<String>();
750 ArrayList<String> values = new ArrayList<String>();
751 for(int n = 0; n < providers.length; n++) {
752 if (isPackageEnabled(providers[n].packageName)) {
753 options.add(providers[n].description);
754 values.add(providers[n].packageName);
757 mWebViewProvider.setEntries(options.toArray(new String[options.size()]));
758 mWebViewProvider.setEntryValues(values.toArray(new String[values.size()]));
760 String value = mWebViewUpdateService.getCurrentWebViewPackageName();
765 for (int i = 0; i < values.size(); i++) {
766 if (value.contentEquals(values.get(i))) {
767 mWebViewProvider.setValueIndex(i);
771 } catch(RemoteException e) {
775 private void updateWebViewMultiprocessOptions() {
776 updateSwitchPreference(mWebViewMultiprocess,
777 Settings.Global.getInt(getActivity().getContentResolver(),
778 Settings.Global.WEBVIEW_MULTIPROCESS, 0) != 0);
781 private void writeWebViewMultiprocessOptions() {
782 boolean value = mWebViewMultiprocess.isChecked();
783 Settings.Global.putInt(getActivity().getContentResolver(),
784 Settings.Global.WEBVIEW_MULTIPROCESS, value ? 1 : 0);
787 String wv_package = mWebViewUpdateService.getCurrentWebViewPackageName();
788 ActivityManagerNative.getDefault().killPackageDependents(
789 wv_package, UserHandle.USER_ALL);
790 } catch(RemoteException e) {
794 private void updateHdcpValues() {
795 ListPreference hdcpChecking = (ListPreference) findPreference(HDCP_CHECKING_KEY);
796 if (hdcpChecking != null) {
797 String currentValue = SystemProperties.get(HDCP_CHECKING_PROPERTY);
798 String[] values = getResources().getStringArray(R.array.hdcp_checking_values);
799 String[] summaries = getResources().getStringArray(R.array.hdcp_checking_summaries);
800 int index = 1; // Defaults to drm-only. Needs to match with R.array.hdcp_checking_values
801 for (int i = 0; i < values.length; i++) {
802 if (currentValue.equals(values[i])) {
807 hdcpChecking.setValue(values[index]);
808 hdcpChecking.setSummary(summaries[index]);
809 hdcpChecking.setOnPreferenceChangeListener(this);
813 private void updatePasswordSummary() {
815 if (mBackupManager.hasBackupPassword()) {
816 mPassword.setSummary(R.string.local_backup_password_summary_change);
818 mPassword.setSummary(R.string.local_backup_password_summary_none);
820 } catch (RemoteException e) {
821 // Not much we can do here
825 private void writeBtHciSnoopLogOptions() {
826 BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
827 adapter.configHciSnoopLog(mBtHciSnoopLog.isChecked());
828 Settings.Secure.putInt(getActivity().getContentResolver(),
829 Settings.Secure.BLUETOOTH_HCI_LOG,
830 mBtHciSnoopLog.isChecked() ? 1 : 0);
833 private boolean writeWebViewProviderOptions(Object newValue) {
835 String updatedProvider = mWebViewUpdateService.changeProviderAndSetting(
836 newValue == null ? "" : newValue.toString());
837 updateWebViewProviderOptions();
838 return newValue != null && newValue.equals(updatedProvider);
839 } catch(RemoteException e) {
844 private void writeDebuggerOptions() {
846 ActivityManagerNative.getDefault().setDebugApp(
847 mDebugApp, mWaitForDebugger.isChecked(), true);
848 } catch (RemoteException ex) {
852 private void writeMockLocation() {
853 AppOpsManager appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE);
855 // Disable the app op of the previous mock location app if such.
856 List<PackageOps> packageOps = appOpsManager.getPackagesForOps(MOCK_LOCATION_APP_OPS);
857 if (packageOps != null) {
858 // Should be one but in case we are in a bad state due to use of command line tools.
859 for (PackageOps packageOp : packageOps) {
860 if (packageOp.getOps().get(0).getMode() != AppOpsManager.MODE_ERRORED) {
861 String oldMockLocationApp = packageOp.getPackageName();
863 ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(
864 oldMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS);
865 appOpsManager.setMode(AppOpsManager.OP_MOCK_LOCATION, ai.uid,
866 oldMockLocationApp, AppOpsManager.MODE_ERRORED);
867 } catch (NameNotFoundException e) {
874 // Enable the app op of the new mock location app if such.
875 if (!TextUtils.isEmpty(mMockLocationApp)) {
877 ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(
878 mMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS);
879 appOpsManager.setMode(AppOpsManager.OP_MOCK_LOCATION, ai.uid,
880 mMockLocationApp, AppOpsManager.MODE_ALLOWED);
881 } catch (NameNotFoundException e) {
887 private static void resetDebuggerOptions() {
889 ActivityManagerNative.getDefault().setDebugApp(
891 } catch (RemoteException ex) {
895 private void updateDebuggerOptions() {
896 mDebugApp = Settings.Global.getString(
897 getActivity().getContentResolver(), Settings.Global.DEBUG_APP);
898 updateSwitchPreference(mWaitForDebugger, Settings.Global.getInt(
899 getActivity().getContentResolver(), Settings.Global.WAIT_FOR_DEBUGGER, 0) != 0);
900 if (mDebugApp != null && mDebugApp.length() > 0) {
903 ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(mDebugApp,
904 PackageManager.GET_DISABLED_COMPONENTS);
905 CharSequence lab = getActivity().getPackageManager().getApplicationLabel(ai);
906 label = lab != null ? lab.toString() : mDebugApp;
907 } catch (PackageManager.NameNotFoundException e) {
910 mDebugAppPref.setSummary(getResources().getString(R.string.debug_app_set, label));
911 mWaitForDebugger.setEnabled(true);
912 mHaveDebugSettings = true;
914 mDebugAppPref.setSummary(getResources().getString(R.string.debug_app_not_set));
915 mWaitForDebugger.setEnabled(false);
919 private void updateMockLocation() {
920 AppOpsManager appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE);
922 List<PackageOps> packageOps = appOpsManager.getPackagesForOps(MOCK_LOCATION_APP_OPS);
923 if (packageOps != null) {
924 for (PackageOps packageOp : packageOps) {
925 if (packageOp.getOps().get(0).getMode() == AppOpsManager.MODE_ALLOWED) {
926 mMockLocationApp = packageOps.get(0).getPackageName();
932 if (!TextUtils.isEmpty(mMockLocationApp)) {
933 String label = mMockLocationApp;
935 ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(
936 mMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS);
937 CharSequence appLabel = getPackageManager().getApplicationLabel(ai);
938 if (appLabel != null) {
939 label = appLabel.toString();
941 } catch (PackageManager.NameNotFoundException e) {
945 mMockLocationAppPref.setSummary(getString(R.string.mock_location_app_set, label));
946 mHaveDebugSettings = true;
948 mMockLocationAppPref.setSummary(getString(R.string.mock_location_app_not_set));
952 private void updateVerifyAppsOverUsbOptions() {
953 updateSwitchPreference(mVerifyAppsOverUsb, Settings.Global.getInt(getActivity().getContentResolver(),
954 Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1) != 0);
955 mVerifyAppsOverUsb.setEnabled(enableVerifierSetting());
958 private void writeVerifyAppsOverUsbOptions() {
959 Settings.Global.putInt(getActivity().getContentResolver(),
960 Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB,
961 mVerifyAppsOverUsb.isChecked() ? 1 : 0);
964 private void updateOtaDisableAutomaticUpdateOptions() {
965 // We use the "disabled status" in code, but show the opposite text
966 // "Automatic system updates" on screen. So a value 0 indicates the
967 // automatic update is enabled.
968 updateSwitchPreference(mOtaDisableAutomaticUpdate, Settings.Global.getInt(
969 getActivity().getContentResolver(),
970 Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, 0) != 1);
973 private void writeOtaDisableAutomaticUpdateOptions() {
974 // We use the "disabled status" in code, but show the opposite text
975 // "Automatic system updates" on screen. So a value 0 indicates the
976 // automatic update is enabled.
977 Settings.Global.putInt(getActivity().getContentResolver(),
978 Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE,
979 mOtaDisableAutomaticUpdate.isChecked() ? 0 : 1);
982 private boolean enableVerifierSetting() {
983 final ContentResolver cr = getActivity().getContentResolver();
984 if (Settings.Global.getInt(cr, Settings.Global.ADB_ENABLED, 0) == 0) {
987 if (Settings.Global.getInt(cr, Settings.Global.PACKAGE_VERIFIER_ENABLE, 1) == 0) {
990 final PackageManager pm = getActivity().getPackageManager();
991 final Intent verification = new Intent(Intent.ACTION_PACKAGE_NEEDS_VERIFICATION);
992 verification.setType(PACKAGE_MIME_TYPE);
993 verification.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
994 final List<ResolveInfo> receivers = pm.queryBroadcastReceivers(verification, 0);
995 if (receivers.size() == 0) {
1002 private boolean showVerifierSetting() {
1003 return Settings.Global.getInt(getActivity().getContentResolver(),
1004 Settings.Global.PACKAGE_VERIFIER_SETTING_VISIBLE, 1) > 0;
1007 private static boolean showEnableOemUnlockPreference() {
1008 return !SystemProperties.get(PERSISTENT_DATA_BLOCK_PROP).equals("");
1011 private boolean enableOemUnlockPreference() {
1012 int flashLockState = PersistentDataBlockManager.FLASH_LOCK_UNKNOWN;
1013 if (mOemUnlockManager != null) {
1014 flashLockState = mOemUnlockManager.getFlashLockState();
1017 return flashLockState != PersistentDataBlockManager.FLASH_LOCK_UNLOCKED;
1020 private void updateOemUnlockOptions() {
1021 if (mEnableOemUnlock != null) {
1022 mEnableOemUnlock.setEnabled(enableOemUnlockPreference());
1026 private void updateBugreportOptions() {
1027 mBugreport.setEnabled(true);
1028 mBugreportInPower.setEnabled(true);
1029 setBugreportStorageProviderStatus();
1032 private void setBugreportStorageProviderStatus() {
1033 final ComponentName componentName = new ComponentName("com.android.shell",
1034 "com.android.shell.BugreportStorageProvider");
1035 final boolean enabled = mBugreportInPower.isChecked();
1036 getPackageManager().setComponentEnabledSetting(componentName,
1037 enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
1038 : PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
1042 // Returns the current state of the system property that controls
1043 // strictmode flashes. One of:
1044 // 0: not explicitly set one way or another
1047 private static int currentStrictModeActiveIndex() {
1048 if (TextUtils.isEmpty(SystemProperties.get(StrictMode.VISUAL_PROPERTY))) {
1051 boolean enabled = SystemProperties.getBoolean(StrictMode.VISUAL_PROPERTY, false);
1052 return enabled ? 1 : 2;
1055 private void writeStrictModeVisualOptions() {
1057 mWindowManager.setStrictModeVisualIndicatorPreference(mStrictMode.isChecked()
1059 } catch (RemoteException e) {
1063 private void updateStrictModeVisualOptions() {
1064 updateSwitchPreference(mStrictMode, currentStrictModeActiveIndex() == 1);
1067 private void writePointerLocationOptions() {
1068 Settings.System.putInt(getActivity().getContentResolver(),
1069 Settings.System.POINTER_LOCATION, mPointerLocation.isChecked() ? 1 : 0);
1072 private void updatePointerLocationOptions() {
1073 updateSwitchPreference(mPointerLocation,
1074 Settings.System.getInt(getActivity().getContentResolver(),
1075 Settings.System.POINTER_LOCATION, 0) != 0);
1078 private void writeShowTouchesOptions() {
1079 Settings.System.putInt(getActivity().getContentResolver(),
1080 Settings.System.SHOW_TOUCHES, mShowTouches.isChecked() ? 1 : 0);
1083 private void updateShowTouchesOptions() {
1084 updateSwitchPreference(mShowTouches,
1085 Settings.System.getInt(getActivity().getContentResolver(),
1086 Settings.System.SHOW_TOUCHES, 0) != 0);
1089 private void updateFlingerOptions() {
1090 // magic communication with surface flinger.
1092 IBinder flinger = ServiceManager.getService("SurfaceFlinger");
1093 if (flinger != null) {
1094 Parcel data = Parcel.obtain();
1095 Parcel reply = Parcel.obtain();
1096 data.writeInterfaceToken("android.ui.ISurfaceComposer");
1097 flinger.transact(1010, data, reply, 0);
1098 @SuppressWarnings("unused")
1099 int showCpu = reply.readInt();
1100 @SuppressWarnings("unused")
1101 int enableGL = reply.readInt();
1102 int showUpdates = reply.readInt();
1103 updateSwitchPreference(mShowScreenUpdates, showUpdates != 0);
1104 @SuppressWarnings("unused")
1105 int showBackground = reply.readInt();
1106 int disableOverlays = reply.readInt();
1107 updateSwitchPreference(mDisableOverlays, disableOverlays != 0);
1111 } catch (RemoteException ex) {
1115 private void writeShowUpdatesOption() {
1117 IBinder flinger = ServiceManager.getService("SurfaceFlinger");
1118 if (flinger != null) {
1119 Parcel data = Parcel.obtain();
1120 data.writeInterfaceToken("android.ui.ISurfaceComposer");
1121 final int showUpdates = mShowScreenUpdates.isChecked() ? 1 : 0;
1122 data.writeInt(showUpdates);
1123 flinger.transact(1002, data, null, 0);
1126 updateFlingerOptions();
1128 } catch (RemoteException ex) {
1132 private void writeDisableOverlaysOption() {
1134 IBinder flinger = ServiceManager.getService("SurfaceFlinger");
1135 if (flinger != null) {
1136 Parcel data = Parcel.obtain();
1137 data.writeInterfaceToken("android.ui.ISurfaceComposer");
1138 final int disableOverlays = mDisableOverlays.isChecked() ? 1 : 0;
1139 data.writeInt(disableOverlays);
1140 flinger.transact(1008, data, null, 0);
1143 updateFlingerOptions();
1145 } catch (RemoteException ex) {
1149 private void updateHardwareUiOptions() {
1150 updateSwitchPreference(mForceHardwareUi,
1151 SystemProperties.getBoolean(HARDWARE_UI_PROPERTY, false));
1154 private void writeHardwareUiOptions() {
1155 SystemProperties.set(HARDWARE_UI_PROPERTY, mForceHardwareUi.isChecked() ? "true" : "false");
1156 pokeSystemProperties();
1159 private void updateMsaaOptions() {
1160 updateSwitchPreference(mForceMsaa, SystemProperties.getBoolean(MSAA_PROPERTY, false));
1163 private void writeMsaaOptions() {
1164 SystemProperties.set(MSAA_PROPERTY, mForceMsaa.isChecked() ? "true" : "false");
1165 pokeSystemProperties();
1168 private void updateTrackFrameTimeOptions() {
1169 String value = SystemProperties.get(ThreadedRenderer.PROFILE_PROPERTY);
1170 if (value == null) {
1174 CharSequence[] values = mTrackFrameTime.getEntryValues();
1175 for (int i = 0; i < values.length; i++) {
1176 if (value.contentEquals(values[i])) {
1177 mTrackFrameTime.setValueIndex(i);
1178 mTrackFrameTime.setSummary(mTrackFrameTime.getEntries()[i]);
1182 mTrackFrameTime.setValueIndex(0);
1183 mTrackFrameTime.setSummary(mTrackFrameTime.getEntries()[0]);
1186 private void writeTrackFrameTimeOptions(Object newValue) {
1187 SystemProperties.set(ThreadedRenderer.PROFILE_PROPERTY,
1188 newValue == null ? "" : newValue.toString());
1189 pokeSystemProperties();
1190 updateTrackFrameTimeOptions();
1193 private void updateShowNonRectClipOptions() {
1194 String value = SystemProperties.get(
1195 ThreadedRenderer.DEBUG_SHOW_NON_RECTANGULAR_CLIP_PROPERTY);
1196 if (value == null) {
1200 CharSequence[] values = mShowNonRectClip.getEntryValues();
1201 for (int i = 0; i < values.length; i++) {
1202 if (value.contentEquals(values[i])) {
1203 mShowNonRectClip.setValueIndex(i);
1204 mShowNonRectClip.setSummary(mShowNonRectClip.getEntries()[i]);
1208 mShowNonRectClip.setValueIndex(0);
1209 mShowNonRectClip.setSummary(mShowNonRectClip.getEntries()[0]);
1212 private void writeShowNonRectClipOptions(Object newValue) {
1213 SystemProperties.set(ThreadedRenderer.DEBUG_SHOW_NON_RECTANGULAR_CLIP_PROPERTY,
1214 newValue == null ? "" : newValue.toString());
1215 pokeSystemProperties();
1216 updateShowNonRectClipOptions();
1219 private void updateShowHwScreenUpdatesOptions() {
1220 updateSwitchPreference(mShowHwScreenUpdates,
1221 SystemProperties.getBoolean(ThreadedRenderer.DEBUG_DIRTY_REGIONS_PROPERTY, false));
1224 private void writeShowHwScreenUpdatesOptions() {
1225 SystemProperties.set(ThreadedRenderer.DEBUG_DIRTY_REGIONS_PROPERTY,
1226 mShowHwScreenUpdates.isChecked() ? "true" : null);
1227 pokeSystemProperties();
1230 private void updateShowHwLayersUpdatesOptions() {
1231 updateSwitchPreference(mShowHwLayersUpdates, SystemProperties.getBoolean(
1232 ThreadedRenderer.DEBUG_SHOW_LAYERS_UPDATES_PROPERTY, false));
1235 private void writeShowHwLayersUpdatesOptions() {
1236 SystemProperties.set(ThreadedRenderer.DEBUG_SHOW_LAYERS_UPDATES_PROPERTY,
1237 mShowHwLayersUpdates.isChecked() ? "true" : null);
1238 pokeSystemProperties();
1241 private void updateDebugHwOverdrawOptions() {
1242 String value = SystemProperties.get(ThreadedRenderer.DEBUG_OVERDRAW_PROPERTY);
1243 if (value == null) {
1247 CharSequence[] values = mDebugHwOverdraw.getEntryValues();
1248 for (int i = 0; i < values.length; i++) {
1249 if (value.contentEquals(values[i])) {
1250 mDebugHwOverdraw.setValueIndex(i);
1251 mDebugHwOverdraw.setSummary(mDebugHwOverdraw.getEntries()[i]);
1255 mDebugHwOverdraw.setValueIndex(0);
1256 mDebugHwOverdraw.setSummary(mDebugHwOverdraw.getEntries()[0]);
1259 private void writeDebugHwOverdrawOptions(Object newValue) {
1260 SystemProperties.set(ThreadedRenderer.DEBUG_OVERDRAW_PROPERTY,
1261 newValue == null ? "" : newValue.toString());
1262 pokeSystemProperties();
1263 updateDebugHwOverdrawOptions();
1266 private void updateDebugLayoutOptions() {
1267 updateSwitchPreference(mDebugLayout,
1268 SystemProperties.getBoolean(View.DEBUG_LAYOUT_PROPERTY, false));
1271 private void writeDebugLayoutOptions() {
1272 SystemProperties.set(View.DEBUG_LAYOUT_PROPERTY,
1273 mDebugLayout.isChecked() ? "true" : "false");
1274 pokeSystemProperties();
1277 private void updateSimulateColorSpace() {
1278 final ContentResolver cr = getContentResolver();
1279 final boolean enabled = Settings.Secure.getInt(
1280 cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0) != 0;
1282 final String mode = Integer.toString(Settings.Secure.getInt(
1283 cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER,
1284 AccessibilityManager.DALTONIZER_DISABLED));
1285 mSimulateColorSpace.setValue(mode);
1286 final int index = mSimulateColorSpace.findIndexOfValue(mode);
1288 // We're using a mode controlled by accessibility preferences.
1289 mSimulateColorSpace.setSummary(getString(R.string.daltonizer_type_overridden,
1290 getString(R.string.accessibility_display_daltonizer_preference_title)));
1292 mSimulateColorSpace.setSummary("%s");
1295 mSimulateColorSpace.setValue(
1296 Integer.toString(AccessibilityManager.DALTONIZER_DISABLED));
1301 * @return <code>true</code> if the color space preference is currently
1302 * controlled by development settings
1304 private boolean usingDevelopmentColorSpace() {
1305 final ContentResolver cr = getContentResolver();
1306 final boolean enabled = Settings.Secure.getInt(
1307 cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0) != 0;
1309 final String mode = Integer.toString(Settings.Secure.getInt(
1310 cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER,
1311 AccessibilityManager.DALTONIZER_DISABLED));
1312 final int index = mSimulateColorSpace.findIndexOfValue(mode);
1314 // We're using a mode controlled by developer preferences.
1321 private void writeSimulateColorSpace(Object value) {
1322 final ContentResolver cr = getContentResolver();
1323 final int newMode = Integer.parseInt(value.toString());
1325 Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0);
1327 Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 1);
1328 Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER, newMode);
1332 private void updateColorTemperature() {
1333 updateSwitchPreference(mColorTemperaturePreference,
1334 SystemProperties.getBoolean(COLOR_TEMPERATURE_PROPERTY, false));
1337 private void writeColorTemperature() {
1338 SystemProperties.set(COLOR_TEMPERATURE_PROPERTY,
1339 mColorTemperaturePreference.isChecked() ? "1" : "0");
1340 pokeSystemProperties();
1341 Toast.makeText(getActivity(), R.string.color_temperature_toast, Toast.LENGTH_LONG).show();
1344 private void updateUSBAudioOptions() {
1345 updateSwitchPreference(mUSBAudio, Settings.Secure.getInt(getContentResolver(),
1346 Settings.Secure.USB_AUDIO_AUTOMATIC_ROUTING_DISABLED, 0) != 0);
1349 private void writeUSBAudioOptions() {
1350 Settings.Secure.putInt(getContentResolver(),
1351 Settings.Secure.USB_AUDIO_AUTOMATIC_ROUTING_DISABLED,
1352 mUSBAudio.isChecked() ? 1 : 0);
1355 private void updateForceResizableOptions() {
1356 updateSwitchPreference(mForceResizable, Settings.Global.getInt(getContentResolver(),
1357 Settings.Global.DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES, 0) != 0);
1360 private void writeForceResizableOptions() {
1361 Settings.Global.putInt(getContentResolver(),
1362 Settings.Global.DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES,
1363 mForceResizable.isChecked() ? 1 : 0);
1366 private void updateForceRtlOptions() {
1367 updateSwitchPreference(mForceRtlLayout,
1368 Settings.Global.getInt(getActivity().getContentResolver(),
1369 Settings.Global.DEVELOPMENT_FORCE_RTL, 0) != 0);
1372 private void writeForceRtlOptions() {
1373 boolean value = mForceRtlLayout.isChecked();
1374 Settings.Global.putInt(getActivity().getContentResolver(),
1375 Settings.Global.DEVELOPMENT_FORCE_RTL, value ? 1 : 0);
1376 SystemProperties.set(Settings.Global.DEVELOPMENT_FORCE_RTL, value ? "1" : "0");
1377 LocalePicker.updateLocale(getActivity().getResources().getConfiguration().locale);
1380 private void updateWifiDisplayCertificationOptions() {
1381 updateSwitchPreference(mWifiDisplayCertification, Settings.Global.getInt(
1382 getActivity().getContentResolver(),
1383 Settings.Global.WIFI_DISPLAY_CERTIFICATION_ON, 0) != 0);
1386 private void writeWifiDisplayCertificationOptions() {
1387 Settings.Global.putInt(getActivity().getContentResolver(),
1388 Settings.Global.WIFI_DISPLAY_CERTIFICATION_ON,
1389 mWifiDisplayCertification.isChecked() ? 1 : 0);
1392 private void updateWifiVerboseLoggingOptions() {
1393 boolean enabled = mWifiManager.getVerboseLoggingLevel() > 0;
1394 updateSwitchPreference(mWifiVerboseLogging, enabled);
1397 private void writeWifiVerboseLoggingOptions() {
1398 mWifiManager.enableVerboseLogging(mWifiVerboseLogging.isChecked() ? 1 : 0);
1401 private void updateWifiAggressiveHandoverOptions() {
1402 boolean enabled = mWifiManager.getAggressiveHandover() > 0;
1403 updateSwitchPreference(mWifiAggressiveHandover, enabled);
1406 private void writeWifiAggressiveHandoverOptions() {
1407 mWifiManager.enableAggressiveHandover(mWifiAggressiveHandover.isChecked() ? 1 : 0);
1410 private void updateWifiAllowScansWithTrafficOptions() {
1411 boolean enabled = mWifiManager.getAllowScansWithTraffic() > 0;
1412 updateSwitchPreference(mWifiAllowScansWithTraffic, enabled);
1415 private void writeWifiAllowScansWithTrafficOptions() {
1416 mWifiManager.setAllowScansWithTraffic(mWifiAllowScansWithTraffic.isChecked() ? 1 : 0);
1419 private void updateBluetoothDisableAbsVolumeOptions() {
1420 updateSwitchPreference(mBluetoothDisableAbsVolume,
1421 SystemProperties.getBoolean(BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_PROPERTY, false));
1424 private void writeBluetoothDisableAbsVolumeOptions() {
1425 SystemProperties.set(BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_PROPERTY,
1426 mBluetoothDisableAbsVolume.isChecked() ? "true" : "false");
1429 private void updateMobileDataAlwaysOnOptions() {
1430 updateSwitchPreference(mMobileDataAlwaysOn, Settings.Global.getInt(
1431 getActivity().getContentResolver(),
1432 Settings.Global.MOBILE_DATA_ALWAYS_ON, 0) != 0);
1435 private void writeMobileDataAlwaysOnOptions() {
1436 Settings.Global.putInt(getActivity().getContentResolver(),
1437 Settings.Global.MOBILE_DATA_ALWAYS_ON,
1438 mMobileDataAlwaysOn.isChecked() ? 1 : 0);
1441 private String defaultLogdSizeValue() {
1442 String defaultValue = SystemProperties.get(SELECT_LOGD_DEFAULT_SIZE_PROPERTY);
1443 if ((defaultValue == null) || (defaultValue.length() == 0)) {
1444 if (SystemProperties.get("ro.config.low_ram").equals("true")) {
1445 defaultValue = SELECT_LOGD_SVELTE_DEFAULT_SIZE_VALUE;
1447 defaultValue = SELECT_LOGD_DEFAULT_SIZE_VALUE;
1450 return defaultValue;
1453 private void updateLogdSizeValues() {
1454 if (mLogdSize != null) {
1455 String currentTag = SystemProperties.get(SELECT_LOGD_TAG_PROPERTY);
1456 String currentValue = SystemProperties.get(SELECT_LOGD_SIZE_PROPERTY);
1457 if ((currentTag != null) && currentTag.startsWith(SELECT_LOGD_TAG_SILENCE)) {
1458 currentValue = SELECT_LOGD_OFF_SIZE_MARKER_VALUE;
1460 if ((currentValue == null) || (currentValue.length() == 0)) {
1461 currentValue = defaultLogdSizeValue();
1463 String[] values = getResources().getStringArray(R.array.select_logd_size_values);
1464 String[] titles = getResources().getStringArray(R.array.select_logd_size_titles);
1465 int index = 2; // punt to second entry if not found
1466 if (SystemProperties.get("ro.config.low_ram").equals("true")) {
1467 mLogdSize.setEntries(R.array.select_logd_size_lowram_titles);
1468 titles = getResources().getStringArray(R.array.select_logd_size_lowram_titles);
1471 String[] summaries = getResources().getStringArray(R.array.select_logd_size_summaries);
1472 for (int i = 0; i < titles.length; i++) {
1473 if (currentValue.equals(values[i])
1474 || currentValue.equals(titles[i])) {
1479 mLogdSize.setValue(values[index]);
1480 mLogdSize.setSummary(summaries[index]);
1481 mLogdSize.setOnPreferenceChangeListener(this);
1485 private void writeLogdSizeOption(Object newValue) {
1486 boolean disable = (newValue != null) &&
1487 (newValue.toString().equals(SELECT_LOGD_OFF_SIZE_MARKER_VALUE));
1488 String currentTag = SystemProperties.get(SELECT_LOGD_TAG_PROPERTY);
1489 if (currentTag == null) {
1492 // filter clean and unstack all references to our setting
1493 String newTag = currentTag.replaceAll(
1494 ",+" + SELECT_LOGD_TAG_SILENCE, "").replaceFirst(
1495 "^" + SELECT_LOGD_TAG_SILENCE + ",*", "").replaceAll(
1496 ",+", ",").replaceFirst(
1499 newValue = SELECT_LOGD_MINIMUM_SIZE_VALUE;
1500 // Make sure snet_event_log get through first, but do not override
1501 String snetValue = SystemProperties.get(SELECT_LOGD_SNET_TAG_PROPERTY);
1502 if ((snetValue == null) || (snetValue.length() == 0)) {
1503 snetValue = SystemProperties.get(SELECT_LOGD_RUNTIME_SNET_TAG_PROPERTY);
1504 if ((snetValue == null) || (snetValue.length() == 0)) {
1505 SystemProperties.set(SELECT_LOGD_SNET_TAG_PROPERTY, "I");
1508 // Silence all log sources, security logs notwithstanding
1509 if (newTag.length() != 0) {
1510 newTag = "," + newTag;
1512 // Stack settings, stack to help preserve original value
1513 newTag = SELECT_LOGD_TAG_SILENCE + newTag;
1515 if (!newTag.equals(currentTag)) {
1516 SystemProperties.set(SELECT_LOGD_TAG_PROPERTY, newTag);
1518 String defaultValue = defaultLogdSizeValue();
1519 final String size = ((newValue != null) && (newValue.toString().length() != 0)) ?
1520 newValue.toString() : defaultValue;
1521 SystemProperties.set(SELECT_LOGD_SIZE_PROPERTY, defaultValue.equals(size) ? "" : size);
1522 SystemProperties.set("ctl.start", "logd-reinit");
1523 pokeSystemProperties();
1524 updateLogdSizeValues();
1527 private void updateUsbConfigurationValues() {
1528 if (mUsbConfiguration != null) {
1529 UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
1531 String[] values = getResources().getStringArray(R.array.usb_configuration_values);
1532 String[] titles = getResources().getStringArray(R.array.usb_configuration_titles);
1534 for (int i = 0; i < titles.length; i++) {
1535 if (manager.isFunctionEnabled(values[i])) {
1540 mUsbConfiguration.setValue(values[index]);
1541 mUsbConfiguration.setSummary(titles[index]);
1542 mUsbConfiguration.setOnPreferenceChangeListener(this);
1546 private void writeUsbConfigurationOption(Object newValue) {
1547 UsbManager manager = (UsbManager)getActivity().getSystemService(Context.USB_SERVICE);
1548 String function = newValue.toString();
1549 manager.setCurrentFunction(function);
1550 if (function.equals("none")) {
1551 manager.setUsbDataUnlocked(false);
1553 manager.setUsbDataUnlocked(true);
1557 private void updateCpuUsageOptions() {
1558 updateSwitchPreference(mShowCpuUsage,
1559 Settings.Global.getInt(getActivity().getContentResolver(),
1560 Settings.Global.SHOW_PROCESSES, 0) != 0);
1563 private void writeCpuUsageOptions() {
1564 boolean value = mShowCpuUsage.isChecked();
1565 Settings.Global.putInt(getActivity().getContentResolver(),
1566 Settings.Global.SHOW_PROCESSES, value ? 1 : 0);
1567 Intent service = (new Intent())
1568 .setClassName("com.android.systemui", "com.android.systemui.LoadAverageService");
1570 getActivity().startService(service);
1572 getActivity().stopService(service);
1576 private void writeImmediatelyDestroyActivitiesOptions() {
1578 ActivityManagerNative.getDefault().setAlwaysFinish(
1579 mImmediatelyDestroyActivities.isChecked());
1580 } catch (RemoteException ex) {
1584 private void updateImmediatelyDestroyActivitiesOptions() {
1585 updateSwitchPreference(mImmediatelyDestroyActivities, Settings.Global.getInt(
1586 getActivity().getContentResolver(), Settings.Global.ALWAYS_FINISH_ACTIVITIES, 0) != 0);
1589 private void updateAnimationScaleValue(int which, ListPreference pref) {
1591 float scale = mWindowManager.getAnimationScale(which);
1593 mHaveDebugSettings = true;
1595 CharSequence[] values = pref.getEntryValues();
1596 for (int i=0; i<values.length; i++) {
1597 float val = Float.parseFloat(values[i].toString());
1599 pref.setValueIndex(i);
1600 pref.setSummary(pref.getEntries()[i]);
1604 pref.setValueIndex(values.length-1);
1605 pref.setSummary(pref.getEntries()[0]);
1606 } catch (RemoteException e) {
1610 private void updateAnimationScaleOptions() {
1611 updateAnimationScaleValue(0, mWindowAnimationScale);
1612 updateAnimationScaleValue(1, mTransitionAnimationScale);
1613 updateAnimationScaleValue(2, mAnimatorDurationScale);
1616 private void writeAnimationScaleOption(int which, ListPreference pref, Object newValue) {
1618 float scale = newValue != null ? Float.parseFloat(newValue.toString()) : 1;
1619 mWindowManager.setAnimationScale(which, scale);
1620 updateAnimationScaleValue(which, pref);
1621 } catch (RemoteException e) {
1625 private void updateOverlayDisplayDevicesOptions() {
1626 String value = Settings.Global.getString(getActivity().getContentResolver(),
1627 Settings.Global.OVERLAY_DISPLAY_DEVICES);
1628 if (value == null) {
1632 CharSequence[] values = mOverlayDisplayDevices.getEntryValues();
1633 for (int i = 0; i < values.length; i++) {
1634 if (value.contentEquals(values[i])) {
1635 mOverlayDisplayDevices.setValueIndex(i);
1636 mOverlayDisplayDevices.setSummary(mOverlayDisplayDevices.getEntries()[i]);
1640 mOverlayDisplayDevices.setValueIndex(0);
1641 mOverlayDisplayDevices.setSummary(mOverlayDisplayDevices.getEntries()[0]);
1644 private void writeOverlayDisplayDevicesOptions(Object newValue) {
1645 Settings.Global.putString(getActivity().getContentResolver(),
1646 Settings.Global.OVERLAY_DISPLAY_DEVICES, (String) newValue);
1647 updateOverlayDisplayDevicesOptions();
1650 private void updateAppProcessLimitOptions() {
1652 int limit = ActivityManagerNative.getDefault().getProcessLimit();
1653 CharSequence[] values = mAppProcessLimit.getEntryValues();
1654 for (int i=0; i<values.length; i++) {
1655 int val = Integer.parseInt(values[i].toString());
1658 mHaveDebugSettings = true;
1660 mAppProcessLimit.setValueIndex(i);
1661 mAppProcessLimit.setSummary(mAppProcessLimit.getEntries()[i]);
1665 mAppProcessLimit.setValueIndex(0);
1666 mAppProcessLimit.setSummary(mAppProcessLimit.getEntries()[0]);
1667 } catch (RemoteException e) {
1671 private void writeAppProcessLimitOptions(Object newValue) {
1673 int limit = newValue != null ? Integer.parseInt(newValue.toString()) : -1;
1674 ActivityManagerNative.getDefault().setProcessLimit(limit);
1675 updateAppProcessLimitOptions();
1676 } catch (RemoteException e) {
1680 private void writeShowAllANRsOptions() {
1681 Settings.Secure.putInt(getActivity().getContentResolver(),
1682 Settings.Secure.ANR_SHOW_BACKGROUND,
1683 mShowAllANRs.isChecked() ? 1 : 0);
1686 private void updateShowAllANRsOptions() {
1687 updateSwitchPreference(mShowAllANRs, Settings.Secure.getInt(
1688 getActivity().getContentResolver(), Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0);
1691 private void confirmEnableOemUnlock() {
1692 DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener() {
1694 public void onClick(DialogInterface dialog, int which) {
1695 if (which == DialogInterface.BUTTON_POSITIVE) {
1696 Utils.setOemUnlockEnabled(getActivity(), true);
1701 DialogInterface.OnDismissListener onDismissListener = new DialogInterface.OnDismissListener() {
1703 public void onDismiss(DialogInterface dialog) {
1704 if (getActivity() == null) {
1711 new AlertDialog.Builder(getActivity())
1712 .setTitle(R.string.confirm_enable_oem_unlock_title)
1713 .setMessage(R.string.confirm_enable_oem_unlock_text)
1714 .setPositiveButton(R.string.enable_text, onClickListener)
1715 .setNegativeButton(android.R.string.cancel, null)
1716 .setOnDismissListener(onDismissListener)
1722 public void onSwitchChanged(Switch switchView, boolean isChecked) {
1723 if (switchView != mSwitchBar.getSwitch()) {
1726 if (isChecked != mLastEnabledState) {
1728 mDialogClicked = false;
1729 if (mEnableDialog != null) dismissDialogs();
1730 mEnableDialog = new AlertDialog.Builder(getActivity()).setMessage(
1731 getActivity().getResources().getString(
1732 R.string.dev_settings_warning_message))
1733 .setTitle(R.string.dev_settings_warning_title)
1734 .setPositiveButton(android.R.string.yes, this)
1735 .setNegativeButton(android.R.string.no, this)
1737 mEnableDialog.setOnDismissListener(this);
1739 resetDangerousOptions();
1740 Settings.Global.putInt(getActivity().getContentResolver(),
1741 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
1742 mLastEnabledState = isChecked;
1743 setPrefsEnabledState(mLastEnabledState);
1749 public void onActivityResult(int requestCode, int resultCode, Intent data) {
1750 if (requestCode == RESULT_DEBUG_APP) {
1751 if (resultCode == Activity.RESULT_OK) {
1752 mDebugApp = data.getAction();
1753 writeDebuggerOptions();
1754 updateDebuggerOptions();
1756 } else if (requestCode == RESULT_MOCK_LOCATION_APP) {
1757 if (resultCode == Activity.RESULT_OK) {
1758 mMockLocationApp = data.getAction();
1759 writeMockLocation();
1760 updateMockLocation();
1762 } else if (requestCode == REQUEST_CODE_ENABLE_OEM_UNLOCK) {
1763 if (resultCode == Activity.RESULT_OK) {
1764 if (mEnableOemUnlock.isChecked()) {
1765 confirmEnableOemUnlock();
1767 Utils.setOemUnlockEnabled(getActivity(), false);
1771 super.onActivityResult(requestCode, resultCode, data);
1776 public boolean onPreferenceTreeClick(Preference preference) {
1777 if (Utils.isMonkeyRunning()) {
1781 if (preference == mEnableAdb) {
1782 if (mEnableAdb.isChecked()) {
1783 mDialogClicked = false;
1784 if (mAdbDialog != null) dismissDialogs();
1785 mAdbDialog = new AlertDialog.Builder(getActivity()).setMessage(
1786 getActivity().getResources().getString(R.string.adb_warning_message))
1787 .setTitle(R.string.adb_warning_title)
1788 .setPositiveButton(android.R.string.yes, this)
1789 .setNegativeButton(android.R.string.no, this)
1791 mAdbDialog.setOnDismissListener(this);
1793 Settings.Global.putInt(getActivity().getContentResolver(),
1794 Settings.Global.ADB_ENABLED, 0);
1795 mVerifyAppsOverUsb.setEnabled(false);
1796 mVerifyAppsOverUsb.setChecked(false);
1797 updateBugreportOptions();
1799 } else if (preference == mClearAdbKeys) {
1800 if (mAdbKeysDialog != null) dismissDialogs();
1801 mAdbKeysDialog = new AlertDialog.Builder(getActivity())
1802 .setMessage(R.string.adb_keys_warning_message)
1803 .setPositiveButton(android.R.string.ok, this)
1804 .setNegativeButton(android.R.string.cancel, null)
1806 } else if (preference == mEnableTerminal) {
1807 final PackageManager pm = getActivity().getPackageManager();
1808 pm.setApplicationEnabledSetting(TERMINAL_APP_PACKAGE,
1809 mEnableTerminal.isChecked() ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
1810 : PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
1811 } else if (preference == mBugreportInPower) {
1812 Settings.Secure.putInt(getActivity().getContentResolver(),
1813 Settings.Global.BUGREPORT_IN_POWER_MENU,
1814 mBugreportInPower.isChecked() ? 1 : 0);
1815 setBugreportStorageProviderStatus();
1816 } else if (preference == mKeepScreenOn) {
1817 Settings.Global.putInt(getActivity().getContentResolver(),
1818 Settings.Global.STAY_ON_WHILE_PLUGGED_IN,
1819 mKeepScreenOn.isChecked() ?
1820 (BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB) : 0);
1821 } else if (preference == mBtHciSnoopLog) {
1822 writeBtHciSnoopLogOptions();
1823 } else if (preference == mEnableOemUnlock && mEnableOemUnlock.isEnabled()) {
1824 if (mEnableOemUnlock.isChecked()) {
1825 if (!showKeyguardConfirmation(getResources(), REQUEST_CODE_ENABLE_OEM_UNLOCK)) {
1826 confirmEnableOemUnlock();
1829 Utils.setOemUnlockEnabled(getActivity(), false);
1831 } else if (preference == mMockLocationAppPref) {
1832 Intent intent = new Intent(getActivity(), AppPicker.class);
1833 intent.putExtra(AppPicker.EXTRA_REQUESTIING_PERMISSION,
1834 Manifest.permission.ACCESS_MOCK_LOCATION);
1835 startActivityForResult(intent, RESULT_MOCK_LOCATION_APP);
1836 } else if (preference == mDebugViewAttributes) {
1837 Settings.Global.putInt(getActivity().getContentResolver(),
1838 Settings.Global.DEBUG_VIEW_ATTRIBUTES,
1839 mDebugViewAttributes.isChecked() ? 1 : 0);
1840 } else if (preference == mForceAllowOnExternal) {
1841 Settings.Global.putInt(getActivity().getContentResolver(),
1842 Settings.Global.FORCE_ALLOW_ON_EXTERNAL,
1843 mForceAllowOnExternal.isChecked() ? 1 : 0);
1844 } else if (preference == mDebugAppPref) {
1845 Intent intent = new Intent(getActivity(), AppPicker.class);
1846 intent.putExtra(AppPicker.EXTRA_DEBUGGABLE, true);
1847 startActivityForResult(intent, RESULT_DEBUG_APP);
1848 } else if (preference == mWaitForDebugger) {
1849 writeDebuggerOptions();
1850 } else if (preference == mVerifyAppsOverUsb) {
1851 writeVerifyAppsOverUsbOptions();
1852 } else if (preference == mOtaDisableAutomaticUpdate) {
1853 writeOtaDisableAutomaticUpdateOptions();
1854 } else if (preference == mStrictMode) {
1855 writeStrictModeVisualOptions();
1856 } else if (preference == mPointerLocation) {
1857 writePointerLocationOptions();
1858 } else if (preference == mShowTouches) {
1859 writeShowTouchesOptions();
1860 } else if (preference == mShowScreenUpdates) {
1861 writeShowUpdatesOption();
1862 } else if (preference == mDisableOverlays) {
1863 writeDisableOverlaysOption();
1864 } else if (preference == mShowCpuUsage) {
1865 writeCpuUsageOptions();
1866 } else if (preference == mImmediatelyDestroyActivities) {
1867 writeImmediatelyDestroyActivitiesOptions();
1868 } else if (preference == mShowAllANRs) {
1869 writeShowAllANRsOptions();
1870 } else if (preference == mForceHardwareUi) {
1871 writeHardwareUiOptions();
1872 } else if (preference == mForceMsaa) {
1874 } else if (preference == mShowHwScreenUpdates) {
1875 writeShowHwScreenUpdatesOptions();
1876 } else if (preference == mShowHwLayersUpdates) {
1877 writeShowHwLayersUpdatesOptions();
1878 } else if (preference == mDebugLayout) {
1879 writeDebugLayoutOptions();
1880 } else if (preference == mForceRtlLayout) {
1881 writeForceRtlOptions();
1882 } else if (preference == mWifiDisplayCertification) {
1883 writeWifiDisplayCertificationOptions();
1884 } else if (preference == mWifiVerboseLogging) {
1885 writeWifiVerboseLoggingOptions();
1886 } else if (preference == mWifiAggressiveHandover) {
1887 writeWifiAggressiveHandoverOptions();
1888 } else if (preference == mWifiAllowScansWithTraffic) {
1889 writeWifiAllowScansWithTrafficOptions();
1890 } else if (preference == mMobileDataAlwaysOn) {
1891 writeMobileDataAlwaysOnOptions();
1892 } else if (preference == mColorTemperaturePreference) {
1893 writeColorTemperature();
1894 } else if (preference == mUSBAudio) {
1895 writeUSBAudioOptions();
1896 } else if (preference == mForceResizable) {
1897 writeForceResizableOptions();
1898 } else if (INACTIVE_APPS_KEY.equals(preference.getKey())) {
1899 startInactiveAppsFragment();
1900 } else if (BACKGROUND_CHECK_KEY.equals(preference.getKey())) {
1901 startBackgroundCheckFragment();
1902 } else if (preference == mBluetoothDisableAbsVolume) {
1903 writeBluetoothDisableAbsVolumeOptions();
1904 } else if (preference == mWebViewMultiprocess) {
1905 writeWebViewMultiprocessOptions();
1906 } else if (SHORTCUT_MANAGER_RESET_KEY.equals(preference.getKey())) {
1907 confirmResetShortcutManagerThrottling();
1909 return super.onPreferenceTreeClick(preference);
1915 private void startInactiveAppsFragment() {
1916 ((SettingsActivity) getActivity()).startPreferencePanel(
1917 InactiveApps.class.getName(),
1918 null, R.string.inactive_apps_title, null, null, 0);
1921 private void startBackgroundCheckFragment() {
1922 ((SettingsActivity) getActivity()).startPreferencePanel(
1923 BackgroundCheckSummary.class.getName(),
1924 null, R.string.background_check_title, null, null, 0);
1927 private boolean showKeyguardConfirmation(Resources resources, int requestCode) {
1928 return new ChooseLockSettingsHelper(getActivity(), this).launchConfirmationActivity(
1929 requestCode, resources.getString(R.string.oem_unlock_enable));
1932 private boolean isPackageEnabled(String packageName) {
1934 return getActivity().getPackageManager().getApplicationInfo(packageName, 0).enabled;
1935 } catch (NameNotFoundException e) {
1936 // Thrown by PackageManager.getApplicationInfo if the package does not exist
1942 public boolean onPreferenceChange(Preference preference, Object newValue) {
1943 if (HDCP_CHECKING_KEY.equals(preference.getKey())) {
1944 SystemProperties.set(HDCP_CHECKING_PROPERTY, newValue.toString());
1946 pokeSystemProperties();
1948 } else if (preference == mWebViewProvider) {
1949 if (newValue == null) {
1950 Log.e(TAG, "Tried to set a null WebView provider");
1953 if (writeWebViewProviderOptions(newValue)) {
1956 // The user chose a package that became invalid since the list was last updated,
1957 // show a Toast to explain the situation.
1958 Toast toast = Toast.makeText(getActivity(),
1959 R.string.select_webview_provider_toast_text, Toast.LENGTH_SHORT);
1963 } else if (preference == mLogdSize) {
1964 writeLogdSizeOption(newValue);
1966 } else if (preference == mUsbConfiguration) {
1967 writeUsbConfigurationOption(newValue);
1969 } else if (preference == mWindowAnimationScale) {
1970 writeAnimationScaleOption(0, mWindowAnimationScale, newValue);
1972 } else if (preference == mTransitionAnimationScale) {
1973 writeAnimationScaleOption(1, mTransitionAnimationScale, newValue);
1975 } else if (preference == mAnimatorDurationScale) {
1976 writeAnimationScaleOption(2, mAnimatorDurationScale, newValue);
1978 } else if (preference == mOverlayDisplayDevices) {
1979 writeOverlayDisplayDevicesOptions(newValue);
1981 } else if (preference == mTrackFrameTime) {
1982 writeTrackFrameTimeOptions(newValue);
1984 } else if (preference == mDebugHwOverdraw) {
1985 writeDebugHwOverdrawOptions(newValue);
1987 } else if (preference == mShowNonRectClip) {
1988 writeShowNonRectClipOptions(newValue);
1990 } else if (preference == mAppProcessLimit) {
1991 writeAppProcessLimitOptions(newValue);
1993 } else if (preference == mSimulateColorSpace) {
1994 writeSimulateColorSpace(newValue);
2000 private void dismissDialogs() {
2001 if (mAdbDialog != null) {
2002 mAdbDialog.dismiss();
2005 if (mAdbKeysDialog != null) {
2006 mAdbKeysDialog.dismiss();
2007 mAdbKeysDialog = null;
2009 if (mEnableDialog != null) {
2010 mEnableDialog.dismiss();
2011 mEnableDialog = null;
2015 public void onClick(DialogInterface dialog, int which) {
2016 if (dialog == mAdbDialog) {
2017 if (which == DialogInterface.BUTTON_POSITIVE) {
2018 mDialogClicked = true;
2019 Settings.Global.putInt(getActivity().getContentResolver(),
2020 Settings.Global.ADB_ENABLED, 1);
2021 mVerifyAppsOverUsb.setEnabled(true);
2022 updateVerifyAppsOverUsbOptions();
2023 updateBugreportOptions();
2026 mEnableAdb.setChecked(false);
2028 } else if (dialog == mAdbKeysDialog) {
2029 if (which == DialogInterface.BUTTON_POSITIVE) {
2031 IBinder b = ServiceManager.getService(Context.USB_SERVICE);
2032 IUsbManager service = IUsbManager.Stub.asInterface(b);
2033 service.clearUsbDebuggingKeys();
2034 } catch (RemoteException e) {
2035 Log.e(TAG, "Unable to clear adb keys", e);
2038 } else if (dialog == mEnableDialog) {
2039 if (which == DialogInterface.BUTTON_POSITIVE) {
2040 mDialogClicked = true;
2041 Settings.Global.putInt(getActivity().getContentResolver(),
2042 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
2043 mLastEnabledState = true;
2044 setPrefsEnabledState(mLastEnabledState);
2047 mSwitchBar.setChecked(false);
2052 public void onDismiss(DialogInterface dialog) {
2053 // Assuming that onClick gets called first
2054 if (dialog == mAdbDialog) {
2055 if (!mDialogClicked) {
2056 mEnableAdb.setChecked(false);
2059 } else if (dialog == mEnableDialog) {
2060 if (!mDialogClicked) {
2061 mSwitchBar.setChecked(false);
2063 mEnableDialog = null;
2068 public void onDestroy() {
2073 void pokeSystemProperties() {
2074 if (!mDontPokeProperties) {
2075 //noinspection unchecked
2076 (new SystemPropPoker()).execute();
2080 private BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
2082 public void onReceive(Context context, Intent intent) {
2083 updateUsbConfigurationValues();
2087 static class SystemPropPoker extends AsyncTask<Void, Void, Void> {
2089 protected Void doInBackground(Void... params) {
2090 String[] services = ServiceManager.listServices();
2091 for (String service : services) {
2092 IBinder obj = ServiceManager.checkService(service);
2094 Parcel data = Parcel.obtain();
2096 obj.transact(IBinder.SYSPROPS_TRANSACTION, data, null, 0);
2097 } catch (RemoteException e) {
2098 } catch (Exception e) {
2099 Log.i(TAG, "Someone wrote a bad service '" + service
2100 + "' that doesn't like to be poked: " + e);
2109 private static boolean isPackageInstalled(Context context, String packageName) {
2111 return context.getPackageManager().getPackageInfo(packageName, 0) != null;
2112 } catch (NameNotFoundException e) {
2121 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
2122 new BaseSearchIndexProvider() {
2124 private boolean isShowingDeveloperOptions(Context context) {
2125 return context.getSharedPreferences(DevelopmentSettings.PREF_FILE,
2126 Context.MODE_PRIVATE).getBoolean(
2127 DevelopmentSettings.PREF_SHOW,
2128 android.os.Build.TYPE.equals("eng"));
2132 public List<SearchIndexableResource> getXmlResourcesToIndex(
2133 Context context, boolean enabled) {
2135 if (!isShowingDeveloperOptions(context)) {
2139 final SearchIndexableResource sir = new SearchIndexableResource(context);
2140 sir.xmlResId = R.xml.development_prefs;
2141 return Arrays.asList(sir);
2145 public List<String> getNonIndexableKeys(Context context) {
2146 if (!isShowingDeveloperOptions(context)) {
2150 final List<String> keys = new ArrayList<String>();
2151 if (!showEnableOemUnlockPreference()) {
2152 keys.add(ENABLE_OEM_UNLOCK);
2158 private void confirmResetShortcutManagerThrottling() {
2159 final IShortcutService service = IShortcutService.Stub.asInterface(
2160 ServiceManager.getService(Context.SHORTCUT_SERVICE));
2162 DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener() {
2164 public void onClick(DialogInterface dialog, int which) {
2165 if (which == DialogInterface.BUTTON_POSITIVE) {
2167 service.resetThrottling();
2168 } catch (RemoteException e) {
2174 new AlertDialog.Builder(getActivity())
2175 .setTitle(R.string.confirm_reset_shortcut_manager_throttling_title)
2176 .setMessage(R.string.confirm_reset_shortcut_manager_throttling_message)
2177 .setPositiveButton(R.string.okay, onClickListener)
2178 .setNegativeButton(android.R.string.cancel, null)