blob: 22417bb3804f17563c6627ec28264a4bbe759bee [file] [log] [blame]
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -08001/*
2 * Copyright (C) 2007 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
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.IBinder;
24import 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
48 private WifiEnabler mWifiEnabler;
49 private AirplaneModeEnabler mAirplaneModeEnabler;
50 private BluetoothEnabler mBtEnabler;
Chouting Zhang71cc49e2009-08-28 14:36:35 -050051 private CheckBoxPreference mAirplaneModePreference;
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) {
60 if ( (preference == mAirplaneModePreference) &&
61 (Boolean.parseBoolean(
62 SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) ) {
63 // In ECM mode launch ECM app dialog
64 startActivityForResult(
65 new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null),
66 REQUEST_CODE_EXIT_ECM);
67
68 return true;
69 }
70 else {
71 // Let the intents be launched by the Preference manager
72 return false;
73 }
74 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080075
76 @Override
77 protected void onCreate(Bundle savedInstanceState) {
78 super.onCreate(savedInstanceState);
79
80 addPreferencesFromResource(R.xml.wireless_settings);
81
82 initToggles();
Chouting Zhang71cc49e2009-08-28 14:36:35 -050083 mAirplaneModePreference = (CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080084 }
85
86 @Override
87 protected void onResume() {
88 super.onResume();
89
90 mWifiEnabler.resume();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080091 mBtEnabler.resume();
Michael Chand3da33792009-09-02 15:20:07 -070092 mAirplaneModeEnabler.resume();
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -080093 }
94
95 @Override
96 protected void onPause() {
97 super.onPause();
98
99 mWifiEnabler.pause();
100 mAirplaneModeEnabler.pause();
101 mBtEnabler.pause();
102 }
103
104 private void initToggles() {
105
Mike Lockwood83bcc982009-07-29 23:25:10 -0700106 Preference airplanePreference = findPreference(KEY_TOGGLE_AIRPLANE);
107 Preference wifiPreference = findPreference(KEY_TOGGLE_WIFI);
108 Preference btPreference = findPreference(KEY_TOGGLE_BLUETOOTH);
109 Preference wifiSettings = findPreference(KEY_WIFI_SETTINGS);
110 Preference vpnSettings = findPreference(KEY_VPN_SETTINGS);
111
Michael Chan0cb37432009-10-29 14:42:06 -0700112 IBinder b = ServiceManager.getService(BluetoothAdapter.BLUETOOTH_SERVICE);
113 if (b == null) {
114 // Disable BT Settings if BT service is not available.
115 Preference btSettings = findPreference(KEY_BT_SETTINGS);
116 btSettings.setEnabled(false);
117 }
118
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800119 mWifiEnabler = new WifiEnabler(
Mike Lockwood83bcc982009-07-29 23:25:10 -0700120 this, (WifiManager) getSystemService(WIFI_SERVICE),
121 (CheckBoxPreference) wifiPreference);
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800122 mAirplaneModeEnabler = new AirplaneModeEnabler(
Mike Lockwood83bcc982009-07-29 23:25:10 -0700123 this, (CheckBoxPreference) airplanePreference);
124 mBtEnabler = new BluetoothEnabler(this, (CheckBoxPreference) btPreference);
125
126 // manually set up dependencies for Wifi if its radio is not toggleable in airplane mode
127 String toggleableRadios = Settings.System.getString(getContentResolver(),
128 Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
129 if (toggleableRadios == null || !toggleableRadios.contains(Settings.System.RADIO_WIFI)) {
130 wifiPreference.setDependency(airplanePreference.getKey());
131 wifiSettings.setDependency(airplanePreference.getKey());
132 vpnSettings.setDependency(airplanePreference.getKey());
133 }
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800134 }
Mike Lockwood83bcc982009-07-29 23:25:10 -0700135
Chouting Zhang71cc49e2009-08-28 14:36:35 -0500136 @Override
137 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
138 switch(requestCode) {
139 case REQUEST_CODE_EXIT_ECM:
140 Boolean isChoiceYes =
141 data.getBooleanExtra(EXIT_ECM_RESULT, false);
142 // Set Airplane mode based on the return value and checkbox state
143 mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes,
144 mAirplaneModePreference.isChecked());
145 break;
146
147 default:
148 break;
149 }
150 }
151
The Android Open Source Projectafc4ab22009-03-03 19:32:34 -0800152}