DevelopmentSettings.java revision 03c4a7401ec8a197794da4ce4c7eddae91dbb77d
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 17package com.android.settings.development; 18 19import android.Manifest; 20import android.app.Activity; 21import android.app.ActivityManager; 22import android.app.AlertDialog; 23import android.app.AppOpsManager; 24import android.app.AppOpsManager.PackageOps; 25import android.app.Dialog; 26import android.app.backup.IBackupManager; 27import android.bluetooth.BluetoothA2dp; 28import android.bluetooth.BluetoothAdapter; 29import android.bluetooth.BluetoothCodecConfig; 30import android.bluetooth.BluetoothCodecStatus; 31import android.bluetooth.BluetoothHeadset; 32import android.bluetooth.BluetoothProfile; 33import android.content.BroadcastReceiver; 34import android.content.ContentResolver; 35import android.content.Context; 36import android.content.DialogInterface; 37import android.content.Intent; 38import android.content.IntentFilter; 39import android.content.pm.ApplicationInfo; 40import android.content.pm.IShortcutService; 41import android.content.pm.PackageManager; 42import android.content.pm.PackageManager.NameNotFoundException; 43import android.content.res.Resources; 44import android.hardware.usb.IUsbManager; 45import android.hardware.usb.UsbManager; 46import android.net.wifi.WifiManager; 47import android.os.AsyncTask; 48import android.os.BatteryManager; 49import android.os.Build; 50import android.os.Bundle; 51import android.os.IBinder; 52import android.os.Parcel; 53import android.os.RemoteException; 54import android.os.ServiceManager; 55import android.os.StrictMode; 56import android.os.SystemProperties; 57import android.os.UserManager; 58import android.os.storage.IStorageManager; 59import android.provider.SearchIndexableResource; 60import android.provider.Settings; 61import android.service.oemlock.OemLockManager; 62import android.support.annotation.VisibleForTesting; 63import android.support.v14.preference.SwitchPreference; 64import android.support.v7.preference.ListPreference; 65import android.support.v7.preference.Preference; 66import android.support.v7.preference.Preference.OnPreferenceChangeListener; 67import android.support.v7.preference.PreferenceGroup; 68import android.support.v7.preference.PreferenceScreen; 69import android.telephony.TelephonyManager; 70import android.text.TextUtils; 71import android.util.Log; 72import android.view.IWindowManager; 73import android.view.LayoutInflater; 74import android.view.ThreadedRenderer; 75import android.view.View; 76import android.view.ViewGroup; 77import android.view.accessibility.AccessibilityManager; 78import android.webkit.IWebViewUpdateService; 79import android.webkit.WebViewFactory; 80import android.widget.Switch; 81import android.widget.Toast; 82 83import com.android.internal.app.LocalePicker; 84import com.android.internal.logging.nano.MetricsProto.MetricsEvent; 85import com.android.settings.R; 86import com.android.settings.RestrictedSettingsFragment; 87import com.android.settings.SettingsActivity; 88import com.android.settings.Utils; 89import com.android.settings.dashboard.DashboardFeatureProvider; 90import com.android.settings.overlay.FeatureFactory; 91import com.android.settings.password.ChooseLockSettingsHelper; 92import com.android.settings.search.BaseSearchIndexProvider; 93import com.android.settings.search.Indexable; 94import com.android.settings.webview.WebViewAppPreferenceController; 95import com.android.settings.widget.SwitchBar; 96import com.android.settingslib.RestrictedLockUtils; 97import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; 98import com.android.settingslib.RestrictedSwitchPreference; 99import com.android.settingslib.drawer.CategoryKey; 100 101import java.util.ArrayList; 102import java.util.Arrays; 103import java.util.HashSet; 104import java.util.List; 105 106/* 107 * Displays preferences for application developers. 108 */ 109public class DevelopmentSettings extends RestrictedSettingsFragment 110 implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener, 111 OnPreferenceChangeListener, SwitchBar.OnSwitchChangeListener, Indexable { 112 private static final String TAG = "DevelopmentSettings"; 113 114 /** 115 * Preference file were development settings prefs are stored. 116 */ 117 public static final String PREF_FILE = "development"; 118 119 /** 120 * Whether to show the development settings to the user. Default is false. 121 */ 122 public static final String PREF_SHOW = "show"; 123 124 private static final String ENABLE_ADB = "enable_adb"; 125 private static final String CLEAR_ADB_KEYS = "clear_adb_keys"; 126 private static final String ENABLE_TERMINAL = "enable_terminal"; 127 private static final String KEEP_SCREEN_ON = "keep_screen_on"; 128 private static final String BT_HCI_SNOOP_LOG = "bt_hci_snoop_log"; 129 private static final String ENABLE_OEM_UNLOCK = "oem_unlock_enable"; 130 private static final String HDCP_CHECKING_KEY = "hdcp_checking"; 131 private static final String HDCP_CHECKING_PROPERTY = "persist.sys.hdcp_checking"; 132 private static final String LOCAL_BACKUP_PASSWORD = "local_backup_password"; 133 private static final String HARDWARE_UI_PROPERTY = "persist.sys.ui.hw"; 134 private static final String MSAA_PROPERTY = "debug.egl.force_msaa"; 135 private static final String OPENGL_TRACES_PROPERTY = "debug.egl.trace"; 136 private static final String TUNER_UI_KEY = "tuner_ui"; 137 private static final String COLOR_TEMPERATURE_PROPERTY = "persist.sys.debug.color_temp"; 138 139 private static final String DEBUG_APP_KEY = "debug_app"; 140 private static final String WAIT_FOR_DEBUGGER_KEY = "wait_for_debugger"; 141 private static final String MOCK_LOCATION_APP_KEY = "mock_location_app"; 142 private static final String DEBUG_VIEW_ATTRIBUTES = "debug_view_attributes"; 143 private static final String FORCE_ALLOW_ON_EXTERNAL_KEY = "force_allow_on_external"; 144 private static final String STRICT_MODE_KEY = "strict_mode"; 145 private static final String POINTER_LOCATION_KEY = "pointer_location"; 146 private static final String SHOW_TOUCHES_KEY = "show_touches"; 147 private static final String SHOW_SCREEN_UPDATES_KEY = "show_screen_updates"; 148 private static final String DISABLE_OVERLAYS_KEY = "disable_overlays"; 149 private static final String SIMULATE_COLOR_SPACE = "simulate_color_space"; 150 private static final String USB_AUDIO_KEY = "usb_audio"; 151 private static final String FORCE_HARDWARE_UI_KEY = "force_hw_ui"; 152 private static final String FORCE_MSAA_KEY = "force_msaa"; 153 private static final String TRACK_FRAME_TIME_KEY = "track_frame_time"; 154 private static final String SHOW_NON_RECTANGULAR_CLIP_KEY = "show_non_rect_clip"; 155 private static final String SHOW_HW_SCREEN_UPDATES_KEY = "show_hw_screen_udpates"; 156 private static final String SHOW_HW_LAYERS_UPDATES_KEY = "show_hw_layers_udpates"; 157 private static final String DEBUG_HW_OVERDRAW_KEY = "debug_hw_overdraw"; 158 private static final String DEBUG_HW_RENDERER_KEY = "debug_hw_renderer"; 159 private static final String DEBUG_LAYOUT_KEY = "debug_layout"; 160 private static final String FORCE_RTL_LAYOUT_KEY = "force_rtl_layout_all_locales"; 161 private static final String WINDOW_ANIMATION_SCALE_KEY = "window_animation_scale"; 162 private static final String TRANSITION_ANIMATION_SCALE_KEY = "transition_animation_scale"; 163 private static final String ANIMATOR_DURATION_SCALE_KEY = "animator_duration_scale"; 164 private static final String OVERLAY_DISPLAY_DEVICES_KEY = "overlay_display_devices"; 165 private static final String DEBUG_DEBUGGING_CATEGORY_KEY = "debug_debugging_category"; 166 private static final String SELECT_LOGD_SIZE_KEY = "select_logd_size"; 167 private static final String SELECT_LOGD_SIZE_PROPERTY = "persist.logd.size"; 168 private static final String SELECT_LOGD_TAG_PROPERTY = "persist.log.tag"; 169 // Tricky, isLoggable only checks for first character, assumes silence 170 private static final String SELECT_LOGD_TAG_SILENCE = "Settings"; 171 private static final String SELECT_LOGD_SNET_TAG_PROPERTY = "persist.log.tag.snet_event_log"; 172 private static final String SELECT_LOGD_RUNTIME_SNET_TAG_PROPERTY = "log.tag.snet_event_log"; 173 private static final String SELECT_LOGD_DEFAULT_SIZE_PROPERTY = "ro.logd.size"; 174 private static final String SELECT_LOGD_DEFAULT_SIZE_VALUE = "262144"; 175 private static final String SELECT_LOGD_SVELTE_DEFAULT_SIZE_VALUE = "65536"; 176 // 32768 is merely a menu marker, 64K is our lowest log buffer size we replace it with. 177 private static final String SELECT_LOGD_MINIMUM_SIZE_VALUE = "65536"; 178 private static final String SELECT_LOGD_OFF_SIZE_MARKER_VALUE = "32768"; 179 private static final String SELECT_LOGPERSIST_KEY = "select_logpersist"; 180 private static final String SELECT_LOGPERSIST_PROPERTY = "persist.logd.logpersistd"; 181 private static final String ACTUAL_LOGPERSIST_PROPERTY = "logd.logpersistd"; 182 private static final String SELECT_LOGPERSIST_PROPERTY_SERVICE = "logcatd"; 183 private static final String SELECT_LOGPERSIST_PROPERTY_CLEAR = "clear"; 184 private static final String SELECT_LOGPERSIST_PROPERTY_STOP = "stop"; 185 private static final String SELECT_LOGPERSIST_PROPERTY_BUFFER = 186 "persist.logd.logpersistd.buffer"; 187 private static final String ACTUAL_LOGPERSIST_PROPERTY_BUFFER = "logd.logpersistd.buffer"; 188 private static final String ACTUAL_LOGPERSIST_PROPERTY_ENABLE = "logd.logpersistd.enable"; 189 190 private static final String WIFI_DISPLAY_CERTIFICATION_KEY = "wifi_display_certification"; 191 private static final String WIFI_VERBOSE_LOGGING_KEY = "wifi_verbose_logging"; 192 private static final String WIFI_AGGRESSIVE_HANDOVER_KEY = "wifi_aggressive_handover"; 193 private static final String WIFI_ALLOW_SCAN_WITH_TRAFFIC_KEY = "wifi_allow_scan_with_traffic"; 194 private static final String USB_CONFIGURATION_KEY = "select_usb_configuration"; 195 private static final String MOBILE_DATA_ALWAYS_ON = "mobile_data_always_on"; 196 private static final String TETHERING_HARDWARE_OFFLOAD = "tethering_hardware_offload"; 197 private static final String KEY_COLOR_MODE = "picture_color_mode"; 198 private static final String FORCE_RESIZABLE_KEY = "force_resizable_activities"; 199 private static final String COLOR_TEMPERATURE_KEY = "color_temperature"; 200 201 private static final String BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_KEY = 202 "bluetooth_disable_absolute_volume"; 203 private static final String BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_PROPERTY = 204 "persist.bluetooth.disableabsvol"; 205 private static final String BLUETOOTH_AVRCP_VERSION_PROPERTY = 206 "persist.bluetooth.avrcpversion"; 207 private static final String BLUETOOTH_ENABLE_INBAND_RINGING_PROPERTY = 208 "persist.bluetooth.enableinbandringing"; 209 private static final String BLUETOOTH_BTSNOOP_ENABLE_PROPERTY = 210 "persist.bluetooth.btsnoopenable"; 211 212 private static final String BLUETOOTH_ENABLE_INBAND_RINGING_KEY = "bluetooth_enable_inband_ringing"; 213 private static final String BLUETOOTH_SELECT_AVRCP_VERSION_KEY = "bluetooth_select_avrcp_version"; 214 private static final String BLUETOOTH_SELECT_A2DP_CODEC_KEY = "bluetooth_select_a2dp_codec"; 215 private static final String BLUETOOTH_SELECT_A2DP_SAMPLE_RATE_KEY = "bluetooth_select_a2dp_sample_rate"; 216 private static final String BLUETOOTH_SELECT_A2DP_BITS_PER_SAMPLE_KEY = "bluetooth_select_a2dp_bits_per_sample"; 217 private static final String BLUETOOTH_SELECT_A2DP_CHANNEL_MODE_KEY = "bluetooth_select_a2dp_channel_mode"; 218 private static final String BLUETOOTH_SELECT_A2DP_LDAC_PLAYBACK_QUALITY_KEY = "bluetooth_select_a2dp_ldac_playback_quality"; 219 220 private static final String INACTIVE_APPS_KEY = "inactive_apps"; 221 222 private static final String IMMEDIATELY_DESTROY_ACTIVITIES_KEY 223 = "immediately_destroy_activities"; 224 private static final String APP_PROCESS_LIMIT_KEY = "app_process_limit"; 225 226 private static final String BACKGROUND_CHECK_KEY = "background_check"; 227 228 private static final String SHOW_ALL_ANRS_KEY = "show_all_anrs"; 229 230 private static final String SHOW_NOTIFICATION_CHANNEL_WARNINGS_KEY = "show_notification_channel_warnings"; 231 232 private static final String TERMINAL_APP_PACKAGE = "com.android.terminal"; 233 234 private static final String KEY_CONVERT_FBE = "convert_to_file_encryption"; 235 236 private static final String OTA_DISABLE_AUTOMATIC_UPDATE_KEY = "ota_disable_automatic_update"; 237 238 private static final int RESULT_DEBUG_APP = 1000; 239 private static final int RESULT_MOCK_LOCATION_APP = 1001; 240 241 private static final String FLASH_LOCKED_PROP = "ro.boot.flash.locked"; 242 243 private static final String SHORTCUT_MANAGER_RESET_KEY = "reset_shortcut_manager_throttling"; 244 245 private static final int REQUEST_CODE_ENABLE_OEM_UNLOCK = 0; 246 247 private static final int[] MOCK_LOCATION_APP_OPS = new int[]{AppOpsManager.OP_MOCK_LOCATION}; 248 249 private IWindowManager mWindowManager; 250 private IBackupManager mBackupManager; 251 private IWebViewUpdateService mWebViewUpdateService; 252 private UserManager mUm; 253 private WifiManager mWifiManager; 254 private OemLockManager mOemLockManager; 255 private TelephonyManager mTelephonyManager; 256 257 private SwitchBar mSwitchBar; 258 259 private boolean mHaveDebugSettings; 260 private boolean mDontPokeProperties; 261 private SwitchPreference mEnableAdb; 262 private Preference mClearAdbKeys; 263 private SwitchPreference mEnableTerminal; 264 private RestrictedSwitchPreference mKeepScreenOn; 265 private SwitchPreference mBtHciSnoopLog; 266 private RestrictedSwitchPreference mEnableOemUnlock; 267 private SwitchPreference mDebugViewAttributes; 268 private SwitchPreference mForceAllowOnExternal; 269 270 private Preference mPassword; 271 private String mDebugApp; 272 private Preference mDebugAppPref; 273 274 private String mMockLocationApp; 275 private Preference mMockLocationAppPref; 276 277 private SwitchPreference mWaitForDebugger; 278 private VerifyAppsOverUsbPreferenceController mVerifyAppsOverUsbController; 279 private SwitchPreference mWifiDisplayCertification; 280 private SwitchPreference mWifiVerboseLogging; 281 private SwitchPreference mWifiAggressiveHandover; 282 private SwitchPreference mMobileDataAlwaysOn; 283 private SwitchPreference mTetheringHardwareOffload; 284 private SwitchPreference mBluetoothDisableAbsVolume; 285 private SwitchPreference mBluetoothEnableInbandRinging; 286 287 private BluetoothA2dp mBluetoothA2dp; 288 private final Object mBluetoothA2dpLock = new Object(); 289 private ListPreference mBluetoothSelectAvrcpVersion; 290 private ListPreference mBluetoothSelectA2dpCodec; 291 private ListPreference mBluetoothSelectA2dpSampleRate; 292 private ListPreference mBluetoothSelectA2dpBitsPerSample; 293 private ListPreference mBluetoothSelectA2dpChannelMode; 294 private ListPreference mBluetoothSelectA2dpLdacPlaybackQuality; 295 296 private SwitchPreference mOtaDisableAutomaticUpdate; 297 private SwitchPreference mWifiAllowScansWithTraffic; 298 private SwitchPreference mStrictMode; 299 private SwitchPreference mPointerLocation; 300 private SwitchPreference mShowTouches; 301 private SwitchPreference mShowScreenUpdates; 302 private SwitchPreference mDisableOverlays; 303 private SwitchPreference mForceHardwareUi; 304 private SwitchPreference mForceMsaa; 305 private SwitchPreference mShowHwScreenUpdates; 306 private SwitchPreference mShowHwLayersUpdates; 307 private SwitchPreference mDebugLayout; 308 private SwitchPreference mForceRtlLayout; 309 private ListPreference mDebugHwOverdraw; 310 private ListPreference mDebugHwRenderer; 311 private ListPreference mLogdSize; 312 private ListPreference mLogpersist; 313 private ListPreference mUsbConfiguration; 314 private ListPreference mTrackFrameTime; 315 private ListPreference mShowNonRectClip; 316 private ListPreference mWindowAnimationScale; 317 private ListPreference mTransitionAnimationScale; 318 private ListPreference mAnimatorDurationScale; 319 private ListPreference mOverlayDisplayDevices; 320 321 private WebViewAppPreferenceController mWebViewAppPrefController; 322 323 private ListPreference mSimulateColorSpace; 324 325 private SwitchPreference mUSBAudio; 326 private SwitchPreference mImmediatelyDestroyActivities; 327 328 private ListPreference mAppProcessLimit; 329 330 private SwitchPreference mShowAllANRs; 331 332 private SwitchPreference mShowNotificationChannelWarnings; 333 334 private ColorModePreference mColorModePreference; 335 336 private SwitchPreference mForceResizable; 337 338 private SwitchPreference mColorTemperaturePreference; 339 340 private final ArrayList<Preference> mAllPrefs = new ArrayList<>(); 341 342 private final ArrayList<SwitchPreference> mResetSwitchPrefs = new ArrayList<>(); 343 344 private final HashSet<Preference> mDisabledPrefs = new HashSet<>(); 345 // To track whether a confirmation dialog was clicked. 346 private boolean mDialogClicked; 347 private Dialog mEnableDialog; 348 private Dialog mAdbDialog; 349 350 private Dialog mAdbKeysDialog; 351 private boolean mUnavailable; 352 353 private boolean mLogpersistCleared; 354 private Dialog mLogpersistClearDialog; 355 private DashboardFeatureProvider mDashboardFeatureProvider; 356 private DevelopmentSettingsEnabler mSettingsEnabler; 357 private BugReportPreferenceController mBugReportController; 358 private BugReportInPowerPreferenceController mBugReportInPowerController; 359 private TelephonyMonitorPreferenceController mTelephonyMonitorController; 360 361 public DevelopmentSettings() { 362 super(UserManager.DISALLOW_DEBUGGING_FEATURES); 363 } 364 365 @Override 366 public int getMetricsCategory() { 367 return MetricsEvent.DEVELOPMENT; 368 } 369 370 @Override 371 public void onAttach(Context context) { 372 super.onAttach(context); 373 mSettingsEnabler = new DevelopmentSettingsEnabler(context, getLifecycle()); 374 mDashboardFeatureProvider = FeatureFactory.getFactory(context) 375 .getDashboardFeatureProvider(context); 376 } 377 378 @Override 379 public void onCreate(Bundle icicle) { 380 super.onCreate(icicle); 381 382 mWindowManager = IWindowManager.Stub.asInterface(ServiceManager.getService("window")); 383 mBackupManager = IBackupManager.Stub.asInterface( 384 ServiceManager.getService(Context.BACKUP_SERVICE)); 385 mWebViewUpdateService = WebViewFactory.getUpdateService(); 386 mOemLockManager = (OemLockManager) getSystemService(Context.OEM_LOCK_SERVICE); 387 mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); 388 389 mUm = (UserManager) getSystemService(Context.USER_SERVICE); 390 391 mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); 392 393 mBugReportController = new BugReportPreferenceController(getActivity()); 394 mBugReportInPowerController = new BugReportInPowerPreferenceController(getActivity()); 395 mTelephonyMonitorController = new TelephonyMonitorPreferenceController(getActivity()); 396 mWebViewAppPrefController = new WebViewAppPreferenceController(getActivity()); 397 mVerifyAppsOverUsbController = new VerifyAppsOverUsbPreferenceController(getActivity()); 398 399 setIfOnlyAvailableForAdmins(true); 400 if (isUiRestricted() || !Utils.isDeviceProvisioned(getActivity())) { 401 // Block access to developer options if the user is not the owner, if user policy 402 // restricts it, or if the device has not been provisioned 403 mUnavailable = true; 404 addPreferencesFromResource(R.xml.placeholder_prefs); 405 return; 406 } 407 408 addPreferencesFromResource(R.xml.development_prefs); 409 410 final PreferenceGroup debugDebuggingCategory = (PreferenceGroup) 411 findPreference(DEBUG_DEBUGGING_CATEGORY_KEY); 412 mEnableAdb = findAndInitSwitchPref(ENABLE_ADB); 413 mClearAdbKeys = findPreference(CLEAR_ADB_KEYS); 414 if (!SystemProperties.getBoolean("ro.adb.secure", false)) { 415 if (debugDebuggingCategory != null) { 416 debugDebuggingCategory.removePreference(mClearAdbKeys); 417 } 418 } 419 mAllPrefs.add(mClearAdbKeys); 420 mEnableTerminal = findAndInitSwitchPref(ENABLE_TERMINAL); 421 if (!isPackageInstalled(getActivity(), TERMINAL_APP_PACKAGE)) { 422 debugDebuggingCategory.removePreference(mEnableTerminal); 423 mEnableTerminal = null; 424 } 425 426 mBugReportController.displayPreference(getPreferenceScreen()); 427 mBugReportInPowerController.displayPreference(getPreferenceScreen()); 428 mTelephonyMonitorController.displayPreference(getPreferenceScreen()); 429 mWebViewAppPrefController.displayPreference(getPreferenceScreen()); 430 431 mKeepScreenOn = (RestrictedSwitchPreference) findAndInitSwitchPref(KEEP_SCREEN_ON); 432 mBtHciSnoopLog = findAndInitSwitchPref(BT_HCI_SNOOP_LOG); 433 mEnableOemUnlock = (RestrictedSwitchPreference) findAndInitSwitchPref(ENABLE_OEM_UNLOCK); 434 if (!showEnableOemUnlockPreference(getActivity())) { 435 removePreference(mEnableOemUnlock); 436 mEnableOemUnlock = null; 437 } 438 439 mDebugViewAttributes = findAndInitSwitchPref(DEBUG_VIEW_ATTRIBUTES); 440 mForceAllowOnExternal = findAndInitSwitchPref(FORCE_ALLOW_ON_EXTERNAL_KEY); 441 mPassword = findPreference(LOCAL_BACKUP_PASSWORD); 442 mAllPrefs.add(mPassword); 443 444 if (!mUm.isAdminUser()) { 445 disableForUser(mEnableAdb); 446 disableForUser(mClearAdbKeys); 447 disableForUser(mEnableTerminal); 448 disableForUser(mPassword); 449 } 450 451 mDebugAppPref = findPreference(DEBUG_APP_KEY); 452 mAllPrefs.add(mDebugAppPref); 453 mWaitForDebugger = findAndInitSwitchPref(WAIT_FOR_DEBUGGER_KEY); 454 455 mMockLocationAppPref = findPreference(MOCK_LOCATION_APP_KEY); 456 mAllPrefs.add(mMockLocationAppPref); 457 458 mVerifyAppsOverUsbController.displayPreference(getPreferenceScreen()); 459 460 mStrictMode = findAndInitSwitchPref(STRICT_MODE_KEY); 461 mPointerLocation = findAndInitSwitchPref(POINTER_LOCATION_KEY); 462 mShowTouches = findAndInitSwitchPref(SHOW_TOUCHES_KEY); 463 mShowScreenUpdates = findAndInitSwitchPref(SHOW_SCREEN_UPDATES_KEY); 464 mDisableOverlays = findAndInitSwitchPref(DISABLE_OVERLAYS_KEY); 465 mForceHardwareUi = findAndInitSwitchPref(FORCE_HARDWARE_UI_KEY); 466 mForceMsaa = findAndInitSwitchPref(FORCE_MSAA_KEY); 467 mTrackFrameTime = addListPreference(TRACK_FRAME_TIME_KEY); 468 mShowNonRectClip = addListPreference(SHOW_NON_RECTANGULAR_CLIP_KEY); 469 mShowHwScreenUpdates = findAndInitSwitchPref(SHOW_HW_SCREEN_UPDATES_KEY); 470 mShowHwLayersUpdates = findAndInitSwitchPref(SHOW_HW_LAYERS_UPDATES_KEY); 471 mDebugLayout = findAndInitSwitchPref(DEBUG_LAYOUT_KEY); 472 mForceRtlLayout = findAndInitSwitchPref(FORCE_RTL_LAYOUT_KEY); 473 mDebugHwOverdraw = addListPreference(DEBUG_HW_OVERDRAW_KEY); 474 mDebugHwRenderer = addListPreference(DEBUG_HW_RENDERER_KEY); 475 mWifiDisplayCertification = findAndInitSwitchPref(WIFI_DISPLAY_CERTIFICATION_KEY); 476 mWifiVerboseLogging = findAndInitSwitchPref(WIFI_VERBOSE_LOGGING_KEY); 477 mWifiAggressiveHandover = findAndInitSwitchPref(WIFI_AGGRESSIVE_HANDOVER_KEY); 478 mWifiAllowScansWithTraffic = findAndInitSwitchPref(WIFI_ALLOW_SCAN_WITH_TRAFFIC_KEY); 479 mMobileDataAlwaysOn = findAndInitSwitchPref(MOBILE_DATA_ALWAYS_ON); 480 mTetheringHardwareOffload = findAndInitSwitchPref(TETHERING_HARDWARE_OFFLOAD); 481 mLogdSize = addListPreference(SELECT_LOGD_SIZE_KEY); 482 if ("1".equals(SystemProperties.get("ro.debuggable", "0"))) { 483 mLogpersist = addListPreference(SELECT_LOGPERSIST_KEY); 484 } else { 485 mLogpersist = (ListPreference) findPreference(SELECT_LOGPERSIST_KEY); 486 if (mLogpersist != null) { 487 mLogpersist.setEnabled(false); 488 if (debugDebuggingCategory != null) { 489 debugDebuggingCategory.removePreference(mLogpersist); 490 } 491 } 492 mLogpersist = null; 493 } 494 mUsbConfiguration = addListPreference(USB_CONFIGURATION_KEY); 495 mBluetoothDisableAbsVolume = findAndInitSwitchPref(BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_KEY); 496 mBluetoothEnableInbandRinging = findAndInitSwitchPref(BLUETOOTH_ENABLE_INBAND_RINGING_KEY); 497 if (!BluetoothHeadset.isInbandRingingSupported(getContext())) { 498 removePreference(mBluetoothEnableInbandRinging); 499 mBluetoothEnableInbandRinging = null; 500 } 501 502 mBluetoothSelectAvrcpVersion = addListPreference(BLUETOOTH_SELECT_AVRCP_VERSION_KEY); 503 mBluetoothSelectA2dpCodec = addListPreference(BLUETOOTH_SELECT_A2DP_CODEC_KEY); 504 mBluetoothSelectA2dpSampleRate = addListPreference(BLUETOOTH_SELECT_A2DP_SAMPLE_RATE_KEY); 505 mBluetoothSelectA2dpBitsPerSample = addListPreference(BLUETOOTH_SELECT_A2DP_BITS_PER_SAMPLE_KEY); 506 mBluetoothSelectA2dpChannelMode = addListPreference(BLUETOOTH_SELECT_A2DP_CHANNEL_MODE_KEY); 507 mBluetoothSelectA2dpLdacPlaybackQuality = addListPreference(BLUETOOTH_SELECT_A2DP_LDAC_PLAYBACK_QUALITY_KEY); 508 initBluetoothConfigurationValues(); 509 510 mWindowAnimationScale = addListPreference(WINDOW_ANIMATION_SCALE_KEY); 511 mTransitionAnimationScale = addListPreference(TRANSITION_ANIMATION_SCALE_KEY); 512 mAnimatorDurationScale = addListPreference(ANIMATOR_DURATION_SCALE_KEY); 513 mOverlayDisplayDevices = addListPreference(OVERLAY_DISPLAY_DEVICES_KEY); 514 mSimulateColorSpace = addListPreference(SIMULATE_COLOR_SPACE); 515 mUSBAudio = findAndInitSwitchPref(USB_AUDIO_KEY); 516 mForceResizable = findAndInitSwitchPref(FORCE_RESIZABLE_KEY); 517 518 mImmediatelyDestroyActivities = (SwitchPreference) findPreference( 519 IMMEDIATELY_DESTROY_ACTIVITIES_KEY); 520 mAllPrefs.add(mImmediatelyDestroyActivities); 521 mResetSwitchPrefs.add(mImmediatelyDestroyActivities); 522 523 mAppProcessLimit = addListPreference(APP_PROCESS_LIMIT_KEY); 524 525 mShowAllANRs = (SwitchPreference) findPreference( 526 SHOW_ALL_ANRS_KEY); 527 mAllPrefs.add(mShowAllANRs); 528 mResetSwitchPrefs.add(mShowAllANRs); 529 530 mShowNotificationChannelWarnings = (SwitchPreference) findPreference( 531 SHOW_NOTIFICATION_CHANNEL_WARNINGS_KEY); 532 mAllPrefs.add(mShowNotificationChannelWarnings); 533 mResetSwitchPrefs.add(mShowNotificationChannelWarnings); 534 535 Preference hdcpChecking = findPreference(HDCP_CHECKING_KEY); 536 if (hdcpChecking != null) { 537 mAllPrefs.add(hdcpChecking); 538 removePreferenceForProduction(hdcpChecking); 539 } 540 541 Preference convertFbePreference = findPreference(KEY_CONVERT_FBE); 542 543 try { 544 IBinder service = ServiceManager.getService("mount"); 545 IStorageManager storageManager = IStorageManager.Stub.asInterface(service); 546 if (!storageManager.isConvertibleToFBE()) { 547 removePreference(KEY_CONVERT_FBE); 548 } else if ("file".equals(SystemProperties.get("ro.crypto.type", "none"))) { 549 convertFbePreference.setEnabled(false); 550 convertFbePreference.setSummary(getResources() 551 .getString(R.string.convert_to_file_encryption_done)); 552 } 553 } catch (RemoteException e) { 554 removePreference(KEY_CONVERT_FBE); 555 } 556 557 mOtaDisableAutomaticUpdate = findAndInitSwitchPref(OTA_DISABLE_AUTOMATIC_UPDATE_KEY); 558 559 mColorModePreference = (ColorModePreference) findPreference(KEY_COLOR_MODE); 560 mColorModePreference.updateCurrentAndSupported(); 561 if (mColorModePreference.getColorModeCount() < 2 || 562 getContext().getDisplay().isWideColorGamut()) { 563 removePreference(KEY_COLOR_MODE); 564 mColorModePreference = null; 565 } 566 567 mColorTemperaturePreference = (SwitchPreference) findPreference(COLOR_TEMPERATURE_KEY); 568 if (getResources().getBoolean(R.bool.config_enableColorTemperature)) { 569 mAllPrefs.add(mColorTemperaturePreference); 570 mResetSwitchPrefs.add(mColorTemperaturePreference); 571 } else { 572 removePreference(COLOR_TEMPERATURE_KEY); 573 mColorTemperaturePreference = null; 574 } 575 576 addDashboardCategoryPreferences(); 577 } 578 579 @VisibleForTesting 580 void addDashboardCategoryPreferences() { 581 final PreferenceScreen screen = getPreferenceScreen(); 582 final List<Preference> tilePrefs = mDashboardFeatureProvider.getPreferencesForCategory( 583 getActivity(), getPrefContext(), getMetricsCategory(), 584 CategoryKey.CATEGORY_SYSTEM_DEVELOPMENT); 585 if (tilePrefs != null) { 586 for (Preference preference : tilePrefs) { 587 screen.addPreference(preference); 588 } 589 } 590 } 591 592 private ListPreference addListPreference(String prefKey) { 593 ListPreference pref = (ListPreference) findPreference(prefKey); 594 mAllPrefs.add(pref); 595 pref.setOnPreferenceChangeListener(this); 596 return pref; 597 } 598 599 private void disableForUser(Preference pref) { 600 if (pref != null) { 601 pref.setEnabled(false); 602 mDisabledPrefs.add(pref); 603 } 604 } 605 606 private SwitchPreference findAndInitSwitchPref(String key) { 607 SwitchPreference pref = (SwitchPreference) findPreference(key); 608 if (pref == null) { 609 throw new IllegalArgumentException("Cannot find preference with key = " + key); 610 } 611 mAllPrefs.add(pref); 612 mResetSwitchPrefs.add(pref); 613 return pref; 614 } 615 616 @Override 617 public void onActivityCreated(Bundle savedInstanceState) { 618 super.onActivityCreated(savedInstanceState); 619 620 final SettingsActivity activity = (SettingsActivity) getActivity(); 621 622 mSwitchBar = activity.getSwitchBar(); 623 if (mUnavailable) { 624 mSwitchBar.setEnabled(false); 625 return; 626 } 627 628 mSwitchBar.addOnSwitchChangeListener(this); 629 } 630 631 private boolean removePreferenceForProduction(Preference preference) { 632 if ("user".equals(Build.TYPE)) { 633 removePreference(preference); 634 return true; 635 } 636 return false; 637 } 638 639 private void removePreference(Preference preference) { 640 getPreferenceScreen().removePreference(preference); 641 mAllPrefs.remove(preference); 642 mResetSwitchPrefs.remove(preference); 643 } 644 645 private void setPrefsEnabledState(boolean enabled) { 646 for (int i = 0; i < mAllPrefs.size(); i++) { 647 Preference pref = mAllPrefs.get(i); 648 pref.setEnabled(enabled && !mDisabledPrefs.contains(pref)); 649 } 650 mBugReportInPowerController.enablePreference(enabled); 651 mTelephonyMonitorController.enablePreference(enabled); 652 mWebViewAppPrefController.enablePreference(enabled); 653 updateAllOptions(); 654 } 655 656 @Override 657 public void onResume() { 658 super.onResume(); 659 660 if (mUnavailable) { 661 // Show error message 662 if (!isUiRestrictedByOnlyAdmin()) { 663 getEmptyTextView().setText(R.string.development_settings_not_available); 664 } 665 getPreferenceScreen().removeAll(); 666 return; 667 } 668 669 // A DeviceAdmin has specified a maximum time until the device 670 // will lock... in this case we can't allow the user to turn 671 // on "stay awake when plugged in" because that would defeat the 672 // restriction. 673 final EnforcedAdmin admin = RestrictedLockUtils.checkIfMaximumTimeToLockIsSet( 674 getActivity()); 675 mKeepScreenOn.setDisabledByAdmin(admin); 676 if (admin == null) { 677 mDisabledPrefs.remove(mKeepScreenOn); 678 } else { 679 mDisabledPrefs.add(mKeepScreenOn); 680 } 681 682 final boolean lastEnabledState = mSettingsEnabler.getLastEnabledState(); 683 mSwitchBar.setChecked(lastEnabledState); 684 setPrefsEnabledState(lastEnabledState); 685 686 if (mHaveDebugSettings && !lastEnabledState) { 687 // Overall debugging is disabled, but there are some debug 688 // settings that are enabled. This is an invalid state. Switch 689 // to debug settings being enabled, so the user knows there is 690 // stuff enabled and can turn it all off if they want. 691 mSettingsEnabler.enableDevelopmentSettings(); 692 mSwitchBar.setChecked(lastEnabledState); 693 setPrefsEnabledState(lastEnabledState); 694 } 695 mSwitchBar.show(); 696 697 if (mColorModePreference != null) { 698 mColorModePreference.startListening(); 699 mColorModePreference.updateCurrentAndSupported(); 700 } 701 } 702 703 @Override 704 public void onPause() { 705 super.onPause(); 706 if (mColorModePreference != null) { 707 mColorModePreference.stopListening(); 708 } 709 } 710 711 @Override 712 public View onCreateView(LayoutInflater inflater, ViewGroup container, 713 Bundle savedInstanceState) { 714 IntentFilter filter = new IntentFilter(); 715 filter.addAction(UsbManager.ACTION_USB_STATE); 716 if (getActivity().registerReceiver(mUsbReceiver, filter) == null) { 717 updateUsbConfigurationValues(); 718 } 719 720 BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); 721 if (adapter != null) { 722 adapter.getProfileProxy(getActivity(), 723 mBluetoothA2dpServiceListener, 724 BluetoothProfile.A2DP); 725 } 726 filter = new IntentFilter(); 727 filter.addAction(BluetoothA2dp.ACTION_CODEC_CONFIG_CHANGED); 728 if (getActivity().registerReceiver(mBluetoothA2dpReceiver, filter) == null) { 729 updateBluetoothA2dpConfigurationValues(); 730 } 731 732 return super.onCreateView(inflater, container, savedInstanceState); 733 } 734 735 @Override 736 public void onDestroyView() { 737 super.onDestroyView(); 738 739 if (mUnavailable) { 740 return; 741 } 742 mSwitchBar.removeOnSwitchChangeListener(this); 743 mSwitchBar.hide(); 744 getActivity().unregisterReceiver(mUsbReceiver); 745 getActivity().unregisterReceiver(mBluetoothA2dpReceiver); 746 BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); 747 if (adapter != null) { 748 adapter.closeProfileProxy(BluetoothProfile.A2DP, mBluetoothA2dp); 749 mBluetoothA2dp = null; 750 } 751 } 752 753 void updateSwitchPreference(SwitchPreference switchPreference, boolean value) { 754 switchPreference.setChecked(value); 755 mHaveDebugSettings |= value; 756 } 757 758 private void updateAllOptions() { 759 final Context context = getActivity(); 760 final ContentResolver cr = context.getContentResolver(); 761 mHaveDebugSettings = false; 762 updateSwitchPreference(mEnableAdb, Settings.Global.getInt(cr, 763 Settings.Global.ADB_ENABLED, 0) != 0); 764 if (mEnableTerminal != null) { 765 updateSwitchPreference(mEnableTerminal, 766 context.getPackageManager().getApplicationEnabledSetting(TERMINAL_APP_PACKAGE) 767 == PackageManager.COMPONENT_ENABLED_STATE_ENABLED); 768 } 769 mHaveDebugSettings |= mBugReportInPowerController.updatePreference(); 770 mHaveDebugSettings |= mTelephonyMonitorController.updatePreference(); 771 updateSwitchPreference(mKeepScreenOn, Settings.Global.getInt(cr, 772 Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0) != 0); 773 updateSwitchPreference(mBtHciSnoopLog, SystemProperties.getBoolean( 774 BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, false)); 775 updateSwitchPreference(mDebugViewAttributes, Settings.Global.getInt(cr, 776 Settings.Global.DEBUG_VIEW_ATTRIBUTES, 0) != 0); 777 updateSwitchPreference(mForceAllowOnExternal, Settings.Global.getInt(cr, 778 Settings.Global.FORCE_ALLOW_ON_EXTERNAL, 0) != 0); 779 updateHdcpValues(); 780 updatePasswordSummary(); 781 updateDebuggerOptions(); 782 updateMockLocation(); 783 updateStrictModeVisualOptions(); 784 updatePointerLocationOptions(); 785 updateShowTouchesOptions(); 786 updateFlingerOptions(); 787 updateHardwareUiOptions(); 788 updateMsaaOptions(); 789 updateTrackFrameTimeOptions(); 790 updateShowNonRectClipOptions(); 791 updateShowHwScreenUpdatesOptions(); 792 updateShowHwLayersUpdatesOptions(); 793 updateDebugHwOverdrawOptions(); 794 updateDebugHwRendererOptions(); 795 updateDebugLayoutOptions(); 796 updateAnimationScaleOptions(); 797 updateOverlayDisplayDevicesOptions(); 798 updateImmediatelyDestroyActivitiesOptions(); 799 updateAppProcessLimitOptions(); 800 updateShowAllANRsOptions(); 801 updateShowNotificationChannelWarningsOptions(); 802 mVerifyAppsOverUsbController.updatePreference(); 803 updateOtaDisableAutomaticUpdateOptions(); 804 updateBugreportOptions(); 805 updateForceRtlOptions(); 806 updateLogdSizeValues(); 807 updateLogpersistValues(); 808 updateWifiDisplayCertificationOptions(); 809 updateWifiVerboseLoggingOptions(); 810 updateWifiAggressiveHandoverOptions(); 811 updateWifiAllowScansWithTrafficOptions(); 812 updateMobileDataAlwaysOnOptions(); 813 updateTetheringHardwareOffloadOptions(); 814 updateSimulateColorSpace(); 815 updateUSBAudioOptions(); 816 updateForceResizableOptions(); 817 Preference webViewAppPref = findPreference(mWebViewAppPrefController.getPreferenceKey()); 818 mWebViewAppPrefController.updateState(webViewAppPref); 819 updateOemUnlockOptions(); 820 if (mColorTemperaturePreference != null) { 821 updateColorTemperature(); 822 } 823 updateBluetoothDisableAbsVolumeOptions(); 824 updateBluetoothEnableInbandRingingOptions(); 825 updateBluetoothA2dpConfigurationValues(); 826 } 827 828 private void resetDangerousOptions() { 829 mDontPokeProperties = true; 830 for (int i = 0; i < mResetSwitchPrefs.size(); i++) { 831 SwitchPreference cb = mResetSwitchPrefs.get(i); 832 if (cb.isChecked()) { 833 cb.setChecked(false); 834 onPreferenceTreeClick(cb); 835 } 836 } 837 mBugReportInPowerController.resetPreference(); 838 resetDebuggerOptions(); 839 writeLogpersistOption(null, true); 840 writeLogdSizeOption(null); 841 writeAnimationScaleOption(0, mWindowAnimationScale, null); 842 writeAnimationScaleOption(1, mTransitionAnimationScale, null); 843 writeAnimationScaleOption(2, mAnimatorDurationScale, null); 844 // Only poke the color space setting if we control it. 845 if (usingDevelopmentColorSpace()) { 846 writeSimulateColorSpace(-1); 847 } 848 writeOverlayDisplayDevicesOptions(null); 849 writeAppProcessLimitOptions(null); 850 mHaveDebugSettings = false; 851 updateAllOptions(); 852 mDontPokeProperties = false; 853 pokeSystemProperties(); 854 } 855 856 private void updateHdcpValues() { 857 ListPreference hdcpChecking = (ListPreference) findPreference(HDCP_CHECKING_KEY); 858 if (hdcpChecking != null) { 859 String currentValue = SystemProperties.get(HDCP_CHECKING_PROPERTY); 860 String[] values = getResources().getStringArray(R.array.hdcp_checking_values); 861 String[] summaries = getResources().getStringArray(R.array.hdcp_checking_summaries); 862 int index = 1; // Defaults to drm-only. Needs to match with R.array.hdcp_checking_values 863 for (int i = 0; i < values.length; i++) { 864 if (currentValue.equals(values[i])) { 865 index = i; 866 break; 867 } 868 } 869 hdcpChecking.setValue(values[index]); 870 hdcpChecking.setSummary(summaries[index]); 871 hdcpChecking.setOnPreferenceChangeListener(this); 872 } 873 } 874 875 private void updatePasswordSummary() { 876 try { 877 if (mBackupManager.hasBackupPassword()) { 878 mPassword.setSummary(R.string.local_backup_password_summary_change); 879 } else { 880 mPassword.setSummary(R.string.local_backup_password_summary_none); 881 } 882 } catch (RemoteException e) { 883 // Not much we can do here 884 } 885 } 886 887 private void writeBtHciSnoopLogOptions() { 888 BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); 889 SystemProperties.set(BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, 890 Boolean.toString(mBtHciSnoopLog.isChecked())); 891 } 892 893 private void writeDebuggerOptions() { 894 try { 895 ActivityManager.getService().setDebugApp( 896 mDebugApp, mWaitForDebugger.isChecked(), true); 897 } catch (RemoteException ex) { 898 } 899 } 900 901 private void writeMockLocation() { 902 AppOpsManager appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE); 903 904 // Disable the app op of the previous mock location app if such. 905 List<PackageOps> packageOps = appOpsManager.getPackagesForOps(MOCK_LOCATION_APP_OPS); 906 if (packageOps != null) { 907 // Should be one but in case we are in a bad state due to use of command line tools. 908 for (PackageOps packageOp : packageOps) { 909 if (packageOp.getOps().get(0).getMode() != AppOpsManager.MODE_ERRORED) { 910 String oldMockLocationApp = packageOp.getPackageName(); 911 try { 912 ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo( 913 oldMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS); 914 appOpsManager.setMode(AppOpsManager.OP_MOCK_LOCATION, ai.uid, 915 oldMockLocationApp, AppOpsManager.MODE_ERRORED); 916 } catch (NameNotFoundException e) { 917 /* ignore */ 918 } 919 } 920 } 921 } 922 923 // Enable the app op of the new mock location app if such. 924 if (!TextUtils.isEmpty(mMockLocationApp)) { 925 try { 926 ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo( 927 mMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS); 928 appOpsManager.setMode(AppOpsManager.OP_MOCK_LOCATION, ai.uid, 929 mMockLocationApp, AppOpsManager.MODE_ALLOWED); 930 } catch (NameNotFoundException e) { 931 /* ignore */ 932 } 933 } 934 } 935 936 private static void resetDebuggerOptions() { 937 try { 938 ActivityManager.getService().setDebugApp( 939 null, false, true); 940 } catch (RemoteException ex) { 941 } 942 } 943 944 private void updateDebuggerOptions() { 945 mDebugApp = Settings.Global.getString( 946 getActivity().getContentResolver(), Settings.Global.DEBUG_APP); 947 updateSwitchPreference(mWaitForDebugger, Settings.Global.getInt( 948 getActivity().getContentResolver(), Settings.Global.WAIT_FOR_DEBUGGER, 0) != 0); 949 if (mDebugApp != null && mDebugApp.length() > 0) { 950 String label; 951 try { 952 ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(mDebugApp, 953 PackageManager.GET_DISABLED_COMPONENTS); 954 CharSequence lab = getActivity().getPackageManager().getApplicationLabel(ai); 955 label = lab != null ? lab.toString() : mDebugApp; 956 } catch (PackageManager.NameNotFoundException e) { 957 label = mDebugApp; 958 } 959 mDebugAppPref.setSummary(getResources().getString(R.string.debug_app_set, label)); 960 mWaitForDebugger.setEnabled(true); 961 mHaveDebugSettings = true; 962 } else { 963 mDebugAppPref.setSummary(getResources().getString(R.string.debug_app_not_set)); 964 mWaitForDebugger.setEnabled(false); 965 } 966 } 967 968 private void updateMockLocation() { 969 AppOpsManager appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE); 970 971 List<PackageOps> packageOps = appOpsManager.getPackagesForOps(MOCK_LOCATION_APP_OPS); 972 if (packageOps != null) { 973 for (PackageOps packageOp : packageOps) { 974 if (packageOp.getOps().get(0).getMode() == AppOpsManager.MODE_ALLOWED) { 975 mMockLocationApp = packageOps.get(0).getPackageName(); 976 break; 977 } 978 } 979 } 980 981 if (!TextUtils.isEmpty(mMockLocationApp)) { 982 String label = mMockLocationApp; 983 try { 984 ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo( 985 mMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS); 986 CharSequence appLabel = getPackageManager().getApplicationLabel(ai); 987 if (appLabel != null) { 988 label = appLabel.toString(); 989 } 990 } catch (PackageManager.NameNotFoundException e) { 991 /* ignore */ 992 } 993 994 mMockLocationAppPref.setSummary(getString(R.string.mock_location_app_set, label)); 995 mHaveDebugSettings = true; 996 } else { 997 mMockLocationAppPref.setSummary(getString(R.string.mock_location_app_not_set)); 998 } 999 } 1000 1001 private void updateOtaDisableAutomaticUpdateOptions() { 1002 // We use the "disabled status" in code, but show the opposite text 1003 // "Automatic system updates" on screen. So a value 0 indicates the 1004 // automatic update is enabled. 1005 updateSwitchPreference(mOtaDisableAutomaticUpdate, Settings.Global.getInt( 1006 getActivity().getContentResolver(), 1007 Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, 0) != 1); 1008 } 1009 1010 private void writeOtaDisableAutomaticUpdateOptions() { 1011 // We use the "disabled status" in code, but show the opposite text 1012 // "Automatic system updates" on screen. So a value 0 indicates the 1013 // automatic update is enabled. 1014 Settings.Global.putInt(getActivity().getContentResolver(), 1015 Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, 1016 mOtaDisableAutomaticUpdate.isChecked() ? 0 : 1); 1017 } 1018 1019 private static boolean showEnableOemUnlockPreference(Context context) { 1020 return context.getSystemService(Context.OEM_LOCK_SERVICE) != null; 1021 } 1022 1023 private boolean enableOemUnlockPreference() { 1024 return !isBootloaderUnlocked() && mOemLockManager.canUserAllowOemUnlock(); 1025 } 1026 1027 private void updateOemUnlockOptions() { 1028 if (mEnableOemUnlock != null) { 1029 updateSwitchPreference(mEnableOemUnlock, mOemLockManager.isOemUnlockAllowed()); 1030 updateOemUnlockSettingDescription(); 1031 // Showing mEnableOemUnlock preference as device has persistent data block. 1032 mEnableOemUnlock.setDisabledByAdmin(null); 1033 mEnableOemUnlock.setEnabled(enableOemUnlockPreference()); 1034 if (mEnableOemUnlock.isEnabled()) { 1035 // Check restriction, disable mEnableOemUnlock and apply policy transparency. 1036 mEnableOemUnlock.checkRestrictionAndSetDisabled(UserManager.DISALLOW_FACTORY_RESET); 1037 } 1038 if (mEnableOemUnlock.isEnabled()) { 1039 // Check restriction, disable mEnableOemUnlock and apply policy transparency. 1040 mEnableOemUnlock.checkRestrictionAndSetDisabled(UserManager.DISALLOW_OEM_UNLOCK); 1041 } 1042 } 1043 } 1044 1045 private void updateBugreportOptions() { 1046 mBugReportController.enablePreference(true); 1047 mBugReportInPowerController.updateBugreportOptions(); 1048 } 1049 1050 // Returns the current state of the system property that controls 1051 // strictmode flashes. One of: 1052 // 0: not explicitly set one way or another 1053 // 1: on 1054 // 2: off 1055 private static int currentStrictModeActiveIndex() { 1056 if (TextUtils.isEmpty(SystemProperties.get(StrictMode.VISUAL_PROPERTY))) { 1057 return 0; 1058 } 1059 boolean enabled = SystemProperties.getBoolean(StrictMode.VISUAL_PROPERTY, false); 1060 return enabled ? 1 : 2; 1061 } 1062 1063 private void writeStrictModeVisualOptions() { 1064 try { 1065 mWindowManager.setStrictModeVisualIndicatorPreference(mStrictMode.isChecked() 1066 ? "1" : ""); 1067 } catch (RemoteException e) { 1068 } 1069 } 1070 1071 private void updateStrictModeVisualOptions() { 1072 updateSwitchPreference(mStrictMode, currentStrictModeActiveIndex() == 1); 1073 } 1074 1075 private void writePointerLocationOptions() { 1076 Settings.System.putInt(getActivity().getContentResolver(), 1077 Settings.System.POINTER_LOCATION, mPointerLocation.isChecked() ? 1 : 0); 1078 } 1079 1080 private void updatePointerLocationOptions() { 1081 updateSwitchPreference(mPointerLocation, 1082 Settings.System.getInt(getActivity().getContentResolver(), 1083 Settings.System.POINTER_LOCATION, 0) != 0); 1084 } 1085 1086 private void writeShowTouchesOptions() { 1087 Settings.System.putInt(getActivity().getContentResolver(), 1088 Settings.System.SHOW_TOUCHES, mShowTouches.isChecked() ? 1 : 0); 1089 } 1090 1091 private void updateShowTouchesOptions() { 1092 updateSwitchPreference(mShowTouches, 1093 Settings.System.getInt(getActivity().getContentResolver(), 1094 Settings.System.SHOW_TOUCHES, 0) != 0); 1095 } 1096 1097 private void updateFlingerOptions() { 1098 // magic communication with surface flinger. 1099 try { 1100 IBinder flinger = ServiceManager.getService("SurfaceFlinger"); 1101 if (flinger != null) { 1102 Parcel data = Parcel.obtain(); 1103 Parcel reply = Parcel.obtain(); 1104 data.writeInterfaceToken("android.ui.ISurfaceComposer"); 1105 flinger.transact(1010, data, reply, 0); 1106 @SuppressWarnings("unused") 1107 int showCpu = reply.readInt(); 1108 @SuppressWarnings("unused") 1109 int enableGL = reply.readInt(); 1110 int showUpdates = reply.readInt(); 1111 updateSwitchPreference(mShowScreenUpdates, showUpdates != 0); 1112 @SuppressWarnings("unused") 1113 int showBackground = reply.readInt(); 1114 int disableOverlays = reply.readInt(); 1115 updateSwitchPreference(mDisableOverlays, disableOverlays != 0); 1116 reply.recycle(); 1117 data.recycle(); 1118 } 1119 } catch (RemoteException ex) { 1120 } 1121 } 1122 1123 private void writeShowUpdatesOption() { 1124 try { 1125 IBinder flinger = ServiceManager.getService("SurfaceFlinger"); 1126 if (flinger != null) { 1127 Parcel data = Parcel.obtain(); 1128 data.writeInterfaceToken("android.ui.ISurfaceComposer"); 1129 final int showUpdates = mShowScreenUpdates.isChecked() ? 1 : 0; 1130 data.writeInt(showUpdates); 1131 flinger.transact(1002, data, null, 0); 1132 data.recycle(); 1133 1134 updateFlingerOptions(); 1135 } 1136 } catch (RemoteException ex) { 1137 } 1138 } 1139 1140 private void writeDisableOverlaysOption() { 1141 try { 1142 IBinder flinger = ServiceManager.getService("SurfaceFlinger"); 1143 if (flinger != null) { 1144 Parcel data = Parcel.obtain(); 1145 data.writeInterfaceToken("android.ui.ISurfaceComposer"); 1146 final int disableOverlays = mDisableOverlays.isChecked() ? 1 : 0; 1147 data.writeInt(disableOverlays); 1148 flinger.transact(1008, data, null, 0); 1149 data.recycle(); 1150 1151 updateFlingerOptions(); 1152 } 1153 } catch (RemoteException ex) { 1154 } 1155 } 1156 1157 private void updateHardwareUiOptions() { 1158 updateSwitchPreference(mForceHardwareUi, 1159 SystemProperties.getBoolean(HARDWARE_UI_PROPERTY, false)); 1160 } 1161 1162 private void writeHardwareUiOptions() { 1163 SystemProperties.set(HARDWARE_UI_PROPERTY, mForceHardwareUi.isChecked() ? "true" : "false"); 1164 pokeSystemProperties(); 1165 } 1166 1167 private void updateMsaaOptions() { 1168 updateSwitchPreference(mForceMsaa, SystemProperties.getBoolean(MSAA_PROPERTY, false)); 1169 } 1170 1171 private void writeMsaaOptions() { 1172 SystemProperties.set(MSAA_PROPERTY, mForceMsaa.isChecked() ? "true" : "false"); 1173 pokeSystemProperties(); 1174 } 1175 1176 private void updateTrackFrameTimeOptions() { 1177 String value = SystemProperties.get(ThreadedRenderer.PROFILE_PROPERTY); 1178 if (value == null) { 1179 value = ""; 1180 } 1181 1182 CharSequence[] values = mTrackFrameTime.getEntryValues(); 1183 for (int i = 0; i < values.length; i++) { 1184 if (value.contentEquals(values[i])) { 1185 mTrackFrameTime.setValueIndex(i); 1186 mTrackFrameTime.setSummary(mTrackFrameTime.getEntries()[i]); 1187 return; 1188 } 1189 } 1190 mTrackFrameTime.setValueIndex(0); 1191 mTrackFrameTime.setSummary(mTrackFrameTime.getEntries()[0]); 1192 } 1193 1194 private void writeTrackFrameTimeOptions(Object newValue) { 1195 SystemProperties.set(ThreadedRenderer.PROFILE_PROPERTY, 1196 newValue == null ? "" : newValue.toString()); 1197 pokeSystemProperties(); 1198 updateTrackFrameTimeOptions(); 1199 } 1200 1201 private void updateShowNonRectClipOptions() { 1202 String value = SystemProperties.get( 1203 ThreadedRenderer.DEBUG_SHOW_NON_RECTANGULAR_CLIP_PROPERTY); 1204 if (value == null) { 1205 value = "hide"; 1206 } 1207 1208 CharSequence[] values = mShowNonRectClip.getEntryValues(); 1209 for (int i = 0; i < values.length; i++) { 1210 if (value.contentEquals(values[i])) { 1211 mShowNonRectClip.setValueIndex(i); 1212 mShowNonRectClip.setSummary(mShowNonRectClip.getEntries()[i]); 1213 return; 1214 } 1215 } 1216 mShowNonRectClip.setValueIndex(0); 1217 mShowNonRectClip.setSummary(mShowNonRectClip.getEntries()[0]); 1218 } 1219 1220 private void writeShowNonRectClipOptions(Object newValue) { 1221 SystemProperties.set(ThreadedRenderer.DEBUG_SHOW_NON_RECTANGULAR_CLIP_PROPERTY, 1222 newValue == null ? "" : newValue.toString()); 1223 pokeSystemProperties(); 1224 updateShowNonRectClipOptions(); 1225 } 1226 1227 private void updateShowHwScreenUpdatesOptions() { 1228 updateSwitchPreference(mShowHwScreenUpdates, 1229 SystemProperties.getBoolean(ThreadedRenderer.DEBUG_DIRTY_REGIONS_PROPERTY, false)); 1230 } 1231 1232 private void writeShowHwScreenUpdatesOptions() { 1233 SystemProperties.set(ThreadedRenderer.DEBUG_DIRTY_REGIONS_PROPERTY, 1234 mShowHwScreenUpdates.isChecked() ? "true" : null); 1235 pokeSystemProperties(); 1236 } 1237 1238 private void updateShowHwLayersUpdatesOptions() { 1239 updateSwitchPreference(mShowHwLayersUpdates, SystemProperties.getBoolean( 1240 ThreadedRenderer.DEBUG_SHOW_LAYERS_UPDATES_PROPERTY, false)); 1241 } 1242 1243 private void writeShowHwLayersUpdatesOptions() { 1244 SystemProperties.set(ThreadedRenderer.DEBUG_SHOW_LAYERS_UPDATES_PROPERTY, 1245 mShowHwLayersUpdates.isChecked() ? "true" : null); 1246 pokeSystemProperties(); 1247 } 1248 1249 private void updateDebugHwOverdrawOptions() { 1250 String value = SystemProperties.get(ThreadedRenderer.DEBUG_OVERDRAW_PROPERTY); 1251 if (value == null) { 1252 value = ""; 1253 } 1254 1255 CharSequence[] values = mDebugHwOverdraw.getEntryValues(); 1256 for (int i = 0; i < values.length; i++) { 1257 if (value.contentEquals(values[i])) { 1258 mDebugHwOverdraw.setValueIndex(i); 1259 mDebugHwOverdraw.setSummary(mDebugHwOverdraw.getEntries()[i]); 1260 return; 1261 } 1262 } 1263 mDebugHwOverdraw.setValueIndex(0); 1264 mDebugHwOverdraw.setSummary(mDebugHwOverdraw.getEntries()[0]); 1265 } 1266 1267 private void writeDebugHwOverdrawOptions(Object newValue) { 1268 SystemProperties.set(ThreadedRenderer.DEBUG_OVERDRAW_PROPERTY, 1269 newValue == null ? "" : newValue.toString()); 1270 pokeSystemProperties(); 1271 updateDebugHwOverdrawOptions(); 1272 } 1273 1274 private void updateDebugHwRendererOptions() { 1275 String value = SystemProperties.get(ThreadedRenderer.DEBUG_RENDERER_PROPERTY); 1276 if (value == null) { 1277 value = ""; 1278 } 1279 1280 CharSequence[] values = mDebugHwRenderer.getEntryValues(); 1281 for (int i = 0; i < values.length; i++) { 1282 if (value.contentEquals(values[i])) { 1283 mDebugHwRenderer.setValueIndex(i); 1284 mDebugHwRenderer.setSummary(mDebugHwRenderer.getEntries()[i]); 1285 return; 1286 } 1287 } 1288 mDebugHwRenderer.setValueIndex(0); 1289 mDebugHwRenderer.setSummary(mDebugHwRenderer.getEntries()[0]); 1290 } 1291 1292 private void writeDebugHwRendererOptions(Object newValue) { 1293 SystemProperties.set(ThreadedRenderer.DEBUG_RENDERER_PROPERTY, 1294 newValue == null ? "" : newValue.toString()); 1295 pokeSystemProperties(); 1296 updateDebugHwRendererOptions(); 1297 } 1298 1299 private void updateDebugLayoutOptions() { 1300 updateSwitchPreference(mDebugLayout, 1301 SystemProperties.getBoolean(View.DEBUG_LAYOUT_PROPERTY, false)); 1302 } 1303 1304 private void writeDebugLayoutOptions() { 1305 SystemProperties.set(View.DEBUG_LAYOUT_PROPERTY, 1306 mDebugLayout.isChecked() ? "true" : "false"); 1307 pokeSystemProperties(); 1308 } 1309 1310 private void updateSimulateColorSpace() { 1311 final ContentResolver cr = getContentResolver(); 1312 final boolean enabled = Settings.Secure.getInt( 1313 cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0) != 0; 1314 if (enabled) { 1315 final String mode = Integer.toString(Settings.Secure.getInt( 1316 cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER, 1317 AccessibilityManager.DALTONIZER_DISABLED)); 1318 mSimulateColorSpace.setValue(mode); 1319 final int index = mSimulateColorSpace.findIndexOfValue(mode); 1320 if (index < 0) { 1321 // We're using a mode controlled by accessibility preferences. 1322 mSimulateColorSpace.setSummary(getString(R.string.daltonizer_type_overridden, 1323 getString(R.string.accessibility_display_daltonizer_preference_title))); 1324 } else { 1325 mSimulateColorSpace.setSummary("%s"); 1326 } 1327 } else { 1328 mSimulateColorSpace.setValue( 1329 Integer.toString(AccessibilityManager.DALTONIZER_DISABLED)); 1330 } 1331 } 1332 1333 /** 1334 * @return <code>true</code> if the color space preference is currently 1335 * controlled by development settings 1336 */ 1337 private boolean usingDevelopmentColorSpace() { 1338 final ContentResolver cr = getContentResolver(); 1339 final boolean enabled = Settings.Secure.getInt( 1340 cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0) != 0; 1341 if (enabled) { 1342 final String mode = Integer.toString(Settings.Secure.getInt( 1343 cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER, 1344 AccessibilityManager.DALTONIZER_DISABLED)); 1345 final int index = mSimulateColorSpace.findIndexOfValue(mode); 1346 if (index >= 0) { 1347 // We're using a mode controlled by developer preferences. 1348 return true; 1349 } 1350 } 1351 return false; 1352 } 1353 1354 private void writeSimulateColorSpace(Object value) { 1355 final ContentResolver cr = getContentResolver(); 1356 final int newMode = Integer.parseInt(value.toString()); 1357 if (newMode < 0) { 1358 Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0); 1359 } else { 1360 Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 1); 1361 Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER, newMode); 1362 } 1363 } 1364 1365 private void updateColorTemperature() { 1366 updateSwitchPreference(mColorTemperaturePreference, 1367 SystemProperties.getBoolean(COLOR_TEMPERATURE_PROPERTY, false)); 1368 } 1369 1370 private void writeColorTemperature() { 1371 SystemProperties.set(COLOR_TEMPERATURE_PROPERTY, 1372 mColorTemperaturePreference.isChecked() ? "1" : "0"); 1373 pokeSystemProperties(); 1374 Toast.makeText(getActivity(), R.string.color_temperature_toast, Toast.LENGTH_LONG).show(); 1375 } 1376 1377 private void updateUSBAudioOptions() { 1378 updateSwitchPreference(mUSBAudio, Settings.Secure.getInt(getContentResolver(), 1379 Settings.Secure.USB_AUDIO_AUTOMATIC_ROUTING_DISABLED, 0) != 0); 1380 } 1381 1382 private void writeUSBAudioOptions() { 1383 Settings.Secure.putInt(getContentResolver(), 1384 Settings.Secure.USB_AUDIO_AUTOMATIC_ROUTING_DISABLED, 1385 mUSBAudio.isChecked() ? 1 : 0); 1386 } 1387 1388 private void updateForceResizableOptions() { 1389 updateSwitchPreference(mForceResizable, Settings.Global.getInt(getContentResolver(), 1390 Settings.Global.DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES, 0) != 0); 1391 } 1392 1393 private void writeForceResizableOptions() { 1394 Settings.Global.putInt(getContentResolver(), 1395 Settings.Global.DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES, 1396 mForceResizable.isChecked() ? 1 : 0); 1397 } 1398 1399 private void updateForceRtlOptions() { 1400 updateSwitchPreference(mForceRtlLayout, 1401 Settings.Global.getInt(getActivity().getContentResolver(), 1402 Settings.Global.DEVELOPMENT_FORCE_RTL, 0) != 0); 1403 } 1404 1405 private void writeForceRtlOptions() { 1406 boolean value = mForceRtlLayout.isChecked(); 1407 Settings.Global.putInt(getActivity().getContentResolver(), 1408 Settings.Global.DEVELOPMENT_FORCE_RTL, value ? 1 : 0); 1409 SystemProperties.set(Settings.Global.DEVELOPMENT_FORCE_RTL, value ? "1" : "0"); 1410 LocalePicker.updateLocales(getActivity().getResources().getConfiguration().getLocales()); 1411 } 1412 1413 private void updateWifiDisplayCertificationOptions() { 1414 updateSwitchPreference(mWifiDisplayCertification, Settings.Global.getInt( 1415 getActivity().getContentResolver(), 1416 Settings.Global.WIFI_DISPLAY_CERTIFICATION_ON, 0) != 0); 1417 } 1418 1419 private void writeWifiDisplayCertificationOptions() { 1420 Settings.Global.putInt(getActivity().getContentResolver(), 1421 Settings.Global.WIFI_DISPLAY_CERTIFICATION_ON, 1422 mWifiDisplayCertification.isChecked() ? 1 : 0); 1423 } 1424 1425 private void updateWifiVerboseLoggingOptions() { 1426 boolean enabled = mWifiManager.getVerboseLoggingLevel() > 0; 1427 updateSwitchPreference(mWifiVerboseLogging, enabled); 1428 } 1429 1430 private void writeWifiVerboseLoggingOptions() { 1431 mWifiManager.enableVerboseLogging(mWifiVerboseLogging.isChecked() ? 1 : 0); 1432 } 1433 1434 private void updateWifiAggressiveHandoverOptions() { 1435 boolean enabled = mWifiManager.getAggressiveHandover() > 0; 1436 updateSwitchPreference(mWifiAggressiveHandover, enabled); 1437 } 1438 1439 private void writeWifiAggressiveHandoverOptions() { 1440 mWifiManager.enableAggressiveHandover(mWifiAggressiveHandover.isChecked() ? 1 : 0); 1441 } 1442 1443 private void updateWifiAllowScansWithTrafficOptions() { 1444 boolean enabled = mWifiManager.getAllowScansWithTraffic() > 0; 1445 updateSwitchPreference(mWifiAllowScansWithTraffic, enabled); 1446 } 1447 1448 private void writeWifiAllowScansWithTrafficOptions() { 1449 mWifiManager.setAllowScansWithTraffic(mWifiAllowScansWithTraffic.isChecked() ? 1 : 0); 1450 } 1451 1452 private void updateBluetoothDisableAbsVolumeOptions() { 1453 updateSwitchPreference(mBluetoothDisableAbsVolume, 1454 SystemProperties.getBoolean(BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_PROPERTY, false)); 1455 } 1456 1457 private void writeBluetoothDisableAbsVolumeOptions() { 1458 SystemProperties.set(BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_PROPERTY, 1459 mBluetoothDisableAbsVolume.isChecked() ? "true" : "false"); 1460 } 1461 1462 private void updateBluetoothEnableInbandRingingOptions() { 1463 if (mBluetoothEnableInbandRinging != null) { 1464 updateSwitchPreference(mBluetoothEnableInbandRinging, 1465 SystemProperties.getBoolean(BLUETOOTH_ENABLE_INBAND_RINGING_PROPERTY, true)); 1466 } 1467 } 1468 1469 private void writeBluetoothEnableInbandRingingOptions() { 1470 if (mBluetoothEnableInbandRinging != null) { 1471 SystemProperties.set(BLUETOOTH_ENABLE_INBAND_RINGING_PROPERTY, 1472 mBluetoothEnableInbandRinging.isChecked() ? "true" : "false"); 1473 } 1474 } 1475 1476 private void updateMobileDataAlwaysOnOptions() { 1477 updateSwitchPreference(mMobileDataAlwaysOn, Settings.Global.getInt( 1478 getActivity().getContentResolver(), 1479 Settings.Global.MOBILE_DATA_ALWAYS_ON, 1) != 0); 1480 } 1481 1482 private void writeMobileDataAlwaysOnOptions() { 1483 Settings.Global.putInt(getActivity().getContentResolver(), 1484 Settings.Global.MOBILE_DATA_ALWAYS_ON, 1485 mMobileDataAlwaysOn.isChecked() ? 1 : 0); 1486 } 1487 1488 private void updateTetheringHardwareOffloadOptions() { 1489 updateSwitchPreference(mTetheringHardwareOffload, Settings.Global.getInt( 1490 getActivity().getContentResolver(), 1491 Settings.Global.TETHER_OFFLOAD_DISABLED, 0) != 1); 1492 } 1493 1494 private void writeTetheringHardwareOffloadOptions() { 1495 Settings.Global.putInt(getActivity().getContentResolver(), 1496 Settings.Global.TETHER_OFFLOAD_DISABLED, 1497 mTetheringHardwareOffload.isChecked() ? 0 : 1); 1498 } 1499 1500 private String defaultLogdSizeValue() { 1501 String defaultValue = SystemProperties.get(SELECT_LOGD_DEFAULT_SIZE_PROPERTY); 1502 if ((defaultValue == null) || (defaultValue.length() == 0)) { 1503 if (SystemProperties.get("ro.config.low_ram").equals("true")) { 1504 defaultValue = SELECT_LOGD_SVELTE_DEFAULT_SIZE_VALUE; 1505 } else { 1506 defaultValue = SELECT_LOGD_DEFAULT_SIZE_VALUE; 1507 } 1508 } 1509 return defaultValue; 1510 } 1511 1512 private void updateLogdSizeValues() { 1513 if (mLogdSize != null) { 1514 String currentTag = SystemProperties.get(SELECT_LOGD_TAG_PROPERTY); 1515 String currentValue = SystemProperties.get(SELECT_LOGD_SIZE_PROPERTY); 1516 if ((currentTag != null) && currentTag.startsWith(SELECT_LOGD_TAG_SILENCE)) { 1517 currentValue = SELECT_LOGD_OFF_SIZE_MARKER_VALUE; 1518 } 1519 if (mLogpersist != null) { 1520 String currentLogpersistEnable 1521 = SystemProperties.get(ACTUAL_LOGPERSIST_PROPERTY_ENABLE); 1522 if ((currentLogpersistEnable == null) 1523 || !currentLogpersistEnable.equals("true") 1524 || currentValue.equals(SELECT_LOGD_OFF_SIZE_MARKER_VALUE)) { 1525 writeLogpersistOption(null, true); 1526 mLogpersist.setEnabled(false); 1527 } else if (mSettingsEnabler.getLastEnabledState()) { 1528 mLogpersist.setEnabled(true); 1529 } 1530 } 1531 if ((currentValue == null) || (currentValue.length() == 0)) { 1532 currentValue = defaultLogdSizeValue(); 1533 } 1534 String[] values = getResources().getStringArray(R.array.select_logd_size_values); 1535 String[] titles = getResources().getStringArray(R.array.select_logd_size_titles); 1536 int index = 2; // punt to second entry if not found 1537 if (SystemProperties.get("ro.config.low_ram").equals("true")) { 1538 mLogdSize.setEntries(R.array.select_logd_size_lowram_titles); 1539 titles = getResources().getStringArray(R.array.select_logd_size_lowram_titles); 1540 index = 1; 1541 } 1542 String[] summaries = getResources().getStringArray(R.array.select_logd_size_summaries); 1543 for (int i = 0; i < titles.length; i++) { 1544 if (currentValue.equals(values[i]) 1545 || currentValue.equals(titles[i])) { 1546 index = i; 1547 break; 1548 } 1549 } 1550 mLogdSize.setValue(values[index]); 1551 mLogdSize.setSummary(summaries[index]); 1552 mLogdSize.setOnPreferenceChangeListener(this); 1553 } 1554 } 1555 1556 private void writeLogdSizeOption(Object newValue) { 1557 boolean disable = (newValue != null) && 1558 (newValue.toString().equals(SELECT_LOGD_OFF_SIZE_MARKER_VALUE)); 1559 String currentTag = SystemProperties.get(SELECT_LOGD_TAG_PROPERTY); 1560 if (currentTag == null) { 1561 currentTag = ""; 1562 } 1563 // filter clean and unstack all references to our setting 1564 String newTag = currentTag.replaceAll( 1565 ",+" + SELECT_LOGD_TAG_SILENCE, "").replaceFirst( 1566 "^" + SELECT_LOGD_TAG_SILENCE + ",*", "").replaceAll( 1567 ",+", ",").replaceFirst( 1568 ",+$", ""); 1569 if (disable) { 1570 newValue = SELECT_LOGD_MINIMUM_SIZE_VALUE; 1571 // Make sure snet_event_log get through first, but do not override 1572 String snetValue = SystemProperties.get(SELECT_LOGD_SNET_TAG_PROPERTY); 1573 if ((snetValue == null) || (snetValue.length() == 0)) { 1574 snetValue = SystemProperties.get(SELECT_LOGD_RUNTIME_SNET_TAG_PROPERTY); 1575 if ((snetValue == null) || (snetValue.length() == 0)) { 1576 SystemProperties.set(SELECT_LOGD_SNET_TAG_PROPERTY, "I"); 1577 } 1578 } 1579 // Silence all log sources, security logs notwithstanding 1580 if (newTag.length() != 0) { 1581 newTag = "," + newTag; 1582 } 1583 // Stack settings, stack to help preserve original value 1584 newTag = SELECT_LOGD_TAG_SILENCE + newTag; 1585 } 1586 if (!newTag.equals(currentTag)) { 1587 SystemProperties.set(SELECT_LOGD_TAG_PROPERTY, newTag); 1588 } 1589 String defaultValue = defaultLogdSizeValue(); 1590 final String size = ((newValue != null) && (newValue.toString().length() != 0)) ? 1591 newValue.toString() : defaultValue; 1592 SystemProperties.set(SELECT_LOGD_SIZE_PROPERTY, defaultValue.equals(size) ? "" : size); 1593 SystemProperties.set("ctl.start", "logd-reinit"); 1594 pokeSystemProperties(); 1595 updateLogdSizeValues(); 1596 } 1597 1598 private void updateLogpersistValues() { 1599 if (mLogpersist == null) { 1600 return; 1601 } 1602 String currentValue = SystemProperties.get(ACTUAL_LOGPERSIST_PROPERTY); 1603 if (currentValue == null) { 1604 currentValue = ""; 1605 } 1606 String currentBuffers = SystemProperties.get(ACTUAL_LOGPERSIST_PROPERTY_BUFFER); 1607 if ((currentBuffers == null) || (currentBuffers.length() == 0)) { 1608 currentBuffers = "all"; 1609 } 1610 int index = 0; 1611 if (currentValue.equals(SELECT_LOGPERSIST_PROPERTY_SERVICE)) { 1612 index = 1; 1613 if (currentBuffers.equals("kernel")) { 1614 index = 3; 1615 } else if (!currentBuffers.equals("all") && 1616 !currentBuffers.contains("radio") && 1617 currentBuffers.contains("security") && 1618 currentBuffers.contains("kernel")) { 1619 index = 2; 1620 if (!currentBuffers.contains("default")) { 1621 String[] contains = {"main", "events", "system", "crash"}; 1622 for (int i = 0; i < contains.length; i++) { 1623 if (!currentBuffers.contains(contains[i])) { 1624 index = 1; 1625 break; 1626 } 1627 } 1628 } 1629 } 1630 } 1631 mLogpersist.setValue( 1632 getResources().getStringArray(R.array.select_logpersist_values)[index]); 1633 mLogpersist.setSummary( 1634 getResources().getStringArray(R.array.select_logpersist_summaries)[index]); 1635 mLogpersist.setOnPreferenceChangeListener(this); 1636 if (index != 0) { 1637 mLogpersistCleared = false; 1638 } else if (!mLogpersistCleared) { 1639 // would File.delete() directly but need to switch uid/gid to access 1640 SystemProperties.set(ACTUAL_LOGPERSIST_PROPERTY, SELECT_LOGPERSIST_PROPERTY_CLEAR); 1641 pokeSystemProperties(); 1642 mLogpersistCleared = true; 1643 } 1644 } 1645 1646 private void setLogpersistOff(boolean update) { 1647 SystemProperties.set(SELECT_LOGPERSIST_PROPERTY_BUFFER, ""); 1648 // deal with trampoline of empty properties 1649 SystemProperties.set(ACTUAL_LOGPERSIST_PROPERTY_BUFFER, ""); 1650 SystemProperties.set(SELECT_LOGPERSIST_PROPERTY, ""); 1651 SystemProperties.set(ACTUAL_LOGPERSIST_PROPERTY, 1652 update ? "" : SELECT_LOGPERSIST_PROPERTY_STOP); 1653 pokeSystemProperties(); 1654 if (update) { 1655 updateLogpersistValues(); 1656 } else { 1657 for (int i = 0; i < 3; i++) { 1658 String currentValue = SystemProperties.get(ACTUAL_LOGPERSIST_PROPERTY); 1659 if ((currentValue == null) || currentValue.equals("")) { 1660 break; 1661 } 1662 try { 1663 Thread.sleep(100); 1664 } catch (InterruptedException e) { 1665 } 1666 } 1667 } 1668 } 1669 1670 private void writeLogpersistOption(Object newValue, boolean skipWarning) { 1671 if (mLogpersist == null) { 1672 return; 1673 } 1674 String currentTag = SystemProperties.get(SELECT_LOGD_TAG_PROPERTY); 1675 if ((currentTag != null) && currentTag.startsWith(SELECT_LOGD_TAG_SILENCE)) { 1676 newValue = null; 1677 skipWarning = true; 1678 } 1679 1680 if ((newValue == null) || newValue.toString().equals("")) { 1681 if (skipWarning) { 1682 mLogpersistCleared = false; 1683 } else if (!mLogpersistCleared) { 1684 // if transitioning from on to off, pop up an are you sure? 1685 String currentValue = SystemProperties.get(ACTUAL_LOGPERSIST_PROPERTY); 1686 if ((currentValue != null) && 1687 currentValue.equals(SELECT_LOGPERSIST_PROPERTY_SERVICE)) { 1688 if (mLogpersistClearDialog != null) dismissDialogs(); 1689 mLogpersistClearDialog = new AlertDialog.Builder(getActivity()).setMessage( 1690 getActivity().getResources().getString( 1691 R.string.dev_logpersist_clear_warning_message)) 1692 .setTitle(R.string.dev_logpersist_clear_warning_title) 1693 .setPositiveButton(android.R.string.yes, this) 1694 .setNegativeButton(android.R.string.no, this) 1695 .show(); 1696 mLogpersistClearDialog.setOnDismissListener(this); 1697 return; 1698 } 1699 } 1700 setLogpersistOff(true); 1701 return; 1702 } 1703 1704 String currentBuffer = SystemProperties.get(ACTUAL_LOGPERSIST_PROPERTY_BUFFER); 1705 if ((currentBuffer != null) && !currentBuffer.equals(newValue.toString())) { 1706 setLogpersistOff(false); 1707 } 1708 SystemProperties.set(SELECT_LOGPERSIST_PROPERTY_BUFFER, newValue.toString()); 1709 SystemProperties.set(SELECT_LOGPERSIST_PROPERTY, SELECT_LOGPERSIST_PROPERTY_SERVICE); 1710 pokeSystemProperties(); 1711 for (int i = 0; i < 3; i++) { 1712 String currentValue = SystemProperties.get(ACTUAL_LOGPERSIST_PROPERTY); 1713 if ((currentValue != null) 1714 && currentValue.equals(SELECT_LOGPERSIST_PROPERTY_SERVICE)) { 1715 break; 1716 } 1717 try { 1718 Thread.sleep(100); 1719 } catch (InterruptedException e) { 1720 } 1721 } 1722 updateLogpersistValues(); 1723 } 1724 1725 private void updateUsbConfigurationValues() { 1726 if (mUsbConfiguration != null) { 1727 UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); 1728 1729 String[] values = getResources().getStringArray(R.array.usb_configuration_values); 1730 String[] titles = getResources().getStringArray(R.array.usb_configuration_titles); 1731 int index = 0; 1732 for (int i = 0; i < titles.length; i++) { 1733 if (manager.isFunctionEnabled(values[i])) { 1734 index = i; 1735 break; 1736 } 1737 } 1738 mUsbConfiguration.setValue(values[index]); 1739 mUsbConfiguration.setSummary(titles[index]); 1740 mUsbConfiguration.setOnPreferenceChangeListener(this); 1741 } 1742 } 1743 1744 private void writeUsbConfigurationOption(Object newValue) { 1745 UsbManager manager = (UsbManager) getActivity().getSystemService(Context.USB_SERVICE); 1746 String function = newValue.toString(); 1747 if (function.equals("none")) { 1748 manager.setCurrentFunction(function, false); 1749 } else { 1750 manager.setCurrentFunction(function, true); 1751 } 1752 } 1753 1754 private void initBluetoothConfigurationValues() { 1755 String[] values; 1756 String[] summaries; 1757 int index; 1758 1759 // Init the AVRCP Version - Default 1760 values = getResources().getStringArray(R.array.bluetooth_avrcp_version_values); 1761 summaries = getResources().getStringArray(R.array.bluetooth_avrcp_versions); 1762 String value = SystemProperties.get(BLUETOOTH_AVRCP_VERSION_PROPERTY, values[0]); 1763 index = mBluetoothSelectAvrcpVersion.findIndexOfValue(value); 1764 mBluetoothSelectAvrcpVersion.setValue(values[index]); 1765 mBluetoothSelectAvrcpVersion.setSummary(summaries[index]); 1766 1767 // Init the Codec Type - Default 1768 values = getResources().getStringArray(R.array.bluetooth_a2dp_codec_values); 1769 summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_summaries); 1770 index = 0; 1771 mBluetoothSelectA2dpCodec.setValue(values[index]); 1772 mBluetoothSelectA2dpCodec.setSummary(summaries[index]); 1773 1774 // Init the Sample Rate - Default 1775 values = getResources().getStringArray(R.array.bluetooth_a2dp_codec_sample_rate_values); 1776 summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_sample_rate_summaries); 1777 index = 0; 1778 mBluetoothSelectA2dpSampleRate.setValue(values[index]); 1779 mBluetoothSelectA2dpSampleRate.setSummary(summaries[index]); 1780 1781 // Init the Bits Per Sample - Default 1782 values = getResources().getStringArray(R.array.bluetooth_a2dp_codec_bits_per_sample_values); 1783 summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_bits_per_sample_summaries); 1784 index = 0; 1785 mBluetoothSelectA2dpBitsPerSample.setValue(values[index]); 1786 mBluetoothSelectA2dpBitsPerSample.setSummary(summaries[index]); 1787 1788 // Init the Channel Mode - Default 1789 values = getResources().getStringArray(R.array.bluetooth_a2dp_codec_channel_mode_values); 1790 summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_channel_mode_summaries); 1791 index = 0; 1792 mBluetoothSelectA2dpChannelMode.setValue(values[index]); 1793 mBluetoothSelectA2dpChannelMode.setSummary(summaries[index]); 1794 1795 // Init the LDAC Playback Quality - ABR 1796 values = getResources().getStringArray(R.array.bluetooth_a2dp_codec_ldac_playback_quality_values); 1797 summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_ldac_playback_quality_summaries); 1798 index = 3; 1799 mBluetoothSelectA2dpLdacPlaybackQuality.setValue(values[index]); 1800 mBluetoothSelectA2dpLdacPlaybackQuality.setSummary(summaries[index]); 1801 } 1802 1803 private void writeBluetoothAvrcpVersion(Object newValue) { 1804 SystemProperties.set(BLUETOOTH_AVRCP_VERSION_PROPERTY, newValue.toString()); 1805 int index = mBluetoothSelectAvrcpVersion.findIndexOfValue(newValue.toString()); 1806 if (index >= 0) { 1807 String[] titles = getResources().getStringArray(R.array.bluetooth_avrcp_versions); 1808 mBluetoothSelectAvrcpVersion.setSummary(titles[index]); 1809 } 1810 } 1811 1812 private void updateBluetoothA2dpConfigurationValues() { 1813 int index; 1814 String[] summaries; 1815 BluetoothCodecStatus codecStatus = null; 1816 BluetoothCodecConfig codecConfig = null; 1817 BluetoothCodecConfig[] codecsLocalCapabilities = null; 1818 BluetoothCodecConfig[] codecsSelectableCapabilities = null; 1819 String streaming; 1820 Resources resources = null; 1821 1822 synchronized (mBluetoothA2dpLock) { 1823 if (mBluetoothA2dp != null) { 1824 codecStatus = mBluetoothA2dp.getCodecStatus(); 1825 if (codecStatus != null) { 1826 codecConfig = codecStatus.getCodecConfig(); 1827 codecsLocalCapabilities = codecStatus.getCodecsLocalCapabilities(); 1828 codecsSelectableCapabilities = codecStatus.getCodecsSelectableCapabilities(); 1829 } 1830 } 1831 } 1832 if (codecConfig == null) { 1833 return; 1834 } 1835 1836 try { 1837 resources = getResources(); 1838 } catch (IllegalStateException e) { 1839 return; 1840 } 1841 if (resources == null) { 1842 return; 1843 } 1844 1845 // Update the Codec Type 1846 index = -1; 1847 switch (codecConfig.getCodecType()) { 1848 case BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC: 1849 index = 1; 1850 break; 1851 case BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC: 1852 index = 2; 1853 break; 1854 case BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX: 1855 index = 3; 1856 break; 1857 case BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD: 1858 index = 4; 1859 break; 1860 case BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC: 1861 index = 5; 1862 break; 1863 case BluetoothCodecConfig.SOURCE_CODEC_TYPE_INVALID: 1864 default: 1865 break; 1866 } 1867 if (index >= 0 && mBluetoothSelectA2dpCodec != null) { 1868 summaries = resources.getStringArray(R.array.bluetooth_a2dp_codec_summaries); 1869 streaming = resources.getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]); 1870 mBluetoothSelectA2dpCodec.setSummary(streaming); 1871 } 1872 1873 // Update the Sample Rate 1874 index = -1; 1875 switch (codecConfig.getSampleRate()) { 1876 case BluetoothCodecConfig.SAMPLE_RATE_44100: 1877 index = 1; 1878 break; 1879 case BluetoothCodecConfig.SAMPLE_RATE_48000: 1880 index = 2; 1881 break; 1882 case BluetoothCodecConfig.SAMPLE_RATE_88200: 1883 index = 3; 1884 break; 1885 case BluetoothCodecConfig.SAMPLE_RATE_96000: 1886 index = 4; 1887 break; 1888 case BluetoothCodecConfig.SAMPLE_RATE_176400: 1889 case BluetoothCodecConfig.SAMPLE_RATE_192000: 1890 case BluetoothCodecConfig.SAMPLE_RATE_NONE: 1891 default: 1892 break; 1893 } 1894 if (index >= 0 && mBluetoothSelectA2dpSampleRate != null) { 1895 summaries = resources.getStringArray(R.array.bluetooth_a2dp_codec_sample_rate_summaries); 1896 streaming = resources.getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]); 1897 mBluetoothSelectA2dpSampleRate.setSummary(streaming); 1898 } 1899 1900 // Update the Bits Per Sample 1901 index = -1; 1902 switch (codecConfig.getBitsPerSample()) { 1903 case BluetoothCodecConfig.BITS_PER_SAMPLE_16: 1904 index = 1; 1905 break; 1906 case BluetoothCodecConfig.BITS_PER_SAMPLE_24: 1907 index = 2; 1908 break; 1909 case BluetoothCodecConfig.BITS_PER_SAMPLE_32: 1910 index = 3; 1911 break; 1912 case BluetoothCodecConfig.BITS_PER_SAMPLE_NONE: 1913 default: 1914 break; 1915 } 1916 if (index >= 0 && mBluetoothSelectA2dpBitsPerSample != null) { 1917 summaries = resources.getStringArray(R.array.bluetooth_a2dp_codec_bits_per_sample_summaries); 1918 streaming = resources.getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]); 1919 mBluetoothSelectA2dpBitsPerSample.setSummary(streaming); 1920 } 1921 1922 // Update the Channel Mode 1923 index = -1; 1924 switch (codecConfig.getChannelMode()) { 1925 case BluetoothCodecConfig.CHANNEL_MODE_MONO: 1926 index = 1; 1927 break; 1928 case BluetoothCodecConfig.CHANNEL_MODE_STEREO: 1929 index = 2; 1930 break; 1931 case BluetoothCodecConfig.CHANNEL_MODE_NONE: 1932 default: 1933 break; 1934 } 1935 if (index >= 0 && mBluetoothSelectA2dpChannelMode != null) { 1936 summaries = resources.getStringArray(R.array.bluetooth_a2dp_codec_channel_mode_summaries); 1937 streaming = resources.getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]); 1938 mBluetoothSelectA2dpChannelMode.setSummary(streaming); 1939 } 1940 1941 // Update the LDAC Playback Quality 1942 // The actual values are 0, 1, 2 - those are extracted 1943 // as mod-10 remainders of a larger value. 1944 // The reason is because within BluetoothCodecConfig we cannot use 1945 // a codec-specific value of zero. 1946 index = (int)codecConfig.getCodecSpecific1(); 1947 if (index > 0) { 1948 index %= 10; 1949 } else { 1950 index = -1; 1951 } 1952 switch (index) { 1953 case 0: 1954 case 1: 1955 case 2: 1956 case 3: 1957 break; 1958 default: 1959 index = -1; 1960 break; 1961 } 1962 if (index >= 0 && mBluetoothSelectA2dpLdacPlaybackQuality != null) { 1963 summaries = resources.getStringArray(R.array.bluetooth_a2dp_codec_ldac_playback_quality_summaries); 1964 streaming = resources.getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]); 1965 mBluetoothSelectA2dpLdacPlaybackQuality.setSummary(streaming); 1966 } 1967 } 1968 1969 private void writeBluetoothConfigurationOption(Preference preference, 1970 Object newValue) { 1971 String[] summaries; 1972 int index; 1973 int codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_INVALID; 1974 int codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT; 1975 int sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_NONE; 1976 int bitsPerSampleValue = BluetoothCodecConfig.BITS_PER_SAMPLE_NONE; 1977 int channelModeValue = BluetoothCodecConfig.CHANNEL_MODE_NONE; 1978 long codecSpecific1Value = 0; 1979 long codecSpecific2Value = 0; 1980 long codecSpecific3Value = 0; 1981 long codecSpecific4Value = 0; 1982 1983 // Codec Type 1984 String codecType = mBluetoothSelectA2dpCodec.getValue(); 1985 if (preference == mBluetoothSelectA2dpCodec) { 1986 codecType = newValue.toString(); 1987 index = mBluetoothSelectA2dpCodec.findIndexOfValue(newValue.toString()); 1988 if (index >= 0) { 1989 summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_summaries); 1990 mBluetoothSelectA2dpCodec.setSummary(summaries[index]); 1991 } 1992 } 1993 index = mBluetoothSelectA2dpCodec.findIndexOfValue(codecType); 1994 switch (index) { 1995 case 0: 1996 // Reset the priority of the current codec to default 1997 String oldValue = mBluetoothSelectA2dpCodec.getValue(); 1998 switch (mBluetoothSelectA2dpCodec.findIndexOfValue(oldValue)) { 1999 case 0: 2000 break; // No current codec 2001 case 1: 2002 codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC; 2003 break; 2004 case 2: 2005 codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC; 2006 break; 2007 case 3: 2008 codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX; 2009 break; 2010 case 4: 2011 codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD; 2012 break; 2013 case 5: 2014 codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC; 2015 break; 2016 default: 2017 break; 2018 } 2019 break; 2020 case 1: 2021 codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC; 2022 codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST; 2023 break; 2024 case 2: 2025 codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC; 2026 codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST; 2027 break; 2028 case 3: 2029 codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX; 2030 codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST; 2031 break; 2032 case 4: 2033 codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD; 2034 codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST; 2035 break; 2036 case 5: 2037 codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC; 2038 codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST; 2039 break; 2040 case 6: 2041 synchronized (mBluetoothA2dpLock) { 2042 if (mBluetoothA2dp != null) { 2043 mBluetoothA2dp.enableOptionalCodecs(); 2044 } 2045 } 2046 return; 2047 case 7: 2048 synchronized (mBluetoothA2dpLock) { 2049 if (mBluetoothA2dp != null) { 2050 mBluetoothA2dp.disableOptionalCodecs(); 2051 } 2052 } 2053 return; 2054 default: 2055 break; 2056 } 2057 2058 // Sample Rate 2059 String sampleRate = mBluetoothSelectA2dpSampleRate.getValue(); 2060 if (preference == mBluetoothSelectA2dpSampleRate) { 2061 sampleRate = newValue.toString(); 2062 index = mBluetoothSelectA2dpSampleRate.findIndexOfValue(newValue.toString()); 2063 if (index >= 0) { 2064 summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_sample_rate_summaries); 2065 mBluetoothSelectA2dpSampleRate.setSummary(summaries[index]); 2066 } 2067 } 2068 index = mBluetoothSelectA2dpSampleRate.findIndexOfValue(sampleRate); 2069 switch (index) { 2070 case 0: 2071 // Reset to default 2072 break; 2073 case 1: 2074 sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_44100; 2075 break; 2076 case 2: 2077 sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_48000; 2078 break; 2079 case 3: 2080 sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_88200; 2081 break; 2082 case 4: 2083 sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_96000; 2084 break; 2085 default: 2086 break; 2087 } 2088 2089 // Bits Per Sample 2090 String bitsPerSample = mBluetoothSelectA2dpBitsPerSample.getValue(); 2091 if (preference == mBluetoothSelectA2dpBitsPerSample) { 2092 bitsPerSample = newValue.toString(); 2093 index = mBluetoothSelectA2dpBitsPerSample.findIndexOfValue(newValue.toString()); 2094 if (index >= 0) { 2095 summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_bits_per_sample_summaries); 2096 mBluetoothSelectA2dpBitsPerSample.setSummary(summaries[index]); 2097 } 2098 } 2099 index = mBluetoothSelectA2dpBitsPerSample.findIndexOfValue(bitsPerSample); 2100 switch (index) { 2101 case 0: 2102 // Reset to default 2103 break; 2104 case 1: 2105 bitsPerSampleValue = BluetoothCodecConfig.BITS_PER_SAMPLE_16; 2106 break; 2107 case 2: 2108 bitsPerSampleValue = BluetoothCodecConfig.BITS_PER_SAMPLE_24; 2109 break; 2110 case 3: 2111 bitsPerSampleValue = BluetoothCodecConfig.BITS_PER_SAMPLE_32; 2112 break; 2113 default: 2114 break; 2115 } 2116 2117 // Channel Mode 2118 String channelMode = mBluetoothSelectA2dpChannelMode.getValue(); 2119 if (preference == mBluetoothSelectA2dpChannelMode) { 2120 channelMode = newValue.toString(); 2121 index = mBluetoothSelectA2dpChannelMode.findIndexOfValue(newValue.toString()); 2122 if (index >= 0) { 2123 summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_channel_mode_summaries); 2124 mBluetoothSelectA2dpChannelMode.setSummary(summaries[index]); 2125 } 2126 } 2127 index = mBluetoothSelectA2dpChannelMode.findIndexOfValue(channelMode); 2128 switch (index) { 2129 case 0: 2130 // Reset to default 2131 break; 2132 case 1: 2133 channelModeValue = BluetoothCodecConfig.CHANNEL_MODE_MONO; 2134 break; 2135 case 2: 2136 channelModeValue = BluetoothCodecConfig.CHANNEL_MODE_STEREO; 2137 break; 2138 default: 2139 break; 2140 } 2141 2142 // LDAC Playback Quality 2143 String ldacPlaybackQuality = mBluetoothSelectA2dpLdacPlaybackQuality.getValue(); 2144 if (preference == mBluetoothSelectA2dpLdacPlaybackQuality) { 2145 ldacPlaybackQuality = newValue.toString(); 2146 index = mBluetoothSelectA2dpLdacPlaybackQuality.findIndexOfValue(newValue.toString()); 2147 if (index >= 0) { 2148 summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_ldac_playback_quality_summaries); 2149 mBluetoothSelectA2dpLdacPlaybackQuality.setSummary(summaries[index]); 2150 } 2151 } 2152 index = mBluetoothSelectA2dpLdacPlaybackQuality.findIndexOfValue(ldacPlaybackQuality); 2153 switch (index) { 2154 case 0: 2155 case 1: 2156 case 2: 2157 case 3: 2158 codecSpecific1Value = 1000 + index; 2159 break; 2160 default: 2161 break; 2162 } 2163 2164 BluetoothCodecConfig codecConfig = 2165 new BluetoothCodecConfig(codecTypeValue, codecPriorityValue, 2166 sampleRateValue, bitsPerSampleValue, 2167 channelModeValue, codecSpecific1Value, 2168 codecSpecific2Value, codecSpecific3Value, 2169 codecSpecific4Value); 2170 2171 synchronized (mBluetoothA2dpLock) { 2172 if (mBluetoothA2dp != null) { 2173 mBluetoothA2dp.setCodecConfigPreference(codecConfig); 2174 } 2175 } 2176 } 2177 2178 private void writeImmediatelyDestroyActivitiesOptions() { 2179 try { 2180 ActivityManager.getService().setAlwaysFinish( 2181 mImmediatelyDestroyActivities.isChecked()); 2182 } catch (RemoteException ex) { 2183 } 2184 } 2185 2186 private void updateImmediatelyDestroyActivitiesOptions() { 2187 updateSwitchPreference(mImmediatelyDestroyActivities, Settings.Global.getInt( 2188 getActivity().getContentResolver(), Settings.Global.ALWAYS_FINISH_ACTIVITIES, 0) 2189 != 0); 2190 } 2191 2192 private void updateAnimationScaleValue(int which, ListPreference pref) { 2193 try { 2194 float scale = mWindowManager.getAnimationScale(which); 2195 if (scale != 1) { 2196 mHaveDebugSettings = true; 2197 } 2198 CharSequence[] values = pref.getEntryValues(); 2199 for (int i = 0; i < values.length; i++) { 2200 float val = Float.parseFloat(values[i].toString()); 2201 if (scale <= val) { 2202 pref.setValueIndex(i); 2203 pref.setSummary(pref.getEntries()[i]); 2204 return; 2205 } 2206 } 2207 pref.setValueIndex(values.length - 1); 2208 pref.setSummary(pref.getEntries()[0]); 2209 } catch (RemoteException e) { 2210 } 2211 } 2212 2213 private void updateAnimationScaleOptions() { 2214 updateAnimationScaleValue(0, mWindowAnimationScale); 2215 updateAnimationScaleValue(1, mTransitionAnimationScale); 2216 updateAnimationScaleValue(2, mAnimatorDurationScale); 2217 } 2218 2219 private void writeAnimationScaleOption(int which, ListPreference pref, Object newValue) { 2220 try { 2221 float scale = newValue != null ? Float.parseFloat(newValue.toString()) : 1; 2222 mWindowManager.setAnimationScale(which, scale); 2223 updateAnimationScaleValue(which, pref); 2224 } catch (RemoteException e) { 2225 } 2226 } 2227 2228 private void updateOverlayDisplayDevicesOptions() { 2229 String value = Settings.Global.getString(getActivity().getContentResolver(), 2230 Settings.Global.OVERLAY_DISPLAY_DEVICES); 2231 if (value == null) { 2232 value = ""; 2233 } 2234 2235 CharSequence[] values = mOverlayDisplayDevices.getEntryValues(); 2236 for (int i = 0; i < values.length; i++) { 2237 if (value.contentEquals(values[i])) { 2238 mOverlayDisplayDevices.setValueIndex(i); 2239 mOverlayDisplayDevices.setSummary(mOverlayDisplayDevices.getEntries()[i]); 2240 return; 2241 } 2242 } 2243 mOverlayDisplayDevices.setValueIndex(0); 2244 mOverlayDisplayDevices.setSummary(mOverlayDisplayDevices.getEntries()[0]); 2245 } 2246 2247 private void writeOverlayDisplayDevicesOptions(Object newValue) { 2248 Settings.Global.putString(getActivity().getContentResolver(), 2249 Settings.Global.OVERLAY_DISPLAY_DEVICES, (String) newValue); 2250 updateOverlayDisplayDevicesOptions(); 2251 } 2252 2253 private void updateAppProcessLimitOptions() { 2254 try { 2255 int limit = ActivityManager.getService().getProcessLimit(); 2256 CharSequence[] values = mAppProcessLimit.getEntryValues(); 2257 for (int i = 0; i < values.length; i++) { 2258 int val = Integer.parseInt(values[i].toString()); 2259 if (val >= limit) { 2260 if (i != 0) { 2261 mHaveDebugSettings = true; 2262 } 2263 mAppProcessLimit.setValueIndex(i); 2264 mAppProcessLimit.setSummary(mAppProcessLimit.getEntries()[i]); 2265 return; 2266 } 2267 } 2268 mAppProcessLimit.setValueIndex(0); 2269 mAppProcessLimit.setSummary(mAppProcessLimit.getEntries()[0]); 2270 } catch (RemoteException e) { 2271 } 2272 } 2273 2274 private void writeAppProcessLimitOptions(Object newValue) { 2275 try { 2276 int limit = newValue != null ? Integer.parseInt(newValue.toString()) : -1; 2277 ActivityManager.getService().setProcessLimit(limit); 2278 updateAppProcessLimitOptions(); 2279 } catch (RemoteException e) { 2280 } 2281 } 2282 2283 private void writeShowAllANRsOptions() { 2284 Settings.Secure.putInt(getActivity().getContentResolver(), 2285 Settings.Secure.ANR_SHOW_BACKGROUND, 2286 mShowAllANRs.isChecked() ? 1 : 0); 2287 } 2288 2289 private void updateShowAllANRsOptions() { 2290 updateSwitchPreference(mShowAllANRs, Settings.Secure.getInt( 2291 getActivity().getContentResolver(), Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0); 2292 } 2293 2294 private void writeShowNotificationChannelWarningsOptions() { 2295 Settings.Global.putInt(getActivity().getContentResolver(), 2296 Settings.Global.SHOW_NOTIFICATION_CHANNEL_WARNINGS, 2297 mShowNotificationChannelWarnings.isChecked() ? 1 : 0); 2298 } 2299 2300 private void updateShowNotificationChannelWarningsOptions() { 2301 final int defaultWarningEnabled = Build.IS_DEBUGGABLE ? 1 : 0; 2302 updateSwitchPreference(mShowNotificationChannelWarnings, Settings.Global.getInt( 2303 getActivity().getContentResolver(), 2304 Settings.Global.SHOW_NOTIFICATION_CHANNEL_WARNINGS, defaultWarningEnabled) != 0); 2305 } 2306 2307 private void confirmEnableOemUnlock() { 2308 DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener() { 2309 @Override 2310 public void onClick(DialogInterface dialog, int which) { 2311 if (which == DialogInterface.BUTTON_POSITIVE) { 2312 mOemLockManager.setOemUnlockAllowedByUser(true); 2313 } 2314 } 2315 }; 2316 2317 DialogInterface.OnDismissListener onDismissListener = 2318 new DialogInterface.OnDismissListener() { 2319 @Override 2320 public void onDismiss(DialogInterface dialog) { 2321 if (getActivity() == null) { 2322 return; 2323 } 2324 updateAllOptions(); 2325 } 2326 }; 2327 2328 new AlertDialog.Builder(getActivity()) 2329 .setTitle(R.string.confirm_enable_oem_unlock_title) 2330 .setMessage(R.string.confirm_enable_oem_unlock_text) 2331 .setPositiveButton(R.string.enable_text, onClickListener) 2332 .setNegativeButton(android.R.string.cancel, null) 2333 .setOnDismissListener(onDismissListener) 2334 .create() 2335 .show(); 2336 } 2337 2338 @Override 2339 public void onSwitchChanged(Switch switchView, boolean isChecked) { 2340 if (switchView != mSwitchBar.getSwitch()) { 2341 return; 2342 } 2343 final boolean lastEnabledState = mSettingsEnabler.getLastEnabledState(); 2344 if (isChecked != lastEnabledState) { 2345 if (isChecked) { 2346 mDialogClicked = false; 2347 if (mEnableDialog != null) dismissDialogs(); 2348 mEnableDialog = new AlertDialog.Builder(getActivity()).setMessage( 2349 getActivity().getResources().getString( 2350 R.string.dev_settings_warning_message)) 2351 .setTitle(R.string.dev_settings_warning_title) 2352 .setPositiveButton(android.R.string.yes, this) 2353 .setNegativeButton(android.R.string.no, this) 2354 .show(); 2355 mEnableDialog.setOnDismissListener(this); 2356 } else { 2357 resetDangerousOptions(); 2358 mSettingsEnabler.disableDevelopmentSettings(); 2359 setPrefsEnabledState(false); 2360 } 2361 } 2362 } 2363 2364 @Override 2365 public void onActivityResult(int requestCode, int resultCode, Intent data) { 2366 if (requestCode == RESULT_DEBUG_APP) { 2367 if (resultCode == Activity.RESULT_OK) { 2368 mDebugApp = data.getAction(); 2369 writeDebuggerOptions(); 2370 updateDebuggerOptions(); 2371 } 2372 } else if (requestCode == RESULT_MOCK_LOCATION_APP) { 2373 if (resultCode == Activity.RESULT_OK) { 2374 mMockLocationApp = data.getAction(); 2375 writeMockLocation(); 2376 updateMockLocation(); 2377 } 2378 } else if (requestCode == REQUEST_CODE_ENABLE_OEM_UNLOCK) { 2379 if (resultCode == Activity.RESULT_OK) { 2380 if (mEnableOemUnlock.isChecked()) { 2381 confirmEnableOemUnlock(); 2382 } else { 2383 mOemLockManager.setOemUnlockAllowedByUser(false); 2384 } 2385 } 2386 } else { 2387 super.onActivityResult(requestCode, resultCode, data); 2388 } 2389 } 2390 2391 @Override 2392 public boolean onPreferenceTreeClick(Preference preference) { 2393 if (Utils.isMonkeyRunning()) { 2394 return false; 2395 } 2396 2397 if (mBugReportInPowerController.handlePreferenceTreeClick(preference)) { 2398 return true; 2399 } 2400 2401 if (mTelephonyMonitorController.handlePreferenceTreeClick(preference)) { 2402 return true; 2403 } 2404 2405 if (mWebViewAppPrefController.handlePreferenceTreeClick(preference)) { 2406 return true; 2407 } 2408 2409 if (mVerifyAppsOverUsbController.handlePreferenceTreeClick(preference)) { 2410 return true; 2411 } 2412 2413 if (preference == mEnableAdb) { 2414 if (mEnableAdb.isChecked()) { 2415 mDialogClicked = false; 2416 if (mAdbDialog != null) dismissDialogs(); 2417 mAdbDialog = new AlertDialog.Builder(getActivity()).setMessage( 2418 getActivity().getResources().getString(R.string.adb_warning_message)) 2419 .setTitle(R.string.adb_warning_title) 2420 .setPositiveButton(android.R.string.yes, this) 2421 .setNegativeButton(android.R.string.no, this) 2422 .show(); 2423 mAdbDialog.setOnDismissListener(this); 2424 } else { 2425 Settings.Global.putInt(getActivity().getContentResolver(), 2426 Settings.Global.ADB_ENABLED, 0); 2427 mVerifyAppsOverUsbController.updatePreference(); 2428 updateBugreportOptions(); 2429 } 2430 } else if (preference == mClearAdbKeys) { 2431 if (mAdbKeysDialog != null) dismissDialogs(); 2432 mAdbKeysDialog = new AlertDialog.Builder(getActivity()) 2433 .setMessage(R.string.adb_keys_warning_message) 2434 .setPositiveButton(android.R.string.ok, this) 2435 .setNegativeButton(android.R.string.cancel, null) 2436 .show(); 2437 } else if (preference == mEnableTerminal) { 2438 final PackageManager pm = getActivity().getPackageManager(); 2439 pm.setApplicationEnabledSetting(TERMINAL_APP_PACKAGE, 2440 mEnableTerminal.isChecked() ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED 2441 : PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0); 2442 } else if (preference == mKeepScreenOn) { 2443 Settings.Global.putInt(getActivity().getContentResolver(), 2444 Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 2445 mKeepScreenOn.isChecked() ? 2446 (BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB 2447 | BatteryManager.BATTERY_PLUGGED_WIRELESS) : 0); 2448 } else if (preference == mBtHciSnoopLog) { 2449 writeBtHciSnoopLogOptions(); 2450 } else if (preference == mEnableOemUnlock && mEnableOemUnlock.isEnabled()) { 2451 if (mEnableOemUnlock.isChecked()) { 2452 if (!showKeyguardConfirmation(getResources(), REQUEST_CODE_ENABLE_OEM_UNLOCK)) { 2453 confirmEnableOemUnlock(); 2454 } 2455 } else { 2456 mOemLockManager.setOemUnlockAllowedByUser(false); 2457 } 2458 } else if (preference == mMockLocationAppPref) { 2459 Intent intent = new Intent(getActivity(), AppPicker.class); 2460 intent.putExtra(AppPicker.EXTRA_REQUESTIING_PERMISSION, 2461 Manifest.permission.ACCESS_MOCK_LOCATION); 2462 startActivityForResult(intent, RESULT_MOCK_LOCATION_APP); 2463 } else if (preference == mDebugViewAttributes) { 2464 Settings.Global.putInt(getActivity().getContentResolver(), 2465 Settings.Global.DEBUG_VIEW_ATTRIBUTES, 2466 mDebugViewAttributes.isChecked() ? 1 : 0); 2467 } else if (preference == mForceAllowOnExternal) { 2468 Settings.Global.putInt(getActivity().getContentResolver(), 2469 Settings.Global.FORCE_ALLOW_ON_EXTERNAL, 2470 mForceAllowOnExternal.isChecked() ? 1 : 0); 2471 } else if (preference == mDebugAppPref) { 2472 Intent intent = new Intent(getActivity(), AppPicker.class); 2473 intent.putExtra(AppPicker.EXTRA_DEBUGGABLE, true); 2474 startActivityForResult(intent, RESULT_DEBUG_APP); 2475 } else if (preference == mWaitForDebugger) { 2476 writeDebuggerOptions(); 2477 } else if (preference == mOtaDisableAutomaticUpdate) { 2478 writeOtaDisableAutomaticUpdateOptions(); 2479 } else if (preference == mStrictMode) { 2480 writeStrictModeVisualOptions(); 2481 } else if (preference == mPointerLocation) { 2482 writePointerLocationOptions(); 2483 } else if (preference == mShowTouches) { 2484 writeShowTouchesOptions(); 2485 } else if (preference == mShowScreenUpdates) { 2486 writeShowUpdatesOption(); 2487 } else if (preference == mDisableOverlays) { 2488 writeDisableOverlaysOption(); 2489 } else if (preference == mImmediatelyDestroyActivities) { 2490 writeImmediatelyDestroyActivitiesOptions(); 2491 } else if (preference == mShowAllANRs) { 2492 writeShowAllANRsOptions(); 2493 } else if (preference == mShowNotificationChannelWarnings) { 2494 writeShowNotificationChannelWarningsOptions(); 2495 } else if (preference == mForceHardwareUi) { 2496 writeHardwareUiOptions(); 2497 } else if (preference == mForceMsaa) { 2498 writeMsaaOptions(); 2499 } else if (preference == mShowHwScreenUpdates) { 2500 writeShowHwScreenUpdatesOptions(); 2501 } else if (preference == mShowHwLayersUpdates) { 2502 writeShowHwLayersUpdatesOptions(); 2503 } else if (preference == mDebugLayout) { 2504 writeDebugLayoutOptions(); 2505 } else if (preference == mForceRtlLayout) { 2506 writeForceRtlOptions(); 2507 } else if (preference == mWifiDisplayCertification) { 2508 writeWifiDisplayCertificationOptions(); 2509 } else if (preference == mWifiVerboseLogging) { 2510 writeWifiVerboseLoggingOptions(); 2511 } else if (preference == mWifiAggressiveHandover) { 2512 writeWifiAggressiveHandoverOptions(); 2513 } else if (preference == mWifiAllowScansWithTraffic) { 2514 writeWifiAllowScansWithTrafficOptions(); 2515 } else if (preference == mMobileDataAlwaysOn) { 2516 writeMobileDataAlwaysOnOptions(); 2517 } else if (preference == mTetheringHardwareOffload) { 2518 writeTetheringHardwareOffloadOptions(); 2519 } else if (preference == mColorTemperaturePreference) { 2520 writeColorTemperature(); 2521 } else if (preference == mUSBAudio) { 2522 writeUSBAudioOptions(); 2523 } else if (preference == mForceResizable) { 2524 writeForceResizableOptions(); 2525 } else if (preference == mBluetoothDisableAbsVolume) { 2526 writeBluetoothDisableAbsVolumeOptions(); 2527 } else if (preference == mBluetoothEnableInbandRinging) { 2528 writeBluetoothEnableInbandRingingOptions(); 2529 } else if (SHORTCUT_MANAGER_RESET_KEY.equals(preference.getKey())) { 2530 resetShortcutManagerThrottling(); 2531 } else { 2532 return super.onPreferenceTreeClick(preference); 2533 } 2534 2535 return false; 2536 } 2537 2538 private boolean showKeyguardConfirmation(Resources resources, int requestCode) { 2539 return new ChooseLockSettingsHelper(getActivity(), this).launchConfirmationActivity( 2540 requestCode, resources.getString(R.string.oem_unlock_enable)); 2541 } 2542 2543 @Override 2544 public boolean onPreferenceChange(Preference preference, Object newValue) { 2545 if (HDCP_CHECKING_KEY.equals(preference.getKey())) { 2546 SystemProperties.set(HDCP_CHECKING_PROPERTY, newValue.toString()); 2547 updateHdcpValues(); 2548 pokeSystemProperties(); 2549 return true; 2550 } else if (preference == mBluetoothSelectAvrcpVersion) { 2551 writeBluetoothAvrcpVersion(newValue); 2552 return true; 2553 } else if ((preference == mBluetoothSelectA2dpCodec) || 2554 (preference == mBluetoothSelectA2dpSampleRate) || 2555 (preference == mBluetoothSelectA2dpBitsPerSample) || 2556 (preference == mBluetoothSelectA2dpChannelMode) || 2557 (preference == mBluetoothSelectA2dpLdacPlaybackQuality)) { 2558 writeBluetoothConfigurationOption(preference, newValue); 2559 return true; 2560 } else if (preference == mLogdSize) { 2561 writeLogdSizeOption(newValue); 2562 return true; 2563 } else if (preference == mLogpersist) { 2564 writeLogpersistOption(newValue, false); 2565 return true; 2566 } else if (preference == mUsbConfiguration) { 2567 writeUsbConfigurationOption(newValue); 2568 return true; 2569 } else if (preference == mWindowAnimationScale) { 2570 writeAnimationScaleOption(0, mWindowAnimationScale, newValue); 2571 return true; 2572 } else if (preference == mTransitionAnimationScale) { 2573 writeAnimationScaleOption(1, mTransitionAnimationScale, newValue); 2574 return true; 2575 } else if (preference == mAnimatorDurationScale) { 2576 writeAnimationScaleOption(2, mAnimatorDurationScale, newValue); 2577 return true; 2578 } else if (preference == mOverlayDisplayDevices) { 2579 writeOverlayDisplayDevicesOptions(newValue); 2580 return true; 2581 } else if (preference == mTrackFrameTime) { 2582 writeTrackFrameTimeOptions(newValue); 2583 return true; 2584 } else if (preference == mDebugHwOverdraw) { 2585 writeDebugHwOverdrawOptions(newValue); 2586 return true; 2587 } else if (preference == mDebugHwRenderer) { 2588 writeDebugHwRendererOptions(newValue); 2589 return true; 2590 } else if (preference == mShowNonRectClip) { 2591 writeShowNonRectClipOptions(newValue); 2592 return true; 2593 } else if (preference == mAppProcessLimit) { 2594 writeAppProcessLimitOptions(newValue); 2595 return true; 2596 } else if (preference == mSimulateColorSpace) { 2597 writeSimulateColorSpace(newValue); 2598 return true; 2599 } 2600 return false; 2601 } 2602 2603 private void dismissDialogs() { 2604 if (mAdbDialog != null) { 2605 mAdbDialog.dismiss(); 2606 mAdbDialog = null; 2607 } 2608 if (mAdbKeysDialog != null) { 2609 mAdbKeysDialog.dismiss(); 2610 mAdbKeysDialog = null; 2611 } 2612 if (mEnableDialog != null) { 2613 mEnableDialog.dismiss(); 2614 mEnableDialog = null; 2615 } 2616 if (mLogpersistClearDialog != null) { 2617 mLogpersistClearDialog.dismiss(); 2618 mLogpersistClearDialog = null; 2619 } 2620 } 2621 2622 public void onClick(DialogInterface dialog, int which) { 2623 if (dialog == mAdbDialog) { 2624 if (which == DialogInterface.BUTTON_POSITIVE) { 2625 mDialogClicked = true; 2626 Settings.Global.putInt(getActivity().getContentResolver(), 2627 Settings.Global.ADB_ENABLED, 1); 2628 mVerifyAppsOverUsbController.updatePreference(); 2629 updateBugreportOptions(); 2630 } else { 2631 // Reset the toggle 2632 mEnableAdb.setChecked(false); 2633 } 2634 } else if (dialog == mAdbKeysDialog) { 2635 if (which == DialogInterface.BUTTON_POSITIVE) { 2636 try { 2637 IBinder b = ServiceManager.getService(Context.USB_SERVICE); 2638 IUsbManager service = IUsbManager.Stub.asInterface(b); 2639 service.clearUsbDebuggingKeys(); 2640 } catch (RemoteException e) { 2641 Log.e(TAG, "Unable to clear adb keys", e); 2642 } 2643 } 2644 } else if (dialog == mEnableDialog) { 2645 if (which == DialogInterface.BUTTON_POSITIVE) { 2646 mDialogClicked = true; 2647 mSettingsEnabler.enableDevelopmentSettings(); 2648 setPrefsEnabledState(true); 2649 } else { 2650 // Reset the toggle 2651 mSwitchBar.setChecked(false); 2652 } 2653 } else if (dialog == mLogpersistClearDialog) { 2654 if (which == DialogInterface.BUTTON_POSITIVE) { 2655 setLogpersistOff(true); 2656 } else { 2657 updateLogpersistValues(); 2658 } 2659 } 2660 } 2661 2662 public void onDismiss(DialogInterface dialog) { 2663 // Assuming that onClick gets called first 2664 if (dialog == mAdbDialog) { 2665 if (!mDialogClicked) { 2666 mEnableAdb.setChecked(false); 2667 } 2668 mAdbDialog = null; 2669 } else if (dialog == mEnableDialog) { 2670 if (!mDialogClicked) { 2671 mSwitchBar.setChecked(false); 2672 } 2673 mEnableDialog = null; 2674 } else if (dialog == mLogpersistClearDialog) { 2675 mLogpersistClearDialog = null; 2676 } 2677 } 2678 2679 @Override 2680 public void onDestroy() { 2681 dismissDialogs(); 2682 super.onDestroy(); 2683 } 2684 2685 void pokeSystemProperties() { 2686 if (!mDontPokeProperties) { 2687 //noinspection unchecked 2688 (new SystemPropPoker()).execute(); 2689 } 2690 } 2691 2692 private BroadcastReceiver mUsbReceiver = new BroadcastReceiver() { 2693 @Override 2694 public void onReceive(Context context, Intent intent) { 2695 updateUsbConfigurationValues(); 2696 } 2697 }; 2698 2699 private BroadcastReceiver mBluetoothA2dpReceiver = new BroadcastReceiver() { 2700 @Override 2701 public void onReceive(Context context, Intent intent) { 2702 Log.d(TAG, "mBluetoothA2dpReceiver.onReceive intent=" + intent); 2703 String action = intent.getAction(); 2704 2705 if (BluetoothA2dp.ACTION_CODEC_CONFIG_CHANGED.equals(action)) { 2706 BluetoothCodecStatus codecStatus = 2707 (BluetoothCodecStatus)intent.getParcelableExtra(BluetoothCodecStatus.EXTRA_CODEC_STATUS); 2708 Log.d(TAG, "Received BluetoothCodecStatus=" + codecStatus); 2709 updateBluetoothA2dpConfigurationValues(); 2710 } 2711 } 2712 }; 2713 2714 private BluetoothProfile.ServiceListener mBluetoothA2dpServiceListener = 2715 new BluetoothProfile.ServiceListener() { 2716 public void onServiceConnected(int profile, 2717 BluetoothProfile proxy) { 2718 synchronized (mBluetoothA2dpLock) { 2719 mBluetoothA2dp = (BluetoothA2dp) proxy; 2720 } 2721 updateBluetoothA2dpConfigurationValues(); 2722 } 2723 2724 public void onServiceDisconnected(int profile) { 2725 synchronized (mBluetoothA2dpLock) { 2726 mBluetoothA2dp = null; 2727 } 2728 updateBluetoothA2dpConfigurationValues(); 2729 } 2730 }; 2731 2732 public static class SystemPropPoker extends AsyncTask<Void, Void, Void> { 2733 @Override 2734 protected Void doInBackground(Void... params) { 2735 String[] services = ServiceManager.listServices(); 2736 for (String service : services) { 2737 IBinder obj = ServiceManager.checkService(service); 2738 if (obj != null) { 2739 Parcel data = Parcel.obtain(); 2740 try { 2741 obj.transact(IBinder.SYSPROPS_TRANSACTION, data, null, 0); 2742 } catch (RemoteException e) { 2743 } catch (Exception e) { 2744 Log.i(TAG, "Someone wrote a bad service '" + service 2745 + "' that doesn't like to be poked: " + e); 2746 } 2747 data.recycle(); 2748 } 2749 } 2750 return null; 2751 } 2752 } 2753 2754 private static boolean isPackageInstalled(Context context, String packageName) { 2755 try { 2756 return context.getPackageManager().getPackageInfo(packageName, 0) != null; 2757 } catch (NameNotFoundException e) { 2758 return false; 2759 } 2760 } 2761 2762 2763 /** 2764 * For Search. 2765 */ 2766 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 2767 new BaseSearchIndexProvider() { 2768 2769 @Override 2770 protected boolean isPageSearchEnabled(Context context) { 2771 return context.getSharedPreferences(DevelopmentSettings.PREF_FILE, 2772 Context.MODE_PRIVATE).getBoolean( 2773 DevelopmentSettings.PREF_SHOW, 2774 android.os.Build.TYPE.equals("eng")); 2775 } 2776 2777 @Override 2778 public List<SearchIndexableResource> getXmlResourcesToIndex( 2779 Context context, boolean enabled) { 2780 2781 final SearchIndexableResource sir = new SearchIndexableResource(context); 2782 sir.xmlResId = R.xml.development_prefs; 2783 return Arrays.asList(sir); 2784 } 2785 2786 @Override 2787 public List<String> getNonIndexableKeys(Context context) { 2788 final List<String> keys = super.getNonIndexableKeys(context); 2789 2790 if (!showEnableOemUnlockPreference(context)) { 2791 keys.add(ENABLE_OEM_UNLOCK); 2792 } 2793 return keys; 2794 } 2795 }; 2796 2797 private void resetShortcutManagerThrottling() { 2798 final IShortcutService service = IShortcutService.Stub.asInterface( 2799 ServiceManager.getService(Context.SHORTCUT_SERVICE)); 2800 if (service != null) { 2801 try { 2802 service.resetThrottling(); 2803 Toast.makeText(getActivity(), R.string.reset_shortcut_manager_throttling_complete, 2804 Toast.LENGTH_SHORT).show(); 2805 } catch (RemoteException e) { 2806 Log.e(TAG, "Failed to reset rate limiting", e); 2807 } 2808 } 2809 } 2810 2811 private void updateOemUnlockSettingDescription() { 2812 if (mEnableOemUnlock != null) { 2813 int oemUnlockSummary = R.string.oem_unlock_enable_summary; 2814 if (isBootloaderUnlocked()) { 2815 oemUnlockSummary = R.string.oem_unlock_enable_disabled_summary_bootloader_unlocked; 2816 } else if (isSimLockedDevice()) { 2817 oemUnlockSummary = R.string.oem_unlock_enable_disabled_summary_sim_locked_device; 2818 } else if (!mOemLockManager.canUserAllowOemUnlock()) { 2819 // If the device isn't SIM-locked but OEM unlock is disallowed by some party, this 2820 // means either some other carrier restriction is in place or the device hasn't been 2821 // able to confirm which restrictions (SIM-lock or otherwise) apply. 2822 oemUnlockSummary = 2823 R.string.oem_unlock_enable_disabled_summary_connectivity_or_locked; 2824 } 2825 mEnableOemUnlock.setSummary(getString(oemUnlockSummary)); 2826 } 2827 } 2828 2829 /** Returns {@code true} if the device is SIM-locked. Otherwise, returns {@code false}. */ 2830 private boolean isSimLockedDevice() { 2831 int phoneCount = mTelephonyManager.getPhoneCount(); 2832 for (int i = 0; i < phoneCount; i++) { 2833 if (mTelephonyManager.getAllowedCarriers(i).size() > 0) { 2834 return true; 2835 } 2836 } 2837 return false; 2838 } 2839 2840 /** 2841 * Returns {@code true} if the bootloader has been unlocked. Otherwise, returns {code false}. 2842 */ 2843 private boolean isBootloaderUnlocked() { 2844 return mOemLockManager.isDeviceOemUnlocked(); 2845 } 2846 2847 2848} 2849