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.content.DialogInterface;
21 import android.os.BatteryManager;
22 import android.os.Bundle;
23 import android.os.SystemProperties;
24 import android.preference.Preference;
25 import android.preference.PreferenceActivity;
26 import android.preference.PreferenceScreen;
27 import android.preference.CheckBoxPreference;
28 import android.provider.Settings;
29 import android.text.TextUtils;
32 * Displays preferences for application developers.
34 public class DevelopmentSettings extends PreferenceActivity
35 implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener {
37 private static final String ENABLE_ADB = "enable_adb";
38 private static final String KEEP_SCREEN_ON = "keep_screen_on";
39 private static final String ALLOW_MOCK_LOCATION = "allow_mock_location";
41 private CheckBoxPreference mEnableAdb;
42 private CheckBoxPreference mKeepScreenOn;
43 private CheckBoxPreference mAllowMockLocation;
45 // To track whether Yes was clicked in the adb warning dialog
46 private boolean mOkClicked;
49 protected void onCreate(Bundle icicle) {
50 super.onCreate(icicle);
52 addPreferencesFromResource(R.xml.development_prefs);
54 mEnableAdb = (CheckBoxPreference) findPreference(ENABLE_ADB);
55 mKeepScreenOn = (CheckBoxPreference) findPreference(KEEP_SCREEN_ON);
56 mAllowMockLocation = (CheckBoxPreference) findPreference(ALLOW_MOCK_LOCATION);
60 protected void onResume() {
63 mEnableAdb.setChecked(Settings.Secure.getInt(getContentResolver(),
64 Settings.Secure.ADB_ENABLED, 0) != 0);
65 mKeepScreenOn.setChecked(Settings.System.getInt(getContentResolver(),
66 Settings.System.STAY_ON_WHILE_PLUGGED_IN, 0) != 0);
67 mAllowMockLocation.setChecked(Settings.Secure.getInt(getContentResolver(),
68 Settings.Secure.ALLOW_MOCK_LOCATION, 0) != 0);
72 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
74 // Those monkeys kept committing suicide, so we add this property
75 // to disable this functionality
76 if (!TextUtils.isEmpty(SystemProperties.get("ro.monkey"))) {
80 if (preference == mEnableAdb) {
81 if (mEnableAdb.isChecked()) {
83 new AlertDialog.Builder(this).setMessage(
84 getResources().getString(R.string.adb_warning_message))
85 .setTitle(R.string.adb_warning_title)
86 .setIcon(android.R.drawable.ic_dialog_alert)
87 .setPositiveButton(android.R.string.yes, this)
88 .setNegativeButton(android.R.string.no, this)
90 .setOnDismissListener(this);
92 Settings.Secure.putInt(getContentResolver(), Settings.Secure.ADB_ENABLED, 0);
94 } else if (preference == mKeepScreenOn) {
95 Settings.System.putInt(getContentResolver(), Settings.System.STAY_ON_WHILE_PLUGGED_IN,
96 mKeepScreenOn.isChecked() ?
97 (BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB) : 0);
98 } else if (preference == mAllowMockLocation) {
99 Settings.Secure.putInt(getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION,
100 mAllowMockLocation.isChecked() ? 1 : 0);
106 public void onClick(DialogInterface dialog, int which) {
107 if (which == DialogInterface.BUTTON_POSITIVE) {
109 Settings.Secure.putInt(getContentResolver(), Settings.Secure.ADB_ENABLED, 1);
112 mEnableAdb.setChecked(false);
116 public void onDismiss(DialogInterface dialog) {
117 // Assuming that onClick gets called first
119 mEnableAdb.setChecked(false);