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; |
John Wang | 33e21fc | 2009-10-08 10:35:27 -0700 | [diff] [blame] | 275 | private boolean mHspaDataDistinguishable; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 276 | |
| 277 | // ringer volume |
| 278 | private IBinder mVolumeIcon; |
| 279 | private IconData mVolumeData; |
| 280 | private boolean mVolumeVisible; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 281 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 282 | // bluetooth device status |
| 283 | private IBinder mBluetoothIcon; |
| 284 | private IconData mBluetoothData; |
| 285 | private int mBluetoothHeadsetState; |
| 286 | private int mBluetoothA2dpState; |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 287 | private int mBluetoothPbapState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 288 | private boolean mBluetoothEnabled; |
| 289 | |
| 290 | // wifi |
| 291 | private static final int[] sWifiSignalImages = new int[] { |
| 292 | com.android.internal.R.drawable.stat_sys_wifi_signal_1, |
| 293 | com.android.internal.R.drawable.stat_sys_wifi_signal_2, |
| 294 | com.android.internal.R.drawable.stat_sys_wifi_signal_3, |
| 295 | com.android.internal.R.drawable.stat_sys_wifi_signal_4, |
| 296 | }; |
| 297 | private static final int sWifiTemporarilyNotConnectedImage = |
| 298 | com.android.internal.R.drawable.stat_sys_wifi_signal_0; |
| 299 | |
| 300 | private int mLastWifiSignalLevel = -1; |
| 301 | private boolean mIsWifiConnected = false; |
| 302 | private IBinder mWifiIcon; |
| 303 | private IconData mWifiData; |
| 304 | |
| 305 | // gps |
| 306 | private IBinder mGpsIcon; |
| 307 | private IconData mGpsEnabledIconData; |
| 308 | private IconData mGpsFixIconData; |
| 309 | |
| 310 | // alarm clock |
| 311 | // Icon lit when clock is set |
| 312 | private IBinder mAlarmClockIcon; |
| 313 | private IconData mAlarmClockIconData; |
| 314 | |
| 315 | // sync state |
| 316 | // If sync is active the SyncActive icon is displayed. If sync is not active but |
| 317 | // sync is failing the SyncFailing icon is displayed. Otherwise neither are displayed. |
| 318 | private IBinder mSyncActiveIcon; |
| 319 | private IBinder mSyncFailingIcon; |
| 320 | |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 321 | // TTY mode |
| 322 | // Icon lit when TTY mode is enabled |
| 323 | private IBinder mTTYModeIcon; |
| 324 | private IconData mTTYModeEnableIconData; |
| 325 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 326 | // Cdma Roaming Indicator, ERI |
| 327 | private IBinder mCdmaRoamingIndicatorIcon; |
| 328 | private IconData mCdmaRoamingIndicatorIconData; |
| 329 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 330 | private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { |
| 331 | @Override |
| 332 | public void onReceive(Context context, Intent intent) { |
| 333 | String action = intent.getAction(); |
| 334 | if (action.equals(Intent.ACTION_TIME_TICK)) { |
| 335 | updateClock(); |
| 336 | } |
| 337 | else if (action.equals(Intent.ACTION_TIME_CHANGED)) { |
| 338 | updateClock(); |
| 339 | } |
Dianne Hackborn | 8ec5b83 | 2009-07-01 21:19:35 -0700 | [diff] [blame] | 340 | else if (action.equals(Intent.ACTION_BATTERY_CHANGED)) { |
| 341 | updateBattery(intent); |
| 342 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 343 | else if (action.equals(Intent.ACTION_CONFIGURATION_CHANGED)) { |
| 344 | updateClock(); |
| 345 | } |
| 346 | else if (action.equals(Intent.ACTION_TIMEZONE_CHANGED)) { |
| 347 | String tz = intent.getStringExtra("time-zone"); |
| 348 | mCalendar = Calendar.getInstance(TimeZone.getTimeZone(tz)); |
| 349 | updateClock(); |
| 350 | } |
| 351 | else if (action.equals(Intent.ACTION_ALARM_CHANGED)) { |
| 352 | updateAlarm(intent); |
| 353 | } |
| 354 | else if (action.equals(Intent.ACTION_SYNC_STATE_CHANGED)) { |
| 355 | updateSyncState(intent); |
| 356 | } |
Mihai Preda | a82842f | 2009-04-29 15:05:56 +0200 | [diff] [blame] | 357 | else if (action.equals(Intent.ACTION_BATTERY_LOW)) { |
| 358 | onBatteryLow(intent); |
| 359 | } |
Mike Lockwood | 69eb0bf | 2009-08-01 23:02:28 -0400 | [diff] [blame] | 360 | else if (action.equals(Intent.ACTION_BATTERY_OKAY) |
| 361 | || action.equals(Intent.ACTION_POWER_CONNECTED)) { |
Dianne Hackborn | 8ec5b83 | 2009-07-01 21:19:35 -0700 | [diff] [blame] | 362 | onBatteryOkay(intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 363 | } |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 364 | else if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED) || |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 365 | action.equals(BluetoothHeadset.ACTION_STATE_CHANGED) || |
| 366 | action.equals(BluetoothA2dp.ACTION_SINK_STATE_CHANGED) || |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 367 | action.equals(BluetoothPbap.PBAP_STATE_CHANGED_ACTION)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 368 | updateBluetooth(intent); |
| 369 | } |
| 370 | else if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION) || |
| 371 | action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION) || |
| 372 | action.equals(WifiManager.RSSI_CHANGED_ACTION)) { |
| 373 | updateWifi(intent); |
| 374 | } |
| 375 | else if (action.equals(GpsLocationProvider.GPS_ENABLED_CHANGE_ACTION) || |
| 376 | action.equals(GpsLocationProvider.GPS_FIX_CHANGE_ACTION)) { |
| 377 | updateGps(intent); |
| 378 | } |
| 379 | else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION) || |
| 380 | action.equals(AudioManager.VIBRATE_SETTING_CHANGED_ACTION)) { |
| 381 | updateVolume(); |
| 382 | } |
| 383 | else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) { |
| 384 | updateSimState(intent); |
| 385 | } |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 386 | else if (action.equals(TtyIntent.TTY_ENABLED_CHANGE_ACTION)) { |
| 387 | updateTTY(intent); |
| 388 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 389 | } |
| 390 | }; |
| 391 | |
| 392 | private StatusBarPolicy(Context context, StatusBarService service) { |
| 393 | mContext = context; |
| 394 | mService = service; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 395 | mSignalStrength = new SignalStrength(); |
Dianne Hackborn | 4840e14 | 2009-03-24 22:40:29 -0700 | [diff] [blame] | 396 | mBatteryStats = BatteryStatsService.getService(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 397 | |
| 398 | // clock |
| 399 | mCalendar = Calendar.getInstance(TimeZone.getDefault()); |
| 400 | mClockData = IconData.makeText("clock", ""); |
| 401 | mClockIcon = service.addIcon(mClockData, null); |
| 402 | updateClock(); |
| 403 | |
| 404 | // battery |
| 405 | mBatteryData = IconData.makeIcon("battery", |
| 406 | null, com.android.internal.R.drawable.stat_sys_battery_unknown, 0, 0); |
| 407 | mBatteryIcon = service.addIcon(mBatteryData, null); |
| 408 | |
| 409 | // phone_signal |
| 410 | mPhone = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 411 | mPhoneData = IconData.makeIcon("phone_signal", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 412 | null, com.android.internal.R.drawable.stat_sys_signal_null, 0, 0); |
| 413 | mPhoneIcon = service.addIcon(mPhoneData, null); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 414 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 415 | // register for phone state notifications. |
| 416 | ((TelephonyManager)mContext.getSystemService(Context.TELEPHONY_SERVICE)) |
| 417 | .listen(mPhoneStateListener, |
| 418 | PhoneStateListener.LISTEN_SERVICE_STATE |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 419 | | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 420 | | PhoneStateListener.LISTEN_CALL_STATE |
| 421 | | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE |
| 422 | | PhoneStateListener.LISTEN_DATA_ACTIVITY); |
| 423 | |
| 424 | // data_connection |
| 425 | mDataData = IconData.makeIcon("data_connection", |
| 426 | null, com.android.internal.R.drawable.stat_sys_data_connected_g, 0, 0); |
| 427 | mDataIcon = service.addIcon(mDataData, null); |
| 428 | service.setIconVisibility(mDataIcon, false); |
| 429 | |
| 430 | // wifi |
| 431 | mWifiData = IconData.makeIcon("wifi", null, sWifiSignalImages[0], 0, 0); |
| 432 | mWifiIcon = service.addIcon(mWifiData, null); |
| 433 | service.setIconVisibility(mWifiIcon, false); |
| 434 | // wifi will get updated by the sticky intents |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 435 | |
| 436 | // TTY status |
| 437 | mTTYModeEnableIconData = IconData.makeIcon("tty", |
| 438 | null, com.android.internal.R.drawable.stat_sys_tty_mode, 0, 0); |
| 439 | mTTYModeIcon = service.addIcon(mTTYModeEnableIconData, null); |
| 440 | service.setIconVisibility(mTTYModeIcon, false); |
| 441 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 442 | // Cdma Roaming Indicator, ERI |
| 443 | mCdmaRoamingIndicatorIconData = IconData.makeIcon("cdma_eri", |
| 444 | null, com.android.internal.R.drawable.stat_sys_roaming_cdma_0, 0, 0); |
| 445 | mCdmaRoamingIndicatorIcon = service.addIcon(mCdmaRoamingIndicatorIconData, null); |
| 446 | service.setIconVisibility(mCdmaRoamingIndicatorIcon, false); |
| 447 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 448 | // bluetooth status |
| 449 | mBluetoothData = IconData.makeIcon("bluetooth", |
| 450 | null, com.android.internal.R.drawable.stat_sys_data_bluetooth, 0, 0); |
| 451 | mBluetoothIcon = service.addIcon(mBluetoothData, null); |
Nick Pelly | f242b7b | 2009-10-08 00:12:45 +0200 | [diff] [blame] | 452 | BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 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); |
John Wang | 33e21fc | 2009-10-08 10:35:27 -0700 | [diff] [blame] | 521 | |
| 522 | // load config to determine if to distinguish Hspa data icon |
| 523 | try { |
| 524 | mHspaDataDistinguishable = mContext.getResources().getBoolean( |
| 525 | com.android.internal.R.bool.config_hspa_data_distinguishable); |
| 526 | } catch (Exception e) { |
| 527 | mHspaDataDistinguishable = false; |
| 528 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | public static void installIcons(Context context, StatusBarService service) { |
| 532 | sInstance = new StatusBarPolicy(context, service); |
| 533 | } |
| 534 | |
| 535 | private final void updateClock() { |
| 536 | mCalendar.setTimeInMillis(System.currentTimeMillis()); |
| 537 | mClockData.text = DateFormat.getTimeFormat(mContext) |
| 538 | .format(mCalendar.getTime()); |
| 539 | mService.updateIcon(mClockIcon, mClockData, null); |
| 540 | } |
| 541 | |
| 542 | private final void updateAlarm(Intent intent) { |
| 543 | boolean alarmSet = intent.getBooleanExtra("alarmSet", false); |
| 544 | mService.setIconVisibility(mAlarmClockIcon, alarmSet); |
| 545 | } |
| 546 | |
| 547 | private final void updateSyncState(Intent intent) { |
| 548 | boolean isActive = intent.getBooleanExtra("active", false); |
| 549 | boolean isFailing = intent.getBooleanExtra("failing", false); |
| 550 | mService.setIconVisibility(mSyncActiveIcon, isActive); |
| 551 | // Don't display sync failing icon: BUG 1297963 Set sync error timeout to "never" |
| 552 | //mService.setIconVisibility(mSyncFailingIcon, isFailing && !isActive); |
| 553 | } |
| 554 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 555 | private final void updateBattery(Intent intent) { |
| 556 | mBatteryData.iconId = intent.getIntExtra("icon-small", 0); |
| 557 | mBatteryData.iconLevel = intent.getIntExtra("level", 0); |
| 558 | mService.updateIcon(mBatteryIcon, mBatteryData, null); |
| 559 | |
| 560 | boolean plugged = intent.getIntExtra("plugged", 0) != 0; |
| 561 | int level = intent.getIntExtra("level", -1); |
| 562 | if (false) { |
| 563 | Log.d(TAG, "updateBattery level=" + level |
| 564 | + " plugged=" + plugged |
| 565 | + " mBatteryPlugged=" + mBatteryPlugged |
| 566 | + " mBatteryLevel=" + mBatteryLevel |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 567 | + " mBatteryFirst=" + mBatteryFirst); |
| 568 | } |
| 569 | |
| 570 | boolean oldPlugged = mBatteryPlugged; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 571 | |
| 572 | mBatteryPlugged = plugged; |
| 573 | mBatteryLevel = level; |
| 574 | |
| 575 | if (mBatteryFirst) { |
| 576 | mBatteryFirst = false; |
| 577 | } |
| 578 | /* |
| 579 | * No longer showing the battery view because it draws attention away |
| 580 | * from the USB storage notification. We could still show it when |
| 581 | * connected to a brick, but that could lead to the user into thinking |
| 582 | * the device does not charge when plugged into USB (since he/she would |
| 583 | * not see the same battery screen on USB as he sees on brick). |
| 584 | */ |
| 585 | /* else { |
| 586 | if (plugged && !oldPlugged) { |
| 587 | showBatteryView(); |
| 588 | } |
| 589 | } |
| 590 | */ |
| 591 | if (false) { |
Mihai Preda | a82842f | 2009-04-29 15:05:56 +0200 | [diff] [blame] | 592 | Log.d(TAG, "plugged=" + plugged + " oldPlugged=" + oldPlugged + " level=" + level); |
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 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 595 | |
Mihai Preda | a82842f | 2009-04-29 15:05:56 +0200 | [diff] [blame] | 596 | private void onBatteryLow(Intent intent) { |
| 597 | if (SHOW_LOW_BATTERY_WARNING) { |
| 598 | if (false) { |
| 599 | Log.d(TAG, "mPhoneState=" + mPhoneState |
| 600 | + " mLowBatteryDialog=" + mLowBatteryDialog |
| 601 | + " mBatteryShowLowOnEndCall=" + mBatteryShowLowOnEndCall); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 602 | } |
Mihai Preda | a82842f | 2009-04-29 15:05:56 +0200 | [diff] [blame] | 603 | |
| 604 | if (mPhoneState == TelephonyManager.CALL_STATE_IDLE) { |
| 605 | showLowBatteryWarning(); |
| 606 | } else { |
| 607 | mBatteryShowLowOnEndCall = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 608 | } |
| 609 | } |
| 610 | } |
| 611 | |
Dianne Hackborn | 8ec5b83 | 2009-07-01 21:19:35 -0700 | [diff] [blame] | 612 | private void onBatteryOkay(Intent intent) { |
| 613 | if (mLowBatteryDialog != null |
| 614 | && SHOW_LOW_BATTERY_WARNING) { |
| 615 | mLowBatteryDialog.dismiss(); |
| 616 | mBatteryShowLowOnEndCall = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 617 | } |
| 618 | } |
| 619 | |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 620 | private void showBatteryView() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 621 | closeLastBatteryView(); |
| 622 | if (mLowBatteryDialog != null) { |
| 623 | mLowBatteryDialog.dismiss(); |
| 624 | } |
| 625 | |
| 626 | int level = mBatteryLevel; |
| 627 | |
| 628 | View v = View.inflate(mContext, com.android.internal.R.layout.battery_status, null); |
| 629 | mBatteryView = v; |
| 630 | int pixelFormat = PixelFormat.TRANSLUCENT; |
| 631 | Drawable bg = v.getBackground(); |
| 632 | if (bg != null) { |
| 633 | pixelFormat = bg.getOpacity(); |
| 634 | } |
| 635 | |
Dianne Hackborn | 568cae5 | 2009-10-07 16:13:39 -0700 | [diff] [blame] | 636 | int flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 637 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
| 638 | | WindowManager.LayoutParams.FLAG_DIM_BEHIND; |
| 639 | |
| 640 | if (!mContext.getResources().getBoolean( |
| 641 | com.android.internal.R.bool.config_sf_slowBlur)) { |
| 642 | flags |= WindowManager.LayoutParams.FLAG_BLUR_BEHIND; |
| 643 | } |
| 644 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 645 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 646 | ViewGroup.LayoutParams.WRAP_CONTENT, |
| 647 | ViewGroup.LayoutParams.WRAP_CONTENT, |
| 648 | WindowManager.LayoutParams.TYPE_TOAST, |
Dianne Hackborn | 568cae5 | 2009-10-07 16:13:39 -0700 | [diff] [blame] | 649 | flags, pixelFormat); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 650 | |
| 651 | // Get the dim amount from the theme |
| 652 | TypedArray a = mContext.obtainStyledAttributes( |
| 653 | com.android.internal.R.styleable.Theme); |
| 654 | lp.dimAmount = a.getFloat(android.R.styleable.Theme_backgroundDimAmount, 0.5f); |
| 655 | a.recycle(); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 656 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 657 | lp.setTitle("Battery"); |
| 658 | |
| 659 | TextView levelTextView = (TextView)v.findViewById(com.android.internal.R.id.level_percent); |
| 660 | levelTextView.setText(mContext.getString( |
| 661 | com.android.internal.R.string.battery_status_text_percent_format, level)); |
| 662 | |
| 663 | setBatteryLevel(v, com.android.internal.R.id.spacer, 100-level, 0, 0); |
| 664 | setBatteryLevel(v, com.android.internal.R.id.level, level, |
| 665 | com.android.internal.R.drawable.battery_charge_fill, level); |
| 666 | |
| 667 | WindowManagerImpl.getDefault().addView(v, lp); |
| 668 | |
| 669 | scheduleCloseBatteryView(); |
| 670 | } |
| 671 | |
| 672 | private void setBatteryLevel(View parent, int id, int height, int background, int level) { |
| 673 | ImageView v = (ImageView)parent.findViewById(id); |
| 674 | LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)v.getLayoutParams(); |
| 675 | lp.weight = height; |
| 676 | if (background != 0) { |
| 677 | v.setBackgroundResource(background); |
| 678 | Drawable bkg = v.getBackground(); |
| 679 | bkg.setLevel(level); |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | private void showLowBatteryWarning() { |
| 684 | closeLastBatteryView(); |
| 685 | |
Mike Lockwood | d81b1f4 | 2009-09-25 09:32:19 -0400 | [diff] [blame] | 686 | // Show exact battery level. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 687 | CharSequence levelText = mContext.getString( |
Mike Lockwood | d81b1f4 | 2009-09-25 09:32:19 -0400 | [diff] [blame] | 688 | 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] | 689 | |
| 690 | if (mBatteryLevelTextView != null) { |
| 691 | mBatteryLevelTextView.setText(levelText); |
| 692 | } else { |
| 693 | View v = View.inflate(mContext, com.android.internal.R.layout.battery_low, null); |
| 694 | mBatteryLevelTextView=(TextView)v.findViewById(com.android.internal.R.id.level_percent); |
| 695 | |
| 696 | mBatteryLevelTextView.setText(levelText); |
| 697 | |
| 698 | AlertDialog.Builder b = new AlertDialog.Builder(mContext); |
| 699 | b.setCancelable(true); |
| 700 | b.setTitle(com.android.internal.R.string.battery_low_title); |
| 701 | b.setView(v); |
| 702 | b.setIcon(android.R.drawable.ic_dialog_alert); |
| 703 | b.setPositiveButton(android.R.string.ok, null); |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 704 | |
Dianne Hackborn | 3d74bb4 | 2009-06-19 10:35:21 -0700 | [diff] [blame] | 705 | final Intent intent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY); |
| 706 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 707 | | Intent.FLAG_ACTIVITY_MULTIPLE_TASK |
| 708 | | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS |
| 709 | | Intent.FLAG_ACTIVITY_NO_HISTORY); |
| 710 | if (intent.resolveActivity(mContext.getPackageManager()) != null) { |
| 711 | b.setNegativeButton(com.android.internal.R.string.battery_low_why, |
| 712 | new DialogInterface.OnClickListener() { |
| 713 | public void onClick(DialogInterface dialog, int which) { |
| 714 | mContext.startActivity(intent); |
| 715 | if (mLowBatteryDialog != null) { |
| 716 | mLowBatteryDialog.dismiss(); |
| 717 | } |
| 718 | } |
| 719 | }); |
| 720 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 721 | |
| 722 | AlertDialog d = b.create(); |
| 723 | d.setOnDismissListener(mLowBatteryListener); |
| 724 | d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); |
| 725 | d.show(); |
| 726 | mLowBatteryDialog = d; |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | private final void updateCallState(int state) { |
| 731 | mPhoneState = state; |
| 732 | if (false) { |
| 733 | Log.d(TAG, "mPhoneState=" + mPhoneState |
| 734 | + " mLowBatteryDialog=" + mLowBatteryDialog |
| 735 | + " mBatteryShowLowOnEndCall=" + mBatteryShowLowOnEndCall); |
| 736 | } |
| 737 | if (mPhoneState == TelephonyManager.CALL_STATE_IDLE) { |
| 738 | if (mBatteryShowLowOnEndCall) { |
| 739 | if (!mBatteryPlugged) { |
| 740 | showLowBatteryWarning(); |
| 741 | } |
| 742 | mBatteryShowLowOnEndCall = false; |
| 743 | } |
| 744 | } else { |
| 745 | if (mLowBatteryDialog != null) { |
| 746 | mLowBatteryDialog.dismiss(); |
| 747 | mBatteryShowLowOnEndCall = true; |
| 748 | } |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | private DialogInterface.OnDismissListener mLowBatteryListener |
| 753 | = new DialogInterface.OnDismissListener() { |
| 754 | public void onDismiss(DialogInterface dialog) { |
| 755 | mLowBatteryDialog = null; |
| 756 | mBatteryLevelTextView = null; |
| 757 | } |
| 758 | }; |
| 759 | |
| 760 | private void scheduleCloseBatteryView() { |
| 761 | Message m = mHandler.obtainMessage(EVENT_BATTERY_CLOSE); |
| 762 | m.arg1 = (++mBatteryViewSequence); |
| 763 | mHandler.sendMessageDelayed(m, 3000); |
| 764 | } |
| 765 | |
| 766 | private void closeLastBatteryView() { |
| 767 | if (mBatteryView != null) { |
| 768 | //mBatteryView.debug(); |
| 769 | WindowManagerImpl.getDefault().removeView(mBatteryView); |
| 770 | mBatteryView = null; |
| 771 | } |
| 772 | } |
| 773 | |
| 774 | private PhoneStateListener mPhoneStateListener = new PhoneStateListener() { |
| 775 | @Override |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 776 | public void onSignalStrengthsChanged(SignalStrength signalStrength) { |
| 777 | mSignalStrength = signalStrength; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 778 | updateSignalStrength(); |
| 779 | } |
| 780 | |
| 781 | @Override |
| 782 | public void onServiceStateChanged(ServiceState state) { |
| 783 | mServiceState = state; |
| 784 | updateSignalStrength(); |
Robert Greenwalt | 98e0b14 | 2009-10-08 21:15:52 -0700 | [diff] [blame^] | 785 | updateCdmaRoamingIcon(state); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 786 | updateDataIcon(); |
| 787 | } |
| 788 | |
| 789 | @Override |
| 790 | public void onCallStateChanged(int state, String incomingNumber) { |
| 791 | updateCallState(state); |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 792 | // In cdma, if a voice call is made, RSSI should switch to 1x. |
| 793 | if (isCdma()) { |
| 794 | updateSignalStrength(); |
| 795 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | @Override |
Robert Greenwalt | 98e0b14 | 2009-10-08 21:15:52 -0700 | [diff] [blame^] | 799 | public void onDataConnectionStateChanged(int state, int networkType) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 800 | mDataState = state; |
Robert Greenwalt | 98e0b14 | 2009-10-08 21:15:52 -0700 | [diff] [blame^] | 801 | updateDataNetType(networkType); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 802 | updateDataIcon(); |
| 803 | } |
| 804 | |
| 805 | @Override |
| 806 | public void onDataActivity(int direction) { |
| 807 | mDataActivity = direction; |
| 808 | updateDataIcon(); |
| 809 | } |
| 810 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 811 | |
| 812 | private final void updateSimState(Intent intent) { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 813 | String stateExtra = intent.getStringExtra(IccCard.INTENT_KEY_ICC_STATE); |
| 814 | if (IccCard.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) { |
| 815 | mSimState = IccCard.State.ABSENT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 816 | } |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 817 | else if (IccCard.INTENT_VALUE_ICC_READY.equals(stateExtra)) { |
| 818 | mSimState = IccCard.State.READY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 819 | } |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 820 | else if (IccCard.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) { |
| 821 | final String lockedReason = intent.getStringExtra(IccCard.INTENT_KEY_LOCKED_REASON); |
| 822 | if (IccCard.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) { |
| 823 | mSimState = IccCard.State.PIN_REQUIRED; |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 824 | } |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 825 | else if (IccCard.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) { |
| 826 | mSimState = IccCard.State.PUK_REQUIRED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 827 | } |
| 828 | else { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 829 | mSimState = IccCard.State.NETWORK_LOCKED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 830 | } |
| 831 | } else { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 832 | mSimState = IccCard.State.UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 833 | } |
| 834 | updateDataIcon(); |
| 835 | } |
| 836 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 837 | private boolean isCdma() { |
Robert Greenwalt | 98e0b14 | 2009-10-08 21:15:52 -0700 | [diff] [blame^] | 838 | return (mSignalStrength != null) && !mSignalStrength.isGsm(); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 839 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 840 | |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 841 | private boolean isEvdo() { |
| 842 | return ( (mServiceState != null) |
| 843 | && ((mServiceState.getRadioTechnology() |
| 844 | == ServiceState.RADIO_TECHNOLOGY_EVDO_0) |
| 845 | || (mServiceState.getRadioTechnology() |
| 846 | == ServiceState.RADIO_TECHNOLOGY_EVDO_A))); |
| 847 | } |
| 848 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 849 | private boolean hasService() { |
| 850 | if (mServiceState != null) { |
| 851 | switch (mServiceState.getState()) { |
| 852 | case ServiceState.STATE_OUT_OF_SERVICE: |
| 853 | case ServiceState.STATE_POWER_OFF: |
| 854 | return false; |
| 855 | default: |
| 856 | return true; |
| 857 | } |
| 858 | } else { |
| 859 | return false; |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | private final void updateSignalStrength() { |
| 864 | int iconLevel = -1; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 865 | int[] iconList; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 866 | |
| 867 | if (!hasService()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 868 | //Log.d(TAG, "updateSignalStrength: no service"); |
| 869 | if (Settings.System.getInt(mContext.getContentResolver(), |
| 870 | Settings.System.AIRPLANE_MODE_ON, 0) == 1) { |
| 871 | mPhoneData.iconId = com.android.internal.R.drawable.stat_sys_signal_flightmode; |
| 872 | } else { |
| 873 | mPhoneData.iconId = com.android.internal.R.drawable.stat_sys_signal_null; |
| 874 | } |
| 875 | mService.updateIcon(mPhoneIcon, mPhoneData, null); |
| 876 | return; |
| 877 | } |
| 878 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 879 | if (!isCdma()) { |
| 880 | int asu = mSignalStrength.getGsmSignalStrength(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 881 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 882 | // ASU ranges from 0 to 31 - TS 27.007 Sec 8.5 |
| 883 | // asu = 0 (-113dB or less) is very weak |
| 884 | // signal, its better to show 0 bars to the user in such cases. |
| 885 | // asu = 99 is a special case, where the signal strength is unknown. |
| 886 | if (asu <= 0 || asu == 99) iconLevel = 0; |
| 887 | else if (asu >= 16) iconLevel = 4; |
| 888 | else if (asu >= 8) iconLevel = 3; |
| 889 | else if (asu >= 4) iconLevel = 2; |
| 890 | else iconLevel = 1; |
| 891 | |
Robert Greenwalt | 98e0b14 | 2009-10-08 21:15:52 -0700 | [diff] [blame^] | 892 | // Though mPhone is a Manager, this call is not an IPC |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 893 | if (mPhone.isNetworkRoaming()) { |
| 894 | iconList = sSignalImages_r; |
| 895 | } else { |
| 896 | iconList = sSignalImages; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 897 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 898 | } else { |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 899 | iconList = this.sSignalImages; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 900 | |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 901 | // If 3G(EV) and 1x network are available than 3G should be |
| 902 | // displayed, displayed RSSI should be from the EV side. |
| 903 | // If a voice call is made then RSSI should switch to 1x. |
| 904 | if ((mPhoneState == TelephonyManager.CALL_STATE_IDLE) && isEvdo()){ |
| 905 | iconLevel = getEvdoLevel(); |
| 906 | if (false) { |
| 907 | Log.d(TAG, "use Evdo level=" + iconLevel + " to replace Cdma Level=" + getCdmaLevel()); |
| 908 | } |
| 909 | } else { |
| 910 | iconLevel = getCdmaLevel(); |
| 911 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 912 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 913 | mPhoneData.iconId = iconList[iconLevel]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 914 | mService.updateIcon(mPhoneIcon, mPhoneData, null); |
| 915 | } |
| 916 | |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 917 | private int getCdmaLevel() { |
| 918 | final int cdmaDbm = mSignalStrength.getCdmaDbm(); |
| 919 | final int cdmaEcio = mSignalStrength.getCdmaEcio(); |
| 920 | int levelDbm = 0; |
| 921 | int levelEcio = 0; |
| 922 | |
| 923 | if (cdmaDbm >= -75) levelDbm = 4; |
| 924 | else if (cdmaDbm >= -85) levelDbm = 3; |
| 925 | else if (cdmaDbm >= -95) levelDbm = 2; |
| 926 | else if (cdmaDbm >= -100) levelDbm = 1; |
| 927 | else levelDbm = 0; |
| 928 | |
| 929 | // Ec/Io are in dB*10 |
| 930 | if (cdmaEcio >= -90) levelEcio = 4; |
| 931 | else if (cdmaEcio >= -110) levelEcio = 3; |
| 932 | else if (cdmaEcio >= -130) levelEcio = 2; |
| 933 | else if (cdmaEcio >= -150) levelEcio = 1; |
| 934 | else levelEcio = 0; |
| 935 | |
| 936 | return (levelDbm < levelEcio) ? levelDbm : levelEcio; |
| 937 | } |
| 938 | |
| 939 | private int getEvdoLevel() { |
| 940 | int evdoDbm = mSignalStrength.getEvdoDbm(); |
| 941 | int evdoSnr = mSignalStrength.getEvdoSnr(); |
| 942 | int levelEvdoDbm = 0; |
| 943 | int levelEvdoSnr = 0; |
| 944 | |
| 945 | if (evdoDbm >= -65) levelEvdoDbm = 4; |
| 946 | else if (evdoDbm >= -75) levelEvdoDbm = 3; |
| 947 | else if (evdoDbm >= -90) levelEvdoDbm = 2; |
| 948 | else if (evdoDbm >= -105) levelEvdoDbm = 1; |
| 949 | else levelEvdoDbm = 0; |
| 950 | |
John Michelau | 1336a56 | 2009-09-28 10:41:02 -0500 | [diff] [blame] | 951 | if (evdoSnr >= 7) levelEvdoSnr = 4; |
| 952 | else if (evdoSnr >= 5) levelEvdoSnr = 3; |
| 953 | else if (evdoSnr >= 3) levelEvdoSnr = 2; |
| 954 | else if (evdoSnr >= 1) levelEvdoSnr = 1; |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 955 | else levelEvdoSnr = 0; |
| 956 | |
| 957 | return (levelEvdoDbm < levelEvdoSnr) ? levelEvdoDbm : levelEvdoSnr; |
| 958 | } |
| 959 | |
Robert Greenwalt | 98e0b14 | 2009-10-08 21:15:52 -0700 | [diff] [blame^] | 960 | private final void updateDataNetType(int net) { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 961 | |
| 962 | switch (net) { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 963 | case TelephonyManager.NETWORK_TYPE_EDGE: |
| 964 | mDataIconList = sDataNetType_e; |
| 965 | break; |
| 966 | case TelephonyManager.NETWORK_TYPE_UMTS: |
| 967 | mDataIconList = sDataNetType_3g; |
| 968 | break; |
Li Zhe | ebe6634 | 2009-08-14 19:22:16 +0800 | [diff] [blame] | 969 | case TelephonyManager.NETWORK_TYPE_HSDPA: |
| 970 | case TelephonyManager.NETWORK_TYPE_HSUPA: |
| 971 | case TelephonyManager.NETWORK_TYPE_HSPA: |
John Wang | 33e21fc | 2009-10-08 10:35:27 -0700 | [diff] [blame] | 972 | if (mHspaDataDistinguishable) { |
| 973 | mDataIconList = sDataNetType_h; |
| 974 | } else { |
| 975 | mDataIconList = sDataNetType_3g; |
| 976 | } |
Li Zhe | ebe6634 | 2009-08-14 19:22:16 +0800 | [diff] [blame] | 977 | break; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 978 | case TelephonyManager.NETWORK_TYPE_CDMA: |
| 979 | // display 1xRTT for IS95A/B |
johnwang | 9f87cb2 | 2009-08-25 15:25:37 -0700 | [diff] [blame] | 980 | mDataIconList = this.sDataNetType_1x; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 981 | break; |
| 982 | case TelephonyManager.NETWORK_TYPE_1xRTT: |
johnwang | 9f87cb2 | 2009-08-25 15:25:37 -0700 | [diff] [blame] | 983 | mDataIconList = this.sDataNetType_1x; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 984 | break; |
| 985 | case TelephonyManager.NETWORK_TYPE_EVDO_0: //fall through |
| 986 | case TelephonyManager.NETWORK_TYPE_EVDO_A: |
johnwang | 9f87cb2 | 2009-08-25 15:25:37 -0700 | [diff] [blame] | 987 | mDataIconList = sDataNetType_3g; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 988 | break; |
| 989 | default: |
| 990 | mDataIconList = sDataNetType_g; |
| 991 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 992 | } |
| 993 | } |
| 994 | |
| 995 | private final void updateDataIcon() { |
| 996 | int iconId; |
| 997 | boolean visible = true; |
| 998 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 999 | if (!isCdma()) { |
| 1000 | // GSM case, we have to check also the sim state |
| 1001 | if (mSimState == IccCard.State.READY || mSimState == IccCard.State.UNKNOWN) { |
| 1002 | if (hasService() && mDataState == TelephonyManager.DATA_CONNECTED) { |
| 1003 | switch (mDataActivity) { |
| 1004 | case TelephonyManager.DATA_ACTIVITY_IN: |
| 1005 | iconId = mDataIconList[1]; |
| 1006 | break; |
| 1007 | case TelephonyManager.DATA_ACTIVITY_OUT: |
| 1008 | iconId = mDataIconList[2]; |
| 1009 | break; |
| 1010 | case TelephonyManager.DATA_ACTIVITY_INOUT: |
| 1011 | iconId = mDataIconList[3]; |
| 1012 | break; |
| 1013 | default: |
| 1014 | iconId = mDataIconList[0]; |
| 1015 | break; |
| 1016 | } |
| 1017 | mDataData.iconId = iconId; |
| 1018 | mService.updateIcon(mDataIcon, mDataData, null); |
| 1019 | } else { |
| 1020 | visible = false; |
| 1021 | } |
| 1022 | } else { |
| 1023 | mDataData.iconId = com.android.internal.R.drawable.stat_sys_no_sim; |
| 1024 | mService.updateIcon(mDataIcon, mDataData, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1025 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1026 | } else { |
| 1027 | // CDMA case, mDataActivity can be also DATA_ACTIVITY_DORMANT |
| 1028 | if (hasService() && mDataState == TelephonyManager.DATA_CONNECTED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1029 | switch (mDataActivity) { |
| 1030 | case TelephonyManager.DATA_ACTIVITY_IN: |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1031 | iconId = mDataIconList[1]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1032 | break; |
| 1033 | case TelephonyManager.DATA_ACTIVITY_OUT: |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1034 | iconId = mDataIconList[2]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1035 | break; |
| 1036 | case TelephonyManager.DATA_ACTIVITY_INOUT: |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1037 | iconId = mDataIconList[3]; |
| 1038 | break; |
| 1039 | case TelephonyManager.DATA_ACTIVITY_DORMANT: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1040 | default: |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1041 | iconId = mDataIconList[0]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1042 | break; |
| 1043 | } |
| 1044 | mDataData.iconId = iconId; |
| 1045 | mService.updateIcon(mDataIcon, mDataData, null); |
| 1046 | } else { |
| 1047 | visible = false; |
| 1048 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1049 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1050 | |
Dianne Hackborn | 4840e14 | 2009-03-24 22:40:29 -0700 | [diff] [blame] | 1051 | long ident = Binder.clearCallingIdentity(); |
| 1052 | try { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 1053 | mBatteryStats.notePhoneDataConnectionState(mPhone.getNetworkType(), visible); |
Dianne Hackborn | 4840e14 | 2009-03-24 22:40:29 -0700 | [diff] [blame] | 1054 | } catch (RemoteException e) { |
| 1055 | } finally { |
| 1056 | Binder.restoreCallingIdentity(ident); |
| 1057 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1058 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1059 | if (mDataIconVisible != visible) { |
| 1060 | mService.setIconVisibility(mDataIcon, visible); |
| 1061 | mDataIconVisible = visible; |
| 1062 | } |
| 1063 | } |
| 1064 | |
| 1065 | private final void updateVolume() { |
| 1066 | AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); |
| 1067 | final int ringerMode = audioManager.getRingerMode(); |
| 1068 | final boolean visible = ringerMode == AudioManager.RINGER_MODE_SILENT || |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1069 | ringerMode == AudioManager.RINGER_MODE_VIBRATE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1070 | final int iconId = audioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER) |
| 1071 | ? com.android.internal.R.drawable.stat_sys_ringer_vibrate |
| 1072 | : com.android.internal.R.drawable.stat_sys_ringer_silent; |
| 1073 | |
| 1074 | if (visible) { |
| 1075 | mVolumeData.iconId = iconId; |
| 1076 | mService.updateIcon(mVolumeIcon, mVolumeData, null); |
| 1077 | } |
| 1078 | if (visible != mVolumeVisible) { |
| 1079 | mService.setIconVisibility(mVolumeIcon, visible); |
| 1080 | mVolumeVisible = visible; |
| 1081 | } |
| 1082 | } |
| 1083 | |
| 1084 | private final void updateBluetooth(Intent intent) { |
| 1085 | int iconId = com.android.internal.R.drawable.stat_sys_data_bluetooth; |
| 1086 | |
| 1087 | String action = intent.getAction(); |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 1088 | if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { |
Nick Pelly | b24e11b | 2009-09-08 17:40:43 -0700 | [diff] [blame] | 1089 | int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR); |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 1090 | mBluetoothEnabled = state == BluetoothAdapter.STATE_ON; |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 1091 | } else if (action.equals(BluetoothHeadset.ACTION_STATE_CHANGED)) { |
| 1092 | mBluetoothHeadsetState = intent.getIntExtra(BluetoothHeadset.EXTRA_STATE, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1093 | BluetoothHeadset.STATE_ERROR); |
Nick Pelly | 005b228 | 2009-09-10 10:21:56 -0700 | [diff] [blame] | 1094 | } else if (action.equals(BluetoothA2dp.ACTION_SINK_STATE_CHANGED)) { |
| 1095 | mBluetoothA2dpState = intent.getIntExtra(BluetoothA2dp.EXTRA_SINK_STATE, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1096 | BluetoothA2dp.STATE_DISCONNECTED); |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 1097 | } else if (action.equals(BluetoothPbap.PBAP_STATE_CHANGED_ACTION)) { |
| 1098 | mBluetoothPbapState = intent.getIntExtra(BluetoothPbap.PBAP_STATE, |
| 1099 | BluetoothPbap.STATE_DISCONNECTED); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1100 | } else { |
| 1101 | return; |
| 1102 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1103 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1104 | if (mBluetoothHeadsetState == BluetoothHeadset.STATE_CONNECTED || |
| 1105 | mBluetoothA2dpState == BluetoothA2dp.STATE_CONNECTED || |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 1106 | mBluetoothA2dpState == BluetoothA2dp.STATE_PLAYING || |
| 1107 | mBluetoothPbapState == BluetoothPbap.STATE_CONNECTED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1108 | iconId = com.android.internal.R.drawable.stat_sys_data_bluetooth_connected; |
| 1109 | } |
| 1110 | |
| 1111 | mBluetoothData.iconId = iconId; |
| 1112 | mService.updateIcon(mBluetoothIcon, mBluetoothData, null); |
| 1113 | mService.setIconVisibility(mBluetoothIcon, mBluetoothEnabled); |
| 1114 | } |
| 1115 | |
| 1116 | private final void updateWifi(Intent intent) { |
| 1117 | final String action = intent.getAction(); |
| 1118 | if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1119 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1120 | final boolean enabled = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, |
| 1121 | WifiManager.WIFI_STATE_UNKNOWN) == WifiManager.WIFI_STATE_ENABLED; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1122 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1123 | if (!enabled) { |
| 1124 | // If disabled, hide the icon. (We show icon when connected.) |
| 1125 | mService.setIconVisibility(mWifiIcon, false); |
| 1126 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1127 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1128 | } else if (action.equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)) { |
| 1129 | final boolean enabled = intent.getBooleanExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED, |
| 1130 | false); |
| 1131 | if (!enabled) { |
| 1132 | mService.setIconVisibility(mWifiIcon, false); |
| 1133 | } |
| 1134 | } else if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) { |
| 1135 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1136 | final NetworkInfo networkInfo = (NetworkInfo) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1137 | intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1138 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1139 | int iconId; |
| 1140 | if (networkInfo != null && networkInfo.isConnected()) { |
| 1141 | mIsWifiConnected = true; |
| 1142 | if (mLastWifiSignalLevel == -1) { |
| 1143 | iconId = sWifiSignalImages[0]; |
| 1144 | } else { |
| 1145 | iconId = sWifiSignalImages[mLastWifiSignalLevel]; |
| 1146 | } |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 1147 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1148 | // Show the icon since wi-fi is connected |
| 1149 | mService.setIconVisibility(mWifiIcon, true); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 1150 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1151 | } else { |
| 1152 | mLastWifiSignalLevel = -1; |
| 1153 | mIsWifiConnected = false; |
| 1154 | iconId = sWifiSignalImages[0]; |
| 1155 | |
| 1156 | // Hide the icon since we're not connected |
| 1157 | mService.setIconVisibility(mWifiIcon, false); |
| 1158 | } |
| 1159 | |
| 1160 | mWifiData.iconId = iconId; |
| 1161 | mService.updateIcon(mWifiIcon, mWifiData, null); |
| 1162 | } else if (action.equals(WifiManager.RSSI_CHANGED_ACTION)) { |
| 1163 | final int newRssi = intent.getIntExtra(WifiManager.EXTRA_NEW_RSSI, -200); |
| 1164 | int newSignalLevel = WifiManager.calculateSignalLevel(newRssi, |
| 1165 | sWifiSignalImages.length); |
| 1166 | if (newSignalLevel != mLastWifiSignalLevel) { |
| 1167 | mLastWifiSignalLevel = newSignalLevel; |
| 1168 | if (mIsWifiConnected) { |
| 1169 | mWifiData.iconId = sWifiSignalImages[newSignalLevel]; |
| 1170 | } else { |
| 1171 | mWifiData.iconId = sWifiTemporarilyNotConnectedImage; |
| 1172 | } |
| 1173 | mService.updateIcon(mWifiIcon, mWifiData, null); |
| 1174 | } |
| 1175 | } |
| 1176 | } |
| 1177 | |
| 1178 | private final void updateGps(Intent intent) { |
| 1179 | final String action = intent.getAction(); |
| 1180 | final boolean enabled = intent.getBooleanExtra(GpsLocationProvider.EXTRA_ENABLED, false); |
| 1181 | |
| 1182 | if (action.equals(GpsLocationProvider.GPS_FIX_CHANGE_ACTION) && enabled) { |
| 1183 | // GPS is getting fixes |
| 1184 | mService.updateIcon(mGpsIcon, mGpsFixIconData, null); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1185 | mService.setIconVisibility(mGpsIcon, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1186 | } else if (action.equals(GpsLocationProvider.GPS_ENABLED_CHANGE_ACTION) && !enabled) { |
| 1187 | // GPS is off |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1188 | mService.setIconVisibility(mGpsIcon, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1189 | } else { |
| 1190 | // GPS is on, but not receiving fixes |
| 1191 | mService.updateIcon(mGpsIcon, mGpsEnabledIconData, null); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1192 | mService.setIconVisibility(mGpsIcon, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1193 | } |
| 1194 | } |
| 1195 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1196 | private final void updateTTY(Intent intent) { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 1197 | final String action = intent.getAction(); |
| 1198 | final boolean enabled = intent.getBooleanExtra(TtyIntent.TTY_ENABLED, false); |
| 1199 | |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 1200 | if (false) Log.v(TAG, "updateTTY: enabled: " + enabled); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 1201 | |
| 1202 | if (enabled) { |
| 1203 | // TTY is on |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 1204 | if (false) Log.v(TAG, "updateTTY: set TTY on"); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 1205 | mService.updateIcon(mTTYModeIcon, mTTYModeEnableIconData, null); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1206 | mService.setIconVisibility(mTTYModeIcon, true); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 1207 | } else { |
| 1208 | // TTY is off |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 1209 | if (false) Log.v(TAG, "updateTTY: set TTY off"); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1210 | mService.setIconVisibility(mTTYModeIcon, false); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 1211 | } |
| 1212 | } |
| 1213 | |
Robert Greenwalt | 98e0b14 | 2009-10-08 21:15:52 -0700 | [diff] [blame^] | 1214 | private final void updateCdmaRoamingIcon(ServiceState state) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1215 | if (!hasService()) { |
| 1216 | mService.setIconVisibility(mCdmaRoamingIndicatorIcon, false); |
Wink Saville | f315238 | 2009-06-01 14:39:20 -0700 | [diff] [blame] | 1217 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1218 | } |
| 1219 | |
| 1220 | if (!isCdma()) { |
| 1221 | mService.setIconVisibility(mCdmaRoamingIndicatorIcon, false); |
Wink Saville | f315238 | 2009-06-01 14:39:20 -0700 | [diff] [blame] | 1222 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1223 | } |
| 1224 | |
| 1225 | int[] iconList = sRoamingIndicatorImages_cdma; |
Robert Greenwalt | 98e0b14 | 2009-10-08 21:15:52 -0700 | [diff] [blame^] | 1226 | int iconIndex = state.getCdmaEriIconIndex(); |
| 1227 | int iconMode = state.getCdmaEriIconMode(); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1228 | |
| 1229 | if (iconIndex == -1) { |
| 1230 | Log.e(TAG, "getCdmaEriIconIndex returned null, skipping ERI icon update"); |
| 1231 | return; |
| 1232 | } |
| 1233 | |
| 1234 | if (iconMode == -1) { |
| 1235 | Log.e(TAG, "getCdmeEriIconMode returned null, skipping ERI icon update"); |
| 1236 | return; |
| 1237 | } |
| 1238 | |
| 1239 | if (iconIndex == EriInfo.ROAMING_INDICATOR_OFF) { |
Dianne Hackborn | bd0a81f | 2009-10-04 13:30:50 -0700 | [diff] [blame] | 1240 | if (false) Log.v(TAG, "Cdma ROAMING_INDICATOR_OFF, removing ERI icon"); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1241 | mService.setIconVisibility(mCdmaRoamingIndicatorIcon, false); |
| 1242 | return; |
| 1243 | } |
| 1244 | |
| 1245 | switch (iconMode) { |
| 1246 | case EriInfo.ROAMING_ICON_MODE_NORMAL: |
| 1247 | mCdmaRoamingIndicatorIconData.iconId = iconList[iconIndex]; |
| 1248 | mService.updateIcon(mCdmaRoamingIndicatorIcon, mCdmaRoamingIndicatorIconData, null); |
| 1249 | mService.setIconVisibility(mCdmaRoamingIndicatorIcon, true); |
| 1250 | break; |
| 1251 | case EriInfo.ROAMING_ICON_MODE_FLASH: |
Wink Saville | f315238 | 2009-06-01 14:39:20 -0700 | [diff] [blame] | 1252 | mCdmaRoamingIndicatorIconData.iconId = |
| 1253 | com.android.internal.R.drawable.stat_sys_roaming_cdma_flash; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1254 | mService.updateIcon(mCdmaRoamingIndicatorIcon, mCdmaRoamingIndicatorIconData, null); |
Wink Saville | f315238 | 2009-06-01 14:39:20 -0700 | [diff] [blame] | 1255 | mService.setIconVisibility(mCdmaRoamingIndicatorIcon, true); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 1256 | break; |
| 1257 | |
| 1258 | } |
| 1259 | mService.updateIcon(mPhoneIcon, mPhoneData, null); |
| 1260 | } |
| 1261 | |
| 1262 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1263 | private class StatusBarHandler extends Handler { |
| 1264 | @Override |
| 1265 | public void handleMessage(Message msg) { |
| 1266 | switch (msg.what) { |
| 1267 | case EVENT_BATTERY_CLOSE: |
| 1268 | if (msg.arg1 == mBatteryViewSequence) { |
| 1269 | closeLastBatteryView(); |
| 1270 | } |
| 1271 | break; |
| 1272 | } |
| 1273 | } |
| 1274 | } |
| 1275 | } |