Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file |
| 5 | * except in compliance with the License. You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software distributed under the |
| 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 11 | * KIND, either express or implied. See the License for the specific language governing |
| 12 | * permissions and limitations under the License. |
| 13 | */ |
| 14 | |
| 15 | package com.android.systemui.globalactions; |
| 16 | |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 17 | import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; |
Adrian Roos | 284b32d | 2020-05-08 14:26:13 +0200 | [diff] [blame] | 18 | import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
Adrian Roos | 2f05bb3 | 2018-02-19 16:42:27 +0100 | [diff] [blame] | 19 | import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; |
Miranda Kephart | 7b2c313 | 2020-03-27 09:54:14 -0400 | [diff] [blame] | 20 | import static android.view.WindowManager.ScreenshotSource.SCREENSHOT_GLOBAL_ACTIONS; |
| 21 | import static android.view.WindowManager.TAKE_SCREENSHOT_FULLSCREEN; |
Adrian Roos | 2f05bb3 | 2018-02-19 16:42:27 +0100 | [diff] [blame] | 22 | |
Chad Brubaker | f4075fe | 2018-01-03 13:23:22 -0800 | [diff] [blame] | 23 | import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_USER_REQUEST; |
| 24 | import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_NOT_REQUIRED; |
Chad Brubaker | 4f28f0d | 2017-09-07 14:28:13 -0700 | [diff] [blame] | 25 | import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN; |
| 26 | |
Matt Pietal | e9440b7 | 2020-05-01 11:36:01 -0400 | [diff] [blame] | 27 | import android.animation.Animator; |
| 28 | import android.animation.AnimatorListenerAdapter; |
| 29 | import android.animation.AnimatorSet; |
| 30 | import android.animation.ObjectAnimator; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 31 | import android.annotation.Nullable; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 32 | import android.app.ActivityManager; |
| 33 | import android.app.Dialog; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 34 | import android.app.IActivityManager; |
Steve Elliott | 4c86885 | 2019-03-14 16:25:41 -0400 | [diff] [blame] | 35 | import android.app.PendingIntent; |
Steve Elliott | 53f12ae | 2019-05-13 17:14:15 -0400 | [diff] [blame] | 36 | import android.app.StatusBarManager; |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 37 | import android.app.WallpaperManager; |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 38 | import android.app.admin.DevicePolicyManager; |
Pavel Grafov | 059021b | 2018-05-02 13:44:46 +0100 | [diff] [blame] | 39 | import android.app.trust.TrustManager; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 40 | import android.content.BroadcastReceiver; |
Matt Pietal | 6126644 | 2020-03-17 12:53:44 -0400 | [diff] [blame] | 41 | import android.content.ComponentName; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 42 | import android.content.ContentResolver; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 43 | import android.content.Context; |
| 44 | import android.content.DialogInterface; |
| 45 | import android.content.Intent; |
| 46 | import android.content.IntentFilter; |
Matt Pietal | 6126644 | 2020-03-17 12:53:44 -0400 | [diff] [blame] | 47 | import android.content.SharedPreferences; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 48 | import android.content.pm.UserInfo; |
Lucas Dupin | cb6726f | 2020-04-07 19:32:38 -0700 | [diff] [blame] | 49 | import android.content.res.ColorStateList; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 50 | import android.content.res.Resources; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 51 | import android.database.ContentObserver; |
Matt Pietal | e0661b6 | 2020-01-29 14:35:31 -0500 | [diff] [blame] | 52 | import android.graphics.Color; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 53 | import android.graphics.drawable.Drawable; |
| 54 | import android.media.AudioManager; |
| 55 | import android.net.ConnectivityManager; |
Steve Elliott | 53f12ae | 2019-05-13 17:14:15 -0400 | [diff] [blame] | 56 | import android.os.Binder; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 57 | import android.os.Handler; |
Steve Elliott | 53f12ae | 2019-05-13 17:14:15 -0400 | [diff] [blame] | 58 | import android.os.IBinder; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 59 | import android.os.Message; |
| 60 | import android.os.RemoteException; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 61 | import android.os.SystemProperties; |
| 62 | import android.os.UserHandle; |
| 63 | import android.os.UserManager; |
| 64 | import android.os.Vibrator; |
| 65 | import android.provider.Settings; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 66 | import android.service.dreams.IDreamManager; |
Inseob Kim | 5e82f73 | 2019-11-08 15:08:38 +0900 | [diff] [blame] | 67 | import android.sysprop.TelephonyProperties; |
Fan Zhang | f991476 | 2019-11-01 15:58:38 -0700 | [diff] [blame] | 68 | import android.telecom.TelecomManager; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 69 | import android.telephony.PhoneStateListener; |
| 70 | import android.telephony.ServiceState; |
| 71 | import android.telephony.TelephonyManager; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 72 | import android.util.ArraySet; |
yuanjiahsu | 88363e9 | 2018-09-06 19:23:52 +0800 | [diff] [blame] | 73 | import android.util.FeatureFlagUtils; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 74 | import android.util.Log; |
Lucas Dupin | 448786c | 2017-07-24 17:44:25 -0700 | [diff] [blame] | 75 | import android.view.ContextThemeWrapper; |
Dave Mankoff | 8df818e | 2020-02-12 14:22:26 -0500 | [diff] [blame] | 76 | import android.view.IWindowManager; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 77 | import android.view.LayoutInflater; |
| 78 | import android.view.View; |
| 79 | import android.view.ViewGroup; |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 80 | import android.view.Window; |
Lucas Dupin | 26571e9 | 2020-04-08 14:55:10 -0700 | [diff] [blame] | 81 | import android.view.WindowInsets; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 82 | import android.view.WindowManager; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 83 | import android.view.accessibility.AccessibilityEvent; |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 84 | import android.widget.BaseAdapter; |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 85 | import android.widget.FrameLayout; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 86 | import android.widget.ImageView; |
| 87 | import android.widget.ImageView.ScaleType; |
Aran Ink | 7c8fea9 | 2020-04-17 14:40:14 -0400 | [diff] [blame] | 88 | import android.widget.LinearLayout; |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 89 | import android.widget.ListPopupWindow; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 90 | import android.widget.TextView; |
| 91 | |
Fabian Kozynski | b6a2037 | 2020-04-01 09:36:43 -0400 | [diff] [blame] | 92 | import androidx.annotation.NonNull; |
| 93 | import androidx.lifecycle.Lifecycle; |
| 94 | import androidx.lifecycle.LifecycleOwner; |
| 95 | import androidx.lifecycle.LifecycleRegistry; |
| 96 | |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 97 | import com.android.internal.R; |
Chris Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 98 | import com.android.internal.annotations.VisibleForTesting; |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 99 | import com.android.internal.colorextraction.ColorExtractor; |
| 100 | import com.android.internal.colorextraction.ColorExtractor.GradientColors; |
Lucas Dupin | 2bd3af6 | 2019-03-25 17:44:28 -0700 | [diff] [blame] | 101 | import com.android.internal.colorextraction.drawable.ScrimDrawable; |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 102 | import com.android.internal.logging.MetricsLogger; |
Chris Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 103 | import com.android.internal.logging.UiEvent; |
| 104 | import com.android.internal.logging.UiEventLogger; |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 105 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Steve Elliott | 53f12ae | 2019-05-13 17:14:15 -0400 | [diff] [blame] | 106 | import com.android.internal.statusbar.IStatusBarService; |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 107 | import com.android.internal.util.EmergencyAffordanceManager; |
Beth Thibodeau | 5898ac4 | 2018-10-26 13:00:09 -0400 | [diff] [blame] | 108 | import com.android.internal.util.ScreenRecordHelper; |
Alison Cichowlas | a2cd19e | 2017-12-06 10:51:21 -0500 | [diff] [blame] | 109 | import com.android.internal.util.ScreenshotHelper; |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 110 | import com.android.internal.view.RotationPolicy; |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 111 | import com.android.internal.widget.LockPatternUtils; |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 112 | import com.android.systemui.Interpolators; |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 113 | import com.android.systemui.MultiListLayout; |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 114 | import com.android.systemui.MultiListLayout.MultiListAdapter; |
Fabian Kozynski | ff5e91f | 2019-09-24 15:38:08 -0400 | [diff] [blame] | 115 | import com.android.systemui.broadcast.BroadcastDispatcher; |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 116 | import com.android.systemui.colorextraction.SysuiColorExtractor; |
Matt Pietal | 6126644 | 2020-03-17 12:53:44 -0400 | [diff] [blame] | 117 | import com.android.systemui.controls.ControlsServiceInfo; |
| 118 | import com.android.systemui.controls.controller.ControlsController; |
Matt Pietal | f4b870b | 2020-04-17 17:11:36 -0400 | [diff] [blame] | 119 | import com.android.systemui.controls.management.ControlsAnimations; |
Fabian Kozynski | 0424ab1 | 2020-02-21 12:09:17 -0500 | [diff] [blame] | 120 | import com.android.systemui.controls.management.ControlsListingController; |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 121 | import com.android.systemui.controls.ui.ControlsUiController; |
Dave Mankoff | 8df818e | 2020-02-12 14:22:26 -0500 | [diff] [blame] | 122 | import com.android.systemui.dagger.qualifiers.Background; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 123 | import com.android.systemui.dagger.qualifiers.Main; |
Steve Elliott | 4c86885 | 2019-03-14 16:25:41 -0400 | [diff] [blame] | 124 | import com.android.systemui.plugins.ActivityStarter; |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 125 | import com.android.systemui.plugins.GlobalActions.GlobalActionsManager; |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 126 | import com.android.systemui.plugins.GlobalActionsPanelPlugin; |
Lucas Dupin | 99f5fba | 2020-03-12 12:59:18 -0700 | [diff] [blame] | 127 | import com.android.systemui.statusbar.BlurUtils; |
Santiago Etchebehere | 68eb53e | 2020-02-25 14:25:34 -0800 | [diff] [blame] | 128 | import com.android.systemui.statusbar.NotificationShadeDepthController; |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 129 | import com.android.systemui.statusbar.phone.NotificationShadeWindowController; |
Lucas Dupin | 43d0124 | 2020-02-03 11:58:33 -0800 | [diff] [blame] | 130 | import com.android.systemui.statusbar.phone.ScrimController; |
Lucas Dupin | e5b7dc7 | 2018-10-02 15:18:05 -0700 | [diff] [blame] | 131 | import com.android.systemui.statusbar.policy.ConfigurationController; |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 132 | import com.android.systemui.statusbar.policy.KeyguardStateController; |
Shaotang Li | 5c42263 | 2018-07-04 14:18:40 +0800 | [diff] [blame] | 133 | import com.android.systemui.util.EmergencyDialerConstants; |
Fabian Kozynski | b6a2037 | 2020-04-01 09:36:43 -0400 | [diff] [blame] | 134 | import com.android.systemui.util.RingerModeTracker; |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 135 | import com.android.systemui.util.leak.RotationUtils; |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 136 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 137 | import java.util.ArrayList; |
| 138 | import java.util.List; |
Dave Mankoff | 8df818e | 2020-02-12 14:22:26 -0500 | [diff] [blame] | 139 | import java.util.concurrent.Executor; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 140 | |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 141 | import javax.inject.Inject; |
| 142 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 143 | /** |
Sean Pont | 9d4fb03 | 2020-03-04 18:54:32 -0800 | [diff] [blame] | 144 | * Helper to show the global actions dialog. Each item is an {@link Action} that may show depending |
| 145 | * on whether the keyguard is showing, and whether the device is provisioned. |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 146 | */ |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 147 | public class GlobalActionsDialog implements DialogInterface.OnDismissListener, |
Sean Pont | 9d4fb03 | 2020-03-04 18:54:32 -0800 | [diff] [blame] | 148 | DialogInterface.OnShowListener, |
| 149 | ConfigurationController.ConfigurationListener, |
Fabian Kozynski | b6a2037 | 2020-04-01 09:36:43 -0400 | [diff] [blame] | 150 | GlobalActionsPanelPlugin.Callbacks, |
| 151 | LifecycleOwner { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 152 | |
Sean Pont | 9d4fb03 | 2020-03-04 18:54:32 -0800 | [diff] [blame] | 153 | public static final String SYSTEM_DIALOG_REASON_KEY = "reason"; |
| 154 | public static final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions"; |
| 155 | public static final String SYSTEM_DIALOG_REASON_DREAM = "dream"; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 156 | |
| 157 | private static final String TAG = "GlobalActionsDialog"; |
| 158 | |
| 159 | private static final boolean SHOW_SILENT_TOGGLE = true; |
| 160 | |
| 161 | /* Valid settings for global actions keys. |
| 162 | * see config.xml config_globalActionList */ |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 163 | @VisibleForTesting |
| 164 | protected static final String GLOBAL_ACTION_KEY_POWER = "power"; |
| 165 | protected static final String GLOBAL_ACTION_KEY_AIRPLANE = "airplane"; |
| 166 | protected static final String GLOBAL_ACTION_KEY_BUGREPORT = "bugreport"; |
| 167 | protected static final String GLOBAL_ACTION_KEY_SILENT = "silent"; |
| 168 | protected static final String GLOBAL_ACTION_KEY_USERS = "users"; |
| 169 | protected static final String GLOBAL_ACTION_KEY_SETTINGS = "settings"; |
| 170 | protected static final String GLOBAL_ACTION_KEY_LOCKDOWN = "lockdown"; |
| 171 | protected static final String GLOBAL_ACTION_KEY_VOICEASSIST = "voiceassist"; |
| 172 | protected static final String GLOBAL_ACTION_KEY_ASSIST = "assist"; |
| 173 | protected static final String GLOBAL_ACTION_KEY_RESTART = "restart"; |
| 174 | protected static final String GLOBAL_ACTION_KEY_LOGOUT = "logout"; |
| 175 | protected static final String GLOBAL_ACTION_KEY_EMERGENCY = "emergency"; |
| 176 | protected static final String GLOBAL_ACTION_KEY_SCREENSHOT = "screenshot"; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 177 | |
Matt Pietal | 6126644 | 2020-03-17 12:53:44 -0400 | [diff] [blame] | 178 | private static final String PREFS_CONTROLS_SEEDING_COMPLETED = "ControlsSeedingCompleted"; |
| 179 | private static final String PREFS_CONTROLS_FILE = "controls_prefs"; |
| 180 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 181 | private final Context mContext; |
| 182 | private final GlobalActionsManager mWindowManagerFuncs; |
| 183 | private final AudioManager mAudioManager; |
| 184 | private final IDreamManager mDreamManager; |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 185 | private final DevicePolicyManager mDevicePolicyManager; |
Chad Brubaker | f4075fe | 2018-01-03 13:23:22 -0800 | [diff] [blame] | 186 | private final LockPatternUtils mLockPatternUtils; |
Fabian Kozynski | f6063ae | 2020-02-24 16:14:35 -0500 | [diff] [blame] | 187 | private final KeyguardStateController mKeyguardStateController; |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 188 | private final BroadcastDispatcher mBroadcastDispatcher; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 189 | private final ContentResolver mContentResolver; |
| 190 | private final Resources mResources; |
Dave Mankoff | 8df818e | 2020-02-12 14:22:26 -0500 | [diff] [blame] | 191 | private final ConfigurationController mConfigurationController; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 192 | private final UserManager mUserManager; |
| 193 | private final TrustManager mTrustManager; |
| 194 | private final IActivityManager mIActivityManager; |
| 195 | private final TelecomManager mTelecomManager; |
| 196 | private final MetricsLogger mMetricsLogger; |
Chris Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 197 | private final UiEventLogger mUiEventLogger; |
Santiago Etchebehere | 68eb53e | 2020-02-25 14:25:34 -0800 | [diff] [blame] | 198 | private final NotificationShadeDepthController mDepthController; |
Lucas Dupin | 99f5fba | 2020-03-12 12:59:18 -0700 | [diff] [blame] | 199 | private final BlurUtils mBlurUtils; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 200 | |
Fabian Kozynski | b6a2037 | 2020-04-01 09:36:43 -0400 | [diff] [blame] | 201 | // Used for RingerModeTracker |
| 202 | private final LifecycleRegistry mLifecycle = new LifecycleRegistry(this); |
| 203 | |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 204 | @VisibleForTesting |
Aran Ink | a65e6836 | 2020-04-14 15:23:24 -0400 | [diff] [blame] | 205 | protected final ArrayList<Action> mItems = new ArrayList<>(); |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 206 | @VisibleForTesting |
Aran Ink | a65e6836 | 2020-04-14 15:23:24 -0400 | [diff] [blame] | 207 | protected final ArrayList<Action> mOverflowItems = new ArrayList<>(); |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 208 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 209 | private ActionsDialog mDialog; |
| 210 | |
| 211 | private Action mSilentModeAction; |
| 212 | private ToggleAction mAirplaneModeOn; |
| 213 | |
| 214 | private MyAdapter mAdapter; |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 215 | private MyOverflowAdapter mOverflowAdapter; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 216 | |
| 217 | private boolean mKeyguardShowing = false; |
| 218 | private boolean mDeviceProvisioned = false; |
Lucas Dupin | cb6726f | 2020-04-07 19:32:38 -0700 | [diff] [blame] | 219 | private ToggleState mAirplaneState = ToggleState.Off; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 220 | private boolean mIsWaitingForEcmExit = false; |
| 221 | private boolean mHasTelephony; |
| 222 | private boolean mHasVibrator; |
| 223 | private final boolean mShowSilentToggle; |
| 224 | private final EmergencyAffordanceManager mEmergencyAffordanceManager; |
Alison Cichowlas | a2cd19e | 2017-12-06 10:51:21 -0500 | [diff] [blame] | 225 | private final ScreenshotHelper mScreenshotHelper; |
Beth Thibodeau | 5898ac4 | 2018-10-26 13:00:09 -0400 | [diff] [blame] | 226 | private final ScreenRecordHelper mScreenRecordHelper; |
Steve Elliott | a3f520792 | 2019-03-18 13:37:22 -0400 | [diff] [blame] | 227 | private final ActivityStarter mActivityStarter; |
Lucas Dupin | 991415e | 2019-11-25 17:48:58 -0800 | [diff] [blame] | 228 | private final SysuiColorExtractor mSysuiColorExtractor; |
| 229 | private final IStatusBarService mStatusBarService; |
| 230 | private final NotificationShadeWindowController mNotificationShadeWindowController; |
Steve Elliott | a3f520792 | 2019-03-18 13:37:22 -0400 | [diff] [blame] | 231 | private GlobalActionsPanelPlugin mPanelPlugin; |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 232 | private ControlsUiController mControlsUiController; |
Dave Mankoff | 8df818e | 2020-02-12 14:22:26 -0500 | [diff] [blame] | 233 | private final IWindowManager mIWindowManager; |
| 234 | private final Executor mBackgroundExecutor; |
Fabian Kozynski | 0424ab1 | 2020-02-21 12:09:17 -0500 | [diff] [blame] | 235 | private final ControlsListingController mControlsListingController; |
Matt Pietal | cd757c8 | 2020-04-08 10:20:48 -0400 | [diff] [blame] | 236 | private List<ControlsServiceInfo> mControlsServiceInfos = new ArrayList<>(); |
| 237 | private ControlsController mControlsController; |
| 238 | private SharedPreferences mControlsPreferences; |
Fabian Kozynski | b6a2037 | 2020-04-01 09:36:43 -0400 | [diff] [blame] | 239 | private final RingerModeTracker mRingerModeTracker; |
Chris Wren | af4ce846 | 2020-04-06 17:36:10 -0400 | [diff] [blame] | 240 | private int mDialogPressDelay = DIALOG_PRESS_DELAY; // ms |
Matt Pietal | 677981d | 2020-04-24 14:38:32 -0400 | [diff] [blame] | 241 | private Handler mMainHandler; |
| 242 | private boolean mShowLockScreenCardsAndControls = false; |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 243 | |
Chris Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 244 | @VisibleForTesting |
| 245 | public enum GlobalActionsEvent implements UiEventLogger.UiEventEnum { |
| 246 | @UiEvent(doc = "The global actions / power menu surface became visible on the screen.") |
Chris Wren | af4ce846 | 2020-04-06 17:36:10 -0400 | [diff] [blame] | 247 | GA_POWER_MENU_OPEN(337), |
| 248 | |
| 249 | @UiEvent(doc = "The global actions bugreport button was pressed.") |
| 250 | GA_BUGREPORT_PRESS(344), |
| 251 | |
| 252 | @UiEvent(doc = "The global actions bugreport button was long pressed.") |
| 253 | GA_BUGREPORT_LONG_PRESS(345), |
| 254 | |
| 255 | @UiEvent(doc = "The global actions emergency button was pressed.") |
| 256 | GA_EMERGENCY_DIALER_PRESS(346), |
| 257 | |
| 258 | @UiEvent(doc = "The global actions screenshot button was pressed.") |
| 259 | GA_SCREENSHOT_PRESS(347), |
| 260 | |
| 261 | @UiEvent(doc = "The global actions screenshot button was long pressed.") |
| 262 | GA_SCREENSHOT_LONG_PRESS(348); |
Chris Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 263 | |
| 264 | private final int mId; |
| 265 | |
| 266 | GlobalActionsEvent(int id) { |
| 267 | mId = id; |
| 268 | } |
| 269 | |
| 270 | @Override |
| 271 | public int getId() { |
| 272 | return mId; |
| 273 | } |
| 274 | } |
| 275 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 276 | /** |
| 277 | * @param context everything needs a context :( |
| 278 | */ |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 279 | @Inject |
| 280 | public GlobalActionsDialog(Context context, GlobalActionsManager windowManagerFuncs, |
| 281 | AudioManager audioManager, IDreamManager iDreamManager, |
| 282 | DevicePolicyManager devicePolicyManager, LockPatternUtils lockPatternUtils, |
Fabian Kozynski | f6063ae | 2020-02-24 16:14:35 -0500 | [diff] [blame] | 283 | BroadcastDispatcher broadcastDispatcher, |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 284 | ConnectivityManager connectivityManager, TelephonyManager telephonyManager, |
| 285 | ContentResolver contentResolver, @Nullable Vibrator vibrator, @Main Resources resources, |
| 286 | ConfigurationController configurationController, ActivityStarter activityStarter, |
| 287 | KeyguardStateController keyguardStateController, UserManager userManager, |
| 288 | TrustManager trustManager, IActivityManager iActivityManager, |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 289 | @Nullable TelecomManager telecomManager, MetricsLogger metricsLogger, |
Santiago Etchebehere | 68eb53e | 2020-02-25 14:25:34 -0800 | [diff] [blame] | 290 | NotificationShadeDepthController depthController, SysuiColorExtractor colorExtractor, |
Lucas Dupin | 99f5fba | 2020-03-12 12:59:18 -0700 | [diff] [blame] | 291 | IStatusBarService statusBarService, BlurUtils blurUtils, |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 292 | NotificationShadeWindowController notificationShadeWindowController, |
Dave Mankoff | 8df818e | 2020-02-12 14:22:26 -0500 | [diff] [blame] | 293 | ControlsUiController controlsUiController, IWindowManager iWindowManager, |
Fabian Kozynski | 0424ab1 | 2020-02-21 12:09:17 -0500 | [diff] [blame] | 294 | @Background Executor backgroundExecutor, |
Matt Pietal | 6126644 | 2020-03-17 12:53:44 -0400 | [diff] [blame] | 295 | ControlsListingController controlsListingController, |
Fabian Kozynski | b6a2037 | 2020-04-01 09:36:43 -0400 | [diff] [blame] | 296 | ControlsController controlsController, UiEventLogger uiEventLogger, |
Matt Pietal | 677981d | 2020-04-24 14:38:32 -0400 | [diff] [blame] | 297 | RingerModeTracker ringerModeTracker, @Main Handler handler) { |
Lucas Dupin | 448786c | 2017-07-24 17:44:25 -0700 | [diff] [blame] | 298 | mContext = new ContextThemeWrapper(context, com.android.systemui.R.style.qs_theme); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 299 | mWindowManagerFuncs = windowManagerFuncs; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 300 | mAudioManager = audioManager; |
| 301 | mDreamManager = iDreamManager; |
| 302 | mDevicePolicyManager = devicePolicyManager; |
| 303 | mLockPatternUtils = lockPatternUtils; |
Fabian Kozynski | f6063ae | 2020-02-24 16:14:35 -0500 | [diff] [blame] | 304 | mKeyguardStateController = keyguardStateController; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 305 | mBroadcastDispatcher = broadcastDispatcher; |
| 306 | mContentResolver = contentResolver; |
| 307 | mResources = resources; |
Dave Mankoff | 8df818e | 2020-02-12 14:22:26 -0500 | [diff] [blame] | 308 | mConfigurationController = configurationController; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 309 | mUserManager = userManager; |
| 310 | mTrustManager = trustManager; |
| 311 | mIActivityManager = iActivityManager; |
| 312 | mTelecomManager = telecomManager; |
| 313 | mMetricsLogger = metricsLogger; |
Chris Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 314 | mUiEventLogger = uiEventLogger; |
Santiago Etchebehere | 68eb53e | 2020-02-25 14:25:34 -0800 | [diff] [blame] | 315 | mDepthController = depthController; |
Lucas Dupin | 991415e | 2019-11-25 17:48:58 -0800 | [diff] [blame] | 316 | mSysuiColorExtractor = colorExtractor; |
| 317 | mStatusBarService = statusBarService; |
| 318 | mNotificationShadeWindowController = notificationShadeWindowController; |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 319 | mControlsUiController = controlsUiController; |
Dave Mankoff | 8df818e | 2020-02-12 14:22:26 -0500 | [diff] [blame] | 320 | mIWindowManager = iWindowManager; |
| 321 | mBackgroundExecutor = backgroundExecutor; |
Fabian Kozynski | 0424ab1 | 2020-02-21 12:09:17 -0500 | [diff] [blame] | 322 | mControlsListingController = controlsListingController; |
Lucas Dupin | 99f5fba | 2020-03-12 12:59:18 -0700 | [diff] [blame] | 323 | mBlurUtils = blurUtils; |
Fabian Kozynski | b6a2037 | 2020-04-01 09:36:43 -0400 | [diff] [blame] | 324 | mRingerModeTracker = ringerModeTracker; |
Matt Pietal | cd757c8 | 2020-04-08 10:20:48 -0400 | [diff] [blame] | 325 | mControlsController = controlsController; |
Matt Pietal | 677981d | 2020-04-24 14:38:32 -0400 | [diff] [blame] | 326 | mMainHandler = handler; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 327 | |
| 328 | // receive broadcasts |
| 329 | IntentFilter filter = new IntentFilter(); |
| 330 | filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
| 331 | filter.addAction(Intent.ACTION_SCREEN_OFF); |
Jayachandran C | 142eae0 | 2019-12-13 19:29:20 -0800 | [diff] [blame] | 332 | filter.addAction(TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED); |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 333 | mBroadcastDispatcher.registerReceiver(mBroadcastReceiver, filter); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 334 | |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 335 | mHasTelephony = connectivityManager.isNetworkSupported(ConnectivityManager.TYPE_MOBILE); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 336 | |
| 337 | // get notified of phone state changes |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 338 | telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE); |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 339 | contentResolver.registerContentObserver( |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 340 | Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON), true, |
| 341 | mAirplaneModeObserver); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 342 | mHasVibrator = vibrator != null && vibrator.hasVibrator(); |
| 343 | |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 344 | mShowSilentToggle = SHOW_SILENT_TOGGLE && !resources.getBoolean( |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 345 | R.bool.config_useFixedVolume); |
Fabian Kozynski | b6a2037 | 2020-04-01 09:36:43 -0400 | [diff] [blame] | 346 | if (mShowSilentToggle) { |
| 347 | mRingerModeTracker.getRingerMode().observe(this, ringer -> |
| 348 | mHandler.sendEmptyMessage(MESSAGE_REFRESH) |
| 349 | ); |
| 350 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 351 | |
| 352 | mEmergencyAffordanceManager = new EmergencyAffordanceManager(context); |
Alison Cichowlas | a2cd19e | 2017-12-06 10:51:21 -0500 | [diff] [blame] | 353 | mScreenshotHelper = new ScreenshotHelper(context); |
Beth Thibodeau | 5898ac4 | 2018-10-26 13:00:09 -0400 | [diff] [blame] | 354 | mScreenRecordHelper = new ScreenRecordHelper(context); |
Lucas Dupin | e5b7dc7 | 2018-10-02 15:18:05 -0700 | [diff] [blame] | 355 | |
Dave Mankoff | 8df818e | 2020-02-12 14:22:26 -0500 | [diff] [blame] | 356 | mConfigurationController.addCallback(this); |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 357 | |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 358 | mActivityStarter = activityStarter; |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 359 | keyguardStateController.addCallback(new KeyguardStateController.Callback() { |
| 360 | @Override |
| 361 | public void onUnlockedChanged() { |
Matt Pietal | 677981d | 2020-04-24 14:38:32 -0400 | [diff] [blame] | 362 | if (mDialog != null) { |
Sean Pont | 9d4fb03 | 2020-03-04 18:54:32 -0800 | [diff] [blame] | 363 | boolean unlocked = keyguardStateController.isUnlocked() |
| 364 | || keyguardStateController.canDismissLockScreen(); |
Matt Pietal | 677981d | 2020-04-24 14:38:32 -0400 | [diff] [blame] | 365 | if (mDialog.mPanelController != null) { |
| 366 | mDialog.mPanelController.onDeviceLockStateChanged(unlocked); |
| 367 | } |
| 368 | if (!mDialog.isShowingControls() && shouldShowControls()) { |
| 369 | mDialog.showControls(mControlsUiController); |
| 370 | } |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 371 | } |
| 372 | } |
| 373 | }); |
Fabian Kozynski | 0424ab1 | 2020-02-21 12:09:17 -0500 | [diff] [blame] | 374 | |
Matt Pietal | 6126644 | 2020-03-17 12:53:44 -0400 | [diff] [blame] | 375 | mControlsListingController.addCallback(list -> { |
Matt Pietal | cd757c8 | 2020-04-08 10:20:48 -0400 | [diff] [blame] | 376 | mControlsServiceInfos = list; |
Matt Pietal | 6126644 | 2020-03-17 12:53:44 -0400 | [diff] [blame] | 377 | }); |
Matt Pietal | cd757c8 | 2020-04-08 10:20:48 -0400 | [diff] [blame] | 378 | |
| 379 | // Need to be user-specific with the context to make sure we read the correct prefs |
| 380 | Context userContext = context.createContextAsUser( |
| 381 | new UserHandle(mUserManager.getUserHandle()), 0); |
| 382 | mControlsPreferences = userContext.getSharedPreferences(PREFS_CONTROLS_FILE, |
| 383 | Context.MODE_PRIVATE); |
| 384 | |
Matt Pietal | 677981d | 2020-04-24 14:38:32 -0400 | [diff] [blame] | 385 | // Listen for changes to show controls on the power menu while locked |
| 386 | onPowerMenuLockScreenSettingsChanged(); |
| 387 | mContext.getContentResolver().registerContentObserver( |
| 388 | Settings.Secure.getUriFor(Settings.Secure.POWER_MENU_LOCKED_SHOW_CONTENT), |
| 389 | false /* notifyForDescendants */, |
| 390 | new ContentObserver(mMainHandler) { |
| 391 | @Override |
| 392 | public void onChange(boolean selfChange) { |
| 393 | onPowerMenuLockScreenSettingsChanged(); |
| 394 | } |
| 395 | }); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 396 | } |
| 397 | |
Matt Pietal | cd757c8 | 2020-04-08 10:20:48 -0400 | [diff] [blame] | 398 | private void seedFavorites() { |
| 399 | if (mControlsServiceInfos.isEmpty() |
| 400 | || mControlsController.getFavorites().size() > 0 |
| 401 | || mControlsPreferences.getBoolean(PREFS_CONTROLS_SEEDING_COMPLETED, false)) { |
| 402 | return; |
| 403 | } |
Matt Pietal | 6126644 | 2020-03-17 12:53:44 -0400 | [diff] [blame] | 404 | |
Matt Pietal | cd757c8 | 2020-04-08 10:20:48 -0400 | [diff] [blame] | 405 | /* |
| 406 | * See if any service providers match the preferred component. If they do, |
| 407 | * and there are no current favorites, and we haven't successfully loaded favorites to |
| 408 | * date, query the preferred component for a limited number of suggested controls. |
| 409 | */ |
| 410 | String preferredControlsPackage = mContext.getResources() |
| 411 | .getString(com.android.systemui.R.string.config_controlsPreferredPackage); |
Matt Pietal | 6126644 | 2020-03-17 12:53:44 -0400 | [diff] [blame] | 412 | |
Matt Pietal | cd757c8 | 2020-04-08 10:20:48 -0400 | [diff] [blame] | 413 | ComponentName preferredComponent = null; |
| 414 | for (ControlsServiceInfo info : mControlsServiceInfos) { |
| 415 | if (info.componentName.getPackageName().equals(preferredControlsPackage)) { |
| 416 | preferredComponent = info.componentName; |
| 417 | break; |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | if (preferredComponent == null) { |
| 422 | Log.i(TAG, "Controls seeding: No preferred component has been set, will not seed"); |
| 423 | mControlsPreferences.edit().putBoolean(PREFS_CONTROLS_SEEDING_COMPLETED, true).apply(); |
Matt Pietal | 69dfb64 | 2020-04-16 13:34:46 -0400 | [diff] [blame] | 424 | return; |
Matt Pietal | cd757c8 | 2020-04-08 10:20:48 -0400 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | mControlsController.seedFavoritesForComponent( |
| 428 | preferredComponent, |
| 429 | (accepted) -> { |
| 430 | Log.i(TAG, "Controls seeded: " + accepted); |
| 431 | mControlsPreferences.edit().putBoolean(PREFS_CONTROLS_SEEDING_COMPLETED, |
| 432 | accepted).apply(); |
| 433 | }); |
| 434 | } |
Matt Pietal | 6126644 | 2020-03-17 12:53:44 -0400 | [diff] [blame] | 435 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 436 | /** |
| 437 | * Show the global actions dialog (creating if necessary) |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 438 | * |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 439 | * @param keyguardShowing True if keyguard is showing |
| 440 | */ |
Matt Pietal | 6ce0a90 | 2020-04-24 10:30:57 -0400 | [diff] [blame] | 441 | public void showOrHideDialog(boolean keyguardShowing, boolean isDeviceProvisioned, |
Steve Elliott | a3f520792 | 2019-03-18 13:37:22 -0400 | [diff] [blame] | 442 | GlobalActionsPanelPlugin panelPlugin) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 443 | mKeyguardShowing = keyguardShowing; |
| 444 | mDeviceProvisioned = isDeviceProvisioned; |
Steve Elliott | a3f520792 | 2019-03-18 13:37:22 -0400 | [diff] [blame] | 445 | mPanelPlugin = panelPlugin; |
Matt Pietal | 6ce0a90 | 2020-04-24 10:30:57 -0400 | [diff] [blame] | 446 | if (mDialog != null && mDialog.isShowing()) { |
| 447 | // In order to force global actions to hide on the same affordance press, we must |
| 448 | // register a call to onGlobalActionsShown() first to prevent the default actions |
| 449 | // menu from showing. This will be followed by a subsequent call to |
| 450 | // onGlobalActionsHidden() on dismiss() |
| 451 | mWindowManagerFuncs.onGlobalActionsShown(); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 452 | mDialog.dismiss(); |
| 453 | mDialog = null; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 454 | } else { |
| 455 | handleShow(); |
| 456 | } |
| 457 | } |
| 458 | |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 459 | /** |
| 460 | * Dismiss the global actions dialog, if it's currently shown |
| 461 | */ |
| 462 | public void dismissDialog() { |
| 463 | mHandler.removeMessages(MESSAGE_DISMISS); |
| 464 | mHandler.sendEmptyMessage(MESSAGE_DISMISS); |
| 465 | } |
| 466 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 467 | private void awakenIfNecessary() { |
| 468 | if (mDreamManager != null) { |
| 469 | try { |
| 470 | if (mDreamManager.isDreaming()) { |
| 471 | mDreamManager.awaken(); |
| 472 | } |
| 473 | } catch (RemoteException e) { |
| 474 | // we tried |
| 475 | } |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | private void handleShow() { |
| 480 | awakenIfNecessary(); |
| 481 | mDialog = createDialog(); |
| 482 | prepareDialog(); |
Matt Pietal | cd757c8 | 2020-04-08 10:20:48 -0400 | [diff] [blame] | 483 | seedFavorites(); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 484 | |
Aran Ink | a65e6836 | 2020-04-14 15:23:24 -0400 | [diff] [blame] | 485 | WindowManager.LayoutParams attrs = mDialog.getWindow().getAttributes(); |
| 486 | attrs.setTitle("ActionsDialog"); |
| 487 | attrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; |
| 488 | mDialog.getWindow().setAttributes(attrs); |
Adrian Roos | 284b32d | 2020-05-08 14:26:13 +0200 | [diff] [blame] | 489 | // Don't acquire soft keyboard focus, to avoid destroying state when capturing bugreports |
| 490 | mDialog.getWindow().setFlags(FLAG_ALT_FOCUSABLE_IM, FLAG_ALT_FOCUSABLE_IM); |
Aran Ink | a65e6836 | 2020-04-14 15:23:24 -0400 | [diff] [blame] | 491 | mDialog.show(); |
| 492 | mWindowManagerFuncs.onGlobalActionsShown(); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 493 | } |
| 494 | |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 495 | @VisibleForTesting |
| 496 | protected boolean shouldShowAction(Action action) { |
| 497 | if (mKeyguardShowing && !action.showDuringKeyguard()) { |
| 498 | return false; |
| 499 | } |
| 500 | if (!mDeviceProvisioned && !action.showBeforeProvisioning()) { |
| 501 | return false; |
| 502 | } |
| 503 | return true; |
| 504 | } |
| 505 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 506 | /** |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 507 | * Returns the maximum number of power menu items to show based on which GlobalActions |
| 508 | * layout is being used. |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 509 | */ |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 510 | @VisibleForTesting |
| 511 | protected int getMaxShownPowerItems() { |
Aran Ink | d397b90 | 2020-04-21 17:53:41 -0400 | [diff] [blame] | 512 | if (shouldUseControlsLayout()) { |
Matt Pietal | 677981d | 2020-04-24 14:38:32 -0400 | [diff] [blame] | 513 | return mResources.getInteger(com.android.systemui.R.integer.power_menu_max_columns); |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 514 | } else { |
| 515 | return Integer.MAX_VALUE; |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | /** |
| 520 | * Add a power menu action item for to either the main or overflow items lists, depending on |
| 521 | * whether controls are enabled and whether the max number of shown items has been reached. |
| 522 | */ |
| 523 | private void addActionItem(Action action) { |
Aran Ink | a65e6836 | 2020-04-14 15:23:24 -0400 | [diff] [blame] | 524 | if (shouldShowAction(action)) { |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 525 | if (mItems.size() < getMaxShownPowerItems()) { |
| 526 | mItems.add(action); |
Aran Ink | a65e6836 | 2020-04-14 15:23:24 -0400 | [diff] [blame] | 527 | } else { |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 528 | mOverflowItems.add(action); |
| 529 | } |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | @VisibleForTesting |
| 534 | protected String[] getDefaultActions() { |
| 535 | return mResources.getStringArray(R.array.config_globalActionsList); |
| 536 | } |
| 537 | |
| 538 | @VisibleForTesting |
| 539 | protected void createActionItems() { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 540 | // Simple toggle style if there's no vibrator, otherwise use a tri-state |
| 541 | if (!mHasVibrator) { |
| 542 | mSilentModeAction = new SilentModeToggleAction(); |
| 543 | } else { |
Lucas Dupin | 40ec6b78 | 2018-06-05 19:07:16 -0700 | [diff] [blame] | 544 | mSilentModeAction = new SilentModeTriStateAction(mAudioManager, mHandler); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 545 | } |
Aran Ink | 780d450 | 2020-02-14 10:39:58 -0500 | [diff] [blame] | 546 | mAirplaneModeOn = new AirplaneModeAction(); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 547 | onAirplaneModeChanged(); |
| 548 | |
Aran Ink | a65e6836 | 2020-04-14 15:23:24 -0400 | [diff] [blame] | 549 | mItems.clear(); |
| 550 | mOverflowItems.clear(); |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 551 | String[] defaultActions = getDefaultActions(); |
| 552 | |
| 553 | // make sure emergency affordance action is first, if needed |
| 554 | if (mEmergencyAffordanceManager.needsEmergencyAffordance()) { |
| 555 | addActionItem(new EmergencyAffordanceAction()); |
| 556 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 557 | |
| 558 | ArraySet<String> addedKeys = new ArraySet<String>(); |
| 559 | for (int i = 0; i < defaultActions.length; i++) { |
| 560 | String actionKey = defaultActions[i]; |
| 561 | if (addedKeys.contains(actionKey)) { |
| 562 | // If we already have added this, don't add it again. |
| 563 | continue; |
| 564 | } |
| 565 | if (GLOBAL_ACTION_KEY_POWER.equals(actionKey)) { |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 566 | addActionItem(new PowerAction()); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 567 | } else if (GLOBAL_ACTION_KEY_AIRPLANE.equals(actionKey)) { |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 568 | addActionItem(mAirplaneModeOn); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 569 | } else if (GLOBAL_ACTION_KEY_BUGREPORT.equals(actionKey)) { |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 570 | if (Settings.Global.getInt(mContentResolver, |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 571 | Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0 && isCurrentUserOwner()) { |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 572 | addActionItem(new BugReportAction()); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 573 | } |
| 574 | } else if (GLOBAL_ACTION_KEY_SILENT.equals(actionKey)) { |
| 575 | if (mShowSilentToggle) { |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 576 | addActionItem(mSilentModeAction); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 577 | } |
| 578 | } else if (GLOBAL_ACTION_KEY_USERS.equals(actionKey)) { |
| 579 | if (SystemProperties.getBoolean("fw.power_user_switcher", false)) { |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 580 | addUsersToMenu(); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 581 | } |
| 582 | } else if (GLOBAL_ACTION_KEY_SETTINGS.equals(actionKey)) { |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 583 | addActionItem(getSettingsAction()); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 584 | } else if (GLOBAL_ACTION_KEY_LOCKDOWN.equals(actionKey)) { |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 585 | if (Settings.Secure.getIntForUser(mContentResolver, |
Sean Pont | 9d4fb03 | 2020-03-04 18:54:32 -0800 | [diff] [blame] | 586 | Settings.Secure.LOCKDOWN_IN_POWER_MENU, 0, getCurrentUser().id) != 0 |
Chad Brubaker | f4075fe | 2018-01-03 13:23:22 -0800 | [diff] [blame] | 587 | && shouldDisplayLockdown()) { |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 588 | addActionItem(getLockdownAction()); |
Chad Brubaker | 4f28f0d | 2017-09-07 14:28:13 -0700 | [diff] [blame] | 589 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 590 | } else if (GLOBAL_ACTION_KEY_VOICEASSIST.equals(actionKey)) { |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 591 | addActionItem(getVoiceAssistAction()); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 592 | } else if (GLOBAL_ACTION_KEY_ASSIST.equals(actionKey)) { |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 593 | addActionItem(getAssistAction()); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 594 | } else if (GLOBAL_ACTION_KEY_RESTART.equals(actionKey)) { |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 595 | addActionItem(new RestartAction()); |
Alison Cichowlas | a2cd19e | 2017-12-06 10:51:21 -0500 | [diff] [blame] | 596 | } else if (GLOBAL_ACTION_KEY_SCREENSHOT.equals(actionKey)) { |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 597 | addActionItem(new ScreenshotAction()); |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 598 | } else if (GLOBAL_ACTION_KEY_LOGOUT.equals(actionKey)) { |
Alex Chau | d795827 | 2017-12-08 11:30:52 +0000 | [diff] [blame] | 599 | if (mDevicePolicyManager.isLogoutEnabled() |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 600 | && getCurrentUser().id != UserHandle.USER_SYSTEM) { |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 601 | addActionItem(new LogoutAction()); |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 602 | } |
Wesley.CW Wang | a9de792 | 2018-07-06 15:26:21 +0800 | [diff] [blame] | 603 | } else if (GLOBAL_ACTION_KEY_EMERGENCY.equals(actionKey)) { |
Aaron Heuckroth | c834340 | 2019-03-13 16:27:15 -0400 | [diff] [blame] | 604 | if (!mEmergencyAffordanceManager.needsEmergencyAffordance()) { |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 605 | addActionItem(new EmergencyDialerAction()); |
Wesley.CW Wang | a9de792 | 2018-07-06 15:26:21 +0800 | [diff] [blame] | 606 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 607 | } else { |
| 608 | Log.e(TAG, "Invalid global action key " + actionKey); |
| 609 | } |
| 610 | // Add here so we don't add more than one. |
| 611 | addedKeys.add(actionKey); |
| 612 | } |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 613 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 614 | |
Aran Ink | a65e6836 | 2020-04-14 15:23:24 -0400 | [diff] [blame] | 615 | private void onRotate() { |
| 616 | // re-allocate actions between main and overflow lists |
| 617 | this.createActionItems(); |
| 618 | } |
| 619 | |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 620 | /** |
| 621 | * Create the global actions dialog. |
| 622 | * |
| 623 | * @return A new dialog. |
| 624 | */ |
| 625 | private ActionsDialog createDialog() { |
| 626 | createActionItems(); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 627 | |
| 628 | mAdapter = new MyAdapter(); |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 629 | mOverflowAdapter = new MyOverflowAdapter(); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 630 | |
Aran Ink | a65e6836 | 2020-04-14 15:23:24 -0400 | [diff] [blame] | 631 | mDepthController.setShowingHomeControls(shouldUseControlsLayout()); |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 632 | ActionsDialog dialog = new ActionsDialog(mContext, mAdapter, mOverflowAdapter, |
| 633 | getWalletPanelViewController(), mDepthController, mSysuiColorExtractor, |
| 634 | mStatusBarService, mNotificationShadeWindowController, |
Aran Ink | a65e6836 | 2020-04-14 15:23:24 -0400 | [diff] [blame] | 635 | shouldShowControls() ? mControlsUiController : null, mBlurUtils, |
Aran Ink | 99c452d | 2020-04-28 14:23:13 -0400 | [diff] [blame] | 636 | shouldUseControlsLayout(), this::onRotate, mKeyguardShowing); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 637 | dialog.setCanceledOnTouchOutside(false); // Handled by the custom class. |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 638 | dialog.setOnDismissListener(this); |
Shaotang Li | 786da90 | 2018-08-02 11:18:00 +0800 | [diff] [blame] | 639 | dialog.setOnShowListener(this); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 640 | |
| 641 | return dialog; |
| 642 | } |
| 643 | |
Chad Brubaker | f4075fe | 2018-01-03 13:23:22 -0800 | [diff] [blame] | 644 | private boolean shouldDisplayLockdown() { |
Chad Brubaker | f4075fe | 2018-01-03 13:23:22 -0800 | [diff] [blame] | 645 | // Lockdown is meaningless without a place to go. |
Fabian Kozynski | f6063ae | 2020-02-24 16:14:35 -0500 | [diff] [blame] | 646 | if (!mKeyguardStateController.isMethodSecure()) { |
Chad Brubaker | f4075fe | 2018-01-03 13:23:22 -0800 | [diff] [blame] | 647 | return false; |
| 648 | } |
| 649 | |
Fabian Kozynski | f6063ae | 2020-02-24 16:14:35 -0500 | [diff] [blame] | 650 | int userId = getCurrentUser().id; |
Chad Brubaker | f4075fe | 2018-01-03 13:23:22 -0800 | [diff] [blame] | 651 | // Only show the lockdown button if the device isn't locked down (for whatever reason). |
| 652 | int state = mLockPatternUtils.getStrongAuthForUser(userId); |
| 653 | return (state == STRONG_AUTH_NOT_REQUIRED |
| 654 | || state == SOME_AUTH_REQUIRED_AFTER_USER_REQUEST); |
| 655 | } |
| 656 | |
Lucas Dupin | e5b7dc7 | 2018-10-02 15:18:05 -0700 | [diff] [blame] | 657 | @Override |
| 658 | public void onUiModeChanged() { |
| 659 | mContext.getTheme().applyStyle(mContext.getThemeResId(), true); |
Lucas Dupin | a4e12ba | 2019-04-18 11:56:28 -0700 | [diff] [blame] | 660 | if (mDialog != null && mDialog.isShowing()) { |
Aaron Heuckroth | 4ef3a54 | 2019-04-01 14:17:23 -0400 | [diff] [blame] | 661 | mDialog.refreshDialog(); |
| 662 | } |
Lucas Dupin | e5b7dc7 | 2018-10-02 15:18:05 -0700 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | public void destroy() { |
Dave Mankoff | 8df818e | 2020-02-12 14:22:26 -0500 | [diff] [blame] | 666 | mConfigurationController.removeCallback(this); |
Lucas Dupin | e5b7dc7 | 2018-10-02 15:18:05 -0700 | [diff] [blame] | 667 | } |
| 668 | |
Sean Pont | 9d4fb03 | 2020-03-04 18:54:32 -0800 | [diff] [blame] | 669 | @Nullable |
| 670 | private GlobalActionsPanelPlugin.PanelViewController getWalletPanelViewController() { |
| 671 | if (mPanelPlugin == null) { |
| 672 | return null; |
| 673 | } |
| 674 | return mPanelPlugin.onPanelShown(this, !mKeyguardStateController.isUnlocked()); |
| 675 | } |
| 676 | |
| 677 | /** |
| 678 | * Implements {@link GlobalActionsPanelPlugin.Callbacks#dismissGlobalActionsMenu()}, which is |
| 679 | * called when the quick access wallet requests dismissal. |
| 680 | */ |
| 681 | @Override |
| 682 | public void dismissGlobalActionsMenu() { |
| 683 | dismissDialog(); |
| 684 | } |
| 685 | |
| 686 | /** |
| 687 | * Implements {@link GlobalActionsPanelPlugin.Callbacks#dismissGlobalActionsMenu()}, which is |
| 688 | * called when the quick access wallet requests that an intent be started (with lock screen |
| 689 | * shown first if needed). |
| 690 | */ |
| 691 | @Override |
| 692 | public void startPendingIntentDismissingKeyguard(PendingIntent pendingIntent) { |
| 693 | mActivityStarter.startPendingIntentDismissingKeyguard(pendingIntent); |
| 694 | } |
| 695 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 696 | private final class PowerAction extends SinglePressAction implements LongPressAction { |
| 697 | private PowerAction() { |
| 698 | super(R.drawable.ic_lock_power_off, |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 699 | R.string.global_action_power_off); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | @Override |
| 703 | public boolean onLongPress() { |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 704 | if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 705 | mWindowManagerFuncs.reboot(true); |
| 706 | return true; |
| 707 | } |
| 708 | return false; |
| 709 | } |
| 710 | |
| 711 | @Override |
| 712 | public boolean showDuringKeyguard() { |
| 713 | return true; |
| 714 | } |
| 715 | |
| 716 | @Override |
| 717 | public boolean showBeforeProvisioning() { |
| 718 | return true; |
| 719 | } |
| 720 | |
| 721 | @Override |
| 722 | public void onPress() { |
| 723 | // shutdown by making sure radio and power are handled accordingly. |
| 724 | mWindowManagerFuncs.shutdown(); |
| 725 | } |
| 726 | } |
| 727 | |
Aaron Heuckroth | c834340 | 2019-03-13 16:27:15 -0400 | [diff] [blame] | 728 | private abstract class EmergencyAction extends SinglePressAction { |
| 729 | EmergencyAction(int iconResId, int messageResId) { |
| 730 | super(iconResId, messageResId); |
| 731 | } |
| 732 | |
| 733 | @Override |
| 734 | public boolean shouldBeSeparated() { |
Aran Ink | a65e6836 | 2020-04-14 15:23:24 -0400 | [diff] [blame] | 735 | return !shouldUseControlsLayout(); |
Aaron Heuckroth | c834340 | 2019-03-13 16:27:15 -0400 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | @Override |
| 739 | public View create( |
| 740 | Context context, View convertView, ViewGroup parent, LayoutInflater inflater) { |
| 741 | View v = super.create(context, convertView, parent, inflater); |
| 742 | int textColor; |
Aran Ink | a65e6836 | 2020-04-14 15:23:24 -0400 | [diff] [blame] | 743 | if (shouldUseControlsLayout()) { |
Lucas Dupin | cb6726f | 2020-04-07 19:32:38 -0700 | [diff] [blame] | 744 | v.setBackgroundTintList(ColorStateList.valueOf(v.getResources().getColor( |
| 745 | com.android.systemui.R.color.global_actions_emergency_background))); |
| 746 | textColor = v.getResources().getColor( |
| 747 | com.android.systemui.R.color.global_actions_emergency_text); |
| 748 | } else if (shouldBeSeparated()) { |
Aaron Heuckroth | c834340 | 2019-03-13 16:27:15 -0400 | [diff] [blame] | 749 | textColor = v.getResources().getColor( |
| 750 | com.android.systemui.R.color.global_actions_alert_text); |
| 751 | } else { |
| 752 | textColor = v.getResources().getColor( |
| 753 | com.android.systemui.R.color.global_actions_text); |
| 754 | } |
| 755 | TextView messageView = v.findViewById(R.id.message); |
| 756 | messageView.setTextColor(textColor); |
Aaron Heuckroth | 3f2d8b5 | 2019-04-05 13:27:51 -0400 | [diff] [blame] | 757 | messageView.setSelected(true); // necessary for marquee to work |
Lucas Dupin | cb6726f | 2020-04-07 19:32:38 -0700 | [diff] [blame] | 758 | ImageView icon = v.findViewById(R.id.icon); |
Aaron Heuckroth | c834340 | 2019-03-13 16:27:15 -0400 | [diff] [blame] | 759 | icon.getDrawable().setTint(textColor); |
| 760 | return v; |
| 761 | } |
| 762 | |
| 763 | @Override |
| 764 | public boolean showDuringKeyguard() { |
| 765 | return true; |
| 766 | } |
| 767 | |
| 768 | @Override |
| 769 | public boolean showBeforeProvisioning() { |
| 770 | return true; |
| 771 | } |
| 772 | } |
| 773 | |
| 774 | private class EmergencyAffordanceAction extends EmergencyAction { |
| 775 | EmergencyAffordanceAction() { |
| 776 | super(R.drawable.emergency_icon, |
| 777 | R.string.global_action_emergency); |
| 778 | } |
| 779 | |
| 780 | @Override |
| 781 | public void onPress() { |
| 782 | mEmergencyAffordanceManager.performEmergencyCall(); |
| 783 | } |
| 784 | } |
| 785 | |
Chris Wren | af4ce846 | 2020-04-06 17:36:10 -0400 | [diff] [blame] | 786 | @VisibleForTesting |
| 787 | class EmergencyDialerAction extends EmergencyAction { |
Wesley.CW Wang | a9de792 | 2018-07-06 15:26:21 +0800 | [diff] [blame] | 788 | private EmergencyDialerAction() { |
Aran Ink | 5019526 | 2019-05-30 10:55:37 -0400 | [diff] [blame] | 789 | super(com.android.systemui.R.drawable.ic_emergency_star, |
Wesley.CW Wang | 3004fcb | 2018-06-15 16:24:57 +0800 | [diff] [blame] | 790 | R.string.global_action_emergency); |
Wesley.CW Wang | 8d07276 | 2018-05-28 16:39:27 +0800 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | @Override |
| 794 | public void onPress() { |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 795 | mMetricsLogger.action(MetricsEvent.ACTION_EMERGENCY_DIALER_FROM_POWER_MENU); |
Chris Wren | af4ce846 | 2020-04-06 17:36:10 -0400 | [diff] [blame] | 796 | mUiEventLogger.log(GlobalActionsEvent.GA_EMERGENCY_DIALER_PRESS); |
Dave Mankoff | 3c6aaab | 2020-01-10 17:50:34 -0500 | [diff] [blame] | 797 | if (mTelecomManager != null) { |
| 798 | Intent intent = mTelecomManager.createLaunchEmergencyDialerIntent( |
| 799 | null /* number */); |
| 800 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 801 | | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS |
| 802 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 803 | intent.putExtra(EmergencyDialerConstants.EXTRA_ENTRY_TYPE, |
| 804 | EmergencyDialerConstants.ENTRY_TYPE_POWER_MENU); |
| 805 | mContext.startActivityAsUser(intent, UserHandle.CURRENT); |
| 806 | } |
Wesley.CW Wang | 8d07276 | 2018-05-28 16:39:27 +0800 | [diff] [blame] | 807 | } |
Wesley.CW Wang | 8d07276 | 2018-05-28 16:39:27 +0800 | [diff] [blame] | 808 | } |
| 809 | |
Chris Wren | af4ce846 | 2020-04-06 17:36:10 -0400 | [diff] [blame] | 810 | @VisibleForTesting |
| 811 | EmergencyDialerAction makeEmergencyDialerActionForTesting() { |
| 812 | return new EmergencyDialerAction(); |
| 813 | } |
| 814 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 815 | private final class RestartAction extends SinglePressAction implements LongPressAction { |
| 816 | private RestartAction() { |
| 817 | super(R.drawable.ic_restart, R.string.global_action_restart); |
| 818 | } |
| 819 | |
| 820 | @Override |
| 821 | public boolean onLongPress() { |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 822 | if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 823 | mWindowManagerFuncs.reboot(true); |
| 824 | return true; |
| 825 | } |
| 826 | return false; |
| 827 | } |
| 828 | |
| 829 | @Override |
| 830 | public boolean showDuringKeyguard() { |
| 831 | return true; |
| 832 | } |
| 833 | |
| 834 | @Override |
| 835 | public boolean showBeforeProvisioning() { |
| 836 | return true; |
| 837 | } |
| 838 | |
| 839 | @Override |
| 840 | public void onPress() { |
| 841 | mWindowManagerFuncs.reboot(false); |
| 842 | } |
| 843 | } |
| 844 | |
Chris Wren | af4ce846 | 2020-04-06 17:36:10 -0400 | [diff] [blame] | 845 | @VisibleForTesting |
| 846 | class ScreenshotAction extends SinglePressAction implements LongPressAction { |
Alison Cichowlas | a2cd19e | 2017-12-06 10:51:21 -0500 | [diff] [blame] | 847 | public ScreenshotAction() { |
| 848 | super(R.drawable.ic_screenshot, R.string.global_action_screenshot); |
| 849 | } |
| 850 | |
| 851 | @Override |
| 852 | public void onPress() { |
| 853 | // Add a little delay before executing, to give the |
| 854 | // dialog a chance to go away before it takes a |
| 855 | // screenshot. |
| 856 | // TODO: instead, omit global action dialog layer |
| 857 | mHandler.postDelayed(new Runnable() { |
| 858 | @Override |
| 859 | public void run() { |
Miranda Kephart | 7b2c313 | 2020-03-27 09:54:14 -0400 | [diff] [blame] | 860 | mScreenshotHelper.takeScreenshot(TAKE_SCREENSHOT_FULLSCREEN, true, true, |
| 861 | SCREENSHOT_GLOBAL_ACTIONS, mHandler, null); |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 862 | mMetricsLogger.action(MetricsEvent.ACTION_SCREENSHOT_POWER_MENU); |
Chris Wren | af4ce846 | 2020-04-06 17:36:10 -0400 | [diff] [blame] | 863 | mUiEventLogger.log(GlobalActionsEvent.GA_SCREENSHOT_PRESS); |
Alison Cichowlas | a2cd19e | 2017-12-06 10:51:21 -0500 | [diff] [blame] | 864 | } |
Chris Wren | af4ce846 | 2020-04-06 17:36:10 -0400 | [diff] [blame] | 865 | }, mDialogPressDelay); |
Alison Cichowlas | a2cd19e | 2017-12-06 10:51:21 -0500 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | @Override |
| 869 | public boolean showDuringKeyguard() { |
| 870 | return true; |
| 871 | } |
| 872 | |
| 873 | @Override |
| 874 | public boolean showBeforeProvisioning() { |
| 875 | return false; |
| 876 | } |
Beth Thibodeau | 5898ac4 | 2018-10-26 13:00:09 -0400 | [diff] [blame] | 877 | |
| 878 | @Override |
| 879 | public boolean onLongPress() { |
| 880 | if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SCREENRECORD_LONG_PRESS)) { |
Chris Wren | af4ce846 | 2020-04-06 17:36:10 -0400 | [diff] [blame] | 881 | mUiEventLogger.log(GlobalActionsEvent.GA_SCREENSHOT_LONG_PRESS); |
Beth Thibodeau | 5898ac4 | 2018-10-26 13:00:09 -0400 | [diff] [blame] | 882 | mScreenRecordHelper.launchRecordPrompt(); |
| 883 | } else { |
| 884 | onPress(); |
| 885 | } |
| 886 | return true; |
| 887 | } |
Alison Cichowlas | a2cd19e | 2017-12-06 10:51:21 -0500 | [diff] [blame] | 888 | } |
| 889 | |
Chris Wren | af4ce846 | 2020-04-06 17:36:10 -0400 | [diff] [blame] | 890 | @VisibleForTesting |
| 891 | ScreenshotAction makeScreenshotActionForTesting() { |
| 892 | return new ScreenshotAction(); |
| 893 | } |
| 894 | |
| 895 | @VisibleForTesting |
| 896 | class BugReportAction extends SinglePressAction implements LongPressAction { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 897 | |
| 898 | public BugReportAction() { |
| 899 | super(R.drawable.ic_lock_bugreport, R.string.bugreport_title); |
| 900 | } |
| 901 | |
| 902 | @Override |
| 903 | public void onPress() { |
| 904 | // don't actually trigger the bugreport if we are running stability |
| 905 | // tests via monkey |
| 906 | if (ActivityManager.isUserAMonkey()) { |
| 907 | return; |
| 908 | } |
| 909 | // Add a little delay before executing, to give the |
| 910 | // dialog a chance to go away before it takes a |
| 911 | // screenshot. |
| 912 | mHandler.postDelayed(new Runnable() { |
| 913 | @Override |
| 914 | public void run() { |
| 915 | try { |
| 916 | // Take an "interactive" bugreport. |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 917 | mMetricsLogger.action( |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 918 | MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_INTERACTIVE); |
Chris Wren | af4ce846 | 2020-04-06 17:36:10 -0400 | [diff] [blame] | 919 | mUiEventLogger.log(GlobalActionsEvent.GA_BUGREPORT_PRESS); |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 920 | if (!mIActivityManager.launchBugReportHandlerApp()) { |
Paul Chang | c40f578 | 2019-11-04 18:55:31 +0800 | [diff] [blame] | 921 | Log.w(TAG, "Bugreport handler could not be launched"); |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 922 | mIActivityManager.requestInteractiveBugReport(); |
Paul Chang | c40f578 | 2019-11-04 18:55:31 +0800 | [diff] [blame] | 923 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 924 | } catch (RemoteException e) { |
| 925 | } |
| 926 | } |
Chris Wren | af4ce846 | 2020-04-06 17:36:10 -0400 | [diff] [blame] | 927 | }, mDialogPressDelay); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | @Override |
| 931 | public boolean onLongPress() { |
| 932 | // don't actually trigger the bugreport if we are running stability |
| 933 | // tests via monkey |
| 934 | if (ActivityManager.isUserAMonkey()) { |
| 935 | return false; |
| 936 | } |
| 937 | try { |
| 938 | // Take a "full" bugreport. |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 939 | mMetricsLogger.action(MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_FULL); |
Chris Wren | af4ce846 | 2020-04-06 17:36:10 -0400 | [diff] [blame] | 940 | mUiEventLogger.log(GlobalActionsEvent.GA_BUGREPORT_LONG_PRESS); |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 941 | mIActivityManager.requestFullBugReport(); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 942 | } catch (RemoteException e) { |
| 943 | } |
| 944 | return false; |
| 945 | } |
| 946 | |
| 947 | public boolean showDuringKeyguard() { |
| 948 | return true; |
| 949 | } |
| 950 | |
| 951 | @Override |
| 952 | public boolean showBeforeProvisioning() { |
| 953 | return false; |
| 954 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 955 | } |
| 956 | |
Chris Wren | af4ce846 | 2020-04-06 17:36:10 -0400 | [diff] [blame] | 957 | @VisibleForTesting |
| 958 | BugReportAction makeBugReportActionForTesting() { |
| 959 | return new BugReportAction(); |
| 960 | } |
| 961 | |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 962 | private final class LogoutAction extends SinglePressAction { |
| 963 | private LogoutAction() { |
| 964 | super(R.drawable.ic_logout, R.string.global_action_logout); |
| 965 | } |
| 966 | |
| 967 | @Override |
| 968 | public boolean showDuringKeyguard() { |
| 969 | return true; |
| 970 | } |
| 971 | |
| 972 | @Override |
| 973 | public boolean showBeforeProvisioning() { |
| 974 | return false; |
| 975 | } |
| 976 | |
| 977 | @Override |
| 978 | public void onPress() { |
| 979 | // Add a little delay before executing, to give the dialog a chance to go away before |
| 980 | // switching user |
| 981 | mHandler.postDelayed(() -> { |
| 982 | try { |
Alex Chau | edb6a01 | 2018-01-26 12:52:43 +0000 | [diff] [blame] | 983 | int currentUserId = getCurrentUser().id; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 984 | mIActivityManager.switchUser(UserHandle.USER_SYSTEM); |
| 985 | mIActivityManager.stopUser(currentUserId, true /*force*/, null); |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 986 | } catch (RemoteException re) { |
| 987 | Log.e(TAG, "Couldn't logout user " + re); |
| 988 | } |
Chris Wren | af4ce846 | 2020-04-06 17:36:10 -0400 | [diff] [blame] | 989 | }, mDialogPressDelay); |
Alex Chau | 0445885 | 2017-11-27 18:21:23 +0000 | [diff] [blame] | 990 | } |
| 991 | } |
| 992 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 993 | private Action getSettingsAction() { |
| 994 | return new SinglePressAction(R.drawable.ic_settings, |
| 995 | R.string.global_action_settings) { |
| 996 | |
| 997 | @Override |
| 998 | public void onPress() { |
| 999 | Intent intent = new Intent(Settings.ACTION_SETTINGS); |
| 1000 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 1001 | mContext.startActivity(intent); |
| 1002 | } |
| 1003 | |
| 1004 | @Override |
| 1005 | public boolean showDuringKeyguard() { |
| 1006 | return true; |
| 1007 | } |
| 1008 | |
| 1009 | @Override |
| 1010 | public boolean showBeforeProvisioning() { |
| 1011 | return true; |
| 1012 | } |
| 1013 | }; |
| 1014 | } |
| 1015 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1016 | private Action getAssistAction() { |
| 1017 | return new SinglePressAction(R.drawable.ic_action_assist_focused, |
| 1018 | R.string.global_action_assist) { |
| 1019 | @Override |
| 1020 | public void onPress() { |
| 1021 | Intent intent = new Intent(Intent.ACTION_ASSIST); |
| 1022 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 1023 | mContext.startActivity(intent); |
| 1024 | } |
| 1025 | |
| 1026 | @Override |
| 1027 | public boolean showDuringKeyguard() { |
| 1028 | return true; |
| 1029 | } |
| 1030 | |
| 1031 | @Override |
| 1032 | public boolean showBeforeProvisioning() { |
| 1033 | return true; |
| 1034 | } |
| 1035 | }; |
| 1036 | } |
| 1037 | |
| 1038 | private Action getVoiceAssistAction() { |
| 1039 | return new SinglePressAction(R.drawable.ic_voice_search, |
| 1040 | R.string.global_action_voice_assist) { |
| 1041 | @Override |
| 1042 | public void onPress() { |
| 1043 | Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST); |
| 1044 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 1045 | mContext.startActivity(intent); |
| 1046 | } |
| 1047 | |
| 1048 | @Override |
| 1049 | public boolean showDuringKeyguard() { |
| 1050 | return true; |
| 1051 | } |
| 1052 | |
| 1053 | @Override |
| 1054 | public boolean showBeforeProvisioning() { |
| 1055 | return true; |
| 1056 | } |
| 1057 | }; |
| 1058 | } |
| 1059 | |
| 1060 | private Action getLockdownAction() { |
Alison Cichowlas | 2112543 | 2018-05-16 15:40:45 -0400 | [diff] [blame] | 1061 | return new SinglePressAction(R.drawable.ic_lock_lockdown, |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1062 | R.string.global_action_lockdown) { |
| 1063 | |
| 1064 | @Override |
| 1065 | public void onPress() { |
Dave Mankoff | 8df818e | 2020-02-12 14:22:26 -0500 | [diff] [blame] | 1066 | mLockPatternUtils.requireStrongAuth(STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN, |
| 1067 | UserHandle.USER_ALL); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1068 | try { |
Dave Mankoff | 8df818e | 2020-02-12 14:22:26 -0500 | [diff] [blame] | 1069 | mIWindowManager.lockNow(null); |
Pavel Grafov | 059021b | 2018-05-02 13:44:46 +0100 | [diff] [blame] | 1070 | // Lock profiles (if any) on the background thread. |
Dave Mankoff | 8df818e | 2020-02-12 14:22:26 -0500 | [diff] [blame] | 1071 | mBackgroundExecutor.execute(() -> lockProfiles()); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1072 | } catch (RemoteException e) { |
| 1073 | Log.e(TAG, "Error while trying to lock device.", e); |
| 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | @Override |
| 1078 | public boolean showDuringKeyguard() { |
| 1079 | return true; |
| 1080 | } |
| 1081 | |
| 1082 | @Override |
| 1083 | public boolean showBeforeProvisioning() { |
| 1084 | return false; |
| 1085 | } |
| 1086 | }; |
| 1087 | } |
| 1088 | |
Pavel Grafov | 059021b | 2018-05-02 13:44:46 +0100 | [diff] [blame] | 1089 | private void lockProfiles() { |
Pavel Grafov | 059021b | 2018-05-02 13:44:46 +0100 | [diff] [blame] | 1090 | final int currentUserId = getCurrentUser().id; |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 1091 | final int[] profileIds = mUserManager.getEnabledProfileIds(currentUserId); |
Pavel Grafov | 059021b | 2018-05-02 13:44:46 +0100 | [diff] [blame] | 1092 | for (final int id : profileIds) { |
| 1093 | if (id != currentUserId) { |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 1094 | mTrustManager.setDeviceLockedForUser(id, true); |
Pavel Grafov | 059021b | 2018-05-02 13:44:46 +0100 | [diff] [blame] | 1095 | } |
| 1096 | } |
| 1097 | } |
| 1098 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1099 | private UserInfo getCurrentUser() { |
| 1100 | try { |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 1101 | return mIActivityManager.getCurrentUser(); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1102 | } catch (RemoteException re) { |
| 1103 | return null; |
| 1104 | } |
| 1105 | } |
| 1106 | |
| 1107 | private boolean isCurrentUserOwner() { |
| 1108 | UserInfo currentUser = getCurrentUser(); |
| 1109 | return currentUser == null || currentUser.isPrimary(); |
| 1110 | } |
| 1111 | |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 1112 | private void addUsersToMenu() { |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 1113 | if (mUserManager.isUserSwitcherEnabled()) { |
| 1114 | List<UserInfo> users = mUserManager.getUsers(); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1115 | UserInfo currentUser = getCurrentUser(); |
| 1116 | for (final UserInfo user : users) { |
| 1117 | if (user.supportsSwitchToByUser()) { |
| 1118 | boolean isCurrentUser = currentUser == null |
| 1119 | ? user.id == 0 : (currentUser.id == user.id); |
| 1120 | Drawable icon = user.iconPath != null ? Drawable.createFromPath(user.iconPath) |
| 1121 | : null; |
| 1122 | SinglePressAction switchToUser = new SinglePressAction( |
| 1123 | R.drawable.ic_menu_cc, icon, |
| 1124 | (user.name != null ? user.name : "Primary") |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1125 | + (isCurrentUser ? " \u2714" : "")) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1126 | public void onPress() { |
| 1127 | try { |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 1128 | mIActivityManager.switchUser(user.id); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1129 | } catch (RemoteException re) { |
| 1130 | Log.e(TAG, "Couldn't switch user " + re); |
| 1131 | } |
| 1132 | } |
| 1133 | |
| 1134 | public boolean showDuringKeyguard() { |
| 1135 | return true; |
| 1136 | } |
| 1137 | |
| 1138 | public boolean showBeforeProvisioning() { |
| 1139 | return false; |
| 1140 | } |
| 1141 | }; |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 1142 | addActionItem(switchToUser); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1143 | } |
| 1144 | } |
| 1145 | } |
| 1146 | } |
| 1147 | |
| 1148 | private void prepareDialog() { |
| 1149 | refreshSilentMode(); |
| 1150 | mAirplaneModeOn.updateState(mAirplaneState); |
| 1151 | mAdapter.notifyDataSetChanged(); |
Fabian Kozynski | b6a2037 | 2020-04-01 09:36:43 -0400 | [diff] [blame] | 1152 | mLifecycle.setCurrentState(Lifecycle.State.RESUMED); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1153 | } |
| 1154 | |
| 1155 | private void refreshSilentMode() { |
| 1156 | if (!mHasVibrator) { |
Fabian Kozynski | b6a2037 | 2020-04-01 09:36:43 -0400 | [diff] [blame] | 1157 | Integer value = mRingerModeTracker.getRingerMode().getValue(); |
| 1158 | final boolean silentModeOn = value != null && value != AudioManager.RINGER_MODE_NORMAL; |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1159 | ((ToggleAction) mSilentModeAction).updateState( |
Lucas Dupin | cb6726f | 2020-04-07 19:32:38 -0700 | [diff] [blame] | 1160 | silentModeOn ? ToggleState.On : ToggleState.Off); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1161 | } |
| 1162 | } |
| 1163 | |
Sean Pont | 9d4fb03 | 2020-03-04 18:54:32 -0800 | [diff] [blame] | 1164 | /** |
| 1165 | * {@inheritDoc} |
| 1166 | */ |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1167 | public void onDismiss(DialogInterface dialog) { |
Steve Elliott | c3147e2 | 2019-11-20 19:34:57 -0500 | [diff] [blame] | 1168 | if (mDialog == dialog) { |
| 1169 | mDialog = null; |
| 1170 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1171 | mWindowManagerFuncs.onGlobalActionsHidden(); |
Fabian Kozynski | b6a2037 | 2020-04-01 09:36:43 -0400 | [diff] [blame] | 1172 | mLifecycle.setCurrentState(Lifecycle.State.DESTROYED); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1173 | } |
| 1174 | |
Sean Pont | 9d4fb03 | 2020-03-04 18:54:32 -0800 | [diff] [blame] | 1175 | /** |
| 1176 | * {@inheritDoc} |
| 1177 | */ |
Shaotang Li | 786da90 | 2018-08-02 11:18:00 +0800 | [diff] [blame] | 1178 | public void onShow(DialogInterface dialog) { |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 1179 | mMetricsLogger.visible(MetricsEvent.POWER_MENU); |
Chris Wren | 65a70c9 | 2020-04-02 10:43:46 -0400 | [diff] [blame] | 1180 | mUiEventLogger.log(GlobalActionsEvent.GA_POWER_MENU_OPEN); |
Shaotang Li | 786da90 | 2018-08-02 11:18:00 +0800 | [diff] [blame] | 1181 | } |
| 1182 | |
Lucas Dupin | cb6726f | 2020-04-07 19:32:38 -0700 | [diff] [blame] | 1183 | private int getActionLayoutId() { |
Aran Ink | a65e6836 | 2020-04-14 15:23:24 -0400 | [diff] [blame] | 1184 | if (shouldUseControlsLayout()) { |
Lucas Dupin | cb6726f | 2020-04-07 19:32:38 -0700 | [diff] [blame] | 1185 | return com.android.systemui.R.layout.global_actions_grid_item_v2; |
| 1186 | } |
| 1187 | return com.android.systemui.R.layout.global_actions_grid_item; |
| 1188 | } |
| 1189 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1190 | /** |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 1191 | * The adapter used for power menu items shown in the global actions dialog. |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1192 | */ |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 1193 | public class MyAdapter extends MultiListAdapter { |
Aaron Heuckroth | 5e28f8c8 | 2019-04-24 13:26:12 -0400 | [diff] [blame] | 1194 | private int countItems(boolean separated) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1195 | int count = 0; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1196 | for (int i = 0; i < mItems.size(); i++) { |
| 1197 | final Action action = mItems.get(i); |
| 1198 | |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 1199 | if (action.shouldBeSeparated() == separated) { |
Aaron Heuckroth | 5e28f8c8 | 2019-04-24 13:26:12 -0400 | [diff] [blame] | 1200 | count++; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1201 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1202 | } |
| 1203 | return count; |
| 1204 | } |
| 1205 | |
Aaron Heuckroth | 5e28f8c8 | 2019-04-24 13:26:12 -0400 | [diff] [blame] | 1206 | @Override |
| 1207 | public int countSeparatedItems() { |
| 1208 | return countItems(true); |
| 1209 | } |
| 1210 | |
| 1211 | @Override |
| 1212 | public int countListItems() { |
| 1213 | return countItems(false); |
| 1214 | } |
| 1215 | |
| 1216 | @Override |
| 1217 | public int getCount() { |
| 1218 | return countSeparatedItems() + countListItems(); |
| 1219 | } |
| 1220 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1221 | @Override |
| 1222 | public boolean isEnabled(int position) { |
| 1223 | return getItem(position).isEnabled(); |
| 1224 | } |
| 1225 | |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 1226 | @Override |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1227 | public boolean areAllItemsEnabled() { |
| 1228 | return false; |
| 1229 | } |
| 1230 | |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 1231 | @Override |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1232 | public Action getItem(int position) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1233 | int filteredPos = 0; |
| 1234 | for (int i = 0; i < mItems.size(); i++) { |
| 1235 | final Action action = mItems.get(i); |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 1236 | if (!shouldShowAction(action)) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1237 | continue; |
| 1238 | } |
| 1239 | if (filteredPos == position) { |
| 1240 | return action; |
| 1241 | } |
| 1242 | filteredPos++; |
| 1243 | } |
| 1244 | |
| 1245 | throw new IllegalArgumentException("position " + position |
| 1246 | + " out of range of showable actions" |
| 1247 | + ", filtered count=" + getCount() |
| 1248 | + ", keyguardshowing=" + mKeyguardShowing |
| 1249 | + ", provisioned=" + mDeviceProvisioned); |
| 1250 | } |
| 1251 | |
| 1252 | |
| 1253 | public long getItemId(int position) { |
| 1254 | return position; |
| 1255 | } |
| 1256 | |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 1257 | @Override |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1258 | public View getView(int position, View convertView, ViewGroup parent) { |
| 1259 | Action action = getItem(position); |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1260 | View view = action.create(mContext, convertView, parent, LayoutInflater.from(mContext)); |
Aaron Heuckroth | 5e28f8c8 | 2019-04-24 13:26:12 -0400 | [diff] [blame] | 1261 | view.setOnClickListener(v -> onClickItem(position)); |
Aran Ink | b4199d9 | 2020-02-07 13:25:21 -0500 | [diff] [blame] | 1262 | if (action instanceof LongPressAction) { |
| 1263 | view.setOnLongClickListener(v -> onLongClickItem(position)); |
| 1264 | } |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1265 | return view; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1266 | } |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 1267 | |
| 1268 | @Override |
| 1269 | public boolean onLongClickItem(int position) { |
| 1270 | final Action action = mAdapter.getItem(position); |
| 1271 | if (action instanceof LongPressAction) { |
Aran Ink | baa2586 | 2019-06-11 15:48:55 -0400 | [diff] [blame] | 1272 | if (mDialog != null) { |
| 1273 | mDialog.dismiss(); |
| 1274 | } else { |
| 1275 | Log.w(TAG, "Action long-clicked while mDialog is null."); |
| 1276 | } |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 1277 | return ((LongPressAction) action).onLongPress(); |
| 1278 | } |
| 1279 | return false; |
| 1280 | } |
| 1281 | |
| 1282 | @Override |
| 1283 | public void onClickItem(int position) { |
| 1284 | Action item = mAdapter.getItem(position); |
| 1285 | if (!(item instanceof SilentModeTriStateAction)) { |
Aran Ink | baa2586 | 2019-06-11 15:48:55 -0400 | [diff] [blame] | 1286 | if (mDialog != null) { |
| 1287 | mDialog.dismiss(); |
| 1288 | } else { |
| 1289 | Log.w(TAG, "Action clicked while mDialog is null."); |
| 1290 | } |
| 1291 | item.onPress(); |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 1292 | } |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 1293 | } |
Aaron Heuckroth | 5e28f8c8 | 2019-04-24 13:26:12 -0400 | [diff] [blame] | 1294 | |
| 1295 | @Override |
| 1296 | public boolean shouldBeSeparated(int position) { |
| 1297 | return getItem(position).shouldBeSeparated(); |
| 1298 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1299 | } |
| 1300 | |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 1301 | /** |
| 1302 | * The adapter used for items in the overflow menu. |
| 1303 | */ |
| 1304 | public class MyOverflowAdapter extends BaseAdapter { |
| 1305 | @Override |
| 1306 | public int getCount() { |
Aran Ink | a65e6836 | 2020-04-14 15:23:24 -0400 | [diff] [blame] | 1307 | return mOverflowItems.size(); |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | @Override |
| 1311 | public Action getItem(int position) { |
Aran Ink | a65e6836 | 2020-04-14 15:23:24 -0400 | [diff] [blame] | 1312 | return mOverflowItems.get(position); |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 1313 | } |
| 1314 | |
| 1315 | @Override |
| 1316 | public long getItemId(int position) { |
| 1317 | return position; |
| 1318 | } |
| 1319 | |
| 1320 | @Override |
| 1321 | public View getView(int position, View convertView, ViewGroup parent) { |
| 1322 | Action action = getItem(position); |
| 1323 | if (action == null) { |
| 1324 | Log.w(TAG, "No overflow action found at position: " + position); |
| 1325 | return null; |
| 1326 | } |
| 1327 | int viewLayoutResource = com.android.systemui.R.layout.controls_more_item; |
| 1328 | View view = convertView != null ? convertView |
| 1329 | : LayoutInflater.from(mContext).inflate(viewLayoutResource, parent, false); |
| 1330 | TextView textView = (TextView) view; |
| 1331 | textView.setOnClickListener(v -> onClickItem(position)); |
| 1332 | if (action.getMessageResId() != 0) { |
| 1333 | textView.setText(action.getMessageResId()); |
| 1334 | } else { |
| 1335 | textView.setText(action.getMessage()); |
| 1336 | } |
| 1337 | |
| 1338 | if (action instanceof LongPressAction) { |
| 1339 | textView.setOnLongClickListener(v -> onLongClickItem(position)); |
| 1340 | } else { |
| 1341 | textView.setOnLongClickListener(null); |
| 1342 | } |
| 1343 | return textView; |
| 1344 | } |
| 1345 | |
| 1346 | private boolean onLongClickItem(int position) { |
| 1347 | final Action action = getItem(position); |
| 1348 | if (action instanceof LongPressAction) { |
| 1349 | if (mDialog != null) { |
| 1350 | mDialog.hidePowerOverflowMenu(); |
| 1351 | mDialog.dismiss(); |
| 1352 | } else { |
| 1353 | Log.w(TAG, "Action long-clicked while mDialog is null."); |
| 1354 | } |
| 1355 | return ((LongPressAction) action).onLongPress(); |
| 1356 | } |
| 1357 | return false; |
| 1358 | } |
| 1359 | |
| 1360 | private void onClickItem(int position) { |
| 1361 | Action item = getItem(position); |
| 1362 | if (!(item instanceof SilentModeTriStateAction)) { |
| 1363 | if (mDialog != null) { |
| 1364 | mDialog.hidePowerOverflowMenu(); |
| 1365 | mDialog.dismiss(); |
| 1366 | } else { |
| 1367 | Log.w(TAG, "Action clicked while mDialog is null."); |
| 1368 | } |
| 1369 | item.onPress(); |
| 1370 | } |
| 1371 | } |
| 1372 | } |
| 1373 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1374 | // note: the scheme below made more sense when we were planning on having |
| 1375 | // 8 different things in the global actions dialog. seems overkill with |
| 1376 | // only 3 items now, but may as well keep this flexible approach so it will |
| 1377 | // be easy should someone decide at the last minute to include something |
| 1378 | // else, such as 'enable wifi', or 'enable bluetooth' |
| 1379 | |
| 1380 | /** |
| 1381 | * What each item in the global actions dialog must be able to support. |
| 1382 | */ |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 1383 | public interface Action { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1384 | /** |
Sean Pont | 9d4fb03 | 2020-03-04 18:54:32 -0800 | [diff] [blame] | 1385 | * @return Text that will be announced when dialog is created. null for none. |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1386 | */ |
| 1387 | CharSequence getLabelForAccessibility(Context context); |
| 1388 | |
| 1389 | View create(Context context, View convertView, ViewGroup parent, LayoutInflater inflater); |
| 1390 | |
| 1391 | void onPress(); |
| 1392 | |
| 1393 | /** |
Sean Pont | 9d4fb03 | 2020-03-04 18:54:32 -0800 | [diff] [blame] | 1394 | * @return whether this action should appear in the dialog when the keygaurd is showing. |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1395 | */ |
| 1396 | boolean showDuringKeyguard(); |
| 1397 | |
| 1398 | /** |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 1399 | * @return whether this action should appear in the dialog before the |
| 1400 | * device is provisioned.f |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1401 | */ |
| 1402 | boolean showBeforeProvisioning(); |
| 1403 | |
| 1404 | boolean isEnabled(); |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 1405 | |
| 1406 | default boolean shouldBeSeparated() { |
| 1407 | return false; |
| 1408 | } |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 1409 | |
| 1410 | /** |
| 1411 | * Return the id of the message associated with this action, or 0 if it doesn't have one. |
| 1412 | * @return |
| 1413 | */ |
| 1414 | int getMessageResId(); |
| 1415 | |
| 1416 | /** |
| 1417 | * Return the message associated with this action, or null if it doesn't have one. |
| 1418 | * @return |
| 1419 | */ |
| 1420 | CharSequence getMessage(); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1421 | } |
| 1422 | |
| 1423 | /** |
| 1424 | * An action that also supports long press. |
| 1425 | */ |
| 1426 | private interface LongPressAction extends Action { |
| 1427 | boolean onLongPress(); |
| 1428 | } |
| 1429 | |
| 1430 | /** |
Sean Pont | 9d4fb03 | 2020-03-04 18:54:32 -0800 | [diff] [blame] | 1431 | * A single press action maintains no state, just responds to a press and takes an action. |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1432 | */ |
Matt Pietal | e0661b6 | 2020-01-29 14:35:31 -0500 | [diff] [blame] | 1433 | |
| 1434 | private abstract class SinglePressAction implements Action { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1435 | private final int mIconResId; |
| 1436 | private final Drawable mIcon; |
| 1437 | private final int mMessageResId; |
| 1438 | private final CharSequence mMessage; |
| 1439 | |
| 1440 | protected SinglePressAction(int iconResId, int messageResId) { |
| 1441 | mIconResId = iconResId; |
| 1442 | mMessageResId = messageResId; |
| 1443 | mMessage = null; |
| 1444 | mIcon = null; |
| 1445 | } |
| 1446 | |
| 1447 | protected SinglePressAction(int iconResId, Drawable icon, CharSequence message) { |
| 1448 | mIconResId = iconResId; |
| 1449 | mMessageResId = 0; |
| 1450 | mMessage = message; |
| 1451 | mIcon = icon; |
| 1452 | } |
| 1453 | |
| 1454 | public boolean isEnabled() { |
| 1455 | return true; |
| 1456 | } |
| 1457 | |
| 1458 | public String getStatus() { |
| 1459 | return null; |
| 1460 | } |
| 1461 | |
| 1462 | abstract public void onPress(); |
| 1463 | |
| 1464 | public CharSequence getLabelForAccessibility(Context context) { |
| 1465 | if (mMessage != null) { |
| 1466 | return mMessage; |
| 1467 | } else { |
| 1468 | return context.getString(mMessageResId); |
| 1469 | } |
| 1470 | } |
| 1471 | |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 1472 | |
| 1473 | public int getMessageResId() { |
| 1474 | return mMessageResId; |
| 1475 | } |
| 1476 | |
| 1477 | public CharSequence getMessage() { |
| 1478 | return mMessage; |
| 1479 | } |
| 1480 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1481 | public View create( |
| 1482 | Context context, View convertView, ViewGroup parent, LayoutInflater inflater) { |
Lucas Dupin | cb6726f | 2020-04-07 19:32:38 -0700 | [diff] [blame] | 1483 | View v = inflater.inflate(getActionLayoutId(), parent, false /* attach */); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1484 | |
Lucas Dupin | cb6726f | 2020-04-07 19:32:38 -0700 | [diff] [blame] | 1485 | ImageView icon = v.findViewById(R.id.icon); |
| 1486 | TextView messageView = v.findViewById(R.id.message); |
Aaron Heuckroth | 3f2d8b5 | 2019-04-05 13:27:51 -0400 | [diff] [blame] | 1487 | messageView.setSelected(true); // necessary for marquee to work |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1488 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1489 | if (mIcon != null) { |
| 1490 | icon.setImageDrawable(mIcon); |
| 1491 | icon.setScaleType(ScaleType.CENTER_CROP); |
| 1492 | } else if (mIconResId != 0) { |
| 1493 | icon.setImageDrawable(context.getDrawable(mIconResId)); |
| 1494 | } |
| 1495 | if (mMessage != null) { |
| 1496 | messageView.setText(mMessage); |
| 1497 | } else { |
| 1498 | messageView.setText(mMessageResId); |
| 1499 | } |
| 1500 | |
| 1501 | return v; |
| 1502 | } |
| 1503 | } |
| 1504 | |
Lucas Dupin | cb6726f | 2020-04-07 19:32:38 -0700 | [diff] [blame] | 1505 | private enum ToggleState { |
| 1506 | Off(false), |
| 1507 | TurningOn(true), |
| 1508 | TurningOff(true), |
| 1509 | On(false); |
| 1510 | |
| 1511 | private final boolean mInTransition; |
| 1512 | |
| 1513 | ToggleState(boolean intermediate) { |
| 1514 | mInTransition = intermediate; |
| 1515 | } |
| 1516 | |
| 1517 | public boolean inTransition() { |
| 1518 | return mInTransition; |
| 1519 | } |
| 1520 | } |
| 1521 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1522 | /** |
Sean Pont | 9d4fb03 | 2020-03-04 18:54:32 -0800 | [diff] [blame] | 1523 | * A toggle action knows whether it is on or off, and displays an icon and status message |
| 1524 | * accordingly. |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1525 | */ |
Lucas Dupin | cb6726f | 2020-04-07 19:32:38 -0700 | [diff] [blame] | 1526 | private abstract class ToggleAction implements Action { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1527 | |
Lucas Dupin | cb6726f | 2020-04-07 19:32:38 -0700 | [diff] [blame] | 1528 | protected ToggleState mState = ToggleState.Off; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1529 | |
| 1530 | // prefs |
| 1531 | protected int mEnabledIconResId; |
| 1532 | protected int mDisabledIconResid; |
| 1533 | protected int mMessageResId; |
| 1534 | protected int mEnabledStatusMessageResId; |
| 1535 | protected int mDisabledStatusMessageResId; |
| 1536 | |
| 1537 | /** |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1538 | * @param enabledIconResId The icon for when this action is on. |
| 1539 | * @param disabledIconResid The icon for when this action is off. |
| 1540 | * @param message The general information message, e.g 'Silent Mode' |
| 1541 | * @param enabledStatusMessageResId The on status message, e.g 'sound disabled' |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1542 | * @param disabledStatusMessageResId The off status message, e.g. 'sound enabled' |
| 1543 | */ |
| 1544 | public ToggleAction(int enabledIconResId, |
| 1545 | int disabledIconResid, |
| 1546 | int message, |
| 1547 | int enabledStatusMessageResId, |
| 1548 | int disabledStatusMessageResId) { |
| 1549 | mEnabledIconResId = enabledIconResId; |
| 1550 | mDisabledIconResid = disabledIconResid; |
| 1551 | mMessageResId = message; |
| 1552 | mEnabledStatusMessageResId = enabledStatusMessageResId; |
| 1553 | mDisabledStatusMessageResId = disabledStatusMessageResId; |
| 1554 | } |
| 1555 | |
| 1556 | /** |
Sean Pont | 9d4fb03 | 2020-03-04 18:54:32 -0800 | [diff] [blame] | 1557 | * Override to make changes to resource IDs just before creating the View. |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1558 | */ |
| 1559 | void willCreate() { |
| 1560 | |
| 1561 | } |
| 1562 | |
| 1563 | @Override |
| 1564 | public CharSequence getLabelForAccessibility(Context context) { |
| 1565 | return context.getString(mMessageResId); |
| 1566 | } |
| 1567 | |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 1568 | private boolean isOn() { |
| 1569 | return mState == ToggleState.On || mState == ToggleState.TurningOn; |
| 1570 | } |
| 1571 | |
| 1572 | @Override |
| 1573 | public CharSequence getMessage() { |
| 1574 | return null; |
| 1575 | } |
| 1576 | @Override |
| 1577 | public int getMessageResId() { |
| 1578 | return isOn() ? mEnabledStatusMessageResId : mDisabledStatusMessageResId; |
| 1579 | } |
| 1580 | |
| 1581 | private int getIconResId() { |
| 1582 | return isOn() ? mEnabledIconResId : mDisabledIconResid; |
| 1583 | } |
| 1584 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1585 | public View create(Context context, View convertView, ViewGroup parent, |
| 1586 | LayoutInflater inflater) { |
| 1587 | willCreate(); |
| 1588 | |
Lucas Dupin | cb6726f | 2020-04-07 19:32:38 -0700 | [diff] [blame] | 1589 | View v = inflater.inflate(getActionLayoutId(), parent, false /* attach */); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1590 | |
| 1591 | ImageView icon = (ImageView) v.findViewById(R.id.icon); |
| 1592 | TextView messageView = (TextView) v.findViewById(R.id.message); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1593 | final boolean enabled = isEnabled(); |
| 1594 | |
| 1595 | if (messageView != null) { |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 1596 | messageView.setText(getMessageResId()); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1597 | messageView.setEnabled(enabled); |
Aaron Heuckroth | 3f2d8b5 | 2019-04-05 13:27:51 -0400 | [diff] [blame] | 1598 | messageView.setSelected(true); // necessary for marquee to work |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1599 | } |
| 1600 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1601 | if (icon != null) { |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 1602 | icon.setImageDrawable(context.getDrawable(getIconResId())); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1603 | icon.setEnabled(enabled); |
| 1604 | } |
| 1605 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1606 | v.setEnabled(enabled); |
| 1607 | |
| 1608 | return v; |
| 1609 | } |
| 1610 | |
| 1611 | public final void onPress() { |
| 1612 | if (mState.inTransition()) { |
| 1613 | Log.w(TAG, "shouldn't be able to toggle when in transition"); |
| 1614 | return; |
| 1615 | } |
| 1616 | |
Lucas Dupin | cb6726f | 2020-04-07 19:32:38 -0700 | [diff] [blame] | 1617 | final boolean nowOn = !(mState == ToggleState.On); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1618 | onToggle(nowOn); |
| 1619 | changeStateFromPress(nowOn); |
| 1620 | } |
| 1621 | |
| 1622 | public boolean isEnabled() { |
| 1623 | return !mState.inTransition(); |
| 1624 | } |
| 1625 | |
| 1626 | /** |
Sean Pont | 9d4fb03 | 2020-03-04 18:54:32 -0800 | [diff] [blame] | 1627 | * Implementations may override this if their state can be in on of the intermediate states |
| 1628 | * until some notification is received (e.g airplane mode is 'turning off' until we know the |
| 1629 | * wireless connections are back online |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1630 | * |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1631 | * @param buttonOn Whether the button was turned on or off |
| 1632 | */ |
| 1633 | protected void changeStateFromPress(boolean buttonOn) { |
Lucas Dupin | cb6726f | 2020-04-07 19:32:38 -0700 | [diff] [blame] | 1634 | mState = buttonOn ? ToggleState.On : ToggleState.Off; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1635 | } |
| 1636 | |
| 1637 | abstract void onToggle(boolean on); |
| 1638 | |
Lucas Dupin | cb6726f | 2020-04-07 19:32:38 -0700 | [diff] [blame] | 1639 | public void updateState(ToggleState state) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1640 | mState = state; |
| 1641 | } |
| 1642 | } |
| 1643 | |
Aran Ink | 780d450 | 2020-02-14 10:39:58 -0500 | [diff] [blame] | 1644 | private class AirplaneModeAction extends ToggleAction { |
| 1645 | AirplaneModeAction() { |
| 1646 | super( |
Sean Pont | 9d4fb03 | 2020-03-04 18:54:32 -0800 | [diff] [blame] | 1647 | R.drawable.ic_lock_airplane_mode, |
| 1648 | R.drawable.ic_lock_airplane_mode_off, |
| 1649 | R.string.global_actions_toggle_airplane_mode, |
| 1650 | R.string.global_actions_airplane_mode_on_status, |
| 1651 | R.string.global_actions_airplane_mode_off_status); |
Aran Ink | 780d450 | 2020-02-14 10:39:58 -0500 | [diff] [blame] | 1652 | } |
Sean Pont | 9d4fb03 | 2020-03-04 18:54:32 -0800 | [diff] [blame] | 1653 | |
Aran Ink | 780d450 | 2020-02-14 10:39:58 -0500 | [diff] [blame] | 1654 | void onToggle(boolean on) { |
| 1655 | if (mHasTelephony && TelephonyProperties.in_ecm_mode().orElse(false)) { |
| 1656 | mIsWaitingForEcmExit = true; |
| 1657 | // Launch ECM exit dialog |
| 1658 | Intent ecmDialogIntent = |
| 1659 | new Intent(TelephonyManager.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null); |
| 1660 | ecmDialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1661 | mContext.startActivity(ecmDialogIntent); |
| 1662 | } else { |
| 1663 | changeAirplaneModeSystemSetting(on); |
| 1664 | } |
| 1665 | } |
| 1666 | |
| 1667 | @Override |
| 1668 | protected void changeStateFromPress(boolean buttonOn) { |
| 1669 | if (!mHasTelephony) return; |
| 1670 | |
| 1671 | // In ECM mode airplane state cannot be changed |
| 1672 | if (!TelephonyProperties.in_ecm_mode().orElse(false)) { |
Lucas Dupin | cb6726f | 2020-04-07 19:32:38 -0700 | [diff] [blame] | 1673 | mState = buttonOn ? ToggleState.TurningOn : ToggleState.TurningOff; |
Aran Ink | 780d450 | 2020-02-14 10:39:58 -0500 | [diff] [blame] | 1674 | mAirplaneState = mState; |
| 1675 | } |
| 1676 | } |
| 1677 | |
| 1678 | public boolean showDuringKeyguard() { |
| 1679 | return true; |
| 1680 | } |
| 1681 | |
| 1682 | public boolean showBeforeProvisioning() { |
| 1683 | return false; |
| 1684 | } |
| 1685 | } |
| 1686 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1687 | private class SilentModeToggleAction extends ToggleAction { |
| 1688 | public SilentModeToggleAction() { |
| 1689 | super(R.drawable.ic_audio_vol_mute, |
| 1690 | R.drawable.ic_audio_vol, |
| 1691 | R.string.global_action_toggle_silent_mode, |
| 1692 | R.string.global_action_silent_mode_on_status, |
| 1693 | R.string.global_action_silent_mode_off_status); |
| 1694 | } |
| 1695 | |
| 1696 | void onToggle(boolean on) { |
| 1697 | if (on) { |
| 1698 | mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT); |
| 1699 | } else { |
| 1700 | mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); |
| 1701 | } |
| 1702 | } |
| 1703 | |
| 1704 | public boolean showDuringKeyguard() { |
| 1705 | return true; |
| 1706 | } |
| 1707 | |
| 1708 | public boolean showBeforeProvisioning() { |
| 1709 | return false; |
| 1710 | } |
| 1711 | } |
| 1712 | |
| 1713 | private static class SilentModeTriStateAction implements Action, View.OnClickListener { |
| 1714 | |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1715 | private final int[] ITEM_IDS = {R.id.option1, R.id.option2, R.id.option3}; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1716 | |
| 1717 | private final AudioManager mAudioManager; |
| 1718 | private final Handler mHandler; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1719 | |
Lucas Dupin | 40ec6b78 | 2018-06-05 19:07:16 -0700 | [diff] [blame] | 1720 | SilentModeTriStateAction(AudioManager audioManager, Handler handler) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1721 | mAudioManager = audioManager; |
| 1722 | mHandler = handler; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1723 | } |
| 1724 | |
| 1725 | private int ringerModeToIndex(int ringerMode) { |
| 1726 | // They just happen to coincide |
| 1727 | return ringerMode; |
| 1728 | } |
| 1729 | |
| 1730 | private int indexToRingerMode(int index) { |
| 1731 | // They just happen to coincide |
| 1732 | return index; |
| 1733 | } |
| 1734 | |
| 1735 | @Override |
| 1736 | public CharSequence getLabelForAccessibility(Context context) { |
| 1737 | return null; |
| 1738 | } |
| 1739 | |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 1740 | @Override |
| 1741 | public int getMessageResId() { |
| 1742 | return 0; |
| 1743 | } |
| 1744 | |
| 1745 | @Override |
| 1746 | public CharSequence getMessage() { |
| 1747 | return null; |
| 1748 | } |
| 1749 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1750 | public View create(Context context, View convertView, ViewGroup parent, |
| 1751 | LayoutInflater inflater) { |
| 1752 | View v = inflater.inflate(R.layout.global_actions_silent_mode, parent, false); |
| 1753 | |
| 1754 | int selectedIndex = ringerModeToIndex(mAudioManager.getRingerMode()); |
| 1755 | for (int i = 0; i < 3; i++) { |
| 1756 | View itemView = v.findViewById(ITEM_IDS[i]); |
| 1757 | itemView.setSelected(selectedIndex == i); |
| 1758 | // Set up click handler |
| 1759 | itemView.setTag(i); |
| 1760 | itemView.setOnClickListener(this); |
| 1761 | } |
| 1762 | return v; |
| 1763 | } |
| 1764 | |
| 1765 | public void onPress() { |
| 1766 | } |
| 1767 | |
| 1768 | public boolean showDuringKeyguard() { |
| 1769 | return true; |
| 1770 | } |
| 1771 | |
| 1772 | public boolean showBeforeProvisioning() { |
| 1773 | return false; |
| 1774 | } |
| 1775 | |
| 1776 | public boolean isEnabled() { |
| 1777 | return true; |
| 1778 | } |
| 1779 | |
| 1780 | void willCreate() { |
| 1781 | } |
| 1782 | |
| 1783 | public void onClick(View v) { |
| 1784 | if (!(v.getTag() instanceof Integer)) return; |
| 1785 | |
| 1786 | int index = (Integer) v.getTag(); |
| 1787 | mAudioManager.setRingerMode(indexToRingerMode(index)); |
| 1788 | mHandler.sendEmptyMessageDelayed(MESSAGE_DISMISS, DIALOG_DISMISS_DELAY); |
| 1789 | } |
| 1790 | } |
| 1791 | |
| 1792 | private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 1793 | public void onReceive(Context context, Intent intent) { |
| 1794 | String action = intent.getAction(); |
| 1795 | if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action) |
| 1796 | || Intent.ACTION_SCREEN_OFF.equals(action)) { |
| 1797 | String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY); |
| 1798 | if (!SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS.equals(reason)) { |
Lucas Dupin | 1d4a579 | 2018-04-02 15:14:59 -0700 | [diff] [blame] | 1799 | mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_DISMISS, reason)); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1800 | } |
Jayachandran C | 142eae0 | 2019-12-13 19:29:20 -0800 | [diff] [blame] | 1801 | } else if (TelephonyManager.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED.equals(action)) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1802 | // Airplane mode can be changed after ECM exits if airplane toggle button |
| 1803 | // is pressed during ECM mode |
Daniel Bright | 4bcbfce | 2020-01-09 21:58:16 -0800 | [diff] [blame] | 1804 | if (!(intent.getBooleanExtra(TelephonyManager.EXTRA_PHONE_IN_ECM_STATE, false)) |
| 1805 | && mIsWaitingForEcmExit) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1806 | mIsWaitingForEcmExit = false; |
| 1807 | changeAirplaneModeSystemSetting(true); |
| 1808 | } |
| 1809 | } |
| 1810 | } |
| 1811 | }; |
| 1812 | |
| 1813 | PhoneStateListener mPhoneStateListener = new PhoneStateListener() { |
| 1814 | @Override |
| 1815 | public void onServiceStateChanged(ServiceState serviceState) { |
| 1816 | if (!mHasTelephony) return; |
| 1817 | final boolean inAirplaneMode = serviceState.getState() == ServiceState.STATE_POWER_OFF; |
Lucas Dupin | cb6726f | 2020-04-07 19:32:38 -0700 | [diff] [blame] | 1818 | mAirplaneState = inAirplaneMode ? ToggleState.On : ToggleState.Off; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1819 | mAirplaneModeOn.updateState(mAirplaneState); |
| 1820 | mAdapter.notifyDataSetChanged(); |
| 1821 | } |
| 1822 | }; |
| 1823 | |
Matt Pietal | 677981d | 2020-04-24 14:38:32 -0400 | [diff] [blame] | 1824 | private ContentObserver mAirplaneModeObserver = new ContentObserver(mMainHandler) { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1825 | @Override |
| 1826 | public void onChange(boolean selfChange) { |
| 1827 | onAirplaneModeChanged(); |
| 1828 | } |
| 1829 | }; |
| 1830 | |
| 1831 | private static final int MESSAGE_DISMISS = 0; |
| 1832 | private static final int MESSAGE_REFRESH = 1; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1833 | private static final int DIALOG_DISMISS_DELAY = 300; // ms |
Lucas Dupin | 7387a86 | 2020-04-13 10:15:29 -0700 | [diff] [blame] | 1834 | private static final int DIALOG_PRESS_DELAY = 850; // ms |
Chris Wren | af4ce846 | 2020-04-06 17:36:10 -0400 | [diff] [blame] | 1835 | |
| 1836 | @VisibleForTesting void setZeroDialogPressDelayForTesting() { |
| 1837 | mDialogPressDelay = 0; // ms |
| 1838 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1839 | |
| 1840 | private Handler mHandler = new Handler() { |
| 1841 | public void handleMessage(Message msg) { |
| 1842 | switch (msg.what) { |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1843 | case MESSAGE_DISMISS: |
| 1844 | if (mDialog != null) { |
Lucas Dupin | 1d4a579 | 2018-04-02 15:14:59 -0700 | [diff] [blame] | 1845 | if (SYSTEM_DIALOG_REASON_DREAM.equals(msg.obj)) { |
Matt Pietal | f4b870b | 2020-04-17 17:11:36 -0400 | [diff] [blame] | 1846 | mDialog.completeDismiss(); |
Lucas Dupin | 1d4a579 | 2018-04-02 15:14:59 -0700 | [diff] [blame] | 1847 | } else { |
| 1848 | mDialog.dismiss(); |
| 1849 | } |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1850 | mDialog = null; |
| 1851 | } |
| 1852 | break; |
| 1853 | case MESSAGE_REFRESH: |
| 1854 | refreshSilentMode(); |
| 1855 | mAdapter.notifyDataSetChanged(); |
| 1856 | break; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1857 | } |
| 1858 | } |
| 1859 | }; |
| 1860 | |
| 1861 | private void onAirplaneModeChanged() { |
| 1862 | // Let the service state callbacks handle the state. |
| 1863 | if (mHasTelephony) return; |
| 1864 | |
| 1865 | boolean airplaneModeOn = Settings.Global.getInt( |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 1866 | mContentResolver, |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1867 | Settings.Global.AIRPLANE_MODE_ON, |
| 1868 | 0) == 1; |
Lucas Dupin | cb6726f | 2020-04-07 19:32:38 -0700 | [diff] [blame] | 1869 | mAirplaneState = airplaneModeOn ? ToggleState.On : ToggleState.Off; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1870 | mAirplaneModeOn.updateState(mAirplaneState); |
| 1871 | } |
| 1872 | |
| 1873 | /** |
| 1874 | * Change the airplane mode system setting |
| 1875 | */ |
| 1876 | private void changeAirplaneModeSystemSetting(boolean on) { |
| 1877 | Settings.Global.putInt( |
Dave Mankoff | c88a2d7 | 2020-01-10 15:59:31 -0500 | [diff] [blame] | 1878 | mContentResolver, |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1879 | Settings.Global.AIRPLANE_MODE_ON, |
| 1880 | on ? 1 : 0); |
| 1881 | Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); |
| 1882 | intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); |
| 1883 | intent.putExtra("state", on); |
| 1884 | mContext.sendBroadcastAsUser(intent, UserHandle.ALL); |
| 1885 | if (!mHasTelephony) { |
Lucas Dupin | cb6726f | 2020-04-07 19:32:38 -0700 | [diff] [blame] | 1886 | mAirplaneState = on ? ToggleState.On : ToggleState.Off; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1887 | } |
| 1888 | } |
| 1889 | |
Fabian Kozynski | b6a2037 | 2020-04-01 09:36:43 -0400 | [diff] [blame] | 1890 | @NonNull |
| 1891 | @Override |
| 1892 | public Lifecycle getLifecycle() { |
| 1893 | return mLifecycle; |
| 1894 | } |
| 1895 | |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1896 | private static final class ActionsDialog extends Dialog implements DialogInterface, |
| 1897 | ColorExtractor.OnColorsChangedListener { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1898 | |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1899 | private final Context mContext; |
| 1900 | private final MyAdapter mAdapter; |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 1901 | private final MyOverflowAdapter mOverflowAdapter; |
Steve Elliott | 53f12ae | 2019-05-13 17:14:15 -0400 | [diff] [blame] | 1902 | private final IStatusBarService mStatusBarService; |
| 1903 | private final IBinder mToken = new Binder(); |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 1904 | private MultiListLayout mGlobalActionsLayout; |
Steve Elliott | e9e7e1f | 2019-03-18 15:54:59 -0400 | [diff] [blame] | 1905 | private Drawable mBackgroundDrawable; |
Lucas Dupin | 2bd3af6 | 2019-03-25 17:44:28 -0700 | [diff] [blame] | 1906 | private final SysuiColorExtractor mColorExtractor; |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 1907 | private final GlobalActionsPanelPlugin.PanelViewController mPanelController; |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1908 | private boolean mKeyguardShowing; |
Beverly | 526d2d6 | 2018-08-15 12:55:33 -0400 | [diff] [blame] | 1909 | private boolean mShowing; |
Steve Elliott | e9e7e1f | 2019-03-18 15:54:59 -0400 | [diff] [blame] | 1910 | private float mScrimAlpha; |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 1911 | private ResetOrientationData mResetOrientationData; |
Steve Elliott | ff2c0d9 | 2019-07-30 15:09:54 -0400 | [diff] [blame] | 1912 | private boolean mHadTopUi; |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 1913 | private final NotificationShadeWindowController mNotificationShadeWindowController; |
Santiago Etchebehere | 68eb53e | 2020-02-25 14:25:34 -0800 | [diff] [blame] | 1914 | private final NotificationShadeDepthController mDepthController; |
Lucas Dupin | 99f5fba | 2020-03-12 12:59:18 -0700 | [diff] [blame] | 1915 | private final BlurUtils mBlurUtils; |
Aran Ink | a65e6836 | 2020-04-14 15:23:24 -0400 | [diff] [blame] | 1916 | private final boolean mUseControlsLayout; |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 1917 | private ListPopupWindow mOverflowPopup; |
Aran Ink | a65e6836 | 2020-04-14 15:23:24 -0400 | [diff] [blame] | 1918 | private final Runnable mOnRotateCallback; |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 1919 | |
| 1920 | private ControlsUiController mControlsUiController; |
| 1921 | private ViewGroup mControlsView; |
Lucas Dupin | 5f9c863 | 2020-04-20 14:47:43 -0700 | [diff] [blame] | 1922 | private ViewGroup mContainer; |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1923 | |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 1924 | ActionsDialog(Context context, MyAdapter adapter, MyOverflowAdapter overflowAdapter, |
Santiago Etchebehere | 68eb53e | 2020-02-25 14:25:34 -0800 | [diff] [blame] | 1925 | GlobalActionsPanelPlugin.PanelViewController plugin, |
| 1926 | NotificationShadeDepthController depthController, |
Lucas Dupin | 991415e | 2019-11-25 17:48:58 -0800 | [diff] [blame] | 1927 | SysuiColorExtractor sysuiColorExtractor, IStatusBarService statusBarService, |
| 1928 | NotificationShadeWindowController notificationShadeWindowController, |
Aran Ink | a65e6836 | 2020-04-14 15:23:24 -0400 | [diff] [blame] | 1929 | ControlsUiController controlsUiController, BlurUtils blurUtils, |
Aran Ink | 99c452d | 2020-04-28 14:23:13 -0400 | [diff] [blame] | 1930 | boolean useControlsLayout, Runnable onRotateCallback, boolean keyguardShowing) { |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1931 | super(context, com.android.systemui.R.style.Theme_SystemUI_Dialog_GlobalActions); |
Lucas Dupin | 448786c | 2017-07-24 17:44:25 -0700 | [diff] [blame] | 1932 | mContext = context; |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 1933 | mAdapter = adapter; |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 1934 | mOverflowAdapter = overflowAdapter; |
Santiago Etchebehere | 68eb53e | 2020-02-25 14:25:34 -0800 | [diff] [blame] | 1935 | mDepthController = depthController; |
Lucas Dupin | 991415e | 2019-11-25 17:48:58 -0800 | [diff] [blame] | 1936 | mColorExtractor = sysuiColorExtractor; |
| 1937 | mStatusBarService = statusBarService; |
| 1938 | mNotificationShadeWindowController = notificationShadeWindowController; |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 1939 | mControlsUiController = controlsUiController; |
Lucas Dupin | 99f5fba | 2020-03-12 12:59:18 -0700 | [diff] [blame] | 1940 | mBlurUtils = blurUtils; |
Aran Ink | a65e6836 | 2020-04-14 15:23:24 -0400 | [diff] [blame] | 1941 | mUseControlsLayout = useControlsLayout; |
| 1942 | mOnRotateCallback = onRotateCallback; |
Aran Ink | 99c452d | 2020-04-28 14:23:13 -0400 | [diff] [blame] | 1943 | mKeyguardShowing = keyguardShowing; |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1944 | |
| 1945 | // Window initialization |
| 1946 | Window window = getWindow(); |
| 1947 | window.requestFeature(Window.FEATURE_NO_TITLE); |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 1948 | // Inflate the decor view, so the attributes below are not overwritten by the theme. |
| 1949 | window.getDecorView(); |
| 1950 | window.getAttributes().systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 1951 | | View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
| 1952 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
| 1953 | window.setLayout(MATCH_PARENT, MATCH_PARENT); |
| 1954 | window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
Alison Cichowlas | 4f19f4a | 2017-07-25 10:56:16 -0400 | [diff] [blame] | 1955 | window.addFlags( |
| 1956 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
Sean Pont | 9d4fb03 | 2020-03-04 18:54:32 -0800 | [diff] [blame] | 1957 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
| 1958 | | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR |
| 1959 | | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
| 1960 | | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
| 1961 | | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED); |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 1962 | window.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY); |
Tiger Huang | 5272444 | 2020-01-20 21:38:42 +0800 | [diff] [blame] | 1963 | window.getAttributes().setFitInsetsTypes(0 /* types */); |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 1964 | setTitle(R.string.global_actions); |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 1965 | |
| 1966 | mPanelController = plugin; |
Steve Elliott | e9e7e1f | 2019-03-18 15:54:59 -0400 | [diff] [blame] | 1967 | initializeLayout(); |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 1968 | } |
| 1969 | |
Matt Pietal | 677981d | 2020-04-24 14:38:32 -0400 | [diff] [blame] | 1970 | private boolean isShowingControls() { |
| 1971 | return mControlsUiController != null; |
| 1972 | } |
| 1973 | |
| 1974 | private void showControls(ControlsUiController controller) { |
| 1975 | mControlsUiController = controller; |
| 1976 | mControlsUiController.show(mControlsView, this::dismissForControlsActivity); |
| 1977 | } |
| 1978 | |
Aaron Heuckroth | c792661 | 2019-04-02 14:21:57 -0400 | [diff] [blame] | 1979 | private boolean shouldUsePanel() { |
Aran Ink | 3f59455 | 2019-05-13 14:29:35 -0400 | [diff] [blame] | 1980 | return mPanelController != null && mPanelController.getPanelContent() != null; |
Aaron Heuckroth | c792661 | 2019-04-02 14:21:57 -0400 | [diff] [blame] | 1981 | } |
| 1982 | |
| 1983 | private void initializePanel() { |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 1984 | int rotation = RotationUtils.getRotation(mContext); |
| 1985 | boolean rotationLocked = RotationPolicy.isRotationLocked(mContext); |
| 1986 | if (rotation != RotationUtils.ROTATION_NONE) { |
| 1987 | if (rotationLocked) { |
| 1988 | if (mResetOrientationData == null) { |
| 1989 | mResetOrientationData = new ResetOrientationData(); |
| 1990 | mResetOrientationData.locked = true; |
| 1991 | mResetOrientationData.rotation = rotation; |
| 1992 | } |
| 1993 | |
| 1994 | // Unlock rotation, so user can choose to rotate to portrait to see the panel. |
Steve Elliott | e05817f | 2019-05-17 14:39:53 -0400 | [diff] [blame] | 1995 | // This call is posted so that the rotation does not change until post-layout, |
| 1996 | // otherwise onConfigurationChanged() may not get invoked. |
| 1997 | mGlobalActionsLayout.post(() -> |
| 1998 | RotationPolicy.setRotationLockAtAngle( |
| 1999 | mContext, false, RotationUtils.ROTATION_NONE)); |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 2000 | } |
| 2001 | } else { |
| 2002 | if (!rotationLocked) { |
| 2003 | if (mResetOrientationData == null) { |
| 2004 | mResetOrientationData = new ResetOrientationData(); |
| 2005 | mResetOrientationData.locked = false; |
| 2006 | } |
| 2007 | |
| 2008 | // Lock to portrait, so the user doesn't accidentally hide the panel. |
Steve Elliott | e05817f | 2019-05-17 14:39:53 -0400 | [diff] [blame] | 2009 | // This call is posted so that the rotation does not change until post-layout, |
| 2010 | // otherwise onConfigurationChanged() may not get invoked. |
| 2011 | mGlobalActionsLayout.post(() -> |
| 2012 | RotationPolicy.setRotationLockAtAngle( |
| 2013 | mContext, true, RotationUtils.ROTATION_NONE)); |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 2014 | } |
| 2015 | |
Steve Elliott | 53f12ae | 2019-05-13 17:14:15 -0400 | [diff] [blame] | 2016 | // Disable rotation suggestions, if enabled |
| 2017 | setRotationSuggestionsEnabled(false); |
| 2018 | |
Steve Elliott | 300b48f | 2019-05-29 14:13:50 -0400 | [diff] [blame] | 2019 | FrameLayout panelContainer = |
| 2020 | findViewById(com.android.systemui.R.id.global_actions_panel_container); |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 2021 | FrameLayout.LayoutParams panelParams = |
| 2022 | new FrameLayout.LayoutParams( |
| 2023 | FrameLayout.LayoutParams.MATCH_PARENT, |
Steve Elliott | 300b48f | 2019-05-29 14:13:50 -0400 | [diff] [blame] | 2024 | FrameLayout.LayoutParams.MATCH_PARENT); |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 2025 | panelContainer.addView(mPanelController.getPanelContent(), panelParams); |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 2026 | } |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 2027 | } |
| 2028 | |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 2029 | private ListPopupWindow createPowerOverflowPopup() { |
Matt Pietal | f74554f | 2020-04-29 13:43:55 -0400 | [diff] [blame] | 2030 | ListPopupWindow popup = new GlobalActionsPopupMenu( |
| 2031 | mContext, false /* isDropDownMode */); |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 2032 | View overflowButton = |
| 2033 | findViewById(com.android.systemui.R.id.global_actions_overflow_button); |
| 2034 | popup.setAnchorView(overflowButton); |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 2035 | popup.setAdapter(mOverflowAdapter); |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 2036 | return popup; |
| 2037 | } |
| 2038 | |
| 2039 | private void showPowerOverflowMenu() { |
Matt Pietal | f74554f | 2020-04-29 13:43:55 -0400 | [diff] [blame] | 2040 | mOverflowPopup = createPowerOverflowPopup(); |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 2041 | mOverflowPopup.show(); |
| 2042 | } |
| 2043 | |
| 2044 | private void hidePowerOverflowMenu() { |
| 2045 | mOverflowPopup.dismiss(); |
Matt Pietal | f74554f | 2020-04-29 13:43:55 -0400 | [diff] [blame] | 2046 | mOverflowPopup = null; |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 2047 | } |
| 2048 | |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 2049 | private void initializeLayout() { |
| 2050 | setContentView(getGlobalActionsLayoutId(mContext)); |
Steve Elliott | 300b48f | 2019-05-29 14:13:50 -0400 | [diff] [blame] | 2051 | fixNavBarClipping(); |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 2052 | mControlsView = findViewById(com.android.systemui.R.id.global_actions_controls); |
Steve Elliott | e9e7e1f | 2019-03-18 15:54:59 -0400 | [diff] [blame] | 2053 | mGlobalActionsLayout = findViewById(com.android.systemui.R.id.global_actions_view); |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 2054 | mGlobalActionsLayout.setListViewAccessibilityDelegate(new View.AccessibilityDelegate() { |
Phil Weaver | 9054e09 | 2018-04-27 16:28:50 -0700 | [diff] [blame] | 2055 | @Override |
| 2056 | public boolean dispatchPopulateAccessibilityEvent( |
| 2057 | View host, AccessibilityEvent event) { |
| 2058 | // Populate the title here, just as Activity does |
| 2059 | event.getText().add(mContext.getString(R.string.global_actions)); |
| 2060 | return true; |
| 2061 | } |
| 2062 | }); |
Aaron Heuckroth | 4ea2fdb | 2019-02-14 16:28:35 -0500 | [diff] [blame] | 2063 | mGlobalActionsLayout.setRotationListener(this::onRotate); |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 2064 | mGlobalActionsLayout.setAdapter(mAdapter); |
Lucas Dupin | 5f9c863 | 2020-04-20 14:47:43 -0700 | [diff] [blame] | 2065 | mContainer = findViewById(com.android.systemui.R.id.global_actions_container); |
| 2066 | // Some legacy dialog layouts don't have the outer container |
| 2067 | if (mContainer == null) { |
| 2068 | mContainer = mGlobalActionsLayout; |
| 2069 | } |
Steve Elliott | e9e7e1f | 2019-03-18 15:54:59 -0400 | [diff] [blame] | 2070 | |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 2071 | View overflowButton = findViewById( |
| 2072 | com.android.systemui.R.id.global_actions_overflow_button); |
| 2073 | if (overflowButton != null) { |
Matt Pietal | 677981d | 2020-04-24 14:38:32 -0400 | [diff] [blame] | 2074 | if (mOverflowAdapter.getCount() > 0) { |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 2075 | overflowButton.setOnClickListener((view) -> showPowerOverflowMenu()); |
Aran Ink | 7c8fea9 | 2020-04-17 14:40:14 -0400 | [diff] [blame] | 2076 | LinearLayout.LayoutParams params = |
| 2077 | (LinearLayout.LayoutParams) mGlobalActionsLayout.getLayoutParams(); |
| 2078 | params.setMarginEnd(0); |
| 2079 | mGlobalActionsLayout.setLayoutParams(params); |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 2080 | } else { |
| 2081 | overflowButton.setVisibility(View.GONE); |
Aran Ink | 7c8fea9 | 2020-04-17 14:40:14 -0400 | [diff] [blame] | 2082 | LinearLayout.LayoutParams params = |
| 2083 | (LinearLayout.LayoutParams) mGlobalActionsLayout.getLayoutParams(); |
| 2084 | params.setMarginEnd(mContext.getResources().getDimensionPixelSize( |
| 2085 | com.android.systemui.R.dimen.global_actions_side_margin)); |
| 2086 | mGlobalActionsLayout.setLayoutParams(params); |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 2087 | } |
| 2088 | } |
| 2089 | |
Steve Elliott | 86ef628 | 2019-05-08 14:45:04 -0400 | [diff] [blame] | 2090 | if (shouldUsePanel()) { |
Steve Elliott | c59eb34 | 2019-04-23 16:59:06 -0400 | [diff] [blame] | 2091 | initializePanel(); |
Steve Elliott | e9e7e1f | 2019-03-18 15:54:59 -0400 | [diff] [blame] | 2092 | } |
Steve Elliott | 86ef628 | 2019-05-08 14:45:04 -0400 | [diff] [blame] | 2093 | if (mBackgroundDrawable == null) { |
| 2094 | mBackgroundDrawable = new ScrimDrawable(); |
Aran Ink | a65e6836 | 2020-04-14 15:23:24 -0400 | [diff] [blame] | 2095 | if (mUseControlsLayout) { |
Lucas Dupin | 3a8531e | 2020-04-06 17:18:09 -0700 | [diff] [blame] | 2096 | mScrimAlpha = 1.0f; |
| 2097 | } else { |
| 2098 | mScrimAlpha = mBlurUtils.supportsBlursOnWindows() |
| 2099 | ? ScrimController.BLUR_SCRIM_ALPHA : ScrimController.BUSY_SCRIM_ALPHA; |
| 2100 | } |
Steve Elliott | 86ef628 | 2019-05-08 14:45:04 -0400 | [diff] [blame] | 2101 | } |
Steve Elliott | e9e7e1f | 2019-03-18 15:54:59 -0400 | [diff] [blame] | 2102 | getWindow().setBackgroundDrawable(mBackgroundDrawable); |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 2103 | } |
| 2104 | |
Steve Elliott | 300b48f | 2019-05-29 14:13:50 -0400 | [diff] [blame] | 2105 | private void fixNavBarClipping() { |
| 2106 | ViewGroup content = findViewById(android.R.id.content); |
| 2107 | content.setClipChildren(false); |
| 2108 | content.setClipToPadding(false); |
| 2109 | ViewGroup contentParent = (ViewGroup) content.getParent(); |
| 2110 | contentParent.setClipChildren(false); |
| 2111 | contentParent.setClipToPadding(false); |
| 2112 | } |
| 2113 | |
Aaron Heuckroth | 166392f | 2019-01-17 16:50:59 -0500 | [diff] [blame] | 2114 | private int getGlobalActionsLayoutId(Context context) { |
Aran Ink | a65e6836 | 2020-04-14 15:23:24 -0400 | [diff] [blame] | 2115 | if (mUseControlsLayout) { |
Matt Pietal | fd3b6cb | 2020-01-08 09:43:54 -0500 | [diff] [blame] | 2116 | return com.android.systemui.R.layout.global_actions_grid_v2; |
| 2117 | } |
| 2118 | |
Steve Elliott | dc16563 | 2019-05-23 14:26:31 -0400 | [diff] [blame] | 2119 | int rotation = RotationUtils.getRotation(context); |
| 2120 | boolean useGridLayout = isForceGridEnabled(context) |
| 2121 | || (shouldUsePanel() && rotation == RotationUtils.ROTATION_NONE); |
| 2122 | if (rotation == RotationUtils.ROTATION_SEASCAPE) { |
Aaron Heuckroth | e2d92ac | 2019-05-01 10:44:59 -0400 | [diff] [blame] | 2123 | if (useGridLayout) { |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 2124 | return com.android.systemui.R.layout.global_actions_grid_seascape; |
Aaron Heuckroth | e2d92ac | 2019-05-01 10:44:59 -0400 | [diff] [blame] | 2125 | } else { |
| 2126 | return com.android.systemui.R.layout.global_actions_column_seascape; |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 2127 | } |
Aaron Heuckroth | e2d92ac | 2019-05-01 10:44:59 -0400 | [diff] [blame] | 2128 | } else { |
| 2129 | if (useGridLayout) { |
| 2130 | return com.android.systemui.R.layout.global_actions_grid; |
| 2131 | } else { |
| 2132 | return com.android.systemui.R.layout.global_actions_column; |
| 2133 | } |
Aaron Heuckroth | 166392f | 2019-01-17 16:50:59 -0500 | [diff] [blame] | 2134 | } |
Aaron Heuckroth | 166392f | 2019-01-17 16:50:59 -0500 | [diff] [blame] | 2135 | } |
| 2136 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 2137 | @Override |
| 2138 | protected void onStart() { |
| 2139 | super.setCanceledOnTouchOutside(true); |
| 2140 | super.onStart(); |
Aaron Heuckroth | 57d60d2 | 2019-03-05 14:00:12 -0500 | [diff] [blame] | 2141 | mGlobalActionsLayout.updateList(); |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 2142 | |
Lucas Dupin | 2bd3af6 | 2019-03-25 17:44:28 -0700 | [diff] [blame] | 2143 | if (mBackgroundDrawable instanceof ScrimDrawable) { |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 2144 | mColorExtractor.addOnColorsChangedListener(this); |
Lucas Dupin | 2bd3af6 | 2019-03-25 17:44:28 -0700 | [diff] [blame] | 2145 | GradientColors colors = mColorExtractor.getNeutralColors(); |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 2146 | updateColors(colors, false /* animate */); |
| 2147 | } |
Lucas Dupin | b5f59fe | 2017-09-14 17:09:39 -0700 | [diff] [blame] | 2148 | } |
| 2149 | |
| 2150 | /** |
| 2151 | * Updates background and system bars according to current GradientColors. |
Sean Pont | 9d4fb03 | 2020-03-04 18:54:32 -0800 | [diff] [blame] | 2152 | * |
| 2153 | * @param colors Colors and hints to use. |
Lucas Dupin | b5f59fe | 2017-09-14 17:09:39 -0700 | [diff] [blame] | 2154 | * @param animate Interpolates gradient if true, just sets otherwise. |
| 2155 | */ |
| 2156 | private void updateColors(GradientColors colors, boolean animate) { |
Lucas Dupin | 2bd3af6 | 2019-03-25 17:44:28 -0700 | [diff] [blame] | 2157 | if (!(mBackgroundDrawable instanceof ScrimDrawable)) { |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 2158 | return; |
| 2159 | } |
Lucas Dupin | 3a8531e | 2020-04-06 17:18:09 -0700 | [diff] [blame] | 2160 | ((ScrimDrawable) mBackgroundDrawable).setColor( |
Aran Ink | a65e6836 | 2020-04-14 15:23:24 -0400 | [diff] [blame] | 2161 | !mUseControlsLayout && colors.supportsDarkText() |
| 2162 | ? Color.WHITE : Color.BLACK, animate); |
Lucas Dupin | b5f59fe | 2017-09-14 17:09:39 -0700 | [diff] [blame] | 2163 | View decorView = getWindow().getDecorView(); |
| 2164 | if (colors.supportsDarkText()) { |
| 2165 | decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR | |
Steve Elliott | 9b87a44 | 2019-03-05 10:24:16 -0500 | [diff] [blame] | 2166 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); |
Lucas Dupin | b5f59fe | 2017-09-14 17:09:39 -0700 | [diff] [blame] | 2167 | } else { |
| 2168 | decorView.setSystemUiVisibility(0); |
| 2169 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 2170 | } |
| 2171 | |
| 2172 | @Override |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 2173 | protected void onStop() { |
| 2174 | super.onStop(); |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 2175 | mColorExtractor.removeOnColorsChangedListener(this); |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 2176 | } |
| 2177 | |
| 2178 | @Override |
| 2179 | public void show() { |
| 2180 | super.show(); |
Beverly | 526d2d6 | 2018-08-15 12:55:33 -0400 | [diff] [blame] | 2181 | mShowing = true; |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 2182 | mHadTopUi = mNotificationShadeWindowController.getForceHasTopUi(); |
| 2183 | mNotificationShadeWindowController.setForceHasTopUi(true); |
Matt Pietal | e9440b7 | 2020-05-01 11:36:01 -0400 | [diff] [blame] | 2184 | |
Lucas Dupin | 26571e9 | 2020-04-08 14:55:10 -0700 | [diff] [blame] | 2185 | ViewGroup root = (ViewGroup) mGlobalActionsLayout.getRootView(); |
| 2186 | root.setOnApplyWindowInsetsListener((v, windowInsets) -> { |
Aran Ink | a65e6836 | 2020-04-14 15:23:24 -0400 | [diff] [blame] | 2187 | if (mUseControlsLayout) { |
Lucas Dupin | 2b353e6 | 2020-04-14 18:23:01 -0700 | [diff] [blame] | 2188 | root.setPadding(windowInsets.getStableInsetLeft(), |
| 2189 | windowInsets.getStableInsetTop(), |
| 2190 | windowInsets.getStableInsetRight(), |
| 2191 | windowInsets.getStableInsetBottom()); |
Lucas Dupin | 26571e9 | 2020-04-08 14:55:10 -0700 | [diff] [blame] | 2192 | } |
| 2193 | return WindowInsets.CONSUMED; |
| 2194 | }); |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 2195 | if (mControlsUiController != null) { |
Matt Pietal | f4b870b | 2020-04-17 17:11:36 -0400 | [diff] [blame] | 2196 | mControlsUiController.show(mControlsView, this::dismissForControlsActivity); |
Matt Pietal | 2223179 | 2020-01-23 09:51:09 -0500 | [diff] [blame] | 2197 | } |
Matt Pietal | e9440b7 | 2020-05-01 11:36:01 -0400 | [diff] [blame] | 2198 | |
| 2199 | mBackgroundDrawable.setAlpha(0); |
| 2200 | float xOffset = mGlobalActionsLayout.getAnimationOffsetX(); |
| 2201 | ObjectAnimator alphaAnimator = |
| 2202 | ObjectAnimator.ofFloat(mContainer, "transitionAlpha", 0f, 1f); |
| 2203 | alphaAnimator.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN); |
| 2204 | alphaAnimator.setDuration(183); |
| 2205 | alphaAnimator.addUpdateListener((animation) -> { |
| 2206 | float animatedValue = animation.getAnimatedFraction(); |
| 2207 | int alpha = (int) (animatedValue * mScrimAlpha * 255); |
| 2208 | mBackgroundDrawable.setAlpha(alpha); |
| 2209 | mDepthController.updateGlobalDialogVisibility(animatedValue, |
| 2210 | mGlobalActionsLayout); |
| 2211 | }); |
| 2212 | |
| 2213 | ObjectAnimator xAnimator = |
| 2214 | ObjectAnimator.ofFloat(mContainer, "translationX", xOffset, 0f); |
| 2215 | alphaAnimator.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN); |
| 2216 | alphaAnimator.setDuration(350); |
| 2217 | |
| 2218 | AnimatorSet animatorSet = new AnimatorSet(); |
| 2219 | animatorSet.playTogether(alphaAnimator, xAnimator); |
| 2220 | animatorSet.start(); |
Jason Monk | 16fbd9d | 2017-04-27 14:28:49 -0400 | [diff] [blame] | 2221 | } |
| 2222 | |
| 2223 | @Override |
| 2224 | public void dismiss() { |
Matt Pietal | f4b870b | 2020-04-17 17:11:36 -0400 | [diff] [blame] | 2225 | dismissWithAnimation(() -> { |
Lucas Dupin | 5f9c863 | 2020-04-20 14:47:43 -0700 | [diff] [blame] | 2226 | mContainer.setTranslationX(0); |
Matt Pietal | e9440b7 | 2020-05-01 11:36:01 -0400 | [diff] [blame] | 2227 | ObjectAnimator alphaAnimator = |
| 2228 | ObjectAnimator.ofFloat(mContainer, "transitionAlpha", 1f, 0f); |
| 2229 | alphaAnimator.setInterpolator(Interpolators.FAST_OUT_LINEAR_IN); |
| 2230 | alphaAnimator.setDuration(233); |
| 2231 | alphaAnimator.addUpdateListener((animation) -> { |
| 2232 | float animatedValue = 1f - animation.getAnimatedFraction(); |
| 2233 | int alpha = (int) (animatedValue * mScrimAlpha * 255); |
| 2234 | mBackgroundDrawable.setAlpha(alpha); |
| 2235 | mDepthController.updateGlobalDialogVisibility(animatedValue, |
| 2236 | mGlobalActionsLayout); |
| 2237 | }); |
| 2238 | |
| 2239 | float xOffset = mGlobalActionsLayout.getAnimationOffsetX(); |
| 2240 | ObjectAnimator xAnimator = |
| 2241 | ObjectAnimator.ofFloat(mContainer, "translationX", 0f, xOffset); |
| 2242 | alphaAnimator.setInterpolator(Interpolators.FAST_OUT_LINEAR_IN); |
| 2243 | alphaAnimator.setDuration(350); |
| 2244 | |
| 2245 | AnimatorSet animatorSet = new AnimatorSet(); |
| 2246 | animatorSet.playTogether(alphaAnimator, xAnimator); |
| 2247 | animatorSet.addListener(new AnimatorListenerAdapter() { |
| 2248 | public void onAnimationEnd(Animator animation) { |
| 2249 | completeDismiss(); |
| 2250 | } |
| 2251 | }); |
| 2252 | |
| 2253 | animatorSet.start(); |
| 2254 | |
| 2255 | // close first, as popup windows will not fade during the animation |
| 2256 | dismissOverflow(false); |
| 2257 | if (mControlsUiController != null) mControlsUiController.closeDialogs(false); |
Matt Pietal | f4b870b | 2020-04-17 17:11:36 -0400 | [diff] [blame] | 2258 | }); |
| 2259 | } |
| 2260 | |
| 2261 | private void dismissForControlsActivity() { |
| 2262 | dismissWithAnimation(() -> { |
Matt Pietal | d8a6ca6 | 2020-04-21 15:00:15 -0400 | [diff] [blame] | 2263 | ViewGroup root = (ViewGroup) mGlobalActionsLayout.getParent(); |
Matt Pietal | f4b870b | 2020-04-17 17:11:36 -0400 | [diff] [blame] | 2264 | ControlsAnimations.exitAnimation(root, this::completeDismiss).start(); |
| 2265 | }); |
| 2266 | } |
| 2267 | |
| 2268 | void dismissWithAnimation(Runnable animation) { |
Beverly | 526d2d6 | 2018-08-15 12:55:33 -0400 | [diff] [blame] | 2269 | if (!mShowing) { |
| 2270 | return; |
| 2271 | } |
| 2272 | mShowing = false; |
Matt Pietal | f4b870b | 2020-04-17 17:11:36 -0400 | [diff] [blame] | 2273 | animation.run(); |
Steve Elliott | ff2c0d9 | 2019-07-30 15:09:54 -0400 | [diff] [blame] | 2274 | } |
| 2275 | |
| 2276 | private void completeDismiss() { |
Matt Pietal | f4b870b | 2020-04-17 17:11:36 -0400 | [diff] [blame] | 2277 | mShowing = false; |
| 2278 | resetOrientation(); |
| 2279 | dismissPanel(); |
Aran Ink | d397b90 | 2020-04-21 17:53:41 -0400 | [diff] [blame] | 2280 | dismissOverflow(true); |
Matt Pietal | f4b870b | 2020-04-17 17:11:36 -0400 | [diff] [blame] | 2281 | if (mControlsUiController != null) mControlsUiController.hide(); |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 2282 | mNotificationShadeWindowController.setForceHasTopUi(mHadTopUi); |
Lucas Dupin | 7719856 | 2020-03-31 14:16:16 -0700 | [diff] [blame] | 2283 | mDepthController.updateGlobalDialogVisibility(0, null /* view */); |
Steve Elliott | ff2c0d9 | 2019-07-30 15:09:54 -0400 | [diff] [blame] | 2284 | super.dismiss(); |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 2285 | } |
| 2286 | |
| 2287 | private void dismissPanel() { |
Steve Elliott | 2d206d3 | 2019-03-14 16:30:33 -0400 | [diff] [blame] | 2288 | if (mPanelController != null) { |
| 2289 | mPanelController.onDismissed(); |
| 2290 | } |
Lucas Dupin | 1d4a579 | 2018-04-02 15:14:59 -0700 | [diff] [blame] | 2291 | } |
| 2292 | |
Aran Ink | d397b90 | 2020-04-21 17:53:41 -0400 | [diff] [blame] | 2293 | private void dismissOverflow(boolean immediate) { |
Aran Ink | 6560ab7 | 2020-04-20 16:04:29 -0400 | [diff] [blame] | 2294 | if (mOverflowPopup != null) { |
Aran Ink | d397b90 | 2020-04-21 17:53:41 -0400 | [diff] [blame] | 2295 | if (immediate) { |
| 2296 | mOverflowPopup.dismissImmediate(); |
| 2297 | } else { |
| 2298 | mOverflowPopup.dismiss(); |
| 2299 | } |
Aran Ink | 6560ab7 | 2020-04-20 16:04:29 -0400 | [diff] [blame] | 2300 | } |
| 2301 | } |
| 2302 | |
Steve Elliott | 53f12ae | 2019-05-13 17:14:15 -0400 | [diff] [blame] | 2303 | private void setRotationSuggestionsEnabled(boolean enabled) { |
| 2304 | try { |
| 2305 | final int userId = Binder.getCallingUserHandle().getIdentifier(); |
| 2306 | final int what = enabled |
| 2307 | ? StatusBarManager.DISABLE2_NONE |
| 2308 | : StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS; |
| 2309 | mStatusBarService.disable2ForUser(what, mToken, mContext.getPackageName(), userId); |
| 2310 | } catch (RemoteException ex) { |
| 2311 | throw ex.rethrowFromSystemServer(); |
| 2312 | } |
| 2313 | } |
| 2314 | |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 2315 | private void resetOrientation() { |
| 2316 | if (mResetOrientationData != null) { |
| 2317 | RotationPolicy.setRotationLockAtAngle(mContext, mResetOrientationData.locked, |
| 2318 | mResetOrientationData.rotation); |
| 2319 | } |
Steve Elliott | 53f12ae | 2019-05-13 17:14:15 -0400 | [diff] [blame] | 2320 | setRotationSuggestionsEnabled(true); |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 2321 | } |
| 2322 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 2323 | @Override |
Lucas Dupin | 7aaa353 | 2017-05-28 08:51:07 -0700 | [diff] [blame] | 2324 | public void onColorsChanged(ColorExtractor extractor, int which) { |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 2325 | if (mKeyguardShowing) { |
| 2326 | if ((WallpaperManager.FLAG_LOCK & which) != 0) { |
Lucas Dupin | b5f59fe | 2017-09-14 17:09:39 -0700 | [diff] [blame] | 2327 | updateColors(extractor.getColors(WallpaperManager.FLAG_LOCK), |
| 2328 | true /* animate */); |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 2329 | } |
| 2330 | } else { |
| 2331 | if ((WallpaperManager.FLAG_SYSTEM & which) != 0) { |
Lucas Dupin | b5f59fe | 2017-09-14 17:09:39 -0700 | [diff] [blame] | 2332 | updateColors(extractor.getColors(WallpaperManager.FLAG_SYSTEM), |
| 2333 | true /* animate */); |
Lucas Dupin | c1cc759 | 2017-05-22 15:56:16 -0700 | [diff] [blame] | 2334 | } |
| 2335 | } |
| 2336 | } |
| 2337 | |
| 2338 | public void setKeyguardShowing(boolean keyguardShowing) { |
| 2339 | mKeyguardShowing = keyguardShowing; |
| 2340 | } |
Aaron Heuckroth | 4ea2fdb | 2019-02-14 16:28:35 -0500 | [diff] [blame] | 2341 | |
Aaron Heuckroth | 4ef3a54 | 2019-04-01 14:17:23 -0400 | [diff] [blame] | 2342 | public void refreshDialog() { |
| 2343 | initializeLayout(); |
| 2344 | mGlobalActionsLayout.updateList(); |
Aran Ink | a65e6836 | 2020-04-14 15:23:24 -0400 | [diff] [blame] | 2345 | if (mControlsUiController != null) { |
Matt Pietal | f4b870b | 2020-04-17 17:11:36 -0400 | [diff] [blame] | 2346 | mControlsUiController.show(mControlsView, this::dismissForControlsActivity); |
Aran Ink | a65e6836 | 2020-04-14 15:23:24 -0400 | [diff] [blame] | 2347 | } |
Aaron Heuckroth | 4ef3a54 | 2019-04-01 14:17:23 -0400 | [diff] [blame] | 2348 | } |
| 2349 | |
Aaron Heuckroth | 4ea2fdb | 2019-02-14 16:28:35 -0500 | [diff] [blame] | 2350 | public void onRotate(int from, int to) { |
Aaron Heuckroth | e2d92ac | 2019-05-01 10:44:59 -0400 | [diff] [blame] | 2351 | if (mShowing) { |
Aran Ink | a65e6836 | 2020-04-14 15:23:24 -0400 | [diff] [blame] | 2352 | mOnRotateCallback.run(); |
Aaron Heuckroth | 4ef3a54 | 2019-04-01 14:17:23 -0400 | [diff] [blame] | 2353 | refreshDialog(); |
Aaron Heuckroth | 4ea2fdb | 2019-02-14 16:28:35 -0500 | [diff] [blame] | 2354 | } |
| 2355 | } |
Steve Elliott | 48f75db | 2019-05-03 15:03:38 -0400 | [diff] [blame] | 2356 | |
| 2357 | private static class ResetOrientationData { |
| 2358 | public boolean locked; |
| 2359 | public int rotation; |
| 2360 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 2361 | } |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 2362 | |
| 2363 | /** |
Aran Ink | 93dd25c | 2019-05-09 14:42:14 -0400 | [diff] [blame] | 2364 | * Determines whether or not debug mode has been activated for the Global Actions Panel. |
| 2365 | */ |
| 2366 | private static boolean isPanelDebugModeEnabled(Context context) { |
| 2367 | return Settings.Secure.getInt(context.getContentResolver(), |
| 2368 | Settings.Secure.GLOBAL_ACTIONS_PANEL_DEBUG_ENABLED, 0) == 1; |
| 2369 | } |
| 2370 | |
| 2371 | /** |
Sean Pont | 9d4fb03 | 2020-03-04 18:54:32 -0800 | [diff] [blame] | 2372 | * Determines whether or not the Global Actions menu should be forced to use the newer |
| 2373 | * grid-style layout. |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 2374 | */ |
Aaron Heuckroth | c792661 | 2019-04-02 14:21:57 -0400 | [diff] [blame] | 2375 | private static boolean isForceGridEnabled(Context context) { |
Aran Ink | 93dd25c | 2019-05-09 14:42:14 -0400 | [diff] [blame] | 2376 | return isPanelDebugModeEnabled(context); |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 2377 | } |
Aaron Heuckroth | f19d272 | 2019-03-11 17:06:02 -0400 | [diff] [blame] | 2378 | |
Aran Ink | cf03827 | 2020-03-31 17:48:37 -0400 | [diff] [blame] | 2379 | @VisibleForTesting |
| 2380 | protected boolean shouldShowControls() { |
Matt Pietal | 677981d | 2020-04-24 14:38:32 -0400 | [diff] [blame] | 2381 | boolean isUnlocked = mKeyguardStateController.isUnlocked() |
| 2382 | || mKeyguardStateController.canDismissLockScreen(); |
| 2383 | return (isUnlocked || mShowLockScreenCardsAndControls) |
Fabian Kozynski | 0424ab1 | 2020-02-21 12:09:17 -0500 | [diff] [blame] | 2384 | && mControlsUiController.getAvailable() |
Matt Pietal | cd757c8 | 2020-04-08 10:20:48 -0400 | [diff] [blame] | 2385 | && !mControlsServiceInfos.isEmpty(); |
Matt Pietal | fd3b6cb | 2020-01-08 09:43:54 -0500 | [diff] [blame] | 2386 | } |
Aran Ink | a65e6836 | 2020-04-14 15:23:24 -0400 | [diff] [blame] | 2387 | // TODO: Remove legacy layout XML and classes. |
| 2388 | protected boolean shouldUseControlsLayout() { |
| 2389 | // always use new controls layout |
| 2390 | return true; |
| 2391 | } |
Matt Pietal | 677981d | 2020-04-24 14:38:32 -0400 | [diff] [blame] | 2392 | |
| 2393 | private void onPowerMenuLockScreenSettingsChanged() { |
| 2394 | mShowLockScreenCardsAndControls = Settings.Secure.getInt(mContentResolver, |
| 2395 | Settings.Secure.POWER_MENU_LOCKED_SHOW_CONTENT, 0) != 0; |
| 2396 | } |
Matt Pietal | f4b870b | 2020-04-17 17:11:36 -0400 | [diff] [blame] | 2397 | } |