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