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 | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 451 | BluetoothAdapter adapter = |
| 452 | (BluetoothAdapter) mContext.getSystemService(Context.BLUETOOTH_SERVICE); |
| 453 | if (adapter != null) { |
| 454 | mBluetoothEnabled = adapter.isEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 455 | } else { |
| 456 | mBluetoothEnabled = false; |
| 457 | } |
| 458 | mBluetoothA2dpState = BluetoothA2dp.STATE_DISCONNECTED; |
| 459 | mBluetoothHeadsetState = BluetoothHeadset.STATE_DISCONNECTED; |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 460 | mBluetoothPbapState = BluetoothPbap.STATE_DISCONNECTED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 461 | mService.setIconVisibility(mBluetoothIcon, mBluetoothEnabled); |
| 462 | |
| 463 | // Gps status |
| 464 | mGpsEnabledIconData = IconData.makeIcon("gps", |
| 465 | null, com.android.internal.R.drawable.stat_sys_gps_acquiring_anim, 0, 0); |
| 466 | mGpsFixIconData = IconData.makeIcon("gps", |
| 467 | null, com.android.internal.R.drawable.stat_sys_gps_on, 0, 0); |
| 468 | mGpsIcon = service.addIcon(mGpsEnabledIconData, null); |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 469 | service.setIconVisibility(mGpsIcon, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 470 | |
| 471 | // Alarm clock |
| 472 | mAlarmClockIconData = IconData.makeIcon( |
| 473 | "alarm_clock", |
| 474 | null, com.android.internal.R.drawable.stat_notify_alarm, 0, 0); |
| 475 | mAlarmClockIcon = service.addIcon(mAlarmClockIconData, null); |
| 476 | service.setIconVisibility(mAlarmClockIcon, false); |
| 477 | |
| 478 | // Sync state |
| 479 | mSyncActiveIcon = service.addIcon(IconData.makeIcon("sync_active", |
| 480 | null, R.drawable.stat_notify_sync_anim0, 0, 0), null); |
| 481 | mSyncFailingIcon = service.addIcon(IconData.makeIcon("sync_failing", |
| 482 | null, R.drawable.stat_notify_sync_error, 0, 0), null); |
| 483 | service.setIconVisibility(mSyncActiveIcon, false); |
| 484 | service.setIconVisibility(mSyncFailingIcon, false); |
| 485 | |
| 486 | // volume |
| 487 | mVolumeData = IconData.makeIcon("volume", |
| 488 | null, com.android.internal.R.drawable.stat_sys_ringer_silent, 0, 0); |
| 489 | mVolumeIcon = service.addIcon(mVolumeData, null); |
| 490 | service.setIconVisibility(mVolumeIcon, false); |
| 491 | updateVolume(); |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 492 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 493 | IntentFilter filter = new IntentFilter(); |
| 494 | |
| 495 | // Register for Intent broadcasts for... |
| 496 | filter.addAction(Intent.ACTION_TIME_TICK); |
| 497 | filter.addAction(Intent.ACTION_TIME_CHANGED); |
| 498 | filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED); |
| 499 | filter.addAction(Intent.ACTION_BATTERY_CHANGED); |
Mihai Preda | a82842f | 2009-04-29 15:05:56 +0200 | [diff] [blame] | 500 | filter.addAction(Intent.ACTION_BATTERY_LOW); |
Dianne Hackborn | 8ec5b83 | 2009-07-01 21:19:35 -0700 | [diff] [blame] | 501 | filter.addAction(Intent.ACTION_BATTERY_OKAY); |
Mike Lockwood | 69eb0bf | 2009-08-01 23:02:28 -0400 | [diff] [blame] | 502 | filter.addAction(Intent.ACTION_POWER_CONNECTED); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 503 | filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); |
| 504 | filter.addAction(Intent.ACTION_ALARM_CHANGED); |
| 505 | filter.addAction(Intent.ACTION_SYNC_STATE_CHANGED); |
| 506 | filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); |
| 507 | filter.addAction(AudioManager.VIBRATE_SETTING_CHANGED_ACTION); |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 508 | filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 509 | filter.addAction(BluetoothHeadset.ACTION_STATE_CHANGED); |
| 510 | filter.addAction(BluetoothA2dp.ACTION_SINK_STATE_CHANGED); |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 511 | filter.addAction(BluetoothPbap.PBAP_STATE_CHANGED_ACTION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 512 | filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); |
| 513 | filter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION); |
| 514 | filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); |
| 515 | filter.addAction(WifiManager.RSSI_CHANGED_ACTION); |
| 516 | filter.addAction(GpsLocationProvider.GPS_ENABLED_CHANGE_ACTION); |
| 517 | filter.addAction(GpsLocationProvider.GPS_FIX_CHANGE_ACTION); |
| 518 | filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 519 | filter.addAction(TtyIntent.TTY_ENABLED_CHANGE_ACTION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 520 | mContext.registerReceiver(mIntentReceiver, filter, null, mHandler); |
| 521 | } |
| 522 | |
| 523 | public static void installIcons(Context context, StatusBarService service) { |
| 524 | sInstance = new StatusBarPolicy(context, service); |
| 525 | } |
| 526 | |
| 527 | private final void updateClock() { |
| 528 | mCalendar.setTimeInMillis(System.currentTimeMillis()); |
| 529 | mClockData.text = DateFormat.getTimeFormat(mContext) |
| 530 | .format(mCalendar.getTime()); |
| 531 | mService.updateIcon(mClockIcon, mClockData, null); |
| 532 | } |
| 533 | |
| 534 | private final void updateAlarm(Intent intent) { |
| 535 | boolean alarmSet = intent.getBooleanExtra("alarmSet", false); |
| 536 | mService.setIconVisibility(mAlarmClockIcon, alarmSet); |
| 537 | } |
| 538 | |
| 539 | private final void updateSyncState(Intent intent) { |
| 540 | boolean isActive = intent.getBooleanExtra("active", false); |
| 541 | boolean isFailing = intent.getBooleanExtra("failing", false); |
| 542 | mService.setIconVisibility(mSyncActiveIcon, isActive); |
| 543 | // Don't display sync failing icon: BUG 1297963 Set sync error timeout to "never" |
| 544 | //mService.setIconVisibility(mSyncFailingIcon, isFailing && !isActive); |
| 545 | } |
| 546 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 547 | private final void updateBattery(Intent intent) { |
| 548 | mBatteryData.iconId = intent.getIntExtra("icon-small", 0); |
| 549 | mBatteryData.iconLevel = intent.getIntExtra("level", 0); |
| 550 | mService.updateIcon(mBatteryIcon, mBatteryData, null); |
| 551 | |
| 552 | boolean plugged = intent.getIntExtra("plugged", 0) != 0; |
| 553 | int level = intent.getIntExtra("level", -1); |
| 554 | if (false) { |
| 555 | Log.d(TAG, "updateBattery level=" + level |
| 556 | + " plugged=" + plugged |
| 557 | + " mBatteryPlugged=" + mBatteryPlugged |
| 558 | + " mBatteryLevel=" + mBatteryLevel |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 559 | + " mBatteryFirst=" + mBatteryFirst); |
| 560 | } |
| 561 | |
| 562 | boolean oldPlugged = mBatteryPlugged; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 563 | |
| 564 | mBatteryPlugged = plugged; |
| 565 | mBatteryLevel = level; |
| 566 | |
| 567 | if (mBatteryFirst) { |
| 568 | mBatteryFirst = false; |
| 569 | } |
| 570 | /* |
| 571 | * No longer showing the battery view because it draws attention away |
| 572 | * from the USB storage notification. We could still show it when |
| 573 | * connected to a brick, but that could lead to the user into thinking |
| 574 | * the device does not charge when plugged into USB (since he/she would |
| 575 | * not see the same battery screen on USB as he sees on brick). |
| 576 | */ |
| 577 | /* else { |
| 578 | if (plugged && !oldPlugged) { |
| 579 | showBatteryView(); |
| 580 | } |
| 581 | } |
| 582 | */ |
| 583 | if (false) { |
Mihai Preda | a82842f | 2009-04-29 15:05:56 +0200 | [diff] [blame] | 584 | Log.d(TAG, "plugged=" + plugged + " oldPlugged=" + oldPlugged + " level=" + level); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 585 | } |
Mihai Preda | a82842f | 2009-04-29 15:05:56 +0200 | [diff] [blame] | 586 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 587 | |
Mihai Preda | a82842f | 2009-04-29 15:05:56 +0200 | [diff] [blame] | 588 | private void onBatteryLow(Intent intent) { |
| 589 | if (SHOW_LOW_BATTERY_WARNING) { |
| 590 | if (false) { |
| 591 | Log.d(TAG, "mPhoneState=" + mPhoneState |
| 592 | + " mLowBatteryDialog=" + mLowBatteryDialog |
| 593 | + " mBatteryShowLowOnEndCall=" + mBatteryShowLowOnEndCall); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 594 | } |
Mihai Preda | a82842f | 2009-04-29 15:05:56 +0200 | [diff] [blame] | 595 | |
| 596 | if (mPhoneState == TelephonyManager.CALL_STATE_IDLE) { |
| 597 | showLowBatteryWarning(); |
| 598 | } else { |
| 599 | mBatteryShowLowOnEndCall = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 600 | } |
| 601 | } |
| 602 | } |
| 603 | |
Dianne Hackborn | 8ec5b83 | 2009-07-01 21:19:35 -0700 | [diff] [blame] | 604 | private void onBatteryOkay(Intent intent) { |
| 605 | if (mLowBatteryDialog != null |
| 606 | && SHOW_LOW_BATTERY_WARNING) { |
| 607 | mLowBatteryDialog.dismiss(); |
| 608 | mBatteryShowLowOnEndCall = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 609 | } |
| 610 | } |
| 611 | |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 612 | private void showBatteryView() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 613 | closeLastBatteryView(); |
| 614 | if (mLowBatteryDialog != null) { |
| 615 | mLowBatteryDialog.dismiss(); |
| 616 | } |
| 617 | |
| 618 | int level = mBatteryLevel; |
| 619 | |
| 620 | View v = View.inflate(mContext, com.android.internal.R.layout.battery_status, null); |
| 621 | mBatteryView = v; |
| 622 | int pixelFormat = PixelFormat.TRANSLUCENT; |
| 623 | Drawable bg = v.getBackground(); |
| 624 | if (bg != null) { |
| 625 | pixelFormat = bg.getOpacity(); |
| 626 | } |
| 627 | |
| 628 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 629 | ViewGroup.LayoutParams.WRAP_CONTENT, |
| 630 | ViewGroup.LayoutParams.WRAP_CONTENT, |
| 631 | WindowManager.LayoutParams.TYPE_TOAST, |
| 632 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 633 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
| 634 | | WindowManager.LayoutParams.FLAG_BLUR_BEHIND |
| 635 | | WindowManager.LayoutParams.FLAG_DIM_BEHIND, |
| 636 | pixelFormat); |
| 637 | |
| 638 | // Get the dim amount from the theme |
| 639 | TypedArray a = mContext.obtainStyledAttributes( |
| 640 | com.android.internal.R.styleable.Theme); |
| 641 | lp.dimAmount = a.getFloat(android.R.styleable.Theme_backgroundDimAmount, 0.5f); |
| 642 | a.recycle(); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 643 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 644 | lp.setTitle("Battery"); |
| 645 | |
| 646 | TextView levelTextView = (TextView)v.findViewById(com.android.internal.R.id.level_percent); |
| 647 | levelTextView.setText(mContext.getString( |
| 648 | com.android.internal.R.string.battery_status_text_percent_format, level)); |
| 649 | |
| 650 | setBatteryLevel(v, com.android.internal.R.id.spacer, 100-level, 0, 0); |
| 651 | setBatteryLevel(v, com.android.internal.R.id.level, level, |
| 652 | com.android.internal.R.drawable.battery_charge_fill, level); |
| 653 | |
| 654 | WindowManagerImpl.getDefault().addView(v, lp); |
| 655 | |
| 656 | scheduleCloseBatteryView(); |
| 657 | } |
| 658 | |
| 659 | private void setBatteryLevel(View parent, int id, int height, int background, int level) { |
| 660 | ImageView v = (ImageView)parent.findViewById(id); |
| 661 | LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)v.getLayoutParams(); |
| 662 | lp.weight = height; |
| 663 | if (background != 0) { |
| 664 | v.setBackgroundResource(background); |
| 665 | Drawable bkg = v.getBackground(); |
| 666 | bkg.setLevel(level); |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | private void showLowBatteryWarning() { |
| 671 | closeLastBatteryView(); |
| 672 | |
Mike Lockwood | d81b1f4 | 2009-09-25 09:32:19 -0400 | [diff] [blame^] | 673 | // Show exact battery level. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 674 | CharSequence levelText = mContext.getString( |
Mike Lockwood | d81b1f4 | 2009-09-25 09:32:19 -0400 | [diff] [blame^] | 675 | 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] | 676 | |
| 677 | if (mBatteryLevelTextView != null) { |
| 678 | mBatteryLevelTextView.setText(levelText); |
| 679 | } else { |
| 680 | View v = View.inflate(mContext, com.android.internal.R.layout.battery_low, null); |
| 681 | mBatteryLevelTextView=(TextView)v.findViewById(com.android.internal.R.id.level_percent); |
| 682 | |
| 683 | mBatteryLevelTextView.setText(levelText); |
| 684 | |
| 685 | AlertDialog.Builder b = new AlertDialog.Builder(mContext); |
| 686 | b.setCancelable(true); |
| 687 | b.setTitle(com.android.internal.R.string.battery_low_title); |
| 688 | b.setView(v); |
| 689 | b.setIcon(android.R.drawable.ic_dialog_alert); |
| 690 | b.setPositiveButton(android.R.string.ok, null); |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 691 | |
Dianne Hackborn | 3d74bb4 | 2009-06-19 10:35:21 -0700 | [diff] [blame] | 692 | final Intent intent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY); |
| 693 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 694 | | Intent.FLAG_ACTIVITY_MULTIPLE_TASK |
| 695 | | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS |
| 696 | | Intent.FLAG_ACTIVITY_NO_HISTORY); |
| 697 | if (intent.resolveActivity(mContext.getPackageManager()) != null) { |
| 698 | b.setNegativeButton(com.android.internal.R.string.battery_low_why, |
| 699 | new DialogInterface.OnClickListener() { |
| 700 | public void onClick(DialogInterface dialog, int which) { |
| 701 | mContext.startActivity(intent); |
| 702 | if (mLowBatteryDialog != null) { |
| 703 | mLowBatteryDialog.dismiss(); |
| 704 | } |
| 705 | } |
| 706 | }); |
| 707 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 708 | |
| 709 | AlertDialog d = b.create(); |
| 710 | d.setOnDismissListener(mLowBatteryListener); |
| 711 | d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); |
| 712 | d.show(); |
| 713 | mLowBatteryDialog = d; |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | private final void updateCallState(int state) { |
| 718 | mPhoneState = state; |
| 719 | if (false) { |
| 720 | Log.d(TAG, "mPhoneState=" + mPhoneState |
| 721 | + " mLowBatteryDialog=" + mLowBatteryDialog |
| 722 | + " mBatteryShowLowOnEndCall=" + mBatteryShowLowOnEndCall); |
| 723 | } |
| 724 | if (mPhoneState == TelephonyManager.CALL_STATE_IDLE) { |
| 725 | if (mBatteryShowLowOnEndCall) { |
| 726 | if (!mBatteryPlugged) { |
| 727 | showLowBatteryWarning(); |
| 728 | } |
| 729 | mBatteryShowLowOnEndCall = false; |
| 730 | } |
| 731 | } else { |
| 732 | if (mLowBatteryDialog != null) { |
| 733 | mLowBatteryDialog.dismiss(); |
| 734 | mBatteryShowLowOnEndCall = true; |
| 735 | } |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | private DialogInterface.OnDismissListener mLowBatteryListener |
| 740 | = new DialogInterface.OnDismissListener() { |
| 741 | public void onDismiss(DialogInterface dialog) { |
| 742 | mLowBatteryDialog = null; |
| 743 | mBatteryLevelTextView = null; |
| 744 | } |
| 745 | }; |
| 746 | |
| 747 | private void scheduleCloseBatteryView() { |
| 748 | Message m = mHandler.obtainMessage(EVENT_BATTERY_CLOSE); |
| 749 | m.arg1 = (++mBatteryViewSequence); |
| 750 | mHandler.sendMessageDelayed(m, 3000); |
| 751 | } |
| 752 | |
| 753 | private void closeLastBatteryView() { |
| 754 | if (mBatteryView != null) { |
| 755 | //mBatteryView.debug(); |
| 756 | WindowManagerImpl.getDefault().removeView(mBatteryView); |
| 757 | mBatteryView = null; |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | private PhoneStateListener mPhoneStateListener = new PhoneStateListener() { |
| 762 | @Override |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 763 | public void onSignalStrengthsChanged(SignalStrength signalStrength) { |
| 764 | mSignalStrength = signalStrength; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 765 | updateSignalStrength(); |
| 766 | } |
| 767 | |
| 768 | @Override |
| 769 | public void onServiceStateChanged(ServiceState state) { |
| 770 | mServiceState = state; |
| 771 | updateSignalStrength(); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 772 | updateCdmaRoamingIcon(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 773 | updateDataIcon(); |
| 774 | } |
| 775 | |
| 776 | @Override |
| 777 | public void onCallStateChanged(int state, String incomingNumber) { |
| 778 | updateCallState(state); |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 779 | // In cdma, if a voice call is made, RSSI should switch to 1x. |
| 780 | if (isCdma()) { |
| 781 | updateSignalStrength(); |
| 782 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | @Override |
| 786 | public void onDataConnectionStateChanged(int state) { |
| 787 | mDataState = state; |
| 788 | updateDataNetType(); |
| 789 | updateDataIcon(); |
| 790 | } |
| 791 | |
| 792 | @Override |
| 793 | public void onDataActivity(int direction) { |
| 794 | mDataActivity = direction; |
| 795 | updateDataIcon(); |
| 796 | } |
| 797 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 798 | |
| 799 | private final void updateSimState(Intent intent) { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 800 | String stateExtra = intent.getStringExtra(IccCard.INTENT_KEY_ICC_STATE); |
| 801 | if (IccCard.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) { |
| 802 | mSimState = IccCard.State.ABSENT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 803 | } |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 804 | else if (IccCard.INTENT_VALUE_ICC_READY.equals(stateExtra)) { |
| 805 | mSimState = IccCard.State.READY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 806 | } |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 807 | else if (IccCard.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) { |
| 808 | final String lockedReason = intent.getStringExtra(IccCard.INTENT_KEY_LOCKED_REASON); |
| 809 | if (IccCard.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) { |
| 810 | mSimState = IccCard.State.PIN_REQUIRED; |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 811 | } |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 812 | else if (IccCard.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) { |
| 813 | mSimState = IccCard.State.PUK_REQUIRED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 814 | } |
| 815 | else { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 816 | mSimState = IccCard.State.NETWORK_LOCKED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 817 | } |
| 818 | } else { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 819 | mSimState = IccCard.State.UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 820 | } |
| 821 | updateDataIcon(); |
| 822 | } |
| 823 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 824 | private boolean isCdma() { |
Wink Saville | f315238 | 2009-06-01 14:39:20 -0700 | [diff] [blame] | 825 | return ((mPhone != null) && (mPhone.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA)); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 826 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 827 | |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 828 | private boolean isEvdo() { |
| 829 | return ( (mServiceState != null) |
| 830 | && ((mServiceState.getRadioTechnology() |
| 831 | == ServiceState.RADIO_TECHNOLOGY_EVDO_0) |
| 832 | || (mServiceState.getRadioTechnology() |
| 833 | == ServiceState.RADIO_TECHNOLOGY_EVDO_A))); |
| 834 | } |
| 835 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 836 | private boolean hasService() { |
| 837 | if (mServiceState != null) { |
| 838 | switch (mServiceState.getState()) { |
| 839 | case ServiceState.STATE_OUT_OF_SERVICE: |
| 840 | case ServiceState.STATE_POWER_OFF: |
| 841 | return false; |
| 842 | default: |
| 843 | return true; |
| 844 | } |
| 845 | } else { |
| 846 | return false; |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | private final void updateSignalStrength() { |
| 851 | int iconLevel = -1; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 852 | int[] iconList; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 853 | |
| 854 | if (!hasService()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 855 | //Log.d(TAG, "updateSignalStrength: no service"); |
| 856 | if (Settings.System.getInt(mContext.getContentResolver(), |
| 857 | Settings.System.AIRPLANE_MODE_ON, 0) == 1) { |
| 858 | mPhoneData.iconId = com.android.internal.R.drawable.stat_sys_signal_flightmode; |
| 859 | } else { |
| 860 | mPhoneData.iconId = com.android.internal.R.drawable.stat_sys_signal_null; |
| 861 | } |
| 862 | mService.updateIcon(mPhoneIcon, mPhoneData, null); |
| 863 | return; |
| 864 | } |
| 865 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 866 | if (!isCdma()) { |
| 867 | int asu = mSignalStrength.getGsmSignalStrength(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 868 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 869 | // ASU ranges from 0 to 31 - TS 27.007 Sec 8.5 |
| 870 | // asu = 0 (-113dB or less) is very weak |
| 871 | // signal, its better to show 0 bars to the user in such cases. |
| 872 | // asu = 99 is a special case, where the signal strength is unknown. |
| 873 | if (asu <= 0 || asu == 99) iconLevel = 0; |
| 874 | else if (asu >= 16) iconLevel = 4; |
| 875 | else if (asu >= 8) iconLevel = 3; |
| 876 | else if (asu >= 4) iconLevel = 2; |
| 877 | else iconLevel = 1; |
| 878 | |
| 879 | if (mPhone.isNetworkRoaming()) { |
| 880 | iconList = sSignalImages_r; |
| 881 | } else { |
| 882 | iconList = sSignalImages; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 883 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 884 | } else { |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 885 | iconList = this.sSignalImages; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 886 | |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 887 | // If 3G(EV) and 1x network are available than 3G should be |
| 888 | // displayed, displayed RSSI should be from the EV side. |
| 889 | // If a voice call is made then RSSI should switch to 1x. |
| 890 | if ((mPhoneState == TelephonyManager.CALL_STATE_IDLE) && isEvdo()){ |
| 891 | iconLevel = getEvdoLevel(); |
| 892 | if (false) { |
| 893 | Log.d(TAG, "use Evdo level=" + iconLevel + " to replace Cdma Level=" + getCdmaLevel()); |
| 894 | } |
| 895 | } else { |
| 896 | iconLevel = getCdmaLevel(); |
| 897 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 898 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 899 | mPhoneData.iconId = iconList[iconLevel]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 900 | mService.updateIcon(mPhoneIcon, mPhoneData, null); |
| 901 | } |
| 902 | |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 903 | private int getCdmaLevel() { |
| 904 | final int cdmaDbm = mSignalStrength.getCdmaDbm(); |
| 905 | final int cdmaEcio = mSignalStrength.getCdmaEcio(); |
| 906 | int levelDbm = 0; |
| 907 | int levelEcio = 0; |
| 908 | |
| 909 | if (cdmaDbm >= -75) levelDbm = 4; |
| 910 | else if (cdmaDbm >= -85) levelDbm = 3; |
| 911 | else if (cdmaDbm >= -95) levelDbm = 2; |
| 912 | else if (cdmaDbm >= -100) levelDbm = 1; |
| 913 | else levelDbm = 0; |
| 914 | |
| 915 | // Ec/Io are in dB*10 |
| 916 | if (cdmaEcio >= -90) levelEcio = 4; |
| 917 | else if (cdmaEcio >= -110) levelEcio = 3; |
| 918 | else if (cdmaEcio >= -130) levelEcio = 2; |
| 919 | else if (cdmaEcio >= -150) levelEcio = 1; |
| 920 | else levelEcio = 0; |
| 921 | |
| 922 | return (levelDbm < levelEcio) ? levelDbm : levelEcio; |
| 923 | } |
| 924 | |
| 925 | private int getEvdoLevel() { |
| 926 | int evdoDbm = mSignalStrength.getEvdoDbm(); |
| 927 | int evdoSnr = mSignalStrength.getEvdoSnr(); |
| 928 | int levelEvdoDbm = 0; |
| 929 | int levelEvdoSnr = 0; |
| 930 | |
| 931 | if (evdoDbm >= -65) levelEvdoDbm = 4; |
| 932 | else if (evdoDbm >= -75) levelEvdoDbm = 3; |
| 933 | else if (evdoDbm >= -90) levelEvdoDbm = 2; |
| 934 | else if (evdoDbm >= -105) levelEvdoDbm = 1; |
| 935 | else levelEvdoDbm = 0; |
| 936 | |
| 937 | if (evdoSnr > 7) levelEvdoSnr = 4; |
| 938 | else if (evdoSnr > 5) levelEvdoSnr = 3; |
| 939 | else if (evdoSnr > 3) levelEvdoSnr = 2; |
| 940 | else if (evdoSnr > 1) levelEvdoSnr = 1; |
| 941 | else levelEvdoSnr = 0; |
| 942 | |
| 943 | return (levelEvdoDbm < levelEvdoSnr) ? levelEvdoDbm : levelEvdoSnr; |
| 944 | } |
| 945 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 946 | private final void updateDataNetType() { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 947 | int net = mPhone.getNetworkType(); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 948 | |
| 949 | switch (net) { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 950 | case TelephonyManager.NETWORK_TYPE_EDGE: |
| 951 | mDataIconList = sDataNetType_e; |
| 952 | break; |
| 953 | case TelephonyManager.NETWORK_TYPE_UMTS: |
| 954 | mDataIconList = sDataNetType_3g; |
| 955 | break; |
Li Zhe | ebe6634 | 2009-08-14 19:22:16 +0800 | [diff] [blame] | 956 | case TelephonyManager.NETWORK_TYPE_HSDPA: |
| 957 | case TelephonyManager.NETWORK_TYPE_HSUPA: |
| 958 | case TelephonyManager.NETWORK_TYPE_HSPA: |
| 959 | mDataIconList = sDataNetType_h; |
| 960 | break; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 961 | case TelephonyManager.NETWORK_TYPE_CDMA: |
| 962 | // display 1xRTT for IS95A/B |
johnwang | 9f87cb2 | 2009-08-25 15:25:37 -0700 | [diff] [blame] | 963 | mDataIconList = this.sDataNetType_1x; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 964 | break; |
| 965 | case TelephonyManager.NETWORK_TYPE_1xRTT: |
johnwang | 9f87cb2 | 2009-08-25 15:25:37 -0700 | [diff] [blame] | 966 | mDataIconList = this.sDataNetType_1x; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 967 | break; |
| 968 | case TelephonyManager.NETWORK_TYPE_EVDO_0: //fall through |
| 969 | case TelephonyManager.NETWORK_TYPE_EVDO_A: |
johnwang | 9f87cb2 | 2009-08-25 15:25:37 -0700 | [diff] [blame] | 970 | mDataIconList = sDataNetType_3g; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 971 | break; |
| 972 | default: |
| 973 | mDataIconList = sDataNetType_g; |
| 974 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 975 | } |
| 976 | } |
| 977 | |
| 978 | private final void updateDataIcon() { |
| 979 | int iconId; |
| 980 | boolean visible = true; |
| 981 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 982 | if (!isCdma()) { |
| 983 | // GSM case, we have to check also the sim state |
| 984 | if (mSimState == IccCard.State.READY || mSimState == IccCard.State.UNKNOWN) { |
| 985 | if (hasService() && mDataState == TelephonyManager.DATA_CONNECTED) { |
| 986 | switch (mDataActivity) { |
| 987 | case TelephonyManager.DATA_ACTIVITY_IN: |
| 988 | iconId = mDataIconList[1]; |
| 989 | break; |
| 990 | case TelephonyManager.DATA_ACTIVITY_OUT: |
| 991 | iconId = mDataIconList[2]; |
| 992 | break; |
| 993 | case TelephonyManager.DATA_ACTIVITY_INOUT: |
| 994 | iconId = mDataIconList[3]; |
| 995 | break; |
| 996 | default: |
| 997 | iconId = mDataIconList[0]; |
| 998 | break; |
| 999 | } |
| 1000 | mDataData.iconId = iconId; |
| 1001 | mService.updateIcon(mDataIcon, mDataData, null); |
| 1002 | } else { |
| 1003 | visible = false; |
| 1004 | } |
| 1005 | } else { |
| 1006 | mDataData.iconId = com.android.internal.R.drawable.stat_sys_no_sim; |
| 1007 | mService.updateIcon(mDataIcon, mDataData, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1008 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1009 | } else { |
| 1010 | // CDMA case, mDataActivity can be also DATA_ACTIVITY_DORMANT |
| 1011 | if (hasService() && mDataState == TelephonyManager.DATA_CONNECTED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1012 | switch (mDataActivity) { |
| 1013 | case TelephonyManager.DATA_ACTIVITY_IN: |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1014 | iconId = mDataIconList[1]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1015 | break; |
| 1016 | case TelephonyManager.DATA_ACTIVITY_OUT: |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1017 | iconId = mDataIconList[2]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1018 | break; |
| 1019 | case TelephonyManager.DATA_ACTIVITY_INOUT: |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1020 | iconId = mDataIconList[3]; |
| 1021 | break; |
| 1022 | case TelephonyManager.DATA_ACTIVITY_DORMANT: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1023 | default: |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1024 | iconId = mDataIconList[0]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1025 | break; |
| 1026 | } |
| 1027 | mDataData.iconId = iconId; |
| 1028 | mService.updateIcon(mDataIcon, mDataData, null); |
| 1029 | } else { |
| 1030 | visible = false; |
| 1031 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1032 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1033 | |
Dianne Hackborn | 4840e14 | 2009-03-24 22:40:29 -0700 | [diff] [blame] | 1034 | long ident = Binder.clearCallingIdentity(); |
| 1035 | try { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 1036 | mBatteryStats.notePhoneDataConnectionState(mPhone.getNetworkType(), visible); |
Dianne Hackborn | 4840e14 | 2009-03-24 22:40:29 -0700 | [diff] [blame] | 1037 | } catch (RemoteException e) { |
| 1038 | } finally { |
| 1039 | Binder.restoreCallingIdentity(ident); |
| 1040 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1041 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1042 | if (mDataIconVisible != visible) { |
| 1043 | mService.setIconVisibility(mDataIcon, visible); |
| 1044 | mDataIconVisible = visible; |
| 1045 | } |
| 1046 | } |
| 1047 | |
| 1048 | private final void updateVolume() { |
| 1049 | AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); |
| 1050 | final int ringerMode = audioManager.getRingerMode(); |
| 1051 | final boolean visible = ringerMode == AudioManager.RINGER_MODE_SILENT || |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1052 | ringerMode == AudioManager.RINGER_MODE_VIBRATE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1053 | final int iconId = audioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER) |
| 1054 | ? com.android.internal.R.drawable.stat_sys_ringer_vibrate |
| 1055 | : com.android.internal.R.drawable.stat_sys_ringer_silent; |
| 1056 | |
| 1057 | if (visible) { |
| 1058 | mVolumeData.iconId = iconId; |
| 1059 | mService.updateIcon(mVolumeIcon, mVolumeData, null); |
| 1060 | } |
| 1061 | if (visible != mVolumeVisible) { |
| 1062 | mService.setIconVisibility(mVolumeIcon, visible); |
| 1063 | mVolumeVisible = visible; |
| 1064 | } |
| 1065 | } |
| 1066 | |
| 1067 | private final void updateBluetooth(Intent intent) { |
| 1068 | int iconId = com.android.internal.R.drawable.stat_sys_data_bluetooth; |
| 1069 | |
| 1070 | String action = intent.getAction(); |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 1071 | if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { |
Nick Pelly | b24e11b | 2009-09-08 17:40:43 -0700 | [diff] [blame] | 1072 | int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR); |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 1073 | mBluetoothEnabled = state == BluetoothAdapter.STATE_ON; |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 1074 | } else if (action.equals(BluetoothHeadset.ACTION_STATE_CHANGED)) { |
| 1075 | mBluetoothHeadsetState = intent.getIntExtra(BluetoothHeadset.EXTRA_STATE, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1076 | BluetoothHeadset.STATE_ERROR); |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 1077 | } else if (action.equals(BluetoothA2dp.ACTION_SINK_STATE_CHANGED)) { |
| 1078 | mBluetoothA2dpState = intent.getIntExtra(BluetoothA2dp.EXTRA_SINK_STATE, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1079 | BluetoothA2dp.STATE_DISCONNECTED); |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 1080 | } else if (action.equals(BluetoothPbap.PBAP_STATE_CHANGED_ACTION)) { |
| 1081 | mBluetoothPbapState = intent.getIntExtra(BluetoothPbap.PBAP_STATE, |
| 1082 | BluetoothPbap.STATE_DISCONNECTED); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1083 | } else { |
| 1084 | return; |
| 1085 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1086 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1087 | if (mBluetoothHeadsetState == BluetoothHeadset.STATE_CONNECTED || |
| 1088 | mBluetoothA2dpState == BluetoothA2dp.STATE_CONNECTED || |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 1089 | mBluetoothA2dpState == BluetoothA2dp.STATE_PLAYING || |
| 1090 | mBluetoothPbapState == BluetoothPbap.STATE_CONNECTED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1091 | iconId = com.android.internal.R.drawable.stat_sys_data_bluetooth_connected; |
| 1092 | } |
| 1093 | |
| 1094 | mBluetoothData.iconId = iconId; |
| 1095 | mService.updateIcon(mBluetoothIcon, mBluetoothData, null); |
| 1096 | mService.setIconVisibility(mBluetoothIcon, mBluetoothEnabled); |
| 1097 | } |
| 1098 | |
| 1099 | private final void updateWifi(Intent intent) { |
| 1100 | final String action = intent.getAction(); |
| 1101 | if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1102 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1103 | final boolean enabled = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, |
| 1104 | WifiManager.WIFI_STATE_UNKNOWN) == WifiManager.WIFI_STATE_ENABLED; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1105 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1106 | if (!enabled) { |
| 1107 | // If disabled, hide the icon. (We show icon when connected.) |
| 1108 | mService.setIconVisibility(mWifiIcon, false); |
| 1109 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1110 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1111 | } else if (action.equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)) { |
| 1112 | final boolean enabled = intent.getBooleanExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED, |
| 1113 | false); |
| 1114 | if (!enabled) { |
| 1115 | mService.setIconVisibility(mWifiIcon, false); |
| 1116 | } |
| 1117 | } else if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) { |
| 1118 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1119 | final NetworkInfo networkInfo = (NetworkInfo) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1120 | intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1121 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1122 | int iconId; |
| 1123 | if (networkInfo != null && networkInfo.isConnected()) { |
| 1124 | mIsWifiConnected = true; |
| 1125 | if (mLastWifiSignalLevel == -1) { |
| 1126 | iconId = sWifiSignalImages[0]; |
| 1127 | } else { |
| 1128 | iconId = sWifiSignalImages[mLastWifiSignalLevel]; |
| 1129 | } |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 1130 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1131 | // Show the icon since wi-fi is connected |
| 1132 | mService.setIconVisibility(mWifiIcon, true); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 1133 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1134 | } else { |
| 1135 | mLastWifiSignalLevel = -1; |
| 1136 | mIsWifiConnected = false; |
| 1137 | iconId = sWifiSignalImages[0]; |
| 1138 | |
| 1139 | // Hide the icon since we're not connected |
| 1140 | mService.setIconVisibility(mWifiIcon, false); |
| 1141 | } |
| 1142 | |
| 1143 | mWifiData.iconId = iconId; |
| 1144 | mService.updateIcon(mWifiIcon, mWifiData, null); |
| 1145 | } else if (action.equals(WifiManager.RSSI_CHANGED_ACTION)) { |
| 1146 | final int newRssi = intent.getIntExtra(WifiManager.EXTRA_NEW_RSSI, -200); |
| 1147 | int newSignalLevel = WifiManager.calculateSignalLevel(newRssi, |
| 1148 | sWifiSignalImages.length); |
| 1149 | if (newSignalLevel != mLastWifiSignalLevel) { |
| 1150 | mLastWifiSignalLevel = newSignalLevel; |
| 1151 | if (mIsWifiConnected) { |
| 1152 | mWifiData.iconId = sWifiSignalImages[newSignalLevel]; |
| 1153 | } else { |
| 1154 | mWifiData.iconId = sWifiTemporarilyNotConnectedImage; |
| 1155 | } |
| 1156 | mService.updateIcon(mWifiIcon, mWifiData, null); |
| 1157 | } |
| 1158 | } |
| 1159 | } |
| 1160 | |
| 1161 | private final void updateGps(Intent intent) { |
| 1162 | final String action = intent.getAction(); |
| 1163 | final boolean enabled = intent.getBooleanExtra(GpsLocationProvider.EXTRA_ENABLED, false); |
| 1164 | |
| 1165 | if (action.equals(GpsLocationProvider.GPS_FIX_CHANGE_ACTION) && enabled) { |
| 1166 | // GPS is getting fixes |
| 1167 | mService.updateIcon(mGpsIcon, mGpsFixIconData, null); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1168 | mService.setIconVisibility(mGpsIcon, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1169 | } else if (action.equals(GpsLocationProvider.GPS_ENABLED_CHANGE_ACTION) && !enabled) { |
| 1170 | // GPS is off |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1171 | mService.setIconVisibility(mGpsIcon, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1172 | } else { |
| 1173 | // GPS is on, but not receiving fixes |
| 1174 | mService.updateIcon(mGpsIcon, mGpsEnabledIconData, null); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1175 | mService.setIconVisibility(mGpsIcon, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1176 | } |
| 1177 | } |
| 1178 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1179 | private final void updateTTY(Intent intent) { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 1180 | final String action = intent.getAction(); |
| 1181 | final boolean enabled = intent.getBooleanExtra(TtyIntent.TTY_ENABLED, false); |
| 1182 | |
| 1183 | Log.i(TAG, "updateTTY: enabled: " + enabled); |
| 1184 | |
| 1185 | if (enabled) { |
| 1186 | // TTY is on |
| 1187 | Log.i(TAG, "updateTTY: set TTY on"); |
| 1188 | mService.updateIcon(mTTYModeIcon, mTTYModeEnableIconData, null); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1189 | mService.setIconVisibility(mTTYModeIcon, true); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 1190 | } else { |
| 1191 | // TTY is off |
| 1192 | Log.i(TAG, "updateTTY: set TTY off"); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1193 | mService.setIconVisibility(mTTYModeIcon, false); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 1194 | } |
| 1195 | } |
| 1196 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1197 | private final void updateCdmaRoamingIcon() { |
| 1198 | if (!hasService()) { |
| 1199 | mService.setIconVisibility(mCdmaRoamingIndicatorIcon, false); |
Wink Saville | f315238 | 2009-06-01 14:39:20 -0700 | [diff] [blame] | 1200 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | if (!isCdma()) { |
| 1204 | mService.setIconVisibility(mCdmaRoamingIndicatorIcon, false); |
Wink Saville | f315238 | 2009-06-01 14:39:20 -0700 | [diff] [blame] | 1205 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1206 | } |
| 1207 | |
| 1208 | int[] iconList = sRoamingIndicatorImages_cdma; |
| 1209 | int iconIndex = mPhone.getCdmaEriIconIndex(); |
| 1210 | int iconMode = mPhone.getCdmaEriIconMode(); |
| 1211 | |
| 1212 | if (iconIndex == -1) { |
| 1213 | Log.e(TAG, "getCdmaEriIconIndex returned null, skipping ERI icon update"); |
| 1214 | return; |
| 1215 | } |
| 1216 | |
| 1217 | if (iconMode == -1) { |
| 1218 | Log.e(TAG, "getCdmeEriIconMode returned null, skipping ERI icon update"); |
| 1219 | return; |
| 1220 | } |
| 1221 | |
| 1222 | if (iconIndex == EriInfo.ROAMING_INDICATOR_OFF) { |
| 1223 | Log.d(TAG, "Cdma ROAMING_INDICATOR_OFF, removing ERI icon"); |
| 1224 | mService.setIconVisibility(mCdmaRoamingIndicatorIcon, false); |
| 1225 | return; |
| 1226 | } |
| 1227 | |
| 1228 | switch (iconMode) { |
| 1229 | case EriInfo.ROAMING_ICON_MODE_NORMAL: |
| 1230 | mCdmaRoamingIndicatorIconData.iconId = iconList[iconIndex]; |
| 1231 | mService.updateIcon(mCdmaRoamingIndicatorIcon, mCdmaRoamingIndicatorIconData, null); |
| 1232 | mService.setIconVisibility(mCdmaRoamingIndicatorIcon, true); |
| 1233 | break; |
| 1234 | case EriInfo.ROAMING_ICON_MODE_FLASH: |
Wink Saville | f315238 | 2009-06-01 14:39:20 -0700 | [diff] [blame] | 1235 | mCdmaRoamingIndicatorIconData.iconId = |
| 1236 | com.android.internal.R.drawable.stat_sys_roaming_cdma_flash; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1237 | mService.updateIcon(mCdmaRoamingIndicatorIcon, mCdmaRoamingIndicatorIconData, null); |
Wink Saville | f315238 | 2009-06-01 14:39:20 -0700 | [diff] [blame] | 1238 | mService.setIconVisibility(mCdmaRoamingIndicatorIcon, true); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1239 | break; |
| 1240 | |
| 1241 | } |
| 1242 | mService.updateIcon(mPhoneIcon, mPhoneData, null); |
| 1243 | } |
| 1244 | |
| 1245 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1246 | private class StatusBarHandler extends Handler { |
| 1247 | @Override |
| 1248 | public void handleMessage(Message msg) { |
| 1249 | switch (msg.what) { |
| 1250 | case EVENT_BATTERY_CLOSE: |
| 1251 | if (msg.arg1 == mBatteryViewSequence) { |
| 1252 | closeLastBatteryView(); |
| 1253 | } |
| 1254 | break; |
| 1255 | } |
| 1256 | } |
| 1257 | } |
| 1258 | } |