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