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