/src/com/android/settings/DevelopmentSettings.java

http://github.com/CyanogenMod/android_packages_apps_Settings · Java · 2601 lines · 2238 code · 260 blank · 103 comment · 599 complexity · 59c4468fa987a0c2594cdf4158f8326d MD5 · raw file

Large files are truncated click here to view the full file

  1. /*
  2. * Copyright (C) 2008 The Android Open Source Project
  3. * Copyright (C) 2013-2014 The CyanogenMod Project
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package com.android.settings;
  18. import android.Manifest;
  19. import android.app.Activity;
  20. import android.app.ActivityManagerNative;
  21. import android.app.AlertDialog;
  22. import android.app.AppOpsManager;
  23. import android.app.AppOpsManager.PackageOps;
  24. import android.app.Dialog;
  25. import android.app.admin.DevicePolicyManager;
  26. import android.app.backup.IBackupManager;
  27. import android.bluetooth.BluetoothAdapter;
  28. import android.content.BroadcastReceiver;
  29. import android.content.ComponentName;
  30. import android.content.ContentResolver;
  31. import android.content.Context;
  32. import android.content.DialogInterface;
  33. import android.content.Intent;
  34. import android.content.IntentFilter;
  35. import android.content.pm.ApplicationInfo;
  36. import android.content.pm.IShortcutService;
  37. import android.content.pm.PackageManager;
  38. import android.content.pm.PackageManager.NameNotFoundException;
  39. import android.content.pm.ResolveInfo;
  40. import android.content.res.Resources;
  41. import android.net.NetworkUtils;
  42. import android.net.wifi.IWifiManager;
  43. import android.net.wifi.WifiInfo;
  44. import android.hardware.usb.IUsbManager;
  45. import android.hardware.usb.UsbManager;
  46. import android.net.wifi.WifiManager;
  47. import android.os.AsyncTask;
  48. import android.os.BatteryManager;
  49. import android.os.Build;
  50. import android.os.Bundle;
  51. import android.os.IBinder;
  52. import android.os.Parcel;
  53. import android.os.RemoteException;
  54. import android.os.ServiceManager;
  55. import android.os.StrictMode;
  56. import android.os.SystemProperties;
  57. import android.os.UserHandle;
  58. import android.os.UserManager;
  59. import android.os.storage.IMountService;
  60. import android.provider.SearchIndexableResource;
  61. import android.provider.Settings;
  62. import android.service.persistentdata.PersistentDataBlockManager;
  63. import android.support.v14.preference.SwitchPreference;
  64. import android.support.v7.preference.ListPreference;
  65. import android.support.v7.preference.Preference;
  66. import android.support.v7.preference.Preference.OnPreferenceChangeListener;
  67. import android.support.v7.preference.Preference.OnPreferenceClickListener;
  68. import android.support.v7.preference.PreferenceGroup;
  69. import android.support.v7.preference.PreferenceScreen;
  70. import android.telephony.TelephonyManager;
  71. import android.text.TextUtils;
  72. import android.util.Log;
  73. import android.view.IWindowManager;
  74. import android.view.LayoutInflater;
  75. import android.view.ThreadedRenderer;
  76. import android.view.View;
  77. import android.view.ViewGroup;
  78. import android.view.accessibility.AccessibilityManager;
  79. import android.webkit.IWebViewUpdateService;
  80. import android.webkit.WebViewProviderInfo;
  81. import android.widget.Switch;
  82. import android.widget.Toast;
  83. import com.android.internal.app.LocalePicker;
  84. import com.android.internal.logging.MetricsProto.MetricsEvent;
  85. import com.android.settings.Settings.AppOpsSummaryActivity;
  86. import com.android.settings.applications.BackgroundCheckSummary;
  87. import com.android.settings.fuelgauge.InactiveApps;
  88. import com.android.settings.search.BaseSearchIndexProvider;
  89. import com.android.settings.search.Indexable;
  90. import com.android.settings.widget.SwitchBar;
  91. import com.android.settingslib.RestrictedLockUtils;
  92. import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
  93. import com.android.settingslib.RestrictedSwitchPreference;
  94. import cyanogenmod.providers.CMSettings;
  95. import java.util.ArrayList;
  96. import java.util.Arrays;
  97. import java.util.HashSet;
  98. import java.util.List;
  99. /*
  100. * Displays preferences for application developers.
  101. */
  102. public class DevelopmentSettings extends RestrictedSettingsFragment
  103. implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener,
  104. OnPreferenceChangeListener, SwitchBar.OnSwitchChangeListener, Indexable,
  105. OnPreferenceClickListener {
  106. private static final String TAG = "DevelopmentSettings";
  107. /**
  108. * Preference file were development settings prefs are stored.
  109. */
  110. public static final String PREF_FILE = "development";
  111. /**
  112. * Whether to show the development settings to the user. Default is false.
  113. */
  114. public static final String PREF_SHOW = "show";
  115. private static final String ENABLE_ADB = "enable_adb";
  116. private static final String ADB_TCPIP = "adb_over_network";
  117. private static final String CLEAR_ADB_KEYS = "clear_adb_keys";
  118. private static final String ENABLE_TERMINAL = "enable_terminal";
  119. private static final String KEEP_SCREEN_ON = "keep_screen_on";
  120. private static final String BT_HCI_SNOOP_LOG = "bt_hci_snoop_log";
  121. private static final String WEBVIEW_PROVIDER_KEY = "select_webview_provider";
  122. private static final String WEBVIEW_MULTIPROCESS_KEY = "enable_webview_multiprocess";
  123. private static final String ENABLE_OEM_UNLOCK = "oem_unlock_enable";
  124. private static final String HDCP_CHECKING_KEY = "hdcp_checking";
  125. private static final String HDCP_CHECKING_PROPERTY = "persist.sys.hdcp_checking";
  126. private static final String LOCAL_BACKUP_PASSWORD = "local_backup_password";
  127. private static final String HARDWARE_UI_PROPERTY = "persist.sys.ui.hw";
  128. private static final String MSAA_PROPERTY = "debug.egl.force_msaa";
  129. private static final String BUGREPORT = "bugreport";
  130. private static final String BUGREPORT_IN_POWER_KEY = "bugreport_in_power";
  131. private static final String OPENGL_TRACES_PROPERTY = "debug.egl.trace";
  132. private static final String TUNER_UI_KEY = "tuner_ui";
  133. private static final String COLOR_TEMPERATURE_PROPERTY = "persist.sys.debug.color_temp";
  134. private static final String DEBUG_APP_KEY = "debug_app";
  135. private static final String WAIT_FOR_DEBUGGER_KEY = "wait_for_debugger";
  136. private static final String MOCK_LOCATION_APP_KEY = "mock_location_app";
  137. private static final String VERIFY_APPS_OVER_USB_KEY = "verify_apps_over_usb";
  138. private static final String DEBUG_VIEW_ATTRIBUTES = "debug_view_attributes";
  139. private static final String FORCE_ALLOW_ON_EXTERNAL_KEY = "force_allow_on_external";
  140. private static final String STRICT_MODE_KEY = "strict_mode";
  141. private static final String POINTER_LOCATION_KEY = "pointer_location";
  142. private static final String SHOW_TOUCHES_KEY = "show_touches";
  143. private static final String SHOW_SCREEN_UPDATES_KEY = "show_screen_updates";
  144. private static final String DISABLE_OVERLAYS_KEY = "disable_overlays";
  145. private static final String SIMULATE_COLOR_SPACE = "simulate_color_space";
  146. private static final String USB_AUDIO_KEY = "usb_audio";
  147. private static final String FORCE_HARDWARE_UI_KEY = "force_hw_ui";
  148. private static final String FORCE_MSAA_KEY = "force_msaa";
  149. private static final String TRACK_FRAME_TIME_KEY = "track_frame_time";
  150. private static final String SHOW_NON_RECTANGULAR_CLIP_KEY = "show_non_rect_clip";
  151. private static final String SHOW_HW_SCREEN_UPDATES_KEY = "show_hw_screen_udpates";
  152. private static final String SHOW_HW_LAYERS_UPDATES_KEY = "show_hw_layers_udpates";
  153. private static final String DEBUG_HW_OVERDRAW_KEY = "debug_hw_overdraw";
  154. private static final String DEBUG_LAYOUT_KEY = "debug_layout";
  155. private static final String FORCE_RTL_LAYOUT_KEY = "force_rtl_layout_all_locales";
  156. private static final String WINDOW_ANIMATION_SCALE_KEY = "window_animation_scale";
  157. private static final String TRANSITION_ANIMATION_SCALE_KEY = "transition_animation_scale";
  158. private static final String ANIMATOR_DURATION_SCALE_KEY = "animator_duration_scale";
  159. private static final String OVERLAY_DISPLAY_DEVICES_KEY = "overlay_display_devices";
  160. private static final String DEBUG_DEBUGGING_CATEGORY_KEY = "debug_debugging_category";
  161. private static final String SELECT_LOGD_SIZE_KEY = "select_logd_size";
  162. private static final String SELECT_LOGD_SIZE_PROPERTY = "persist.logd.size";
  163. private static final String SELECT_LOGD_TAG_PROPERTY = "persist.log.tag";
  164. // Tricky, isLoggable only checks for first character, assumes silence
  165. private static final String SELECT_LOGD_TAG_SILENCE = "Settings";
  166. private static final String SELECT_LOGD_SNET_TAG_PROPERTY = "persist.log.tag.snet_event_log";
  167. private static final String SELECT_LOGD_RUNTIME_SNET_TAG_PROPERTY = "log.tag.snet_event_log";
  168. private static final String SELECT_LOGD_DEFAULT_SIZE_PROPERTY = "ro.logd.size";
  169. private static final String SELECT_LOGD_DEFAULT_SIZE_VALUE = "262144";
  170. private static final String SELECT_LOGD_SVELTE_DEFAULT_SIZE_VALUE = "65536";
  171. // 32768 is merely a menu marker, 64K is our lowest log buffer size we replace it with.
  172. private static final String SELECT_LOGD_MINIMUM_SIZE_VALUE = "65536";
  173. private static final String SELECT_LOGD_OFF_SIZE_MARKER_VALUE = "32768";
  174. private static final String SELECT_LOGPERSIST_KEY = "select_logpersist";
  175. private static final String SELECT_LOGPERSIST_PROPERTY = "persist.logd.logpersistd";
  176. private static final String ACTUAL_LOGPERSIST_PROPERTY = "logd.logpersistd";
  177. private static final String SELECT_LOGPERSIST_PROPERTY_SERVICE = "logcatd";
  178. private static final String SELECT_LOGPERSIST_PROPERTY_CLEAR = "clear";
  179. private static final String SELECT_LOGPERSIST_PROPERTY_STOP = "stop";
  180. private static final String SELECT_LOGPERSIST_PROPERTY_BUFFER = "persist.logd.logpersistd.buffer";
  181. private static final String ACTUAL_LOGPERSIST_PROPERTY_BUFFER = "logd.logpersistd.buffer";
  182. private static final String ACTUAL_LOGPERSIST_PROPERTY_ENABLE = "logd.logpersistd.enable";
  183. private static final String WIFI_DISPLAY_CERTIFICATION_KEY = "wifi_display_certification";
  184. private static final String WIFI_VERBOSE_LOGGING_KEY = "wifi_verbose_logging";
  185. private static final String WIFI_AGGRESSIVE_HANDOVER_KEY = "wifi_aggressive_handover";
  186. private static final String WIFI_ALLOW_SCAN_WITH_TRAFFIC_KEY = "wifi_allow_scan_with_traffic";
  187. private static final String USB_CONFIGURATION_KEY = "select_usb_configuration";
  188. private static final String MOBILE_DATA_ALWAYS_ON = "mobile_data_always_on";
  189. private static final String KEY_COLOR_MODE = "color_mode";
  190. private static final String FORCE_RESIZABLE_KEY = "force_resizable_activities";
  191. private static final String COLOR_TEMPERATURE_KEY = "color_temperature";
  192. private static final String BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_KEY =
  193. "bluetooth_disable_absolute_volume";
  194. private static final String BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_PROPERTY =
  195. "persist.bluetooth.disableabsvol";
  196. private static final String INACTIVE_APPS_KEY = "inactive_apps";
  197. private static final String ROOT_ACCESS_KEY = "root_access";
  198. private static final String ROOT_ACCESS_PROPERTY = "persist.sys.root_access";
  199. private static final String ROOT_APPOPS_KEY = "root_appops";
  200. private static final String IMMEDIATELY_DESTROY_ACTIVITIES_KEY
  201. = "immediately_destroy_activities";
  202. private static final String APP_PROCESS_LIMIT_KEY = "app_process_limit";
  203. private static final String BACKGROUND_CHECK_KEY = "background_check";
  204. private static final String SHOW_ALL_ANRS_KEY = "show_all_anrs";
  205. private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive";
  206. private static final String TERMINAL_APP_PACKAGE = "com.android.terminal";
  207. private static final String KEY_CONVERT_FBE = "convert_to_file_encryption";
  208. private static final String OTA_DISABLE_AUTOMATIC_UPDATE_KEY = "ota_disable_automatic_update";
  209. private static final String DEVELOPMENT_TOOLS = "development_tools";
  210. private static final int RESULT_DEBUG_APP = 1000;
  211. private static final int RESULT_MOCK_LOCATION_APP = 1001;
  212. private static final String PERSISTENT_DATA_BLOCK_PROP = "ro.frp.pst";
  213. private static final String FLASH_LOCKED_PROP = "ro.boot.flash.locked";
  214. private static final String SHORTCUT_MANAGER_RESET_KEY = "reset_shortcut_manager_throttling";
  215. private static final int REQUEST_CODE_ENABLE_OEM_UNLOCK = 0;
  216. private static final int[] MOCK_LOCATION_APP_OPS = new int[] {AppOpsManager.OP_MOCK_LOCATION};
  217. private IWindowManager mWindowManager;
  218. private IBackupManager mBackupManager;
  219. private IWebViewUpdateService mWebViewUpdateService;
  220. private DevicePolicyManager mDpm;
  221. private UserManager mUm;
  222. private WifiManager mWifiManager;
  223. private PersistentDataBlockManager mOemUnlockManager;
  224. private TelephonyManager mTelephonyManager;
  225. private SwitchBar mSwitchBar;
  226. private boolean mLastEnabledState;
  227. private boolean mHaveDebugSettings;
  228. private boolean mDontPokeProperties;
  229. private SwitchPreference mEnableAdb;
  230. private SwitchPreference mAdbOverNetwork;
  231. private Preference mClearAdbKeys;
  232. private SwitchPreference mEnableTerminal;
  233. private Preference mBugreport;
  234. private SwitchPreference mBugreportInPower;
  235. private RestrictedSwitchPreference mKeepScreenOn;
  236. private SwitchPreference mBtHciSnoopLog;
  237. private RestrictedSwitchPreference mEnableOemUnlock;
  238. private SwitchPreference mDebugViewAttributes;
  239. private SwitchPreference mForceAllowOnExternal;
  240. private PreferenceScreen mPassword;
  241. private String mDebugApp;
  242. private Preference mDebugAppPref;
  243. private String mMockLocationApp;
  244. private Preference mMockLocationAppPref;
  245. private SwitchPreference mWaitForDebugger;
  246. private SwitchPreference mVerifyAppsOverUsb;
  247. private SwitchPreference mWifiDisplayCertification;
  248. private SwitchPreference mWifiVerboseLogging;
  249. private SwitchPreference mWifiAggressiveHandover;
  250. private SwitchPreference mMobileDataAlwaysOn;
  251. private SwitchPreference mBluetoothDisableAbsVolume;
  252. private SwitchPreference mOtaDisableAutomaticUpdate;
  253. private SwitchPreference mWifiAllowScansWithTraffic;
  254. private SwitchPreference mStrictMode;
  255. private SwitchPreference mPointerLocation;
  256. private SwitchPreference mShowTouches;
  257. private SwitchPreference mShowScreenUpdates;
  258. private SwitchPreference mDisableOverlays;
  259. private SwitchPreference mForceHardwareUi;
  260. private SwitchPreference mForceMsaa;
  261. private SwitchPreference mShowHwScreenUpdates;
  262. private SwitchPreference mShowHwLayersUpdates;
  263. private SwitchPreference mDebugLayout;
  264. private SwitchPreference mForceRtlLayout;
  265. private ListPreference mDebugHwOverdraw;
  266. private ListPreference mLogdSize;
  267. private ListPreference mLogpersist;
  268. private ListPreference mUsbConfiguration;
  269. private ListPreference mTrackFrameTime;
  270. private ListPreference mShowNonRectClip;
  271. private ListPreference mWindowAnimationScale;
  272. private ListPreference mTransitionAnimationScale;
  273. private ListPreference mAnimatorDurationScale;
  274. private ListPreference mOverlayDisplayDevices;
  275. private SwitchPreference mWebViewMultiprocess;
  276. private ListPreference mWebViewProvider;
  277. private ListPreference mSimulateColorSpace;
  278. private SwitchPreference mUSBAudio;
  279. private SwitchPreference mImmediatelyDestroyActivities;
  280. private ListPreference mAppProcessLimit;
  281. private SwitchPreference mShowAllANRs;
  282. private ColorModePreference mColorModePreference;
  283. private Preference mRootAppops;
  284. private SwitchPreference mForceResizable;
  285. private SwitchPreference mColorTemperaturePreference;
  286. private ListPreference mRootAccess;
  287. private Object mSelectedRootValue;
  288. private PreferenceScreen mDevelopmentTools;
  289. private final ArrayList<Preference> mAllPrefs = new ArrayList<Preference>();
  290. private final ArrayList<SwitchPreference> mResetSwitchPrefs
  291. = new ArrayList<SwitchPreference>();
  292. private final HashSet<Preference> mDisabledPrefs = new HashSet<Preference>();
  293. // To track whether a confirmation dialog was clicked.
  294. private boolean mDialogClicked;
  295. private Dialog mEnableDialog;
  296. private Dialog mAdbDialog;
  297. private Dialog mAdbTcpDialog;
  298. private Dialog mAdbKeysDialog;
  299. private boolean mUnavailable;
  300. private Dialog mRootDialog;
  301. private boolean mLogpersistCleared;
  302. private Dialog mLogpersistClearDialog;
  303. public DevelopmentSettings() {
  304. super(UserManager.DISALLOW_DEBUGGING_FEATURES);
  305. }
  306. @Override
  307. protected int getMetricsCategory() {
  308. return MetricsEvent.DEVELOPMENT;
  309. }
  310. @Override
  311. public void onCreate(Bundle icicle) {
  312. super.onCreate(icicle);
  313. mWindowManager = IWindowManager.Stub.asInterface(ServiceManager.getService("window"));
  314. mBackupManager = IBackupManager.Stub.asInterface(
  315. ServiceManager.getService(Context.BACKUP_SERVICE));
  316. mWebViewUpdateService =
  317. IWebViewUpdateService.Stub.asInterface(ServiceManager.getService("webviewupdate"));
  318. mOemUnlockManager = (PersistentDataBlockManager)getActivity()
  319. .getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
  320. mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
  321. mDpm = (DevicePolicyManager)getActivity().getSystemService(Context.DEVICE_POLICY_SERVICE);
  322. mUm = (UserManager) getSystemService(Context.USER_SERVICE);
  323. mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
  324. setIfOnlyAvailableForAdmins(true);
  325. if (isUiRestricted() || !Utils.isDeviceProvisioned(getActivity())) {
  326. // Block access to developer options if the user is not the owner, if user policy
  327. // restricts it, or if the device has not been provisioned
  328. mUnavailable = true;
  329. setPreferenceScreen(new PreferenceScreen(getPrefContext(), null));
  330. return;
  331. }
  332. addPreferencesFromResource(R.xml.development_prefs);
  333. final PreferenceGroup debugDebuggingCategory = (PreferenceGroup)
  334. findPreference(DEBUG_DEBUGGING_CATEGORY_KEY);
  335. mEnableAdb = findAndInitSwitchPref(ENABLE_ADB);
  336. mAdbOverNetwork = findAndInitSwitchPref(ADB_TCPIP);
  337. mClearAdbKeys = findPreference(CLEAR_ADB_KEYS);
  338. if (!SystemProperties.getBoolean("ro.adb.secure", false)) {
  339. if (debugDebuggingCategory != null) {
  340. debugDebuggingCategory.removePreference(mClearAdbKeys);
  341. }
  342. }
  343. mAllPrefs.add(mClearAdbKeys);
  344. mEnableTerminal = findAndInitSwitchPref(ENABLE_TERMINAL);
  345. if (!isPackageInstalled(getActivity(), TERMINAL_APP_PACKAGE)) {
  346. debugDebuggingCategory.removePreference(mEnableTerminal);
  347. mEnableTerminal = null;
  348. }
  349. mBugreport = findPreference(BUGREPORT);
  350. mBugreportInPower = findAndInitSwitchPref(BUGREPORT_IN_POWER_KEY);
  351. mKeepScreenOn = (RestrictedSwitchPreference) findAndInitSwitchPref(KEEP_SCREEN_ON);
  352. mBtHciSnoopLog = findAndInitSwitchPref(BT_HCI_SNOOP_LOG);
  353. mEnableOemUnlock = (RestrictedSwitchPreference) findAndInitSwitchPref(ENABLE_OEM_UNLOCK);
  354. if (!showEnableOemUnlockPreference()) {
  355. removePreference(mEnableOemUnlock);
  356. mEnableOemUnlock = null;
  357. }
  358. mDebugViewAttributes = findAndInitSwitchPref(DEBUG_VIEW_ATTRIBUTES);
  359. mForceAllowOnExternal = findAndInitSwitchPref(FORCE_ALLOW_ON_EXTERNAL_KEY);
  360. mPassword = (PreferenceScreen) findPreference(LOCAL_BACKUP_PASSWORD);
  361. mAllPrefs.add(mPassword);
  362. if (!mUm.isAdminUser()) {
  363. disableForUser(mEnableAdb);
  364. disableForUser(mClearAdbKeys);
  365. disableForUser(mEnableTerminal);
  366. disableForUser(mPassword);
  367. }
  368. mDebugAppPref = findPreference(DEBUG_APP_KEY);
  369. mAllPrefs.add(mDebugAppPref);
  370. mWaitForDebugger = findAndInitSwitchPref(WAIT_FOR_DEBUGGER_KEY);
  371. mMockLocationAppPref = findPreference(MOCK_LOCATION_APP_KEY);
  372. mAllPrefs.add(mMockLocationAppPref);
  373. mVerifyAppsOverUsb = findAndInitSwitchPref(VERIFY_APPS_OVER_USB_KEY);
  374. if (!showVerifierSetting()) {
  375. if (debugDebuggingCategory != null) {
  376. debugDebuggingCategory.removePreference(mVerifyAppsOverUsb);
  377. } else {
  378. mVerifyAppsOverUsb.setEnabled(false);
  379. }
  380. }
  381. mStrictMode = findAndInitSwitchPref(STRICT_MODE_KEY);
  382. mPointerLocation = findAndInitSwitchPref(POINTER_LOCATION_KEY);
  383. mShowTouches = findAndInitSwitchPref(SHOW_TOUCHES_KEY);
  384. mShowScreenUpdates = findAndInitSwitchPref(SHOW_SCREEN_UPDATES_KEY);
  385. mDisableOverlays = findAndInitSwitchPref(DISABLE_OVERLAYS_KEY);
  386. mForceHardwareUi = findAndInitSwitchPref(FORCE_HARDWARE_UI_KEY);
  387. mForceMsaa = findAndInitSwitchPref(FORCE_MSAA_KEY);
  388. mTrackFrameTime = addListPreference(TRACK_FRAME_TIME_KEY);
  389. mShowNonRectClip = addListPreference(SHOW_NON_RECTANGULAR_CLIP_KEY);
  390. mShowHwScreenUpdates = findAndInitSwitchPref(SHOW_HW_SCREEN_UPDATES_KEY);
  391. mShowHwLayersUpdates = findAndInitSwitchPref(SHOW_HW_LAYERS_UPDATES_KEY);
  392. mDebugLayout = findAndInitSwitchPref(DEBUG_LAYOUT_KEY);
  393. mForceRtlLayout = findAndInitSwitchPref(FORCE_RTL_LAYOUT_KEY);
  394. mDebugHwOverdraw = addListPreference(DEBUG_HW_OVERDRAW_KEY);
  395. mWifiDisplayCertification = findAndInitSwitchPref(WIFI_DISPLAY_CERTIFICATION_KEY);
  396. mWifiVerboseLogging = findAndInitSwitchPref(WIFI_VERBOSE_LOGGING_KEY);
  397. mWifiAggressiveHandover = findAndInitSwitchPref(WIFI_AGGRESSIVE_HANDOVER_KEY);
  398. mWifiAllowScansWithTraffic = findAndInitSwitchPref(WIFI_ALLOW_SCAN_WITH_TRAFFIC_KEY);
  399. mMobileDataAlwaysOn = findAndInitSwitchPref(MOBILE_DATA_ALWAYS_ON);
  400. mLogdSize = addListPreference(SELECT_LOGD_SIZE_KEY);
  401. if ("1".equals(SystemProperties.get("ro.debuggable", "0"))) {
  402. mLogpersist = addListPreference(SELECT_LOGPERSIST_KEY);
  403. } else {
  404. mLogpersist = (ListPreference) findPreference(SELECT_LOGPERSIST_KEY);
  405. if (mLogpersist != null) {
  406. mLogpersist.setEnabled(false);
  407. if (debugDebuggingCategory != null) {
  408. debugDebuggingCategory.removePreference(mLogpersist);
  409. }
  410. }
  411. mLogpersist = null;
  412. }
  413. mUsbConfiguration = addListPreference(USB_CONFIGURATION_KEY);
  414. mWebViewProvider = addListPreference(WEBVIEW_PROVIDER_KEY);
  415. mWebViewMultiprocess = findAndInitSwitchPref(WEBVIEW_MULTIPROCESS_KEY);
  416. mBluetoothDisableAbsVolume = findAndInitSwitchPref(BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_KEY);
  417. mWindowAnimationScale = addListPreference(WINDOW_ANIMATION_SCALE_KEY);
  418. mTransitionAnimationScale = addListPreference(TRANSITION_ANIMATION_SCALE_KEY);
  419. mAnimatorDurationScale = addListPreference(ANIMATOR_DURATION_SCALE_KEY);
  420. mOverlayDisplayDevices = addListPreference(OVERLAY_DISPLAY_DEVICES_KEY);
  421. mSimulateColorSpace = addListPreference(SIMULATE_COLOR_SPACE);
  422. mUSBAudio = findAndInitSwitchPref(USB_AUDIO_KEY);
  423. mForceResizable = findAndInitSwitchPref(FORCE_RESIZABLE_KEY);
  424. mImmediatelyDestroyActivities = (SwitchPreference) findPreference(
  425. IMMEDIATELY_DESTROY_ACTIVITIES_KEY);
  426. mAllPrefs.add(mImmediatelyDestroyActivities);
  427. mResetSwitchPrefs.add(mImmediatelyDestroyActivities);
  428. mAppProcessLimit = addListPreference(APP_PROCESS_LIMIT_KEY);
  429. mShowAllANRs = (SwitchPreference) findPreference(
  430. SHOW_ALL_ANRS_KEY);
  431. mAllPrefs.add(mShowAllANRs);
  432. mResetSwitchPrefs.add(mShowAllANRs);
  433. Preference hdcpChecking = findPreference(HDCP_CHECKING_KEY);
  434. if (hdcpChecking != null) {
  435. mAllPrefs.add(hdcpChecking);
  436. removePreferenceForProduction(hdcpChecking);
  437. }
  438. PreferenceScreen convertFbePreference =
  439. (PreferenceScreen) findPreference(KEY_CONVERT_FBE);
  440. try {
  441. IBinder service = ServiceManager.getService("mount");
  442. IMountService mountService = IMountService.Stub.asInterface(service);
  443. if (!mountService.isConvertibleToFBE()) {
  444. removePreference(KEY_CONVERT_FBE);
  445. } else if ("file".equals(SystemProperties.get("ro.crypto.type", "none"))) {
  446. convertFbePreference.setEnabled(false);
  447. convertFbePreference.setSummary(getResources()
  448. .getString(R.string.convert_to_file_encryption_done));
  449. }
  450. } catch(RemoteException e) {
  451. removePreference(KEY_CONVERT_FBE);
  452. }
  453. mOtaDisableAutomaticUpdate = findAndInitSwitchPref(OTA_DISABLE_AUTOMATIC_UPDATE_KEY);
  454. if (!SystemProperties.getBoolean("ro.build.ab_update", false)) {
  455. removePreference(mOtaDisableAutomaticUpdate);
  456. mOtaDisableAutomaticUpdate = null;
  457. }
  458. mColorModePreference = (ColorModePreference) findPreference(KEY_COLOR_MODE);
  459. mColorModePreference.updateCurrentAndSupported();
  460. if (mColorModePreference.getColorModeCount() < 2) {
  461. removePreference(KEY_COLOR_MODE);
  462. mColorModePreference = null;
  463. }
  464. updateWebViewProviderOptions();
  465. mColorTemperaturePreference = (SwitchPreference) findPreference(COLOR_TEMPERATURE_KEY);
  466. if (getResources().getBoolean(R.bool.config_enableColorTemperature)) {
  467. mAllPrefs.add(mColorTemperaturePreference);
  468. mResetSwitchPrefs.add(mColorTemperaturePreference);
  469. } else {
  470. removePreference(COLOR_TEMPERATURE_KEY);
  471. mColorTemperaturePreference = null;
  472. }
  473. mRootAccess = (ListPreference) findPreference(ROOT_ACCESS_KEY);
  474. mRootAccess.setOnPreferenceChangeListener(this);
  475. mRootAppops = (Preference) findPreference(ROOT_APPOPS_KEY);
  476. mRootAppops.setOnPreferenceClickListener(this);
  477. if (!removeRootOptionsIfRequired()) {
  478. mAllPrefs.add(mRootAccess);
  479. mAllPrefs.add(mRootAppops);
  480. }
  481. mDevelopmentTools = (PreferenceScreen) findPreference(DEVELOPMENT_TOOLS);
  482. mAllPrefs.add(mDevelopmentTools);
  483. }
  484. private ListPreference addListPreference(String prefKey) {
  485. ListPreference pref = (ListPreference) findPreference(prefKey);
  486. mAllPrefs.add(pref);
  487. pref.setOnPreferenceChangeListener(this);
  488. return pref;
  489. }
  490. private void disableForUser(Preference pref) {
  491. if (pref != null) {
  492. pref.setEnabled(false);
  493. mDisabledPrefs.add(pref);
  494. }
  495. }
  496. private SwitchPreference findAndInitSwitchPref(String key) {
  497. SwitchPreference pref = (SwitchPreference) findPreference(key);
  498. if (pref == null) {
  499. throw new IllegalArgumentException("Cannot find preference with key = " + key);
  500. }
  501. mAllPrefs.add(pref);
  502. mResetSwitchPrefs.add(pref);
  503. return pref;
  504. }
  505. private boolean removeRootOptionsIfRequired() {
  506. // user builds don't get root, and eng always gets root
  507. if (!(Build.IS_DEBUGGABLE || "eng".equals(Build.TYPE))) {
  508. if (mRootAccess != null) {
  509. getPreferenceScreen().removePreference(mRootAccess);
  510. return true;
  511. }
  512. }
  513. return false;
  514. }
  515. @Override
  516. public void onActivityCreated(Bundle savedInstanceState) {
  517. super.onActivityCreated(savedInstanceState);
  518. final SettingsActivity activity = (SettingsActivity) getActivity();
  519. mSwitchBar = activity.getSwitchBar();
  520. if (mUnavailable) {
  521. mSwitchBar.setEnabled(false);
  522. return;
  523. }
  524. mSwitchBar.addOnSwitchChangeListener(this);
  525. }
  526. private boolean removePreferenceForProduction(Preference preference) {
  527. if ("user".equals(Build.TYPE)) {
  528. removePreference(preference);
  529. return true;
  530. }
  531. return false;
  532. }
  533. private void removePreference(Preference preference) {
  534. getPreferenceScreen().removePreference(preference);
  535. mAllPrefs.remove(preference);
  536. mResetSwitchPrefs.remove(preference);
  537. }
  538. private void setPrefsEnabledState(boolean enabled) {
  539. for (int i = 0; i < mAllPrefs.size(); i++) {
  540. Preference pref = mAllPrefs.get(i);
  541. pref.setEnabled(enabled && !mDisabledPrefs.contains(pref));
  542. }
  543. updateAllOptions();
  544. }
  545. @Override
  546. public void onResume() {
  547. super.onResume();
  548. if (mUnavailable) {
  549. // Show error message
  550. if (!isUiRestrictedByOnlyAdmin()) {
  551. getEmptyTextView().setText(R.string.development_settings_not_available);
  552. }
  553. getPreferenceScreen().removeAll();
  554. return;
  555. }
  556. // A DeviceAdmin has specified a maximum time until the device
  557. // will lock... in this case we can't allow the user to turn
  558. // on "stay awake when plugged in" because that would defeat the
  559. // restriction.
  560. final EnforcedAdmin admin = RestrictedLockUtils.checkIfMaximumTimeToLockIsSet(
  561. getActivity());
  562. mKeepScreenOn.setDisabledByAdmin(admin);
  563. if (admin == null) {
  564. mDisabledPrefs.remove(mKeepScreenOn);
  565. } else {
  566. mDisabledPrefs.add(mKeepScreenOn);
  567. }
  568. final ContentResolver cr = getActivity().getContentResolver();
  569. mLastEnabledState = Settings.Global.getInt(cr,
  570. Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
  571. mSwitchBar.setChecked(mLastEnabledState);
  572. setPrefsEnabledState(mLastEnabledState);
  573. if (mHaveDebugSettings && !mLastEnabledState) {
  574. // Overall debugging is disabled, but there are some debug
  575. // settings that are enabled. This is an invalid state. Switch
  576. // to debug settings being enabled, so the user knows there is
  577. // stuff enabled and can turn it all off if they want.
  578. Settings.Global.putInt(getActivity().getContentResolver(),
  579. Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
  580. mLastEnabledState = true;
  581. mSwitchBar.setChecked(mLastEnabledState);
  582. setPrefsEnabledState(mLastEnabledState);
  583. }
  584. mSwitchBar.show();
  585. if (mColorModePreference != null) {
  586. mColorModePreference.startListening();
  587. mColorModePreference.updateCurrentAndSupported();
  588. }
  589. }
  590. @Override
  591. public void onPause() {
  592. super.onPause();
  593. if (mColorModePreference != null) {
  594. mColorModePreference.stopListening();
  595. }
  596. }
  597. @Override
  598. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  599. Bundle savedInstanceState) {
  600. IntentFilter filter = new IntentFilter();
  601. filter.addAction(UsbManager.ACTION_USB_STATE);
  602. if (getActivity().registerReceiver(mUsbReceiver, filter) == null) {
  603. updateUsbConfigurationValues();
  604. }
  605. return super.onCreateView(inflater, container, savedInstanceState);
  606. }
  607. @Override
  608. public void onDestroyView() {
  609. super.onDestroyView();
  610. if (mUnavailable) {
  611. return;
  612. }
  613. mSwitchBar.removeOnSwitchChangeListener(this);
  614. mSwitchBar.hide();
  615. getActivity().unregisterReceiver(mUsbReceiver);
  616. }
  617. void updateSwitchPreference(SwitchPreference switchPreference, boolean value) {
  618. switchPreference.setChecked(value);
  619. mHaveDebugSettings |= value;
  620. }
  621. private void updateAllOptions() {
  622. final Context context = getActivity();
  623. final ContentResolver cr = context.getContentResolver();
  624. mHaveDebugSettings = false;
  625. updateSwitchPreference(mEnableAdb, Settings.Global.getInt(cr,
  626. Settings.Global.ADB_ENABLED, 0) != 0);
  627. if (mEnableTerminal != null) {
  628. updateSwitchPreference(mEnableTerminal,
  629. context.getPackageManager().getApplicationEnabledSetting(TERMINAL_APP_PACKAGE)
  630. == PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
  631. }
  632. updateSwitchPreference(mBugreportInPower, Settings.Secure.getInt(cr,
  633. Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0);
  634. updateSwitchPreference(mKeepScreenOn, Settings.Global.getInt(cr,
  635. Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0) != 0);
  636. updateSwitchPreference(mBtHciSnoopLog, Settings.Secure.getInt(cr,
  637. Settings.Secure.BLUETOOTH_HCI_LOG, 0) != 0);
  638. updateSwitchPreference(mDebugViewAttributes, Settings.Global.getInt(cr,
  639. Settings.Global.DEBUG_VIEW_ATTRIBUTES, 0) != 0);
  640. updateSwitchPreference(mForceAllowOnExternal, Settings.Global.getInt(cr,
  641. Settings.Global.FORCE_ALLOW_ON_EXTERNAL, 0) != 0);
  642. updateHdcpValues();
  643. updatePasswordSummary();
  644. updateDebuggerOptions();
  645. updateMockLocation();
  646. updateStrictModeVisualOptions();
  647. updatePointerLocationOptions();
  648. updateShowTouchesOptions();
  649. updateFlingerOptions();
  650. updateHardwareUiOptions();
  651. updateMsaaOptions();
  652. updateTrackFrameTimeOptions();
  653. updateShowNonRectClipOptions();
  654. updateShowHwScreenUpdatesOptions();
  655. updateShowHwLayersUpdatesOptions();
  656. updateDebugHwOverdrawOptions();
  657. updateDebugLayoutOptions();
  658. updateAnimationScaleOptions();
  659. updateOverlayDisplayDevicesOptions();
  660. updateImmediatelyDestroyActivitiesOptions();
  661. updateAppProcessLimitOptions();
  662. updateShowAllANRsOptions();
  663. updateVerifyAppsOverUsbOptions();
  664. if (mOtaDisableAutomaticUpdate != null) {
  665. updateOtaDisableAutomaticUpdateOptions();
  666. }
  667. updateBugreportOptions();
  668. updateForceRtlOptions();
  669. updateLogdSizeValues();
  670. updateLogpersistValues();
  671. updateWifiDisplayCertificationOptions();
  672. updateWifiVerboseLoggingOptions();
  673. updateWifiAggressiveHandoverOptions();
  674. updateWifiAllowScansWithTrafficOptions();
  675. updateMobileDataAlwaysOnOptions();
  676. updateSimulateColorSpace();
  677. updateUSBAudioOptions();
  678. updateForceResizableOptions();
  679. updateWebViewMultiprocessOptions();
  680. updateWebViewProviderOptions();
  681. updateOemUnlockOptions();
  682. if (mColorTemperaturePreference != null) {
  683. updateColorTemperature();
  684. }
  685. updateBluetoothDisableAbsVolumeOptions();
  686. updateRootAccessOptions();
  687. updateAdbOverNetwork();
  688. }
  689. private void updateAdbOverNetwork() {
  690. int port = CMSettings.Secure.getInt(getActivity().getContentResolver(),
  691. CMSettings.Secure.ADB_PORT, 0);
  692. boolean enabled = port > 0;
  693. updateSwitchPreference(mAdbOverNetwork, enabled);
  694. WifiInfo wifiInfo = null;
  695. if (enabled) {
  696. IWifiManager wifiManager = IWifiManager.Stub.asInterface(
  697. ServiceManager.getService(Context.WIFI_SERVICE));
  698. try {
  699. wifiInfo = wifiManager.getConnectionInfo();
  700. } catch (RemoteException e) {
  701. Log.e(TAG, "wifiManager, getConnectionInfo()", e);
  702. }
  703. }
  704. if (wifiInfo != null) {
  705. String hostAddress = NetworkUtils.intToInetAddress(
  706. wifiInfo.getIpAddress()).getHostAddress();
  707. mAdbOverNetwork.setSummary(hostAddress + ":" + String.valueOf(port));
  708. } else {
  709. mAdbOverNetwork.setSummary(R.string.adb_over_network_summary);
  710. }
  711. }
  712. private void resetDangerousOptions() {
  713. mDontPokeProperties = true;
  714. for (int i=0; i< mResetSwitchPrefs.size(); i++) {
  715. SwitchPreference cb = mResetSwitchPrefs.get(i);
  716. if (cb.isChecked()) {
  717. cb.setChecked(false);
  718. onPreferenceTreeClick(cb);
  719. }
  720. }
  721. resetDebuggerOptions();
  722. writeLogpersistOption(null, true);
  723. writeLogdSizeOption(null);
  724. resetRootAccessOptions();
  725. resetAdbNotifyOptions();
  726. writeAnimationScaleOption(0, mWindowAnimationScale, null);
  727. writeAnimationScaleOption(1, mTransitionAnimationScale, null);
  728. writeAnimationScaleOption(2, mAnimatorDurationScale, null);
  729. // Only poke the color space setting if we control it.
  730. if (usingDevelopmentColorSpace()) {
  731. writeSimulateColorSpace(-1);
  732. }
  733. writeOverlayDisplayDevicesOptions(null);
  734. writeAppProcessLimitOptions(null);
  735. mHaveDebugSettings = false;
  736. updateAllOptions();
  737. mDontPokeProperties = false;
  738. pokeSystemProperties();
  739. }
  740. private void updateWebViewProviderOptions() {
  741. try {
  742. WebViewProviderInfo[] providers = mWebViewUpdateService.getValidWebViewPackages();
  743. if (providers == null) {
  744. Log.e(TAG, "No WebView providers available");
  745. return;
  746. }
  747. ArrayList<String> options = new ArrayList<String>();
  748. ArrayList<String> values = new ArrayList<String>();
  749. for(int n = 0; n < providers.length; n++) {
  750. if (Utils.isPackageEnabled(getActivity(), providers[n].packageName)) {
  751. options.add(providers[n].description);
  752. values.add(providers[n].packageName);
  753. }
  754. }
  755. mWebViewProvider.setEntries(options.toArray(new String[options.size()]));
  756. mWebViewProvider.setEntryValues(values.toArray(new String[values.size()]));
  757. String value = mWebViewUpdateService.getCurrentWebViewPackageName();
  758. if (value == null) {
  759. value = "";
  760. }
  761. for (int i = 0; i < values.size(); i++) {
  762. if (value.contentEquals(values.get(i))) {
  763. mWebViewProvider.setValueIndex(i);
  764. return;
  765. }
  766. }
  767. } catch(RemoteException e) {
  768. }
  769. }
  770. private void updateWebViewMultiprocessOptions() {
  771. updateSwitchPreference(mWebViewMultiprocess,
  772. Settings.Global.getInt(getActivity().getContentResolver(),
  773. Settings.Global.WEBVIEW_MULTIPROCESS, 0) != 0);
  774. }
  775. private void writeWebViewMultiprocessOptions() {
  776. boolean value = mWebViewMultiprocess.isChecked();
  777. Settings.Global.putInt(getActivity().getContentResolver(),
  778. Settings.Global.WEBVIEW_MULTIPROCESS, value ? 1 : 0);
  779. try {
  780. String wv_package = mWebViewUpdateService.getCurrentWebViewPackageName();
  781. ActivityManagerNative.getDefault().killPackageDependents(
  782. wv_package, UserHandle.USER_ALL);
  783. } catch(RemoteException e) {
  784. }
  785. }
  786. private void updateRootAccessOptions() {
  787. String value = SystemProperties.get(ROOT_ACCESS_PROPERTY, "0");
  788. mRootAccess.setValue(value);
  789. mRootAccess.setSummary(getResources()
  790. .getStringArray(R.array.root_access_entries)[Integer.valueOf(value)]);
  791. if (mRootAppops != null) {
  792. mRootAppops.setEnabled(isRootForAppsEnabled());
  793. }
  794. }
  795. public static boolean isRootForAppsEnabled() {
  796. int value = SystemProperties.getInt(ROOT_ACCESS_PROPERTY, 0);
  797. boolean daemonState =
  798. SystemProperties.get("init.svc.su_daemon", "absent").equals("running");
  799. return daemonState && (value == 1 || value == 3);
  800. }
  801. private void writeRootAccessOptions(Object newValue) {
  802. String oldValue = SystemProperties.get(ROOT_ACCESS_PROPERTY, "0");
  803. SystemProperties.set(ROOT_ACCESS_PROPERTY, newValue.toString());
  804. if (Integer.valueOf(newValue.toString()) < 2 && !oldValue.equals(newValue)
  805. && "1".equals(SystemProperties.get("service.adb.root", "0"))) {
  806. SystemProperties.set("service.adb.root", "0");
  807. Settings.Secure.putInt(getActivity().getContentResolver(),
  808. Settings.Secure.ADB_ENABLED, 0);
  809. Settings.Secure.putInt(getActivity().getContentResolver(),
  810. Settings.Secure.ADB_ENABLED, 1);
  811. }
  812. updateRootAccessOptions();
  813. }
  814. private void resetRootAccessOptions() {
  815. String oldValue = SystemProperties.get(ROOT_ACCESS_PROPERTY, "0");
  816. SystemProperties.set(ROOT_ACCESS_PROPERTY, "0");
  817. if (!oldValue.equals("0") && "1".equals(SystemProperties.get("service.adb.root", "0"))) {
  818. SystemProperties.set("service.adb.root", "0");
  819. Settings.Secure.putInt(getActivity().getContentResolver(),
  820. Settings.Secure.ADB_ENABLED, 0);
  821. Settings.Secure.putInt(getActivity().getContentResolver(),
  822. Settings.Secure.ADB_ENABLED, 1);
  823. }
  824. updateRootAccessOptions();
  825. }
  826. private void resetAdbNotifyOptions() {
  827. CMSettings.Secure.putInt(getActivity().getContentResolver(),
  828. CMSettings.Secure.ADB_NOTIFY, 1);
  829. }
  830. private void updateHdcpValues() {
  831. ListPreference hdcpChecking = (ListPreference) findPreference(HDCP_CHECKING_KEY);
  832. if (hdcpChecking != null) {
  833. String currentValue = SystemProperties.get(HDCP_CHECKING_PROPERTY);
  834. String[] values = getResources().getStringArray(R.array.hdcp_checking_values);
  835. String[] summaries = getResources().getStringArray(R.array.hdcp_checking_summaries);
  836. int index = 1; // Defaults to drm-only. Needs to match with R.array.hdcp_checking_values
  837. for (int i = 0; i < values.length; i++) {
  838. if (currentValue.equals(values[i])) {
  839. index = i;
  840. break;
  841. }
  842. }
  843. hdcpChecking.setValue(values[index]);
  844. hdcpChecking.setSummary(summaries[index]);
  845. hdcpChecking.setOnPreferenceChangeListener(this);
  846. }
  847. }
  848. private void updatePasswordSummary() {
  849. try {
  850. if (mBackupManager == null) {
  851. Log.e(TAG, "Backup Manager is unavailable!");
  852. return;
  853. }
  854. if (mBackupManager.hasBackupPassword()) {
  855. mPassword.setSummary(R.string.local_backup_password_summary_change);
  856. } else {
  857. mPassword.setSummary(R.string.local_backup_password_summary_none);
  858. }
  859. } catch (RemoteException e) {
  860. // Not much we can do here
  861. }
  862. }
  863. private void writeBtHciSnoopLogOptions() {
  864. BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
  865. adapter.configHciSnoopLog(mBtHciSnoopLog.isChecked());
  866. Settings.Secure.putInt(getActivity().getContentResolver(),
  867. Settings.Secure.BLUETOOTH_HCI_LOG,
  868. mBtHciSnoopLog.isChecked() ? 1 : 0);
  869. }
  870. private boolean writeWebViewProviderOptions(Object newValue) {
  871. try {
  872. String updatedProvider = mWebViewUpdateService.changeProviderAndSetting(
  873. newValue == null ? "" : newValue.toString());
  874. updateWebViewProviderOptions();
  875. return newValue != null && newValue.equals(updatedProvider);
  876. } catch(RemoteException e) {
  877. }
  878. return false;
  879. }
  880. private void writeDebuggerOptions() {
  881. try {
  882. ActivityManagerNative.getDefault().setDebugApp(
  883. mDebugApp, mWaitForDebugger.isChecked(), true);
  884. } catch (RemoteException ex) {
  885. }
  886. }
  887. private void writeMockLocation() {
  888. AppOpsManager appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE);
  889. // Disable the app op of the previous mock location app if such.
  890. List<PackageOps> packageOps = appOpsManager.getPackagesForOps(MOCK_LOCATION_APP_OPS);
  891. if (packageOps != null) {
  892. // Should be one but in case we are in a bad state due to use of command line tools.
  893. for (PackageOps packageOp : packageOps) {
  894. if (packageOp.getOps().get(0).getMode() != AppOpsManager.MODE_ERRORED) {
  895. String oldMockLocationApp = packageOp.getPackageName();
  896. try {
  897. ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(
  898. oldMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS);
  899. appOpsManager.setMode(AppOpsManager.OP_MOCK_LOCATION, ai.uid,
  900. oldMockLocationApp, AppOpsManager.MODE_ERRORED);
  901. } catch (NameNotFoundException e) {
  902. /* ignore */
  903. }
  904. }
  905. }
  906. }
  907. // Enable the app op of the new mock location app if such.
  908. if (!TextUtils.isEmpty(mMockLocationApp)) {
  909. try {
  910. ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(
  911. mMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS);
  912. appOpsManager.setMode(AppOpsManager.OP_MOCK_LOCATION, ai.uid,
  913. mMockLocationApp, AppOpsManager.MODE_ALLOWED);
  914. } catch (NameNotFoundException e) {
  915. /* ignore */
  916. }
  917. }
  918. }
  919. private static void resetDebuggerOptions() {
  920. try {
  921. ActivityManagerNative.getDefault().setDebugApp(
  922. null, false, true);
  923. } catch (RemoteException ex) {
  924. }
  925. }
  926. private void updateDebuggerOptions() {
  927. mDebugApp = Settings.Global.getString(
  928. getActivity().getContentResolver(), Settings.Global.DEBUG_APP);
  929. updateSwitchPreference(mWaitForDebugger, Settings.Global.getInt(
  930. getActivity().getContentResolver(), Settings.Global.WAIT_FOR_DEBUGGER, 0) != 0);
  931. if (mDebugApp != null && mDebugApp.length() > 0) {
  932. String label;
  933. try {
  934. ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(mDebugApp,
  935. PackageManager.GET_DISABLED_COMPONENTS);
  936. CharSequence lab = getActivity().getPackageManager().getApplicationLabel(ai);
  937. label = lab != null ? lab.toString() : mDebugApp;
  938. } catch (PackageManager.NameNotFoundException e) {
  939. label = mDebugApp;
  940. }
  941. mDebugAppPref.setSummary(getResources().getString(R.string.debug_app_set, label));
  942. mWaitForDebugger.setEnabled(true);
  943. mHaveDebugSettings = true;
  944. } else {
  945. mDebugAppPref.setSummary(getResources().getString(R.string.debug_app_not_set));
  946. mWaitForDebugger.setEnabled(false);
  947. }
  948. }
  949. private void updateMockLocation() {
  950. AppOpsManager appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE);
  951. List<PackageOps> packageOps = appOpsManager.getPackagesForOps(MOCK_LOCATION_APP_OPS);
  952. if (packageOps != null) {
  953. for (PackageOps packageOp : packageOps) {
  954. if (packageOp.getOps().get(0).getMode() == AppOpsManager.MODE_ALLOWED) {
  955. mMockLocationApp = packageOps.get(0).getPackageName();
  956. break;
  957. }
  958. }
  959. }
  960. if (!TextUtils.isEmpty(mMockLocationApp)) {
  961. String label = mMockLocationApp;
  962. try {
  963. ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(
  964. mMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS);
  965. CharSequence appLabel = getPackageManager().getApplicationLabel(ai);
  966. if (appLabel != null) {
  967. label = appLabel.toString();
  968. }
  969. } catch (PackageManager.NameNotFoundException e) {
  970. /* ignore */
  971. }
  972. mMockLocationAppPref.setSummary(getString(R.string.mock_location_app_set, label));
  973. mHaveDebugSettings = true;
  974. } else {
  975. mMockLocationAppPref.setSummary(getString(R.string.mock_location_app_not_set));
  976. }
  977. }
  978. private void updateVerifyAppsOverUsbOptions() {
  979. updateSwitchPreference(mVerifyAppsOverUsb, Settings.Global.getInt(getActivity().getContentResolver(),
  980. Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1) != 0);
  981. mVerifyAppsOverUsb.setEnabled(enableVerifierSetting());
  982. }
  983. private void writeVerifyAppsOverUsbOptions() {
  984. Settings.Global.putInt(getActivity().getContentResolver(),
  985. Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB,
  986. mVerifyAppsOverUsb.isChecked() ? 1 : 0);
  987. }
  988. private void updateOtaDisableAutomaticUpdateOptions() {
  989. // We use the "disabled status" in code, but show the opposite text
  990. // "Automatic system updates" on screen. So a value 0 indicates the
  991. // automatic update is enabled.
  992. updateSwitchPreference(mOtaDisableAutomaticUpdate, Settings.Global.getInt(
  993. getActivity().getContentResolver(),
  994. Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE, 0) != 1);
  995. }
  996. private void writeOtaDisableAutomaticUpdateOptions() {
  997. // We use the "disabled status" in code, but show the opposite text
  998. // "Automatic system updates" on screen. So a value 0 indicates the
  999. // automatic update is enab…