blob: 5f18b5dfe8ab7d3602910ad0e125cc11c4ae9012 [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
Daniel Sandlerb1e8dab2011-09-26 20:06:19 -040067 private static final boolean SHOW_SYNC_ICON = false;
68
Dianne Hackborn4840e142009-03-24 22:40:29 -070069 private final Context mContext;
Joe Onorato798ac4c2010-05-27 16:39:00 -040070 private final StatusBarManager mService;
Joe Onorato10523b4d2010-10-25 10:42:46 -070071 private final Handler mHandler = new Handler();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072
San Mehat4154c072010-02-09 18:37:54 -080073 // storage
74 private StorageManager mStorageManager;
75
Svetoslav Ganov6179ea32011-06-28 01:12:41 -070076
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077 // Assume it's all good unless we hear otherwise. We don't always seem
78 // to get broadcasts that it *is* there.
Wink Saville04e71b32009-04-02 11:00:54 -070079 IccCard.State mSimState = IccCard.State.READY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080
81 // ringer volume
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 private boolean mVolumeVisible;
Wink Saville04e71b32009-04-02 11:00:54 -070083
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084 // bluetooth device status
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -040085 private boolean mBluetoothEnabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086
87 // wifi
Robert Greenwaltd7085fc2010-09-08 15:24:47 -070088 private static final int[][] sWifiSignalImages = {
89 { R.drawable.stat_sys_wifi_signal_1,
90 R.drawable.stat_sys_wifi_signal_2,
91 R.drawable.stat_sys_wifi_signal_3,
92 R.drawable.stat_sys_wifi_signal_4 },
Robert Greenwalt26faee32010-09-10 09:36:43 -070093 { R.drawable.stat_sys_wifi_signal_1_fully,
94 R.drawable.stat_sys_wifi_signal_2_fully,
95 R.drawable.stat_sys_wifi_signal_3_fully,
96 R.drawable.stat_sys_wifi_signal_4_fully }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 };
98 private static final int sWifiTemporarilyNotConnectedImage =
Joe Onorato798ac4c2010-05-27 16:39:00 -040099 R.drawable.stat_sys_wifi_signal_0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100
101 private int mLastWifiSignalLevel = -1;
102 private boolean mIsWifiConnected = false;
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700103
104 // state of inet connection - 0 not connected, 100 connected
105 private int mInetCondition = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106
107 // sync state
108 // If sync is active the SyncActive icon is displayed. If sync is not active but
109 // sync is failing the SyncFailing icon is displayed. Otherwise neither are displayed.
Wink Savillee9b06d72009-05-18 21:47:50 -0700110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111 private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
112 @Override
113 public void onReceive(Context context, Intent intent) {
114 String action = intent.getAction();
Daniel Sandler2b697352011-07-22 16:23:09 -0400115 if (action.equals(Intent.ACTION_ALARM_CHANGED)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116 updateAlarm(intent);
117 }
118 else if (action.equals(Intent.ACTION_SYNC_STATE_CHANGED)) {
119 updateSyncState(intent);
120 }
Nick Pellyde893f52009-09-08 13:15:33 -0700121 else if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED) ||
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -0700122 action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123 updateBluetooth(intent);
124 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125 else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION) ||
126 action.equals(AudioManager.VIBRATE_SETTING_CHANGED_ACTION)) {
127 updateVolume();
128 }
129 else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
130 updateSimState(intent);
131 }
Wink Saville04e71b32009-04-02 11:00:54 -0700132 else if (action.equals(TtyIntent.TTY_ENABLED_CHANGE_ACTION)) {
133 updateTTY(intent);
134 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135 }
136 };
137
Joe Onoratofd52b182010-11-10 18:00:52 -0800138 public PhoneStatusBarPolicy(Context context) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 mContext = context;
Joe Onorato798ac4c2010-05-27 16:39:00 -0400140 mService = (StatusBarManager)context.getSystemService(Context.STATUS_BAR_SERVICE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400142 // listen for broadcasts
143 IntentFilter filter = new IntentFilter();
144 filter.addAction(Intent.ACTION_ALARM_CHANGED);
145 filter.addAction(Intent.ACTION_SYNC_STATE_CHANGED);
146 filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
147 filter.addAction(AudioManager.VIBRATE_SETTING_CHANGED_ACTION);
148 filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
149 filter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
150 filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
151 filter.addAction(TtyIntent.TTY_ENABLED_CHANGE_ACTION);
152 mContext.registerReceiver(mIntentReceiver, filter, null, mHandler);
153
San Mehat4154c072010-02-09 18:37:54 -0800154 // storage
155 mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
156 mStorageManager.registerListener(
Joe Onoratofe4f3ae2010-06-04 11:25:26 -0700157 new com.android.systemui.usb.StorageNotification(context));
San Mehat4154c072010-02-09 18:37:54 -0800158
Wink Saville04e71b32009-04-02 11:00:54 -0700159 // TTY status
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700160 mService.setIcon("tty", R.drawable.stat_sys_tty_mode, 0, null);
Joe Onorato798ac4c2010-05-27 16:39:00 -0400161 mService.setIconVisibility("tty", false);
Wink Saville04e71b32009-04-02 11:00:54 -0700162
Wink Savillee9b06d72009-05-18 21:47:50 -0700163 // Cdma Roaming Indicator, ERI
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700164 mService.setIcon("cdma_eri", R.drawable.stat_sys_roaming_cdma_0, 0, null);
Joe Onorato798ac4c2010-05-27 16:39:00 -0400165 mService.setIconVisibility("cdma_eri", false);
Wink Savillee9b06d72009-05-18 21:47:50 -0700166
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167 // bluetooth status
Nick Pellyf242b7b2009-10-08 00:12:45 +0200168 BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400169 int bluetoothIcon = R.drawable.stat_sys_data_bluetooth;
Nick Pellybd022f42009-08-14 18:33:38 -0700170 if (adapter != null) {
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400171 mBluetoothEnabled = (adapter.getState() == BluetoothAdapter.STATE_ON);
172 if (adapter.getConnectionState() == BluetoothAdapter.STATE_CONNECTED) {
173 bluetoothIcon = R.drawable.stat_sys_data_bluetooth_connected;
174 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800175 }
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400176 mService.setIcon("bluetooth", bluetoothIcon, 0, null);
Joe Onorato0cbda992010-05-02 16:28:15 -0700177 mService.setIconVisibility("bluetooth", mBluetoothEnabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179 // Alarm clock
Justin Hofdfbbf62011-08-26 08:51:27 -0700180 mService.setIcon("alarm_clock", R.drawable.stat_sys_alarm, 0, null);
Joe Onorato798ac4c2010-05-27 16:39:00 -0400181 mService.setIconVisibility("alarm_clock", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182
183 // Sync state
Justin Ho9f176582011-09-20 18:16:48 -0700184 mService.setIcon("sync_active", R.drawable.stat_sys_sync, 0, null);
185 mService.setIcon("sync_failing", R.drawable.stat_sys_sync_error, 0, null);
Joe Onorato798ac4c2010-05-27 16:39:00 -0400186 mService.setIconVisibility("sync_active", false);
187 mService.setIconVisibility("sync_failing", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800188
189 // volume
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700190 mService.setIcon("volume", R.drawable.stat_sys_ringer_silent, 0, null);
Joe Onorato798ac4c2010-05-27 16:39:00 -0400191 mService.setIconVisibility("volume", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800192 updateVolume();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193 }
194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195 private final void updateAlarm(Intent intent) {
196 boolean alarmSet = intent.getBooleanExtra("alarmSet", false);
Joe Onorato0cbda992010-05-02 16:28:15 -0700197 mService.setIconVisibility("alarm_clock", alarmSet);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800198 }
199
200 private final void updateSyncState(Intent intent) {
Daniel Sandlerb1e8dab2011-09-26 20:06:19 -0400201 if (!SHOW_SYNC_ICON) return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800202 boolean isActive = intent.getBooleanExtra("active", false);
203 boolean isFailing = intent.getBooleanExtra("failing", false);
Joe Onorato0cbda992010-05-02 16:28:15 -0700204 mService.setIconVisibility("sync_active", isActive);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205 // Don't display sync failing icon: BUG 1297963 Set sync error timeout to "never"
Joe Onorato0cbda992010-05-02 16:28:15 -0700206 //mService.setIconVisibility("sync_failing", isFailing && !isActive);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207 }
208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 private final void updateSimState(Intent intent) {
Wink Saville04e71b32009-04-02 11:00:54 -0700210 String stateExtra = intent.getStringExtra(IccCard.INTENT_KEY_ICC_STATE);
211 if (IccCard.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) {
212 mSimState = IccCard.State.ABSENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800213 }
Wink Saville04e71b32009-04-02 11:00:54 -0700214 else if (IccCard.INTENT_VALUE_ICC_READY.equals(stateExtra)) {
215 mSimState = IccCard.State.READY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 }
Wink Saville04e71b32009-04-02 11:00:54 -0700217 else if (IccCard.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) {
218 final String lockedReason = intent.getStringExtra(IccCard.INTENT_KEY_LOCKED_REASON);
219 if (IccCard.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) {
220 mSimState = IccCard.State.PIN_REQUIRED;
johnwang347c5a22009-08-24 22:11:11 -0700221 }
Wink Saville04e71b32009-04-02 11:00:54 -0700222 else if (IccCard.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) {
223 mSimState = IccCard.State.PUK_REQUIRED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 }
225 else {
Wink Saville04e71b32009-04-02 11:00:54 -0700226 mSimState = IccCard.State.NETWORK_LOCKED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800227 }
228 } else {
Wink Saville04e71b32009-04-02 11:00:54 -0700229 mSimState = IccCard.State.UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231 }
232
233 private final void updateVolume() {
234 AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
235 final int ringerMode = audioManager.getRingerMode();
236 final boolean visible = ringerMode == AudioManager.RINGER_MODE_SILENT ||
Wink Savillee9b06d72009-05-18 21:47:50 -0700237 ringerMode == AudioManager.RINGER_MODE_VIBRATE;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700238
239 final int iconId;
240 String contentDescription = null;
241 if (audioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER)) {
242 iconId = R.drawable.stat_sys_ringer_vibrate;
243 contentDescription = mContext.getString(R.string.accessibility_ringer_vibrate);
244 } else {
245 iconId = R.drawable.stat_sys_ringer_silent;
246 contentDescription = mContext.getString(R.string.accessibility_ringer_silent);
247 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248
249 if (visible) {
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700250 mService.setIcon("volume", iconId, 0, contentDescription);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800251 }
252 if (visible != mVolumeVisible) {
Joe Onorato0cbda992010-05-02 16:28:15 -0700253 mService.setIconVisibility("volume", visible);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800254 mVolumeVisible = visible;
255 }
256 }
257
258 private final void updateBluetooth(Intent intent) {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400259 int iconId = R.drawable.stat_sys_data_bluetooth;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700260 String contentDescription = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800261 String action = intent.getAction();
Nick Pellyde893f52009-09-08 13:15:33 -0700262 if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
Nick Pellyb24e11b2009-09-08 17:40:43 -0700263 int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
Nick Pellyde893f52009-09-08 13:15:33 -0700264 mBluetoothEnabled = state == BluetoothAdapter.STATE_ON;
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -0700265 } else if (action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) {
Jaikumar Ganesh0b63a6a2011-07-11 14:34:34 -0700266 int state = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE,
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -0700267 BluetoothAdapter.STATE_DISCONNECTED);
268 if (state == BluetoothAdapter.STATE_CONNECTED) {
269 iconId = R.drawable.stat_sys_data_bluetooth_connected;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700270 contentDescription = mContext.getString(R.string.accessibility_bluetooth_connected);
271 } else {
272 contentDescription = mContext.getString(
273 R.string.accessibility_bluetooth_disconnected);
Jaikumar Ganesh084c6652009-12-07 10:58:18 -0800274 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 } else {
276 return;
277 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700278
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700279 mService.setIcon("bluetooth", iconId, 0, contentDescription);
Joe Onorato0cbda992010-05-02 16:28:15 -0700280 mService.setIconVisibility("bluetooth", mBluetoothEnabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 }
282
Wink Savillee9b06d72009-05-18 21:47:50 -0700283 private final void updateTTY(Intent intent) {
Wink Saville04e71b32009-04-02 11:00:54 -0700284 final String action = intent.getAction();
285 final boolean enabled = intent.getBooleanExtra(TtyIntent.TTY_ENABLED, false);
286
Joe Onorato8a9b2202010-02-26 18:56:32 -0800287 if (false) Slog.v(TAG, "updateTTY: enabled: " + enabled);
Wink Saville04e71b32009-04-02 11:00:54 -0700288
289 if (enabled) {
290 // TTY is on
Joe Onorato8a9b2202010-02-26 18:56:32 -0800291 if (false) Slog.v(TAG, "updateTTY: set TTY on");
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700292 mService.setIcon("tty", R.drawable.stat_sys_tty_mode, 0,
293 mContext.getString(R.string.accessibility_tty_enabled));
Joe Onorato0cbda992010-05-02 16:28:15 -0700294 mService.setIconVisibility("tty", true);
Wink Saville04e71b32009-04-02 11:00:54 -0700295 } else {
296 // TTY is off
Joe Onorato8a9b2202010-02-26 18:56:32 -0800297 if (false) Slog.v(TAG, "updateTTY: set TTY off");
Joe Onorato0cbda992010-05-02 16:28:15 -0700298 mService.setIconVisibility("tty", false);
Wink Saville04e71b32009-04-02 11:00:54 -0700299 }
300 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800301}