blob: 6550c87361643aeeccf5817a7cc8b36d0440453c [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 Monk952d5d82014-10-27 15:28:22 -040047import com.android.systemui.statusbar.policy.HotspotController;
Jason Monk3e189872016-01-12 09:10:34 -050048import com.android.systemui.statusbar.policy.RotationLockController;
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 Monk3e189872016-01-12 09:10:34 -050056public class PhoneStatusBarPolicy implements Callback, RotationLockController.RotationLockControllerCallback {
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
Jason Monk3e189872016-01-12 09:10:34 -050060 private final String mSlotCast;
61 private final String mSlotHotspot;
62 private final String mSlotBluetooth;
63 private final String mSlotTty;
64 private final String mSlotZen;
65 private final String mSlotVolume;
66 private final String mSlotAlarmClock;
67 private final String mSlotManagedProfile;
68 private final String mSlotRotate;
69 private final String mSlotHeadset;
John Spurlocka37e9c82014-07-08 09:40:31 -040070
Dianne Hackborn4840e142009-03-24 22:40:29 -070071 private final Context mContext;
Joe Onorato10523b4d2010-10-25 10:42:46 -070072 private final Handler mHandler = new Handler();
John Spurlock96fe98d2014-08-27 09:36:02 -040073 private final CastController mCast;
Jason Monk952d5d82014-10-27 15:28:22 -040074 private final HotspotController mHotspot;
John Spurlock15782262015-05-29 15:35:53 -040075 private final AlarmManager mAlarmManager;
Adrian Roos88b11932015-07-22 14:59:48 -070076 private final UserInfoController mUserInfoController;
Rubin Xu1205fb12015-11-04 17:45:03 +000077 private final UserManager mUserManager;
Jason Monk07473ce2016-01-05 14:59:19 -050078 private final StatusBarIconController mIconController;
Jason Monk3e189872016-01-12 09:10:34 -050079 private final RotationLockController mRotationLockController;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081 // Assume it's all good unless we hear otherwise. We don't always seem
82 // to get broadcasts that it *is* there.
Wink Savillea639b312012-07-10 12:37:54 -070083 IccCardConstants.State mSimState = IccCardConstants.State.READY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084
John Spurlocka37e9c82014-07-08 09:40:31 -040085 private boolean mZenVisible;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 private boolean mVolumeVisible;
John Spurlock604a5ee2015-06-01 12:27:22 -040087 private boolean mCurrentUserSetup;
Wink Saville04e71b32009-04-02 11:00:54 -070088
John Spurlockae641c92014-06-30 18:11:40 -040089 private int mZen;
John Spurlockba2c6a02014-05-19 09:44:06 -040090
Kenny Guy3094d4a2015-04-01 19:14:10 +010091 private boolean mManagedProfileFocused = false;
Rubin Xu1205fb12015-11-04 17:45:03 +000092 private boolean mManagedProfileIconVisible = false;
93 private boolean mManagedProfileInQuietMode = false;
Kenny Guy3094d4a2015-04-01 19:14:10 +010094
95 private boolean mKeyguardVisible = true;
Jason Monk70364362015-08-06 16:32:18 -040096 private BluetoothController mBluetooth;
Wink Savillee9b06d72009-05-18 21:47:50 -070097
Jason Monk07473ce2016-01-05 14:59:19 -050098 public PhoneStatusBarPolicy(Context context, StatusBarIconController iconController,
99 CastController cast, HotspotController hotspot, UserInfoController userInfoController,
Jason Monk3e189872016-01-12 09:10:34 -0500100 BluetoothController bluetooth, RotationLockController rotationLockController) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101 mContext = context;
Jason Monk07473ce2016-01-05 14:59:19 -0500102 mIconController = iconController;
John Spurlock96fe98d2014-08-27 09:36:02 -0400103 mCast = cast;
Jason Monk952d5d82014-10-27 15:28:22 -0400104 mHotspot = hotspot;
Jason Monk70364362015-08-06 16:32:18 -0400105 mBluetooth = bluetooth;
106 mBluetooth.addStateChangedCallback(this);
John Spurlock15782262015-05-29 15:35:53 -0400107 mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Adrian Roos88b11932015-07-22 14:59:48 -0700108 mUserInfoController = userInfoController;
Rubin Xu1205fb12015-11-04 17:45:03 +0000109 mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
Jason Monk3e189872016-01-12 09:10:34 -0500110 mRotationLockController = rotationLockController;
111
112 mSlotCast = context.getString(com.android.internal.R.string.status_bar_cast);
113 mSlotHotspot = context.getString(com.android.internal.R.string.status_bar_hotspot);
114 mSlotBluetooth = context.getString(com.android.internal.R.string.status_bar_bluetooth);
115 mSlotTty = context.getString(com.android.internal.R.string.status_bar_tty);
116 mSlotZen = context.getString(com.android.internal.R.string.status_bar_zen);
117 mSlotVolume = context.getString(com.android.internal.R.string.status_bar_volume);
118 mSlotAlarmClock = context.getString(com.android.internal.R.string.status_bar_alarm_clock);
119 mSlotManagedProfile = context.getString(
120 com.android.internal.R.string.status_bar_managed_profile);
121 mSlotRotate = context.getString(com.android.internal.R.string.status_bar_rotate);
122 mSlotHeadset = context.getString(com.android.internal.R.string.status_bar_headset);
123
124 mRotationLockController.addRotationLockControllerCallback(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400126 // listen for broadcasts
127 IntentFilter filter = new IntentFilter();
Adrian Roosc42a1e12014-07-07 23:35:53 +0200128 filter.addAction(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED);
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400129 filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
John Spurlockbcc10872014-11-28 15:29:21 -0500130 filter.addAction(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION);
Jason Monk3e189872016-01-12 09:10:34 -0500131 filter.addAction(AudioManager.ACTION_HEADSET_PLUG);
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400132 filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700133 filter.addAction(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED);
Rubin Xu1205fb12015-11-04 17:45:03 +0000134 filter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABILITY_CHANGED);
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400135 mContext.registerReceiver(mIntentReceiver, filter, null, mHandler);
136
Kenny Guy3094d4a2015-04-01 19:14:10 +0100137 // listen for user / profile change.
138 try {
139 ActivityManagerNative.getDefault().registerUserSwitchObserver(mUserSwitchListener);
140 } catch (RemoteException e) {
141 // Ignore
142 }
143
Wink Saville04e71b32009-04-02 11:00:54 -0700144 // TTY status
Jason Monk3e189872016-01-12 09:10:34 -0500145 mIconController.setIcon(mSlotTty, R.drawable.stat_sys_tty_mode, null);
146 mIconController.setIconVisibility(mSlotTty, false);
Wink Saville04e71b32009-04-02 11:00:54 -0700147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 // bluetooth status
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700149 updateBluetooth();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 // Alarm clock
Jason Monk3e189872016-01-12 09:10:34 -0500152 mIconController.setIcon(mSlotAlarmClock, R.drawable.stat_sys_alarm, null);
153 mIconController.setIconVisibility(mSlotAlarmClock, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154
John Spurlocka37e9c82014-07-08 09:40:31 -0400155 // zen
Jason Monk3e189872016-01-12 09:10:34 -0500156 mIconController.setIcon(mSlotZen, R.drawable.stat_sys_zen_important, null);
157 mIconController.setIconVisibility(mSlotZen, false);
John Spurlocka37e9c82014-07-08 09:40:31 -0400158
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159 // volume
Jason Monk3e189872016-01-12 09:10:34 -0500160 mIconController.setIcon(mSlotVolume, R.drawable.stat_sys_ringer_vibrate, null);
161 mIconController.setIconVisibility(mSlotVolume, false);
John Spurlocka37e9c82014-07-08 09:40:31 -0400162 updateVolumeZen();
John Spurlock96fe98d2014-08-27 09:36:02 -0400163
164 // cast
Jason Monk3e189872016-01-12 09:10:34 -0500165 mIconController.setIcon(mSlotCast, R.drawable.stat_sys_cast, null);
166 mIconController.setIconVisibility(mSlotCast, false);
John Spurlock96fe98d2014-08-27 09:36:02 -0400167 mCast.addCallback(mCastCallback);
Jason Monk952d5d82014-10-27 15:28:22 -0400168
169 // hotspot
Jason Monk3e189872016-01-12 09:10:34 -0500170 mIconController.setIcon(mSlotHotspot, R.drawable.stat_sys_hotspot,
Jason Monk08187a42015-06-09 14:33:51 -0400171 mContext.getString(R.string.accessibility_status_bar_hotspot));
Jason Monk3e189872016-01-12 09:10:34 -0500172 mIconController.setIconVisibility(mSlotHotspot, mHotspot.isHotspotEnabled());
Jason Monk952d5d82014-10-27 15:28:22 -0400173 mHotspot.addCallback(mHotspotCallback);
Kenny Guy3094d4a2015-04-01 19:14:10 +0100174
175 // managed profile
Jason Monk3e189872016-01-12 09:10:34 -0500176 mIconController.setIcon(mSlotManagedProfile, R.drawable.stat_sys_managed_profile_status,
Adrian Roos1b5eb972015-06-11 18:22:52 -0700177 mContext.getString(R.string.accessibility_managed_profile));
Jason Monk3e189872016-01-12 09:10:34 -0500178 mIconController.setIconVisibility(mSlotManagedProfile, mManagedProfileIconVisible);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179 }
180
John Spurlockae641c92014-06-30 18:11:40 -0400181 public void setZenMode(int zen) {
John Spurlockba2c6a02014-05-19 09:44:06 -0400182 mZen = zen;
John Spurlocka37e9c82014-07-08 09:40:31 -0400183 updateVolumeZen();
John Spurlockba2c6a02014-05-19 09:44:06 -0400184 }
185
Adrian Roosc42a1e12014-07-07 23:35:53 +0200186 private void updateAlarm() {
John Spurlock604a5ee2015-06-01 12:27:22 -0400187 final AlarmClockInfo alarm = mAlarmManager.getNextAlarmClock(UserHandle.USER_CURRENT);
188 final boolean hasAlarm = alarm != null && alarm.getTriggerTime() > 0;
John Spurlock15782262015-05-29 15:35:53 -0400189 final boolean zenNone = mZen == Global.ZEN_MODE_NO_INTERRUPTIONS;
Jason Monk3e189872016-01-12 09:10:34 -0500190 mIconController.setIcon(mSlotAlarmClock, zenNone ? R.drawable.stat_sys_alarm_dim
Jason Monk07473ce2016-01-05 14:59:19 -0500191 : R.drawable.stat_sys_alarm, null);
Jason Monk3e189872016-01-12 09:10:34 -0500192 mIconController.setIconVisibility(mSlotAlarmClock, mCurrentUserSetup && hasAlarm);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193 }
194
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195 private final void updateSimState(Intent intent) {
Wink Savillea639b312012-07-10 12:37:54 -0700196 String stateExtra = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
197 if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) {
198 mSimState = IccCardConstants.State.ABSENT;
Jason Monk07473ce2016-01-05 14:59:19 -0500199 } else if (IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR.equals(stateExtra)) {
Rakesh Pallerlaf099a5f2013-02-06 11:44:23 +0530200 mSimState = IccCardConstants.State.CARD_IO_ERROR;
Jason Monk07473ce2016-01-05 14:59:19 -0500201 } else if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(stateExtra)) {
Wink Savillea639b312012-07-10 12:37:54 -0700202 mSimState = IccCardConstants.State.READY;
Jason Monk07473ce2016-01-05 14:59:19 -0500203 } else if (IccCardConstants.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) {
Wink Savillea639b312012-07-10 12:37:54 -0700204 final String lockedReason =
205 intent.getStringExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON);
206 if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) {
207 mSimState = IccCardConstants.State.PIN_REQUIRED;
Jason Monk07473ce2016-01-05 14:59:19 -0500208 } else if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) {
Wink Savillea639b312012-07-10 12:37:54 -0700209 mSimState = IccCardConstants.State.PUK_REQUIRED;
Jason Monk07473ce2016-01-05 14:59:19 -0500210 } else {
Wink Savillea639b312012-07-10 12:37:54 -0700211 mSimState = IccCardConstants.State.NETWORK_LOCKED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212 }
213 } else {
Wink Savillea639b312012-07-10 12:37:54 -0700214 mSimState = IccCardConstants.State.UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800215 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 }
217
John Spurlockbcc10872014-11-28 15:29:21 -0500218 private final void updateVolumeZen() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219 AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
John Spurlocka37e9c82014-07-08 09:40:31 -0400220
221 boolean zenVisible = false;
222 int zenIconId = 0;
223 String zenDescription = null;
224
225 boolean volumeVisible = false;
226 int volumeIconId = 0;
227 String volumeDescription = null;
228
John Spurlockf88d8082015-03-25 18:09:51 -0400229 if (DndTile.isVisible(mContext) || DndTile.isCombinedIcon(mContext)) {
John Spurlock3c4076a2015-02-24 12:12:25 -0500230 zenVisible = mZen != Global.ZEN_MODE_OFF;
John Spurlock4ec8b602015-05-11 17:46:28 -0400231 zenIconId = mZen == Global.ZEN_MODE_NO_INTERRUPTIONS
232 ? R.drawable.stat_sys_dnd_total_silence : R.drawable.stat_sys_dnd;
John Spurlock3c4076a2015-02-24 12:12:25 -0500233 zenDescription = mContext.getString(R.string.quick_settings_dnd_label);
234 } else if (mZen == Global.ZEN_MODE_NO_INTERRUPTIONS) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400235 zenVisible = true;
236 zenIconId = R.drawable.stat_sys_zen_none;
John Spurlockd9c75db2015-04-28 11:19:13 -0400237 zenDescription = mContext.getString(R.string.interruption_level_none);
John Spurlockae641c92014-06-30 18:11:40 -0400238 } else if (mZen == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400239 zenVisible = true;
240 zenIconId = R.drawable.stat_sys_zen_important;
John Spurlockd9c75db2015-04-28 11:19:13 -0400241 zenDescription = mContext.getString(R.string.interruption_level_priority);
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700242 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800243
John Spurlockd9c75db2015-04-28 11:19:13 -0400244 if (DndTile.isVisible(mContext) && !DndTile.isCombinedIcon(mContext)
John Spurlocka48d7792015-03-03 17:35:57 -0500245 && audioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_SILENT) {
246 volumeVisible = true;
247 volumeIconId = R.drawable.stat_sys_ringer_silent;
248 volumeDescription = mContext.getString(R.string.accessibility_ringer_silent);
John Spurlock4f1163c2015-04-02 17:41:21 -0400249 } else if (mZen != Global.ZEN_MODE_NO_INTERRUPTIONS && mZen != Global.ZEN_MODE_ALARMS &&
John Spurlock661f2cf2014-11-17 10:29:10 -0500250 audioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_VIBRATE) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400251 volumeVisible = true;
252 volumeIconId = R.drawable.stat_sys_ringer_vibrate;
253 volumeDescription = mContext.getString(R.string.accessibility_ringer_vibrate);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800254 }
John Spurlocka37e9c82014-07-08 09:40:31 -0400255
256 if (zenVisible) {
Jason Monk3e189872016-01-12 09:10:34 -0500257 mIconController.setIcon(mSlotZen, zenIconId, zenDescription);
John Spurlocka37e9c82014-07-08 09:40:31 -0400258 }
259 if (zenVisible != mZenVisible) {
Jason Monk3e189872016-01-12 09:10:34 -0500260 mIconController.setIconVisibility(mSlotZen, zenVisible);
John Spurlocka37e9c82014-07-08 09:40:31 -0400261 mZenVisible = zenVisible;
262 }
263
264 if (volumeVisible) {
Jason Monk3e189872016-01-12 09:10:34 -0500265 mIconController.setIcon(mSlotVolume, volumeIconId, volumeDescription);
John Spurlocka37e9c82014-07-08 09:40:31 -0400266 }
267 if (volumeVisible != mVolumeVisible) {
Jason Monk3e189872016-01-12 09:10:34 -0500268 mIconController.setIconVisibility(mSlotVolume, volumeVisible);
John Spurlocka37e9c82014-07-08 09:40:31 -0400269 mVolumeVisible = volumeVisible;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270 }
John Spurlock15782262015-05-29 15:35:53 -0400271 updateAlarm();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272 }
273
Jason Monk70364362015-08-06 16:32:18 -0400274 @Override
275 public void onBluetoothDevicesChanged() {
276 updateBluetooth();
277 }
278
279 @Override
280 public void onBluetoothStateChange(boolean enabled) {
281 updateBluetooth();
282 }
283
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700284 private final void updateBluetooth() {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400285 int iconId = R.drawable.stat_sys_data_bluetooth;
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700286 String contentDescription =
Jason Monk1aa32822015-07-14 16:10:32 -0400287 mContext.getString(R.string.accessibility_quick_settings_bluetooth_on);
Jason Monk70364362015-08-06 16:32:18 -0400288 boolean bluetoothEnabled = false;
289 if (mBluetooth != null) {
290 bluetoothEnabled = mBluetooth.isBluetoothEnabled();
291 if (mBluetooth.isBluetoothConnected()) {
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -0700292 iconId = R.drawable.stat_sys_data_bluetooth_connected;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700293 contentDescription = mContext.getString(R.string.accessibility_bluetooth_connected);
Jaikumar Ganesh084c6652009-12-07 10:58:18 -0800294 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700296
Jason Monk3e189872016-01-12 09:10:34 -0500297 mIconController.setIcon(mSlotBluetooth, iconId, contentDescription);
298 mIconController.setIconVisibility(mSlotBluetooth, bluetoothEnabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800299 }
300
Wink Savillee9b06d72009-05-18 21:47:50 -0700301 private final void updateTTY(Intent intent) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700302 int currentTtyMode = intent.getIntExtra(TelecomManager.EXTRA_CURRENT_TTY_MODE,
303 TelecomManager.TTY_MODE_OFF);
304 boolean enabled = currentTtyMode != TelecomManager.TTY_MODE_OFF;
Wink Saville04e71b32009-04-02 11:00:54 -0700305
John Spurlocka37e9c82014-07-08 09:40:31 -0400306 if (DEBUG) Log.v(TAG, "updateTTY: enabled: " + enabled);
Wink Saville04e71b32009-04-02 11:00:54 -0700307
308 if (enabled) {
309 // TTY is on
John Spurlocka37e9c82014-07-08 09:40:31 -0400310 if (DEBUG) Log.v(TAG, "updateTTY: set TTY on");
Jason Monk3e189872016-01-12 09:10:34 -0500311 mIconController.setIcon(mSlotTty, R.drawable.stat_sys_tty_mode,
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700312 mContext.getString(R.string.accessibility_tty_enabled));
Jason Monk3e189872016-01-12 09:10:34 -0500313 mIconController.setIconVisibility(mSlotTty, true);
Wink Saville04e71b32009-04-02 11:00:54 -0700314 } else {
315 // TTY is off
John Spurlocka37e9c82014-07-08 09:40:31 -0400316 if (DEBUG) Log.v(TAG, "updateTTY: set TTY off");
Jason Monk3e189872016-01-12 09:10:34 -0500317 mIconController.setIconVisibility(mSlotTty, false);
Wink Saville04e71b32009-04-02 11:00:54 -0700318 }
319 }
John Spurlock96fe98d2014-08-27 09:36:02 -0400320
321 private void updateCast() {
322 boolean isCasting = false;
323 for (CastDevice device : mCast.getCastDevices()) {
324 if (device.state == CastDevice.STATE_CONNECTING
325 || device.state == CastDevice.STATE_CONNECTED) {
326 isCasting = true;
327 break;
328 }
329 }
330 if (DEBUG) Log.v(TAG, "updateCast: isCasting: " + isCasting);
Dan Sandler8fd25bf2015-10-20 16:01:27 -0700331 mHandler.removeCallbacks(mRemoveCastIconRunnable);
John Spurlock96fe98d2014-08-27 09:36:02 -0400332 if (isCasting) {
Jason Monk3e189872016-01-12 09:10:34 -0500333 mIconController.setIcon(mSlotCast, R.drawable.stat_sys_cast,
John Spurlock96fe98d2014-08-27 09:36:02 -0400334 mContext.getString(R.string.accessibility_casting));
Jason Monk3e189872016-01-12 09:10:34 -0500335 mIconController.setIconVisibility(mSlotCast, true);
Dan Sandler8fd25bf2015-10-20 16:01:27 -0700336 } else {
337 // don't turn off the screen-record icon for a few seconds, just to make sure the user
338 // has seen it
339 if (DEBUG) Log.v(TAG, "updateCast: hiding icon in 3 sec...");
340 mHandler.postDelayed(mRemoveCastIconRunnable, 3000);
John Spurlock96fe98d2014-08-27 09:36:02 -0400341 }
John Spurlock96fe98d2014-08-27 09:36:02 -0400342 }
343
Rubin Xu1205fb12015-11-04 17:45:03 +0000344 private void updateQuietState() {
345 mManagedProfileInQuietMode = false;
346 int currentUserId = ActivityManager.getCurrentUser();
347 for (UserInfo ui : mUserManager.getEnabledProfiles(currentUserId)) {
348 if (ui.isManagedProfile() && ui.isQuietModeEnabled()) {
349 mManagedProfileInQuietMode = true;
350 return;
351 }
352 }
353 }
354
Kenny Guy3094d4a2015-04-01 19:14:10 +0100355 private void profileChanged(int userId) {
Kenny Guy3094d4a2015-04-01 19:14:10 +0100356 UserInfo user = null;
357 if (userId == UserHandle.USER_CURRENT) {
358 try {
359 user = ActivityManagerNative.getDefault().getCurrentUser();
360 } catch (RemoteException e) {
361 // Ignore
362 }
363 } else {
Rubin Xu1205fb12015-11-04 17:45:03 +0000364 user = mUserManager.getUserInfo(userId);
Kenny Guy3094d4a2015-04-01 19:14:10 +0100365 }
366
367 mManagedProfileFocused = user != null && user.isManagedProfile();
368 if (DEBUG) Log.v(TAG, "profileChanged: mManagedProfileFocused: " + mManagedProfileFocused);
369 // Actually update the icon later when transition starts.
370 }
371
372 private void updateManagedProfile() {
373 if (DEBUG) Log.v(TAG, "updateManagedProfile: mManagedProfileFocused: "
374 + mManagedProfileFocused
375 + " mKeyguardVisible: " + mKeyguardVisible);
Rubin Xu1205fb12015-11-04 17:45:03 +0000376 final boolean showIcon;
377 if (mManagedProfileFocused && !mKeyguardVisible) {
378 showIcon = true;
Jason Monk3e189872016-01-12 09:10:34 -0500379 mIconController.setIcon(mSlotManagedProfile,
Jason Monk07473ce2016-01-05 14:59:19 -0500380 R.drawable.stat_sys_managed_profile_status,
Rubin Xu1205fb12015-11-04 17:45:03 +0000381 mContext.getString(R.string.accessibility_managed_profile));
382 } else if (mManagedProfileInQuietMode) {
383 showIcon = true;
Jason Monk3e189872016-01-12 09:10:34 -0500384 mIconController.setIcon(mSlotManagedProfile,
Jason Monk07473ce2016-01-05 14:59:19 -0500385 R.drawable.stat_sys_managed_profile_status_off,
Rubin Xu1205fb12015-11-04 17:45:03 +0000386 mContext.getString(R.string.accessibility_managed_profile));
387 } else {
388 showIcon = false;
389 }
Kenny Guy3094d4a2015-04-01 19:14:10 +0100390 if (mManagedProfileIconVisible != showIcon) {
Jason Monk3e189872016-01-12 09:10:34 -0500391 mIconController.setIconVisibility(mSlotManagedProfile, showIcon);
Kenny Guy3094d4a2015-04-01 19:14:10 +0100392 mManagedProfileIconVisible = showIcon;
393 }
394 }
395
Fyodor Kupolov6005b3f2015-11-23 17:41:50 -0800396 private final SynchronousUserSwitchObserver mUserSwitchListener =
397 new SynchronousUserSwitchObserver() {
Kenny Guy3094d4a2015-04-01 19:14:10 +0100398 @Override
Fyodor Kupolov6005b3f2015-11-23 17:41:50 -0800399 public void onUserSwitching(int newUserId) throws RemoteException {
Adrian Roos88b11932015-07-22 14:59:48 -0700400 mUserInfoController.reloadUserInfo();
Kenny Guy3094d4a2015-04-01 19:14:10 +0100401 }
402
403 @Override
404 public void onUserSwitchComplete(int newUserId) throws RemoteException {
405 updateAlarm();
406 profileChanged(newUserId);
Rubin Xu1205fb12015-11-04 17:45:03 +0000407 updateQuietState();
408 updateManagedProfile();
Kenny Guy3094d4a2015-04-01 19:14:10 +0100409 }
410
411 @Override
412 public void onForegroundProfileSwitch(int newProfileId) {
413 profileChanged(newProfileId);
414 }
415 };
416
Jason Monk952d5d82014-10-27 15:28:22 -0400417 private final HotspotController.Callback mHotspotCallback = new HotspotController.Callback() {
418 @Override
419 public void onHotspotChanged(boolean enabled) {
Jason Monk3e189872016-01-12 09:10:34 -0500420 mIconController.setIconVisibility(mSlotHotspot, enabled);
Jason Monk952d5d82014-10-27 15:28:22 -0400421 }
422 };
423
John Spurlock96fe98d2014-08-27 09:36:02 -0400424 private final CastController.Callback mCastCallback = new CastController.Callback() {
425 @Override
426 public void onCastDevicesChanged() {
427 updateCast();
428 }
429 };
Kenny Guy3094d4a2015-04-01 19:14:10 +0100430
431 public void appTransitionStarting(long startTime, long duration) {
432 updateManagedProfile();
433 }
434
435 public void setKeyguardShowing(boolean visible) {
436 mKeyguardVisible = visible;
437 updateManagedProfile();
438 }
John Spurlock604a5ee2015-06-01 12:27:22 -0400439
440 public void setCurrentUserSetup(boolean userSetup) {
441 if (mCurrentUserSetup == userSetup) return;
442 mCurrentUserSetup = userSetup;
443 updateAlarm();
Rubin Xu1205fb12015-11-04 17:45:03 +0000444 updateQuietState();
John Spurlock604a5ee2015-06-01 12:27:22 -0400445 }
Jason Monk3e189872016-01-12 09:10:34 -0500446
447 @Override
448 public void onRotationLockStateChanged(boolean rotationLocked, boolean affordanceVisible) {
449 boolean portrait = RotationLockTile.isCurrentOrientationLockPortrait(
450 mRotationLockController, mContext);
451 if (rotationLocked) {
452 if (portrait) {
453 mIconController.setIcon(mSlotRotate, R.drawable.stat_sys_rotate_portrait,
454 mContext.getString(R.string.accessibility_rotation_lock_on_portrait));
455 } else {
456 mIconController.setIcon(mSlotRotate, R.drawable.stat_sys_rotate_landscape,
457 mContext.getString(R.string.accessibility_rotation_lock_on_landscape));
458 }
Jason Monk8816dff2016-02-09 21:50:36 -0500459 mIconController.setIconVisibility(mSlotRotate, true);
Jason Monk3e189872016-01-12 09:10:34 -0500460 } else {
Jason Monk8816dff2016-02-09 21:50:36 -0500461 mIconController.setIconVisibility(mSlotRotate, false);
Jason Monk3e189872016-01-12 09:10:34 -0500462 }
463 }
464
465 private void updateHeadsetPlug(Intent intent) {
466 boolean connected = intent.getIntExtra("state", 0) != 0;
467 boolean hasMic = intent.getIntExtra("microphone", 0) != 0;
468 if (connected) {
469 String contentDescription = mContext.getString(hasMic
470 ? R.string.accessibility_status_bar_headset
471 : R.string.accessibility_status_bar_headphones);
472 mIconController.setIcon(mSlotHeadset, hasMic ? R.drawable.ic_headset_mic
473 : R.drawable.ic_headset, contentDescription);
474 mIconController.setIconVisibility(mSlotHeadset, true);
475 } else {
476 mIconController.setIconVisibility(mSlotHeadset, false);
477 }
478 }
479
480 private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
481 @Override
482 public void onReceive(Context context, Intent intent) {
483 String action = intent.getAction();
484 if (action.equals(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED)) {
485 updateAlarm();
486 } else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION) ||
487 action.equals(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION)) {
488 updateVolumeZen();
489 } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
490 updateSimState(intent);
491 } else if (action.equals(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED)) {
492 updateTTY(intent);
493 } else if (action.equals(Intent.ACTION_MANAGED_PROFILE_AVAILABILITY_CHANGED)) {
494 updateQuietState();
495 updateManagedProfile();
496 } else if (action.equals(AudioManager.ACTION_HEADSET_PLUG)) {
497 updateHeadsetPlug(intent);
498 }
499 }
500 };
501
502 private Runnable mRemoveCastIconRunnable = new Runnable() {
503 @Override
504 public void run() {
505 if (DEBUG) Log.v(TAG, "updateCast: hiding icon NOW");
506 mIconController.setIconVisibility(mSlotCast, false);
507 }
508 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800509}