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.DialogInterface;
22 import android.os.BatteryManager;
23 import android.os.Bundle;
24 import android.os.SystemProperties;
25 import android.preference.Preference;
26 import android.preference.PreferenceActivity;
27 import android.preference.PreferenceScreen;
28 import android.preference.CheckBoxPreference;
29 import android.provider.Settings;
30 import android.text.TextUtils;
33 * Displays preferences for application developers.
35 public class DevelopmentSettings extends PreferenceActivity
36 implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener {
38 private static final String ENABLE_ADB = "enable_adb";
39 private static final String KEEP_SCREEN_ON = "keep_screen_on";
40 private static final String ALLOW_MOCK_LOCATION = "allow_mock_location";
42 private CheckBoxPreference mEnableAdb;
43 private CheckBoxPreference mKeepScreenOn;
44 private CheckBoxPreference mAllowMockLocation;
46 // To track whether Yes was clicked in the adb warning dialog
47 private boolean mOkClicked;
49 private Dialog mOkDialog;
52 protected void onCreate(Bundle icicle) {
53 super.onCreate(icicle);
55 addPreferencesFromResource(R.xml.development_prefs);
57 mEnableAdb = (CheckBoxPreference) findPreference(ENABLE_ADB);
58 mKeepScreenOn = (CheckBoxPreference) findPreference(KEEP_SCREEN_ON);
59 mAllowMockLocation = (CheckBoxPreference) findPreference(ALLOW_MOCK_LOCATION);
63 protected void onResume() {
66 mEnableAdb.setChecked(Settings.Secure.getInt(getContentResolver(),
67 Settings.Secure.ADB_ENABLED, 0) != 0);
68 mKeepScreenOn.setChecked(Settings.System.getInt(getContentResolver(),
69 Settings.System.STAY_ON_WHILE_PLUGGED_IN, 0) != 0);
70 mAllowMockLocation.setChecked(Settings.Secure.getInt(getContentResolver(),
71 Settings.Secure.ALLOW_MOCK_LOCATION, 0) != 0);
75 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
77 // Those monkeys kept committing suicide, so we add this property
78 // to disable this functionality
79 if (!TextUtils.isEmpty(SystemProperties.get("ro.monkey"))) {
83 if (preference == mEnableAdb) {
84 if (mEnableAdb.isChecked()) {
86 if (mOkDialog != null) dismissDialog();
87 mOkDialog = new AlertDialog.Builder(this).setMessage(
88 getResources().getString(R.string.adb_warning_message))
89 .setTitle(R.string.adb_warning_title)
90 .setIcon(android.R.drawable.ic_dialog_alert)
91 .setPositiveButton(android.R.string.yes, this)
92 .setNegativeButton(android.R.string.no, this)
94 mOkDialog.setOnDismissListener(this);
96 Settings.Secure.putInt(getContentResolver(), Settings.Secure.ADB_ENABLED, 0);
98 } else if (preference == mKeepScreenOn) {
99 Settings.System.putInt(getContentResolver(), Settings.System.STAY_ON_WHILE_PLUGGED_IN,
100 mKeepScreenOn.isChecked() ?
101 (BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB) : 0);
102 } else if (preference == mAllowMockLocation) {
103 Settings.Secure.putInt(getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION,
104 mAllowMockLocation.isChecked() ? 1 : 0);
110 private void dismissDialog() {
111 if (mOkDialog == null) return;
116 public void onClick(DialogInterface dialog, int which) {
117 if (which == DialogInterface.BUTTON_POSITIVE) {
119 Settings.Secure.putInt(getContentResolver(), Settings.Secure.ADB_ENABLED, 1);
122 mEnableAdb.setChecked(false);
126 public void onDismiss(DialogInterface dialog) {
127 // Assuming that onClick gets called first
129 mEnableAdb.setChecked(false);
134 public void onDestroy() {