blob: 322a8c83e0bd9070493bfd8775438155f5c38b28 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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 Onoratofd52b182010-11-10 18:00:52 -080017package com.android.systemui.statusbar.phone;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080018
Joe Onorato798ac4c2010-05-27 16:39:00 -040019import android.app.StatusBarManager;
Nick Pellybd022f42009-08-14 18:33:38 -070020import android.bluetooth.BluetoothAdapter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import android.content.BroadcastReceiver;
22import android.content.Context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.content.Intent;
24import android.content.IntentFilter;
Mike Lockwood00b74272010-03-26 10:41:48 -040025import android.location.LocationManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import android.media.AudioManager;
Robert Greenwaltd7085fc2010-09-08 15:24:47 -070027import android.net.ConnectivityManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.net.NetworkInfo;
29import android.net.wifi.WifiManager;
Dianne Hackborn4840e142009-03-24 22:40:29 -070030import android.os.Binder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.os.Handler;
Dianne Hackborn4840e142009-03-24 22:40:29 -070032import android.os.RemoteException;
San Mehat4154c072010-02-09 18:37:54 -080033import android.os.storage.StorageManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.provider.Settings;
35import android.telephony.PhoneStateListener;
36import android.telephony.ServiceState;
Wink Savillee9b06d72009-05-18 21:47:50 -070037import android.telephony.SignalStrength;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038import android.telephony.TelephonyManager;
Joe Onorato8a9b2202010-02-26 18:56:32 -080039import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040
Wink Saville04e71b32009-04-02 11:00:54 -070041import com.android.internal.telephony.IccCard;
42import com.android.internal.telephony.TelephonyIntents;
Wink Savillee9b06d72009-05-18 21:47:50 -070043import com.android.internal.telephony.cdma.EriInfo;
Wink Saville04e71b32009-04-02 11:00:54 -070044import com.android.internal.telephony.cdma.TtyIntent;
45import com.android.server.am.BatteryStatsService;
Joe Onorato798ac4c2010-05-27 16:39:00 -040046import com.android.systemui.R;
47
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048/**
49 * This class contains all of the policy about which icons are installed in the status
Joe Onorato798ac4c2010-05-27 16:39:00 -040050 * bar at boot time. It goes through the normal API for icons, even though it probably
51 * strictly doesn't need to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052 */
Joe Onoratofd52b182010-11-10 18:00:52 -080053public class PhoneStatusBarPolicy {
54 private static final String TAG = "PhoneStatusBarPolicy";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056 // message codes for the handler
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057 private static final int EVENT_BATTERY_CLOSE = 4;
58
Daniel Sandler2c195f72010-05-21 15:42:06 -040059 private static final int AM_PM_STYLE_NORMAL = 0;
60 private static final int AM_PM_STYLE_SMALL = 1;
61 private static final int AM_PM_STYLE_GONE = 2;
62
63 private static final int AM_PM_STYLE = AM_PM_STYLE_GONE;
64
Robert Greenwaltd7085fc2010-09-08 15:24:47 -070065 private static final int INET_CONDITION_THRESHOLD = 50;
66
Dianne Hackborn4840e142009-03-24 22:40:29 -070067 private final Context mContext;
Joe Onorato798ac4c2010-05-27 16:39:00 -040068 private final StatusBarManager mService;
Joe Onorato10523b4d2010-10-25 10:42:46 -070069 private final Handler mHandler = new Handler();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070
San Mehat4154c072010-02-09 18:37:54 -080071 // storage
72 private StorageManager mStorageManager;
73
Svetoslav Ganov6179ea32011-06-28 01:12:41 -070074
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075 // Assume it's all good unless we hear otherwise. We don't always seem
76 // to get broadcasts that it *is* there.
Wink Saville04e71b32009-04-02 11:00:54 -070077 IccCard.State mSimState = IccCard.State.READY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078
79 // ringer volume
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080 private boolean mVolumeVisible;
Wink Saville04e71b32009-04-02 11:00:54 -070081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 // bluetooth device status
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083 private boolean mBluetoothEnabled;
84
85 // wifi
Robert Greenwaltd7085fc2010-09-08 15:24:47 -070086 private static final int[][] sWifiSignalImages = {
87 { R.drawable.stat_sys_wifi_signal_1,
88 R.drawable.stat_sys_wifi_signal_2,
89 R.drawable.stat_sys_wifi_signal_3,
90 R.drawable.stat_sys_wifi_signal_4 },
Robert Greenwalt26faee32010-09-10 09:36:43 -070091 { R.drawable.stat_sys_wifi_signal_1_fully,
92 R.drawable.stat_sys_wifi_signal_2_fully,
93 R.drawable.stat_sys_wifi_signal_3_fully,
94 R.drawable.stat_sys_wifi_signal_4_fully }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095 };
96 private static final int sWifiTemporarilyNotConnectedImage =
Joe Onorato798ac4c2010-05-27 16:39:00 -040097 R.drawable.stat_sys_wifi_signal_0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098
99 private int mLastWifiSignalLevel = -1;
100 private boolean mIsWifiConnected = false;
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700101
102 // state of inet connection - 0 not connected, 100 connected
103 private int mInetCondition = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104
105 // sync state
106 // If sync is active the SyncActive icon is displayed. If sync is not active but
107 // sync is failing the SyncFailing icon is displayed. Otherwise neither are displayed.
Wink Savillee9b06d72009-05-18 21:47:50 -0700108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
110 @Override
111 public void onReceive(Context context, Intent intent) {
112 String action = intent.getAction();
Daniel Sandler2b697352011-07-22 16:23:09 -0400113 if (action.equals(Intent.ACTION_ALARM_CHANGED)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114 updateAlarm(intent);
115 }
116 else if (action.equals(Intent.ACTION_SYNC_STATE_CHANGED)) {
117 updateSyncState(intent);
118 }
Nick Pellyde893f52009-09-08 13:15:33 -0700119 else if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED) ||
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -0700120 action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121 updateBluetooth(intent);
122 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123 else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION) ||
124 action.equals(AudioManager.VIBRATE_SETTING_CHANGED_ACTION)) {
125 updateVolume();
126 }
127 else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
128 updateSimState(intent);
129 }
Wink Saville04e71b32009-04-02 11:00:54 -0700130 else if (action.equals(TtyIntent.TTY_ENABLED_CHANGE_ACTION)) {
131 updateTTY(intent);
132 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133 }
134 };
135
Joe Onoratofd52b182010-11-10 18:00:52 -0800136 public PhoneStatusBarPolicy(Context context) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137 mContext = context;
Joe Onorato798ac4c2010-05-27 16:39:00 -0400138 mService = (StatusBarManager)context.getSystemService(Context.STATUS_BAR_SERVICE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139
San Mehat4154c072010-02-09 18:37:54 -0800140 // storage
141 mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
142 mStorageManager.registerListener(
Joe Onoratofe4f3ae2010-06-04 11:25:26 -0700143 new com.android.systemui.usb.StorageNotification(context));
San Mehat4154c072010-02-09 18:37:54 -0800144
Wink Saville04e71b32009-04-02 11:00:54 -0700145 // TTY status
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700146 mService.setIcon("tty", R.drawable.stat_sys_tty_mode, 0, null);
Joe Onorato798ac4c2010-05-27 16:39:00 -0400147 mService.setIconVisibility("tty", false);
Wink Saville04e71b32009-04-02 11:00:54 -0700148
Wink Savillee9b06d72009-05-18 21:47:50 -0700149 // Cdma Roaming Indicator, ERI
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700150 mService.setIcon("cdma_eri", R.drawable.stat_sys_roaming_cdma_0, 0, null);
Joe Onorato798ac4c2010-05-27 16:39:00 -0400151 mService.setIconVisibility("cdma_eri", false);
Wink Savillee9b06d72009-05-18 21:47:50 -0700152
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 // bluetooth status
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700154 mService.setIcon("bluetooth", R.drawable.stat_sys_data_bluetooth, 0, null);
Nick Pellyf242b7b2009-10-08 00:12:45 +0200155 BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
Nick Pellybd022f42009-08-14 18:33:38 -0700156 if (adapter != null) {
157 mBluetoothEnabled = adapter.isEnabled();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 } else {
159 mBluetoothEnabled = false;
160 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700161 mService.setIconVisibility("bluetooth", mBluetoothEnabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 // Alarm clock
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700164 mService.setIcon("alarm_clock", R.drawable.stat_notify_alarm, 0, null);
Joe Onorato798ac4c2010-05-27 16:39:00 -0400165 mService.setIconVisibility("alarm_clock", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166
167 // Sync state
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700168 mService.setIcon("sync_active", com.android.internal.R.drawable.stat_notify_sync_anim0,
169 0, null);
170 mService.setIcon("sync_failing", com.android.internal.R.drawable.stat_notify_sync_error,
171 0, null);
Joe Onorato798ac4c2010-05-27 16:39:00 -0400172 mService.setIconVisibility("sync_active", false);
173 mService.setIconVisibility("sync_failing", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174
175 // volume
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700176 mService.setIcon("volume", R.drawable.stat_sys_ringer_silent, 0, null);
Joe Onorato798ac4c2010-05-27 16:39:00 -0400177 mService.setIconVisibility("volume", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 updateVolume();
johnwang347c5a22009-08-24 22:11:11 -0700179
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800180 IntentFilter filter = new IntentFilter();
181
182 // Register for Intent broadcasts for...
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183 filter.addAction(Intent.ACTION_ALARM_CHANGED);
184 filter.addAction(Intent.ACTION_SYNC_STATE_CHANGED);
185 filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
186 filter.addAction(AudioManager.VIBRATE_SETTING_CHANGED_ACTION);
Nick Pellyde893f52009-09-08 13:15:33 -0700187 filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -0700188 filter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189 filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
Wink Saville04e71b32009-04-02 11:00:54 -0700190 filter.addAction(TtyIntent.TTY_ENABLED_CHANGE_ACTION);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 mContext.registerReceiver(mIntentReceiver, filter, null, mHandler);
192 }
193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194 private final void updateAlarm(Intent intent) {
195 boolean alarmSet = intent.getBooleanExtra("alarmSet", false);
Joe Onorato0cbda992010-05-02 16:28:15 -0700196 mService.setIconVisibility("alarm_clock", alarmSet);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800197 }
198
199 private final void updateSyncState(Intent intent) {
200 boolean isActive = intent.getBooleanExtra("active", false);
201 boolean isFailing = intent.getBooleanExtra("failing", false);
Joe Onorato0cbda992010-05-02 16:28:15 -0700202 mService.setIconVisibility("sync_active", isActive);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800203 // Don't display sync failing icon: BUG 1297963 Set sync error timeout to "never"
Joe Onorato0cbda992010-05-02 16:28:15 -0700204 //mService.setIconVisibility("sync_failing", isFailing && !isActive);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205 }
206
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207 private final void updateSimState(Intent intent) {
Wink Saville04e71b32009-04-02 11:00:54 -0700208 String stateExtra = intent.getStringExtra(IccCard.INTENT_KEY_ICC_STATE);
209 if (IccCard.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) {
210 mSimState = IccCard.State.ABSENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800211 }
Wink Saville04e71b32009-04-02 11:00:54 -0700212 else if (IccCard.INTENT_VALUE_ICC_READY.equals(stateExtra)) {
213 mSimState = IccCard.State.READY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214 }
Wink Saville04e71b32009-04-02 11:00:54 -0700215 else if (IccCard.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) {
216 final String lockedReason = intent.getStringExtra(IccCard.INTENT_KEY_LOCKED_REASON);
217 if (IccCard.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) {
218 mSimState = IccCard.State.PIN_REQUIRED;
johnwang347c5a22009-08-24 22:11:11 -0700219 }
Wink Saville04e71b32009-04-02 11:00:54 -0700220 else if (IccCard.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) {
221 mSimState = IccCard.State.PUK_REQUIRED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222 }
223 else {
Wink Saville04e71b32009-04-02 11:00:54 -0700224 mSimState = IccCard.State.NETWORK_LOCKED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225 }
226 } else {
Wink Saville04e71b32009-04-02 11:00:54 -0700227 mSimState = IccCard.State.UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800228 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229 }
230
231 private final void updateVolume() {
232 AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
233 final int ringerMode = audioManager.getRingerMode();
234 final boolean visible = ringerMode == AudioManager.RINGER_MODE_SILENT ||
Wink Savillee9b06d72009-05-18 21:47:50 -0700235 ringerMode == AudioManager.RINGER_MODE_VIBRATE;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700236
237 final int iconId;
238 String contentDescription = null;
239 if (audioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER)) {
240 iconId = R.drawable.stat_sys_ringer_vibrate;
241 contentDescription = mContext.getString(R.string.accessibility_ringer_vibrate);
242 } else {
243 iconId = R.drawable.stat_sys_ringer_silent;
244 contentDescription = mContext.getString(R.string.accessibility_ringer_silent);
245 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246
247 if (visible) {
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700248 mService.setIcon("volume", iconId, 0, contentDescription);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800249 }
250 if (visible != mVolumeVisible) {
Joe Onorato0cbda992010-05-02 16:28:15 -0700251 mService.setIconVisibility("volume", visible);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800252 mVolumeVisible = visible;
253 }
254 }
255
256 private final void updateBluetooth(Intent intent) {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400257 int iconId = R.drawable.stat_sys_data_bluetooth;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700258 String contentDescription = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259 String action = intent.getAction();
Nick Pellyde893f52009-09-08 13:15:33 -0700260 if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
Nick Pellyb24e11b2009-09-08 17:40:43 -0700261 int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
Nick Pellyde893f52009-09-08 13:15:33 -0700262 mBluetoothEnabled = state == BluetoothAdapter.STATE_ON;
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -0700263 } else if (action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) {
Jaikumar Ganesh0b63a6a2011-07-11 14:34:34 -0700264 int state = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE,
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -0700265 BluetoothAdapter.STATE_DISCONNECTED);
266 if (state == BluetoothAdapter.STATE_CONNECTED) {
267 iconId = R.drawable.stat_sys_data_bluetooth_connected;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700268 contentDescription = mContext.getString(R.string.accessibility_bluetooth_connected);
269 } else {
270 contentDescription = mContext.getString(
271 R.string.accessibility_bluetooth_disconnected);
Jaikumar Ganesh084c6652009-12-07 10:58:18 -0800272 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 } else {
274 return;
275 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700276
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700277 mService.setIcon("bluetooth", iconId, 0, contentDescription);
Joe Onorato0cbda992010-05-02 16:28:15 -0700278 mService.setIconVisibility("bluetooth", mBluetoothEnabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 }
280
Wink Savillee9b06d72009-05-18 21:47:50 -0700281 private final void updateTTY(Intent intent) {
Wink Saville04e71b32009-04-02 11:00:54 -0700282 final String action = intent.getAction();
283 final boolean enabled = intent.getBooleanExtra(TtyIntent.TTY_ENABLED, false);
284
Joe Onorato8a9b2202010-02-26 18:56:32 -0800285 if (false) Slog.v(TAG, "updateTTY: enabled: " + enabled);
Wink Saville04e71b32009-04-02 11:00:54 -0700286
287 if (enabled) {
288 // TTY is on
Joe Onorato8a9b2202010-02-26 18:56:32 -0800289 if (false) Slog.v(TAG, "updateTTY: set TTY on");
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700290 mService.setIcon("tty", R.drawable.stat_sys_tty_mode, 0,
291 mContext.getString(R.string.accessibility_tty_enabled));
Joe Onorato0cbda992010-05-02 16:28:15 -0700292 mService.setIconVisibility("tty", true);
Wink Saville04e71b32009-04-02 11:00:54 -0700293 } else {
294 // TTY is off
Joe Onorato8a9b2202010-02-26 18:56:32 -0800295 if (false) Slog.v(TAG, "updateTTY: set TTY off");
Joe Onorato0cbda992010-05-02 16:28:15 -0700296 mService.setIconVisibility("tty", false);
Wink Saville04e71b32009-04-02 11:00:54 -0700297 }
298 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800299}