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