blob: 0ac2e7c4b8cd9ba7aa48707fbbe39604f7d9d860 [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;
Winsonc0d70582016-01-29 10:24:39 -080037
Wink Savillea639b312012-07-10 12:37:54 -070038import com.android.internal.telephony.IccCardConstants;
Wink Saville04e71b32009-04-02 11:00:54 -070039import com.android.internal.telephony.TelephonyIntents;
Joe Onorato798ac4c2010-05-27 16:39:00 -040040import com.android.systemui.R;
John Spurlock3c4076a2015-02-24 12:12:25 -050041import com.android.systemui.qs.tiles.DndTile;
Jason Monk3e189872016-01-12 09:10:34 -050042import com.android.systemui.qs.tiles.RotationLockTile;
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 Monkf23aa992016-01-22 16:45:21 -050047import com.android.systemui.statusbar.policy.DataSaverController;
Jason Monk952d5d82014-10-27 15:28:22 -040048import com.android.systemui.statusbar.policy.HotspotController;
Jason Monk3e189872016-01-12 09:10:34 -050049import com.android.systemui.statusbar.policy.RotationLockController;
Adrian Roos88b11932015-07-22 14:59:48 -070050import com.android.systemui.statusbar.policy.UserInfoController;
Joe Onorato798ac4c2010-05-27 16:39:00 -040051
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052/**
53 * This class contains all of the policy about which icons are installed in the status
Joe Onorato798ac4c2010-05-27 16:39:00 -040054 * bar at boot time. It goes through the normal API for icons, even though it probably
55 * strictly doesn't need to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056 */
Jason Monkf23aa992016-01-22 16:45:21 -050057public class PhoneStatusBarPolicy implements Callback, RotationLockController.RotationLockControllerCallback, DataSaverController.Listener {
Joe Onoratofd52b182010-11-10 18:00:52 -080058 private static final String TAG = "PhoneStatusBarPolicy";
John Spurlocka37e9c82014-07-08 09:40:31 -040059 private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Robert Greenwaltd7085fc2010-09-08 15:24:47 -070060
Jason Monk3e189872016-01-12 09:10:34 -050061 private final String mSlotCast;
62 private final String mSlotHotspot;
63 private final String mSlotBluetooth;
64 private final String mSlotTty;
65 private final String mSlotZen;
66 private final String mSlotVolume;
67 private final String mSlotAlarmClock;
68 private final String mSlotManagedProfile;
69 private final String mSlotRotate;
70 private final String mSlotHeadset;
Jason Monkf23aa992016-01-22 16:45:21 -050071 private final String mSlotDataSaver;
John Spurlocka37e9c82014-07-08 09:40:31 -040072
Dianne Hackborn4840e142009-03-24 22:40:29 -070073 private final Context mContext;
Joe Onorato10523b4d2010-10-25 10:42:46 -070074 private final Handler mHandler = new Handler();
John Spurlock96fe98d2014-08-27 09:36:02 -040075 private final CastController mCast;
Jason Monk952d5d82014-10-27 15:28:22 -040076 private final HotspotController mHotspot;
John Spurlock15782262015-05-29 15:35:53 -040077 private final AlarmManager mAlarmManager;
Adrian Roos88b11932015-07-22 14:59:48 -070078 private final UserInfoController mUserInfoController;
Rubin Xu1205fb12015-11-04 17:45:03 +000079 private final UserManager mUserManager;
Jason Monk07473ce2016-01-05 14:59:19 -050080 private final StatusBarIconController mIconController;
Jason Monk3e189872016-01-12 09:10:34 -050081 private final RotationLockController mRotationLockController;
Jason Monkf23aa992016-01-22 16:45:21 -050082 private final DataSaverController mDataSaver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084 // Assume it's all good unless we hear otherwise. We don't always seem
85 // to get broadcasts that it *is* there.
Wink Savillea639b312012-07-10 12:37:54 -070086 IccCardConstants.State mSimState = IccCardConstants.State.READY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087
John Spurlocka37e9c82014-07-08 09:40:31 -040088 private boolean mZenVisible;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 private boolean mVolumeVisible;
John Spurlock604a5ee2015-06-01 12:27:22 -040090 private boolean mCurrentUserSetup;
Wink Saville04e71b32009-04-02 11:00:54 -070091
John Spurlockae641c92014-06-30 18:11:40 -040092 private int mZen;
John Spurlockba2c6a02014-05-19 09:44:06 -040093
Kenny Guy3094d4a2015-04-01 19:14:10 +010094 private boolean mManagedProfileFocused = false;
Rubin Xu1205fb12015-11-04 17:45:03 +000095 private boolean mManagedProfileIconVisible = false;
96 private boolean mManagedProfileInQuietMode = false;
Kenny Guy3094d4a2015-04-01 19:14:10 +010097
98 private boolean mKeyguardVisible = true;
Jason Monk70364362015-08-06 16:32:18 -040099 private BluetoothController mBluetooth;
Wink Savillee9b06d72009-05-18 21:47:50 -0700100
Jason Monk07473ce2016-01-05 14:59:19 -0500101 public PhoneStatusBarPolicy(Context context, StatusBarIconController iconController,
102 CastController cast, HotspotController hotspot, UserInfoController userInfoController,
Jason Monkf23aa992016-01-22 16:45:21 -0500103 BluetoothController bluetooth, RotationLockController rotationLockController,
104 DataSaverController dataSaver) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105 mContext = context;
Jason Monk07473ce2016-01-05 14:59:19 -0500106 mIconController = iconController;
John Spurlock96fe98d2014-08-27 09:36:02 -0400107 mCast = cast;
Jason Monk952d5d82014-10-27 15:28:22 -0400108 mHotspot = hotspot;
Jason Monk70364362015-08-06 16:32:18 -0400109 mBluetooth = bluetooth;
110 mBluetooth.addStateChangedCallback(this);
John Spurlock15782262015-05-29 15:35:53 -0400111 mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Adrian Roos88b11932015-07-22 14:59:48 -0700112 mUserInfoController = userInfoController;
Rubin Xu1205fb12015-11-04 17:45:03 +0000113 mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
Jason Monk3e189872016-01-12 09:10:34 -0500114 mRotationLockController = rotationLockController;
Jason Monkf23aa992016-01-22 16:45:21 -0500115 mDataSaver = dataSaver;
Jason Monk3e189872016-01-12 09:10:34 -0500116
117 mSlotCast = context.getString(com.android.internal.R.string.status_bar_cast);
118 mSlotHotspot = context.getString(com.android.internal.R.string.status_bar_hotspot);
119 mSlotBluetooth = context.getString(com.android.internal.R.string.status_bar_bluetooth);
120 mSlotTty = context.getString(com.android.internal.R.string.status_bar_tty);
121 mSlotZen = context.getString(com.android.internal.R.string.status_bar_zen);
122 mSlotVolume = context.getString(com.android.internal.R.string.status_bar_volume);
123 mSlotAlarmClock = context.getString(com.android.internal.R.string.status_bar_alarm_clock);
124 mSlotManagedProfile = context.getString(
125 com.android.internal.R.string.status_bar_managed_profile);
126 mSlotRotate = context.getString(com.android.internal.R.string.status_bar_rotate);
127 mSlotHeadset = context.getString(com.android.internal.R.string.status_bar_headset);
Jason Monkf23aa992016-01-22 16:45:21 -0500128 mSlotDataSaver = context.getString(com.android.internal.R.string.status_bar_data_saver);
Jason Monk3e189872016-01-12 09:10:34 -0500129
130 mRotationLockController.addRotationLockControllerCallback(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400132 // listen for broadcasts
133 IntentFilter filter = new IntentFilter();
Adrian Roosc42a1e12014-07-07 23:35:53 +0200134 filter.addAction(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED);
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400135 filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
John Spurlockbcc10872014-11-28 15:29:21 -0500136 filter.addAction(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION);
Jason Monk3e189872016-01-12 09:10:34 -0500137 filter.addAction(AudioManager.ACTION_HEADSET_PLUG);
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 Xue95057a2016-04-01 16:49:25 +0100140 filter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE);
141 filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE);
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400142 mContext.registerReceiver(mIntentReceiver, filter, null, mHandler);
143
Kenny Guy3094d4a2015-04-01 19:14:10 +0100144 // listen for user / profile change.
145 try {
146 ActivityManagerNative.getDefault().registerUserSwitchObserver(mUserSwitchListener);
147 } catch (RemoteException e) {
148 // Ignore
149 }
150
Wink Saville04e71b32009-04-02 11:00:54 -0700151 // TTY status
Jason Monk3e189872016-01-12 09:10:34 -0500152 mIconController.setIcon(mSlotTty, R.drawable.stat_sys_tty_mode, null);
153 mIconController.setIconVisibility(mSlotTty, false);
Wink Saville04e71b32009-04-02 11:00:54 -0700154
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 // bluetooth status
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700156 updateBluetooth();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 // Alarm clock
Jason Monk3e189872016-01-12 09:10:34 -0500159 mIconController.setIcon(mSlotAlarmClock, R.drawable.stat_sys_alarm, null);
160 mIconController.setIconVisibility(mSlotAlarmClock, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161
John Spurlocka37e9c82014-07-08 09:40:31 -0400162 // zen
Jason Monk3e189872016-01-12 09:10:34 -0500163 mIconController.setIcon(mSlotZen, R.drawable.stat_sys_zen_important, null);
164 mIconController.setIconVisibility(mSlotZen, false);
John Spurlocka37e9c82014-07-08 09:40:31 -0400165
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 // volume
Jason Monk3e189872016-01-12 09:10:34 -0500167 mIconController.setIcon(mSlotVolume, R.drawable.stat_sys_ringer_vibrate, null);
168 mIconController.setIconVisibility(mSlotVolume, false);
John Spurlocka37e9c82014-07-08 09:40:31 -0400169 updateVolumeZen();
John Spurlock96fe98d2014-08-27 09:36:02 -0400170
171 // cast
Jason Monk3e189872016-01-12 09:10:34 -0500172 mIconController.setIcon(mSlotCast, R.drawable.stat_sys_cast, null);
173 mIconController.setIconVisibility(mSlotCast, false);
John Spurlock96fe98d2014-08-27 09:36:02 -0400174 mCast.addCallback(mCastCallback);
Jason Monk952d5d82014-10-27 15:28:22 -0400175
176 // hotspot
Jason Monk3e189872016-01-12 09:10:34 -0500177 mIconController.setIcon(mSlotHotspot, R.drawable.stat_sys_hotspot,
Jason Monk08187a42015-06-09 14:33:51 -0400178 mContext.getString(R.string.accessibility_status_bar_hotspot));
Jason Monk3e189872016-01-12 09:10:34 -0500179 mIconController.setIconVisibility(mSlotHotspot, mHotspot.isHotspotEnabled());
Jason Monk952d5d82014-10-27 15:28:22 -0400180 mHotspot.addCallback(mHotspotCallback);
Kenny Guy3094d4a2015-04-01 19:14:10 +0100181
182 // managed profile
Jason Monk3e189872016-01-12 09:10:34 -0500183 mIconController.setIcon(mSlotManagedProfile, R.drawable.stat_sys_managed_profile_status,
Adrian Roos1b5eb972015-06-11 18:22:52 -0700184 mContext.getString(R.string.accessibility_managed_profile));
Jason Monk3e189872016-01-12 09:10:34 -0500185 mIconController.setIconVisibility(mSlotManagedProfile, mManagedProfileIconVisible);
Jason Monkf23aa992016-01-22 16:45:21 -0500186
187 // data saver
188 mIconController.setIcon(mSlotDataSaver, R.drawable.stat_sys_data_saver,
189 context.getString(R.string.accessibility_data_saver_on));
190 mIconController.setIconVisibility(mSlotDataSaver, false);
191 mDataSaver.addListener(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800192 }
193
John Spurlockae641c92014-06-30 18:11:40 -0400194 public void setZenMode(int zen) {
John Spurlockba2c6a02014-05-19 09:44:06 -0400195 mZen = zen;
John Spurlocka37e9c82014-07-08 09:40:31 -0400196 updateVolumeZen();
John Spurlockba2c6a02014-05-19 09:44:06 -0400197 }
198
Adrian Roosc42a1e12014-07-07 23:35:53 +0200199 private void updateAlarm() {
John Spurlock604a5ee2015-06-01 12:27:22 -0400200 final AlarmClockInfo alarm = mAlarmManager.getNextAlarmClock(UserHandle.USER_CURRENT);
201 final boolean hasAlarm = alarm != null && alarm.getTriggerTime() > 0;
John Spurlock15782262015-05-29 15:35:53 -0400202 final boolean zenNone = mZen == Global.ZEN_MODE_NO_INTERRUPTIONS;
Jason Monk3e189872016-01-12 09:10:34 -0500203 mIconController.setIcon(mSlotAlarmClock, zenNone ? R.drawable.stat_sys_alarm_dim
Jason Monk07473ce2016-01-05 14:59:19 -0500204 : R.drawable.stat_sys_alarm, null);
Jason Monk3e189872016-01-12 09:10:34 -0500205 mIconController.setIconVisibility(mSlotAlarmClock, mCurrentUserSetup && hasAlarm);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800206 }
207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800208 private final void updateSimState(Intent intent) {
Wink Savillea639b312012-07-10 12:37:54 -0700209 String stateExtra = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
210 if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) {
211 mSimState = IccCardConstants.State.ABSENT;
Jason Monk07473ce2016-01-05 14:59:19 -0500212 } else if (IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR.equals(stateExtra)) {
Rakesh Pallerlaf099a5f2013-02-06 11:44:23 +0530213 mSimState = IccCardConstants.State.CARD_IO_ERROR;
Jason Monk07473ce2016-01-05 14:59:19 -0500214 } else if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(stateExtra)) {
Wink Savillea639b312012-07-10 12:37:54 -0700215 mSimState = IccCardConstants.State.READY;
Jason Monk07473ce2016-01-05 14:59:19 -0500216 } else if (IccCardConstants.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) {
Wink Savillea639b312012-07-10 12:37:54 -0700217 final String lockedReason =
218 intent.getStringExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON);
219 if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) {
220 mSimState = IccCardConstants.State.PIN_REQUIRED;
Jason Monk07473ce2016-01-05 14:59:19 -0500221 } else if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) {
Wink Savillea639b312012-07-10 12:37:54 -0700222 mSimState = IccCardConstants.State.PUK_REQUIRED;
Jason Monk07473ce2016-01-05 14:59:19 -0500223 } else {
Wink Savillea639b312012-07-10 12:37:54 -0700224 mSimState = IccCardConstants.State.NETWORK_LOCKED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225 }
226 } else {
Wink Savillea639b312012-07-10 12:37:54 -0700227 mSimState = IccCardConstants.State.UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800228 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229 }
230
John Spurlockbcc10872014-11-28 15:29:21 -0500231 private final void updateVolumeZen() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232 AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
John Spurlocka37e9c82014-07-08 09:40:31 -0400233
234 boolean zenVisible = false;
235 int zenIconId = 0;
236 String zenDescription = null;
237
238 boolean volumeVisible = false;
239 int volumeIconId = 0;
240 String volumeDescription = null;
241
John Spurlockf88d8082015-03-25 18:09:51 -0400242 if (DndTile.isVisible(mContext) || DndTile.isCombinedIcon(mContext)) {
John Spurlock3c4076a2015-02-24 12:12:25 -0500243 zenVisible = mZen != Global.ZEN_MODE_OFF;
John Spurlock4ec8b602015-05-11 17:46:28 -0400244 zenIconId = mZen == Global.ZEN_MODE_NO_INTERRUPTIONS
245 ? R.drawable.stat_sys_dnd_total_silence : R.drawable.stat_sys_dnd;
John Spurlock3c4076a2015-02-24 12:12:25 -0500246 zenDescription = mContext.getString(R.string.quick_settings_dnd_label);
247 } else if (mZen == Global.ZEN_MODE_NO_INTERRUPTIONS) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400248 zenVisible = true;
249 zenIconId = R.drawable.stat_sys_zen_none;
John Spurlockd9c75db2015-04-28 11:19:13 -0400250 zenDescription = mContext.getString(R.string.interruption_level_none);
John Spurlockae641c92014-06-30 18:11:40 -0400251 } else if (mZen == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400252 zenVisible = true;
253 zenIconId = R.drawable.stat_sys_zen_important;
John Spurlockd9c75db2015-04-28 11:19:13 -0400254 zenDescription = mContext.getString(R.string.interruption_level_priority);
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700255 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800256
John Spurlockd9c75db2015-04-28 11:19:13 -0400257 if (DndTile.isVisible(mContext) && !DndTile.isCombinedIcon(mContext)
John Spurlocka48d7792015-03-03 17:35:57 -0500258 && audioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_SILENT) {
259 volumeVisible = true;
260 volumeIconId = R.drawable.stat_sys_ringer_silent;
261 volumeDescription = mContext.getString(R.string.accessibility_ringer_silent);
John Spurlock4f1163c2015-04-02 17:41:21 -0400262 } else if (mZen != Global.ZEN_MODE_NO_INTERRUPTIONS && mZen != Global.ZEN_MODE_ALARMS &&
John Spurlock661f2cf2014-11-17 10:29:10 -0500263 audioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_VIBRATE) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400264 volumeVisible = true;
265 volumeIconId = R.drawable.stat_sys_ringer_vibrate;
266 volumeDescription = mContext.getString(R.string.accessibility_ringer_vibrate);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800267 }
John Spurlocka37e9c82014-07-08 09:40:31 -0400268
269 if (zenVisible) {
Jason Monk3e189872016-01-12 09:10:34 -0500270 mIconController.setIcon(mSlotZen, zenIconId, zenDescription);
John Spurlocka37e9c82014-07-08 09:40:31 -0400271 }
272 if (zenVisible != mZenVisible) {
Jason Monk3e189872016-01-12 09:10:34 -0500273 mIconController.setIconVisibility(mSlotZen, zenVisible);
John Spurlocka37e9c82014-07-08 09:40:31 -0400274 mZenVisible = zenVisible;
275 }
276
277 if (volumeVisible) {
Jason Monk3e189872016-01-12 09:10:34 -0500278 mIconController.setIcon(mSlotVolume, volumeIconId, volumeDescription);
John Spurlocka37e9c82014-07-08 09:40:31 -0400279 }
280 if (volumeVisible != mVolumeVisible) {
Jason Monk3e189872016-01-12 09:10:34 -0500281 mIconController.setIconVisibility(mSlotVolume, volumeVisible);
John Spurlocka37e9c82014-07-08 09:40:31 -0400282 mVolumeVisible = volumeVisible;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800283 }
John Spurlock15782262015-05-29 15:35:53 -0400284 updateAlarm();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 }
286
Jason Monk70364362015-08-06 16:32:18 -0400287 @Override
288 public void onBluetoothDevicesChanged() {
289 updateBluetooth();
290 }
291
292 @Override
293 public void onBluetoothStateChange(boolean enabled) {
294 updateBluetooth();
295 }
296
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700297 private final void updateBluetooth() {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400298 int iconId = R.drawable.stat_sys_data_bluetooth;
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700299 String contentDescription =
Jason Monk1aa32822015-07-14 16:10:32 -0400300 mContext.getString(R.string.accessibility_quick_settings_bluetooth_on);
Jason Monk70364362015-08-06 16:32:18 -0400301 boolean bluetoothEnabled = false;
302 if (mBluetooth != null) {
303 bluetoothEnabled = mBluetooth.isBluetoothEnabled();
304 if (mBluetooth.isBluetoothConnected()) {
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -0700305 iconId = R.drawable.stat_sys_data_bluetooth_connected;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700306 contentDescription = mContext.getString(R.string.accessibility_bluetooth_connected);
Jaikumar Ganesh084c6652009-12-07 10:58:18 -0800307 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800308 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700309
Jason Monk3e189872016-01-12 09:10:34 -0500310 mIconController.setIcon(mSlotBluetooth, iconId, contentDescription);
311 mIconController.setIconVisibility(mSlotBluetooth, bluetoothEnabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800312 }
313
Wink Savillee9b06d72009-05-18 21:47:50 -0700314 private final void updateTTY(Intent intent) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700315 int currentTtyMode = intent.getIntExtra(TelecomManager.EXTRA_CURRENT_TTY_MODE,
316 TelecomManager.TTY_MODE_OFF);
317 boolean enabled = currentTtyMode != TelecomManager.TTY_MODE_OFF;
Wink Saville04e71b32009-04-02 11:00:54 -0700318
John Spurlocka37e9c82014-07-08 09:40:31 -0400319 if (DEBUG) Log.v(TAG, "updateTTY: enabled: " + enabled);
Wink Saville04e71b32009-04-02 11:00:54 -0700320
321 if (enabled) {
322 // TTY is on
John Spurlocka37e9c82014-07-08 09:40:31 -0400323 if (DEBUG) Log.v(TAG, "updateTTY: set TTY on");
Jason Monk3e189872016-01-12 09:10:34 -0500324 mIconController.setIcon(mSlotTty, R.drawable.stat_sys_tty_mode,
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700325 mContext.getString(R.string.accessibility_tty_enabled));
Jason Monk3e189872016-01-12 09:10:34 -0500326 mIconController.setIconVisibility(mSlotTty, true);
Wink Saville04e71b32009-04-02 11:00:54 -0700327 } else {
328 // TTY is off
John Spurlocka37e9c82014-07-08 09:40:31 -0400329 if (DEBUG) Log.v(TAG, "updateTTY: set TTY off");
Jason Monk3e189872016-01-12 09:10:34 -0500330 mIconController.setIconVisibility(mSlotTty, false);
Wink Saville04e71b32009-04-02 11:00:54 -0700331 }
332 }
John Spurlock96fe98d2014-08-27 09:36:02 -0400333
334 private void updateCast() {
335 boolean isCasting = false;
336 for (CastDevice device : mCast.getCastDevices()) {
337 if (device.state == CastDevice.STATE_CONNECTING
338 || device.state == CastDevice.STATE_CONNECTED) {
339 isCasting = true;
340 break;
341 }
342 }
343 if (DEBUG) Log.v(TAG, "updateCast: isCasting: " + isCasting);
Dan Sandler8fd25bf2015-10-20 16:01:27 -0700344 mHandler.removeCallbacks(mRemoveCastIconRunnable);
John Spurlock96fe98d2014-08-27 09:36:02 -0400345 if (isCasting) {
Jason Monk3e189872016-01-12 09:10:34 -0500346 mIconController.setIcon(mSlotCast, R.drawable.stat_sys_cast,
John Spurlock96fe98d2014-08-27 09:36:02 -0400347 mContext.getString(R.string.accessibility_casting));
Jason Monk3e189872016-01-12 09:10:34 -0500348 mIconController.setIconVisibility(mSlotCast, true);
Dan Sandler8fd25bf2015-10-20 16:01:27 -0700349 } else {
350 // don't turn off the screen-record icon for a few seconds, just to make sure the user
351 // has seen it
352 if (DEBUG) Log.v(TAG, "updateCast: hiding icon in 3 sec...");
353 mHandler.postDelayed(mRemoveCastIconRunnable, 3000);
John Spurlock96fe98d2014-08-27 09:36:02 -0400354 }
John Spurlock96fe98d2014-08-27 09:36:02 -0400355 }
356
Rubin Xu1205fb12015-11-04 17:45:03 +0000357 private void updateQuietState() {
358 mManagedProfileInQuietMode = false;
359 int currentUserId = ActivityManager.getCurrentUser();
360 for (UserInfo ui : mUserManager.getEnabledProfiles(currentUserId)) {
361 if (ui.isManagedProfile() && ui.isQuietModeEnabled()) {
362 mManagedProfileInQuietMode = true;
363 return;
364 }
365 }
366 }
367
Kenny Guy3094d4a2015-04-01 19:14:10 +0100368 private void profileChanged(int userId) {
Kenny Guy3094d4a2015-04-01 19:14:10 +0100369 UserInfo user = null;
370 if (userId == UserHandle.USER_CURRENT) {
371 try {
372 user = ActivityManagerNative.getDefault().getCurrentUser();
373 } catch (RemoteException e) {
374 // Ignore
375 }
376 } else {
Rubin Xu1205fb12015-11-04 17:45:03 +0000377 user = mUserManager.getUserInfo(userId);
Kenny Guy3094d4a2015-04-01 19:14:10 +0100378 }
379
380 mManagedProfileFocused = user != null && user.isManagedProfile();
381 if (DEBUG) Log.v(TAG, "profileChanged: mManagedProfileFocused: " + mManagedProfileFocused);
382 // Actually update the icon later when transition starts.
383 }
384
385 private void updateManagedProfile() {
386 if (DEBUG) Log.v(TAG, "updateManagedProfile: mManagedProfileFocused: "
387 + mManagedProfileFocused
388 + " mKeyguardVisible: " + mKeyguardVisible);
Rubin Xu1205fb12015-11-04 17:45:03 +0000389 final boolean showIcon;
390 if (mManagedProfileFocused && !mKeyguardVisible) {
391 showIcon = true;
Jason Monk3e189872016-01-12 09:10:34 -0500392 mIconController.setIcon(mSlotManagedProfile,
Jason Monk07473ce2016-01-05 14:59:19 -0500393 R.drawable.stat_sys_managed_profile_status,
Rubin Xu1205fb12015-11-04 17:45:03 +0000394 mContext.getString(R.string.accessibility_managed_profile));
395 } else if (mManagedProfileInQuietMode) {
396 showIcon = true;
Jason Monk3e189872016-01-12 09:10:34 -0500397 mIconController.setIcon(mSlotManagedProfile,
Jason Monk07473ce2016-01-05 14:59:19 -0500398 R.drawable.stat_sys_managed_profile_status_off,
Rubin Xu1205fb12015-11-04 17:45:03 +0000399 mContext.getString(R.string.accessibility_managed_profile));
400 } else {
401 showIcon = false;
402 }
Kenny Guy3094d4a2015-04-01 19:14:10 +0100403 if (mManagedProfileIconVisible != showIcon) {
Jason Monk3e189872016-01-12 09:10:34 -0500404 mIconController.setIconVisibility(mSlotManagedProfile, showIcon);
Kenny Guy3094d4a2015-04-01 19:14:10 +0100405 mManagedProfileIconVisible = showIcon;
406 }
407 }
408
Fyodor Kupolov6005b3f2015-11-23 17:41:50 -0800409 private final SynchronousUserSwitchObserver mUserSwitchListener =
410 new SynchronousUserSwitchObserver() {
Kenny Guy3094d4a2015-04-01 19:14:10 +0100411 @Override
Fyodor Kupolov6005b3f2015-11-23 17:41:50 -0800412 public void onUserSwitching(int newUserId) throws RemoteException {
Adrian Roos88b11932015-07-22 14:59:48 -0700413 mUserInfoController.reloadUserInfo();
Kenny Guy3094d4a2015-04-01 19:14:10 +0100414 }
415
416 @Override
417 public void onUserSwitchComplete(int newUserId) throws RemoteException {
418 updateAlarm();
419 profileChanged(newUserId);
Rubin Xu1205fb12015-11-04 17:45:03 +0000420 updateQuietState();
421 updateManagedProfile();
Kenny Guy3094d4a2015-04-01 19:14:10 +0100422 }
423
424 @Override
425 public void onForegroundProfileSwitch(int newProfileId) {
426 profileChanged(newProfileId);
427 }
428 };
429
Jason Monk952d5d82014-10-27 15:28:22 -0400430 private final HotspotController.Callback mHotspotCallback = new HotspotController.Callback() {
431 @Override
432 public void onHotspotChanged(boolean enabled) {
Jason Monk3e189872016-01-12 09:10:34 -0500433 mIconController.setIconVisibility(mSlotHotspot, enabled);
Jason Monk952d5d82014-10-27 15:28:22 -0400434 }
435 };
436
John Spurlock96fe98d2014-08-27 09:36:02 -0400437 private final CastController.Callback mCastCallback = new CastController.Callback() {
438 @Override
439 public void onCastDevicesChanged() {
440 updateCast();
441 }
442 };
Kenny Guy3094d4a2015-04-01 19:14:10 +0100443
444 public void appTransitionStarting(long startTime, long duration) {
445 updateManagedProfile();
446 }
447
448 public void setKeyguardShowing(boolean visible) {
449 mKeyguardVisible = visible;
450 updateManagedProfile();
451 }
John Spurlock604a5ee2015-06-01 12:27:22 -0400452
453 public void setCurrentUserSetup(boolean userSetup) {
454 if (mCurrentUserSetup == userSetup) return;
455 mCurrentUserSetup = userSetup;
456 updateAlarm();
Rubin Xu1205fb12015-11-04 17:45:03 +0000457 updateQuietState();
John Spurlock604a5ee2015-06-01 12:27:22 -0400458 }
Jason Monk3e189872016-01-12 09:10:34 -0500459
460 @Override
461 public void onRotationLockStateChanged(boolean rotationLocked, boolean affordanceVisible) {
462 boolean portrait = RotationLockTile.isCurrentOrientationLockPortrait(
463 mRotationLockController, mContext);
464 if (rotationLocked) {
465 if (portrait) {
466 mIconController.setIcon(mSlotRotate, R.drawable.stat_sys_rotate_portrait,
467 mContext.getString(R.string.accessibility_rotation_lock_on_portrait));
468 } else {
469 mIconController.setIcon(mSlotRotate, R.drawable.stat_sys_rotate_landscape,
470 mContext.getString(R.string.accessibility_rotation_lock_on_landscape));
471 }
Jason Monk8816dff2016-02-09 21:50:36 -0500472 mIconController.setIconVisibility(mSlotRotate, true);
Jason Monk3e189872016-01-12 09:10:34 -0500473 } else {
Jason Monk8816dff2016-02-09 21:50:36 -0500474 mIconController.setIconVisibility(mSlotRotate, false);
Jason Monk3e189872016-01-12 09:10:34 -0500475 }
476 }
477
478 private void updateHeadsetPlug(Intent intent) {
479 boolean connected = intent.getIntExtra("state", 0) != 0;
480 boolean hasMic = intent.getIntExtra("microphone", 0) != 0;
481 if (connected) {
482 String contentDescription = mContext.getString(hasMic
483 ? R.string.accessibility_status_bar_headset
484 : R.string.accessibility_status_bar_headphones);
485 mIconController.setIcon(mSlotHeadset, hasMic ? R.drawable.ic_headset_mic
486 : R.drawable.ic_headset, contentDescription);
487 mIconController.setIconVisibility(mSlotHeadset, true);
488 } else {
489 mIconController.setIconVisibility(mSlotHeadset, false);
490 }
491 }
492
Jason Monkf23aa992016-01-22 16:45:21 -0500493 @Override
494 public void onDataSaverChanged(boolean isDataSaving) {
495 mIconController.setIconVisibility(mSlotDataSaver, isDataSaving);
496 }
497
Jason Monk3e189872016-01-12 09:10:34 -0500498 private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
499 @Override
500 public void onReceive(Context context, Intent intent) {
501 String action = intent.getAction();
502 if (action.equals(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED)) {
503 updateAlarm();
504 } else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION) ||
505 action.equals(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION)) {
506 updateVolumeZen();
507 } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
508 updateSimState(intent);
509 } else if (action.equals(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED)) {
510 updateTTY(intent);
Rubin Xue95057a2016-04-01 16:49:25 +0100511 } else if (action.equals(Intent.ACTION_MANAGED_PROFILE_AVAILABLE) ||
512 action.equals(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE)) {
Jason Monk3e189872016-01-12 09:10:34 -0500513 updateQuietState();
514 updateManagedProfile();
515 } else if (action.equals(AudioManager.ACTION_HEADSET_PLUG)) {
516 updateHeadsetPlug(intent);
517 }
518 }
519 };
520
521 private Runnable mRemoveCastIconRunnable = new Runnable() {
522 @Override
523 public void run() {
524 if (DEBUG) Log.v(TAG, "updateCast: hiding icon NOW");
525 mIconController.setIconVisibility(mSlotCast, false);
526 }
527 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528}