blob: 5177f0e7a15d8920ccad3c11bcb0615ce9eff783 [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;
Kenny Guy3094d4a2015-04-01 19:14:10 +010023import android.app.IUserSwitchObserver;
Joe Onorato798ac4c2010-05-27 16:39:00 -040024import android.app.StatusBarManager;
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.IRemoteCallback;
33import android.os.RemoteException;
Adrian Roosc42a1e12014-07-07 23:35:53 +020034import android.os.UserHandle;
Kenny Guy3094d4a2015-04-01 19:14:10 +010035import android.os.UserManager;
John Spurlockae641c92014-06-30 18:11:40 -040036import android.provider.Settings.Global;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070037import android.telecom.TelecomManager;
John Spurlockcd686b52013-06-05 10:13:46 -040038import android.util.Log;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039
Wink Savillea639b312012-07-10 12:37:54 -070040import com.android.internal.telephony.IccCardConstants;
Wink Saville04e71b32009-04-02 11:00:54 -070041import com.android.internal.telephony.TelephonyIntents;
Joe Onorato798ac4c2010-05-27 16:39:00 -040042import com.android.systemui.R;
John Spurlock3c4076a2015-02-24 12:12:25 -050043import com.android.systemui.qs.tiles.DndTile;
Jason Monk70364362015-08-06 16:32:18 -040044import com.android.systemui.statusbar.policy.BluetoothController;
45import com.android.systemui.statusbar.policy.BluetoothController.Callback;
John Spurlock96fe98d2014-08-27 09:36:02 -040046import com.android.systemui.statusbar.policy.CastController;
47import com.android.systemui.statusbar.policy.CastController.CastDevice;
Jason Monk952d5d82014-10-27 15:28:22 -040048import com.android.systemui.statusbar.policy.HotspotController;
Adrian Roos88b11932015-07-22 14:59:48 -070049import com.android.systemui.statusbar.policy.UserInfoController;
Joe Onorato798ac4c2010-05-27 16:39:00 -040050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051/**
52 * This class contains all of the policy about which icons are installed in the status
Joe Onorato798ac4c2010-05-27 16:39:00 -040053 * bar at boot time. It goes through the normal API for icons, even though it probably
54 * strictly doesn't need to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055 */
Jason Monk70364362015-08-06 16:32:18 -040056public class PhoneStatusBarPolicy implements Callback {
Joe Onoratofd52b182010-11-10 18:00:52 -080057 private static final String TAG = "PhoneStatusBarPolicy";
John Spurlocka37e9c82014-07-08 09:40:31 -040058 private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Robert Greenwaltd7085fc2010-09-08 15:24:47 -070059
John Spurlock96fe98d2014-08-27 09:36:02 -040060 private static final String SLOT_CAST = "cast";
Jason Monk952d5d82014-10-27 15:28:22 -040061 private static final String SLOT_HOTSPOT = "hotspot";
John Spurlocka37e9c82014-07-08 09:40:31 -040062 private static final String SLOT_BLUETOOTH = "bluetooth";
63 private static final String SLOT_TTY = "tty";
64 private static final String SLOT_ZEN = "zen";
65 private static final String SLOT_VOLUME = "volume";
John Spurlocka37e9c82014-07-08 09:40:31 -040066 private static final String SLOT_ALARM_CLOCK = "alarm_clock";
Kenny Guy3094d4a2015-04-01 19:14:10 +010067 private static final String SLOT_MANAGED_PROFILE = "managed_profile";
John Spurlocka37e9c82014-07-08 09:40:31 -040068
Dianne Hackborn4840e142009-03-24 22:40:29 -070069 private final Context mContext;
Joe Onorato798ac4c2010-05-27 16:39:00 -040070 private final StatusBarManager mService;
Joe Onorato10523b4d2010-10-25 10:42:46 -070071 private final Handler mHandler = new Handler();
John Spurlock96fe98d2014-08-27 09:36:02 -040072 private final CastController mCast;
Jason Monk952d5d82014-10-27 15:28:22 -040073 private final HotspotController mHotspot;
John Spurlock15782262015-05-29 15:35:53 -040074 private final AlarmManager mAlarmManager;
Adrian Roos88b11932015-07-22 14:59:48 -070075 private final UserInfoController mUserInfoController;
Rubin Xu1205fb12015-11-04 17:45:03 +000076 private final UserManager mUserManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078 // Assume it's all good unless we hear otherwise. We don't always seem
79 // to get broadcasts that it *is* there.
Wink Savillea639b312012-07-10 12:37:54 -070080 IccCardConstants.State mSimState = IccCardConstants.State.READY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081
John Spurlocka37e9c82014-07-08 09:40:31 -040082 private boolean mZenVisible;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083 private boolean mVolumeVisible;
John Spurlock604a5ee2015-06-01 12:27:22 -040084 private boolean mCurrentUserSetup;
Wink Saville04e71b32009-04-02 11:00:54 -070085
John Spurlockae641c92014-06-30 18:11:40 -040086 private int mZen;
John Spurlockba2c6a02014-05-19 09:44:06 -040087
Kenny Guy3094d4a2015-04-01 19:14:10 +010088 private boolean mManagedProfileFocused = false;
Rubin Xu1205fb12015-11-04 17:45:03 +000089 private boolean mManagedProfileIconVisible = false;
90 private boolean mManagedProfileInQuietMode = false;
Kenny Guy3094d4a2015-04-01 19:14:10 +010091
92 private boolean mKeyguardVisible = true;
Jason Monk70364362015-08-06 16:32:18 -040093 private BluetoothController mBluetooth;
Wink Savillee9b06d72009-05-18 21:47:50 -070094
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095 private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
96 @Override
97 public void onReceive(Context context, Intent intent) {
98 String action = intent.getAction();
Adrian Roosc42a1e12014-07-07 23:35:53 +020099 if (action.equals(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED)) {
100 updateAlarm();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101 }
John Spurlockbcc10872014-11-28 15:29:21 -0500102 else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION) ||
103 action.equals(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION)) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400104 updateVolumeZen();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105 }
106 else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
107 updateSimState(intent);
108 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700109 else if (action.equals(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED)) {
Wink Saville04e71b32009-04-02 11:00:54 -0700110 updateTTY(intent);
111 }
Rubin Xu1205fb12015-11-04 17:45:03 +0000112 else if (action.equals(Intent.ACTION_MANAGED_PROFILE_AVAILABILITY_CHANGED)) {
113 updateQuietState();
114 updateManagedProfile();
115 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116 }
117 };
118
Dan Sandler8fd25bf2015-10-20 16:01:27 -0700119 private Runnable mRemoveCastIconRunnable = new Runnable() {
120 @Override
121 public void run() {
122 if (DEBUG) Log.v(TAG, "updateCast: hiding icon NOW");
123 mService.setIconVisibility(SLOT_CAST, false);
124 }
125 };
126
Adrian Roos88b11932015-07-22 14:59:48 -0700127 public PhoneStatusBarPolicy(Context context, CastController cast, HotspotController hotspot,
Jason Monk70364362015-08-06 16:32:18 -0400128 UserInfoController userInfoController, BluetoothController bluetooth) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129 mContext = context;
John Spurlock96fe98d2014-08-27 09:36:02 -0400130 mCast = cast;
Jason Monk952d5d82014-10-27 15:28:22 -0400131 mHotspot = hotspot;
Jason Monk70364362015-08-06 16:32:18 -0400132 mBluetooth = bluetooth;
133 mBluetooth.addStateChangedCallback(this);
John Spurlock15782262015-05-29 15:35:53 -0400134 mService = (StatusBarManager) context.getSystemService(Context.STATUS_BAR_SERVICE);
135 mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Adrian Roos88b11932015-07-22 14:59:48 -0700136 mUserInfoController = userInfoController;
Rubin Xu1205fb12015-11-04 17:45:03 +0000137 mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400139 // listen for broadcasts
140 IntentFilter filter = new IntentFilter();
Adrian Roosc42a1e12014-07-07 23:35:53 +0200141 filter.addAction(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED);
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400142 filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
John Spurlockbcc10872014-11-28 15:29:21 -0500143 filter.addAction(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION);
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400144 filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700145 filter.addAction(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED);
Rubin Xu1205fb12015-11-04 17:45:03 +0000146 filter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABILITY_CHANGED);
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400147 mContext.registerReceiver(mIntentReceiver, filter, null, mHandler);
148
Kenny Guy3094d4a2015-04-01 19:14:10 +0100149 // listen for user / profile change.
150 try {
151 ActivityManagerNative.getDefault().registerUserSwitchObserver(mUserSwitchListener);
152 } catch (RemoteException e) {
153 // Ignore
154 }
155
Wink Saville04e71b32009-04-02 11:00:54 -0700156 // TTY status
John Spurlocka37e9c82014-07-08 09:40:31 -0400157 mService.setIcon(SLOT_TTY, R.drawable.stat_sys_tty_mode, 0, null);
158 mService.setIconVisibility(SLOT_TTY, false);
Wink Saville04e71b32009-04-02 11:00:54 -0700159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160 // bluetooth status
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700161 updateBluetooth();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 // Alarm clock
John Spurlocka37e9c82014-07-08 09:40:31 -0400164 mService.setIcon(SLOT_ALARM_CLOCK, R.drawable.stat_sys_alarm, 0, null);
165 mService.setIconVisibility(SLOT_ALARM_CLOCK, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166
John Spurlocka37e9c82014-07-08 09:40:31 -0400167 // zen
168 mService.setIcon(SLOT_ZEN, R.drawable.stat_sys_zen_important, 0, null);
169 mService.setIconVisibility(SLOT_ZEN, false);
170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171 // volume
John Spurlockad494bc2014-07-19 15:56:19 -0400172 mService.setIcon(SLOT_VOLUME, R.drawable.stat_sys_ringer_vibrate, 0, null);
John Spurlocka37e9c82014-07-08 09:40:31 -0400173 mService.setIconVisibility(SLOT_VOLUME, false);
174 updateVolumeZen();
John Spurlock96fe98d2014-08-27 09:36:02 -0400175
176 // cast
177 mService.setIcon(SLOT_CAST, R.drawable.stat_sys_cast, 0, null);
178 mService.setIconVisibility(SLOT_CAST, false);
179 mCast.addCallback(mCastCallback);
Jason Monk952d5d82014-10-27 15:28:22 -0400180
181 // hotspot
Jason Monk08187a42015-06-09 14:33:51 -0400182 mService.setIcon(SLOT_HOTSPOT, R.drawable.stat_sys_hotspot, 0,
183 mContext.getString(R.string.accessibility_status_bar_hotspot));
Jason Monk952d5d82014-10-27 15:28:22 -0400184 mService.setIconVisibility(SLOT_HOTSPOT, mHotspot.isHotspotEnabled());
185 mHotspot.addCallback(mHotspotCallback);
Kenny Guy3094d4a2015-04-01 19:14:10 +0100186
187 // managed profile
Adrian Roos1b5eb972015-06-11 18:22:52 -0700188 mService.setIcon(SLOT_MANAGED_PROFILE, R.drawable.stat_sys_managed_profile_status, 0,
189 mContext.getString(R.string.accessibility_managed_profile));
Rubin Xu1205fb12015-11-04 17:45:03 +0000190 mService.setIconVisibility(SLOT_MANAGED_PROFILE, mManagedProfileIconVisible);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 }
192
John Spurlockae641c92014-06-30 18:11:40 -0400193 public void setZenMode(int zen) {
John Spurlockba2c6a02014-05-19 09:44:06 -0400194 mZen = zen;
John Spurlocka37e9c82014-07-08 09:40:31 -0400195 updateVolumeZen();
John Spurlockba2c6a02014-05-19 09:44:06 -0400196 }
197
Adrian Roosc42a1e12014-07-07 23:35:53 +0200198 private void updateAlarm() {
John Spurlock604a5ee2015-06-01 12:27:22 -0400199 final AlarmClockInfo alarm = mAlarmManager.getNextAlarmClock(UserHandle.USER_CURRENT);
200 final boolean hasAlarm = alarm != null && alarm.getTriggerTime() > 0;
John Spurlock15782262015-05-29 15:35:53 -0400201 final boolean zenNone = mZen == Global.ZEN_MODE_NO_INTERRUPTIONS;
John Spurlock15782262015-05-29 15:35:53 -0400202 mService.setIcon(SLOT_ALARM_CLOCK, zenNone ? R.drawable.stat_sys_alarm_dim
203 : R.drawable.stat_sys_alarm, 0, null);
John Spurlock604a5ee2015-06-01 12:27:22 -0400204 mService.setIconVisibility(SLOT_ALARM_CLOCK, mCurrentUserSetup && hasAlarm);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205 }
206
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207 private final void updateSimState(Intent intent) {
Wink Savillea639b312012-07-10 12:37:54 -0700208 String stateExtra = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
209 if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) {
210 mSimState = IccCardConstants.State.ABSENT;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800211 }
Rakesh Pallerlaf099a5f2013-02-06 11:44:23 +0530212 else if (IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR.equals(stateExtra)) {
213 mSimState = IccCardConstants.State.CARD_IO_ERROR;
214 }
Wink Savillea639b312012-07-10 12:37:54 -0700215 else if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(stateExtra)) {
216 mSimState = IccCardConstants.State.READY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800217 }
Wink Savillea639b312012-07-10 12:37:54 -0700218 else if (IccCardConstants.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) {
219 final String lockedReason =
220 intent.getStringExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON);
221 if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) {
222 mSimState = IccCardConstants.State.PIN_REQUIRED;
johnwang347c5a22009-08-24 22:11:11 -0700223 }
Wink Savillea639b312012-07-10 12:37:54 -0700224 else if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) {
225 mSimState = IccCardConstants.State.PUK_REQUIRED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226 }
227 else {
Wink Savillea639b312012-07-10 12:37:54 -0700228 mSimState = IccCardConstants.State.NETWORK_LOCKED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229 }
230 } else {
Wink Savillea639b312012-07-10 12:37:54 -0700231 mSimState = IccCardConstants.State.UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233 }
234
John Spurlockbcc10872014-11-28 15:29:21 -0500235 private final void updateVolumeZen() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236 AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
John Spurlocka37e9c82014-07-08 09:40:31 -0400237
238 boolean zenVisible = false;
239 int zenIconId = 0;
240 String zenDescription = null;
241
242 boolean volumeVisible = false;
243 int volumeIconId = 0;
244 String volumeDescription = null;
245
John Spurlockf88d8082015-03-25 18:09:51 -0400246 if (DndTile.isVisible(mContext) || DndTile.isCombinedIcon(mContext)) {
John Spurlock3c4076a2015-02-24 12:12:25 -0500247 zenVisible = mZen != Global.ZEN_MODE_OFF;
John Spurlock4ec8b602015-05-11 17:46:28 -0400248 zenIconId = mZen == Global.ZEN_MODE_NO_INTERRUPTIONS
249 ? R.drawable.stat_sys_dnd_total_silence : R.drawable.stat_sys_dnd;
John Spurlock3c4076a2015-02-24 12:12:25 -0500250 zenDescription = mContext.getString(R.string.quick_settings_dnd_label);
251 } else if (mZen == Global.ZEN_MODE_NO_INTERRUPTIONS) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400252 zenVisible = true;
253 zenIconId = R.drawable.stat_sys_zen_none;
John Spurlockd9c75db2015-04-28 11:19:13 -0400254 zenDescription = mContext.getString(R.string.interruption_level_none);
John Spurlockae641c92014-06-30 18:11:40 -0400255 } else if (mZen == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400256 zenVisible = true;
257 zenIconId = R.drawable.stat_sys_zen_important;
John Spurlockd9c75db2015-04-28 11:19:13 -0400258 zenDescription = mContext.getString(R.string.interruption_level_priority);
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700259 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800260
John Spurlockd9c75db2015-04-28 11:19:13 -0400261 if (DndTile.isVisible(mContext) && !DndTile.isCombinedIcon(mContext)
John Spurlocka48d7792015-03-03 17:35:57 -0500262 && audioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_SILENT) {
263 volumeVisible = true;
264 volumeIconId = R.drawable.stat_sys_ringer_silent;
265 volumeDescription = mContext.getString(R.string.accessibility_ringer_silent);
John Spurlock4f1163c2015-04-02 17:41:21 -0400266 } else if (mZen != Global.ZEN_MODE_NO_INTERRUPTIONS && mZen != Global.ZEN_MODE_ALARMS &&
John Spurlock661f2cf2014-11-17 10:29:10 -0500267 audioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_VIBRATE) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400268 volumeVisible = true;
269 volumeIconId = R.drawable.stat_sys_ringer_vibrate;
270 volumeDescription = mContext.getString(R.string.accessibility_ringer_vibrate);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271 }
John Spurlocka37e9c82014-07-08 09:40:31 -0400272
273 if (zenVisible) {
274 mService.setIcon(SLOT_ZEN, zenIconId, 0, zenDescription);
275 }
276 if (zenVisible != mZenVisible) {
277 mService.setIconVisibility(SLOT_ZEN, zenVisible);
278 mZenVisible = zenVisible;
279 }
280
281 if (volumeVisible) {
282 mService.setIcon(SLOT_VOLUME, volumeIconId, 0, volumeDescription);
283 }
284 if (volumeVisible != mVolumeVisible) {
285 mService.setIconVisibility(SLOT_VOLUME, volumeVisible);
286 mVolumeVisible = volumeVisible;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800287 }
John Spurlock15782262015-05-29 15:35:53 -0400288 updateAlarm();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800289 }
290
Jason Monk70364362015-08-06 16:32:18 -0400291 @Override
292 public void onBluetoothDevicesChanged() {
293 updateBluetooth();
294 }
295
296 @Override
297 public void onBluetoothStateChange(boolean enabled) {
298 updateBluetooth();
299 }
300
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700301 private final void updateBluetooth() {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400302 int iconId = R.drawable.stat_sys_data_bluetooth;
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700303 String contentDescription =
Jason Monk1aa32822015-07-14 16:10:32 -0400304 mContext.getString(R.string.accessibility_quick_settings_bluetooth_on);
Jason Monk70364362015-08-06 16:32:18 -0400305 boolean bluetoothEnabled = false;
306 if (mBluetooth != null) {
307 bluetoothEnabled = mBluetooth.isBluetoothEnabled();
308 if (mBluetooth.isBluetoothConnected()) {
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -0700309 iconId = R.drawable.stat_sys_data_bluetooth_connected;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700310 contentDescription = mContext.getString(R.string.accessibility_bluetooth_connected);
Jaikumar Ganesh084c6652009-12-07 10:58:18 -0800311 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800312 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700313
John Spurlocka37e9c82014-07-08 09:40:31 -0400314 mService.setIcon(SLOT_BLUETOOTH, iconId, 0, contentDescription);
Jason Monk70364362015-08-06 16:32:18 -0400315 mService.setIconVisibility(SLOT_BLUETOOTH, bluetoothEnabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316 }
317
Wink Savillee9b06d72009-05-18 21:47:50 -0700318 private final void updateTTY(Intent intent) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700319 int currentTtyMode = intent.getIntExtra(TelecomManager.EXTRA_CURRENT_TTY_MODE,
320 TelecomManager.TTY_MODE_OFF);
321 boolean enabled = currentTtyMode != TelecomManager.TTY_MODE_OFF;
Wink Saville04e71b32009-04-02 11:00:54 -0700322
John Spurlocka37e9c82014-07-08 09:40:31 -0400323 if (DEBUG) Log.v(TAG, "updateTTY: enabled: " + enabled);
Wink Saville04e71b32009-04-02 11:00:54 -0700324
325 if (enabled) {
326 // TTY is on
John Spurlocka37e9c82014-07-08 09:40:31 -0400327 if (DEBUG) Log.v(TAG, "updateTTY: set TTY on");
328 mService.setIcon(SLOT_TTY, R.drawable.stat_sys_tty_mode, 0,
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700329 mContext.getString(R.string.accessibility_tty_enabled));
John Spurlocka37e9c82014-07-08 09:40:31 -0400330 mService.setIconVisibility(SLOT_TTY, true);
Wink Saville04e71b32009-04-02 11:00:54 -0700331 } else {
332 // TTY is off
John Spurlocka37e9c82014-07-08 09:40:31 -0400333 if (DEBUG) Log.v(TAG, "updateTTY: set TTY off");
334 mService.setIconVisibility(SLOT_TTY, false);
Wink Saville04e71b32009-04-02 11:00:54 -0700335 }
336 }
John Spurlock96fe98d2014-08-27 09:36:02 -0400337
338 private void updateCast() {
339 boolean isCasting = false;
340 for (CastDevice device : mCast.getCastDevices()) {
341 if (device.state == CastDevice.STATE_CONNECTING
342 || device.state == CastDevice.STATE_CONNECTED) {
343 isCasting = true;
344 break;
345 }
346 }
347 if (DEBUG) Log.v(TAG, "updateCast: isCasting: " + isCasting);
Dan Sandler8fd25bf2015-10-20 16:01:27 -0700348 mHandler.removeCallbacks(mRemoveCastIconRunnable);
John Spurlock96fe98d2014-08-27 09:36:02 -0400349 if (isCasting) {
350 mService.setIcon(SLOT_CAST, R.drawable.stat_sys_cast, 0,
351 mContext.getString(R.string.accessibility_casting));
Dan Sandler8fd25bf2015-10-20 16:01:27 -0700352 mService.setIconVisibility(SLOT_CAST, true);
353 } else {
354 // don't turn off the screen-record icon for a few seconds, just to make sure the user
355 // has seen it
356 if (DEBUG) Log.v(TAG, "updateCast: hiding icon in 3 sec...");
357 mHandler.postDelayed(mRemoveCastIconRunnable, 3000);
John Spurlock96fe98d2014-08-27 09:36:02 -0400358 }
John Spurlock96fe98d2014-08-27 09:36:02 -0400359 }
360
Rubin Xu1205fb12015-11-04 17:45:03 +0000361 private void updateQuietState() {
362 mManagedProfileInQuietMode = false;
363 int currentUserId = ActivityManager.getCurrentUser();
364 for (UserInfo ui : mUserManager.getEnabledProfiles(currentUserId)) {
365 if (ui.isManagedProfile() && ui.isQuietModeEnabled()) {
366 mManagedProfileInQuietMode = true;
367 return;
368 }
369 }
370 }
371
Kenny Guy3094d4a2015-04-01 19:14:10 +0100372 private void profileChanged(int userId) {
Kenny Guy3094d4a2015-04-01 19:14:10 +0100373 UserInfo user = null;
374 if (userId == UserHandle.USER_CURRENT) {
375 try {
376 user = ActivityManagerNative.getDefault().getCurrentUser();
377 } catch (RemoteException e) {
378 // Ignore
379 }
380 } else {
Rubin Xu1205fb12015-11-04 17:45:03 +0000381 user = mUserManager.getUserInfo(userId);
Kenny Guy3094d4a2015-04-01 19:14:10 +0100382 }
383
384 mManagedProfileFocused = user != null && user.isManagedProfile();
385 if (DEBUG) Log.v(TAG, "profileChanged: mManagedProfileFocused: " + mManagedProfileFocused);
386 // Actually update the icon later when transition starts.
387 }
388
389 private void updateManagedProfile() {
390 if (DEBUG) Log.v(TAG, "updateManagedProfile: mManagedProfileFocused: "
391 + mManagedProfileFocused
392 + " mKeyguardVisible: " + mKeyguardVisible);
Rubin Xu1205fb12015-11-04 17:45:03 +0000393 final boolean showIcon;
394 if (mManagedProfileFocused && !mKeyguardVisible) {
395 showIcon = true;
396 mService.setIcon(SLOT_MANAGED_PROFILE, R.drawable.stat_sys_managed_profile_status, 0,
397 mContext.getString(R.string.accessibility_managed_profile));
398 } else if (mManagedProfileInQuietMode) {
399 showIcon = true;
400 mService.setIcon(SLOT_MANAGED_PROFILE, R.drawable.stat_sys_managed_profile_status_off, 0,
401 mContext.getString(R.string.accessibility_managed_profile));
402 } else {
403 showIcon = false;
404 }
Kenny Guy3094d4a2015-04-01 19:14:10 +0100405 if (mManagedProfileIconVisible != showIcon) {
406 mService.setIconVisibility(SLOT_MANAGED_PROFILE, showIcon);
407 mManagedProfileIconVisible = showIcon;
408 }
409 }
410
411 private final IUserSwitchObserver.Stub mUserSwitchListener =
412 new IUserSwitchObserver.Stub() {
413 @Override
414 public void onUserSwitching(int newUserId, IRemoteCallback reply) {
Adrian Roos88b11932015-07-22 14:59:48 -0700415 mUserInfoController.reloadUserInfo();
Amith Yamasanica0ac5c2015-11-20 09:44:08 -0800416 if (reply != null) {
417 try {
418 reply.sendResult(null);
419 } catch (RemoteException e) {
420 }
421 }
Kenny Guy3094d4a2015-04-01 19:14:10 +0100422 }
423
424 @Override
425 public void onUserSwitchComplete(int newUserId) throws RemoteException {
426 updateAlarm();
427 profileChanged(newUserId);
Rubin Xu1205fb12015-11-04 17:45:03 +0000428 updateQuietState();
429 updateManagedProfile();
Kenny Guy3094d4a2015-04-01 19:14:10 +0100430 }
431
432 @Override
433 public void onForegroundProfileSwitch(int newProfileId) {
434 profileChanged(newProfileId);
435 }
436 };
437
Jason Monk952d5d82014-10-27 15:28:22 -0400438 private final HotspotController.Callback mHotspotCallback = new HotspotController.Callback() {
439 @Override
440 public void onHotspotChanged(boolean enabled) {
441 mService.setIconVisibility(SLOT_HOTSPOT, enabled);
442 }
443 };
444
John Spurlock96fe98d2014-08-27 09:36:02 -0400445 private final CastController.Callback mCastCallback = new CastController.Callback() {
446 @Override
447 public void onCastDevicesChanged() {
448 updateCast();
449 }
450 };
Kenny Guy3094d4a2015-04-01 19:14:10 +0100451
452 public void appTransitionStarting(long startTime, long duration) {
453 updateManagedProfile();
454 }
455
456 public void setKeyguardShowing(boolean visible) {
457 mKeyguardVisible = visible;
458 updateManagedProfile();
459 }
John Spurlock604a5ee2015-06-01 12:27:22 -0400460
461 public void setCurrentUserSetup(boolean userSetup) {
462 if (mCurrentUserSetup == userSetup) return;
463 mCurrentUserSetup = userSetup;
464 updateAlarm();
Rubin Xu1205fb12015-11-04 17:45:03 +0000465 updateQuietState();
John Spurlock604a5ee2015-06-01 12:27:22 -0400466 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800467}