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