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.app.Activity;
20 import android.app.ActivityManagerNative;
21 import android.app.AlertDialog;
22 import android.app.Dialog;
23 import android.app.admin.DevicePolicyManager;
24 import android.app.backup.IBackupManager;
25 import android.bluetooth.BluetoothAdapter;
26 import android.content.ContentResolver;
27 import android.content.Context;
28 import android.content.DialogInterface;
29 import android.content.Intent;
30 import android.content.pm.ApplicationInfo;
31 import android.content.pm.PackageManager;
32 import android.content.pm.PackageManager.NameNotFoundException;
33 import android.content.pm.ResolveInfo;
34 import android.content.res.Resources;
35 import android.hardware.usb.IUsbManager;
36 import android.net.wifi.WifiManager;
37 import android.os.AsyncTask;
38 import android.os.BatteryManager;
39 import android.os.Build;
40 import android.os.Bundle;
41 import android.os.IBinder;
42 import android.os.Parcel;
43 import android.os.RemoteException;
44 import android.os.ServiceManager;
45 import android.os.StrictMode;
46 import android.os.SystemProperties;
47 import android.os.UserHandle;
48 import android.os.UserManager;
49 import android.preference.ListPreference;
50 import android.preference.Preference;
51 import android.preference.Preference.OnPreferenceChangeListener;
52 import android.preference.PreferenceGroup;
53 import android.preference.PreferenceScreen;
54 import android.preference.SwitchPreference;
55 import android.provider.SearchIndexableResource;
56 import android.provider.Settings;
57 import android.text.TextUtils;
58 import android.util.Log;
59 import android.view.HardwareRenderer;
60 import android.view.IWindowManager;
61 import android.view.View;
62 import android.view.accessibility.AccessibilityManager;
63 import android.widget.Switch;
64 import android.widget.TextView;
66 import com.android.settings.search.BaseSearchIndexProvider;
67 import com.android.settings.search.Indexable;
68 import com.android.settings.widget.SwitchBar;
70 import java.util.ArrayList;
71 import java.util.Arrays;
72 import java.util.HashSet;
73 import java.util.List;
76 * Displays preferences for application developers.
78 public class DevelopmentSettings extends SettingsPreferenceFragment
79 implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener,
80 OnPreferenceChangeListener, SwitchBar.OnSwitchChangeListener, Indexable {
81 private static final String TAG = "DevelopmentSettings";
84 * Preference file were development settings prefs are stored.
86 public static final String PREF_FILE = "development";
89 * Whether to show the development settings to the user. Default is false.
91 public static final String PREF_SHOW = "show";
93 private static final String ENABLE_ADB = "enable_adb";
94 private static final String CLEAR_ADB_KEYS = "clear_adb_keys";
95 private static final String ENABLE_TERMINAL = "enable_terminal";
96 private static final String KEEP_SCREEN_ON = "keep_screen_on";
97 private static final String BT_HCI_SNOOP_LOG = "bt_hci_snoop_log";
98 private static final String ENABLE_OEM_UNLOCK = "oem_unlock_enable";
99 private static final String ALLOW_MOCK_LOCATION = "allow_mock_location";
100 private static final String HDCP_CHECKING_KEY = "hdcp_checking";
101 private static final String HDCP_CHECKING_PROPERTY = "persist.sys.hdcp_checking";
102 private static final String LOCAL_BACKUP_PASSWORD = "local_backup_password";
103 private static final String HARDWARE_UI_PROPERTY = "persist.sys.ui.hw";
104 private static final String MSAA_PROPERTY = "debug.egl.force_msaa";
105 private static final String BUGREPORT = "bugreport";
106 private static final String BUGREPORT_IN_POWER_KEY = "bugreport_in_power";
107 private static final String OPENGL_TRACES_PROPERTY = "debug.egl.trace";
109 private static final String DEBUG_APP_KEY = "debug_app";
110 private static final String WAIT_FOR_DEBUGGER_KEY = "wait_for_debugger";
111 private static final String VERIFY_APPS_OVER_USB_KEY = "verify_apps_over_usb";
112 private static final String DEBUG_VIEW_ATTRIBUTES = "debug_view_attributes";
113 private static final String STRICT_MODE_KEY = "strict_mode";
114 private static final String POINTER_LOCATION_KEY = "pointer_location";
115 private static final String SHOW_TOUCHES_KEY = "show_touches";
116 private static final String SHOW_SCREEN_UPDATES_KEY = "show_screen_updates";
117 private static final String DISABLE_OVERLAYS_KEY = "disable_overlays";
118 private static final String SIMULATE_COLOR_SPACE = "simulate_color_space";
119 private static final String USE_AWESOMEPLAYER_KEY = "use_awesomeplayer";
120 private static final String USB_AUDIO_KEY = "usb_audio";
121 private static final String USE_AWESOMEPLAYER_PROPERTY = "persist.sys.media.use-awesome";
122 private static final String SHOW_CPU_USAGE_KEY = "show_cpu_usage";
123 private static final String FORCE_HARDWARE_UI_KEY = "force_hw_ui";
124 private static final String FORCE_MSAA_KEY = "force_msaa";
125 private static final String TRACK_FRAME_TIME_KEY = "track_frame_time";
126 private static final String SHOW_NON_RECTANGULAR_CLIP_KEY = "show_non_rect_clip";
127 private static final String SHOW_HW_SCREEN_UPDATES_KEY = "show_hw_screen_udpates";
128 private static final String SHOW_HW_LAYERS_UPDATES_KEY = "show_hw_layers_udpates";
129 private static final String DEBUG_HW_OVERDRAW_KEY = "debug_hw_overdraw";
130 private static final String DEBUG_LAYOUT_KEY = "debug_layout";
131 private static final String FORCE_RTL_LAYOUT_KEY = "force_rtl_layout_all_locales";
132 private static final String WINDOW_ANIMATION_SCALE_KEY = "window_animation_scale";
133 private static final String TRANSITION_ANIMATION_SCALE_KEY = "transition_animation_scale";
134 private static final String ANIMATOR_DURATION_SCALE_KEY = "animator_duration_scale";
135 private static final String OVERLAY_DISPLAY_DEVICES_KEY = "overlay_display_devices";
136 private static final String DEBUG_DEBUGGING_CATEGORY_KEY = "debug_debugging_category";
137 private static final String DEBUG_APPLICATIONS_CATEGORY_KEY = "debug_applications_category";
138 private static final String WIFI_DISPLAY_CERTIFICATION_KEY = "wifi_display_certification";
139 private static final String WIFI_VERBOSE_LOGGING_KEY = "wifi_verbose_logging";
140 private static final String WIFI_AGGRESSIVE_HANDOVER_KEY = "wifi_aggressive_handover";
141 private static final String WIFI_ALLOW_SCAN_WITH_TRAFFIC_KEY = "wifi_allow_scan_with_traffic";
142 private static final String SELECT_LOGD_SIZE_KEY = "select_logd_size";
143 private static final String SELECT_LOGD_SIZE_PROPERTY = "persist.logd.size";
144 private static final String SELECT_LOGD_DEFAULT_SIZE_PROPERTY = "ro.logd.size";
146 private static final String OPENGL_TRACES_KEY = "enable_opengl_traces";
148 private static final String IMMEDIATELY_DESTROY_ACTIVITIES_KEY
149 = "immediately_destroy_activities";
150 private static final String APP_PROCESS_LIMIT_KEY = "app_process_limit";
152 private static final String SHOW_ALL_ANRS_KEY = "show_all_anrs";
154 private static final String PROCESS_STATS = "proc_stats";
156 private static final String TAG_CONFIRM_ENFORCE = "confirm_enforce";
158 private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive";
160 private static final String TERMINAL_APP_PACKAGE = "com.android.terminal";
162 private static final int RESULT_DEBUG_APP = 1000;
164 private static final String PERSISTENT_DATA_BLOCK_PROP = "ro.frp.pst";
166 private static final int REQUEST_CODE_ENABLE_OEM_UNLOCK = 0;
168 private static String DEFAULT_LOG_RING_BUFFER_SIZE_IN_BYTES = "262144"; // 256K
170 private IWindowManager mWindowManager;
171 private IBackupManager mBackupManager;
172 private DevicePolicyManager mDpm;
173 private UserManager mUm;
174 private WifiManager mWifiManager;
176 private SwitchBar mSwitchBar;
177 private boolean mLastEnabledState;
178 private boolean mHaveDebugSettings;
179 private boolean mDontPokeProperties;
181 private SwitchPreference mEnableAdb;
182 private Preference mClearAdbKeys;
183 private SwitchPreference mEnableTerminal;
184 private Preference mBugreport;
185 private SwitchPreference mBugreportInPower;
186 private SwitchPreference mKeepScreenOn;
187 private SwitchPreference mBtHciSnoopLog;
188 private SwitchPreference mEnableOemUnlock;
189 private SwitchPreference mAllowMockLocation;
190 private SwitchPreference mDebugViewAttributes;
192 private PreferenceScreen mPassword;
193 private String mDebugApp;
194 private Preference mDebugAppPref;
195 private SwitchPreference mWaitForDebugger;
196 private SwitchPreference mVerifyAppsOverUsb;
197 private SwitchPreference mWifiDisplayCertification;
198 private SwitchPreference mWifiVerboseLogging;
199 private SwitchPreference mWifiAggressiveHandover;
201 private SwitchPreference mWifiAllowScansWithTraffic;
202 private SwitchPreference mStrictMode;
203 private SwitchPreference mPointerLocation;
204 private SwitchPreference mShowTouches;
205 private SwitchPreference mShowScreenUpdates;
206 private SwitchPreference mDisableOverlays;
207 private SwitchPreference mShowCpuUsage;
208 private SwitchPreference mForceHardwareUi;
209 private SwitchPreference mForceMsaa;
210 private SwitchPreference mShowHwScreenUpdates;
211 private SwitchPreference mShowHwLayersUpdates;
212 private SwitchPreference mDebugLayout;
213 private SwitchPreference mForceRtlLayout;
214 private ListPreference mDebugHwOverdraw;
215 private ListPreference mLogdSize;
216 private ListPreference mTrackFrameTime;
217 private ListPreference mShowNonRectClip;
218 private ListPreference mWindowAnimationScale;
219 private ListPreference mTransitionAnimationScale;
220 private ListPreference mAnimatorDurationScale;
221 private ListPreference mOverlayDisplayDevices;
222 private ListPreference mOpenGLTraces;
224 private ListPreference mSimulateColorSpace;
226 private SwitchPreference mUseAwesomePlayer;
227 private SwitchPreference mUSBAudio;
228 private SwitchPreference mImmediatelyDestroyActivities;
230 private ListPreference mAppProcessLimit;
232 private SwitchPreference mShowAllANRs;
234 private PreferenceScreen mProcessStats;
235 private final ArrayList<Preference> mAllPrefs = new ArrayList<Preference>();
237 private final ArrayList<SwitchPreference> mResetSwitchPrefs
238 = new ArrayList<SwitchPreference>();
240 private final HashSet<Preference> mDisabledPrefs = new HashSet<Preference>();
241 // To track whether a confirmation dialog was clicked.
242 private boolean mDialogClicked;
243 private Dialog mEnableDialog;
244 private Dialog mAdbDialog;
246 private Dialog mAdbKeysDialog;
247 private boolean mUnavailable;
250 public void onCreate(Bundle icicle) {
251 super.onCreate(icicle);
253 mWindowManager = IWindowManager.Stub.asInterface(ServiceManager.getService("window"));
254 mBackupManager = IBackupManager.Stub.asInterface(
255 ServiceManager.getService(Context.BACKUP_SERVICE));
256 mDpm = (DevicePolicyManager)getActivity().getSystemService(Context.DEVICE_POLICY_SERVICE);
257 mUm = (UserManager) getSystemService(Context.USER_SERVICE);
259 mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
261 if (android.os.Process.myUserHandle().getIdentifier() != UserHandle.USER_OWNER
262 || mUm.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES)) {
264 setPreferenceScreen(new PreferenceScreen(getActivity(), null));
268 addPreferencesFromResource(R.xml.development_prefs);
270 final PreferenceGroup debugDebuggingCategory = (PreferenceGroup)
271 findPreference(DEBUG_DEBUGGING_CATEGORY_KEY);
273 mEnableAdb = findAndInitSwitchPref(ENABLE_ADB);
274 mClearAdbKeys = findPreference(CLEAR_ADB_KEYS);
275 if (!SystemProperties.getBoolean("ro.adb.secure", false)) {
276 if (debugDebuggingCategory != null) {
277 debugDebuggingCategory.removePreference(mClearAdbKeys);
280 mAllPrefs.add(mClearAdbKeys);
281 mEnableTerminal = findAndInitSwitchPref(ENABLE_TERMINAL);
282 if (!isPackageInstalled(getActivity(), TERMINAL_APP_PACKAGE)) {
283 debugDebuggingCategory.removePreference(mEnableTerminal);
284 mEnableTerminal = null;
287 mBugreport = findPreference(BUGREPORT);
288 mBugreportInPower = findAndInitSwitchPref(BUGREPORT_IN_POWER_KEY);
289 mKeepScreenOn = findAndInitSwitchPref(KEEP_SCREEN_ON);
290 mBtHciSnoopLog = findAndInitSwitchPref(BT_HCI_SNOOP_LOG);
291 mEnableOemUnlock = findAndInitSwitchPref(ENABLE_OEM_UNLOCK);
292 if (!showEnableOemUnlockPreference()) {
293 removePreference(mEnableOemUnlock);
294 mEnableOemUnlock = null;
296 mAllowMockLocation = findAndInitSwitchPref(ALLOW_MOCK_LOCATION);
297 mDebugViewAttributes = findAndInitSwitchPref(DEBUG_VIEW_ATTRIBUTES);
298 mPassword = (PreferenceScreen) findPreference(LOCAL_BACKUP_PASSWORD);
299 mAllPrefs.add(mPassword);
302 if (!android.os.Process.myUserHandle().equals(UserHandle.OWNER)) {
303 disableForUser(mEnableAdb);
304 disableForUser(mClearAdbKeys);
305 disableForUser(mEnableTerminal);
306 disableForUser(mPassword);
309 mDebugAppPref = findPreference(DEBUG_APP_KEY);
310 mAllPrefs.add(mDebugAppPref);
311 mWaitForDebugger = findAndInitSwitchPref(WAIT_FOR_DEBUGGER_KEY);
312 mVerifyAppsOverUsb = findAndInitSwitchPref(VERIFY_APPS_OVER_USB_KEY);
313 if (!showVerifierSetting()) {
314 if (debugDebuggingCategory != null) {
315 debugDebuggingCategory.removePreference(mVerifyAppsOverUsb);
317 mVerifyAppsOverUsb.setEnabled(false);
320 mStrictMode = findAndInitSwitchPref(STRICT_MODE_KEY);
321 mPointerLocation = findAndInitSwitchPref(POINTER_LOCATION_KEY);
322 mShowTouches = findAndInitSwitchPref(SHOW_TOUCHES_KEY);
323 mShowScreenUpdates = findAndInitSwitchPref(SHOW_SCREEN_UPDATES_KEY);
324 mDisableOverlays = findAndInitSwitchPref(DISABLE_OVERLAYS_KEY);
325 mShowCpuUsage = findAndInitSwitchPref(SHOW_CPU_USAGE_KEY);
326 mForceHardwareUi = findAndInitSwitchPref(FORCE_HARDWARE_UI_KEY);
327 mForceMsaa = findAndInitSwitchPref(FORCE_MSAA_KEY);
328 mTrackFrameTime = addListPreference(TRACK_FRAME_TIME_KEY);
329 mShowNonRectClip = addListPreference(SHOW_NON_RECTANGULAR_CLIP_KEY);
330 mShowHwScreenUpdates = findAndInitSwitchPref(SHOW_HW_SCREEN_UPDATES_KEY);
331 mShowHwLayersUpdates = findAndInitSwitchPref(SHOW_HW_LAYERS_UPDATES_KEY);
332 mDebugLayout = findAndInitSwitchPref(DEBUG_LAYOUT_KEY);
333 mForceRtlLayout = findAndInitSwitchPref(FORCE_RTL_LAYOUT_KEY);
334 mDebugHwOverdraw = addListPreference(DEBUG_HW_OVERDRAW_KEY);
335 mWifiDisplayCertification = findAndInitSwitchPref(WIFI_DISPLAY_CERTIFICATION_KEY);
336 mWifiVerboseLogging = findAndInitSwitchPref(WIFI_VERBOSE_LOGGING_KEY);
337 mWifiAggressiveHandover = findAndInitSwitchPref(WIFI_AGGRESSIVE_HANDOVER_KEY);
338 mWifiAllowScansWithTraffic = findAndInitSwitchPref(WIFI_ALLOW_SCAN_WITH_TRAFFIC_KEY);
339 mLogdSize = addListPreference(SELECT_LOGD_SIZE_KEY);
341 mWindowAnimationScale = addListPreference(WINDOW_ANIMATION_SCALE_KEY);
342 mTransitionAnimationScale = addListPreference(TRANSITION_ANIMATION_SCALE_KEY);
343 mAnimatorDurationScale = addListPreference(ANIMATOR_DURATION_SCALE_KEY);
344 mOverlayDisplayDevices = addListPreference(OVERLAY_DISPLAY_DEVICES_KEY);
345 mOpenGLTraces = addListPreference(OPENGL_TRACES_KEY);
346 mSimulateColorSpace = addListPreference(SIMULATE_COLOR_SPACE);
347 mUseAwesomePlayer = findAndInitSwitchPref(USE_AWESOMEPLAYER_KEY);
348 mUSBAudio = findAndInitSwitchPref(USB_AUDIO_KEY);
350 mImmediatelyDestroyActivities = (SwitchPreference) findPreference(
351 IMMEDIATELY_DESTROY_ACTIVITIES_KEY);
352 mAllPrefs.add(mImmediatelyDestroyActivities);
353 mResetSwitchPrefs.add(mImmediatelyDestroyActivities);
355 mAppProcessLimit = addListPreference(APP_PROCESS_LIMIT_KEY);
357 mShowAllANRs = (SwitchPreference) findPreference(
359 mAllPrefs.add(mShowAllANRs);
360 mResetSwitchPrefs.add(mShowAllANRs);
362 Preference hdcpChecking = findPreference(HDCP_CHECKING_KEY);
363 if (hdcpChecking != null) {
364 mAllPrefs.add(hdcpChecking);
365 removePreferenceForProduction(hdcpChecking);
368 mProcessStats = (PreferenceScreen) findPreference(PROCESS_STATS);
369 mAllPrefs.add(mProcessStats);
372 private ListPreference addListPreference(String prefKey) {
373 ListPreference pref = (ListPreference) findPreference(prefKey);
375 pref.setOnPreferenceChangeListener(this);
379 private void disableForUser(Preference pref) {
381 pref.setEnabled(false);
382 mDisabledPrefs.add(pref);
386 private SwitchPreference findAndInitSwitchPref(String key) {
387 SwitchPreference pref = (SwitchPreference) findPreference(key);
389 throw new IllegalArgumentException("Cannot find preference with key = " + key);
392 mResetSwitchPrefs.add(pref);
397 public void onActivityCreated(Bundle savedInstanceState) {
398 super.onActivityCreated(savedInstanceState);
400 final SettingsActivity activity = (SettingsActivity) getActivity();
402 mSwitchBar = activity.getSwitchBar();
404 mSwitchBar.setEnabled(false);
408 mSwitchBar.addOnSwitchChangeListener(this);
411 private boolean removePreferenceForProduction(Preference preference) {
412 if ("user".equals(Build.TYPE)) {
413 removePreference(preference);
419 private void removePreference(Preference preference) {
420 getPreferenceScreen().removePreference(preference);
421 mAllPrefs.remove(preference);
424 private void setPrefsEnabledState(boolean enabled) {
425 for (int i = 0; i < mAllPrefs.size(); i++) {
426 Preference pref = mAllPrefs.get(i);
427 pref.setEnabled(enabled && !mDisabledPrefs.contains(pref));
433 public void onResume() {
437 // Show error message
438 TextView emptyView = (TextView) getView().findViewById(android.R.id.empty);
439 getListView().setEmptyView(emptyView);
440 if (emptyView != null) {
441 emptyView.setText(R.string.development_settings_not_available);
446 if (mDpm.getMaximumTimeToLock(null) > 0) {
447 // A DeviceAdmin has specified a maximum time until the device
448 // will lock... in this case we can't allow the user to turn
449 // on "stay awake when plugged in" because that would defeat the
451 mDisabledPrefs.add(mKeepScreenOn);
453 mDisabledPrefs.remove(mKeepScreenOn);
456 final ContentResolver cr = getActivity().getContentResolver();
457 mLastEnabledState = Settings.Global.getInt(cr,
458 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
459 mSwitchBar.setChecked(mLastEnabledState);
460 setPrefsEnabledState(mLastEnabledState);
462 if (mHaveDebugSettings && !mLastEnabledState) {
463 // Overall debugging is disabled, but there are some debug
464 // settings that are enabled. This is an invalid state. Switch
465 // to debug settings being enabled, so the user knows there is
466 // stuff enabled and can turn it all off if they want.
467 Settings.Global.putInt(getActivity().getContentResolver(),
468 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
469 mLastEnabledState = true;
470 mSwitchBar.setChecked(mLastEnabledState);
471 setPrefsEnabledState(mLastEnabledState);
477 public void onDestroyView() {
478 super.onDestroyView();
483 mSwitchBar.removeOnSwitchChangeListener(this);
487 void updateSwitchPreference(SwitchPreference switchPreference, boolean value) {
488 switchPreference.setChecked(value);
489 mHaveDebugSettings |= value;
492 private void updateAllOptions() {
493 final Context context = getActivity();
494 final ContentResolver cr = context.getContentResolver();
495 mHaveDebugSettings = false;
496 updateSwitchPreference(mEnableAdb, Settings.Global.getInt(cr,
497 Settings.Global.ADB_ENABLED, 0) != 0);
498 if (mEnableTerminal != null) {
499 updateSwitchPreference(mEnableTerminal,
500 context.getPackageManager().getApplicationEnabledSetting(TERMINAL_APP_PACKAGE)
501 == PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
503 updateSwitchPreference(mBugreportInPower, Settings.Secure.getInt(cr,
504 Settings.Secure.BUGREPORT_IN_POWER_MENU, 0) != 0);
505 updateSwitchPreference(mKeepScreenOn, Settings.Global.getInt(cr,
506 Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0) != 0);
507 updateSwitchPreference(mBtHciSnoopLog, Settings.Secure.getInt(cr,
508 Settings.Secure.BLUETOOTH_HCI_LOG, 0) != 0);
509 if (mEnableOemUnlock != null) {
510 updateSwitchPreference(mEnableOemUnlock, Utils.isOemUnlockEnabled(getActivity()));
512 updateSwitchPreference(mAllowMockLocation, Settings.Secure.getInt(cr,
513 Settings.Secure.ALLOW_MOCK_LOCATION, 0) != 0);
514 updateSwitchPreference(mDebugViewAttributes, Settings.Global.getInt(cr,
515 Settings.Global.DEBUG_VIEW_ATTRIBUTES, 0) != 0);
517 updatePasswordSummary();
518 updateDebuggerOptions();
519 updateStrictModeVisualOptions();
520 updatePointerLocationOptions();
521 updateShowTouchesOptions();
522 updateFlingerOptions();
523 updateCpuUsageOptions();
524 updateHardwareUiOptions();
526 updateTrackFrameTimeOptions();
527 updateShowNonRectClipOptions();
528 updateShowHwScreenUpdatesOptions();
529 updateShowHwLayersUpdatesOptions();
530 updateDebugHwOverdrawOptions();
531 updateDebugLayoutOptions();
532 updateAnimationScaleOptions();
533 updateOverlayDisplayDevicesOptions();
534 updateOpenGLTracesOptions();
535 updateImmediatelyDestroyActivitiesOptions();
536 updateAppProcessLimitOptions();
537 updateShowAllANRsOptions();
538 updateVerifyAppsOverUsbOptions();
539 updateBugreportOptions();
540 updateForceRtlOptions();
541 updateLogdSizeValues();
542 updateWifiDisplayCertificationOptions();
543 updateWifiVerboseLoggingOptions();
544 updateWifiAggressiveHandoverOptions();
545 updateWifiAllowScansWithTrafficOptions();
546 updateSimulateColorSpace();
547 updateUseNuplayerOptions();
548 updateUSBAudioOptions();
551 private void resetDangerousOptions() {
552 mDontPokeProperties = true;
553 for (int i=0; i< mResetSwitchPrefs.size(); i++) {
554 SwitchPreference cb = mResetSwitchPrefs.get(i);
555 if (cb.isChecked()) {
556 cb.setChecked(false);
557 onPreferenceTreeClick(null, cb);
560 resetDebuggerOptions();
561 writeLogdSizeOption(null);
562 writeAnimationScaleOption(0, mWindowAnimationScale, null);
563 writeAnimationScaleOption(1, mTransitionAnimationScale, null);
564 writeAnimationScaleOption(2, mAnimatorDurationScale, null);
565 // Only poke the color space setting if we control it.
566 if (usingDevelopmentColorSpace()) {
567 writeSimulateColorSpace(-1);
569 writeOverlayDisplayDevicesOptions(null);
570 writeAppProcessLimitOptions(null);
571 mHaveDebugSettings = false;
573 mDontPokeProperties = false;
574 pokeSystemProperties();
577 private void updateHdcpValues() {
578 ListPreference hdcpChecking = (ListPreference) findPreference(HDCP_CHECKING_KEY);
579 if (hdcpChecking != null) {
580 String currentValue = SystemProperties.get(HDCP_CHECKING_PROPERTY);
581 String[] values = getResources().getStringArray(R.array.hdcp_checking_values);
582 String[] summaries = getResources().getStringArray(R.array.hdcp_checking_summaries);
583 int index = 1; // Defaults to drm-only. Needs to match with R.array.hdcp_checking_values
584 for (int i = 0; i < values.length; i++) {
585 if (currentValue.equals(values[i])) {
590 hdcpChecking.setValue(values[index]);
591 hdcpChecking.setSummary(summaries[index]);
592 hdcpChecking.setOnPreferenceChangeListener(this);
596 private void updatePasswordSummary() {
598 if (mBackupManager.hasBackupPassword()) {
599 mPassword.setSummary(R.string.local_backup_password_summary_change);
601 mPassword.setSummary(R.string.local_backup_password_summary_none);
603 } catch (RemoteException e) {
604 // Not much we can do here
608 private void writeBtHciSnoopLogOptions() {
609 BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
610 adapter.configHciSnoopLog(mBtHciSnoopLog.isChecked());
611 Settings.Secure.putInt(getActivity().getContentResolver(),
612 Settings.Secure.BLUETOOTH_HCI_LOG,
613 mBtHciSnoopLog.isChecked() ? 1 : 0);
616 private void writeDebuggerOptions() {
618 ActivityManagerNative.getDefault().setDebugApp(
619 mDebugApp, mWaitForDebugger.isChecked(), true);
620 } catch (RemoteException ex) {
624 private static void resetDebuggerOptions() {
626 ActivityManagerNative.getDefault().setDebugApp(
628 } catch (RemoteException ex) {
632 private void updateDebuggerOptions() {
633 mDebugApp = Settings.Global.getString(
634 getActivity().getContentResolver(), Settings.Global.DEBUG_APP);
635 updateSwitchPreference(mWaitForDebugger, Settings.Global.getInt(
636 getActivity().getContentResolver(), Settings.Global.WAIT_FOR_DEBUGGER, 0) != 0);
637 if (mDebugApp != null && mDebugApp.length() > 0) {
640 ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(mDebugApp,
641 PackageManager.GET_DISABLED_COMPONENTS);
642 CharSequence lab = getActivity().getPackageManager().getApplicationLabel(ai);
643 label = lab != null ? lab.toString() : mDebugApp;
644 } catch (PackageManager.NameNotFoundException e) {
647 mDebugAppPref.setSummary(getResources().getString(R.string.debug_app_set, label));
648 mWaitForDebugger.setEnabled(true);
649 mHaveDebugSettings = true;
651 mDebugAppPref.setSummary(getResources().getString(R.string.debug_app_not_set));
652 mWaitForDebugger.setEnabled(false);
656 private void updateVerifyAppsOverUsbOptions() {
657 updateSwitchPreference(mVerifyAppsOverUsb, Settings.Global.getInt(getActivity().getContentResolver(),
658 Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1) != 0);
659 mVerifyAppsOverUsb.setEnabled(enableVerifierSetting());
662 private void writeVerifyAppsOverUsbOptions() {
663 Settings.Global.putInt(getActivity().getContentResolver(),
664 Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, mVerifyAppsOverUsb.isChecked() ? 1 : 0);
667 private boolean enableVerifierSetting() {
668 final ContentResolver cr = getActivity().getContentResolver();
669 if (Settings.Global.getInt(cr, Settings.Global.ADB_ENABLED, 0) == 0) {
672 if (Settings.Global.getInt(cr, Settings.Global.PACKAGE_VERIFIER_ENABLE, 1) == 0) {
675 final PackageManager pm = getActivity().getPackageManager();
676 final Intent verification = new Intent(Intent.ACTION_PACKAGE_NEEDS_VERIFICATION);
677 verification.setType(PACKAGE_MIME_TYPE);
678 verification.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
679 final List<ResolveInfo> receivers = pm.queryBroadcastReceivers(verification, 0);
680 if (receivers.size() == 0) {
687 private boolean showVerifierSetting() {
688 return Settings.Global.getInt(getActivity().getContentResolver(),
689 Settings.Global.PACKAGE_VERIFIER_SETTING_VISIBLE, 1) > 0;
692 private static boolean showEnableOemUnlockPreference() {
693 return !SystemProperties.get(PERSISTENT_DATA_BLOCK_PROP).equals("");
696 private void updateBugreportOptions() {
697 if ("user".equals(Build.TYPE)) {
698 final ContentResolver resolver = getActivity().getContentResolver();
699 final boolean adbEnabled = Settings.Global.getInt(
700 resolver, Settings.Global.ADB_ENABLED, 0) != 0;
702 mBugreport.setEnabled(true);
703 mBugreportInPower.setEnabled(true);
705 mBugreport.setEnabled(false);
706 mBugreportInPower.setEnabled(false);
707 mBugreportInPower.setChecked(false);
708 Settings.Secure.putInt(resolver, Settings.Secure.BUGREPORT_IN_POWER_MENU, 0);
711 mBugreportInPower.setEnabled(true);
715 // Returns the current state of the system property that controls
716 // strictmode flashes. One of:
717 // 0: not explicitly set one way or another
720 private static int currentStrictModeActiveIndex() {
721 if (TextUtils.isEmpty(SystemProperties.get(StrictMode.VISUAL_PROPERTY))) {
724 boolean enabled = SystemProperties.getBoolean(StrictMode.VISUAL_PROPERTY, false);
725 return enabled ? 1 : 2;
728 private void writeStrictModeVisualOptions() {
730 mWindowManager.setStrictModeVisualIndicatorPreference(mStrictMode.isChecked()
732 } catch (RemoteException e) {
736 private void updateStrictModeVisualOptions() {
737 updateSwitchPreference(mStrictMode, currentStrictModeActiveIndex() == 1);
740 private void writePointerLocationOptions() {
741 Settings.System.putInt(getActivity().getContentResolver(),
742 Settings.System.POINTER_LOCATION, mPointerLocation.isChecked() ? 1 : 0);
745 private void updatePointerLocationOptions() {
746 updateSwitchPreference(mPointerLocation, Settings.System.getInt(getActivity().getContentResolver(),
747 Settings.System.POINTER_LOCATION, 0) != 0);
750 private void writeShowTouchesOptions() {
751 Settings.System.putInt(getActivity().getContentResolver(),
752 Settings.System.SHOW_TOUCHES, mShowTouches.isChecked() ? 1 : 0);
755 private void updateShowTouchesOptions() {
756 updateSwitchPreference(mShowTouches, Settings.System.getInt(getActivity().getContentResolver(),
757 Settings.System.SHOW_TOUCHES, 0) != 0);
760 private void updateFlingerOptions() {
761 // magic communication with surface flinger.
763 IBinder flinger = ServiceManager.getService("SurfaceFlinger");
764 if (flinger != null) {
765 Parcel data = Parcel.obtain();
766 Parcel reply = Parcel.obtain();
767 data.writeInterfaceToken("android.ui.ISurfaceComposer");
768 flinger.transact(1010, data, reply, 0);
769 @SuppressWarnings("unused")
770 int showCpu = reply.readInt();
771 @SuppressWarnings("unused")
772 int enableGL = reply.readInt();
773 int showUpdates = reply.readInt();
774 updateSwitchPreference(mShowScreenUpdates, showUpdates != 0);
775 @SuppressWarnings("unused")
776 int showBackground = reply.readInt();
777 int disableOverlays = reply.readInt();
778 updateSwitchPreference(mDisableOverlays, disableOverlays != 0);
782 } catch (RemoteException ex) {
786 private void writeShowUpdatesOption() {
788 IBinder flinger = ServiceManager.getService("SurfaceFlinger");
789 if (flinger != null) {
790 Parcel data = Parcel.obtain();
791 data.writeInterfaceToken("android.ui.ISurfaceComposer");
792 final int showUpdates = mShowScreenUpdates.isChecked() ? 1 : 0;
793 data.writeInt(showUpdates);
794 flinger.transact(1002, data, null, 0);
797 updateFlingerOptions();
799 } catch (RemoteException ex) {
803 private void writeDisableOverlaysOption() {
805 IBinder flinger = ServiceManager.getService("SurfaceFlinger");
806 if (flinger != null) {
807 Parcel data = Parcel.obtain();
808 data.writeInterfaceToken("android.ui.ISurfaceComposer");
809 final int disableOverlays = mDisableOverlays.isChecked() ? 1 : 0;
810 data.writeInt(disableOverlays);
811 flinger.transact(1008, data, null, 0);
814 updateFlingerOptions();
816 } catch (RemoteException ex) {
820 private void updateHardwareUiOptions() {
821 updateSwitchPreference(mForceHardwareUi, SystemProperties.getBoolean(HARDWARE_UI_PROPERTY, false));
824 private void writeHardwareUiOptions() {
825 SystemProperties.set(HARDWARE_UI_PROPERTY, mForceHardwareUi.isChecked() ? "true" : "false");
826 pokeSystemProperties();
829 private void updateMsaaOptions() {
830 updateSwitchPreference(mForceMsaa, SystemProperties.getBoolean(MSAA_PROPERTY, false));
833 private void writeMsaaOptions() {
834 SystemProperties.set(MSAA_PROPERTY, mForceMsaa.isChecked() ? "true" : "false");
835 pokeSystemProperties();
838 private void updateTrackFrameTimeOptions() {
839 String value = SystemProperties.get(HardwareRenderer.PROFILE_PROPERTY);
844 CharSequence[] values = mTrackFrameTime.getEntryValues();
845 for (int i = 0; i < values.length; i++) {
846 if (value.contentEquals(values[i])) {
847 mTrackFrameTime.setValueIndex(i);
848 mTrackFrameTime.setSummary(mTrackFrameTime.getEntries()[i]);
852 mTrackFrameTime.setValueIndex(0);
853 mTrackFrameTime.setSummary(mTrackFrameTime.getEntries()[0]);
856 private void writeTrackFrameTimeOptions(Object newValue) {
857 SystemProperties.set(HardwareRenderer.PROFILE_PROPERTY,
858 newValue == null ? "" : newValue.toString());
859 pokeSystemProperties();
860 updateTrackFrameTimeOptions();
863 private void updateShowNonRectClipOptions() {
864 String value = SystemProperties.get(
865 HardwareRenderer.DEBUG_SHOW_NON_RECTANGULAR_CLIP_PROPERTY);
870 CharSequence[] values = mShowNonRectClip.getEntryValues();
871 for (int i = 0; i < values.length; i++) {
872 if (value.contentEquals(values[i])) {
873 mShowNonRectClip.setValueIndex(i);
874 mShowNonRectClip.setSummary(mShowNonRectClip.getEntries()[i]);
878 mShowNonRectClip.setValueIndex(0);
879 mShowNonRectClip.setSummary(mShowNonRectClip.getEntries()[0]);
882 private void writeShowNonRectClipOptions(Object newValue) {
883 SystemProperties.set(HardwareRenderer.DEBUG_SHOW_NON_RECTANGULAR_CLIP_PROPERTY,
884 newValue == null ? "" : newValue.toString());
885 pokeSystemProperties();
886 updateShowNonRectClipOptions();
889 private void updateShowHwScreenUpdatesOptions() {
890 updateSwitchPreference(mShowHwScreenUpdates,
891 SystemProperties.getBoolean(HardwareRenderer.DEBUG_DIRTY_REGIONS_PROPERTY, false));
894 private void writeShowHwScreenUpdatesOptions() {
895 SystemProperties.set(HardwareRenderer.DEBUG_DIRTY_REGIONS_PROPERTY,
896 mShowHwScreenUpdates.isChecked() ? "true" : null);
897 pokeSystemProperties();
900 private void updateShowHwLayersUpdatesOptions() {
901 updateSwitchPreference(mShowHwLayersUpdates, SystemProperties.getBoolean(
902 HardwareRenderer.DEBUG_SHOW_LAYERS_UPDATES_PROPERTY, false));
905 private void writeShowHwLayersUpdatesOptions() {
906 SystemProperties.set(HardwareRenderer.DEBUG_SHOW_LAYERS_UPDATES_PROPERTY,
907 mShowHwLayersUpdates.isChecked() ? "true" : null);
908 pokeSystemProperties();
911 private void updateDebugHwOverdrawOptions() {
912 String value = SystemProperties.get(HardwareRenderer.DEBUG_OVERDRAW_PROPERTY);
917 CharSequence[] values = mDebugHwOverdraw.getEntryValues();
918 for (int i = 0; i < values.length; i++) {
919 if (value.contentEquals(values[i])) {
920 mDebugHwOverdraw.setValueIndex(i);
921 mDebugHwOverdraw.setSummary(mDebugHwOverdraw.getEntries()[i]);
925 mDebugHwOverdraw.setValueIndex(0);
926 mDebugHwOverdraw.setSummary(mDebugHwOverdraw.getEntries()[0]);
929 private void writeDebugHwOverdrawOptions(Object newValue) {
930 SystemProperties.set(HardwareRenderer.DEBUG_OVERDRAW_PROPERTY,
931 newValue == null ? "" : newValue.toString());
932 pokeSystemProperties();
933 updateDebugHwOverdrawOptions();
936 private void updateDebugLayoutOptions() {
937 updateSwitchPreference(mDebugLayout,
938 SystemProperties.getBoolean(View.DEBUG_LAYOUT_PROPERTY, false));
941 private void writeDebugLayoutOptions() {
942 SystemProperties.set(View.DEBUG_LAYOUT_PROPERTY,
943 mDebugLayout.isChecked() ? "true" : "false");
944 pokeSystemProperties();
947 private void updateSimulateColorSpace() {
948 final ContentResolver cr = getContentResolver();
949 final boolean enabled = Settings.Secure.getInt(
950 cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0) != 0;
952 final String mode = Integer.toString(Settings.Secure.getInt(
953 cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER,
954 AccessibilityManager.DALTONIZER_DISABLED));
955 mSimulateColorSpace.setValue(mode);
956 final int index = mSimulateColorSpace.findIndexOfValue(mode);
958 // We're using a mode controlled by accessibility preferences.
959 mSimulateColorSpace.setSummary(getString(R.string.daltonizer_type_overridden,
960 getString(R.string.accessibility_display_daltonizer_preference_title)));
962 mSimulateColorSpace.setSummary("%s");
965 mSimulateColorSpace.setValue(
966 Integer.toString(AccessibilityManager.DALTONIZER_DISABLED));
971 * @return <code>true</code> if the color space preference is currently
972 * controlled by development settings
974 private boolean usingDevelopmentColorSpace() {
975 final ContentResolver cr = getContentResolver();
976 final boolean enabled = Settings.Secure.getInt(
977 cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0) != 0;
979 final String mode = Integer.toString(Settings.Secure.getInt(
980 cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER,
981 AccessibilityManager.DALTONIZER_DISABLED));
982 final int index = mSimulateColorSpace.findIndexOfValue(mode);
984 // We're using a mode controlled by developer preferences.
991 private void writeSimulateColorSpace(Object value) {
992 final ContentResolver cr = getContentResolver();
993 final int newMode = Integer.parseInt(value.toString());
995 Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0);
997 Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 1);
998 Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER, newMode);
1002 private void updateUseNuplayerOptions() {
1003 updateSwitchPreference(
1004 mUseAwesomePlayer, SystemProperties.getBoolean(USE_AWESOMEPLAYER_PROPERTY, false));
1007 private void writeUseAwesomePlayerOptions() {
1008 SystemProperties.set(
1009 USE_AWESOMEPLAYER_PROPERTY, mUseAwesomePlayer.isChecked() ? "true" : "false");
1010 pokeSystemProperties();
1013 private void updateUSBAudioOptions() {
1014 updateSwitchPreference(mUSBAudio, Settings.Secure.getInt(getContentResolver(),
1015 Settings.Secure.USB_AUDIO_AUTOMATIC_ROUTING_DISABLED, 0) != 0);
1018 private void writeUSBAudioOptions() {
1019 Settings.Secure.putInt(getContentResolver(),
1020 Settings.Secure.USB_AUDIO_AUTOMATIC_ROUTING_DISABLED,
1021 mUSBAudio.isChecked() ? 1 : 0);
1024 private void updateForceRtlOptions() {
1025 updateSwitchPreference(mForceRtlLayout, Settings.Global.getInt(getActivity().getContentResolver(),
1026 Settings.Global.DEVELOPMENT_FORCE_RTL, 0) != 0);
1029 private void writeForceRtlOptions() {
1030 boolean value = mForceRtlLayout.isChecked();
1031 Settings.Global.putInt(getActivity().getContentResolver(),
1032 Settings.Global.DEVELOPMENT_FORCE_RTL, value ? 1 : 0);
1033 SystemProperties.set(Settings.Global.DEVELOPMENT_FORCE_RTL, value ? "1" : "0");
1034 LocalePicker.updateLocale(getActivity().getResources().getConfiguration().locale);
1037 private void updateWifiDisplayCertificationOptions() {
1038 updateSwitchPreference(mWifiDisplayCertification, Settings.Global.getInt(
1039 getActivity().getContentResolver(),
1040 Settings.Global.WIFI_DISPLAY_CERTIFICATION_ON, 0) != 0);
1043 private void writeWifiDisplayCertificationOptions() {
1044 Settings.Global.putInt(getActivity().getContentResolver(),
1045 Settings.Global.WIFI_DISPLAY_CERTIFICATION_ON,
1046 mWifiDisplayCertification.isChecked() ? 1 : 0);
1049 private void updateWifiVerboseLoggingOptions() {
1050 boolean enabled = mWifiManager.getVerboseLoggingLevel() > 0;
1051 updateSwitchPreference(mWifiVerboseLogging, enabled);
1054 private void writeWifiVerboseLoggingOptions() {
1055 mWifiManager.enableVerboseLogging(mWifiVerboseLogging.isChecked() ? 1 : 0);
1058 private void updateWifiAggressiveHandoverOptions() {
1059 boolean enabled = mWifiManager.getAggressiveHandover() > 0;
1060 updateSwitchPreference(mWifiAggressiveHandover, enabled);
1063 private void writeWifiAggressiveHandoverOptions() {
1064 mWifiManager.enableAggressiveHandover(mWifiAggressiveHandover.isChecked() ? 1 : 0);
1067 private void updateWifiAllowScansWithTrafficOptions() {
1068 boolean enabled = mWifiManager.getAllowScansWithTraffic() > 0;
1069 updateSwitchPreference(mWifiAllowScansWithTraffic, enabled);
1072 private void writeWifiAllowScansWithTrafficOptions() {
1073 mWifiManager.setAllowScansWithTraffic(mWifiAllowScansWithTraffic.isChecked() ? 1 : 0);
1076 private void updateLogdSizeValues() {
1077 if (mLogdSize != null) {
1078 String currentValue = SystemProperties.get(SELECT_LOGD_SIZE_PROPERTY);
1079 if (currentValue == null) {
1080 currentValue = SystemProperties.get(SELECT_LOGD_DEFAULT_SIZE_PROPERTY);
1081 if (currentValue == null) {
1082 currentValue = "256K";
1085 String[] values = getResources().getStringArray(R.array.select_logd_size_values);
1086 String[] titles = getResources().getStringArray(R.array.select_logd_size_titles);
1087 if (SystemProperties.get("ro.config.low_ram").equals("true")) {
1088 mLogdSize.setEntries(R.array.select_logd_size_lowram_titles);
1089 titles = getResources().getStringArray(R.array.select_logd_size_lowram_titles);
1091 String[] summaries = getResources().getStringArray(R.array.select_logd_size_summaries);
1092 int index = 1; // punt to second entry if not found
1093 for (int i = 0; i < titles.length; i++) {
1094 if (currentValue.equals(values[i])
1095 || currentValue.equals(titles[i])) {
1100 mLogdSize.setValue(values[index]);
1101 mLogdSize.setSummary(summaries[index]);
1102 mLogdSize.setOnPreferenceChangeListener(this);
1106 private void writeLogdSizeOption(Object newValue) {
1107 String currentValue = SystemProperties.get(SELECT_LOGD_DEFAULT_SIZE_PROPERTY);
1108 if (currentValue != null) {
1109 DEFAULT_LOG_RING_BUFFER_SIZE_IN_BYTES = currentValue;
1111 final String size = (newValue != null) ?
1112 newValue.toString() : DEFAULT_LOG_RING_BUFFER_SIZE_IN_BYTES;
1113 SystemProperties.set(SELECT_LOGD_SIZE_PROPERTY, size);
1114 pokeSystemProperties();
1116 Process p = Runtime.getRuntime().exec("logcat -b all -G " + size);
1118 Log.i(TAG, "Logcat ring buffer sizes set to: " + size);
1119 } catch (Exception e) {
1120 Log.w(TAG, "Cannot set logcat ring buffer sizes", e);
1122 updateLogdSizeValues();
1125 private void updateCpuUsageOptions() {
1126 updateSwitchPreference(mShowCpuUsage, Settings.Global.getInt(getActivity().getContentResolver(),
1127 Settings.Global.SHOW_PROCESSES, 0) != 0);
1130 private void writeCpuUsageOptions() {
1131 boolean value = mShowCpuUsage.isChecked();
1132 Settings.Global.putInt(getActivity().getContentResolver(),
1133 Settings.Global.SHOW_PROCESSES, value ? 1 : 0);
1134 Intent service = (new Intent())
1135 .setClassName("com.android.systemui", "com.android.systemui.LoadAverageService");
1137 getActivity().startService(service);
1139 getActivity().stopService(service);
1143 private void writeImmediatelyDestroyActivitiesOptions() {
1145 ActivityManagerNative.getDefault().setAlwaysFinish(
1146 mImmediatelyDestroyActivities.isChecked());
1147 } catch (RemoteException ex) {
1151 private void updateImmediatelyDestroyActivitiesOptions() {
1152 updateSwitchPreference(mImmediatelyDestroyActivities, Settings.Global.getInt(
1153 getActivity().getContentResolver(), Settings.Global.ALWAYS_FINISH_ACTIVITIES, 0) != 0);
1156 private void updateAnimationScaleValue(int which, ListPreference pref) {
1158 float scale = mWindowManager.getAnimationScale(which);
1160 mHaveDebugSettings = true;
1162 CharSequence[] values = pref.getEntryValues();
1163 for (int i=0; i<values.length; i++) {
1164 float val = Float.parseFloat(values[i].toString());
1166 pref.setValueIndex(i);
1167 pref.setSummary(pref.getEntries()[i]);
1171 pref.setValueIndex(values.length-1);
1172 pref.setSummary(pref.getEntries()[0]);
1173 } catch (RemoteException e) {
1177 private void updateAnimationScaleOptions() {
1178 updateAnimationScaleValue(0, mWindowAnimationScale);
1179 updateAnimationScaleValue(1, mTransitionAnimationScale);
1180 updateAnimationScaleValue(2, mAnimatorDurationScale);
1183 private void writeAnimationScaleOption(int which, ListPreference pref, Object newValue) {
1185 float scale = newValue != null ? Float.parseFloat(newValue.toString()) : 1;
1186 mWindowManager.setAnimationScale(which, scale);
1187 updateAnimationScaleValue(which, pref);
1188 } catch (RemoteException e) {
1192 private void updateOverlayDisplayDevicesOptions() {
1193 String value = Settings.Global.getString(getActivity().getContentResolver(),
1194 Settings.Global.OVERLAY_DISPLAY_DEVICES);
1195 if (value == null) {
1199 CharSequence[] values = mOverlayDisplayDevices.getEntryValues();
1200 for (int i = 0; i < values.length; i++) {
1201 if (value.contentEquals(values[i])) {
1202 mOverlayDisplayDevices.setValueIndex(i);
1203 mOverlayDisplayDevices.setSummary(mOverlayDisplayDevices.getEntries()[i]);
1207 mOverlayDisplayDevices.setValueIndex(0);
1208 mOverlayDisplayDevices.setSummary(mOverlayDisplayDevices.getEntries()[0]);
1211 private void writeOverlayDisplayDevicesOptions(Object newValue) {
1212 Settings.Global.putString(getActivity().getContentResolver(),
1213 Settings.Global.OVERLAY_DISPLAY_DEVICES, (String)newValue);
1214 updateOverlayDisplayDevicesOptions();
1217 private void updateOpenGLTracesOptions() {
1218 String value = SystemProperties.get(OPENGL_TRACES_PROPERTY);
1219 if (value == null) {
1223 CharSequence[] values = mOpenGLTraces.getEntryValues();
1224 for (int i = 0; i < values.length; i++) {
1225 if (value.contentEquals(values[i])) {
1226 mOpenGLTraces.setValueIndex(i);
1227 mOpenGLTraces.setSummary(mOpenGLTraces.getEntries()[i]);
1231 mOpenGLTraces.setValueIndex(0);
1232 mOpenGLTraces.setSummary(mOpenGLTraces.getEntries()[0]);
1235 private void writeOpenGLTracesOptions(Object newValue) {
1236 SystemProperties.set(OPENGL_TRACES_PROPERTY, newValue == null ? "" : newValue.toString());
1237 pokeSystemProperties();
1238 updateOpenGLTracesOptions();
1241 private void updateAppProcessLimitOptions() {
1243 int limit = ActivityManagerNative.getDefault().getProcessLimit();
1244 CharSequence[] values = mAppProcessLimit.getEntryValues();
1245 for (int i=0; i<values.length; i++) {
1246 int val = Integer.parseInt(values[i].toString());
1249 mHaveDebugSettings = true;
1251 mAppProcessLimit.setValueIndex(i);
1252 mAppProcessLimit.setSummary(mAppProcessLimit.getEntries()[i]);
1256 mAppProcessLimit.setValueIndex(0);
1257 mAppProcessLimit.setSummary(mAppProcessLimit.getEntries()[0]);
1258 } catch (RemoteException e) {
1262 private void writeAppProcessLimitOptions(Object newValue) {
1264 int limit = newValue != null ? Integer.parseInt(newValue.toString()) : -1;
1265 ActivityManagerNative.getDefault().setProcessLimit(limit);
1266 updateAppProcessLimitOptions();
1267 } catch (RemoteException e) {
1271 private void writeShowAllANRsOptions() {
1272 Settings.Secure.putInt(getActivity().getContentResolver(),
1273 Settings.Secure.ANR_SHOW_BACKGROUND,
1274 mShowAllANRs.isChecked() ? 1 : 0);
1277 private void updateShowAllANRsOptions() {
1278 updateSwitchPreference(mShowAllANRs, Settings.Secure.getInt(
1279 getActivity().getContentResolver(), Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0);
1282 private void confirmEnableOemUnlock() {
1283 DialogInterface.OnClickListener onConfirmListener = new DialogInterface.OnClickListener() {
1285 public void onClick(DialogInterface dialog, int which) {
1286 Utils.setOemUnlockEnabled(getActivity(), true);
1291 new AlertDialog.Builder(getActivity())
1292 .setTitle(R.string.confirm_enable_oem_unlock_title)
1293 .setMessage(R.string.confirm_enable_oem_unlock_text)
1294 .setPositiveButton(R.string.enable_text, onConfirmListener)
1295 .setNegativeButton(android.R.string.cancel, null)
1301 public void onSwitchChanged(Switch switchView, boolean isChecked) {
1302 if (switchView != mSwitchBar.getSwitch()) {
1305 if (isChecked != mLastEnabledState) {
1307 mDialogClicked = false;
1308 if (mEnableDialog != null) dismissDialogs();
1309 mEnableDialog = new AlertDialog.Builder(getActivity()).setMessage(
1310 getActivity().getResources().getString(
1311 R.string.dev_settings_warning_message))
1312 .setTitle(R.string.dev_settings_warning_title)
1313 .setPositiveButton(android.R.string.yes, this)
1314 .setNegativeButton(android.R.string.no, this)
1316 mEnableDialog.setOnDismissListener(this);
1318 resetDangerousOptions();
1319 Settings.Global.putInt(getActivity().getContentResolver(),
1320 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
1321 mLastEnabledState = isChecked;
1322 setPrefsEnabledState(mLastEnabledState);
1328 public void onActivityResult(int requestCode, int resultCode, Intent data) {
1329 if (requestCode == RESULT_DEBUG_APP) {
1330 if (resultCode == Activity.RESULT_OK) {
1331 mDebugApp = data.getAction();
1332 writeDebuggerOptions();
1333 updateDebuggerOptions();
1335 } else if (requestCode == REQUEST_CODE_ENABLE_OEM_UNLOCK) {
1336 if (resultCode == Activity.RESULT_OK) {
1337 if (mEnableOemUnlock.isChecked()) {
1338 confirmEnableOemUnlock();
1340 Utils.setOemUnlockEnabled(getActivity(), false);
1344 super.onActivityResult(requestCode, resultCode, data);
1349 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
1350 if (Utils.isMonkeyRunning()) {
1354 if (preference == mEnableAdb) {
1355 if (mEnableAdb.isChecked()) {
1356 mDialogClicked = false;
1357 if (mAdbDialog != null) dismissDialogs();
1358 mAdbDialog = new AlertDialog.Builder(getActivity()).setMessage(
1359 getActivity().getResources().getString(R.string.adb_warning_message))
1360 .setTitle(R.string.adb_warning_title)
1361 .setPositiveButton(android.R.string.yes, this)
1362 .setNegativeButton(android.R.string.no, this)
1364 mAdbDialog.setOnDismissListener(this);
1366 Settings.Global.putInt(getActivity().getContentResolver(),
1367 Settings.Global.ADB_ENABLED, 0);
1368 mVerifyAppsOverUsb.setEnabled(false);
1369 mVerifyAppsOverUsb.setChecked(false);
1370 updateBugreportOptions();
1372 } else if (preference == mClearAdbKeys) {
1373 if (mAdbKeysDialog != null) dismissDialogs();
1374 mAdbKeysDialog = new AlertDialog.Builder(getActivity())
1375 .setMessage(R.string.adb_keys_warning_message)
1376 .setPositiveButton(android.R.string.ok, this)
1377 .setNegativeButton(android.R.string.cancel, null)
1379 } else if (preference == mEnableTerminal) {
1380 final PackageManager pm = getActivity().getPackageManager();
1381 pm.setApplicationEnabledSetting(TERMINAL_APP_PACKAGE,
1382 mEnableTerminal.isChecked() ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
1383 : PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
1384 } else if (preference == mBugreportInPower) {
1385 Settings.Secure.putInt(getActivity().getContentResolver(),
1386 Settings.Secure.BUGREPORT_IN_POWER_MENU,
1387 mBugreportInPower.isChecked() ? 1 : 0);
1388 } else if (preference == mKeepScreenOn) {
1389 Settings.Global.putInt(getActivity().getContentResolver(),
1390 Settings.Global.STAY_ON_WHILE_PLUGGED_IN,
1391 mKeepScreenOn.isChecked() ?
1392 (BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB) : 0);
1393 } else if (preference == mBtHciSnoopLog) {
1394 writeBtHciSnoopLogOptions();
1395 } else if (preference == mEnableOemUnlock) {
1396 if (!showKeyguardConfirmation(getResources(), REQUEST_CODE_ENABLE_OEM_UNLOCK)) {
1397 if (mEnableOemUnlock.isChecked()) {
1398 confirmEnableOemUnlock();
1400 Utils.setOemUnlockEnabled(getActivity(), false);
1403 } else if (preference == mAllowMockLocation) {
1404 Settings.Secure.putInt(getActivity().getContentResolver(),
1405 Settings.Secure.ALLOW_MOCK_LOCATION,
1406 mAllowMockLocation.isChecked() ? 1 : 0);
1407 } else if (preference == mDebugViewAttributes) {
1408 Settings.Global.putInt(getActivity().getContentResolver(),
1409 Settings.Global.DEBUG_VIEW_ATTRIBUTES,
1410 mDebugViewAttributes.isChecked() ? 1 : 0);
1411 } else if (preference == mDebugAppPref) {
1412 startActivityForResult(new Intent(getActivity(), AppPicker.class), RESULT_DEBUG_APP);
1413 } else if (preference == mWaitForDebugger) {
1414 writeDebuggerOptions();
1415 } else if (preference == mVerifyAppsOverUsb) {
1416 writeVerifyAppsOverUsbOptions();
1417 } else if (preference == mStrictMode) {
1418 writeStrictModeVisualOptions();
1419 } else if (preference == mPointerLocation) {
1420 writePointerLocationOptions();
1421 } else if (preference == mShowTouches) {
1422 writeShowTouchesOptions();
1423 } else if (preference == mShowScreenUpdates) {
1424 writeShowUpdatesOption();
1425 } else if (preference == mDisableOverlays) {
1426 writeDisableOverlaysOption();
1427 } else if (preference == mShowCpuUsage) {
1428 writeCpuUsageOptions();
1429 } else if (preference == mImmediatelyDestroyActivities) {
1430 writeImmediatelyDestroyActivitiesOptions();
1431 } else if (preference == mShowAllANRs) {
1432 writeShowAllANRsOptions();
1433 } else if (preference == mForceHardwareUi) {
1434 writeHardwareUiOptions();
1435 } else if (preference == mForceMsaa) {
1437 } else if (preference == mShowHwScreenUpdates) {
1438 writeShowHwScreenUpdatesOptions();
1439 } else if (preference == mShowHwLayersUpdates) {
1440 writeShowHwLayersUpdatesOptions();
1441 } else if (preference == mDebugLayout) {
1442 writeDebugLayoutOptions();
1443 } else if (preference == mForceRtlLayout) {
1444 writeForceRtlOptions();
1445 } else if (preference == mWifiDisplayCertification) {
1446 writeWifiDisplayCertificationOptions();
1447 } else if (preference == mWifiVerboseLogging) {
1448 writeWifiVerboseLoggingOptions();
1449 } else if (preference == mWifiAggressiveHandover) {
1450 writeWifiAggressiveHandoverOptions();
1451 } else if (preference == mWifiAllowScansWithTraffic) {
1452 writeWifiAllowScansWithTrafficOptions();
1453 } else if (preference == mUseAwesomePlayer) {
1454 writeUseAwesomePlayerOptions();
1455 } else if (preference == mUSBAudio) {
1456 writeUSBAudioOptions();
1458 return super.onPreferenceTreeClick(preferenceScreen, preference);
1464 private boolean showKeyguardConfirmation(Resources resources, int requestCode) {
1465 return new ChooseLockSettingsHelper(getActivity(), this)
1466 .launchConfirmationActivity(requestCode,
1467 resources.getString(R.string.oem_unlock_enable_pin_prompt),
1468 resources.getString(R.string.oem_unlock_enable_pin_description));
1472 public boolean onPreferenceChange(Preference preference, Object newValue) {
1473 if (HDCP_CHECKING_KEY.equals(preference.getKey())) {
1474 SystemProperties.set(HDCP_CHECKING_PROPERTY, newValue.toString());
1476 pokeSystemProperties();
1478 } else if (preference == mLogdSize) {
1479 writeLogdSizeOption(newValue);
1481 } else if (preference == mWindowAnimationScale) {
1482 writeAnimationScaleOption(0, mWindowAnimationScale, newValue);
1484 } else if (preference == mTransitionAnimationScale) {
1485 writeAnimationScaleOption(1, mTransitionAnimationScale, newValue);
1487 } else if (preference == mAnimatorDurationScale) {
1488 writeAnimationScaleOption(2, mAnimatorDurationScale, newValue);
1490 } else if (preference == mOverlayDisplayDevices) {
1491 writeOverlayDisplayDevicesOptions(newValue);
1493 } else if (preference == mOpenGLTraces) {
1494 writeOpenGLTracesOptions(newValue);
1496 } else if (preference == mTrackFrameTime) {
1497 writeTrackFrameTimeOptions(newValue);
1499 } else if (preference == mDebugHwOverdraw) {
1500 writeDebugHwOverdrawOptions(newValue);
1502 } else if (preference == mShowNonRectClip) {
1503 writeShowNonRectClipOptions(newValue);
1505 } else if (preference == mAppProcessLimit) {
1506 writeAppProcessLimitOptions(newValue);
1508 } else if (preference == mSimulateColorSpace) {
1509 writeSimulateColorSpace(newValue);
1515 private void dismissDialogs() {
1516 if (mAdbDialog != null) {
1517 mAdbDialog.dismiss();
1520 if (mAdbKeysDialog != null) {
1521 mAdbKeysDialog.dismiss();
1522 mAdbKeysDialog = null;
1524 if (mEnableDialog != null) {
1525 mEnableDialog.dismiss();
1526 mEnableDialog = null;
1530 public void onClick(DialogInterface dialog, int which) {
1531 if (dialog == mAdbDialog) {
1532 if (which == DialogInterface.BUTTON_POSITIVE) {
1533 mDialogClicked = true;
1534 Settings.Global.putInt(getActivity().getContentResolver(),
1535 Settings.Global.ADB_ENABLED, 1);
1536 mVerifyAppsOverUsb.setEnabled(true);
1537 updateVerifyAppsOverUsbOptions();
1538 updateBugreportOptions();
1541 mEnableAdb.setChecked(false);
1543 } else if (dialog == mAdbKeysDialog) {
1544 if (which == DialogInterface.BUTTON_POSITIVE) {
1546 IBinder b = ServiceManager.getService(Context.USB_SERVICE);
1547 IUsbManager service = IUsbManager.Stub.asInterface(b);
1548 service.clearUsbDebuggingKeys();
1549 } catch (RemoteException e) {
1550 Log.e(TAG, "Unable to clear adb keys", e);
1553 } else if (dialog == mEnableDialog) {
1554 if (which == DialogInterface.BUTTON_POSITIVE) {
1555 mDialogClicked = true;
1556 Settings.Global.putInt(getActivity().getContentResolver(),
1557 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
1558 mLastEnabledState = true;
1559 setPrefsEnabledState(mLastEnabledState);
1562 mSwitchBar.setChecked(false);
1567 public void onDismiss(DialogInterface dialog) {
1568 // Assuming that onClick gets called first
1569 if (dialog == mAdbDialog) {
1570 if (!mDialogClicked) {
1571 mEnableAdb.setChecked(false);
1574 } else if (dialog == mEnableDialog) {
1575 if (!mDialogClicked) {
1576 mSwitchBar.setChecked(false);
1578 mEnableDialog = null;
1583 public void onDestroy() {
1588 void pokeSystemProperties() {
1589 if (!mDontPokeProperties) {
1590 //noinspection unchecked
1591 (new SystemPropPoker()).execute();
1595 static class SystemPropPoker extends AsyncTask<Void, Void, Void> {
1597 protected Void doInBackground(Void... params) {
1600 services = ServiceManager.listServices();
1601 } catch (RemoteException e) {
1604 for (String service : services) {
1605 IBinder obj = ServiceManager.checkService(service);
1607 Parcel data = Parcel.obtain();
1609 obj.transact(IBinder.SYSPROPS_TRANSACTION, data, null, 0);
1610 } catch (RemoteException e) {
1611 } catch (Exception e) {
1612 Log.i(TAG, "Someone wrote a bad service '" + service
1613 + "' that doesn't like to be poked: " + e);
1622 private static boolean isPackageInstalled(Context context, String packageName) {
1624 return context.getPackageManager().getPackageInfo(packageName, 0) != null;
1625 } catch (NameNotFoundException e) {
1633 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
1634 new BaseSearchIndexProvider() {
1636 private boolean isShowingDeveloperOptions(Context context) {
1637 return context.getSharedPreferences(DevelopmentSettings.PREF_FILE,
1638 Context.MODE_PRIVATE).getBoolean(
1639 DevelopmentSettings.PREF_SHOW,
1640 android.os.Build.TYPE.equals("eng"));
1644 public List<SearchIndexableResource> getXmlResourcesToIndex(
1645 Context context, boolean enabled) {
1647 if (!isShowingDeveloperOptions(context)) {
1651 final SearchIndexableResource sir = new SearchIndexableResource(context);
1652 sir.xmlResId = R.xml.development_prefs;
1653 return Arrays.asList(sir);
1657 public List<String> getNonIndexableKeys(Context context) {
1658 if (!isShowingDeveloperOptions(context)) {
1662 final List<String> keys = new ArrayList<String>();
1663 if (!showEnableOemUnlockPreference()) {
1664 keys.add(ENABLE_OEM_UNLOCK);