blob: dedbe5d70f8ff0e042c3e97df20fcf580d289fec [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 Onoratofd52b182010-11-10 18:00:52 -080017package com.android.systemui.statusbar.phone;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080018
Joe Onorato798ac4c2010-05-27 16:39:00 -040019import android.app.StatusBarManager;
Nick Pellybd022f42009-08-14 18:33:38 -070020import android.bluetooth.BluetoothAdapter;
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -070021import android.bluetooth.BluetoothProfile;
Jiafa Liu3f416732009-07-02 16:36:02 +080022import android.bluetooth.BluetoothPbap;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.content.BroadcastReceiver;
24import android.content.Context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.content.Intent;
26import android.content.IntentFilter;
27import android.content.res.TypedArray;
28import android.graphics.PixelFormat;
Daniel Sandler2c195f72010-05-21 15:42:06 -040029import android.graphics.Typeface;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.graphics.drawable.Drawable;
Mike Lockwood00b74272010-03-26 10:41:48 -040031import android.location.LocationManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.media.AudioManager;
Robert Greenwaltd7085fc2010-09-08 15:24:47 -070033import android.net.ConnectivityManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.net.NetworkInfo;
Daniel Sandler0e9d2af2010-01-25 11:33:03 -050035import android.net.Uri;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.net.wifi.WifiManager;
Dianne Hackborn4840e142009-03-24 22:40:29 -070037import android.os.Binder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038import android.os.Handler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import android.os.Message;
Dianne Hackborn4840e142009-03-24 22:40:29 -070040import android.os.RemoteException;
San Mehat4154c072010-02-09 18:37:54 -080041import android.os.storage.StorageManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042import android.provider.Settings;
43import android.telephony.PhoneStateListener;
44import android.telephony.ServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -070045import android.telephony.SignalStrength;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046import android.telephony.TelephonyManager;
47import android.text.format.DateFormat;
Daniel Sandler2c195f72010-05-21 15:42:06 -040048import android.text.style.CharacterStyle;
Eric Fischer36e136c2010-01-14 17:42:48 -080049import android.text.style.RelativeSizeSpan;
Daniel Sandler2c195f72010-05-21 15:42:06 -040050import android.text.style.ForegroundColorSpan;
51import android.text.style.StyleSpan;
Eric Fischer36e136c2010-01-14 17:42:48 -080052import android.text.Spannable;
53import android.text.SpannableStringBuilder;
Joe Onorato8a9b2202010-02-26 18:56:32 -080054import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import android.view.View;
56import android.view.ViewGroup;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import android.widget.ImageView;
58import android.widget.LinearLayout;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059
Wink Saville04e71b32009-04-02 11:00:54 -070060import com.android.internal.app.IBatteryStats;
Wink Saville04e71b32009-04-02 11:00:54 -070061import com.android.internal.telephony.IccCard;
62import com.android.internal.telephony.TelephonyIntents;
Wink Savillee9b06d72009-05-18 21:47:50 -070063import com.android.internal.telephony.cdma.EriInfo;
Wink Saville04e71b32009-04-02 11:00:54 -070064import com.android.internal.telephony.cdma.TtyIntent;
65import com.android.server.am.BatteryStatsService;
66
Joe Onorato798ac4c2010-05-27 16:39:00 -040067import com.android.systemui.R;
68
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069/**
70 * This class contains all of the policy about which icons are installed in the status
Joe Onorato798ac4c2010-05-27 16:39:00 -040071 * bar at boot time. It goes through the normal API for icons, even though it probably
72 * strictly doesn't need to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073 */
Joe Onoratofd52b182010-11-10 18:00:52 -080074public class PhoneStatusBarPolicy {
75 private static final String TAG = "PhoneStatusBarPolicy";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077 // message codes for the handler
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078 private static final int EVENT_BATTERY_CLOSE = 4;
79
Daniel Sandler2c195f72010-05-21 15:42:06 -040080 private static final int AM_PM_STYLE_NORMAL = 0;
81 private static final int AM_PM_STYLE_SMALL = 1;
82 private static final int AM_PM_STYLE_GONE = 2;
83
84 private static final int AM_PM_STYLE = AM_PM_STYLE_GONE;
85
Robert Greenwaltd7085fc2010-09-08 15:24:47 -070086 private static final int INET_CONDITION_THRESHOLD = 50;
87
Dianne Hackborn4840e142009-03-24 22:40:29 -070088 private final Context mContext;
Joe Onorato798ac4c2010-05-27 16:39:00 -040089 private final StatusBarManager mService;
Joe Onorato10523b4d2010-10-25 10:42:46 -070090 private final Handler mHandler = new Handler();
Dianne Hackborn4840e142009-03-24 22:40:29 -070091 private final IBatteryStats mBatteryStats;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092
San Mehat4154c072010-02-09 18:37:54 -080093 // storage
94 private StorageManager mStorageManager;
95
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 // phone
97 private TelephonyManager mPhone;
Joe Onorato0cbda992010-05-02 16:28:15 -070098 private int mPhoneSignalIconId;
Wink Saville04e71b32009-04-02 11:00:54 -070099
100 //***** Signal strength icons
Wink Saville04e71b32009-04-02 11:00:54 -0700101 //GSM/UMTS
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700102 private static final int[][] sSignalImages = {
103 { R.drawable.stat_sys_signal_0,
104 R.drawable.stat_sys_signal_1,
105 R.drawable.stat_sys_signal_2,
106 R.drawable.stat_sys_signal_3,
107 R.drawable.stat_sys_signal_4 },
108 { R.drawable.stat_sys_signal_0_fully,
109 R.drawable.stat_sys_signal_1_fully,
110 R.drawable.stat_sys_signal_2_fully,
111 R.drawable.stat_sys_signal_3_fully,
112 R.drawable.stat_sys_signal_4_fully }
Wink Savillee9b06d72009-05-18 21:47:50 -0700113 };
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700114 private static final int[][] sSignalImages_r = {
115 { R.drawable.stat_sys_r_signal_0,
116 R.drawable.stat_sys_r_signal_1,
117 R.drawable.stat_sys_r_signal_2,
118 R.drawable.stat_sys_r_signal_3,
119 R.drawable.stat_sys_r_signal_4 },
120 { R.drawable.stat_sys_r_signal_0_fully,
121 R.drawable.stat_sys_r_signal_1_fully,
122 R.drawable.stat_sys_r_signal_2_fully,
123 R.drawable.stat_sys_r_signal_3_fully,
124 R.drawable.stat_sys_r_signal_4_fully }
Wink Savillee9b06d72009-05-18 21:47:50 -0700125 };
Wink Savillee9b06d72009-05-18 21:47:50 -0700126 private static final int[] sRoamingIndicatorImages_cdma = new int[] {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400127 R.drawable.stat_sys_roaming_cdma_0, //Standard Roaming Indicator
Wink Savillee9b06d72009-05-18 21:47:50 -0700128 // 1 is Standard Roaming Indicator OFF
129 // TODO T: image never used, remove and put 0 instead?
Joe Onorato798ac4c2010-05-27 16:39:00 -0400130 R.drawable.stat_sys_roaming_cdma_0,
Wink Savillee9b06d72009-05-18 21:47:50 -0700131
132 // 2 is Standard Roaming Indicator FLASHING
133 // TODO T: image never used, remove and put 0 instead?
Joe Onorato798ac4c2010-05-27 16:39:00 -0400134 R.drawable.stat_sys_roaming_cdma_0,
Wink Savillee9b06d72009-05-18 21:47:50 -0700135
136 // 3-12 Standard ERI
Joe Onorato798ac4c2010-05-27 16:39:00 -0400137 R.drawable.stat_sys_roaming_cdma_0, //3
138 R.drawable.stat_sys_roaming_cdma_0,
139 R.drawable.stat_sys_roaming_cdma_0,
140 R.drawable.stat_sys_roaming_cdma_0,
141 R.drawable.stat_sys_roaming_cdma_0,
142 R.drawable.stat_sys_roaming_cdma_0,
143 R.drawable.stat_sys_roaming_cdma_0,
144 R.drawable.stat_sys_roaming_cdma_0,
145 R.drawable.stat_sys_roaming_cdma_0,
146 R.drawable.stat_sys_roaming_cdma_0,
Wink Savillee9b06d72009-05-18 21:47:50 -0700147
148 // 13-63 Reserved for Standard ERI
Joe Onorato798ac4c2010-05-27 16:39:00 -0400149 R.drawable.stat_sys_roaming_cdma_0, //13
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,
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,
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,
Wink Savillee9b06d72009-05-18 21:47:50 -0700200
201 // 64-127 Reserved for Non Standard (Operator Specific) ERI
Joe Onorato798ac4c2010-05-27 16:39:00 -0400202 R.drawable.stat_sys_roaming_cdma_0, //64
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,
220 R.drawable.stat_sys_roaming_cdma_0,
221 R.drawable.stat_sys_roaming_cdma_0 //83
Wink Savillee9b06d72009-05-18 21:47:50 -0700222
223 // 128-255 Reserved
Wink Saville04e71b32009-04-02 11:00:54 -0700224 };
Wink Saville04e71b32009-04-02 11:00:54 -0700225
226 //***** Data connection icons
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700227 private int[] mDataIconList = sDataNetType_g[0];
Wink Saville04e71b32009-04-02 11:00:54 -0700228 //GSM/UMTS
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700229 private static final int[][] sDataNetType_g = {
230 { R.drawable.stat_sys_data_connected_g,
231 R.drawable.stat_sys_data_in_g,
232 R.drawable.stat_sys_data_out_g,
233 R.drawable.stat_sys_data_inandout_g },
Robert Greenwalt26faee32010-09-10 09:36:43 -0700234 { R.drawable.stat_sys_data_fully_connected_g,
235 R.drawable.stat_sys_data_fully_in_g,
236 R.drawable.stat_sys_data_fully_out_g,
237 R.drawable.stat_sys_data_fully_inandout_g }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238 };
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700239 private static final int[][] sDataNetType_3g = {
240 { R.drawable.stat_sys_data_connected_3g,
241 R.drawable.stat_sys_data_in_3g,
242 R.drawable.stat_sys_data_out_3g,
243 R.drawable.stat_sys_data_inandout_3g },
Robert Greenwalt26faee32010-09-10 09:36:43 -0700244 { R.drawable.stat_sys_data_fully_connected_3g,
245 R.drawable.stat_sys_data_fully_in_3g,
246 R.drawable.stat_sys_data_fully_out_3g,
247 R.drawable.stat_sys_data_fully_inandout_3g }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 };
Wink Saville2b8bcfe2011-02-24 17:58:51 -0800249 private static final int[][] sDataNetType_4g = {
250 { R.drawable.stat_sys_data_connected_4g,
251 R.drawable.stat_sys_data_in_4g,
252 R.drawable.stat_sys_data_out_4g,
253 R.drawable.stat_sys_data_inandout_4g },
254 { R.drawable.stat_sys_data_fully_connected_4g,
255 R.drawable.stat_sys_data_fully_in_4g,
256 R.drawable.stat_sys_data_fully_out_4g,
257 R.drawable.stat_sys_data_fully_inandout_4g }
258 };
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700259 private static final int[][] sDataNetType_e = {
260 { R.drawable.stat_sys_data_connected_e,
261 R.drawable.stat_sys_data_in_e,
262 R.drawable.stat_sys_data_out_e,
263 R.drawable.stat_sys_data_inandout_e },
Robert Greenwalt26faee32010-09-10 09:36:43 -0700264 { R.drawable.stat_sys_data_fully_connected_e,
265 R.drawable.stat_sys_data_fully_in_e,
266 R.drawable.stat_sys_data_fully_out_e,
267 R.drawable.stat_sys_data_fully_inandout_e }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 };
Li Zheebe66342009-08-14 19:22:16 +0800269 //3.5G
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700270 private static final int[][] sDataNetType_h = {
271 { R.drawable.stat_sys_data_connected_h,
272 R.drawable.stat_sys_data_in_h,
273 R.drawable.stat_sys_data_out_h,
274 R.drawable.stat_sys_data_inandout_h },
Robert Greenwalt26faee32010-09-10 09:36:43 -0700275 { R.drawable.stat_sys_data_fully_connected_h,
276 R.drawable.stat_sys_data_fully_in_h,
277 R.drawable.stat_sys_data_fully_out_h,
278 R.drawable.stat_sys_data_fully_inandout_h }
Li Zheebe66342009-08-14 19:22:16 +0800279 };
280
Wink Saville04e71b32009-04-02 11:00:54 -0700281 //CDMA
johnwang9f87cb22009-08-25 15:25:37 -0700282 // Use 3G icons for EVDO data and 1x icons for 1XRTT data
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700283 private static final int[][] sDataNetType_1x = {
284 { R.drawable.stat_sys_data_connected_1x,
285 R.drawable.stat_sys_data_in_1x,
286 R.drawable.stat_sys_data_out_1x,
287 R.drawable.stat_sys_data_inandout_1x },
Robert Greenwalt26faee32010-09-10 09:36:43 -0700288 { R.drawable.stat_sys_data_fully_connected_1x,
289 R.drawable.stat_sys_data_fully_in_1x,
290 R.drawable.stat_sys_data_fully_out_1x,
291 R.drawable.stat_sys_data_fully_inandout_1x }
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700292 };
Wink Saville04e71b32009-04-02 11:00:54 -0700293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800294 // Assume it's all good unless we hear otherwise. We don't always seem
295 // to get broadcasts that it *is* there.
Wink Saville04e71b32009-04-02 11:00:54 -0700296 IccCard.State mSimState = IccCard.State.READY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800297 int mPhoneState = TelephonyManager.CALL_STATE_IDLE;
298 int mDataState = TelephonyManager.DATA_DISCONNECTED;
299 int mDataActivity = TelephonyManager.DATA_ACTIVITY_NONE;
300 ServiceState mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700301 SignalStrength mSignalStrength;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800302
303 // data connection
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800304 private boolean mDataIconVisible;
John Wang33e21fc2009-10-08 10:35:27 -0700305 private boolean mHspaDataDistinguishable;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800306
307 // ringer volume
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800308 private boolean mVolumeVisible;
Wink Saville04e71b32009-04-02 11:00:54 -0700309
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800310 // bluetooth device status
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800311 private boolean mBluetoothEnabled;
312
313 // wifi
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700314 private static final int[][] sWifiSignalImages = {
315 { R.drawable.stat_sys_wifi_signal_1,
316 R.drawable.stat_sys_wifi_signal_2,
317 R.drawable.stat_sys_wifi_signal_3,
318 R.drawable.stat_sys_wifi_signal_4 },
Robert Greenwalt26faee32010-09-10 09:36:43 -0700319 { R.drawable.stat_sys_wifi_signal_1_fully,
320 R.drawable.stat_sys_wifi_signal_2_fully,
321 R.drawable.stat_sys_wifi_signal_3_fully,
322 R.drawable.stat_sys_wifi_signal_4_fully }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800323 };
324 private static final int sWifiTemporarilyNotConnectedImage =
Joe Onorato798ac4c2010-05-27 16:39:00 -0400325 R.drawable.stat_sys_wifi_signal_0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800326
327 private int mLastWifiSignalLevel = -1;
328 private boolean mIsWifiConnected = false;
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700329
330 // state of inet connection - 0 not connected, 100 connected
331 private int mInetCondition = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800332
333 // sync state
334 // If sync is active the SyncActive icon is displayed. If sync is not active but
335 // sync is failing the SyncFailing icon is displayed. Otherwise neither are displayed.
Wink Savillee9b06d72009-05-18 21:47:50 -0700336
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800337 private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
338 @Override
339 public void onReceive(Context context, Intent intent) {
340 String action = intent.getAction();
Joe Onorato263700d2010-05-14 11:54:53 -0700341 if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {
Dianne Hackborn8ec5b832009-07-01 21:19:35 -0700342 updateBattery(intent);
343 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344 else if (action.equals(Intent.ACTION_ALARM_CHANGED)) {
345 updateAlarm(intent);
346 }
347 else if (action.equals(Intent.ACTION_SYNC_STATE_CHANGED)) {
348 updateSyncState(intent);
349 }
Nick Pellyde893f52009-09-08 13:15:33 -0700350 else if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED) ||
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -0700351 action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352 updateBluetooth(intent);
353 }
354 else if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION) ||
355 action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION) ||
356 action.equals(WifiManager.RSSI_CHANGED_ACTION)) {
357 updateWifi(intent);
358 }
Mike Lockwood00b74272010-03-26 10:41:48 -0400359 else if (action.equals(LocationManager.GPS_ENABLED_CHANGE_ACTION) ||
360 action.equals(LocationManager.GPS_FIX_CHANGE_ACTION)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800361 updateGps(intent);
362 }
363 else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION) ||
364 action.equals(AudioManager.VIBRATE_SETTING_CHANGED_ACTION)) {
365 updateVolume();
366 }
367 else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
368 updateSimState(intent);
369 }
Wink Saville04e71b32009-04-02 11:00:54 -0700370 else if (action.equals(TtyIntent.TTY_ENABLED_CHANGE_ACTION)) {
371 updateTTY(intent);
372 }
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700373 else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION) ||
374 action.equals(ConnectivityManager.INET_CONDITION_ACTION)) {
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700375 // TODO - stop using other means to get wifi/mobile info
376 updateConnectivity(intent);
377 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 }
379 };
380
Joe Onoratofd52b182010-11-10 18:00:52 -0800381 public PhoneStatusBarPolicy(Context context) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382 mContext = context;
Joe Onorato798ac4c2010-05-27 16:39:00 -0400383 mService = (StatusBarManager)context.getSystemService(Context.STATUS_BAR_SERVICE);
Wink Savillee9b06d72009-05-18 21:47:50 -0700384 mSignalStrength = new SignalStrength();
Dianne Hackborn4840e142009-03-24 22:40:29 -0700385 mBatteryStats = BatteryStatsService.getService();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386
San Mehat4154c072010-02-09 18:37:54 -0800387 // storage
388 mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
389 mStorageManager.registerListener(
Joe Onoratofe4f3ae2010-06-04 11:25:26 -0700390 new com.android.systemui.usb.StorageNotification(context));
San Mehat4154c072010-02-09 18:37:54 -0800391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800392 // battery
Joe Onorato798ac4c2010-05-27 16:39:00 -0400393 mService.setIcon("battery", com.android.internal.R.drawable.stat_sys_battery_unknown, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800394
395 // phone_signal
396 mPhone = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
Joe Onorato798ac4c2010-05-27 16:39:00 -0400397 mPhoneSignalIconId = R.drawable.stat_sys_signal_null;
398 mService.setIcon("phone_signal", mPhoneSignalIconId, 0);
Wink Savillee9b06d72009-05-18 21:47:50 -0700399
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800400 // register for phone state notifications.
401 ((TelephonyManager)mContext.getSystemService(Context.TELEPHONY_SERVICE))
402 .listen(mPhoneStateListener,
403 PhoneStateListener.LISTEN_SERVICE_STATE
Wink Savillee9b06d72009-05-18 21:47:50 -0700404 | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800405 | PhoneStateListener.LISTEN_CALL_STATE
406 | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
407 | PhoneStateListener.LISTEN_DATA_ACTIVITY);
408
409 // data_connection
Joe Onorato798ac4c2010-05-27 16:39:00 -0400410 mService.setIcon("data_connection", R.drawable.stat_sys_data_connected_g, 0);
411 mService.setIconVisibility("data_connection", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800412
413 // wifi
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700414 mService.setIcon("wifi", sWifiSignalImages[0][0], 0);
Joe Onorato798ac4c2010-05-27 16:39:00 -0400415 mService.setIconVisibility("wifi", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800416 // wifi will get updated by the sticky intents
Wink Saville04e71b32009-04-02 11:00:54 -0700417
418 // TTY status
Joe Onorato798ac4c2010-05-27 16:39:00 -0400419 mService.setIcon("tty", R.drawable.stat_sys_tty_mode, 0);
420 mService.setIconVisibility("tty", false);
Wink Saville04e71b32009-04-02 11:00:54 -0700421
Wink Savillee9b06d72009-05-18 21:47:50 -0700422 // Cdma Roaming Indicator, ERI
Joe Onorato798ac4c2010-05-27 16:39:00 -0400423 mService.setIcon("cdma_eri", R.drawable.stat_sys_roaming_cdma_0, 0);
424 mService.setIconVisibility("cdma_eri", false);
Wink Savillee9b06d72009-05-18 21:47:50 -0700425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800426 // bluetooth status
Joe Onorato798ac4c2010-05-27 16:39:00 -0400427 mService.setIcon("bluetooth", R.drawable.stat_sys_data_bluetooth, 0);
Nick Pellyf242b7b2009-10-08 00:12:45 +0200428 BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
Nick Pellybd022f42009-08-14 18:33:38 -0700429 if (adapter != null) {
430 mBluetoothEnabled = adapter.isEnabled();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800431 } else {
432 mBluetoothEnabled = false;
433 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700434 mService.setIconVisibility("bluetooth", mBluetoothEnabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435
436 // Gps status
Joe Onorato798ac4c2010-05-27 16:39:00 -0400437 mService.setIcon("gps", R.drawable.stat_sys_gps_acquiring_anim, 0);
438 mService.setIconVisibility("gps", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800439
440 // Alarm clock
Joe Onorato798ac4c2010-05-27 16:39:00 -0400441 mService.setIcon("alarm_clock", R.drawable.stat_notify_alarm, 0);
442 mService.setIconVisibility("alarm_clock", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443
444 // Sync state
Joe Onorato798ac4c2010-05-27 16:39:00 -0400445 mService.setIcon("sync_active", com.android.internal.R.drawable.stat_notify_sync_anim0, 0);
446 mService.setIcon("sync_failing", com.android.internal.R.drawable.stat_notify_sync_error, 0);
447 mService.setIconVisibility("sync_active", false);
448 mService.setIconVisibility("sync_failing", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800449
450 // volume
Joe Onorato798ac4c2010-05-27 16:39:00 -0400451 mService.setIcon("volume", R.drawable.stat_sys_ringer_silent, 0);
452 mService.setIconVisibility("volume", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800453 updateVolume();
johnwang347c5a22009-08-24 22:11:11 -0700454
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800455 IntentFilter filter = new IntentFilter();
456
457 // Register for Intent broadcasts for...
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800458 filter.addAction(Intent.ACTION_BATTERY_CHANGED);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800459 filter.addAction(Intent.ACTION_ALARM_CHANGED);
460 filter.addAction(Intent.ACTION_SYNC_STATE_CHANGED);
461 filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
462 filter.addAction(AudioManager.VIBRATE_SETTING_CHANGED_ACTION);
Nick Pellyde893f52009-09-08 13:15:33 -0700463 filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -0700464 filter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800465 filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
466 filter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
467 filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
468 filter.addAction(WifiManager.RSSI_CHANGED_ACTION);
Mike Lockwood00b74272010-03-26 10:41:48 -0400469 filter.addAction(LocationManager.GPS_ENABLED_CHANGE_ACTION);
470 filter.addAction(LocationManager.GPS_FIX_CHANGE_ACTION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800471 filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
Wink Saville04e71b32009-04-02 11:00:54 -0700472 filter.addAction(TtyIntent.TTY_ENABLED_CHANGE_ACTION);
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700473 filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700474 filter.addAction(ConnectivityManager.INET_CONDITION_ACTION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800475 mContext.registerReceiver(mIntentReceiver, filter, null, mHandler);
John Wang33e21fc2009-10-08 10:35:27 -0700476
477 // load config to determine if to distinguish Hspa data icon
478 try {
479 mHspaDataDistinguishable = mContext.getResources().getBoolean(
Joe Onorato798ac4c2010-05-27 16:39:00 -0400480 R.bool.config_hspa_data_distinguishable);
John Wang33e21fc2009-10-08 10:35:27 -0700481 } catch (Exception e) {
482 mHspaDataDistinguishable = false;
483 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800484 }
485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486 private final void updateAlarm(Intent intent) {
487 boolean alarmSet = intent.getBooleanExtra("alarmSet", false);
Joe Onorato0cbda992010-05-02 16:28:15 -0700488 mService.setIconVisibility("alarm_clock", alarmSet);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800489 }
490
491 private final void updateSyncState(Intent intent) {
492 boolean isActive = intent.getBooleanExtra("active", false);
493 boolean isFailing = intent.getBooleanExtra("failing", false);
Joe Onorato0cbda992010-05-02 16:28:15 -0700494 mService.setIconVisibility("sync_active", isActive);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800495 // Don't display sync failing icon: BUG 1297963 Set sync error timeout to "never"
Joe Onorato0cbda992010-05-02 16:28:15 -0700496 //mService.setIconVisibility("sync_failing", isFailing && !isActive);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497 }
498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800499 private final void updateBattery(Intent intent) {
Joe Onorato0cbda992010-05-02 16:28:15 -0700500 final int id = intent.getIntExtra("icon-small", 0);
501 int level = intent.getIntExtra("level", 0);
Joe Onorato798ac4c2010-05-27 16:39:00 -0400502 mService.setIcon("battery", id, level);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503 }
504
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700505 private void updateConnectivity(Intent intent) {
506 NetworkInfo info = (NetworkInfo)(intent.getParcelableExtra(
507 ConnectivityManager.EXTRA_NETWORK_INFO));
508 int connectionStatus = intent.getIntExtra(ConnectivityManager.EXTRA_INET_CONDITION, 0);
Robert Greenwalt029be812010-09-20 18:01:43 -0700509
510 int inetCondition = (connectionStatus > INET_CONDITION_THRESHOLD ? 1 : 0);
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700511
512 switch (info.getType()) {
513 case ConnectivityManager.TYPE_MOBILE:
Robert Greenwalt029be812010-09-20 18:01:43 -0700514 mInetCondition = inetCondition;
515 updateDataNetType(info.getSubtype());
516 updateDataIcon();
517 updateSignalStrength(); // apply any change in connectionStatus
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700518 break;
519 case ConnectivityManager.TYPE_WIFI:
Robert Greenwalt029be812010-09-20 18:01:43 -0700520 mInetCondition = inetCondition;
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700521 if (info.isConnected()) {
522 mIsWifiConnected = true;
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700523 int iconId;
524 if (mLastWifiSignalLevel == -1) {
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700525 iconId = sWifiSignalImages[mInetCondition][0];
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700526 } else {
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700527 iconId = sWifiSignalImages[mInetCondition][mLastWifiSignalLevel];
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700528 }
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700529 mService.setIcon("wifi", iconId, 0);
530 // Show the icon since wi-fi is connected
531 mService.setIconVisibility("wifi", true);
532 } else {
533 mLastWifiSignalLevel = -1;
534 mIsWifiConnected = false;
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700535 int iconId = sWifiSignalImages[0][0];
536
537 mService.setIcon("wifi", iconId, 0);
538 // Hide the icon since we're not connected
539 mService.setIconVisibility("wifi", false);
540 }
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700541 updateSignalStrength(); // apply any change in mInetCondition
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700542 break;
543 }
544 }
545
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800546 private PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
547 @Override
Wink Savillee9b06d72009-05-18 21:47:50 -0700548 public void onSignalStrengthsChanged(SignalStrength signalStrength) {
549 mSignalStrength = signalStrength;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800550 updateSignalStrength();
551 }
552
553 @Override
554 public void onServiceStateChanged(ServiceState state) {
555 mServiceState = state;
556 updateSignalStrength();
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700557 updateCdmaRoamingIcon(state);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800558 updateDataIcon();
559 }
560
561 @Override
562 public void onCallStateChanged(int state, String incomingNumber) {
johnwang347c5a22009-08-24 22:11:11 -0700563 // In cdma, if a voice call is made, RSSI should switch to 1x.
564 if (isCdma()) {
565 updateSignalStrength();
566 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567 }
568
569 @Override
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700570 public void onDataConnectionStateChanged(int state, int networkType) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800571 mDataState = state;
Robert Greenwalt029be812010-09-20 18:01:43 -0700572 updateDataNetType(networkType);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800573 updateDataIcon();
574 }
575
576 @Override
577 public void onDataActivity(int direction) {
578 mDataActivity = direction;
579 updateDataIcon();
580 }
581 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800582
583 private final void updateSimState(Intent intent) {
Wink Saville04e71b32009-04-02 11:00:54 -0700584 String stateExtra = intent.getStringExtra(IccCard.INTENT_KEY_ICC_STATE);
585 if (IccCard.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) {
586 mSimState = IccCard.State.ABSENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800587 }
Wink Saville04e71b32009-04-02 11:00:54 -0700588 else if (IccCard.INTENT_VALUE_ICC_READY.equals(stateExtra)) {
589 mSimState = IccCard.State.READY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 }
Wink Saville04e71b32009-04-02 11:00:54 -0700591 else if (IccCard.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) {
592 final String lockedReason = intent.getStringExtra(IccCard.INTENT_KEY_LOCKED_REASON);
593 if (IccCard.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) {
594 mSimState = IccCard.State.PIN_REQUIRED;
johnwang347c5a22009-08-24 22:11:11 -0700595 }
Wink Saville04e71b32009-04-02 11:00:54 -0700596 else if (IccCard.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) {
597 mSimState = IccCard.State.PUK_REQUIRED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800598 }
599 else {
Wink Saville04e71b32009-04-02 11:00:54 -0700600 mSimState = IccCard.State.NETWORK_LOCKED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800601 }
602 } else {
Wink Saville04e71b32009-04-02 11:00:54 -0700603 mSimState = IccCard.State.UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800604 }
605 updateDataIcon();
606 }
607
Wink Savillee9b06d72009-05-18 21:47:50 -0700608 private boolean isCdma() {
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700609 return (mSignalStrength != null) && !mSignalStrength.isGsm();
Wink Savillee9b06d72009-05-18 21:47:50 -0700610 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800611
Wink Savillee9b06d72009-05-18 21:47:50 -0700612 private boolean hasService() {
613 if (mServiceState != null) {
614 switch (mServiceState.getState()) {
615 case ServiceState.STATE_OUT_OF_SERVICE:
616 case ServiceState.STATE_POWER_OFF:
617 return false;
618 default:
619 return true;
620 }
621 } else {
622 return false;
623 }
624 }
625
626 private final void updateSignalStrength() {
Wink Savillee9b06d72009-05-18 21:47:50 -0700627 int[] iconList;
Wink Savillee9b06d72009-05-18 21:47:50 -0700628
John Wang56c2d2f2010-04-07 08:57:17 -0700629 // Display signal strength while in "emergency calls only" mode
Joe Onorato49a8bbf2010-09-23 09:50:04 -0700630 if (mServiceState == null || (!hasService() && !mServiceState.isEmergencyOnly())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800631 //Slog.d(TAG, "updateSignalStrength: no service");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800632 if (Settings.System.getInt(mContext.getContentResolver(),
633 Settings.System.AIRPLANE_MODE_ON, 0) == 1) {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400634 mPhoneSignalIconId = R.drawable.stat_sys_signal_flightmode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 } else {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400636 mPhoneSignalIconId = R.drawable.stat_sys_signal_null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800637 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400638 mService.setIcon("phone_signal", mPhoneSignalIconId, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800639 return;
640 }
641
Wink Savillee9b06d72009-05-18 21:47:50 -0700642 if (!isCdma()) {
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700643 // Though mPhone is a Manager, this call is not an IPC
Wink Savillee9b06d72009-05-18 21:47:50 -0700644 if (mPhone.isNetworkRoaming()) {
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700645 iconList = sSignalImages_r[mInetCondition];
Wink Savillee9b06d72009-05-18 21:47:50 -0700646 } else {
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700647 iconList = sSignalImages[mInetCondition];
Wink Saville04e71b32009-04-02 11:00:54 -0700648 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800649 } else {
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700650 iconList = sSignalImages[mInetCondition];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800651 }
Wink Saville52840902011-02-18 12:40:47 -0800652 mPhoneSignalIconId = iconList[mSignalStrength.getLevel()];
Joe Onorato798ac4c2010-05-27 16:39:00 -0400653 mService.setIcon("phone_signal", mPhoneSignalIconId, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800654 }
655
Robert Greenwalt029be812010-09-20 18:01:43 -0700656 private final void updateDataNetType(int net) {
Wink Saville04e71b32009-04-02 11:00:54 -0700657 switch (net) {
Wink Saville04e71b32009-04-02 11:00:54 -0700658 case TelephonyManager.NETWORK_TYPE_EDGE:
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700659 mDataIconList = sDataNetType_e[mInetCondition];
Wink Saville04e71b32009-04-02 11:00:54 -0700660 break;
661 case TelephonyManager.NETWORK_TYPE_UMTS:
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700662 mDataIconList = sDataNetType_3g[mInetCondition];
Wink Saville04e71b32009-04-02 11:00:54 -0700663 break;
Li Zheebe66342009-08-14 19:22:16 +0800664 case TelephonyManager.NETWORK_TYPE_HSDPA:
665 case TelephonyManager.NETWORK_TYPE_HSUPA:
666 case TelephonyManager.NETWORK_TYPE_HSPA:
John Wang33e21fc2009-10-08 10:35:27 -0700667 if (mHspaDataDistinguishable) {
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700668 mDataIconList = sDataNetType_h[mInetCondition];
John Wang33e21fc2009-10-08 10:35:27 -0700669 } else {
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700670 mDataIconList = sDataNetType_3g[mInetCondition];
John Wang33e21fc2009-10-08 10:35:27 -0700671 }
Li Zheebe66342009-08-14 19:22:16 +0800672 break;
Wink Saville04e71b32009-04-02 11:00:54 -0700673 case TelephonyManager.NETWORK_TYPE_CDMA:
674 // display 1xRTT for IS95A/B
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700675 mDataIconList = sDataNetType_1x[mInetCondition];
Wink Saville04e71b32009-04-02 11:00:54 -0700676 break;
677 case TelephonyManager.NETWORK_TYPE_1xRTT:
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700678 mDataIconList = sDataNetType_1x[mInetCondition];
Wink Saville04e71b32009-04-02 11:00:54 -0700679 break;
680 case TelephonyManager.NETWORK_TYPE_EVDO_0: //fall through
681 case TelephonyManager.NETWORK_TYPE_EVDO_A:
Naveen Kalla0a5174a2010-04-21 14:48:03 -0700682 case TelephonyManager.NETWORK_TYPE_EVDO_B:
Wink Saville2b8bcfe2011-02-24 17:58:51 -0800683 case TelephonyManager.NETWORK_TYPE_EHRPD:
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700684 mDataIconList = sDataNetType_3g[mInetCondition];
Wink Saville04e71b32009-04-02 11:00:54 -0700685 break;
Wink Saville2b8bcfe2011-02-24 17:58:51 -0800686 case TelephonyManager.NETWORK_TYPE_LTE:
687 mDataIconList = sDataNetType_4g[mInetCondition];
688 break;
Wink Saville04e71b32009-04-02 11:00:54 -0700689 default:
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700690 mDataIconList = sDataNetType_g[mInetCondition];
Wink Saville04e71b32009-04-02 11:00:54 -0700691 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800692 }
693 }
694
695 private final void updateDataIcon() {
696 int iconId;
697 boolean visible = true;
698
Wink Savillee9b06d72009-05-18 21:47:50 -0700699 if (!isCdma()) {
700 // GSM case, we have to check also the sim state
701 if (mSimState == IccCard.State.READY || mSimState == IccCard.State.UNKNOWN) {
702 if (hasService() && mDataState == TelephonyManager.DATA_CONNECTED) {
703 switch (mDataActivity) {
704 case TelephonyManager.DATA_ACTIVITY_IN:
705 iconId = mDataIconList[1];
706 break;
707 case TelephonyManager.DATA_ACTIVITY_OUT:
708 iconId = mDataIconList[2];
709 break;
710 case TelephonyManager.DATA_ACTIVITY_INOUT:
711 iconId = mDataIconList[3];
712 break;
713 default:
714 iconId = mDataIconList[0];
715 break;
716 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400717 mService.setIcon("data_connection", iconId, 0);
Wink Savillee9b06d72009-05-18 21:47:50 -0700718 } else {
719 visible = false;
720 }
721 } else {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400722 iconId = R.drawable.stat_sys_no_sim;
723 mService.setIcon("data_connection", iconId, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800724 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700725 } else {
726 // CDMA case, mDataActivity can be also DATA_ACTIVITY_DORMANT
727 if (hasService() && mDataState == TelephonyManager.DATA_CONNECTED) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800728 switch (mDataActivity) {
729 case TelephonyManager.DATA_ACTIVITY_IN:
Wink Savillee9b06d72009-05-18 21:47:50 -0700730 iconId = mDataIconList[1];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800731 break;
732 case TelephonyManager.DATA_ACTIVITY_OUT:
Wink Savillee9b06d72009-05-18 21:47:50 -0700733 iconId = mDataIconList[2];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800734 break;
735 case TelephonyManager.DATA_ACTIVITY_INOUT:
Wink Savillee9b06d72009-05-18 21:47:50 -0700736 iconId = mDataIconList[3];
737 break;
738 case TelephonyManager.DATA_ACTIVITY_DORMANT:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800739 default:
Wink Savillee9b06d72009-05-18 21:47:50 -0700740 iconId = mDataIconList[0];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800741 break;
742 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400743 mService.setIcon("data_connection", iconId, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800744 } else {
745 visible = false;
746 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800747 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700748
Dianne Hackborn4840e142009-03-24 22:40:29 -0700749 long ident = Binder.clearCallingIdentity();
750 try {
Wink Saville04e71b32009-04-02 11:00:54 -0700751 mBatteryStats.notePhoneDataConnectionState(mPhone.getNetworkType(), visible);
Dianne Hackborn4840e142009-03-24 22:40:29 -0700752 } catch (RemoteException e) {
753 } finally {
754 Binder.restoreCallingIdentity(ident);
755 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700756
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800757 if (mDataIconVisible != visible) {
Joe Onorato0cbda992010-05-02 16:28:15 -0700758 mService.setIconVisibility("data_connection", visible);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800759 mDataIconVisible = visible;
760 }
761 }
762
763 private final void updateVolume() {
764 AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
765 final int ringerMode = audioManager.getRingerMode();
766 final boolean visible = ringerMode == AudioManager.RINGER_MODE_SILENT ||
Wink Savillee9b06d72009-05-18 21:47:50 -0700767 ringerMode == AudioManager.RINGER_MODE_VIBRATE;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800768 final int iconId = audioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER)
Joe Onorato798ac4c2010-05-27 16:39:00 -0400769 ? R.drawable.stat_sys_ringer_vibrate
770 : R.drawable.stat_sys_ringer_silent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800771
772 if (visible) {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400773 mService.setIcon("volume", iconId, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800774 }
775 if (visible != mVolumeVisible) {
Joe Onorato0cbda992010-05-02 16:28:15 -0700776 mService.setIconVisibility("volume", visible);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800777 mVolumeVisible = visible;
778 }
779 }
780
781 private final void updateBluetooth(Intent intent) {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400782 int iconId = R.drawable.stat_sys_data_bluetooth;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800783 String action = intent.getAction();
Nick Pellyde893f52009-09-08 13:15:33 -0700784 if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
Nick Pellyb24e11b2009-09-08 17:40:43 -0700785 int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
Nick Pellyde893f52009-09-08 13:15:33 -0700786 mBluetoothEnabled = state == BluetoothAdapter.STATE_ON;
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -0700787 } else if (action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) {
Jaikumar Ganesh0b63a6a2011-07-11 14:34:34 -0700788 int state = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE,
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -0700789 BluetoothAdapter.STATE_DISCONNECTED);
790 if (state == BluetoothAdapter.STATE_CONNECTED) {
791 iconId = R.drawable.stat_sys_data_bluetooth_connected;
Jaikumar Ganesh084c6652009-12-07 10:58:18 -0800792 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800793 } else {
794 return;
795 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700796
Joe Onorato798ac4c2010-05-27 16:39:00 -0400797 mService.setIcon("bluetooth", iconId, 0);
Joe Onorato0cbda992010-05-02 16:28:15 -0700798 mService.setIconVisibility("bluetooth", mBluetoothEnabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800799 }
800
801 private final void updateWifi(Intent intent) {
802 final String action = intent.getAction();
803 if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800805 final boolean enabled = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
806 WifiManager.WIFI_STATE_UNKNOWN) == WifiManager.WIFI_STATE_ENABLED;
Wink Savillee9b06d72009-05-18 21:47:50 -0700807
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800808 if (!enabled) {
809 // If disabled, hide the icon. (We show icon when connected.)
Joe Onorato0cbda992010-05-02 16:28:15 -0700810 mService.setIconVisibility("wifi", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800811 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800813 } else if (action.equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)) {
814 final boolean enabled = intent.getBooleanExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED,
815 false);
816 if (!enabled) {
Joe Onorato0cbda992010-05-02 16:28:15 -0700817 mService.setIconVisibility("wifi", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800818 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800819 } else if (action.equals(WifiManager.RSSI_CHANGED_ACTION)) {
Joe Onorato0cbda992010-05-02 16:28:15 -0700820 int iconId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800821 final int newRssi = intent.getIntExtra(WifiManager.EXTRA_NEW_RSSI, -200);
822 int newSignalLevel = WifiManager.calculateSignalLevel(newRssi,
Robert Greenwaltfa974c52010-09-13 15:53:26 -0700823 sWifiSignalImages[0].length);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800824 if (newSignalLevel != mLastWifiSignalLevel) {
825 mLastWifiSignalLevel = newSignalLevel;
826 if (mIsWifiConnected) {
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700827 iconId = sWifiSignalImages[mInetCondition][newSignalLevel];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800828 } else {
Joe Onorato0cbda992010-05-02 16:28:15 -0700829 iconId = sWifiTemporarilyNotConnectedImage;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800830 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400831 mService.setIcon("wifi", iconId, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800832 }
833 }
834 }
835
836 private final void updateGps(Intent intent) {
837 final String action = intent.getAction();
Mike Lockwood00b74272010-03-26 10:41:48 -0400838 final boolean enabled = intent.getBooleanExtra(LocationManager.EXTRA_GPS_ENABLED, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800839
Mike Lockwood00b74272010-03-26 10:41:48 -0400840 if (action.equals(LocationManager.GPS_FIX_CHANGE_ACTION) && enabled) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800841 // GPS is getting fixes
Joe Onorato798ac4c2010-05-27 16:39:00 -0400842 mService.setIcon("gps", com.android.internal.R.drawable.stat_sys_gps_on, 0);
Joe Onorato0cbda992010-05-02 16:28:15 -0700843 mService.setIconVisibility("gps", true);
Mike Lockwood00b74272010-03-26 10:41:48 -0400844 } else if (action.equals(LocationManager.GPS_ENABLED_CHANGE_ACTION) && !enabled) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800845 // GPS is off
Joe Onorato0cbda992010-05-02 16:28:15 -0700846 mService.setIconVisibility("gps", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800847 } else {
848 // GPS is on, but not receiving fixes
Joe Onorato798ac4c2010-05-27 16:39:00 -0400849 mService.setIcon("gps", R.drawable.stat_sys_gps_acquiring_anim, 0);
Joe Onorato0cbda992010-05-02 16:28:15 -0700850 mService.setIconVisibility("gps", true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800851 }
852 }
853
Wink Savillee9b06d72009-05-18 21:47:50 -0700854 private final void updateTTY(Intent intent) {
Wink Saville04e71b32009-04-02 11:00:54 -0700855 final String action = intent.getAction();
856 final boolean enabled = intent.getBooleanExtra(TtyIntent.TTY_ENABLED, false);
857
Joe Onorato8a9b2202010-02-26 18:56:32 -0800858 if (false) Slog.v(TAG, "updateTTY: enabled: " + enabled);
Wink Saville04e71b32009-04-02 11:00:54 -0700859
860 if (enabled) {
861 // TTY is on
Joe Onorato8a9b2202010-02-26 18:56:32 -0800862 if (false) Slog.v(TAG, "updateTTY: set TTY on");
Joe Onorato798ac4c2010-05-27 16:39:00 -0400863 mService.setIcon("tty", R.drawable.stat_sys_tty_mode, 0);
Joe Onorato0cbda992010-05-02 16:28:15 -0700864 mService.setIconVisibility("tty", true);
Wink Saville04e71b32009-04-02 11:00:54 -0700865 } else {
866 // TTY is off
Joe Onorato8a9b2202010-02-26 18:56:32 -0800867 if (false) Slog.v(TAG, "updateTTY: set TTY off");
Joe Onorato0cbda992010-05-02 16:28:15 -0700868 mService.setIconVisibility("tty", false);
Wink Saville04e71b32009-04-02 11:00:54 -0700869 }
870 }
871
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700872 private final void updateCdmaRoamingIcon(ServiceState state) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700873 if (!hasService()) {
Joe Onorato0cbda992010-05-02 16:28:15 -0700874 mService.setIconVisibility("cdma_eri", false);
Wink Savillef3152382009-06-01 14:39:20 -0700875 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700876 }
877
878 if (!isCdma()) {
Joe Onorato0cbda992010-05-02 16:28:15 -0700879 mService.setIconVisibility("cdma_eri", false);
Wink Savillef3152382009-06-01 14:39:20 -0700880 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700881 }
882
883 int[] iconList = sRoamingIndicatorImages_cdma;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700884 int iconIndex = state.getCdmaEriIconIndex();
885 int iconMode = state.getCdmaEriIconMode();
Wink Savillee9b06d72009-05-18 21:47:50 -0700886
887 if (iconIndex == -1) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800888 Slog.e(TAG, "getCdmaEriIconIndex returned null, skipping ERI icon update");
Wink Savillee9b06d72009-05-18 21:47:50 -0700889 return;
890 }
891
892 if (iconMode == -1) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800893 Slog.e(TAG, "getCdmeEriIconMode returned null, skipping ERI icon update");
Wink Savillee9b06d72009-05-18 21:47:50 -0700894 return;
895 }
896
897 if (iconIndex == EriInfo.ROAMING_INDICATOR_OFF) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800898 if (false) Slog.v(TAG, "Cdma ROAMING_INDICATOR_OFF, removing ERI icon");
Joe Onorato0cbda992010-05-02 16:28:15 -0700899 mService.setIconVisibility("cdma_eri", false);
Wink Savillee9b06d72009-05-18 21:47:50 -0700900 return;
901 }
902
903 switch (iconMode) {
904 case EriInfo.ROAMING_ICON_MODE_NORMAL:
Joe Onorato798ac4c2010-05-27 16:39:00 -0400905 mService.setIcon("cdma_eri", iconList[iconIndex], 0);
Joe Onorato0cbda992010-05-02 16:28:15 -0700906 mService.setIconVisibility("cdma_eri", true);
Wink Savillee9b06d72009-05-18 21:47:50 -0700907 break;
908 case EriInfo.ROAMING_ICON_MODE_FLASH:
Joe Onorato798ac4c2010-05-27 16:39:00 -0400909 mService.setIcon("cdma_eri", R.drawable.stat_sys_roaming_cdma_flash, 0);
Joe Onorato0cbda992010-05-02 16:28:15 -0700910 mService.setIconVisibility("cdma_eri", true);
Wink Savillee9b06d72009-05-18 21:47:50 -0700911 break;
912
913 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400914 mService.setIcon("phone_signal", mPhoneSignalIconId, 0);
Wink Savillee9b06d72009-05-18 21:47:50 -0700915 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800916}