1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 17 package com.android.settings; 18 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.os.UserManager; 57 import android.os.storage.IMountService; 58 import android.provider.SearchIndexableResource; 59 import android.provider.Settings; 60 import android.service.persistentdata.PersistentDataBlockManager; 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.telephony.TelephonyManager; 68 import android.text.TextUtils; 69 import android.util.Log; 70 import android.view.IWindowManager; 71 import android.view.LayoutInflater; 72 import android.view.ThreadedRenderer; 73 import android.view.View; 74 import android.view.ViewGroup; 75 import android.view.accessibility.AccessibilityManager; 76 import android.webkit.IWebViewUpdateService; 77 import android.webkit.WebViewProviderInfo; 78 import android.widget.Switch; 79 import android.widget.Toast; 80 81 import com.android.internal.app.LocalePicker; 82 import com.android.internal.logging.MetricsProto.MetricsEvent; 83 import com.android.settings.applications.BackgroundCheckSummary; 84 import com.android.settings.fuelgauge.InactiveApps; 85 import com.android.settings.search.BaseSearchIndexProvider; 86 import com.android.settings.search.Indexable; 87 import com.android.settings.widget.SwitchBar; 88 import com.android.settingslib.RestrictedLockUtils; 89 import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; 90 import com.android.settingslib.RestrictedSwitchPreference; 91 92 import java.util.ArrayList; 93 import java.util.Arrays; 94 import java.util.HashSet; 95 import java.util.List; 96 97 /* 98 * Displays preferences for application developers. 99 */ 100 public class DevelopmentSettings extends RestrictedSettingsFragment 101 implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener, 102 OnPreferenceChangeListener, SwitchBar.OnSwitchChangeListener, Indexable { 103 private static final String TAG = "DevelopmentSettings"; 104 105 /** 106 * Preference file were development settings prefs are stored. 107 */ 108 public static final String PREF_FILE = "development"; 109 110 /** 111 * Whether to show the development settings to the user. Default is false. 112 */ 113 public static final String PREF_SHOW = "show"; 114 115 private static final String ENABLE_ADB = "enable_adb"; 116 private static final String CLEAR_ADB_KEYS = "clear_adb_keys"; 117 private static final String ENABLE_TERMINAL = "enable_terminal"; 118 private static final String KEEP_SCREEN_ON = "keep_screen_on"; 119 private static final String BT_HCI_SNOOP_LOG = "bt_hci_snoop_log"; 120 private static final String WEBVIEW_PROVIDER_KEY = "select_webview_provider"; 121 private static final String WEBVIEW_MULTIPROCESS_KEY = "enable_webview_multiprocess"; 122 private static final String ENABLE_OEM_UNLOCK = "oem_unlock_enable"; 123 private static final String HDCP_CHECKING_KEY = "hdcp_checking"; 124 private static final String HDCP_CHECKING_PROPERTY = "persist.sys.hdcp_checking"; 125 private static final String LOCAL_BACKUP_PASSWORD = "local_backup_password"; 126 private static final String HARDWARE_UI_PROPERTY = "persist.sys.ui.hw"; 127 private static final String MSAA_PROPERTY = "debug.egl.force_msaa"; 128 private static final String BUGREPORT = "bugreport"; 129 private static final String BUGREPORT_IN_POWER_KEY = "bugreport_in_power"; 130 private static final String OPENGL_TRACES_PROPERTY = "debug.egl.trace"; 131 private static final String TUNER_UI_KEY = "tuner_ui"; 132 private static final String COLOR_TEMPERATURE_PROPERTY = "persist.sys.debug.color_temp"; 133 134 private static final String DEBUG_APP_KEY = "debug_app"; 135 private static final String WAIT_FOR_DEBUGGER_KEY = "wait_for_debugger"; 136 private static final String MOCK_LOCATION_APP_KEY = "mock_location_app"; 137 private static final String VERIFY_APPS_OVER_USB_KEY = "verify_apps_over_usb"; 138 private static final String DEBUG_VIEW_ATTRIBUTES = "debug_view_attributes"; 139 private static final String FORCE_ALLOW_ON_EXTERNAL_KEY = "force_allow_on_external"; 140 private static final String STRICT_MODE_KEY = "strict_mode"; 141 private static final String POINTER_LOCATION_KEY = "pointer_location"; 142 private static final String SHOW_TOUCHES_KEY = "show_touches"; 143 private static final String SHOW_SCREEN_UPDATES_KEY = "show_screen_updates"; 144 private static final String DISABLE_OVERLAYS_KEY = "disable_overlays"; 145 private static final String SIMULATE_COLOR_SPACE = "simulate_color_space"; 146 private static final String USB_AUDIO_KEY = "usb_audio"; 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"; 174 private static final String SELECT_LOGPERSIST_KEY = "select_logpersist"; 175 private static final String SELECT_LOGPERSIST_PROPERTY = "persist.logd.logpersistd"; 176 private static final String ACTUAL_LOGPERSIST_PROPERTY = "logd.logpersistd"; 177 private static final String SELECT_LOGPERSIST_PROPERTY_SERVICE = "logcatd"; 178 private static final String SELECT_LOGPERSIST_PROPERTY_CLEAR = "clear"; 179 private static final String SELECT_LOGPERSIST_PROPERTY_STOP = "stop"; 180 private static final String SELECT_LOGPERSIST_PROPERTY_BUFFER = "persist.logd.logpersistd.buffer"; 181 private static final String ACTUAL_LOGPERSIST_PROPERTY_BUFFER = "logd.logpersistd.buffer"; 182 private static final String ACTUAL_LOGPERSIST_PROPERTY_ENABLE = "logd.logpersistd.enable"; 183 184 private static final String WIFI_DISPLAY_CERTIFICATION_KEY = "wifi_display_certification"; 185 private static final String WIFI_VERBOSE_LOGGING_KEY = "wifi_verbose_logging"; 186 private static final String WIFI_AGGRESSIVE_HANDOVER_KEY = "wifi_aggressive_handover"; 187 private static final String WIFI_ALLOW_SCAN_WITH_TRAFFIC_KEY = "wifi_allow_scan_with_traffic"; 188 private static final String USB_CONFIGURATION_KEY = "select_usb_configuration"; 189 private static final String MOBILE_DATA_ALWAYS_ON = "mobile_data_always_on"; 190 private static final String KEY_COLOR_MODE = "color_mode"; 191 private static final String FORCE_RESIZABLE_KEY = "force_resizable_activities"; 192 private static final String COLOR_TEMPERATURE_KEY = "color_temperature"; 193 194 private static final String BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_KEY = 195 "bluetooth_disable_absolute_volume"; 196 private static final String BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_PROPERTY = 197 "persist.bluetooth.disableabsvol"; 198 199 private static final String INACTIVE_APPS_KEY = "inactive_apps"; 200 201 private static final String IMMEDIATELY_DESTROY_ACTIVITIES_KEY 202 = "immediately_destroy_activities"; 203 private static final String APP_PROCESS_LIMIT_KEY = "app_process_limit"; 204 205 private static final String BACKGROUND_CHECK_KEY = "background_check"; 206 207 private static final String SHOW_ALL_ANRS_KEY = "show_all_anrs"; 208 209 private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive"; 210 211 private static final String TERMINAL_APP_PACKAGE = "com.android.terminal"; 212 213 private static final String KEY_CONVERT_FBE = "convert_to_file_encryption"; 214 215 private static final String OTA_DISABLE_AUTOMATIC_UPDATE_KEY = "ota_disable_automatic_update"; 216 217 private static final int RESULT_DEBUG_APP = 1000; 218 private static final int RESULT_MOCK_LOCATION_APP = 1001; 219 220 private static final String PERSISTENT_DATA_BLOCK_PROP = "ro.frp.pst"; 221 private static final String FLASH_LOCKED_PROP = "ro.boot.flash.locked"; 222 223 private static final String SHORTCUT_MANAGER_RESET_KEY = "reset_shortcut_manager_throttling"; 224 225 private static final int REQUEST_CODE_ENABLE_OEM_UNLOCK = 0; 226 227 private static final int[] MOCK_LOCATION_APP_OPS = new int[] {AppOpsManager.OP_MOCK_LOCATION}; 228 229 private IWindowManager mWindowManager; 230 private IBackupManager mBackupManager; 231 private IWebViewUpdateService mWebViewUpdateService; 232 private DevicePolicyManager mDpm; 233 private UserManager mUm; 234 private WifiManager mWifiManager; 235 private PersistentDataBlockManager mOemUnlockManager; 236 private TelephonyManager mTelephonyManager; 237 238 private SwitchBar mSwitchBar; 239 private boolean mLastEnabledState; 240 private boolean mHaveDebugSettings; 241 private boolean mDontPokeProperties; 242 243 private SwitchPreference mEnableAdb; 244 private Preference mClearAdbKeys; 245 private SwitchPreference mEnableTerminal; 246 private Preference mBugreport; 247 private SwitchPreference mBugreportInPower; 248 private RestrictedSwitchPreference mKeepScreenOn; 249 private SwitchPreference mBtHciSnoopLog; 250 private RestrictedSwitchPreference mEnableOemUnlock; 251 private SwitchPreference mDebugViewAttributes; 252 private SwitchPreference mForceAllowOnExternal; 253 254 private PreferenceScreen mPassword; 255 private String mDebugApp; 256 private Preference mDebugAppPref; 257 258 private String mMockLocationApp; 259 private Preference mMockLocationAppPref; 260 261 private SwitchPreference mWaitForDebugger; 262 private SwitchPreference mVerifyAppsOverUsb; 263 private SwitchPreference mWifiDisplayCertification; 264 private SwitchPreference mWifiVerboseLogging; 265 private SwitchPreference mWifiAggressiveHandover; 266 private SwitchPreference mMobileDataAlwaysOn; 267 private SwitchPreference mBluetoothDisableAbsVolume; 268 private SwitchPreference mOtaDisableAutomaticUpdate; 269 270 private SwitchPreference mWifiAllowScansWithTraffic; 271 private SwitchPreference mStrictMode; 272 private SwitchPreference mPointerLocation; 273 private SwitchPreference mShowTouches; 274 private SwitchPreference mShowScreenUpdates; 275 private SwitchPreference mDisableOverlays; 276 private SwitchPreference mForceHardwareUi; 277 private SwitchPreference mForceMsaa; 278 private SwitchPreference mShowHwScreenUpdates; 279 private SwitchPreference mShowHwLayersUpdates; 280 private SwitchPreference mDebugLayout; 281 private SwitchPreference mForceRtlLayout; 282 private ListPreference mDebugHwOverdraw; 283 private ListPreference mLogdSize; 284 private ListPreference mLogpersist; 285 private ListPreference mUsbConfiguration; 286 private ListPreference mTrackFrameTime; 287 private ListPreference mShowNonRectClip; 288 private ListPreference mWindowAnimationScale; 289 private ListPreference mTransitionAnimationScale; 290 private ListPreference mAnimatorDurationScale; 291 private ListPreference mOverlayDisplayDevices; 292 293 private SwitchPreference mWebViewMultiprocess; 294 private ListPreference mWebViewProvider; 295 296 private ListPreference mSimulateColorSpace; 297 298 private SwitchPreference mUSBAudio; 299 private SwitchPreference mImmediatelyDestroyActivities; 300 301 private ListPreference mAppProcessLimit; 302 303 private SwitchPreference mShowAllANRs; 304 305 private ColorModePreference mColorModePreference; 306 307 private SwitchPreference mForceResizable; 308 309 private SwitchPreference mColorTemperaturePreference; 310 311 private final ArrayList<Preference> mAllPrefs = new ArrayList<Preference>(); 312 313 private final ArrayList<SwitchPreference> mResetSwitchPrefs 314 = new ArrayList<SwitchPreference>(); 315 316 private final HashSet<Preference> mDisabledPrefs = new HashSet<Preference>(); 317 // To track whether a confirmation dialog was clicked. 318 private boolean mDialogClicked; 319 private Dialog mEnableDialog; 320 private Dialog mAdbDialog; 321 322 private Dialog mAdbKeysDialog; 323 private boolean mUnavailable; 324 325 private boolean mLogpersistCleared; 326 private Dialog mLogpersistClearDialog; 327 328 public DevelopmentSettings() { 329 super(UserManager.DISALLOW_DEBUGGING_FEATURES); 330 } 331 332 @Override 333 protected int getMetricsCategory() { 334 return MetricsEvent.DEVELOPMENT; 335 } 336 337 @Override 338 public void onCreate(Bundle icicle) { 339 super.onCreate(icicle); 340 341 mWindowManager = IWindowManager.Stub.asInterface(ServiceManager.getService("window")); 342 mBackupManager = IBackupManager.Stub.asInterface( 343 ServiceManager.getService(Context.BACKUP_SERVICE)); 344 mWebViewUpdateService = 345 IWebViewUpdateService.Stub.asInterface(ServiceManager.getService("webviewupdate")); 346 mOemUnlockManager = (PersistentDataBlockManager)getActivity() 347 .getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE); 348 mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); 349 350 mDpm = (DevicePolicyManager)getActivity().getSystemService(Context.DEVICE_POLICY_SERVICE); 351 mUm = (UserManager) getSystemService(Context.USER_SERVICE); 352 353 mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); 354 355 setIfOnlyAvailableForAdmins(true); 356 if (isUiRestricted() || !Utils.isDeviceProvisioned(getActivity())) { 357 // Block access to developer options if the user is not the owner, if user policy 358 // restricts it, or if the device has not been provisioned 359 mUnavailable = true; 360 setPreferenceScreen(new PreferenceScreen(getPrefContext(), null)); 361 return; 362 } 363 364 addPreferencesFromResource(R.xml.development_prefs); 365 366 final PreferenceGroup debugDebuggingCategory = (PreferenceGroup) 367 findPreference(DEBUG_DEBUGGING_CATEGORY_KEY); 368 mEnableAdb = findAndInitSwitchPref(ENABLE_ADB); 369 mClearAdbKeys = findPreference(CLEAR_ADB_KEYS); 370 if (!SystemProperties.getBoolean("ro.adb.secure", false)) { 371 if (debugDebuggingCategory != null) { 372 debugDebuggingCategory.removePreference(mClearAdbKeys); 373 } 374 } 375 mAllPrefs.add(mClearAdbKeys); 376 mEnableTerminal = findAndInitSwitchPref(ENABLE_TERMINAL); 377 if (!isPackageInstalled(getActivity(), TERMINAL_APP_PACKAGE)) { 378 debugDebuggingCategory.removePreference(mEnableTerminal); 379 mEnableTerminal = null; 380 } 381 382 mBugreport = findPreference(BUGREPORT); 383 mBugreportInPower = findAndInitSwitchPref(BUGREPORT_IN_POWER_KEY); 384 mKeepScreenOn = (RestrictedSwitchPreference) findAndInitSwitchPref(KEEP_SCREEN_ON); 385 mBtHciSnoopLog = findAndInitSwitchPref(BT_HCI_SNOOP_LOG); 386 mEnableOemUnlock = (RestrictedSwitchPreference) findAndInitSwitchPref(ENABLE_OEM_UNLOCK); 387 if (!showEnableOemUnlockPreference()) { 388 removePreference(mEnableOemUnlock); 389 mEnableOemUnlock = null; 390 } 391 392 mDebugViewAttributes = findAndInitSwitchPref(DEBUG_VIEW_ATTRIBUTES); 393 mForceAllowOnExternal = findAndInitSwitchPref(FORCE_ALLOW_ON_EXTERNAL_KEY); 394 mPassword = (PreferenceScreen) findPreference(LOCAL_BACKUP_PASSWORD); 395 mAllPrefs.add(mPassword); 396 397 if (!mUm.isAdminUser()) { 398 disableForUser(mEnableAdb); 399 disableForUser(mClearAdbKeys); 400 disableForUser(mEnableTerminal); 401 disableForUser(mPassword); 402 } 403 404 mDebugAppPref = findPreference(DEBUG_APP_KEY); 405 mAllPrefs.add(mDebugAppPref); 406 mWaitForDebugger = findAndInitSwitchPref(WAIT_FOR_DEBUGGER_KEY); 407 408 mMockLocationAppPref = findPreference(MOCK_LOCATION_APP_KEY); 409 mAllPrefs.add(mMockLocationAppPref); 410 411 mVerifyAppsOverUsb = findAndInitSwitchPref(VERIFY_APPS_OVER_USB_KEY); 412 if (!showVerifierSetting()) { 413 if (debugDebuggingCategory != null) { 414 debugDebuggingCategory.removePreference(mVerifyAppsOverUsb); 415 } else { 416 mVerifyAppsOverUsb.setEnabled(false); 417 } 418 } 419 mStrictMode = findAndInitSwitchPref(STRICT_MODE_KEY); 420 mPointerLocation = findAndInitSwitchPref(POINTER_LOCATION_KEY); 421 mShowTouches = findAndInitSwitchPref(SHOW_TOUCHES_KEY); 422 mShowScreenUpdates = findAndInitSwitchPref(SHOW_SCREEN_UPDATES_KEY); 423 mDisableOverlays = findAndInitSwitchPref(DISABLE_OVERLAYS_KEY); 424 mForceHardwareUi = findAndInitSwitchPref(FORCE_HARDWARE_UI_KEY); 425 mForceMsaa = findAndInitSwitchPref(FORCE_MSAA_KEY); 426 mTrackFrameTime = addListPreference(TRACK_FRAME_TIME_KEY); 427 mShowNonRectClip = addListPreference(SHOW_NON_RECTANGULAR_CLIP_KEY); 428 mShowHwScreenUpdates = findAndInitSwitchPref(SHOW_HW_SCREEN_UPDATES_KEY); 429 mShowHwLayersUpdates = findAndInitSwitchPref(SHOW_HW_LAYERS_UPDATES_KEY); 430 mDebugLayout = findAndInitSwitchPref(DEBUG_LAYOUT_KEY); 431 mForceRtlLayout = findAndInitSwitchPref(FORCE_RTL_LAYOUT_KEY); 432 mDebugHwOverdraw = addListPreference(DEBUG_HW_OVERDRAW_KEY); 433 mWifiDisplayCertification = findAndInitSwitchPref(WIFI_DISPLAY_CERTIFICATION_KEY); 434 mWifiVerboseLogging = findAndInitSwitchPref(WIFI_VERBOSE_LOGGING_KEY); 435 mWifiAggressiveHandover = findAndInitSwitchPref(WIFI_AGGRESSIVE_HANDOVER_KEY); 436 mWifiAllowScansWithTraffic = findAndInitSwitchPref(WIFI_ALLOW_SCAN_WITH_TRAFFIC_KEY); 437 mMobileDataAlwaysOn = findAndInitSwitchPref(MOBILE_DATA_ALWAYS_ON); 438 mLogdSize = addListPreference(SELECT_LOGD_SIZE_KEY); 439 if ("1".equals(SystemProperties.get("ro.debuggable", "0"))) { 440 mLogpersist = addListPreference(SELECT_LOGPERSIST_KEY); 441 } else { 442 mLogpersist = (ListPreference) findPreference(SELECT_LOGPERSIST_KEY); 443 if (mLogpersist != null) { 444 mLogpersist.setEnabled(false); 445 if (debugDebuggingCategory != null) { 446 debugDebuggingCategory.removePreference(mLogpersist); 447 } 448 } 449 mLogpersist = null; 450 } 451 mUsbConfiguration = addListPreference(USB_CONFIGURATION_KEY); 452 mWebViewProvider = addListPreference(WEBVIEW_PROVIDER_KEY); 453 mWebViewMultiprocess = findAndInitSwitchPref(WEBVIEW_MULTIPROCESS_KEY); 454 mBluetoothDisableAbsVolume = findAndInitSwitchPref(BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_KEY); 455 456 mWindowAnimationScale = addListPreference(WINDOW_ANIMATION_SCALE_KEY); 457 mTransitionAnimationScale = addListPreference(TRANSITION_ANIMATION_SCALE_KEY); 458 mAnimatorDurationScale = addListPreference(ANIMATOR_DURATION_SCALE_KEY); 459 mOverlayDisplayDevices = addListPreference(OVERLAY_DISPLAY_DEVICES_KEY); 460 mSimulateColorSpace = addListPreference(SIMULATE_COLOR_SPACE); 461 mUSBAudio = findAndInitSwitchPref(USB_AUDIO_KEY); 462 mForceResizable = findAndInitSwitchPref(FORCE_RESIZABLE_KEY); 463 464 mImmediatelyDestroyActivities = (SwitchPreference) findPreference( 465 IMMEDIATELY_DESTROY_ACTIVITIES_KEY); 466 mAllPrefs.add(mImmediatelyDestroyActivities); 467 mResetSwitchPrefs.add(mImmediatelyDestroyActivities); 468 469 mAppProcessLimit = addListPreference(APP_PROCESS_LIMIT_KEY); 470 471 mShowAllANRs = (SwitchPreference) findPreference( 472 SHOW_ALL_ANRS_KEY); 473 mAllPrefs.add(mShowAllANRs); 474 mResetSwitchPrefs.add(mShowAllANRs); 475 476 Preference hdcpChecking = findPreference(HDCP_CHECKING_KEY); 477 if (hdcpChecking != null) { 478 mAllPrefs.add(hdcpChecking); 479 removePreferenceForProduction(hdcpChecking); 480 } 481 482 PreferenceScreen convertFbePreference = 483 (PreferenceScreen) findPreference(KEY_CONVERT_FBE); 484 485 try { 486 IBinder service = ServiceManager.getService("mount"); 487 IMountService mountService = IMountService.Stub.asInterface(service); 488 if (!mountService.isConvertibleToFBE()) { 489 removePreference(KEY_CONVERT_FBE); 490 } else if ("file".equals(SystemProperties.get("ro.crypto.type", "none"))) { 491 convertFbePreference.setEnabled(false); 492 convertFbePreference.setSummary(getResources() 493 .getString(R.string.convert_to_file_encryption_done)); 494 } 495 } catch(RemoteException e) { 496 removePreference(KEY_CONVERT_FBE); 497 } 498 499 mOtaDisableAutomaticUpdate = findAndInitSwitchPref(OTA_DISABLE_AUTOMATIC_UPDATE_KEY); 500 501 mColorModePreference = (ColorModePreference) findPreference(KEY_COLOR_MODE); 502 mColorModePreference.updateCurrentAndSupported(); 503 if (mColorModePreference.getColorModeCount() < 2) { 504 removePreference(KEY_COLOR_MODE); 505 mColorModePreference = null; 506 } 507 updateWebViewProviderOptions(); 508 509 mColorTemperaturePreference = (SwitchPreference) findPreference(COLOR_TEMPERATURE_KEY); 510 if (getResources().getBoolean(R.bool.config_enableColorTemperature)) { 511 mAllPrefs.add(mColorTemperaturePreference); 512 mResetSwitchPrefs.add(mColorTemperaturePreference); 513 } else { 514 removePreference(COLOR_TEMPERATURE_KEY); 515 mColorTemperaturePreference = null; 516 } 517 } 518 519 private ListPreference addListPreference(String prefKey) { 520 ListPreference pref = (ListPreference) findPreference(prefKey); 521 mAllPrefs.add(pref); 522 pref.setOnPreferenceChangeListener(this); 523 return pref; 524 } 525 526 private void disableForUser(Preference pref) { 527 if (pref != null) { 528 pref.setEnabled(false); 529 mDisabledPrefs.add(pref); 530 } 531 } 532 533 private SwitchPreference findAndInitSwitchPref(String key) { 534 SwitchPreference pref = (SwitchPreference) findPreference(key); 535 if (pref == null) { 536 throw new IllegalArgumentException("Cannot find preference with key = " + key); 537 } 538 mAllPrefs.add(pref); 539 mResetSwitchPrefs.add(pref); 540 return pref; 541 } 542 543 @Override 544 public void onActivityCreated(Bundle savedInstanceState) { 545 super.onActivityCreated(savedInstanceState); 546 547 final SettingsActivity activity = (SettingsActivity) getActivity(); 548 549 mSwitchBar = activity.getSwitchBar(); 550 if (mUnavailable) { 551 mSwitchBar.setEnabled(false); 552 return; 553 } 554 555 mSwitchBar.addOnSwitchChangeListener(this); 556 } 557 558 private boolean removePreferenceForProduction(Preference preference) { 559 if ("user".equals(Build.TYPE)) { 560 removePreference(preference); 561 return true; 562 } 563 return false; 564 } 565 566 private void removePreference(Preference preference) { 567 getPreferenceScreen().removePreference(preference); 568 mAllPrefs.remove(preference); 569 mResetSwitchPrefs.remove(preference); 570 } 571 572 private void setPrefsEnabledState(boolean enabled) { 573 for (int i = 0; i < mAllPrefs.size(); i++) { 574 Preference pref = mAllPrefs.get(i); 575 pref.setEnabled(enabled && !mDisabledPrefs.contains(pref)); 576 } 577 updateAllOptions(); 578 } 579 580 @Override 581 public void onResume() { 582 super.onResume(); 583 584 if (mUnavailable) { 585 // Show error message 586 if (!isUiRestrictedByOnlyAdmin()) { 587 getEmptyTextView().setText(R.string.development_settings_not_available); 588 } 589 getPreferenceScreen().removeAll(); 590 return; 591 } 592 593 // A DeviceAdmin has specified a maximum time until the device 594 // will lock... in this case we can't allow the user to turn 595 // on "stay awake when plugged in" because that would defeat the 596 // restriction. 597 final EnforcedAdmin admin = RestrictedLockUtils.checkIfMaximumTimeToLockIsSet( 598 getActivity()); 599 mKeepScreenOn.setDisabledByAdmin(admin); 600 if (admin == null) { 601 mDisabledPrefs.remove(mKeepScreenOn); 602 } else { 603 mDisabledPrefs.add(mKeepScreenOn); 604 } 605 606 final ContentResolver cr = getActivity().getContentResolver(); 607 mLastEnabledState = Settings.Global.getInt(cr, 608 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0; 609 mSwitchBar.setChecked(mLastEnabledState); 610 setPrefsEnabledState(mLastEnabledState); 611 612 if (mHaveDebugSettings && !mLastEnabledState) { 613 // Overall debugging is disabled, but there are some debug 614 // settings that are enabled. This is an invalid state. Switch 615 // to debug settings being enabled, so the user knows there is 616 // stuff enabled and can turn it all off if they want. 617 Settings.Global.putInt(getActivity().getContentResolver(), 618 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1); 619 mLastEnabledState = true; 620 mSwitchBar.setChecked(mLastEnabledState); 621 setPrefsEnabledState(mLastEnabledState); 622 } 623 mSwitchBar.show(); 624 625 if (mColorModePreference != null) { 626 mColorModePreference.startListening(); 627 mColorModePreference.updateCurrentAndSupported(); 628 } 629 } 630 631 @Override 632 public void onPause() { 633 super.onPause(); 634 if (mColorModePreference != null) { 635 mColorModePreference.stopListening(); 636 } 637 } 638 639 @Override 640 public View onCreateView(LayoutInflater inflater, ViewGroup container, 641 Bundle savedInstanceState) { 642 IntentFilter filter = new IntentFilter(); 643 filter.addAction(UsbManager.ACTION_USB_STATE); 644 if (getActivity().registerReceiver(mUsbReceiver, filter) == null) { 645 updateUsbConfigurationValues(); 646 } 647 return super.onCreateView(inflater, container, savedInstanceState); 648 } 649 650 @Override 651 public void onDestroyView() { 652 super.onDestroyView(); 653 654 if (mUnavailable) { 655 return; 656 } 657 mSwitchBar.removeOnSwitchChangeListener(this); 658 mSwitchBar.hide(); 659 getActivity().unregisterReceiver(mUsbReceiver); 660 } 661 662 void updateSwitchPreference(SwitchPreference switchPreference, boolean value) { 663 switchPreference.setChecked(value); 664 mHaveDebugSettings |= value; 665 } 666 667 private void updateAllOptions() { 668 final Context context = getActivity(); 669 final ContentResolver cr = context.getContentResolver(); 670 mHaveDebugSettings = false; 671 updateSwitchPreference(mEnableAdb, Settings.Global.getInt(cr, 672 Settings.Global.ADB_ENABLED, 0) != 0); 673 if (mEnableTerminal != null) { 674 updateSwitchPreference(mEnableTerminal, 675 context.getPackageManager().getApplicationEnabledSetting(TERMINAL_APP_PACKAGE) 676 == PackageManager.COMPONENT_ENABLED_STATE_ENABLED); 677 } 678 updateSwitchPreference(mBugreportInPower, Settings.Secure.getInt(cr, 679 Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0); 680 updateSwitchPreference(mKeepScreenOn, Settings.Global.getInt(cr, 681 Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0) != 0); 682 updateSwitchPreference(mBtHciSnoopLog, Settings.Secure.getInt(cr, 683 Settings.Secure.BLUETOOTH_HCI_LOG, 0) != 0); 684 updateSwitchPreference(mDebugViewAttributes, Settings.Global.getInt(cr, 685 Settings.Global.DEBUG_VIEW_ATTRIBUTES, 0) != 0); 686 updateSwitchPreference(mForceAllowOnExternal, Settings.Global.getInt(cr, 687 Settings.Global.FORCE_ALLOW_ON_EXTERNAL, 0) != 0); 688 updateHdcpValues(); 689 updatePasswordSummary(); 690 updateDebuggerOptions(); 691 updateMockLocation(); 692 updateStrictModeVisualOptions(); 693 updatePointerLocationOptions(); 694 updateShowTouchesOptions(); 695 updateFlingerOptions(); 696 updateHardwareUiOptions(); 697 updateMsaaOptions(); 698 updateTrackFrameTimeOptions(); 699 updateShowNonRectClipOptions(); 700 updateShowHwScreenUpdatesOptions(); 701 updateShowHwLayersUpdatesOptions(); 702 updateDebugHwOverdrawOptions(); 703 updateDebugLayoutOptions(); 704 updateAnimationScaleOptions(); 705 updateOverlayDisplayDevicesOptions(); 706 updateImmediatelyDestroyActivitiesOptions(); 707 updateAppProcessLimitOptions(); 708 updateShowAllANRsOptions(); 709 updateVerifyAppsOverUsbOptions(); 710 updateOtaDisableAutomaticUpdateOptions(); 711 updateBugreportOptions(); 712 updateForceRtlOptions(); 713 updateLogdSizeValues(); 714 updateLogpersistValues(); 715 updateWifiDisplayCertificationOptions(); 716 updateWifiVerboseLoggingOptions(); 717 updateWifiAggressiveHandoverOptions(); 718 updateWifiAllowScansWithTrafficOptions(); 719 updateMobileDataAlwaysOnOptions(); 720 updateSimulateColorSpace(); 721 updateUSBAudioOptions(); 722 updateForceResizableOptions(); 723 updateWebViewMultiprocessOptions(); 724 updateWebViewProviderOptions(); 725 updateOemUnlockOptions(); 726 if (mColorTemperaturePreference != null) { 727 updateColorTemperature(); 728 } 729 updateBluetoothDisableAbsVolumeOptions(); 730 } 731 732 private void resetDangerousOptions() { 733 mDontPokeProperties = true; 734 for (int i=0; i< mResetSwitchPrefs.size(); i++) { 735 SwitchPreference cb = mResetSwitchPrefs.get(i); 736 if (cb.isChecked()) { 737 cb.setChecked(false); 738 onPreferenceTreeClick(cb); 739 } 740 } 741 resetDebuggerOptions(); 742 writeLogpersistOption(null, true); 743 writeLogdSizeOption(null); 744 writeAnimationScaleOption(0, mWindowAnimationScale, null); 745 writeAnimationScaleOption(1, mTransitionAnimationScale, null); 746 writeAnimationScaleOption(2, mAnimatorDurationScale, null); 747 // Only poke the color space setting if we control it. 748 if (usingDevelopmentColorSpace()) { 749 writeSimulateColorSpace(-1); 750 } 751 writeOverlayDisplayDevicesOptions(null); 752 writeAppProcessLimitOptions(null); 753 mHaveDebugSettings = false; 754 updateAllOptions(); 755 mDontPokeProperties = false; 756 pokeSystemProperties(); 757 } 758 759 private void updateWebViewProviderOptions() { 760 try { 761 WebViewProviderInfo[] providers = mWebViewUpdateService.getValidWebViewPackages(); 762 if (providers == null) { 763 Log.e(TAG, "No WebView providers available"); 764 return; 765 } 766 ArrayList<String> options = new ArrayList<String>(); 767 ArrayList<String> values = new ArrayList<String>(); 768 for(int n = 0; n < providers.length; n++) { 769 if (Utils.isPackageEnabled(getActivity(), providers[n].packageName)) { 770 options.add(providers[n].description); 771 values.add(providers[n].packageName); 772 } 773 } 774 mWebViewProvider.setEntries(options.toArray(new String[options.size()])); 775 mWebViewProvider.setEntryValues(values.toArray(new String[values.size()])); 776 777 String value = mWebViewUpdateService.getCurrentWebViewPackageName(); 778 if (value == null) { 779 value = ""; 780 } 781 782 for (int i = 0; i < values.size(); i++) { 783 if (value.contentEquals(values.get(i))) { 784 mWebViewProvider.setValueIndex(i); 785 return; 786 } 787 } 788 } catch(RemoteException e) { 789 } 790 } 791 792 private void updateWebViewMultiprocessOptions() { 793 updateSwitchPreference(mWebViewMultiprocess, 794 Settings.Global.getInt(getActivity().getContentResolver(), 795 Settings.Global.WEBVIEW_MULTIPROCESS, 0) != 0); 796 } 797 798 private void writeWebViewMultiprocessOptions() { 799 boolean value = mWebViewMultiprocess.isChecked(); 800 Settings.Global.putInt(getActivity().getContentResolver(), 801 Settings.Global.WEBVIEW_MULTIPROCESS, value ? 1 : 0); 802 803 try { 804 String wv_package = mWebViewUpdateService.getCurrentWebViewPackageName(); 805 ActivityManagerNative.getDefault().killPackageDependents( 806 wv_package, UserHandle.USER_ALL); 807 } catch(RemoteException e) { 808 } 809 } 810 811 private void updateHdcpValues() { 812 ListPreference hdcpChecking = (ListPreference) findPreference(HDCP_CHECKING_KEY); 813 if (hdcpChecking != null) { 814 String currentValue = SystemProperties.get(HDCP_CHECKING_PROPERTY); 815 String[] values = getResources().getStringArray(R.array.hdcp_checking_values); 816 String[] summaries = getResources().getStringArray(R.array.hdcp_checking_summaries); 817 int index = 1; // Defaults to drm-only. Needs to match with R.array.hdcp_checking_values 818 for (int i = 0; i < values.length; i++) { 819 if (currentValue.equals(values[i])) { 820 index = i; 821 break; 822 } 823 } 824 hdcpChecking.setValue(values[index]); 825 hdcpChecking.setSummary(summaries[index]); 826 hdcpChecking.setOnPreferenceChangeListener(this); 827 } 828 } 829 830 private void updatePasswordSummary() { 831 try { 832 if (mBackupManager.hasBackupPassword()) { 833 mPassword.setSummary(R.string.local_backup_password_summary_change); 834 } else { 835 mPassword.setSummary(R.string.local_backup_password_summary_none); 836 } 837 } catch (RemoteException e) { 838 // Not much we can do here 839 } 840 } 841 842 private void writeBtHciSnoopLogOptions() { 843 BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); 844 adapter.configHciSnoopLog(mBtHciSnoopLog.isChecked()); 845 Settings.Secure.putInt(getActivity().getContentResolver(), 846 Settings.Secure.BLUETOOTH_HCI_LOG, 847 mBtHciSnoopLog.isChecked() ? 1 : 0); 848 } 849 850 private boolean writeWebViewProviderOptions(Object newValue) { 851 try { 852 String updatedProvider = mWebViewUpdateService.changeProviderAndSetting( 853 newValue == null ? "" : newValue.toString()); 854 updateWebViewProviderOptions(); 855 return newValue != null && newValue.equals(updatedProvider); 856 } catch(RemoteException e) { 857 } 858 return false; 859 } 860 861 private void writeDebuggerOptions() { 862 try { 863 ActivityManagerNative.getDefault().setDebugApp( 864 mDebugApp, mWaitForDebugger.isChecked(), true); 865 } catch (RemoteException ex) { 866 } 867 } 868 869 private void writeMockLocation() { 870 AppOpsManager appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE); 871 872 // Disable the app op of the previous mock location app if such. 873 List<PackageOps> packageOps = appOpsManager.getPackagesForOps(MOCK_LOCATION_APP_OPS); 874 if (packageOps != null) { 875 // Should be one but in case we are in a bad state due to use of command line tools. 876 for (PackageOps packageOp : packageOps) { 877 if (packageOp.getOps().get(0).getMode() != AppOpsManager.MODE_ERRORED) { 878 String oldMockLocationApp = packageOp.getPackageName(); 879 try { 880 ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo( 881 oldMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS); 882 appOpsManager.setMode(AppOpsManager.OP_MOCK_LOCATION, ai.uid, 883 oldMockLocationApp, AppOpsManager.MODE_ERRORED); 884 } catch (NameNotFoundException e) { 885 /* ignore */ 886 } 887 } 888 } 889 } 890 891 // Enable the app op of the new mock location app if such. 892 if (!TextUtils.isEmpty(mMockLocationApp)) { 893 try { 894 ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo( 895 mMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS); 896 appOpsManager.setMode(AppOpsManager.OP_MOCK_LOCATION, ai.uid, 897 mMockLocationApp, AppOpsManager.MODE_ALLOWED); 898 } catch (NameNotFoundException e) { 899 /* ignore */ 900 } 901 } 902 } 903 904 private static void resetDebuggerOptions() { 905 try { 906 ActivityManagerNative.getDefault().setDebugApp( 907 null, false, true); 908 } catch (RemoteException ex) { 909 } 910 } 911 912 private void updateDebuggerOptions() { 913 mDebugApp = Settings.Global.getString( 914 getActivity().getContentResolver(), Settings.Global.DEBUG_APP); 915 updateSwitchPreference(mWaitForDebugger, Settings.Global.getInt( 916 getActivity().getContentResolver(), Settings.Global.WAIT_FOR_DEBUGGER, 0) != 0); 917 if (mDebugApp != null && mDebugApp.length() > 0) { 918 String label; 919 try { 920 ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(mDebugApp, 921 PackageManager.GET_DISABLED_COMPONENTS); 922 CharSequence lab = getActivity().getPackageManager().getApplicationLabel(ai); 923 label = lab != null ? lab.toString() : mDebugApp; 924 } catch (PackageManager.NameNotFoundException e) { 925 label = mDebugApp; 926 } 927 mDebugAppPref.setSummary(getResources().getString(R.string.debug_app_set, label)); 928 mWaitForDebugger.setEnabled(true); 929 mHaveDebugSettings = true; 930 } else { 931 mDebugAppPref.setSummary(getResources().getString(R.string.debug_app_not_set)); 932 mWaitForDebugger.setEnabled(false); 933 } 934 } 935 936 private void updateMockLocation() { 937 AppOpsManager appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE); 938 939 List<PackageOps> packageOps = appOpsManager.getPackagesForOps(MOCK_LOCATION_APP_OPS); 940 if (packageOps != null) { 941 for (PackageOps packageOp : packageOps) { 942 if (packageOp.getOps().get(0).getMode() == AppOpsManager.MODE_ALLOWED) { 943 mMockLocationApp = packageOps.get(0).getPackageName(); 944 break; 945 } 946 } 947 } 948 949 if (!TextUtils.isEmpty(mMockLocationApp)) { 950 String label = mMockLocationApp; 951 try { 952 ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo( 953 mMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS); 954 CharSequence appLabel = getPackageManager().getApplicationLabel(ai); 955 if (appLabel != null) { 956 label = appLabel.toString(); 957 } 958 } catch (PackageManager.NameNotFoundException e) { 959 /* ignore */ 960 } 961 962 mMockLocationAppPref.setSummary(getString(R.string.mock_location_app_set, label)); 963 mHaveDebugSettings = true; 964 } else { 965 mMockLocationAppPref.setSummary(getString(R.string.mock_location_app_not_set)); 966 } 967 } 968 969 private void updateVerifyAppsOverUsbOptions() { 970 updateSwitchPreference(mVerifyAppsOverUsb, Settings.Global.getInt(getActivity().getContentResolver(), 971 Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1) != 0); 972 mVerifyAppsOverUsb.setEnabled(enableVerifierSetting()); 973 } 974 975 private void writeVerifyAppsOverUsbOptions() { 976 Settings.Global.putInt(getActivity().getContentResolver(), 977 Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, 978 mVerifyAppsOverUsb.isChecked() ? 1 : 0); 979 } 980 981 private void updateOtaDisableAutomaticUpdateOptions() { 982 // We use the "disabled status" in code, but show the opposite text 983 // "Automatic system updates" on screen. So a value 0 indicates the 984 // automatic update is enabled. 985 updateSwitchPreference(mOtaDisableAutomaticUpdate, Settings.Global.getInt( 986 getActivity().getContentResolver(), 987 Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, 0) != 1); 988 } 989 990 private void writeOtaDisableAutomaticUpdateOptions() { 991 // We use the "disabled status" in code, but show the opposite text 992 // "Automatic system updates" on screen. So a value 0 indicates the 993 // automatic update is enabled. 994 Settings.Global.putInt(getActivity().getContentResolver(), 995 Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, 996 mOtaDisableAutomaticUpdate.isChecked() ? 0 : 1); 997 } 998 999 private boolean enableVerifierSetting() { 1000 final ContentResolver cr = getActivity().getContentResolver(); 1001 if (Settings.Global.getInt(cr, Settings.Global.ADB_ENABLED, 0) == 0) { 1002 return false; 1003 } 1004 if (Settings.Global.getInt(cr, Settings.Global.PACKAGE_VERIFIER_ENABLE, 1) == 0) { 1005 return false; 1006 } else { 1007 final PackageManager pm = getActivity().getPackageManager(); 1008 final Intent verification = new Intent(Intent.ACTION_PACKAGE_NEEDS_VERIFICATION); 1009 verification.setType(PACKAGE_MIME_TYPE); 1010 verification.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 1011 final List<ResolveInfo> receivers = pm.queryBroadcastReceivers(verification, 0); 1012 if (receivers.size() == 0) { 1013 return false; 1014 } 1015 } 1016 return true; 1017 } 1018 1019 private boolean showVerifierSetting() { 1020 return Settings.Global.getInt(getActivity().getContentResolver(), 1021 Settings.Global.PACKAGE_VERIFIER_SETTING_VISIBLE, 1) > 0; 1022 } 1023 1024 private static boolean showEnableOemUnlockPreference() { 1025 return !SystemProperties.get(PERSISTENT_DATA_BLOCK_PROP).equals(""); 1026 } 1027 1028 private boolean enableOemUnlockPreference() { 1029 return !isBootloaderUnlocked() && isOemUnlockAllowed(); 1030 } 1031 1032 private void updateOemUnlockOptions() { 1033 if (mEnableOemUnlock != null) { 1034 updateSwitchPreference(mEnableOemUnlock, Utils.isOemUnlockEnabled(getActivity())); 1035 updateOemUnlockSettingDescription(); 1036 // Showing mEnableOemUnlock preference as device has persistent data block. 1037 mEnableOemUnlock.setDisabledByAdmin(null); 1038 mEnableOemUnlock.setEnabled(enableOemUnlockPreference()); 1039 if (mEnableOemUnlock.isEnabled()) { 1040 // Check restriction, disable mEnableOemUnlock and apply policy transparency. 1041 mEnableOemUnlock.checkRestrictionAndSetDisabled(UserManager.DISALLOW_FACTORY_RESET); 1042 } 1043 if (mEnableOemUnlock.isEnabled()) { 1044 // Check restriction, disable mEnableOemUnlock and apply policy transparency. 1045 mEnableOemUnlock.checkRestrictionAndSetDisabled(UserManager.DISALLOW_OEM_UNLOCK); 1046 } 1047 } 1048 } 1049 1050 private void updateBugreportOptions() { 1051 mBugreport.setEnabled(true); 1052 mBugreportInPower.setEnabled(true); 1053 setBugreportStorageProviderStatus(); 1054 } 1055 1056 private void setBugreportStorageProviderStatus() { 1057 final ComponentName componentName = new ComponentName("com.android.shell", 1058 "com.android.shell.BugreportStorageProvider"); 1059 final boolean enabled = mBugreportInPower.isChecked(); 1060 getPackageManager().setComponentEnabledSetting(componentName, 1061 enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED 1062 : PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 1063 0); 1064 } 1065 1066 // Returns the current state of the system property that controls 1067 // strictmode flashes. One of: 1068 // 0: not explicitly set one way or another 1069 // 1: on 1070 // 2: off 1071 private static int currentStrictModeActiveIndex() { 1072 if (TextUtils.isEmpty(SystemProperties.get(StrictMode.VISUAL_PROPERTY))) { 1073 return 0; 1074 } 1075 boolean enabled = SystemProperties.getBoolean(StrictMode.VISUAL_PROPERTY, false); 1076 return enabled ? 1 : 2; 1077 } 1078 1079 private void writeStrictModeVisualOptions() { 1080 try { 1081 mWindowManager.setStrictModeVisualIndicatorPreference(mStrictMode.isChecked() 1082 ? "1" : ""); 1083 } catch (RemoteException e) { 1084 } 1085 } 1086 1087 private void updateStrictModeVisualOptions() { 1088 updateSwitchPreference(mStrictMode, currentStrictModeActiveIndex() == 1); 1089 } 1090 1091 private void writePointerLocationOptions() { 1092 Settings.System.putInt(getActivity().getContentResolver(), 1093 Settings.System.POINTER_LOCATION, mPointerLocation.isChecked() ? 1 : 0); 1094 } 1095 1096 private void updatePointerLocationOptions() { 1097 updateSwitchPreference(mPointerLocation, 1098 Settings.System.getInt(getActivity().getContentResolver(), 1099 Settings.System.POINTER_LOCATION, 0) != 0); 1100 } 1101 1102 private void writeShowTouchesOptions() { 1103 Settings.System.putInt(getActivity().getContentResolver(), 1104 Settings.System.SHOW_TOUCHES, mShowTouches.isChecked() ? 1 : 0); 1105 } 1106 1107 private void updateShowTouchesOptions() { 1108 updateSwitchPreference(mShowTouches, 1109 Settings.System.getInt(getActivity().getContentResolver(), 1110 Settings.System.SHOW_TOUCHES, 0) != 0); 1111 } 1112 1113 private void updateFlingerOptions() { 1114 // magic communication with surface flinger. 1115 try { 1116 IBinder flinger = ServiceManager.getService("SurfaceFlinger"); 1117 if (flinger != null) { 1118 Parcel data = Parcel.obtain(); 1119 Parcel reply = Parcel.obtain(); 1120 data.writeInterfaceToken("android.ui.ISurfaceComposer"); 1121 flinger.transact(1010, data, reply, 0); 1122 @SuppressWarnings("unused") 1123 int showCpu = reply.readInt(); 1124 @SuppressWarnings("unused") 1125 int enableGL = reply.readInt(); 1126 int showUpdates = reply.readInt(); 1127 updateSwitchPreference(mShowScreenUpdates, showUpdates != 0); 1128 @SuppressWarnings("unused") 1129 int showBackground = reply.readInt(); 1130 int disableOverlays = reply.readInt(); 1131 updateSwitchPreference(mDisableOverlays, disableOverlays != 0); 1132 reply.recycle(); 1133 data.recycle(); 1134 } 1135 } catch (RemoteException ex) { 1136 } 1137 } 1138 1139 private void writeShowUpdatesOption() { 1140 try { 1141 IBinder flinger = ServiceManager.getService("SurfaceFlinger"); 1142 if (flinger != null) { 1143 Parcel data = Parcel.obtain(); 1144 data.writeInterfaceToken("android.ui.ISurfaceComposer"); 1145 final int showUpdates = mShowScreenUpdates.isChecked() ? 1 : 0; 1146 data.writeInt(showUpdates); 1147 flinger.transact(1002, data, null, 0); 1148 data.recycle(); 1149 1150 updateFlingerOptions(); 1151 } 1152 } catch (RemoteException ex) { 1153 } 1154 } 1155 1156 private void writeDisableOverlaysOption() { 1157 try { 1158 IBinder flinger = ServiceManager.getService("SurfaceFlinger"); 1159 if (flinger != null) { 1160 Parcel data = Parcel.obtain(); 1161 data.writeInterfaceToken("android.ui.ISurfaceComposer"); 1162 final int disableOverlays = mDisableOverlays.isChecked() ? 1 : 0; 1163 data.writeInt(disableOverlays); 1164 flinger.transact(1008, data, null, 0); 1165 data.recycle(); 1166 1167 updateFlingerOptions(); 1168 } 1169 } catch (RemoteException ex) { 1170 } 1171 } 1172 1173 private void updateHardwareUiOptions() { 1174 updateSwitchPreference(mForceHardwareUi, 1175 SystemProperties.getBoolean(HARDWARE_UI_PROPERTY, false)); 1176 } 1177 1178 private void writeHardwareUiOptions() { 1179 SystemProperties.set(HARDWARE_UI_PROPERTY, mForceHardwareUi.isChecked() ? "true" : "false"); 1180 pokeSystemProperties(); 1181 } 1182 1183 private void updateMsaaOptions() { 1184 updateSwitchPreference(mForceMsaa, SystemProperties.getBoolean(MSAA_PROPERTY, false)); 1185 } 1186 1187 private void writeMsaaOptions() { 1188 SystemProperties.set(MSAA_PROPERTY, mForceMsaa.isChecked() ? "true" : "false"); 1189 pokeSystemProperties(); 1190 } 1191 1192 private void updateTrackFrameTimeOptions() { 1193 String value = SystemProperties.get(ThreadedRenderer.PROFILE_PROPERTY); 1194 if (value == null) { 1195 value = ""; 1196 } 1197 1198 CharSequence[] values = mTrackFrameTime.getEntryValues(); 1199 for (int i = 0; i < values.length; i++) { 1200 if (value.contentEquals(values[i])) { 1201 mTrackFrameTime.setValueIndex(i); 1202 mTrackFrameTime.setSummary(mTrackFrameTime.getEntries()[i]); 1203 return; 1204 } 1205 } 1206 mTrackFrameTime.setValueIndex(0); 1207 mTrackFrameTime.setSummary(mTrackFrameTime.getEntries()[0]); 1208 } 1209 1210 private void writeTrackFrameTimeOptions(Object newValue) { 1211 SystemProperties.set(ThreadedRenderer.PROFILE_PROPERTY, 1212 newValue == null ? "" : newValue.toString()); 1213 pokeSystemProperties(); 1214 updateTrackFrameTimeOptions(); 1215 } 1216 1217 private void updateShowNonRectClipOptions() { 1218 String value = SystemProperties.get( 1219 ThreadedRenderer.DEBUG_SHOW_NON_RECTANGULAR_CLIP_PROPERTY); 1220 if (value == null) { 1221 value = "hide"; 1222 } 1223 1224 CharSequence[] values = mShowNonRectClip.getEntryValues(); 1225 for (int i = 0; i < values.length; i++) { 1226 if (value.contentEquals(values[i])) { 1227 mShowNonRectClip.setValueIndex(i); 1228 mShowNonRectClip.setSummary(mShowNonRectClip.getEntries()[i]); 1229 return; 1230 } 1231 } 1232 mShowNonRectClip.setValueIndex(0); 1233 mShowNonRectClip.setSummary(mShowNonRectClip.getEntries()[0]); 1234 } 1235 1236 private void writeShowNonRectClipOptions(Object newValue) { 1237 SystemProperties.set(ThreadedRenderer.DEBUG_SHOW_NON_RECTANGULAR_CLIP_PROPERTY, 1238 newValue == null ? "" : newValue.toString()); 1239 pokeSystemProperties(); 1240 updateShowNonRectClipOptions(); 1241 } 1242 1243 private void updateShowHwScreenUpdatesOptions() { 1244 updateSwitchPreference(mShowHwScreenUpdates, 1245 SystemProperties.getBoolean(ThreadedRenderer.DEBUG_DIRTY_REGIONS_PROPERTY, false)); 1246 } 1247 1248 private void writeShowHwScreenUpdatesOptions() { 1249 SystemProperties.set(ThreadedRenderer.DEBUG_DIRTY_REGIONS_PROPERTY, 1250 mShowHwScreenUpdates.isChecked() ? "true" : null); 1251 pokeSystemProperties(); 1252 } 1253 1254 private void updateShowHwLayersUpdatesOptions() { 1255 updateSwitchPreference(mShowHwLayersUpdates, SystemProperties.getBoolean( 1256 ThreadedRenderer.DEBUG_SHOW_LAYERS_UPDATES_PROPERTY, false)); 1257 } 1258 1259 private void writeShowHwLayersUpdatesOptions() { 1260 SystemProperties.set(ThreadedRenderer.DEBUG_SHOW_LAYERS_UPDATES_PROPERTY, 1261 mShowHwLayersUpdates.isChecked() ? "true" : null); 1262 pokeSystemProperties(); 1263 } 1264 1265 private void updateDebugHwOverdrawOptions() { 1266 String value = SystemProperties.get(ThreadedRenderer.DEBUG_OVERDRAW_PROPERTY); 1267 if (value == null) { 1268 value = ""; 1269 } 1270 1271 CharSequence[] values = mDebugHwOverdraw.getEntryValues(); 1272 for (int i = 0; i < values.length; i++) { 1273 if (value.contentEquals(values[i])) { 1274 mDebugHwOverdraw.setValueIndex(i); 1275 mDebugHwOverdraw.setSummary(mDebugHwOverdraw.getEntries()[i]); 1276 return; 1277 } 1278 } 1279 mDebugHwOverdraw.setValueIndex(0); 1280 mDebugHwOverdraw.setSummary(mDebugHwOverdraw.getEntries()[0]); 1281 } 1282 1283 private void writeDebugHwOverdrawOptions(Object newValue) { 1284 SystemProperties.set(ThreadedRenderer.DEBUG_OVERDRAW_PROPERTY, 1285 newValue == null ? "" : newValue.toString()); 1286 pokeSystemProperties(); 1287 updateDebugHwOverdrawOptions(); 1288 } 1289 1290 private void updateDebugLayoutOptions() { 1291 updateSwitchPreference(mDebugLayout, 1292 SystemProperties.getBoolean(View.DEBUG_LAYOUT_PROPERTY, false)); 1293 } 1294 1295 private void writeDebugLayoutOptions() { 1296 SystemProperties.set(View.DEBUG_LAYOUT_PROPERTY, 1297 mDebugLayout.isChecked() ? "true" : "false"); 1298 pokeSystemProperties(); 1299 } 1300 1301 private void updateSimulateColorSpace() { 1302 final ContentResolver cr = getContentResolver(); 1303 final boolean enabled = Settings.Secure.getInt( 1304 cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0) != 0; 1305 if (enabled) { 1306 final String mode = Integer.toString(Settings.Secure.getInt( 1307 cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER, 1308 AccessibilityManager.DALTONIZER_DISABLED)); 1309 mSimulateColorSpace.setValue(mode); 1310 final int index = mSimulateColorSpace.findIndexOfValue(mode); 1311 if (index < 0) { 1312 // We're using a mode controlled by accessibility preferences. 1313 mSimulateColorSpace.setSummary(getString(R.string.daltonizer_type_overridden, 1314 getString(R.string.accessibility_display_daltonizer_preference_title))); 1315 } else { 1316 mSimulateColorSpace.setSummary("%s"); 1317 } 1318 } else { 1319 mSimulateColorSpace.setValue( 1320 Integer.toString(AccessibilityManager.DALTONIZER_DISABLED)); 1321 } 1322 } 1323 1324 /** 1325 * @return <code>true</code> if the color space preference is currently 1326 * controlled by development settings 1327 */ 1328 private boolean usingDevelopmentColorSpace() { 1329 final ContentResolver cr = getContentResolver(); 1330 final boolean enabled = Settings.Secure.getInt( 1331 cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0) != 0; 1332 if (enabled) { 1333 final String mode = Integer.toString(Settings.Secure.getInt( 1334 cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER, 1335 AccessibilityManager.DALTONIZER_DISABLED)); 1336 final int index = mSimulateColorSpace.findIndexOfValue(mode); 1337 if (index >= 0) { 1338 // We're using a mode controlled by developer preferences. 1339 return true; 1340 } 1341 } 1342 return false; 1343 } 1344 1345 private void writeSimulateColorSpace(Object value) { 1346 final ContentResolver cr = getContentResolver(); 1347 final int newMode = Integer.parseInt(value.toString()); 1348 if (newMode < 0) { 1349 Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0); 1350 } else { 1351 Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 1); 1352 Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER, newMode); 1353 } 1354 } 1355 1356 private void updateColorTemperature() { 1357 updateSwitchPreference(mColorTemperaturePreference, 1358 SystemProperties.getBoolean(COLOR_TEMPERATURE_PROPERTY, false)); 1359 } 1360 1361 private void writeColorTemperature() { 1362 SystemProperties.set(COLOR_TEMPERATURE_PROPERTY, 1363 mColorTemperaturePreference.isChecked() ? "1" : "0"); 1364 pokeSystemProperties(); 1365 Toast.makeText(getActivity(), R.string.color_temperature_toast, Toast.LENGTH_LONG).show(); 1366 } 1367 1368 private void updateUSBAudioOptions() { 1369 updateSwitchPreference(mUSBAudio, Settings.Secure.getInt(getContentResolver(), 1370 Settings.Secure.USB_AUDIO_AUTOMATIC_ROUTING_DISABLED, 0) != 0); 1371 } 1372 1373 private void writeUSBAudioOptions() { 1374 Settings.Secure.putInt(getContentResolver(), 1375 Settings.Secure.USB_AUDIO_AUTOMATIC_ROUTING_DISABLED, 1376 mUSBAudio.isChecked() ? 1 : 0); 1377 } 1378 1379 private void updateForceResizableOptions() { 1380 updateSwitchPreference(mForceResizable, Settings.Global.getInt(getContentResolver(), 1381 Settings.Global.DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES, 0) != 0); 1382 } 1383 1384 private void writeForceResizableOptions() { 1385 Settings.Global.putInt(getContentResolver(), 1386 Settings.Global.DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES, 1387 mForceResizable.isChecked() ? 1 : 0); 1388 } 1389 1390 private void updateForceRtlOptions() { 1391 updateSwitchPreference(mForceRtlLayout, 1392 Settings.Global.getInt(getActivity().getContentResolver(), 1393 Settings.Global.DEVELOPMENT_FORCE_RTL, 0) != 0); 1394 } 1395 1396 private void writeForceRtlOptions() { 1397 boolean value = mForceRtlLayout.isChecked(); 1398 Settings.Global.putInt(getActivity().getContentResolver(), 1399 Settings.Global.DEVELOPMENT_FORCE_RTL, value ? 1 : 0); 1400 SystemProperties.set(Settings.Global.DEVELOPMENT_FORCE_RTL, value ? "1" : "0"); 1401 LocalePicker.updateLocale(getActivity().getResources().getConfiguration().locale); 1402 } 1403 1404 private void updateWifiDisplayCertificationOptions() { 1405 updateSwitchPreference(mWifiDisplayCertification, Settings.Global.getInt( 1406 getActivity().getContentResolver(), 1407 Settings.Global.WIFI_DISPLAY_CERTIFICATION_ON, 0) != 0); 1408 } 1409 1410 private void writeWifiDisplayCertificationOptions() { 1411 Settings.Global.putInt(getActivity().getContentResolver(), 1412 Settings.Global.WIFI_DISPLAY_CERTIFICATION_ON, 1413 mWifiDisplayCertification.isChecked() ? 1 : 0); 1414 } 1415 1416 private void updateWifiVerboseLoggingOptions() { 1417 boolean enabled = mWifiManager.getVerboseLoggingLevel() > 0; 1418 updateSwitchPreference(mWifiVerboseLogging, enabled); 1419 } 1420 1421 private void writeWifiVerboseLoggingOptions() { 1422 mWifiManager.enableVerboseLogging(mWifiVerboseLogging.isChecked() ? 1 : 0); 1423 } 1424 1425 private void updateWifiAggressiveHandoverOptions() { 1426 boolean enabled = mWifiManager.getAggressiveHandover() > 0; 1427 updateSwitchPreference(mWifiAggressiveHandover, enabled); 1428 } 1429 1430 private void writeWifiAggressiveHandoverOptions() { 1431 mWifiManager.enableAggressiveHandover(mWifiAggressiveHandover.isChecked() ? 1 : 0); 1432 } 1433 1434 private void updateWifiAllowScansWithTrafficOptions() { 1435 boolean enabled = mWifiManager.getAllowScansWithTraffic() > 0; 1436 updateSwitchPreference(mWifiAllowScansWithTraffic, enabled); 1437 } 1438 1439 private void writeWifiAllowScansWithTrafficOptions() { 1440 mWifiManager.setAllowScansWithTraffic(mWifiAllowScansWithTraffic.isChecked() ? 1 : 0); 1441 } 1442 1443 private void updateBluetoothDisableAbsVolumeOptions() { 1444 updateSwitchPreference(mBluetoothDisableAbsVolume, 1445 SystemProperties.getBoolean(BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_PROPERTY, false)); 1446 } 1447 1448 private void writeBluetoothDisableAbsVolumeOptions() { 1449 SystemProperties.set(BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_PROPERTY, 1450 mBluetoothDisableAbsVolume.isChecked() ? "true" : "false"); 1451 } 1452 1453 private void updateMobileDataAlwaysOnOptions() { 1454 updateSwitchPreference(mMobileDataAlwaysOn, Settings.Global.getInt( 1455 getActivity().getContentResolver(), 1456 Settings.Global.MOBILE_DATA_ALWAYS_ON, 0) != 0); 1457 } 1458 1459 private void writeMobileDataAlwaysOnOptions() { 1460 Settings.Global.putInt(getActivity().getContentResolver(), 1461 Settings.Global.MOBILE_DATA_ALWAYS_ON, 1462 mMobileDataAlwaysOn.isChecked() ? 1 : 0); 1463 } 1464 1465 private String defaultLogdSizeValue() { 1466 String defaultValue = SystemProperties.get(SELECT_LOGD_DEFAULT_SIZE_PROPERTY); 1467 if ((defaultValue == null) || (defaultValue.length() == 0)) { 1468 if (SystemProperties.get("ro.config.low_ram").equals("true")) { 1469 defaultValue = SELECT_LOGD_SVELTE_DEFAULT_SIZE_VALUE; 1470 } else { 1471 defaultValue = SELECT_LOGD_DEFAULT_SIZE_VALUE; 1472 } 1473 } 1474 return defaultValue; 1475 } 1476 1477 private void updateLogdSizeValues() { 1478 if (mLogdSize != null) { 1479 String currentTag = SystemProperties.get(SELECT_LOGD_TAG_PROPERTY); 1480 String currentValue = SystemProperties.get(SELECT_LOGD_SIZE_PROPERTY); 1481 if ((currentTag != null) && currentTag.startsWith(SELECT_LOGD_TAG_SILENCE)) { 1482 currentValue = SELECT_LOGD_OFF_SIZE_MARKER_VALUE; 1483 } 1484 if (mLogpersist != null) { 1485 String currentLogpersistEnable 1486 = SystemProperties.get(ACTUAL_LOGPERSIST_PROPERTY_ENABLE); 1487 if ((currentLogpersistEnable == null) 1488 || !currentLogpersistEnable.equals("true") 1489 || currentValue.equals(SELECT_LOGD_OFF_SIZE_MARKER_VALUE)) { 1490 writeLogpersistOption(null, true); 1491 mLogpersist.setEnabled(false); 1492 } else if (mLastEnabledState) { 1493 mLogpersist.setEnabled(true); 1494 } 1495 } 1496 if ((currentValue == null) || (currentValue.length() == 0)) { 1497 currentValue = defaultLogdSizeValue(); 1498 } 1499 String[] values = getResources().getStringArray(R.array.select_logd_size_values); 1500 String[] titles = getResources().getStringArray(R.array.select_logd_size_titles); 1501 int index = 2; // punt to second entry if not found 1502 if (SystemProperties.get("ro.config.low_ram").equals("true")) { 1503 mLogdSize.setEntries(R.array.select_logd_size_lowram_titles); 1504 titles = getResources().getStringArray(R.array.select_logd_size_lowram_titles); 1505 index = 1; 1506 } 1507 String[] summaries = getResources().getStringArray(R.array.select_logd_size_summaries); 1508 for (int i = 0; i < titles.length; i++) { 1509 if (currentValue.equals(values[i]) 1510 || currentValue.equals(titles[i])) { 1511 index = i; 1512 break; 1513 } 1514 } 1515 mLogdSize.setValue(values[index]); 1516 mLogdSize.setSummary(summaries[index]); 1517 mLogdSize.setOnPreferenceChangeListener(this); 1518 } 1519 } 1520 1521 private void writeLogdSizeOption(Object newValue) { 1522 boolean disable = (newValue != null) && 1523 (newValue.toString().equals(SELECT_LOGD_OFF_SIZE_MARKER_VALUE)); 1524 String currentTag = SystemProperties.get(SELECT_LOGD_TAG_PROPERTY); 1525 if (currentTag == null) { 1526 currentTag = ""; 1527 } 1528 // filter clean and unstack all references to our setting 1529 String newTag = currentTag.replaceAll( 1530 ",+" + SELECT_LOGD_TAG_SILENCE, "").replaceFirst( 1531 "^" + SELECT_LOGD_TAG_SILENCE + ",*", "").replaceAll( 1532 ",+", ",").replaceFirst( 1533 ",+$", ""); 1534 if (disable) { 1535 newValue = SELECT_LOGD_MINIMUM_SIZE_VALUE; 1536 // Make sure snet_event_log get through first, but do not override 1537 String snetValue = SystemProperties.get(SELECT_LOGD_SNET_TAG_PROPERTY); 1538 if ((snetValue == null) || (snetValue.length() == 0)) { 1539 snetValue = SystemProperties.get(SELECT_LOGD_RUNTIME_SNET_TAG_PROPERTY); 1540 if ((snetValue == null) || (snetValue.length() == 0)) { 1541 SystemProperties.set(SELECT_LOGD_SNET_TAG_PROPERTY, "I"); 1542 } 1543 } 1544 // Silence all log sources, security logs notwithstanding 1545 if (newTag.length() != 0) { 1546 newTag = "," + newTag; 1547 } 1548 // Stack settings, stack to help preserve original value 1549 newTag = SELECT_LOGD_TAG_SILENCE + newTag; 1550 } 1551 if (!newTag.equals(currentTag)) { 1552 SystemProperties.set(SELECT_LOGD_TAG_PROPERTY, newTag); 1553 } 1554 String defaultValue = defaultLogdSizeValue(); 1555 final String size = ((newValue != null) && (newValue.toString().length() != 0)) ? 1556 newValue.toString() : defaultValue; 1557 SystemProperties.set(SELECT_LOGD_SIZE_PROPERTY, defaultValue.equals(size) ? "" : size); 1558 SystemProperties.set("ctl.start", "logd-reinit"); 1559 pokeSystemProperties(); 1560 updateLogdSizeValues(); 1561 } 1562 1563 private void updateLogpersistValues() { 1564 if (mLogpersist == null) { 1565 return; 1566 } 1567 String currentValue = SystemProperties.get(ACTUAL_LOGPERSIST_PROPERTY); 1568 if (currentValue == null) { 1569 currentValue = ""; 1570 } 1571 String currentBuffers = SystemProperties.get(ACTUAL_LOGPERSIST_PROPERTY_BUFFER); 1572 if ((currentBuffers == null) || (currentBuffers.length() == 0)) { 1573 currentBuffers = "all"; 1574 } 1575 int index = 0; 1576 if (currentValue.equals(SELECT_LOGPERSIST_PROPERTY_SERVICE)) { 1577 index = 1; 1578 if (currentBuffers.equals("kernel")) { 1579 index = 3; 1580 } else if (!currentBuffers.equals("all") && 1581 !currentBuffers.contains("radio") && 1582 currentBuffers.contains("security") && 1583 currentBuffers.contains("kernel")) { 1584 index = 2; 1585 if (!currentBuffers.contains("default")) { 1586 String[] contains = { "main", "events", "system", "crash" }; 1587 for (int i = 0; i < contains.length; i++) { 1588 if (!currentBuffers.contains(contains[i])) { 1589 index = 1; 1590 break; 1591 } 1592 } 1593 } 1594 } 1595 } 1596 mLogpersist.setValue(getResources().getStringArray(R.array.select_logpersist_values)[index]); 1597 mLogpersist.setSummary(getResources().getStringArray(R.array.select_logpersist_summaries)[index]); 1598 mLogpersist.setOnPreferenceChangeListener(this); 1599 if (index != 0) { 1600 mLogpersistCleared = false; 1601 } else if (!mLogpersistCleared) { 1602 // would File.delete() directly but need to switch uid/gid to access 1603 SystemProperties.set(ACTUAL_LOGPERSIST_PROPERTY, SELECT_LOGPERSIST_PROPERTY_CLEAR); 1604 pokeSystemProperties(); 1605 mLogpersistCleared = true; 1606 } 1607 } 1608 1609 private void setLogpersistOff(boolean update) { 1610 SystemProperties.set(SELECT_LOGPERSIST_PROPERTY_BUFFER, ""); 1611 // deal with trampoline of empty properties 1612 SystemProperties.set(ACTUAL_LOGPERSIST_PROPERTY_BUFFER, ""); 1613 SystemProperties.set(SELECT_LOGPERSIST_PROPERTY, ""); 1614 SystemProperties.set(ACTUAL_LOGPERSIST_PROPERTY, 1615 update ? "" : SELECT_LOGPERSIST_PROPERTY_STOP); 1616 pokeSystemProperties(); 1617 if (update) { 1618 updateLogpersistValues(); 1619 } else { 1620 for (int i = 0; i < 3; i++) { 1621 String currentValue = SystemProperties.get(ACTUAL_LOGPERSIST_PROPERTY); 1622 if ((currentValue == null) || currentValue.equals("")) { 1623 break; 1624 } 1625 try { 1626 Thread.sleep(100); 1627 } catch (InterruptedException e) { 1628 } 1629 } 1630 } 1631 } 1632 1633 private void writeLogpersistOption(Object newValue, boolean skipWarning) { 1634 if (mLogpersist == null) { 1635 return; 1636 } 1637 String currentTag = SystemProperties.get(SELECT_LOGD_TAG_PROPERTY); 1638 if ((currentTag != null) && currentTag.startsWith(SELECT_LOGD_TAG_SILENCE)) { 1639 newValue = null; 1640 skipWarning = true; 1641 } 1642 1643 if ((newValue == null) || newValue.toString().equals("")) { 1644 if (skipWarning) { 1645 mLogpersistCleared = false; 1646 } else if (!mLogpersistCleared) { 1647 // if transitioning from on to off, pop up an are you sure? 1648 String currentValue = SystemProperties.get(ACTUAL_LOGPERSIST_PROPERTY); 1649 if ((currentValue != null) && 1650 currentValue.equals(SELECT_LOGPERSIST_PROPERTY_SERVICE)) { 1651 if (mLogpersistClearDialog != null) dismissDialogs(); 1652 mLogpersistClearDialog = new AlertDialog.Builder(getActivity()).setMessage( 1653 getActivity().getResources().getString( 1654 R.string.dev_logpersist_clear_warning_message)) 1655 .setTitle(R.string.dev_logpersist_clear_warning_title) 1656 .setPositiveButton(android.R.string.yes, this) 1657 .setNegativeButton(android.R.string.no, this) 1658 .show(); 1659 mLogpersistClearDialog.setOnDismissListener(this); 1660 return; 1661 } 1662 } 1663 setLogpersistOff(true); 1664 return; 1665 } 1666 1667 String currentBuffer = SystemProperties.get(ACTUAL_LOGPERSIST_PROPERTY_BUFFER); 1668 if ((currentBuffer != null) && !currentBuffer.equals(newValue.toString())) { 1669 setLogpersistOff(false); 1670 } 1671 SystemProperties.set(SELECT_LOGPERSIST_PROPERTY_BUFFER, newValue.toString()); 1672 SystemProperties.set(SELECT_LOGPERSIST_PROPERTY, SELECT_LOGPERSIST_PROPERTY_SERVICE); 1673 pokeSystemProperties(); 1674 for (int i = 0; i < 3; i++) { 1675 String currentValue = SystemProperties.get(ACTUAL_LOGPERSIST_PROPERTY); 1676 if ((currentValue != null) 1677 && currentValue.equals(SELECT_LOGPERSIST_PROPERTY_SERVICE)) { 1678 break; 1679 } 1680 try { 1681 Thread.sleep(100); 1682 } catch (InterruptedException e) { 1683 } 1684 } 1685 updateLogpersistValues(); 1686 } 1687 1688 private void updateUsbConfigurationValues() { 1689 if (mUsbConfiguration != null) { 1690 UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); 1691 1692 String[] values = getResources().getStringArray(R.array.usb_configuration_values); 1693 String[] titles = getResources().getStringArray(R.array.usb_configuration_titles); 1694 int index = 0; 1695 for (int i = 0; i < titles.length; i++) { 1696 if (manager.isFunctionEnabled(values[i])) { 1697 index = i; 1698 break; 1699 } 1700 } 1701 mUsbConfiguration.setValue(values[index]); 1702 mUsbConfiguration.setSummary(titles[index]); 1703 mUsbConfiguration.setOnPreferenceChangeListener(this); 1704 } 1705 } 1706 1707 private void writeUsbConfigurationOption(Object newValue) { 1708 UsbManager manager = (UsbManager)getActivity().getSystemService(Context.USB_SERVICE); 1709 String function = newValue.toString(); 1710 manager.setCurrentFunction(function); 1711 if (function.equals("none")) { 1712 manager.setUsbDataUnlocked(false); 1713 } else { 1714 manager.setUsbDataUnlocked(true); 1715 } 1716 } 1717 1718 private void writeImmediatelyDestroyActivitiesOptions() { 1719 try { 1720 ActivityManagerNative.getDefault().setAlwaysFinish( 1721 mImmediatelyDestroyActivities.isChecked()); 1722 } catch (RemoteException ex) { 1723 } 1724 } 1725 1726 private void updateImmediatelyDestroyActivitiesOptions() { 1727 updateSwitchPreference(mImmediatelyDestroyActivities, Settings.Global.getInt( 1728 getActivity().getContentResolver(), Settings.Global.ALWAYS_FINISH_ACTIVITIES, 0) != 0); 1729 } 1730 1731 private void updateAnimationScaleValue(int which, ListPreference pref) { 1732 try { 1733 float scale = mWindowManager.getAnimationScale(which); 1734 if (scale != 1) { 1735 mHaveDebugSettings = true; 1736 } 1737 CharSequence[] values = pref.getEntryValues(); 1738 for (int i=0; i<values.length; i++) { 1739 float val = Float.parseFloat(values[i].toString()); 1740 if (scale <= val) { 1741 pref.setValueIndex(i); 1742 pref.setSummary(pref.getEntries()[i]); 1743 return; 1744 } 1745 } 1746 pref.setValueIndex(values.length-1); 1747 pref.setSummary(pref.getEntries()[0]); 1748 } catch (RemoteException e) { 1749 } 1750 } 1751 1752 private void updateAnimationScaleOptions() { 1753 updateAnimationScaleValue(0, mWindowAnimationScale); 1754 updateAnimationScaleValue(1, mTransitionAnimationScale); 1755 updateAnimationScaleValue(2, mAnimatorDurationScale); 1756 } 1757 1758 private void writeAnimationScaleOption(int which, ListPreference pref, Object newValue) { 1759 try { 1760 float scale = newValue != null ? Float.parseFloat(newValue.toString()) : 1; 1761 mWindowManager.setAnimationScale(which, scale); 1762 updateAnimationScaleValue(which, pref); 1763 } catch (RemoteException e) { 1764 } 1765 } 1766 1767 private void updateOverlayDisplayDevicesOptions() { 1768 String value = Settings.Global.getString(getActivity().getContentResolver(), 1769 Settings.Global.OVERLAY_DISPLAY_DEVICES); 1770 if (value == null) { 1771 value = ""; 1772 } 1773 1774 CharSequence[] values = mOverlayDisplayDevices.getEntryValues(); 1775 for (int i = 0; i < values.length; i++) { 1776 if (value.contentEquals(values[i])) { 1777 mOverlayDisplayDevices.setValueIndex(i); 1778 mOverlayDisplayDevices.setSummary(mOverlayDisplayDevices.getEntries()[i]); 1779 return; 1780 } 1781 } 1782 mOverlayDisplayDevices.setValueIndex(0); 1783 mOverlayDisplayDevices.setSummary(mOverlayDisplayDevices.getEntries()[0]); 1784 } 1785 1786 private void writeOverlayDisplayDevicesOptions(Object newValue) { 1787 Settings.Global.putString(getActivity().getContentResolver(), 1788 Settings.Global.OVERLAY_DISPLAY_DEVICES, (String) newValue); 1789 updateOverlayDisplayDevicesOptions(); 1790 } 1791 1792 private void updateAppProcessLimitOptions() { 1793 try { 1794 int limit = ActivityManagerNative.getDefault().getProcessLimit(); 1795 CharSequence[] values = mAppProcessLimit.getEntryValues(); 1796 for (int i=0; i<values.length; i++) { 1797 int val = Integer.parseInt(values[i].toString()); 1798 if (val >= limit) { 1799 if (i != 0) { 1800 mHaveDebugSettings = true; 1801 } 1802 mAppProcessLimit.setValueIndex(i); 1803 mAppProcessLimit.setSummary(mAppProcessLimit.getEntries()[i]); 1804 return; 1805 } 1806 } 1807 mAppProcessLimit.setValueIndex(0); 1808 mAppProcessLimit.setSummary(mAppProcessLimit.getEntries()[0]); 1809 } catch (RemoteException e) { 1810 } 1811 } 1812 1813 private void writeAppProcessLimitOptions(Object newValue) { 1814 try { 1815 int limit = newValue != null ? Integer.parseInt(newValue.toString()) : -1; 1816 ActivityManagerNative.getDefault().setProcessLimit(limit); 1817 updateAppProcessLimitOptions(); 1818 } catch (RemoteException e) { 1819 } 1820 } 1821 1822 private void writeShowAllANRsOptions() { 1823 Settings.Secure.putInt(getActivity().getContentResolver(), 1824 Settings.Secure.ANR_SHOW_BACKGROUND, 1825 mShowAllANRs.isChecked() ? 1 : 0); 1826 } 1827 1828 private void updateShowAllANRsOptions() { 1829 updateSwitchPreference(mShowAllANRs, Settings.Secure.getInt( 1830 getActivity().getContentResolver(), Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0); 1831 } 1832 1833 private void confirmEnableOemUnlock() { 1834 DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener() { 1835 @Override 1836 public void onClick(DialogInterface dialog, int which) { 1837 if (which == DialogInterface.BUTTON_POSITIVE) { 1838 Utils.setOemUnlockEnabled(getActivity(), true); 1839 } 1840 } 1841 }; 1842 1843 DialogInterface.OnDismissListener onDismissListener = new DialogInterface.OnDismissListener() { 1844 @Override 1845 public void onDismiss(DialogInterface dialog) { 1846 if (getActivity() == null) { 1847 return; 1848 } 1849 updateAllOptions(); 1850 } 1851 }; 1852 1853 new AlertDialog.Builder(getActivity()) 1854 .setTitle(R.string.confirm_enable_oem_unlock_title) 1855 .setMessage(R.string.confirm_enable_oem_unlock_text) 1856 .setPositiveButton(R.string.enable_text, onClickListener) 1857 .setNegativeButton(android.R.string.cancel, null) 1858 .setOnDismissListener(onDismissListener) 1859 .create() 1860 .show(); 1861 } 1862 1863 @Override 1864 public void onSwitchChanged(Switch switchView, boolean isChecked) { 1865 if (switchView != mSwitchBar.getSwitch()) { 1866 return; 1867 } 1868 if (isChecked != mLastEnabledState) { 1869 if (isChecked) { 1870 mDialogClicked = false; 1871 if (mEnableDialog != null) dismissDialogs(); 1872 mEnableDialog = new AlertDialog.Builder(getActivity()).setMessage( 1873 getActivity().getResources().getString( 1874 R.string.dev_settings_warning_message)) 1875 .setTitle(R.string.dev_settings_warning_title) 1876 .setPositiveButton(android.R.string.yes, this) 1877 .setNegativeButton(android.R.string.no, this) 1878 .show(); 1879 mEnableDialog.setOnDismissListener(this); 1880 } else { 1881 resetDangerousOptions(); 1882 Settings.Global.putInt(getActivity().getContentResolver(), 1883 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0); 1884 mLastEnabledState = isChecked; 1885 setPrefsEnabledState(mLastEnabledState); 1886 } 1887 } 1888 } 1889 1890 @Override 1891 public void onActivityResult(int requestCode, int resultCode, Intent data) { 1892 if (requestCode == RESULT_DEBUG_APP) { 1893 if (resultCode == Activity.RESULT_OK) { 1894 mDebugApp = data.getAction(); 1895 writeDebuggerOptions(); 1896 updateDebuggerOptions(); 1897 } 1898 } else if (requestCode == RESULT_MOCK_LOCATION_APP) { 1899 if (resultCode == Activity.RESULT_OK) { 1900 mMockLocationApp = data.getAction(); 1901 writeMockLocation(); 1902 updateMockLocation(); 1903 } 1904 } else if (requestCode == REQUEST_CODE_ENABLE_OEM_UNLOCK) { 1905 if (resultCode == Activity.RESULT_OK) { 1906 if (mEnableOemUnlock.isChecked()) { 1907 confirmEnableOemUnlock(); 1908 } else { 1909 Utils.setOemUnlockEnabled(getActivity(), false); 1910 } 1911 } 1912 } else { 1913 super.onActivityResult(requestCode, resultCode, data); 1914 } 1915 } 1916 1917 @Override 1918 public boolean onPreferenceTreeClick(Preference preference) { 1919 if (Utils.isMonkeyRunning()) { 1920 return false; 1921 } 1922 1923 if (preference == mEnableAdb) { 1924 if (mEnableAdb.isChecked()) { 1925 mDialogClicked = false; 1926 if (mAdbDialog != null) dismissDialogs(); 1927 mAdbDialog = new AlertDialog.Builder(getActivity()).setMessage( 1928 getActivity().getResources().getString(R.string.adb_warning_message)) 1929 .setTitle(R.string.adb_warning_title) 1930 .setPositiveButton(android.R.string.yes, this) 1931 .setNegativeButton(android.R.string.no, this) 1932 .show(); 1933 mAdbDialog.setOnDismissListener(this); 1934 } else { 1935 Settings.Global.putInt(getActivity().getContentResolver(), 1936 Settings.Global.ADB_ENABLED, 0); 1937 mVerifyAppsOverUsb.setEnabled(false); 1938 mVerifyAppsOverUsb.setChecked(false); 1939 updateBugreportOptions(); 1940 } 1941 } else if (preference == mClearAdbKeys) { 1942 if (mAdbKeysDialog != null) dismissDialogs(); 1943 mAdbKeysDialog = new AlertDialog.Builder(getActivity()) 1944 .setMessage(R.string.adb_keys_warning_message) 1945 .setPositiveButton(android.R.string.ok, this) 1946 .setNegativeButton(android.R.string.cancel, null) 1947 .show(); 1948 } else if (preference == mEnableTerminal) { 1949 final PackageManager pm = getActivity().getPackageManager(); 1950 pm.setApplicationEnabledSetting(TERMINAL_APP_PACKAGE, 1951 mEnableTerminal.isChecked() ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED 1952 : PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0); 1953 } else if (preference == mBugreportInPower) { 1954 Settings.Secure.putInt(getActivity().getContentResolver(), 1955 Settings.Global.BUGREPORT_IN_POWER_MENU, 1956 mBugreportInPower.isChecked() ? 1 : 0); 1957 setBugreportStorageProviderStatus(); 1958 } else if (preference == mKeepScreenOn) { 1959 Settings.Global.putInt(getActivity().getContentResolver(), 1960 Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 1961 mKeepScreenOn.isChecked() ? 1962 (BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB) : 0); 1963 } else if (preference == mBtHciSnoopLog) { 1964 writeBtHciSnoopLogOptions(); 1965 } else if (preference == mEnableOemUnlock && mEnableOemUnlock.isEnabled()) { 1966 if (mEnableOemUnlock.isChecked()) { 1967 if (!showKeyguardConfirmation(getResources(), REQUEST_CODE_ENABLE_OEM_UNLOCK)) { 1968 confirmEnableOemUnlock(); 1969 } 1970 } else { 1971 Utils.setOemUnlockEnabled(getActivity(), false); 1972 } 1973 } else if (preference == mMockLocationAppPref) { 1974 Intent intent = new Intent(getActivity(), AppPicker.class); 1975 intent.putExtra(AppPicker.EXTRA_REQUESTIING_PERMISSION, 1976 Manifest.permission.ACCESS_MOCK_LOCATION); 1977 startActivityForResult(intent, RESULT_MOCK_LOCATION_APP); 1978 } else if (preference == mDebugViewAttributes) { 1979 Settings.Global.putInt(getActivity().getContentResolver(), 1980 Settings.Global.DEBUG_VIEW_ATTRIBUTES, 1981 mDebugViewAttributes.isChecked() ? 1 : 0); 1982 } else if (preference == mForceAllowOnExternal) { 1983 Settings.Global.putInt(getActivity().getContentResolver(), 1984 Settings.Global.FORCE_ALLOW_ON_EXTERNAL, 1985 mForceAllowOnExternal.isChecked() ? 1 : 0); 1986 } else if (preference == mDebugAppPref) { 1987 Intent intent = new Intent(getActivity(), AppPicker.class); 1988 intent.putExtra(AppPicker.EXTRA_DEBUGGABLE, true); 1989 startActivityForResult(intent, RESULT_DEBUG_APP); 1990 } else if (preference == mWaitForDebugger) { 1991 writeDebuggerOptions(); 1992 } else if (preference == mVerifyAppsOverUsb) { 1993 writeVerifyAppsOverUsbOptions(); 1994 } else if (preference == mOtaDisableAutomaticUpdate) { 1995 writeOtaDisableAutomaticUpdateOptions(); 1996 } else if (preference == mStrictMode) { 1997 writeStrictModeVisualOptions(); 1998 } else if (preference == mPointerLocation) { 1999 writePointerLocationOptions(); 2000 } else if (preference == mShowTouches) { 2001 writeShowTouchesOptions(); 2002 } else if (preference == mShowScreenUpdates) { 2003 writeShowUpdatesOption(); 2004 } else if (preference == mDisableOverlays) { 2005 writeDisableOverlaysOption(); 2006 } else if (preference == mImmediatelyDestroyActivities) { 2007 writeImmediatelyDestroyActivitiesOptions(); 2008 } else if (preference == mShowAllANRs) { 2009 writeShowAllANRsOptions(); 2010 } else if (preference == mForceHardwareUi) { 2011 writeHardwareUiOptions(); 2012 } else if (preference == mForceMsaa) { 2013 writeMsaaOptions(); 2014 } else if (preference == mShowHwScreenUpdates) { 2015 writeShowHwScreenUpdatesOptions(); 2016 } else if (preference == mShowHwLayersUpdates) { 2017 writeShowHwLayersUpdatesOptions(); 2018 } else if (preference == mDebugLayout) { 2019 writeDebugLayoutOptions(); 2020 } else if (preference == mForceRtlLayout) { 2021 writeForceRtlOptions(); 2022 } else if (preference == mWifiDisplayCertification) { 2023 writeWifiDisplayCertificationOptions(); 2024 } else if (preference == mWifiVerboseLogging) { 2025 writeWifiVerboseLoggingOptions(); 2026 } else if (preference == mWifiAggressiveHandover) { 2027 writeWifiAggressiveHandoverOptions(); 2028 } else if (preference == mWifiAllowScansWithTraffic) { 2029 writeWifiAllowScansWithTrafficOptions(); 2030 } else if (preference == mMobileDataAlwaysOn) { 2031 writeMobileDataAlwaysOnOptions(); 2032 } else if (preference == mColorTemperaturePreference) { 2033 writeColorTemperature(); 2034 } else if (preference == mUSBAudio) { 2035 writeUSBAudioOptions(); 2036 } else if (preference == mForceResizable) { 2037 writeForceResizableOptions(); 2038 } else if (INACTIVE_APPS_KEY.equals(preference.getKey())) { 2039 startInactiveAppsFragment(); 2040 } else if (BACKGROUND_CHECK_KEY.equals(preference.getKey())) { 2041 startBackgroundCheckFragment(); 2042 } else if (preference == mBluetoothDisableAbsVolume) { 2043 writeBluetoothDisableAbsVolumeOptions(); 2044 } else if (preference == mWebViewMultiprocess) { 2045 writeWebViewMultiprocessOptions(); 2046 } else if (SHORTCUT_MANAGER_RESET_KEY.equals(preference.getKey())) { 2047 resetShortcutManagerThrottling(); 2048 } else { 2049 return super.onPreferenceTreeClick(preference); 2050 } 2051 2052 return false; 2053 } 2054 2055 private void startInactiveAppsFragment() { 2056 ((SettingsActivity) getActivity()).startPreferencePanel( 2057 InactiveApps.class.getName(), 2058 null, R.string.inactive_apps_title, null, null, 0); 2059 } 2060 2061 private void startBackgroundCheckFragment() { 2062 ((SettingsActivity) getActivity()).startPreferencePanel( 2063 BackgroundCheckSummary.class.getName(), 2064 null, R.string.background_check_title, null, null, 0); 2065 } 2066 2067 private boolean showKeyguardConfirmation(Resources resources, int requestCode) { 2068 return new ChooseLockSettingsHelper(getActivity(), this).launchConfirmationActivity( 2069 requestCode, resources.getString(R.string.oem_unlock_enable)); 2070 } 2071 2072 @Override 2073 public boolean onPreferenceChange(Preference preference, Object newValue) { 2074 if (HDCP_CHECKING_KEY.equals(preference.getKey())) { 2075 SystemProperties.set(HDCP_CHECKING_PROPERTY, newValue.toString()); 2076 updateHdcpValues(); 2077 pokeSystemProperties(); 2078 return true; 2079 } else if (preference == mWebViewProvider) { 2080 if (newValue == null) { 2081 Log.e(TAG, "Tried to set a null WebView provider"); 2082 return false; 2083 } 2084 if (writeWebViewProviderOptions(newValue)) { 2085 return true; 2086 } else { 2087 // The user chose a package that became invalid since the list was last updated, 2088 // show a Toast to explain the situation. 2089 Toast toast = Toast.makeText(getActivity(), 2090 R.string.select_webview_provider_toast_text, Toast.LENGTH_SHORT); 2091 toast.show(); 2092 } 2093 return false; 2094 } else if (preference == mLogdSize) { 2095 writeLogdSizeOption(newValue); 2096 return true; 2097 } else if (preference == mLogpersist) { 2098 writeLogpersistOption(newValue, false); 2099 return true; 2100 } else if (preference == mUsbConfiguration) { 2101 writeUsbConfigurationOption(newValue); 2102 return true; 2103 } else if (preference == mWindowAnimationScale) { 2104 writeAnimationScaleOption(0, mWindowAnimationScale, newValue); 2105 return true; 2106 } else if (preference == mTransitionAnimationScale) { 2107 writeAnimationScaleOption(1, mTransitionAnimationScale, newValue); 2108 return true; 2109 } else if (preference == mAnimatorDurationScale) { 2110 writeAnimationScaleOption(2, mAnimatorDurationScale, newValue); 2111 return true; 2112 } else if (preference == mOverlayDisplayDevices) { 2113 writeOverlayDisplayDevicesOptions(newValue); 2114 return true; 2115 } else if (preference == mTrackFrameTime) { 2116 writeTrackFrameTimeOptions(newValue); 2117 return true; 2118 } else if (preference == mDebugHwOverdraw) { 2119 writeDebugHwOverdrawOptions(newValue); 2120 return true; 2121 } else if (preference == mShowNonRectClip) { 2122 writeShowNonRectClipOptions(newValue); 2123 return true; 2124 } else if (preference == mAppProcessLimit) { 2125 writeAppProcessLimitOptions(newValue); 2126 return true; 2127 } else if (preference == mSimulateColorSpace) { 2128 writeSimulateColorSpace(newValue); 2129 return true; 2130 } 2131 return false; 2132 } 2133 2134 private void dismissDialogs() { 2135 if (mAdbDialog != null) { 2136 mAdbDialog.dismiss(); 2137 mAdbDialog = null; 2138 } 2139 if (mAdbKeysDialog != null) { 2140 mAdbKeysDialog.dismiss(); 2141 mAdbKeysDialog = null; 2142 } 2143 if (mEnableDialog != null) { 2144 mEnableDialog.dismiss(); 2145 mEnableDialog = null; 2146 } 2147 if (mLogpersistClearDialog != null) { 2148 mLogpersistClearDialog.dismiss(); 2149 mLogpersistClearDialog = null; 2150 } 2151 } 2152 2153 public void onClick(DialogInterface dialog, int which) { 2154 if (dialog == mAdbDialog) { 2155 if (which == DialogInterface.BUTTON_POSITIVE) { 2156 mDialogClicked = true; 2157 Settings.Global.putInt(getActivity().getContentResolver(), 2158 Settings.Global.ADB_ENABLED, 1); 2159 mVerifyAppsOverUsb.setEnabled(true); 2160 updateVerifyAppsOverUsbOptions(); 2161 updateBugreportOptions(); 2162 } else { 2163 // Reset the toggle 2164 mEnableAdb.setChecked(false); 2165 } 2166 } else if (dialog == mAdbKeysDialog) { 2167 if (which == DialogInterface.BUTTON_POSITIVE) { 2168 try { 2169 IBinder b = ServiceManager.getService(Context.USB_SERVICE); 2170 IUsbManager service = IUsbManager.Stub.asInterface(b); 2171 service.clearUsbDebuggingKeys(); 2172 } catch (RemoteException e) { 2173 Log.e(TAG, "Unable to clear adb keys", e); 2174 } 2175 } 2176 } else if (dialog == mEnableDialog) { 2177 if (which == DialogInterface.BUTTON_POSITIVE) { 2178 mDialogClicked = true; 2179 Settings.Global.putInt(getActivity().getContentResolver(), 2180 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1); 2181 mLastEnabledState = true; 2182 setPrefsEnabledState(mLastEnabledState); 2183 } else { 2184 // Reset the toggle 2185 mSwitchBar.setChecked(false); 2186 } 2187 } else if (dialog == mLogpersistClearDialog) { 2188 if (which == DialogInterface.BUTTON_POSITIVE) { 2189 setLogpersistOff(true); 2190 } else { 2191 updateLogpersistValues(); 2192 } 2193 } 2194 } 2195 2196 public void onDismiss(DialogInterface dialog) { 2197 // Assuming that onClick gets called first 2198 if (dialog == mAdbDialog) { 2199 if (!mDialogClicked) { 2200 mEnableAdb.setChecked(false); 2201 } 2202 mAdbDialog = null; 2203 } else if (dialog == mEnableDialog) { 2204 if (!mDialogClicked) { 2205 mSwitchBar.setChecked(false); 2206 } 2207 mEnableDialog = null; 2208 } else if (dialog == mLogpersistClearDialog) { 2209 mLogpersistClearDialog = null; 2210 } 2211 } 2212 2213 @Override 2214 public void onDestroy() { 2215 dismissDialogs(); 2216 super.onDestroy(); 2217 } 2218 2219 void pokeSystemProperties() { 2220 if (!mDontPokeProperties) { 2221 //noinspection unchecked 2222 (new SystemPropPoker()).execute(); 2223 } 2224 } 2225 2226 private BroadcastReceiver mUsbReceiver = new BroadcastReceiver() { 2227 @Override 2228 public void onReceive(Context context, Intent intent) { 2229 updateUsbConfigurationValues(); 2230 } 2231 }; 2232 2233 public static class SystemPropPoker extends AsyncTask<Void, Void, Void> { 2234 @Override 2235 protected Void doInBackground(Void... params) { 2236 String[] services = ServiceManager.listServices(); 2237 for (String service : services) { 2238 IBinder obj = ServiceManager.checkService(service); 2239 if (obj != null) { 2240 Parcel data = Parcel.obtain(); 2241 try { 2242 obj.transact(IBinder.SYSPROPS_TRANSACTION, data, null, 0); 2243 } catch (RemoteException e) { 2244 } catch (Exception e) { 2245 Log.i(TAG, "Someone wrote a bad service '" + service 2246 + "' that doesn't like to be poked: " + e); 2247 } 2248 data.recycle(); 2249 } 2250 } 2251 return null; 2252 } 2253 } 2254 2255 private static boolean isPackageInstalled(Context context, String packageName) { 2256 try { 2257 return context.getPackageManager().getPackageInfo(packageName, 0) != null; 2258 } catch (NameNotFoundException e) { 2259 return false; 2260 } 2261 } 2262 2263 2264 /** 2265 * For Search. 2266 */ 2267 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 2268 new BaseSearchIndexProvider() { 2269 2270 private boolean isShowingDeveloperOptions(Context context) { 2271 return context.getSharedPreferences(DevelopmentSettings.PREF_FILE, 2272 Context.MODE_PRIVATE).getBoolean( 2273 DevelopmentSettings.PREF_SHOW, 2274 android.os.Build.TYPE.equals("eng")); 2275 } 2276 2277 @Override 2278 public List<SearchIndexableResource> getXmlResourcesToIndex( 2279 Context context, boolean enabled) { 2280 2281 if (!isShowingDeveloperOptions(context)) { 2282 return null; 2283 } 2284 2285 final SearchIndexableResource sir = new SearchIndexableResource(context); 2286 sir.xmlResId = R.xml.development_prefs; 2287 return Arrays.asList(sir); 2288 } 2289 2290 @Override 2291 public List<String> getNonIndexableKeys(Context context) { 2292 if (!isShowingDeveloperOptions(context)) { 2293 return null; 2294 } 2295 2296 final List<String> keys = new ArrayList<String>(); 2297 if (!showEnableOemUnlockPreference()) { 2298 keys.add(ENABLE_OEM_UNLOCK); 2299 } 2300 return keys; 2301 } 2302 }; 2303 2304 private void resetShortcutManagerThrottling() { 2305 final IShortcutService service = IShortcutService.Stub.asInterface( 2306 ServiceManager.getService(Context.SHORTCUT_SERVICE)); 2307 if (service != null) { 2308 try { 2309 service.resetThrottling(); 2310 Toast.makeText(getActivity(), R.string.reset_shortcut_manager_throttling_complete, 2311 Toast.LENGTH_SHORT).show(); 2312 } catch (RemoteException e) { 2313 Log.e(TAG, "Failed to reset rate limiting", e); 2314 } 2315 } 2316 } 2317 2318 private void updateOemUnlockSettingDescription() { 2319 if (mEnableOemUnlock != null) { 2320 int oemUnlockSummary = R.string.oem_unlock_enable_summary; 2321 if (isBootloaderUnlocked()) { 2322 oemUnlockSummary = R.string.oem_unlock_enable_disabled_summary_bootloader_unlocked; 2323 } else if (isSimLockedDevice()) { 2324 oemUnlockSummary = R.string.oem_unlock_enable_disabled_summary_sim_locked_device; 2325 } else if (!isOemUnlockAllowed()) { 2326 // If the device isn't SIM-locked but OEM unlock is disabled by the system via the 2327 // user restriction, this means either some other carrier restriction is in place or 2328 // the device hasn't been able to confirm which restrictions (SIM-lock or otherwise) 2329 // apply. 2330 oemUnlockSummary = 2331 R.string.oem_unlock_enable_disabled_summary_connectivity_or_locked; 2332 } 2333 mEnableOemUnlock.setSummary(getString(oemUnlockSummary)); 2334 } 2335 } 2336 2337 /** Returns {@code true} if the device is SIM-locked. Otherwise, returns {@code false}. */ 2338 private boolean isSimLockedDevice() { 2339 int phoneCount = mTelephonyManager.getPhoneCount(); 2340 for (int i = 0; i < phoneCount; i++) { 2341 if (mTelephonyManager.getAllowedCarriers(i).size() > 0) { 2342 return true; 2343 } 2344 } 2345 return false; 2346 } 2347 2348 /** 2349 * Returns {@code true} if the bootloader has been unlocked. Otherwise, returns {code false}. 2350 */ 2351 private boolean isBootloaderUnlocked() { 2352 int flashLockState = PersistentDataBlockManager.FLASH_LOCK_UNKNOWN; 2353 if (mOemUnlockManager != null) { 2354 flashLockState = mOemUnlockManager.getFlashLockState(); 2355 } 2356 2357 return flashLockState == PersistentDataBlockManager.FLASH_LOCK_UNLOCKED; 2358 } 2359 2360 /** 2361 * Returns {@code true} if OEM unlock is disallowed by user restriction 2362 * {@link UserManager#DISALLOW_FACTORY_RESET} or {@link UserManager#DISALLOW_OEM_UNLOCK}. 2363 * Otherwise, returns {@code false}. 2364 */ 2365 private boolean isOemUnlockAllowed() { 2366 UserHandle userHandle = UserHandle.of(UserHandle.myUserId()); 2367 return !(mUm.hasBaseUserRestriction(UserManager.DISALLOW_OEM_UNLOCK, userHandle) 2368 || mUm.hasBaseUserRestriction(UserManager.DISALLOW_FACTORY_RESET, userHandle)); 2369 } 2370 } 2371