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