blob: a03a0ba9875900ea098559b04550c4a9ae4d7254 [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;
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 */
74public class StatusBarPolicy {
75 private static final String TAG = "StatusBarPolicy";
76
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 };
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700249 private static final int[][] sDataNetType_e = {
250 { R.drawable.stat_sys_data_connected_e,
251 R.drawable.stat_sys_data_in_e,
252 R.drawable.stat_sys_data_out_e,
253 R.drawable.stat_sys_data_inandout_e },
Robert Greenwalt26faee32010-09-10 09:36:43 -0700254 { R.drawable.stat_sys_data_fully_connected_e,
255 R.drawable.stat_sys_data_fully_in_e,
256 R.drawable.stat_sys_data_fully_out_e,
257 R.drawable.stat_sys_data_fully_inandout_e }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800258 };
Li Zheebe66342009-08-14 19:22:16 +0800259 //3.5G
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700260 private static final int[][] sDataNetType_h = {
261 { R.drawable.stat_sys_data_connected_h,
262 R.drawable.stat_sys_data_in_h,
263 R.drawable.stat_sys_data_out_h,
264 R.drawable.stat_sys_data_inandout_h },
Robert Greenwalt26faee32010-09-10 09:36:43 -0700265 { R.drawable.stat_sys_data_fully_connected_h,
266 R.drawable.stat_sys_data_fully_in_h,
267 R.drawable.stat_sys_data_fully_out_h,
268 R.drawable.stat_sys_data_fully_inandout_h }
Li Zheebe66342009-08-14 19:22:16 +0800269 };
270
Wink Saville04e71b32009-04-02 11:00:54 -0700271 //CDMA
johnwang9f87cb22009-08-25 15:25:37 -0700272 // Use 3G icons for EVDO data and 1x icons for 1XRTT data
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700273 private static final int[][] sDataNetType_1x = {
274 { R.drawable.stat_sys_data_connected_1x,
275 R.drawable.stat_sys_data_in_1x,
276 R.drawable.stat_sys_data_out_1x,
277 R.drawable.stat_sys_data_inandout_1x },
Robert Greenwalt26faee32010-09-10 09:36:43 -0700278 { R.drawable.stat_sys_data_fully_connected_1x,
279 R.drawable.stat_sys_data_fully_in_1x,
280 R.drawable.stat_sys_data_fully_out_1x,
281 R.drawable.stat_sys_data_fully_inandout_1x }
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700282 };
Wink Saville04e71b32009-04-02 11:00:54 -0700283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800284 // Assume it's all good unless we hear otherwise. We don't always seem
285 // to get broadcasts that it *is* there.
Wink Saville04e71b32009-04-02 11:00:54 -0700286 IccCard.State mSimState = IccCard.State.READY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800287 int mPhoneState = TelephonyManager.CALL_STATE_IDLE;
288 int mDataState = TelephonyManager.DATA_DISCONNECTED;
289 int mDataActivity = TelephonyManager.DATA_ACTIVITY_NONE;
290 ServiceState mServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -0700291 SignalStrength mSignalStrength;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800292
293 // data connection
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800294 private boolean mDataIconVisible;
John Wang33e21fc2009-10-08 10:35:27 -0700295 private boolean mHspaDataDistinguishable;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800296
297 // ringer volume
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800298 private boolean mVolumeVisible;
Wink Saville04e71b32009-04-02 11:00:54 -0700299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800300 // bluetooth device status
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800301 private boolean mBluetoothEnabled;
302
303 // wifi
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700304 private static final int[][] sWifiSignalImages = {
305 { R.drawable.stat_sys_wifi_signal_1,
306 R.drawable.stat_sys_wifi_signal_2,
307 R.drawable.stat_sys_wifi_signal_3,
308 R.drawable.stat_sys_wifi_signal_4 },
Robert Greenwalt26faee32010-09-10 09:36:43 -0700309 { R.drawable.stat_sys_wifi_signal_1_fully,
310 R.drawable.stat_sys_wifi_signal_2_fully,
311 R.drawable.stat_sys_wifi_signal_3_fully,
312 R.drawable.stat_sys_wifi_signal_4_fully }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800313 };
314 private static final int sWifiTemporarilyNotConnectedImage =
Joe Onorato798ac4c2010-05-27 16:39:00 -0400315 R.drawable.stat_sys_wifi_signal_0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316
317 private int mLastWifiSignalLevel = -1;
318 private boolean mIsWifiConnected = false;
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700319
320 // state of inet connection - 0 not connected, 100 connected
321 private int mInetCondition = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800322
323 // sync state
324 // If sync is active the SyncActive icon is displayed. If sync is not active but
325 // sync is failing the SyncFailing icon is displayed. Otherwise neither are displayed.
Wink Savillee9b06d72009-05-18 21:47:50 -0700326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800327 private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
328 @Override
329 public void onReceive(Context context, Intent intent) {
330 String action = intent.getAction();
Joe Onorato263700d2010-05-14 11:54:53 -0700331 if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {
Dianne Hackborn8ec5b832009-07-01 21:19:35 -0700332 updateBattery(intent);
333 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800334 else if (action.equals(Intent.ACTION_ALARM_CHANGED)) {
335 updateAlarm(intent);
336 }
337 else if (action.equals(Intent.ACTION_SYNC_STATE_CHANGED)) {
338 updateSyncState(intent);
339 }
Nick Pellyde893f52009-09-08 13:15:33 -0700340 else if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED) ||
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -0700341 action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342 updateBluetooth(intent);
343 }
344 else if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION) ||
345 action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION) ||
346 action.equals(WifiManager.RSSI_CHANGED_ACTION)) {
347 updateWifi(intent);
348 }
Mike Lockwood00b74272010-03-26 10:41:48 -0400349 else if (action.equals(LocationManager.GPS_ENABLED_CHANGE_ACTION) ||
350 action.equals(LocationManager.GPS_FIX_CHANGE_ACTION)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800351 updateGps(intent);
352 }
353 else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION) ||
354 action.equals(AudioManager.VIBRATE_SETTING_CHANGED_ACTION)) {
355 updateVolume();
356 }
357 else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
358 updateSimState(intent);
359 }
Wink Saville04e71b32009-04-02 11:00:54 -0700360 else if (action.equals(TtyIntent.TTY_ENABLED_CHANGE_ACTION)) {
361 updateTTY(intent);
362 }
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700363 else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION) ||
364 action.equals(ConnectivityManager.INET_CONDITION_ACTION)) {
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700365 // TODO - stop using other means to get wifi/mobile info
366 updateConnectivity(intent);
367 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800368 }
369 };
370
Joe Onorato798ac4c2010-05-27 16:39:00 -0400371 public StatusBarPolicy(Context context) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800372 mContext = context;
Joe Onorato798ac4c2010-05-27 16:39:00 -0400373 mService = (StatusBarManager)context.getSystemService(Context.STATUS_BAR_SERVICE);
Wink Savillee9b06d72009-05-18 21:47:50 -0700374 mSignalStrength = new SignalStrength();
Dianne Hackborn4840e142009-03-24 22:40:29 -0700375 mBatteryStats = BatteryStatsService.getService();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376
San Mehat4154c072010-02-09 18:37:54 -0800377 // storage
378 mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
379 mStorageManager.registerListener(
Joe Onoratofe4f3ae2010-06-04 11:25:26 -0700380 new com.android.systemui.usb.StorageNotification(context));
San Mehat4154c072010-02-09 18:37:54 -0800381
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382 // battery
Joe Onorato798ac4c2010-05-27 16:39:00 -0400383 mService.setIcon("battery", com.android.internal.R.drawable.stat_sys_battery_unknown, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384
385 // phone_signal
386 mPhone = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
Joe Onorato798ac4c2010-05-27 16:39:00 -0400387 mPhoneSignalIconId = R.drawable.stat_sys_signal_null;
388 mService.setIcon("phone_signal", mPhoneSignalIconId, 0);
Wink Savillee9b06d72009-05-18 21:47:50 -0700389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800390 // register for phone state notifications.
391 ((TelephonyManager)mContext.getSystemService(Context.TELEPHONY_SERVICE))
392 .listen(mPhoneStateListener,
393 PhoneStateListener.LISTEN_SERVICE_STATE
Wink Savillee9b06d72009-05-18 21:47:50 -0700394 | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 | PhoneStateListener.LISTEN_CALL_STATE
396 | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
397 | PhoneStateListener.LISTEN_DATA_ACTIVITY);
398
399 // data_connection
Joe Onorato798ac4c2010-05-27 16:39:00 -0400400 mService.setIcon("data_connection", R.drawable.stat_sys_data_connected_g, 0);
401 mService.setIconVisibility("data_connection", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800402
403 // wifi
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700404 mService.setIcon("wifi", sWifiSignalImages[0][0], 0);
Joe Onorato798ac4c2010-05-27 16:39:00 -0400405 mService.setIconVisibility("wifi", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800406 // wifi will get updated by the sticky intents
Wink Saville04e71b32009-04-02 11:00:54 -0700407
408 // TTY status
Joe Onorato798ac4c2010-05-27 16:39:00 -0400409 mService.setIcon("tty", R.drawable.stat_sys_tty_mode, 0);
410 mService.setIconVisibility("tty", false);
Wink Saville04e71b32009-04-02 11:00:54 -0700411
Wink Savillee9b06d72009-05-18 21:47:50 -0700412 // Cdma Roaming Indicator, ERI
Joe Onorato798ac4c2010-05-27 16:39:00 -0400413 mService.setIcon("cdma_eri", R.drawable.stat_sys_roaming_cdma_0, 0);
414 mService.setIconVisibility("cdma_eri", false);
Wink Savillee9b06d72009-05-18 21:47:50 -0700415
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800416 // bluetooth status
Joe Onorato798ac4c2010-05-27 16:39:00 -0400417 mService.setIcon("bluetooth", R.drawable.stat_sys_data_bluetooth, 0);
Nick Pellyf242b7b2009-10-08 00:12:45 +0200418 BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
Nick Pellybd022f42009-08-14 18:33:38 -0700419 if (adapter != null) {
420 mBluetoothEnabled = adapter.isEnabled();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800421 } else {
422 mBluetoothEnabled = false;
423 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700424 mService.setIconVisibility("bluetooth", mBluetoothEnabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800425
426 // Gps status
Joe Onorato798ac4c2010-05-27 16:39:00 -0400427 mService.setIcon("gps", R.drawable.stat_sys_gps_acquiring_anim, 0);
428 mService.setIconVisibility("gps", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429
430 // Alarm clock
Joe Onorato798ac4c2010-05-27 16:39:00 -0400431 mService.setIcon("alarm_clock", R.drawable.stat_notify_alarm, 0);
432 mService.setIconVisibility("alarm_clock", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800433
434 // Sync state
Joe Onorato798ac4c2010-05-27 16:39:00 -0400435 mService.setIcon("sync_active", com.android.internal.R.drawable.stat_notify_sync_anim0, 0);
436 mService.setIcon("sync_failing", com.android.internal.R.drawable.stat_notify_sync_error, 0);
437 mService.setIconVisibility("sync_active", false);
438 mService.setIconVisibility("sync_failing", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800439
440 // volume
Joe Onorato798ac4c2010-05-27 16:39:00 -0400441 mService.setIcon("volume", R.drawable.stat_sys_ringer_silent, 0);
442 mService.setIconVisibility("volume", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 updateVolume();
johnwang347c5a22009-08-24 22:11:11 -0700444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800445 IntentFilter filter = new IntentFilter();
446
447 // Register for Intent broadcasts for...
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800448 filter.addAction(Intent.ACTION_BATTERY_CHANGED);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800449 filter.addAction(Intent.ACTION_ALARM_CHANGED);
450 filter.addAction(Intent.ACTION_SYNC_STATE_CHANGED);
451 filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
452 filter.addAction(AudioManager.VIBRATE_SETTING_CHANGED_ACTION);
Nick Pellyde893f52009-09-08 13:15:33 -0700453 filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -0700454 filter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800455 filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
456 filter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
457 filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
458 filter.addAction(WifiManager.RSSI_CHANGED_ACTION);
Mike Lockwood00b74272010-03-26 10:41:48 -0400459 filter.addAction(LocationManager.GPS_ENABLED_CHANGE_ACTION);
460 filter.addAction(LocationManager.GPS_FIX_CHANGE_ACTION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800461 filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
Wink Saville04e71b32009-04-02 11:00:54 -0700462 filter.addAction(TtyIntent.TTY_ENABLED_CHANGE_ACTION);
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700463 filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700464 filter.addAction(ConnectivityManager.INET_CONDITION_ACTION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800465 mContext.registerReceiver(mIntentReceiver, filter, null, mHandler);
John Wang33e21fc2009-10-08 10:35:27 -0700466
467 // load config to determine if to distinguish Hspa data icon
468 try {
469 mHspaDataDistinguishable = mContext.getResources().getBoolean(
Joe Onorato798ac4c2010-05-27 16:39:00 -0400470 R.bool.config_hspa_data_distinguishable);
John Wang33e21fc2009-10-08 10:35:27 -0700471 } catch (Exception e) {
472 mHspaDataDistinguishable = false;
473 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800474 }
475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800476 private final void updateAlarm(Intent intent) {
477 boolean alarmSet = intent.getBooleanExtra("alarmSet", false);
Joe Onorato0cbda992010-05-02 16:28:15 -0700478 mService.setIconVisibility("alarm_clock", alarmSet);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800479 }
480
481 private final void updateSyncState(Intent intent) {
482 boolean isActive = intent.getBooleanExtra("active", false);
483 boolean isFailing = intent.getBooleanExtra("failing", false);
Joe Onorato0cbda992010-05-02 16:28:15 -0700484 mService.setIconVisibility("sync_active", isActive);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800485 // Don't display sync failing icon: BUG 1297963 Set sync error timeout to "never"
Joe Onorato0cbda992010-05-02 16:28:15 -0700486 //mService.setIconVisibility("sync_failing", isFailing && !isActive);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800487 }
488
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800489 private final void updateBattery(Intent intent) {
Joe Onorato0cbda992010-05-02 16:28:15 -0700490 final int id = intent.getIntExtra("icon-small", 0);
491 int level = intent.getIntExtra("level", 0);
Joe Onorato798ac4c2010-05-27 16:39:00 -0400492 mService.setIcon("battery", id, level);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800493 }
494
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700495 private void updateConnectivity(Intent intent) {
496 NetworkInfo info = (NetworkInfo)(intent.getParcelableExtra(
497 ConnectivityManager.EXTRA_NETWORK_INFO));
498 int connectionStatus = intent.getIntExtra(ConnectivityManager.EXTRA_INET_CONDITION, 0);
Robert Greenwalt029be812010-09-20 18:01:43 -0700499
500 int inetCondition = (connectionStatus > INET_CONDITION_THRESHOLD ? 1 : 0);
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700501
502 switch (info.getType()) {
503 case ConnectivityManager.TYPE_MOBILE:
Robert Greenwalt029be812010-09-20 18:01:43 -0700504 mInetCondition = inetCondition;
505 updateDataNetType(info.getSubtype());
506 updateDataIcon();
507 updateSignalStrength(); // apply any change in connectionStatus
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700508 break;
509 case ConnectivityManager.TYPE_WIFI:
Robert Greenwalt029be812010-09-20 18:01:43 -0700510 mInetCondition = inetCondition;
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700511 if (info.isConnected()) {
512 mIsWifiConnected = true;
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700513 int iconId;
514 if (mLastWifiSignalLevel == -1) {
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700515 iconId = sWifiSignalImages[mInetCondition][0];
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700516 } else {
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700517 iconId = sWifiSignalImages[mInetCondition][mLastWifiSignalLevel];
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700518 }
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700519 mService.setIcon("wifi", iconId, 0);
520 // Show the icon since wi-fi is connected
521 mService.setIconVisibility("wifi", true);
522 } else {
523 mLastWifiSignalLevel = -1;
524 mIsWifiConnected = false;
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700525 int iconId = sWifiSignalImages[0][0];
526
527 mService.setIcon("wifi", iconId, 0);
528 // Hide the icon since we're not connected
529 mService.setIconVisibility("wifi", false);
530 }
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700531 updateSignalStrength(); // apply any change in mInetCondition
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700532 break;
533 }
534 }
535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 private PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
537 @Override
Wink Savillee9b06d72009-05-18 21:47:50 -0700538 public void onSignalStrengthsChanged(SignalStrength signalStrength) {
539 mSignalStrength = signalStrength;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800540 updateSignalStrength();
541 }
542
543 @Override
544 public void onServiceStateChanged(ServiceState state) {
545 mServiceState = state;
546 updateSignalStrength();
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700547 updateCdmaRoamingIcon(state);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800548 updateDataIcon();
549 }
550
551 @Override
552 public void onCallStateChanged(int state, String incomingNumber) {
johnwang347c5a22009-08-24 22:11:11 -0700553 // In cdma, if a voice call is made, RSSI should switch to 1x.
554 if (isCdma()) {
555 updateSignalStrength();
556 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800557 }
558
559 @Override
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700560 public void onDataConnectionStateChanged(int state, int networkType) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800561 mDataState = state;
Robert Greenwalt029be812010-09-20 18:01:43 -0700562 updateDataNetType(networkType);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 updateDataIcon();
564 }
565
566 @Override
567 public void onDataActivity(int direction) {
568 mDataActivity = direction;
569 updateDataIcon();
570 }
571 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800572
573 private final void updateSimState(Intent intent) {
Wink Saville04e71b32009-04-02 11:00:54 -0700574 String stateExtra = intent.getStringExtra(IccCard.INTENT_KEY_ICC_STATE);
575 if (IccCard.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) {
576 mSimState = IccCard.State.ABSENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800577 }
Wink Saville04e71b32009-04-02 11:00:54 -0700578 else if (IccCard.INTENT_VALUE_ICC_READY.equals(stateExtra)) {
579 mSimState = IccCard.State.READY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800580 }
Wink Saville04e71b32009-04-02 11:00:54 -0700581 else if (IccCard.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) {
582 final String lockedReason = intent.getStringExtra(IccCard.INTENT_KEY_LOCKED_REASON);
583 if (IccCard.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) {
584 mSimState = IccCard.State.PIN_REQUIRED;
johnwang347c5a22009-08-24 22:11:11 -0700585 }
Wink Saville04e71b32009-04-02 11:00:54 -0700586 else if (IccCard.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) {
587 mSimState = IccCard.State.PUK_REQUIRED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800588 }
589 else {
Wink Saville04e71b32009-04-02 11:00:54 -0700590 mSimState = IccCard.State.NETWORK_LOCKED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800591 }
592 } else {
Wink Saville04e71b32009-04-02 11:00:54 -0700593 mSimState = IccCard.State.UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 }
595 updateDataIcon();
596 }
597
Wink Savillee9b06d72009-05-18 21:47:50 -0700598 private boolean isCdma() {
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700599 return (mSignalStrength != null) && !mSignalStrength.isGsm();
Wink Savillee9b06d72009-05-18 21:47:50 -0700600 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800601
johnwang347c5a22009-08-24 22:11:11 -0700602 private boolean isEvdo() {
603 return ( (mServiceState != null)
604 && ((mServiceState.getRadioTechnology()
605 == ServiceState.RADIO_TECHNOLOGY_EVDO_0)
606 || (mServiceState.getRadioTechnology()
Naveen Kalla0a5174a2010-04-21 14:48:03 -0700607 == ServiceState.RADIO_TECHNOLOGY_EVDO_A)
608 || (mServiceState.getRadioTechnology()
609 == ServiceState.RADIO_TECHNOLOGY_EVDO_B)));
johnwang347c5a22009-08-24 22:11:11 -0700610 }
611
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() {
627 int iconLevel = -1;
Wink Savillee9b06d72009-05-18 21:47:50 -0700628 int[] iconList;
Wink Savillee9b06d72009-05-18 21:47:50 -0700629
John Wang56c2d2f2010-04-07 08:57:17 -0700630 // Display signal strength while in "emergency calls only" mode
Joe Onorato49a8bbf2010-09-23 09:50:04 -0700631 if (mServiceState == null || (!hasService() && !mServiceState.isEmergencyOnly())) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800632 //Slog.d(TAG, "updateSignalStrength: no service");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800633 if (Settings.System.getInt(mContext.getContentResolver(),
634 Settings.System.AIRPLANE_MODE_ON, 0) == 1) {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400635 mPhoneSignalIconId = R.drawable.stat_sys_signal_flightmode;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800636 } else {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400637 mPhoneSignalIconId = R.drawable.stat_sys_signal_null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800638 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400639 mService.setIcon("phone_signal", mPhoneSignalIconId, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800640 return;
641 }
642
Wink Savillee9b06d72009-05-18 21:47:50 -0700643 if (!isCdma()) {
644 int asu = mSignalStrength.getGsmSignalStrength();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645
Wink Savillee9b06d72009-05-18 21:47:50 -0700646 // ASU ranges from 0 to 31 - TS 27.007 Sec 8.5
647 // asu = 0 (-113dB or less) is very weak
648 // signal, its better to show 0 bars to the user in such cases.
649 // asu = 99 is a special case, where the signal strength is unknown.
jshee63e472010-03-18 11:14:42 -0700650 if (asu <= 2 || asu == 99) iconLevel = 0;
651 else if (asu >= 12) iconLevel = 4;
Wink Savillee9b06d72009-05-18 21:47:50 -0700652 else if (asu >= 8) iconLevel = 3;
jshee63e472010-03-18 11:14:42 -0700653 else if (asu >= 5) iconLevel = 2;
Wink Savillee9b06d72009-05-18 21:47:50 -0700654 else iconLevel = 1;
655
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700656 // Though mPhone is a Manager, this call is not an IPC
Wink Savillee9b06d72009-05-18 21:47:50 -0700657 if (mPhone.isNetworkRoaming()) {
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700658 iconList = sSignalImages_r[mInetCondition];
Wink Savillee9b06d72009-05-18 21:47:50 -0700659 } else {
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700660 iconList = sSignalImages[mInetCondition];
Wink Saville04e71b32009-04-02 11:00:54 -0700661 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800662 } else {
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700663 iconList = sSignalImages[mInetCondition];
Wink Savillee9b06d72009-05-18 21:47:50 -0700664
johnwang347c5a22009-08-24 22:11:11 -0700665 // If 3G(EV) and 1x network are available than 3G should be
666 // displayed, displayed RSSI should be from the EV side.
667 // If a voice call is made then RSSI should switch to 1x.
668 if ((mPhoneState == TelephonyManager.CALL_STATE_IDLE) && isEvdo()){
669 iconLevel = getEvdoLevel();
670 if (false) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800671 Slog.d(TAG, "use Evdo level=" + iconLevel + " to replace Cdma Level=" + getCdmaLevel());
johnwang347c5a22009-08-24 22:11:11 -0700672 }
673 } else {
674 iconLevel = getCdmaLevel();
675 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800676 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700677 mPhoneSignalIconId = iconList[iconLevel];
Joe Onorato798ac4c2010-05-27 16:39:00 -0400678 mService.setIcon("phone_signal", mPhoneSignalIconId, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800679 }
680
johnwang347c5a22009-08-24 22:11:11 -0700681 private int getCdmaLevel() {
682 final int cdmaDbm = mSignalStrength.getCdmaDbm();
683 final int cdmaEcio = mSignalStrength.getCdmaEcio();
684 int levelDbm = 0;
685 int levelEcio = 0;
686
687 if (cdmaDbm >= -75) levelDbm = 4;
688 else if (cdmaDbm >= -85) levelDbm = 3;
689 else if (cdmaDbm >= -95) levelDbm = 2;
690 else if (cdmaDbm >= -100) levelDbm = 1;
691 else levelDbm = 0;
692
693 // Ec/Io are in dB*10
694 if (cdmaEcio >= -90) levelEcio = 4;
695 else if (cdmaEcio >= -110) levelEcio = 3;
696 else if (cdmaEcio >= -130) levelEcio = 2;
697 else if (cdmaEcio >= -150) levelEcio = 1;
698 else levelEcio = 0;
699
700 return (levelDbm < levelEcio) ? levelDbm : levelEcio;
701 }
702
703 private int getEvdoLevel() {
704 int evdoDbm = mSignalStrength.getEvdoDbm();
705 int evdoSnr = mSignalStrength.getEvdoSnr();
706 int levelEvdoDbm = 0;
707 int levelEvdoSnr = 0;
708
709 if (evdoDbm >= -65) levelEvdoDbm = 4;
710 else if (evdoDbm >= -75) levelEvdoDbm = 3;
711 else if (evdoDbm >= -90) levelEvdoDbm = 2;
712 else if (evdoDbm >= -105) levelEvdoDbm = 1;
713 else levelEvdoDbm = 0;
714
John Michelau1336a562009-09-28 10:41:02 -0500715 if (evdoSnr >= 7) levelEvdoSnr = 4;
716 else if (evdoSnr >= 5) levelEvdoSnr = 3;
717 else if (evdoSnr >= 3) levelEvdoSnr = 2;
718 else if (evdoSnr >= 1) levelEvdoSnr = 1;
johnwang347c5a22009-08-24 22:11:11 -0700719 else levelEvdoSnr = 0;
720
721 return (levelEvdoDbm < levelEvdoSnr) ? levelEvdoDbm : levelEvdoSnr;
722 }
723
Robert Greenwalt029be812010-09-20 18:01:43 -0700724 private final void updateDataNetType(int net) {
Wink Saville04e71b32009-04-02 11:00:54 -0700725 switch (net) {
Wink Saville04e71b32009-04-02 11:00:54 -0700726 case TelephonyManager.NETWORK_TYPE_EDGE:
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700727 mDataIconList = sDataNetType_e[mInetCondition];
Wink Saville04e71b32009-04-02 11:00:54 -0700728 break;
729 case TelephonyManager.NETWORK_TYPE_UMTS:
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700730 mDataIconList = sDataNetType_3g[mInetCondition];
Wink Saville04e71b32009-04-02 11:00:54 -0700731 break;
Li Zheebe66342009-08-14 19:22:16 +0800732 case TelephonyManager.NETWORK_TYPE_HSDPA:
733 case TelephonyManager.NETWORK_TYPE_HSUPA:
734 case TelephonyManager.NETWORK_TYPE_HSPA:
John Wang33e21fc2009-10-08 10:35:27 -0700735 if (mHspaDataDistinguishable) {
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700736 mDataIconList = sDataNetType_h[mInetCondition];
John Wang33e21fc2009-10-08 10:35:27 -0700737 } else {
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700738 mDataIconList = sDataNetType_3g[mInetCondition];
John Wang33e21fc2009-10-08 10:35:27 -0700739 }
Li Zheebe66342009-08-14 19:22:16 +0800740 break;
Wink Saville04e71b32009-04-02 11:00:54 -0700741 case TelephonyManager.NETWORK_TYPE_CDMA:
742 // display 1xRTT for IS95A/B
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700743 mDataIconList = sDataNetType_1x[mInetCondition];
Wink Saville04e71b32009-04-02 11:00:54 -0700744 break;
745 case TelephonyManager.NETWORK_TYPE_1xRTT:
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700746 mDataIconList = sDataNetType_1x[mInetCondition];
Wink Saville04e71b32009-04-02 11:00:54 -0700747 break;
748 case TelephonyManager.NETWORK_TYPE_EVDO_0: //fall through
749 case TelephonyManager.NETWORK_TYPE_EVDO_A:
Naveen Kalla0a5174a2010-04-21 14:48:03 -0700750 case TelephonyManager.NETWORK_TYPE_EVDO_B:
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700751 mDataIconList = sDataNetType_3g[mInetCondition];
Wink Saville04e71b32009-04-02 11:00:54 -0700752 break;
753 default:
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700754 mDataIconList = sDataNetType_g[mInetCondition];
Wink Saville04e71b32009-04-02 11:00:54 -0700755 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800756 }
757 }
758
759 private final void updateDataIcon() {
760 int iconId;
761 boolean visible = true;
762
Wink Savillee9b06d72009-05-18 21:47:50 -0700763 if (!isCdma()) {
764 // GSM case, we have to check also the sim state
765 if (mSimState == IccCard.State.READY || mSimState == IccCard.State.UNKNOWN) {
766 if (hasService() && mDataState == TelephonyManager.DATA_CONNECTED) {
767 switch (mDataActivity) {
768 case TelephonyManager.DATA_ACTIVITY_IN:
769 iconId = mDataIconList[1];
770 break;
771 case TelephonyManager.DATA_ACTIVITY_OUT:
772 iconId = mDataIconList[2];
773 break;
774 case TelephonyManager.DATA_ACTIVITY_INOUT:
775 iconId = mDataIconList[3];
776 break;
777 default:
778 iconId = mDataIconList[0];
779 break;
780 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400781 mService.setIcon("data_connection", iconId, 0);
Wink Savillee9b06d72009-05-18 21:47:50 -0700782 } else {
783 visible = false;
784 }
785 } else {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400786 iconId = R.drawable.stat_sys_no_sim;
787 mService.setIcon("data_connection", iconId, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800788 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700789 } else {
790 // CDMA case, mDataActivity can be also DATA_ACTIVITY_DORMANT
791 if (hasService() && mDataState == TelephonyManager.DATA_CONNECTED) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800792 switch (mDataActivity) {
793 case TelephonyManager.DATA_ACTIVITY_IN:
Wink Savillee9b06d72009-05-18 21:47:50 -0700794 iconId = mDataIconList[1];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800795 break;
796 case TelephonyManager.DATA_ACTIVITY_OUT:
Wink Savillee9b06d72009-05-18 21:47:50 -0700797 iconId = mDataIconList[2];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800798 break;
799 case TelephonyManager.DATA_ACTIVITY_INOUT:
Wink Savillee9b06d72009-05-18 21:47:50 -0700800 iconId = mDataIconList[3];
801 break;
802 case TelephonyManager.DATA_ACTIVITY_DORMANT:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800803 default:
Wink Savillee9b06d72009-05-18 21:47:50 -0700804 iconId = mDataIconList[0];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800805 break;
806 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400807 mService.setIcon("data_connection", iconId, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800808 } else {
809 visible = false;
810 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800811 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700812
Dianne Hackborn4840e142009-03-24 22:40:29 -0700813 long ident = Binder.clearCallingIdentity();
814 try {
Wink Saville04e71b32009-04-02 11:00:54 -0700815 mBatteryStats.notePhoneDataConnectionState(mPhone.getNetworkType(), visible);
Dianne Hackborn4840e142009-03-24 22:40:29 -0700816 } catch (RemoteException e) {
817 } finally {
818 Binder.restoreCallingIdentity(ident);
819 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700820
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800821 if (mDataIconVisible != visible) {
Joe Onorato0cbda992010-05-02 16:28:15 -0700822 mService.setIconVisibility("data_connection", visible);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800823 mDataIconVisible = visible;
824 }
825 }
826
827 private final void updateVolume() {
828 AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
829 final int ringerMode = audioManager.getRingerMode();
830 final boolean visible = ringerMode == AudioManager.RINGER_MODE_SILENT ||
Wink Savillee9b06d72009-05-18 21:47:50 -0700831 ringerMode == AudioManager.RINGER_MODE_VIBRATE;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800832 final int iconId = audioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER)
Joe Onorato798ac4c2010-05-27 16:39:00 -0400833 ? R.drawable.stat_sys_ringer_vibrate
834 : R.drawable.stat_sys_ringer_silent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800835
836 if (visible) {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400837 mService.setIcon("volume", iconId, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800838 }
839 if (visible != mVolumeVisible) {
Joe Onorato0cbda992010-05-02 16:28:15 -0700840 mService.setIconVisibility("volume", visible);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800841 mVolumeVisible = visible;
842 }
843 }
844
845 private final void updateBluetooth(Intent intent) {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400846 int iconId = R.drawable.stat_sys_data_bluetooth;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800847 String action = intent.getAction();
Nick Pellyde893f52009-09-08 13:15:33 -0700848 if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
Nick Pellyb24e11b2009-09-08 17:40:43 -0700849 int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
Nick Pellyde893f52009-09-08 13:15:33 -0700850 mBluetoothEnabled = state == BluetoothAdapter.STATE_ON;
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -0700851 } else if (action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) {
852 int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
853 BluetoothAdapter.STATE_DISCONNECTED);
854 if (state == BluetoothAdapter.STATE_CONNECTED) {
855 iconId = R.drawable.stat_sys_data_bluetooth_connected;
Jaikumar Ganesh084c6652009-12-07 10:58:18 -0800856 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800857 } else {
858 return;
859 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700860
Joe Onorato798ac4c2010-05-27 16:39:00 -0400861 mService.setIcon("bluetooth", iconId, 0);
Joe Onorato0cbda992010-05-02 16:28:15 -0700862 mService.setIconVisibility("bluetooth", mBluetoothEnabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800863 }
864
865 private final void updateWifi(Intent intent) {
866 final String action = intent.getAction();
867 if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700868
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800869 final boolean enabled = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
870 WifiManager.WIFI_STATE_UNKNOWN) == WifiManager.WIFI_STATE_ENABLED;
Wink Savillee9b06d72009-05-18 21:47:50 -0700871
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800872 if (!enabled) {
873 // If disabled, hide the icon. (We show icon when connected.)
Joe Onorato0cbda992010-05-02 16:28:15 -0700874 mService.setIconVisibility("wifi", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800875 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700876
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800877 } else if (action.equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)) {
878 final boolean enabled = intent.getBooleanExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED,
879 false);
880 if (!enabled) {
Joe Onorato0cbda992010-05-02 16:28:15 -0700881 mService.setIconVisibility("wifi", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800882 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800883 } else if (action.equals(WifiManager.RSSI_CHANGED_ACTION)) {
Joe Onorato0cbda992010-05-02 16:28:15 -0700884 int iconId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800885 final int newRssi = intent.getIntExtra(WifiManager.EXTRA_NEW_RSSI, -200);
886 int newSignalLevel = WifiManager.calculateSignalLevel(newRssi,
Robert Greenwaltfa974c52010-09-13 15:53:26 -0700887 sWifiSignalImages[0].length);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800888 if (newSignalLevel != mLastWifiSignalLevel) {
889 mLastWifiSignalLevel = newSignalLevel;
890 if (mIsWifiConnected) {
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700891 iconId = sWifiSignalImages[mInetCondition][newSignalLevel];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800892 } else {
Joe Onorato0cbda992010-05-02 16:28:15 -0700893 iconId = sWifiTemporarilyNotConnectedImage;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800894 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400895 mService.setIcon("wifi", iconId, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800896 }
897 }
898 }
899
900 private final void updateGps(Intent intent) {
901 final String action = intent.getAction();
Mike Lockwood00b74272010-03-26 10:41:48 -0400902 final boolean enabled = intent.getBooleanExtra(LocationManager.EXTRA_GPS_ENABLED, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800903
Mike Lockwood00b74272010-03-26 10:41:48 -0400904 if (action.equals(LocationManager.GPS_FIX_CHANGE_ACTION) && enabled) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800905 // GPS is getting fixes
Joe Onorato798ac4c2010-05-27 16:39:00 -0400906 mService.setIcon("gps", com.android.internal.R.drawable.stat_sys_gps_on, 0);
Joe Onorato0cbda992010-05-02 16:28:15 -0700907 mService.setIconVisibility("gps", true);
Mike Lockwood00b74272010-03-26 10:41:48 -0400908 } else if (action.equals(LocationManager.GPS_ENABLED_CHANGE_ACTION) && !enabled) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800909 // GPS is off
Joe Onorato0cbda992010-05-02 16:28:15 -0700910 mService.setIconVisibility("gps", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800911 } else {
912 // GPS is on, but not receiving fixes
Joe Onorato798ac4c2010-05-27 16:39:00 -0400913 mService.setIcon("gps", R.drawable.stat_sys_gps_acquiring_anim, 0);
Joe Onorato0cbda992010-05-02 16:28:15 -0700914 mService.setIconVisibility("gps", true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800915 }
916 }
917
Wink Savillee9b06d72009-05-18 21:47:50 -0700918 private final void updateTTY(Intent intent) {
Wink Saville04e71b32009-04-02 11:00:54 -0700919 final String action = intent.getAction();
920 final boolean enabled = intent.getBooleanExtra(TtyIntent.TTY_ENABLED, false);
921
Joe Onorato8a9b2202010-02-26 18:56:32 -0800922 if (false) Slog.v(TAG, "updateTTY: enabled: " + enabled);
Wink Saville04e71b32009-04-02 11:00:54 -0700923
924 if (enabled) {
925 // TTY is on
Joe Onorato8a9b2202010-02-26 18:56:32 -0800926 if (false) Slog.v(TAG, "updateTTY: set TTY on");
Joe Onorato798ac4c2010-05-27 16:39:00 -0400927 mService.setIcon("tty", R.drawable.stat_sys_tty_mode, 0);
Joe Onorato0cbda992010-05-02 16:28:15 -0700928 mService.setIconVisibility("tty", true);
Wink Saville04e71b32009-04-02 11:00:54 -0700929 } else {
930 // TTY is off
Joe Onorato8a9b2202010-02-26 18:56:32 -0800931 if (false) Slog.v(TAG, "updateTTY: set TTY off");
Joe Onorato0cbda992010-05-02 16:28:15 -0700932 mService.setIconVisibility("tty", false);
Wink Saville04e71b32009-04-02 11:00:54 -0700933 }
934 }
935
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700936 private final void updateCdmaRoamingIcon(ServiceState state) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700937 if (!hasService()) {
Joe Onorato0cbda992010-05-02 16:28:15 -0700938 mService.setIconVisibility("cdma_eri", false);
Wink Savillef3152382009-06-01 14:39:20 -0700939 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700940 }
941
942 if (!isCdma()) {
Joe Onorato0cbda992010-05-02 16:28:15 -0700943 mService.setIconVisibility("cdma_eri", false);
Wink Savillef3152382009-06-01 14:39:20 -0700944 return;
Wink Savillee9b06d72009-05-18 21:47:50 -0700945 }
946
947 int[] iconList = sRoamingIndicatorImages_cdma;
Robert Greenwalt98e0b142009-10-08 21:15:52 -0700948 int iconIndex = state.getCdmaEriIconIndex();
949 int iconMode = state.getCdmaEriIconMode();
Wink Savillee9b06d72009-05-18 21:47:50 -0700950
951 if (iconIndex == -1) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800952 Slog.e(TAG, "getCdmaEriIconIndex returned null, skipping ERI icon update");
Wink Savillee9b06d72009-05-18 21:47:50 -0700953 return;
954 }
955
956 if (iconMode == -1) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800957 Slog.e(TAG, "getCdmeEriIconMode returned null, skipping ERI icon update");
Wink Savillee9b06d72009-05-18 21:47:50 -0700958 return;
959 }
960
961 if (iconIndex == EriInfo.ROAMING_INDICATOR_OFF) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800962 if (false) Slog.v(TAG, "Cdma ROAMING_INDICATOR_OFF, removing ERI icon");
Joe Onorato0cbda992010-05-02 16:28:15 -0700963 mService.setIconVisibility("cdma_eri", false);
Wink Savillee9b06d72009-05-18 21:47:50 -0700964 return;
965 }
966
967 switch (iconMode) {
968 case EriInfo.ROAMING_ICON_MODE_NORMAL:
Joe Onorato798ac4c2010-05-27 16:39:00 -0400969 mService.setIcon("cdma_eri", iconList[iconIndex], 0);
Joe Onorato0cbda992010-05-02 16:28:15 -0700970 mService.setIconVisibility("cdma_eri", true);
Wink Savillee9b06d72009-05-18 21:47:50 -0700971 break;
972 case EriInfo.ROAMING_ICON_MODE_FLASH:
Joe Onorato798ac4c2010-05-27 16:39:00 -0400973 mService.setIcon("cdma_eri", R.drawable.stat_sys_roaming_cdma_flash, 0);
Joe Onorato0cbda992010-05-02 16:28:15 -0700974 mService.setIconVisibility("cdma_eri", true);
Wink Savillee9b06d72009-05-18 21:47:50 -0700975 break;
976
977 }
Joe Onorato798ac4c2010-05-27 16:39:00 -0400978 mService.setIcon("phone_signal", mPhoneSignalIconId, 0);
Wink Savillee9b06d72009-05-18 21:47:50 -0700979 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800980}