blob: 1d0b2d89a5248d4bafcadf58ff5212b337bd355d [file] [log] [blame]
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001/*
Chia-chi Yeh4e142112009-12-25 14:48:46 +08002 * Copyright (C) 2009 The Android Open Source Project
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08003 *
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
Michael Chan0cb37432009-10-29 14:42:06 -070019import android.bluetooth.BluetoothAdapter;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050020import android.content.Intent;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080021import android.net.wifi.WifiManager;
22import android.os.Bundle;
Michael Chan0cb37432009-10-29 14:42:06 -070023import android.os.ServiceManager;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050024import android.os.SystemProperties;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080025import android.preference.CheckBoxPreference;
Mike Lockwood83bcc982009-07-29 23:25:10 -070026import android.preference.Preference;
27import android.preference.PreferenceActivity;
Michael Chan0cb37432009-10-29 14:42:06 -070028import android.preference.PreferenceScreen;
Mike Lockwood83bcc982009-07-29 23:25:10 -070029import android.provider.Settings;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080030
Chouting Zhang71cc49e2009-08-28 14:36:35 -050031import com.android.internal.telephony.TelephonyIntents;
32import com.android.internal.telephony.TelephonyProperties;
Michael Chan0cb37432009-10-29 14:42:06 -070033import com.android.settings.bluetooth.BluetoothEnabler;
34import com.android.settings.wifi.WifiEnabler;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050035
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080036public 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 Lockwood83bcc982009-07-29 23:25:10 -070041 private static final String KEY_WIFI_SETTINGS = "wifi_settings";
Michael Chan0cb37432009-10-29 14:42:06 -070042 private static final String KEY_BT_SETTINGS = "bt_settings";
Mike Lockwood83bcc982009-07-29 23:25:10 -070043 private static final String KEY_VPN_SETTINGS = "vpn_settings";
Chouting Zhang71cc49e2009-08-28 14:36:35 -050044 public static final String EXIT_ECM_RESULT = "exit_ecm_result";
45 public static final int REQUEST_CODE_EXIT_ECM = 1;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080046
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080047 private AirplaneModeEnabler mAirplaneModeEnabler;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050048 private CheckBoxPreference mAirplaneModePreference;
Chia-chi Yeh4e142112009-12-25 14:48:46 +080049 private WifiEnabler mWifiEnabler;
50 private BluetoothEnabler mBtEnabler;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050051
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 Yeh4e142112009-12-25 14:48:46 +080059 if (preference == mAirplaneModePreference && Boolean.parseBoolean(
60 SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
Chouting Zhang71cc49e2009-08-28 14:36:35 -050061 // 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 Zhang71cc49e2009-08-28 14:36:35 -050065 return true;
66 }
Chia-chi Yeh4e142112009-12-25 14:48:46 +080067 // Let the intents be launched by the Preference manager
68 return false;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050069 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080070
71 @Override
72 protected void onCreate(Bundle savedInstanceState) {
73 super.onCreate(savedInstanceState);
74
75 addPreferencesFromResource(R.xml.wireless_settings);
76
Chia-chi Yeh4e142112009-12-25 14:48:46 +080077 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 Zhang71cc49e2009-08-28 14:36:35 -050082 mAirplaneModePreference = (CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE);
Chia-chi Yeh4e142112009-12-25 14:48:46 +080083 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 Projectafc4ab22009-03-03 19:32:34 -0800106 }
107
108 @Override
109 protected void onResume() {
110 super.onResume();
111
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800112 mAirplaneModeEnabler.resume();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800113 mWifiEnabler.resume();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800114 mBtEnabler.resume();
115 }
116
117 @Override
118 protected void onPause() {
119 super.onPause();
120
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800121 mAirplaneModeEnabler.pause();
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800122 mWifiEnabler.pause();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800123 mBtEnabler.pause();
124 }
125
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500126 @Override
127 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800128 if (requestCode == REQUEST_CODE_EXIT_ECM) {
129 Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500130 // Set Airplane mode based on the return value and checkbox state
131 mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes,
132 mAirplaneModePreference.isChecked());
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500133 }
134 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800135}