blob: 540b9d003a17abdda2f4e0dc1f14231b1d7a8fed [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
Kenny Guy3094d4a2015-04-01 19:14:10 +010019import android.app.ActivityManagerNative;
Adrian Roosc42a1e12014-07-07 23:35:53 +020020import android.app.AlarmManager;
John Spurlock604a5ee2015-06-01 12:27:22 -040021import android.app.AlarmManager.AlarmClockInfo;
Kenny Guy3094d4a2015-04-01 19:14:10 +010022import android.app.IUserSwitchObserver;
Joe Onorato798ac4c2010-05-27 16:39:00 -040023import android.app.StatusBarManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.content.BroadcastReceiver;
25import android.content.Context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import android.content.Intent;
27import android.content.IntentFilter;
Kenny Guy3094d4a2015-04-01 19:14:10 +010028import android.content.pm.UserInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.media.AudioManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.os.Handler;
Kenny Guy3094d4a2015-04-01 19:14:10 +010031import android.os.IRemoteCallback;
32import android.os.RemoteException;
Adrian Roosc42a1e12014-07-07 23:35:53 +020033import android.os.UserHandle;
Kenny Guy3094d4a2015-04-01 19:14:10 +010034import android.os.UserManager;
John Spurlockae641c92014-06-30 18:11:40 -040035import android.provider.Settings.Global;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070036import android.telecom.TelecomManager;
John Spurlockcd686b52013-06-05 10:13:46 -040037import android.util.Log;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038
Wink Savillea639b312012-07-10 12:37:54 -070039import com.android.internal.telephony.IccCardConstants;
Wink Saville04e71b32009-04-02 11:00:54 -070040import com.android.internal.telephony.TelephonyIntents;
Joe Onorato798ac4c2010-05-27 16:39:00 -040041import com.android.systemui.R;
John Spurlock3c4076a2015-02-24 12:12:25 -050042import com.android.systemui.qs.tiles.DndTile;
Jason Monk70364362015-08-06 16:32:18 -040043import com.android.systemui.statusbar.policy.BluetoothController;
44import com.android.systemui.statusbar.policy.BluetoothController.Callback;
John Spurlock96fe98d2014-08-27 09:36:02 -040045import com.android.systemui.statusbar.policy.CastController;
46import com.android.systemui.statusbar.policy.CastController.CastDevice;
Jason Monk952d5d82014-10-27 15:28:22 -040047import com.android.systemui.statusbar.policy.HotspotController;
Adrian Roos88b11932015-07-22 14:59:48 -070048import com.android.systemui.statusbar.policy.UserInfoController;
Joe Onorato798ac4c2010-05-27 16:39:00 -040049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050/**
51 * This class contains all of the policy about which icons are installed in the status
Joe Onorato798ac4c2010-05-27 16:39:00 -040052 * bar at boot time. It goes through the normal API for icons, even though it probably
53 * strictly doesn't need to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054 */
Jason Monk70364362015-08-06 16:32:18 -040055public class PhoneStatusBarPolicy implements Callback {
Joe Onoratofd52b182010-11-10 18:00:52 -080056 private static final String TAG = "PhoneStatusBarPolicy";
John Spurlocka37e9c82014-07-08 09:40:31 -040057 private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Robert Greenwaltd7085fc2010-09-08 15:24:47 -070058
John Spurlock96fe98d2014-08-27 09:36:02 -040059 private static final String SLOT_CAST = "cast";
Jason Monk952d5d82014-10-27 15:28:22 -040060 private static final String SLOT_HOTSPOT = "hotspot";
John Spurlocka37e9c82014-07-08 09:40:31 -040061 private static final String SLOT_BLUETOOTH = "bluetooth";
62 private static final String SLOT_TTY = "tty";
63 private static final String SLOT_ZEN = "zen";
64 private static final String SLOT_VOLUME = "volume";
John Spurlocka37e9c82014-07-08 09:40:31 -040065 private static final String SLOT_ALARM_CLOCK = "alarm_clock";
Kenny Guy3094d4a2015-04-01 19:14:10 +010066 private static final String SLOT_MANAGED_PROFILE = "managed_profile";
John Spurlocka37e9c82014-07-08 09:40:31 -040067
Dianne Hackborn4840e142009-03-24 22:40:29 -070068 private final Context mContext;
Joe Onorato798ac4c2010-05-27 16:39:00 -040069 private final StatusBarManager mService;
Joe Onorato10523b4d2010-10-25 10:42:46 -070070 private final Handler mHandler = new Handler();
John Spurlock96fe98d2014-08-27 09:36:02 -040071 private final CastController mCast;
Jason Monk952d5d82014-10-27 15:28:22 -040072 private final HotspotController mHotspot;
John Spurlock15782262015-05-29 15:35:53 -040073 private final AlarmManager mAlarmManager;
Adrian Roos88b11932015-07-22 14:59:48 -070074 private final UserInfoController mUserInfoController;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076 // Assume it's all good unless we hear otherwise. We don't always seem
77 // to get broadcasts that it *is* there.
Wink Savillea639b312012-07-10 12:37:54 -070078 IccCardConstants.State mSimState = IccCardConstants.State.READY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080079
John Spurlocka37e9c82014-07-08 09:40:31 -040080 private boolean mZenVisible;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081 private boolean mVolumeVisible;
John Spurlock604a5ee2015-06-01 12:27:22 -040082 private boolean mCurrentUserSetup;
Wink Saville04e71b32009-04-02 11:00:54 -070083
John Spurlockae641c92014-06-30 18:11:40 -040084 private int mZen;
John Spurlockba2c6a02014-05-19 09:44:06 -040085
Kenny Guy3094d4a2015-04-01 19:14:10 +010086 private boolean mManagedProfileFocused = false;
87 private boolean mManagedProfileIconVisible = true;
88
89 private boolean mKeyguardVisible = true;
Jason Monk70364362015-08-06 16:32:18 -040090 private BluetoothController mBluetooth;
Wink Savillee9b06d72009-05-18 21:47:50 -070091
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
93 @Override
94 public void onReceive(Context context, Intent intent) {
95 String action = intent.getAction();
Adrian Roosc42a1e12014-07-07 23:35:53 +020096 if (action.equals(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED)) {
97 updateAlarm();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 }
John Spurlockbcc10872014-11-28 15:29:21 -050099 else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION) ||
100 action.equals(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION)) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400101 updateVolumeZen();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102 }
103 else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
104 updateSimState(intent);
105 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700106 else if (action.equals(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED)) {
Wink Saville04e71b32009-04-02 11:00:54 -0700107 updateTTY(intent);
108 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 }
110 };
111
Adrian Roos88b11932015-07-22 14:59:48 -0700112 public PhoneStatusBarPolicy(Context context, CastController cast, HotspotController hotspot,
Jason Monk70364362015-08-06 16:32:18 -0400113 UserInfoController userInfoController, BluetoothController bluetooth) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114 mContext = context;
John Spurlock96fe98d2014-08-27 09:36:02 -0400115 mCast = cast;
Jason Monk952d5d82014-10-27 15:28:22 -0400116 mHotspot = hotspot;
Jason Monk70364362015-08-06 16:32:18 -0400117 mBluetooth = bluetooth;
118 mBluetooth.addStateChangedCallback(this);
John Spurlock15782262015-05-29 15:35:53 -0400119 mService = (StatusBarManager) context.getSystemService(Context.STATUS_BAR_SERVICE);
120 mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Adrian Roos88b11932015-07-22 14:59:48 -0700121 mUserInfoController = userInfoController;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400123 // listen for broadcasts
124 IntentFilter filter = new IntentFilter();
Adrian Roosc42a1e12014-07-07 23:35:53 +0200125 filter.addAction(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED);
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400126 filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
John Spurlockbcc10872014-11-28 15:29:21 -0500127 filter.addAction(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION);
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400128 filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700129 filter.addAction(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED);
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400130 mContext.registerReceiver(mIntentReceiver, filter, null, mHandler);
131
Kenny Guy3094d4a2015-04-01 19:14:10 +0100132 // listen for user / profile change.
133 try {
134 ActivityManagerNative.getDefault().registerUserSwitchObserver(mUserSwitchListener);
135 } catch (RemoteException e) {
136 // Ignore
137 }
138
Wink Saville04e71b32009-04-02 11:00:54 -0700139 // TTY status
John Spurlocka37e9c82014-07-08 09:40:31 -0400140 mService.setIcon(SLOT_TTY, R.drawable.stat_sys_tty_mode, 0, null);
141 mService.setIconVisibility(SLOT_TTY, false);
Wink Saville04e71b32009-04-02 11:00:54 -0700142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143 // bluetooth status
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700144 updateBluetooth();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146 // Alarm clock
John Spurlocka37e9c82014-07-08 09:40:31 -0400147 mService.setIcon(SLOT_ALARM_CLOCK, R.drawable.stat_sys_alarm, 0, null);
148 mService.setIconVisibility(SLOT_ALARM_CLOCK, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149
John Spurlocka37e9c82014-07-08 09:40:31 -0400150 // zen
151 mService.setIcon(SLOT_ZEN, R.drawable.stat_sys_zen_important, 0, null);
152 mService.setIconVisibility(SLOT_ZEN, false);
153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154 // volume
John Spurlockad494bc2014-07-19 15:56:19 -0400155 mService.setIcon(SLOT_VOLUME, R.drawable.stat_sys_ringer_vibrate, 0, null);
John Spurlocka37e9c82014-07-08 09:40:31 -0400156 mService.setIconVisibility(SLOT_VOLUME, false);
157 updateVolumeZen();
John Spurlock96fe98d2014-08-27 09:36:02 -0400158
159 // cast
160 mService.setIcon(SLOT_CAST, R.drawable.stat_sys_cast, 0, null);
161 mService.setIconVisibility(SLOT_CAST, false);
162 mCast.addCallback(mCastCallback);
Jason Monk952d5d82014-10-27 15:28:22 -0400163
164 // hotspot
Jason Monk08187a42015-06-09 14:33:51 -0400165 mService.setIcon(SLOT_HOTSPOT, R.drawable.stat_sys_hotspot, 0,
166 mContext.getString(R.string.accessibility_status_bar_hotspot));
Jason Monk952d5d82014-10-27 15:28:22 -0400167 mService.setIconVisibility(SLOT_HOTSPOT, mHotspot.isHotspotEnabled());
168 mHotspot.addCallback(mHotspotCallback);
Kenny Guy3094d4a2015-04-01 19:14:10 +0100169
170 // managed profile
Adrian Roos1b5eb972015-06-11 18:22:52 -0700171 mService.setIcon(SLOT_MANAGED_PROFILE, R.drawable.stat_sys_managed_profile_status, 0,
172 mContext.getString(R.string.accessibility_managed_profile));
Kenny Guy3094d4a2015-04-01 19:14:10 +0100173 mService.setIconVisibility(SLOT_MANAGED_PROFILE, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 }
175
John Spurlockae641c92014-06-30 18:11:40 -0400176 public void setZenMode(int zen) {
John Spurlockba2c6a02014-05-19 09:44:06 -0400177 mZen = zen;
John Spurlocka37e9c82014-07-08 09:40:31 -0400178 updateVolumeZen();
John Spurlockba2c6a02014-05-19 09:44:06 -0400179 }
180
Adrian Roosc42a1e12014-07-07 23:35:53 +0200181 private void updateAlarm() {
John Spurlock604a5ee2015-06-01 12:27:22 -0400182 final AlarmClockInfo alarm = mAlarmManager.getNextAlarmClock(UserHandle.USER_CURRENT);
183 final boolean hasAlarm = alarm != null && alarm.getTriggerTime() > 0;
John Spurlock15782262015-05-29 15:35:53 -0400184 final boolean zenNone = mZen == Global.ZEN_MODE_NO_INTERRUPTIONS;
John Spurlock15782262015-05-29 15:35:53 -0400185 mService.setIcon(SLOT_ALARM_CLOCK, zenNone ? R.drawable.stat_sys_alarm_dim
186 : R.drawable.stat_sys_alarm, 0, null);
John Spurlock604a5ee2015-06-01 12:27:22 -0400187 mService.setIconVisibility(SLOT_ALARM_CLOCK, mCurrentUserSetup && hasAlarm);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800188 }
189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190 private final void updateSimState(Intent intent) {
Wink Savillea639b312012-07-10 12:37:54 -0700191 String stateExtra = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
192 if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) {
193 mSimState = IccCardConstants.State.ABSENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194 }
Rakesh Pallerlaf099a5f2013-02-06 11:44:23 +0530195 else if (IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR.equals(stateExtra)) {
196 mSimState = IccCardConstants.State.CARD_IO_ERROR;
197 }
Wink Savillea639b312012-07-10 12:37:54 -0700198 else if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(stateExtra)) {
199 mSimState = IccCardConstants.State.READY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800200 }
Wink Savillea639b312012-07-10 12:37:54 -0700201 else if (IccCardConstants.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) {
202 final String lockedReason =
203 intent.getStringExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON);
204 if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) {
205 mSimState = IccCardConstants.State.PIN_REQUIRED;
johnwang347c5a22009-08-24 22:11:11 -0700206 }
Wink Savillea639b312012-07-10 12:37:54 -0700207 else if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) {
208 mSimState = IccCardConstants.State.PUK_REQUIRED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 }
210 else {
Wink Savillea639b312012-07-10 12:37:54 -0700211 mSimState = IccCardConstants.State.NETWORK_LOCKED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212 }
213 } else {
Wink Savillea639b312012-07-10 12:37:54 -0700214 mSimState = IccCardConstants.State.UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800215 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 }
217
John Spurlockbcc10872014-11-28 15:29:21 -0500218 private final void updateVolumeZen() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219 AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
John Spurlocka37e9c82014-07-08 09:40:31 -0400220
221 boolean zenVisible = false;
222 int zenIconId = 0;
223 String zenDescription = null;
224
225 boolean volumeVisible = false;
226 int volumeIconId = 0;
227 String volumeDescription = null;
228
John Spurlockf88d8082015-03-25 18:09:51 -0400229 if (DndTile.isVisible(mContext) || DndTile.isCombinedIcon(mContext)) {
John Spurlock3c4076a2015-02-24 12:12:25 -0500230 zenVisible = mZen != Global.ZEN_MODE_OFF;
John Spurlock4ec8b602015-05-11 17:46:28 -0400231 zenIconId = mZen == Global.ZEN_MODE_NO_INTERRUPTIONS
232 ? R.drawable.stat_sys_dnd_total_silence : R.drawable.stat_sys_dnd;
John Spurlock3c4076a2015-02-24 12:12:25 -0500233 zenDescription = mContext.getString(R.string.quick_settings_dnd_label);
234 } else if (mZen == Global.ZEN_MODE_NO_INTERRUPTIONS) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400235 zenVisible = true;
236 zenIconId = R.drawable.stat_sys_zen_none;
John Spurlockd9c75db2015-04-28 11:19:13 -0400237 zenDescription = mContext.getString(R.string.interruption_level_none);
John Spurlockae641c92014-06-30 18:11:40 -0400238 } else if (mZen == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400239 zenVisible = true;
240 zenIconId = R.drawable.stat_sys_zen_important;
John Spurlockd9c75db2015-04-28 11:19:13 -0400241 zenDescription = mContext.getString(R.string.interruption_level_priority);
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700242 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800243
John Spurlockd9c75db2015-04-28 11:19:13 -0400244 if (DndTile.isVisible(mContext) && !DndTile.isCombinedIcon(mContext)
John Spurlocka48d7792015-03-03 17:35:57 -0500245 && audioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_SILENT) {
246 volumeVisible = true;
247 volumeIconId = R.drawable.stat_sys_ringer_silent;
248 volumeDescription = mContext.getString(R.string.accessibility_ringer_silent);
John Spurlock4f1163c2015-04-02 17:41:21 -0400249 } else if (mZen != Global.ZEN_MODE_NO_INTERRUPTIONS && mZen != Global.ZEN_MODE_ALARMS &&
John Spurlock661f2cf2014-11-17 10:29:10 -0500250 audioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_VIBRATE) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400251 volumeVisible = true;
252 volumeIconId = R.drawable.stat_sys_ringer_vibrate;
253 volumeDescription = mContext.getString(R.string.accessibility_ringer_vibrate);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800254 }
John Spurlocka37e9c82014-07-08 09:40:31 -0400255
256 if (zenVisible) {
257 mService.setIcon(SLOT_ZEN, zenIconId, 0, zenDescription);
258 }
259 if (zenVisible != mZenVisible) {
260 mService.setIconVisibility(SLOT_ZEN, zenVisible);
261 mZenVisible = zenVisible;
262 }
263
264 if (volumeVisible) {
265 mService.setIcon(SLOT_VOLUME, volumeIconId, 0, volumeDescription);
266 }
267 if (volumeVisible != mVolumeVisible) {
268 mService.setIconVisibility(SLOT_VOLUME, volumeVisible);
269 mVolumeVisible = volumeVisible;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270 }
John Spurlock15782262015-05-29 15:35:53 -0400271 updateAlarm();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272 }
273
Jason Monk70364362015-08-06 16:32:18 -0400274 @Override
275 public void onBluetoothDevicesChanged() {
276 updateBluetooth();
277 }
278
279 @Override
280 public void onBluetoothStateChange(boolean enabled) {
281 updateBluetooth();
282 }
283
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700284 private final void updateBluetooth() {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400285 int iconId = R.drawable.stat_sys_data_bluetooth;
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700286 String contentDescription =
Jason Monk1aa32822015-07-14 16:10:32 -0400287 mContext.getString(R.string.accessibility_quick_settings_bluetooth_on);
Jason Monk70364362015-08-06 16:32:18 -0400288 boolean bluetoothEnabled = false;
289 if (mBluetooth != null) {
290 bluetoothEnabled = mBluetooth.isBluetoothEnabled();
291 if (mBluetooth.isBluetoothConnected()) {
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -0700292 iconId = R.drawable.stat_sys_data_bluetooth_connected;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700293 contentDescription = mContext.getString(R.string.accessibility_bluetooth_connected);
Jaikumar Ganesh084c6652009-12-07 10:58:18 -0800294 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700296
John Spurlocka37e9c82014-07-08 09:40:31 -0400297 mService.setIcon(SLOT_BLUETOOTH, iconId, 0, contentDescription);
Jason Monk70364362015-08-06 16:32:18 -0400298 mService.setIconVisibility(SLOT_BLUETOOTH, bluetoothEnabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800299 }
300
Wink Savillee9b06d72009-05-18 21:47:50 -0700301 private final void updateTTY(Intent intent) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700302 int currentTtyMode = intent.getIntExtra(TelecomManager.EXTRA_CURRENT_TTY_MODE,
303 TelecomManager.TTY_MODE_OFF);
304 boolean enabled = currentTtyMode != TelecomManager.TTY_MODE_OFF;
Wink Saville04e71b32009-04-02 11:00:54 -0700305
John Spurlocka37e9c82014-07-08 09:40:31 -0400306 if (DEBUG) Log.v(TAG, "updateTTY: enabled: " + enabled);
Wink Saville04e71b32009-04-02 11:00:54 -0700307
308 if (enabled) {
309 // TTY is on
John Spurlocka37e9c82014-07-08 09:40:31 -0400310 if (DEBUG) Log.v(TAG, "updateTTY: set TTY on");
311 mService.setIcon(SLOT_TTY, R.drawable.stat_sys_tty_mode, 0,
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700312 mContext.getString(R.string.accessibility_tty_enabled));
John Spurlocka37e9c82014-07-08 09:40:31 -0400313 mService.setIconVisibility(SLOT_TTY, true);
Wink Saville04e71b32009-04-02 11:00:54 -0700314 } else {
315 // TTY is off
John Spurlocka37e9c82014-07-08 09:40:31 -0400316 if (DEBUG) Log.v(TAG, "updateTTY: set TTY off");
317 mService.setIconVisibility(SLOT_TTY, false);
Wink Saville04e71b32009-04-02 11:00:54 -0700318 }
319 }
John Spurlock96fe98d2014-08-27 09:36:02 -0400320
321 private void updateCast() {
322 boolean isCasting = false;
323 for (CastDevice device : mCast.getCastDevices()) {
324 if (device.state == CastDevice.STATE_CONNECTING
325 || device.state == CastDevice.STATE_CONNECTED) {
326 isCasting = true;
327 break;
328 }
329 }
330 if (DEBUG) Log.v(TAG, "updateCast: isCasting: " + isCasting);
331 if (isCasting) {
332 mService.setIcon(SLOT_CAST, R.drawable.stat_sys_cast, 0,
333 mContext.getString(R.string.accessibility_casting));
334 }
335 mService.setIconVisibility(SLOT_CAST, isCasting);
336 }
337
Kenny Guy3094d4a2015-04-01 19:14:10 +0100338 private void profileChanged(int userId) {
339 UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
340 UserInfo user = null;
341 if (userId == UserHandle.USER_CURRENT) {
342 try {
343 user = ActivityManagerNative.getDefault().getCurrentUser();
344 } catch (RemoteException e) {
345 // Ignore
346 }
347 } else {
348 user = userManager.getUserInfo(userId);
349 }
350
351 mManagedProfileFocused = user != null && user.isManagedProfile();
352 if (DEBUG) Log.v(TAG, "profileChanged: mManagedProfileFocused: " + mManagedProfileFocused);
353 // Actually update the icon later when transition starts.
354 }
355
356 private void updateManagedProfile() {
357 if (DEBUG) Log.v(TAG, "updateManagedProfile: mManagedProfileFocused: "
358 + mManagedProfileFocused
359 + " mKeyguardVisible: " + mKeyguardVisible);
360 boolean showIcon = mManagedProfileFocused && !mKeyguardVisible;
361 if (mManagedProfileIconVisible != showIcon) {
362 mService.setIconVisibility(SLOT_MANAGED_PROFILE, showIcon);
363 mManagedProfileIconVisible = showIcon;
364 }
365 }
366
367 private final IUserSwitchObserver.Stub mUserSwitchListener =
368 new IUserSwitchObserver.Stub() {
369 @Override
370 public void onUserSwitching(int newUserId, IRemoteCallback reply) {
Adrian Roos88b11932015-07-22 14:59:48 -0700371 mUserInfoController.reloadUserInfo();
Kenny Guy3094d4a2015-04-01 19:14:10 +0100372 }
373
374 @Override
375 public void onUserSwitchComplete(int newUserId) throws RemoteException {
376 updateAlarm();
377 profileChanged(newUserId);
378 }
379
380 @Override
381 public void onForegroundProfileSwitch(int newProfileId) {
382 profileChanged(newProfileId);
383 }
384 };
385
Jason Monk952d5d82014-10-27 15:28:22 -0400386 private final HotspotController.Callback mHotspotCallback = new HotspotController.Callback() {
387 @Override
388 public void onHotspotChanged(boolean enabled) {
389 mService.setIconVisibility(SLOT_HOTSPOT, enabled);
390 }
391 };
392
John Spurlock96fe98d2014-08-27 09:36:02 -0400393 private final CastController.Callback mCastCallback = new CastController.Callback() {
394 @Override
395 public void onCastDevicesChanged() {
396 updateCast();
397 }
398 };
Kenny Guy3094d4a2015-04-01 19:14:10 +0100399
400 public void appTransitionStarting(long startTime, long duration) {
401 updateManagedProfile();
402 }
403
404 public void setKeyguardShowing(boolean visible) {
405 mKeyguardVisible = visible;
406 updateManagedProfile();
407 }
John Spurlock604a5ee2015-06-01 12:27:22 -0400408
409 public void setCurrentUserSetup(boolean userSetup) {
410 if (mCurrentUserSetup == userSetup) return;
411 mCurrentUserSetup = userSetup;
412 updateAlarm();
413 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800414}