The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 1 | /* |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame^] | 2 | * Copyright (C) 2009 The Android Open Source Project |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 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 | |
Michael Chan | 0cb3743 | 2009-10-29 14:42:06 -0700 | [diff] [blame] | 19 | import android.bluetooth.BluetoothAdapter; |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 20 | import android.content.Intent; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 21 | import android.net.wifi.WifiManager; |
| 22 | import android.os.Bundle; |
Michael Chan | 0cb3743 | 2009-10-29 14:42:06 -0700 | [diff] [blame] | 23 | import android.os.ServiceManager; |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 24 | import android.os.SystemProperties; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 25 | import android.preference.CheckBoxPreference; |
Mike Lockwood | 83bcc98 | 2009-07-29 23:25:10 -0700 | [diff] [blame] | 26 | import android.preference.Preference; |
| 27 | import android.preference.PreferenceActivity; |
Michael Chan | 0cb3743 | 2009-10-29 14:42:06 -0700 | [diff] [blame] | 28 | import android.preference.PreferenceScreen; |
Mike Lockwood | 83bcc98 | 2009-07-29 23:25:10 -0700 | [diff] [blame] | 29 | import android.provider.Settings; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 30 | |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 31 | import com.android.internal.telephony.TelephonyIntents; |
| 32 | import com.android.internal.telephony.TelephonyProperties; |
Michael Chan | 0cb3743 | 2009-10-29 14:42:06 -0700 | [diff] [blame] | 33 | import com.android.settings.bluetooth.BluetoothEnabler; |
| 34 | import com.android.settings.wifi.WifiEnabler; |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 35 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 36 | public class WirelessSettings extends PreferenceActivity { |
| 37 | |
| 38 | private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane"; |
| 39 | private static final String KEY_TOGGLE_BLUETOOTH = "toggle_bluetooth"; |
| 40 | private static final String KEY_TOGGLE_WIFI = "toggle_wifi"; |
Mike Lockwood | 83bcc98 | 2009-07-29 23:25:10 -0700 | [diff] [blame] | 41 | private static final String KEY_WIFI_SETTINGS = "wifi_settings"; |
Michael Chan | 0cb3743 | 2009-10-29 14:42:06 -0700 | [diff] [blame] | 42 | private static final String KEY_BT_SETTINGS = "bt_settings"; |
Mike Lockwood | 83bcc98 | 2009-07-29 23:25:10 -0700 | [diff] [blame] | 43 | private static final String KEY_VPN_SETTINGS = "vpn_settings"; |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 44 | public static final String EXIT_ECM_RESULT = "exit_ecm_result"; |
| 45 | public static final int REQUEST_CODE_EXIT_ECM = 1; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 46 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 47 | private AirplaneModeEnabler mAirplaneModeEnabler; |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 48 | private CheckBoxPreference mAirplaneModePreference; |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame^] | 49 | private WifiEnabler mWifiEnabler; |
| 50 | private BluetoothEnabler mBtEnabler; |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 51 | |
| 52 | /** |
| 53 | * Invoked on each preference click in this hierarchy, overrides |
| 54 | * PreferenceActivity's implementation. Used to make sure we track the |
| 55 | * preference click events. |
| 56 | */ |
| 57 | @Override |
| 58 | public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame^] | 59 | if (preference == mAirplaneModePreference && Boolean.parseBoolean( |
| 60 | SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) { |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 61 | // In ECM mode launch ECM app dialog |
| 62 | startActivityForResult( |
| 63 | new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null), |
| 64 | REQUEST_CODE_EXIT_ECM); |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 65 | return true; |
| 66 | } |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame^] | 67 | // Let the intents be launched by the Preference manager |
| 68 | return false; |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 69 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 70 | |
| 71 | @Override |
| 72 | protected void onCreate(Bundle savedInstanceState) { |
| 73 | super.onCreate(savedInstanceState); |
| 74 | |
| 75 | addPreferencesFromResource(R.xml.wireless_settings); |
| 76 | |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame^] | 77 | CheckBoxPreference airplane = (CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE); |
| 78 | CheckBoxPreference wifi = (CheckBoxPreference) findPreference(KEY_TOGGLE_WIFI); |
| 79 | CheckBoxPreference bt = (CheckBoxPreference) findPreference(KEY_TOGGLE_BLUETOOTH); |
| 80 | |
| 81 | mAirplaneModeEnabler = new AirplaneModeEnabler(this, airplane); |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 82 | mAirplaneModePreference = (CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE); |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame^] | 83 | mWifiEnabler = new WifiEnabler(this, wifi); |
| 84 | mBtEnabler = new BluetoothEnabler(this, bt); |
| 85 | |
| 86 | String toggleable = Settings.System.getString(getContentResolver(), |
| 87 | Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS); |
| 88 | |
| 89 | // Manually set up dependencies for Wifi when not toggleable. |
| 90 | if (toggleable == null || !toggleable.contains(Settings.System.RADIO_WIFI)) { |
| 91 | wifi.setDependency(KEY_TOGGLE_AIRPLANE); |
| 92 | findPreference(KEY_WIFI_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE); |
| 93 | findPreference(KEY_VPN_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE); |
| 94 | } |
| 95 | |
| 96 | // Manually set dependencies for Bluetooth when not toggleable. |
| 97 | if (toggleable == null || !toggleable.contains(Settings.System.RADIO_BLUETOOTH)) { |
| 98 | bt.setDependency(KEY_TOGGLE_AIRPLANE); |
| 99 | findPreference(KEY_BT_SETTINGS).setDependency(KEY_TOGGLE_AIRPLANE); |
| 100 | } |
| 101 | |
| 102 | // Disable BT Settings if BT service is not available. |
| 103 | if (ServiceManager.getService(BluetoothAdapter.BLUETOOTH_SERVICE) == null) { |
| 104 | findPreference(KEY_BT_SETTINGS).setEnabled(false); |
| 105 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | @Override |
| 109 | protected void onResume() { |
| 110 | super.onResume(); |
| 111 | |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame^] | 112 | mAirplaneModeEnabler.resume(); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 113 | mWifiEnabler.resume(); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 114 | mBtEnabler.resume(); |
| 115 | } |
| 116 | |
| 117 | @Override |
| 118 | protected void onPause() { |
| 119 | super.onPause(); |
| 120 | |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 121 | mAirplaneModeEnabler.pause(); |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame^] | 122 | mWifiEnabler.pause(); |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 123 | mBtEnabler.pause(); |
| 124 | } |
| 125 | |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 126 | @Override |
| 127 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
Chia-chi Yeh | 4e14211 | 2009-12-25 14:48:46 +0800 | [diff] [blame^] | 128 | if (requestCode == REQUEST_CODE_EXIT_ECM) { |
| 129 | Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false); |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 130 | // Set Airplane mode based on the return value and checkbox state |
| 131 | mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes, |
| 132 | mAirplaneModePreference.isChecked()); |
Chouting Zhang | 71cc49e | 2009-08-28 14:36:35 -0500 | [diff] [blame] | 133 | } |
| 134 | } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 135 | } |