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 | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 17 | package com.android.systemui.statusbar.phone; |
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; |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 20 | import android.bluetooth.BluetoothAdapter; |
Jaikumar Ganesh | d9bb688 | 2010-09-27 17:05:24 -0700 | [diff] [blame] | 21 | import android.bluetooth.BluetoothProfile; |
Jiafa Liu | 3f41673 | 2009-07-02 16:36:02 +0800 | [diff] [blame] | 22 | import android.bluetooth.BluetoothPbap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | import android.content.BroadcastReceiver; |
| 24 | import android.content.Context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | import android.content.Intent; |
| 26 | import android.content.IntentFilter; |
| 27 | import android.content.res.TypedArray; |
| 28 | import android.graphics.PixelFormat; |
Daniel Sandler | 2c195f7 | 2010-05-21 15:42:06 -0400 | [diff] [blame] | 29 | import android.graphics.Typeface; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import android.graphics.drawable.Drawable; |
Mike Lockwood | 00b7427 | 2010-03-26 10:41:48 -0400 | [diff] [blame] | 31 | import android.location.LocationManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import android.media.AudioManager; |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 33 | import android.net.ConnectivityManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | import android.net.NetworkInfo; |
Daniel Sandler | 0e9d2af | 2010-01-25 11:33:03 -0500 | [diff] [blame] | 35 | import android.net.Uri; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.net.wifi.WifiManager; |
Dianne Hackborn | 4840e14 | 2009-03-24 22:40:29 -0700 | [diff] [blame] | 37 | import android.os.Binder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | import android.os.Handler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | import android.os.Message; |
Dianne Hackborn | 4840e14 | 2009-03-24 22:40:29 -0700 | [diff] [blame] | 40 | import android.os.RemoteException; |
San Mehat | 4154c07 | 2010-02-09 18:37:54 -0800 | [diff] [blame] | 41 | import android.os.storage.StorageManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | import android.provider.Settings; |
| 43 | import android.telephony.PhoneStateListener; |
| 44 | import android.telephony.ServiceState; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 45 | import android.telephony.SignalStrength; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | import android.telephony.TelephonyManager; |
| 47 | import android.text.format.DateFormat; |
Daniel Sandler | 2c195f7 | 2010-05-21 15:42:06 -0400 | [diff] [blame] | 48 | import android.text.style.CharacterStyle; |
Eric Fischer | 36e136c | 2010-01-14 17:42:48 -0800 | [diff] [blame] | 49 | import android.text.style.RelativeSizeSpan; |
Daniel Sandler | 2c195f7 | 2010-05-21 15:42:06 -0400 | [diff] [blame] | 50 | import android.text.style.ForegroundColorSpan; |
| 51 | import android.text.style.StyleSpan; |
Eric Fischer | 36e136c | 2010-01-14 17:42:48 -0800 | [diff] [blame] | 52 | import android.text.Spannable; |
| 53 | import android.text.SpannableStringBuilder; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 54 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | import android.view.View; |
| 56 | import android.view.ViewGroup; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | import android.widget.ImageView; |
| 58 | import android.widget.LinearLayout; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 60 | import com.android.internal.app.IBatteryStats; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 61 | import com.android.internal.telephony.IccCard; |
| 62 | import com.android.internal.telephony.TelephonyIntents; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 63 | import com.android.internal.telephony.cdma.EriInfo; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 64 | import com.android.internal.telephony.cdma.TtyIntent; |
| 65 | import com.android.server.am.BatteryStatsService; |
| 66 | |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 67 | import com.android.systemui.R; |
| 68 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | /** |
| 70 | * 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] | 71 | * bar at boot time. It goes through the normal API for icons, even though it probably |
| 72 | * strictly doesn't need to. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | */ |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 74 | public class PhoneStatusBarPolicy { |
| 75 | private static final String TAG = "PhoneStatusBarPolicy"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | // message codes for the handler |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | private static final int EVENT_BATTERY_CLOSE = 4; |
| 79 | |
Daniel Sandler | 2c195f7 | 2010-05-21 15:42:06 -0400 | [diff] [blame] | 80 | private static final int AM_PM_STYLE_NORMAL = 0; |
| 81 | private static final int AM_PM_STYLE_SMALL = 1; |
| 82 | private static final int AM_PM_STYLE_GONE = 2; |
| 83 | |
| 84 | private static final int AM_PM_STYLE = AM_PM_STYLE_GONE; |
| 85 | |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 86 | private static final int INET_CONDITION_THRESHOLD = 50; |
| 87 | |
Dianne Hackborn | 4840e14 | 2009-03-24 22:40:29 -0700 | [diff] [blame] | 88 | private final Context mContext; |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 89 | private final StatusBarManager mService; |
Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 90 | private final Handler mHandler = new Handler(); |
Dianne Hackborn | 4840e14 | 2009-03-24 22:40:29 -0700 | [diff] [blame] | 91 | private final IBatteryStats mBatteryStats; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | |
San Mehat | 4154c07 | 2010-02-09 18:37:54 -0800 | [diff] [blame] | 93 | // storage |
| 94 | private StorageManager mStorageManager; |
| 95 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | // phone |
| 97 | private TelephonyManager mPhone; |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 98 | private int mPhoneSignalIconId; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 99 | |
| 100 | //***** Signal strength icons |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 101 | //GSM/UMTS |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 102 | private static final int[][] sSignalImages = { |
| 103 | { R.drawable.stat_sys_signal_0, |
| 104 | R.drawable.stat_sys_signal_1, |
| 105 | R.drawable.stat_sys_signal_2, |
| 106 | R.drawable.stat_sys_signal_3, |
| 107 | R.drawable.stat_sys_signal_4 }, |
| 108 | { R.drawable.stat_sys_signal_0_fully, |
| 109 | R.drawable.stat_sys_signal_1_fully, |
| 110 | R.drawable.stat_sys_signal_2_fully, |
| 111 | R.drawable.stat_sys_signal_3_fully, |
| 112 | R.drawable.stat_sys_signal_4_fully } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 113 | }; |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 114 | private static final int[][] sSignalImages_r = { |
| 115 | { R.drawable.stat_sys_r_signal_0, |
| 116 | R.drawable.stat_sys_r_signal_1, |
| 117 | R.drawable.stat_sys_r_signal_2, |
| 118 | R.drawable.stat_sys_r_signal_3, |
| 119 | R.drawable.stat_sys_r_signal_4 }, |
| 120 | { R.drawable.stat_sys_r_signal_0_fully, |
| 121 | R.drawable.stat_sys_r_signal_1_fully, |
| 122 | R.drawable.stat_sys_r_signal_2_fully, |
| 123 | R.drawable.stat_sys_r_signal_3_fully, |
| 124 | R.drawable.stat_sys_r_signal_4_fully } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 125 | }; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 126 | private static final int[] sRoamingIndicatorImages_cdma = new int[] { |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 127 | R.drawable.stat_sys_roaming_cdma_0, //Standard Roaming Indicator |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 128 | // 1 is Standard Roaming Indicator OFF |
| 129 | // TODO T: image never used, remove and put 0 instead? |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 130 | R.drawable.stat_sys_roaming_cdma_0, |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 131 | |
| 132 | // 2 is Standard Roaming Indicator FLASHING |
| 133 | // TODO T: image never used, remove and put 0 instead? |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 134 | R.drawable.stat_sys_roaming_cdma_0, |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 135 | |
| 136 | // 3-12 Standard ERI |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 137 | R.drawable.stat_sys_roaming_cdma_0, //3 |
| 138 | R.drawable.stat_sys_roaming_cdma_0, |
| 139 | R.drawable.stat_sys_roaming_cdma_0, |
| 140 | R.drawable.stat_sys_roaming_cdma_0, |
| 141 | R.drawable.stat_sys_roaming_cdma_0, |
| 142 | R.drawable.stat_sys_roaming_cdma_0, |
| 143 | R.drawable.stat_sys_roaming_cdma_0, |
| 144 | R.drawable.stat_sys_roaming_cdma_0, |
| 145 | R.drawable.stat_sys_roaming_cdma_0, |
| 146 | R.drawable.stat_sys_roaming_cdma_0, |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 147 | |
| 148 | // 13-63 Reserved for Standard ERI |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 149 | R.drawable.stat_sys_roaming_cdma_0, //13 |
| 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, |
| 155 | R.drawable.stat_sys_roaming_cdma_0, |
| 156 | R.drawable.stat_sys_roaming_cdma_0, |
| 157 | R.drawable.stat_sys_roaming_cdma_0, |
| 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, |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 200 | |
| 201 | // 64-127 Reserved for Non Standard (Operator Specific) ERI |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 202 | R.drawable.stat_sys_roaming_cdma_0, //64 |
| 203 | R.drawable.stat_sys_roaming_cdma_0, |
| 204 | R.drawable.stat_sys_roaming_cdma_0, |
| 205 | R.drawable.stat_sys_roaming_cdma_0, |
| 206 | R.drawable.stat_sys_roaming_cdma_0, |
| 207 | R.drawable.stat_sys_roaming_cdma_0, |
| 208 | R.drawable.stat_sys_roaming_cdma_0, |
| 209 | R.drawable.stat_sys_roaming_cdma_0, |
| 210 | R.drawable.stat_sys_roaming_cdma_0, |
| 211 | R.drawable.stat_sys_roaming_cdma_0, |
| 212 | R.drawable.stat_sys_roaming_cdma_0, |
| 213 | R.drawable.stat_sys_roaming_cdma_0, |
| 214 | R.drawable.stat_sys_roaming_cdma_0, |
| 215 | R.drawable.stat_sys_roaming_cdma_0, |
| 216 | R.drawable.stat_sys_roaming_cdma_0, |
| 217 | R.drawable.stat_sys_roaming_cdma_0, |
| 218 | R.drawable.stat_sys_roaming_cdma_0, |
| 219 | R.drawable.stat_sys_roaming_cdma_0, |
| 220 | R.drawable.stat_sys_roaming_cdma_0, |
| 221 | R.drawable.stat_sys_roaming_cdma_0 //83 |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 222 | |
| 223 | // 128-255 Reserved |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 224 | }; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 225 | |
| 226 | //***** Data connection icons |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 227 | private int[] mDataIconList = sDataNetType_g[0]; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 228 | //GSM/UMTS |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 229 | private static final int[][] sDataNetType_g = { |
| 230 | { R.drawable.stat_sys_data_connected_g, |
| 231 | R.drawable.stat_sys_data_in_g, |
| 232 | R.drawable.stat_sys_data_out_g, |
| 233 | R.drawable.stat_sys_data_inandout_g }, |
Robert Greenwalt | 26faee3 | 2010-09-10 09:36:43 -0700 | [diff] [blame] | 234 | { R.drawable.stat_sys_data_fully_connected_g, |
| 235 | R.drawable.stat_sys_data_fully_in_g, |
| 236 | R.drawable.stat_sys_data_fully_out_g, |
| 237 | R.drawable.stat_sys_data_fully_inandout_g } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | }; |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 239 | private static final int[][] sDataNetType_3g = { |
| 240 | { R.drawable.stat_sys_data_connected_3g, |
| 241 | R.drawable.stat_sys_data_in_3g, |
| 242 | R.drawable.stat_sys_data_out_3g, |
| 243 | R.drawable.stat_sys_data_inandout_3g }, |
Robert Greenwalt | 26faee3 | 2010-09-10 09:36:43 -0700 | [diff] [blame] | 244 | { R.drawable.stat_sys_data_fully_connected_3g, |
| 245 | R.drawable.stat_sys_data_fully_in_3g, |
| 246 | R.drawable.stat_sys_data_fully_out_3g, |
| 247 | R.drawable.stat_sys_data_fully_inandout_3g } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 248 | }; |
Wink Saville | 2b8bcfe | 2011-02-24 17:58:51 -0800 | [diff] [blame] | 249 | private static final int[][] sDataNetType_4g = { |
| 250 | { R.drawable.stat_sys_data_connected_4g, |
| 251 | R.drawable.stat_sys_data_in_4g, |
| 252 | R.drawable.stat_sys_data_out_4g, |
| 253 | R.drawable.stat_sys_data_inandout_4g }, |
| 254 | { R.drawable.stat_sys_data_fully_connected_4g, |
| 255 | R.drawable.stat_sys_data_fully_in_4g, |
| 256 | R.drawable.stat_sys_data_fully_out_4g, |
| 257 | R.drawable.stat_sys_data_fully_inandout_4g } |
| 258 | }; |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 259 | private static final int[][] sDataNetType_e = { |
| 260 | { R.drawable.stat_sys_data_connected_e, |
| 261 | R.drawable.stat_sys_data_in_e, |
| 262 | R.drawable.stat_sys_data_out_e, |
| 263 | R.drawable.stat_sys_data_inandout_e }, |
Robert Greenwalt | 26faee3 | 2010-09-10 09:36:43 -0700 | [diff] [blame] | 264 | { R.drawable.stat_sys_data_fully_connected_e, |
| 265 | R.drawable.stat_sys_data_fully_in_e, |
| 266 | R.drawable.stat_sys_data_fully_out_e, |
| 267 | R.drawable.stat_sys_data_fully_inandout_e } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 268 | }; |
Li Zhe | ebe6634 | 2009-08-14 19:22:16 +0800 | [diff] [blame] | 269 | //3.5G |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 270 | private static final int[][] sDataNetType_h = { |
| 271 | { R.drawable.stat_sys_data_connected_h, |
| 272 | R.drawable.stat_sys_data_in_h, |
| 273 | R.drawable.stat_sys_data_out_h, |
| 274 | R.drawable.stat_sys_data_inandout_h }, |
Robert Greenwalt | 26faee3 | 2010-09-10 09:36:43 -0700 | [diff] [blame] | 275 | { R.drawable.stat_sys_data_fully_connected_h, |
| 276 | R.drawable.stat_sys_data_fully_in_h, |
| 277 | R.drawable.stat_sys_data_fully_out_h, |
| 278 | R.drawable.stat_sys_data_fully_inandout_h } |
Li Zhe | ebe6634 | 2009-08-14 19:22:16 +0800 | [diff] [blame] | 279 | }; |
| 280 | |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 281 | //CDMA |
johnwang | 9f87cb2 | 2009-08-25 15:25:37 -0700 | [diff] [blame] | 282 | // Use 3G icons for EVDO data and 1x icons for 1XRTT data |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 283 | private static final int[][] sDataNetType_1x = { |
| 284 | { R.drawable.stat_sys_data_connected_1x, |
| 285 | R.drawable.stat_sys_data_in_1x, |
| 286 | R.drawable.stat_sys_data_out_1x, |
| 287 | R.drawable.stat_sys_data_inandout_1x }, |
Robert Greenwalt | 26faee3 | 2010-09-10 09:36:43 -0700 | [diff] [blame] | 288 | { R.drawable.stat_sys_data_fully_connected_1x, |
| 289 | R.drawable.stat_sys_data_fully_in_1x, |
| 290 | R.drawable.stat_sys_data_fully_out_1x, |
| 291 | R.drawable.stat_sys_data_fully_inandout_1x } |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 292 | }; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 293 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 294 | // Assume it's all good unless we hear otherwise. We don't always seem |
| 295 | // to get broadcasts that it *is* there. |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 296 | IccCard.State mSimState = IccCard.State.READY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 297 | int mPhoneState = TelephonyManager.CALL_STATE_IDLE; |
| 298 | int mDataState = TelephonyManager.DATA_DISCONNECTED; |
| 299 | int mDataActivity = TelephonyManager.DATA_ACTIVITY_NONE; |
| 300 | ServiceState mServiceState; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 301 | SignalStrength mSignalStrength; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 302 | |
| 303 | // data connection |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 304 | private boolean mDataIconVisible; |
John Wang | 33e21fc | 2009-10-08 10:35:27 -0700 | [diff] [blame] | 305 | private boolean mHspaDataDistinguishable; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 306 | |
| 307 | // ringer volume |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 308 | private boolean mVolumeVisible; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 309 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 310 | // bluetooth device status |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 311 | private boolean mBluetoothEnabled; |
| 312 | |
| 313 | // wifi |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 314 | private static final int[][] sWifiSignalImages = { |
| 315 | { R.drawable.stat_sys_wifi_signal_1, |
| 316 | R.drawable.stat_sys_wifi_signal_2, |
| 317 | R.drawable.stat_sys_wifi_signal_3, |
| 318 | R.drawable.stat_sys_wifi_signal_4 }, |
Robert Greenwalt | 26faee3 | 2010-09-10 09:36:43 -0700 | [diff] [blame] | 319 | { R.drawable.stat_sys_wifi_signal_1_fully, |
| 320 | R.drawable.stat_sys_wifi_signal_2_fully, |
| 321 | R.drawable.stat_sys_wifi_signal_3_fully, |
| 322 | R.drawable.stat_sys_wifi_signal_4_fully } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 323 | }; |
| 324 | private static final int sWifiTemporarilyNotConnectedImage = |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 325 | R.drawable.stat_sys_wifi_signal_0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 326 | |
| 327 | private int mLastWifiSignalLevel = -1; |
| 328 | private boolean mIsWifiConnected = false; |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 329 | |
| 330 | // state of inet connection - 0 not connected, 100 connected |
| 331 | private int mInetCondition = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 332 | |
| 333 | // sync state |
| 334 | // If sync is active the SyncActive icon is displayed. If sync is not active but |
| 335 | // sync is failing the SyncFailing icon is displayed. Otherwise neither are displayed. |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 336 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 337 | private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { |
| 338 | @Override |
| 339 | public void onReceive(Context context, Intent intent) { |
| 340 | String action = intent.getAction(); |
Joe Onorato | 263700d | 2010-05-14 11:54:53 -0700 | [diff] [blame] | 341 | if (action.equals(Intent.ACTION_BATTERY_CHANGED)) { |
Dianne Hackborn | 8ec5b83 | 2009-07-01 21:19:35 -0700 | [diff] [blame] | 342 | updateBattery(intent); |
| 343 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 344 | else if (action.equals(Intent.ACTION_ALARM_CHANGED)) { |
| 345 | updateAlarm(intent); |
| 346 | } |
| 347 | else if (action.equals(Intent.ACTION_SYNC_STATE_CHANGED)) { |
| 348 | updateSyncState(intent); |
| 349 | } |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 350 | else if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED) || |
Jaikumar Ganesh | d9bb688 | 2010-09-27 17:05:24 -0700 | [diff] [blame] | 351 | action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 352 | updateBluetooth(intent); |
| 353 | } |
| 354 | else if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION) || |
| 355 | action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION) || |
| 356 | action.equals(WifiManager.RSSI_CHANGED_ACTION)) { |
| 357 | updateWifi(intent); |
| 358 | } |
Mike Lockwood | 00b7427 | 2010-03-26 10:41:48 -0400 | [diff] [blame] | 359 | else if (action.equals(LocationManager.GPS_ENABLED_CHANGE_ACTION) || |
| 360 | action.equals(LocationManager.GPS_FIX_CHANGE_ACTION)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 361 | updateGps(intent); |
| 362 | } |
| 363 | else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION) || |
| 364 | action.equals(AudioManager.VIBRATE_SETTING_CHANGED_ACTION)) { |
| 365 | updateVolume(); |
| 366 | } |
| 367 | else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) { |
| 368 | updateSimState(intent); |
| 369 | } |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 370 | else if (action.equals(TtyIntent.TTY_ENABLED_CHANGE_ACTION)) { |
| 371 | updateTTY(intent); |
| 372 | } |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 373 | else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION) || |
| 374 | action.equals(ConnectivityManager.INET_CONDITION_ACTION)) { |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 375 | // TODO - stop using other means to get wifi/mobile info |
| 376 | updateConnectivity(intent); |
| 377 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 378 | } |
| 379 | }; |
| 380 | |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 381 | public PhoneStatusBarPolicy(Context context) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 382 | mContext = context; |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 383 | mService = (StatusBarManager)context.getSystemService(Context.STATUS_BAR_SERVICE); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 384 | mSignalStrength = new SignalStrength(); |
Dianne Hackborn | 4840e14 | 2009-03-24 22:40:29 -0700 | [diff] [blame] | 385 | mBatteryStats = BatteryStatsService.getService(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 386 | |
San Mehat | 4154c07 | 2010-02-09 18:37:54 -0800 | [diff] [blame] | 387 | // storage |
| 388 | mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE); |
| 389 | mStorageManager.registerListener( |
Joe Onorato | fe4f3ae | 2010-06-04 11:25:26 -0700 | [diff] [blame] | 390 | new com.android.systemui.usb.StorageNotification(context)); |
San Mehat | 4154c07 | 2010-02-09 18:37:54 -0800 | [diff] [blame] | 391 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 392 | // battery |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 393 | 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] | 394 | |
| 395 | // phone_signal |
| 396 | mPhone = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 397 | mPhoneSignalIconId = R.drawable.stat_sys_signal_null; |
| 398 | mService.setIcon("phone_signal", mPhoneSignalIconId, 0); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 399 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 400 | // register for phone state notifications. |
| 401 | ((TelephonyManager)mContext.getSystemService(Context.TELEPHONY_SERVICE)) |
| 402 | .listen(mPhoneStateListener, |
| 403 | PhoneStateListener.LISTEN_SERVICE_STATE |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 404 | | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 405 | | PhoneStateListener.LISTEN_CALL_STATE |
| 406 | | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE |
| 407 | | PhoneStateListener.LISTEN_DATA_ACTIVITY); |
| 408 | |
| 409 | // data_connection |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 410 | mService.setIcon("data_connection", R.drawable.stat_sys_data_connected_g, 0); |
| 411 | mService.setIconVisibility("data_connection", false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 412 | |
| 413 | // wifi |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 414 | mService.setIcon("wifi", sWifiSignalImages[0][0], 0); |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 415 | mService.setIconVisibility("wifi", false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 416 | // wifi will get updated by the sticky intents |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 417 | |
| 418 | // TTY status |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 419 | mService.setIcon("tty", R.drawable.stat_sys_tty_mode, 0); |
| 420 | mService.setIconVisibility("tty", false); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 421 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 422 | // Cdma Roaming Indicator, ERI |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 423 | mService.setIcon("cdma_eri", R.drawable.stat_sys_roaming_cdma_0, 0); |
| 424 | mService.setIconVisibility("cdma_eri", false); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 425 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 426 | // bluetooth status |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 427 | mService.setIcon("bluetooth", R.drawable.stat_sys_data_bluetooth, 0); |
Nick Pelly | f242b7b | 2009-10-08 00:12:45 +0200 | [diff] [blame] | 428 | BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 429 | if (adapter != null) { |
| 430 | mBluetoothEnabled = adapter.isEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 431 | } else { |
| 432 | mBluetoothEnabled = false; |
| 433 | } |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 434 | mService.setIconVisibility("bluetooth", mBluetoothEnabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 435 | |
| 436 | // Gps status |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 437 | mService.setIcon("gps", R.drawable.stat_sys_gps_acquiring_anim, 0); |
| 438 | mService.setIconVisibility("gps", false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 439 | |
| 440 | // Alarm clock |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 441 | mService.setIcon("alarm_clock", R.drawable.stat_notify_alarm, 0); |
| 442 | mService.setIconVisibility("alarm_clock", false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 443 | |
| 444 | // Sync state |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 445 | mService.setIcon("sync_active", com.android.internal.R.drawable.stat_notify_sync_anim0, 0); |
| 446 | mService.setIcon("sync_failing", com.android.internal.R.drawable.stat_notify_sync_error, 0); |
| 447 | mService.setIconVisibility("sync_active", false); |
| 448 | mService.setIconVisibility("sync_failing", false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 449 | |
| 450 | // volume |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 451 | mService.setIcon("volume", R.drawable.stat_sys_ringer_silent, 0); |
| 452 | mService.setIconVisibility("volume", false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 453 | updateVolume(); |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 454 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 455 | IntentFilter filter = new IntentFilter(); |
| 456 | |
| 457 | // Register for Intent broadcasts for... |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 458 | filter.addAction(Intent.ACTION_BATTERY_CHANGED); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 459 | filter.addAction(Intent.ACTION_ALARM_CHANGED); |
| 460 | filter.addAction(Intent.ACTION_SYNC_STATE_CHANGED); |
| 461 | filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); |
| 462 | filter.addAction(AudioManager.VIBRATE_SETTING_CHANGED_ACTION); |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 463 | filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); |
Jaikumar Ganesh | d9bb688 | 2010-09-27 17:05:24 -0700 | [diff] [blame] | 464 | filter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 465 | filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); |
| 466 | filter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION); |
| 467 | filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); |
| 468 | filter.addAction(WifiManager.RSSI_CHANGED_ACTION); |
Mike Lockwood | 00b7427 | 2010-03-26 10:41:48 -0400 | [diff] [blame] | 469 | filter.addAction(LocationManager.GPS_ENABLED_CHANGE_ACTION); |
| 470 | filter.addAction(LocationManager.GPS_FIX_CHANGE_ACTION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 471 | filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 472 | filter.addAction(TtyIntent.TTY_ENABLED_CHANGE_ACTION); |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 473 | filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 474 | filter.addAction(ConnectivityManager.INET_CONDITION_ACTION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 475 | mContext.registerReceiver(mIntentReceiver, filter, null, mHandler); |
John Wang | 33e21fc | 2009-10-08 10:35:27 -0700 | [diff] [blame] | 476 | |
| 477 | // load config to determine if to distinguish Hspa data icon |
| 478 | try { |
| 479 | mHspaDataDistinguishable = mContext.getResources().getBoolean( |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 480 | R.bool.config_hspa_data_distinguishable); |
John Wang | 33e21fc | 2009-10-08 10:35:27 -0700 | [diff] [blame] | 481 | } catch (Exception e) { |
| 482 | mHspaDataDistinguishable = false; |
| 483 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 484 | } |
| 485 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 486 | private final void updateAlarm(Intent intent) { |
| 487 | boolean alarmSet = intent.getBooleanExtra("alarmSet", false); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 488 | mService.setIconVisibility("alarm_clock", alarmSet); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | private final void updateSyncState(Intent intent) { |
| 492 | boolean isActive = intent.getBooleanExtra("active", false); |
| 493 | boolean isFailing = intent.getBooleanExtra("failing", false); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 494 | mService.setIconVisibility("sync_active", isActive); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 495 | // 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] | 496 | //mService.setIconVisibility("sync_failing", isFailing && !isActive); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 497 | } |
| 498 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 499 | private final void updateBattery(Intent intent) { |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 500 | final int id = intent.getIntExtra("icon-small", 0); |
| 501 | int level = intent.getIntExtra("level", 0); |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 502 | mService.setIcon("battery", id, level); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 503 | } |
| 504 | |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 505 | private void updateConnectivity(Intent intent) { |
| 506 | NetworkInfo info = (NetworkInfo)(intent.getParcelableExtra( |
| 507 | ConnectivityManager.EXTRA_NETWORK_INFO)); |
| 508 | int connectionStatus = intent.getIntExtra(ConnectivityManager.EXTRA_INET_CONDITION, 0); |
Robert Greenwalt | 029be81 | 2010-09-20 18:01:43 -0700 | [diff] [blame] | 509 | |
| 510 | int inetCondition = (connectionStatus > INET_CONDITION_THRESHOLD ? 1 : 0); |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 511 | |
| 512 | switch (info.getType()) { |
| 513 | case ConnectivityManager.TYPE_MOBILE: |
Robert Greenwalt | 029be81 | 2010-09-20 18:01:43 -0700 | [diff] [blame] | 514 | mInetCondition = inetCondition; |
| 515 | updateDataNetType(info.getSubtype()); |
| 516 | updateDataIcon(); |
| 517 | updateSignalStrength(); // apply any change in connectionStatus |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 518 | break; |
| 519 | case ConnectivityManager.TYPE_WIFI: |
Robert Greenwalt | 029be81 | 2010-09-20 18:01:43 -0700 | [diff] [blame] | 520 | mInetCondition = inetCondition; |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 521 | if (info.isConnected()) { |
| 522 | mIsWifiConnected = true; |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 523 | int iconId; |
| 524 | if (mLastWifiSignalLevel == -1) { |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 525 | iconId = sWifiSignalImages[mInetCondition][0]; |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 526 | } else { |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 527 | iconId = sWifiSignalImages[mInetCondition][mLastWifiSignalLevel]; |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 528 | } |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 529 | mService.setIcon("wifi", iconId, 0); |
| 530 | // Show the icon since wi-fi is connected |
| 531 | mService.setIconVisibility("wifi", true); |
| 532 | } else { |
| 533 | mLastWifiSignalLevel = -1; |
| 534 | mIsWifiConnected = false; |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 535 | int iconId = sWifiSignalImages[0][0]; |
| 536 | |
| 537 | mService.setIcon("wifi", iconId, 0); |
| 538 | // Hide the icon since we're not connected |
| 539 | mService.setIconVisibility("wifi", false); |
| 540 | } |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 541 | updateSignalStrength(); // apply any change in mInetCondition |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 542 | break; |
| 543 | } |
| 544 | } |
| 545 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 546 | private PhoneStateListener mPhoneStateListener = new PhoneStateListener() { |
| 547 | @Override |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 548 | public void onSignalStrengthsChanged(SignalStrength signalStrength) { |
| 549 | mSignalStrength = signalStrength; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 550 | updateSignalStrength(); |
| 551 | } |
| 552 | |
| 553 | @Override |
| 554 | public void onServiceStateChanged(ServiceState state) { |
| 555 | mServiceState = state; |
| 556 | updateSignalStrength(); |
Robert Greenwalt | 98e0b14 | 2009-10-08 21:15:52 -0700 | [diff] [blame] | 557 | updateCdmaRoamingIcon(state); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 558 | updateDataIcon(); |
| 559 | } |
| 560 | |
| 561 | @Override |
| 562 | public void onCallStateChanged(int state, String incomingNumber) { |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 563 | // In cdma, if a voice call is made, RSSI should switch to 1x. |
| 564 | if (isCdma()) { |
| 565 | updateSignalStrength(); |
| 566 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | @Override |
Robert Greenwalt | 98e0b14 | 2009-10-08 21:15:52 -0700 | [diff] [blame] | 570 | public void onDataConnectionStateChanged(int state, int networkType) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 571 | mDataState = state; |
Robert Greenwalt | 029be81 | 2010-09-20 18:01:43 -0700 | [diff] [blame] | 572 | updateDataNetType(networkType); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 573 | updateDataIcon(); |
| 574 | } |
| 575 | |
| 576 | @Override |
| 577 | public void onDataActivity(int direction) { |
| 578 | mDataActivity = direction; |
| 579 | updateDataIcon(); |
| 580 | } |
| 581 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 582 | |
| 583 | private final void updateSimState(Intent intent) { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 584 | String stateExtra = intent.getStringExtra(IccCard.INTENT_KEY_ICC_STATE); |
| 585 | if (IccCard.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) { |
| 586 | mSimState = IccCard.State.ABSENT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 587 | } |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 588 | else if (IccCard.INTENT_VALUE_ICC_READY.equals(stateExtra)) { |
| 589 | mSimState = IccCard.State.READY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 590 | } |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 591 | else if (IccCard.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) { |
| 592 | final String lockedReason = intent.getStringExtra(IccCard.INTENT_KEY_LOCKED_REASON); |
| 593 | if (IccCard.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) { |
| 594 | mSimState = IccCard.State.PIN_REQUIRED; |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 595 | } |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 596 | else if (IccCard.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) { |
| 597 | mSimState = IccCard.State.PUK_REQUIRED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 598 | } |
| 599 | else { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 600 | mSimState = IccCard.State.NETWORK_LOCKED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 601 | } |
| 602 | } else { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 603 | mSimState = IccCard.State.UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 604 | } |
| 605 | updateDataIcon(); |
| 606 | } |
| 607 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 608 | private boolean isCdma() { |
Robert Greenwalt | 98e0b14 | 2009-10-08 21:15:52 -0700 | [diff] [blame] | 609 | return (mSignalStrength != null) && !mSignalStrength.isGsm(); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 610 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 611 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 612 | private boolean hasService() { |
| 613 | if (mServiceState != null) { |
| 614 | switch (mServiceState.getState()) { |
| 615 | case ServiceState.STATE_OUT_OF_SERVICE: |
| 616 | case ServiceState.STATE_POWER_OFF: |
| 617 | return false; |
| 618 | default: |
| 619 | return true; |
| 620 | } |
| 621 | } else { |
| 622 | return false; |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | private final void updateSignalStrength() { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 627 | int[] iconList; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 628 | |
John Wang | 56c2d2f | 2010-04-07 08:57:17 -0700 | [diff] [blame] | 629 | // Display signal strength while in "emergency calls only" mode |
Joe Onorato | 49a8bbf | 2010-09-23 09:50:04 -0700 | [diff] [blame] | 630 | if (mServiceState == null || (!hasService() && !mServiceState.isEmergencyOnly())) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 631 | //Slog.d(TAG, "updateSignalStrength: no service"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 632 | if (Settings.System.getInt(mContext.getContentResolver(), |
| 633 | Settings.System.AIRPLANE_MODE_ON, 0) == 1) { |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 634 | mPhoneSignalIconId = R.drawable.stat_sys_signal_flightmode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 635 | } else { |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 636 | mPhoneSignalIconId = R.drawable.stat_sys_signal_null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 637 | } |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 638 | mService.setIcon("phone_signal", mPhoneSignalIconId, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 639 | return; |
| 640 | } |
| 641 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 642 | if (!isCdma()) { |
Robert Greenwalt | 98e0b14 | 2009-10-08 21:15:52 -0700 | [diff] [blame] | 643 | // Though mPhone is a Manager, this call is not an IPC |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 644 | if (mPhone.isNetworkRoaming()) { |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 645 | iconList = sSignalImages_r[mInetCondition]; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 646 | } else { |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 647 | iconList = sSignalImages[mInetCondition]; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 648 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 649 | } else { |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 650 | iconList = sSignalImages[mInetCondition]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 651 | } |
Wink Saville | 5284090 | 2011-02-18 12:40:47 -0800 | [diff] [blame] | 652 | mPhoneSignalIconId = iconList[mSignalStrength.getLevel()]; |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 653 | mService.setIcon("phone_signal", mPhoneSignalIconId, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 654 | } |
| 655 | |
Robert Greenwalt | 029be81 | 2010-09-20 18:01:43 -0700 | [diff] [blame] | 656 | private final void updateDataNetType(int net) { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 657 | switch (net) { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 658 | case TelephonyManager.NETWORK_TYPE_EDGE: |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 659 | mDataIconList = sDataNetType_e[mInetCondition]; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 660 | break; |
| 661 | case TelephonyManager.NETWORK_TYPE_UMTS: |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 662 | mDataIconList = sDataNetType_3g[mInetCondition]; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 663 | break; |
Li Zhe | ebe6634 | 2009-08-14 19:22:16 +0800 | [diff] [blame] | 664 | case TelephonyManager.NETWORK_TYPE_HSDPA: |
| 665 | case TelephonyManager.NETWORK_TYPE_HSUPA: |
| 666 | case TelephonyManager.NETWORK_TYPE_HSPA: |
John Wang | 33e21fc | 2009-10-08 10:35:27 -0700 | [diff] [blame] | 667 | if (mHspaDataDistinguishable) { |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 668 | mDataIconList = sDataNetType_h[mInetCondition]; |
John Wang | 33e21fc | 2009-10-08 10:35:27 -0700 | [diff] [blame] | 669 | } else { |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 670 | mDataIconList = sDataNetType_3g[mInetCondition]; |
John Wang | 33e21fc | 2009-10-08 10:35:27 -0700 | [diff] [blame] | 671 | } |
Li Zhe | ebe6634 | 2009-08-14 19:22:16 +0800 | [diff] [blame] | 672 | break; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 673 | case TelephonyManager.NETWORK_TYPE_CDMA: |
| 674 | // display 1xRTT for IS95A/B |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 675 | mDataIconList = sDataNetType_1x[mInetCondition]; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 676 | break; |
| 677 | case TelephonyManager.NETWORK_TYPE_1xRTT: |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 678 | mDataIconList = sDataNetType_1x[mInetCondition]; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 679 | break; |
| 680 | case TelephonyManager.NETWORK_TYPE_EVDO_0: //fall through |
| 681 | case TelephonyManager.NETWORK_TYPE_EVDO_A: |
Naveen Kalla | 0a5174a | 2010-04-21 14:48:03 -0700 | [diff] [blame] | 682 | case TelephonyManager.NETWORK_TYPE_EVDO_B: |
Wink Saville | 2b8bcfe | 2011-02-24 17:58:51 -0800 | [diff] [blame] | 683 | case TelephonyManager.NETWORK_TYPE_EHRPD: |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 684 | mDataIconList = sDataNetType_3g[mInetCondition]; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 685 | break; |
Wink Saville | 2b8bcfe | 2011-02-24 17:58:51 -0800 | [diff] [blame] | 686 | case TelephonyManager.NETWORK_TYPE_LTE: |
| 687 | mDataIconList = sDataNetType_4g[mInetCondition]; |
| 688 | break; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 689 | default: |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 690 | mDataIconList = sDataNetType_g[mInetCondition]; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 691 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 692 | } |
| 693 | } |
| 694 | |
| 695 | private final void updateDataIcon() { |
| 696 | int iconId; |
| 697 | boolean visible = true; |
| 698 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 699 | if (!isCdma()) { |
| 700 | // GSM case, we have to check also the sim state |
| 701 | if (mSimState == IccCard.State.READY || mSimState == IccCard.State.UNKNOWN) { |
| 702 | if (hasService() && mDataState == TelephonyManager.DATA_CONNECTED) { |
| 703 | switch (mDataActivity) { |
| 704 | case TelephonyManager.DATA_ACTIVITY_IN: |
| 705 | iconId = mDataIconList[1]; |
| 706 | break; |
| 707 | case TelephonyManager.DATA_ACTIVITY_OUT: |
| 708 | iconId = mDataIconList[2]; |
| 709 | break; |
| 710 | case TelephonyManager.DATA_ACTIVITY_INOUT: |
| 711 | iconId = mDataIconList[3]; |
| 712 | break; |
| 713 | default: |
| 714 | iconId = mDataIconList[0]; |
| 715 | break; |
| 716 | } |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 717 | mService.setIcon("data_connection", iconId, 0); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 718 | } else { |
| 719 | visible = false; |
| 720 | } |
| 721 | } else { |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 722 | iconId = R.drawable.stat_sys_no_sim; |
| 723 | mService.setIcon("data_connection", iconId, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 724 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 725 | } else { |
| 726 | // CDMA case, mDataActivity can be also DATA_ACTIVITY_DORMANT |
| 727 | if (hasService() && mDataState == TelephonyManager.DATA_CONNECTED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 728 | switch (mDataActivity) { |
| 729 | case TelephonyManager.DATA_ACTIVITY_IN: |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 730 | iconId = mDataIconList[1]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 731 | break; |
| 732 | case TelephonyManager.DATA_ACTIVITY_OUT: |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 733 | iconId = mDataIconList[2]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 734 | break; |
| 735 | case TelephonyManager.DATA_ACTIVITY_INOUT: |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 736 | iconId = mDataIconList[3]; |
| 737 | break; |
| 738 | case TelephonyManager.DATA_ACTIVITY_DORMANT: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 739 | default: |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 740 | iconId = mDataIconList[0]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 741 | break; |
| 742 | } |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 743 | mService.setIcon("data_connection", iconId, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 744 | } else { |
| 745 | visible = false; |
| 746 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 747 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 748 | |
Dianne Hackborn | 4840e14 | 2009-03-24 22:40:29 -0700 | [diff] [blame] | 749 | long ident = Binder.clearCallingIdentity(); |
| 750 | try { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 751 | mBatteryStats.notePhoneDataConnectionState(mPhone.getNetworkType(), visible); |
Dianne Hackborn | 4840e14 | 2009-03-24 22:40:29 -0700 | [diff] [blame] | 752 | } catch (RemoteException e) { |
| 753 | } finally { |
| 754 | Binder.restoreCallingIdentity(ident); |
| 755 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 756 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 757 | if (mDataIconVisible != visible) { |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 758 | mService.setIconVisibility("data_connection", visible); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 759 | mDataIconVisible = visible; |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | private final void updateVolume() { |
| 764 | AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); |
| 765 | final int ringerMode = audioManager.getRingerMode(); |
| 766 | final boolean visible = ringerMode == AudioManager.RINGER_MODE_SILENT || |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 767 | ringerMode == AudioManager.RINGER_MODE_VIBRATE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 768 | final int iconId = audioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER) |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 769 | ? R.drawable.stat_sys_ringer_vibrate |
| 770 | : R.drawable.stat_sys_ringer_silent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 771 | |
| 772 | if (visible) { |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 773 | mService.setIcon("volume", iconId, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 774 | } |
| 775 | if (visible != mVolumeVisible) { |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 776 | mService.setIconVisibility("volume", visible); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 777 | mVolumeVisible = visible; |
| 778 | } |
| 779 | } |
| 780 | |
| 781 | private final void updateBluetooth(Intent intent) { |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 782 | int iconId = R.drawable.stat_sys_data_bluetooth; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 783 | String action = intent.getAction(); |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 784 | if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { |
Nick Pelly | b24e11b | 2009-09-08 17:40:43 -0700 | [diff] [blame] | 785 | int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR); |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 786 | mBluetoothEnabled = state == BluetoothAdapter.STATE_ON; |
Jaikumar Ganesh | d9bb688 | 2010-09-27 17:05:24 -0700 | [diff] [blame] | 787 | } else if (action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) { |
Jaikumar Ganesh | 0b63a6a | 2011-07-11 14:34:34 -0700 | [diff] [blame^] | 788 | int state = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE, |
Jaikumar Ganesh | d9bb688 | 2010-09-27 17:05:24 -0700 | [diff] [blame] | 789 | BluetoothAdapter.STATE_DISCONNECTED); |
| 790 | if (state == BluetoothAdapter.STATE_CONNECTED) { |
| 791 | iconId = R.drawable.stat_sys_data_bluetooth_connected; |
Jaikumar Ganesh | 084c665 | 2009-12-07 10:58:18 -0800 | [diff] [blame] | 792 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 793 | } else { |
| 794 | return; |
| 795 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 796 | |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 797 | mService.setIcon("bluetooth", iconId, 0); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 798 | mService.setIconVisibility("bluetooth", mBluetoothEnabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | private final void updateWifi(Intent intent) { |
| 802 | final String action = intent.getAction(); |
| 803 | if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 804 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 805 | final boolean enabled = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, |
| 806 | WifiManager.WIFI_STATE_UNKNOWN) == WifiManager.WIFI_STATE_ENABLED; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 807 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 808 | if (!enabled) { |
| 809 | // If disabled, hide the icon. (We show icon when connected.) |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 810 | mService.setIconVisibility("wifi", false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 811 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 812 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 813 | } else if (action.equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)) { |
| 814 | final boolean enabled = intent.getBooleanExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED, |
| 815 | false); |
| 816 | if (!enabled) { |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 817 | mService.setIconVisibility("wifi", false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 818 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 819 | } else if (action.equals(WifiManager.RSSI_CHANGED_ACTION)) { |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 820 | int iconId; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 821 | final int newRssi = intent.getIntExtra(WifiManager.EXTRA_NEW_RSSI, -200); |
| 822 | int newSignalLevel = WifiManager.calculateSignalLevel(newRssi, |
Robert Greenwalt | fa974c5 | 2010-09-13 15:53:26 -0700 | [diff] [blame] | 823 | sWifiSignalImages[0].length); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 824 | if (newSignalLevel != mLastWifiSignalLevel) { |
| 825 | mLastWifiSignalLevel = newSignalLevel; |
| 826 | if (mIsWifiConnected) { |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 827 | iconId = sWifiSignalImages[mInetCondition][newSignalLevel]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 828 | } else { |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 829 | iconId = sWifiTemporarilyNotConnectedImage; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 830 | } |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 831 | mService.setIcon("wifi", iconId, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 832 | } |
| 833 | } |
| 834 | } |
| 835 | |
| 836 | private final void updateGps(Intent intent) { |
| 837 | final String action = intent.getAction(); |
Mike Lockwood | 00b7427 | 2010-03-26 10:41:48 -0400 | [diff] [blame] | 838 | 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] | 839 | |
Mike Lockwood | 00b7427 | 2010-03-26 10:41:48 -0400 | [diff] [blame] | 840 | if (action.equals(LocationManager.GPS_FIX_CHANGE_ACTION) && enabled) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 841 | // GPS is getting fixes |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 842 | 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] | 843 | mService.setIconVisibility("gps", true); |
Mike Lockwood | 00b7427 | 2010-03-26 10:41:48 -0400 | [diff] [blame] | 844 | } 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] | 845 | // GPS is off |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 846 | mService.setIconVisibility("gps", false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 847 | } else { |
| 848 | // GPS is on, but not receiving fixes |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 849 | mService.setIcon("gps", R.drawable.stat_sys_gps_acquiring_anim, 0); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 850 | mService.setIconVisibility("gps", true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 851 | } |
| 852 | } |
| 853 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 854 | private final void updateTTY(Intent intent) { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 855 | final String action = intent.getAction(); |
| 856 | final boolean enabled = intent.getBooleanExtra(TtyIntent.TTY_ENABLED, false); |
| 857 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 858 | if (false) Slog.v(TAG, "updateTTY: enabled: " + enabled); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 859 | |
| 860 | if (enabled) { |
| 861 | // TTY is on |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 862 | if (false) Slog.v(TAG, "updateTTY: set TTY on"); |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 863 | mService.setIcon("tty", R.drawable.stat_sys_tty_mode, 0); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 864 | mService.setIconVisibility("tty", true); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 865 | } else { |
| 866 | // TTY is off |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 867 | if (false) Slog.v(TAG, "updateTTY: set TTY off"); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 868 | mService.setIconVisibility("tty", false); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 869 | } |
| 870 | } |
| 871 | |
Robert Greenwalt | 98e0b14 | 2009-10-08 21:15:52 -0700 | [diff] [blame] | 872 | private final void updateCdmaRoamingIcon(ServiceState state) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 873 | if (!hasService()) { |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 874 | mService.setIconVisibility("cdma_eri", false); |
Wink Saville | f315238 | 2009-06-01 14:39:20 -0700 | [diff] [blame] | 875 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | if (!isCdma()) { |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 879 | mService.setIconVisibility("cdma_eri", false); |
Wink Saville | f315238 | 2009-06-01 14:39:20 -0700 | [diff] [blame] | 880 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | int[] iconList = sRoamingIndicatorImages_cdma; |
Robert Greenwalt | 98e0b14 | 2009-10-08 21:15:52 -0700 | [diff] [blame] | 884 | int iconIndex = state.getCdmaEriIconIndex(); |
| 885 | int iconMode = state.getCdmaEriIconMode(); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 886 | |
| 887 | if (iconIndex == -1) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 888 | Slog.e(TAG, "getCdmaEriIconIndex returned null, skipping ERI icon update"); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 889 | return; |
| 890 | } |
| 891 | |
| 892 | if (iconMode == -1) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 893 | Slog.e(TAG, "getCdmeEriIconMode returned null, skipping ERI icon update"); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 894 | return; |
| 895 | } |
| 896 | |
| 897 | if (iconIndex == EriInfo.ROAMING_INDICATOR_OFF) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 898 | if (false) Slog.v(TAG, "Cdma ROAMING_INDICATOR_OFF, removing ERI icon"); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 899 | mService.setIconVisibility("cdma_eri", false); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 900 | return; |
| 901 | } |
| 902 | |
| 903 | switch (iconMode) { |
| 904 | case EriInfo.ROAMING_ICON_MODE_NORMAL: |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 905 | mService.setIcon("cdma_eri", iconList[iconIndex], 0); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 906 | mService.setIconVisibility("cdma_eri", true); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 907 | break; |
| 908 | case EriInfo.ROAMING_ICON_MODE_FLASH: |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 909 | mService.setIcon("cdma_eri", R.drawable.stat_sys_roaming_cdma_flash, 0); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 910 | mService.setIconVisibility("cdma_eri", true); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 911 | break; |
| 912 | |
| 913 | } |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 914 | mService.setIcon("phone_signal", mPhoneSignalIconId, 0); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 915 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 916 | } |