The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 17 | package com.android.systemui.statusbar.phone; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 19 | import android.annotation.Nullable; |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 20 | import android.app.ActivityTaskManager; |
Jason Monk | 697b82a | 2017-04-19 18:41:06 -0400 | [diff] [blame] | 21 | import android.app.AlarmManager; |
John Spurlock | 604a5ee | 2015-06-01 12:27:22 -0400 | [diff] [blame] | 22 | import android.app.AlarmManager.AlarmClockInfo; |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 23 | import android.app.IActivityManager; |
Jason Monk | 697b82a | 2017-04-19 18:41:06 -0400 | [diff] [blame] | 24 | import android.app.SynchronousUserSwitchObserver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | import android.content.BroadcastReceiver; |
| 26 | import android.content.Context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | import android.content.Intent; |
| 28 | import android.content.IntentFilter; |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 29 | import android.content.SharedPreferences; |
| 30 | import android.content.res.Resources; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import android.media.AudioManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import android.os.Handler; |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 33 | import android.os.RemoteException; |
Adrian Roos | c42a1e1 | 2014-07-07 23:35:53 +0200 | [diff] [blame] | 34 | import android.os.UserHandle; |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 35 | import android.os.UserManager; |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 36 | import android.provider.Settings.Global; |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 37 | import android.service.notification.ZenModeConfig; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 38 | import android.telecom.TelecomManager; |
Evan Laird | bee3eb8 | 2018-05-16 15:58:49 -0400 | [diff] [blame] | 39 | import android.text.format.DateFormat; |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 40 | import android.util.Log; |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 41 | |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 42 | import com.android.systemui.R; |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 43 | import com.android.systemui.broadcast.BroadcastDispatcher; |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 44 | import com.android.systemui.dagger.qualifiers.DisplayId; |
| 45 | import com.android.systemui.dagger.qualifiers.Main; |
Dave Mankoff | c7cf9fc | 2019-12-19 15:43:20 -0500 | [diff] [blame] | 46 | import com.android.systemui.dagger.qualifiers.UiBackground; |
John Spurlock | 3c4076a | 2015-02-24 12:12:25 -0500 | [diff] [blame] | 47 | import com.android.systemui.qs.tiles.DndTile; |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 48 | import com.android.systemui.qs.tiles.RotationLockTile; |
Beth Thibodeau | 8bfbf1f | 2020-02-13 13:55:37 -0500 | [diff] [blame] | 49 | import com.android.systemui.screenrecord.RecordingController; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 50 | import com.android.systemui.statusbar.CommandQueue; |
Jason Monk | 7036436 | 2015-08-06 16:32:18 -0400 | [diff] [blame] | 51 | import com.android.systemui.statusbar.policy.BluetoothController; |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 52 | import com.android.systemui.statusbar.policy.CastController; |
| 53 | import com.android.systemui.statusbar.policy.CastController.CastDevice; |
Jason Monk | f23aa99 | 2016-01-22 16:45:21 -0500 | [diff] [blame] | 54 | import com.android.systemui.statusbar.policy.DataSaverController; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 55 | import com.android.systemui.statusbar.policy.DataSaverController.Listener; |
| 56 | import com.android.systemui.statusbar.policy.DeviceProvisionedController; |
| 57 | import com.android.systemui.statusbar.policy.DeviceProvisionedController.DeviceProvisionedListener; |
Jason Monk | 952d5d8 | 2014-10-27 15:28:22 -0400 | [diff] [blame] | 58 | import com.android.systemui.statusbar.policy.HotspotController; |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 59 | import com.android.systemui.statusbar.policy.KeyguardStateController; |
Jason Monk | 359bb74 | 2017-04-13 10:40:40 -0400 | [diff] [blame] | 60 | import com.android.systemui.statusbar.policy.LocationController; |
Juan Flores | 2ff3720 | 2015-04-30 13:44:23 +0200 | [diff] [blame] | 61 | import com.android.systemui.statusbar.policy.NextAlarmController; |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 62 | import com.android.systemui.statusbar.policy.RotationLockController; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 63 | import com.android.systemui.statusbar.policy.RotationLockController.RotationLockControllerCallback; |
Michael Groover | a51ea81 | 2019-03-19 18:56:36 -0700 | [diff] [blame] | 64 | import com.android.systemui.statusbar.policy.SensorPrivacyController; |
Adrian Roos | 88b1193 | 2015-07-22 14:59:48 -0700 | [diff] [blame] | 65 | import com.android.systemui.statusbar.policy.UserInfoController; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 66 | import com.android.systemui.statusbar.policy.ZenModeController; |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 67 | import com.android.systemui.util.time.DateFormatUtil; |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 68 | |
Evan Laird | bee3eb8 | 2018-05-16 15:58:49 -0400 | [diff] [blame] | 69 | import java.util.Locale; |
Dave Mankoff | c7cf9fc | 2019-12-19 15:43:20 -0500 | [diff] [blame] | 70 | import java.util.concurrent.Executor; |
Jason Monk | 697b82a | 2017-04-19 18:41:06 -0400 | [diff] [blame] | 71 | |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 72 | import javax.inject.Inject; |
| 73 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | /** |
yoshiki iguchi | 69d6585 | 2019-02-13 18:07:41 +0900 | [diff] [blame] | 75 | * This class contains all of the policy about which icons are installed in the status bar at boot |
| 76 | * time. It goes through the normal API for icons, even though it probably strictly doesn't need to. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | */ |
yoshiki iguchi | 69d6585 | 2019-02-13 18:07:41 +0900 | [diff] [blame] | 78 | public class PhoneStatusBarPolicy |
| 79 | implements BluetoothController.Callback, |
| 80 | CommandQueue.Callbacks, |
| 81 | RotationLockControllerCallback, |
| 82 | Listener, |
| 83 | ZenModeController.Callback, |
| 84 | DeviceProvisionedListener, |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 85 | KeyguardStateController.Callback, |
Beth Thibodeau | 8bfbf1f | 2020-02-13 13:55:37 -0500 | [diff] [blame] | 86 | LocationController.LocationChangeCallback, |
| 87 | RecordingController.RecordingStateChangeCallback { |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 88 | private static final String TAG = "PhoneStatusBarPolicy"; |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 89 | private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 90 | |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 91 | static final int LOCATION_STATUS_ICON_ID = |
Fabian Kozynski | 228e310 | 2019-11-25 11:04:34 -0500 | [diff] [blame] | 92 | com.android.internal.R.drawable.perm_group_location; |
Jason Monk | 359bb74 | 2017-04-13 10:40:40 -0400 | [diff] [blame] | 93 | |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 94 | private final String mSlotCast; |
| 95 | private final String mSlotHotspot; |
| 96 | private final String mSlotBluetooth; |
| 97 | private final String mSlotTty; |
| 98 | private final String mSlotZen; |
| 99 | private final String mSlotVolume; |
| 100 | private final String mSlotAlarmClock; |
| 101 | private final String mSlotManagedProfile; |
| 102 | private final String mSlotRotate; |
| 103 | private final String mSlotHeadset; |
Jason Monk | f23aa99 | 2016-01-22 16:45:21 -0500 | [diff] [blame] | 104 | private final String mSlotDataSaver; |
Jason Monk | 359bb74 | 2017-04-13 10:40:40 -0400 | [diff] [blame] | 105 | private final String mSlotLocation; |
Michael Groover | a51ea81 | 2019-03-19 18:56:36 -0700 | [diff] [blame] | 106 | private final String mSlotSensorsOff; |
Beth Thibodeau | 8bfbf1f | 2020-02-13 13:55:37 -0500 | [diff] [blame] | 107 | private final String mSlotScreenRecord; |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 108 | private final int mDisplayId; |
| 109 | private final SharedPreferences mSharedPreferences; |
| 110 | private final DateFormatUtil mDateFormatUtil; |
| 111 | private final TelecomManager mTelecomManager; |
| 112 | private final AudioManager mAudioManager; |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 113 | |
Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 114 | private final Handler mHandler = new Handler(); |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 115 | private final CastController mCast; |
Jason Monk | 952d5d8 | 2014-10-27 15:28:22 -0400 | [diff] [blame] | 116 | private final HotspotController mHotspot; |
Evan Laird | bee3eb8 | 2018-05-16 15:58:49 -0400 | [diff] [blame] | 117 | private final NextAlarmController mNextAlarmController; |
John Spurlock | 1578226 | 2015-05-29 15:35:53 -0400 | [diff] [blame] | 118 | private final AlarmManager mAlarmManager; |
Adrian Roos | 88b1193 | 2015-07-22 14:59:48 -0700 | [diff] [blame] | 119 | private final UserInfoController mUserInfoController; |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 120 | private final IActivityManager mIActivityManager; |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 121 | private final UserManager mUserManager; |
Jason Monk | 07473ce | 2016-01-05 14:59:19 -0500 | [diff] [blame] | 122 | private final StatusBarIconController mIconController; |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 123 | private final CommandQueue mCommandQueue; |
| 124 | private final BroadcastDispatcher mBroadcastDispatcher; |
| 125 | private final Resources mResources; |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 126 | private final RotationLockController mRotationLockController; |
Jason Monk | f23aa99 | 2016-01-22 16:45:21 -0500 | [diff] [blame] | 127 | private final DataSaverController mDataSaver; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 128 | private final ZenModeController mZenController; |
| 129 | private final DeviceProvisionedController mProvisionedController; |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 130 | private final KeyguardStateController mKeyguardStateController; |
Jason Monk | 359bb74 | 2017-04-13 10:40:40 -0400 | [diff] [blame] | 131 | private final LocationController mLocationController; |
Dave Mankoff | c7cf9fc | 2019-12-19 15:43:20 -0500 | [diff] [blame] | 132 | private final Executor mUiBgExecutor; |
Michael Groover | a51ea81 | 2019-03-19 18:56:36 -0700 | [diff] [blame] | 133 | private final SensorPrivacyController mSensorPrivacyController; |
Beth Thibodeau | 8bfbf1f | 2020-02-13 13:55:37 -0500 | [diff] [blame] | 134 | private final RecordingController mRecordingController; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 136 | private boolean mZenVisible; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | private boolean mVolumeVisible; |
John Spurlock | 604a5ee | 2015-06-01 12:27:22 -0400 | [diff] [blame] | 138 | private boolean mCurrentUserSetup; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 139 | |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 140 | private boolean mManagedProfileIconVisible = false; |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 141 | |
Jason Monk | 7036436 | 2015-08-06 16:32:18 -0400 | [diff] [blame] | 142 | private BluetoothController mBluetooth; |
Evan Laird | bee3eb8 | 2018-05-16 15:58:49 -0400 | [diff] [blame] | 143 | private AlarmManager.AlarmClockInfo mNextAlarm; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 144 | |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 145 | @Inject |
| 146 | public PhoneStatusBarPolicy(StatusBarIconController iconController, |
Dave Mankoff | c7cf9fc | 2019-12-19 15:43:20 -0500 | [diff] [blame] | 147 | CommandQueue commandQueue, BroadcastDispatcher broadcastDispatcher, |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 148 | @UiBackground Executor uiBgExecutor, @Main Resources resources, |
| 149 | CastController castController, HotspotController hotspotController, |
| 150 | BluetoothController bluetoothController, NextAlarmController nextAlarmController, |
| 151 | UserInfoController userInfoController, RotationLockController rotationLockController, |
| 152 | DataSaverController dataSaverController, ZenModeController zenModeController, |
| 153 | DeviceProvisionedController deviceProvisionedController, |
| 154 | KeyguardStateController keyguardStateController, |
| 155 | LocationController locationController, |
| 156 | SensorPrivacyController sensorPrivacyController, IActivityManager iActivityManager, |
| 157 | AlarmManager alarmManager, UserManager userManager, AudioManager audioManager, |
| 158 | RecordingController recordingController, |
| 159 | @Nullable TelecomManager telecomManager, @DisplayId int displayId, |
| 160 | @Main SharedPreferences sharedPreferences, DateFormatUtil dateFormatUtil) { |
Jason Monk | 07473ce | 2016-01-05 14:59:19 -0500 | [diff] [blame] | 161 | mIconController = iconController; |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 162 | mCommandQueue = commandQueue; |
| 163 | mBroadcastDispatcher = broadcastDispatcher; |
| 164 | mResources = resources; |
| 165 | mCast = castController; |
| 166 | mHotspot = hotspotController; |
| 167 | mBluetooth = bluetoothController; |
| 168 | mNextAlarmController = nextAlarmController; |
| 169 | mAlarmManager = alarmManager; |
| 170 | mUserInfoController = userInfoController; |
| 171 | mIActivityManager = iActivityManager; |
| 172 | mUserManager = userManager; |
| 173 | mRotationLockController = rotationLockController; |
| 174 | mDataSaver = dataSaverController; |
| 175 | mZenController = zenModeController; |
| 176 | mProvisionedController = deviceProvisionedController; |
| 177 | mKeyguardStateController = keyguardStateController; |
| 178 | mLocationController = locationController; |
| 179 | mSensorPrivacyController = sensorPrivacyController; |
| 180 | mRecordingController = recordingController; |
Dave Mankoff | c7cf9fc | 2019-12-19 15:43:20 -0500 | [diff] [blame] | 181 | mUiBgExecutor = uiBgExecutor; |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 182 | mAudioManager = audioManager; |
| 183 | mTelecomManager = telecomManager; |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 184 | |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 185 | mSlotCast = resources.getString(com.android.internal.R.string.status_bar_cast); |
| 186 | mSlotHotspot = resources.getString(com.android.internal.R.string.status_bar_hotspot); |
| 187 | mSlotBluetooth = resources.getString(com.android.internal.R.string.status_bar_bluetooth); |
| 188 | mSlotTty = resources.getString(com.android.internal.R.string.status_bar_tty); |
| 189 | mSlotZen = resources.getString(com.android.internal.R.string.status_bar_zen); |
| 190 | mSlotVolume = resources.getString(com.android.internal.R.string.status_bar_volume); |
| 191 | mSlotAlarmClock = resources.getString(com.android.internal.R.string.status_bar_alarm_clock); |
| 192 | mSlotManagedProfile = resources.getString( |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 193 | com.android.internal.R.string.status_bar_managed_profile); |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 194 | mSlotRotate = resources.getString(com.android.internal.R.string.status_bar_rotate); |
| 195 | mSlotHeadset = resources.getString(com.android.internal.R.string.status_bar_headset); |
| 196 | mSlotDataSaver = resources.getString(com.android.internal.R.string.status_bar_data_saver); |
| 197 | mSlotLocation = resources.getString(com.android.internal.R.string.status_bar_location); |
| 198 | mSlotSensorsOff = resources.getString(com.android.internal.R.string.status_bar_sensors_off); |
| 199 | mSlotScreenRecord = resources.getString( |
Beth Thibodeau | 8bfbf1f | 2020-02-13 13:55:37 -0500 | [diff] [blame] | 200 | com.android.internal.R.string.status_bar_screen_record); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 201 | |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 202 | mDisplayId = displayId; |
| 203 | mSharedPreferences = sharedPreferences; |
| 204 | mDateFormatUtil = dateFormatUtil; |
| 205 | } |
| 206 | |
| 207 | /** Initialize the object after construction. */ |
| 208 | public void init() { |
Daniel Sandler | e3b7a2d | 2011-10-27 16:16:15 -0400 | [diff] [blame] | 209 | // listen for broadcasts |
| 210 | IntentFilter filter = new IntentFilter(); |
Daniel Sandler | e3b7a2d | 2011-10-27 16:16:15 -0400 | [diff] [blame] | 211 | filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); |
John Spurlock | bcc1087 | 2014-11-28 15:29:21 -0500 | [diff] [blame] | 212 | filter.addAction(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 213 | filter.addAction(AudioManager.ACTION_HEADSET_PLUG); |
Daniel Bright | 350f7f9 | 2020-01-22 14:24:11 -0800 | [diff] [blame] | 214 | filter.addAction(Intent.ACTION_SIM_STATE_CHANGED); |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 215 | filter.addAction(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED); |
Rubin Xu | e95057a | 2016-04-01 16:49:25 +0100 | [diff] [blame] | 216 | filter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE); |
| 217 | filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE); |
Nicolas Prevot | 6c7b874 | 2016-04-13 10:28:58 +0100 | [diff] [blame] | 218 | filter.addAction(Intent.ACTION_MANAGED_PROFILE_REMOVED); |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 219 | mBroadcastDispatcher.registerReceiverWithHandler(mIntentReceiver, filter, mHandler); |
Daniel Sandler | e3b7a2d | 2011-10-27 16:16:15 -0400 | [diff] [blame] | 220 | |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 221 | // listen for user / profile change. |
| 222 | try { |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 223 | mIActivityManager.registerUserSwitchObserver(mUserSwitchListener, TAG); |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 224 | } catch (RemoteException e) { |
| 225 | // Ignore |
| 226 | } |
| 227 | |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 228 | // TTY status |
Hall Liu | 108ca20 | 2017-07-24 15:19:04 -0700 | [diff] [blame] | 229 | updateTTY(); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 230 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 231 | // bluetooth status |
Jorim Jaggi | 2d75f9f | 2014-10-08 17:10:58 -0700 | [diff] [blame] | 232 | updateBluetooth(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 233 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 234 | // Alarm clock |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 235 | mIconController.setIcon(mSlotAlarmClock, R.drawable.stat_sys_alarm, null); |
| 236 | mIconController.setIconVisibility(mSlotAlarmClock, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 238 | // zen |
Amin Shaikh | 833bb0f | 2019-03-28 14:03:48 -0400 | [diff] [blame] | 239 | mIconController.setIcon(mSlotZen, R.drawable.stat_sys_dnd, null); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 240 | mIconController.setIconVisibility(mSlotZen, false); |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 241 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 242 | // volume |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 243 | mIconController.setIcon(mSlotVolume, R.drawable.stat_sys_ringer_vibrate, null); |
| 244 | mIconController.setIconVisibility(mSlotVolume, false); |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 245 | updateVolumeZen(); |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 246 | |
| 247 | // cast |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 248 | mIconController.setIcon(mSlotCast, R.drawable.stat_sys_cast, null); |
| 249 | mIconController.setIconVisibility(mSlotCast, false); |
Jason Monk | 952d5d8 | 2014-10-27 15:28:22 -0400 | [diff] [blame] | 250 | |
| 251 | // hotspot |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 252 | mIconController.setIcon(mSlotHotspot, R.drawable.stat_sys_hotspot, |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 253 | mResources.getString(R.string.accessibility_status_bar_hotspot)); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 254 | mIconController.setIconVisibility(mSlotHotspot, mHotspot.isHotspotEnabled()); |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 255 | |
| 256 | // managed profile |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 257 | mIconController.setIcon(mSlotManagedProfile, R.drawable.stat_sys_managed_profile_status, |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 258 | mResources.getString(R.string.accessibility_managed_profile)); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 259 | mIconController.setIconVisibility(mSlotManagedProfile, mManagedProfileIconVisible); |
Jason Monk | f23aa99 | 2016-01-22 16:45:21 -0500 | [diff] [blame] | 260 | |
| 261 | // data saver |
| 262 | mIconController.setIcon(mSlotDataSaver, R.drawable.stat_sys_data_saver, |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 263 | mResources.getString(R.string.accessibility_data_saver_on)); |
Jason Monk | f23aa99 | 2016-01-22 16:45:21 -0500 | [diff] [blame] | 264 | mIconController.setIconVisibility(mSlotDataSaver, false); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 265 | |
Fabian Kozynski | ed5dfd9 | 2018-12-20 15:00:48 -0500 | [diff] [blame] | 266 | mIconController.setIcon(mSlotLocation, LOCATION_STATUS_ICON_ID, |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 267 | mResources.getString(R.string.accessibility_location_active)); |
Fabian Kozynski | ed5dfd9 | 2018-12-20 15:00:48 -0500 | [diff] [blame] | 268 | mIconController.setIconVisibility(mSlotLocation, false); |
Evan Laird | cf1a103 | 2018-11-14 13:46:08 -0500 | [diff] [blame] | 269 | |
Michael Groover | a51ea81 | 2019-03-19 18:56:36 -0700 | [diff] [blame] | 270 | // sensors off |
Michael Groover | 1ddabcc | 2019-04-19 18:35:24 -0700 | [diff] [blame] | 271 | mIconController.setIcon(mSlotSensorsOff, R.drawable.stat_sys_sensors_off, |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 272 | mResources.getString(R.string.accessibility_sensors_off_active)); |
Michael Groover | a51ea81 | 2019-03-19 18:56:36 -0700 | [diff] [blame] | 273 | mIconController.setIconVisibility(mSlotSensorsOff, |
| 274 | mSensorPrivacyController.isSensorPrivacyEnabled()); |
| 275 | |
Beth Thibodeau | 8bfbf1f | 2020-02-13 13:55:37 -0500 | [diff] [blame] | 276 | // screen record |
| 277 | mIconController.setIcon(mSlotScreenRecord, R.drawable.stat_sys_screen_record, null); |
| 278 | mIconController.setIconVisibility(mSlotScreenRecord, false); |
| 279 | |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 280 | mRotationLockController.addCallback(this); |
| 281 | mBluetooth.addCallback(this); |
| 282 | mProvisionedController.addCallback(this); |
| 283 | mZenController.addCallback(this); |
| 284 | mCast.addCallback(mCastCallback); |
| 285 | mHotspot.addCallback(mHotspotCallback); |
Evan Laird | bee3eb8 | 2018-05-16 15:58:49 -0400 | [diff] [blame] | 286 | mNextAlarmController.addCallback(mNextAlarmCallback); |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 287 | mDataSaver.addCallback(this); |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 288 | mKeyguardStateController.addCallback(this); |
Michael Groover | a51ea81 | 2019-03-19 18:56:36 -0700 | [diff] [blame] | 289 | mSensorPrivacyController.addCallback(mSensorPrivacyListener); |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 290 | mLocationController.addCallback(this); |
Beth Thibodeau | 8bfbf1f | 2020-02-13 13:55:37 -0500 | [diff] [blame] | 291 | mRecordingController.addCallback(this); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 292 | |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 293 | mCommandQueue.addCallback(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 294 | } |
| 295 | |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 296 | @Override |
| 297 | public void onZenChanged(int zen) { |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 298 | updateVolumeZen(); |
John Spurlock | ba2c6a0 | 2014-05-19 09:44:06 -0400 | [diff] [blame] | 299 | } |
| 300 | |
Jason Monk | 359bb74 | 2017-04-13 10:40:40 -0400 | [diff] [blame] | 301 | @Override |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 302 | public void onConfigChanged(ZenModeConfig config) { |
| 303 | updateVolumeZen(); |
| 304 | } |
| 305 | |
Adrian Roos | c42a1e1 | 2014-07-07 23:35:53 +0200 | [diff] [blame] | 306 | private void updateAlarm() { |
John Spurlock | 604a5ee | 2015-06-01 12:27:22 -0400 | [diff] [blame] | 307 | final AlarmClockInfo alarm = mAlarmManager.getNextAlarmClock(UserHandle.USER_CURRENT); |
| 308 | final boolean hasAlarm = alarm != null && alarm.getTriggerTime() > 0; |
Jason Monk | 20c0eb4 | 2017-03-02 17:35:49 -0500 | [diff] [blame] | 309 | int zen = mZenController.getZen(); |
| 310 | final boolean zenNone = zen == Global.ZEN_MODE_NO_INTERRUPTIONS; |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 311 | mIconController.setIcon(mSlotAlarmClock, zenNone ? R.drawable.stat_sys_alarm_dim |
Evan Laird | bee3eb8 | 2018-05-16 15:58:49 -0400 | [diff] [blame] | 312 | : R.drawable.stat_sys_alarm, buildAlarmContentDescription()); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 313 | mIconController.setIconVisibility(mSlotAlarmClock, mCurrentUserSetup && hasAlarm); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 314 | } |
| 315 | |
Evan Laird | bee3eb8 | 2018-05-16 15:58:49 -0400 | [diff] [blame] | 316 | private String buildAlarmContentDescription() { |
| 317 | if (mNextAlarm == null) { |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 318 | return mResources.getString(R.string.status_bar_alarm); |
Evan Laird | bee3eb8 | 2018-05-16 15:58:49 -0400 | [diff] [blame] | 319 | } |
Evan Laird | bee3eb8 | 2018-05-16 15:58:49 -0400 | [diff] [blame] | 320 | |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 321 | String skeleton = mDateFormatUtil.is24HourFormat() ? "EHm" : "Ehma"; |
Evan Laird | bee3eb8 | 2018-05-16 15:58:49 -0400 | [diff] [blame] | 322 | String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton); |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 323 | String dateString = DateFormat.format(pattern, mNextAlarm.getTriggerTime()).toString(); |
Evan Laird | bee3eb8 | 2018-05-16 15:58:49 -0400 | [diff] [blame] | 324 | |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 325 | return mResources.getString(R.string.accessibility_quick_settings_alarm, dateString); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 326 | } |
| 327 | |
John Spurlock | bcc1087 | 2014-11-28 15:29:21 -0500 | [diff] [blame] | 328 | private final void updateVolumeZen() { |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 329 | boolean zenVisible = false; |
| 330 | int zenIconId = 0; |
| 331 | String zenDescription = null; |
| 332 | |
| 333 | boolean volumeVisible = false; |
| 334 | int volumeIconId = 0; |
| 335 | String volumeDescription = null; |
Jason Monk | 20c0eb4 | 2017-03-02 17:35:49 -0500 | [diff] [blame] | 336 | int zen = mZenController.getZen(); |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 337 | |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 338 | if (DndTile.isVisible(mSharedPreferences) || DndTile.isCombinedIcon(mSharedPreferences)) { |
Jason Monk | 20c0eb4 | 2017-03-02 17:35:49 -0500 | [diff] [blame] | 339 | zenVisible = zen != Global.ZEN_MODE_OFF; |
Evan Laird | a9adbd5 | 2018-05-16 11:32:08 -0400 | [diff] [blame] | 340 | zenIconId = R.drawable.stat_sys_dnd; |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 341 | zenDescription = mResources.getString(R.string.quick_settings_dnd_label); |
Jason Monk | 20c0eb4 | 2017-03-02 17:35:49 -0500 | [diff] [blame] | 342 | } else if (zen == Global.ZEN_MODE_NO_INTERRUPTIONS) { |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 343 | zenVisible = true; |
Amin Shaikh | 833bb0f | 2019-03-28 14:03:48 -0400 | [diff] [blame] | 344 | zenIconId = R.drawable.stat_sys_dnd; |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 345 | zenDescription = mResources.getString(R.string.interruption_level_none); |
Jason Monk | 20c0eb4 | 2017-03-02 17:35:49 -0500 | [diff] [blame] | 346 | } else if (zen == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS) { |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 347 | zenVisible = true; |
Amin Shaikh | 833bb0f | 2019-03-28 14:03:48 -0400 | [diff] [blame] | 348 | zenIconId = R.drawable.stat_sys_dnd; |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 349 | zenDescription = mResources.getString(R.string.interruption_level_priority); |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 350 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 351 | |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 352 | if (!ZenModeConfig.isZenOverridingRinger(zen, mZenController.getConsolidatedPolicy())) { |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 353 | if (mAudioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_VIBRATE) { |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 354 | volumeVisible = true; |
| 355 | volumeIconId = R.drawable.stat_sys_ringer_vibrate; |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 356 | volumeDescription = mResources.getString(R.string.accessibility_ringer_vibrate); |
| 357 | } else if (mAudioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_SILENT) { |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 358 | volumeVisible = true; |
| 359 | volumeIconId = R.drawable.stat_sys_ringer_silent; |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 360 | volumeDescription = mResources.getString(R.string.accessibility_ringer_silent); |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 361 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 362 | } |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 363 | |
| 364 | if (zenVisible) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 365 | mIconController.setIcon(mSlotZen, zenIconId, zenDescription); |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 366 | } |
| 367 | if (zenVisible != mZenVisible) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 368 | mIconController.setIconVisibility(mSlotZen, zenVisible); |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 369 | mZenVisible = zenVisible; |
| 370 | } |
| 371 | |
| 372 | if (volumeVisible) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 373 | mIconController.setIcon(mSlotVolume, volumeIconId, volumeDescription); |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 374 | } |
| 375 | if (volumeVisible != mVolumeVisible) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 376 | mIconController.setIconVisibility(mSlotVolume, volumeVisible); |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 377 | mVolumeVisible = volumeVisible; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 378 | } |
John Spurlock | 1578226 | 2015-05-29 15:35:53 -0400 | [diff] [blame] | 379 | updateAlarm(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 380 | } |
| 381 | |
Jason Monk | 7036436 | 2015-08-06 16:32:18 -0400 | [diff] [blame] | 382 | @Override |
| 383 | public void onBluetoothDevicesChanged() { |
| 384 | updateBluetooth(); |
| 385 | } |
| 386 | |
| 387 | @Override |
| 388 | public void onBluetoothStateChange(boolean enabled) { |
| 389 | updateBluetooth(); |
| 390 | } |
| 391 | |
Jorim Jaggi | 2d75f9f | 2014-10-08 17:10:58 -0700 | [diff] [blame] | 392 | private final void updateBluetooth() { |
Amin Shaikh | ad29e93 | 2019-03-08 11:26:12 -0500 | [diff] [blame] | 393 | int iconId = R.drawable.stat_sys_data_bluetooth_connected; |
Jorim Jaggi | 2d75f9f | 2014-10-08 17:10:58 -0700 | [diff] [blame] | 394 | String contentDescription = |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 395 | mResources.getString(R.string.accessibility_quick_settings_bluetooth_on); |
Evan Laird | 3cdf47e | 2018-01-29 16:01:41 -0500 | [diff] [blame] | 396 | boolean bluetoothVisible = false; |
Jason Monk | 7036436 | 2015-08-06 16:32:18 -0400 | [diff] [blame] | 397 | if (mBluetooth != null) { |
Ugo Yu | 40f0880 | 2019-11-19 09:56:40 +0800 | [diff] [blame] | 398 | if (mBluetooth.isBluetoothConnected() |
| 399 | && (mBluetooth.isBluetoothAudioActive() |
| 400 | || !mBluetooth.isBluetoothAudioProfileOnly())) { |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 401 | contentDescription = mResources.getString( |
Ugo Yu | 40f0880 | 2019-11-19 09:56:40 +0800 | [diff] [blame] | 402 | R.string.accessibility_bluetooth_connected); |
Evan Laird | 3cdf47e | 2018-01-29 16:01:41 -0500 | [diff] [blame] | 403 | bluetoothVisible = mBluetooth.isBluetoothEnabled(); |
Jaikumar Ganesh | 084c665 | 2009-12-07 10:58:18 -0800 | [diff] [blame] | 404 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 405 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 406 | |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 407 | mIconController.setIcon(mSlotBluetooth, iconId, contentDescription); |
Evan Laird | 3cdf47e | 2018-01-29 16:01:41 -0500 | [diff] [blame] | 408 | mIconController.setIconVisibility(mSlotBluetooth, bluetoothVisible); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 409 | } |
| 410 | |
Hall Liu | 108ca20 | 2017-07-24 15:19:04 -0700 | [diff] [blame] | 411 | private final void updateTTY() { |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 412 | if (mTelecomManager == null) { |
Hall Liu | 108ca20 | 2017-07-24 15:19:04 -0700 | [diff] [blame] | 413 | updateTTY(TelecomManager.TTY_MODE_OFF); |
| 414 | } else { |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 415 | updateTTY(mTelecomManager.getCurrentTtyMode()); |
Hall Liu | 108ca20 | 2017-07-24 15:19:04 -0700 | [diff] [blame] | 416 | } |
| 417 | } |
| 418 | |
| 419 | private final void updateTTY(int currentTtyMode) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 420 | boolean enabled = currentTtyMode != TelecomManager.TTY_MODE_OFF; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 421 | |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 422 | if (DEBUG) Log.v(TAG, "updateTTY: enabled: " + enabled); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 423 | |
| 424 | if (enabled) { |
| 425 | // TTY is on |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 426 | if (DEBUG) Log.v(TAG, "updateTTY: set TTY on"); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 427 | mIconController.setIcon(mSlotTty, R.drawable.stat_sys_tty_mode, |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 428 | mResources.getString(R.string.accessibility_tty_enabled)); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 429 | mIconController.setIconVisibility(mSlotTty, true); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 430 | } else { |
| 431 | // TTY is off |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 432 | if (DEBUG) Log.v(TAG, "updateTTY: set TTY off"); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 433 | mIconController.setIconVisibility(mSlotTty, false); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 434 | } |
| 435 | } |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 436 | |
| 437 | private void updateCast() { |
| 438 | boolean isCasting = false; |
| 439 | for (CastDevice device : mCast.getCastDevices()) { |
| 440 | if (device.state == CastDevice.STATE_CONNECTING |
| 441 | || device.state == CastDevice.STATE_CONNECTED) { |
| 442 | isCasting = true; |
| 443 | break; |
| 444 | } |
| 445 | } |
| 446 | if (DEBUG) Log.v(TAG, "updateCast: isCasting: " + isCasting); |
Dan Sandler | 8fd25bf | 2015-10-20 16:01:27 -0700 | [diff] [blame] | 447 | mHandler.removeCallbacks(mRemoveCastIconRunnable); |
Beth Thibodeau | 8bfbf1f | 2020-02-13 13:55:37 -0500 | [diff] [blame] | 448 | if (isCasting && !mRecordingController.isRecording()) { // screen record has its own icon |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 449 | mIconController.setIcon(mSlotCast, R.drawable.stat_sys_cast, |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 450 | mResources.getString(R.string.accessibility_casting)); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 451 | mIconController.setIconVisibility(mSlotCast, true); |
Dan Sandler | 8fd25bf | 2015-10-20 16:01:27 -0700 | [diff] [blame] | 452 | } else { |
| 453 | // don't turn off the screen-record icon for a few seconds, just to make sure the user |
| 454 | // has seen it |
| 455 | if (DEBUG) Log.v(TAG, "updateCast: hiding icon in 3 sec..."); |
| 456 | mHandler.postDelayed(mRemoveCastIconRunnable, 3000); |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 457 | } |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 458 | } |
| 459 | |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 460 | private void updateManagedProfile() { |
Jorim Jaggi | fabc743 | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 461 | // getLastResumedActivityUserId needds to acquire the AM lock, which may be contended in |
| 462 | // some cases. Since it doesn't really matter here whether it's updated in this frame |
| 463 | // or in the next one, we call this method from our UI offload thread. |
Dave Mankoff | c7cf9fc | 2019-12-19 15:43:20 -0500 | [diff] [blame] | 464 | mUiBgExecutor.execute(() -> { |
Jorim Jaggi | fabc743 | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 465 | final int userId; |
| 466 | try { |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 467 | userId = ActivityTaskManager.getService().getLastResumedActivityUserId(); |
Jorim Jaggi | fabc743 | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 468 | boolean isManagedProfile = mUserManager.isManagedProfile(userId); |
| 469 | mHandler.post(() -> { |
| 470 | final boolean showIcon; |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 471 | if (isManagedProfile && (!mKeyguardStateController.isShowing() |
| 472 | || mKeyguardStateController.isOccluded())) { |
Jorim Jaggi | fabc743 | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 473 | showIcon = true; |
| 474 | mIconController.setIcon(mSlotManagedProfile, |
| 475 | R.drawable.stat_sys_managed_profile_status, |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 476 | mResources.getString(R.string.accessibility_managed_profile)); |
Jorim Jaggi | fabc743 | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 477 | } else { |
| 478 | showIcon = false; |
| 479 | } |
| 480 | if (mManagedProfileIconVisible != showIcon) { |
| 481 | mIconController.setIconVisibility(mSlotManagedProfile, showIcon); |
| 482 | mManagedProfileIconVisible = showIcon; |
| 483 | } |
| 484 | }); |
| 485 | } catch (RemoteException e) { |
| 486 | Log.w(TAG, "updateManagedProfile: ", e); |
Tony Mak | ec319ab | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 487 | } |
Jorim Jaggi | fabc743 | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 488 | }); |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 489 | } |
| 490 | |
Fyodor Kupolov | 6005b3f | 2015-11-23 17:41:50 -0800 | [diff] [blame] | 491 | private final SynchronousUserSwitchObserver mUserSwitchListener = |
| 492 | new SynchronousUserSwitchObserver() { |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 493 | @Override |
Fyodor Kupolov | 6005b3f | 2015-11-23 17:41:50 -0800 | [diff] [blame] | 494 | public void onUserSwitching(int newUserId) throws RemoteException { |
Tony Mak | ec319ab | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 495 | mHandler.post(() -> mUserInfoController.reloadUserInfo()); |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | @Override |
| 499 | public void onUserSwitchComplete(int newUserId) throws RemoteException { |
Tony Mak | ec319ab | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 500 | mHandler.post(() -> { |
| 501 | updateAlarm(); |
Tony Mak | ec319ab | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 502 | updateManagedProfile(); |
Toni Barzic | e97f923 | 2016-04-27 18:10:58 -0700 | [diff] [blame] | 503 | }); |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 504 | } |
| 505 | }; |
| 506 | |
Jason Monk | 952d5d8 | 2014-10-27 15:28:22 -0400 | [diff] [blame] | 507 | private final HotspotController.Callback mHotspotCallback = new HotspotController.Callback() { |
| 508 | @Override |
Rohan Shah | e407112 | 2018-01-22 15:16:09 -0800 | [diff] [blame] | 509 | public void onHotspotChanged(boolean enabled, int numDevices) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 510 | mIconController.setIconVisibility(mSlotHotspot, enabled); |
Jason Monk | 952d5d8 | 2014-10-27 15:28:22 -0400 | [diff] [blame] | 511 | } |
| 512 | }; |
| 513 | |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 514 | private final CastController.Callback mCastCallback = new CastController.Callback() { |
| 515 | @Override |
| 516 | public void onCastDevicesChanged() { |
| 517 | updateCast(); |
| 518 | } |
| 519 | }; |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 520 | |
Juan Flores | 2ff3720 | 2015-04-30 13:44:23 +0200 | [diff] [blame] | 521 | private final NextAlarmController.NextAlarmChangeCallback mNextAlarmCallback = |
| 522 | new NextAlarmController.NextAlarmChangeCallback() { |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 523 | @Override |
| 524 | public void onNextAlarmChanged(AlarmManager.AlarmClockInfo nextAlarm) { |
Evan Laird | bee3eb8 | 2018-05-16 15:58:49 -0400 | [diff] [blame] | 525 | mNextAlarm = nextAlarm; |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 526 | updateAlarm(); |
| 527 | } |
| 528 | }; |
Juan Flores | 2ff3720 | 2015-04-30 13:44:23 +0200 | [diff] [blame] | 529 | |
Michael Groover | a51ea81 | 2019-03-19 18:56:36 -0700 | [diff] [blame] | 530 | private final SensorPrivacyController.OnSensorPrivacyChangedListener mSensorPrivacyListener = |
| 531 | new SensorPrivacyController.OnSensorPrivacyChangedListener() { |
| 532 | @Override |
| 533 | public void onSensorPrivacyChanged(boolean enabled) { |
| 534 | mHandler.post(() -> { |
| 535 | mIconController.setIconVisibility(mSlotSensorsOff, enabled); |
| 536 | }); |
| 537 | } |
| 538 | }; |
| 539 | |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 540 | @Override |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 541 | public void appTransitionStarting(int displayId, long startTime, long duration, |
| 542 | boolean forced) { |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 543 | if (mDisplayId == displayId) { |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 544 | updateManagedProfile(); |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 545 | } |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 546 | } |
| 547 | |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 548 | @Override |
| 549 | public void onKeyguardShowingChanged() { |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 550 | updateManagedProfile(); |
| 551 | } |
John Spurlock | 604a5ee | 2015-06-01 12:27:22 -0400 | [diff] [blame] | 552 | |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 553 | @Override |
| 554 | public void onUserSetupChanged() { |
| 555 | boolean userSetup = mProvisionedController.isUserSetup( |
| 556 | mProvisionedController.getCurrentUser()); |
John Spurlock | 604a5ee | 2015-06-01 12:27:22 -0400 | [diff] [blame] | 557 | if (mCurrentUserSetup == userSetup) return; |
| 558 | mCurrentUserSetup = userSetup; |
| 559 | updateAlarm(); |
| 560 | } |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 561 | |
| 562 | @Override |
| 563 | public void onRotationLockStateChanged(boolean rotationLocked, boolean affordanceVisible) { |
| 564 | boolean portrait = RotationLockTile.isCurrentOrientationLockPortrait( |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 565 | mRotationLockController, mResources); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 566 | if (rotationLocked) { |
| 567 | if (portrait) { |
| 568 | mIconController.setIcon(mSlotRotate, R.drawable.stat_sys_rotate_portrait, |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 569 | mResources.getString(R.string.accessibility_rotation_lock_on_portrait)); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 570 | } else { |
| 571 | mIconController.setIcon(mSlotRotate, R.drawable.stat_sys_rotate_landscape, |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 572 | mResources.getString(R.string.accessibility_rotation_lock_on_landscape)); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 573 | } |
Jason Monk | 8816dff | 2016-02-09 21:50:36 -0500 | [diff] [blame] | 574 | mIconController.setIconVisibility(mSlotRotate, true); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 575 | } else { |
Jason Monk | 8816dff | 2016-02-09 21:50:36 -0500 | [diff] [blame] | 576 | mIconController.setIconVisibility(mSlotRotate, false); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 577 | } |
| 578 | } |
| 579 | |
| 580 | private void updateHeadsetPlug(Intent intent) { |
| 581 | boolean connected = intent.getIntExtra("state", 0) != 0; |
| 582 | boolean hasMic = intent.getIntExtra("microphone", 0) != 0; |
| 583 | if (connected) { |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 584 | String contentDescription = mResources.getString(hasMic |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 585 | ? R.string.accessibility_status_bar_headset |
| 586 | : R.string.accessibility_status_bar_headphones); |
Amin Shaikh | ad29e93 | 2019-03-08 11:26:12 -0500 | [diff] [blame] | 587 | mIconController.setIcon(mSlotHeadset, hasMic ? R.drawable.stat_sys_headset_mic |
| 588 | : R.drawable.stat_sys_headset, contentDescription); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 589 | mIconController.setIconVisibility(mSlotHeadset, true); |
| 590 | } else { |
| 591 | mIconController.setIconVisibility(mSlotHeadset, false); |
| 592 | } |
| 593 | } |
| 594 | |
Jason Monk | f23aa99 | 2016-01-22 16:45:21 -0500 | [diff] [blame] | 595 | @Override |
| 596 | public void onDataSaverChanged(boolean isDataSaving) { |
| 597 | mIconController.setIconVisibility(mSlotDataSaver, isDataSaving); |
| 598 | } |
| 599 | |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 600 | @Override |
| 601 | public void onLocationActiveChanged(boolean active) { |
Fabian Kozynski | 228e310 | 2019-11-25 11:04:34 -0500 | [diff] [blame] | 602 | updateLocation(); |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | // Updates the status view based on the current state of location requests. |
| 606 | private void updateLocation() { |
| 607 | if (mLocationController.isLocationActive()) { |
| 608 | mIconController.setIconVisibility(mSlotLocation, true); |
| 609 | } else { |
| 610 | mIconController.setIconVisibility(mSlotLocation, false); |
| 611 | } |
| 612 | } |
| 613 | |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 614 | private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { |
| 615 | @Override |
| 616 | public void onReceive(Context context, Intent intent) { |
| 617 | String action = intent.getAction(); |
Lucas Dupin | 5e0f0d2 | 2018-02-26 13:32:16 -0800 | [diff] [blame] | 618 | switch (action) { |
| 619 | case AudioManager.RINGER_MODE_CHANGED_ACTION: |
| 620 | case AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION: |
| 621 | updateVolumeZen(); |
| 622 | break; |
Daniel Bright | 350f7f9 | 2020-01-22 14:24:11 -0800 | [diff] [blame] | 623 | case Intent.ACTION_SIM_STATE_CHANGED: |
Lucas Dupin | 5e0f0d2 | 2018-02-26 13:32:16 -0800 | [diff] [blame] | 624 | // Avoid rebroadcast because SysUI is direct boot aware. |
Meng Wang | 0e8d91a | 2020-01-17 14:58:01 -0800 | [diff] [blame] | 625 | if (intent.getBooleanExtra(Intent.EXTRA_REBROADCAST_ON_UNLOCK, false)) { |
Lucas Dupin | 5e0f0d2 | 2018-02-26 13:32:16 -0800 | [diff] [blame] | 626 | break; |
| 627 | } |
Lucas Dupin | 5e0f0d2 | 2018-02-26 13:32:16 -0800 | [diff] [blame] | 628 | break; |
| 629 | case TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED: |
| 630 | updateTTY(intent.getIntExtra(TelecomManager.EXTRA_CURRENT_TTY_MODE, |
| 631 | TelecomManager.TTY_MODE_OFF)); |
| 632 | break; |
| 633 | case Intent.ACTION_MANAGED_PROFILE_AVAILABLE: |
| 634 | case Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE: |
| 635 | case Intent.ACTION_MANAGED_PROFILE_REMOVED: |
| 636 | updateManagedProfile(); |
| 637 | break; |
| 638 | case AudioManager.ACTION_HEADSET_PLUG: |
| 639 | updateHeadsetPlug(intent); |
| 640 | break; |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 641 | } |
| 642 | } |
| 643 | }; |
| 644 | |
| 645 | private Runnable mRemoveCastIconRunnable = new Runnable() { |
| 646 | @Override |
| 647 | public void run() { |
| 648 | if (DEBUG) Log.v(TAG, "updateCast: hiding icon NOW"); |
| 649 | mIconController.setIconVisibility(mSlotCast, false); |
| 650 | } |
| 651 | }; |
Beth Thibodeau | 8bfbf1f | 2020-02-13 13:55:37 -0500 | [diff] [blame] | 652 | |
| 653 | // Screen Recording |
| 654 | @Override |
| 655 | public void onCountdown(long millisUntilFinished) { |
| 656 | if (DEBUG) Log.d(TAG, "screenrecord: countdown " + millisUntilFinished); |
| 657 | int countdown = (int) Math.floorDiv(millisUntilFinished + 500, 1000); |
| 658 | int resourceId = R.drawable.stat_sys_screen_record; |
| 659 | switch (countdown) { |
| 660 | case 1: |
| 661 | resourceId = R.drawable.stat_sys_screen_record_1; |
| 662 | break; |
| 663 | case 2: |
| 664 | resourceId = R.drawable.stat_sys_screen_record_2; |
| 665 | break; |
| 666 | case 3: |
| 667 | resourceId = R.drawable.stat_sys_screen_record_3; |
| 668 | break; |
| 669 | } |
| 670 | mIconController.setIcon(mSlotScreenRecord, resourceId, null); |
| 671 | mIconController.setIconVisibility(mSlotScreenRecord, true); |
| 672 | } |
| 673 | |
| 674 | @Override |
Beth Thibodeau | 5877278 | 2020-02-18 20:55:38 -0500 | [diff] [blame] | 675 | public void onCountdownEnd() { |
| 676 | if (DEBUG) Log.d(TAG, "screenrecord: hiding icon during countdown"); |
| 677 | mHandler.post(() -> mIconController.setIconVisibility(mSlotScreenRecord, false)); |
| 678 | } |
| 679 | |
| 680 | @Override |
Beth Thibodeau | 8bfbf1f | 2020-02-13 13:55:37 -0500 | [diff] [blame] | 681 | public void onRecordingStart() { |
| 682 | if (DEBUG) Log.d(TAG, "screenrecord: showing icon"); |
| 683 | mIconController.setIcon(mSlotScreenRecord, |
| 684 | R.drawable.stat_sys_screen_record, null); |
| 685 | mIconController.setIconVisibility(mSlotScreenRecord, true); |
| 686 | } |
| 687 | |
| 688 | @Override |
| 689 | public void onRecordingEnd() { |
Beth Thibodeau | 5877278 | 2020-02-18 20:55:38 -0500 | [diff] [blame] | 690 | // Ensure this is on the main thread |
Beth Thibodeau | 8bfbf1f | 2020-02-13 13:55:37 -0500 | [diff] [blame] | 691 | if (DEBUG) Log.d(TAG, "screenrecord: hiding icon"); |
| 692 | mHandler.post(() -> mIconController.setIconVisibility(mSlotScreenRecord, false)); |
| 693 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 694 | } |