blob: fa8e1a6b9243e1f6096ca2108d96ef4816b09110 [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;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.media.AudioManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import android.os.Handler;
John Spurlockae641c92014-06-30 18:11:40 -040027import android.provider.Settings.Global;
John Spurlockcd686b52013-06-05 10:13:46 -040028import android.util.Log;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029
Wink Savillea639b312012-07-10 12:37:54 -070030import com.android.internal.telephony.IccCardConstants;
Wink Saville04e71b32009-04-02 11:00:54 -070031import com.android.internal.telephony.TelephonyIntents;
32import com.android.internal.telephony.cdma.TtyIntent;
Joe Onorato798ac4c2010-05-27 16:39:00 -040033import com.android.systemui.R;
34
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035/**
36 * This class contains all of the policy about which icons are installed in the status
Joe Onorato798ac4c2010-05-27 16:39:00 -040037 * bar at boot time. It goes through the normal API for icons, even though it probably
38 * strictly doesn't need to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039 */
Joe Onoratofd52b182010-11-10 18:00:52 -080040public class PhoneStatusBarPolicy {
41 private static final String TAG = "PhoneStatusBarPolicy";
John Spurlocka37e9c82014-07-08 09:40:31 -040042 private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Robert Greenwaltd7085fc2010-09-08 15:24:47 -070043
Daniel Sandlerb1e8dab2011-09-26 20:06:19 -040044 private static final boolean SHOW_SYNC_ICON = false;
45
John Spurlocka37e9c82014-07-08 09:40:31 -040046 private static final String SLOT_SYNC_ACTIVE = "sync_active";
47 private static final String SLOT_BLUETOOTH = "bluetooth";
48 private static final String SLOT_TTY = "tty";
49 private static final String SLOT_ZEN = "zen";
50 private static final String SLOT_VOLUME = "volume";
51 private static final String SLOT_CDMA_ERI = "cdma_eri";
52 private static final String SLOT_ALARM_CLOCK = "alarm_clock";
53
Dianne Hackborn4840e142009-03-24 22:40:29 -070054 private final Context mContext;
Joe Onorato798ac4c2010-05-27 16:39:00 -040055 private final StatusBarManager mService;
Joe Onorato10523b4d2010-10-25 10:42:46 -070056 private final Handler mHandler = new Handler();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058 // Assume it's all good unless we hear otherwise. We don't always seem
59 // to get broadcasts that it *is* there.
Wink Savillea639b312012-07-10 12:37:54 -070060 IccCardConstants.State mSimState = IccCardConstants.State.READY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061
John Spurlocka37e9c82014-07-08 09:40:31 -040062 private boolean mZenVisible;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063 private boolean mVolumeVisible;
Wink Saville04e71b32009-04-02 11:00:54 -070064
John Spurlockae641c92014-06-30 18:11:40 -040065 private int mZen;
John Spurlockba2c6a02014-05-19 09:44:06 -040066
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -040067 private boolean mBluetoothEnabled = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068
Wink Savillee9b06d72009-05-18 21:47:50 -070069
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070 private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
71 @Override
72 public void onReceive(Context context, Intent intent) {
73 String action = intent.getAction();
Daniel Sandler2b697352011-07-22 16:23:09 -040074 if (action.equals(Intent.ACTION_ALARM_CHANGED)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075 updateAlarm(intent);
76 }
77 else if (action.equals(Intent.ACTION_SYNC_STATE_CHANGED)) {
78 updateSyncState(intent);
79 }
Nick Pellyde893f52009-09-08 13:15:33 -070080 else if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED) ||
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -070081 action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 updateBluetooth(intent);
83 }
Eric Laurentbffc3d12012-05-07 17:43:49 -070084 else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
John Spurlocka37e9c82014-07-08 09:40:31 -040085 updateVolumeZen();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 }
87 else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
88 updateSimState(intent);
89 }
Wink Saville04e71b32009-04-02 11:00:54 -070090 else if (action.equals(TtyIntent.TTY_ENABLED_CHANGE_ACTION)) {
91 updateTTY(intent);
92 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 }
94 };
95
Joe Onoratofd52b182010-11-10 18:00:52 -080096 public PhoneStatusBarPolicy(Context context) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 mContext = context;
Joe Onorato798ac4c2010-05-27 16:39:00 -040098 mService = (StatusBarManager)context.getSystemService(Context.STATUS_BAR_SERVICE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400100 // listen for broadcasts
101 IntentFilter filter = new IntentFilter();
102 filter.addAction(Intent.ACTION_ALARM_CHANGED);
103 filter.addAction(Intent.ACTION_SYNC_STATE_CHANGED);
104 filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400105 filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
106 filter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
107 filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
108 filter.addAction(TtyIntent.TTY_ENABLED_CHANGE_ACTION);
109 mContext.registerReceiver(mIntentReceiver, filter, null, mHandler);
110
Wink Saville04e71b32009-04-02 11:00:54 -0700111 // TTY status
John Spurlocka37e9c82014-07-08 09:40:31 -0400112 mService.setIcon(SLOT_TTY, R.drawable.stat_sys_tty_mode, 0, null);
113 mService.setIconVisibility(SLOT_TTY, false);
Wink Saville04e71b32009-04-02 11:00:54 -0700114
Wink Savillee9b06d72009-05-18 21:47:50 -0700115 // Cdma Roaming Indicator, ERI
John Spurlocka37e9c82014-07-08 09:40:31 -0400116 mService.setIcon(SLOT_CDMA_ERI, R.drawable.stat_sys_roaming_cdma_0, 0, null);
117 mService.setIconVisibility(SLOT_CDMA_ERI, false);
Wink Savillee9b06d72009-05-18 21:47:50 -0700118
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119 // bluetooth status
Nick Pellyf242b7b2009-10-08 00:12:45 +0200120 BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400121 int bluetoothIcon = R.drawable.stat_sys_data_bluetooth;
Nick Pellybd022f42009-08-14 18:33:38 -0700122 if (adapter != null) {
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400123 mBluetoothEnabled = (adapter.getState() == BluetoothAdapter.STATE_ON);
124 if (adapter.getConnectionState() == BluetoothAdapter.STATE_CONNECTED) {
125 bluetoothIcon = R.drawable.stat_sys_data_bluetooth_connected;
126 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127 }
John Spurlocka37e9c82014-07-08 09:40:31 -0400128 mService.setIcon(SLOT_BLUETOOTH, bluetoothIcon, 0, null);
129 mService.setIconVisibility(SLOT_BLUETOOTH, mBluetoothEnabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131 // Alarm clock
John Spurlocka37e9c82014-07-08 09:40:31 -0400132 mService.setIcon(SLOT_ALARM_CLOCK, R.drawable.stat_sys_alarm, 0, null);
133 mService.setIconVisibility(SLOT_ALARM_CLOCK, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134
135 // Sync state
John Spurlocka37e9c82014-07-08 09:40:31 -0400136 mService.setIcon(SLOT_SYNC_ACTIVE, R.drawable.stat_sys_sync, 0, null);
137 mService.setIconVisibility(SLOT_SYNC_ACTIVE, false);
John Spurlock3c875662013-08-31 15:07:25 -0400138 // "sync_failing" is obsolete: b/1297963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139
John Spurlocka37e9c82014-07-08 09:40:31 -0400140 // zen
141 mService.setIcon(SLOT_ZEN, R.drawable.stat_sys_zen_important, 0, null);
142 mService.setIconVisibility(SLOT_ZEN, false);
143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 // volume
John Spurlocka37e9c82014-07-08 09:40:31 -0400145 mService.setIcon(SLOT_VOLUME, R.drawable.stat_sys_ringer_silent, 0, null);
146 mService.setIconVisibility(SLOT_VOLUME, false);
147 updateVolumeZen();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 }
149
John Spurlockae641c92014-06-30 18:11:40 -0400150 public void setZenMode(int zen) {
John Spurlockba2c6a02014-05-19 09:44:06 -0400151 mZen = zen;
John Spurlocka37e9c82014-07-08 09:40:31 -0400152 updateVolumeZen();
John Spurlockba2c6a02014-05-19 09:44:06 -0400153 }
154
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 private final void updateAlarm(Intent intent) {
156 boolean alarmSet = intent.getBooleanExtra("alarmSet", false);
John Spurlocka37e9c82014-07-08 09:40:31 -0400157 mService.setIconVisibility(SLOT_ALARM_CLOCK, alarmSet);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 }
159
160 private final void updateSyncState(Intent intent) {
Daniel Sandlerb1e8dab2011-09-26 20:06:19 -0400161 if (!SHOW_SYNC_ICON) return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 boolean isActive = intent.getBooleanExtra("active", false);
John Spurlocka37e9c82014-07-08 09:40:31 -0400163 mService.setIconVisibility(SLOT_SYNC_ACTIVE, isActive);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 }
165
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 private final void updateSimState(Intent intent) {
Wink Savillea639b312012-07-10 12:37:54 -0700167 String stateExtra = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
168 if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) {
169 mSimState = IccCardConstants.State.ABSENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 }
Rakesh Pallerlaf099a5f2013-02-06 11:44:23 +0530171 else if (IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR.equals(stateExtra)) {
172 mSimState = IccCardConstants.State.CARD_IO_ERROR;
173 }
Wink Savillea639b312012-07-10 12:37:54 -0700174 else if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(stateExtra)) {
175 mSimState = IccCardConstants.State.READY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 }
Wink Savillea639b312012-07-10 12:37:54 -0700177 else if (IccCardConstants.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) {
178 final String lockedReason =
179 intent.getStringExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON);
180 if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) {
181 mSimState = IccCardConstants.State.PIN_REQUIRED;
johnwang347c5a22009-08-24 22:11:11 -0700182 }
Wink Savillea639b312012-07-10 12:37:54 -0700183 else if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) {
184 mSimState = IccCardConstants.State.PUK_REQUIRED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 }
186 else {
Wink Savillea639b312012-07-10 12:37:54 -0700187 mSimState = IccCardConstants.State.NETWORK_LOCKED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800188 }
189 } else {
Wink Savillea639b312012-07-10 12:37:54 -0700190 mSimState = IccCardConstants.State.UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800192 }
193
John Spurlocka37e9c82014-07-08 09:40:31 -0400194 private final void updateVolumeZen() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195 AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
John Spurlocka37e9c82014-07-08 09:40:31 -0400196
197 boolean zenVisible = false;
198 int zenIconId = 0;
199 String zenDescription = null;
200
201 boolean volumeVisible = false;
202 int volumeIconId = 0;
203 String volumeDescription = null;
204
205 if (mZen == Global.ZEN_MODE_NO_INTERRUPTIONS) {
206 zenVisible = true;
207 zenIconId = R.drawable.stat_sys_zen_none;
208 zenDescription = mContext.getString(R.string.zen_no_interruptions);
John Spurlockae641c92014-06-30 18:11:40 -0400209 } else if (mZen == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400210 zenVisible = true;
211 zenIconId = R.drawable.stat_sys_zen_important;
212 zenDescription = mContext.getString(R.string.zen_important_interruptions);
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700213 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214
John Spurlocka37e9c82014-07-08 09:40:31 -0400215 if (mZen != Global.ZEN_MODE_NO_INTERRUPTIONS &&
216 audioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) {
217 volumeVisible = true;
218 volumeIconId = R.drawable.stat_sys_ringer_vibrate;
219 volumeDescription = mContext.getString(R.string.accessibility_ringer_vibrate);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800220 }
John Spurlocka37e9c82014-07-08 09:40:31 -0400221
222 if (zenVisible) {
223 mService.setIcon(SLOT_ZEN, zenIconId, 0, zenDescription);
224 }
225 if (zenVisible != mZenVisible) {
226 mService.setIconVisibility(SLOT_ZEN, zenVisible);
227 mZenVisible = zenVisible;
228 }
229
230 if (volumeVisible) {
231 mService.setIcon(SLOT_VOLUME, volumeIconId, 0, volumeDescription);
232 }
233 if (volumeVisible != mVolumeVisible) {
234 mService.setIconVisibility(SLOT_VOLUME, volumeVisible);
235 mVolumeVisible = volumeVisible;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236 }
237 }
238
239 private final void updateBluetooth(Intent intent) {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400240 int iconId = R.drawable.stat_sys_data_bluetooth;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700241 String contentDescription = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800242 String action = intent.getAction();
Nick Pellyde893f52009-09-08 13:15:33 -0700243 if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
Nick Pellyb24e11b2009-09-08 17:40:43 -0700244 int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
Nick Pellyde893f52009-09-08 13:15:33 -0700245 mBluetoothEnabled = state == BluetoothAdapter.STATE_ON;
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -0700246 } else if (action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) {
Jaikumar Ganesh0b63a6a2011-07-11 14:34:34 -0700247 int state = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE,
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -0700248 BluetoothAdapter.STATE_DISCONNECTED);
249 if (state == BluetoothAdapter.STATE_CONNECTED) {
250 iconId = R.drawable.stat_sys_data_bluetooth_connected;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700251 contentDescription = mContext.getString(R.string.accessibility_bluetooth_connected);
252 } else {
253 contentDescription = mContext.getString(
254 R.string.accessibility_bluetooth_disconnected);
Jaikumar Ganesh084c6652009-12-07 10:58:18 -0800255 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800256 } else {
257 return;
258 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700259
John Spurlocka37e9c82014-07-08 09:40:31 -0400260 mService.setIcon(SLOT_BLUETOOTH, iconId, 0, contentDescription);
261 mService.setIconVisibility(SLOT_BLUETOOTH, mBluetoothEnabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800262 }
263
Wink Savillee9b06d72009-05-18 21:47:50 -0700264 private final void updateTTY(Intent intent) {
Wink Saville04e71b32009-04-02 11:00:54 -0700265 final boolean enabled = intent.getBooleanExtra(TtyIntent.TTY_ENABLED, false);
266
John Spurlocka37e9c82014-07-08 09:40:31 -0400267 if (DEBUG) Log.v(TAG, "updateTTY: enabled: " + enabled);
Wink Saville04e71b32009-04-02 11:00:54 -0700268
269 if (enabled) {
270 // TTY is on
John Spurlocka37e9c82014-07-08 09:40:31 -0400271 if (DEBUG) Log.v(TAG, "updateTTY: set TTY on");
272 mService.setIcon(SLOT_TTY, R.drawable.stat_sys_tty_mode, 0,
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700273 mContext.getString(R.string.accessibility_tty_enabled));
John Spurlocka37e9c82014-07-08 09:40:31 -0400274 mService.setIconVisibility(SLOT_TTY, true);
Wink Saville04e71b32009-04-02 11:00:54 -0700275 } else {
276 // TTY is off
John Spurlocka37e9c82014-07-08 09:40:31 -0400277 if (DEBUG) Log.v(TAG, "updateTTY: set TTY off");
278 mService.setIconVisibility(SLOT_TTY, false);
Wink Saville04e71b32009-04-02 11:00:54 -0700279 }
280 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281}