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; |
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 | */ |
| 74 | public class StatusBarPolicy { |
| 75 | private static final String TAG = "StatusBarPolicy"; |
| 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 | }; |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 249 | private static final int[][] sDataNetType_e = { |
| 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 }, |
Robert Greenwalt | 26faee3 | 2010-09-10 09:36:43 -0700 | [diff] [blame] | 254 | { R.drawable.stat_sys_data_fully_connected_e, |
| 255 | R.drawable.stat_sys_data_fully_in_e, |
| 256 | R.drawable.stat_sys_data_fully_out_e, |
| 257 | R.drawable.stat_sys_data_fully_inandout_e } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 258 | }; |
Li Zhe | ebe6634 | 2009-08-14 19:22:16 +0800 | [diff] [blame] | 259 | //3.5G |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 260 | private static final int[][] sDataNetType_h = { |
| 261 | { R.drawable.stat_sys_data_connected_h, |
| 262 | R.drawable.stat_sys_data_in_h, |
| 263 | R.drawable.stat_sys_data_out_h, |
| 264 | R.drawable.stat_sys_data_inandout_h }, |
Robert Greenwalt | 26faee3 | 2010-09-10 09:36:43 -0700 | [diff] [blame] | 265 | { R.drawable.stat_sys_data_fully_connected_h, |
| 266 | R.drawable.stat_sys_data_fully_in_h, |
| 267 | R.drawable.stat_sys_data_fully_out_h, |
| 268 | R.drawable.stat_sys_data_fully_inandout_h } |
Li Zhe | ebe6634 | 2009-08-14 19:22:16 +0800 | [diff] [blame] | 269 | }; |
| 270 | |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 271 | //CDMA |
johnwang | 9f87cb2 | 2009-08-25 15:25:37 -0700 | [diff] [blame] | 272 | // Use 3G icons for EVDO data and 1x icons for 1XRTT data |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 273 | private static final int[][] sDataNetType_1x = { |
| 274 | { R.drawable.stat_sys_data_connected_1x, |
| 275 | R.drawable.stat_sys_data_in_1x, |
| 276 | R.drawable.stat_sys_data_out_1x, |
| 277 | R.drawable.stat_sys_data_inandout_1x }, |
Robert Greenwalt | 26faee3 | 2010-09-10 09:36:43 -0700 | [diff] [blame] | 278 | { R.drawable.stat_sys_data_fully_connected_1x, |
| 279 | R.drawable.stat_sys_data_fully_in_1x, |
| 280 | R.drawable.stat_sys_data_fully_out_1x, |
| 281 | R.drawable.stat_sys_data_fully_inandout_1x } |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 282 | }; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 283 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 284 | // Assume it's all good unless we hear otherwise. We don't always seem |
| 285 | // to get broadcasts that it *is* there. |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 286 | IccCard.State mSimState = IccCard.State.READY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 287 | int mPhoneState = TelephonyManager.CALL_STATE_IDLE; |
| 288 | int mDataState = TelephonyManager.DATA_DISCONNECTED; |
| 289 | int mDataActivity = TelephonyManager.DATA_ACTIVITY_NONE; |
| 290 | ServiceState mServiceState; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 291 | SignalStrength mSignalStrength; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 292 | |
| 293 | // data connection |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 294 | private boolean mDataIconVisible; |
John Wang | 33e21fc | 2009-10-08 10:35:27 -0700 | [diff] [blame] | 295 | private boolean mHspaDataDistinguishable; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 296 | |
| 297 | // ringer volume |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 298 | private boolean mVolumeVisible; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 299 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 300 | // bluetooth device status |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 301 | private boolean mBluetoothEnabled; |
| 302 | |
| 303 | // wifi |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 304 | private static final int[][] sWifiSignalImages = { |
| 305 | { R.drawable.stat_sys_wifi_signal_1, |
| 306 | R.drawable.stat_sys_wifi_signal_2, |
| 307 | R.drawable.stat_sys_wifi_signal_3, |
| 308 | R.drawable.stat_sys_wifi_signal_4 }, |
Robert Greenwalt | 26faee3 | 2010-09-10 09:36:43 -0700 | [diff] [blame] | 309 | { R.drawable.stat_sys_wifi_signal_1_fully, |
| 310 | R.drawable.stat_sys_wifi_signal_2_fully, |
| 311 | R.drawable.stat_sys_wifi_signal_3_fully, |
| 312 | R.drawable.stat_sys_wifi_signal_4_fully } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 313 | }; |
| 314 | private static final int sWifiTemporarilyNotConnectedImage = |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 315 | R.drawable.stat_sys_wifi_signal_0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 316 | |
| 317 | private int mLastWifiSignalLevel = -1; |
| 318 | private boolean mIsWifiConnected = false; |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 319 | |
| 320 | // state of inet connection - 0 not connected, 100 connected |
| 321 | private int mInetCondition = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 322 | |
| 323 | // sync state |
| 324 | // If sync is active the SyncActive icon is displayed. If sync is not active but |
| 325 | // sync is failing the SyncFailing icon is displayed. Otherwise neither are displayed. |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 326 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 327 | private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { |
| 328 | @Override |
| 329 | public void onReceive(Context context, Intent intent) { |
| 330 | String action = intent.getAction(); |
Joe Onorato | 263700d | 2010-05-14 11:54:53 -0700 | [diff] [blame] | 331 | if (action.equals(Intent.ACTION_BATTERY_CHANGED)) { |
Dianne Hackborn | 8ec5b83 | 2009-07-01 21:19:35 -0700 | [diff] [blame] | 332 | updateBattery(intent); |
| 333 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 334 | else if (action.equals(Intent.ACTION_ALARM_CHANGED)) { |
| 335 | updateAlarm(intent); |
| 336 | } |
| 337 | else if (action.equals(Intent.ACTION_SYNC_STATE_CHANGED)) { |
| 338 | updateSyncState(intent); |
| 339 | } |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 340 | else if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED) || |
Jaikumar Ganesh | d9bb688 | 2010-09-27 17:05:24 -0700 | [diff] [blame] | 341 | action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 342 | updateBluetooth(intent); |
| 343 | } |
| 344 | else if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION) || |
| 345 | action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION) || |
| 346 | action.equals(WifiManager.RSSI_CHANGED_ACTION)) { |
| 347 | updateWifi(intent); |
| 348 | } |
Mike Lockwood | 00b7427 | 2010-03-26 10:41:48 -0400 | [diff] [blame] | 349 | else if (action.equals(LocationManager.GPS_ENABLED_CHANGE_ACTION) || |
| 350 | action.equals(LocationManager.GPS_FIX_CHANGE_ACTION)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 351 | updateGps(intent); |
| 352 | } |
| 353 | else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION) || |
| 354 | action.equals(AudioManager.VIBRATE_SETTING_CHANGED_ACTION)) { |
| 355 | updateVolume(); |
| 356 | } |
| 357 | else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) { |
| 358 | updateSimState(intent); |
| 359 | } |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 360 | else if (action.equals(TtyIntent.TTY_ENABLED_CHANGE_ACTION)) { |
| 361 | updateTTY(intent); |
| 362 | } |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 363 | else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION) || |
| 364 | action.equals(ConnectivityManager.INET_CONDITION_ACTION)) { |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 365 | // TODO - stop using other means to get wifi/mobile info |
| 366 | updateConnectivity(intent); |
| 367 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 368 | } |
| 369 | }; |
| 370 | |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 371 | public StatusBarPolicy(Context context) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | mContext = context; |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 373 | mService = (StatusBarManager)context.getSystemService(Context.STATUS_BAR_SERVICE); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 374 | mSignalStrength = new SignalStrength(); |
Dianne Hackborn | 4840e14 | 2009-03-24 22:40:29 -0700 | [diff] [blame] | 375 | mBatteryStats = BatteryStatsService.getService(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 | |
San Mehat | 4154c07 | 2010-02-09 18:37:54 -0800 | [diff] [blame] | 377 | // storage |
| 378 | mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE); |
| 379 | mStorageManager.registerListener( |
Joe Onorato | fe4f3ae | 2010-06-04 11:25:26 -0700 | [diff] [blame] | 380 | new com.android.systemui.usb.StorageNotification(context)); |
San Mehat | 4154c07 | 2010-02-09 18:37:54 -0800 | [diff] [blame] | 381 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 382 | // battery |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 383 | 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] | 384 | |
| 385 | // phone_signal |
| 386 | mPhone = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 387 | mPhoneSignalIconId = R.drawable.stat_sys_signal_null; |
| 388 | mService.setIcon("phone_signal", mPhoneSignalIconId, 0); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 389 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 390 | // register for phone state notifications. |
| 391 | ((TelephonyManager)mContext.getSystemService(Context.TELEPHONY_SERVICE)) |
| 392 | .listen(mPhoneStateListener, |
| 393 | PhoneStateListener.LISTEN_SERVICE_STATE |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 394 | | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 395 | | PhoneStateListener.LISTEN_CALL_STATE |
| 396 | | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE |
| 397 | | PhoneStateListener.LISTEN_DATA_ACTIVITY); |
| 398 | |
| 399 | // data_connection |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 400 | mService.setIcon("data_connection", R.drawable.stat_sys_data_connected_g, 0); |
| 401 | mService.setIconVisibility("data_connection", false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | |
| 403 | // wifi |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 404 | mService.setIcon("wifi", sWifiSignalImages[0][0], 0); |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 405 | mService.setIconVisibility("wifi", false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 406 | // wifi will get updated by the sticky intents |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 407 | |
| 408 | // TTY status |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 409 | mService.setIcon("tty", R.drawable.stat_sys_tty_mode, 0); |
| 410 | mService.setIconVisibility("tty", false); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 411 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 412 | // Cdma Roaming Indicator, ERI |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 413 | mService.setIcon("cdma_eri", R.drawable.stat_sys_roaming_cdma_0, 0); |
| 414 | mService.setIconVisibility("cdma_eri", false); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 415 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 416 | // bluetooth status |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 417 | mService.setIcon("bluetooth", R.drawable.stat_sys_data_bluetooth, 0); |
Nick Pelly | f242b7b | 2009-10-08 00:12:45 +0200 | [diff] [blame] | 418 | BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 419 | if (adapter != null) { |
| 420 | mBluetoothEnabled = adapter.isEnabled(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 421 | } else { |
| 422 | mBluetoothEnabled = false; |
| 423 | } |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 424 | mService.setIconVisibility("bluetooth", mBluetoothEnabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 425 | |
| 426 | // Gps status |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 427 | mService.setIcon("gps", R.drawable.stat_sys_gps_acquiring_anim, 0); |
| 428 | mService.setIconVisibility("gps", false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 429 | |
| 430 | // Alarm clock |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 431 | mService.setIcon("alarm_clock", R.drawable.stat_notify_alarm, 0); |
| 432 | mService.setIconVisibility("alarm_clock", false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 433 | |
| 434 | // Sync state |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 435 | mService.setIcon("sync_active", com.android.internal.R.drawable.stat_notify_sync_anim0, 0); |
| 436 | mService.setIcon("sync_failing", com.android.internal.R.drawable.stat_notify_sync_error, 0); |
| 437 | mService.setIconVisibility("sync_active", false); |
| 438 | mService.setIconVisibility("sync_failing", false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 439 | |
| 440 | // volume |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 441 | mService.setIcon("volume", R.drawable.stat_sys_ringer_silent, 0); |
| 442 | mService.setIconVisibility("volume", false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 443 | updateVolume(); |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 444 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 445 | IntentFilter filter = new IntentFilter(); |
| 446 | |
| 447 | // Register for Intent broadcasts for... |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 448 | filter.addAction(Intent.ACTION_BATTERY_CHANGED); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 449 | filter.addAction(Intent.ACTION_ALARM_CHANGED); |
| 450 | filter.addAction(Intent.ACTION_SYNC_STATE_CHANGED); |
| 451 | filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); |
| 452 | filter.addAction(AudioManager.VIBRATE_SETTING_CHANGED_ACTION); |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 453 | filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); |
Jaikumar Ganesh | d9bb688 | 2010-09-27 17:05:24 -0700 | [diff] [blame] | 454 | filter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 455 | filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); |
| 456 | filter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION); |
| 457 | filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); |
| 458 | filter.addAction(WifiManager.RSSI_CHANGED_ACTION); |
Mike Lockwood | 00b7427 | 2010-03-26 10:41:48 -0400 | [diff] [blame] | 459 | filter.addAction(LocationManager.GPS_ENABLED_CHANGE_ACTION); |
| 460 | filter.addAction(LocationManager.GPS_FIX_CHANGE_ACTION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 461 | filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 462 | filter.addAction(TtyIntent.TTY_ENABLED_CHANGE_ACTION); |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 463 | filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 464 | filter.addAction(ConnectivityManager.INET_CONDITION_ACTION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 465 | mContext.registerReceiver(mIntentReceiver, filter, null, mHandler); |
John Wang | 33e21fc | 2009-10-08 10:35:27 -0700 | [diff] [blame] | 466 | |
| 467 | // load config to determine if to distinguish Hspa data icon |
| 468 | try { |
| 469 | mHspaDataDistinguishable = mContext.getResources().getBoolean( |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 470 | R.bool.config_hspa_data_distinguishable); |
John Wang | 33e21fc | 2009-10-08 10:35:27 -0700 | [diff] [blame] | 471 | } catch (Exception e) { |
| 472 | mHspaDataDistinguishable = false; |
| 473 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 474 | } |
| 475 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 476 | private final void updateAlarm(Intent intent) { |
| 477 | boolean alarmSet = intent.getBooleanExtra("alarmSet", false); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 478 | mService.setIconVisibility("alarm_clock", alarmSet); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | private final void updateSyncState(Intent intent) { |
| 482 | boolean isActive = intent.getBooleanExtra("active", false); |
| 483 | boolean isFailing = intent.getBooleanExtra("failing", false); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 484 | mService.setIconVisibility("sync_active", isActive); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 485 | // 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] | 486 | //mService.setIconVisibility("sync_failing", isFailing && !isActive); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 487 | } |
| 488 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 489 | private final void updateBattery(Intent intent) { |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 490 | final int id = intent.getIntExtra("icon-small", 0); |
| 491 | int level = intent.getIntExtra("level", 0); |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 492 | mService.setIcon("battery", id, level); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 493 | } |
| 494 | |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 495 | private void updateConnectivity(Intent intent) { |
| 496 | NetworkInfo info = (NetworkInfo)(intent.getParcelableExtra( |
| 497 | ConnectivityManager.EXTRA_NETWORK_INFO)); |
| 498 | int connectionStatus = intent.getIntExtra(ConnectivityManager.EXTRA_INET_CONDITION, 0); |
Robert Greenwalt | 029be81 | 2010-09-20 18:01:43 -0700 | [diff] [blame] | 499 | |
| 500 | int inetCondition = (connectionStatus > INET_CONDITION_THRESHOLD ? 1 : 0); |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 501 | |
| 502 | switch (info.getType()) { |
| 503 | case ConnectivityManager.TYPE_MOBILE: |
Robert Greenwalt | 029be81 | 2010-09-20 18:01:43 -0700 | [diff] [blame] | 504 | mInetCondition = inetCondition; |
| 505 | updateDataNetType(info.getSubtype()); |
| 506 | updateDataIcon(); |
| 507 | updateSignalStrength(); // apply any change in connectionStatus |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 508 | break; |
| 509 | case ConnectivityManager.TYPE_WIFI: |
Robert Greenwalt | 029be81 | 2010-09-20 18:01:43 -0700 | [diff] [blame] | 510 | mInetCondition = inetCondition; |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 511 | if (info.isConnected()) { |
| 512 | mIsWifiConnected = true; |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 513 | int iconId; |
| 514 | if (mLastWifiSignalLevel == -1) { |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 515 | iconId = sWifiSignalImages[mInetCondition][0]; |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 516 | } else { |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 517 | iconId = sWifiSignalImages[mInetCondition][mLastWifiSignalLevel]; |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 518 | } |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 519 | mService.setIcon("wifi", iconId, 0); |
| 520 | // Show the icon since wi-fi is connected |
| 521 | mService.setIconVisibility("wifi", true); |
| 522 | } else { |
| 523 | mLastWifiSignalLevel = -1; |
| 524 | mIsWifiConnected = false; |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 525 | int iconId = sWifiSignalImages[0][0]; |
| 526 | |
| 527 | mService.setIcon("wifi", iconId, 0); |
| 528 | // Hide the icon since we're not connected |
| 529 | mService.setIconVisibility("wifi", false); |
| 530 | } |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 531 | updateSignalStrength(); // apply any change in mInetCondition |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 532 | break; |
| 533 | } |
| 534 | } |
| 535 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 536 | private PhoneStateListener mPhoneStateListener = new PhoneStateListener() { |
| 537 | @Override |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 538 | public void onSignalStrengthsChanged(SignalStrength signalStrength) { |
| 539 | mSignalStrength = signalStrength; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 540 | updateSignalStrength(); |
| 541 | } |
| 542 | |
| 543 | @Override |
| 544 | public void onServiceStateChanged(ServiceState state) { |
| 545 | mServiceState = state; |
| 546 | updateSignalStrength(); |
Robert Greenwalt | 98e0b14 | 2009-10-08 21:15:52 -0700 | [diff] [blame] | 547 | updateCdmaRoamingIcon(state); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 548 | updateDataIcon(); |
| 549 | } |
| 550 | |
| 551 | @Override |
| 552 | public void onCallStateChanged(int state, String incomingNumber) { |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 553 | // In cdma, if a voice call is made, RSSI should switch to 1x. |
| 554 | if (isCdma()) { |
| 555 | updateSignalStrength(); |
| 556 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | @Override |
Robert Greenwalt | 98e0b14 | 2009-10-08 21:15:52 -0700 | [diff] [blame] | 560 | public void onDataConnectionStateChanged(int state, int networkType) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 561 | mDataState = state; |
Robert Greenwalt | 029be81 | 2010-09-20 18:01:43 -0700 | [diff] [blame] | 562 | updateDataNetType(networkType); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 563 | updateDataIcon(); |
| 564 | } |
| 565 | |
| 566 | @Override |
| 567 | public void onDataActivity(int direction) { |
| 568 | mDataActivity = direction; |
| 569 | updateDataIcon(); |
| 570 | } |
| 571 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 572 | |
| 573 | private final void updateSimState(Intent intent) { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 574 | String stateExtra = intent.getStringExtra(IccCard.INTENT_KEY_ICC_STATE); |
| 575 | if (IccCard.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) { |
| 576 | mSimState = IccCard.State.ABSENT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 577 | } |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 578 | else if (IccCard.INTENT_VALUE_ICC_READY.equals(stateExtra)) { |
| 579 | mSimState = IccCard.State.READY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 580 | } |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 581 | else if (IccCard.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) { |
| 582 | final String lockedReason = intent.getStringExtra(IccCard.INTENT_KEY_LOCKED_REASON); |
| 583 | if (IccCard.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) { |
| 584 | mSimState = IccCard.State.PIN_REQUIRED; |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 585 | } |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 586 | else if (IccCard.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) { |
| 587 | mSimState = IccCard.State.PUK_REQUIRED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 588 | } |
| 589 | else { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 590 | mSimState = IccCard.State.NETWORK_LOCKED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 591 | } |
| 592 | } else { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 593 | mSimState = IccCard.State.UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 594 | } |
| 595 | updateDataIcon(); |
| 596 | } |
| 597 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 598 | private boolean isCdma() { |
Robert Greenwalt | 98e0b14 | 2009-10-08 21:15:52 -0700 | [diff] [blame] | 599 | return (mSignalStrength != null) && !mSignalStrength.isGsm(); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 600 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 601 | |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 602 | private boolean isEvdo() { |
| 603 | return ( (mServiceState != null) |
| 604 | && ((mServiceState.getRadioTechnology() |
| 605 | == ServiceState.RADIO_TECHNOLOGY_EVDO_0) |
| 606 | || (mServiceState.getRadioTechnology() |
Naveen Kalla | 0a5174a | 2010-04-21 14:48:03 -0700 | [diff] [blame] | 607 | == ServiceState.RADIO_TECHNOLOGY_EVDO_A) |
| 608 | || (mServiceState.getRadioTechnology() |
| 609 | == ServiceState.RADIO_TECHNOLOGY_EVDO_B))); |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 610 | } |
| 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() { |
| 627 | int iconLevel = -1; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 628 | int[] iconList; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 629 | |
John Wang | 56c2d2f | 2010-04-07 08:57:17 -0700 | [diff] [blame] | 630 | // Display signal strength while in "emergency calls only" mode |
Joe Onorato | 49a8bbf | 2010-09-23 09:50:04 -0700 | [diff] [blame] | 631 | if (mServiceState == null || (!hasService() && !mServiceState.isEmergencyOnly())) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 632 | //Slog.d(TAG, "updateSignalStrength: no service"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 633 | if (Settings.System.getInt(mContext.getContentResolver(), |
| 634 | Settings.System.AIRPLANE_MODE_ON, 0) == 1) { |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 635 | mPhoneSignalIconId = R.drawable.stat_sys_signal_flightmode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 636 | } else { |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 637 | mPhoneSignalIconId = R.drawable.stat_sys_signal_null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 638 | } |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 639 | mService.setIcon("phone_signal", mPhoneSignalIconId, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 640 | return; |
| 641 | } |
| 642 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 643 | if (!isCdma()) { |
| 644 | int asu = mSignalStrength.getGsmSignalStrength(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 645 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 646 | // ASU ranges from 0 to 31 - TS 27.007 Sec 8.5 |
| 647 | // asu = 0 (-113dB or less) is very weak |
| 648 | // signal, its better to show 0 bars to the user in such cases. |
| 649 | // asu = 99 is a special case, where the signal strength is unknown. |
jsh | ee63e47 | 2010-03-18 11:14:42 -0700 | [diff] [blame] | 650 | if (asu <= 2 || asu == 99) iconLevel = 0; |
| 651 | else if (asu >= 12) iconLevel = 4; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 652 | else if (asu >= 8) iconLevel = 3; |
jsh | ee63e47 | 2010-03-18 11:14:42 -0700 | [diff] [blame] | 653 | else if (asu >= 5) iconLevel = 2; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 654 | else iconLevel = 1; |
| 655 | |
Robert Greenwalt | 98e0b14 | 2009-10-08 21:15:52 -0700 | [diff] [blame] | 656 | // Though mPhone is a Manager, this call is not an IPC |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 657 | if (mPhone.isNetworkRoaming()) { |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 658 | iconList = sSignalImages_r[mInetCondition]; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 659 | } else { |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 660 | iconList = sSignalImages[mInetCondition]; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 661 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 662 | } else { |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 663 | iconList = sSignalImages[mInetCondition]; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 664 | |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 665 | // If 3G(EV) and 1x network are available than 3G should be |
| 666 | // displayed, displayed RSSI should be from the EV side. |
| 667 | // If a voice call is made then RSSI should switch to 1x. |
| 668 | if ((mPhoneState == TelephonyManager.CALL_STATE_IDLE) && isEvdo()){ |
| 669 | iconLevel = getEvdoLevel(); |
| 670 | if (false) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 671 | Slog.d(TAG, "use Evdo level=" + iconLevel + " to replace Cdma Level=" + getCdmaLevel()); |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 672 | } |
| 673 | } else { |
| 674 | iconLevel = getCdmaLevel(); |
| 675 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 676 | } |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 677 | mPhoneSignalIconId = iconList[iconLevel]; |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 678 | mService.setIcon("phone_signal", mPhoneSignalIconId, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 679 | } |
| 680 | |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 681 | private int getCdmaLevel() { |
| 682 | final int cdmaDbm = mSignalStrength.getCdmaDbm(); |
| 683 | final int cdmaEcio = mSignalStrength.getCdmaEcio(); |
| 684 | int levelDbm = 0; |
| 685 | int levelEcio = 0; |
| 686 | |
| 687 | if (cdmaDbm >= -75) levelDbm = 4; |
| 688 | else if (cdmaDbm >= -85) levelDbm = 3; |
| 689 | else if (cdmaDbm >= -95) levelDbm = 2; |
| 690 | else if (cdmaDbm >= -100) levelDbm = 1; |
| 691 | else levelDbm = 0; |
| 692 | |
| 693 | // Ec/Io are in dB*10 |
| 694 | if (cdmaEcio >= -90) levelEcio = 4; |
| 695 | else if (cdmaEcio >= -110) levelEcio = 3; |
| 696 | else if (cdmaEcio >= -130) levelEcio = 2; |
| 697 | else if (cdmaEcio >= -150) levelEcio = 1; |
| 698 | else levelEcio = 0; |
| 699 | |
| 700 | return (levelDbm < levelEcio) ? levelDbm : levelEcio; |
| 701 | } |
| 702 | |
| 703 | private int getEvdoLevel() { |
| 704 | int evdoDbm = mSignalStrength.getEvdoDbm(); |
| 705 | int evdoSnr = mSignalStrength.getEvdoSnr(); |
| 706 | int levelEvdoDbm = 0; |
| 707 | int levelEvdoSnr = 0; |
| 708 | |
| 709 | if (evdoDbm >= -65) levelEvdoDbm = 4; |
| 710 | else if (evdoDbm >= -75) levelEvdoDbm = 3; |
| 711 | else if (evdoDbm >= -90) levelEvdoDbm = 2; |
| 712 | else if (evdoDbm >= -105) levelEvdoDbm = 1; |
| 713 | else levelEvdoDbm = 0; |
| 714 | |
John Michelau | 1336a56 | 2009-09-28 10:41:02 -0500 | [diff] [blame] | 715 | if (evdoSnr >= 7) levelEvdoSnr = 4; |
| 716 | else if (evdoSnr >= 5) levelEvdoSnr = 3; |
| 717 | else if (evdoSnr >= 3) levelEvdoSnr = 2; |
| 718 | else if (evdoSnr >= 1) levelEvdoSnr = 1; |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 719 | else levelEvdoSnr = 0; |
| 720 | |
| 721 | return (levelEvdoDbm < levelEvdoSnr) ? levelEvdoDbm : levelEvdoSnr; |
| 722 | } |
| 723 | |
Robert Greenwalt | 029be81 | 2010-09-20 18:01:43 -0700 | [diff] [blame] | 724 | private final void updateDataNetType(int net) { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 725 | switch (net) { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 726 | case TelephonyManager.NETWORK_TYPE_EDGE: |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 727 | mDataIconList = sDataNetType_e[mInetCondition]; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 728 | break; |
| 729 | case TelephonyManager.NETWORK_TYPE_UMTS: |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 730 | mDataIconList = sDataNetType_3g[mInetCondition]; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 731 | break; |
Li Zhe | ebe6634 | 2009-08-14 19:22:16 +0800 | [diff] [blame] | 732 | case TelephonyManager.NETWORK_TYPE_HSDPA: |
| 733 | case TelephonyManager.NETWORK_TYPE_HSUPA: |
| 734 | case TelephonyManager.NETWORK_TYPE_HSPA: |
John Wang | 33e21fc | 2009-10-08 10:35:27 -0700 | [diff] [blame] | 735 | if (mHspaDataDistinguishable) { |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 736 | mDataIconList = sDataNetType_h[mInetCondition]; |
John Wang | 33e21fc | 2009-10-08 10:35:27 -0700 | [diff] [blame] | 737 | } else { |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 738 | mDataIconList = sDataNetType_3g[mInetCondition]; |
John Wang | 33e21fc | 2009-10-08 10:35:27 -0700 | [diff] [blame] | 739 | } |
Li Zhe | ebe6634 | 2009-08-14 19:22:16 +0800 | [diff] [blame] | 740 | break; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 741 | case TelephonyManager.NETWORK_TYPE_CDMA: |
| 742 | // display 1xRTT for IS95A/B |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 743 | mDataIconList = sDataNetType_1x[mInetCondition]; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 744 | break; |
| 745 | case TelephonyManager.NETWORK_TYPE_1xRTT: |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 746 | mDataIconList = sDataNetType_1x[mInetCondition]; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 747 | break; |
| 748 | case TelephonyManager.NETWORK_TYPE_EVDO_0: //fall through |
| 749 | case TelephonyManager.NETWORK_TYPE_EVDO_A: |
Naveen Kalla | 0a5174a | 2010-04-21 14:48:03 -0700 | [diff] [blame] | 750 | case TelephonyManager.NETWORK_TYPE_EVDO_B: |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 751 | mDataIconList = sDataNetType_3g[mInetCondition]; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 752 | break; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame^] | 753 | // TODO - add support for NETWORK_TYPE_LTE and NETWORK_TYPE_EHRPD |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 754 | default: |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 755 | mDataIconList = sDataNetType_g[mInetCondition]; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 756 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 757 | } |
| 758 | } |
| 759 | |
| 760 | private final void updateDataIcon() { |
| 761 | int iconId; |
| 762 | boolean visible = true; |
| 763 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 764 | if (!isCdma()) { |
| 765 | // GSM case, we have to check also the sim state |
| 766 | if (mSimState == IccCard.State.READY || mSimState == IccCard.State.UNKNOWN) { |
| 767 | if (hasService() && mDataState == TelephonyManager.DATA_CONNECTED) { |
| 768 | switch (mDataActivity) { |
| 769 | case TelephonyManager.DATA_ACTIVITY_IN: |
| 770 | iconId = mDataIconList[1]; |
| 771 | break; |
| 772 | case TelephonyManager.DATA_ACTIVITY_OUT: |
| 773 | iconId = mDataIconList[2]; |
| 774 | break; |
| 775 | case TelephonyManager.DATA_ACTIVITY_INOUT: |
| 776 | iconId = mDataIconList[3]; |
| 777 | break; |
| 778 | default: |
| 779 | iconId = mDataIconList[0]; |
| 780 | break; |
| 781 | } |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 782 | mService.setIcon("data_connection", iconId, 0); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 783 | } else { |
| 784 | visible = false; |
| 785 | } |
| 786 | } else { |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 787 | iconId = R.drawable.stat_sys_no_sim; |
| 788 | mService.setIcon("data_connection", iconId, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 789 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 790 | } else { |
| 791 | // CDMA case, mDataActivity can be also DATA_ACTIVITY_DORMANT |
| 792 | if (hasService() && mDataState == TelephonyManager.DATA_CONNECTED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 793 | switch (mDataActivity) { |
| 794 | case TelephonyManager.DATA_ACTIVITY_IN: |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 795 | iconId = mDataIconList[1]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 796 | break; |
| 797 | case TelephonyManager.DATA_ACTIVITY_OUT: |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 798 | iconId = mDataIconList[2]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 799 | break; |
| 800 | case TelephonyManager.DATA_ACTIVITY_INOUT: |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 801 | iconId = mDataIconList[3]; |
| 802 | break; |
| 803 | case TelephonyManager.DATA_ACTIVITY_DORMANT: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 804 | default: |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 805 | iconId = mDataIconList[0]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 806 | break; |
| 807 | } |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 808 | mService.setIcon("data_connection", iconId, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 809 | } else { |
| 810 | visible = false; |
| 811 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 812 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 813 | |
Dianne Hackborn | 4840e14 | 2009-03-24 22:40:29 -0700 | [diff] [blame] | 814 | long ident = Binder.clearCallingIdentity(); |
| 815 | try { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 816 | mBatteryStats.notePhoneDataConnectionState(mPhone.getNetworkType(), visible); |
Dianne Hackborn | 4840e14 | 2009-03-24 22:40:29 -0700 | [diff] [blame] | 817 | } catch (RemoteException e) { |
| 818 | } finally { |
| 819 | Binder.restoreCallingIdentity(ident); |
| 820 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 821 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 822 | if (mDataIconVisible != visible) { |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 823 | mService.setIconVisibility("data_connection", visible); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 824 | mDataIconVisible = visible; |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | private final void updateVolume() { |
| 829 | AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); |
| 830 | final int ringerMode = audioManager.getRingerMode(); |
| 831 | final boolean visible = ringerMode == AudioManager.RINGER_MODE_SILENT || |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 832 | ringerMode == AudioManager.RINGER_MODE_VIBRATE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 833 | final int iconId = audioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER) |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 834 | ? R.drawable.stat_sys_ringer_vibrate |
| 835 | : R.drawable.stat_sys_ringer_silent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 836 | |
| 837 | if (visible) { |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 838 | mService.setIcon("volume", iconId, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 839 | } |
| 840 | if (visible != mVolumeVisible) { |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 841 | mService.setIconVisibility("volume", visible); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 842 | mVolumeVisible = visible; |
| 843 | } |
| 844 | } |
| 845 | |
| 846 | private final void updateBluetooth(Intent intent) { |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 847 | int iconId = R.drawable.stat_sys_data_bluetooth; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 848 | String action = intent.getAction(); |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 849 | if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { |
Nick Pelly | b24e11b | 2009-09-08 17:40:43 -0700 | [diff] [blame] | 850 | int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR); |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 851 | mBluetoothEnabled = state == BluetoothAdapter.STATE_ON; |
Jaikumar Ganesh | d9bb688 | 2010-09-27 17:05:24 -0700 | [diff] [blame] | 852 | } else if (action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) { |
| 853 | int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, |
| 854 | BluetoothAdapter.STATE_DISCONNECTED); |
| 855 | if (state == BluetoothAdapter.STATE_CONNECTED) { |
| 856 | iconId = R.drawable.stat_sys_data_bluetooth_connected; |
Jaikumar Ganesh | 084c665 | 2009-12-07 10:58:18 -0800 | [diff] [blame] | 857 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 858 | } else { |
| 859 | return; |
| 860 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 861 | |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 862 | mService.setIcon("bluetooth", iconId, 0); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 863 | mService.setIconVisibility("bluetooth", mBluetoothEnabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | private final void updateWifi(Intent intent) { |
| 867 | final String action = intent.getAction(); |
| 868 | if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 869 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 870 | final boolean enabled = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, |
| 871 | WifiManager.WIFI_STATE_UNKNOWN) == WifiManager.WIFI_STATE_ENABLED; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 872 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 873 | if (!enabled) { |
| 874 | // If disabled, hide the icon. (We show icon when connected.) |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 875 | mService.setIconVisibility("wifi", false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 876 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 877 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 878 | } else if (action.equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)) { |
| 879 | final boolean enabled = intent.getBooleanExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED, |
| 880 | false); |
| 881 | if (!enabled) { |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 882 | mService.setIconVisibility("wifi", false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 883 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 884 | } else if (action.equals(WifiManager.RSSI_CHANGED_ACTION)) { |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 885 | int iconId; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 886 | final int newRssi = intent.getIntExtra(WifiManager.EXTRA_NEW_RSSI, -200); |
| 887 | int newSignalLevel = WifiManager.calculateSignalLevel(newRssi, |
Robert Greenwalt | fa974c5 | 2010-09-13 15:53:26 -0700 | [diff] [blame] | 888 | sWifiSignalImages[0].length); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 889 | if (newSignalLevel != mLastWifiSignalLevel) { |
| 890 | mLastWifiSignalLevel = newSignalLevel; |
| 891 | if (mIsWifiConnected) { |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 892 | iconId = sWifiSignalImages[mInetCondition][newSignalLevel]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 893 | } else { |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 894 | iconId = sWifiTemporarilyNotConnectedImage; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 895 | } |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 896 | mService.setIcon("wifi", iconId, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 897 | } |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | private final void updateGps(Intent intent) { |
| 902 | final String action = intent.getAction(); |
Mike Lockwood | 00b7427 | 2010-03-26 10:41:48 -0400 | [diff] [blame] | 903 | 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] | 904 | |
Mike Lockwood | 00b7427 | 2010-03-26 10:41:48 -0400 | [diff] [blame] | 905 | if (action.equals(LocationManager.GPS_FIX_CHANGE_ACTION) && enabled) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 906 | // GPS is getting fixes |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 907 | 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] | 908 | mService.setIconVisibility("gps", true); |
Mike Lockwood | 00b7427 | 2010-03-26 10:41:48 -0400 | [diff] [blame] | 909 | } 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] | 910 | // GPS is off |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 911 | mService.setIconVisibility("gps", false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 912 | } else { |
| 913 | // GPS is on, but not receiving fixes |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 914 | mService.setIcon("gps", R.drawable.stat_sys_gps_acquiring_anim, 0); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 915 | mService.setIconVisibility("gps", true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 916 | } |
| 917 | } |
| 918 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 919 | private final void updateTTY(Intent intent) { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 920 | final String action = intent.getAction(); |
| 921 | final boolean enabled = intent.getBooleanExtra(TtyIntent.TTY_ENABLED, false); |
| 922 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 923 | if (false) Slog.v(TAG, "updateTTY: enabled: " + enabled); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 924 | |
| 925 | if (enabled) { |
| 926 | // TTY is on |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 927 | if (false) Slog.v(TAG, "updateTTY: set TTY on"); |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 928 | mService.setIcon("tty", R.drawable.stat_sys_tty_mode, 0); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 929 | mService.setIconVisibility("tty", true); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 930 | } else { |
| 931 | // TTY is off |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 932 | if (false) Slog.v(TAG, "updateTTY: set TTY off"); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 933 | mService.setIconVisibility("tty", false); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 934 | } |
| 935 | } |
| 936 | |
Robert Greenwalt | 98e0b14 | 2009-10-08 21:15:52 -0700 | [diff] [blame] | 937 | private final void updateCdmaRoamingIcon(ServiceState state) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 938 | if (!hasService()) { |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 939 | mService.setIconVisibility("cdma_eri", false); |
Wink Saville | f315238 | 2009-06-01 14:39:20 -0700 | [diff] [blame] | 940 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | if (!isCdma()) { |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 944 | mService.setIconVisibility("cdma_eri", false); |
Wink Saville | f315238 | 2009-06-01 14:39:20 -0700 | [diff] [blame] | 945 | return; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | int[] iconList = sRoamingIndicatorImages_cdma; |
Robert Greenwalt | 98e0b14 | 2009-10-08 21:15:52 -0700 | [diff] [blame] | 949 | int iconIndex = state.getCdmaEriIconIndex(); |
| 950 | int iconMode = state.getCdmaEriIconMode(); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 951 | |
| 952 | if (iconIndex == -1) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 953 | Slog.e(TAG, "getCdmaEriIconIndex returned null, skipping ERI icon update"); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 954 | return; |
| 955 | } |
| 956 | |
| 957 | if (iconMode == -1) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 958 | Slog.e(TAG, "getCdmeEriIconMode returned null, skipping ERI icon update"); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 959 | return; |
| 960 | } |
| 961 | |
| 962 | if (iconIndex == EriInfo.ROAMING_INDICATOR_OFF) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 963 | if (false) Slog.v(TAG, "Cdma ROAMING_INDICATOR_OFF, removing ERI icon"); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 964 | mService.setIconVisibility("cdma_eri", false); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 965 | return; |
| 966 | } |
| 967 | |
| 968 | switch (iconMode) { |
| 969 | case EriInfo.ROAMING_ICON_MODE_NORMAL: |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 970 | mService.setIcon("cdma_eri", iconList[iconIndex], 0); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 971 | mService.setIconVisibility("cdma_eri", true); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 972 | break; |
| 973 | case EriInfo.ROAMING_ICON_MODE_FLASH: |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 974 | mService.setIcon("cdma_eri", R.drawable.stat_sys_roaming_cdma_flash, 0); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 975 | mService.setIconVisibility("cdma_eri", true); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 976 | break; |
| 977 | |
| 978 | } |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 979 | mService.setIcon("phone_signal", mPhoneSignalIconId, 0); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 980 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 981 | } |