OSDN Git Service

resolved conflicts for merge of c2c64a31 to master
[android-x86/packages-apps-Settings.git] / src / com / android / settings / DevelopmentSettings.java
index a16f8b6..02045ab 100644 (file)
@@ -34,6 +34,7 @@ import android.content.pm.PackageManager;
 import android.content.pm.PackageManager.NameNotFoundException;
 import android.content.pm.ResolveInfo;
 import android.hardware.usb.IUsbManager;
+import android.net.wifi.WifiManager;
 import android.os.AsyncTask;
 import android.os.BatteryManager;
 import android.os.Build;
@@ -46,6 +47,7 @@ import android.os.ServiceManager;
 import android.os.StrictMode;
 import android.os.SystemProperties;
 import android.os.UserHandle;
+import android.os.UserManager;
 import android.preference.CheckBoxPreference;
 import android.preference.ListPreference;
 import android.preference.Preference;
@@ -59,10 +61,13 @@ import android.view.Gravity;
 import android.view.HardwareRenderer;
 import android.view.IWindowManager;
 import android.view.View;
+import android.view.accessibility.AccessibilityManager;
+import android.webkit.WebView;
 import android.widget.CompoundButton;
 import android.widget.Switch;
 import android.widget.TextView;
 
+import com.android.settings.widget.SwitchBar;
 import dalvik.system.VMRuntime;
 
 import java.io.File;
@@ -73,9 +78,9 @@ import java.util.List;
 /*
  * Displays preferences for application developers.
  */
-public class DevelopmentSettings extends RestrictedSettingsFragment
+public class DevelopmentSettings extends SettingsPreferenceFragment
         implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener,
-                OnPreferenceChangeListener, CompoundButton.OnCheckedChangeListener {
+                OnPreferenceChangeListener, SwitchBar.OnSwitchChangeListener {
     private static final String TAG = "DevelopmentSettings";
 
     /**
@@ -113,6 +118,9 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
     private static final String SHOW_TOUCHES_KEY = "show_touches";
     private static final String SHOW_SCREEN_UPDATES_KEY = "show_screen_updates";
     private static final String DISABLE_OVERLAYS_KEY = "disable_overlays";
+    private static final String SIMULATE_COLOR_SPACE = "simulate_color_space";
+    private static final String USE_NUPLAYER_KEY = "use_nuplayer";
+    private static final String USE_NUPLAYER_PROPERTY = "persist.sys.media.use-nuplayer";
     private static final String SHOW_CPU_USAGE_KEY = "show_cpu_usage";
     private static final String FORCE_HARDWARE_UI_KEY = "force_hw_ui";
     private static final String FORCE_MSAA_KEY = "force_msaa";
@@ -130,6 +138,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
     private static final String DEBUG_DEBUGGING_CATEGORY_KEY = "debug_debugging_category";
     private static final String DEBUG_APPLICATIONS_CATEGORY_KEY = "debug_applications_category";
     private static final String WIFI_DISPLAY_CERTIFICATION_KEY = "wifi_display_certification";
+    private static final String WIFI_VERBOSE_LOGGING_KEY = "wifi_verbose_logging";
     private static final String SELECT_LOGD_SIZE_KEY = "select_logd_size";
     private static final String SELECT_LOGD_SIZE_PROPERTY = "persist.logd.size";
     private static final String SELECT_LOGD_DEFAULT_SIZE_PROPERTY = "ro.logd.size";
@@ -142,6 +151,10 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
 
     private static final String SHOW_ALL_ANRS_KEY = "show_all_anrs";
 
+    private static final String WEBVIEW_DATA_REDUCTION_PROXY_KEY = "webview_data_reduction_proxy";
+
+    private static final String PROCESS_STATS = "proc_stats";
+
     private static final String TAG_CONFIRM_ENFORCE = "confirm_enforce";
 
     private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive";
@@ -153,8 +166,10 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
     private IWindowManager mWindowManager;
     private IBackupManager mBackupManager;
     private DevicePolicyManager mDpm;
+    private UserManager mUm;
+    private WifiManager mWifiManager;
 
-    private Switch mEnabledSwitch;
+    private SwitchBar mSwitchBar;
     private boolean mLastEnabledState;
     private boolean mHaveDebugSettings;
     private boolean mDontPokeProperties;
@@ -174,6 +189,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
     private CheckBoxPreference mWaitForDebugger;
     private CheckBoxPreference mVerifyAppsOverUsb;
     private CheckBoxPreference mWifiDisplayCertification;
+    private CheckBoxPreference mWifiVerboseLogging;
 
     private CheckBoxPreference mStrictMode;
     private CheckBoxPreference mPointerLocation;
@@ -196,12 +212,19 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
     private ListPreference mAnimatorDurationScale;
     private ListPreference mOverlayDisplayDevices;
     private ListPreference mOpenGLTraces;
+    private ListPreference mSimulateColorSpace;
+
+    private CheckBoxPreference mUseNuplayer;
 
     private CheckBoxPreference mImmediatelyDestroyActivities;
     private ListPreference mAppProcessLimit;
 
     private CheckBoxPreference mShowAllANRs;
 
+    private CheckBoxPreference mWebViewDataReductionProxy;
+
+    private PreferenceScreen mProcessStats;
+
     private final ArrayList<Preference> mAllPrefs = new ArrayList<Preference>();
     private final ArrayList<CheckBoxPreference> mResetCbPrefs
             = new ArrayList<CheckBoxPreference>();
@@ -216,10 +239,6 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
 
     private boolean mUnavailable;
 
-    public DevelopmentSettings() {
-        super(RESTRICTIONS_PIN_SET);
-    }
-
     @Override
     public void onCreate(Bundle icicle) {
         super.onCreate(icicle);
@@ -228,8 +247,12 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
         mBackupManager = IBackupManager.Stub.asInterface(
                 ServiceManager.getService(Context.BACKUP_SERVICE));
         mDpm = (DevicePolicyManager)getActivity().getSystemService(Context.DEVICE_POLICY_SERVICE);
+        mUm = (UserManager) getSystemService(Context.USER_SERVICE);
+
+        mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
 
-        if (android.os.Process.myUserHandle().getIdentifier() != UserHandle.USER_OWNER) {
+        if (android.os.Process.myUserHandle().getIdentifier() != UserHandle.USER_OWNER
+                || mUm.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES)) {
             mUnavailable = true;
             setPreferenceScreen(new PreferenceScreen(getActivity(), null));
             return;
@@ -247,6 +270,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
                 debugDebuggingCategory.removePreference(mClearAdbKeys);
             }
         }
+        mAllPrefs.add(mClearAdbKeys);
         mEnableTerminal = findAndInitCheckboxPref(ENABLE_TERMINAL);
         if (!isPackageInstalled(getActivity(), TERMINAL_APP_PACKAGE)) {
             debugDebuggingCategory.removePreference(mEnableTerminal);
@@ -295,6 +319,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
         mForceRtlLayout = findAndInitCheckboxPref(FORCE_RTL_LAYOUT_KEY);
         mDebugHwOverdraw = addListPreference(DEBUG_HW_OVERDRAW_KEY);
         mWifiDisplayCertification = findAndInitCheckboxPref(WIFI_DISPLAY_CERTIFICATION_KEY);
+        mWifiVerboseLogging = findAndInitCheckboxPref(WIFI_VERBOSE_LOGGING_KEY);
         mLogdSize = addListPreference(SELECT_LOGD_SIZE_KEY);
 
         mWindowAnimationScale = addListPreference(WINDOW_ANIMATION_SCALE_KEY);
@@ -302,11 +327,14 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
         mAnimatorDurationScale = addListPreference(ANIMATOR_DURATION_SCALE_KEY);
         mOverlayDisplayDevices = addListPreference(OVERLAY_DISPLAY_DEVICES_KEY);
         mOpenGLTraces = addListPreference(OPENGL_TRACES_KEY);
+        mSimulateColorSpace = addListPreference(SIMULATE_COLOR_SPACE);
+        mUseNuplayer = findAndInitCheckboxPref(USE_NUPLAYER_KEY);
 
         mImmediatelyDestroyActivities = (CheckBoxPreference) findPreference(
                 IMMEDIATELY_DESTROY_ACTIVITIES_KEY);
         mAllPrefs.add(mImmediatelyDestroyActivities);
         mResetCbPrefs.add(mImmediatelyDestroyActivities);
+
         mAppProcessLimit = addListPreference(APP_PROCESS_LIMIT_KEY);
 
         mShowAllANRs = (CheckBoxPreference) findPreference(
@@ -325,6 +353,11 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
             mAllPrefs.add(hdcpChecking);
             removePreferenceForProduction(hdcpChecking);
         }
+
+        mProcessStats = (PreferenceScreen) findPreference(PROCESS_STATS);
+        mAllPrefs.add(mProcessStats);
+
+        mWebViewDataReductionProxy = findAndInitCheckboxPref(WEBVIEW_DATA_REDUCTION_PROXY_KEY);
     }
 
     private ListPreference addListPreference(String prefKey) {
@@ -355,37 +388,15 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
 
-        final Activity activity = getActivity();
-        mEnabledSwitch = new Switch(activity);
+        final SettingsActivity activity = (SettingsActivity) getActivity();
 
-        final int padding = activity.getResources().getDimensionPixelSize(
-                R.dimen.action_bar_switch_padding);
-        mEnabledSwitch.setPaddingRelative(0, 0, padding, 0);
-        if (mUnavailable) {
-            mEnabledSwitch.setEnabled(false);
+        mSwitchBar = activity.getSwitchBar();
+       if (mUnavailable) {
+            mSwitchBar.setEnabled(false);
             return;
         }
-        mEnabledSwitch.setOnCheckedChangeListener(this);
-    }
-
-    @Override
-    public void onStart() {
-        super.onStart();
-        final Activity activity = getActivity();
-        activity.getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
-                ActionBar.DISPLAY_SHOW_CUSTOM);
-        activity.getActionBar().setCustomView(mEnabledSwitch, new ActionBar.LayoutParams(
-                ActionBar.LayoutParams.WRAP_CONTENT,
-                ActionBar.LayoutParams.WRAP_CONTENT,
-                Gravity.CENTER_VERTICAL | Gravity.END));
-    }
 
-    @Override
-    public void onStop() {
-        super.onStop();
-        final Activity activity = getActivity();
-        activity.getActionBar().setDisplayOptions(0, ActionBar.DISPLAY_SHOW_CUSTOM);
-        activity.getActionBar().setCustomView(null);
+        mSwitchBar.addOnSwitchChangeListener(this);
     }
 
     private boolean removePreferenceForProduction(Preference preference) {
@@ -436,7 +447,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
         final ContentResolver cr = getActivity().getContentResolver();
         mLastEnabledState = Settings.Global.getInt(cr,
                 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
-        mEnabledSwitch.setChecked(mLastEnabledState);
+        mSwitchBar.setChecked(mLastEnabledState);
         setPrefsEnabledState(mLastEnabledState);
 
         if (mHaveDebugSettings && !mLastEnabledState) {
@@ -447,9 +458,21 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
             Settings.Global.putInt(getActivity().getContentResolver(),
                     Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
             mLastEnabledState = true;
-            mEnabledSwitch.setChecked(mLastEnabledState);
+            mSwitchBar.setChecked(mLastEnabledState);
             setPrefsEnabledState(mLastEnabledState);
         }
+        mSwitchBar.show();
+    }
+
+    @Override
+    public void onDestroyView() {
+        super.onDestroyView();
+
+        if (mUnavailable) {
+            return;
+        }
+        mSwitchBar.removeOnSwitchChangeListener(this);
+        mSwitchBar.hide();
     }
 
     void updateCheckBox(CheckBoxPreference checkBox, boolean value) {
@@ -499,11 +522,15 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
         updateImmediatelyDestroyActivitiesOptions();
         updateAppProcessLimitOptions();
         updateShowAllANRsOptions();
+        updateWebViewDataReductionProxyOptions();
         updateVerifyAppsOverUsbOptions();
         updateBugreportOptions();
         updateForceRtlOptions();
         updateLogdSizeValues();
         updateWifiDisplayCertificationOptions();
+        updateWifiVerboseLoggingOptions();
+        updateSimulateColorSpace();
+        updateUseNuplayerOptions();
     }
 
     private void resetDangerousOptions() {
@@ -941,6 +968,49 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
         pokeSystemProperties();
     }
 
+    private void updateSimulateColorSpace() {
+        final ContentResolver cr = getContentResolver();
+        final boolean enabled = Settings.Secure.getInt(
+                cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0) != 0;
+        if (enabled) {
+            final String mode = Integer.toString(Settings.Secure.getInt(
+                    cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER,
+                    AccessibilityManager.DALTONIZER_DISABLED));
+            mSimulateColorSpace.setValue(mode);
+            final int index = mSimulateColorSpace.findIndexOfValue(mode);
+            if (index < 0) {
+                // We're using a mode controlled by accessibility preferences.
+                mSimulateColorSpace.setSummary(getString(R.string.daltonizer_type_overridden,
+                        getString(R.string.accessibility_display_daltonizer_preference_title)));
+            } else {
+                mSimulateColorSpace.setSummary("%s");
+            }
+        } else {
+            mSimulateColorSpace.setValue(
+                    Integer.toString(AccessibilityManager.DALTONIZER_DISABLED));
+        }
+    }
+
+    private void writeSimulateColorSpace(Object value) {
+        final ContentResolver cr = getContentResolver();
+        final int newMode = Integer.parseInt(value.toString());
+        if (newMode < 0) {
+            Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0);
+        } else {
+            Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 1);
+            Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER, newMode);
+        }
+    }
+
+    private void updateUseNuplayerOptions() {
+        updateCheckBox(mUseNuplayer, SystemProperties.getBoolean(USE_NUPLAYER_PROPERTY, false));
+    }
+
+    private void writeUseNuplayerOptions() {
+        SystemProperties.set(USE_NUPLAYER_PROPERTY, mUseNuplayer.isChecked() ? "true" : "false");
+        pokeSystemProperties();
+    }
+
     private void updateForceRtlOptions() {
         updateCheckBox(mForceRtlLayout, Settings.Global.getInt(getActivity().getContentResolver(),
                 Settings.Global.DEVELOPMENT_FORCE_RTL, 0) != 0);
@@ -966,6 +1036,15 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
                 mWifiDisplayCertification.isChecked() ? 1 : 0);
     }
 
+    private void updateWifiVerboseLoggingOptions() {
+        boolean enabled = mWifiManager.getVerboseLoggingLevel() > 0;
+        updateCheckBox(mWifiVerboseLogging, enabled);
+    }
+
+    private void writeWifiVerboseLoggingOptions() {
+        mWifiManager.enableVerboseLogging(mWifiVerboseLogging.isChecked() ? 1 : 0);
+    }
+
     private void updateLogdSizeValues() {
         if (mLogdSize != null) {
             String currentValue = SystemProperties.get(SELECT_LOGD_SIZE_PROPERTY);
@@ -1160,29 +1239,44 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
             getActivity().getContentResolver(), Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0);
     }
 
+    private void writeWebViewDataReductionProxyOptions() {
+        Settings.Secure.putInt(getActivity().getContentResolver(),
+                Settings.Secure.WEBVIEW_DATA_REDUCTION_PROXY,
+                mWebViewDataReductionProxy.isChecked() ? 1 : 0);
+        Intent intent = new Intent(WebView.DATA_REDUCTION_PROXY_SETTING_CHANGED);
+        // Broadcast to all apps running as current user.
+        getActivity().sendBroadcastAsUser(intent, UserHandle.CURRENT);
+    }
+
+    private void updateWebViewDataReductionProxyOptions() {
+        updateCheckBox(mWebViewDataReductionProxy, Settings.Secure.getInt(
+            getActivity().getContentResolver(),
+            Settings.Secure.WEBVIEW_DATA_REDUCTION_PROXY, 0) != 0);
+    }
+
     @Override
-    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
-        if (buttonView == mEnabledSwitch) {
-            if (isChecked != mLastEnabledState) {
-                if (isChecked) {
-                    mDialogClicked = false;
-                    if (mEnableDialog != null) dismissDialogs();
-                    mEnableDialog = new AlertDialog.Builder(getActivity()).setMessage(
-                            getActivity().getResources().getString(
-                                    R.string.dev_settings_warning_message))
-                            .setTitle(R.string.dev_settings_warning_title)
-                            .setIconAttribute(android.R.attr.alertDialogIcon)
-                            .setPositiveButton(android.R.string.yes, this)
-                            .setNegativeButton(android.R.string.no, this)
-                            .show();
-                    mEnableDialog.setOnDismissListener(this);
-                } else {
-                    resetDangerousOptions();
-                    Settings.Global.putInt(getActivity().getContentResolver(),
-                            Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
-                    mLastEnabledState = isChecked;
-                    setPrefsEnabledState(mLastEnabledState);
-                }
+    public void onSwitchChanged(Switch switchView, boolean isChecked) {
+        if (switchView != mSwitchBar.getSwitch()) {
+            return;
+        }
+        if (isChecked != mLastEnabledState) {
+            if (isChecked) {
+                mDialogClicked = false;
+                if (mEnableDialog != null) dismissDialogs();
+                mEnableDialog = new AlertDialog.Builder(getActivity()).setMessage(
+                        getActivity().getResources().getString(
+                                R.string.dev_settings_warning_message))
+                        .setTitle(R.string.dev_settings_warning_title)
+                        .setPositiveButton(android.R.string.yes, this)
+                        .setNegativeButton(android.R.string.no, this)
+                        .show();
+                mEnableDialog.setOnDismissListener(this);
+            } else {
+                resetDangerousOptions();
+                Settings.Global.putInt(getActivity().getContentResolver(),
+                        Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
+                mLastEnabledState = isChecked;
+                setPrefsEnabledState(mLastEnabledState);
             }
         }
     }
@@ -1213,7 +1307,6 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
                 mAdbDialog = new AlertDialog.Builder(getActivity()).setMessage(
                         getActivity().getResources().getString(R.string.adb_warning_message))
                         .setTitle(R.string.adb_warning_title)
-                        .setIconAttribute(android.R.attr.alertDialogIcon)
                         .setPositiveButton(android.R.string.yes, this)
                         .setNegativeButton(android.R.string.no, this)
                         .show();
@@ -1274,6 +1367,8 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
             writeImmediatelyDestroyActivitiesOptions();
         } else if (preference == mShowAllANRs) {
             writeShowAllANRsOptions();
+        } else if (preference == mWebViewDataReductionProxy) {
+            writeWebViewDataReductionProxyOptions();
         } else if (preference == mForceHardwareUi) {
             writeHardwareUiOptions();
         } else if (preference == mForceMsaa) {
@@ -1288,6 +1383,10 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
             writeForceRtlOptions();
         } else if (preference == mWifiDisplayCertification) {
             writeWifiDisplayCertificationOptions();
+        } else if (preference == mWifiVerboseLogging) {
+            writeWifiVerboseLoggingOptions();
+        } else if (preference == mUseNuplayer) {
+            writeUseNuplayerOptions();
         } else {
             return super.onPreferenceTreeClick(preferenceScreen, preference);
         }
@@ -1359,6 +1458,9 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
         } else if (preference == mAppProcessLimit) {
             writeAppProcessLimitOptions(newValue);
             return true;
+        } else if (preference == mSimulateColorSpace) {
+            writeSimulateColorSpace(newValue);
+            return true;
         }
         return false;
     }
@@ -1410,7 +1512,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
                 setPrefsEnabledState(mLastEnabledState);
             } else {
                 // Reset the toggle
-                mEnabledSwitch.setChecked(false);
+                mSwitchBar.setChecked(false);
             }
         }
     }
@@ -1424,7 +1526,7 @@ public class DevelopmentSettings extends RestrictedSettingsFragment
             mAdbDialog = null;
         } else if (dialog == mEnableDialog) {
             if (!mDialogClicked) {
-                mEnabledSwitch.setChecked(false);
+                mSwitchBar.setChecked(false);
             }
             mEnableDialog = null;
         }