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