blob: bf75e27af7b8a86f34f4e3eeac0fd908192d2726 [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;
Chia-chi Yehb90452f2010-01-13 06:11:29 +080020import android.content.Context;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050021import android.content.Intent;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080022import android.net.wifi.WifiManager;
23import android.os.Bundle;
Michael Chan0cb37432009-10-29 14:42:06 -070024import android.os.ServiceManager;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050025import android.os.SystemProperties;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080026import android.preference.CheckBoxPreference;
Mike Lockwood83bcc982009-07-29 23:25:10 -070027import android.preference.Preference;
28import android.preference.PreferenceActivity;
Michael Chan0cb37432009-10-29 14:42:06 -070029import android.preference.PreferenceScreen;
Mike Lockwood83bcc982009-07-29 23:25:10 -070030import android.provider.Settings;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080031
Chouting Zhang71cc49e2009-08-28 14:36:35 -050032import com.android.internal.telephony.TelephonyIntents;
33import com.android.internal.telephony.TelephonyProperties;
Michael Chan0cb37432009-10-29 14:42:06 -070034import com.android.settings.bluetooth.BluetoothEnabler;
35import com.android.settings.wifi.WifiEnabler;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050036
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080037public 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 Lockwood83bcc982009-07-29 23:25:10 -070042 private static final String KEY_WIFI_SETTINGS = "wifi_settings";
Michael Chan0cb37432009-10-29 14:42:06 -070043 private static final String KEY_BT_SETTINGS = "bt_settings";
Mike Lockwood83bcc982009-07-29 23:25:10 -070044 private static final String KEY_VPN_SETTINGS = "vpn_settings";
Chouting Zhang71cc49e2009-08-28 14:36:35 -050045 public static final String EXIT_ECM_RESULT = "exit_ecm_result";
46 public static final int REQUEST_CODE_EXIT_ECM = 1;
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080047
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080048 private AirplaneModeEnabler mAirplaneModeEnabler;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050049 private CheckBoxPreference mAirplaneModePreference;
Chia-chi Yeh4e142112009-12-25 14:48:46 +080050 private WifiEnabler mWifiEnabler;
51 private BluetoothEnabler mBtEnabler;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050052
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 Yeh4e142112009-12-25 14:48:46 +080060 if (preference == mAirplaneModePreference && Boolean.parseBoolean(
61 SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
Chouting Zhang71cc49e2009-08-28 14:36:35 -050062 // 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 Zhang71cc49e2009-08-28 14:36:35 -050066 return true;
67 }
Chia-chi Yeh4e142112009-12-25 14:48:46 +080068 // Let the intents be launched by the Preference manager
69 return false;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050070 }
Chia-chi Yehb90452f2010-01-13 06:11:29 +080071
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 Projectafc4ab22009-03-03 19:32:34 -080082 @Override
83 protected void onCreate(Bundle savedInstanceState) {
84 super.onCreate(savedInstanceState);
85
86 addPreferencesFromResource(R.xml.wireless_settings);
87
Chia-chi Yeh4e142112009-12-25 14:48:46 +080088 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 Zhang71cc49e2009-08-28 14:36:35 -050093 mAirplaneModePreference = (CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE);
Chia-chi Yeh4e142112009-12-25 14:48:46 +080094 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 Yehb90452f2010-01-13 06:11:29 +0800100 // Manually set dependencies for Wifi when not toggleable.
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800101 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 Yehb90452f2010-01-13 06:11:29 +0800113 // Disable Bluetooth Settings if Bluetooth service is not available.
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800114 if (ServiceManager.getService(BluetoothAdapter.BLUETOOTH_SERVICE) == null) {
115 findPreference(KEY_BT_SETTINGS).setEnabled(false);
116 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800117 }
118
119 @Override
120 protected void onResume() {
121 super.onResume();
122
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800123 mAirplaneModeEnabler.resume();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800124 mWifiEnabler.resume();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800125 mBtEnabler.resume();
126 }
127
128 @Override
129 protected void onPause() {
130 super.onPause();
131
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800132 mAirplaneModeEnabler.pause();
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800133 mWifiEnabler.pause();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800134 mBtEnabler.pause();
135 }
136
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500137 @Override
138 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Chia-chi Yeh4e142112009-12-25 14:48:46 +0800139 if (requestCode == REQUEST_CODE_EXIT_ECM) {
140 Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false);
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500141 // Set Airplane mode based on the return value and checkbox state
142 mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes,
143 mAirplaneModePreference.isChecked());
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500144 }
145 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800146}