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 | |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 19 | import android.app.ActivityManager; |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 20 | import android.app.ActivityManager.StackId; |
| 21 | import android.app.ActivityManager.StackInfo; |
Adrian Roos | c42a1e1 | 2014-07-07 23:35:53 +0200 | [diff] [blame] | 22 | import android.app.AlarmManager; |
John Spurlock | 604a5ee | 2015-06-01 12:27:22 -0400 | [diff] [blame] | 23 | import android.app.AlarmManager.AlarmClockInfo; |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 24 | import android.app.AppGlobals; |
| 25 | import android.app.Notification; |
| 26 | import android.app.Notification.Action; |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 27 | import android.app.NotificationManager; |
| 28 | import android.app.PendingIntent; |
Fyodor Kupolov | 6005b3f | 2015-11-23 17:41:50 -0800 | [diff] [blame] | 29 | import android.app.SynchronousUserSwitchObserver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import android.content.BroadcastReceiver; |
| 31 | import android.content.Context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import android.content.Intent; |
| 33 | import android.content.IntentFilter; |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 34 | import android.content.pm.ApplicationInfo; |
| 35 | import android.content.pm.IPackageManager; |
| 36 | import android.content.pm.PackageManager; |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 37 | import android.content.pm.UserInfo; |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 38 | import android.graphics.drawable.Icon; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | import android.media.AudioManager; |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 40 | import android.net.Uri; |
| 41 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | import android.os.Handler; |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 43 | import android.os.RemoteException; |
Adrian Roos | c42a1e1 | 2014-07-07 23:35:53 +0200 | [diff] [blame] | 44 | import android.os.UserHandle; |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 45 | import android.os.UserManager; |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 46 | import android.provider.Settings; |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 47 | import android.provider.Settings.Global; |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 48 | import android.service.notification.StatusBarNotification; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 49 | import android.telecom.TelecomManager; |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 50 | import android.util.ArraySet; |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 51 | import android.util.Log; |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 52 | import android.util.Pair; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 53 | |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 54 | import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 55 | import com.android.internal.telephony.IccCardConstants; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 56 | import com.android.internal.telephony.TelephonyIntents; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 57 | import com.android.systemui.Dependency; |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 58 | import com.android.systemui.R; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 59 | import com.android.systemui.SysUiServiceProvider; |
John Spurlock | 3c4076a | 2015-02-24 12:12:25 -0500 | [diff] [blame] | 60 | import com.android.systemui.qs.tiles.DndTile; |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 61 | import com.android.systemui.qs.tiles.RotationLockTile; |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 62 | import com.android.systemui.recents.misc.SystemServicesProxy; |
| 63 | import com.android.systemui.recents.misc.SystemServicesProxy.TaskStackListener; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 64 | import com.android.systemui.statusbar.CommandQueue; |
| 65 | import com.android.systemui.statusbar.CommandQueue.Callbacks; |
Jason Monk | 7036436 | 2015-08-06 16:32:18 -0400 | [diff] [blame] | 66 | import com.android.systemui.statusbar.policy.BluetoothController; |
| 67 | import com.android.systemui.statusbar.policy.BluetoothController.Callback; |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 68 | import com.android.systemui.statusbar.policy.CastController; |
| 69 | import com.android.systemui.statusbar.policy.CastController.CastDevice; |
Jason Monk | f23aa99 | 2016-01-22 16:45:21 -0500 | [diff] [blame] | 70 | import com.android.systemui.statusbar.policy.DataSaverController; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 71 | import com.android.systemui.statusbar.policy.DataSaverController.Listener; |
| 72 | import com.android.systemui.statusbar.policy.DeviceProvisionedController; |
| 73 | import com.android.systemui.statusbar.policy.DeviceProvisionedController.DeviceProvisionedListener; |
Jason Monk | 952d5d8 | 2014-10-27 15:28:22 -0400 | [diff] [blame] | 74 | import com.android.systemui.statusbar.policy.HotspotController; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 75 | import com.android.systemui.statusbar.policy.KeyguardMonitor; |
Juan Flores | 2ff3720 | 2015-04-30 13:44:23 +0200 | [diff] [blame] | 76 | import com.android.systemui.statusbar.policy.NextAlarmController; |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 77 | import com.android.systemui.statusbar.policy.RotationLockController; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 78 | import com.android.systemui.statusbar.policy.RotationLockController.RotationLockControllerCallback; |
Adrian Roos | 88b1193 | 2015-07-22 14:59:48 -0700 | [diff] [blame] | 79 | import com.android.systemui.statusbar.policy.UserInfoController; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 80 | import com.android.systemui.statusbar.policy.ZenModeController; |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 81 | import com.android.systemui.util.NotificationChannels; |
| 82 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | /** |
| 84 | * 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] | 85 | * bar at boot time. It goes through the normal API for icons, even though it probably |
| 86 | * strictly doesn't need to. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | */ |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 88 | public class PhoneStatusBarPolicy implements Callback, Callbacks, |
| 89 | RotationLockControllerCallback, Listener, |
| 90 | ZenModeController.Callback, DeviceProvisionedListener, KeyguardMonitor.Callback { |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 91 | private static final String TAG = "PhoneStatusBarPolicy"; |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 92 | private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 93 | |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 94 | private final String mSlotCast; |
| 95 | private final String mSlotHotspot; |
| 96 | private final String mSlotBluetooth; |
| 97 | private final String mSlotTty; |
| 98 | private final String mSlotZen; |
| 99 | private final String mSlotVolume; |
| 100 | private final String mSlotAlarmClock; |
| 101 | private final String mSlotManagedProfile; |
| 102 | private final String mSlotRotate; |
| 103 | private final String mSlotHeadset; |
Jason Monk | f23aa99 | 2016-01-22 16:45:21 -0500 | [diff] [blame] | 104 | private final String mSlotDataSaver; |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 105 | |
Dianne Hackborn | 4840e14 | 2009-03-24 22:40:29 -0700 | [diff] [blame] | 106 | private final Context mContext; |
Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 107 | private final Handler mHandler = new Handler(); |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 108 | private final CastController mCast; |
Jason Monk | 952d5d8 | 2014-10-27 15:28:22 -0400 | [diff] [blame] | 109 | private final HotspotController mHotspot; |
Juan Flores | 2ff3720 | 2015-04-30 13:44:23 +0200 | [diff] [blame] | 110 | private final NextAlarmController mNextAlarm; |
John Spurlock | 1578226 | 2015-05-29 15:35:53 -0400 | [diff] [blame] | 111 | private final AlarmManager mAlarmManager; |
Adrian Roos | 88b1193 | 2015-07-22 14:59:48 -0700 | [diff] [blame] | 112 | private final UserInfoController mUserInfoController; |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 113 | private final UserManager mUserManager; |
Jason Monk | 07473ce | 2016-01-05 14:59:19 -0500 | [diff] [blame] | 114 | private final StatusBarIconController mIconController; |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 115 | private final RotationLockController mRotationLockController; |
Jason Monk | f23aa99 | 2016-01-22 16:45:21 -0500 | [diff] [blame] | 116 | private final DataSaverController mDataSaver; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 117 | private final ZenModeController mZenController; |
| 118 | private final DeviceProvisionedController mProvisionedController; |
| 119 | private final KeyguardMonitor mKeyguardMonitor; |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 120 | private final ArraySet<Pair<String, Integer>> mCurrentNotifs = new ArraySet<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 121 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 122 | // Assume it's all good unless we hear otherwise. We don't always seem |
| 123 | // to get broadcasts that it *is* there. |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 124 | IccCardConstants.State mSimState = IccCardConstants.State.READY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 126 | private boolean mZenVisible; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | private boolean mVolumeVisible; |
John Spurlock | 604a5ee | 2015-06-01 12:27:22 -0400 | [diff] [blame] | 128 | private boolean mCurrentUserSetup; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 129 | |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 130 | private boolean mManagedProfileIconVisible = false; |
| 131 | private boolean mManagedProfileInQuietMode = false; |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 132 | |
Jason Monk | 7036436 | 2015-08-06 16:32:18 -0400 | [diff] [blame] | 133 | private BluetoothController mBluetooth; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 134 | |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 135 | public PhoneStatusBarPolicy(Context context, StatusBarIconController iconController) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | mContext = context; |
Jason Monk | 07473ce | 2016-01-05 14:59:19 -0500 | [diff] [blame] | 137 | mIconController = iconController; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 138 | mCast = Dependency.get(CastController.class); |
| 139 | mHotspot = Dependency.get(HotspotController.class); |
| 140 | mBluetooth = Dependency.get(BluetoothController.class); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 141 | mNextAlarm = Dependency.get(NextAlarmController.class); |
John Spurlock | 1578226 | 2015-05-29 15:35:53 -0400 | [diff] [blame] | 142 | mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 143 | mUserInfoController = Dependency.get(UserInfoController.class); |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 144 | mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 145 | mRotationLockController = Dependency.get(RotationLockController.class); |
| 146 | mDataSaver = Dependency.get(DataSaverController.class); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 147 | mZenController = Dependency.get(ZenModeController.class); |
| 148 | mProvisionedController = Dependency.get(DeviceProvisionedController.class); |
| 149 | mKeyguardMonitor = Dependency.get(KeyguardMonitor.class); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 150 | |
| 151 | mSlotCast = context.getString(com.android.internal.R.string.status_bar_cast); |
| 152 | mSlotHotspot = context.getString(com.android.internal.R.string.status_bar_hotspot); |
| 153 | mSlotBluetooth = context.getString(com.android.internal.R.string.status_bar_bluetooth); |
| 154 | mSlotTty = context.getString(com.android.internal.R.string.status_bar_tty); |
| 155 | mSlotZen = context.getString(com.android.internal.R.string.status_bar_zen); |
| 156 | mSlotVolume = context.getString(com.android.internal.R.string.status_bar_volume); |
| 157 | mSlotAlarmClock = context.getString(com.android.internal.R.string.status_bar_alarm_clock); |
| 158 | mSlotManagedProfile = context.getString( |
| 159 | com.android.internal.R.string.status_bar_managed_profile); |
| 160 | mSlotRotate = context.getString(com.android.internal.R.string.status_bar_rotate); |
| 161 | mSlotHeadset = context.getString(com.android.internal.R.string.status_bar_headset); |
Jason Monk | f23aa99 | 2016-01-22 16:45:21 -0500 | [diff] [blame] | 162 | mSlotDataSaver = context.getString(com.android.internal.R.string.status_bar_data_saver); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 163 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | |
Daniel Sandler | e3b7a2d | 2011-10-27 16:16:15 -0400 | [diff] [blame] | 165 | // listen for broadcasts |
| 166 | IntentFilter filter = new IntentFilter(); |
Daniel Sandler | e3b7a2d | 2011-10-27 16:16:15 -0400 | [diff] [blame] | 167 | filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); |
John Spurlock | bcc1087 | 2014-11-28 15:29:21 -0500 | [diff] [blame] | 168 | filter.addAction(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 169 | filter.addAction(AudioManager.ACTION_HEADSET_PLUG); |
Daniel Sandler | e3b7a2d | 2011-10-27 16:16:15 -0400 | [diff] [blame] | 170 | filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 171 | filter.addAction(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED); |
Rubin Xu | e95057a | 2016-04-01 16:49:25 +0100 | [diff] [blame] | 172 | filter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE); |
| 173 | filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE); |
Nicolas Prevot | 6c7b874 | 2016-04-13 10:28:58 +0100 | [diff] [blame] | 174 | filter.addAction(Intent.ACTION_MANAGED_PROFILE_REMOVED); |
Daniel Sandler | e3b7a2d | 2011-10-27 16:16:15 -0400 | [diff] [blame] | 175 | mContext.registerReceiver(mIntentReceiver, filter, null, mHandler); |
| 176 | |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 177 | // listen for user / profile change. |
| 178 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 179 | ActivityManager.getService().registerUserSwitchObserver(mUserSwitchListener, TAG); |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 180 | } catch (RemoteException e) { |
| 181 | // Ignore |
| 182 | } |
| 183 | |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 184 | // TTY status |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 185 | mIconController.setIcon(mSlotTty, R.drawable.stat_sys_tty_mode, null); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 186 | mIconController.setIconVisibility(mSlotTty, false); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 187 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | // bluetooth status |
Jorim Jaggi | 2d75f9f | 2014-10-08 17:10:58 -0700 | [diff] [blame] | 189 | updateBluetooth(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 190 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | // Alarm clock |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 192 | mIconController.setIcon(mSlotAlarmClock, R.drawable.stat_sys_alarm, null); |
| 193 | mIconController.setIconVisibility(mSlotAlarmClock, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 195 | // zen |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 196 | mIconController.setIcon(mSlotZen, R.drawable.stat_sys_zen_important, null); |
| 197 | mIconController.setIconVisibility(mSlotZen, false); |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 198 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 199 | // volume |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 200 | mIconController.setIcon(mSlotVolume, R.drawable.stat_sys_ringer_vibrate, null); |
| 201 | mIconController.setIconVisibility(mSlotVolume, false); |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 202 | updateVolumeZen(); |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 203 | |
| 204 | // cast |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 205 | mIconController.setIcon(mSlotCast, R.drawable.stat_sys_cast, null); |
| 206 | mIconController.setIconVisibility(mSlotCast, false); |
Jason Monk | 952d5d8 | 2014-10-27 15:28:22 -0400 | [diff] [blame] | 207 | |
| 208 | // hotspot |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 209 | mIconController.setIcon(mSlotHotspot, R.drawable.stat_sys_hotspot, |
Jason Monk | 08187a4 | 2015-06-09 14:33:51 -0400 | [diff] [blame] | 210 | mContext.getString(R.string.accessibility_status_bar_hotspot)); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 211 | mIconController.setIconVisibility(mSlotHotspot, mHotspot.isHotspotEnabled()); |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 212 | |
| 213 | // managed profile |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 214 | mIconController.setIcon(mSlotManagedProfile, R.drawable.stat_sys_managed_profile_status, |
Adrian Roos | 1b5eb97 | 2015-06-11 18:22:52 -0700 | [diff] [blame] | 215 | mContext.getString(R.string.accessibility_managed_profile)); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 216 | mIconController.setIconVisibility(mSlotManagedProfile, mManagedProfileIconVisible); |
Jason Monk | f23aa99 | 2016-01-22 16:45:21 -0500 | [diff] [blame] | 217 | |
| 218 | // data saver |
| 219 | mIconController.setIcon(mSlotDataSaver, R.drawable.stat_sys_data_saver, |
| 220 | context.getString(R.string.accessibility_data_saver_on)); |
| 221 | mIconController.setIconVisibility(mSlotDataSaver, false); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 222 | |
| 223 | mRotationLockController.addCallback(this); |
| 224 | mBluetooth.addCallback(this); |
| 225 | mProvisionedController.addCallback(this); |
| 226 | mZenController.addCallback(this); |
| 227 | mCast.addCallback(mCastCallback); |
| 228 | mHotspot.addCallback(mHotspotCallback); |
| 229 | mNextAlarm.addCallback(mNextAlarmCallback); |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 230 | mDataSaver.addCallback(this); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 231 | mKeyguardMonitor.addCallback(this); |
| 232 | |
| 233 | SysUiServiceProvider.getComponent(mContext, CommandQueue.class).addCallbacks(this); |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 234 | SystemServicesProxy.getInstance(mContext).registerTaskStackListener(mTaskListener); |
| 235 | |
| 236 | // Clear out all old notifications on startup (only present in the case where sysui dies) |
| 237 | NotificationManager noMan = mContext.getSystemService(NotificationManager.class); |
| 238 | for (StatusBarNotification notification : noMan.getActiveNotifications()) { |
| 239 | if (notification.getId() == SystemMessage.NOTE_INSTANT_APPS) { |
| 240 | noMan.cancel(notification.getTag(), notification.getId()); |
| 241 | } |
| 242 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | } |
| 244 | |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 245 | public void destroy() { |
| 246 | mRotationLockController.removeCallback(this); |
| 247 | mBluetooth.removeCallback(this); |
| 248 | mProvisionedController.removeCallback(this); |
| 249 | mZenController.removeCallback(this); |
| 250 | mCast.removeCallback(mCastCallback); |
| 251 | mHotspot.removeCallback(mHotspotCallback); |
| 252 | mNextAlarm.removeCallback(mNextAlarmCallback); |
| 253 | mDataSaver.removeCallback(this); |
| 254 | mKeyguardMonitor.removeCallback(this); |
| 255 | SysUiServiceProvider.getComponent(mContext, CommandQueue.class).removeCallbacks(this); |
| 256 | mContext.unregisterReceiver(mIntentReceiver); |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 257 | |
| 258 | NotificationManager noMan = mContext.getSystemService(NotificationManager.class); |
| 259 | mCurrentNotifs.forEach(v -> noMan.cancelAsUser(v.first, SystemMessage.NOTE_INSTANT_APPS, |
| 260 | new UserHandle(v.second))); |
Nicolas Prevot | 1dbbe7d | 2016-05-17 12:52:54 +0100 | [diff] [blame] | 261 | } |
| 262 | |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 263 | @Override |
| 264 | public void onZenChanged(int zen) { |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 265 | updateVolumeZen(); |
John Spurlock | ba2c6a0 | 2014-05-19 09:44:06 -0400 | [diff] [blame] | 266 | } |
| 267 | |
Adrian Roos | c42a1e1 | 2014-07-07 23:35:53 +0200 | [diff] [blame] | 268 | private void updateAlarm() { |
John Spurlock | 604a5ee | 2015-06-01 12:27:22 -0400 | [diff] [blame] | 269 | final AlarmClockInfo alarm = mAlarmManager.getNextAlarmClock(UserHandle.USER_CURRENT); |
| 270 | final boolean hasAlarm = alarm != null && alarm.getTriggerTime() > 0; |
Jason Monk | 20c0eb4 | 2017-03-02 17:35:49 -0500 | [diff] [blame] | 271 | int zen = mZenController.getZen(); |
| 272 | final boolean zenNone = zen == Global.ZEN_MODE_NO_INTERRUPTIONS; |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 273 | mIconController.setIcon(mSlotAlarmClock, zenNone ? R.drawable.stat_sys_alarm_dim |
Jason Monk | 07473ce | 2016-01-05 14:59:19 -0500 | [diff] [blame] | 274 | : R.drawable.stat_sys_alarm, null); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 275 | mIconController.setIconVisibility(mSlotAlarmClock, mCurrentUserSetup && hasAlarm); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 276 | } |
| 277 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 278 | private final void updateSimState(Intent intent) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 279 | String stateExtra = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE); |
| 280 | if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) { |
| 281 | mSimState = IccCardConstants.State.ABSENT; |
Jason Monk | 07473ce | 2016-01-05 14:59:19 -0500 | [diff] [blame] | 282 | } else if (IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR.equals(stateExtra)) { |
Rakesh Pallerla | f099a5f | 2013-02-06 11:44:23 +0530 | [diff] [blame] | 283 | mSimState = IccCardConstants.State.CARD_IO_ERROR; |
Junda Liu | a2f6a67 | 2016-05-24 10:07:40 -0700 | [diff] [blame] | 284 | } else if (IccCardConstants.INTENT_VALUE_ICC_CARD_RESTRICTED.equals(stateExtra)) { |
| 285 | mSimState = IccCardConstants.State.CARD_RESTRICTED; |
Jason Monk | 07473ce | 2016-01-05 14:59:19 -0500 | [diff] [blame] | 286 | } else if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(stateExtra)) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 287 | mSimState = IccCardConstants.State.READY; |
Jason Monk | 07473ce | 2016-01-05 14:59:19 -0500 | [diff] [blame] | 288 | } else if (IccCardConstants.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 289 | final String lockedReason = |
| 290 | intent.getStringExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON); |
| 291 | if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) { |
| 292 | mSimState = IccCardConstants.State.PIN_REQUIRED; |
Jason Monk | 07473ce | 2016-01-05 14:59:19 -0500 | [diff] [blame] | 293 | } else if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 294 | mSimState = IccCardConstants.State.PUK_REQUIRED; |
Jason Monk | 07473ce | 2016-01-05 14:59:19 -0500 | [diff] [blame] | 295 | } else { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 296 | mSimState = IccCardConstants.State.NETWORK_LOCKED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 297 | } |
| 298 | } else { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 299 | mSimState = IccCardConstants.State.UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 300 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 301 | } |
| 302 | |
John Spurlock | bcc1087 | 2014-11-28 15:29:21 -0500 | [diff] [blame] | 303 | private final void updateVolumeZen() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 304 | AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 305 | |
| 306 | boolean zenVisible = false; |
| 307 | int zenIconId = 0; |
| 308 | String zenDescription = null; |
| 309 | |
| 310 | boolean volumeVisible = false; |
| 311 | int volumeIconId = 0; |
| 312 | String volumeDescription = null; |
Jason Monk | 20c0eb4 | 2017-03-02 17:35:49 -0500 | [diff] [blame] | 313 | int zen = mZenController.getZen(); |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 314 | |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 315 | if (DndTile.isVisible(mContext) || DndTile.isCombinedIcon(mContext)) { |
Jason Monk | 20c0eb4 | 2017-03-02 17:35:49 -0500 | [diff] [blame] | 316 | zenVisible = zen != Global.ZEN_MODE_OFF; |
| 317 | zenIconId = zen == Global.ZEN_MODE_NO_INTERRUPTIONS |
John Spurlock | 4ec8b60 | 2015-05-11 17:46:28 -0400 | [diff] [blame] | 318 | ? R.drawable.stat_sys_dnd_total_silence : R.drawable.stat_sys_dnd; |
John Spurlock | 3c4076a | 2015-02-24 12:12:25 -0500 | [diff] [blame] | 319 | zenDescription = mContext.getString(R.string.quick_settings_dnd_label); |
Jason Monk | 20c0eb4 | 2017-03-02 17:35:49 -0500 | [diff] [blame] | 320 | } else if (zen == Global.ZEN_MODE_NO_INTERRUPTIONS) { |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 321 | zenVisible = true; |
| 322 | zenIconId = R.drawable.stat_sys_zen_none; |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 323 | zenDescription = mContext.getString(R.string.interruption_level_none); |
Jason Monk | 20c0eb4 | 2017-03-02 17:35:49 -0500 | [diff] [blame] | 324 | } else if (zen == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS) { |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 325 | zenVisible = true; |
| 326 | zenIconId = R.drawable.stat_sys_zen_important; |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 327 | zenDescription = mContext.getString(R.string.interruption_level_priority); |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 328 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 329 | |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 330 | if (DndTile.isVisible(mContext) && !DndTile.isCombinedIcon(mContext) |
John Spurlock | a48d779 | 2015-03-03 17:35:57 -0500 | [diff] [blame] | 331 | && audioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_SILENT) { |
| 332 | volumeVisible = true; |
| 333 | volumeIconId = R.drawable.stat_sys_ringer_silent; |
| 334 | volumeDescription = mContext.getString(R.string.accessibility_ringer_silent); |
Jason Monk | 20c0eb4 | 2017-03-02 17:35:49 -0500 | [diff] [blame] | 335 | } else if (zen != Global.ZEN_MODE_NO_INTERRUPTIONS && zen != Global.ZEN_MODE_ALARMS && |
John Spurlock | 661f2cf | 2014-11-17 10:29:10 -0500 | [diff] [blame] | 336 | audioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_VIBRATE) { |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 337 | volumeVisible = true; |
| 338 | volumeIconId = R.drawable.stat_sys_ringer_vibrate; |
| 339 | volumeDescription = mContext.getString(R.string.accessibility_ringer_vibrate); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 340 | } |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 341 | |
| 342 | if (zenVisible) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 343 | mIconController.setIcon(mSlotZen, zenIconId, zenDescription); |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 344 | } |
| 345 | if (zenVisible != mZenVisible) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 346 | mIconController.setIconVisibility(mSlotZen, zenVisible); |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 347 | mZenVisible = zenVisible; |
| 348 | } |
| 349 | |
| 350 | if (volumeVisible) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 351 | mIconController.setIcon(mSlotVolume, volumeIconId, volumeDescription); |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 352 | } |
| 353 | if (volumeVisible != mVolumeVisible) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 354 | mIconController.setIconVisibility(mSlotVolume, volumeVisible); |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 355 | mVolumeVisible = volumeVisible; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 356 | } |
John Spurlock | 1578226 | 2015-05-29 15:35:53 -0400 | [diff] [blame] | 357 | updateAlarm(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 358 | } |
| 359 | |
Jason Monk | 7036436 | 2015-08-06 16:32:18 -0400 | [diff] [blame] | 360 | @Override |
| 361 | public void onBluetoothDevicesChanged() { |
| 362 | updateBluetooth(); |
| 363 | } |
| 364 | |
| 365 | @Override |
| 366 | public void onBluetoothStateChange(boolean enabled) { |
| 367 | updateBluetooth(); |
| 368 | } |
| 369 | |
Jorim Jaggi | 2d75f9f | 2014-10-08 17:10:58 -0700 | [diff] [blame] | 370 | private final void updateBluetooth() { |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 371 | int iconId = R.drawable.stat_sys_data_bluetooth; |
Jorim Jaggi | 2d75f9f | 2014-10-08 17:10:58 -0700 | [diff] [blame] | 372 | String contentDescription = |
Jason Monk | 1aa3282 | 2015-07-14 16:10:32 -0400 | [diff] [blame] | 373 | mContext.getString(R.string.accessibility_quick_settings_bluetooth_on); |
Jason Monk | 7036436 | 2015-08-06 16:32:18 -0400 | [diff] [blame] | 374 | boolean bluetoothEnabled = false; |
| 375 | if (mBluetooth != null) { |
| 376 | bluetoothEnabled = mBluetooth.isBluetoothEnabled(); |
| 377 | if (mBluetooth.isBluetoothConnected()) { |
Jaikumar Ganesh | d9bb688 | 2010-09-27 17:05:24 -0700 | [diff] [blame] | 378 | iconId = R.drawable.stat_sys_data_bluetooth_connected; |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 379 | contentDescription = mContext.getString(R.string.accessibility_bluetooth_connected); |
Jaikumar Ganesh | 084c665 | 2009-12-07 10:58:18 -0800 | [diff] [blame] | 380 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 381 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 382 | |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 383 | mIconController.setIcon(mSlotBluetooth, iconId, contentDescription); |
| 384 | mIconController.setIconVisibility(mSlotBluetooth, bluetoothEnabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 385 | } |
| 386 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 387 | private final void updateTTY(Intent intent) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 388 | int currentTtyMode = intent.getIntExtra(TelecomManager.EXTRA_CURRENT_TTY_MODE, |
| 389 | TelecomManager.TTY_MODE_OFF); |
| 390 | boolean enabled = currentTtyMode != TelecomManager.TTY_MODE_OFF; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 391 | |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 392 | if (DEBUG) Log.v(TAG, "updateTTY: enabled: " + enabled); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 393 | |
| 394 | if (enabled) { |
| 395 | // TTY is on |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 396 | if (DEBUG) Log.v(TAG, "updateTTY: set TTY on"); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 397 | mIconController.setIcon(mSlotTty, R.drawable.stat_sys_tty_mode, |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 398 | mContext.getString(R.string.accessibility_tty_enabled)); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 399 | mIconController.setIconVisibility(mSlotTty, true); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 400 | } else { |
| 401 | // TTY is off |
John Spurlock | a37e9c8 | 2014-07-08 09:40:31 -0400 | [diff] [blame] | 402 | if (DEBUG) Log.v(TAG, "updateTTY: set TTY off"); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 403 | mIconController.setIconVisibility(mSlotTty, false); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 404 | } |
| 405 | } |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 406 | |
| 407 | private void updateCast() { |
| 408 | boolean isCasting = false; |
| 409 | for (CastDevice device : mCast.getCastDevices()) { |
| 410 | if (device.state == CastDevice.STATE_CONNECTING |
| 411 | || device.state == CastDevice.STATE_CONNECTED) { |
| 412 | isCasting = true; |
| 413 | break; |
| 414 | } |
| 415 | } |
| 416 | if (DEBUG) Log.v(TAG, "updateCast: isCasting: " + isCasting); |
Dan Sandler | 8fd25bf | 2015-10-20 16:01:27 -0700 | [diff] [blame] | 417 | mHandler.removeCallbacks(mRemoveCastIconRunnable); |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 418 | if (isCasting) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 419 | mIconController.setIcon(mSlotCast, R.drawable.stat_sys_cast, |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 420 | mContext.getString(R.string.accessibility_casting)); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 421 | mIconController.setIconVisibility(mSlotCast, true); |
Dan Sandler | 8fd25bf | 2015-10-20 16:01:27 -0700 | [diff] [blame] | 422 | } else { |
| 423 | // don't turn off the screen-record icon for a few seconds, just to make sure the user |
| 424 | // has seen it |
| 425 | if (DEBUG) Log.v(TAG, "updateCast: hiding icon in 3 sec..."); |
| 426 | mHandler.postDelayed(mRemoveCastIconRunnable, 3000); |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 427 | } |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 428 | } |
| 429 | |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 430 | private void updateQuietState() { |
| 431 | mManagedProfileInQuietMode = false; |
| 432 | int currentUserId = ActivityManager.getCurrentUser(); |
| 433 | for (UserInfo ui : mUserManager.getEnabledProfiles(currentUserId)) { |
| 434 | if (ui.isManagedProfile() && ui.isQuietModeEnabled()) { |
| 435 | mManagedProfileInQuietMode = true; |
| 436 | return; |
| 437 | } |
| 438 | } |
| 439 | } |
| 440 | |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 441 | private void updateManagedProfile() { |
Tony Mak | ec319ab | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 442 | try { |
| 443 | final boolean showIcon; |
| 444 | final int userId = ActivityManager.getService().getLastResumedActivityUserId(); |
| 445 | if (mUserManager.isManagedProfile(userId) && !mKeyguardMonitor.isShowing()) { |
| 446 | showIcon = true; |
| 447 | mIconController.setIcon(mSlotManagedProfile, |
| 448 | R.drawable.stat_sys_managed_profile_status, |
| 449 | mContext.getString(R.string.accessibility_managed_profile)); |
| 450 | } else if (mManagedProfileInQuietMode) { |
| 451 | showIcon = true; |
| 452 | mIconController.setIcon(mSlotManagedProfile, |
| 453 | R.drawable.stat_sys_managed_profile_status_off, |
| 454 | mContext.getString(R.string.accessibility_managed_profile)); |
| 455 | } else { |
| 456 | showIcon = false; |
| 457 | } |
| 458 | if (mManagedProfileIconVisible != showIcon) { |
| 459 | mIconController.setIconVisibility(mSlotManagedProfile, showIcon); |
| 460 | mManagedProfileIconVisible = showIcon; |
| 461 | } |
| 462 | } catch (RemoteException ex) { |
| 463 | Log.w(TAG, "updateManagedProfile: ", ex); |
| 464 | // ignore |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 465 | } |
| 466 | } |
| 467 | |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 468 | private void updateForegroundInstantApps() { |
| 469 | NotificationManager noMan = mContext.getSystemService(NotificationManager.class); |
| 470 | ArraySet<Pair<String, Integer>> notifs = new ArraySet<>(mCurrentNotifs); |
| 471 | IPackageManager pm = AppGlobals.getPackageManager(); |
| 472 | mCurrentNotifs.clear(); |
| 473 | try { |
| 474 | int[] STACKS_TO_CHECK = new int[]{ |
| 475 | StackId.FULLSCREEN_WORKSPACE_STACK_ID, |
| 476 | StackId.DOCKED_STACK_ID, |
| 477 | }; |
| 478 | for (int i = 0; i < STACKS_TO_CHECK.length; i++) { |
| 479 | StackInfo info = ActivityManager.getService().getStackInfo(STACKS_TO_CHECK[i]); |
| 480 | if (info == null || info.topActivity == null) continue; |
| 481 | String pkg = info.topActivity.getPackageName(); |
| 482 | if (!hasNotif(notifs, pkg, info.userId)) { |
| 483 | // TODO: Optimize by not always needing to get application info. |
| 484 | // Maybe cache non-ephemeral packages? |
Jason Monk | 4597600 | 2017-02-21 13:45:36 -0500 | [diff] [blame] | 485 | ApplicationInfo appInfo = pm.getApplicationInfo(pkg, |
| 486 | PackageManager.MATCH_UNINSTALLED_PACKAGES, info.userId); |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 487 | if (appInfo.isInstantApp()) { |
| 488 | postEphemeralNotif(pkg, info.userId, appInfo, noMan); |
| 489 | } |
| 490 | } |
| 491 | } |
| 492 | } catch (RemoteException e) { |
| 493 | e.rethrowFromSystemServer(); |
| 494 | } |
| 495 | // Cancel all the leftover notifications that don't have a foreground process anymore. |
| 496 | notifs.forEach(v -> noMan.cancelAsUser(v.first, SystemMessage.NOTE_INSTANT_APPS, |
| 497 | new UserHandle(v.second))); |
| 498 | } |
| 499 | |
| 500 | private void postEphemeralNotif(String pkg, int userId, ApplicationInfo appInfo, |
| 501 | NotificationManager noMan) { |
| 502 | final Bundle extras = new Bundle(); |
| 503 | extras.putString(Notification.EXTRA_SUBSTITUTE_APP_NAME, |
| 504 | mContext.getString(R.string.instant_apps)); |
| 505 | mCurrentNotifs.add(new Pair<>(pkg, userId)); |
| 506 | String message = mContext.getString(R.string.instant_apps_message); |
| 507 | PendingIntent appInfoAction = PendingIntent.getActivity(mContext, 0, |
| 508 | new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS) |
| 509 | .setData(Uri.fromParts("package", pkg, null)), 0); |
| 510 | // TODO: Add action for go to web as well. |
| 511 | Action action = new Notification.Action.Builder(null, mContext.getString(R.string.app_info), |
| 512 | appInfoAction).build(); |
| 513 | |
| 514 | noMan.notifyAsUser(pkg, SystemMessage.NOTE_INSTANT_APPS, |
| 515 | new Notification.Builder(mContext, NotificationChannels.GENERAL) |
| 516 | .addExtras(extras) |
| 517 | .addAction(action) |
| 518 | .setContentIntent(appInfoAction) |
| 519 | .setColor(mContext.getColor(R.color.instant_apps_color)) |
| 520 | .setContentTitle(appInfo.loadLabel(mContext.getPackageManager())) |
| 521 | .setLargeIcon(Icon.createWithResource(pkg, appInfo.icon)) |
| 522 | .setSmallIcon(Icon.createWithResource(mContext.getPackageName(), |
| 523 | R.drawable.instant_icon)) |
| 524 | .setContentText(message) |
| 525 | .setOngoing(true) |
| 526 | .build(), |
| 527 | new UserHandle(userId)); |
| 528 | } |
| 529 | |
| 530 | private boolean hasNotif(ArraySet<Pair<String, Integer>> notifs, String pkg, int userId) { |
| 531 | Pair<String, Integer> key = new Pair<>(pkg, userId); |
| 532 | if (notifs.remove(key)) { |
| 533 | mCurrentNotifs.add(key); |
| 534 | return true; |
| 535 | } |
| 536 | return false; |
| 537 | } |
| 538 | |
Fyodor Kupolov | 6005b3f | 2015-11-23 17:41:50 -0800 | [diff] [blame] | 539 | private final SynchronousUserSwitchObserver mUserSwitchListener = |
| 540 | new SynchronousUserSwitchObserver() { |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 541 | @Override |
Fyodor Kupolov | 6005b3f | 2015-11-23 17:41:50 -0800 | [diff] [blame] | 542 | public void onUserSwitching(int newUserId) throws RemoteException { |
Tony Mak | ec319ab | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 543 | mHandler.post(() -> mUserInfoController.reloadUserInfo()); |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | @Override |
| 547 | public void onUserSwitchComplete(int newUserId) throws RemoteException { |
Tony Mak | ec319ab | 2017-03-28 18:50:01 +0100 | [diff] [blame] | 548 | mHandler.post(() -> { |
| 549 | updateAlarm(); |
| 550 | updateQuietState(); |
| 551 | updateManagedProfile(); |
| 552 | updateForegroundInstantApps(); |
Toni Barzic | e97f923 | 2016-04-27 18:10:58 -0700 | [diff] [blame] | 553 | }); |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 554 | } |
| 555 | }; |
| 556 | |
Jason Monk | 952d5d8 | 2014-10-27 15:28:22 -0400 | [diff] [blame] | 557 | private final HotspotController.Callback mHotspotCallback = new HotspotController.Callback() { |
| 558 | @Override |
| 559 | public void onHotspotChanged(boolean enabled) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 560 | mIconController.setIconVisibility(mSlotHotspot, enabled); |
Jason Monk | 952d5d8 | 2014-10-27 15:28:22 -0400 | [diff] [blame] | 561 | } |
| 562 | }; |
| 563 | |
John Spurlock | 96fe98d | 2014-08-27 09:36:02 -0400 | [diff] [blame] | 564 | private final CastController.Callback mCastCallback = new CastController.Callback() { |
| 565 | @Override |
| 566 | public void onCastDevicesChanged() { |
| 567 | updateCast(); |
| 568 | } |
| 569 | }; |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 570 | |
Juan Flores | 2ff3720 | 2015-04-30 13:44:23 +0200 | [diff] [blame] | 571 | private final NextAlarmController.NextAlarmChangeCallback mNextAlarmCallback = |
| 572 | new NextAlarmController.NextAlarmChangeCallback() { |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 573 | @Override |
| 574 | public void onNextAlarmChanged(AlarmManager.AlarmClockInfo nextAlarm) { |
| 575 | updateAlarm(); |
| 576 | } |
| 577 | }; |
Juan Flores | 2ff3720 | 2015-04-30 13:44:23 +0200 | [diff] [blame] | 578 | |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 579 | @Override |
| 580 | public void appTransitionStarting(long startTime, long duration, boolean forced) { |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 581 | updateManagedProfile(); |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 582 | updateForegroundInstantApps(); |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 583 | } |
| 584 | |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 585 | @Override |
| 586 | public void onKeyguardShowingChanged() { |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 587 | updateManagedProfile(); |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 588 | updateForegroundInstantApps(); |
Kenny Guy | 3094d4a | 2015-04-01 19:14:10 +0100 | [diff] [blame] | 589 | } |
John Spurlock | 604a5ee | 2015-06-01 12:27:22 -0400 | [diff] [blame] | 590 | |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 591 | @Override |
| 592 | public void onUserSetupChanged() { |
| 593 | boolean userSetup = mProvisionedController.isUserSetup( |
| 594 | mProvisionedController.getCurrentUser()); |
John Spurlock | 604a5ee | 2015-06-01 12:27:22 -0400 | [diff] [blame] | 595 | if (mCurrentUserSetup == userSetup) return; |
| 596 | mCurrentUserSetup = userSetup; |
| 597 | updateAlarm(); |
Rubin Xu | 1205fb1 | 2015-11-04 17:45:03 +0000 | [diff] [blame] | 598 | updateQuietState(); |
John Spurlock | 604a5ee | 2015-06-01 12:27:22 -0400 | [diff] [blame] | 599 | } |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 600 | |
| 601 | @Override |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 602 | public void preloadRecentApps() { |
| 603 | updateForegroundInstantApps(); |
| 604 | } |
| 605 | |
| 606 | @Override |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 607 | public void onRotationLockStateChanged(boolean rotationLocked, boolean affordanceVisible) { |
| 608 | boolean portrait = RotationLockTile.isCurrentOrientationLockPortrait( |
| 609 | mRotationLockController, mContext); |
| 610 | if (rotationLocked) { |
| 611 | if (portrait) { |
| 612 | mIconController.setIcon(mSlotRotate, R.drawable.stat_sys_rotate_portrait, |
| 613 | mContext.getString(R.string.accessibility_rotation_lock_on_portrait)); |
| 614 | } else { |
| 615 | mIconController.setIcon(mSlotRotate, R.drawable.stat_sys_rotate_landscape, |
| 616 | mContext.getString(R.string.accessibility_rotation_lock_on_landscape)); |
| 617 | } |
Jason Monk | 8816dff | 2016-02-09 21:50:36 -0500 | [diff] [blame] | 618 | mIconController.setIconVisibility(mSlotRotate, true); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 619 | } else { |
Jason Monk | 8816dff | 2016-02-09 21:50:36 -0500 | [diff] [blame] | 620 | mIconController.setIconVisibility(mSlotRotate, false); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 621 | } |
| 622 | } |
| 623 | |
| 624 | private void updateHeadsetPlug(Intent intent) { |
| 625 | boolean connected = intent.getIntExtra("state", 0) != 0; |
| 626 | boolean hasMic = intent.getIntExtra("microphone", 0) != 0; |
| 627 | if (connected) { |
| 628 | String contentDescription = mContext.getString(hasMic |
| 629 | ? R.string.accessibility_status_bar_headset |
| 630 | : R.string.accessibility_status_bar_headphones); |
| 631 | mIconController.setIcon(mSlotHeadset, hasMic ? R.drawable.ic_headset_mic |
| 632 | : R.drawable.ic_headset, contentDescription); |
| 633 | mIconController.setIconVisibility(mSlotHeadset, true); |
| 634 | } else { |
| 635 | mIconController.setIconVisibility(mSlotHeadset, false); |
| 636 | } |
| 637 | } |
| 638 | |
Jason Monk | f23aa99 | 2016-01-22 16:45:21 -0500 | [diff] [blame] | 639 | @Override |
| 640 | public void onDataSaverChanged(boolean isDataSaving) { |
| 641 | mIconController.setIconVisibility(mSlotDataSaver, isDataSaving); |
| 642 | } |
| 643 | |
Jason Monk | 324b886 | 2017-02-16 17:19:12 -0500 | [diff] [blame] | 644 | private final TaskStackListener mTaskListener = new TaskStackListener() { |
| 645 | @Override |
| 646 | public void onTaskStackChanged() { |
| 647 | // Listen for changes to stacks and then check which instant apps are foreground. |
| 648 | updateForegroundInstantApps(); |
| 649 | } |
| 650 | }; |
| 651 | |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 652 | private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { |
| 653 | @Override |
| 654 | public void onReceive(Context context, Intent intent) { |
| 655 | String action = intent.getAction(); |
Julia Reynolds | 4e6024b | 2016-04-26 16:12:26 -0400 | [diff] [blame] | 656 | if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION) || |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 657 | action.equals(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION)) { |
| 658 | updateVolumeZen(); |
| 659 | } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) { |
| 660 | updateSimState(intent); |
| 661 | } else if (action.equals(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED)) { |
| 662 | updateTTY(intent); |
Rubin Xu | e95057a | 2016-04-01 16:49:25 +0100 | [diff] [blame] | 663 | } else if (action.equals(Intent.ACTION_MANAGED_PROFILE_AVAILABLE) || |
Nicolas Prevot | 6c7b874 | 2016-04-13 10:28:58 +0100 | [diff] [blame] | 664 | action.equals(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE) || |
| 665 | action.equals(Intent.ACTION_MANAGED_PROFILE_REMOVED)) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 666 | updateQuietState(); |
| 667 | updateManagedProfile(); |
| 668 | } else if (action.equals(AudioManager.ACTION_HEADSET_PLUG)) { |
| 669 | updateHeadsetPlug(intent); |
| 670 | } |
| 671 | } |
| 672 | }; |
| 673 | |
| 674 | private Runnable mRemoveCastIconRunnable = new Runnable() { |
| 675 | @Override |
| 676 | public void run() { |
| 677 | if (DEBUG) Log.v(TAG, "updateCast: hiding icon NOW"); |
| 678 | mIconController.setIconVisibility(mSlotCast, false); |
| 679 | } |
| 680 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 681 | } |