The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.settings; |
| 18 | |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 19 | import android.os.BatteryManager; |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 20 | import android.os.Bundle; |
| 21 | import android.os.SystemProperties; |
| 22 | import android.preference.Preference; |
| 23 | import android.preference.PreferenceActivity; |
| 24 | import android.preference.PreferenceScreen; |
| 25 | import android.preference.CheckBoxPreference; |
| 26 | import android.provider.Settings; |
| 27 | import android.text.TextUtils; |
| 28 | |
| 29 | /* |
| 30 | * Displays preferences for application developers. |
| 31 | */ |
| 32 | public 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 Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 36 | private static final String ALLOW_MOCK_LOCATION = "allow_mock_location"; |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 37 | |
| 38 | private CheckBoxPreference mEnableAdb; |
| 39 | private CheckBoxPreference mKeepScreenOn; |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 40 | private CheckBoxPreference mAllowMockLocation; |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 41 | |
| 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 Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 50 | mAllowMockLocation = (CheckBoxPreference) findPreference(ALLOW_MOCK_LOCATION); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | @Override |
| 54 | protected void onResume() { |
| 55 | super.onResume(); |
| 56 | |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 57 | mEnableAdb.setChecked(Settings.Secure.getInt(getContentResolver(), |
| 58 | Settings.Secure.ADB_ENABLED, 0) != 0); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 59 | mKeepScreenOn.setChecked(Settings.System.getInt(getContentResolver(), |
| 60 | Settings.System.STAY_ON_WHILE_PLUGGED_IN, 0) != 0); |
The Android Open Source Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 61 | mAllowMockLocation.setChecked(Settings.Secure.getInt(getContentResolver(), |
| 62 | Settings.Secure.ALLOW_MOCK_LOCATION, 0) != 0); |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 63 | } |
| 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 Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 75 | Settings.Secure.putInt(getContentResolver(), Settings.Secure.ADB_ENABLED, |
The Android Open Source Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 76 | 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 Project | abc48f8 | 2008-12-17 18:06:01 -0800 | [diff] [blame] | 79 | 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 Project | de2d9f5 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | return false; |
| 87 | } |
| 88 | } |