blob: fb74e70f61a4f66b3534081d3dc9a4a8f25fcd6e [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;
Nick Pellybd022f42009-08-14 18:33:38 -070021import android.bluetooth.BluetoothAdapter;
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -070022import android.bluetooth.BluetoothProfile;
Jiafa Liu3f416732009-07-02 16:36:02 +080023import android.bluetooth.BluetoothPbap;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.content.BroadcastReceiver;
Daniel Sandler0e9d2af2010-01-25 11:33:03 -050025import android.content.ContentResolver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import android.content.Context;
27import android.content.DialogInterface;
28import android.content.Intent;
29import android.content.IntentFilter;
30import android.content.res.TypedArray;
31import android.graphics.PixelFormat;
Daniel Sandler2c195f72010-05-21 15:42:06 -040032import android.graphics.Typeface;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.graphics.drawable.Drawable;
Mike Lockwood00b74272010-03-26 10:41:48 -040034import android.location.LocationManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035import android.media.AudioManager;
Daniel Sandler0e9d2af2010-01-25 11:33:03 -050036import android.media.Ringtone;
37import android.media.RingtoneManager;
Robert Greenwaltd7085fc2010-09-08 15:24:47 -070038import android.net.ConnectivityManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import android.net.NetworkInfo;
Daniel Sandler0e9d2af2010-01-25 11:33:03 -050040import android.net.Uri;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import android.net.wifi.WifiManager;
Dianne Hackborn4840e142009-03-24 22:40:29 -070042import android.os.Binder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043import android.os.Handler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044import android.os.Message;
Dianne Hackborn4840e142009-03-24 22:40:29 -070045import android.os.RemoteException;
San Mehat4154c072010-02-09 18:37:54 -080046import android.os.storage.StorageManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import android.provider.Settings;
48import android.telephony.PhoneStateListener;
49import android.telephony.ServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -070050import android.telephony.SignalStrength;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051import android.telephony.TelephonyManager;
52import android.text.format.DateFormat;
Daniel Sandler2c195f72010-05-21 15:42:06 -040053import android.text.style.CharacterStyle;
Eric Fischer36e136c2010-01-14 17:42:48 -080054import android.text.style.RelativeSizeSpan;
Daniel Sandler2c195f72010-05-21 15:42:06 -040055import android.text.style.ForegroundColorSpan;
56import android.text.style.StyleSpan;
Eric Fischer36e136c2010-01-14 17:42:48 -080057import android.text.Spannable;
58import android.text.SpannableStringBuilder;
Joe Onorato8a9b2202010-02-26 18:56:32 -080059import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import android.view.View;
61import android.view.ViewGroup;
62import android.view.WindowManager;
63import android.view.WindowManagerImpl;
64import android.widget.ImageView;
65import android.widget.LinearLayout;
66import android.widget.TextView;
67
Wink Saville04e71b32009-04-02 11:00:54 -070068import com.android.internal.app.IBatteryStats;
Wink Saville04e71b32009-04-02 11:00:54 -070069import com.android.internal.telephony.IccCard;
70import com.android.internal.telephony.TelephonyIntents;
Wink Savillee9b06d72009-05-18 21:47:50 -070071import com.android.internal.telephony.cdma.EriInfo;
Wink Saville04e71b32009-04-02 11:00:54 -070072import com.android.internal.telephony.cdma.TtyIntent;
73import com.android.server.am.BatteryStatsService;
74
Joe Onorato798ac4c2010-05-27 16:39:00 -040075import com.android.systemui.R;
76
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077/**
78 * This class contains all of the policy about which icons are installed in the status
Joe Onorato798ac4c2010-05-27 16:39:00 -040079 * bar at boot time. It goes through the normal API for icons, even though it probably
80 * strictly doesn't need to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081 */
82public class StatusBarPolicy {
83 private static final String TAG = "StatusBarPolicy";
84
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085 // message codes for the handler
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 private static final int EVENT_BATTERY_CLOSE = 4;
87
Daniel Sandler2c195f72010-05-21 15:42:06 -040088 private static final int AM_PM_STYLE_NORMAL = 0;
89 private static final int AM_PM_STYLE_SMALL = 1;
90 private static final int AM_PM_STYLE_GONE = 2;
91
92 private static final int AM_PM_STYLE = AM_PM_STYLE_GONE;
93
Robert Greenwaltd7085fc2010-09-08 15:24:47 -070094 private static final int INET_CONDITION_THRESHOLD = 50;
95
Dianne Hackborn4840e142009-03-24 22:40:29 -070096 private final Context mContext;
Joe Onorato798ac4c2010-05-27 16:39:00 -040097 private final StatusBarManager mService;
Dianne Hackborn4840e142009-03-24 22:40:29 -070098 private final Handler mHandler = new StatusBarHandler();
99 private final IBatteryStats mBatteryStats;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100
San Mehat4154c072010-02-09 18:37:54 -0800101 // storage
102 private StorageManager mStorageManager;
103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104 // battery
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105 private boolean mBatteryFirst = true;
106 private boolean mBatteryPlugged;
107 private int mBatteryLevel;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 private AlertDialog mLowBatteryDialog;
109 private TextView mBatteryLevelTextView;
110 private View mBatteryView;
111 private int mBatteryViewSequence;
112 private boolean mBatteryShowLowOnEndCall = false;
113 private static final boolean SHOW_LOW_BATTERY_WARNING = true;
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500114 private static final boolean SHOW_BATTERY_WARNINGS_IN_CALL = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115
116 // phone
117 private TelephonyManager mPhone;
Joe Onorato0cbda992010-05-02 16:28:15 -0700118 private int mPhoneSignalIconId;
Wink Saville04e71b32009-04-02 11:00:54 -0700119
120 //***** Signal strength icons
Wink Saville04e71b32009-04-02 11:00:54 -0700121 //GSM/UMTS
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700122 private static final int[][] sSignalImages = {
123 { R.drawable.stat_sys_signal_0,
124 R.drawable.stat_sys_signal_1,
125 R.drawable.stat_sys_signal_2,
126 R.drawable.stat_sys_signal_3,
127 R.drawable.stat_sys_signal_4 },
128 { R.drawable.stat_sys_signal_0_fully,
129 R.drawable.stat_sys_signal_1_fully,
130 R.drawable.stat_sys_signal_2_fully,
131 R.drawable.stat_sys_signal_3_fully,
132 R.drawable.stat_sys_signal_4_fully }
Wink Savillee9b06d72009-05-18 21:47:50 -0700133 };
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700134 private static final int[][] sSignalImages_r = {
135 { R.drawable.stat_sys_r_signal_0,
136 R.drawable.stat_sys_r_signal_1,
137 R.drawable.stat_sys_r_signal_2,
138 R.drawable.stat_sys_r_signal_3,
139 R.drawable.stat_sys_r_signal_4 },
140 { R.drawable.stat_sys_r_signal_0_fully,
141 R.drawable.stat_sys_r_signal_1_fully,
142 R.drawable.stat_sys_r_signal_2_fully,
143 R.drawable.stat_sys_r_signal_3_fully,
144 R.drawable.stat_sys_r_signal_4_fully }
Wink Savillee9b06d72009-05-18 21:47:50 -0700145 };
Wink Savillee9b06d72009-05-18 21:47:50 -0700146 private static final int[] sRoamingIndicatorImages_cdma = new int[] {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400147 R.drawable.stat_sys_roaming_cdma_0, //Standard Roaming Indicator
Wink Savillee9b06d72009-05-18 21:47:50 -0700148 // 1 is Standard Roaming Indicator OFF
149 // TODO T: image never used, remove and put 0 instead?
Joe Onorato798ac4c2010-05-27 16:39:00 -0400150 R.drawable.stat_sys_roaming_cdma_0,
Wink Savillee9b06d72009-05-18 21:47:50 -0700151
152 // 2 is Standard Roaming Indicator FLASHING
153 // TODO T: image never used, remove and put 0 instead?
Joe Onorato798ac4c2010-05-27 16:39:00 -0400154 R.drawable.stat_sys_roaming_cdma_0,
Wink Savillee9b06d72009-05-18 21:47:50 -0700155
156 // 3-12 Standard ERI
Joe Onorato798ac4c2010-05-27 16:39:00 -0400157 R.drawable.stat_sys_roaming_cdma_0, //3
158 R.drawable.stat_sys_roaming_cdma_0,
159 R.drawable.stat_sys_roaming_cdma_0,
160 R.drawable.stat_sys_roaming_cdma_0,
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,
Wink Savillee9b06d72009-05-18 21:47:50 -0700167
168 // 13-63 Reserved for Standard ERI
Joe Onorato798ac4c2010-05-27 16:39:00 -0400169 R.drawable.stat_sys_roaming_cdma_0, //13
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,
211 R.drawable.stat_sys_roaming_cdma_0,
212 R.drawable.stat_sys_roaming_cdma_0,
213 R.drawable.stat_sys_roaming_cdma_0,
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,
Wink Savillee9b06d72009-05-18 21:47:50 -0700220
221 // 64-127 Reserved for Non Standard (Operator Specific) ERI
Joe Onorato798ac4c2010-05-27 16:39:00 -0400222 R.drawable.stat_sys_roaming_cdma_0, //64
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,
233 R.drawable.stat_sys_roaming_cdma_0,
234 R.drawable.stat_sys_roaming_cdma_0,
235 R.drawable.stat_sys_roaming_cdma_0,
236 R.drawable.stat_sys_roaming_cdma_0,
237 R.drawable.stat_sys_roaming_cdma_0,
238 R.drawable.stat_sys_roaming_cdma_0,
239 R.drawable.stat_sys_roaming_cdma_0,
240 R.drawable.stat_sys_roaming_cdma_0,
241 R.drawable.stat_sys_roaming_cdma_0 //83
Wink Savillee9b06d72009-05-18 21:47:50 -0700242
243 // 128-255 Reserved
Wink Saville04e71b32009-04-02 11:00:54 -0700244 };
Wink Saville04e71b32009-04-02 11:00:54 -0700245
246 //***** Data connection icons
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700247 private int[] mDataIconList = sDataNetType_g[0];
Wink Saville04e71b32009-04-02 11:00:54 -0700248 //GSM/UMTS
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700249 private static final int[][] sDataNetType_g = {
250 { R.drawable.stat_sys_data_connected_g,
251 R.drawable.stat_sys_data_in_g,
252 R.drawable.stat_sys_data_out_g,
253 R.drawable.stat_sys_data_inandout_g },
Robert Greenwalt26faee32010-09-10 09:36:43 -0700254 { R.drawable.stat_sys_data_fully_connected_g,
255 R.drawable.stat_sys_data_fully_in_g,
256 R.drawable.stat_sys_data_fully_out_g,
257 R.drawable.stat_sys_data_fully_inandout_g }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800258 };
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700259 private static final int[][] sDataNetType_3g = {
260 { R.drawable.stat_sys_data_connected_3g,
261 R.drawable.stat_sys_data_in_3g,
262 R.drawable.stat_sys_data_out_3g,
263 R.drawable.stat_sys_data_inandout_3g },
Robert Greenwalt26faee32010-09-10 09:36:43 -0700264 { R.drawable.stat_sys_data_fully_connected_3g,
265 R.drawable.stat_sys_data_fully_in_3g,
266 R.drawable.stat_sys_data_fully_out_3g,
267 R.drawable.stat_sys_data_fully_inandout_3g }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 };
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700269 private static final int[][] sDataNetType_e = {
270 { R.drawable.stat_sys_data_connected_e,
271 R.drawable.stat_sys_data_in_e,
272 R.drawable.stat_sys_data_out_e,
273 R.drawable.stat_sys_data_inandout_e },
Robert Greenwalt26faee32010-09-10 09:36:43 -0700274 { R.drawable.stat_sys_data_fully_connected_e,
275 R.drawable.stat_sys_data_fully_in_e,
276 R.drawable.stat_sys_data_fully_out_e,
277 R.drawable.stat_sys_data_fully_inandout_e }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 };
Li Zheebe66342009-08-14 19:22:16 +0800279 //3.5G
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700280 private static final int[][] sDataNetType_h = {
281 { R.drawable.stat_sys_data_connected_h,
282 R.drawable.stat_sys_data_in_h,
283 R.drawable.stat_sys_data_out_h,
284 R.drawable.stat_sys_data_inandout_h },
Robert Greenwalt26faee32010-09-10 09:36:43 -0700285 { R.drawable.stat_sys_data_fully_connected_h,
286 R.drawable.stat_sys_data_fully_in_h,
287 R.drawable.stat_sys_data_fully_out_h,
288 R.drawable.stat_sys_data_fully_inandout_h }
Li Zheebe66342009-08-14 19:22:16 +0800289 };
290
Wink Saville04e71b32009-04-02 11:00:54 -0700291 //CDMA
johnwang9f87cb22009-08-25 15:25:37 -0700292 // Use 3G icons for EVDO data and 1x icons for 1XRTT data
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700293 private static final int[][] sDataNetType_1x = {
294 { R.drawable.stat_sys_data_connected_1x,
295 R.drawable.stat_sys_data_in_1x,
296 R.drawable.stat_sys_data_out_1x,
297 R.drawable.stat_sys_data_inandout_1x },
Robert Greenwalt26faee32010-09-10 09:36:43 -0700298 { R.drawable.stat_sys_data_fully_connected_1x,
299 R.drawable.stat_sys_data_fully_in_1x,
300 R.drawable.stat_sys_data_fully_out_1x,
301 R.drawable.stat_sys_data_fully_inandout_1x }
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700302 };
Wink Saville04e71b32009-04-02 11:00:54 -0700303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800304 // Assume it's all good unless we hear otherwise. We don't always seem
305 // to get broadcasts that it *is* there.
Wink Saville04e71b32009-04-02 11:00:54 -0700306 IccCard.State mSimState = IccCard.State.READY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307 int mPhoneState = TelephonyManager.CALL_STATE_IDLE;
308 int mDataState = TelephonyManager.DATA_DISCONNECTED;
309 int mDataActivity = TelephonyManager.DATA_ACTIVITY_NONE;
310 ServiceState mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700311 SignalStrength mSignalStrength;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800312
313 // data connection
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800314 private boolean mDataIconVisible;
John Wang33e21fc2009-10-08 10:35:27 -0700315 private boolean mHspaDataDistinguishable;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316
317 // ringer volume
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800318 private boolean mVolumeVisible;
Wink Saville04e71b32009-04-02 11:00:54 -0700319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800320 // bluetooth device status
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800321 private boolean mBluetoothEnabled;
322
323 // wifi
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700324 private static final int[][] sWifiSignalImages = {
325 { R.drawable.stat_sys_wifi_signal_1,
326 R.drawable.stat_sys_wifi_signal_2,
327 R.drawable.stat_sys_wifi_signal_3,
328 R.drawable.stat_sys_wifi_signal_4 },
Robert Greenwalt26faee32010-09-10 09:36:43 -0700329 { R.drawable.stat_sys_wifi_signal_1_fully,
330 R.drawable.stat_sys_wifi_signal_2_fully,
331 R.drawable.stat_sys_wifi_signal_3_fully,
332 R.drawable.stat_sys_wifi_signal_4_fully }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800333 };
334 private static final int sWifiTemporarilyNotConnectedImage =
Joe Onorato798ac4c2010-05-27 16:39:00 -0400335 R.drawable.stat_sys_wifi_signal_0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800336
337 private int mLastWifiSignalLevel = -1;
338 private boolean mIsWifiConnected = false;
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700339
340 // state of inet connection - 0 not connected, 100 connected
341 private int mInetCondition = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342
343 // sync state
344 // If sync is active the SyncActive icon is displayed. If sync is not active but
345 // sync is failing the SyncFailing icon is displayed. Otherwise neither are displayed.
Wink Savillee9b06d72009-05-18 21:47:50 -0700346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800347 private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
348 @Override
349 public void onReceive(Context context, Intent intent) {
350 String action = intent.getAction();
Joe Onorato263700d2010-05-14 11:54:53 -0700351 if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {
Dianne Hackborn8ec5b832009-07-01 21:19:35 -0700352 updateBattery(intent);
353 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 else if (action.equals(Intent.ACTION_ALARM_CHANGED)) {
355 updateAlarm(intent);
356 }
357 else if (action.equals(Intent.ACTION_SYNC_STATE_CHANGED)) {
358 updateSyncState(intent);
359 }
Mihai Predaa82842f2009-04-29 15:05:56 +0200360 else if (action.equals(Intent.ACTION_BATTERY_LOW)) {
361 onBatteryLow(intent);
362 }
Mike Lockwood69eb0bf2009-08-01 23:02:28 -0400363 else if (action.equals(Intent.ACTION_BATTERY_OKAY)
364 || action.equals(Intent.ACTION_POWER_CONNECTED)) {
Dianne Hackborn8ec5b832009-07-01 21:19:35 -0700365 onBatteryOkay(intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366 }
Nick Pellyde893f52009-09-08 13:15:33 -0700367 else if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED) ||
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -0700368 action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800369 updateBluetooth(intent);
370 }
371 else if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION) ||
372 action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION) ||
373 action.equals(WifiManager.RSSI_CHANGED_ACTION)) {
374 updateWifi(intent);
375 }
Mike Lockwood00b74272010-03-26 10:41:48 -0400376 else if (action.equals(LocationManager.GPS_ENABLED_CHANGE_ACTION) ||
377 action.equals(LocationManager.GPS_FIX_CHANGE_ACTION)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 updateGps(intent);
379 }
380 else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION) ||
381 action.equals(AudioManager.VIBRATE_SETTING_CHANGED_ACTION)) {
382 updateVolume();
383 }
384 else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
385 updateSimState(intent);
386 }
Wink Saville04e71b32009-04-02 11:00:54 -0700387 else if (action.equals(TtyIntent.TTY_ENABLED_CHANGE_ACTION)) {
388 updateTTY(intent);
389 }
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700390 else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION) ||
391 action.equals(ConnectivityManager.INET_CONDITION_ACTION)) {
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700392 // TODO - stop using other means to get wifi/mobile info
393 updateConnectivity(intent);
394 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 }
396 };
397
Joe Onorato798ac4c2010-05-27 16:39:00 -0400398 public StatusBarPolicy(Context context) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399 mContext = context;
Joe Onorato798ac4c2010-05-27 16:39:00 -0400400 mService = (StatusBarManager)context.getSystemService(Context.STATUS_BAR_SERVICE);
Wink Savillee9b06d72009-05-18 21:47:50 -0700401 mSignalStrength = new SignalStrength();
Dianne Hackborn4840e142009-03-24 22:40:29 -0700402 mBatteryStats = BatteryStatsService.getService();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800403
San Mehat4154c072010-02-09 18:37:54 -0800404 // storage
405 mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
406 mStorageManager.registerListener(
Joe Onoratofe4f3ae2010-06-04 11:25:26 -0700407 new com.android.systemui.usb.StorageNotification(context));
San Mehat4154c072010-02-09 18:37:54 -0800408
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800409 // battery
Joe Onorato798ac4c2010-05-27 16:39:00 -0400410 mService.setIcon("battery", com.android.internal.R.drawable.stat_sys_battery_unknown, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800411
412 // phone_signal
413 mPhone = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
Joe Onorato798ac4c2010-05-27 16:39:00 -0400414 mPhoneSignalIconId = R.drawable.stat_sys_signal_null;
415 mService.setIcon("phone_signal", mPhoneSignalIconId, 0);
Wink Savillee9b06d72009-05-18 21:47:50 -0700416
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800417 // register for phone state notifications.
418 ((TelephonyManager)mContext.getSystemService(Context.TELEPHONY_SERVICE))
419 .listen(mPhoneStateListener,
420 PhoneStateListener.LISTEN_SERVICE_STATE
Wink Savillee9b06d72009-05-18 21:47:50 -0700421 | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 | PhoneStateListener.LISTEN_CALL_STATE
423 | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
424 | PhoneStateListener.LISTEN_DATA_ACTIVITY);
425
426 // data_connection
Joe Onorato798ac4c2010-05-27 16:39:00 -0400427 mService.setIcon("data_connection", R.drawable.stat_sys_data_connected_g, 0);
428 mService.setIconVisibility("data_connection", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429
430 // wifi
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700431 mService.setIcon("wifi", sWifiSignalImages[0][0], 0);
Joe Onorato798ac4c2010-05-27 16:39:00 -0400432 mService.setIconVisibility("wifi", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800433 // wifi will get updated by the sticky intents
Wink Saville04e71b32009-04-02 11:00:54 -0700434
435 // TTY status
Joe Onorato798ac4c2010-05-27 16:39:00 -0400436 mService.setIcon("tty", R.drawable.stat_sys_tty_mode, 0);
437 mService.setIconVisibility("tty", false);
Wink Saville04e71b32009-04-02 11:00:54 -0700438
Wink Savillee9b06d72009-05-18 21:47:50 -0700439 // Cdma Roaming Indicator, ERI
Joe Onorato798ac4c2010-05-27 16:39:00 -0400440 mService.setIcon("cdma_eri", R.drawable.stat_sys_roaming_cdma_0, 0);
441 mService.setIconVisibility("cdma_eri", false);
Wink Savillee9b06d72009-05-18 21:47:50 -0700442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 // bluetooth status
Joe Onorato798ac4c2010-05-27 16:39:00 -0400444 mService.setIcon("bluetooth", R.drawable.stat_sys_data_bluetooth, 0);
Nick Pellyf242b7b2009-10-08 00:12:45 +0200445 BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
Nick Pellybd022f42009-08-14 18:33:38 -0700446 if (adapter != null) {
447 mBluetoothEnabled = adapter.isEnabled();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800448 } else {
449 mBluetoothEnabled = false;
450 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700451 mService.setIconVisibility("bluetooth", mBluetoothEnabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800452
453 // Gps status
Joe Onorato798ac4c2010-05-27 16:39:00 -0400454 mService.setIcon("gps", R.drawable.stat_sys_gps_acquiring_anim, 0);
455 mService.setIconVisibility("gps", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800456
457 // Alarm clock
Joe Onorato798ac4c2010-05-27 16:39:00 -0400458 mService.setIcon("alarm_clock", R.drawable.stat_notify_alarm, 0);
459 mService.setIconVisibility("alarm_clock", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800460
461 // Sync state
Joe Onorato798ac4c2010-05-27 16:39:00 -0400462 mService.setIcon("sync_active", com.android.internal.R.drawable.stat_notify_sync_anim0, 0);
463 mService.setIcon("sync_failing", com.android.internal.R.drawable.stat_notify_sync_error, 0);
464 mService.setIconVisibility("sync_active", false);
465 mService.setIconVisibility("sync_failing", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800466
467 // volume
Joe Onorato798ac4c2010-05-27 16:39:00 -0400468 mService.setIcon("volume", R.drawable.stat_sys_ringer_silent, 0);
469 mService.setIconVisibility("volume", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800470 updateVolume();
johnwang347c5a22009-08-24 22:11:11 -0700471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800472 IntentFilter filter = new IntentFilter();
473
474 // Register for Intent broadcasts for...
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800475 filter.addAction(Intent.ACTION_BATTERY_CHANGED);
Mihai Predaa82842f2009-04-29 15:05:56 +0200476 filter.addAction(Intent.ACTION_BATTERY_LOW);
Dianne Hackborn8ec5b832009-07-01 21:19:35 -0700477 filter.addAction(Intent.ACTION_BATTERY_OKAY);
Mike Lockwood69eb0bf2009-08-01 23:02:28 -0400478 filter.addAction(Intent.ACTION_POWER_CONNECTED);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800479 filter.addAction(Intent.ACTION_ALARM_CHANGED);
480 filter.addAction(Intent.ACTION_SYNC_STATE_CHANGED);
481 filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
482 filter.addAction(AudioManager.VIBRATE_SETTING_CHANGED_ACTION);
Nick Pellyde893f52009-09-08 13:15:33 -0700483 filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -0700484 filter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800485 filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
486 filter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
487 filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
488 filter.addAction(WifiManager.RSSI_CHANGED_ACTION);
Mike Lockwood00b74272010-03-26 10:41:48 -0400489 filter.addAction(LocationManager.GPS_ENABLED_CHANGE_ACTION);
490 filter.addAction(LocationManager.GPS_FIX_CHANGE_ACTION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800491 filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
Wink Saville04e71b32009-04-02 11:00:54 -0700492 filter.addAction(TtyIntent.TTY_ENABLED_CHANGE_ACTION);
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700493 filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700494 filter.addAction(ConnectivityManager.INET_CONDITION_ACTION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800495 mContext.registerReceiver(mIntentReceiver, filter, null, mHandler);
John Wang33e21fc2009-10-08 10:35:27 -0700496
497 // load config to determine if to distinguish Hspa data icon
498 try {
499 mHspaDataDistinguishable = mContext.getResources().getBoolean(
Joe Onorato798ac4c2010-05-27 16:39:00 -0400500 R.bool.config_hspa_data_distinguishable);
John Wang33e21fc2009-10-08 10:35:27 -0700501 } catch (Exception e) {
502 mHspaDataDistinguishable = false;
503 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 }
505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800506 private final void updateAlarm(Intent intent) {
507 boolean alarmSet = intent.getBooleanExtra("alarmSet", false);
Joe Onorato0cbda992010-05-02 16:28:15 -0700508 mService.setIconVisibility("alarm_clock", alarmSet);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800509 }
510
511 private final void updateSyncState(Intent intent) {
512 boolean isActive = intent.getBooleanExtra("active", false);
513 boolean isFailing = intent.getBooleanExtra("failing", false);
Joe Onorato0cbda992010-05-02 16:28:15 -0700514 mService.setIconVisibility("sync_active", isActive);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800515 // Don't display sync failing icon: BUG 1297963 Set sync error timeout to "never"
Joe Onorato0cbda992010-05-02 16:28:15 -0700516 //mService.setIconVisibility("sync_failing", isFailing && !isActive);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800517 }
518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800519 private final void updateBattery(Intent intent) {
Joe Onorato0cbda992010-05-02 16:28:15 -0700520 final int id = intent.getIntExtra("icon-small", 0);
521 int level = intent.getIntExtra("level", 0);
Joe Onorato798ac4c2010-05-27 16:39:00 -0400522 mService.setIcon("battery", id, level);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800523
524 boolean plugged = intent.getIntExtra("plugged", 0) != 0;
Joe Onorato0cbda992010-05-02 16:28:15 -0700525 level = intent.getIntExtra("level", -1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800526 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800527 Slog.d(TAG, "updateBattery level=" + level
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528 + " plugged=" + plugged
529 + " mBatteryPlugged=" + mBatteryPlugged
530 + " mBatteryLevel=" + mBatteryLevel
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800531 + " mBatteryFirst=" + mBatteryFirst);
532 }
533
534 boolean oldPlugged = mBatteryPlugged;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800535
536 mBatteryPlugged = plugged;
537 mBatteryLevel = level;
538
539 if (mBatteryFirst) {
540 mBatteryFirst = false;
541 }
542 /*
543 * No longer showing the battery view because it draws attention away
544 * from the USB storage notification. We could still show it when
545 * connected to a brick, but that could lead to the user into thinking
546 * the device does not charge when plugged into USB (since he/she would
547 * not see the same battery screen on USB as he sees on brick).
548 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800549 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800550 Slog.d(TAG, "plugged=" + plugged + " oldPlugged=" + oldPlugged + " level=" + level);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800551 }
Mihai Predaa82842f2009-04-29 15:05:56 +0200552 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800553
Mihai Predaa82842f2009-04-29 15:05:56 +0200554 private void onBatteryLow(Intent intent) {
555 if (SHOW_LOW_BATTERY_WARNING) {
556 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800557 Slog.d(TAG, "mPhoneState=" + mPhoneState
Mihai Predaa82842f2009-04-29 15:05:56 +0200558 + " mLowBatteryDialog=" + mLowBatteryDialog
559 + " mBatteryShowLowOnEndCall=" + mBatteryShowLowOnEndCall);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800560 }
Mihai Predaa82842f2009-04-29 15:05:56 +0200561
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500562 if (SHOW_BATTERY_WARNINGS_IN_CALL || mPhoneState == TelephonyManager.CALL_STATE_IDLE) {
Mihai Predaa82842f2009-04-29 15:05:56 +0200563 showLowBatteryWarning();
564 } else {
565 mBatteryShowLowOnEndCall = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800566 }
567 }
568 }
569
Dianne Hackborn8ec5b832009-07-01 21:19:35 -0700570 private void onBatteryOkay(Intent intent) {
571 if (mLowBatteryDialog != null
572 && SHOW_LOW_BATTERY_WARNING) {
573 mLowBatteryDialog.dismiss();
574 mBatteryShowLowOnEndCall = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575 }
576 }
577
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800578 private void setBatteryLevel(View parent, int id, int height, int background, int level) {
579 ImageView v = (ImageView)parent.findViewById(id);
580 LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)v.getLayoutParams();
581 lp.weight = height;
582 if (background != 0) {
583 v.setBackgroundResource(background);
584 Drawable bkg = v.getBackground();
585 bkg.setLevel(level);
586 }
587 }
588
589 private void showLowBatteryWarning() {
590 closeLastBatteryView();
591
Mike Lockwoodd81b1f42009-09-25 09:32:19 -0400592 // Show exact battery level.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 CharSequence levelText = mContext.getString(
Joe Onorato798ac4c2010-05-27 16:39:00 -0400594 R.string.battery_low_percent_format, mBatteryLevel);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800595
596 if (mBatteryLevelTextView != null) {
597 mBatteryLevelTextView.setText(levelText);
598 } else {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400599 View v = View.inflate(mContext, R.layout.battery_low, null);
600 mBatteryLevelTextView=(TextView)v.findViewById(R.id.level_percent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800601
602 mBatteryLevelTextView.setText(levelText);
603
604 AlertDialog.Builder b = new AlertDialog.Builder(mContext);
605 b.setCancelable(true);
Joe Onorato798ac4c2010-05-27 16:39:00 -0400606 b.setTitle(R.string.battery_low_title);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800607 b.setView(v);
608 b.setIcon(android.R.drawable.ic_dialog_alert);
609 b.setPositiveButton(android.R.string.ok, null);
johnwang347c5a22009-08-24 22:11:11 -0700610
Dianne Hackborn3d74bb42009-06-19 10:35:21 -0700611 final Intent intent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
612 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
613 | Intent.FLAG_ACTIVITY_MULTIPLE_TASK
614 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
615 | Intent.FLAG_ACTIVITY_NO_HISTORY);
616 if (intent.resolveActivity(mContext.getPackageManager()) != null) {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400617 b.setNegativeButton(R.string.battery_low_why,
Dianne Hackborn3d74bb42009-06-19 10:35:21 -0700618 new DialogInterface.OnClickListener() {
619 public void onClick(DialogInterface dialog, int which) {
620 mContext.startActivity(intent);
621 if (mLowBatteryDialog != null) {
622 mLowBatteryDialog.dismiss();
623 }
624 }
625 });
626 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800627
628 AlertDialog d = b.create();
629 d.setOnDismissListener(mLowBatteryListener);
630 d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
631 d.show();
632 mLowBatteryDialog = d;
633 }
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500634
635 final ContentResolver cr = mContext.getContentResolver();
636 if (Settings.System.getInt(cr,
John Wang56c2d2f2010-04-07 08:57:17 -0700637 Settings.System.POWER_SOUNDS_ENABLED, 1) == 1)
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500638 {
639 final String soundPath = Settings.System.getString(cr,
640 Settings.System.LOW_BATTERY_SOUND);
641 if (soundPath != null) {
642 final Uri soundUri = Uri.parse("file://" + soundPath);
643 if (soundUri != null) {
644 final Ringtone sfx = RingtoneManager.getRingtone(mContext, soundUri);
Daniel Sandlerec2c88d2010-02-20 01:04:57 -0500645 if (sfx != null) {
646 sfx.setStreamType(AudioManager.STREAM_SYSTEM);
647 sfx.play();
648 }
Daniel Sandler0e9d2af2010-01-25 11:33:03 -0500649 }
650 }
651 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800652 }
653
654 private final void updateCallState(int state) {
655 mPhoneState = state;
656 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800657 Slog.d(TAG, "mPhoneState=" + mPhoneState
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800658 + " mLowBatteryDialog=" + mLowBatteryDialog
659 + " mBatteryShowLowOnEndCall=" + mBatteryShowLowOnEndCall);
660 }
661 if (mPhoneState == TelephonyManager.CALL_STATE_IDLE) {
662 if (mBatteryShowLowOnEndCall) {
663 if (!mBatteryPlugged) {
664 showLowBatteryWarning();
665 }
666 mBatteryShowLowOnEndCall = false;
667 }
668 } else {
669 if (mLowBatteryDialog != null) {
670 mLowBatteryDialog.dismiss();
671 mBatteryShowLowOnEndCall = true;
672 }
673 }
674 }
675
676 private DialogInterface.OnDismissListener mLowBatteryListener
677 = new DialogInterface.OnDismissListener() {
678 public void onDismiss(DialogInterface dialog) {
679 mLowBatteryDialog = null;
680 mBatteryLevelTextView = null;
681 }
682 };
683
684 private void scheduleCloseBatteryView() {
685 Message m = mHandler.obtainMessage(EVENT_BATTERY_CLOSE);
686 m.arg1 = (++mBatteryViewSequence);
687 mHandler.sendMessageDelayed(m, 3000);
688 }
689
690 private void closeLastBatteryView() {
691 if (mBatteryView != null) {
692 //mBatteryView.debug();
693 WindowManagerImpl.getDefault().removeView(mBatteryView);
694 mBatteryView = null;
695 }
696 }
697
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700698 private void updateConnectivity(Intent intent) {
699 NetworkInfo info = (NetworkInfo)(intent.getParcelableExtra(
700 ConnectivityManager.EXTRA_NETWORK_INFO));
701 int connectionStatus = intent.getIntExtra(ConnectivityManager.EXTRA_INET_CONDITION, 0);
Robert Greenwalt029be812010-09-20 18:01:43 -0700702
703 int inetCondition = (connectionStatus > INET_CONDITION_THRESHOLD ? 1 : 0);
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700704
705 switch (info.getType()) {
706 case ConnectivityManager.TYPE_MOBILE:
Robert Greenwalt029be812010-09-20 18:01:43 -0700707 mInetCondition = inetCondition;
708 updateDataNetType(info.getSubtype());
709 updateDataIcon();
710 updateSignalStrength(); // apply any change in connectionStatus
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700711 break;
712 case ConnectivityManager.TYPE_WIFI:
Robert Greenwalt029be812010-09-20 18:01:43 -0700713 mInetCondition = inetCondition;
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700714 if (info.isConnected()) {
715 mIsWifiConnected = true;
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700716 int iconId;
717 if (mLastWifiSignalLevel == -1) {
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700718 iconId = sWifiSignalImages[mInetCondition][0];
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700719 } else {
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700720 iconId = sWifiSignalImages[mInetCondition][mLastWifiSignalLevel];
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700721 }
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700722 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;
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700728 int iconId = sWifiSignalImages[0][0];
729
730 mService.setIcon("wifi", iconId, 0);
731 // Hide the icon since we're not connected
732 mService.setIconVisibility("wifi", false);
733 }
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700734 updateSignalStrength(); // apply any change in mInetCondition
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700735 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 Greenwalt029be812010-09-20 18:01:43 -0700766 updateDataNetType(networkType);
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
Joe Onorato49a8bbf2010-09-23 09:50:04 -0700835 if (mServiceState == null || (!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()) {
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700862 iconList = sSignalImages_r[mInetCondition];
Wink Savillee9b06d72009-05-18 21:47:50 -0700863 } else {
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700864 iconList = sSignalImages[mInetCondition];
Wink Saville04e71b32009-04-02 11:00:54 -0700865 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800866 } else {
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700867 iconList = sSignalImages[mInetCondition];
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 Greenwalt029be812010-09-20 18:01:43 -0700928 private final void updateDataNetType(int net) {
Wink Saville04e71b32009-04-02 11:00:54 -0700929 switch (net) {
Wink Saville04e71b32009-04-02 11:00:54 -0700930 case TelephonyManager.NETWORK_TYPE_EDGE:
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700931 mDataIconList = sDataNetType_e[mInetCondition];
Wink Saville04e71b32009-04-02 11:00:54 -0700932 break;
933 case TelephonyManager.NETWORK_TYPE_UMTS:
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700934 mDataIconList = sDataNetType_3g[mInetCondition];
Wink Saville04e71b32009-04-02 11:00:54 -0700935 break;
Li Zheebe66342009-08-14 19:22:16 +0800936 case TelephonyManager.NETWORK_TYPE_HSDPA:
937 case TelephonyManager.NETWORK_TYPE_HSUPA:
938 case TelephonyManager.NETWORK_TYPE_HSPA:
John Wang33e21fc2009-10-08 10:35:27 -0700939 if (mHspaDataDistinguishable) {
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700940 mDataIconList = sDataNetType_h[mInetCondition];
John Wang33e21fc2009-10-08 10:35:27 -0700941 } else {
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700942 mDataIconList = sDataNetType_3g[mInetCondition];
John Wang33e21fc2009-10-08 10:35:27 -0700943 }
Li Zheebe66342009-08-14 19:22:16 +0800944 break;
Wink Saville04e71b32009-04-02 11:00:54 -0700945 case TelephonyManager.NETWORK_TYPE_CDMA:
946 // display 1xRTT for IS95A/B
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700947 mDataIconList = sDataNetType_1x[mInetCondition];
Wink Saville04e71b32009-04-02 11:00:54 -0700948 break;
949 case TelephonyManager.NETWORK_TYPE_1xRTT:
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700950 mDataIconList = sDataNetType_1x[mInetCondition];
Wink Saville04e71b32009-04-02 11:00:54 -0700951 break;
952 case TelephonyManager.NETWORK_TYPE_EVDO_0: //fall through
953 case TelephonyManager.NETWORK_TYPE_EVDO_A:
Naveen Kalla0a5174a2010-04-21 14:48:03 -0700954 case TelephonyManager.NETWORK_TYPE_EVDO_B:
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700955 mDataIconList = sDataNetType_3g[mInetCondition];
Wink Saville04e71b32009-04-02 11:00:54 -0700956 break;
957 default:
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700958 mDataIconList = sDataNetType_g[mInetCondition];
Wink Saville04e71b32009-04-02 11:00:54 -0700959 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800960 }
961 }
962
963 private final void updateDataIcon() {
964 int iconId;
965 boolean visible = true;
966
Wink Savillee9b06d72009-05-18 21:47:50 -0700967 if (!isCdma()) {
968 // GSM case, we have to check also the sim state
969 if (mSimState == IccCard.State.READY || mSimState == IccCard.State.UNKNOWN) {
970 if (hasService() && mDataState == TelephonyManager.DATA_CONNECTED) {
971 switch (mDataActivity) {
972 case TelephonyManager.DATA_ACTIVITY_IN:
973 iconId = mDataIconList[1];
974 break;
975 case TelephonyManager.DATA_ACTIVITY_OUT:
976 iconId = mDataIconList[2];
977 break;
978 case TelephonyManager.DATA_ACTIVITY_INOUT:
979 iconId = mDataIconList[3];
980 break;
981 default:
982 iconId = mDataIconList[0];
983 break;
984 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400985 mService.setIcon("data_connection", iconId, 0);
Wink Savillee9b06d72009-05-18 21:47:50 -0700986 } else {
987 visible = false;
988 }
989 } else {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400990 iconId = R.drawable.stat_sys_no_sim;
991 mService.setIcon("data_connection", iconId, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800992 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700993 } else {
994 // CDMA case, mDataActivity can be also DATA_ACTIVITY_DORMANT
995 if (hasService() && mDataState == TelephonyManager.DATA_CONNECTED) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800996 switch (mDataActivity) {
997 case TelephonyManager.DATA_ACTIVITY_IN:
Wink Savillee9b06d72009-05-18 21:47:50 -0700998 iconId = mDataIconList[1];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800999 break;
1000 case TelephonyManager.DATA_ACTIVITY_OUT:
Wink Savillee9b06d72009-05-18 21:47:50 -07001001 iconId = mDataIconList[2];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001002 break;
1003 case TelephonyManager.DATA_ACTIVITY_INOUT:
Wink Savillee9b06d72009-05-18 21:47:50 -07001004 iconId = mDataIconList[3];
1005 break;
1006 case TelephonyManager.DATA_ACTIVITY_DORMANT:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001007 default:
Wink Savillee9b06d72009-05-18 21:47:50 -07001008 iconId = mDataIconList[0];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001009 break;
1010 }
Joe Onorato798ac4c2010-05-27 16:39:00 -04001011 mService.setIcon("data_connection", iconId, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001012 } else {
1013 visible = false;
1014 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001015 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001016
Dianne Hackborn4840e142009-03-24 22:40:29 -07001017 long ident = Binder.clearCallingIdentity();
1018 try {
Wink Saville04e71b32009-04-02 11:00:54 -07001019 mBatteryStats.notePhoneDataConnectionState(mPhone.getNetworkType(), visible);
Dianne Hackborn4840e142009-03-24 22:40:29 -07001020 } catch (RemoteException e) {
1021 } finally {
1022 Binder.restoreCallingIdentity(ident);
1023 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001024
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001025 if (mDataIconVisible != visible) {
Joe Onorato0cbda992010-05-02 16:28:15 -07001026 mService.setIconVisibility("data_connection", visible);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001027 mDataIconVisible = visible;
1028 }
1029 }
1030
1031 private final void updateVolume() {
1032 AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
1033 final int ringerMode = audioManager.getRingerMode();
1034 final boolean visible = ringerMode == AudioManager.RINGER_MODE_SILENT ||
Wink Savillee9b06d72009-05-18 21:47:50 -07001035 ringerMode == AudioManager.RINGER_MODE_VIBRATE;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001036 final int iconId = audioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER)
Joe Onorato798ac4c2010-05-27 16:39:00 -04001037 ? R.drawable.stat_sys_ringer_vibrate
1038 : R.drawable.stat_sys_ringer_silent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001039
1040 if (visible) {
Joe Onorato798ac4c2010-05-27 16:39:00 -04001041 mService.setIcon("volume", iconId, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001042 }
1043 if (visible != mVolumeVisible) {
Joe Onorato0cbda992010-05-02 16:28:15 -07001044 mService.setIconVisibility("volume", visible);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001045 mVolumeVisible = visible;
1046 }
1047 }
1048
1049 private final void updateBluetooth(Intent intent) {
Joe Onorato798ac4c2010-05-27 16:39:00 -04001050 int iconId = R.drawable.stat_sys_data_bluetooth;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001051 String action = intent.getAction();
Nick Pellyde893f52009-09-08 13:15:33 -07001052 if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
Nick Pellyb24e11b2009-09-08 17:40:43 -07001053 int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
Nick Pellyde893f52009-09-08 13:15:33 -07001054 mBluetoothEnabled = state == BluetoothAdapter.STATE_ON;
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -07001055 } else if (action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) {
1056 int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
1057 BluetoothAdapter.STATE_DISCONNECTED);
1058 if (state == BluetoothAdapter.STATE_CONNECTED) {
1059 iconId = R.drawable.stat_sys_data_bluetooth_connected;
Jaikumar Ganesh084c6652009-12-07 10:58:18 -08001060 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001061 } else {
1062 return;
1063 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001064
Joe Onorato798ac4c2010-05-27 16:39:00 -04001065 mService.setIcon("bluetooth", iconId, 0);
Joe Onorato0cbda992010-05-02 16:28:15 -07001066 mService.setIconVisibility("bluetooth", mBluetoothEnabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001067 }
1068
1069 private final void updateWifi(Intent intent) {
1070 final String action = intent.getAction();
1071 if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001072
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001073 final boolean enabled = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
1074 WifiManager.WIFI_STATE_UNKNOWN) == WifiManager.WIFI_STATE_ENABLED;
Wink Savillee9b06d72009-05-18 21:47:50 -07001075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001076 if (!enabled) {
1077 // If disabled, hide the icon. (We show icon when connected.)
Joe Onorato0cbda992010-05-02 16:28:15 -07001078 mService.setIconVisibility("wifi", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001079 }
Wink Savillee9b06d72009-05-18 21:47:50 -07001080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001081 } else if (action.equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)) {
1082 final boolean enabled = intent.getBooleanExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED,
1083 false);
1084 if (!enabled) {
Joe Onorato0cbda992010-05-02 16:28:15 -07001085 mService.setIconVisibility("wifi", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001086 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001087 } else if (action.equals(WifiManager.RSSI_CHANGED_ACTION)) {
Joe Onorato0cbda992010-05-02 16:28:15 -07001088 int iconId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001089 final int newRssi = intent.getIntExtra(WifiManager.EXTRA_NEW_RSSI, -200);
1090 int newSignalLevel = WifiManager.calculateSignalLevel(newRssi,
Robert Greenwaltfa974c52010-09-13 15:53:26 -07001091 sWifiSignalImages[0].length);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001092 if (newSignalLevel != mLastWifiSignalLevel) {
1093 mLastWifiSignalLevel = newSignalLevel;
1094 if (mIsWifiConnected) {
Robert Greenwalt1e9aac22010-09-15 17:36:33 -07001095 iconId = sWifiSignalImages[mInetCondition][newSignalLevel];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001096 } else {
Joe Onorato0cbda992010-05-02 16:28:15 -07001097 iconId = sWifiTemporarilyNotConnectedImage;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001098 }
Joe Onorato798ac4c2010-05-27 16:39:00 -04001099 mService.setIcon("wifi", iconId, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001100 }
1101 }
1102 }
1103
1104 private final void updateGps(Intent intent) {
1105 final String action = intent.getAction();
Mike Lockwood00b74272010-03-26 10:41:48 -04001106 final boolean enabled = intent.getBooleanExtra(LocationManager.EXTRA_GPS_ENABLED, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001107
Mike Lockwood00b74272010-03-26 10:41:48 -04001108 if (action.equals(LocationManager.GPS_FIX_CHANGE_ACTION) && enabled) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001109 // GPS is getting fixes
Joe Onorato798ac4c2010-05-27 16:39:00 -04001110 mService.setIcon("gps", com.android.internal.R.drawable.stat_sys_gps_on, 0);
Joe Onorato0cbda992010-05-02 16:28:15 -07001111 mService.setIconVisibility("gps", true);
Mike Lockwood00b74272010-03-26 10:41:48 -04001112 } else if (action.equals(LocationManager.GPS_ENABLED_CHANGE_ACTION) && !enabled) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001113 // GPS is off
Joe Onorato0cbda992010-05-02 16:28:15 -07001114 mService.setIconVisibility("gps", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001115 } else {
1116 // GPS is on, but not receiving fixes
Joe Onorato798ac4c2010-05-27 16:39:00 -04001117 mService.setIcon("gps", R.drawable.stat_sys_gps_acquiring_anim, 0);
Joe Onorato0cbda992010-05-02 16:28:15 -07001118 mService.setIconVisibility("gps", true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001119 }
1120 }
1121
Wink Savillee9b06d72009-05-18 21:47:50 -07001122 private final void updateTTY(Intent intent) {
Wink Saville04e71b32009-04-02 11:00:54 -07001123 final String action = intent.getAction();
1124 final boolean enabled = intent.getBooleanExtra(TtyIntent.TTY_ENABLED, false);
1125
Joe Onorato8a9b2202010-02-26 18:56:32 -08001126 if (false) Slog.v(TAG, "updateTTY: enabled: " + enabled);
Wink Saville04e71b32009-04-02 11:00:54 -07001127
1128 if (enabled) {
1129 // TTY is on
Joe Onorato8a9b2202010-02-26 18:56:32 -08001130 if (false) Slog.v(TAG, "updateTTY: set TTY on");
Joe Onorato798ac4c2010-05-27 16:39:00 -04001131 mService.setIcon("tty", R.drawable.stat_sys_tty_mode, 0);
Joe Onorato0cbda992010-05-02 16:28:15 -07001132 mService.setIconVisibility("tty", true);
Wink Saville04e71b32009-04-02 11:00:54 -07001133 } else {
1134 // TTY is off
Joe Onorato8a9b2202010-02-26 18:56:32 -08001135 if (false) Slog.v(TAG, "updateTTY: set TTY off");
Joe Onorato0cbda992010-05-02 16:28:15 -07001136 mService.setIconVisibility("tty", false);
Wink Saville04e71b32009-04-02 11:00:54 -07001137 }
1138 }
1139
Robert Greenwalt98e0b142009-10-08 21:15:52 -07001140 private final void updateCdmaRoamingIcon(ServiceState state) {
Wink Savillee9b06d72009-05-18 21:47:50 -07001141 if (!hasService()) {
Joe Onorato0cbda992010-05-02 16:28:15 -07001142 mService.setIconVisibility("cdma_eri", false);
Wink Savillef3152382009-06-01 14:39:20 -07001143 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001144 }
1145
1146 if (!isCdma()) {
Joe Onorato0cbda992010-05-02 16:28:15 -07001147 mService.setIconVisibility("cdma_eri", false);
Wink Savillef3152382009-06-01 14:39:20 -07001148 return;
Wink Savillee9b06d72009-05-18 21:47:50 -07001149 }
1150
1151 int[] iconList = sRoamingIndicatorImages_cdma;
Robert Greenwalt98e0b142009-10-08 21:15:52 -07001152 int iconIndex = state.getCdmaEriIconIndex();
1153 int iconMode = state.getCdmaEriIconMode();
Wink Savillee9b06d72009-05-18 21:47:50 -07001154
1155 if (iconIndex == -1) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001156 Slog.e(TAG, "getCdmaEriIconIndex returned null, skipping ERI icon update");
Wink Savillee9b06d72009-05-18 21:47:50 -07001157 return;
1158 }
1159
1160 if (iconMode == -1) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001161 Slog.e(TAG, "getCdmeEriIconMode returned null, skipping ERI icon update");
Wink Savillee9b06d72009-05-18 21:47:50 -07001162 return;
1163 }
1164
1165 if (iconIndex == EriInfo.ROAMING_INDICATOR_OFF) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001166 if (false) Slog.v(TAG, "Cdma ROAMING_INDICATOR_OFF, removing ERI icon");
Joe Onorato0cbda992010-05-02 16:28:15 -07001167 mService.setIconVisibility("cdma_eri", false);
Wink Savillee9b06d72009-05-18 21:47:50 -07001168 return;
1169 }
1170
1171 switch (iconMode) {
1172 case EriInfo.ROAMING_ICON_MODE_NORMAL:
Joe Onorato798ac4c2010-05-27 16:39:00 -04001173 mService.setIcon("cdma_eri", iconList[iconIndex], 0);
Joe Onorato0cbda992010-05-02 16:28:15 -07001174 mService.setIconVisibility("cdma_eri", true);
Wink Savillee9b06d72009-05-18 21:47:50 -07001175 break;
1176 case EriInfo.ROAMING_ICON_MODE_FLASH:
Joe Onorato798ac4c2010-05-27 16:39:00 -04001177 mService.setIcon("cdma_eri", R.drawable.stat_sys_roaming_cdma_flash, 0);
Joe Onorato0cbda992010-05-02 16:28:15 -07001178 mService.setIconVisibility("cdma_eri", true);
Wink Savillee9b06d72009-05-18 21:47:50 -07001179 break;
1180
1181 }
Joe Onorato798ac4c2010-05-27 16:39:00 -04001182 mService.setIcon("phone_signal", mPhoneSignalIconId, 0);
Wink Savillee9b06d72009-05-18 21:47:50 -07001183 }
1184
1185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001186 private class StatusBarHandler extends Handler {
1187 @Override
1188 public void handleMessage(Message msg) {
1189 switch (msg.what) {
1190 case EVENT_BATTERY_CLOSE:
1191 if (msg.arg1 == mBatteryViewSequence) {
1192 closeLastBatteryView();
1193 }
1194 break;
1195 }
1196 }
1197 }
1198}