blob: 59d831c921dbf9a72dc66147056057519bd7f590 [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
Rubin Xu1205fb12015-11-04 17:45:03 +000019import android.app.ActivityManager;
Kenny Guy3094d4a2015-04-01 19:14:10 +010020import android.app.ActivityManagerNative;
Adrian Roosc42a1e12014-07-07 23:35:53 +020021import android.app.AlarmManager;
John Spurlock604a5ee2015-06-01 12:27:22 -040022import android.app.AlarmManager.AlarmClockInfo;
Fyodor Kupolov6005b3f2015-11-23 17:41:50 -080023import android.app.SynchronousUserSwitchObserver;
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.RemoteException;
Adrian Roosc42a1e12014-07-07 23:35:53 +020032import android.os.UserHandle;
Kenny Guy3094d4a2015-04-01 19:14:10 +010033import android.os.UserManager;
John Spurlockae641c92014-06-30 18:11:40 -040034import android.provider.Settings.Global;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070035import android.telecom.TelecomManager;
John Spurlockcd686b52013-06-05 10:13:46 -040036import android.util.Log;
Wink Savillea639b312012-07-10 12:37:54 -070037import com.android.internal.telephony.IccCardConstants;
Wink Saville04e71b32009-04-02 11:00:54 -070038import com.android.internal.telephony.TelephonyIntents;
Joe Onorato798ac4c2010-05-27 16:39:00 -040039import com.android.systemui.R;
John Spurlock3c4076a2015-02-24 12:12:25 -050040import com.android.systemui.qs.tiles.DndTile;
Jason Monk70364362015-08-06 16:32:18 -040041import com.android.systemui.statusbar.policy.BluetoothController;
42import com.android.systemui.statusbar.policy.BluetoothController.Callback;
John Spurlock96fe98d2014-08-27 09:36:02 -040043import com.android.systemui.statusbar.policy.CastController;
44import com.android.systemui.statusbar.policy.CastController.CastDevice;
Jason Monk952d5d82014-10-27 15:28:22 -040045import com.android.systemui.statusbar.policy.HotspotController;
Adrian Roos88b11932015-07-22 14:59:48 -070046import com.android.systemui.statusbar.policy.UserInfoController;
Joe Onorato798ac4c2010-05-27 16:39:00 -040047
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 */
Jason Monk70364362015-08-06 16:32:18 -040053public class PhoneStatusBarPolicy implements Callback {
Joe Onoratofd52b182010-11-10 18:00:52 -080054 private static final String TAG = "PhoneStatusBarPolicy";
John Spurlocka37e9c82014-07-08 09:40:31 -040055 private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Robert Greenwaltd7085fc2010-09-08 15:24:47 -070056
John Spurlock96fe98d2014-08-27 09:36:02 -040057 private static final String SLOT_CAST = "cast";
Jason Monk952d5d82014-10-27 15:28:22 -040058 private static final String SLOT_HOTSPOT = "hotspot";
John Spurlocka37e9c82014-07-08 09:40:31 -040059 private static final String SLOT_BLUETOOTH = "bluetooth";
60 private static final String SLOT_TTY = "tty";
61 private static final String SLOT_ZEN = "zen";
62 private static final String SLOT_VOLUME = "volume";
John Spurlocka37e9c82014-07-08 09:40:31 -040063 private static final String SLOT_ALARM_CLOCK = "alarm_clock";
Kenny Guy3094d4a2015-04-01 19:14:10 +010064 private static final String SLOT_MANAGED_PROFILE = "managed_profile";
John Spurlocka37e9c82014-07-08 09:40:31 -040065
Dianne Hackborn4840e142009-03-24 22:40:29 -070066 private final Context mContext;
Joe Onorato10523b4d2010-10-25 10:42:46 -070067 private final Handler mHandler = new Handler();
John Spurlock96fe98d2014-08-27 09:36:02 -040068 private final CastController mCast;
Jason Monk952d5d82014-10-27 15:28:22 -040069 private final HotspotController mHotspot;
John Spurlock15782262015-05-29 15:35:53 -040070 private final AlarmManager mAlarmManager;
Adrian Roos88b11932015-07-22 14:59:48 -070071 private final UserInfoController mUserInfoController;
Rubin Xu1205fb12015-11-04 17:45:03 +000072 private final UserManager mUserManager;
Jason Monk07473ce2016-01-05 14:59:19 -050073 private final StatusBarIconController mIconController;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074
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 Savillea639b312012-07-10 12:37:54 -070077 IccCardConstants.State mSimState = IccCardConstants.State.READY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078
John Spurlocka37e9c82014-07-08 09:40:31 -040079 private boolean mZenVisible;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080 private boolean mVolumeVisible;
John Spurlock604a5ee2015-06-01 12:27:22 -040081 private boolean mCurrentUserSetup;
Wink Saville04e71b32009-04-02 11:00:54 -070082
John Spurlockae641c92014-06-30 18:11:40 -040083 private int mZen;
John Spurlockba2c6a02014-05-19 09:44:06 -040084
Kenny Guy3094d4a2015-04-01 19:14:10 +010085 private boolean mManagedProfileFocused = false;
Rubin Xu1205fb12015-11-04 17:45:03 +000086 private boolean mManagedProfileIconVisible = false;
87 private boolean mManagedProfileInQuietMode = false;
Kenny Guy3094d4a2015-04-01 19:14:10 +010088
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();
Jason Monk07473ce2016-01-05 14:59:19 -050098 } else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION) ||
John Spurlockbcc10872014-11-28 15:29:21 -050099 action.equals(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION)) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400100 updateVolumeZen();
Jason Monk07473ce2016-01-05 14:59:19 -0500101 } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102 updateSimState(intent);
Jason Monk07473ce2016-01-05 14:59:19 -0500103 } else if (action.equals(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED)) {
Wink Saville04e71b32009-04-02 11:00:54 -0700104 updateTTY(intent);
Jason Monk07473ce2016-01-05 14:59:19 -0500105 } else if (action.equals(Intent.ACTION_MANAGED_PROFILE_AVAILABILITY_CHANGED)) {
Rubin Xu1205fb12015-11-04 17:45:03 +0000106 updateQuietState();
107 updateManagedProfile();
108 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 }
110 };
111
Dan Sandler8fd25bf2015-10-20 16:01:27 -0700112 private Runnable mRemoveCastIconRunnable = new Runnable() {
113 @Override
114 public void run() {
115 if (DEBUG) Log.v(TAG, "updateCast: hiding icon NOW");
Jason Monk07473ce2016-01-05 14:59:19 -0500116 mIconController.setIconVisibility(SLOT_CAST, false);
Dan Sandler8fd25bf2015-10-20 16:01:27 -0700117 }
118 };
119
Jason Monk07473ce2016-01-05 14:59:19 -0500120 public PhoneStatusBarPolicy(Context context, StatusBarIconController iconController,
121 CastController cast, HotspotController hotspot, UserInfoController userInfoController,
122 BluetoothController bluetooth) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123 mContext = context;
Jason Monk07473ce2016-01-05 14:59:19 -0500124 mIconController = iconController;
John Spurlock96fe98d2014-08-27 09:36:02 -0400125 mCast = cast;
Jason Monk952d5d82014-10-27 15:28:22 -0400126 mHotspot = hotspot;
Jason Monk70364362015-08-06 16:32:18 -0400127 mBluetooth = bluetooth;
128 mBluetooth.addStateChangedCallback(this);
John Spurlock15782262015-05-29 15:35:53 -0400129 mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Adrian Roos88b11932015-07-22 14:59:48 -0700130 mUserInfoController = userInfoController;
Rubin Xu1205fb12015-11-04 17:45:03 +0000131 mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400133 // listen for broadcasts
134 IntentFilter filter = new IntentFilter();
Adrian Roosc42a1e12014-07-07 23:35:53 +0200135 filter.addAction(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED);
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400136 filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
John Spurlockbcc10872014-11-28 15:29:21 -0500137 filter.addAction(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION);
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400138 filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700139 filter.addAction(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED);
Rubin Xu1205fb12015-11-04 17:45:03 +0000140 filter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABILITY_CHANGED);
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400141 mContext.registerReceiver(mIntentReceiver, filter, null, mHandler);
142
Kenny Guy3094d4a2015-04-01 19:14:10 +0100143 // listen for user / profile change.
144 try {
145 ActivityManagerNative.getDefault().registerUserSwitchObserver(mUserSwitchListener);
146 } catch (RemoteException e) {
147 // Ignore
148 }
149
Wink Saville04e71b32009-04-02 11:00:54 -0700150 // TTY status
Jason Monk07473ce2016-01-05 14:59:19 -0500151 mIconController.setIcon(SLOT_TTY, R.drawable.stat_sys_tty_mode, null);
152 mIconController.setIconVisibility(SLOT_TTY, false);
Wink Saville04e71b32009-04-02 11:00:54 -0700153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154 // bluetooth status
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700155 updateBluetooth();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 // Alarm clock
Jason Monk07473ce2016-01-05 14:59:19 -0500158 mIconController.setIcon(SLOT_ALARM_CLOCK, R.drawable.stat_sys_alarm, null);
159 mIconController.setIconVisibility(SLOT_ALARM_CLOCK, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160
John Spurlocka37e9c82014-07-08 09:40:31 -0400161 // zen
Jason Monk07473ce2016-01-05 14:59:19 -0500162 mIconController.setIcon(SLOT_ZEN, R.drawable.stat_sys_zen_important, null);
163 mIconController.setIconVisibility(SLOT_ZEN, false);
John Spurlocka37e9c82014-07-08 09:40:31 -0400164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 // volume
Jason Monk07473ce2016-01-05 14:59:19 -0500166 mIconController.setIcon(SLOT_VOLUME, R.drawable.stat_sys_ringer_vibrate, null);
167 mIconController.setIconVisibility(SLOT_VOLUME, false);
John Spurlocka37e9c82014-07-08 09:40:31 -0400168 updateVolumeZen();
John Spurlock96fe98d2014-08-27 09:36:02 -0400169
170 // cast
Jason Monk07473ce2016-01-05 14:59:19 -0500171 mIconController.setIcon(SLOT_CAST, R.drawable.stat_sys_cast, null);
172 mIconController.setIconVisibility(SLOT_CAST, false);
John Spurlock96fe98d2014-08-27 09:36:02 -0400173 mCast.addCallback(mCastCallback);
Jason Monk952d5d82014-10-27 15:28:22 -0400174
175 // hotspot
Jason Monk07473ce2016-01-05 14:59:19 -0500176 mIconController.setIcon(SLOT_HOTSPOT, R.drawable.stat_sys_hotspot,
Jason Monk08187a42015-06-09 14:33:51 -0400177 mContext.getString(R.string.accessibility_status_bar_hotspot));
Jason Monk07473ce2016-01-05 14:59:19 -0500178 mIconController.setIconVisibility(SLOT_HOTSPOT, mHotspot.isHotspotEnabled());
Jason Monk952d5d82014-10-27 15:28:22 -0400179 mHotspot.addCallback(mHotspotCallback);
Kenny Guy3094d4a2015-04-01 19:14:10 +0100180
181 // managed profile
Jason Monk07473ce2016-01-05 14:59:19 -0500182 mIconController.setIcon(SLOT_MANAGED_PROFILE, R.drawable.stat_sys_managed_profile_status,
Adrian Roos1b5eb972015-06-11 18:22:52 -0700183 mContext.getString(R.string.accessibility_managed_profile));
Jason Monk07473ce2016-01-05 14:59:19 -0500184 mIconController.setIconVisibility(SLOT_MANAGED_PROFILE, mManagedProfileIconVisible);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 }
186
John Spurlockae641c92014-06-30 18:11:40 -0400187 public void setZenMode(int zen) {
John Spurlockba2c6a02014-05-19 09:44:06 -0400188 mZen = zen;
John Spurlocka37e9c82014-07-08 09:40:31 -0400189 updateVolumeZen();
John Spurlockba2c6a02014-05-19 09:44:06 -0400190 }
191
Adrian Roosc42a1e12014-07-07 23:35:53 +0200192 private void updateAlarm() {
John Spurlock604a5ee2015-06-01 12:27:22 -0400193 final AlarmClockInfo alarm = mAlarmManager.getNextAlarmClock(UserHandle.USER_CURRENT);
194 final boolean hasAlarm = alarm != null && alarm.getTriggerTime() > 0;
John Spurlock15782262015-05-29 15:35:53 -0400195 final boolean zenNone = mZen == Global.ZEN_MODE_NO_INTERRUPTIONS;
Jason Monk07473ce2016-01-05 14:59:19 -0500196 mIconController.setIcon(SLOT_ALARM_CLOCK, zenNone ? R.drawable.stat_sys_alarm_dim
197 : R.drawable.stat_sys_alarm, null);
198 mIconController.setIconVisibility(SLOT_ALARM_CLOCK, mCurrentUserSetup && hasAlarm);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199 }
200
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800201 private final void updateSimState(Intent intent) {
Wink Savillea639b312012-07-10 12:37:54 -0700202 String stateExtra = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
203 if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) {
204 mSimState = IccCardConstants.State.ABSENT;
Jason Monk07473ce2016-01-05 14:59:19 -0500205 } else if (IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR.equals(stateExtra)) {
Rakesh Pallerlaf099a5f2013-02-06 11:44:23 +0530206 mSimState = IccCardConstants.State.CARD_IO_ERROR;
Jason Monk07473ce2016-01-05 14:59:19 -0500207 } else if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(stateExtra)) {
Wink Savillea639b312012-07-10 12:37:54 -0700208 mSimState = IccCardConstants.State.READY;
Jason Monk07473ce2016-01-05 14:59:19 -0500209 } else if (IccCardConstants.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) {
Wink Savillea639b312012-07-10 12:37:54 -0700210 final String lockedReason =
211 intent.getStringExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON);
212 if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) {
213 mSimState = IccCardConstants.State.PIN_REQUIRED;
Jason Monk07473ce2016-01-05 14:59:19 -0500214 } else if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) {
Wink Savillea639b312012-07-10 12:37:54 -0700215 mSimState = IccCardConstants.State.PUK_REQUIRED;
Jason Monk07473ce2016-01-05 14:59:19 -0500216 } else {
Wink Savillea639b312012-07-10 12:37:54 -0700217 mSimState = IccCardConstants.State.NETWORK_LOCKED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800218 }
219 } else {
Wink Savillea639b312012-07-10 12:37:54 -0700220 mSimState = IccCardConstants.State.UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222 }
223
John Spurlockbcc10872014-11-28 15:29:21 -0500224 private final void updateVolumeZen() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225 AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
John Spurlocka37e9c82014-07-08 09:40:31 -0400226
227 boolean zenVisible = false;
228 int zenIconId = 0;
229 String zenDescription = null;
230
231 boolean volumeVisible = false;
232 int volumeIconId = 0;
233 String volumeDescription = null;
234
John Spurlockf88d8082015-03-25 18:09:51 -0400235 if (DndTile.isVisible(mContext) || DndTile.isCombinedIcon(mContext)) {
John Spurlock3c4076a2015-02-24 12:12:25 -0500236 zenVisible = mZen != Global.ZEN_MODE_OFF;
John Spurlock4ec8b602015-05-11 17:46:28 -0400237 zenIconId = mZen == Global.ZEN_MODE_NO_INTERRUPTIONS
238 ? R.drawable.stat_sys_dnd_total_silence : R.drawable.stat_sys_dnd;
John Spurlock3c4076a2015-02-24 12:12:25 -0500239 zenDescription = mContext.getString(R.string.quick_settings_dnd_label);
240 } else if (mZen == Global.ZEN_MODE_NO_INTERRUPTIONS) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400241 zenVisible = true;
242 zenIconId = R.drawable.stat_sys_zen_none;
John Spurlockd9c75db2015-04-28 11:19:13 -0400243 zenDescription = mContext.getString(R.string.interruption_level_none);
John Spurlockae641c92014-06-30 18:11:40 -0400244 } else if (mZen == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400245 zenVisible = true;
246 zenIconId = R.drawable.stat_sys_zen_important;
John Spurlockd9c75db2015-04-28 11:19:13 -0400247 zenDescription = mContext.getString(R.string.interruption_level_priority);
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700248 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800249
John Spurlockd9c75db2015-04-28 11:19:13 -0400250 if (DndTile.isVisible(mContext) && !DndTile.isCombinedIcon(mContext)
John Spurlocka48d7792015-03-03 17:35:57 -0500251 && audioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_SILENT) {
252 volumeVisible = true;
253 volumeIconId = R.drawable.stat_sys_ringer_silent;
254 volumeDescription = mContext.getString(R.string.accessibility_ringer_silent);
John Spurlock4f1163c2015-04-02 17:41:21 -0400255 } else if (mZen != Global.ZEN_MODE_NO_INTERRUPTIONS && mZen != Global.ZEN_MODE_ALARMS &&
John Spurlock661f2cf2014-11-17 10:29:10 -0500256 audioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_VIBRATE) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400257 volumeVisible = true;
258 volumeIconId = R.drawable.stat_sys_ringer_vibrate;
259 volumeDescription = mContext.getString(R.string.accessibility_ringer_vibrate);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800260 }
John Spurlocka37e9c82014-07-08 09:40:31 -0400261
262 if (zenVisible) {
Jason Monk07473ce2016-01-05 14:59:19 -0500263 mIconController.setIcon(SLOT_ZEN, zenIconId, zenDescription);
John Spurlocka37e9c82014-07-08 09:40:31 -0400264 }
265 if (zenVisible != mZenVisible) {
Jason Monk07473ce2016-01-05 14:59:19 -0500266 mIconController.setIconVisibility(SLOT_ZEN, zenVisible);
John Spurlocka37e9c82014-07-08 09:40:31 -0400267 mZenVisible = zenVisible;
268 }
269
270 if (volumeVisible) {
Jason Monk07473ce2016-01-05 14:59:19 -0500271 mIconController.setIcon(SLOT_VOLUME, volumeIconId, volumeDescription);
John Spurlocka37e9c82014-07-08 09:40:31 -0400272 }
273 if (volumeVisible != mVolumeVisible) {
Jason Monk07473ce2016-01-05 14:59:19 -0500274 mIconController.setIconVisibility(SLOT_VOLUME, volumeVisible);
John Spurlocka37e9c82014-07-08 09:40:31 -0400275 mVolumeVisible = volumeVisible;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800276 }
John Spurlock15782262015-05-29 15:35:53 -0400277 updateAlarm();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 }
279
Jason Monk70364362015-08-06 16:32:18 -0400280 @Override
281 public void onBluetoothDevicesChanged() {
282 updateBluetooth();
283 }
284
285 @Override
286 public void onBluetoothStateChange(boolean enabled) {
287 updateBluetooth();
288 }
289
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700290 private final void updateBluetooth() {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400291 int iconId = R.drawable.stat_sys_data_bluetooth;
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700292 String contentDescription =
Jason Monk1aa32822015-07-14 16:10:32 -0400293 mContext.getString(R.string.accessibility_quick_settings_bluetooth_on);
Jason Monk70364362015-08-06 16:32:18 -0400294 boolean bluetoothEnabled = false;
295 if (mBluetooth != null) {
296 bluetoothEnabled = mBluetooth.isBluetoothEnabled();
297 if (mBluetooth.isBluetoothConnected()) {
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -0700298 iconId = R.drawable.stat_sys_data_bluetooth_connected;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700299 contentDescription = mContext.getString(R.string.accessibility_bluetooth_connected);
Jaikumar Ganesh084c6652009-12-07 10:58:18 -0800300 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800301 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700302
Jason Monk07473ce2016-01-05 14:59:19 -0500303 mIconController.setIcon(SLOT_BLUETOOTH, iconId, contentDescription);
304 mIconController.setIconVisibility(SLOT_BLUETOOTH, bluetoothEnabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800305 }
306
Wink Savillee9b06d72009-05-18 21:47:50 -0700307 private final void updateTTY(Intent intent) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700308 int currentTtyMode = intent.getIntExtra(TelecomManager.EXTRA_CURRENT_TTY_MODE,
309 TelecomManager.TTY_MODE_OFF);
310 boolean enabled = currentTtyMode != TelecomManager.TTY_MODE_OFF;
Wink Saville04e71b32009-04-02 11:00:54 -0700311
John Spurlocka37e9c82014-07-08 09:40:31 -0400312 if (DEBUG) Log.v(TAG, "updateTTY: enabled: " + enabled);
Wink Saville04e71b32009-04-02 11:00:54 -0700313
314 if (enabled) {
315 // TTY is on
John Spurlocka37e9c82014-07-08 09:40:31 -0400316 if (DEBUG) Log.v(TAG, "updateTTY: set TTY on");
Jason Monk07473ce2016-01-05 14:59:19 -0500317 mIconController.setIcon(SLOT_TTY, R.drawable.stat_sys_tty_mode,
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700318 mContext.getString(R.string.accessibility_tty_enabled));
Jason Monk07473ce2016-01-05 14:59:19 -0500319 mIconController.setIconVisibility(SLOT_TTY, true);
Wink Saville04e71b32009-04-02 11:00:54 -0700320 } else {
321 // TTY is off
John Spurlocka37e9c82014-07-08 09:40:31 -0400322 if (DEBUG) Log.v(TAG, "updateTTY: set TTY off");
Jason Monk07473ce2016-01-05 14:59:19 -0500323 mIconController.setIconVisibility(SLOT_TTY, false);
Wink Saville04e71b32009-04-02 11:00:54 -0700324 }
325 }
John Spurlock96fe98d2014-08-27 09:36:02 -0400326
327 private void updateCast() {
328 boolean isCasting = false;
329 for (CastDevice device : mCast.getCastDevices()) {
330 if (device.state == CastDevice.STATE_CONNECTING
331 || device.state == CastDevice.STATE_CONNECTED) {
332 isCasting = true;
333 break;
334 }
335 }
336 if (DEBUG) Log.v(TAG, "updateCast: isCasting: " + isCasting);
Dan Sandler8fd25bf2015-10-20 16:01:27 -0700337 mHandler.removeCallbacks(mRemoveCastIconRunnable);
John Spurlock96fe98d2014-08-27 09:36:02 -0400338 if (isCasting) {
Jason Monk07473ce2016-01-05 14:59:19 -0500339 mIconController.setIcon(SLOT_CAST, R.drawable.stat_sys_cast,
John Spurlock96fe98d2014-08-27 09:36:02 -0400340 mContext.getString(R.string.accessibility_casting));
Jason Monk07473ce2016-01-05 14:59:19 -0500341 mIconController.setIconVisibility(SLOT_CAST, true);
Dan Sandler8fd25bf2015-10-20 16:01:27 -0700342 } else {
343 // don't turn off the screen-record icon for a few seconds, just to make sure the user
344 // has seen it
345 if (DEBUG) Log.v(TAG, "updateCast: hiding icon in 3 sec...");
346 mHandler.postDelayed(mRemoveCastIconRunnable, 3000);
John Spurlock96fe98d2014-08-27 09:36:02 -0400347 }
John Spurlock96fe98d2014-08-27 09:36:02 -0400348 }
349
Rubin Xu1205fb12015-11-04 17:45:03 +0000350 private void updateQuietState() {
351 mManagedProfileInQuietMode = false;
352 int currentUserId = ActivityManager.getCurrentUser();
353 for (UserInfo ui : mUserManager.getEnabledProfiles(currentUserId)) {
354 if (ui.isManagedProfile() && ui.isQuietModeEnabled()) {
355 mManagedProfileInQuietMode = true;
356 return;
357 }
358 }
359 }
360
Kenny Guy3094d4a2015-04-01 19:14:10 +0100361 private void profileChanged(int userId) {
Kenny Guy3094d4a2015-04-01 19:14:10 +0100362 UserInfo user = null;
363 if (userId == UserHandle.USER_CURRENT) {
364 try {
365 user = ActivityManagerNative.getDefault().getCurrentUser();
366 } catch (RemoteException e) {
367 // Ignore
368 }
369 } else {
Rubin Xu1205fb12015-11-04 17:45:03 +0000370 user = mUserManager.getUserInfo(userId);
Kenny Guy3094d4a2015-04-01 19:14:10 +0100371 }
372
373 mManagedProfileFocused = user != null && user.isManagedProfile();
374 if (DEBUG) Log.v(TAG, "profileChanged: mManagedProfileFocused: " + mManagedProfileFocused);
375 // Actually update the icon later when transition starts.
376 }
377
378 private void updateManagedProfile() {
379 if (DEBUG) Log.v(TAG, "updateManagedProfile: mManagedProfileFocused: "
380 + mManagedProfileFocused
381 + " mKeyguardVisible: " + mKeyguardVisible);
Rubin Xu1205fb12015-11-04 17:45:03 +0000382 final boolean showIcon;
383 if (mManagedProfileFocused && !mKeyguardVisible) {
384 showIcon = true;
Jason Monk07473ce2016-01-05 14:59:19 -0500385 mIconController.setIcon(SLOT_MANAGED_PROFILE,
386 R.drawable.stat_sys_managed_profile_status,
Rubin Xu1205fb12015-11-04 17:45:03 +0000387 mContext.getString(R.string.accessibility_managed_profile));
388 } else if (mManagedProfileInQuietMode) {
389 showIcon = true;
Jason Monk07473ce2016-01-05 14:59:19 -0500390 mIconController.setIcon(SLOT_MANAGED_PROFILE,
391 R.drawable.stat_sys_managed_profile_status_off,
Rubin Xu1205fb12015-11-04 17:45:03 +0000392 mContext.getString(R.string.accessibility_managed_profile));
393 } else {
394 showIcon = false;
395 }
Kenny Guy3094d4a2015-04-01 19:14:10 +0100396 if (mManagedProfileIconVisible != showIcon) {
Jason Monk07473ce2016-01-05 14:59:19 -0500397 mIconController.setIconVisibility(SLOT_MANAGED_PROFILE, showIcon);
Kenny Guy3094d4a2015-04-01 19:14:10 +0100398 mManagedProfileIconVisible = showIcon;
399 }
400 }
401
Fyodor Kupolov6005b3f2015-11-23 17:41:50 -0800402 private final SynchronousUserSwitchObserver mUserSwitchListener =
403 new SynchronousUserSwitchObserver() {
Kenny Guy3094d4a2015-04-01 19:14:10 +0100404 @Override
Fyodor Kupolov6005b3f2015-11-23 17:41:50 -0800405 public void onUserSwitching(int newUserId) throws RemoteException {
Adrian Roos88b11932015-07-22 14:59:48 -0700406 mUserInfoController.reloadUserInfo();
Kenny Guy3094d4a2015-04-01 19:14:10 +0100407 }
408
409 @Override
410 public void onUserSwitchComplete(int newUserId) throws RemoteException {
411 updateAlarm();
412 profileChanged(newUserId);
Rubin Xu1205fb12015-11-04 17:45:03 +0000413 updateQuietState();
414 updateManagedProfile();
Kenny Guy3094d4a2015-04-01 19:14:10 +0100415 }
416
417 @Override
418 public void onForegroundProfileSwitch(int newProfileId) {
419 profileChanged(newProfileId);
420 }
421 };
422
Jason Monk952d5d82014-10-27 15:28:22 -0400423 private final HotspotController.Callback mHotspotCallback = new HotspotController.Callback() {
424 @Override
425 public void onHotspotChanged(boolean enabled) {
Jason Monk07473ce2016-01-05 14:59:19 -0500426 mIconController.setIconVisibility(SLOT_HOTSPOT, enabled);
Jason Monk952d5d82014-10-27 15:28:22 -0400427 }
428 };
429
John Spurlock96fe98d2014-08-27 09:36:02 -0400430 private final CastController.Callback mCastCallback = new CastController.Callback() {
431 @Override
432 public void onCastDevicesChanged() {
433 updateCast();
434 }
435 };
Kenny Guy3094d4a2015-04-01 19:14:10 +0100436
437 public void appTransitionStarting(long startTime, long duration) {
438 updateManagedProfile();
439 }
440
441 public void setKeyguardShowing(boolean visible) {
442 mKeyguardVisible = visible;
443 updateManagedProfile();
444 }
John Spurlock604a5ee2015-06-01 12:27:22 -0400445
446 public void setCurrentUserSetup(boolean userSetup) {
447 if (mCurrentUserSetup == userSetup) return;
448 mCurrentUserSetup = userSetup;
449 updateAlarm();
Rubin Xu1205fb12015-11-04 17:45:03 +0000450 updateQuietState();
John Spurlock604a5ee2015-06-01 12:27:22 -0400451 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800452}