The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.status; |
| 18 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | import android.app.AlertDialog; |
| 20 | import android.bluetooth.BluetoothA2dp; |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 21 | import android.bluetooth.BluetoothAdapter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.bluetooth.BluetoothHeadset; |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 23 | import android.bluetooth.BluetoothPbap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.content.BroadcastReceiver; |
| 25 | import android.content.Context; |
| 26 | import android.content.DialogInterface; |
| 27 | import android.content.Intent; |
| 28 | import android.content.IntentFilter; |
| 29 | import android.content.res.TypedArray; |
| 30 | import android.graphics.PixelFormat; |
| 31 | import android.graphics.drawable.Drawable; |
| 32 | import android.media.AudioManager; |
| 33 | import android.net.NetworkInfo; |
| 34 | import android.net.wifi.WifiManager; |
Dianne Hackborn | 4840e14 | 2009-03-24 22:40:29 -0700 | [diff] [blame] | 35 | import android.os.Binder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.os.Handler; |
| 37 | import android.os.IBinder; |
| 38 | import android.os.Message; |
Dianne Hackborn | 4840e14 | 2009-03-24 22:40:29 -0700 | [diff] [blame] | 39 | import android.os.RemoteException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | import android.provider.Settings; |
| 41 | import android.telephony.PhoneStateListener; |
| 42 | import android.telephony.ServiceState; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 43 | import android.telephony.SignalStrength; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | import android.telephony.TelephonyManager; |
| 45 | import android.text.format.DateFormat; |
| 46 | import android.util.Log; |
| 47 | import android.view.View; |
| 48 | import android.view.ViewGroup; |
| 49 | import android.view.WindowManager; |
| 50 | import android.view.WindowManagerImpl; |
| 51 | import android.widget.ImageView; |
| 52 | import android.widget.LinearLayout; |
| 53 | import android.widget.TextView; |
| 54 | |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 55 | import com.android.internal.R; |
| 56 | import com.android.internal.app.IBatteryStats; |
| 57 | import com.android.internal.location.GpsLocationProvider; |
| 58 | import com.android.internal.telephony.IccCard; |
| 59 | import com.android.internal.telephony.TelephonyIntents; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 60 | import com.android.internal.telephony.cdma.EriInfo; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 61 | import com.android.internal.telephony.cdma.TtyIntent; |
| 62 | import com.android.server.am.BatteryStatsService; |
| 63 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | import java.util.Calendar; |
| 65 | import java.util.TimeZone; |
| 66 | |
| 67 | /** |
| 68 | * This class contains all of the policy about which icons are installed in the status |
| 69 | * bar at boot time. In reality, it should go into the android.policy package, but |
| 70 | * putting it here is the first step from extracting it. |
| 71 | */ |
| 72 | public class StatusBarPolicy { |
| 73 | private static final String TAG = "StatusBarPolicy"; |
| 74 | |
| 75 | private static StatusBarPolicy sInstance; |
| 76 | |
| 77 | // message codes for the handler |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | private static final int EVENT_BATTERY_CLOSE = 4; |
| 79 | |
Dianne Hackborn | 4840e14 | 2009-03-24 22:40:29 -0700 | [diff] [blame] | 80 | private final Context mContext; |
| 81 | private final StatusBarService mService; |
| 82 | private final Handler mHandler = new StatusBarHandler(); |
| 83 | private final IBatteryStats mBatteryStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | |
| 85 | // clock |
| 86 | private Calendar mCalendar; |
| 87 | private IBinder mClockIcon; |
| 88 | private IconData mClockData; |
| 89 | |
| 90 | // battery |
| 91 | private IBinder mBatteryIcon; |
| 92 | private IconData mBatteryData; |
| 93 | private boolean mBatteryFirst = true; |
| 94 | private boolean mBatteryPlugged; |
| 95 | private int mBatteryLevel; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | private AlertDialog mLowBatteryDialog; |
| 97 | private TextView mBatteryLevelTextView; |
| 98 | private View mBatteryView; |
| 99 | private int mBatteryViewSequence; |
| 100 | private boolean mBatteryShowLowOnEndCall = false; |
| 101 | private static final boolean SHOW_LOW_BATTERY_WARNING = true; |
| 102 | |
| 103 | // phone |
| 104 | private TelephonyManager mPhone; |
| 105 | private IBinder mPhoneIcon; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 106 | |
| 107 | //***** Signal strength icons |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | private IconData mPhoneData; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 109 | //GSM/UMTS |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | private static final int[] sSignalImages = new int[] { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 111 | com.android.internal.R.drawable.stat_sys_signal_0, |
| 112 | com.android.internal.R.drawable.stat_sys_signal_1, |
| 113 | com.android.internal.R.drawable.stat_sys_signal_2, |
| 114 | com.android.internal.R.drawable.stat_sys_signal_3, |
| 115 | com.android.internal.R.drawable.stat_sys_signal_4 |
| 116 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | private static final int[] sSignalImages_r = new int[] { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 118 | com.android.internal.R.drawable.stat_sys_r_signal_0, |
| 119 | com.android.internal.R.drawable.stat_sys_r_signal_1, |
| 120 | com.android.internal.R.drawable.stat_sys_r_signal_2, |
| 121 | com.android.internal.R.drawable.stat_sys_r_signal_3, |
| 122 | com.android.internal.R.drawable.stat_sys_r_signal_4 |
| 123 | }; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 124 | private static final int[] sRoamingIndicatorImages_cdma = new int[] { |
| 125 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, //Standard Roaming Indicator |
| 126 | // 1 is Standard Roaming Indicator OFF |
| 127 | // TODO T: image never used, remove and put 0 instead? |
| 128 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 129 | |
| 130 | // 2 is Standard Roaming Indicator FLASHING |
| 131 | // TODO T: image never used, remove and put 0 instead? |
| 132 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 133 | |
| 134 | // 3-12 Standard ERI |
| 135 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, //3 |
| 136 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 137 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 138 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 139 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 140 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 141 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 142 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 143 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 144 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 145 | |
| 146 | // 13-63 Reserved for Standard ERI |
| 147 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, //13 |
| 148 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 149 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 150 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 151 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 152 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 153 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 154 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 155 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 156 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 157 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 158 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 159 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 160 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 161 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 162 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 163 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 164 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 165 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 166 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 167 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 168 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 169 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 170 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 171 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 172 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 173 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 174 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 175 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 176 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 177 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 178 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 179 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 180 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 181 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 182 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 183 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 184 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 185 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 186 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 187 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 188 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 189 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 190 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 191 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 192 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 193 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 194 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 195 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 196 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 197 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 198 | |
| 199 | // 64-127 Reserved for Non Standard (Operator Specific) ERI |
| 200 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, //64 |
| 201 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 202 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 203 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 204 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 205 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 206 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 207 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 208 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 209 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 210 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 211 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 212 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 213 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 214 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 215 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 216 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 217 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 218 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0, |
| 219 | com.android.internal.R.drawable.stat_sys_roaming_cdma_0 //83 |
| 220 | |
| 221 | // 128-255 Reserved |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 222 | }; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 223 | |
| 224 | //***** Data connection icons |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 225 | private int[] mDataIconList = sDataNetType_g; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 226 | //GSM/UMTS |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | private static final int[] sDataNetType_g = new int[] { |
| 228 | com.android.internal.R.drawable.stat_sys_data_connected_g, |
| 229 | com.android.internal.R.drawable.stat_sys_data_in_g, |
| 230 | com.android.internal.R.drawable.stat_sys_data_out_g, |
| 231 | com.android.internal.R.drawable.stat_sys_data_inandout_g, |
| 232 | }; |
| 233 | private static final int[] sDataNetType_3g = new int[] { |
| 234 | com.android.internal.R.drawable.stat_sys_data_connected_3g, |
| 235 | com.android.internal.R.drawable.stat_sys_data_in_3g, |
| 236 | com.android.internal.R.drawable.stat_sys_data_out_3g, |
| 237 | com.android.internal.R.drawable.stat_sys_data_inandout_3g, |
| 238 | }; |
| 239 | private static final int[] sDataNetType_e = new int[] { |
| 240 | com.android.internal.R.drawable.stat_sys_data_connected_e, |
| 241 | com.android.internal.R.drawable.stat_sys_data_in_e, |
| 242 | com.android.internal.R.drawable.stat_sys_data_out_e, |
| 243 | com.android.internal.R.drawable.stat_sys_data_inandout_e, |
| 244 | }; |
Li Zhe | ebe6634 | 2009-08-14 19:22:16 +0800 | [diff] [blame] | 245 | //3.5G |
| 246 | private static final int[] sDataNetType_h = new int[] { |
| 247 | com.android.internal.R.drawable.stat_sys_data_connected_h, |
| 248 | com.android.internal.R.drawable.stat_sys_data_in_h, |
| 249 | com.android.internal.R.drawable.stat_sys_data_out_h, |
| 250 | com.android.internal.R.drawable.stat_sys_data_inandout_h, |
| 251 | }; |
| 252 | |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 253 | //CDMA |
johnwang | 9f87cb2 | 2009-08-25 15:25:37 -0700 | [diff] [blame] | 254 | // Use 3G icons for EVDO data and 1x icons for 1XRTT data |
| 255 | private static final int[] sDataNetType_1x = new int[] { |
| 256 | com.android.internal.R.drawable.stat_sys_data_connected_1x, |
| 257 | com.android.internal.R.drawable.stat_sys_data_in_1x, |
| 258 | com.android.internal.R.drawable.stat_sys_data_out_1x, |
| 259 | com.android.internal.R.drawable.stat_sys_data_inandout_1x, |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 260 | }; |
| 261 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 262 | // Assume it's all good unless we hear otherwise. We don't always seem |
| 263 | // to get broadcasts that it *is* there. |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 264 | IccCard.State mSimState = IccCard.State.READY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 265 | int mPhoneState = TelephonyManager.CALL_STATE_IDLE; |
| 266 | int mDataState = TelephonyManager.DATA_DISCONNECTED; |
| 267 | int mDataActivity = TelephonyManager.DATA_ACTIVITY_NONE; |
| 268 | ServiceState mServiceState; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 269 | SignalStrength mSignalStrength; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 270 | |
| 271 | // data connection |
| 272 | private IBinder mDataIcon; |
| 273 | private IconData mDataData; |
| 274 | private boolean mDataIconVisible; |
| 275 | |
| 276 | // ringer volume |
| 277 | private IBinder mVolumeIcon; |
| 278 | private IconData mVolumeData; |
| 279 | private boolean mVolumeVisible; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 280 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 281 | // bluetooth device status |
| 282 | private IBinder mBluetoothIcon; |
| 283 | private IconData mBluetoothData; |
| 284 | private int mBluetoothHeadsetState; |
| 285 | private int mBluetoothA2dpState; |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 286 | private int mBluetoothPbapState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 287 | private boolean mBluetoothEnabled; |
| 288 | |
| 289 | // wifi |
| 290 | private static final int[] sWifiSignalImages = new int[] { |
| 291 | com.android.internal.R.drawable.stat_sys_wifi_signal_1, |
| 292 | com.android.internal.R.drawable.stat_sys_wifi_signal_2, |
| 293 | com.android.internal.R.drawable.stat_sys_wifi_signal_3, |
| 294 | com.android.internal.R.drawable.stat_sys_wifi_signal_4, |
| 295 | }; |
| 296 | private static final int sWifiTemporarilyNotConnectedImage = |
| 297 | com.android.internal.R.drawable.stat_sys_wifi_signal_0; |
| 298 | |
| 299 | private int mLastWifiSignalLevel = -1; |
| 300 | private boolean mIsWifiConnected = false; |
| 301 | private IBinder mWifiIcon; |
| 302 | private IconData mWifiData; |
| 303 | |
| 304 | // gps |
| 305 | private IBinder mGpsIcon; |
| 306 | private IconData mGpsEnabledIconData; |
| 307 | private IconData mGpsFixIconData; |
| 308 | |
| 309 | // alarm clock |
| 310 | // Icon lit when clock is set |
| 311 | private IBinder mAlarmClockIcon; |
| 312 | private IconData mAlarmClockIconData; |
| 313 | |
| 314 | // sync state |
| 315 | // If sync is active the SyncActive icon is displayed. If sync is not active but |
| 316 | // sync is failing the SyncFailing icon is displayed. Otherwise neither are displayed. |
| 317 | private IBinder mSyncActiveIcon; |
| 318 | private IBinder mSyncFailingIcon; |
| 319 | |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 320 | // TTY mode |
| 321 | // Icon lit when TTY mode is enabled |
| 322 | private IBinder mTTYModeIcon; |
| 323 | private IconData mTTYModeEnableIconData; |
| 324 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 325 | // Cdma Roaming Indicator, ERI |
| 326 | private IBinder mCdmaRoamingIndicatorIcon; |
| 327 | private IconData mCdmaRoamingIndicatorIconData; |
| 328 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 329 | private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { |
| 330 | @Override |
| 331 | public void onReceive(Context context, Intent intent) { |
| 332 | String action = intent.getAction(); |
| 333 | if (action.equals(Intent.ACTION_TIME_TICK)) { |
| 334 | updateClock(); |
| 335 | } |
| 336 | else if (action.equals(Intent.ACTION_TIME_CHANGED)) { |
| 337 | updateClock(); |
| 338 | } |
Dianne Hackborn | 8ec5b83 | 2009-07-01 21:19:35 -0700 | [diff] [blame] | 339 | else if (action.equals(Intent.ACTION_BATTERY_CHANGED)) { |
| 340 | updateBattery(intent); |
| 341 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 342 | else if (action.equals(Intent.ACTION_CONFIGURATION_CHANGED)) { |
| 343 | updateClock(); |
| 344 | } |
| 345 | else if (action.equals(Intent.ACTION_TIMEZONE_CHANGED)) { |
| 346 | String tz = intent.getStringExtra("time-zone"); |
| 347 | mCalendar = Calendar.getInstance(TimeZone.getTimeZone(tz)); |
| 348 | updateClock(); |
| 349 | } |
| 350 | else if (action.equals(Intent.ACTION_ALARM_CHANGED)) { |
| 351 | updateAlarm(intent); |
| 352 | } |
| 353 | else if (action.equals(Intent.ACTION_SYNC_STATE_CHANGED)) { |
| 354 | updateSyncState(intent); |
| 355 | } |
Mihai Preda | a82842f | 2009-04-29 15:05:56 +0200 | [diff] [blame] | 356 | else if (action.equals(Intent.ACTION_BATTERY_LOW)) { |
| 357 | onBatteryLow(intent); |
| 358 | } |
Mike Lockwood | 69eb0bf | 2009-08-01 23:02:28 -0400 | [diff] [blame] | 359 | else if (action.equals(Intent.ACTION_BATTERY_OKAY) |
| 360 | || action.equals(Intent.ACTION_POWER_CONNECTED)) { |
Dianne Hackborn | 8ec5b83 | 2009-07-01 21:19:35 -0700 | [diff] [blame] | 361 | onBatteryOkay(intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 362 | } |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 363 | else if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED) || |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 364 | action.equals(BluetoothHeadset.ACTION_STATE_CHANGED) || |
| 365 | action.equals(BluetoothA2dp.ACTION_SINK_STATE_CHANGED) || |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 366 | action.equals(BluetoothPbap.PBAP_STATE_CHANGED_ACTION)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 367 | updateBluetooth(intent); |
| 368 | } |
| 369 | else if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION) || |
| 370 | action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION) || |
| 371 | action.equals(WifiManager.RSSI_CHANGED_ACTION)) { |
| 372 | updateWifi(intent); |
| 373 | } |
| 374 | else if (action.equals(GpsLocationProvider.GPS_ENABLED_CHANGE_ACTION) || |
| 375 | action.equals(GpsLocationProvider.GPS_FIX_CHANGE_ACTION)) { |
| 376 | updateGps(intent); |
| 377 | } |
| 378 | else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION) || |
| 379 | action.equals(AudioManager.VIBRATE_SETTING_CHANGED_ACTION)) { |
| 380 | updateVolume(); |
| 381 | } |
| 382 | else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) { |
| 383 | updateSimState(intent); |
| 384 | } |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 385 | else if (action.equals(TtyIntent.TTY_ENABLED_CHANGE_ACTION)) { |
| 386 | updateTTY(intent); |
| 387 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 | } |
| 389 | }; |
| 390 | |
| 391 | private StatusBarPolicy(Context context, StatusBarService service) { |
| 392 | mContext = context; |
| 393 | mService = service; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 394 | mSignalStrength = new SignalStrength(); |
Dianne Hackborn | 4840e14 | 2009-03-24 22:40:29 -0700 | [diff] [blame] | 395 | mBatteryStats = BatteryStatsService.getService(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 396 | |
| 397 | // clock |
| 398 | mCalendar = Calendar.getInstance(TimeZone.getDefault()); |
| 399 | mClockData = IconData.makeText("clock", ""); |
| 400 | mClockIcon = service.addIcon(mClockData, null); |
| 401 | updateClock(); |
| 402 | |
| 403 | // battery |
| 404 | mBatteryData = IconData.makeIcon("battery", |
| 405 | null, com.android.internal.R.drawable.stat_sys_battery_unknown, 0, 0); |
| 406 | mBatteryIcon = service.addIcon(mBatteryData, null); |
| 407 | |
| 408 | // phone_signal |
| 409 | mPhone = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 410 | mPhoneData = IconData.makeIcon("phone_signal", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 411 | null, com.android.internal.R.drawable.stat_sys_signal_null, 0, 0); |
| 412 | mPhoneIcon = service.addIcon(mPhoneData, null); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 413 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 414 | // register for phone state notifications. |
| 415 | ((TelephonyManager)mContext.getSystemService(Context.TELEPHONY_SERVICE)) |
| 416 | .listen(mPhoneStateListener, |
| 417 | PhoneStateListener.LISTEN_SERVICE_STATE |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 418 | | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 419 | | PhoneStateListener.LISTEN_CALL_STATE |
| 420 | | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE |
| 421 | | PhoneStateListener.LISTEN_DATA_ACTIVITY); |
| 422 | |
| 423 | // data_connection |
| 424 | mDataData = IconData.makeIcon("data_connection", |
| 425 | null, com.android.internal.R.drawable.stat_sys_data_connected_g, 0, 0); |
| 426 | mDataIcon = service.addIcon(mDataData, null); |
| 427 | service.setIconVisibility(mDataIcon, false); |
| 428 | |
| 429 | // wifi |
| 430 | mWifiData = IconData.makeIcon("wifi", null, sWifiSignalImages[0], 0, 0); |
| 431 | mWifiIcon = service.addIcon(mWifiData, null); |
| 432 | service.setIconVisibility(mWifiIcon, false); |
| 433 | // wifi will get updated by the sticky intents |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 434 | |
| 435 | // TTY status |
| 436 | mTTYModeEnableIconData = IconData.makeIcon("tty", |
| 437 | null, com.android.internal.R.drawable.stat_sys_tty_mode, 0, 0); |
| 438 | mTTYModeIcon = service.addIcon(mTTYModeEnableIconData, null); |
| 439 | service.setIconVisibility(mTTYModeIcon, false); |
| 440 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 441 | // Cdma Roaming Indicator, ERI |
| 442 | mCdmaRoamingIndicatorIconData = IconData.makeIcon("cdma_eri", |
| 443 | null, com.android.internal.R.drawable.stat_sys_roaming_cdma_0, 0, 0); |
| 444 | mCdmaRoamingIndicatorIcon = service.addIcon(mCdmaRoamingIndicatorIconData, null); |
| 445 | service.setIconVisibility(mCdmaRoamingIndicatorIcon, false); |
| 446 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 447 | // bluetooth status |
| 448 | mBluetoothData = IconData.makeIcon("bluetooth", |
| 449 | null, com.android.internal.R.drawable.stat_sys_data_bluetooth, 0, 0); |
| 450 | mBluetoothIcon = service.addIcon(mBluetoothData, null); |
Nick Pelly | f242b7b | 2009-10-08 00:12:45 +0200 | [diff] [blame^] | 451 | BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 452 | if (adapter != null) { |
| 453 | mBluetoothEnabled = adapter.isEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 454 | } else { |
| 455 | mBluetoothEnabled = false; |
| 456 | } |
| 457 | mBluetoothA2dpState = BluetoothA2dp.STATE_DISCONNECTED; |
| 458 | mBluetoothHeadsetState = BluetoothHeadset.STATE_DISCONNECTED; |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 459 | mBluetoothPbapState = BluetoothPbap.STATE_DISCONNECTED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 460 | mService.setIconVisibility(mBluetoothIcon, mBluetoothEnabled); |
| 461 | |
| 462 | // Gps status |
| 463 | mGpsEnabledIconData = IconData.makeIcon("gps", |
| 464 | null, com.android.internal.R.drawable.stat_sys_gps_acquiring_anim, 0, 0); |
| 465 | mGpsFixIconData = IconData.makeIcon("gps", |
| 466 | null, com.android.internal.R.drawable.stat_sys_gps_on, 0, 0); |
| 467 | mGpsIcon = service.addIcon(mGpsEnabledIconData, null); |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 468 | service.setIconVisibility(mGpsIcon, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 469 | |
| 470 | // Alarm clock |
| 471 | mAlarmClockIconData = IconData.makeIcon( |
| 472 | "alarm_clock", |
| 473 | null, com.android.internal.R.drawable.stat_notify_alarm, 0, 0); |
| 474 | mAlarmClockIcon = service.addIcon(mAlarmClockIconData, null); |
| 475 | service.setIconVisibility(mAlarmClockIcon, false); |
| 476 | |
| 477 | // Sync state |
| 478 | mSyncActiveIcon = service.addIcon(IconData.makeIcon("sync_active", |
| 479 | null, R.drawable.stat_notify_sync_anim0, 0, 0), null); |
| 480 | mSyncFailingIcon = service.addIcon(IconData.makeIcon("sync_failing", |
| 481 | null, R.drawable.stat_notify_sync_error, 0, 0), null); |
| 482 | service.setIconVisibility(mSyncActiveIcon, false); |
| 483 | service.setIconVisibility(mSyncFailingIcon, false); |
| 484 | |
| 485 | // volume |
| 486 | mVolumeData = IconData.makeIcon("volume", |
| 487 | null, com.android.internal.R.drawable.stat_sys_ringer_silent, 0, 0); |
| 488 | mVolumeIcon = service.addIcon(mVolumeData, null); |
| 489 | service.setIconVisibility(mVolumeIcon, false); |
| 490 | updateVolume(); |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 491 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 492 | IntentFilter filter = new IntentFilter(); |
| 493 | |
| 494 | // Register for Intent broadcasts for... |
| 495 | filter.addAction(Intent.ACTION_TIME_TICK); |
| 496 | filter.addAction(Intent.ACTION_TIME_CHANGED); |
| 497 | filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED); |
| 498 | filter.addAction(Intent.ACTION_BATTERY_CHANGED); |
Mihai Preda | a82842f | 2009-04-29 15:05:56 +0200 | [diff] [blame] | 499 | filter.addAction(Intent.ACTION_BATTERY_LOW); |
Dianne Hackborn | 8ec5b83 | 2009-07-01 21:19:35 -0700 | [diff] [blame] | 500 | filter.addAction(Intent.ACTION_BATTERY_OKAY); |
Mike Lockwood | 69eb0bf | 2009-08-01 23:02:28 -0400 | [diff] [blame] | 501 | filter.addAction(Intent.ACTION_POWER_CONNECTED); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 502 | filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); |
| 503 | filter.addAction(Intent.ACTION_ALARM_CHANGED); |
| 504 | filter.addAction(Intent.ACTION_SYNC_STATE_CHANGED); |
| 505 | filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); |
| 506 | filter.addAction(AudioManager.VIBRATE_SETTING_CHANGED_ACTION); |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 507 | filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 508 | filter.addAction(BluetoothHeadset.ACTION_STATE_CHANGED); |
| 509 | filter.addAction(BluetoothA2dp.ACTION_SINK_STATE_CHANGED); |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 510 | filter.addAction(BluetoothPbap.PBAP_STATE_CHANGED_ACTION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 511 | filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); |
| 512 | filter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION); |
| 513 | filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); |
| 514 | filter.addAction(WifiManager.RSSI_CHANGED_ACTION); |
| 515 | filter.addAction(GpsLocationProvider.GPS_ENABLED_CHANGE_ACTION); |
| 516 | filter.addAction(GpsLocationProvider.GPS_FIX_CHANGE_ACTION); |
| 517 | filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 518 | filter.addAction(TtyIntent.TTY_ENABLED_CHANGE_ACTION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 519 | mContext.registerReceiver(mIntentReceiver, filter, null, mHandler); |
| 520 | } |
| 521 | |
| 522 | public static void installIcons(Context context, StatusBarService service) { |
| 523 | sInstance = new StatusBarPolicy(context, service); |
| 524 | } |
| 525 | |
| 526 | private final void updateClock() { |
| 527 | mCalendar.setTimeInMillis(System.currentTimeMillis()); |
| 528 | mClockData.text = DateFormat.getTimeFormat(mContext) |
| 529 | .format(mCalendar.getTime()); |
| 530 | mService.updateIcon(mClockIcon, mClockData, null); |
| 531 | } |
| 532 | |
| 533 | private final void updateAlarm(Intent intent) { |
| 534 | boolean alarmSet = intent.getBooleanExtra("alarmSet", false); |
| 535 | mService.setIconVisibility(mAlarmClockIcon, alarmSet); |
| 536 | } |
| 537 | |
| 538 | private final void updateSyncState(Intent intent) { |
| 539 | boolean isActive = intent.getBooleanExtra("active", false); |
| 540 | boolean isFailing = intent.getBooleanExtra("failing", false); |
| 541 | mService.setIconVisibility(mSyncActiveIcon, isActive); |
| 542 | // Don't display sync failing icon: BUG 1297963 Set sync error timeout to "never" |
| 543 | //mService.setIconVisibility(mSyncFailingIcon, isFailing && !isActive); |
| 544 | } |
| 545 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 546 | private final void updateBattery(Intent intent) { |
| 547 | mBatteryData.iconId = intent.getIntExtra("icon-small", 0); |
| 548 | mBatteryData.iconLevel = intent.getIntExtra("level", 0); |
| 549 | mService.updateIcon(mBatteryIcon, mBatteryData, null); |
| 550 | |
| 551 | boolean plugged = intent.getIntExtra("plugged", 0) != 0; |
| 552 | int level = intent.getIntExtra("level", -1); |
| 553 | if (false) { |
| 554 | Log.d(TAG, "updateBattery level=" + level |
| 555 | + " plugged=" + plugged |
| 556 | + " mBatteryPlugged=" + mBatteryPlugged |
| 557 | + " mBatteryLevel=" + mBatteryLevel |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 558 | + " mBatteryFirst=" + mBatteryFirst); |
| 559 | } |
| 560 | |
| 561 | boolean oldPlugged = mBatteryPlugged; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 562 | |
| 563 | mBatteryPlugged = plugged; |
| 564 | mBatteryLevel = level; |
| 565 | |
| 566 | if (mBatteryFirst) { |
| 567 | mBatteryFirst = false; |
| 568 | } |
| 569 | /* |
| 570 | * No longer showing the battery view because it draws attention away |
| 571 | * from the USB storage notification. We could still show it when |
| 572 | * connected to a brick, but that could lead to the user into thinking |
| 573 | * the device does not charge when plugged into USB (since he/she would |
| 574 | * not see the same battery screen on USB as he sees on brick). |
| 575 | */ |
| 576 | /* else { |
| 577 | if (plugged && !oldPlugged) { |
| 578 | showBatteryView(); |
| 579 | } |
| 580 | } |
| 581 | */ |
| 582 | if (false) { |
Mihai Preda | a82842f | 2009-04-29 15:05:56 +0200 | [diff] [blame] | 583 | Log.d(TAG, "plugged=" + plugged + " oldPlugged=" + oldPlugged + " level=" + level); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 584 | } |
Mihai Preda | a82842f | 2009-04-29 15:05:56 +0200 | [diff] [blame] | 585 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 586 | |
Mihai Preda | a82842f | 2009-04-29 15:05:56 +0200 | [diff] [blame] | 587 | private void onBatteryLow(Intent intent) { |
| 588 | if (SHOW_LOW_BATTERY_WARNING) { |
| 589 | if (false) { |
| 590 | Log.d(TAG, "mPhoneState=" + mPhoneState |
| 591 | + " mLowBatteryDialog=" + mLowBatteryDialog |
| 592 | + " mBatteryShowLowOnEndCall=" + mBatteryShowLowOnEndCall); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 593 | } |
Mihai Preda | a82842f | 2009-04-29 15:05:56 +0200 | [diff] [blame] | 594 | |
| 595 | if (mPhoneState == TelephonyManager.CALL_STATE_IDLE) { |
| 596 | showLowBatteryWarning(); |
| 597 | } else { |
| 598 | mBatteryShowLowOnEndCall = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 599 | } |
| 600 | } |
| 601 | } |
| 602 | |
Dianne Hackborn | 8ec5b83 | 2009-07-01 21:19:35 -0700 | [diff] [blame] | 603 | private void onBatteryOkay(Intent intent) { |
| 604 | if (mLowBatteryDialog != null |
| 605 | && SHOW_LOW_BATTERY_WARNING) { |
| 606 | mLowBatteryDialog.dismiss(); |
| 607 | mBatteryShowLowOnEndCall = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 608 | } |
| 609 | } |
| 610 | |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 611 | private void showBatteryView() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 612 | closeLastBatteryView(); |
| 613 | if (mLowBatteryDialog != null) { |
| 614 | mLowBatteryDialog.dismiss(); |
| 615 | } |
| 616 | |
| 617 | int level = mBatteryLevel; |
| 618 | |
| 619 | View v = View.inflate(mContext, com.android.internal.R.layout.battery_status, null); |
| 620 | mBatteryView = v; |
| 621 | int pixelFormat = PixelFormat.TRANSLUCENT; |
| 622 | Drawable bg = v.getBackground(); |
| 623 | if (bg != null) { |
| 624 | pixelFormat = bg.getOpacity(); |
| 625 | } |
| 626 | |
| 627 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 628 | ViewGroup.LayoutParams.WRAP_CONTENT, |
| 629 | ViewGroup.LayoutParams.WRAP_CONTENT, |
| 630 | WindowManager.LayoutParams.TYPE_TOAST, |
| 631 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 632 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
| 633 | | WindowManager.LayoutParams.FLAG_BLUR_BEHIND |
| 634 | | WindowManager.LayoutParams.FLAG_DIM_BEHIND, |
| 635 | pixelFormat); |
| 636 | |
| 637 | // Get the dim amount from the theme |
| 638 | TypedArray a = mContext.obtainStyledAttributes( |
| 639 | com.android.internal.R.styleable.Theme); |
| 640 | lp.dimAmount = a.getFloat(android.R.styleable.Theme_backgroundDimAmount, 0.5f); |
| 641 | a.recycle(); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 642 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 643 | lp.setTitle("Battery"); |
| 644 | |
| 645 | TextView levelTextView = (TextView)v.findViewById(com.android.internal.R.id.level_percent); |
| 646 | levelTextView.setText(mContext.getString( |
| 647 | com.android.internal.R.string.battery_status_text_percent_format, level)); |
| 648 | |
| 649 | setBatteryLevel(v, com.android.internal.R.id.spacer, 100-level, 0, 0); |
| 650 | setBatteryLevel(v, com.android.internal.R.id.level, level, |
| 651 | com.android.internal.R.drawable.battery_charge_fill, level); |
| 652 | |
| 653 | WindowManagerImpl.getDefault().addView(v, lp); |
| 654 | |
| 655 | scheduleCloseBatteryView(); |
| 656 | } |
| 657 | |
| 658 | private void setBatteryLevel(View parent, int id, int height, int background, int level) { |
| 659 | ImageView v = (ImageView)parent.findViewById(id); |
| 660 | LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)v.getLayoutParams(); |
| 661 | lp.weight = height; |
| 662 | if (background != 0) { |
| 663 | v.setBackgroundResource(background); |
| 664 | Drawable bkg = v.getBackground(); |
| 665 | bkg.setLevel(level); |
| 666 | } |
| 667 | } |
| 668 | |
| 669 | private void showLowBatteryWarning() { |
| 670 | closeLastBatteryView(); |
| 671 | |
Mike Lockwood | d81b1f4 | 2009-09-25 09:32:19 -0400 | [diff] [blame] | 672 | // Show exact battery level. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 673 | CharSequence levelText = mContext.getString( |
Mike Lockwood | d81b1f4 | 2009-09-25 09:32:19 -0400 | [diff] [blame] | 674 | com.android.internal.R.string.battery_low_percent_format, mBatteryLevel); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 675 | |
| 676 | if (mBatteryLevelTextView != null) { |
| 677 | mBatteryLevelTextView.setText(levelText); |
| 678 | } else { |
| 679 | View v = View.inflate(mContext, com.android.internal.R.layout.battery_low, null); |
| 680 | mBatteryLevelTextView=(TextView)v.findViewById(com.android.internal.R.id.level_percent); |
| 681 | |
| 682 | mBatteryLevelTextView.setText(levelText); |
| 683 | |
| 684 | AlertDialog.Builder b = new AlertDialog.Builder(mContext); |
| 685 | b.setCancelable(true); |
| 686 | b.setTitle(com.android.internal.R.string.battery_low_title); |
| 687 | b.setView(v); |
| 688 | b.setIcon(android.R.drawable.ic_dialog_alert); |
| 689 | b.setPositiveButton(android.R.string.ok, null); |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 690 | |
Dianne Hackborn | 3d74bb4 | 2009-06-19 10:35:21 -0700 | [diff] [blame] | 691 | final Intent intent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY); |
| 692 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 693 | | Intent.FLAG_ACTIVITY_MULTIPLE_TASK |
| 694 | | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS |
| 695 | | Intent.FLAG_ACTIVITY_NO_HISTORY); |
| 696 | if (intent.resolveActivity(mContext.getPackageManager()) != null) { |
| 697 | b.setNegativeButton(com.android.internal.R.string.battery_low_why, |
| 698 | new DialogInterface.OnClickListener() { |
| 699 | public void onClick(DialogInterface dialog, int which) { |
| 700 | mContext.startActivity(intent); |
| 701 | if (mLowBatteryDialog != null) { |
| 702 | mLowBatteryDialog.dismiss(); |
| 703 | } |
| 704 | } |
| 705 | }); |
| 706 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 707 | |
| 708 | AlertDialog d = b.create(); |
| 709 | d.setOnDismissListener(mLowBatteryListener); |
| 710 | d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); |
| 711 | d.show(); |
| 712 | mLowBatteryDialog = d; |
| 713 | } |
| 714 | } |
| 715 | |
| 716 | private final void updateCallState(int state) { |
| 717 | mPhoneState = state; |
| 718 | if (false) { |
| 719 | Log.d(TAG, "mPhoneState=" + mPhoneState |
| 720 | + " mLowBatteryDialog=" + mLowBatteryDialog |
| 721 | + " mBatteryShowLowOnEndCall=" + mBatteryShowLowOnEndCall); |
| 722 | } |
| 723 | if (mPhoneState == TelephonyManager.CALL_STATE_IDLE) { |
| 724 | if (mBatteryShowLowOnEndCall) { |
| 725 | if (!mBatteryPlugged) { |
| 726 | showLowBatteryWarning(); |
| 727 | } |
| 728 | mBatteryShowLowOnEndCall = false; |
| 729 | } |
| 730 | } else { |
| 731 | if (mLowBatteryDialog != null) { |
| 732 | mLowBatteryDialog.dismiss(); |
| 733 | mBatteryShowLowOnEndCall = true; |
| 734 | } |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | private DialogInterface.OnDismissListener mLowBatteryListener |
| 739 | = new DialogInterface.OnDismissListener() { |
| 740 | public void onDismiss(DialogInterface dialog) { |
| 741 | mLowBatteryDialog = null; |
| 742 | mBatteryLevelTextView = null; |
| 743 | } |
| 744 | }; |
| 745 | |
| 746 | private void scheduleCloseBatteryView() { |
| 747 | Message m = mHandler.obtainMessage(EVENT_BATTERY_CLOSE); |
| 748 | m.arg1 = (++mBatteryViewSequence); |
| 749 | mHandler.sendMessageDelayed(m, 3000); |
| 750 | } |
| 751 | |
| 752 | private void closeLastBatteryView() { |
| 753 | if (mBatteryView != null) { |
| 754 | //mBatteryView.debug(); |
| 755 | WindowManagerImpl.getDefault().removeView(mBatteryView); |
| 756 | mBatteryView = null; |
| 757 | } |
| 758 | } |
| 759 | |
| 760 | private PhoneStateListener mPhoneStateListener = new PhoneStateListener() { |
| 761 | @Override |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 762 | public void onSignalStrengthsChanged(SignalStrength signalStrength) { |
| 763 | mSignalStrength = signalStrength; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 764 | updateSignalStrength(); |
| 765 | } |
| 766 | |
| 767 | @Override |
| 768 | public void onServiceStateChanged(ServiceState state) { |
| 769 | mServiceState = state; |
| 770 | updateSignalStrength(); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 771 | updateCdmaRoamingIcon(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 772 | updateDataIcon(); |
| 773 | } |
| 774 | |
| 775 | @Override |
| 776 | public void onCallStateChanged(int state, String incomingNumber) { |
| 777 | updateCallState(state); |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 778 | // In cdma, if a voice call is made, RSSI should switch to 1x. |
| 779 | if (isCdma()) { |
| 780 | updateSignalStrength(); |
| 781 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | @Override |
| 785 | public void onDataConnectionStateChanged(int state) { |
| 786 | mDataState = state; |
| 787 | updateDataNetType(); |
| 788 | updateDataIcon(); |
| 789 | } |
| 790 | |
| 791 | @Override |
| 792 | public void onDataActivity(int direction) { |
| 793 | mDataActivity = direction; |
| 794 | updateDataIcon(); |
| 795 | } |
| 796 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 797 | |
| 798 | private final void updateSimState(Intent intent) { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 799 | String stateExtra = intent.getStringExtra(IccCard.INTENT_KEY_ICC_STATE); |
| 800 | if (IccCard.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) { |
| 801 | mSimState = IccCard.State.ABSENT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 802 | } |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 803 | else if (IccCard.INTENT_VALUE_ICC_READY.equals(stateExtra)) { |
| 804 | mSimState = IccCard.State.READY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 805 | } |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 806 | else if (IccCard.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) { |
| 807 | final String lockedReason = intent.getStringExtra(IccCard.INTENT_KEY_LOCKED_REASON); |
| 808 | if (IccCard.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) { |
| 809 | mSimState = IccCard.State.PIN_REQUIRED; |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 810 | } |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 811 | else if (IccCard.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) { |
| 812 | mSimState = IccCard.State.PUK_REQUIRED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 813 | } |
| 814 | else { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 815 | mSimState = IccCard.State.NETWORK_LOCKED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 816 | } |
| 817 | } else { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 818 | mSimState = IccCard.State.UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 819 | } |
| 820 | updateDataIcon(); |
| 821 | } |
| 822 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 823 | private boolean isCdma() { |
Wink Saville | f315238 | 2009-06-01 14:39:20 -0700 | [diff] [blame] | 824 | return ((mPhone != null) && (mPhone.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA)); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 825 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 826 | |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 827 | private boolean isEvdo() { |
| 828 | return ( (mServiceState != null) |
| 829 | && ((mServiceState.getRadioTechnology() |
| 830 | == ServiceState.RADIO_TECHNOLOGY_EVDO_0) |
| 831 | || (mServiceState.getRadioTechnology() |
| 832 | == ServiceState.RADIO_TECHNOLOGY_EVDO_A))); |
| 833 | } |
| 834 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 835 | private boolean hasService() { |
| 836 | if (mServiceState != null) { |
| 837 | switch (mServiceState.getState()) { |
| 838 | case ServiceState.STATE_OUT_OF_SERVICE: |
| 839 | case ServiceState.STATE_POWER_OFF: |
| 840 | return false; |
| 841 | default: |
| 842 | return true; |
| 843 | } |
| 844 | } else { |
| 845 | return false; |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | private final void updateSignalStrength() { |
| 850 | int iconLevel = -1; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 851 | int[] iconList; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 852 | |
| 853 | if (!hasService()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 854 | //Log.d(TAG, "updateSignalStrength: no service"); |
| 855 | if (Settings.System.getInt(mContext.getContentResolver(), |
| 856 | Settings.System.AIRPLANE_MODE_ON, 0) == 1) { |
| 857 | mPhoneData.iconId = com.android.internal.R.drawable.stat_sys_signal_flightmode; |
| 858 | } else { |
| 859 | mPhoneData.iconId = com.android.internal.R.drawable.stat_sys_signal_null; |
| 860 | } |
| 861 | mService.updateIcon(mPhoneIcon, mPhoneData, null); |
| 862 | return; |
| 863 | } |
| 864 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 865 | if (!isCdma()) { |
| 866 | int asu = mSignalStrength.getGsmSignalStrength(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 867 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 868 | // ASU ranges from 0 to 31 - TS 27.007 Sec 8.5 |
| 869 | // asu = 0 (-113dB or less) is very weak |
| 870 | // signal, its better to show 0 bars to the user in such cases. |
| 871 | // asu = 99 is a special case, where the signal strength is unknown. |
| 872 | if (asu <= 0 || asu == 99) iconLevel = 0; |
| 873 | else if (asu >= 16) iconLevel = 4; |
| 874 | else if (asu >= 8) iconLevel = 3; |
| 875 | else if (asu >= 4) iconLevel = 2; |
| 876 | else iconLevel = 1; |
| 877 | |
| 878 | if (mPhone.isNetworkRoaming()) { |
| 879 | iconList = sSignalImages_r; |
| 880 | } else { |
| 881 | iconList = sSignalImages; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 882 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 883 | } else { |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 884 | iconList = this.sSignalImages; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 885 | |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 886 | // If 3G(EV) and 1x network are available than 3G should be |
| 887 | // displayed, displayed RSSI should be from the EV side. |
| 888 | // If a voice call is made then RSSI should switch to 1x. |
| 889 | if ((mPhoneState == TelephonyManager.CALL_STATE_IDLE) && isEvdo()){ |
| 890 | iconLevel = getEvdoLevel(); |
| 891 | if (false) { |
| 892 | Log.d(TAG, "use Evdo level=" + iconLevel + " to replace Cdma Level=" + getCdmaLevel()); |
| 893 | } |
| 894 | } else { |
| 895 | iconLevel = getCdmaLevel(); |
| 896 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 897 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 898 | mPhoneData.iconId = iconList[iconLevel]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 899 | mService.updateIcon(mPhoneIcon, mPhoneData, null); |
| 900 | } |
| 901 | |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 902 | private int getCdmaLevel() { |
| 903 | final int cdmaDbm = mSignalStrength.getCdmaDbm(); |
| 904 | final int cdmaEcio = mSignalStrength.getCdmaEcio(); |
| 905 | int levelDbm = 0; |
| 906 | int levelEcio = 0; |
| 907 | |
| 908 | if (cdmaDbm >= -75) levelDbm = 4; |
| 909 | else if (cdmaDbm >= -85) levelDbm = 3; |
| 910 | else if (cdmaDbm >= -95) levelDbm = 2; |
| 911 | else if (cdmaDbm >= -100) levelDbm = 1; |
| 912 | else levelDbm = 0; |
| 913 | |
| 914 | // Ec/Io are in dB*10 |
| 915 | if (cdmaEcio >= -90) levelEcio = 4; |
| 916 | else if (cdmaEcio >= -110) levelEcio = 3; |
| 917 | else if (cdmaEcio >= -130) levelEcio = 2; |
| 918 | else if (cdmaEcio >= -150) levelEcio = 1; |
| 919 | else levelEcio = 0; |
| 920 | |
| 921 | return (levelDbm < levelEcio) ? levelDbm : levelEcio; |
| 922 | } |
| 923 | |
| 924 | private int getEvdoLevel() { |
| 925 | int evdoDbm = mSignalStrength.getEvdoDbm(); |
| 926 | int evdoSnr = mSignalStrength.getEvdoSnr(); |
| 927 | int levelEvdoDbm = 0; |
| 928 | int levelEvdoSnr = 0; |
| 929 | |
| 930 | if (evdoDbm >= -65) levelEvdoDbm = 4; |
| 931 | else if (evdoDbm >= -75) levelEvdoDbm = 3; |
| 932 | else if (evdoDbm >= -90) levelEvdoDbm = 2; |
| 933 | else if (evdoDbm >= -105) levelEvdoDbm = 1; |
| 934 | else levelEvdoDbm = 0; |
| 935 | |
John Michelau | 1336a56 | 2009-09-28 10:41:02 -0500 | [diff] [blame] | 936 | if (evdoSnr >= 7) levelEvdoSnr = 4; |
| 937 | else if (evdoSnr >= 5) levelEvdoSnr = 3; |
| 938 | else if (evdoSnr >= 3) levelEvdoSnr = 2; |
| 939 | else if (evdoSnr >= 1) levelEvdoSnr = 1; |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 940 | else levelEvdoSnr = 0; |
| 941 | |
| 942 | return (levelEvdoDbm < levelEvdoSnr) ? levelEvdoDbm : levelEvdoSnr; |
| 943 | } |
| 944 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 945 | private final void updateDataNetType() { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 946 | int net = mPhone.getNetworkType(); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 947 | |
| 948 | switch (net) { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 949 | case TelephonyManager.NETWORK_TYPE_EDGE: |
| 950 | mDataIconList = sDataNetType_e; |
| 951 | break; |
| 952 | case TelephonyManager.NETWORK_TYPE_UMTS: |
| 953 | mDataIconList = sDataNetType_3g; |
| 954 | break; |
Li Zhe | ebe6634 | 2009-08-14 19:22:16 +0800 | [diff] [blame] | 955 | case TelephonyManager.NETWORK_TYPE_HSDPA: |
| 956 | case TelephonyManager.NETWORK_TYPE_HSUPA: |
| 957 | case TelephonyManager.NETWORK_TYPE_HSPA: |
| 958 | mDataIconList = sDataNetType_h; |
| 959 | break; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 960 | case TelephonyManager.NETWORK_TYPE_CDMA: |
| 961 | // display 1xRTT for IS95A/B |
johnwang | 9f87cb2 | 2009-08-25 15:25:37 -0700 | [diff] [blame] | 962 | mDataIconList = this.sDataNetType_1x; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 963 | break; |
| 964 | case TelephonyManager.NETWORK_TYPE_1xRTT: |
johnwang | 9f87cb2 | 2009-08-25 15:25:37 -0700 | [diff] [blame] | 965 | mDataIconList = this.sDataNetType_1x; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 966 | break; |
| 967 | case TelephonyManager.NETWORK_TYPE_EVDO_0: //fall through |
| 968 | case TelephonyManager.NETWORK_TYPE_EVDO_A: |
johnwang | 9f87cb2 | 2009-08-25 15:25:37 -0700 | [diff] [blame] | 969 | mDataIconList = sDataNetType_3g; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 970 | break; |
| 971 | default: |
| 972 | mDataIconList = sDataNetType_g; |
| 973 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 974 | } |
| 975 | } |
| 976 | |
| 977 | private final void updateDataIcon() { |
| 978 | int iconId; |
| 979 | boolean visible = true; |
| 980 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 981 | if (!isCdma()) { |
| 982 | // GSM case, we have to check also the sim state |
| 983 | if (mSimState == IccCard.State.READY || mSimState == IccCard.State.UNKNOWN) { |
| 984 | if (hasService() && mDataState == TelephonyManager.DATA_CONNECTED) { |
| 985 | switch (mDataActivity) { |
| 986 | case TelephonyManager.DATA_ACTIVITY_IN: |
| 987 | iconId = mDataIconList[1]; |
| 988 | break; |
| 989 | case TelephonyManager.DATA_ACTIVITY_OUT: |
| 990 | iconId = mDataIconList[2]; |
| 991 | break; |
| 992 | case TelephonyManager.DATA_ACTIVITY_INOUT: |
| 993 | iconId = mDataIconList[3]; |
| 994 | break; |
| 995 | default: |
| 996 | iconId = mDataIconList[0]; |
| 997 | break; |
| 998 | } |
| 999 | mDataData.iconId = iconId; |
| 1000 | mService.updateIcon(mDataIcon, mDataData, null); |
| 1001 | } else { |
| 1002 | visible = false; |
| 1003 | } |
| 1004 | } else { |
| 1005 | mDataData.iconId = com.android.internal.R.drawable.stat_sys_no_sim; |
| 1006 | mService.updateIcon(mDataIcon, mDataData, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1007 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1008 | } else { |
| 1009 | // CDMA case, mDataActivity can be also DATA_ACTIVITY_DORMANT |
| 1010 | if (hasService() && mDataState == TelephonyManager.DATA_CONNECTED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1011 | switch (mDataActivity) { |
| 1012 | case TelephonyManager.DATA_ACTIVITY_IN: |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1013 | iconId = mDataIconList[1]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1014 | break; |
| 1015 | case TelephonyManager.DATA_ACTIVITY_OUT: |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1016 | iconId = mDataIconList[2]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1017 | break; |
| 1018 | case TelephonyManager.DATA_ACTIVITY_INOUT: |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1019 | iconId = mDataIconList[3]; |
| 1020 | break; |
| 1021 | case TelephonyManager.DATA_ACTIVITY_DORMANT: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1022 | default: |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1023 | iconId = mDataIconList[0]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1024 | break; |
| 1025 | } |
| 1026 | mDataData.iconId = iconId; |
| 1027 | mService.updateIcon(mDataIcon, mDataData, null); |
| 1028 | } else { |
| 1029 | visible = false; |
| 1030 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1031 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1032 | |
Dianne Hackborn | 4840e14 | 2009-03-24 22:40:29 -0700 | [diff] [blame] | 1033 | long ident = Binder.clearCallingIdentity(); |
| 1034 | try { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 1035 | mBatteryStats.notePhoneDataConnectionState(mPhone.getNetworkType(), visible); |
Dianne Hackborn | 4840e14 | 2009-03-24 22:40:29 -0700 | [diff] [blame] | 1036 | } catch (RemoteException e) { |
| 1037 | } finally { |
| 1038 | Binder.restoreCallingIdentity(ident); |
| 1039 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1040 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1041 | if (mDataIconVisible != visible) { |
| 1042 | mService.setIconVisibility(mDataIcon, visible); |
| 1043 | mDataIconVisible = visible; |
| 1044 | } |
| 1045 | } |
| 1046 | |
| 1047 | private final void updateVolume() { |
| 1048 | AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); |
| 1049 | final int ringerMode = audioManager.getRingerMode(); |
| 1050 | final boolean visible = ringerMode == AudioManager.RINGER_MODE_SILENT || |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1051 | ringerMode == AudioManager.RINGER_MODE_VIBRATE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1052 | final int iconId = audioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER) |
| 1053 | ? com.android.internal.R.drawable.stat_sys_ringer_vibrate |
| 1054 | : com.android.internal.R.drawable.stat_sys_ringer_silent; |
| 1055 | |
| 1056 | if (visible) { |
| 1057 | mVolumeData.iconId = iconId; |
| 1058 | mService.updateIcon(mVolumeIcon, mVolumeData, null); |
| 1059 | } |
| 1060 | if (visible != mVolumeVisible) { |
| 1061 | mService.setIconVisibility(mVolumeIcon, visible); |
| 1062 | mVolumeVisible = visible; |
| 1063 | } |
| 1064 | } |
| 1065 | |
| 1066 | private final void updateBluetooth(Intent intent) { |
| 1067 | int iconId = com.android.internal.R.drawable.stat_sys_data_bluetooth; |
| 1068 | |
| 1069 | String action = intent.getAction(); |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 1070 | if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { |
Nick Pelly | b24e11b | 2009-09-08 17:40:43 -0700 | [diff] [blame] | 1071 | int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR); |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 1072 | mBluetoothEnabled = state == BluetoothAdapter.STATE_ON; |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 1073 | } else if (action.equals(BluetoothHeadset.ACTION_STATE_CHANGED)) { |
| 1074 | mBluetoothHeadsetState = intent.getIntExtra(BluetoothHeadset.EXTRA_STATE, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1075 | BluetoothHeadset.STATE_ERROR); |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 1076 | } else if (action.equals(BluetoothA2dp.ACTION_SINK_STATE_CHANGED)) { |
| 1077 | mBluetoothA2dpState = intent.getIntExtra(BluetoothA2dp.EXTRA_SINK_STATE, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1078 | BluetoothA2dp.STATE_DISCONNECTED); |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 1079 | } else if (action.equals(BluetoothPbap.PBAP_STATE_CHANGED_ACTION)) { |
| 1080 | mBluetoothPbapState = intent.getIntExtra(BluetoothPbap.PBAP_STATE, |
| 1081 | BluetoothPbap.STATE_DISCONNECTED); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1082 | } else { |
| 1083 | return; |
| 1084 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1085 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1086 | if (mBluetoothHeadsetState == BluetoothHeadset.STATE_CONNECTED || |
| 1087 | mBluetoothA2dpState == BluetoothA2dp.STATE_CONNECTED || |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 1088 | mBluetoothA2dpState == BluetoothA2dp.STATE_PLAYING || |
| 1089 | mBluetoothPbapState == BluetoothPbap.STATE_CONNECTED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1090 | iconId = com.android.internal.R.drawable.stat_sys_data_bluetooth_connected; |
| 1091 | } |
| 1092 | |
| 1093 | mBluetoothData.iconId = iconId; |
| 1094 | mService.updateIcon(mBluetoothIcon, mBluetoothData, null); |
| 1095 | mService.setIconVisibility(mBluetoothIcon, mBluetoothEnabled); |
| 1096 | } |
| 1097 | |
| 1098 | private final void updateWifi(Intent intent) { |
| 1099 | final String action = intent.getAction(); |
| 1100 | if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1101 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1102 | final boolean enabled = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, |
| 1103 | WifiManager.WIFI_STATE_UNKNOWN) == WifiManager.WIFI_STATE_ENABLED; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1104 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1105 | if (!enabled) { |
| 1106 | // If disabled, hide the icon. (We show icon when connected.) |
| 1107 | mService.setIconVisibility(mWifiIcon, false); |
| 1108 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1109 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1110 | } else if (action.equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)) { |
| 1111 | final boolean enabled = intent.getBooleanExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED, |
| 1112 | false); |
| 1113 | if (!enabled) { |
| 1114 | mService.setIconVisibility(mWifiIcon, false); |
| 1115 | } |
| 1116 | } else if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) { |
| 1117 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1118 | final NetworkInfo networkInfo = (NetworkInfo) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1119 | intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1120 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1121 | int iconId; |
| 1122 | if (networkInfo != null && networkInfo.isConnected()) { |
| 1123 | mIsWifiConnected = true; |
| 1124 | if (mLastWifiSignalLevel == -1) { |
| 1125 | iconId = sWifiSignalImages[0]; |
| 1126 | } else { |
| 1127 | iconId = sWifiSignalImages[mLastWifiSignalLevel]; |
| 1128 | } |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 1129 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1130 | // Show the icon since wi-fi is connected |
| 1131 | mService.setIconVisibility(mWifiIcon, true); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 1132 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1133 | } else { |
| 1134 | mLastWifiSignalLevel = -1; |
| 1135 | mIsWifiConnected = false; |
| 1136 | iconId = sWifiSignalImages[0]; |
| 1137 | |
| 1138 | // Hide the icon since we're not connected |
| 1139 | mService.setIconVisibility(mWifiIcon, false); |
| 1140 | } |
| 1141 | |
| 1142 | mWifiData.iconId = iconId; |
| 1143 | mService.updateIcon(mWifiIcon, mWifiData, null); |
| 1144 | } else if (action.equals(WifiManager.RSSI_CHANGED_ACTION)) { |
| 1145 | final int newRssi = intent.getIntExtra(WifiManager.EXTRA_NEW_RSSI, -200); |
| 1146 | int newSignalLevel = WifiManager.calculateSignalLevel(newRssi, |
| 1147 | sWifiSignalImages.length); |
| 1148 | if (newSignalLevel != mLastWifiSignalLevel) { |
| 1149 | mLastWifiSignalLevel = newSignalLevel; |
| 1150 | if (mIsWifiConnected) { |
| 1151 | mWifiData.iconId = sWifiSignalImages[newSignalLevel]; |
| 1152 | } else { |
| 1153 | mWifiData.iconId = sWifiTemporarilyNotConnectedImage; |
| 1154 | } |
| 1155 | mService.updateIcon(mWifiIcon, mWifiData, null); |
| 1156 | } |
| 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | private final void updateGps(Intent intent) { |
| 1161 | final String action = intent.getAction(); |
| 1162 | final boolean enabled = intent.getBooleanExtra(GpsLocationProvider.EXTRA_ENABLED, false); |
| 1163 | |
| 1164 | if (action.equals(GpsLocationProvider.GPS_FIX_CHANGE_ACTION) && enabled) { |
| 1165 | // GPS is getting fixes |
| 1166 | mService.updateIcon(mGpsIcon, mGpsFixIconData, null); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1167 | mService.setIconVisibility(mGpsIcon, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1168 | } else if (action.equals(GpsLocationProvider.GPS_ENABLED_CHANGE_ACTION) && !enabled) { |
| 1169 | // GPS is off |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1170 | mService.setIconVisibility(mGpsIcon, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1171 | } else { |
| 1172 | // GPS is on, but not receiving fixes |
| 1173 | mService.updateIcon(mGpsIcon, mGpsEnabledIconData, null); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1174 | mService.setIconVisibility(mGpsIcon, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1175 | } |
| 1176 | } |
| 1177 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1178 | private final void updateTTY(Intent intent) { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 1179 | final String action = intent.getAction(); |
| 1180 | final boolean enabled = intent.getBooleanExtra(TtyIntent.TTY_ENABLED, false); |
| 1181 | |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 1182 | if (false) Log.v(TAG, "updateTTY: enabled: " + enabled); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 1183 | |
| 1184 | if (enabled) { |
| 1185 | // TTY is on |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 1186 | if (false) Log.v(TAG, "updateTTY: set TTY on"); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 1187 | mService.updateIcon(mTTYModeIcon, mTTYModeEnableIconData, null); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1188 | mService.setIconVisibility(mTTYModeIcon, true); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 1189 | } else { |
| 1190 | // TTY is off |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 1191 | if (false) Log.v(TAG, "updateTTY: set TTY off"); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1192 | mService.setIconVisibility(mTTYModeIcon, false); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 1193 | } |
| 1194 | } |
| 1195 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1196 | private final void updateCdmaRoamingIcon() { |
| 1197 | if (!hasService()) { |
| 1198 | mService.setIconVisibility(mCdmaRoamingIndicatorIcon, false); |
Wink Saville | f315238 | 2009-06-01 14:39:20 -0700 | [diff] [blame] | 1199 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | if (!isCdma()) { |
| 1203 | mService.setIconVisibility(mCdmaRoamingIndicatorIcon, false); |
Wink Saville | f315238 | 2009-06-01 14:39:20 -0700 | [diff] [blame] | 1204 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | int[] iconList = sRoamingIndicatorImages_cdma; |
| 1208 | int iconIndex = mPhone.getCdmaEriIconIndex(); |
| 1209 | int iconMode = mPhone.getCdmaEriIconMode(); |
| 1210 | |
| 1211 | if (iconIndex == -1) { |
| 1212 | Log.e(TAG, "getCdmaEriIconIndex returned null, skipping ERI icon update"); |
| 1213 | return; |
| 1214 | } |
| 1215 | |
| 1216 | if (iconMode == -1) { |
| 1217 | Log.e(TAG, "getCdmeEriIconMode returned null, skipping ERI icon update"); |
| 1218 | return; |
| 1219 | } |
| 1220 | |
| 1221 | if (iconIndex == EriInfo.ROAMING_INDICATOR_OFF) { |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 1222 | if (false) Log.v(TAG, "Cdma ROAMING_INDICATOR_OFF, removing ERI icon"); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1223 | mService.setIconVisibility(mCdmaRoamingIndicatorIcon, false); |
| 1224 | return; |
| 1225 | } |
| 1226 | |
| 1227 | switch (iconMode) { |
| 1228 | case EriInfo.ROAMING_ICON_MODE_NORMAL: |
| 1229 | mCdmaRoamingIndicatorIconData.iconId = iconList[iconIndex]; |
| 1230 | mService.updateIcon(mCdmaRoamingIndicatorIcon, mCdmaRoamingIndicatorIconData, null); |
| 1231 | mService.setIconVisibility(mCdmaRoamingIndicatorIcon, true); |
| 1232 | break; |
| 1233 | case EriInfo.ROAMING_ICON_MODE_FLASH: |
Wink Saville | f315238 | 2009-06-01 14:39:20 -0700 | [diff] [blame] | 1234 | mCdmaRoamingIndicatorIconData.iconId = |
| 1235 | com.android.internal.R.drawable.stat_sys_roaming_cdma_flash; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1236 | mService.updateIcon(mCdmaRoamingIndicatorIcon, mCdmaRoamingIndicatorIconData, null); |
Wink Saville | f315238 | 2009-06-01 14:39:20 -0700 | [diff] [blame] | 1237 | mService.setIconVisibility(mCdmaRoamingIndicatorIcon, true); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1238 | break; |
| 1239 | |
| 1240 | } |
| 1241 | mService.updateIcon(mPhoneIcon, mPhoneData, null); |
| 1242 | } |
| 1243 | |
| 1244 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1245 | private class StatusBarHandler extends Handler { |
| 1246 | @Override |
| 1247 | public void handleMessage(Message msg) { |
| 1248 | switch (msg.what) { |
| 1249 | case EVENT_BATTERY_CLOSE: |
| 1250 | if (msg.arg1 == mBatteryViewSequence) { |
| 1251 | closeLastBatteryView(); |
| 1252 | } |
| 1253 | break; |
| 1254 | } |
| 1255 | } |
| 1256 | } |
| 1257 | } |