blob: c5688e6d9c844bcfafad923adf47f7916afd2b3d [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2008 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
Joe Onorato798ac4c2010-05-27 16:39:00 -040017package com.android.systemui.statusbar.policy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080018
Joe Onorato798ac4c2010-05-27 16:39:00 -040019import android.app.StatusBarManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import android.app.AlertDialog;
21import android.bluetooth.BluetoothA2dp;
Nick Pellybd022f42009-08-14 18:33:38 -070022import android.bluetooth.BluetoothAdapter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.bluetooth.BluetoothHeadset;
Jiafa Liu3f416732009-07-02 16:36:02 +080024import android.bluetooth.BluetoothPbap;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.content.BroadcastReceiver;
Daniel Sandler0e9d2af2010-01-25 11:33:03 -050026import android.content.ContentResolver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.content.Context;
28import android.content.DialogInterface;
29import android.content.Intent;
30import android.content.IntentFilter;
31import android.content.res.TypedArray;
32import android.graphics.PixelFormat;
Daniel Sandler2c195f72010-05-21 15:42:06 -040033import android.graphics.Typeface;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.graphics.drawable.Drawable;
Mike Lockwood00b74272010-03-26 10:41:48 -040035import android.location.LocationManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.media.AudioManager;
Daniel Sandler0e9d2af2010-01-25 11:33:03 -050037import android.media.Ringtone;
38import android.media.RingtoneManager;
Robert Greenwaltd7085fc2010-09-08 15:24:47 -070039import android.net.ConnectivityManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040import android.net.NetworkInfo;
Daniel Sandler0e9d2af2010-01-25 11:33:03 -050041import android.net.Uri;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042import android.net.wifi.WifiManager;
Dianne Hackborn4840e142009-03-24 22:40:29 -070043import android.os.Binder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044import android.os.Handler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045import android.os.Message;
Dianne Hackborn4840e142009-03-24 22:40:29 -070046import android.os.RemoteException;
San Mehat4154c072010-02-09 18:37:54 -080047import android.os.storage.StorageManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048import android.provider.Settings;
49import android.telephony.PhoneStateListener;
50import android.telephony.ServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -070051import android.telephony.SignalStrength;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052import android.telephony.TelephonyManager;
53import android.text.format.DateFormat;
Daniel Sandler2c195f72010-05-21 15:42:06 -040054import android.text.style.CharacterStyle;
Eric Fischer36e136c2010-01-14 17:42:48 -080055import android.text.style.RelativeSizeSpan;
Daniel Sandler2c195f72010-05-21 15:42:06 -040056import android.text.style.ForegroundColorSpan;
57import android.text.style.StyleSpan;
Eric Fischer36e136c2010-01-14 17:42:48 -080058import android.text.Spannable;
59import android.text.SpannableStringBuilder;
Joe Onorato8a9b2202010-02-26 18:56:32 -080060import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import android.view.View;
62import android.view.ViewGroup;
63import android.view.WindowManager;
64import android.view.WindowManagerImpl;
65import android.widget.ImageView;
66import android.widget.LinearLayout;
67import android.widget.TextView;
68
Wink Saville04e71b32009-04-02 11:00:54 -070069import com.android.internal.app.IBatteryStats;
Wink Saville04e71b32009-04-02 11:00:54 -070070import com.android.internal.telephony.IccCard;
71import com.android.internal.telephony.TelephonyIntents;
Wink Savillee9b06d72009-05-18 21:47:50 -070072import com.android.internal.telephony.cdma.EriInfo;
Wink Saville04e71b32009-04-02 11:00:54 -070073import com.android.internal.telephony.cdma.TtyIntent;
74import com.android.server.am.BatteryStatsService;
75
Joe Onorato798ac4c2010-05-27 16:39:00 -040076import com.android.systemui.R;
77
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078/**
79 * This class contains all of the policy about which icons are installed in the status
Joe Onorato798ac4c2010-05-27 16:39:00 -040080 * bar at boot time. It goes through the normal API for icons, even though it probably
81 * strictly doesn't need to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 */
83public class StatusBarPolicy {
84 private static final String TAG = "StatusBarPolicy";
85
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 // message codes for the handler
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087 private static final int EVENT_BATTERY_CLOSE = 4;
88
Daniel Sandler2c195f72010-05-21 15:42:06 -040089 private static final int AM_PM_STYLE_NORMAL = 0;
90 private static final int AM_PM_STYLE_SMALL = 1;
91 private static final int AM_PM_STYLE_GONE = 2;
92
93 private static final int AM_PM_STYLE = AM_PM_STYLE_GONE;
94
Robert Greenwaltd7085fc2010-09-08 15:24:47 -070095 private static final int INET_CONDITION_THRESHOLD = 50;
96
Dianne Hackborn4840e142009-03-24 22:40:29 -070097 private final Context mContext;
Joe Onorato798ac4c2010-05-27 16:39:00 -040098 private final StatusBarManager mService;
Dianne Hackborn4840e142009-03-24 22:40:29 -070099 private final Handler mHandler = new StatusBarHandler();
100 private final IBatteryStats mBatteryStats;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101
San Mehat4154c072010-02-09 18:37:54 -0800102 // storage
103 private StorageManager mStorageManager;
104
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105 // battery
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106 private boolean mBatteryFirst = true;
107 private boolean mBatteryPlugged;
108 private int mBatteryLevel;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 private AlertDialog mLowBatteryDialog;
110 private TextView mBatteryLevelTextView;
111 private View mBatteryView;
112 private int mBatteryViewSequence;
113 private boolean mBatteryShowLowOnEndCall = false;
114 private static final boolean SHOW_LOW_BATTERY_WARNING = true;
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500115 private static final boolean SHOW_BATTERY_WARNINGS_IN_CALL = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116
117 // phone
118 private TelephonyManager mPhone;
Joe Onorato0cbda992010-05-02 16:28:15 -0700119 private int mPhoneSignalIconId;
Wink Saville04e71b32009-04-02 11:00:54 -0700120
121 //***** Signal strength icons
Wink Saville04e71b32009-04-02 11:00:54 -0700122 //GSM/UMTS
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123 private static final int[] sSignalImages = new int[] {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400124 R.drawable.stat_sys_signal_0,
125 R.drawable.stat_sys_signal_1,
126 R.drawable.stat_sys_signal_2,
127 R.drawable.stat_sys_signal_3,
128 R.drawable.stat_sys_signal_4
Wink Savillee9b06d72009-05-18 21:47:50 -0700129 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130 private static final int[] sSignalImages_r = new int[] {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400131 R.drawable.stat_sys_r_signal_0,
132 R.drawable.stat_sys_r_signal_1,
133 R.drawable.stat_sys_r_signal_2,
134 R.drawable.stat_sys_r_signal_3,
135 R.drawable.stat_sys_r_signal_4
Wink Savillee9b06d72009-05-18 21:47:50 -0700136 };
Wink Savillee9b06d72009-05-18 21:47:50 -0700137 private static final int[] sRoamingIndicatorImages_cdma = new int[] {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400138 R.drawable.stat_sys_roaming_cdma_0, //Standard Roaming Indicator
Wink Savillee9b06d72009-05-18 21:47:50 -0700139 // 1 is Standard Roaming Indicator OFF
140 // TODO T: image never used, remove and put 0 instead?
Joe Onorato798ac4c2010-05-27 16:39:00 -0400141 R.drawable.stat_sys_roaming_cdma_0,
Wink Savillee9b06d72009-05-18 21:47:50 -0700142
143 // 2 is Standard Roaming Indicator FLASHING
144 // TODO T: image never used, remove and put 0 instead?
Joe Onorato798ac4c2010-05-27 16:39:00 -0400145 R.drawable.stat_sys_roaming_cdma_0,
Wink Savillee9b06d72009-05-18 21:47:50 -0700146
147 // 3-12 Standard ERI
Joe Onorato798ac4c2010-05-27 16:39:00 -0400148 R.drawable.stat_sys_roaming_cdma_0, //3
149 R.drawable.stat_sys_roaming_cdma_0,
150 R.drawable.stat_sys_roaming_cdma_0,
151 R.drawable.stat_sys_roaming_cdma_0,
152 R.drawable.stat_sys_roaming_cdma_0,
153 R.drawable.stat_sys_roaming_cdma_0,
154 R.drawable.stat_sys_roaming_cdma_0,
155 R.drawable.stat_sys_roaming_cdma_0,
156 R.drawable.stat_sys_roaming_cdma_0,
157 R.drawable.stat_sys_roaming_cdma_0,
Wink Savillee9b06d72009-05-18 21:47:50 -0700158
159 // 13-63 Reserved for Standard ERI
Joe Onorato798ac4c2010-05-27 16:39:00 -0400160 R.drawable.stat_sys_roaming_cdma_0, //13
161 R.drawable.stat_sys_roaming_cdma_0,
162 R.drawable.stat_sys_roaming_cdma_0,
163 R.drawable.stat_sys_roaming_cdma_0,
164 R.drawable.stat_sys_roaming_cdma_0,
165 R.drawable.stat_sys_roaming_cdma_0,
166 R.drawable.stat_sys_roaming_cdma_0,
167 R.drawable.stat_sys_roaming_cdma_0,
168 R.drawable.stat_sys_roaming_cdma_0,
169 R.drawable.stat_sys_roaming_cdma_0,
170 R.drawable.stat_sys_roaming_cdma_0,
171 R.drawable.stat_sys_roaming_cdma_0,
172 R.drawable.stat_sys_roaming_cdma_0,
173 R.drawable.stat_sys_roaming_cdma_0,
174 R.drawable.stat_sys_roaming_cdma_0,
175 R.drawable.stat_sys_roaming_cdma_0,
176 R.drawable.stat_sys_roaming_cdma_0,
177 R.drawable.stat_sys_roaming_cdma_0,
178 R.drawable.stat_sys_roaming_cdma_0,
179 R.drawable.stat_sys_roaming_cdma_0,
180 R.drawable.stat_sys_roaming_cdma_0,
181 R.drawable.stat_sys_roaming_cdma_0,
182 R.drawable.stat_sys_roaming_cdma_0,
183 R.drawable.stat_sys_roaming_cdma_0,
184 R.drawable.stat_sys_roaming_cdma_0,
185 R.drawable.stat_sys_roaming_cdma_0,
186 R.drawable.stat_sys_roaming_cdma_0,
187 R.drawable.stat_sys_roaming_cdma_0,
188 R.drawable.stat_sys_roaming_cdma_0,
189 R.drawable.stat_sys_roaming_cdma_0,
190 R.drawable.stat_sys_roaming_cdma_0,
191 R.drawable.stat_sys_roaming_cdma_0,
192 R.drawable.stat_sys_roaming_cdma_0,
193 R.drawable.stat_sys_roaming_cdma_0,
194 R.drawable.stat_sys_roaming_cdma_0,
195 R.drawable.stat_sys_roaming_cdma_0,
196 R.drawable.stat_sys_roaming_cdma_0,
197 R.drawable.stat_sys_roaming_cdma_0,
198 R.drawable.stat_sys_roaming_cdma_0,
199 R.drawable.stat_sys_roaming_cdma_0,
200 R.drawable.stat_sys_roaming_cdma_0,
201 R.drawable.stat_sys_roaming_cdma_0,
202 R.drawable.stat_sys_roaming_cdma_0,
203 R.drawable.stat_sys_roaming_cdma_0,
204 R.drawable.stat_sys_roaming_cdma_0,
205 R.drawable.stat_sys_roaming_cdma_0,
206 R.drawable.stat_sys_roaming_cdma_0,
207 R.drawable.stat_sys_roaming_cdma_0,
208 R.drawable.stat_sys_roaming_cdma_0,
209 R.drawable.stat_sys_roaming_cdma_0,
210 R.drawable.stat_sys_roaming_cdma_0,
Wink Savillee9b06d72009-05-18 21:47:50 -0700211
212 // 64-127 Reserved for Non Standard (Operator Specific) ERI
Joe Onorato798ac4c2010-05-27 16:39:00 -0400213 R.drawable.stat_sys_roaming_cdma_0, //64
214 R.drawable.stat_sys_roaming_cdma_0,
215 R.drawable.stat_sys_roaming_cdma_0,
216 R.drawable.stat_sys_roaming_cdma_0,
217 R.drawable.stat_sys_roaming_cdma_0,
218 R.drawable.stat_sys_roaming_cdma_0,
219 R.drawable.stat_sys_roaming_cdma_0,
220 R.drawable.stat_sys_roaming_cdma_0,
221 R.drawable.stat_sys_roaming_cdma_0,
222 R.drawable.stat_sys_roaming_cdma_0,
223 R.drawable.stat_sys_roaming_cdma_0,
224 R.drawable.stat_sys_roaming_cdma_0,
225 R.drawable.stat_sys_roaming_cdma_0,
226 R.drawable.stat_sys_roaming_cdma_0,
227 R.drawable.stat_sys_roaming_cdma_0,
228 R.drawable.stat_sys_roaming_cdma_0,
229 R.drawable.stat_sys_roaming_cdma_0,
230 R.drawable.stat_sys_roaming_cdma_0,
231 R.drawable.stat_sys_roaming_cdma_0,
232 R.drawable.stat_sys_roaming_cdma_0 //83
Wink Savillee9b06d72009-05-18 21:47:50 -0700233
234 // 128-255 Reserved
Wink Saville04e71b32009-04-02 11:00:54 -0700235 };
Wink Saville04e71b32009-04-02 11:00:54 -0700236
237 //***** Data connection icons
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700238 private int[] mDataIconList = sDataNetType_g[0];
Wink Saville04e71b32009-04-02 11:00:54 -0700239 //GSM/UMTS
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700240 private static final int[][] sDataNetType_g = {
241 { R.drawable.stat_sys_data_connected_g,
242 R.drawable.stat_sys_data_in_g,
243 R.drawable.stat_sys_data_out_g,
244 R.drawable.stat_sys_data_inandout_g },
245 { R.drawable.stat_sys_roaming_cdma_0,
246 R.drawable.stat_sys_roaming_cdma_0,
247 R.drawable.stat_sys_roaming_cdma_0,
248 R.drawable.stat_sys_roaming_cdma_0 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800249 };
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700250 private static final int[][] sDataNetType_3g = {
251 { R.drawable.stat_sys_data_connected_3g,
252 R.drawable.stat_sys_data_in_3g,
253 R.drawable.stat_sys_data_out_3g,
254 R.drawable.stat_sys_data_inandout_3g },
255 { R.drawable.stat_sys_roaming_cdma_0,
256 R.drawable.stat_sys_roaming_cdma_0,
257 R.drawable.stat_sys_roaming_cdma_0,
258 R.drawable.stat_sys_roaming_cdma_0 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259 };
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700260 private static final int[][] sDataNetType_e = {
261 { R.drawable.stat_sys_data_connected_e,
262 R.drawable.stat_sys_data_in_e,
263 R.drawable.stat_sys_data_out_e,
264 R.drawable.stat_sys_data_inandout_e },
265 { R.drawable.stat_sys_roaming_cdma_0,
266 R.drawable.stat_sys_roaming_cdma_0,
267 R.drawable.stat_sys_roaming_cdma_0,
268 R.drawable.stat_sys_roaming_cdma_0 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800269 };
Li Zheebe66342009-08-14 19:22:16 +0800270 //3.5G
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700271 private static final int[][] sDataNetType_h = {
272 { R.drawable.stat_sys_data_connected_h,
273 R.drawable.stat_sys_data_in_h,
274 R.drawable.stat_sys_data_out_h,
275 R.drawable.stat_sys_data_inandout_h },
276 { R.drawable.stat_sys_roaming_cdma_0,
277 R.drawable.stat_sys_roaming_cdma_0,
278 R.drawable.stat_sys_roaming_cdma_0,
279 R.drawable.stat_sys_roaming_cdma_0 }
Li Zheebe66342009-08-14 19:22:16 +0800280 };
281
Wink Saville04e71b32009-04-02 11:00:54 -0700282 //CDMA
johnwang9f87cb22009-08-25 15:25:37 -0700283 // Use 3G icons for EVDO data and 1x icons for 1XRTT data
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700284 private static final int[][] sDataNetType_1x = {
285 { R.drawable.stat_sys_data_connected_1x,
286 R.drawable.stat_sys_data_in_1x,
287 R.drawable.stat_sys_data_out_1x,
288 R.drawable.stat_sys_data_inandout_1x },
289 { R.drawable.stat_sys_roaming_cdma_0,
290 R.drawable.stat_sys_roaming_cdma_0,
291 R.drawable.stat_sys_roaming_cdma_0,
292 R.drawable.stat_sys_roaming_cdma_0 }
293 };
Wink Saville04e71b32009-04-02 11:00:54 -0700294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 // Assume it's all good unless we hear otherwise. We don't always seem
296 // to get broadcasts that it *is* there.
Wink Saville04e71b32009-04-02 11:00:54 -0700297 IccCard.State mSimState = IccCard.State.READY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800298 int mPhoneState = TelephonyManager.CALL_STATE_IDLE;
299 int mDataState = TelephonyManager.DATA_DISCONNECTED;
300 int mDataActivity = TelephonyManager.DATA_ACTIVITY_NONE;
301 ServiceState mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700302 SignalStrength mSignalStrength;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800303
304 // data connection
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800305 private boolean mDataIconVisible;
John Wang33e21fc2009-10-08 10:35:27 -0700306 private boolean mHspaDataDistinguishable;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307
308 // ringer volume
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800309 private boolean mVolumeVisible;
Wink Saville04e71b32009-04-02 11:00:54 -0700310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800311 // bluetooth device status
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800312 private int mBluetoothHeadsetState;
Jaikumar Ganesh084c6652009-12-07 10:58:18 -0800313 private boolean mBluetoothA2dpConnected;
Jiafa Liu3f416732009-07-02 16:36:02 +0800314 private int mBluetoothPbapState;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315 private boolean mBluetoothEnabled;
316
317 // wifi
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700318 private static final int[][] sWifiSignalImages = {
319 { R.drawable.stat_sys_wifi_signal_1,
320 R.drawable.stat_sys_wifi_signal_2,
321 R.drawable.stat_sys_wifi_signal_3,
322 R.drawable.stat_sys_wifi_signal_4 },
323 { R.drawable.stat_sys_data_in_e,
324 R.drawable.stat_sys_data_in_e,
325 R.drawable.stat_sys_data_in_e,
326 R.drawable.stat_sys_data_in_e }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800327 };
328 private static final int sWifiTemporarilyNotConnectedImage =
Joe Onorato798ac4c2010-05-27 16:39:00 -0400329 R.drawable.stat_sys_wifi_signal_0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800330
331 private int mLastWifiSignalLevel = -1;
332 private boolean mIsWifiConnected = false;
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700333 private int mLastWifiInetConnectivityState = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800334
335 // sync state
336 // If sync is active the SyncActive icon is displayed. If sync is not active but
337 // sync is failing the SyncFailing icon is displayed. Otherwise neither are displayed.
Wink Savillee9b06d72009-05-18 21:47:50 -0700338
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800339 private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
340 @Override
341 public void onReceive(Context context, Intent intent) {
342 String action = intent.getAction();
Joe Onorato263700d2010-05-14 11:54:53 -0700343 if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {
Dianne Hackborn8ec5b832009-07-01 21:19:35 -0700344 updateBattery(intent);
345 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346 else if (action.equals(Intent.ACTION_ALARM_CHANGED)) {
347 updateAlarm(intent);
348 }
349 else if (action.equals(Intent.ACTION_SYNC_STATE_CHANGED)) {
350 updateSyncState(intent);
351 }
Mihai Predaa82842f2009-04-29 15:05:56 +0200352 else if (action.equals(Intent.ACTION_BATTERY_LOW)) {
353 onBatteryLow(intent);
354 }
Mike Lockwood69eb0bf2009-08-01 23:02:28 -0400355 else if (action.equals(Intent.ACTION_BATTERY_OKAY)
356 || action.equals(Intent.ACTION_POWER_CONNECTED)) {
Dianne Hackborn8ec5b832009-07-01 21:19:35 -0700357 onBatteryOkay(intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800358 }
Nick Pellyde893f52009-09-08 13:15:33 -0700359 else if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED) ||
Nick Pelly005b2282009-09-10 10:21:56 -0700360 action.equals(BluetoothHeadset.ACTION_STATE_CHANGED) ||
361 action.equals(BluetoothA2dp.ACTION_SINK_STATE_CHANGED) ||
Jiafa Liu3f416732009-07-02 16:36:02 +0800362 action.equals(BluetoothPbap.PBAP_STATE_CHANGED_ACTION)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363 updateBluetooth(intent);
364 }
365 else if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION) ||
366 action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION) ||
367 action.equals(WifiManager.RSSI_CHANGED_ACTION)) {
368 updateWifi(intent);
369 }
Mike Lockwood00b74272010-03-26 10:41:48 -0400370 else if (action.equals(LocationManager.GPS_ENABLED_CHANGE_ACTION) ||
371 action.equals(LocationManager.GPS_FIX_CHANGE_ACTION)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800372 updateGps(intent);
373 }
374 else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION) ||
375 action.equals(AudioManager.VIBRATE_SETTING_CHANGED_ACTION)) {
376 updateVolume();
377 }
378 else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
379 updateSimState(intent);
380 }
Wink Saville04e71b32009-04-02 11:00:54 -0700381 else if (action.equals(TtyIntent.TTY_ENABLED_CHANGE_ACTION)) {
382 updateTTY(intent);
383 }
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700384 else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
385 // TODO - stop using other means to get wifi/mobile info
386 updateConnectivity(intent);
387 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388 }
389 };
390
Joe Onorato798ac4c2010-05-27 16:39:00 -0400391 public StatusBarPolicy(Context context) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800392 mContext = context;
Joe Onorato798ac4c2010-05-27 16:39:00 -0400393 mService = (StatusBarManager)context.getSystemService(Context.STATUS_BAR_SERVICE);
Wink Savillee9b06d72009-05-18 21:47:50 -0700394 mSignalStrength = new SignalStrength();
Dianne Hackborn4840e142009-03-24 22:40:29 -0700395 mBatteryStats = BatteryStatsService.getService();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800396
San Mehat4154c072010-02-09 18:37:54 -0800397 // storage
398 mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
399 mStorageManager.registerListener(
Joe Onoratofe4f3ae2010-06-04 11:25:26 -0700400 new com.android.systemui.usb.StorageNotification(context));
San Mehat4154c072010-02-09 18:37:54 -0800401
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800402 // battery
Joe Onorato798ac4c2010-05-27 16:39:00 -0400403 mService.setIcon("battery", com.android.internal.R.drawable.stat_sys_battery_unknown, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404
405 // phone_signal
406 mPhone = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
Joe Onorato798ac4c2010-05-27 16:39:00 -0400407 mPhoneSignalIconId = R.drawable.stat_sys_signal_null;
408 mService.setIcon("phone_signal", mPhoneSignalIconId, 0);
Wink Savillee9b06d72009-05-18 21:47:50 -0700409
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800410 // register for phone state notifications.
411 ((TelephonyManager)mContext.getSystemService(Context.TELEPHONY_SERVICE))
412 .listen(mPhoneStateListener,
413 PhoneStateListener.LISTEN_SERVICE_STATE
Wink Savillee9b06d72009-05-18 21:47:50 -0700414 | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800415 | PhoneStateListener.LISTEN_CALL_STATE
416 | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
417 | PhoneStateListener.LISTEN_DATA_ACTIVITY);
418
419 // data_connection
Joe Onorato798ac4c2010-05-27 16:39:00 -0400420 mService.setIcon("data_connection", R.drawable.stat_sys_data_connected_g, 0);
421 mService.setIconVisibility("data_connection", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422
423 // wifi
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700424 mService.setIcon("wifi", sWifiSignalImages[0][0], 0);
Joe Onorato798ac4c2010-05-27 16:39:00 -0400425 mService.setIconVisibility("wifi", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800426 // wifi will get updated by the sticky intents
Wink Saville04e71b32009-04-02 11:00:54 -0700427
428 // TTY status
Joe Onorato798ac4c2010-05-27 16:39:00 -0400429 mService.setIcon("tty", R.drawable.stat_sys_tty_mode, 0);
430 mService.setIconVisibility("tty", false);
Wink Saville04e71b32009-04-02 11:00:54 -0700431
Wink Savillee9b06d72009-05-18 21:47:50 -0700432 // Cdma Roaming Indicator, ERI
Joe Onorato798ac4c2010-05-27 16:39:00 -0400433 mService.setIcon("cdma_eri", R.drawable.stat_sys_roaming_cdma_0, 0);
434 mService.setIconVisibility("cdma_eri", false);
Wink Savillee9b06d72009-05-18 21:47:50 -0700435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800436 // bluetooth status
Joe Onorato798ac4c2010-05-27 16:39:00 -0400437 mService.setIcon("bluetooth", R.drawable.stat_sys_data_bluetooth, 0);
Nick Pellyf242b7b2009-10-08 00:12:45 +0200438 BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
Nick Pellybd022f42009-08-14 18:33:38 -0700439 if (adapter != null) {
440 mBluetoothEnabled = adapter.isEnabled();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800441 } else {
442 mBluetoothEnabled = false;
443 }
Jaikumar Ganesh084c6652009-12-07 10:58:18 -0800444 mBluetoothA2dpConnected = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800445 mBluetoothHeadsetState = BluetoothHeadset.STATE_DISCONNECTED;
Jiafa Liu3f416732009-07-02 16:36:02 +0800446 mBluetoothPbapState = BluetoothPbap.STATE_DISCONNECTED;
Joe Onorato0cbda992010-05-02 16:28:15 -0700447 mService.setIconVisibility("bluetooth", mBluetoothEnabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800448
449 // Gps status
Joe Onorato798ac4c2010-05-27 16:39:00 -0400450 mService.setIcon("gps", R.drawable.stat_sys_gps_acquiring_anim, 0);
451 mService.setIconVisibility("gps", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800452
453 // Alarm clock
Joe Onorato798ac4c2010-05-27 16:39:00 -0400454 mService.setIcon("alarm_clock", R.drawable.stat_notify_alarm, 0);
455 mService.setIconVisibility("alarm_clock", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800456
457 // Sync state
Joe Onorato798ac4c2010-05-27 16:39:00 -0400458 mService.setIcon("sync_active", com.android.internal.R.drawable.stat_notify_sync_anim0, 0);
459 mService.setIcon("sync_failing", com.android.internal.R.drawable.stat_notify_sync_error, 0);
460 mService.setIconVisibility("sync_active", false);
461 mService.setIconVisibility("sync_failing", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462
463 // volume
Joe Onorato798ac4c2010-05-27 16:39:00 -0400464 mService.setIcon("volume", R.drawable.stat_sys_ringer_silent, 0);
465 mService.setIconVisibility("volume", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800466 updateVolume();
johnwang347c5a22009-08-24 22:11:11 -0700467
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800468 IntentFilter filter = new IntentFilter();
469
470 // Register for Intent broadcasts for...
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800471 filter.addAction(Intent.ACTION_BATTERY_CHANGED);
Mihai Predaa82842f2009-04-29 15:05:56 +0200472 filter.addAction(Intent.ACTION_BATTERY_LOW);
Dianne Hackborn8ec5b832009-07-01 21:19:35 -0700473 filter.addAction(Intent.ACTION_BATTERY_OKAY);
Mike Lockwood69eb0bf2009-08-01 23:02:28 -0400474 filter.addAction(Intent.ACTION_POWER_CONNECTED);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800475 filter.addAction(Intent.ACTION_ALARM_CHANGED);
476 filter.addAction(Intent.ACTION_SYNC_STATE_CHANGED);
477 filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
478 filter.addAction(AudioManager.VIBRATE_SETTING_CHANGED_ACTION);
Nick Pellyde893f52009-09-08 13:15:33 -0700479 filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
Nick Pelly005b2282009-09-10 10:21:56 -0700480 filter.addAction(BluetoothHeadset.ACTION_STATE_CHANGED);
481 filter.addAction(BluetoothA2dp.ACTION_SINK_STATE_CHANGED);
Jiafa Liu3f416732009-07-02 16:36:02 +0800482 filter.addAction(BluetoothPbap.PBAP_STATE_CHANGED_ACTION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800483 filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
484 filter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
485 filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
486 filter.addAction(WifiManager.RSSI_CHANGED_ACTION);
Mike Lockwood00b74272010-03-26 10:41:48 -0400487 filter.addAction(LocationManager.GPS_ENABLED_CHANGE_ACTION);
488 filter.addAction(LocationManager.GPS_FIX_CHANGE_ACTION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800489 filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
Wink Saville04e71b32009-04-02 11:00:54 -0700490 filter.addAction(TtyIntent.TTY_ENABLED_CHANGE_ACTION);
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700491 filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800492 mContext.registerReceiver(mIntentReceiver, filter, null, mHandler);
John Wang33e21fc2009-10-08 10:35:27 -0700493
494 // load config to determine if to distinguish Hspa data icon
495 try {
496 mHspaDataDistinguishable = mContext.getResources().getBoolean(
Joe Onorato798ac4c2010-05-27 16:39:00 -0400497 R.bool.config_hspa_data_distinguishable);
John Wang33e21fc2009-10-08 10:35:27 -0700498 } catch (Exception e) {
499 mHspaDataDistinguishable = false;
500 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501 }
502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503 private final void updateAlarm(Intent intent) {
504 boolean alarmSet = intent.getBooleanExtra("alarmSet", false);
Joe Onorato0cbda992010-05-02 16:28:15 -0700505 mService.setIconVisibility("alarm_clock", alarmSet);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800506 }
507
508 private final void updateSyncState(Intent intent) {
509 boolean isActive = intent.getBooleanExtra("active", false);
510 boolean isFailing = intent.getBooleanExtra("failing", false);
Joe Onorato0cbda992010-05-02 16:28:15 -0700511 mService.setIconVisibility("sync_active", isActive);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800512 // Don't display sync failing icon: BUG 1297963 Set sync error timeout to "never"
Joe Onorato0cbda992010-05-02 16:28:15 -0700513 //mService.setIconVisibility("sync_failing", isFailing && !isActive);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800514 }
515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800516 private final void updateBattery(Intent intent) {
Joe Onorato0cbda992010-05-02 16:28:15 -0700517 final int id = intent.getIntExtra("icon-small", 0);
518 int level = intent.getIntExtra("level", 0);
Joe Onorato798ac4c2010-05-27 16:39:00 -0400519 mService.setIcon("battery", id, level);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800520
521 boolean plugged = intent.getIntExtra("plugged", 0) != 0;
Joe Onorato0cbda992010-05-02 16:28:15 -0700522 level = intent.getIntExtra("level", -1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800523 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800524 Slog.d(TAG, "updateBattery level=" + level
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800525 + " plugged=" + plugged
526 + " mBatteryPlugged=" + mBatteryPlugged
527 + " mBatteryLevel=" + mBatteryLevel
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528 + " mBatteryFirst=" + mBatteryFirst);
529 }
530
531 boolean oldPlugged = mBatteryPlugged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532
533 mBatteryPlugged = plugged;
534 mBatteryLevel = level;
535
536 if (mBatteryFirst) {
537 mBatteryFirst = false;
538 }
539 /*
540 * No longer showing the battery view because it draws attention away
541 * from the USB storage notification. We could still show it when
542 * connected to a brick, but that could lead to the user into thinking
543 * the device does not charge when plugged into USB (since he/she would
544 * not see the same battery screen on USB as he sees on brick).
545 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800546 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800547 Slog.d(TAG, "plugged=" + plugged + " oldPlugged=" + oldPlugged + " level=" + level);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800548 }
Mihai Predaa82842f2009-04-29 15:05:56 +0200549 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800550
Mihai Predaa82842f2009-04-29 15:05:56 +0200551 private void onBatteryLow(Intent intent) {
552 if (SHOW_LOW_BATTERY_WARNING) {
553 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800554 Slog.d(TAG, "mPhoneState=" + mPhoneState
Mihai Predaa82842f2009-04-29 15:05:56 +0200555 + " mLowBatteryDialog=" + mLowBatteryDialog
556 + " mBatteryShowLowOnEndCall=" + mBatteryShowLowOnEndCall);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800557 }
Mihai Predaa82842f2009-04-29 15:05:56 +0200558
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500559 if (SHOW_BATTERY_WARNINGS_IN_CALL || mPhoneState == TelephonyManager.CALL_STATE_IDLE) {
Mihai Predaa82842f2009-04-29 15:05:56 +0200560 showLowBatteryWarning();
561 } else {
562 mBatteryShowLowOnEndCall = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 }
564 }
565 }
566
Dianne Hackborn8ec5b832009-07-01 21:19:35 -0700567 private void onBatteryOkay(Intent intent) {
568 if (mLowBatteryDialog != null
569 && SHOW_LOW_BATTERY_WARNING) {
570 mLowBatteryDialog.dismiss();
571 mBatteryShowLowOnEndCall = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800572 }
573 }
574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575 private void setBatteryLevel(View parent, int id, int height, int background, int level) {
576 ImageView v = (ImageView)parent.findViewById(id);
577 LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)v.getLayoutParams();
578 lp.weight = height;
579 if (background != 0) {
580 v.setBackgroundResource(background);
581 Drawable bkg = v.getBackground();
582 bkg.setLevel(level);
583 }
584 }
585
586 private void showLowBatteryWarning() {
587 closeLastBatteryView();
588
Mike Lockwoodd81b1f42009-09-25 09:32:19 -0400589 // Show exact battery level.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 CharSequence levelText = mContext.getString(
Joe Onorato798ac4c2010-05-27 16:39:00 -0400591 R.string.battery_low_percent_format, mBatteryLevel);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800592
593 if (mBatteryLevelTextView != null) {
594 mBatteryLevelTextView.setText(levelText);
595 } else {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400596 View v = View.inflate(mContext, R.layout.battery_low, null);
597 mBatteryLevelTextView=(TextView)v.findViewById(R.id.level_percent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800598
599 mBatteryLevelTextView.setText(levelText);
600
601 AlertDialog.Builder b = new AlertDialog.Builder(mContext);
602 b.setCancelable(true);
Joe Onorato798ac4c2010-05-27 16:39:00 -0400603 b.setTitle(R.string.battery_low_title);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800604 b.setView(v);
605 b.setIcon(android.R.drawable.ic_dialog_alert);
606 b.setPositiveButton(android.R.string.ok, null);
johnwang347c5a22009-08-24 22:11:11 -0700607
Dianne Hackborn3d74bb42009-06-19 10:35:21 -0700608 final Intent intent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
609 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
610 | Intent.FLAG_ACTIVITY_MULTIPLE_TASK
611 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
612 | Intent.FLAG_ACTIVITY_NO_HISTORY);
613 if (intent.resolveActivity(mContext.getPackageManager()) != null) {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400614 b.setNegativeButton(R.string.battery_low_why,
Dianne Hackborn3d74bb42009-06-19 10:35:21 -0700615 new DialogInterface.OnClickListener() {
616 public void onClick(DialogInterface dialog, int which) {
617 mContext.startActivity(intent);
618 if (mLowBatteryDialog != null) {
619 mLowBatteryDialog.dismiss();
620 }
621 }
622 });
623 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800624
625 AlertDialog d = b.create();
626 d.setOnDismissListener(mLowBatteryListener);
627 d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
628 d.show();
629 mLowBatteryDialog = d;
630 }
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500631
632 final ContentResolver cr = mContext.getContentResolver();
633 if (Settings.System.getInt(cr,
John Wang56c2d2f2010-04-07 08:57:17 -0700634 Settings.System.POWER_SOUNDS_ENABLED, 1) == 1)
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500635 {
636 final String soundPath = Settings.System.getString(cr,
637 Settings.System.LOW_BATTERY_SOUND);
638 if (soundPath != null) {
639 final Uri soundUri = Uri.parse("file://" + soundPath);
640 if (soundUri != null) {
641 final Ringtone sfx = RingtoneManager.getRingtone(mContext, soundUri);
Daniel Sandlerec2c88d2010-02-20 01:04:57 -0500642 if (sfx != null) {
643 sfx.setStreamType(AudioManager.STREAM_SYSTEM);
644 sfx.play();
645 }
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500646 }
647 }
648 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800649 }
650
651 private final void updateCallState(int state) {
652 mPhoneState = state;
653 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800654 Slog.d(TAG, "mPhoneState=" + mPhoneState
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800655 + " mLowBatteryDialog=" + mLowBatteryDialog
656 + " mBatteryShowLowOnEndCall=" + mBatteryShowLowOnEndCall);
657 }
658 if (mPhoneState == TelephonyManager.CALL_STATE_IDLE) {
659 if (mBatteryShowLowOnEndCall) {
660 if (!mBatteryPlugged) {
661 showLowBatteryWarning();
662 }
663 mBatteryShowLowOnEndCall = false;
664 }
665 } else {
666 if (mLowBatteryDialog != null) {
667 mLowBatteryDialog.dismiss();
668 mBatteryShowLowOnEndCall = true;
669 }
670 }
671 }
672
673 private DialogInterface.OnDismissListener mLowBatteryListener
674 = new DialogInterface.OnDismissListener() {
675 public void onDismiss(DialogInterface dialog) {
676 mLowBatteryDialog = null;
677 mBatteryLevelTextView = null;
678 }
679 };
680
681 private void scheduleCloseBatteryView() {
682 Message m = mHandler.obtainMessage(EVENT_BATTERY_CLOSE);
683 m.arg1 = (++mBatteryViewSequence);
684 mHandler.sendMessageDelayed(m, 3000);
685 }
686
687 private void closeLastBatteryView() {
688 if (mBatteryView != null) {
689 //mBatteryView.debug();
690 WindowManagerImpl.getDefault().removeView(mBatteryView);
691 mBatteryView = null;
692 }
693 }
694
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700695 private void updateConnectivity(Intent intent) {
696 NetworkInfo info = (NetworkInfo)(intent.getParcelableExtra(
697 ConnectivityManager.EXTRA_NETWORK_INFO));
698 int connectionStatus = intent.getIntExtra(ConnectivityManager.EXTRA_INET_CONDITION, 0);
699 Slog.d(TAG, "got CONNECTIVITY_ACTION - info=" + info + ", status = " + connectionStatus);
700 if (info.isConnected() == false) return;
701
702 switch (info.getType()) {
703 case ConnectivityManager.TYPE_MOBILE:
704 if (info.isConnected()) {
705 updateDataNetType(info.getSubtype(), connectionStatus);
706 updateDataIcon();
707 }
708 break;
709 case ConnectivityManager.TYPE_WIFI:
710 if (info.isConnected()) {
711 mIsWifiConnected = true;
712 mLastWifiInetConnectivityState =
713 (connectionStatus > INET_CONDITION_THRESHOLD ? 1 : 0);
714 int iconId;
715 if (mLastWifiSignalLevel == -1) {
716 iconId = sWifiSignalImages[mLastWifiInetConnectivityState][0];
717 } else {
718 iconId = sWifiSignalImages[mLastWifiInetConnectivityState]
719 [mLastWifiSignalLevel];
720 }
721
722 mService.setIcon("wifi", iconId, 0);
723 // Show the icon since wi-fi is connected
724 mService.setIconVisibility("wifi", true);
725 } else {
726 mLastWifiSignalLevel = -1;
727 mIsWifiConnected = false;
728 mLastWifiInetConnectivityState = 0;
729 int iconId = sWifiSignalImages[0][0];
730
731 mService.setIcon("wifi", iconId, 0);
732 // Hide the icon since we're not connected
733 mService.setIconVisibility("wifi", false);
734 }
735 break;
736 }
737 }
738
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800739 private PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
740 @Override
Wink Savillee9b06d72009-05-18 21:47:50 -0700741 public void onSignalStrengthsChanged(SignalStrength signalStrength) {
742 mSignalStrength = signalStrength;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800743 updateSignalStrength();
744 }
745
746 @Override
747 public void onServiceStateChanged(ServiceState state) {
748 mServiceState = state;
749 updateSignalStrength();
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700750 updateCdmaRoamingIcon(state);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800751 updateDataIcon();
752 }
753
754 @Override
755 public void onCallStateChanged(int state, String incomingNumber) {
756 updateCallState(state);
johnwang347c5a22009-08-24 22:11:11 -0700757 // In cdma, if a voice call is made, RSSI should switch to 1x.
758 if (isCdma()) {
759 updateSignalStrength();
760 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800761 }
762
763 @Override
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700764 public void onDataConnectionStateChanged(int state, int networkType) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800765 mDataState = state;
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700766 updateDataNetType(networkType, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800767 updateDataIcon();
768 }
769
770 @Override
771 public void onDataActivity(int direction) {
772 mDataActivity = direction;
773 updateDataIcon();
774 }
775 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800776
777 private final void updateSimState(Intent intent) {
Wink Saville04e71b32009-04-02 11:00:54 -0700778 String stateExtra = intent.getStringExtra(IccCard.INTENT_KEY_ICC_STATE);
779 if (IccCard.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) {
780 mSimState = IccCard.State.ABSENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800781 }
Wink Saville04e71b32009-04-02 11:00:54 -0700782 else if (IccCard.INTENT_VALUE_ICC_READY.equals(stateExtra)) {
783 mSimState = IccCard.State.READY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800784 }
Wink Saville04e71b32009-04-02 11:00:54 -0700785 else if (IccCard.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) {
786 final String lockedReason = intent.getStringExtra(IccCard.INTENT_KEY_LOCKED_REASON);
787 if (IccCard.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) {
788 mSimState = IccCard.State.PIN_REQUIRED;
johnwang347c5a22009-08-24 22:11:11 -0700789 }
Wink Saville04e71b32009-04-02 11:00:54 -0700790 else if (IccCard.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) {
791 mSimState = IccCard.State.PUK_REQUIRED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800792 }
793 else {
Wink Saville04e71b32009-04-02 11:00:54 -0700794 mSimState = IccCard.State.NETWORK_LOCKED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800795 }
796 } else {
Wink Saville04e71b32009-04-02 11:00:54 -0700797 mSimState = IccCard.State.UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800798 }
799 updateDataIcon();
800 }
801
Wink Savillee9b06d72009-05-18 21:47:50 -0700802 private boolean isCdma() {
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700803 return (mSignalStrength != null) && !mSignalStrength.isGsm();
Wink Savillee9b06d72009-05-18 21:47:50 -0700804 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800805
johnwang347c5a22009-08-24 22:11:11 -0700806 private boolean isEvdo() {
807 return ( (mServiceState != null)
808 && ((mServiceState.getRadioTechnology()
809 == ServiceState.RADIO_TECHNOLOGY_EVDO_0)
810 || (mServiceState.getRadioTechnology()
Naveen Kalla0a5174a2010-04-21 14:48:03 -0700811 == ServiceState.RADIO_TECHNOLOGY_EVDO_A)
812 || (mServiceState.getRadioTechnology()
813 == ServiceState.RADIO_TECHNOLOGY_EVDO_B)));
johnwang347c5a22009-08-24 22:11:11 -0700814 }
815
Wink Savillee9b06d72009-05-18 21:47:50 -0700816 private boolean hasService() {
817 if (mServiceState != null) {
818 switch (mServiceState.getState()) {
819 case ServiceState.STATE_OUT_OF_SERVICE:
820 case ServiceState.STATE_POWER_OFF:
821 return false;
822 default:
823 return true;
824 }
825 } else {
826 return false;
827 }
828 }
829
830 private final void updateSignalStrength() {
831 int iconLevel = -1;
Wink Savillee9b06d72009-05-18 21:47:50 -0700832 int[] iconList;
Wink Savillee9b06d72009-05-18 21:47:50 -0700833
John Wang56c2d2f2010-04-07 08:57:17 -0700834 // Display signal strength while in "emergency calls only" mode
835 if (!hasService() && !mServiceState.isEmergencyOnly()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800836 //Slog.d(TAG, "updateSignalStrength: no service");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800837 if (Settings.System.getInt(mContext.getContentResolver(),
838 Settings.System.AIRPLANE_MODE_ON, 0) == 1) {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400839 mPhoneSignalIconId = R.drawable.stat_sys_signal_flightmode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800840 } else {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400841 mPhoneSignalIconId = R.drawable.stat_sys_signal_null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800842 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400843 mService.setIcon("phone_signal", mPhoneSignalIconId, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800844 return;
845 }
846
Wink Savillee9b06d72009-05-18 21:47:50 -0700847 if (!isCdma()) {
848 int asu = mSignalStrength.getGsmSignalStrength();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800849
Wink Savillee9b06d72009-05-18 21:47:50 -0700850 // ASU ranges from 0 to 31 - TS 27.007 Sec 8.5
851 // asu = 0 (-113dB or less) is very weak
852 // signal, its better to show 0 bars to the user in such cases.
853 // asu = 99 is a special case, where the signal strength is unknown.
jshee63e472010-03-18 11:14:42 -0700854 if (asu <= 2 || asu == 99) iconLevel = 0;
855 else if (asu >= 12) iconLevel = 4;
Wink Savillee9b06d72009-05-18 21:47:50 -0700856 else if (asu >= 8) iconLevel = 3;
jshee63e472010-03-18 11:14:42 -0700857 else if (asu >= 5) iconLevel = 2;
Wink Savillee9b06d72009-05-18 21:47:50 -0700858 else iconLevel = 1;
859
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700860 // Though mPhone is a Manager, this call is not an IPC
Wink Savillee9b06d72009-05-18 21:47:50 -0700861 if (mPhone.isNetworkRoaming()) {
862 iconList = sSignalImages_r;
863 } else {
864 iconList = sSignalImages;
Wink Saville04e71b32009-04-02 11:00:54 -0700865 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800866 } else {
johnwang347c5a22009-08-24 22:11:11 -0700867 iconList = this.sSignalImages;
Wink Savillee9b06d72009-05-18 21:47:50 -0700868
johnwang347c5a22009-08-24 22:11:11 -0700869 // If 3G(EV) and 1x network are available than 3G should be
870 // displayed, displayed RSSI should be from the EV side.
871 // If a voice call is made then RSSI should switch to 1x.
872 if ((mPhoneState == TelephonyManager.CALL_STATE_IDLE) && isEvdo()){
873 iconLevel = getEvdoLevel();
874 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800875 Slog.d(TAG, "use Evdo level=" + iconLevel + " to replace Cdma Level=" + getCdmaLevel());
johnwang347c5a22009-08-24 22:11:11 -0700876 }
877 } else {
878 iconLevel = getCdmaLevel();
879 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800880 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700881 mPhoneSignalIconId = iconList[iconLevel];
Joe Onorato798ac4c2010-05-27 16:39:00 -0400882 mService.setIcon("phone_signal", mPhoneSignalIconId, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800883 }
884
johnwang347c5a22009-08-24 22:11:11 -0700885 private int getCdmaLevel() {
886 final int cdmaDbm = mSignalStrength.getCdmaDbm();
887 final int cdmaEcio = mSignalStrength.getCdmaEcio();
888 int levelDbm = 0;
889 int levelEcio = 0;
890
891 if (cdmaDbm >= -75) levelDbm = 4;
892 else if (cdmaDbm >= -85) levelDbm = 3;
893 else if (cdmaDbm >= -95) levelDbm = 2;
894 else if (cdmaDbm >= -100) levelDbm = 1;
895 else levelDbm = 0;
896
897 // Ec/Io are in dB*10
898 if (cdmaEcio >= -90) levelEcio = 4;
899 else if (cdmaEcio >= -110) levelEcio = 3;
900 else if (cdmaEcio >= -130) levelEcio = 2;
901 else if (cdmaEcio >= -150) levelEcio = 1;
902 else levelEcio = 0;
903
904 return (levelDbm < levelEcio) ? levelDbm : levelEcio;
905 }
906
907 private int getEvdoLevel() {
908 int evdoDbm = mSignalStrength.getEvdoDbm();
909 int evdoSnr = mSignalStrength.getEvdoSnr();
910 int levelEvdoDbm = 0;
911 int levelEvdoSnr = 0;
912
913 if (evdoDbm >= -65) levelEvdoDbm = 4;
914 else if (evdoDbm >= -75) levelEvdoDbm = 3;
915 else if (evdoDbm >= -90) levelEvdoDbm = 2;
916 else if (evdoDbm >= -105) levelEvdoDbm = 1;
917 else levelEvdoDbm = 0;
918
John Michelau1336a562009-09-28 10:41:02 -0500919 if (evdoSnr >= 7) levelEvdoSnr = 4;
920 else if (evdoSnr >= 5) levelEvdoSnr = 3;
921 else if (evdoSnr >= 3) levelEvdoSnr = 2;
922 else if (evdoSnr >= 1) levelEvdoSnr = 1;
johnwang347c5a22009-08-24 22:11:11 -0700923 else levelEvdoSnr = 0;
924
925 return (levelEvdoDbm < levelEvdoSnr) ? levelEvdoDbm : levelEvdoSnr;
926 }
927
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700928 private final void updateDataNetType(int net, int inetCondition) {
929 int connected = (inetCondition > INET_CONDITION_THRESHOLD ? 1 : 0);
Wink Saville04e71b32009-04-02 11:00:54 -0700930 switch (net) {
Wink Saville04e71b32009-04-02 11:00:54 -0700931 case TelephonyManager.NETWORK_TYPE_EDGE:
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700932 mDataIconList = sDataNetType_e[connected];
Wink Saville04e71b32009-04-02 11:00:54 -0700933 break;
934 case TelephonyManager.NETWORK_TYPE_UMTS:
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700935 mDataIconList = sDataNetType_3g[connected];
Wink Saville04e71b32009-04-02 11:00:54 -0700936 break;
Li Zheebe66342009-08-14 19:22:16 +0800937 case TelephonyManager.NETWORK_TYPE_HSDPA:
938 case TelephonyManager.NETWORK_TYPE_HSUPA:
939 case TelephonyManager.NETWORK_TYPE_HSPA:
John Wang33e21fc2009-10-08 10:35:27 -0700940 if (mHspaDataDistinguishable) {
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700941 mDataIconList = sDataNetType_h[connected];
John Wang33e21fc2009-10-08 10:35:27 -0700942 } else {
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700943 mDataIconList = sDataNetType_3g[connected];
John Wang33e21fc2009-10-08 10:35:27 -0700944 }
Li Zheebe66342009-08-14 19:22:16 +0800945 break;
Wink Saville04e71b32009-04-02 11:00:54 -0700946 case TelephonyManager.NETWORK_TYPE_CDMA:
947 // display 1xRTT for IS95A/B
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700948 mDataIconList = sDataNetType_1x[connected];
Wink Saville04e71b32009-04-02 11:00:54 -0700949 break;
950 case TelephonyManager.NETWORK_TYPE_1xRTT:
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700951 mDataIconList = sDataNetType_1x[connected];
Wink Saville04e71b32009-04-02 11:00:54 -0700952 break;
953 case TelephonyManager.NETWORK_TYPE_EVDO_0: //fall through
954 case TelephonyManager.NETWORK_TYPE_EVDO_A:
Naveen Kalla0a5174a2010-04-21 14:48:03 -0700955 case TelephonyManager.NETWORK_TYPE_EVDO_B:
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700956 mDataIconList = sDataNetType_3g[connected];
Wink Saville04e71b32009-04-02 11:00:54 -0700957 break;
958 default:
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700959 mDataIconList = sDataNetType_g[connected];
Wink Saville04e71b32009-04-02 11:00:54 -0700960 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800961 }
962 }
963
964 private final void updateDataIcon() {
965 int iconId;
966 boolean visible = true;
967
Wink Savillee9b06d72009-05-18 21:47:50 -0700968 if (!isCdma()) {
969 // GSM case, we have to check also the sim state
970 if (mSimState == IccCard.State.READY || mSimState == IccCard.State.UNKNOWN) {
971 if (hasService() && mDataState == TelephonyManager.DATA_CONNECTED) {
972 switch (mDataActivity) {
973 case TelephonyManager.DATA_ACTIVITY_IN:
974 iconId = mDataIconList[1];
975 break;
976 case TelephonyManager.DATA_ACTIVITY_OUT:
977 iconId = mDataIconList[2];
978 break;
979 case TelephonyManager.DATA_ACTIVITY_INOUT:
980 iconId = mDataIconList[3];
981 break;
982 default:
983 iconId = mDataIconList[0];
984 break;
985 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400986 mService.setIcon("data_connection", iconId, 0);
Wink Savillee9b06d72009-05-18 21:47:50 -0700987 } else {
988 visible = false;
989 }
990 } else {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400991 iconId = R.drawable.stat_sys_no_sim;
992 mService.setIcon("data_connection", iconId, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800993 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700994 } else {
995 // CDMA case, mDataActivity can be also DATA_ACTIVITY_DORMANT
996 if (hasService() && mDataState == TelephonyManager.DATA_CONNECTED) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800997 switch (mDataActivity) {
998 case TelephonyManager.DATA_ACTIVITY_IN:
Wink Savillee9b06d72009-05-18 21:47:50 -0700999 iconId = mDataIconList[1];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001000 break;
1001 case TelephonyManager.DATA_ACTIVITY_OUT:
Wink Savillee9b06d72009-05-18 21:47:50 -07001002 iconId = mDataIconList[2];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001003 break;
1004 case TelephonyManager.DATA_ACTIVITY_INOUT:
Wink Savillee9b06d72009-05-18 21:47:50 -07001005 iconId = mDataIconList[3];
1006 break;
1007 case TelephonyManager.DATA_ACTIVITY_DORMANT:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001008 default:
Wink Savillee9b06d72009-05-18 21:47:50 -07001009 iconId = mDataIconList[0];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001010 break;
1011 }
Joe Onorato798ac4c2010-05-27 16:39:00 -04001012 mService.setIcon("data_connection", iconId, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001013 } else {
1014 visible = false;
1015 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001016 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001017
Dianne Hackborn4840e142009-03-24 22:40:29 -07001018 long ident = Binder.clearCallingIdentity();
1019 try {
Wink Saville04e71b32009-04-02 11:00:54 -07001020 mBatteryStats.notePhoneDataConnectionState(mPhone.getNetworkType(), visible);
Dianne Hackborn4840e142009-03-24 22:40:29 -07001021 } catch (RemoteException e) {
1022 } finally {
1023 Binder.restoreCallingIdentity(ident);
1024 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001025
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001026 if (mDataIconVisible != visible) {
Joe Onorato0cbda992010-05-02 16:28:15 -07001027 mService.setIconVisibility("data_connection", visible);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001028 mDataIconVisible = visible;
1029 }
1030 }
1031
1032 private final void updateVolume() {
1033 AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
1034 final int ringerMode = audioManager.getRingerMode();
1035 final boolean visible = ringerMode == AudioManager.RINGER_MODE_SILENT ||
Wink Savillee9b06d72009-05-18 21:47:50 -07001036 ringerMode == AudioManager.RINGER_MODE_VIBRATE;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001037 final int iconId = audioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER)
Joe Onorato798ac4c2010-05-27 16:39:00 -04001038 ? R.drawable.stat_sys_ringer_vibrate
1039 : R.drawable.stat_sys_ringer_silent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001040
1041 if (visible) {
Joe Onorato798ac4c2010-05-27 16:39:00 -04001042 mService.setIcon("volume", iconId, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001043 }
1044 if (visible != mVolumeVisible) {
Joe Onorato0cbda992010-05-02 16:28:15 -07001045 mService.setIconVisibility("volume", visible);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001046 mVolumeVisible = visible;
1047 }
1048 }
1049
1050 private final void updateBluetooth(Intent intent) {
Joe Onorato798ac4c2010-05-27 16:39:00 -04001051 int iconId = R.drawable.stat_sys_data_bluetooth;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001052 String action = intent.getAction();
Nick Pellyde893f52009-09-08 13:15:33 -07001053 if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
Nick Pellyb24e11b2009-09-08 17:40:43 -07001054 int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
Nick Pellyde893f52009-09-08 13:15:33 -07001055 mBluetoothEnabled = state == BluetoothAdapter.STATE_ON;
Nick Pelly005b2282009-09-10 10:21:56 -07001056 } else if (action.equals(BluetoothHeadset.ACTION_STATE_CHANGED)) {
1057 mBluetoothHeadsetState = intent.getIntExtra(BluetoothHeadset.EXTRA_STATE,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001058 BluetoothHeadset.STATE_ERROR);
Nick Pelly005b2282009-09-10 10:21:56 -07001059 } else if (action.equals(BluetoothA2dp.ACTION_SINK_STATE_CHANGED)) {
Jaikumar Ganesh084c6652009-12-07 10:58:18 -08001060 BluetoothA2dp a2dp = new BluetoothA2dp(mContext);
1061 if (a2dp.getConnectedSinks().size() != 0) {
1062 mBluetoothA2dpConnected = true;
1063 } else {
1064 mBluetoothA2dpConnected = false;
1065 }
Jiafa Liu3f416732009-07-02 16:36:02 +08001066 } else if (action.equals(BluetoothPbap.PBAP_STATE_CHANGED_ACTION)) {
1067 mBluetoothPbapState = intent.getIntExtra(BluetoothPbap.PBAP_STATE,
1068 BluetoothPbap.STATE_DISCONNECTED);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001069 } else {
1070 return;
1071 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001072
Jaikumar Ganesh084c6652009-12-07 10:58:18 -08001073 if (mBluetoothHeadsetState == BluetoothHeadset.STATE_CONNECTED || mBluetoothA2dpConnected ||
Jiafa Liu3f416732009-07-02 16:36:02 +08001074 mBluetoothPbapState == BluetoothPbap.STATE_CONNECTED) {
Joe Onorato798ac4c2010-05-27 16:39:00 -04001075 iconId = R.drawable.stat_sys_data_bluetooth_connected;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001076 }
1077
Joe Onorato798ac4c2010-05-27 16:39:00 -04001078 mService.setIcon("bluetooth", iconId, 0);
Joe Onorato0cbda992010-05-02 16:28:15 -07001079 mService.setIconVisibility("bluetooth", mBluetoothEnabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001080 }
1081
1082 private final void updateWifi(Intent intent) {
1083 final String action = intent.getAction();
1084 if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001085
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001086 final boolean enabled = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
1087 WifiManager.WIFI_STATE_UNKNOWN) == WifiManager.WIFI_STATE_ENABLED;
Wink Savillee9b06d72009-05-18 21:47:50 -07001088
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001089 if (!enabled) {
1090 // If disabled, hide the icon. (We show icon when connected.)
Joe Onorato0cbda992010-05-02 16:28:15 -07001091 mService.setIconVisibility("wifi", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001092 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001094 } else if (action.equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)) {
1095 final boolean enabled = intent.getBooleanExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED,
1096 false);
1097 if (!enabled) {
Joe Onorato0cbda992010-05-02 16:28:15 -07001098 mService.setIconVisibility("wifi", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001099 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001100 } else if (action.equals(WifiManager.RSSI_CHANGED_ACTION)) {
Joe Onorato0cbda992010-05-02 16:28:15 -07001101 int iconId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001102 final int newRssi = intent.getIntExtra(WifiManager.EXTRA_NEW_RSSI, -200);
1103 int newSignalLevel = WifiManager.calculateSignalLevel(newRssi,
1104 sWifiSignalImages.length);
1105 if (newSignalLevel != mLastWifiSignalLevel) {
1106 mLastWifiSignalLevel = newSignalLevel;
1107 if (mIsWifiConnected) {
Robert Greenwaltd7085fc2010-09-08 15:24:47 -07001108 iconId = sWifiSignalImages[mLastWifiInetConnectivityState][newSignalLevel];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001109 } else {
Joe Onorato0cbda992010-05-02 16:28:15 -07001110 iconId = sWifiTemporarilyNotConnectedImage;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001111 }
Joe Onorato798ac4c2010-05-27 16:39:00 -04001112 mService.setIcon("wifi", iconId, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001113 }
1114 }
1115 }
1116
1117 private final void updateGps(Intent intent) {
1118 final String action = intent.getAction();
Mike Lockwood00b74272010-03-26 10:41:48 -04001119 final boolean enabled = intent.getBooleanExtra(LocationManager.EXTRA_GPS_ENABLED, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001120
Mike Lockwood00b74272010-03-26 10:41:48 -04001121 if (action.equals(LocationManager.GPS_FIX_CHANGE_ACTION) && enabled) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001122 // GPS is getting fixes
Joe Onorato798ac4c2010-05-27 16:39:00 -04001123 mService.setIcon("gps", com.android.internal.R.drawable.stat_sys_gps_on, 0);
Joe Onorato0cbda992010-05-02 16:28:15 -07001124 mService.setIconVisibility("gps", true);
Mike Lockwood00b74272010-03-26 10:41:48 -04001125 } else if (action.equals(LocationManager.GPS_ENABLED_CHANGE_ACTION) && !enabled) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001126 // GPS is off
Joe Onorato0cbda992010-05-02 16:28:15 -07001127 mService.setIconVisibility("gps", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001128 } else {
1129 // GPS is on, but not receiving fixes
Joe Onorato798ac4c2010-05-27 16:39:00 -04001130 mService.setIcon("gps", R.drawable.stat_sys_gps_acquiring_anim, 0);
Joe Onorato0cbda992010-05-02 16:28:15 -07001131 mService.setIconVisibility("gps", true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001132 }
1133 }
1134
Wink Savillee9b06d72009-05-18 21:47:50 -07001135 private final void updateTTY(Intent intent) {
Wink Saville04e71b32009-04-02 11:00:54 -07001136 final String action = intent.getAction();
1137 final boolean enabled = intent.getBooleanExtra(TtyIntent.TTY_ENABLED, false);
1138
Joe Onorato8a9b2202010-02-26 18:56:32 -08001139 if (false) Slog.v(TAG, "updateTTY: enabled: " + enabled);
Wink Saville04e71b32009-04-02 11:00:54 -07001140
1141 if (enabled) {
1142 // TTY is on
Joe Onorato8a9b2202010-02-26 18:56:32 -08001143 if (false) Slog.v(TAG, "updateTTY: set TTY on");
Joe Onorato798ac4c2010-05-27 16:39:00 -04001144 mService.setIcon("tty", R.drawable.stat_sys_tty_mode, 0);
Joe Onorato0cbda992010-05-02 16:28:15 -07001145 mService.setIconVisibility("tty", true);
Wink Saville04e71b32009-04-02 11:00:54 -07001146 } else {
1147 // TTY is off
Joe Onorato8a9b2202010-02-26 18:56:32 -08001148 if (false) Slog.v(TAG, "updateTTY: set TTY off");
Joe Onorato0cbda992010-05-02 16:28:15 -07001149 mService.setIconVisibility("tty", false);
Wink Saville04e71b32009-04-02 11:00:54 -07001150 }
1151 }
1152
Robert Greenwalt98e0b142009-10-08 21:15:52 -07001153 private final void updateCdmaRoamingIcon(ServiceState state) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001154 if (!hasService()) {
Joe Onorato0cbda992010-05-02 16:28:15 -07001155 mService.setIconVisibility("cdma_eri", false);
Wink Savillef3152382009-06-01 14:39:20 -07001156 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001157 }
1158
1159 if (!isCdma()) {
Joe Onorato0cbda992010-05-02 16:28:15 -07001160 mService.setIconVisibility("cdma_eri", false);
Wink Savillef3152382009-06-01 14:39:20 -07001161 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001162 }
1163
1164 int[] iconList = sRoamingIndicatorImages_cdma;
Robert Greenwalt98e0b142009-10-08 21:15:52 -07001165 int iconIndex = state.getCdmaEriIconIndex();
1166 int iconMode = state.getCdmaEriIconMode();
Wink Savillee9b06d72009-05-18 21:47:50 -07001167
1168 if (iconIndex == -1) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001169 Slog.e(TAG, "getCdmaEriIconIndex returned null, skipping ERI icon update");
Wink Savillee9b06d72009-05-18 21:47:50 -07001170 return;
1171 }
1172
1173 if (iconMode == -1) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001174 Slog.e(TAG, "getCdmeEriIconMode returned null, skipping ERI icon update");
Wink Savillee9b06d72009-05-18 21:47:50 -07001175 return;
1176 }
1177
1178 if (iconIndex == EriInfo.ROAMING_INDICATOR_OFF) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001179 if (false) Slog.v(TAG, "Cdma ROAMING_INDICATOR_OFF, removing ERI icon");
Joe Onorato0cbda992010-05-02 16:28:15 -07001180 mService.setIconVisibility("cdma_eri", false);
Wink Savillee9b06d72009-05-18 21:47:50 -07001181 return;
1182 }
1183
1184 switch (iconMode) {
1185 case EriInfo.ROAMING_ICON_MODE_NORMAL:
Joe Onorato798ac4c2010-05-27 16:39:00 -04001186 mService.setIcon("cdma_eri", iconList[iconIndex], 0);
Joe Onorato0cbda992010-05-02 16:28:15 -07001187 mService.setIconVisibility("cdma_eri", true);
Wink Savillee9b06d72009-05-18 21:47:50 -07001188 break;
1189 case EriInfo.ROAMING_ICON_MODE_FLASH:
Joe Onorato798ac4c2010-05-27 16:39:00 -04001190 mService.setIcon("cdma_eri", R.drawable.stat_sys_roaming_cdma_flash, 0);
Joe Onorato0cbda992010-05-02 16:28:15 -07001191 mService.setIconVisibility("cdma_eri", true);
Wink Savillee9b06d72009-05-18 21:47:50 -07001192 break;
1193
1194 }
Joe Onorato798ac4c2010-05-27 16:39:00 -04001195 mService.setIcon("phone_signal", mPhoneSignalIconId, 0);
Wink Savillee9b06d72009-05-18 21:47:50 -07001196 }
1197
1198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001199 private class StatusBarHandler extends Handler {
1200 @Override
1201 public void handleMessage(Message msg) {
1202 switch (msg.what) {
1203 case EVENT_BATTERY_CLOSE:
1204 if (msg.arg1 == mBatteryViewSequence) {
1205 closeLastBatteryView();
1206 }
1207 break;
1208 }
1209 }
1210 }
1211}