blob: 37d61b945f80a36bd24b9b5be0d1dc3f19243f81 [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;
Wink Savillea639b312012-07-10 12:37:54 -070037import com.android.internal.telephony.IccCardConstants;
Wink Saville04e71b32009-04-02 11:00:54 -070038import com.android.internal.telephony.TelephonyIntents;
Joe Onorato798ac4c2010-05-27 16:39:00 -040039import com.android.systemui.R;
John Spurlock3c4076a2015-02-24 12:12:25 -050040import com.android.systemui.qs.tiles.DndTile;
Jason Monk3e189872016-01-12 09:10:34 -050041import com.android.systemui.qs.tiles.RotationLockTile;
Jason Monk70364362015-08-06 16:32:18 -040042import com.android.systemui.statusbar.policy.BluetoothController;
43import com.android.systemui.statusbar.policy.BluetoothController.Callback;
John Spurlock96fe98d2014-08-27 09:36:02 -040044import com.android.systemui.statusbar.policy.CastController;
45import com.android.systemui.statusbar.policy.CastController.CastDevice;
Jason Monk952d5d82014-10-27 15:28:22 -040046import com.android.systemui.statusbar.policy.HotspotController;
Jason Monk3e189872016-01-12 09:10:34 -050047import com.android.systemui.statusbar.policy.RotationLockController;
Adrian Roos88b11932015-07-22 14:59:48 -070048import com.android.systemui.statusbar.policy.UserInfoController;
Joe Onorato798ac4c2010-05-27 16:39:00 -040049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050/**
51 * This class contains all of the policy about which icons are installed in the status
Joe Onorato798ac4c2010-05-27 16:39:00 -040052 * bar at boot time. It goes through the normal API for icons, even though it probably
53 * strictly doesn't need to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054 */
Jason Monk3e189872016-01-12 09:10:34 -050055public class PhoneStatusBarPolicy implements Callback, RotationLockController.RotationLockControllerCallback {
Joe Onoratofd52b182010-11-10 18:00:52 -080056 private static final String TAG = "PhoneStatusBarPolicy";
John Spurlocka37e9c82014-07-08 09:40:31 -040057 private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Robert Greenwaltd7085fc2010-09-08 15:24:47 -070058
Jason Monk3e189872016-01-12 09:10:34 -050059 private final String mSlotCast;
60 private final String mSlotHotspot;
61 private final String mSlotBluetooth;
62 private final String mSlotTty;
63 private final String mSlotZen;
64 private final String mSlotVolume;
65 private final String mSlotAlarmClock;
66 private final String mSlotManagedProfile;
67 private final String mSlotRotate;
68 private final String mSlotHeadset;
John Spurlocka37e9c82014-07-08 09:40:31 -040069
Dianne Hackborn4840e142009-03-24 22:40:29 -070070 private final Context mContext;
Joe Onorato10523b4d2010-10-25 10:42:46 -070071 private final Handler mHandler = new Handler();
John Spurlock96fe98d2014-08-27 09:36:02 -040072 private final CastController mCast;
Jason Monk952d5d82014-10-27 15:28:22 -040073 private final HotspotController mHotspot;
John Spurlock15782262015-05-29 15:35:53 -040074 private final AlarmManager mAlarmManager;
Adrian Roos88b11932015-07-22 14:59:48 -070075 private final UserInfoController mUserInfoController;
Rubin Xu1205fb12015-11-04 17:45:03 +000076 private final UserManager mUserManager;
Jason Monk07473ce2016-01-05 14:59:19 -050077 private final StatusBarIconController mIconController;
Jason Monk3e189872016-01-12 09:10:34 -050078 private final RotationLockController mRotationLockController;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080 // Assume it's all good unless we hear otherwise. We don't always seem
81 // to get broadcasts that it *is* there.
Wink Savillea639b312012-07-10 12:37:54 -070082 IccCardConstants.State mSimState = IccCardConstants.State.READY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083
John Spurlocka37e9c82014-07-08 09:40:31 -040084 private boolean mZenVisible;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085 private boolean mVolumeVisible;
John Spurlock604a5ee2015-06-01 12:27:22 -040086 private boolean mCurrentUserSetup;
Wink Saville04e71b32009-04-02 11:00:54 -070087
John Spurlockae641c92014-06-30 18:11:40 -040088 private int mZen;
John Spurlockba2c6a02014-05-19 09:44:06 -040089
Kenny Guy3094d4a2015-04-01 19:14:10 +010090 private boolean mManagedProfileFocused = false;
Rubin Xu1205fb12015-11-04 17:45:03 +000091 private boolean mManagedProfileIconVisible = false;
92 private boolean mManagedProfileInQuietMode = false;
Kenny Guy3094d4a2015-04-01 19:14:10 +010093
94 private boolean mKeyguardVisible = true;
Jason Monk70364362015-08-06 16:32:18 -040095 private BluetoothController mBluetooth;
Wink Savillee9b06d72009-05-18 21:47:50 -070096
Jason Monk07473ce2016-01-05 14:59:19 -050097 public PhoneStatusBarPolicy(Context context, StatusBarIconController iconController,
98 CastController cast, HotspotController hotspot, UserInfoController userInfoController,
Jason Monk3e189872016-01-12 09:10:34 -050099 BluetoothController bluetooth, RotationLockController rotationLockController) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 mContext = context;
Jason Monk07473ce2016-01-05 14:59:19 -0500101 mIconController = iconController;
John Spurlock96fe98d2014-08-27 09:36:02 -0400102 mCast = cast;
Jason Monk952d5d82014-10-27 15:28:22 -0400103 mHotspot = hotspot;
Jason Monk70364362015-08-06 16:32:18 -0400104 mBluetooth = bluetooth;
105 mBluetooth.addStateChangedCallback(this);
John Spurlock15782262015-05-29 15:35:53 -0400106 mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Adrian Roos88b11932015-07-22 14:59:48 -0700107 mUserInfoController = userInfoController;
Rubin Xu1205fb12015-11-04 17:45:03 +0000108 mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
Jason Monk3e189872016-01-12 09:10:34 -0500109 mRotationLockController = rotationLockController;
110
111 mSlotCast = context.getString(com.android.internal.R.string.status_bar_cast);
112 mSlotHotspot = context.getString(com.android.internal.R.string.status_bar_hotspot);
113 mSlotBluetooth = context.getString(com.android.internal.R.string.status_bar_bluetooth);
114 mSlotTty = context.getString(com.android.internal.R.string.status_bar_tty);
115 mSlotZen = context.getString(com.android.internal.R.string.status_bar_zen);
116 mSlotVolume = context.getString(com.android.internal.R.string.status_bar_volume);
117 mSlotAlarmClock = context.getString(com.android.internal.R.string.status_bar_alarm_clock);
118 mSlotManagedProfile = context.getString(
119 com.android.internal.R.string.status_bar_managed_profile);
120 mSlotRotate = context.getString(com.android.internal.R.string.status_bar_rotate);
121 mSlotHeadset = context.getString(com.android.internal.R.string.status_bar_headset);
122
123 mRotationLockController.addRotationLockControllerCallback(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400125 // listen for broadcasts
126 IntentFilter filter = new IntentFilter();
Adrian Roosc42a1e12014-07-07 23:35:53 +0200127 filter.addAction(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED);
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400128 filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
John Spurlockbcc10872014-11-28 15:29:21 -0500129 filter.addAction(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION);
Jason Monk3e189872016-01-12 09:10:34 -0500130 filter.addAction(AudioManager.ACTION_HEADSET_PLUG);
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400131 filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700132 filter.addAction(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED);
Rubin Xu1205fb12015-11-04 17:45:03 +0000133 filter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABILITY_CHANGED);
Daniel Sandlere3b7a2d2011-10-27 16:16:15 -0400134 mContext.registerReceiver(mIntentReceiver, filter, null, mHandler);
135
Kenny Guy3094d4a2015-04-01 19:14:10 +0100136 // listen for user / profile change.
137 try {
138 ActivityManagerNative.getDefault().registerUserSwitchObserver(mUserSwitchListener);
139 } catch (RemoteException e) {
140 // Ignore
141 }
142
Wink Saville04e71b32009-04-02 11:00:54 -0700143 // TTY status
Jason Monk3e189872016-01-12 09:10:34 -0500144 mIconController.setIcon(mSlotTty, R.drawable.stat_sys_tty_mode, null);
145 mIconController.setIconVisibility(mSlotTty, false);
Wink Saville04e71b32009-04-02 11:00:54 -0700146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 // bluetooth status
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700148 updateBluetooth();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 // Alarm clock
Jason Monk3e189872016-01-12 09:10:34 -0500151 mIconController.setIcon(mSlotAlarmClock, R.drawable.stat_sys_alarm, null);
152 mIconController.setIconVisibility(mSlotAlarmClock, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153
John Spurlocka37e9c82014-07-08 09:40:31 -0400154 // zen
Jason Monk3e189872016-01-12 09:10:34 -0500155 mIconController.setIcon(mSlotZen, R.drawable.stat_sys_zen_important, null);
156 mIconController.setIconVisibility(mSlotZen, false);
John Spurlocka37e9c82014-07-08 09:40:31 -0400157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 // volume
Jason Monk3e189872016-01-12 09:10:34 -0500159 mIconController.setIcon(mSlotVolume, R.drawable.stat_sys_ringer_vibrate, null);
160 mIconController.setIconVisibility(mSlotVolume, false);
John Spurlocka37e9c82014-07-08 09:40:31 -0400161 updateVolumeZen();
John Spurlock96fe98d2014-08-27 09:36:02 -0400162
163 // cast
Jason Monk3e189872016-01-12 09:10:34 -0500164 mIconController.setIcon(mSlotCast, R.drawable.stat_sys_cast, null);
165 mIconController.setIconVisibility(mSlotCast, false);
John Spurlock96fe98d2014-08-27 09:36:02 -0400166 mCast.addCallback(mCastCallback);
Jason Monk952d5d82014-10-27 15:28:22 -0400167
168 // hotspot
Jason Monk3e189872016-01-12 09:10:34 -0500169 mIconController.setIcon(mSlotHotspot, R.drawable.stat_sys_hotspot,
Jason Monk08187a42015-06-09 14:33:51 -0400170 mContext.getString(R.string.accessibility_status_bar_hotspot));
Jason Monk3e189872016-01-12 09:10:34 -0500171 mIconController.setIconVisibility(mSlotHotspot, mHotspot.isHotspotEnabled());
Jason Monk952d5d82014-10-27 15:28:22 -0400172 mHotspot.addCallback(mHotspotCallback);
Kenny Guy3094d4a2015-04-01 19:14:10 +0100173
174 // managed profile
Jason Monk3e189872016-01-12 09:10:34 -0500175 mIconController.setIcon(mSlotManagedProfile, R.drawable.stat_sys_managed_profile_status,
Adrian Roos1b5eb972015-06-11 18:22:52 -0700176 mContext.getString(R.string.accessibility_managed_profile));
Jason Monk3e189872016-01-12 09:10:34 -0500177 mIconController.setIconVisibility(mSlotManagedProfile, mManagedProfileIconVisible);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 }
179
John Spurlockae641c92014-06-30 18:11:40 -0400180 public void setZenMode(int zen) {
John Spurlockba2c6a02014-05-19 09:44:06 -0400181 mZen = zen;
John Spurlocka37e9c82014-07-08 09:40:31 -0400182 updateVolumeZen();
John Spurlockba2c6a02014-05-19 09:44:06 -0400183 }
184
Adrian Roosc42a1e12014-07-07 23:35:53 +0200185 private void updateAlarm() {
John Spurlock604a5ee2015-06-01 12:27:22 -0400186 final AlarmClockInfo alarm = mAlarmManager.getNextAlarmClock(UserHandle.USER_CURRENT);
187 final boolean hasAlarm = alarm != null && alarm.getTriggerTime() > 0;
John Spurlock15782262015-05-29 15:35:53 -0400188 final boolean zenNone = mZen == Global.ZEN_MODE_NO_INTERRUPTIONS;
Jason Monk3e189872016-01-12 09:10:34 -0500189 mIconController.setIcon(mSlotAlarmClock, zenNone ? R.drawable.stat_sys_alarm_dim
Jason Monk07473ce2016-01-05 14:59:19 -0500190 : R.drawable.stat_sys_alarm, null);
Jason Monk3e189872016-01-12 09:10:34 -0500191 mIconController.setIconVisibility(mSlotAlarmClock, mCurrentUserSetup && hasAlarm);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800192 }
193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194 private final void updateSimState(Intent intent) {
Wink Savillea639b312012-07-10 12:37:54 -0700195 String stateExtra = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
196 if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) {
197 mSimState = IccCardConstants.State.ABSENT;
Jason Monk07473ce2016-01-05 14:59:19 -0500198 } else if (IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR.equals(stateExtra)) {
Rakesh Pallerlaf099a5f2013-02-06 11:44:23 +0530199 mSimState = IccCardConstants.State.CARD_IO_ERROR;
Jason Monk07473ce2016-01-05 14:59:19 -0500200 } else if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(stateExtra)) {
Wink Savillea639b312012-07-10 12:37:54 -0700201 mSimState = IccCardConstants.State.READY;
Jason Monk07473ce2016-01-05 14:59:19 -0500202 } else if (IccCardConstants.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) {
Wink Savillea639b312012-07-10 12:37:54 -0700203 final String lockedReason =
204 intent.getStringExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON);
205 if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) {
206 mSimState = IccCardConstants.State.PIN_REQUIRED;
Jason Monk07473ce2016-01-05 14:59:19 -0500207 } else if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) {
Wink Savillea639b312012-07-10 12:37:54 -0700208 mSimState = IccCardConstants.State.PUK_REQUIRED;
Jason Monk07473ce2016-01-05 14:59:19 -0500209 } else {
Wink Savillea639b312012-07-10 12:37:54 -0700210 mSimState = IccCardConstants.State.NETWORK_LOCKED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800211 }
212 } else {
Wink Savillea639b312012-07-10 12:37:54 -0700213 mSimState = IccCardConstants.State.UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800215 }
216
John Spurlockbcc10872014-11-28 15:29:21 -0500217 private final void updateVolumeZen() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800218 AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
John Spurlocka37e9c82014-07-08 09:40:31 -0400219
220 boolean zenVisible = false;
221 int zenIconId = 0;
222 String zenDescription = null;
223
224 boolean volumeVisible = false;
225 int volumeIconId = 0;
226 String volumeDescription = null;
227
John Spurlockf88d8082015-03-25 18:09:51 -0400228 if (DndTile.isVisible(mContext) || DndTile.isCombinedIcon(mContext)) {
John Spurlock3c4076a2015-02-24 12:12:25 -0500229 zenVisible = mZen != Global.ZEN_MODE_OFF;
John Spurlock4ec8b602015-05-11 17:46:28 -0400230 zenIconId = mZen == Global.ZEN_MODE_NO_INTERRUPTIONS
231 ? R.drawable.stat_sys_dnd_total_silence : R.drawable.stat_sys_dnd;
John Spurlock3c4076a2015-02-24 12:12:25 -0500232 zenDescription = mContext.getString(R.string.quick_settings_dnd_label);
233 } else if (mZen == Global.ZEN_MODE_NO_INTERRUPTIONS) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400234 zenVisible = true;
235 zenIconId = R.drawable.stat_sys_zen_none;
John Spurlockd9c75db2015-04-28 11:19:13 -0400236 zenDescription = mContext.getString(R.string.interruption_level_none);
John Spurlockae641c92014-06-30 18:11:40 -0400237 } else if (mZen == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400238 zenVisible = true;
239 zenIconId = R.drawable.stat_sys_zen_important;
John Spurlockd9c75db2015-04-28 11:19:13 -0400240 zenDescription = mContext.getString(R.string.interruption_level_priority);
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700241 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800242
John Spurlockd9c75db2015-04-28 11:19:13 -0400243 if (DndTile.isVisible(mContext) && !DndTile.isCombinedIcon(mContext)
John Spurlocka48d7792015-03-03 17:35:57 -0500244 && audioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_SILENT) {
245 volumeVisible = true;
246 volumeIconId = R.drawable.stat_sys_ringer_silent;
247 volumeDescription = mContext.getString(R.string.accessibility_ringer_silent);
John Spurlock4f1163c2015-04-02 17:41:21 -0400248 } else if (mZen != Global.ZEN_MODE_NO_INTERRUPTIONS && mZen != Global.ZEN_MODE_ALARMS &&
John Spurlock661f2cf2014-11-17 10:29:10 -0500249 audioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_VIBRATE) {
John Spurlocka37e9c82014-07-08 09:40:31 -0400250 volumeVisible = true;
251 volumeIconId = R.drawable.stat_sys_ringer_vibrate;
252 volumeDescription = mContext.getString(R.string.accessibility_ringer_vibrate);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800253 }
John Spurlocka37e9c82014-07-08 09:40:31 -0400254
255 if (zenVisible) {
Jason Monk3e189872016-01-12 09:10:34 -0500256 mIconController.setIcon(mSlotZen, zenIconId, zenDescription);
John Spurlocka37e9c82014-07-08 09:40:31 -0400257 }
258 if (zenVisible != mZenVisible) {
Jason Monk3e189872016-01-12 09:10:34 -0500259 mIconController.setIconVisibility(mSlotZen, zenVisible);
John Spurlocka37e9c82014-07-08 09:40:31 -0400260 mZenVisible = zenVisible;
261 }
262
263 if (volumeVisible) {
Jason Monk3e189872016-01-12 09:10:34 -0500264 mIconController.setIcon(mSlotVolume, volumeIconId, volumeDescription);
John Spurlocka37e9c82014-07-08 09:40:31 -0400265 }
266 if (volumeVisible != mVolumeVisible) {
Jason Monk3e189872016-01-12 09:10:34 -0500267 mIconController.setIconVisibility(mSlotVolume, volumeVisible);
John Spurlocka37e9c82014-07-08 09:40:31 -0400268 mVolumeVisible = volumeVisible;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800269 }
John Spurlock15782262015-05-29 15:35:53 -0400270 updateAlarm();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271 }
272
Jason Monk70364362015-08-06 16:32:18 -0400273 @Override
274 public void onBluetoothDevicesChanged() {
275 updateBluetooth();
276 }
277
278 @Override
279 public void onBluetoothStateChange(boolean enabled) {
280 updateBluetooth();
281 }
282
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700283 private final void updateBluetooth() {
Joe Onorato798ac4c2010-05-27 16:39:00 -0400284 int iconId = R.drawable.stat_sys_data_bluetooth;
Jorim Jaggi2d75f9f2014-10-08 17:10:58 -0700285 String contentDescription =
Jason Monk1aa32822015-07-14 16:10:32 -0400286 mContext.getString(R.string.accessibility_quick_settings_bluetooth_on);
Jason Monk70364362015-08-06 16:32:18 -0400287 boolean bluetoothEnabled = false;
288 if (mBluetooth != null) {
289 bluetoothEnabled = mBluetooth.isBluetoothEnabled();
290 if (mBluetooth.isBluetoothConnected()) {
Jaikumar Ganeshd9bb6882010-09-27 17:05:24 -0700291 iconId = R.drawable.stat_sys_data_bluetooth_connected;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700292 contentDescription = mContext.getString(R.string.accessibility_bluetooth_connected);
Jaikumar Ganesh084c6652009-12-07 10:58:18 -0800293 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800294 }
Wink Savillee9b06d72009-05-18 21:47:50 -0700295
Jason Monk3e189872016-01-12 09:10:34 -0500296 mIconController.setIcon(mSlotBluetooth, iconId, contentDescription);
297 mIconController.setIconVisibility(mSlotBluetooth, bluetoothEnabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800298 }
299
Wink Savillee9b06d72009-05-18 21:47:50 -0700300 private final void updateTTY(Intent intent) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700301 int currentTtyMode = intent.getIntExtra(TelecomManager.EXTRA_CURRENT_TTY_MODE,
302 TelecomManager.TTY_MODE_OFF);
303 boolean enabled = currentTtyMode != TelecomManager.TTY_MODE_OFF;
Wink Saville04e71b32009-04-02 11:00:54 -0700304
John Spurlocka37e9c82014-07-08 09:40:31 -0400305 if (DEBUG) Log.v(TAG, "updateTTY: enabled: " + enabled);
Wink Saville04e71b32009-04-02 11:00:54 -0700306
307 if (enabled) {
308 // TTY is on
John Spurlocka37e9c82014-07-08 09:40:31 -0400309 if (DEBUG) Log.v(TAG, "updateTTY: set TTY on");
Jason Monk3e189872016-01-12 09:10:34 -0500310 mIconController.setIcon(mSlotTty, R.drawable.stat_sys_tty_mode,
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700311 mContext.getString(R.string.accessibility_tty_enabled));
Jason Monk3e189872016-01-12 09:10:34 -0500312 mIconController.setIconVisibility(mSlotTty, true);
Wink Saville04e71b32009-04-02 11:00:54 -0700313 } else {
314 // TTY is off
John Spurlocka37e9c82014-07-08 09:40:31 -0400315 if (DEBUG) Log.v(TAG, "updateTTY: set TTY off");
Jason Monk3e189872016-01-12 09:10:34 -0500316 mIconController.setIconVisibility(mSlotTty, false);
Wink Saville04e71b32009-04-02 11:00:54 -0700317 }
318 }
John Spurlock96fe98d2014-08-27 09:36:02 -0400319
320 private void updateCast() {
321 boolean isCasting = false;
322 for (CastDevice device : mCast.getCastDevices()) {
323 if (device.state == CastDevice.STATE_CONNECTING
324 || device.state == CastDevice.STATE_CONNECTED) {
325 isCasting = true;
326 break;
327 }
328 }
329 if (DEBUG) Log.v(TAG, "updateCast: isCasting: " + isCasting);
Dan Sandler8fd25bf2015-10-20 16:01:27 -0700330 mHandler.removeCallbacks(mRemoveCastIconRunnable);
John Spurlock96fe98d2014-08-27 09:36:02 -0400331 if (isCasting) {
Jason Monk3e189872016-01-12 09:10:34 -0500332 mIconController.setIcon(mSlotCast, R.drawable.stat_sys_cast,
John Spurlock96fe98d2014-08-27 09:36:02 -0400333 mContext.getString(R.string.accessibility_casting));
Jason Monk3e189872016-01-12 09:10:34 -0500334 mIconController.setIconVisibility(mSlotCast, true);
Dan Sandler8fd25bf2015-10-20 16:01:27 -0700335 } else {
336 // don't turn off the screen-record icon for a few seconds, just to make sure the user
337 // has seen it
338 if (DEBUG) Log.v(TAG, "updateCast: hiding icon in 3 sec...");
339 mHandler.postDelayed(mRemoveCastIconRunnable, 3000);
John Spurlock96fe98d2014-08-27 09:36:02 -0400340 }
John Spurlock96fe98d2014-08-27 09:36:02 -0400341 }
342
Rubin Xu1205fb12015-11-04 17:45:03 +0000343 private void updateQuietState() {
344 mManagedProfileInQuietMode = false;
345 int currentUserId = ActivityManager.getCurrentUser();
346 for (UserInfo ui : mUserManager.getEnabledProfiles(currentUserId)) {
347 if (ui.isManagedProfile() && ui.isQuietModeEnabled()) {
348 mManagedProfileInQuietMode = true;
349 return;
350 }
351 }
352 }
353
Kenny Guy3094d4a2015-04-01 19:14:10 +0100354 private void profileChanged(int userId) {
Kenny Guy3094d4a2015-04-01 19:14:10 +0100355 UserInfo user = null;
356 if (userId == UserHandle.USER_CURRENT) {
357 try {
358 user = ActivityManagerNative.getDefault().getCurrentUser();
359 } catch (RemoteException e) {
360 // Ignore
361 }
362 } else {
Rubin Xu1205fb12015-11-04 17:45:03 +0000363 user = mUserManager.getUserInfo(userId);
Kenny Guy3094d4a2015-04-01 19:14:10 +0100364 }
365
366 mManagedProfileFocused = user != null && user.isManagedProfile();
367 if (DEBUG) Log.v(TAG, "profileChanged: mManagedProfileFocused: " + mManagedProfileFocused);
368 // Actually update the icon later when transition starts.
369 }
370
371 private void updateManagedProfile() {
372 if (DEBUG) Log.v(TAG, "updateManagedProfile: mManagedProfileFocused: "
373 + mManagedProfileFocused
374 + " mKeyguardVisible: " + mKeyguardVisible);
Rubin Xu1205fb12015-11-04 17:45:03 +0000375 final boolean showIcon;
376 if (mManagedProfileFocused && !mKeyguardVisible) {
377 showIcon = true;
Jason Monk3e189872016-01-12 09:10:34 -0500378 mIconController.setIcon(mSlotManagedProfile,
Jason Monk07473ce2016-01-05 14:59:19 -0500379 R.drawable.stat_sys_managed_profile_status,
Rubin Xu1205fb12015-11-04 17:45:03 +0000380 mContext.getString(R.string.accessibility_managed_profile));
381 } else if (mManagedProfileInQuietMode) {
382 showIcon = true;
Jason Monk3e189872016-01-12 09:10:34 -0500383 mIconController.setIcon(mSlotManagedProfile,
Jason Monk07473ce2016-01-05 14:59:19 -0500384 R.drawable.stat_sys_managed_profile_status_off,
Rubin Xu1205fb12015-11-04 17:45:03 +0000385 mContext.getString(R.string.accessibility_managed_profile));
386 } else {
387 showIcon = false;
388 }
Kenny Guy3094d4a2015-04-01 19:14:10 +0100389 if (mManagedProfileIconVisible != showIcon) {
Jason Monk3e189872016-01-12 09:10:34 -0500390 mIconController.setIconVisibility(mSlotManagedProfile, showIcon);
Kenny Guy3094d4a2015-04-01 19:14:10 +0100391 mManagedProfileIconVisible = showIcon;
392 }
393 }
394
Fyodor Kupolov6005b3f2015-11-23 17:41:50 -0800395 private final SynchronousUserSwitchObserver mUserSwitchListener =
396 new SynchronousUserSwitchObserver() {
Kenny Guy3094d4a2015-04-01 19:14:10 +0100397 @Override
Fyodor Kupolov6005b3f2015-11-23 17:41:50 -0800398 public void onUserSwitching(int newUserId) throws RemoteException {
Adrian Roos88b11932015-07-22 14:59:48 -0700399 mUserInfoController.reloadUserInfo();
Kenny Guy3094d4a2015-04-01 19:14:10 +0100400 }
401
402 @Override
403 public void onUserSwitchComplete(int newUserId) throws RemoteException {
404 updateAlarm();
405 profileChanged(newUserId);
Rubin Xu1205fb12015-11-04 17:45:03 +0000406 updateQuietState();
407 updateManagedProfile();
Kenny Guy3094d4a2015-04-01 19:14:10 +0100408 }
409
410 @Override
411 public void onForegroundProfileSwitch(int newProfileId) {
412 profileChanged(newProfileId);
413 }
414 };
415
Jason Monk952d5d82014-10-27 15:28:22 -0400416 private final HotspotController.Callback mHotspotCallback = new HotspotController.Callback() {
417 @Override
418 public void onHotspotChanged(boolean enabled) {
Jason Monk3e189872016-01-12 09:10:34 -0500419 mIconController.setIconVisibility(mSlotHotspot, enabled);
Jason Monk952d5d82014-10-27 15:28:22 -0400420 }
421 };
422
John Spurlock96fe98d2014-08-27 09:36:02 -0400423 private final CastController.Callback mCastCallback = new CastController.Callback() {
424 @Override
425 public void onCastDevicesChanged() {
426 updateCast();
427 }
428 };
Kenny Guy3094d4a2015-04-01 19:14:10 +0100429
430 public void appTransitionStarting(long startTime, long duration) {
431 updateManagedProfile();
432 }
433
434 public void setKeyguardShowing(boolean visible) {
435 mKeyguardVisible = visible;
436 updateManagedProfile();
437 }
John Spurlock604a5ee2015-06-01 12:27:22 -0400438
439 public void setCurrentUserSetup(boolean userSetup) {
440 if (mCurrentUserSetup == userSetup) return;
441 mCurrentUserSetup = userSetup;
442 updateAlarm();
Rubin Xu1205fb12015-11-04 17:45:03 +0000443 updateQuietState();
John Spurlock604a5ee2015-06-01 12:27:22 -0400444 }
Jason Monk3e189872016-01-12 09:10:34 -0500445
446 @Override
447 public void onRotationLockStateChanged(boolean rotationLocked, boolean affordanceVisible) {
448 boolean portrait = RotationLockTile.isCurrentOrientationLockPortrait(
449 mRotationLockController, mContext);
450 if (rotationLocked) {
451 if (portrait) {
452 mIconController.setIcon(mSlotRotate, R.drawable.stat_sys_rotate_portrait,
453 mContext.getString(R.string.accessibility_rotation_lock_on_portrait));
454 } else {
455 mIconController.setIcon(mSlotRotate, R.drawable.stat_sys_rotate_landscape,
456 mContext.getString(R.string.accessibility_rotation_lock_on_landscape));
457 }
458 } else {
459 mIconController.setIcon(mSlotRotate, portrait
460 ? R.drawable.stat_sys_auto_rotate_portrait
461 : R.drawable.stat_sys_auto_rotate_landscape,
462 mContext.getString(R.string.accessibility_rotation_lock_off));
463 }
464 }
465
466 private void updateHeadsetPlug(Intent intent) {
467 boolean connected = intent.getIntExtra("state", 0) != 0;
468 boolean hasMic = intent.getIntExtra("microphone", 0) != 0;
469 if (connected) {
470 String contentDescription = mContext.getString(hasMic
471 ? R.string.accessibility_status_bar_headset
472 : R.string.accessibility_status_bar_headphones);
473 mIconController.setIcon(mSlotHeadset, hasMic ? R.drawable.ic_headset_mic
474 : R.drawable.ic_headset, contentDescription);
475 mIconController.setIconVisibility(mSlotHeadset, true);
476 } else {
477 mIconController.setIconVisibility(mSlotHeadset, false);
478 }
479 }
480
481 private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
482 @Override
483 public void onReceive(Context context, Intent intent) {
484 String action = intent.getAction();
485 if (action.equals(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED)) {
486 updateAlarm();
487 } else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION) ||
488 action.equals(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION)) {
489 updateVolumeZen();
490 } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
491 updateSimState(intent);
492 } else if (action.equals(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED)) {
493 updateTTY(intent);
494 } else if (action.equals(Intent.ACTION_MANAGED_PROFILE_AVAILABILITY_CHANGED)) {
495 updateQuietState();
496 updateManagedProfile();
497 } else if (action.equals(AudioManager.ACTION_HEADSET_PLUG)) {
498 updateHeadsetPlug(intent);
499 }
500 }
501 };
502
503 private Runnable mRemoveCastIconRunnable = new Runnable() {
504 @Override
505 public void run() {
506 if (DEBUG) Log.v(TAG, "updateCast: hiding icon NOW");
507 mIconController.setIconVisibility(mSlotCast, false);
508 }
509 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510}