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