blob: 155f085f5f59cabc1cc4c86540d3150baf953654 [file] [log] [blame]
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17package com.android.settings;
18
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080019import android.os.BatteryManager;
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070020import android.os.Bundle;
21import android.os.SystemProperties;
22import android.preference.Preference;
23import android.preference.PreferenceActivity;
24import android.preference.PreferenceScreen;
25import android.preference.CheckBoxPreference;
26import android.provider.Settings;
27import android.text.TextUtils;
28
29/*
30 * Displays preferences for application developers.
31 */
32public class DevelopmentSettings extends PreferenceActivity {
33
34 private static final String ENABLE_ADB = "enable_adb";
35 private static final String KEEP_SCREEN_ON = "keep_screen_on";
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080036 private static final String ALLOW_MOCK_LOCATION = "allow_mock_location";
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070037
38 private CheckBoxPreference mEnableAdb;
39 private CheckBoxPreference mKeepScreenOn;
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080040 private CheckBoxPreference mAllowMockLocation;
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070041
42 @Override
43 protected void onCreate(Bundle icicle) {
44 super.onCreate(icicle);
45
46 addPreferencesFromResource(R.xml.development_prefs);
47
48 mEnableAdb = (CheckBoxPreference) findPreference(ENABLE_ADB);
49 mKeepScreenOn = (CheckBoxPreference) findPreference(KEEP_SCREEN_ON);
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080050 mAllowMockLocation = (CheckBoxPreference) findPreference(ALLOW_MOCK_LOCATION);
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070051 }
52
53 @Override
54 protected void onResume() {
55 super.onResume();
56
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080057 mEnableAdb.setChecked(Settings.Secure.getInt(getContentResolver(),
58 Settings.Secure.ADB_ENABLED, 0) != 0);
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070059 mKeepScreenOn.setChecked(Settings.System.getInt(getContentResolver(),
60 Settings.System.STAY_ON_WHILE_PLUGGED_IN, 0) != 0);
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080061 mAllowMockLocation.setChecked(Settings.Secure.getInt(getContentResolver(),
62 Settings.Secure.ALLOW_MOCK_LOCATION, 0) != 0);
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070063 }
64
65 @Override
66 public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
67
68 // Those monkeys kept committing suicide, so we add this property
69 // to disable this functionality
70 if (!TextUtils.isEmpty(SystemProperties.get("ro.monkey"))) {
71 return false;
72 }
73
74 if (preference == mEnableAdb) {
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080075 Settings.Secure.putInt(getContentResolver(), Settings.Secure.ADB_ENABLED,
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070076 mEnableAdb.isChecked() ? 1 : 0);
77 } else if (preference == mKeepScreenOn) {
78 Settings.System.putInt(getContentResolver(), Settings.System.STAY_ON_WHILE_PLUGGED_IN,
The Android Open Source Projectabc48f82008-12-17 18:06:01 -080079 mKeepScreenOn.isChecked() ?
80 (BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB) : 0);
81 } else if (preference == mAllowMockLocation) {
82 Settings.Secure.putInt(getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION,
83 mAllowMockLocation.isChecked() ? 1 : 0);
The Android Open Source Projectde2d9f52008-10-21 07:00:00 -070084 }
85
86 return false;
87 }
88}