2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings;
19 import android.app.AlertDialog;
20 import android.app.Dialog;
21 import android.content.ContentResolver;
22 import android.content.DialogInterface;
23 import android.os.BatteryManager;
24 import android.os.Build;
25 import android.os.Bundle;
26 import android.os.SystemProperties;
27 import android.preference.CheckBoxPreference;
28 import android.preference.ListPreference;
29 import android.preference.Preference;
30 import android.preference.PreferenceFragment;
31 import android.preference.PreferenceScreen;
32 import android.preference.Preference.OnPreferenceChangeListener;
33 import android.provider.Settings;
36 * Displays preferences for application developers.
38 public class DevelopmentSettings extends PreferenceFragment
39 implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener,
40 OnPreferenceChangeListener {
42 private static final String ENABLE_ADB = "enable_adb";
43 private static final String KEEP_SCREEN_ON = "keep_screen_on";
44 private static final String ALLOW_MOCK_LOCATION = "allow_mock_location";
45 private static final String HDCP_CHECKING_KEY = "hdcp_checking";
46 private static final String HDCP_CHECKING_PROPERTY = "persist.sys.hdcp_checking";
48 private CheckBoxPreference mEnableAdb;
49 private CheckBoxPreference mKeepScreenOn;
50 private CheckBoxPreference mAllowMockLocation;
52 // To track whether Yes was clicked in the adb warning dialog
53 private boolean mOkClicked;
55 private Dialog mOkDialog;
58 public void onCreate(Bundle icicle) {
59 super.onCreate(icicle);
61 addPreferencesFromResource(R.xml.development_prefs);
63 mEnableAdb = (CheckBoxPreference) findPreference(ENABLE_ADB);
64 mKeepScreenOn = (CheckBoxPreference) findPreference(KEEP_SCREEN_ON);
65 mAllowMockLocation = (CheckBoxPreference) findPreference(ALLOW_MOCK_LOCATION);
67 //removeHdcpOptionsForProduction();
70 private void removeHdcpOptionsForProduction() {
71 if ("user".equals(Build.TYPE)) {
72 Preference hdcpChecking = findPreference(HDCP_CHECKING_KEY);
73 if (hdcpChecking != null) {
74 // Remove the preference
75 getPreferenceScreen().removePreference(hdcpChecking);
81 public void onResume() {
84 final ContentResolver cr = getActivity().getContentResolver();
85 mEnableAdb.setChecked(Settings.Secure.getInt(cr,
86 Settings.Secure.ADB_ENABLED, 0) != 0);
87 mKeepScreenOn.setChecked(Settings.System.getInt(cr,
88 Settings.System.STAY_ON_WHILE_PLUGGED_IN, 0) != 0);
89 mAllowMockLocation.setChecked(Settings.Secure.getInt(cr,
90 Settings.Secure.ALLOW_MOCK_LOCATION, 0) != 0);
94 private void updateHdcpValues() {
95 int index = 1; // Defaults to drm-only. Needs to match with R.array.hdcp_checking_values
96 ListPreference hdcpChecking = (ListPreference) findPreference(HDCP_CHECKING_KEY);
97 if (hdcpChecking != null) {
98 String currentValue = SystemProperties.get(HDCP_CHECKING_PROPERTY);
99 String[] values = getResources().getStringArray(R.array.hdcp_checking_values);
100 String[] summaries = getResources().getStringArray(R.array.hdcp_checking_summaries);
101 for (int i = 0; i < values.length; i++) {
102 if (currentValue.equals(values[i])) {
107 hdcpChecking.setValue(values[index]);
108 hdcpChecking.setSummary(summaries[index]);
109 hdcpChecking.setOnPreferenceChangeListener(this);
114 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
116 if (Utils.isMonkeyRunning()) {
120 if (preference == mEnableAdb) {
121 if (mEnableAdb.isChecked()) {
123 if (mOkDialog != null) dismissDialog();
124 mOkDialog = new AlertDialog.Builder(getActivity()).setMessage(
125 getActivity().getResources().getString(R.string.adb_warning_message))
126 .setTitle(R.string.adb_warning_title)
127 .setIcon(android.R.drawable.ic_dialog_alert)
128 .setPositiveButton(android.R.string.yes, this)
129 .setNegativeButton(android.R.string.no, this)
131 mOkDialog.setOnDismissListener(this);
133 Settings.Secure.putInt(getActivity().getContentResolver(),
134 Settings.Secure.ADB_ENABLED, 0);
136 } else if (preference == mKeepScreenOn) {
137 Settings.System.putInt(getActivity().getContentResolver(),
138 Settings.System.STAY_ON_WHILE_PLUGGED_IN,
139 mKeepScreenOn.isChecked() ?
140 (BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB) : 0);
141 } else if (preference == mAllowMockLocation) {
142 Settings.Secure.putInt(getActivity().getContentResolver(),
143 Settings.Secure.ALLOW_MOCK_LOCATION,
144 mAllowMockLocation.isChecked() ? 1 : 0);
150 private void dismissDialog() {
151 if (mOkDialog == null) return;
156 public void onClick(DialogInterface dialog, int which) {
157 if (which == DialogInterface.BUTTON_POSITIVE) {
159 Settings.Secure.putInt(getActivity().getContentResolver(),
160 Settings.Secure.ADB_ENABLED, 1);
163 mEnableAdb.setChecked(false);
167 public void onDismiss(DialogInterface dialog) {
168 // Assuming that onClick gets called first
170 mEnableAdb.setChecked(false);
175 public void onDestroy() {
181 public boolean onPreferenceChange(Preference preference, Object newValue) {
182 if (HDCP_CHECKING_KEY.equals(preference.getKey())) {
183 SystemProperties.set(HDCP_CHECKING_PROPERTY, newValue.toString());