Advertisement
Guest User

Compile Error

a guest
Aug 20th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 55.06 KB | None | 0 0
  1. /*
  2. * Copyright (C) 2008 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16.  
  17. package com.android.settings;
  18.  
  19. import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
  20.  
  21. import android.app.ActionBar;
  22. import android.app.Activity;
  23. import android.app.ActivityManagerNative;
  24. import android.app.ActivityThread;
  25. import android.app.AlertDialog;
  26. import android.app.Dialog;
  27. import android.app.DialogFragment;
  28. import android.app.admin.DevicePolicyManager;
  29. import android.app.backup.IBackupManager;
  30. import android.content.ContentResolver;
  31. import android.content.Context;
  32. import android.content.DialogInterface;
  33. import android.content.res.Configuration;
  34. import android.content.DialogInterface.OnClickListener;
  35. import android.content.Intent;
  36. import android.content.pm.ApplicationInfo;
  37. import android.content.pm.PackageManager;
  38. import android.content.pm.ResolveInfo;
  39. import android.os.AsyncTask;
  40. import android.os.BatteryManager;
  41. import android.os.Build;
  42. import android.os.Bundle;
  43. import android.os.IBinder;
  44. import android.os.Parcel;
  45. import android.os.RemoteException;
  46. import android.os.ServiceManager;
  47. import android.os.StrictMode;
  48. import android.os.SystemProperties;
  49. import android.os.Trace;
  50. import android.os.UserHandle;
  51. import android.preference.CheckBoxPreference;
  52. import android.preference.ListPreference;
  53. import android.preference.MultiCheckPreference;
  54. import android.preference.Preference;
  55. import android.preference.Preference.OnPreferenceChangeListener;
  56. import android.preference.PreferenceFragment;
  57. import android.preference.PreferenceGroup;
  58. import android.preference.PreferenceScreen;
  59. import android.provider.Settings;
  60. import android.text.TextUtils;
  61. import android.util.Log;
  62. import android.view.Gravity;
  63. import android.view.HardwareRenderer;
  64. import android.view.IWindowManager;
  65. import android.view.View;
  66. import android.widget.CompoundButton;
  67. import android.widget.Switch;
  68.  
  69. import com.mediatek.xlog.Xlog;
  70.  
  71. import java.util.ArrayList;
  72. import java.util.HashSet;
  73. import java.util.List;
  74.  
  75. /*
  76. * Displays preferences for application developers.
  77. */
  78. public class DevelopmentSettings extends PreferenceFragment
  79. implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener,
  80. OnPreferenceChangeListener, CompoundButton.OnCheckedChangeListener {
  81.  
  82. private static final String TAG = "DevelopmentSettings";
  83.  
  84. /**
  85. * Preference file were development settings prefs are stored.
  86. */
  87. public static final String PREF_FILE = "development";
  88.  
  89. /**
  90. * Whether to show the development settings to the user. Default is false.
  91. */
  92. public static final String PREF_SHOW = "show";
  93.  
  94. private static final String ENABLE_ADB = "enable_adb";
  95. private static final String KEEP_SCREEN_ON = "keep_screen_on";
  96. private static final String ALLOW_MOCK_LOCATION = "allow_mock_location";
  97. private static final String HDCP_CHECKING_KEY = "hdcp_checking";
  98. private static final String HDCP_CHECKING_PROPERTY = "persist.sys.hdcp_checking";
  99. private static final String ENFORCE_READ_EXTERNAL = "enforce_read_external";
  100. private static final String LOCAL_BACKUP_PASSWORD = "local_backup_password";
  101. private static final String HARDWARE_UI_PROPERTY = "persist.sys.ui.hw";
  102. private static final String MSAA_PROPERTY = "debug.egl.force_msaa";
  103. private static final String BUGREPORT = "bugreport";
  104. private static final String BUGREPORT_IN_POWER_KEY = "bugreport_in_power";
  105. private static final String OPENGL_TRACES_PROPERTY = "debug.egl.trace";
  106.  
  107. private static final String DEBUG_APP_KEY = "debug_app";
  108. private static final String WAIT_FOR_DEBUGGER_KEY = "wait_for_debugger";
  109. private static final String VERIFY_APPS_OVER_USB_KEY = "verify_apps_over_usb";
  110. private static final String STRICT_MODE_KEY = "strict_mode";
  111. private static final String POINTER_LOCATION_KEY = "pointer_location";
  112. private static final String SHOW_TOUCHES_KEY = "show_touches";
  113. private static final String SHOW_SCREEN_UPDATES_KEY = "show_screen_updates";
  114. private static final String DISABLE_OVERLAYS_KEY = "disable_overlays";
  115. private static final String SHOW_CPU_USAGE_KEY = "show_cpu_usage";
  116. private static final String FORCE_HARDWARE_UI_KEY = "force_hw_ui";
  117. private static final String FORCE_MSAA_KEY = "force_msaa";
  118. private static final String TRACK_FRAME_TIME_KEY = "track_frame_time";
  119. private static final String SHOW_HW_SCREEN_UPDATES_KEY = "show_hw_screen_udpates";
  120. private static final String SHOW_HW_LAYERS_UPDATES_KEY = "show_hw_layers_udpates";
  121. private static final String SHOW_HW_OVERDRAW_KEY = "show_hw_overdraw";
  122. private static final String DEBUG_LAYOUT_KEY = "debug_layout";
  123. private static final String WINDOW_ANIMATION_SCALE_KEY = "window_animation_scale";
  124. private static final String TRANSITION_ANIMATION_SCALE_KEY = "transition_animation_scale";
  125. private static final String ANIMATOR_DURATION_SCALE_KEY = "animator_duration_scale";
  126. private static final String OVERLAY_DISPLAY_DEVICES_KEY = "overlay_display_devices";
  127. private static final String DEBUG_DEBUGGING_CATEGORY_KEY = "debug_debugging_category";
  128. private static final String DEBUG_DRAWING_CATEGORY_KEY = "debug_drawing_category";
  129. private static final String OPENGL_TRACES_KEY = "enable_opengl_traces";
  130.  
  131. private static final String ENABLE_TRACES_KEY = "enable_traces";
  132.  
  133. private static final String IMMEDIATELY_DESTROY_ACTIVITIES_KEY
  134. = "immediately_destroy_activities";
  135. private static final String APP_PROCESS_LIMIT_KEY = "app_process_limit";
  136.  
  137. private static final String SHOW_ALL_ANRS_KEY = "show_all_anrs";
  138.  
  139. private static final String TAG_CONFIRM_ENFORCE = "confirm_enforce";
  140.  
  141. private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive";
  142.  
  143. private static final int RESULT_DEBUG_APP = 1000;
  144.  
  145. // current simulate feature option, for turn off "simulate secondary display"
  146. private static final boolean SUPPORT_SECONDARY_DISPLAY = false;
  147.  
  148. private IWindowManager mWindowManager;
  149. private IBackupManager mBackupManager;
  150. private DevicePolicyManager mDpm;
  151.  
  152. private Switch mEnabledSwitch;
  153. private boolean mLastEnabledState;
  154. private boolean mHaveDebugSettings;
  155. private boolean mDontPokeProperties;
  156.  
  157. private CheckBoxPreference mEnableAdb;
  158. private Preference mBugreport;
  159. private CheckBoxPreference mBugreportInPower;
  160. private CheckBoxPreference mKeepScreenOn;
  161. private CheckBoxPreference mEnforceReadExternal;
  162. private CheckBoxPreference mAllowMockLocation;
  163. private PreferenceScreen mPassword;
  164.  
  165. private String mDebugApp;
  166. private Preference mDebugAppPref;
  167. private CheckBoxPreference mWaitForDebugger;
  168. private CheckBoxPreference mVerifyAppsOverUsb;
  169.  
  170. private CheckBoxPreference mStrictMode;
  171. private CheckBoxPreference mPointerLocation;
  172. private CheckBoxPreference mShowTouches;
  173. private CheckBoxPreference mShowScreenUpdates;
  174. private CheckBoxPreference mDisableOverlays;
  175. private CheckBoxPreference mShowCpuUsage;
  176. private CheckBoxPreference mForceHardwareUi;
  177. private CheckBoxPreference mForceMsaa;
  178. private CheckBoxPreference mTrackFrameTime;
  179. private CheckBoxPreference mShowHwScreenUpdates;
  180. private CheckBoxPreference mShowHwLayersUpdates;
  181. private CheckBoxPreference mShowHwOverdraw;
  182. private CheckBoxPreference mDebugLayout;
  183. private ListPreference mWindowAnimationScale;
  184. private ListPreference mTransitionAnimationScale;
  185. private ListPreference mAnimatorDurationScale;
  186. private ListPreference mOverlayDisplayDevices;
  187. private ListPreference mOpenGLTraces;
  188. private MultiCheckPreference mEnableTracesPref;
  189.  
  190. private CheckBoxPreference mImmediatelyDestroyActivities;
  191. private ListPreference mAppProcessLimit;
  192.  
  193. private CheckBoxPreference mShowAllANRs;
  194.  
  195. private final ArrayList<Preference> mAllPrefs = new ArrayList<Preference>();
  196. private final ArrayList<CheckBoxPreference> mResetCbPrefs
  197. = new ArrayList<CheckBoxPreference>();
  198.  
  199. private final HashSet<Preference> mDisabledPrefs = new HashSet<Preference>();
  200.  
  201. // To track whether a confirmation dialog was clicked.
  202. private boolean mDialogClicked;
  203. private Dialog mEnableDialog;
  204. private Dialog mAdbDialog;
  205.  
  206. @Override
  207. public void onCreate(Bundle icicle) {
  208. super.onCreate(icicle);
  209.  
  210. mWindowManager = IWindowManager.Stub.asInterface(ServiceManager.getService("window"));
  211. mBackupManager = IBackupManager.Stub.asInterface(
  212. ServiceManager.getService(Context.BACKUP_SERVICE));
  213. mDpm = (DevicePolicyManager)getActivity().getSystemService(Context.DEVICE_POLICY_SERVICE);
  214.  
  215. addPreferencesFromResource(R.xml.development_prefs);
  216.  
  217. mEnableAdb = findAndInitCheckboxPref(ENABLE_ADB);
  218. mBugreport = findPreference(BUGREPORT);
  219. mBugreportInPower = findAndInitCheckboxPref(BUGREPORT_IN_POWER_KEY);
  220. mKeepScreenOn = findAndInitCheckboxPref(KEEP_SCREEN_ON);
  221. mEnforceReadExternal = findAndInitCheckboxPref(ENFORCE_READ_EXTERNAL);
  222. mAllowMockLocation = findAndInitCheckboxPref(ALLOW_MOCK_LOCATION);
  223. mPassword = (PreferenceScreen) findPreference(LOCAL_BACKUP_PASSWORD);
  224. mAllPrefs.add(mPassword);
  225.  
  226. if (!android.os.Process.myUserHandle().equals(UserHandle.OWNER)) {
  227. disableForUser(mEnableAdb);
  228. disableForUser(mPassword);
  229. }
  230.  
  231. mDebugAppPref = findPreference(DEBUG_APP_KEY);
  232. mAllPrefs.add(mDebugAppPref);
  233. mWaitForDebugger = findAndInitCheckboxPref(WAIT_FOR_DEBUGGER_KEY);
  234. mVerifyAppsOverUsb = findAndInitCheckboxPref(VERIFY_APPS_OVER_USB_KEY);
  235. if (!showVerifierSetting()) {
  236. PreferenceGroup debugDebuggingCategory = (PreferenceGroup)
  237. findPreference(DEBUG_DEBUGGING_CATEGORY_KEY);
  238. if (debugDebuggingCategory != null) {
  239. debugDebuggingCategory.removePreference(mVerifyAppsOverUsb);
  240. } else {
  241. mVerifyAppsOverUsb.setEnabled(false);
  242. }
  243. }
  244. mStrictMode = findAndInitCheckboxPref(STRICT_MODE_KEY);
  245. mPointerLocation = findAndInitCheckboxPref(POINTER_LOCATION_KEY);
  246. mShowTouches = findAndInitCheckboxPref(SHOW_TOUCHES_KEY);
  247. mShowScreenUpdates = findAndInitCheckboxPref(SHOW_SCREEN_UPDATES_KEY);
  248. mDisableOverlays = findAndInitCheckboxPref(DISABLE_OVERLAYS_KEY);
  249. mShowCpuUsage = findAndInitCheckboxPref(SHOW_CPU_USAGE_KEY);
  250. mForceHardwareUi = findAndInitCheckboxPref(FORCE_HARDWARE_UI_KEY);
  251. mForceMsaa = findAndInitCheckboxPref(FORCE_MSAA_KEY);
  252. mTrackFrameTime = findAndInitCheckboxPref(TRACK_FRAME_TIME_KEY);
  253. mShowHwScreenUpdates = findAndInitCheckboxPref(SHOW_HW_SCREEN_UPDATES_KEY);
  254. mShowHwLayersUpdates = findAndInitCheckboxPref(SHOW_HW_LAYERS_UPDATES_KEY);
  255. mShowHwOverdraw = findAndInitCheckboxPref(SHOW_HW_OVERDRAW_KEY);
  256. mDebugLayout = findAndInitCheckboxPref(DEBUG_LAYOUT_KEY);
  257. mWindowAnimationScale = (ListPreference) findPreference(WINDOW_ANIMATION_SCALE_KEY);
  258. mAllPrefs.add(mWindowAnimationScale);
  259. mWindowAnimationScale.setOnPreferenceChangeListener(this);
  260. mTransitionAnimationScale = (ListPreference) findPreference(TRANSITION_ANIMATION_SCALE_KEY);
  261. mAllPrefs.add(mTransitionAnimationScale);
  262. mTransitionAnimationScale.setOnPreferenceChangeListener(this);
  263. mAnimatorDurationScale = (ListPreference) findPreference(ANIMATOR_DURATION_SCALE_KEY);
  264. mAllPrefs.add(mAnimatorDurationScale);
  265. mAnimatorDurationScale.setOnPreferenceChangeListener(this);
  266. mOverlayDisplayDevices = (ListPreference) findPreference(OVERLAY_DISPLAY_DEVICES_KEY);
  267. mAllPrefs.add(mOverlayDisplayDevices);
  268.  
  269. if (!SUPPORT_SECONDARY_DISPLAY) {
  270. PreferenceGroup debugDrawingCategory = (PreferenceGroup)
  271. findPreference(DEBUG_DRAWING_CATEGORY_KEY);
  272.  
  273. if (debugDrawingCategory != null) {
  274. debugDrawingCategory.removePreference(mOverlayDisplayDevices);
  275. }
  276. mAllPrefs.remove(mOverlayDisplayDevices);
  277. }
  278. mOverlayDisplayDevices.setOnPreferenceChangeListener(this);
  279. mOpenGLTraces = (ListPreference) findPreference(OPENGL_TRACES_KEY);
  280. mAllPrefs.add(mOpenGLTraces);
  281. mOpenGLTraces.setOnPreferenceChangeListener(this);
  282. mEnableTracesPref = (MultiCheckPreference)findPreference(ENABLE_TRACES_KEY);
  283. String[] traceValues = new String[Trace.TRACE_TAGS.length];
  284. // {@ M: ALPS00592231
  285. for (int i=Trace.TRACE_FLAGS_START_BIT; i<=traceValues.length; i++) {
  286. traceValues[i-1] = Integer.toString(1<<i);
  287. }
  288. // @}
  289. mEnableTracesPref.setEntries(Trace.TRACE_TAGS);
  290. mEnableTracesPref.setEntryValues(traceValues);
  291. mAllPrefs.add(mEnableTracesPref);
  292. mEnableTracesPref.setOnPreferenceChangeListener(this);
  293.  
  294. mImmediatelyDestroyActivities = (CheckBoxPreference) findPreference(
  295. IMMEDIATELY_DESTROY_ACTIVITIES_KEY);
  296. mAllPrefs.add(mImmediatelyDestroyActivities);
  297. mResetCbPrefs.add(mImmediatelyDestroyActivities);
  298. mAppProcessLimit = (ListPreference) findPreference(APP_PROCESS_LIMIT_KEY);
  299. mAllPrefs.add(mAppProcessLimit);
  300. mAppProcessLimit.setOnPreferenceChangeListener(this);
  301.  
  302. mShowAllANRs = (CheckBoxPreference) findPreference(
  303. SHOW_ALL_ANRS_KEY);
  304. mAllPrefs.add(mShowAllANRs);
  305. mResetCbPrefs.add(mShowAllANRs);
  306.  
  307. Preference hdcpChecking = findPreference(HDCP_CHECKING_KEY);
  308. if (hdcpChecking != null) {
  309. mAllPrefs.add(hdcpChecking);
  310. }
  311. removeHdcpOptionsForProduction();
  312. }
  313.  
  314. private void disableForUser(Preference pref) {
  315. if (pref != null) {
  316. pref.setEnabled(false);
  317. mDisabledPrefs.add(pref);
  318. }
  319. }
  320.  
  321. private CheckBoxPreference findAndInitCheckboxPref(String key) {
  322. CheckBoxPreference pref = (CheckBoxPreference) findPreference(key);
  323. if (pref == null) {
  324. throw new IllegalArgumentException("Cannot find preference with key = " + key);
  325. }
  326. mAllPrefs.add(pref);
  327. mResetCbPrefs.add(pref);
  328. return pref;
  329. }
  330.  
  331. @Override
  332. public void onActivityCreated(Bundle savedInstanceState) {
  333. super.onActivityCreated(savedInstanceState);
  334.  
  335. final Activity activity = getActivity();
  336. mEnabledSwitch = new Switch(activity);
  337.  
  338. final int padding = activity.getResources().getDimensionPixelSize(
  339. R.dimen.action_bar_switch_padding);
  340. mEnabledSwitch.setPadding(0, 0, padding, 0);
  341. mEnabledSwitch.setOnCheckedChangeListener(this);
  342. }
  343.  
  344. @Override
  345. public void onStart() {
  346. super.onStart();
  347. final Activity activity = getActivity();
  348. activity.getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
  349. ActionBar.DISPLAY_SHOW_CUSTOM);
  350. activity.getActionBar().setCustomView(mEnabledSwitch, new ActionBar.LayoutParams(
  351. ActionBar.LayoutParams.WRAP_CONTENT,
  352. ActionBar.LayoutParams.WRAP_CONTENT,
  353. Gravity.CENTER_VERTICAL | Gravity.END));
  354. }
  355.  
  356. @Override
  357. public void onStop() {
  358. super.onStop();
  359. final Activity activity = getActivity();
  360. activity.getActionBar().setDisplayOptions(0, ActionBar.DISPLAY_SHOW_CUSTOM);
  361. activity.getActionBar().setCustomView(null);
  362. }
  363.  
  364. private void removeHdcpOptionsForProduction() {
  365. if ("user".equals(Build.TYPE)) {
  366. Preference hdcpChecking = findPreference(HDCP_CHECKING_KEY);
  367. if (hdcpChecking != null) {
  368. // Remove the preference
  369. getPreferenceScreen().removePreference(hdcpChecking);
  370. mAllPrefs.remove(hdcpChecking);
  371. }
  372. }
  373. }
  374.  
  375. private void setPrefsEnabledState(boolean enabled) {
  376. for (int i = 0; i < mAllPrefs.size(); i++) {
  377. Preference pref = mAllPrefs.get(i);
  378. pref.setEnabled(enabled && !mDisabledPrefs.contains(pref));
  379. }
  380. updateAllOptions();
  381. }
  382.  
  383. @Override
  384. public void onResume() {
  385. super.onResume();
  386.  
  387. if (mDpm.getMaximumTimeToLock(null) > 0) {
  388. // A DeviceAdmin has specified a maximum time until the device
  389. // will lock... in this case we can't allow the user to turn
  390. // on "stay awake when plugged in" because that would defeat the
  391. // restriction.
  392. mDisabledPrefs.add(mKeepScreenOn);
  393. } else {
  394. mDisabledPrefs.remove(mKeepScreenOn);
  395. }
  396.  
  397. final ContentResolver cr = getActivity().getContentResolver();
  398. mLastEnabledState = Settings.Global.getInt(cr,
  399. Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
  400. /** M: mtk54279 [ALPS00327180] @{ */
  401. if (mEnableDialog == null) {
  402. //the first time to lanuch this activity, apply the mLastEnabledState to Switch, for sync status.
  403. //if the dialog is not null, we don't need to apply the mLastEnabledState to Switch status.
  404. Xlog.d(TAG, "development enable dialog is null");
  405. mEnabledSwitch.setChecked(mLastEnabledState);
  406. }
  407.  
  408. /** M: end @} */
  409.  
  410. setPrefsEnabledState(mLastEnabledState);
  411.  
  412. if (mHaveDebugSettings && !mLastEnabledState) {
  413. // Overall debugging is disabled, but there are some debug
  414. // settings that are enabled. This is an invalid state. Switch
  415. // to debug settings being enabled, so the user knows there is
  416. // stuff enabled and can turn it all off if they want.
  417. Settings.Global.putInt(getActivity().getContentResolver(),
  418. Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
  419. mLastEnabledState = true;
  420. mEnabledSwitch.setChecked(mLastEnabledState);
  421. setPrefsEnabledState(mLastEnabledState);
  422. }
  423. }
  424.  
  425. void updateCheckBox(CheckBoxPreference checkBox, boolean value) {
  426. checkBox.setChecked(value);
  427. mHaveDebugSettings |= value;
  428. }
  429.  
  430. private void updateAllOptions() {
  431. final Context context = getActivity();
  432. final ContentResolver cr = context.getContentResolver();
  433. mHaveDebugSettings = false;
  434. /// M: fix [ALPS00244115] Lock and unlock screen, the "USB debugging" is unchecked @{
  435. if (mAdbDialog != null && mAdbDialog.isShowing()) {
  436. updateCheckBox(mEnableAdb,true);
  437. } else {
  438. updateCheckBox(mEnableAdb, Settings.Global.getInt(cr,
  439. Settings.Global.ADB_ENABLED, 0) != 0);
  440. }
  441. /// @}
  442.  
  443. updateCheckBox(mBugreportInPower, Settings.Secure.getInt(cr,
  444. Settings.Secure.BUGREPORT_IN_POWER_MENU, 0) != 0);
  445. updateCheckBox(mKeepScreenOn, Settings.Global.getInt(cr,
  446. Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0) != 0);
  447. updateCheckBox(mEnforceReadExternal, isPermissionEnforced(READ_EXTERNAL_STORAGE));
  448. updateCheckBox(mAllowMockLocation, Settings.Secure.getInt(cr,
  449. Settings.Secure.ALLOW_MOCK_LOCATION, 0) != 0);
  450. updateHdcpValues();
  451. updatePasswordSummary();
  452. updateDebuggerOptions();
  453. updateStrictModeVisualOptions();
  454. updatePointerLocationOptions();
  455. updateShowTouchesOptions();
  456. updateFlingerOptions();
  457. updateCpuUsageOptions();
  458. updateHardwareUiOptions();
  459. updateMsaaOptions();
  460. updateTrackFrameTimeOptions();
  461. updateShowHwScreenUpdatesOptions();
  462. updateShowHwLayersUpdatesOptions();
  463. updateShowHwOverdrawOptions();
  464. updateDebugLayoutOptions();
  465. updateAnimationScaleOptions();
  466. updateOverlayDisplayDevicesOptions();
  467. updateOpenGLTracesOptions();
  468. updateEnableTracesOptions();
  469. updateImmediatelyDestroyActivitiesOptions();
  470. updateAppProcessLimitOptions();
  471. updateShowAllANRsOptions();
  472. updateVerifyAppsOverUsbOptions();
  473. updateBugreportOptions();
  474. }
  475.  
  476. private void resetDangerousOptions() {
  477. mDontPokeProperties = true;
  478. for (int i=0; i<mResetCbPrefs.size(); i++) {
  479. CheckBoxPreference cb = mResetCbPrefs.get(i);
  480. if (cb.isChecked()) {
  481. cb.setChecked(false);
  482. onPreferenceTreeClick(null, cb);
  483. }
  484. }
  485. resetDebuggerOptions();
  486. writeAnimationScaleOption(0, mWindowAnimationScale, null);
  487. writeAnimationScaleOption(1, mTransitionAnimationScale, null);
  488. writeAnimationScaleOption(2, mAnimatorDurationScale, null);
  489. writeOverlayDisplayDevicesOptions(null);
  490. writeEnableTracesOptions(0);
  491. writeAppProcessLimitOptions(null);
  492. mHaveDebugSettings = false;
  493. updateAllOptions();
  494. mDontPokeProperties = false;
  495. pokeSystemProperties();
  496. }
  497.  
  498. private void updateHdcpValues() {
  499. int index = 1; // Defaults to drm-only. Needs to match with R.array.hdcp_checking_values
  500. ListPreference hdcpChecking = (ListPreference) findPreference(HDCP_CHECKING_KEY);
  501. if (hdcpChecking != null) {
  502. String currentValue = SystemProperties.get(HDCP_CHECKING_PROPERTY);
  503. String[] values = getResources().getStringArray(R.array.hdcp_checking_values);
  504. String[] summaries = getResources().getStringArray(R.array.hdcp_checking_summaries);
  505. for (int i = 0; i < values.length; i++) {
  506. if (currentValue.equals(values[i])) {
  507. index = i;
  508. break;
  509. }
  510. }
  511. hdcpChecking.setValue(values[index]);
  512. hdcpChecking.setSummary(summaries[index]);
  513. hdcpChecking.setOnPreferenceChangeListener(this);
  514. }
  515. }
  516.  
  517. private void updatePasswordSummary() {
  518. try {
  519. if (mBackupManager.hasBackupPassword()) {
  520. mPassword.setSummary(R.string.local_backup_password_summary_change);
  521. } else {
  522. mPassword.setSummary(R.string.local_backup_password_summary_none);
  523. }
  524. } catch (RemoteException e) {
  525. // Not much we can do here
  526. }
  527. }
  528.  
  529. private void writeDebuggerOptions() {
  530. try {
  531. ActivityManagerNative.getDefault().setDebugApp(
  532. mDebugApp, mWaitForDebugger.isChecked(), true);
  533. } catch (RemoteException ex) {
  534. }
  535. }
  536.  
  537. private static void resetDebuggerOptions() {
  538. try {
  539. ActivityManagerNative.getDefault().setDebugApp(
  540. null, false, true);
  541. } catch (RemoteException ex) {
  542. }
  543. }
  544.  
  545. private void updateDebuggerOptions() {
  546. mDebugApp = Settings.Global.getString(
  547. getActivity().getContentResolver(), Settings.Global.DEBUG_APP);
  548. updateCheckBox(mWaitForDebugger, Settings.Global.getInt(
  549. getActivity().getContentResolver(), Settings.Global.WAIT_FOR_DEBUGGER, 0) != 0);
  550. if (mDebugApp != null && mDebugApp.length() > 0) {
  551. String label;
  552. try {
  553. ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(mDebugApp,
  554. PackageManager.GET_DISABLED_COMPONENTS);
  555. CharSequence lab = getActivity().getPackageManager().getApplicationLabel(ai);
  556. label = lab != null ? lab.toString() : mDebugApp;
  557. } catch (PackageManager.NameNotFoundException e) {
  558. label = mDebugApp;
  559. }
  560. mDebugAppPref.setSummary(getResources().getString(R.string.debug_app_set, label));
  561. mWaitForDebugger.setEnabled(true);
  562. mHaveDebugSettings = true;
  563. } else {
  564. mDebugAppPref.setSummary(getResources().getString(R.string.debug_app_not_set));
  565. mWaitForDebugger.setEnabled(false);
  566. }
  567. }
  568.  
  569. private void updateVerifyAppsOverUsbOptions() {
  570. updateCheckBox(mVerifyAppsOverUsb, Settings.Global.getInt(getActivity().getContentResolver(),
  571. Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1) != 0);
  572. mVerifyAppsOverUsb.setEnabled(enableVerifierSetting());
  573. }
  574.  
  575. private void writeVerifyAppsOverUsbOptions() {
  576. Settings.Global.putInt(getActivity().getContentResolver(),
  577. Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, mVerifyAppsOverUsb.isChecked() ? 1 : 0);
  578. }
  579.  
  580. private boolean enableVerifierSetting() {
  581. final ContentResolver cr = getActivity().getContentResolver();
  582. if (Settings.Global.getInt(cr, Settings.Global.ADB_ENABLED, 0) == 0) {
  583. return false;
  584. }
  585. if (Settings.Global.getInt(cr, Settings.Global.PACKAGE_VERIFIER_ENABLE, 1) == 0) {
  586. return false;
  587. } else {
  588. final PackageManager pm = getActivity().getPackageManager();
  589. final Intent verification = new Intent(Intent.ACTION_PACKAGE_NEEDS_VERIFICATION);
  590. verification.setType(PACKAGE_MIME_TYPE);
  591. verification.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
  592. final List<ResolveInfo> receivers = pm.queryBroadcastReceivers(verification, 0);
  593. if (receivers.size() == 0) {
  594. return false;
  595. }
  596. }
  597. return true;
  598. }
  599.  
  600. private boolean showVerifierSetting() {
  601. return Settings.Global.getInt(getActivity().getContentResolver(),
  602. Settings.Global.PACKAGE_VERIFIER_SETTING_VISIBLE, 1) > 0;
  603. }
  604.  
  605. private void updateBugreportOptions() {
  606. if ("user".equals(Build.TYPE)) {
  607. final ContentResolver resolver = getActivity().getContentResolver();
  608. final boolean adbEnabled = Settings.Global.getInt(
  609. resolver, Settings.Global.ADB_ENABLED, 0) != 0;
  610. if (adbEnabled) {
  611. mBugreport.setEnabled(true);
  612. mBugreportInPower.setEnabled(true);
  613. } else {
  614. mBugreport.setEnabled(false);
  615. mBugreportInPower.setEnabled(false);
  616. mBugreportInPower.setChecked(false);
  617. Settings.Secure.putInt(resolver, Settings.Secure.BUGREPORT_IN_POWER_MENU, 0);
  618. }
  619. } else {
  620. mBugreportInPower.setEnabled(true);
  621. }
  622. }
  623.  
  624. // Returns the current state of the system property that controls
  625. // strictmode flashes. One of:
  626. // 0: not explicitly set one way or another
  627. // 1: on
  628. // 2: off
  629. private static int currentStrictModeActiveIndex() {
  630. if (TextUtils.isEmpty(SystemProperties.get(StrictMode.VISUAL_PROPERTY))) {
  631. return 0;
  632. }
  633. boolean enabled = SystemProperties.getBoolean(StrictMode.VISUAL_PROPERTY, false);
  634. return enabled ? 1 : 2;
  635. }
  636.  
  637. private void writeStrictModeVisualOptions() {
  638. try {
  639. mWindowManager.setStrictModeVisualIndicatorPreference(mStrictMode.isChecked()
  640. ? "1" : "");
  641. } catch (RemoteException e) {
  642. }
  643. }
  644.  
  645. private void updateStrictModeVisualOptions() {
  646. updateCheckBox(mStrictMode, currentStrictModeActiveIndex() == 1);
  647. }
  648.  
  649. private void writePointerLocationOptions() {
  650. Settings.System.putInt(getActivity().getContentResolver(),
  651. Settings.System.POINTER_LOCATION, mPointerLocation.isChecked() ? 1 : 0);
  652. }
  653.  
  654. private void updatePointerLocationOptions() {
  655. updateCheckBox(mPointerLocation, Settings.System.getInt(getActivity().getContentResolver(),
  656. Settings.System.POINTER_LOCATION, 0) != 0);
  657. }
  658.  
  659. private void writeShowTouchesOptions() {
  660. Settings.System.putInt(getActivity().getContentResolver(),
  661. Settings.System.SHOW_TOUCHES, mShowTouches.isChecked() ? 1 : 0);
  662. }
  663.  
  664. private void updateShowTouchesOptions() {
  665. updateCheckBox(mShowTouches, Settings.System.getInt(getActivity().getContentResolver(),
  666. Settings.System.SHOW_TOUCHES, 0) != 0);
  667. }
  668.  
  669. private void updateFlingerOptions() {
  670. // magic communication with surface flinger.
  671. try {
  672. IBinder flinger = ServiceManager.getService("SurfaceFlinger");
  673. if (flinger != null) {
  674. Parcel data = Parcel.obtain();
  675. Parcel reply = Parcel.obtain();
  676. data.writeInterfaceToken("android.ui.ISurfaceComposer");
  677. flinger.transact(1010, data, reply, 0);
  678. @SuppressWarnings("unused")
  679. int showCpu = reply.readInt();
  680. @SuppressWarnings("unused")
  681. int enableGL = reply.readInt();
  682. int showUpdates = reply.readInt();
  683. updateCheckBox(mShowScreenUpdates, showUpdates != 0);
  684. @SuppressWarnings("unused")
  685. int showBackground = reply.readInt();
  686. int disableOverlays = reply.readInt();
  687. updateCheckBox(mDisableOverlays, disableOverlays != 0);
  688. reply.recycle();
  689. data.recycle();
  690. }
  691. } catch (RemoteException ex) {
  692. }
  693. }
  694.  
  695. private void writeShowUpdatesOption() {
  696. try {
  697. IBinder flinger = ServiceManager.getService("SurfaceFlinger");
  698. if (flinger != null) {
  699. Parcel data = Parcel.obtain();
  700. data.writeInterfaceToken("android.ui.ISurfaceComposer");
  701. final int showUpdates = mShowScreenUpdates.isChecked() ? 1 : 0;
  702. data.writeInt(showUpdates);
  703. flinger.transact(1002, data, null, 0);
  704. data.recycle();
  705.  
  706. updateFlingerOptions();
  707. }
  708. } catch (RemoteException ex) {
  709. }
  710. }
  711.  
  712. private void writeDisableOverlaysOption() {
  713. try {
  714. IBinder flinger = ServiceManager.getService("SurfaceFlinger");
  715. if (flinger != null) {
  716. Parcel data = Parcel.obtain();
  717. data.writeInterfaceToken("android.ui.ISurfaceComposer");
  718. final int disableOverlays = mDisableOverlays.isChecked() ? 1 : 0;
  719. data.writeInt(disableOverlays);
  720. flinger.transact(1008, data, null, 0);
  721. data.recycle();
  722.  
  723. updateFlingerOptions();
  724. }
  725. } catch (RemoteException ex) {
  726. }
  727. }
  728.  
  729. private void updateHardwareUiOptions() {
  730. updateCheckBox(mForceHardwareUi, SystemProperties.getBoolean(HARDWARE_UI_PROPERTY, false));
  731. }
  732.  
  733. private void writeHardwareUiOptions() {
  734. SystemProperties.set(HARDWARE_UI_PROPERTY, mForceHardwareUi.isChecked() ? "true" : "false");
  735. pokeSystemProperties();
  736. }
  737.  
  738. private void updateMsaaOptions() {
  739. updateCheckBox(mForceMsaa, SystemProperties.getBoolean(MSAA_PROPERTY, false));
  740. }
  741.  
  742. private void writeMsaaOptions() {
  743. SystemProperties.set(MSAA_PROPERTY, mForceMsaa.isChecked() ? "true" : "false");
  744. pokeSystemProperties();
  745. }
  746.  
  747. private void updateTrackFrameTimeOptions() {
  748. updateCheckBox(mTrackFrameTime,
  749. SystemProperties.getBoolean(HardwareRenderer.PROFILE_PROPERTY, false));
  750. }
  751.  
  752. private void writeTrackFrameTimeOptions() {
  753. SystemProperties.set(HardwareRenderer.PROFILE_PROPERTY,
  754. mTrackFrameTime.isChecked() ? "true" : "false");
  755. pokeSystemProperties();
  756. }
  757.  
  758. private void updateShowHwScreenUpdatesOptions() {
  759. updateCheckBox(mShowHwScreenUpdates,
  760. SystemProperties.getBoolean(HardwareRenderer.DEBUG_DIRTY_REGIONS_PROPERTY, false));
  761. }
  762.  
  763. private void writeShowHwScreenUpdatesOptions() {
  764. SystemProperties.set(HardwareRenderer.DEBUG_DIRTY_REGIONS_PROPERTY,
  765. mShowHwScreenUpdates.isChecked() ? "true" : null);
  766. pokeSystemProperties();
  767. }
  768.  
  769. private void updateShowHwLayersUpdatesOptions() {
  770. updateCheckBox(mShowHwLayersUpdates, SystemProperties.getBoolean(
  771. HardwareRenderer.DEBUG_SHOW_LAYERS_UPDATES_PROPERTY, false));
  772. }
  773.  
  774. private void writeShowHwLayersUpdatesOptions() {
  775. SystemProperties.set(HardwareRenderer.DEBUG_SHOW_LAYERS_UPDATES_PROPERTY,
  776. mShowHwLayersUpdates.isChecked() ? "true" : null);
  777. pokeSystemProperties();
  778. }
  779.  
  780. private void updateShowHwOverdrawOptions() {
  781. updateCheckBox(mShowHwOverdraw, SystemProperties.getBoolean(
  782. HardwareRenderer.DEBUG_SHOW_OVERDRAW_PROPERTY, false));
  783. }
  784.  
  785. private void writeShowHwOverdrawOptions() {
  786. SystemProperties.set(HardwareRenderer.DEBUG_SHOW_OVERDRAW_PROPERTY,
  787. mShowHwOverdraw.isChecked() ? "true" : null);
  788. pokeSystemProperties();
  789. }
  790.  
  791. private void updateDebugLayoutOptions() {
  792. updateCheckBox(mDebugLayout,
  793. SystemProperties.getBoolean(View.DEBUG_LAYOUT_PROPERTY, false));
  794. }
  795.  
  796. private void writeDebugLayoutOptions() {
  797. SystemProperties.set(View.DEBUG_LAYOUT_PROPERTY,
  798. mDebugLayout.isChecked() ? "true" : "false");
  799. pokeSystemProperties();
  800. }
  801.  
  802. private void updateCpuUsageOptions() {
  803. updateCheckBox(mShowCpuUsage, Settings.Global.getInt(getActivity().getContentResolver(),
  804. Settings.Global.SHOW_PROCESSES, 0) != 0);
  805. }
  806.  
  807. private void writeCpuUsageOptions() {
  808. boolean value = mShowCpuUsage.isChecked();
  809. Settings.Global.putInt(getActivity().getContentResolver(),
  810. Settings.Global.SHOW_PROCESSES, value ? 1 : 0);
  811. Intent service = (new Intent())
  812. .setClassName("com.android.systemui", "com.android.systemui.LoadAverageService");
  813. if (value) {
  814. getActivity().startService(service);
  815. } else {
  816. getActivity().stopService(service);
  817. }
  818. }
  819.  
  820. private void writeImmediatelyDestroyActivitiesOptions() {
  821. try {
  822. ActivityManagerNative.getDefault().setAlwaysFinish(
  823. mImmediatelyDestroyActivities.isChecked());
  824. } catch (RemoteException ex) {
  825. }
  826. }
  827.  
  828. private void updateImmediatelyDestroyActivitiesOptions() {
  829. updateCheckBox(mImmediatelyDestroyActivities, Settings.Global.getInt(
  830. getActivity().getContentResolver(), Settings.Global.ALWAYS_FINISH_ACTIVITIES, 0) != 0);
  831. }
  832.  
  833. private void updateAnimationScaleValue(int which, ListPreference pref) {
  834. try {
  835. float scale = mWindowManager.getAnimationScale(which);
  836. if (scale != 1) {
  837. mHaveDebugSettings = true;
  838. }
  839. CharSequence[] values = pref.getEntryValues();
  840. for (int i=0; i<values.length; i++) {
  841. float val = Float.parseFloat(values[i].toString());
  842. if (scale <= val) {
  843. pref.setValueIndex(i);
  844. pref.setSummary(pref.getEntries()[i]);
  845. return;
  846. }
  847. }
  848. pref.setValueIndex(values.length-1);
  849. pref.setSummary(pref.getEntries()[0]);
  850. } catch (RemoteException e) {
  851. }
  852. }
  853.  
  854. private void updateAnimationScaleOptions() {
  855. updateAnimationScaleValue(0, mWindowAnimationScale);
  856. updateAnimationScaleValue(1, mTransitionAnimationScale);
  857. updateAnimationScaleValue(2, mAnimatorDurationScale);
  858. }
  859.  
  860. private void writeAnimationScaleOption(int which, ListPreference pref, Object newValue) {
  861. try {
  862. float scale = newValue != null ? Float.parseFloat(newValue.toString()) : 1;
  863. mWindowManager.setAnimationScale(which, scale);
  864. updateAnimationScaleValue(which, pref);
  865. } catch (RemoteException e) {
  866. }
  867. }
  868.  
  869. private void updateOverlayDisplayDevicesOptions() {
  870. String value = Settings.Global.getString(getActivity().getContentResolver(),
  871. Settings.Global.OVERLAY_DISPLAY_DEVICES);
  872. if (value == null) {
  873. value = "";
  874. }
  875.  
  876. CharSequence[] values = mOverlayDisplayDevices.getEntryValues();
  877. for (int i = 0; i < values.length; i++) {
  878. if (value.contentEquals(values[i])) {
  879. mOverlayDisplayDevices.setValueIndex(i);
  880. mOverlayDisplayDevices.setSummary(mOverlayDisplayDevices.getEntries()[i]);
  881. return;
  882. }
  883. }
  884. mOverlayDisplayDevices.setValueIndex(0);
  885. mOverlayDisplayDevices.setSummary(mOverlayDisplayDevices.getEntries()[0]);
  886. }
  887.  
  888. private void writeOverlayDisplayDevicesOptions(Object newValue) {
  889. Settings.Global.putString(getActivity().getContentResolver(),
  890. Settings.Global.OVERLAY_DISPLAY_DEVICES, (String)newValue);
  891. updateOverlayDisplayDevicesOptions();
  892. }
  893.  
  894. private void updateOpenGLTracesOptions() {
  895. String value = SystemProperties.get(OPENGL_TRACES_PROPERTY);
  896. if (value == null) {
  897. value = "";
  898. }
  899.  
  900. CharSequence[] values = mOpenGLTraces.getEntryValues();
  901. for (int i = 0; i < values.length; i++) {
  902. if (value.contentEquals(values[i])) {
  903. mOpenGLTraces.setValueIndex(i);
  904. mOpenGLTraces.setSummary(mOpenGLTraces.getEntries()[i]);
  905. return;
  906. }
  907. }
  908. mOpenGLTraces.setValueIndex(0);
  909. mOpenGLTraces.setSummary(mOpenGLTraces.getEntries()[0]);
  910. }
  911.  
  912. private void writeOpenGLTracesOptions(Object newValue) {
  913. SystemProperties.set(OPENGL_TRACES_PROPERTY, newValue == null ? "" : newValue.toString());
  914. pokeSystemProperties();
  915. updateOpenGLTracesOptions();
  916. }
  917.  
  918. private void updateAppProcessLimitOptions() {
  919. try {
  920. int limit = ActivityManagerNative.getDefault().getProcessLimit();
  921. CharSequence[] values = mAppProcessLimit.getEntryValues();
  922. for (int i=0; i<values.length; i++) {
  923. int val = Integer.parseInt(values[i].toString());
  924. if (val >= limit) {
  925. if (i != 0) {
  926. mHaveDebugSettings = true;
  927. }
  928. mAppProcessLimit.setValueIndex(i);
  929. mAppProcessLimit.setSummary(mAppProcessLimit.getEntries()[i]);
  930. return;
  931. }
  932. }
  933. mAppProcessLimit.setValueIndex(0);
  934. mAppProcessLimit.setSummary(mAppProcessLimit.getEntries()[0]);
  935. } catch (RemoteException e) {
  936. }
  937. }
  938.  
  939. private void writeAppProcessLimitOptions(Object newValue) {
  940. try {
  941. int limit = newValue != null ? Integer.parseInt(newValue.toString()) : -1;
  942. ActivityManagerNative.getDefault().setProcessLimit(limit);
  943. updateAppProcessLimitOptions();
  944. } catch (RemoteException e) {
  945. }
  946. }
  947.  
  948. private void writeShowAllANRsOptions() {
  949. Settings.Secure.putInt(getActivity().getContentResolver(),
  950. Settings.Secure.ANR_SHOW_BACKGROUND,
  951. mShowAllANRs.isChecked() ? 1 : 0);
  952. }
  953.  
  954. private void updateShowAllANRsOptions() {
  955. updateCheckBox(mShowAllANRs, Settings.Secure.getInt(
  956. getActivity().getContentResolver(), Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0);
  957. }
  958.  
  959. private void updateEnableTracesOptions() {
  960. long flags = SystemProperties.getLong(Trace.PROPERTY_TRACE_TAG_ENABLEFLAGS, 0);
  961. String[] values = mEnableTracesPref.getEntryValues();
  962. int numSet = 0;
  963. // {@ M: ALPS00592231
  964. for (int i=Trace.TRACE_FLAGS_START_BIT; i<=values.length; i++) { // @}
  965. boolean set = (flags&(1<<i)) != 0;
  966. mEnableTracesPref.setValue(i-Trace.TRACE_FLAGS_START_BIT, set);
  967. if (set) {
  968. numSet++;
  969. }
  970. }
  971. if (numSet == 0) {
  972. mEnableTracesPref.setSummary(R.string.enable_traces_summary_none);
  973. } else if (numSet == values.length) {
  974. mHaveDebugSettings = true;
  975. mEnableTracesPref.setSummary(R.string.enable_traces_summary_all);
  976. } else {
  977. mHaveDebugSettings = true;
  978. mEnableTracesPref.setSummary(getString(R.string.enable_traces_summary_num, numSet));
  979. }
  980. }
  981.  
  982. private void writeEnableTracesOptions() {
  983. long value = 0;
  984. String[] values = mEnableTracesPref.getEntryValues();
  985. // {@ M: ALPS00592231
  986. for (int i=Trace.TRACE_FLAGS_START_BIT; i<=values.length; i++) { // @}
  987. if (mEnableTracesPref.getValue(i-Trace.TRACE_FLAGS_START_BIT)) {
  988. value |= 1<<i;
  989. }
  990. }
  991. writeEnableTracesOptions(value);
  992. // Make sure summary is updated.
  993. updateEnableTracesOptions();
  994. }
  995.  
  996. private void writeEnableTracesOptions(long value) {
  997. SystemProperties.set(Trace.PROPERTY_TRACE_TAG_ENABLEFLAGS,
  998. "0x" + Long.toString(value, 16));
  999. pokeSystemProperties();
  1000. }
  1001.  
  1002. @Override
  1003. public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  1004. if (buttonView == mEnabledSwitch) {
  1005. if (isChecked != mLastEnabledState) {
  1006. if (isChecked) {
  1007. mDialogClicked = false;
  1008. if (mEnableDialog != null) dismissDialogs();
  1009. mEnableDialog = new AlertDialog.Builder(getActivity()).setMessage(
  1010. getActivity().getResources().getString(
  1011. R.string.dev_settings_warning_message))
  1012. .setTitle(R.string.dev_settings_warning_title)
  1013. .setIconAttribute(android.R.attr.alertDialogIcon)
  1014. .setPositiveButton(android.R.string.yes, this)
  1015. .setNegativeButton(android.R.string.no, this)
  1016. .show();
  1017. mEnableDialog.setOnDismissListener(this);
  1018. } else {
  1019. resetDangerousOptions();
  1020. Settings.Global.putInt(getActivity().getContentResolver(),
  1021. Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
  1022. mLastEnabledState = isChecked;
  1023. setPrefsEnabledState(mLastEnabledState);
  1024. }
  1025. }
  1026. }
  1027. }
  1028.  
  1029. @Override
  1030. public void onActivityResult(int requestCode, int resultCode, Intent data) {
  1031. if (requestCode == RESULT_DEBUG_APP) {
  1032. if (resultCode == Activity.RESULT_OK) {
  1033. mDebugApp = data.getAction();
  1034. writeDebuggerOptions();
  1035. updateDebuggerOptions();
  1036. }
  1037. } else {
  1038. super.onActivityResult(requestCode, resultCode, data);
  1039. }
  1040. }
  1041.  
  1042. @Override
  1043. public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
  1044.  
  1045. if (Utils.isMonkeyRunning()) {
  1046. return false;
  1047. }
  1048.  
  1049. if (preference == mEnableAdb) {
  1050. if (mEnableAdb.isChecked()) {
  1051. mDialogClicked = false;
  1052. if (mAdbDialog != null) dismissDialogs();
  1053. mAdbDialog = new AlertDialog.Builder(getActivity()).setMessage(
  1054. getActivity().getResources().getString(R.string.adb_warning_message))
  1055. .setTitle(R.string.adb_warning_title)
  1056. .setIconAttribute(android.R.attr.alertDialogIcon)
  1057. .setPositiveButton(android.R.string.yes, this)
  1058. .setNegativeButton(android.R.string.no, this)
  1059. .show();
  1060. mAdbDialog.setOnDismissListener(this);
  1061. } else {
  1062. Settings.Global.putInt(getActivity().getContentResolver(),
  1063. Settings.Global.ADB_ENABLED, 0);
  1064. mVerifyAppsOverUsb.setEnabled(false);
  1065. mVerifyAppsOverUsb.setChecked(false);
  1066. updateBugreportOptions();
  1067. }
  1068. } else if (preference == mBugreportInPower) {
  1069. Settings.Secure.putInt(getActivity().getContentResolver(),
  1070. Settings.Secure.BUGREPORT_IN_POWER_MENU,
  1071. mBugreportInPower.isChecked() ? 1 : 0);
  1072. } else if (preference == mKeepScreenOn) {
  1073. Settings.Global.putInt(getActivity().getContentResolver(),
  1074. Settings.Global.STAY_ON_WHILE_PLUGGED_IN,
  1075. mKeepScreenOn.isChecked() ?
  1076. (BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB) : 0);
  1077. } else if (preference == mEnforceReadExternal) {
  1078. if (mEnforceReadExternal.isChecked()) {
  1079. ConfirmEnforceFragment.show(this);
  1080. } else {
  1081. setPermissionEnforced(getActivity(), READ_EXTERNAL_STORAGE, false);
  1082. }
  1083. } else if (preference == mAllowMockLocation) {
  1084. Settings.Secure.putInt(getActivity().getContentResolver(),
  1085. Settings.Secure.ALLOW_MOCK_LOCATION,
  1086. mAllowMockLocation.isChecked() ? 1 : 0);
  1087. } else if (preference == mDebugAppPref) {
  1088. startActivityForResult(new Intent(getActivity(), AppPicker.class), RESULT_DEBUG_APP);
  1089. } else if (preference == mWaitForDebugger) {
  1090. writeDebuggerOptions();
  1091. } else if (preference == mVerifyAppsOverUsb) {
  1092. writeVerifyAppsOverUsbOptions();
  1093. } else if (preference == mStrictMode) {
  1094. writeStrictModeVisualOptions();
  1095. } else if (preference == mPointerLocation) {
  1096. writePointerLocationOptions();
  1097. } else if (preference == mShowTouches) {
  1098. writeShowTouchesOptions();
  1099. } else if (preference == mShowScreenUpdates) {
  1100. writeShowUpdatesOption();
  1101. } else if (preference == mDisableOverlays) {
  1102. writeDisableOverlaysOption();
  1103. } else if (preference == mShowCpuUsage) {
  1104. writeCpuUsageOptions();
  1105. } else if (preference == mImmediatelyDestroyActivities) {
  1106. writeImmediatelyDestroyActivitiesOptions();
  1107. } else if (preference == mShowAllANRs) {
  1108. writeShowAllANRsOptions();
  1109. } else if (preference == mForceHardwareUi) {
  1110. writeHardwareUiOptions();
  1111. } else if (preference == mForceMsaa) {
  1112. writeMsaaOptions();
  1113. } else if (preference == mTrackFrameTime) {
  1114. writeTrackFrameTimeOptions();
  1115. } else if (preference == mShowHwScreenUpdates) {
  1116. writeShowHwScreenUpdatesOptions();
  1117. } else if (preference == mShowHwLayersUpdates) {
  1118. writeShowHwLayersUpdatesOptions();
  1119. } else if (preference == mShowHwOverdraw) {
  1120. writeShowHwOverdrawOptions();
  1121. } else if (preference == mDebugLayout) {
  1122. writeDebugLayoutOptions();
  1123. }
  1124.  
  1125. return false;
  1126. }
  1127.  
  1128. @Override
  1129. public boolean onPreferenceChange(Preference preference, Object newValue) {
  1130. if (HDCP_CHECKING_KEY.equals(preference.getKey())) {
  1131. SystemProperties.set(HDCP_CHECKING_PROPERTY, newValue.toString());
  1132. updateHdcpValues();
  1133. pokeSystemProperties();
  1134. return true;
  1135. } else if (preference == mWindowAnimationScale) {
  1136. writeAnimationScaleOption(0, mWindowAnimationScale, newValue);
  1137. return true;
  1138. } else if (preference == mTransitionAnimationScale) {
  1139. writeAnimationScaleOption(1, mTransitionAnimationScale, newValue);
  1140. return true;
  1141. } else if (preference == mAnimatorDurationScale) {
  1142. writeAnimationScaleOption(2, mAnimatorDurationScale, newValue);
  1143. return true;
  1144. } else if (preference == mOverlayDisplayDevices) {
  1145. writeOverlayDisplayDevicesOptions(newValue);
  1146. return true;
  1147. } else if (preference == mOpenGLTraces) {
  1148. writeOpenGLTracesOptions(newValue);
  1149. return true;
  1150. } else if (preference == mEnableTracesPref) {
  1151. writeEnableTracesOptions();
  1152. return true;
  1153. } else if (preference == mAppProcessLimit) {
  1154. writeAppProcessLimitOptions(newValue);
  1155. return true;
  1156. }
  1157. return false;
  1158. }
  1159.  
  1160. private void dismissDialogs() {
  1161. if (mAdbDialog != null) {
  1162. mAdbDialog.dismiss();
  1163. mAdbDialog = null;
  1164. }
  1165. if (mEnableDialog != null) {
  1166. mEnableDialog.dismiss();
  1167. mEnableDialog = null;
  1168. }
  1169. }
  1170.  
  1171. public void onClick(DialogInterface dialog, int which) {
  1172. if (dialog == mAdbDialog) {
  1173. if (which == DialogInterface.BUTTON_POSITIVE) {
  1174. mDialogClicked = true;
  1175. Settings.Global.putInt(getActivity().getContentResolver(),
  1176. Settings.Global.ADB_ENABLED, 1);
  1177. mVerifyAppsOverUsb.setEnabled(true);
  1178. updateVerifyAppsOverUsbOptions();
  1179. updateBugreportOptions();
  1180. } else {
  1181. // Reset the toggle
  1182. mEnableAdb.setChecked(false);
  1183. }
  1184. } else if (dialog == mEnableDialog) {
  1185. if (which == DialogInterface.BUTTON_POSITIVE) {
  1186. mDialogClicked = true;
  1187. Settings.Global.putInt(getActivity().getContentResolver(),
  1188. Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
  1189. mLastEnabledState = true;
  1190. /// M: mtk54279 see CR[ALPS00327180]
  1191. mEnabledSwitch.setChecked(mLastEnabledState);
  1192. /// M: end
  1193. setPrefsEnabledState(mLastEnabledState);
  1194. } else {
  1195. // Reset the toggle
  1196. mEnabledSwitch.setChecked(false);
  1197. }
  1198. }
  1199. }
  1200.  
  1201. public void onDismiss(DialogInterface dialog) {
  1202. // Assuming that onClick gets called first
  1203. if (dialog == mAdbDialog) {
  1204. if (!mDialogClicked) {
  1205. mEnableAdb.setChecked(false);
  1206. }
  1207. mAdbDialog = null;
  1208. } else if (dialog == mEnableDialog) {
  1209. if (!mDialogClicked) {
  1210. mEnabledSwitch.setChecked(false);
  1211. }
  1212. mEnableDialog = null;
  1213. }
  1214. }
  1215.  
  1216. @Override
  1217. public void onDestroy() {
  1218. dismissDialogs();
  1219. super.onDestroy();
  1220. }
  1221.  
  1222. void pokeSystemProperties() {
  1223. if (!mDontPokeProperties) {
  1224. //noinspection unchecked
  1225. (new SystemPropPoker()).execute();
  1226. }
  1227. }
  1228.  
  1229. static class SystemPropPoker extends AsyncTask<Void, Void, Void> {
  1230. @Override
  1231. protected Void doInBackground(Void... params) {
  1232. String[] services;
  1233. try {
  1234. services = ServiceManager.listServices();
  1235. } catch (RemoteException e) {
  1236. return null;
  1237. }
  1238. for (String service : services) {
  1239. IBinder obj = ServiceManager.checkService(service);
  1240. if (obj != null) {
  1241. Parcel data = Parcel.obtain();
  1242. try {
  1243. obj.transact(IBinder.SYSPROPS_TRANSACTION, data, null, 0);
  1244. } catch (RemoteException e) {
  1245. } catch (Exception e) {
  1246. Log.i("DevSettings", "Somone wrote a bad service '" + service
  1247. + "' that doesn't like to be poked: " + e);
  1248. }
  1249. data.recycle();
  1250. }
  1251. }
  1252. return null;
  1253. }
  1254. }
  1255.  
  1256. /**
  1257. * Dialog to confirm enforcement of {@link android.Manifest.permission#READ_EXTERNAL_STORAGE}.
  1258. */
  1259. public static class ConfirmEnforceFragment extends DialogFragment {
  1260. public static void show(DevelopmentSettings parent) {
  1261. final ConfirmEnforceFragment dialog = new ConfirmEnforceFragment();
  1262. dialog.setTargetFragment(parent, 0);
  1263. dialog.show(parent.getFragmentManager(), TAG_CONFIRM_ENFORCE);
  1264. }
  1265.  
  1266. @Override
  1267. public Dialog onCreateDialog(Bundle savedInstanceState) {
  1268. final Context context = getActivity();
  1269.  
  1270. final AlertDialog.Builder builder = new AlertDialog.Builder(context);
  1271. builder.setTitle(R.string.enforce_read_external_confirm_title);
  1272. builder.setMessage(R.string.enforce_read_external_confirm_message);
  1273.  
  1274. builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
  1275. @Override
  1276. public void onClick(DialogInterface dialog, int which) {
  1277. setPermissionEnforced(context, READ_EXTERNAL_STORAGE, true);
  1278. ((DevelopmentSettings) getTargetFragment()).updateAllOptions();
  1279. }
  1280. });
  1281. builder.setNegativeButton(android.R.string.cancel, new OnClickListener() {
  1282. @Override
  1283. public void onClick(DialogInterface dialog, int which) {
  1284. ((DevelopmentSettings) getTargetFragment()).updateAllOptions();
  1285. }
  1286. });
  1287.  
  1288. return builder.create();
  1289. }
  1290. }
  1291.  
  1292. private static boolean isPermissionEnforced(String permission) {
  1293. try {
  1294. return ActivityThread.getPackageManager().isPermissionEnforced(permission);
  1295. } catch (RemoteException e) {
  1296. throw new RuntimeException("Problem talking with PackageManager", e);
  1297. }
  1298. }
  1299.  
  1300. private static void setPermissionEnforced(
  1301. Context context, String permission, boolean enforced) {
  1302. try {
  1303. // TODO: offload to background thread
  1304. ActivityThread.getPackageManager()
  1305. .setPermissionEnforced(READ_EXTERNAL_STORAGE, enforced);
  1306. } catch (RemoteException e) {
  1307. throw new RuntimeException("Problem talking with PackageManager", e);
  1308. }
  1309. }
  1310.  
  1311. /** M: mtk54279
  1312. * this is invoke for rotation configuration changed
  1313. * fix the checkbox list layout did not on the the same line level
  1314. */
  1315. @Override
  1316. public void onConfigurationChanged(Configuration newConfig) {
  1317. super.onConfigurationChanged(newConfig);
  1318. Xlog.d(TAG,"-->onConfigurationChanged");
  1319. getListView().clearScrapViewsIfNeeded();
  1320. }
  1321. }
  1322.  
  1323.  
  1324. ERROR:
  1325.  
  1326. Description Resource Path Location Type
  1327. ActivityManagerNative cannot be resolved DevelopmentSettings.java /AdvancedSettings/src/com/android/settings line 920 Java Problem
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement