blob: 823af36fff5a9a738888ced50c24cf3af8204ed3 [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);
Nicolas Prevot6c7b8742016-04-13 10:28:58 +0100142 filter.addAction(Intent.ACTION_MANAGED_PROFILE_REMOVED);
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400143 mContext.registerReceiver(mIntentReceiver, filter, null, mHandler);
144
Kenny Guy3094d4a2015-04-01 19:14:10 +0100145 // listen for user / profile change.
146 try {
147 ActivityManagerNative.getDefault().registerUserSwitchObserver(mUserSwitchListener);
148 } catch (RemoteException e) {
149 // Ignore
150 }
151
Wink Saville04e71b32009-04-02 11:00:54 -0700152 // TTY status
Jason Monk3e189872016-01-12 09:10:34 -0500153 mIconController.setIcon(mSlotTty, R.drawable.stat_sys_tty_mode, null);
154 mIconController.setIconVisibility(mSlotTty, false);
Wink Saville04e71b32009-04-02 11:00:54 -0700155
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 // bluetooth status
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700157 updateBluetooth();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159 // Alarm clock
Jason Monk3e189872016-01-12 09:10:34 -0500160 mIconController.setIcon(mSlotAlarmClock, R.drawable.stat_sys_alarm, null);
161 mIconController.setIconVisibility(mSlotAlarmClock, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162
John Spurlocka37e9c82014-07-08 09:40:31 -0400163 // zen
Jason Monk3e189872016-01-12 09:10:34 -0500164 mIconController.setIcon(mSlotZen, R.drawable.stat_sys_zen_important, null);
165 mIconController.setIconVisibility(mSlotZen, false);
John Spurlocka37e9c82014-07-08 09:40:31 -0400166
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167 // volume
Jason Monk3e189872016-01-12 09:10:34 -0500168 mIconController.setIcon(mSlotVolume, R.drawable.stat_sys_ringer_vibrate, null);
169 mIconController.setIconVisibility(mSlotVolume, false);
John Spurlocka37e9c82014-07-08 09:40:31 -0400170 updateVolumeZen();
John Spurlock96fe98d2014-08-27 09:36:02 -0400171
172 // cast
Jason Monk3e189872016-01-12 09:10:34 -0500173 mIconController.setIcon(mSlotCast, R.drawable.stat_sys_cast, null);
174 mIconController.setIconVisibility(mSlotCast, false);
John Spurlock96fe98d2014-08-27 09:36:02 -0400175 mCast.addCallback(mCastCallback);
Jason Monk952d5d82014-10-27 15:28:22 -0400176
177 // hotspot
Jason Monk3e189872016-01-12 09:10:34 -0500178 mIconController.setIcon(mSlotHotspot, R.drawable.stat_sys_hotspot,
Jason Monk08187a42015-06-09 14:33:51 -0400179 mContext.getString(R.string.accessibility_status_bar_hotspot));
Jason Monk3e189872016-01-12 09:10:34 -0500180 mIconController.setIconVisibility(mSlotHotspot, mHotspot.isHotspotEnabled());
Jason Monk952d5d82014-10-27 15:28:22 -0400181 mHotspot.addCallback(mHotspotCallback);
Kenny Guy3094d4a2015-04-01 19:14:10 +0100182
183 // managed profile
Jason Monk3e189872016-01-12 09:10:34 -0500184 mIconController.setIcon(mSlotManagedProfile, R.drawable.stat_sys_managed_profile_status,
Adrian Roos1b5eb972015-06-11 18:22:52 -0700185 mContext.getString(R.string.accessibility_managed_profile));
Jason Monk3e189872016-01-12 09:10:34 -0500186 mIconController.setIconVisibility(mSlotManagedProfile, mManagedProfileIconVisible);
Jason Monkf23aa992016-01-22 16:45:21 -0500187
188 // data saver
189 mIconController.setIcon(mSlotDataSaver, R.drawable.stat_sys_data_saver,
190 context.getString(R.string.accessibility_data_saver_on));
191 mIconController.setIconVisibility(mSlotDataSaver, false);
192 mDataSaver.addListener(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193 }
194
John Spurlockae641c92014-06-30 18:11:40 -0400195 public void setZenMode(int zen) {
John Spurlockba2c6a02014-05-19 09:44:06 -0400196 mZen = zen;
John Spurlocka37e9c82014-07-08 09:40:31 -0400197 updateVolumeZen();
John Spurlockba2c6a02014-05-19 09:44:06 -0400198 }
199
Adrian Roosc42a1e12014-07-07 23:35:53 +0200200 private void updateAlarm() {
John Spurlock604a5ee2015-06-01 12:27:22 -0400201 final AlarmClockInfo alarm = mAlarmManager.getNextAlarmClock(UserHandle.USER_CURRENT);
202 final boolean hasAlarm = alarm != null && alarm.getTriggerTime() > 0;
John Spurlock15782262015-05-29 15:35:53 -0400203 final boolean zenNone = mZen == Global.ZEN_MODE_NO_INTERRUPTIONS;
Jason Monk3e189872016-01-12 09:10:34 -0500204 mIconController.setIcon(mSlotAlarmClock, zenNone ? R.drawable.stat_sys_alarm_dim
Jason Monk07473ce2016-01-05 14:59:19 -0500205 : R.drawable.stat_sys_alarm, null);
Jason Monk3e189872016-01-12 09:10:34 -0500206 mIconController.setIconVisibility(mSlotAlarmClock, mCurrentUserSetup && hasAlarm);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207 }
208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 private final void updateSimState(Intent intent) {
Wink Savillea639b312012-07-10 12:37:54 -0700210 String stateExtra = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
211 if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) {
212 mSimState = IccCardConstants.State.ABSENT;
Jason Monk07473ce2016-01-05 14:59:19 -0500213 } else if (IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR.equals(stateExtra)) {
Rakesh Pallerlaf099a5f2013-02-06 11:44:23 +0530214 mSimState = IccCardConstants.State.CARD_IO_ERROR;
Jason Monk07473ce2016-01-05 14:59:19 -0500215 } else if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(stateExtra)) {
Wink Savillea639b312012-07-10 12:37:54 -0700216 mSimState = IccCardConstants.State.READY;
Jason Monk07473ce2016-01-05 14:59:19 -0500217 } else if (IccCardConstants.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) {
Wink Savillea639b312012-07-10 12:37:54 -0700218 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;
Jason Monk07473ce2016-01-05 14:59:19 -0500222 } else if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) {
Wink Savillea639b312012-07-10 12:37:54 -0700223 mSimState = IccCardConstants.State.PUK_REQUIRED;
Jason Monk07473ce2016-01-05 14:59:19 -0500224 } else {
Wink Savillea639b312012-07-10 12:37:54 -0700225 mSimState = IccCardConstants.State.NETWORK_LOCKED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226 }
227 } else {
Wink Savillea639b312012-07-10 12:37:54 -0700228 mSimState = IccCardConstants.State.UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230 }
231
John Spurlockbcc10872014-11-28 15:29:21 -0500232 private final void updateVolumeZen() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233 AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
John Spurlocka37e9c82014-07-08 09:40:31 -0400234
235 boolean zenVisible = false;
236 int zenIconId = 0;
237 String zenDescription = null;
238
239 boolean volumeVisible = false;
240 int volumeIconId = 0;
241 String volumeDescription = null;
242
John Spurlockf88d8082015-03-25 18:09:51 -0400243 if (DndTile.isVisible(mContext) || DndTile.isCombinedIcon(mContext)) {
John Spurlock3c4076a2015-02-24 12:12:25 -0500244 zenVisible = mZen != Global.ZEN_MODE_OFF;
John Spurlock4ec8b602015-05-11 17:46:28 -0400245 zenIconId = mZen == Global.ZEN_MODE_NO_INTERRUPTIONS
246 ? R.drawable.stat_sys_dnd_total_silence : R.drawable.stat_sys_dnd;
John Spurlock3c4076a2015-02-24 12:12:25 -0500247 zenDescription = mContext.getString(R.string.quick_settings_dnd_label);
248 } else if (mZen == Global.ZEN_MODE_NO_INTERRUPTIONS) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400249 zenVisible = true;
250 zenIconId = R.drawable.stat_sys_zen_none;
John Spurlockd9c75db2015-04-28 11:19:13 -0400251 zenDescription = mContext.getString(R.string.interruption_level_none);
John Spurlockae641c92014-06-30 18:11:40 -0400252 } else if (mZen == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400253 zenVisible = true;
254 zenIconId = R.drawable.stat_sys_zen_important;
John Spurlockd9c75db2015-04-28 11:19:13 -0400255 zenDescription = mContext.getString(R.string.interruption_level_priority);
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700256 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800257
John Spurlockd9c75db2015-04-28 11:19:13 -0400258 if (DndTile.isVisible(mContext) && !DndTile.isCombinedIcon(mContext)
John Spurlocka48d7792015-03-03 17:35:57 -0500259 && audioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_SILENT) {
260 volumeVisible = true;
261 volumeIconId = R.drawable.stat_sys_ringer_silent;
262 volumeDescription = mContext.getString(R.string.accessibility_ringer_silent);
John Spurlock4f1163c2015-04-02 17:41:21 -0400263 } else if (mZen != Global.ZEN_MODE_NO_INTERRUPTIONS && mZen != Global.ZEN_MODE_ALARMS &&
John Spurlock661f2cf2014-11-17 10:29:10 -0500264 audioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_VIBRATE) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400265 volumeVisible = true;
266 volumeIconId = R.drawable.stat_sys_ringer_vibrate;
267 volumeDescription = mContext.getString(R.string.accessibility_ringer_vibrate);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 }
John Spurlocka37e9c82014-07-08 09:40:31 -0400269
270 if (zenVisible) {
Jason Monk3e189872016-01-12 09:10:34 -0500271 mIconController.setIcon(mSlotZen, zenIconId, zenDescription);
John Spurlocka37e9c82014-07-08 09:40:31 -0400272 }
273 if (zenVisible != mZenVisible) {
Jason Monk3e189872016-01-12 09:10:34 -0500274 mIconController.setIconVisibility(mSlotZen, zenVisible);
John Spurlocka37e9c82014-07-08 09:40:31 -0400275 mZenVisible = zenVisible;
276 }
277
278 if (volumeVisible) {
Jason Monk3e189872016-01-12 09:10:34 -0500279 mIconController.setIcon(mSlotVolume, volumeIconId, volumeDescription);
John Spurlocka37e9c82014-07-08 09:40:31 -0400280 }
281 if (volumeVisible != mVolumeVisible) {
Jason Monk3e189872016-01-12 09:10:34 -0500282 mIconController.setIconVisibility(mSlotVolume, volumeVisible);
John Spurlocka37e9c82014-07-08 09:40:31 -0400283 mVolumeVisible = volumeVisible;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800284 }
John Spurlock15782262015-05-29 15:35:53 -0400285 updateAlarm();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 }
287
Jason Monk70364362015-08-06 16:32:18 -0400288 @Override
289 public void onBluetoothDevicesChanged() {
290 updateBluetooth();
291 }
292
293 @Override
294 public void onBluetoothStateChange(boolean enabled) {
295 updateBluetooth();
296 }
297
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700298 private final void updateBluetooth() {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400299 int iconId = R.drawable.stat_sys_data_bluetooth;
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700300 String contentDescription =
Jason Monk1aa32822015-07-14 16:10:32 -0400301 mContext.getString(R.string.accessibility_quick_settings_bluetooth_on);
Jason Monk70364362015-08-06 16:32:18 -0400302 boolean bluetoothEnabled = false;
303 if (mBluetooth != null) {
304 bluetoothEnabled = mBluetooth.isBluetoothEnabled();
305 if (mBluetooth.isBluetoothConnected()) {
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -0700306 iconId = R.drawable.stat_sys_data_bluetooth_connected;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700307 contentDescription = mContext.getString(R.string.accessibility_bluetooth_connected);
Jaikumar Ganesh084c6652009-12-07 10:58:18 -0800308 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800309 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700310
Jason Monk3e189872016-01-12 09:10:34 -0500311 mIconController.setIcon(mSlotBluetooth, iconId, contentDescription);
312 mIconController.setIconVisibility(mSlotBluetooth, bluetoothEnabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800313 }
314
Wink Savillee9b06d72009-05-18 21:47:50 -0700315 private final void updateTTY(Intent intent) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700316 int currentTtyMode = intent.getIntExtra(TelecomManager.EXTRA_CURRENT_TTY_MODE,
317 TelecomManager.TTY_MODE_OFF);
318 boolean enabled = currentTtyMode != TelecomManager.TTY_MODE_OFF;
Wink Saville04e71b32009-04-02 11:00:54 -0700319
John Spurlocka37e9c82014-07-08 09:40:31 -0400320 if (DEBUG) Log.v(TAG, "updateTTY: enabled: " + enabled);
Wink Saville04e71b32009-04-02 11:00:54 -0700321
322 if (enabled) {
323 // TTY is on
John Spurlocka37e9c82014-07-08 09:40:31 -0400324 if (DEBUG) Log.v(TAG, "updateTTY: set TTY on");
Jason Monk3e189872016-01-12 09:10:34 -0500325 mIconController.setIcon(mSlotTty, R.drawable.stat_sys_tty_mode,
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700326 mContext.getString(R.string.accessibility_tty_enabled));
Jason Monk3e189872016-01-12 09:10:34 -0500327 mIconController.setIconVisibility(mSlotTty, true);
Wink Saville04e71b32009-04-02 11:00:54 -0700328 } else {
329 // TTY is off
John Spurlocka37e9c82014-07-08 09:40:31 -0400330 if (DEBUG) Log.v(TAG, "updateTTY: set TTY off");
Jason Monk3e189872016-01-12 09:10:34 -0500331 mIconController.setIconVisibility(mSlotTty, false);
Wink Saville04e71b32009-04-02 11:00:54 -0700332 }
333 }
John Spurlock96fe98d2014-08-27 09:36:02 -0400334
335 private void updateCast() {
336 boolean isCasting = false;
337 for (CastDevice device : mCast.getCastDevices()) {
338 if (device.state == CastDevice.STATE_CONNECTING
339 || device.state == CastDevice.STATE_CONNECTED) {
340 isCasting = true;
341 break;
342 }
343 }
344 if (DEBUG) Log.v(TAG, "updateCast: isCasting: " + isCasting);
Dan Sandler8fd25bf2015-10-20 16:01:27 -0700345 mHandler.removeCallbacks(mRemoveCastIconRunnable);
John Spurlock96fe98d2014-08-27 09:36:02 -0400346 if (isCasting) {
Jason Monk3e189872016-01-12 09:10:34 -0500347 mIconController.setIcon(mSlotCast, R.drawable.stat_sys_cast,
John Spurlock96fe98d2014-08-27 09:36:02 -0400348 mContext.getString(R.string.accessibility_casting));
Jason Monk3e189872016-01-12 09:10:34 -0500349 mIconController.setIconVisibility(mSlotCast, true);
Dan Sandler8fd25bf2015-10-20 16:01:27 -0700350 } else {
351 // don't turn off the screen-record icon for a few seconds, just to make sure the user
352 // has seen it
353 if (DEBUG) Log.v(TAG, "updateCast: hiding icon in 3 sec...");
354 mHandler.postDelayed(mRemoveCastIconRunnable, 3000);
John Spurlock96fe98d2014-08-27 09:36:02 -0400355 }
John Spurlock96fe98d2014-08-27 09:36:02 -0400356 }
357
Rubin Xu1205fb12015-11-04 17:45:03 +0000358 private void updateQuietState() {
359 mManagedProfileInQuietMode = false;
360 int currentUserId = ActivityManager.getCurrentUser();
361 for (UserInfo ui : mUserManager.getEnabledProfiles(currentUserId)) {
362 if (ui.isManagedProfile() && ui.isQuietModeEnabled()) {
363 mManagedProfileInQuietMode = true;
364 return;
365 }
366 }
367 }
368
Kenny Guy3094d4a2015-04-01 19:14:10 +0100369 private void profileChanged(int userId) {
Kenny Guy3094d4a2015-04-01 19:14:10 +0100370 UserInfo user = null;
371 if (userId == UserHandle.USER_CURRENT) {
372 try {
373 user = ActivityManagerNative.getDefault().getCurrentUser();
374 } catch (RemoteException e) {
375 // Ignore
376 }
377 } else {
Rubin Xu1205fb12015-11-04 17:45:03 +0000378 user = mUserManager.getUserInfo(userId);
Kenny Guy3094d4a2015-04-01 19:14:10 +0100379 }
380
381 mManagedProfileFocused = user != null && user.isManagedProfile();
382 if (DEBUG) Log.v(TAG, "profileChanged: mManagedProfileFocused: " + mManagedProfileFocused);
383 // Actually update the icon later when transition starts.
384 }
385
386 private void updateManagedProfile() {
387 if (DEBUG) Log.v(TAG, "updateManagedProfile: mManagedProfileFocused: "
388 + mManagedProfileFocused
389 + " mKeyguardVisible: " + mKeyguardVisible);
Rubin Xu1205fb12015-11-04 17:45:03 +0000390 final boolean showIcon;
391 if (mManagedProfileFocused && !mKeyguardVisible) {
392 showIcon = true;
Jason Monk3e189872016-01-12 09:10:34 -0500393 mIconController.setIcon(mSlotManagedProfile,
Jason Monk07473ce2016-01-05 14:59:19 -0500394 R.drawable.stat_sys_managed_profile_status,
Rubin Xu1205fb12015-11-04 17:45:03 +0000395 mContext.getString(R.string.accessibility_managed_profile));
396 } else if (mManagedProfileInQuietMode) {
397 showIcon = true;
Jason Monk3e189872016-01-12 09:10:34 -0500398 mIconController.setIcon(mSlotManagedProfile,
Jason Monk07473ce2016-01-05 14:59:19 -0500399 R.drawable.stat_sys_managed_profile_status_off,
Rubin Xu1205fb12015-11-04 17:45:03 +0000400 mContext.getString(R.string.accessibility_managed_profile));
401 } else {
402 showIcon = false;
403 }
Kenny Guy3094d4a2015-04-01 19:14:10 +0100404 if (mManagedProfileIconVisible != showIcon) {
Jason Monk3e189872016-01-12 09:10:34 -0500405 mIconController.setIconVisibility(mSlotManagedProfile, showIcon);
Kenny Guy3094d4a2015-04-01 19:14:10 +0100406 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) {
Jason Monk3e189872016-01-12 09:10:34 -0500434 mIconController.setIconVisibility(mSlotHotspot, enabled);
Jason Monk952d5d82014-10-27 15:28:22 -0400435 }
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 }
Jason Monk3e189872016-01-12 09:10:34 -0500460
461 @Override
462 public void onRotationLockStateChanged(boolean rotationLocked, boolean affordanceVisible) {
463 boolean portrait = RotationLockTile.isCurrentOrientationLockPortrait(
464 mRotationLockController, mContext);
465 if (rotationLocked) {
466 if (portrait) {
467 mIconController.setIcon(mSlotRotate, R.drawable.stat_sys_rotate_portrait,
468 mContext.getString(R.string.accessibility_rotation_lock_on_portrait));
469 } else {
470 mIconController.setIcon(mSlotRotate, R.drawable.stat_sys_rotate_landscape,
471 mContext.getString(R.string.accessibility_rotation_lock_on_landscape));
472 }
Jason Monk8816dff2016-02-09 21:50:36 -0500473 mIconController.setIconVisibility(mSlotRotate, true);
Jason Monk3e189872016-01-12 09:10:34 -0500474 } else {
Jason Monk8816dff2016-02-09 21:50:36 -0500475 mIconController.setIconVisibility(mSlotRotate, false);
Jason Monk3e189872016-01-12 09:10:34 -0500476 }
477 }
478
479 private void updateHeadsetPlug(Intent intent) {
480 boolean connected = intent.getIntExtra("state", 0) != 0;
481 boolean hasMic = intent.getIntExtra("microphone", 0) != 0;
482 if (connected) {
483 String contentDescription = mContext.getString(hasMic
484 ? R.string.accessibility_status_bar_headset
485 : R.string.accessibility_status_bar_headphones);
486 mIconController.setIcon(mSlotHeadset, hasMic ? R.drawable.ic_headset_mic
487 : R.drawable.ic_headset, contentDescription);
488 mIconController.setIconVisibility(mSlotHeadset, true);
489 } else {
490 mIconController.setIconVisibility(mSlotHeadset, false);
491 }
492 }
493
Jason Monkf23aa992016-01-22 16:45:21 -0500494 @Override
495 public void onDataSaverChanged(boolean isDataSaving) {
496 mIconController.setIconVisibility(mSlotDataSaver, isDataSaving);
497 }
498
Jason Monk3e189872016-01-12 09:10:34 -0500499 private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
500 @Override
501 public void onReceive(Context context, Intent intent) {
502 String action = intent.getAction();
503 if (action.equals(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED)) {
504 updateAlarm();
505 } else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION) ||
506 action.equals(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION)) {
507 updateVolumeZen();
508 } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
509 updateSimState(intent);
510 } else if (action.equals(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED)) {
511 updateTTY(intent);
Rubin Xue95057a2016-04-01 16:49:25 +0100512 } else if (action.equals(Intent.ACTION_MANAGED_PROFILE_AVAILABLE) ||
Nicolas Prevot6c7b8742016-04-13 10:28:58 +0100513 action.equals(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE) ||
514 action.equals(Intent.ACTION_MANAGED_PROFILE_REMOVED)) {
Jason Monk3e189872016-01-12 09:10:34 -0500515 updateQuietState();
516 updateManagedProfile();
517 } else if (action.equals(AudioManager.ACTION_HEADSET_PLUG)) {
518 updateHeadsetPlug(intent);
519 }
520 }
521 };
522
523 private Runnable mRemoveCastIconRunnable = new Runnable() {
524 @Override
525 public void run() {
526 if (DEBUG) Log.v(TAG, "updateCast: hiding icon NOW");
527 mIconController.setIconVisibility(mSlotCast, false);
528 }
529 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800530}