blob: b89cd228819c7b5045c5772f9cb44131e6b84c5b [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;
Joe Onorato798ac4c2010-05-27 16:39:00 -040023import android.app.StatusBarManager;
Fyodor Kupolov6005b3f2015-11-23 17:41:50 -080024import android.app.SynchronousUserSwitchObserver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.content.BroadcastReceiver;
26import android.content.Context;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.content.Intent;
28import android.content.IntentFilter;
Kenny Guy3094d4a2015-04-01 19:14:10 +010029import android.content.pm.UserInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.media.AudioManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.os.Handler;
Kenny Guy3094d4a2015-04-01 19:14:10 +010032import 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;
Rubin Xu1205fb12015-11-04 17:45:03 +000075 private final UserManager mUserManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076
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 Savillea639b312012-07-10 12:37:54 -070079 IccCardConstants.State mSimState = IccCardConstants.State.READY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080
John Spurlocka37e9c82014-07-08 09:40:31 -040081 private boolean mZenVisible;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 private boolean mVolumeVisible;
John Spurlock604a5ee2015-06-01 12:27:22 -040083 private boolean mCurrentUserSetup;
Wink Saville04e71b32009-04-02 11:00:54 -070084
John Spurlockae641c92014-06-30 18:11:40 -040085 private int mZen;
John Spurlockba2c6a02014-05-19 09:44:06 -040086
Kenny Guy3094d4a2015-04-01 19:14:10 +010087 private boolean mManagedProfileFocused = false;
Rubin Xu1205fb12015-11-04 17:45:03 +000088 private boolean mManagedProfileIconVisible = false;
89 private boolean mManagedProfileInQuietMode = false;
Kenny Guy3094d4a2015-04-01 19:14:10 +010090
91 private boolean mKeyguardVisible = true;
Jason Monk70364362015-08-06 16:32:18 -040092 private BluetoothController mBluetooth;
Wink Savillee9b06d72009-05-18 21:47:50 -070093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
95 @Override
96 public void onReceive(Context context, Intent intent) {
97 String action = intent.getAction();
Adrian Roosc42a1e12014-07-07 23:35:53 +020098 if (action.equals(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED)) {
99 updateAlarm();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 }
John Spurlockbcc10872014-11-28 15:29:21 -0500101 else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION) ||
102 action.equals(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION)) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400103 updateVolumeZen();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104 }
105 else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
106 updateSimState(intent);
107 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700108 else if (action.equals(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED)) {
Wink Saville04e71b32009-04-02 11:00:54 -0700109 updateTTY(intent);
110 }
Rubin Xu1205fb12015-11-04 17:45:03 +0000111 else if (action.equals(Intent.ACTION_MANAGED_PROFILE_AVAILABILITY_CHANGED)) {
112 updateQuietState();
113 updateManagedProfile();
114 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 }
116 };
117
Dan Sandler8fd25bf2015-10-20 16:01:27 -0700118 private Runnable mRemoveCastIconRunnable = new Runnable() {
119 @Override
120 public void run() {
121 if (DEBUG) Log.v(TAG, "updateCast: hiding icon NOW");
122 mService.setIconVisibility(SLOT_CAST, false);
123 }
124 };
125
Adrian Roos88b11932015-07-22 14:59:48 -0700126 public PhoneStatusBarPolicy(Context context, CastController cast, HotspotController hotspot,
Jason Monk70364362015-08-06 16:32:18 -0400127 UserInfoController userInfoController, BluetoothController bluetooth) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128 mContext = context;
John Spurlock96fe98d2014-08-27 09:36:02 -0400129 mCast = cast;
Jason Monk952d5d82014-10-27 15:28:22 -0400130 mHotspot = hotspot;
Jason Monk70364362015-08-06 16:32:18 -0400131 mBluetooth = bluetooth;
132 mBluetooth.addStateChangedCallback(this);
John Spurlock15782262015-05-29 15:35:53 -0400133 mService = (StatusBarManager) context.getSystemService(Context.STATUS_BAR_SERVICE);
134 mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Adrian Roos88b11932015-07-22 14:59:48 -0700135 mUserInfoController = userInfoController;
Rubin Xu1205fb12015-11-04 17:45:03 +0000136 mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400138 // listen for broadcasts
139 IntentFilter filter = new IntentFilter();
Adrian Roosc42a1e12014-07-07 23:35:53 +0200140 filter.addAction(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED);
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400141 filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
John Spurlockbcc10872014-11-28 15:29:21 -0500142 filter.addAction(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION);
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400143 filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700144 filter.addAction(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED);
Rubin Xu1205fb12015-11-04 17:45:03 +0000145 filter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABILITY_CHANGED);
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400146 mContext.registerReceiver(mIntentReceiver, filter, null, mHandler);
147
Kenny Guy3094d4a2015-04-01 19:14:10 +0100148 // listen for user / profile change.
149 try {
150 ActivityManagerNative.getDefault().registerUserSwitchObserver(mUserSwitchListener);
151 } catch (RemoteException e) {
152 // Ignore
153 }
154
Wink Saville04e71b32009-04-02 11:00:54 -0700155 // TTY status
John Spurlocka37e9c82014-07-08 09:40:31 -0400156 mService.setIcon(SLOT_TTY, R.drawable.stat_sys_tty_mode, 0, null);
157 mService.setIconVisibility(SLOT_TTY, false);
Wink Saville04e71b32009-04-02 11:00:54 -0700158
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159 // bluetooth status
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700160 updateBluetooth();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 // Alarm clock
John Spurlocka37e9c82014-07-08 09:40:31 -0400163 mService.setIcon(SLOT_ALARM_CLOCK, R.drawable.stat_sys_alarm, 0, null);
164 mService.setIconVisibility(SLOT_ALARM_CLOCK, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165
John Spurlocka37e9c82014-07-08 09:40:31 -0400166 // zen
167 mService.setIcon(SLOT_ZEN, R.drawable.stat_sys_zen_important, 0, null);
168 mService.setIconVisibility(SLOT_ZEN, false);
169
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 // volume
John Spurlockad494bc2014-07-19 15:56:19 -0400171 mService.setIcon(SLOT_VOLUME, R.drawable.stat_sys_ringer_vibrate, 0, null);
John Spurlocka37e9c82014-07-08 09:40:31 -0400172 mService.setIconVisibility(SLOT_VOLUME, false);
173 updateVolumeZen();
John Spurlock96fe98d2014-08-27 09:36:02 -0400174
175 // cast
176 mService.setIcon(SLOT_CAST, R.drawable.stat_sys_cast, 0, null);
177 mService.setIconVisibility(SLOT_CAST, false);
178 mCast.addCallback(mCastCallback);
Jason Monk952d5d82014-10-27 15:28:22 -0400179
180 // hotspot
Jason Monk08187a42015-06-09 14:33:51 -0400181 mService.setIcon(SLOT_HOTSPOT, R.drawable.stat_sys_hotspot, 0,
182 mContext.getString(R.string.accessibility_status_bar_hotspot));
Jason Monk952d5d82014-10-27 15:28:22 -0400183 mService.setIconVisibility(SLOT_HOTSPOT, mHotspot.isHotspotEnabled());
184 mHotspot.addCallback(mHotspotCallback);
Kenny Guy3094d4a2015-04-01 19:14:10 +0100185
186 // managed profile
Adrian Roos1b5eb972015-06-11 18:22:52 -0700187 mService.setIcon(SLOT_MANAGED_PROFILE, R.drawable.stat_sys_managed_profile_status, 0,
188 mContext.getString(R.string.accessibility_managed_profile));
Rubin Xu1205fb12015-11-04 17:45:03 +0000189 mService.setIconVisibility(SLOT_MANAGED_PROFILE, mManagedProfileIconVisible);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190 }
191
John Spurlockae641c92014-06-30 18:11:40 -0400192 public void setZenMode(int zen) {
John Spurlockba2c6a02014-05-19 09:44:06 -0400193 mZen = zen;
John Spurlocka37e9c82014-07-08 09:40:31 -0400194 updateVolumeZen();
John Spurlockba2c6a02014-05-19 09:44:06 -0400195 }
196
Adrian Roosc42a1e12014-07-07 23:35:53 +0200197 private void updateAlarm() {
John Spurlock604a5ee2015-06-01 12:27:22 -0400198 final AlarmClockInfo alarm = mAlarmManager.getNextAlarmClock(UserHandle.USER_CURRENT);
199 final boolean hasAlarm = alarm != null && alarm.getTriggerTime() > 0;
John Spurlock15782262015-05-29 15:35:53 -0400200 final boolean zenNone = mZen == Global.ZEN_MODE_NO_INTERRUPTIONS;
John Spurlock15782262015-05-29 15:35:53 -0400201 mService.setIcon(SLOT_ALARM_CLOCK, zenNone ? R.drawable.stat_sys_alarm_dim
202 : R.drawable.stat_sys_alarm, 0, null);
John Spurlock604a5ee2015-06-01 12:27:22 -0400203 mService.setIconVisibility(SLOT_ALARM_CLOCK, mCurrentUserSetup && hasAlarm);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800204 }
205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800206 private final void updateSimState(Intent intent) {
Wink Savillea639b312012-07-10 12:37:54 -0700207 String stateExtra = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
208 if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) {
209 mSimState = IccCardConstants.State.ABSENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800210 }
Rakesh Pallerlaf099a5f2013-02-06 11:44:23 +0530211 else if (IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR.equals(stateExtra)) {
212 mSimState = IccCardConstants.State.CARD_IO_ERROR;
213 }
Wink Savillea639b312012-07-10 12:37:54 -0700214 else if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(stateExtra)) {
215 mSimState = IccCardConstants.State.READY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 }
Wink Savillea639b312012-07-10 12:37:54 -0700217 else if (IccCardConstants.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) {
218 final String lockedReason =
219 intent.getStringExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON);
220 if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) {
221 mSimState = IccCardConstants.State.PIN_REQUIRED;
johnwang347c5a22009-08-24 22:11:11 -0700222 }
Wink Savillea639b312012-07-10 12:37:54 -0700223 else if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) {
224 mSimState = IccCardConstants.State.PUK_REQUIRED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225 }
226 else {
Wink Savillea639b312012-07-10 12:37:54 -0700227 mSimState = IccCardConstants.State.NETWORK_LOCKED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800228 }
229 } else {
Wink Savillea639b312012-07-10 12:37:54 -0700230 mSimState = IccCardConstants.State.UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232 }
233
John Spurlockbcc10872014-11-28 15:29:21 -0500234 private final void updateVolumeZen() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800235 AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
John Spurlocka37e9c82014-07-08 09:40:31 -0400236
237 boolean zenVisible = false;
238 int zenIconId = 0;
239 String zenDescription = null;
240
241 boolean volumeVisible = false;
242 int volumeIconId = 0;
243 String volumeDescription = null;
244
John Spurlockf88d8082015-03-25 18:09:51 -0400245 if (DndTile.isVisible(mContext) || DndTile.isCombinedIcon(mContext)) {
John Spurlock3c4076a2015-02-24 12:12:25 -0500246 zenVisible = mZen != Global.ZEN_MODE_OFF;
John Spurlock4ec8b602015-05-11 17:46:28 -0400247 zenIconId = mZen == Global.ZEN_MODE_NO_INTERRUPTIONS
248 ? R.drawable.stat_sys_dnd_total_silence : R.drawable.stat_sys_dnd;
John Spurlock3c4076a2015-02-24 12:12:25 -0500249 zenDescription = mContext.getString(R.string.quick_settings_dnd_label);
250 } else if (mZen == Global.ZEN_MODE_NO_INTERRUPTIONS) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400251 zenVisible = true;
252 zenIconId = R.drawable.stat_sys_zen_none;
John Spurlockd9c75db2015-04-28 11:19:13 -0400253 zenDescription = mContext.getString(R.string.interruption_level_none);
John Spurlockae641c92014-06-30 18:11:40 -0400254 } else if (mZen == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400255 zenVisible = true;
256 zenIconId = R.drawable.stat_sys_zen_important;
John Spurlockd9c75db2015-04-28 11:19:13 -0400257 zenDescription = mContext.getString(R.string.interruption_level_priority);
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700258 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259
John Spurlockd9c75db2015-04-28 11:19:13 -0400260 if (DndTile.isVisible(mContext) && !DndTile.isCombinedIcon(mContext)
John Spurlocka48d7792015-03-03 17:35:57 -0500261 && audioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_SILENT) {
262 volumeVisible = true;
263 volumeIconId = R.drawable.stat_sys_ringer_silent;
264 volumeDescription = mContext.getString(R.string.accessibility_ringer_silent);
John Spurlock4f1163c2015-04-02 17:41:21 -0400265 } else if (mZen != Global.ZEN_MODE_NO_INTERRUPTIONS && mZen != Global.ZEN_MODE_ALARMS &&
John Spurlock661f2cf2014-11-17 10:29:10 -0500266 audioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_VIBRATE) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400267 volumeVisible = true;
268 volumeIconId = R.drawable.stat_sys_ringer_vibrate;
269 volumeDescription = mContext.getString(R.string.accessibility_ringer_vibrate);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270 }
John Spurlocka37e9c82014-07-08 09:40:31 -0400271
272 if (zenVisible) {
273 mService.setIcon(SLOT_ZEN, zenIconId, 0, zenDescription);
274 }
275 if (zenVisible != mZenVisible) {
276 mService.setIconVisibility(SLOT_ZEN, zenVisible);
277 mZenVisible = zenVisible;
278 }
279
280 if (volumeVisible) {
281 mService.setIcon(SLOT_VOLUME, volumeIconId, 0, volumeDescription);
282 }
283 if (volumeVisible != mVolumeVisible) {
284 mService.setIconVisibility(SLOT_VOLUME, volumeVisible);
285 mVolumeVisible = volumeVisible;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 }
John Spurlock15782262015-05-29 15:35:53 -0400287 updateAlarm();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800288 }
289
Jason Monk70364362015-08-06 16:32:18 -0400290 @Override
291 public void onBluetoothDevicesChanged() {
292 updateBluetooth();
293 }
294
295 @Override
296 public void onBluetoothStateChange(boolean enabled) {
297 updateBluetooth();
298 }
299
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700300 private final void updateBluetooth() {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400301 int iconId = R.drawable.stat_sys_data_bluetooth;
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700302 String contentDescription =
Jason Monk1aa32822015-07-14 16:10:32 -0400303 mContext.getString(R.string.accessibility_quick_settings_bluetooth_on);
Jason Monk70364362015-08-06 16:32:18 -0400304 boolean bluetoothEnabled = false;
305 if (mBluetooth != null) {
306 bluetoothEnabled = mBluetooth.isBluetoothEnabled();
307 if (mBluetooth.isBluetoothConnected()) {
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -0700308 iconId = R.drawable.stat_sys_data_bluetooth_connected;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700309 contentDescription = mContext.getString(R.string.accessibility_bluetooth_connected);
Jaikumar Ganesh084c6652009-12-07 10:58:18 -0800310 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800311 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700312
John Spurlocka37e9c82014-07-08 09:40:31 -0400313 mService.setIcon(SLOT_BLUETOOTH, iconId, 0, contentDescription);
Jason Monk70364362015-08-06 16:32:18 -0400314 mService.setIconVisibility(SLOT_BLUETOOTH, bluetoothEnabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315 }
316
Wink Savillee9b06d72009-05-18 21:47:50 -0700317 private final void updateTTY(Intent intent) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700318 int currentTtyMode = intent.getIntExtra(TelecomManager.EXTRA_CURRENT_TTY_MODE,
319 TelecomManager.TTY_MODE_OFF);
320 boolean enabled = currentTtyMode != TelecomManager.TTY_MODE_OFF;
Wink Saville04e71b32009-04-02 11:00:54 -0700321
John Spurlocka37e9c82014-07-08 09:40:31 -0400322 if (DEBUG) Log.v(TAG, "updateTTY: enabled: " + enabled);
Wink Saville04e71b32009-04-02 11:00:54 -0700323
324 if (enabled) {
325 // TTY is on
John Spurlocka37e9c82014-07-08 09:40:31 -0400326 if (DEBUG) Log.v(TAG, "updateTTY: set TTY on");
327 mService.setIcon(SLOT_TTY, R.drawable.stat_sys_tty_mode, 0,
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700328 mContext.getString(R.string.accessibility_tty_enabled));
John Spurlocka37e9c82014-07-08 09:40:31 -0400329 mService.setIconVisibility(SLOT_TTY, true);
Wink Saville04e71b32009-04-02 11:00:54 -0700330 } else {
331 // TTY is off
John Spurlocka37e9c82014-07-08 09:40:31 -0400332 if (DEBUG) Log.v(TAG, "updateTTY: set TTY off");
333 mService.setIconVisibility(SLOT_TTY, false);
Wink Saville04e71b32009-04-02 11:00:54 -0700334 }
335 }
John Spurlock96fe98d2014-08-27 09:36:02 -0400336
337 private void updateCast() {
338 boolean isCasting = false;
339 for (CastDevice device : mCast.getCastDevices()) {
340 if (device.state == CastDevice.STATE_CONNECTING
341 || device.state == CastDevice.STATE_CONNECTED) {
342 isCasting = true;
343 break;
344 }
345 }
346 if (DEBUG) Log.v(TAG, "updateCast: isCasting: " + isCasting);
Dan Sandler8fd25bf2015-10-20 16:01:27 -0700347 mHandler.removeCallbacks(mRemoveCastIconRunnable);
John Spurlock96fe98d2014-08-27 09:36:02 -0400348 if (isCasting) {
349 mService.setIcon(SLOT_CAST, R.drawable.stat_sys_cast, 0,
350 mContext.getString(R.string.accessibility_casting));
Dan Sandler8fd25bf2015-10-20 16:01:27 -0700351 mService.setIconVisibility(SLOT_CAST, true);
352 } else {
353 // don't turn off the screen-record icon for a few seconds, just to make sure the user
354 // has seen it
355 if (DEBUG) Log.v(TAG, "updateCast: hiding icon in 3 sec...");
356 mHandler.postDelayed(mRemoveCastIconRunnable, 3000);
John Spurlock96fe98d2014-08-27 09:36:02 -0400357 }
John Spurlock96fe98d2014-08-27 09:36:02 -0400358 }
359
Rubin Xu1205fb12015-11-04 17:45:03 +0000360 private void updateQuietState() {
361 mManagedProfileInQuietMode = false;
362 int currentUserId = ActivityManager.getCurrentUser();
363 for (UserInfo ui : mUserManager.getEnabledProfiles(currentUserId)) {
364 if (ui.isManagedProfile() && ui.isQuietModeEnabled()) {
365 mManagedProfileInQuietMode = true;
366 return;
367 }
368 }
369 }
370
Kenny Guy3094d4a2015-04-01 19:14:10 +0100371 private void profileChanged(int userId) {
Kenny Guy3094d4a2015-04-01 19:14:10 +0100372 UserInfo user = null;
373 if (userId == UserHandle.USER_CURRENT) {
374 try {
375 user = ActivityManagerNative.getDefault().getCurrentUser();
376 } catch (RemoteException e) {
377 // Ignore
378 }
379 } else {
Rubin Xu1205fb12015-11-04 17:45:03 +0000380 user = mUserManager.getUserInfo(userId);
Kenny Guy3094d4a2015-04-01 19:14:10 +0100381 }
382
383 mManagedProfileFocused = user != null && user.isManagedProfile();
384 if (DEBUG) Log.v(TAG, "profileChanged: mManagedProfileFocused: " + mManagedProfileFocused);
385 // Actually update the icon later when transition starts.
386 }
387
388 private void updateManagedProfile() {
389 if (DEBUG) Log.v(TAG, "updateManagedProfile: mManagedProfileFocused: "
390 + mManagedProfileFocused
391 + " mKeyguardVisible: " + mKeyguardVisible);
Rubin Xu1205fb12015-11-04 17:45:03 +0000392 final boolean showIcon;
393 if (mManagedProfileFocused && !mKeyguardVisible) {
394 showIcon = true;
395 mService.setIcon(SLOT_MANAGED_PROFILE, R.drawable.stat_sys_managed_profile_status, 0,
396 mContext.getString(R.string.accessibility_managed_profile));
397 } else if (mManagedProfileInQuietMode) {
398 showIcon = true;
399 mService.setIcon(SLOT_MANAGED_PROFILE, R.drawable.stat_sys_managed_profile_status_off, 0,
400 mContext.getString(R.string.accessibility_managed_profile));
401 } else {
402 showIcon = false;
403 }
Kenny Guy3094d4a2015-04-01 19:14:10 +0100404 if (mManagedProfileIconVisible != showIcon) {
405 mService.setIconVisibility(SLOT_MANAGED_PROFILE, showIcon);
406 mManagedProfileIconVisible = showIcon;
407 }
408 }
409
Fyodor Kupolov6005b3f2015-11-23 17:41:50 -0800410 private final SynchronousUserSwitchObserver mUserSwitchListener =
411 new SynchronousUserSwitchObserver() {
Kenny Guy3094d4a2015-04-01 19:14:10 +0100412 @Override
Fyodor Kupolov6005b3f2015-11-23 17:41:50 -0800413 public void onUserSwitching(int newUserId) throws RemoteException {
Adrian Roos88b11932015-07-22 14:59:48 -0700414 mUserInfoController.reloadUserInfo();
Kenny Guy3094d4a2015-04-01 19:14:10 +0100415 }
416
417 @Override
418 public void onUserSwitchComplete(int newUserId) throws RemoteException {
419 updateAlarm();
420 profileChanged(newUserId);
Rubin Xu1205fb12015-11-04 17:45:03 +0000421 updateQuietState();
422 updateManagedProfile();
Kenny Guy3094d4a2015-04-01 19:14:10 +0100423 }
424
425 @Override
426 public void onForegroundProfileSwitch(int newProfileId) {
427 profileChanged(newProfileId);
428 }
429 };
430
Jason Monk952d5d82014-10-27 15:28:22 -0400431 private final HotspotController.Callback mHotspotCallback = new HotspotController.Callback() {
432 @Override
433 public void onHotspotChanged(boolean enabled) {
434 mService.setIconVisibility(SLOT_HOTSPOT, enabled);
435 }
436 };
437
John Spurlock96fe98d2014-08-27 09:36:02 -0400438 private final CastController.Callback mCastCallback = new CastController.Callback() {
439 @Override
440 public void onCastDevicesChanged() {
441 updateCast();
442 }
443 };
Kenny Guy3094d4a2015-04-01 19:14:10 +0100444
445 public void appTransitionStarting(long startTime, long duration) {
446 updateManagedProfile();
447 }
448
449 public void setKeyguardShowing(boolean visible) {
450 mKeyguardVisible = visible;
451 updateManagedProfile();
452 }
John Spurlock604a5ee2015-06-01 12:27:22 -0400453
454 public void setCurrentUserSetup(boolean userSetup) {
455 if (mCurrentUserSetup == userSetup) return;
456 mCurrentUserSetup = userSetup;
457 updateAlarm();
Rubin Xu1205fb12015-11-04 17:45:03 +0000458 updateQuietState();
John Spurlock604a5ee2015-06-01 12:27:22 -0400459 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800460}