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