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