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