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 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; |
| 20 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
| 21 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
| 22 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
| 23 | |
Jason Monk | 697b82a | 2017-04-19 18:41:06 -0400 | [diff] [blame] | 24 | import android.app.ActivityManager; |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 25 | import android.app.ActivityManager.StackInfo; |
Jason Monk | 697b82a | 2017-04-19 18:41:06 -0400 | [diff] [blame] | 26 | import android.app.AlarmManager; |
John Spurlock | 604a5ee | 2015-06-01 12:27:22 -0400 | [diff] [blame] | 27 | import android.app.AlarmManager.AlarmClockInfo; |
Jason Monk | 697b82a | 2017-04-19 18:41:06 -0400 | [diff] [blame] | 28 | import android.app.AppGlobals; |
| 29 | import android.app.Notification; |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 30 | import android.app.Notification.Action; |
Jason Monk | 697b82a | 2017-04-19 18:41:06 -0400 | [diff] [blame] | 31 | import android.app.NotificationManager; |
| 32 | import android.app.PendingIntent; |
| 33 | import android.app.SynchronousUserSwitchObserver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | import android.content.BroadcastReceiver; |
Jason Monk | 697b82a | 2017-04-19 18:41:06 -0400 | [diff] [blame] | 35 | import android.content.ComponentName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.content.Context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.content.Intent; |
| 38 | import android.content.IntentFilter; |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 39 | import android.content.pm.ApplicationInfo; |
| 40 | import android.content.pm.IPackageManager; |
| 41 | import android.content.pm.PackageManager; |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 42 | import android.graphics.drawable.Icon; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | import android.media.AudioManager; |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 44 | import android.net.Uri; |
| 45 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | import android.os.Handler; |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 47 | import android.os.RemoteException; |
Adrian Roos | c42a1e1 | 2014-07-07 23:35:53 +0200 | [diff] [blame] | 48 | import android.os.UserHandle; |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 49 | import android.os.UserManager; |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 50 | import android.provider.Settings; |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 51 | import android.provider.Settings.Global; |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 52 | import android.service.notification.StatusBarNotification; |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 53 | import android.service.notification.ZenModeConfig; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 54 | import android.telecom.TelecomManager; |
Evan Laird | bee3eb8 | 2018-05-16 15:58:49 -0400 | [diff] [blame] | 55 | import android.text.format.DateFormat; |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 56 | import android.util.ArraySet; |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 57 | import android.util.Log; |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 58 | import android.util.Pair; |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 59 | import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 60 | import com.android.internal.telephony.IccCardConstants; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 61 | import com.android.internal.telephony.TelephonyIntents; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 62 | import com.android.systemui.Dependency; |
Jason Monk | f85fc96 | 2017-04-19 17:13:41 -0400 | [diff] [blame] | 63 | import com.android.systemui.DockedStackExistsListener; |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 64 | import com.android.systemui.R; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 65 | import com.android.systemui.SysUiServiceProvider; |
Jorim Jaggi | fabc743 | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 66 | import com.android.systemui.UiOffloadThread; |
John Spurlock | 3c4076a | 2015-02-24 12:12:25 -0500 | [diff] [blame] | 67 | import com.android.systemui.qs.tiles.DndTile; |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 68 | import com.android.systemui.qs.tiles.RotationLockTile; |
Winson Chung | aa35745 | 2017-10-31 11:35:30 -0700 | [diff] [blame] | 69 | import com.android.systemui.recents.misc.SysUiTaskStackChangeListener; |
Winson Chung | 2cf6ad8 | 2017-11-09 17:36:59 -0800 | [diff] [blame] | 70 | import com.android.systemui.shared.system.ActivityManagerWrapper; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 71 | import com.android.systemui.statusbar.CommandQueue; |
| 72 | import com.android.systemui.statusbar.CommandQueue.Callbacks; |
Jason Monk | 7036436 | 2015-08-06 16:32:18 -0400 | [diff] [blame] | 73 | import com.android.systemui.statusbar.policy.BluetoothController; |
| 74 | import com.android.systemui.statusbar.policy.BluetoothController.Callback; |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 75 | import com.android.systemui.statusbar.policy.CastController; |
| 76 | import com.android.systemui.statusbar.policy.CastController.CastDevice; |
Jason Monk | f23aa99 | 2016-01-22 16:45:21 -0500 | [diff] [blame] | 77 | import com.android.systemui.statusbar.policy.DataSaverController; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 78 | import com.android.systemui.statusbar.policy.DataSaverController.Listener; |
| 79 | import com.android.systemui.statusbar.policy.DeviceProvisionedController; |
| 80 | import com.android.systemui.statusbar.policy.DeviceProvisionedController.DeviceProvisionedListener; |
Jason Monk | 952d5d8 | 2014-10-27 15:28:22 -0400 | [diff] [blame] | 81 | import com.android.systemui.statusbar.policy.HotspotController; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 82 | import com.android.systemui.statusbar.policy.KeyguardMonitor; |
Jason Monk | 359bb74 | 2017-04-13 10:40:40 -0400 | [diff] [blame] | 83 | import com.android.systemui.statusbar.policy.LocationController; |
| 84 | import com.android.systemui.statusbar.policy.LocationController.LocationChangeCallback; |
Juan Flores | 2ff3720 | 2015-04-30 13:44:23 +0200 | [diff] [blame] | 85 | import com.android.systemui.statusbar.policy.NextAlarmController; |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 86 | import com.android.systemui.statusbar.policy.RotationLockController; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 87 | import com.android.systemui.statusbar.policy.RotationLockController.RotationLockControllerCallback; |
Adrian Roos | 88b1193 | 2015-07-22 14:59:48 -0700 | [diff] [blame] | 88 | import com.android.systemui.statusbar.policy.UserInfoController; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 89 | import com.android.systemui.statusbar.policy.ZenModeController; |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 90 | import com.android.systemui.util.NotificationChannels; |
| 91 | |
Jason Monk | 697b82a | 2017-04-19 18:41:06 -0400 | [diff] [blame] | 92 | import java.util.List; |
Evan Laird | bee3eb8 | 2018-05-16 15:58:49 -0400 | [diff] [blame] | 93 | import java.util.Locale; |
Jason Monk | 697b82a | 2017-04-19 18:41:06 -0400 | [diff] [blame] | 94 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | /** |
| 96 | * This class contains all of the policy about which icons are installed in the status |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 97 | * bar at boot time. It goes through the normal API for icons, even though it probably |
| 98 | * strictly doesn't need to. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | */ |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 100 | public class PhoneStatusBarPolicy implements Callback, Callbacks, |
Jason Monk | 359bb74 | 2017-04-13 10:40:40 -0400 | [diff] [blame] | 101 | RotationLockControllerCallback, Listener, LocationChangeCallback, |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 102 | ZenModeController.Callback, DeviceProvisionedListener, KeyguardMonitor.Callback { |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 103 | private static final String TAG = "PhoneStatusBarPolicy"; |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 104 | private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 105 | |
Jason Monk | 359bb74 | 2017-04-13 10:40:40 -0400 | [diff] [blame] | 106 | public static final int LOCATION_STATUS_ICON_ID = R.drawable.stat_sys_location; |
Jason Monk | 697b82a | 2017-04-19 18:41:06 -0400 | [diff] [blame] | 107 | public static final int NUM_TASKS_FOR_INSTANT_APP_INFO = 5; |
Jason Monk | 359bb74 | 2017-04-13 10:40:40 -0400 | [diff] [blame] | 108 | |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 109 | private final String mSlotCast; |
| 110 | private final String mSlotHotspot; |
| 111 | private final String mSlotBluetooth; |
| 112 | private final String mSlotTty; |
| 113 | private final String mSlotZen; |
| 114 | private final String mSlotVolume; |
| 115 | private final String mSlotAlarmClock; |
| 116 | private final String mSlotManagedProfile; |
| 117 | private final String mSlotRotate; |
| 118 | private final String mSlotHeadset; |
Jason Monk | f23aa99 | 2016-01-22 16:45:21 -0500 | [diff] [blame] | 119 | private final String mSlotDataSaver; |
Jason Monk | 359bb74 | 2017-04-13 10:40:40 -0400 | [diff] [blame] | 120 | private final String mSlotLocation; |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 121 | |
Dianne Hackborn | 4840e14 | 2009-03-24 22:40:29 -0700 | [diff] [blame] | 122 | private final Context mContext; |
Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 123 | private final Handler mHandler = new Handler(); |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 124 | private final CastController mCast; |
Jason Monk | 952d5d8 | 2014-10-27 15:28:22 -0400 | [diff] [blame] | 125 | private final HotspotController mHotspot; |
Evan Laird | bee3eb8 | 2018-05-16 15:58:49 -0400 | [diff] [blame] | 126 | private final NextAlarmController mNextAlarmController; |
John Spurlock | 1578226 | 2015-05-29 15:35:53 -0400 | [diff] [blame] | 127 | private final AlarmManager mAlarmManager; |
Adrian Roos | 88b1193 | 2015-07-22 14:59:48 -0700 | [diff] [blame] | 128 | private final UserInfoController mUserInfoController; |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 129 | private final UserManager mUserManager; |
Jason Monk | 07473ce | 2016-01-05 14:59:19 -0500 | [diff] [blame] | 130 | private final StatusBarIconController mIconController; |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 131 | private final RotationLockController mRotationLockController; |
Jason Monk | f23aa99 | 2016-01-22 16:45:21 -0500 | [diff] [blame] | 132 | private final DataSaverController mDataSaver; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 133 | private final ZenModeController mZenController; |
| 134 | private final DeviceProvisionedController mProvisionedController; |
| 135 | private final KeyguardMonitor mKeyguardMonitor; |
Jason Monk | 359bb74 | 2017-04-13 10:40:40 -0400 | [diff] [blame] | 136 | private final LocationController mLocationController; |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 137 | private final ArraySet<Pair<String, Integer>> mCurrentNotifs = new ArraySet<>(); |
Jorim Jaggi | fabc743 | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 138 | private final UiOffloadThread mUiOffloadThread = Dependency.get(UiOffloadThread.class); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | // Assume it's all good unless we hear otherwise. We don't always seem |
| 141 | // to get broadcasts that it *is* there. |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 142 | IccCardConstants.State mSimState = IccCardConstants.State.READY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 144 | private boolean mZenVisible; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | private boolean mVolumeVisible; |
John Spurlock | 604a5ee | 2015-06-01 12:27:22 -0400 | [diff] [blame] | 146 | private boolean mCurrentUserSetup; |
Jason Monk | f85fc96 | 2017-04-19 17:13:41 -0400 | [diff] [blame] | 147 | private boolean mDockedStackExists; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 148 | |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 149 | private boolean mManagedProfileIconVisible = false; |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 150 | |
Jason Monk | 7036436 | 2015-08-06 16:32:18 -0400 | [diff] [blame] | 151 | private BluetoothController mBluetooth; |
Evan Laird | bee3eb8 | 2018-05-16 15:58:49 -0400 | [diff] [blame] | 152 | private AlarmManager.AlarmClockInfo mNextAlarm; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 153 | |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 154 | public PhoneStatusBarPolicy(Context context, StatusBarIconController iconController) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | mContext = context; |
Jason Monk | 07473ce | 2016-01-05 14:59:19 -0500 | [diff] [blame] | 156 | mIconController = iconController; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 157 | mCast = Dependency.get(CastController.class); |
| 158 | mHotspot = Dependency.get(HotspotController.class); |
| 159 | mBluetooth = Dependency.get(BluetoothController.class); |
Evan Laird | bee3eb8 | 2018-05-16 15:58:49 -0400 | [diff] [blame] | 160 | mNextAlarmController = Dependency.get(NextAlarmController.class); |
John Spurlock | 1578226 | 2015-05-29 15:35:53 -0400 | [diff] [blame] | 161 | mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 162 | mUserInfoController = Dependency.get(UserInfoController.class); |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 163 | mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 164 | mRotationLockController = Dependency.get(RotationLockController.class); |
| 165 | mDataSaver = Dependency.get(DataSaverController.class); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 166 | mZenController = Dependency.get(ZenModeController.class); |
| 167 | mProvisionedController = Dependency.get(DeviceProvisionedController.class); |
| 168 | mKeyguardMonitor = Dependency.get(KeyguardMonitor.class); |
Jason Monk | 359bb74 | 2017-04-13 10:40:40 -0400 | [diff] [blame] | 169 | mLocationController = Dependency.get(LocationController.class); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 170 | |
| 171 | mSlotCast = context.getString(com.android.internal.R.string.status_bar_cast); |
| 172 | mSlotHotspot = context.getString(com.android.internal.R.string.status_bar_hotspot); |
| 173 | mSlotBluetooth = context.getString(com.android.internal.R.string.status_bar_bluetooth); |
| 174 | mSlotTty = context.getString(com.android.internal.R.string.status_bar_tty); |
| 175 | mSlotZen = context.getString(com.android.internal.R.string.status_bar_zen); |
| 176 | mSlotVolume = context.getString(com.android.internal.R.string.status_bar_volume); |
| 177 | mSlotAlarmClock = context.getString(com.android.internal.R.string.status_bar_alarm_clock); |
| 178 | mSlotManagedProfile = context.getString( |
| 179 | com.android.internal.R.string.status_bar_managed_profile); |
| 180 | mSlotRotate = context.getString(com.android.internal.R.string.status_bar_rotate); |
| 181 | mSlotHeadset = context.getString(com.android.internal.R.string.status_bar_headset); |
Jason Monk | f23aa99 | 2016-01-22 16:45:21 -0500 | [diff] [blame] | 182 | mSlotDataSaver = context.getString(com.android.internal.R.string.status_bar_data_saver); |
Jason Monk | 359bb74 | 2017-04-13 10:40:40 -0400 | [diff] [blame] | 183 | mSlotLocation = context.getString(com.android.internal.R.string.status_bar_location); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | |
Daniel Sandler | e3b7a2d | 2011-10-27 16:16:15 -0400 | [diff] [blame] | 185 | // listen for broadcasts |
| 186 | IntentFilter filter = new IntentFilter(); |
Daniel Sandler | e3b7a2d | 2011-10-27 16:16:15 -0400 | [diff] [blame] | 187 | filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); |
John Spurlock | bcc1087 | 2014-11-28 15:29:21 -0500 | [diff] [blame] | 188 | filter.addAction(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 189 | filter.addAction(AudioManager.ACTION_HEADSET_PLUG); |
Daniel Sandler | e3b7a2d | 2011-10-27 16:16:15 -0400 | [diff] [blame] | 190 | filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 191 | filter.addAction(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED); |
Rubin Xu | e95057a | 2016-04-01 16:49:25 +0100 | [diff] [blame] | 192 | filter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE); |
| 193 | filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE); |
Nicolas Prevot | 6c7b874 | 2016-04-13 10:28:58 +0100 | [diff] [blame] | 194 | filter.addAction(Intent.ACTION_MANAGED_PROFILE_REMOVED); |
Daniel Sandler | e3b7a2d | 2011-10-27 16:16:15 -0400 | [diff] [blame] | 195 | mContext.registerReceiver(mIntentReceiver, filter, null, mHandler); |
| 196 | |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 197 | // listen for user / profile change. |
| 198 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 199 | ActivityManager.getService().registerUserSwitchObserver(mUserSwitchListener, TAG); |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 200 | } catch (RemoteException e) { |
| 201 | // Ignore |
| 202 | } |
| 203 | |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 204 | // TTY status |
Hall Liu | 108ca20 | 2017-07-24 15:19:04 -0700 | [diff] [blame] | 205 | updateTTY(); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 206 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 207 | // bluetooth status |
Jorim Jaggi | 2d75f9f | 2014-10-08 17:10:58 -0700 | [diff] [blame] | 208 | updateBluetooth(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 209 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 210 | // Alarm clock |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 211 | mIconController.setIcon(mSlotAlarmClock, R.drawable.stat_sys_alarm, null); |
| 212 | mIconController.setIconVisibility(mSlotAlarmClock, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 213 | |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 214 | // zen |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 215 | mIconController.setIcon(mSlotZen, R.drawable.stat_sys_zen_important, null); |
| 216 | mIconController.setIconVisibility(mSlotZen, false); |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 217 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 218 | // volume |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 219 | mIconController.setIcon(mSlotVolume, R.drawable.stat_sys_ringer_vibrate, null); |
| 220 | mIconController.setIconVisibility(mSlotVolume, false); |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 221 | updateVolumeZen(); |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 222 | |
| 223 | // cast |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 224 | mIconController.setIcon(mSlotCast, R.drawable.stat_sys_cast, null); |
| 225 | mIconController.setIconVisibility(mSlotCast, false); |
Jason Monk | 952d5d8 | 2014-10-27 15:28:22 -0400 | [diff] [blame] | 226 | |
| 227 | // hotspot |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 228 | mIconController.setIcon(mSlotHotspot, R.drawable.stat_sys_hotspot, |
Jason Monk | 08187a4 | 2015-06-09 14:33:51 -0400 | [diff] [blame] | 229 | mContext.getString(R.string.accessibility_status_bar_hotspot)); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 230 | mIconController.setIconVisibility(mSlotHotspot, mHotspot.isHotspotEnabled()); |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 231 | |
| 232 | // managed profile |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 233 | mIconController.setIcon(mSlotManagedProfile, R.drawable.stat_sys_managed_profile_status, |
Adrian Roos | 1b5eb97 | 2015-06-11 18:22:52 -0700 | [diff] [blame] | 234 | mContext.getString(R.string.accessibility_managed_profile)); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 235 | mIconController.setIconVisibility(mSlotManagedProfile, mManagedProfileIconVisible); |
Jason Monk | f23aa99 | 2016-01-22 16:45:21 -0500 | [diff] [blame] | 236 | |
| 237 | // data saver |
| 238 | mIconController.setIcon(mSlotDataSaver, R.drawable.stat_sys_data_saver, |
| 239 | context.getString(R.string.accessibility_data_saver_on)); |
| 240 | mIconController.setIconVisibility(mSlotDataSaver, false); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 241 | |
| 242 | mRotationLockController.addCallback(this); |
| 243 | mBluetooth.addCallback(this); |
| 244 | mProvisionedController.addCallback(this); |
| 245 | mZenController.addCallback(this); |
| 246 | mCast.addCallback(mCastCallback); |
| 247 | mHotspot.addCallback(mHotspotCallback); |
Evan Laird | bee3eb8 | 2018-05-16 15:58:49 -0400 | [diff] [blame] | 248 | mNextAlarmController.addCallback(mNextAlarmCallback); |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 249 | mDataSaver.addCallback(this); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 250 | mKeyguardMonitor.addCallback(this); |
Jason Monk | 359bb74 | 2017-04-13 10:40:40 -0400 | [diff] [blame] | 251 | mLocationController.addCallback(this); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 252 | |
| 253 | SysUiServiceProvider.getComponent(mContext, CommandQueue.class).addCallbacks(this); |
Winson Chung | 2cf6ad8 | 2017-11-09 17:36:59 -0800 | [diff] [blame] | 254 | ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskListener); |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 255 | |
| 256 | // Clear out all old notifications on startup (only present in the case where sysui dies) |
| 257 | NotificationManager noMan = mContext.getSystemService(NotificationManager.class); |
| 258 | for (StatusBarNotification notification : noMan.getActiveNotifications()) { |
| 259 | if (notification.getId() == SystemMessage.NOTE_INSTANT_APPS) { |
| 260 | noMan.cancel(notification.getTag(), notification.getId()); |
| 261 | } |
| 262 | } |
Jason Monk | f85fc96 | 2017-04-19 17:13:41 -0400 | [diff] [blame] | 263 | DockedStackExistsListener.register(exists -> { |
| 264 | mDockedStackExists = exists; |
| 265 | updateForegroundInstantApps(); |
| 266 | }); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 267 | } |
| 268 | |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 269 | public void destroy() { |
| 270 | mRotationLockController.removeCallback(this); |
| 271 | mBluetooth.removeCallback(this); |
| 272 | mProvisionedController.removeCallback(this); |
| 273 | mZenController.removeCallback(this); |
| 274 | mCast.removeCallback(mCastCallback); |
| 275 | mHotspot.removeCallback(mHotspotCallback); |
Evan Laird | bee3eb8 | 2018-05-16 15:58:49 -0400 | [diff] [blame] | 276 | mNextAlarmController.removeCallback(mNextAlarmCallback); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 277 | mDataSaver.removeCallback(this); |
| 278 | mKeyguardMonitor.removeCallback(this); |
Jason Monk | 359bb74 | 2017-04-13 10:40:40 -0400 | [diff] [blame] | 279 | mLocationController.removeCallback(this); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 280 | SysUiServiceProvider.getComponent(mContext, CommandQueue.class).removeCallbacks(this); |
| 281 | mContext.unregisterReceiver(mIntentReceiver); |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 282 | |
| 283 | NotificationManager noMan = mContext.getSystemService(NotificationManager.class); |
| 284 | mCurrentNotifs.forEach(v -> noMan.cancelAsUser(v.first, SystemMessage.NOTE_INSTANT_APPS, |
| 285 | new UserHandle(v.second))); |
Nicolas Prevot | 1dbbe7d | 2016-05-17 12:52:54 +0100 | [diff] [blame] | 286 | } |
| 287 | |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 288 | @Override |
| 289 | public void onZenChanged(int zen) { |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 290 | updateVolumeZen(); |
John Spurlock | ba2c6a0 | 2014-05-19 09:44:06 -0400 | [diff] [blame] | 291 | } |
| 292 | |
Jason Monk | 359bb74 | 2017-04-13 10:40:40 -0400 | [diff] [blame] | 293 | @Override |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 294 | public void onConfigChanged(ZenModeConfig config) { |
| 295 | updateVolumeZen(); |
| 296 | } |
| 297 | |
| 298 | @Override |
Jason Monk | 359bb74 | 2017-04-13 10:40:40 -0400 | [diff] [blame] | 299 | public void onLocationActiveChanged(boolean active) { |
| 300 | updateLocation(); |
| 301 | } |
| 302 | |
| 303 | // Updates the status view based on the current state of location requests. |
| 304 | private void updateLocation() { |
| 305 | if (mLocationController.isLocationActive()) { |
| 306 | mIconController.setIcon(mSlotLocation, LOCATION_STATUS_ICON_ID, |
| 307 | mContext.getString(R.string.accessibility_location_active)); |
| 308 | } else { |
Evan Laird | e1d13c9 | 2018-03-20 16:58:01 -0400 | [diff] [blame] | 309 | mIconController.removeAllIconsForSlot(mSlotLocation); |
Jason Monk | 359bb74 | 2017-04-13 10:40:40 -0400 | [diff] [blame] | 310 | } |
| 311 | } |
| 312 | |
Adrian Roos | c42a1e1 | 2014-07-07 23:35:53 +0200 | [diff] [blame] | 313 | private void updateAlarm() { |
John Spurlock | 604a5ee | 2015-06-01 12:27:22 -0400 | [diff] [blame] | 314 | final AlarmClockInfo alarm = mAlarmManager.getNextAlarmClock(UserHandle.USER_CURRENT); |
| 315 | final boolean hasAlarm = alarm != null && alarm.getTriggerTime() > 0; |
Jason Monk | 20c0eb4 | 2017-03-02 17:35:49 -0500 | [diff] [blame] | 316 | int zen = mZenController.getZen(); |
| 317 | final boolean zenNone = zen == Global.ZEN_MODE_NO_INTERRUPTIONS; |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 318 | mIconController.setIcon(mSlotAlarmClock, zenNone ? R.drawable.stat_sys_alarm_dim |
Evan Laird | bee3eb8 | 2018-05-16 15:58:49 -0400 | [diff] [blame] | 319 | : R.drawable.stat_sys_alarm, buildAlarmContentDescription()); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 320 | mIconController.setIconVisibility(mSlotAlarmClock, mCurrentUserSetup && hasAlarm); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 321 | } |
| 322 | |
Evan Laird | bee3eb8 | 2018-05-16 15:58:49 -0400 | [diff] [blame] | 323 | private String buildAlarmContentDescription() { |
| 324 | if (mNextAlarm == null) { |
| 325 | return mContext.getString(R.string.status_bar_alarm); |
| 326 | } |
| 327 | return formatNextAlarm(mNextAlarm, mContext); |
| 328 | } |
| 329 | |
| 330 | private static String formatNextAlarm(AlarmManager.AlarmClockInfo info, Context context) { |
| 331 | if (info == null) { |
| 332 | return ""; |
| 333 | } |
| 334 | String skeleton = DateFormat.is24HourFormat( |
| 335 | context, ActivityManager.getCurrentUser()) ? "EHm" : "Ehma"; |
| 336 | String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton); |
| 337 | String dateString = DateFormat.format(pattern, info.getTriggerTime()).toString(); |
| 338 | |
| 339 | return context.getString(R.string.accessibility_quick_settings_alarm, dateString); |
| 340 | } |
| 341 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 342 | private final void updateSimState(Intent intent) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 343 | String stateExtra = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE); |
| 344 | if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) { |
| 345 | mSimState = IccCardConstants.State.ABSENT; |
Jason Monk | 07473ce | 2016-01-05 14:59:19 -0500 | [diff] [blame] | 346 | } else if (IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR.equals(stateExtra)) { |
Rakesh Pallerla | f099a5f | 2013-02-06 11:44:23 +0530 | [diff] [blame] | 347 | mSimState = IccCardConstants.State.CARD_IO_ERROR; |
Junda Liu | a2f6a67 | 2016-05-24 10:07:40 -0700 | [diff] [blame] | 348 | } else if (IccCardConstants.INTENT_VALUE_ICC_CARD_RESTRICTED.equals(stateExtra)) { |
| 349 | mSimState = IccCardConstants.State.CARD_RESTRICTED; |
Jason Monk | 07473ce | 2016-01-05 14:59:19 -0500 | [diff] [blame] | 350 | } else if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(stateExtra)) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 351 | mSimState = IccCardConstants.State.READY; |
Jason Monk | 07473ce | 2016-01-05 14:59:19 -0500 | [diff] [blame] | 352 | } else if (IccCardConstants.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 353 | final String lockedReason = |
| 354 | intent.getStringExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON); |
| 355 | if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) { |
| 356 | mSimState = IccCardConstants.State.PIN_REQUIRED; |
Jason Monk | 07473ce | 2016-01-05 14:59:19 -0500 | [diff] [blame] | 357 | } else if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 358 | mSimState = IccCardConstants.State.PUK_REQUIRED; |
Jason Monk | 07473ce | 2016-01-05 14:59:19 -0500 | [diff] [blame] | 359 | } else { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 360 | mSimState = IccCardConstants.State.NETWORK_LOCKED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 361 | } |
| 362 | } else { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 363 | mSimState = IccCardConstants.State.UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 364 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 365 | } |
| 366 | |
John Spurlock | bcc1087 | 2014-11-28 15:29:21 -0500 | [diff] [blame] | 367 | private final void updateVolumeZen() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 368 | AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 369 | |
| 370 | boolean zenVisible = false; |
| 371 | int zenIconId = 0; |
| 372 | String zenDescription = null; |
| 373 | |
| 374 | boolean volumeVisible = false; |
| 375 | int volumeIconId = 0; |
| 376 | String volumeDescription = null; |
Jason Monk | 20c0eb4 | 2017-03-02 17:35:49 -0500 | [diff] [blame] | 377 | int zen = mZenController.getZen(); |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 378 | |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 379 | if (DndTile.isVisible(mContext) || DndTile.isCombinedIcon(mContext)) { |
Jason Monk | 20c0eb4 | 2017-03-02 17:35:49 -0500 | [diff] [blame] | 380 | zenVisible = zen != Global.ZEN_MODE_OFF; |
Evan Laird | a9adbd5 | 2018-05-16 11:32:08 -0400 | [diff] [blame] | 381 | zenIconId = R.drawable.stat_sys_dnd; |
John Spurlock | 3c4076a | 2015-02-24 12:12:25 -0500 | [diff] [blame] | 382 | zenDescription = mContext.getString(R.string.quick_settings_dnd_label); |
Jason Monk | 20c0eb4 | 2017-03-02 17:35:49 -0500 | [diff] [blame] | 383 | } else if (zen == Global.ZEN_MODE_NO_INTERRUPTIONS) { |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 384 | zenVisible = true; |
| 385 | zenIconId = R.drawable.stat_sys_zen_none; |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 386 | zenDescription = mContext.getString(R.string.interruption_level_none); |
Jason Monk | 20c0eb4 | 2017-03-02 17:35:49 -0500 | [diff] [blame] | 387 | } else if (zen == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS) { |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 388 | zenVisible = true; |
| 389 | zenIconId = R.drawable.stat_sys_zen_important; |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 390 | zenDescription = mContext.getString(R.string.interruption_level_priority); |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 391 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 392 | |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 393 | if (!ZenModeConfig.isZenOverridingRinger(zen, mZenController.getConfig())) { |
| 394 | if (audioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_VIBRATE) { |
| 395 | volumeVisible = true; |
| 396 | volumeIconId = R.drawable.stat_sys_ringer_vibrate; |
| 397 | volumeDescription = mContext.getString(R.string.accessibility_ringer_vibrate); |
| 398 | } else if (audioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_SILENT) { |
| 399 | volumeVisible = true; |
| 400 | volumeIconId = R.drawable.stat_sys_ringer_silent; |
| 401 | volumeDescription = mContext.getString(R.string.accessibility_ringer_silent); |
| 402 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 403 | } |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 404 | |
| 405 | if (zenVisible) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 406 | mIconController.setIcon(mSlotZen, zenIconId, zenDescription); |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 407 | } |
| 408 | if (zenVisible != mZenVisible) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 409 | mIconController.setIconVisibility(mSlotZen, zenVisible); |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 410 | mZenVisible = zenVisible; |
| 411 | } |
| 412 | |
| 413 | if (volumeVisible) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 414 | mIconController.setIcon(mSlotVolume, volumeIconId, volumeDescription); |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 415 | } |
| 416 | if (volumeVisible != mVolumeVisible) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 417 | mIconController.setIconVisibility(mSlotVolume, volumeVisible); |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 418 | mVolumeVisible = volumeVisible; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 419 | } |
John Spurlock | 1578226 | 2015-05-29 15:35:53 -0400 | [diff] [blame] | 420 | updateAlarm(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 421 | } |
| 422 | |
Jason Monk | 7036436 | 2015-08-06 16:32:18 -0400 | [diff] [blame] | 423 | @Override |
| 424 | public void onBluetoothDevicesChanged() { |
| 425 | updateBluetooth(); |
| 426 | } |
| 427 | |
| 428 | @Override |
| 429 | public void onBluetoothStateChange(boolean enabled) { |
| 430 | updateBluetooth(); |
| 431 | } |
| 432 | |
Jorim Jaggi | 2d75f9f | 2014-10-08 17:10:58 -0700 | [diff] [blame] | 433 | private final void updateBluetooth() { |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 434 | int iconId = R.drawable.stat_sys_data_bluetooth; |
Jorim Jaggi | 2d75f9f | 2014-10-08 17:10:58 -0700 | [diff] [blame] | 435 | String contentDescription = |
Jason Monk | 1aa3282 | 2015-07-14 16:10:32 -0400 | [diff] [blame] | 436 | mContext.getString(R.string.accessibility_quick_settings_bluetooth_on); |
Evan Laird | 3cdf47e | 2018-01-29 16:01:41 -0500 | [diff] [blame] | 437 | boolean bluetoothVisible = false; |
Jason Monk | 7036436 | 2015-08-06 16:32:18 -0400 | [diff] [blame] | 438 | if (mBluetooth != null) { |
Jason Monk | 7036436 | 2015-08-06 16:32:18 -0400 | [diff] [blame] | 439 | if (mBluetooth.isBluetoothConnected()) { |
Jaikumar Ganesh | d9bb688 | 2010-09-27 17:05:24 -0700 | [diff] [blame] | 440 | iconId = R.drawable.stat_sys_data_bluetooth_connected; |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 441 | contentDescription = mContext.getString(R.string.accessibility_bluetooth_connected); |
Evan Laird | 3cdf47e | 2018-01-29 16:01:41 -0500 | [diff] [blame] | 442 | bluetoothVisible = mBluetooth.isBluetoothEnabled(); |
Jaikumar Ganesh | 084c665 | 2009-12-07 10:58:18 -0800 | [diff] [blame] | 443 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 444 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 445 | |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 446 | mIconController.setIcon(mSlotBluetooth, iconId, contentDescription); |
Evan Laird | 3cdf47e | 2018-01-29 16:01:41 -0500 | [diff] [blame] | 447 | mIconController.setIconVisibility(mSlotBluetooth, bluetoothVisible); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 448 | } |
| 449 | |
Hall Liu | 108ca20 | 2017-07-24 15:19:04 -0700 | [diff] [blame] | 450 | private final void updateTTY() { |
| 451 | TelecomManager telecomManager = |
| 452 | (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); |
| 453 | if (telecomManager == null) { |
| 454 | updateTTY(TelecomManager.TTY_MODE_OFF); |
| 455 | } else { |
| 456 | updateTTY(telecomManager.getCurrentTtyMode()); |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | private final void updateTTY(int currentTtyMode) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 461 | boolean enabled = currentTtyMode != TelecomManager.TTY_MODE_OFF; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 462 | |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 463 | if (DEBUG) Log.v(TAG, "updateTTY: enabled: " + enabled); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 464 | |
| 465 | if (enabled) { |
| 466 | // TTY is on |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 467 | if (DEBUG) Log.v(TAG, "updateTTY: set TTY on"); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 468 | mIconController.setIcon(mSlotTty, R.drawable.stat_sys_tty_mode, |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 469 | mContext.getString(R.string.accessibility_tty_enabled)); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 470 | mIconController.setIconVisibility(mSlotTty, true); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 471 | } else { |
| 472 | // TTY is off |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 473 | if (DEBUG) Log.v(TAG, "updateTTY: set TTY off"); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 474 | mIconController.setIconVisibility(mSlotTty, false); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 475 | } |
| 476 | } |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 477 | |
| 478 | private void updateCast() { |
| 479 | boolean isCasting = false; |
| 480 | for (CastDevice device : mCast.getCastDevices()) { |
| 481 | if (device.state == CastDevice.STATE_CONNECTING |
| 482 | || device.state == CastDevice.STATE_CONNECTED) { |
| 483 | isCasting = true; |
| 484 | break; |
| 485 | } |
| 486 | } |
| 487 | if (DEBUG) Log.v(TAG, "updateCast: isCasting: " + isCasting); |
Dan Sandler | 8fd25bf | 2015-10-20 16:01:27 -0700 | [diff] [blame] | 488 | mHandler.removeCallbacks(mRemoveCastIconRunnable); |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 489 | if (isCasting) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 490 | mIconController.setIcon(mSlotCast, R.drawable.stat_sys_cast, |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 491 | mContext.getString(R.string.accessibility_casting)); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 492 | mIconController.setIconVisibility(mSlotCast, true); |
Dan Sandler | 8fd25bf | 2015-10-20 16:01:27 -0700 | [diff] [blame] | 493 | } else { |
| 494 | // don't turn off the screen-record icon for a few seconds, just to make sure the user |
| 495 | // has seen it |
| 496 | if (DEBUG) Log.v(TAG, "updateCast: hiding icon in 3 sec..."); |
| 497 | mHandler.postDelayed(mRemoveCastIconRunnable, 3000); |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 498 | } |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 499 | } |
| 500 | |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 501 | private void updateManagedProfile() { |
Jorim Jaggi | fabc743 | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 502 | // getLastResumedActivityUserId needds to acquire the AM lock, which may be contended in |
| 503 | // some cases. Since it doesn't really matter here whether it's updated in this frame |
| 504 | // or in the next one, we call this method from our UI offload thread. |
| 505 | mUiOffloadThread.submit(() -> { |
| 506 | final int userId; |
| 507 | try { |
| 508 | userId = ActivityManager.getService().getLastResumedActivityUserId(); |
| 509 | boolean isManagedProfile = mUserManager.isManagedProfile(userId); |
| 510 | mHandler.post(() -> { |
| 511 | final boolean showIcon; |
Pavel Grafov | 410d808 | 2017-06-29 18:42:32 +0100 | [diff] [blame] | 512 | if (isManagedProfile && |
| 513 | (!mKeyguardMonitor.isShowing() || mKeyguardMonitor.isOccluded())) { |
Jorim Jaggi | fabc743 | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 514 | showIcon = true; |
| 515 | mIconController.setIcon(mSlotManagedProfile, |
| 516 | R.drawable.stat_sys_managed_profile_status, |
| 517 | mContext.getString(R.string.accessibility_managed_profile)); |
Jorim Jaggi | fabc743 | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 518 | } else { |
| 519 | showIcon = false; |
| 520 | } |
| 521 | if (mManagedProfileIconVisible != showIcon) { |
| 522 | mIconController.setIconVisibility(mSlotManagedProfile, showIcon); |
| 523 | mManagedProfileIconVisible = showIcon; |
| 524 | } |
| 525 | }); |
| 526 | } catch (RemoteException e) { |
| 527 | Log.w(TAG, "updateManagedProfile: ", e); |
Tony Mak | ec319ab | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 528 | } |
Jorim Jaggi | fabc743 | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 529 | }); |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 530 | } |
| 531 | |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 532 | private void updateForegroundInstantApps() { |
| 533 | NotificationManager noMan = mContext.getSystemService(NotificationManager.class); |
| 534 | ArraySet<Pair<String, Integer>> notifs = new ArraySet<>(mCurrentNotifs); |
| 535 | IPackageManager pm = AppGlobals.getPackageManager(); |
| 536 | mCurrentNotifs.clear(); |
Jorim Jaggi | fabc743 | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 537 | mUiOffloadThread.submit(() -> { |
| 538 | try { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 539 | final StackInfo focusedStack = ActivityManager.getService().getFocusedStackInfo(); |
| 540 | if (focusedStack != null) { |
| 541 | final int windowingMode = |
| 542 | focusedStack.configuration.windowConfiguration.getWindowingMode(); |
| 543 | if (windowingMode == WINDOWING_MODE_FULLSCREEN |
| 544 | || windowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY) { |
| 545 | checkStack(focusedStack, notifs, noMan, pm); |
| 546 | } |
Jorim Jaggi | fabc743 | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 547 | } |
| 548 | if (mDockedStackExists) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 549 | checkStack(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_UNDEFINED, |
| 550 | notifs, noMan, pm); |
Jorim Jaggi | fabc743 | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 551 | } |
| 552 | } catch (RemoteException e) { |
| 553 | e.rethrowFromSystemServer(); |
Jason Monk | f85fc96 | 2017-04-19 17:13:41 -0400 | [diff] [blame] | 554 | } |
Jorim Jaggi | fabc743 | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 555 | // Cancel all the leftover notifications that don't have a foreground process anymore. |
| 556 | notifs.forEach(v -> noMan.cancelAsUser(v.first, SystemMessage.NOTE_INSTANT_APPS, |
| 557 | new UserHandle(v.second))); |
| 558 | }); |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 559 | } |
| 560 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 561 | private void checkStack(int windowingMode, int activityType, |
| 562 | ArraySet<Pair<String, Integer>> notifs, NotificationManager noMan, IPackageManager pm) { |
| 563 | try { |
| 564 | final StackInfo info = |
| 565 | ActivityManager.getService().getStackInfo(windowingMode, activityType); |
| 566 | checkStack(info, notifs, noMan, pm); |
| 567 | } catch (RemoteException e) { |
| 568 | e.rethrowFromSystemServer(); |
| 569 | } |
| 570 | } |
| 571 | private void checkStack(StackInfo info, ArraySet<Pair<String, Integer>> notifs, |
Jason Monk | f85fc96 | 2017-04-19 17:13:41 -0400 | [diff] [blame] | 572 | NotificationManager noMan, IPackageManager pm) { |
| 573 | try { |
Jason Monk | f85fc96 | 2017-04-19 17:13:41 -0400 | [diff] [blame] | 574 | if (info == null || info.topActivity == null) return; |
| 575 | String pkg = info.topActivity.getPackageName(); |
| 576 | if (!hasNotif(notifs, pkg, info.userId)) { |
| 577 | // TODO: Optimize by not always needing to get application info. |
| 578 | // Maybe cache non-ephemeral packages? |
| 579 | ApplicationInfo appInfo = pm.getApplicationInfo(pkg, |
| 580 | PackageManager.MATCH_UNINSTALLED_PACKAGES, info.userId); |
| 581 | if (appInfo.isInstantApp()) { |
Jason Monk | 697b82a | 2017-04-19 18:41:06 -0400 | [diff] [blame] | 582 | postEphemeralNotif(pkg, info.userId, appInfo, noMan, info.taskIds[info.taskIds.length - 1]); |
Jason Monk | f85fc96 | 2017-04-19 17:13:41 -0400 | [diff] [blame] | 583 | } |
| 584 | } |
| 585 | } catch (RemoteException e) { |
| 586 | e.rethrowFromSystemServer(); |
| 587 | } |
| 588 | } |
| 589 | |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 590 | private void postEphemeralNotif(String pkg, int userId, ApplicationInfo appInfo, |
Jason Monk | 697b82a | 2017-04-19 18:41:06 -0400 | [diff] [blame] | 591 | NotificationManager noMan, int taskId) { |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 592 | final Bundle extras = new Bundle(); |
| 593 | extras.putString(Notification.EXTRA_SUBSTITUTE_APP_NAME, |
| 594 | mContext.getString(R.string.instant_apps)); |
| 595 | mCurrentNotifs.add(new Pair<>(pkg, userId)); |
| 596 | String message = mContext.getString(R.string.instant_apps_message); |
| 597 | PendingIntent appInfoAction = PendingIntent.getActivity(mContext, 0, |
| 598 | new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS) |
| 599 | .setData(Uri.fromParts("package", pkg, null)), 0); |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 600 | Action action = new Notification.Action.Builder(null, mContext.getString(R.string.app_info), |
| 601 | appInfoAction).build(); |
| 602 | |
Jason Monk | 697b82a | 2017-04-19 18:41:06 -0400 | [diff] [blame] | 603 | Intent browserIntent = getTaskIntent(taskId, userId); |
| 604 | Notification.Builder builder = new Notification.Builder(mContext, NotificationChannels.GENERAL); |
Patrick Baumann | 531db46 | 2018-02-13 13:01:47 -0800 | [diff] [blame] | 605 | if (browserIntent != null && browserIntent.isWebIntent()) { |
Jesse Evans | a2024a2 | 2017-04-20 14:44:49 -0700 | [diff] [blame] | 606 | // Make sure that this doesn't resolve back to an instant app |
| 607 | browserIntent.setComponent(null) |
| 608 | .setPackage(null) |
| 609 | .addFlags(Intent.FLAG_IGNORE_EPHEMERAL) |
| 610 | .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 611 | |
Jason Monk | 697b82a | 2017-04-19 18:41:06 -0400 | [diff] [blame] | 612 | PendingIntent pendingIntent = PendingIntent.getActivity(mContext, |
| 613 | 0 /* requestCode */, browserIntent, 0 /* flags */); |
Jason Monk | 697b82a | 2017-04-19 18:41:06 -0400 | [diff] [blame] | 614 | ComponentName aiaComponent = null; |
| 615 | try { |
| 616 | aiaComponent = AppGlobals.getPackageManager().getInstantAppInstallerComponent(); |
| 617 | } catch (RemoteException e) { |
| 618 | e.rethrowFromSystemServer(); |
| 619 | } |
| 620 | Intent goToWebIntent = new Intent() |
| 621 | .setComponent(aiaComponent) |
| 622 | .setAction(Intent.ACTION_VIEW) |
| 623 | .addCategory(Intent.CATEGORY_BROWSABLE) |
Jason Monk | 83c0051 | 2017-05-08 11:23:14 -0400 | [diff] [blame] | 624 | .addCategory("unique:" + System.currentTimeMillis()) |
Jason Monk | 697b82a | 2017-04-19 18:41:06 -0400 | [diff] [blame] | 625 | .putExtra(Intent.EXTRA_PACKAGE_NAME, appInfo.packageName) |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 626 | .putExtra(Intent.EXTRA_VERSION_CODE, (int) (appInfo.versionCode & 0x7fffffff)) |
Patrick Baumann | 531db46 | 2018-02-13 13:01:47 -0800 | [diff] [blame] | 627 | .putExtra(Intent.EXTRA_LONG_VERSION_CODE, appInfo.versionCode) |
Patrick Baumann | 531db46 | 2018-02-13 13:01:47 -0800 | [diff] [blame] | 628 | .putExtra(Intent.EXTRA_INSTANT_APP_FAILURE, pendingIntent); |
Jason Monk | 697b82a | 2017-04-19 18:41:06 -0400 | [diff] [blame] | 629 | |
| 630 | PendingIntent webPendingIntent = PendingIntent.getActivity(mContext, 0, goToWebIntent, 0); |
| 631 | Action webAction = new Notification.Action.Builder(null, mContext.getString(R.string.go_to_web), |
| 632 | webPendingIntent).build(); |
| 633 | builder.addAction(webAction); |
| 634 | } |
| 635 | |
| 636 | noMan.notifyAsUser(pkg, SystemMessage.NOTE_INSTANT_APPS, builder |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 637 | .addExtras(extras) |
| 638 | .addAction(action) |
| 639 | .setContentIntent(appInfoAction) |
| 640 | .setColor(mContext.getColor(R.color.instant_apps_color)) |
| 641 | .setContentTitle(appInfo.loadLabel(mContext.getPackageManager())) |
| 642 | .setLargeIcon(Icon.createWithResource(pkg, appInfo.icon)) |
| 643 | .setSmallIcon(Icon.createWithResource(mContext.getPackageName(), |
| 644 | R.drawable.instant_icon)) |
| 645 | .setContentText(message) |
| 646 | .setOngoing(true) |
| 647 | .build(), |
| 648 | new UserHandle(userId)); |
| 649 | } |
| 650 | |
Jason Monk | 697b82a | 2017-04-19 18:41:06 -0400 | [diff] [blame] | 651 | private Intent getTaskIntent(int taskId, int userId) { |
Winson Chung | 5fa3975 | 2017-10-04 14:50:15 -0700 | [diff] [blame] | 652 | try { |
| 653 | final List<ActivityManager.RecentTaskInfo> tasks = |
| 654 | ActivityManager.getService().getRecentTasks( |
| 655 | NUM_TASKS_FOR_INSTANT_APP_INFO, 0, userId).getList(); |
| 656 | for (int i = 0; i < tasks.size(); i++) { |
| 657 | if (tasks.get(i).id == taskId) { |
| 658 | return tasks.get(i).baseIntent; |
| 659 | } |
Jason Monk | 697b82a | 2017-04-19 18:41:06 -0400 | [diff] [blame] | 660 | } |
Winson Chung | 5fa3975 | 2017-10-04 14:50:15 -0700 | [diff] [blame] | 661 | } catch (RemoteException e) { |
| 662 | // Fall through |
Jason Monk | 697b82a | 2017-04-19 18:41:06 -0400 | [diff] [blame] | 663 | } |
| 664 | return null; |
| 665 | } |
| 666 | |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 667 | private boolean hasNotif(ArraySet<Pair<String, Integer>> notifs, String pkg, int userId) { |
| 668 | Pair<String, Integer> key = new Pair<>(pkg, userId); |
| 669 | if (notifs.remove(key)) { |
| 670 | mCurrentNotifs.add(key); |
| 671 | return true; |
| 672 | } |
| 673 | return false; |
| 674 | } |
| 675 | |
Fyodor Kupolov | 6005b3f | 2015-11-23 17:41:50 -0800 | [diff] [blame] | 676 | private final SynchronousUserSwitchObserver mUserSwitchListener = |
| 677 | new SynchronousUserSwitchObserver() { |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 678 | @Override |
Fyodor Kupolov | 6005b3f | 2015-11-23 17:41:50 -0800 | [diff] [blame] | 679 | public void onUserSwitching(int newUserId) throws RemoteException { |
Tony Mak | ec319ab | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 680 | mHandler.post(() -> mUserInfoController.reloadUserInfo()); |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | @Override |
| 684 | public void onUserSwitchComplete(int newUserId) throws RemoteException { |
Tony Mak | ec319ab | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 685 | mHandler.post(() -> { |
| 686 | updateAlarm(); |
Tony Mak | ec319ab | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 687 | updateManagedProfile(); |
| 688 | updateForegroundInstantApps(); |
Toni Barzic | e97f923 | 2016-04-27 18:10:58 -0700 | [diff] [blame] | 689 | }); |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 690 | } |
| 691 | }; |
| 692 | |
Jason Monk | 952d5d8 | 2014-10-27 15:28:22 -0400 | [diff] [blame] | 693 | private final HotspotController.Callback mHotspotCallback = new HotspotController.Callback() { |
| 694 | @Override |
Rohan Shah | e407112 | 2018-01-22 15:16:09 -0800 | [diff] [blame] | 695 | public void onHotspotChanged(boolean enabled, int numDevices) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 696 | mIconController.setIconVisibility(mSlotHotspot, enabled); |
Jason Monk | 952d5d8 | 2014-10-27 15:28:22 -0400 | [diff] [blame] | 697 | } |
| 698 | }; |
| 699 | |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 700 | private final CastController.Callback mCastCallback = new CastController.Callback() { |
| 701 | @Override |
| 702 | public void onCastDevicesChanged() { |
| 703 | updateCast(); |
| 704 | } |
| 705 | }; |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 706 | |
Juan Flores | 2ff3720 | 2015-04-30 13:44:23 +0200 | [diff] [blame] | 707 | private final NextAlarmController.NextAlarmChangeCallback mNextAlarmCallback = |
| 708 | new NextAlarmController.NextAlarmChangeCallback() { |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 709 | @Override |
| 710 | public void onNextAlarmChanged(AlarmManager.AlarmClockInfo nextAlarm) { |
Evan Laird | bee3eb8 | 2018-05-16 15:58:49 -0400 | [diff] [blame] | 711 | mNextAlarm = nextAlarm; |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 712 | updateAlarm(); |
| 713 | } |
| 714 | }; |
Juan Flores | 2ff3720 | 2015-04-30 13:44:23 +0200 | [diff] [blame] | 715 | |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 716 | @Override |
| 717 | public void appTransitionStarting(long startTime, long duration, boolean forced) { |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 718 | updateManagedProfile(); |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 719 | updateForegroundInstantApps(); |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 720 | } |
| 721 | |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 722 | @Override |
| 723 | public void onKeyguardShowingChanged() { |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 724 | updateManagedProfile(); |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 725 | updateForegroundInstantApps(); |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 726 | } |
John Spurlock | 604a5ee | 2015-06-01 12:27:22 -0400 | [diff] [blame] | 727 | |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 728 | @Override |
| 729 | public void onUserSetupChanged() { |
| 730 | boolean userSetup = mProvisionedController.isUserSetup( |
| 731 | mProvisionedController.getCurrentUser()); |
John Spurlock | 604a5ee | 2015-06-01 12:27:22 -0400 | [diff] [blame] | 732 | if (mCurrentUserSetup == userSetup) return; |
| 733 | mCurrentUserSetup = userSetup; |
| 734 | updateAlarm(); |
| 735 | } |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 736 | |
| 737 | @Override |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 738 | public void preloadRecentApps() { |
| 739 | updateForegroundInstantApps(); |
| 740 | } |
| 741 | |
| 742 | @Override |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 743 | public void onRotationLockStateChanged(boolean rotationLocked, boolean affordanceVisible) { |
| 744 | boolean portrait = RotationLockTile.isCurrentOrientationLockPortrait( |
| 745 | mRotationLockController, mContext); |
| 746 | if (rotationLocked) { |
| 747 | if (portrait) { |
| 748 | mIconController.setIcon(mSlotRotate, R.drawable.stat_sys_rotate_portrait, |
| 749 | mContext.getString(R.string.accessibility_rotation_lock_on_portrait)); |
| 750 | } else { |
| 751 | mIconController.setIcon(mSlotRotate, R.drawable.stat_sys_rotate_landscape, |
| 752 | mContext.getString(R.string.accessibility_rotation_lock_on_landscape)); |
| 753 | } |
Jason Monk | 8816dff | 2016-02-09 21:50:36 -0500 | [diff] [blame] | 754 | mIconController.setIconVisibility(mSlotRotate, true); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 755 | } else { |
Jason Monk | 8816dff | 2016-02-09 21:50:36 -0500 | [diff] [blame] | 756 | mIconController.setIconVisibility(mSlotRotate, false); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 757 | } |
| 758 | } |
| 759 | |
| 760 | private void updateHeadsetPlug(Intent intent) { |
| 761 | boolean connected = intent.getIntExtra("state", 0) != 0; |
| 762 | boolean hasMic = intent.getIntExtra("microphone", 0) != 0; |
| 763 | if (connected) { |
| 764 | String contentDescription = mContext.getString(hasMic |
| 765 | ? R.string.accessibility_status_bar_headset |
| 766 | : R.string.accessibility_status_bar_headphones); |
| 767 | mIconController.setIcon(mSlotHeadset, hasMic ? R.drawable.ic_headset_mic |
| 768 | : R.drawable.ic_headset, contentDescription); |
| 769 | mIconController.setIconVisibility(mSlotHeadset, true); |
| 770 | } else { |
| 771 | mIconController.setIconVisibility(mSlotHeadset, false); |
| 772 | } |
| 773 | } |
| 774 | |
Jason Monk | f23aa99 | 2016-01-22 16:45:21 -0500 | [diff] [blame] | 775 | @Override |
| 776 | public void onDataSaverChanged(boolean isDataSaving) { |
| 777 | mIconController.setIconVisibility(mSlotDataSaver, isDataSaving); |
| 778 | } |
| 779 | |
Winson Chung | aa35745 | 2017-10-31 11:35:30 -0700 | [diff] [blame] | 780 | private final SysUiTaskStackChangeListener mTaskListener = new SysUiTaskStackChangeListener() { |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 781 | @Override |
| 782 | public void onTaskStackChanged() { |
| 783 | // Listen for changes to stacks and then check which instant apps are foreground. |
| 784 | updateForegroundInstantApps(); |
| 785 | } |
| 786 | }; |
| 787 | |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 788 | private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { |
| 789 | @Override |
| 790 | public void onReceive(Context context, Intent intent) { |
| 791 | String action = intent.getAction(); |
Lucas Dupin | 5e0f0d2 | 2018-02-26 13:32:16 -0800 | [diff] [blame] | 792 | switch (action) { |
| 793 | case AudioManager.RINGER_MODE_CHANGED_ACTION: |
| 794 | case AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION: |
| 795 | updateVolumeZen(); |
| 796 | break; |
| 797 | case TelephonyIntents.ACTION_SIM_STATE_CHANGED: |
| 798 | // Avoid rebroadcast because SysUI is direct boot aware. |
| 799 | if (intent.getBooleanExtra(TelephonyIntents.EXTRA_REBROADCAST_ON_UNLOCK, |
| 800 | false)) { |
| 801 | break; |
| 802 | } |
| 803 | updateSimState(intent); |
| 804 | break; |
| 805 | case TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED: |
| 806 | updateTTY(intent.getIntExtra(TelecomManager.EXTRA_CURRENT_TTY_MODE, |
| 807 | TelecomManager.TTY_MODE_OFF)); |
| 808 | break; |
| 809 | case Intent.ACTION_MANAGED_PROFILE_AVAILABLE: |
| 810 | case Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE: |
| 811 | case Intent.ACTION_MANAGED_PROFILE_REMOVED: |
| 812 | updateManagedProfile(); |
| 813 | break; |
| 814 | case AudioManager.ACTION_HEADSET_PLUG: |
| 815 | updateHeadsetPlug(intent); |
| 816 | break; |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 817 | } |
| 818 | } |
| 819 | }; |
| 820 | |
| 821 | private Runnable mRemoveCastIconRunnable = new Runnable() { |
| 822 | @Override |
| 823 | public void run() { |
| 824 | if (DEBUG) Log.v(TAG, "updateCast: hiding icon NOW"); |
| 825 | mIconController.setIconVisibility(mSlotCast, false); |
| 826 | } |
| 827 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 828 | } |