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;
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;
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;
/*
* 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";
/**
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";
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";
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";
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;
private CheckBoxPreference mWaitForDebugger;
private CheckBoxPreference mVerifyAppsOverUsb;
private CheckBoxPreference mWifiDisplayCertification;
+ private CheckBoxPreference mWifiVerboseLogging;
private CheckBoxPreference mStrictMode;
private CheckBoxPreference mPointerLocation;
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>();
private boolean mUnavailable;
- public DevelopmentSettings() {
- super(RESTRICTIONS_PIN_SET);
- }
-
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
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;
debugDebuggingCategory.removePreference(mClearAdbKeys);
}
}
+ mAllPrefs.add(mClearAdbKeys);
mEnableTerminal = findAndInitCheckboxPref(ENABLE_TERMINAL);
if (!isPackageInstalled(getActivity(), TERMINAL_APP_PACKAGE)) {
debugDebuggingCategory.removePreference(mEnableTerminal);
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);
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(
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) {
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) {
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) {
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) {
updateImmediatelyDestroyActivitiesOptions();
updateAppProcessLimitOptions();
updateShowAllANRsOptions();
+ updateWebViewDataReductionProxyOptions();
updateVerifyAppsOverUsbOptions();
updateBugreportOptions();
updateForceRtlOptions();
updateLogdSizeValues();
updateWifiDisplayCertificationOptions();
+ updateWifiVerboseLoggingOptions();
+ updateSimulateColorSpace();
+ updateUseNuplayerOptions();
}
private void resetDangerousOptions() {
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);
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);
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);
}
}
}
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();
writeImmediatelyDestroyActivitiesOptions();
} else if (preference == mShowAllANRs) {
writeShowAllANRsOptions();
+ } else if (preference == mWebViewDataReductionProxy) {
+ writeWebViewDataReductionProxyOptions();
} else if (preference == mForceHardwareUi) {
writeHardwareUiOptions();
} else if (preference == mForceMsaa) {
writeForceRtlOptions();
} else if (preference == mWifiDisplayCertification) {
writeWifiDisplayCertificationOptions();
+ } else if (preference == mWifiVerboseLogging) {
+ writeWifiVerboseLoggingOptions();
+ } else if (preference == mUseNuplayer) {
+ writeUseNuplayerOptions();
} else {
return super.onPreferenceTreeClick(preferenceScreen, preference);
}
} else if (preference == mAppProcessLimit) {
writeAppProcessLimitOptions(newValue);
return true;
+ } else if (preference == mSimulateColorSpace) {
+ writeSimulateColorSpace(newValue);
+ return true;
}
return false;
}
setPrefsEnabledState(mLastEnabledState);
} else {
// Reset the toggle
- mEnabledSwitch.setChecked(false);
+ mSwitchBar.setChecked(false);
}
}
}
mAdbDialog = null;
} else if (dialog == mEnableDialog) {
if (!mDialogClicked) {
- mEnabledSwitch.setChecked(false);
+ mSwitchBar.setChecked(false);
}
mEnableDialog = null;
}