blob: 608e3038e7cab257fd6aba36a23afd93f220b524 [file] [log] [blame]
Jason Monk361915c2017-03-21 20:33:59 -04001/*
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
15package com.android.systemui.globalactions;
16
Adrian Roosedfab3b2018-03-08 18:39:20 +010017import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
Adrian Roos2f05bb32018-02-19 16:42:27 +010018import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
19
Chad Brubakerf4075fe2018-01-03 13:23:22 -080020import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_USER_REQUEST;
21import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_NOT_REQUIRED;
Chad Brubaker4f28f0d2017-09-07 14:28:13 -070022import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN;
23
Jason Monk361915c2017-03-21 20:33:59 -040024import android.app.ActivityManager;
25import android.app.Dialog;
Chad Brubakerf4075fe2018-01-03 13:23:22 -080026import android.app.KeyguardManager;
Lucas Dupinc1cc7592017-05-22 15:56:16 -070027import android.app.WallpaperManager;
Alex Chau04458852017-11-27 18:21:23 +000028import android.app.admin.DevicePolicyManager;
Pavel Grafov059021b2018-05-02 13:44:46 +010029import android.app.trust.TrustManager;
Jason Monk361915c2017-03-21 20:33:59 -040030import android.content.BroadcastReceiver;
31import android.content.Context;
32import android.content.DialogInterface;
33import android.content.Intent;
34import android.content.IntentFilter;
35import android.content.pm.UserInfo;
36import android.database.ContentObserver;
Lucas Dupinc1cc7592017-05-22 15:56:16 -070037import android.graphics.Point;
Jason Monk361915c2017-03-21 20:33:59 -040038import android.graphics.drawable.Drawable;
39import android.media.AudioManager;
40import android.net.ConnectivityManager;
41import android.os.Build;
Jason Monk361915c2017-03-21 20:33:59 -040042import android.os.Handler;
43import android.os.Message;
44import android.os.RemoteException;
45import android.os.ServiceManager;
46import android.os.SystemProperties;
47import android.os.UserHandle;
48import android.os.UserManager;
49import android.os.Vibrator;
50import android.provider.Settings;
51import android.service.dreams.DreamService;
52import android.service.dreams.IDreamManager;
53import android.telephony.PhoneStateListener;
54import android.telephony.ServiceState;
55import android.telephony.TelephonyManager;
56import android.text.TextUtils;
57import android.util.ArraySet;
yuanjiahsu88363e92018-09-06 19:23:52 +080058import android.util.FeatureFlagUtils;
Jason Monk361915c2017-03-21 20:33:59 -040059import android.util.Log;
Lucas Dupin448786c2017-07-24 17:44:25 -070060import android.view.ContextThemeWrapper;
Jason Monk361915c2017-03-21 20:33:59 -040061import android.view.LayoutInflater;
62import android.view.View;
63import android.view.ViewGroup;
Lucas Dupinc1cc7592017-05-22 15:56:16 -070064import android.view.Window;
Jason Monk361915c2017-03-21 20:33:59 -040065import android.view.WindowManager;
66import android.view.WindowManagerGlobal;
67import android.view.accessibility.AccessibilityEvent;
Jason Monk16fbd9d2017-04-27 14:28:49 -040068import android.widget.AdapterView.OnItemLongClickListener;
Jason Monk361915c2017-03-21 20:33:59 -040069import android.widget.BaseAdapter;
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +080070import android.widget.FrameLayout;
Jason Monk361915c2017-03-21 20:33:59 -040071import android.widget.ImageView;
72import android.widget.ImageView.ScaleType;
Jason Monk16fbd9d2017-04-27 14:28:49 -040073import android.widget.LinearLayout;
Jason Monk361915c2017-03-21 20:33:59 -040074import android.widget.TextView;
75
Charles He9851a8d2017-10-10 17:31:30 +010076import com.android.internal.R;
77import com.android.internal.colorextraction.ColorExtractor;
78import com.android.internal.colorextraction.ColorExtractor.GradientColors;
Lucas Dupine2292a92017-07-06 14:35:30 -070079import com.android.internal.colorextraction.drawable.GradientDrawable;
Charles He9851a8d2017-10-10 17:31:30 +010080import com.android.internal.logging.MetricsLogger;
81import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
82import com.android.internal.telephony.TelephonyIntents;
83import com.android.internal.telephony.TelephonyProperties;
84import com.android.internal.util.EmergencyAffordanceManager;
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -050085import com.android.internal.util.ScreenshotHelper;
Charles He9851a8d2017-10-10 17:31:30 +010086import com.android.internal.widget.LockPatternUtils;
87import com.android.systemui.Dependency;
88import com.android.systemui.HardwareUiLayout;
89import com.android.systemui.Interpolators;
90import com.android.systemui.colorextraction.SysuiColorExtractor;
91import com.android.systemui.plugins.GlobalActions.GlobalActionsManager;
92import com.android.systemui.statusbar.phone.ScrimController;
Lucas Dupine5b7dc72018-10-02 15:18:05 -070093import com.android.systemui.statusbar.policy.ConfigurationController;
Shaotang Li5c422632018-07-04 14:18:40 +080094import com.android.systemui.util.EmergencyDialerConstants;
Julia Reynolds42411922017-11-08 11:19:09 -050095import com.android.systemui.volume.SystemUIInterpolators.LogAccelerateInterpolator;
Lucas Dupinc1cc7592017-05-22 15:56:16 -070096
Jason Monk361915c2017-03-21 20:33:59 -040097import java.util.ArrayList;
98import java.util.List;
99
100/**
101 * Helper to show the global actions dialog. Each item is an {@link Action} that
102 * may show depending on whether the keyguard is showing, and whether the device
103 * is provisioned.
104 */
Charles He9851a8d2017-10-10 17:31:30 +0100105class GlobalActionsDialog implements DialogInterface.OnDismissListener,
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700106 DialogInterface.OnClickListener, DialogInterface.OnShowListener,
107 ConfigurationController.ConfigurationListener {
Jason Monk361915c2017-03-21 20:33:59 -0400108
109 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
110 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
Lucas Dupin1d4a5792018-04-02 15:14:59 -0700111 static public final String SYSTEM_DIALOG_REASON_DREAM = "dream";
Jason Monk361915c2017-03-21 20:33:59 -0400112
113 private static final String TAG = "GlobalActionsDialog";
114
115 private static final boolean SHOW_SILENT_TOGGLE = true;
116
117 /* Valid settings for global actions keys.
118 * see config.xml config_globalActionList */
119 private static final String GLOBAL_ACTION_KEY_POWER = "power";
120 private static final String GLOBAL_ACTION_KEY_AIRPLANE = "airplane";
121 private static final String GLOBAL_ACTION_KEY_BUGREPORT = "bugreport";
122 private static final String GLOBAL_ACTION_KEY_SILENT = "silent";
123 private static final String GLOBAL_ACTION_KEY_USERS = "users";
124 private static final String GLOBAL_ACTION_KEY_SETTINGS = "settings";
125 private static final String GLOBAL_ACTION_KEY_LOCKDOWN = "lockdown";
126 private static final String GLOBAL_ACTION_KEY_VOICEASSIST = "voiceassist";
127 private static final String GLOBAL_ACTION_KEY_ASSIST = "assist";
128 private static final String GLOBAL_ACTION_KEY_RESTART = "restart";
Alex Chau04458852017-11-27 18:21:23 +0000129 private static final String GLOBAL_ACTION_KEY_LOGOUT = "logout";
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800130 private static final String GLOBAL_ACTION_KEY_EMERGENCY = "emergency";
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500131 private static final String GLOBAL_ACTION_KEY_SCREENSHOT = "screenshot";
Jason Monk361915c2017-03-21 20:33:59 -0400132
133 private final Context mContext;
134 private final GlobalActionsManager mWindowManagerFuncs;
135 private final AudioManager mAudioManager;
136 private final IDreamManager mDreamManager;
Alex Chau04458852017-11-27 18:21:23 +0000137 private final DevicePolicyManager mDevicePolicyManager;
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800138 private final LockPatternUtils mLockPatternUtils;
139 private final KeyguardManager mKeyguardManager;
Jason Monk361915c2017-03-21 20:33:59 -0400140
141 private ArrayList<Action> mItems;
142 private ActionsDialog mDialog;
143
144 private Action mSilentModeAction;
145 private ToggleAction mAirplaneModeOn;
146
147 private MyAdapter mAdapter;
148
149 private boolean mKeyguardShowing = false;
150 private boolean mDeviceProvisioned = false;
151 private ToggleAction.State mAirplaneState = ToggleAction.State.Off;
152 private boolean mIsWaitingForEcmExit = false;
153 private boolean mHasTelephony;
154 private boolean mHasVibrator;
Alex Chau04458852017-11-27 18:21:23 +0000155 private boolean mHasLogoutButton;
Chad Brubaker72a73ea2018-01-26 15:56:55 -0800156 private boolean mHasLockdownButton;
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800157 private boolean mSeparatedEmergencyButtonEnabled;
Jason Monk361915c2017-03-21 20:33:59 -0400158 private final boolean mShowSilentToggle;
159 private final EmergencyAffordanceManager mEmergencyAffordanceManager;
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500160 private final ScreenshotHelper mScreenshotHelper;
Jason Monk361915c2017-03-21 20:33:59 -0400161
162 /**
163 * @param context everything needs a context :(
164 */
165 public GlobalActionsDialog(Context context, GlobalActionsManager windowManagerFuncs) {
Lucas Dupin448786c2017-07-24 17:44:25 -0700166 mContext = new ContextThemeWrapper(context, com.android.systemui.R.style.qs_theme);
Jason Monk361915c2017-03-21 20:33:59 -0400167 mWindowManagerFuncs = windowManagerFuncs;
168 mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
169 mDreamManager = IDreamManager.Stub.asInterface(
170 ServiceManager.getService(DreamService.DREAM_SERVICE));
Alex Chau04458852017-11-27 18:21:23 +0000171 mDevicePolicyManager = (DevicePolicyManager) mContext.getSystemService(
172 Context.DEVICE_POLICY_SERVICE);
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800173 mLockPatternUtils = new LockPatternUtils(mContext);
174 mKeyguardManager = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
Jason Monk361915c2017-03-21 20:33:59 -0400175
176 // receive broadcasts
177 IntentFilter filter = new IntentFilter();
178 filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
179 filter.addAction(Intent.ACTION_SCREEN_OFF);
180 filter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
181 context.registerReceiver(mBroadcastReceiver, filter);
182
183 ConnectivityManager cm = (ConnectivityManager)
184 context.getSystemService(Context.CONNECTIVITY_SERVICE);
185 mHasTelephony = cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE);
186
187 // get notified of phone state changes
188 TelephonyManager telephonyManager =
189 (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
190 telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
191 mContext.getContentResolver().registerContentObserver(
192 Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON), true,
193 mAirplaneModeObserver);
194 Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
195 mHasVibrator = vibrator != null && vibrator.hasVibrator();
196
197 mShowSilentToggle = SHOW_SILENT_TOGGLE && !mContext.getResources().getBoolean(
198 R.bool.config_useFixedVolume);
199
200 mEmergencyAffordanceManager = new EmergencyAffordanceManager(context);
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500201 mScreenshotHelper = new ScreenshotHelper(context);
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700202
203 Dependency.get(ConfigurationController.class).addCallback(this);
Jason Monk361915c2017-03-21 20:33:59 -0400204 }
205
206 /**
207 * Show the global actions dialog (creating if necessary)
Jason Monk16fbd9d2017-04-27 14:28:49 -0400208 *
Jason Monk361915c2017-03-21 20:33:59 -0400209 * @param keyguardShowing True if keyguard is showing
210 */
211 public void showDialog(boolean keyguardShowing, boolean isDeviceProvisioned) {
212 mKeyguardShowing = keyguardShowing;
213 mDeviceProvisioned = isDeviceProvisioned;
214 if (mDialog != null) {
215 mDialog.dismiss();
216 mDialog = null;
217 // Show delayed, so that the dismiss of the previous dialog completes
218 mHandler.sendEmptyMessage(MESSAGE_SHOW);
219 } else {
220 handleShow();
221 }
222 }
223
Charles He9851a8d2017-10-10 17:31:30 +0100224 /**
225 * Dismiss the global actions dialog, if it's currently shown
226 */
227 public void dismissDialog() {
228 mHandler.removeMessages(MESSAGE_DISMISS);
229 mHandler.sendEmptyMessage(MESSAGE_DISMISS);
230 }
231
Jason Monk361915c2017-03-21 20:33:59 -0400232 private void awakenIfNecessary() {
233 if (mDreamManager != null) {
234 try {
235 if (mDreamManager.isDreaming()) {
236 mDreamManager.awaken();
237 }
238 } catch (RemoteException e) {
239 // we tried
240 }
241 }
242 }
243
244 private void handleShow() {
245 awakenIfNecessary();
246 mDialog = createDialog();
247 prepareDialog();
248
249 // If we only have 1 item and it's a simple press action, just do this action.
250 if (mAdapter.getCount() == 1
251 && mAdapter.getItem(0) instanceof SinglePressAction
252 && !(mAdapter.getItem(0) instanceof LongPressAction)) {
253 ((SinglePressAction) mAdapter.getItem(0)).onPress();
254 } else {
255 WindowManager.LayoutParams attrs = mDialog.getWindow().getAttributes();
256 attrs.setTitle("ActionsDialog");
Adrian Roos2f05bb32018-02-19 16:42:27 +0100257 attrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
Jason Monk361915c2017-03-21 20:33:59 -0400258 mDialog.getWindow().setAttributes(attrs);
259 mDialog.show();
260 mWindowManagerFuncs.onGlobalActionsShown();
Jason Monk361915c2017-03-21 20:33:59 -0400261 }
262 }
263
264 /**
265 * Create the global actions dialog.
Jason Monk16fbd9d2017-04-27 14:28:49 -0400266 *
Jason Monk361915c2017-03-21 20:33:59 -0400267 * @return A new dialog.
268 */
269 private ActionsDialog createDialog() {
270 // Simple toggle style if there's no vibrator, otherwise use a tri-state
271 if (!mHasVibrator) {
272 mSilentModeAction = new SilentModeToggleAction();
273 } else {
Lucas Dupin40ec6b782018-06-05 19:07:16 -0700274 mSilentModeAction = new SilentModeTriStateAction(mAudioManager, mHandler);
Jason Monk361915c2017-03-21 20:33:59 -0400275 }
276 mAirplaneModeOn = new ToggleAction(
277 R.drawable.ic_lock_airplane_mode,
278 R.drawable.ic_lock_airplane_mode_off,
279 R.string.global_actions_toggle_airplane_mode,
280 R.string.global_actions_airplane_mode_on_status,
281 R.string.global_actions_airplane_mode_off_status) {
282
283 void onToggle(boolean on) {
284 if (mHasTelephony && Boolean.parseBoolean(
285 SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
286 mIsWaitingForEcmExit = true;
287 // Launch ECM exit dialog
288 Intent ecmDialogIntent =
289 new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null);
290 ecmDialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
291 mContext.startActivity(ecmDialogIntent);
292 } else {
293 changeAirplaneModeSystemSetting(on);
294 }
295 }
296
297 @Override
298 protected void changeStateFromPress(boolean buttonOn) {
299 if (!mHasTelephony) return;
300
301 // In ECM mode airplane state cannot be changed
302 if (!(Boolean.parseBoolean(
303 SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE)))) {
304 mState = buttonOn ? State.TurningOn : State.TurningOff;
305 mAirplaneState = mState;
306 }
307 }
308
309 public boolean showDuringKeyguard() {
310 return true;
311 }
312
313 public boolean showBeforeProvisioning() {
314 return false;
315 }
316 };
317 onAirplaneModeChanged();
318
319 mItems = new ArrayList<Action>();
320 String[] defaultActions = mContext.getResources().getStringArray(
321 R.array.config_globalActionsList);
322
323 ArraySet<String> addedKeys = new ArraySet<String>();
Alex Chau04458852017-11-27 18:21:23 +0000324 mHasLogoutButton = false;
Chad Brubaker72a73ea2018-01-26 15:56:55 -0800325 mHasLockdownButton = false;
yuanjiahsu88363e92018-09-06 19:23:52 +0800326 mSeparatedEmergencyButtonEnabled = FeatureFlagUtils
327 .isEnabled(mContext, FeatureFlagUtils.EMERGENCY_DIAL_SHORTCUTS);
Jason Monk361915c2017-03-21 20:33:59 -0400328 for (int i = 0; i < defaultActions.length; i++) {
329 String actionKey = defaultActions[i];
330 if (addedKeys.contains(actionKey)) {
331 // If we already have added this, don't add it again.
332 continue;
333 }
334 if (GLOBAL_ACTION_KEY_POWER.equals(actionKey)) {
335 mItems.add(new PowerAction());
336 } else if (GLOBAL_ACTION_KEY_AIRPLANE.equals(actionKey)) {
337 mItems.add(mAirplaneModeOn);
338 } else if (GLOBAL_ACTION_KEY_BUGREPORT.equals(actionKey)) {
339 if (Settings.Global.getInt(mContext.getContentResolver(),
340 Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0 && isCurrentUserOwner()) {
341 mItems.add(new BugReportAction());
342 }
343 } else if (GLOBAL_ACTION_KEY_SILENT.equals(actionKey)) {
344 if (mShowSilentToggle) {
345 mItems.add(mSilentModeAction);
346 }
347 } else if (GLOBAL_ACTION_KEY_USERS.equals(actionKey)) {
348 if (SystemProperties.getBoolean("fw.power_user_switcher", false)) {
349 addUsersToMenu(mItems);
350 }
351 } else if (GLOBAL_ACTION_KEY_SETTINGS.equals(actionKey)) {
352 mItems.add(getSettingsAction());
353 } else if (GLOBAL_ACTION_KEY_LOCKDOWN.equals(actionKey)) {
Chad Brubaker02cd6cf2018-05-01 14:59:33 -0700354 if (Settings.Secure.getIntForUser(mContext.getContentResolver(),
355 Settings.Secure.LOCKDOWN_IN_POWER_MENU, 0, getCurrentUser().id) != 0
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800356 && shouldDisplayLockdown()) {
Chad Brubaker4f28f0d2017-09-07 14:28:13 -0700357 mItems.add(getLockdownAction());
Chad Brubaker72a73ea2018-01-26 15:56:55 -0800358 mHasLockdownButton = true;
Chad Brubaker4f28f0d2017-09-07 14:28:13 -0700359 }
Jason Monk361915c2017-03-21 20:33:59 -0400360 } else if (GLOBAL_ACTION_KEY_VOICEASSIST.equals(actionKey)) {
361 mItems.add(getVoiceAssistAction());
362 } else if (GLOBAL_ACTION_KEY_ASSIST.equals(actionKey)) {
363 mItems.add(getAssistAction());
364 } else if (GLOBAL_ACTION_KEY_RESTART.equals(actionKey)) {
365 mItems.add(new RestartAction());
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500366 } else if (GLOBAL_ACTION_KEY_SCREENSHOT.equals(actionKey)) {
367 mItems.add(new ScreenshotAction());
Alex Chau04458852017-11-27 18:21:23 +0000368 } else if (GLOBAL_ACTION_KEY_LOGOUT.equals(actionKey)) {
Alex Chaud7958272017-12-08 11:30:52 +0000369 if (mDevicePolicyManager.isLogoutEnabled()
Alex Chau04458852017-11-27 18:21:23 +0000370 && getCurrentUser().id != UserHandle.USER_SYSTEM) {
371 mItems.add(new LogoutAction());
372 mHasLogoutButton = true;
373 }
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800374 } else if (GLOBAL_ACTION_KEY_EMERGENCY.equals(actionKey)) {
375 if (mSeparatedEmergencyButtonEnabled
376 && !mEmergencyAffordanceManager.needsEmergencyAffordance()) {
377 mItems.add(new EmergencyDialerAction());
378 }
Jason Monk361915c2017-03-21 20:33:59 -0400379 } else {
380 Log.e(TAG, "Invalid global action key " + actionKey);
381 }
382 // Add here so we don't add more than one.
383 addedKeys.add(actionKey);
384 }
385
386 if (mEmergencyAffordanceManager.needsEmergencyAffordance()) {
387 mItems.add(getEmergencyAction());
388 }
389
390 mAdapter = new MyAdapter();
391
Lucas Dupin1d4a5792018-04-02 15:14:59 -0700392 OnItemLongClickListener onItemLongClickListener = (parent, view, position, id) -> {
393 final Action action = mAdapter.getItem(position);
394 if (action instanceof LongPressAction) {
395 mDialog.dismiss();
396 return ((LongPressAction) action).onLongPress();
Jason Monk16fbd9d2017-04-27 14:28:49 -0400397 }
Lucas Dupin1d4a5792018-04-02 15:14:59 -0700398 return false;
Jason Monk16fbd9d2017-04-27 14:28:49 -0400399 };
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +0800400 ActionsDialog dialog = new ActionsDialog(mContext, this, mAdapter, onItemLongClickListener,
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800401 mSeparatedEmergencyButtonEnabled);
Jason Monk361915c2017-03-21 20:33:59 -0400402 dialog.setCanceledOnTouchOutside(false); // Handled by the custom class.
Lucas Dupinc1cc7592017-05-22 15:56:16 -0700403 dialog.setKeyguardShowing(mKeyguardShowing);
Jason Monk361915c2017-03-21 20:33:59 -0400404
405 dialog.setOnDismissListener(this);
Shaotang Li786da902018-08-02 11:18:00 +0800406 dialog.setOnShowListener(this);
Jason Monk361915c2017-03-21 20:33:59 -0400407
408 return dialog;
409 }
410
Chad Brubakerf4075fe2018-01-03 13:23:22 -0800411 private boolean shouldDisplayLockdown() {
412 int userId = getCurrentUser().id;
413 // Lockdown is meaningless without a place to go.
414 if (!mKeyguardManager.isDeviceSecure(userId)) {
415 return false;
416 }
417
418 // Only show the lockdown button if the device isn't locked down (for whatever reason).
419 int state = mLockPatternUtils.getStrongAuthForUser(userId);
420 return (state == STRONG_AUTH_NOT_REQUIRED
421 || state == SOME_AUTH_REQUIRED_AFTER_USER_REQUEST);
422 }
423
Lucas Dupine5b7dc72018-10-02 15:18:05 -0700424 @Override
425 public void onUiModeChanged() {
426 mContext.getTheme().applyStyle(mContext.getThemeResId(), true);
427 }
428
429 public void destroy() {
430 Dependency.get(ConfigurationController.class).removeCallback(this);
431 }
432
Jason Monk361915c2017-03-21 20:33:59 -0400433 private final class PowerAction extends SinglePressAction implements LongPressAction {
434 private PowerAction() {
435 super(R.drawable.ic_lock_power_off,
Jason Monk16fbd9d2017-04-27 14:28:49 -0400436 R.string.global_action_power_off);
Jason Monk361915c2017-03-21 20:33:59 -0400437 }
438
439 @Override
440 public boolean onLongPress() {
441 UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
442 if (!um.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
443 mWindowManagerFuncs.reboot(true);
444 return true;
445 }
446 return false;
447 }
448
449 @Override
450 public boolean showDuringKeyguard() {
451 return true;
452 }
453
454 @Override
455 public boolean showBeforeProvisioning() {
456 return true;
457 }
458
459 @Override
460 public void onPress() {
461 // shutdown by making sure radio and power are handled accordingly.
462 mWindowManagerFuncs.shutdown();
463 }
464 }
465
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800466 private class EmergencyDialerAction extends SinglePressAction {
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800467 private EmergencyDialerAction() {
468 super(R.drawable.ic_faster_emergency,
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +0800469 R.string.global_action_emergency);
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800470 }
471
472 @Override
473 public void onPress() {
Shaotang Li786da902018-08-02 11:18:00 +0800474 MetricsLogger.action(mContext, MetricsEvent.ACTION_EMERGENCY_DIALER_FROM_POWER_MENU);
Shaotang Li5c422632018-07-04 14:18:40 +0800475 Intent intent = new Intent(EmergencyDialerConstants.ACTION_DIAL);
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800476 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
Shaotang Li5c422632018-07-04 14:18:40 +0800477 intent.putExtra(EmergencyDialerConstants.EXTRA_ENTRY_TYPE,
478 EmergencyDialerConstants.ENTRY_TYPE_POWER_MENU);
Wesley.CW Wang8d072762018-05-28 16:39:27 +0800479 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
480 }
481
482 @Override
483 public boolean showDuringKeyguard() {
484 return true;
485 }
486
487 @Override
488 public boolean showBeforeProvisioning() {
489 return true;
490 }
491 }
492
Jason Monk361915c2017-03-21 20:33:59 -0400493 private final class RestartAction extends SinglePressAction implements LongPressAction {
494 private RestartAction() {
495 super(R.drawable.ic_restart, R.string.global_action_restart);
496 }
497
498 @Override
499 public boolean onLongPress() {
500 UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
501 if (!um.hasUserRestriction(UserManager.DISALLOW_SAFE_BOOT)) {
502 mWindowManagerFuncs.reboot(true);
503 return true;
504 }
505 return false;
506 }
507
508 @Override
509 public boolean showDuringKeyguard() {
510 return true;
511 }
512
513 @Override
514 public boolean showBeforeProvisioning() {
515 return true;
516 }
517
518 @Override
519 public void onPress() {
520 mWindowManagerFuncs.reboot(false);
521 }
522 }
523
524
Alison Cichowlasa2cd19e2017-12-06 10:51:21 -0500525 private class ScreenshotAction extends SinglePressAction {
526 public ScreenshotAction() {
527 super(R.drawable.ic_screenshot, R.string.global_action_screenshot);
528 }
529
530 @Override
531 public void onPress() {
532 // Add a little delay before executing, to give the
533 // dialog a chance to go away before it takes a
534 // screenshot.
535 // TODO: instead, omit global action dialog layer
536 mHandler.postDelayed(new Runnable() {
537 @Override
538 public void run() {
539 mScreenshotHelper.takeScreenshot(1, true, true, mHandler);
540 MetricsLogger.action(mContext,
541 MetricsEvent.ACTION_SCREENSHOT_POWER_MENU);
542 }
543 }, 500);
544 }
545
546 @Override
547 public boolean showDuringKeyguard() {
548 return true;
549 }
550
551 @Override
552 public boolean showBeforeProvisioning() {
553 return false;
554 }
555 }
556
Jason Monk361915c2017-03-21 20:33:59 -0400557 private class BugReportAction extends SinglePressAction implements LongPressAction {
558
559 public BugReportAction() {
560 super(R.drawable.ic_lock_bugreport, R.string.bugreport_title);
561 }
562
563 @Override
564 public void onPress() {
565 // don't actually trigger the bugreport if we are running stability
566 // tests via monkey
567 if (ActivityManager.isUserAMonkey()) {
568 return;
569 }
570 // Add a little delay before executing, to give the
571 // dialog a chance to go away before it takes a
572 // screenshot.
573 mHandler.postDelayed(new Runnable() {
574 @Override
575 public void run() {
576 try {
577 // Take an "interactive" bugreport.
578 MetricsLogger.action(mContext,
579 MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_INTERACTIVE);
580 ActivityManager.getService().requestBugReport(
581 ActivityManager.BUGREPORT_OPTION_INTERACTIVE);
582 } catch (RemoteException e) {
583 }
584 }
585 }, 500);
586 }
587
588 @Override
589 public boolean onLongPress() {
590 // don't actually trigger the bugreport if we are running stability
591 // tests via monkey
592 if (ActivityManager.isUserAMonkey()) {
593 return false;
594 }
595 try {
596 // Take a "full" bugreport.
597 MetricsLogger.action(mContext, MetricsEvent.ACTION_BUGREPORT_FROM_POWER_MENU_FULL);
598 ActivityManager.getService().requestBugReport(
599 ActivityManager.BUGREPORT_OPTION_FULL);
600 } catch (RemoteException e) {
601 }
602 return false;
603 }
604
605 public boolean showDuringKeyguard() {
606 return true;
607 }
608
609 @Override
610 public boolean showBeforeProvisioning() {
611 return false;
612 }
613
614 @Override
615 public String getStatus() {
616 return mContext.getString(
617 R.string.bugreport_status,
618 Build.VERSION.RELEASE,
619 Build.ID);
620 }
621 }
622
Alex Chau04458852017-11-27 18:21:23 +0000623 private final class LogoutAction extends SinglePressAction {
624 private LogoutAction() {
625 super(R.drawable.ic_logout, R.string.global_action_logout);
626 }
627
628 @Override
629 public boolean showDuringKeyguard() {
630 return true;
631 }
632
633 @Override
634 public boolean showBeforeProvisioning() {
635 return false;
636 }
637
638 @Override
639 public void onPress() {
640 // Add a little delay before executing, to give the dialog a chance to go away before
641 // switching user
642 mHandler.postDelayed(() -> {
643 try {
Alex Chauedb6a012018-01-26 12:52:43 +0000644 int currentUserId = getCurrentUser().id;
Alex Chau04458852017-11-27 18:21:23 +0000645 ActivityManager.getService().switchUser(UserHandle.USER_SYSTEM);
Alex Chauedb6a012018-01-26 12:52:43 +0000646 ActivityManager.getService().stopUser(currentUserId, true /*force*/, null);
Alex Chau04458852017-11-27 18:21:23 +0000647 } catch (RemoteException re) {
648 Log.e(TAG, "Couldn't logout user " + re);
649 }
650 }, 500);
651 }
652 }
653
Jason Monk361915c2017-03-21 20:33:59 -0400654 private Action getSettingsAction() {
655 return new SinglePressAction(R.drawable.ic_settings,
656 R.string.global_action_settings) {
657
658 @Override
659 public void onPress() {
660 Intent intent = new Intent(Settings.ACTION_SETTINGS);
661 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
662 mContext.startActivity(intent);
663 }
664
665 @Override
666 public boolean showDuringKeyguard() {
667 return true;
668 }
669
670 @Override
671 public boolean showBeforeProvisioning() {
672 return true;
673 }
674 };
675 }
676
677 private Action getEmergencyAction() {
Wesley.CW Wanga9de7922018-07-06 15:26:21 +0800678 Drawable emergencyIcon = mContext.getDrawable(R.drawable.emergency_icon);
679 if(!mSeparatedEmergencyButtonEnabled) {
680 // use un-colored legacy treatment
681 emergencyIcon.setTintList(null);
682 }
683
Jason Monk361915c2017-03-21 20:33:59 -0400684 return new SinglePressAction(R.drawable.emergency_icon,
685 R.string.global_action_emergency) {
686 @Override
687 public void onPress() {
688 mEmergencyAffordanceManager.performEmergencyCall();
689 }
690
691 @Override
692 public boolean showDuringKeyguard() {
693 return true;
694 }
695
696 @Override
697 public boolean showBeforeProvisioning() {
698 return true;
699 }
700 };
701 }
702
703 private Action getAssistAction() {
704 return new SinglePressAction(R.drawable.ic_action_assist_focused,
705 R.string.global_action_assist) {
706 @Override
707 public void onPress() {
708 Intent intent = new Intent(Intent.ACTION_ASSIST);
709 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
710 mContext.startActivity(intent);
711 }
712
713 @Override
714 public boolean showDuringKeyguard() {
715 return true;
716 }
717
718 @Override
719 public boolean showBeforeProvisioning() {
720 return true;
721 }
722 };
723 }
724
725 private Action getVoiceAssistAction() {
726 return new SinglePressAction(R.drawable.ic_voice_search,
727 R.string.global_action_voice_assist) {
728 @Override
729 public void onPress() {
730 Intent intent = new Intent(Intent.ACTION_VOICE_ASSIST);
731 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
732 mContext.startActivity(intent);
733 }
734
735 @Override
736 public boolean showDuringKeyguard() {
737 return true;
738 }
739
740 @Override
741 public boolean showBeforeProvisioning() {
742 return true;
743 }
744 };
745 }
746
747 private Action getLockdownAction() {
Alison Cichowlas21125432018-05-16 15:40:45 -0400748 return new SinglePressAction(R.drawable.ic_lock_lockdown,
Jason Monk361915c2017-03-21 20:33:59 -0400749 R.string.global_action_lockdown) {
750
751 @Override
752 public void onPress() {
Chad Brubaker4f28f0d2017-09-07 14:28:13 -0700753 new LockPatternUtils(mContext)
754 .requireStrongAuth(STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN,
755 UserHandle.USER_ALL);
Jason Monk361915c2017-03-21 20:33:59 -0400756 try {
757 WindowManagerGlobal.getWindowManagerService().lockNow(null);
Pavel Grafov059021b2018-05-02 13:44:46 +0100758 // Lock profiles (if any) on the background thread.
759 final Handler bgHandler = new Handler(Dependency.get(Dependency.BG_LOOPER));
760 bgHandler.post(() -> lockProfiles());
Jason Monk361915c2017-03-21 20:33:59 -0400761 } catch (RemoteException e) {
762 Log.e(TAG, "Error while trying to lock device.", e);
763 }
764 }
765
766 @Override
767 public boolean showDuringKeyguard() {
768 return true;
769 }
770
771 @Override
772 public boolean showBeforeProvisioning() {
773 return false;
774 }
775 };
776 }
777
Pavel Grafov059021b2018-05-02 13:44:46 +0100778 private void lockProfiles() {
779 final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
780 final TrustManager tm = (TrustManager) mContext.getSystemService(Context.TRUST_SERVICE);
781 final int currentUserId = getCurrentUser().id;
782 final int[] profileIds = um.getEnabledProfileIds(currentUserId);
783 for (final int id : profileIds) {
784 if (id != currentUserId) {
785 tm.setDeviceLockedForUser(id, true);
786 }
787 }
788 }
789
Jason Monk361915c2017-03-21 20:33:59 -0400790 private UserInfo getCurrentUser() {
791 try {
792 return ActivityManager.getService().getCurrentUser();
793 } catch (RemoteException re) {
794 return null;
795 }
796 }
797
798 private boolean isCurrentUserOwner() {
799 UserInfo currentUser = getCurrentUser();
800 return currentUser == null || currentUser.isPrimary();
801 }
802
803 private void addUsersToMenu(ArrayList<Action> items) {
804 UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
805 if (um.isUserSwitcherEnabled()) {
806 List<UserInfo> users = um.getUsers();
807 UserInfo currentUser = getCurrentUser();
808 for (final UserInfo user : users) {
809 if (user.supportsSwitchToByUser()) {
810 boolean isCurrentUser = currentUser == null
811 ? user.id == 0 : (currentUser.id == user.id);
812 Drawable icon = user.iconPath != null ? Drawable.createFromPath(user.iconPath)
813 : null;
814 SinglePressAction switchToUser = new SinglePressAction(
815 R.drawable.ic_menu_cc, icon,
816 (user.name != null ? user.name : "Primary")
Jason Monk16fbd9d2017-04-27 14:28:49 -0400817 + (isCurrentUser ? " \u2714" : "")) {
Jason Monk361915c2017-03-21 20:33:59 -0400818 public void onPress() {
819 try {
820 ActivityManager.getService().switchUser(user.id);
821 } catch (RemoteException re) {
822 Log.e(TAG, "Couldn't switch user " + re);
823 }
824 }
825
826 public boolean showDuringKeyguard() {
827 return true;
828 }
829
830 public boolean showBeforeProvisioning() {
831 return false;
832 }
833 };
834 items.add(switchToUser);
835 }
836 }
837 }
838 }
839
840 private void prepareDialog() {
841 refreshSilentMode();
842 mAirplaneModeOn.updateState(mAirplaneState);
843 mAdapter.notifyDataSetChanged();
Jason Monk361915c2017-03-21 20:33:59 -0400844 if (mShowSilentToggle) {
845 IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
846 mContext.registerReceiver(mRingerModeReceiver, filter);
847 }
848 }
849
850 private void refreshSilentMode() {
851 if (!mHasVibrator) {
852 final boolean silentModeOn =
853 mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL;
Jason Monk16fbd9d2017-04-27 14:28:49 -0400854 ((ToggleAction) mSilentModeAction).updateState(
Jason Monk361915c2017-03-21 20:33:59 -0400855 silentModeOn ? ToggleAction.State.On : ToggleAction.State.Off);
856 }
857 }
858
859 /** {@inheritDoc} */
860 public void onDismiss(DialogInterface dialog) {
861 mWindowManagerFuncs.onGlobalActionsHidden();
862 if (mShowSilentToggle) {
863 try {
864 mContext.unregisterReceiver(mRingerModeReceiver);
865 } catch (IllegalArgumentException ie) {
866 // ignore this
867 Log.w(TAG, ie);
868 }
869 }
870 }
871
872 /** {@inheritDoc} */
873 public void onClick(DialogInterface dialog, int which) {
Jason Monkfd279662017-06-29 19:37:48 -0400874 Action item = mAdapter.getItem(which);
Jason Monkb4302182017-08-04 13:39:17 -0400875 if (!(item instanceof SilentModeTriStateAction)) {
Jason Monk361915c2017-03-21 20:33:59 -0400876 dialog.dismiss();
877 }
Jason Monkfd279662017-06-29 19:37:48 -0400878 item.onPress();
Jason Monk361915c2017-03-21 20:33:59 -0400879 }
880
Shaotang Li786da902018-08-02 11:18:00 +0800881 /** {@inheritDoc} */
882 public void onShow(DialogInterface dialog) {
883 MetricsLogger.visible(mContext, MetricsEvent.POWER_MENU);
884 }
885
Jason Monk361915c2017-03-21 20:33:59 -0400886 /**
887 * The adapter used for the list within the global actions dialog, taking
888 * into account whether the keyguard is showing via
Jason Monk16fbd9d2017-04-27 14:28:49 -0400889 * {@link com.android.systemui.globalactions.GlobalActionsDialog#mKeyguardShowing} and whether
890 * the device is provisioned
Jason Monk361915c2017-03-21 20:33:59 -0400891 * via {@link com.android.systemui.globalactions.GlobalActionsDialog#mDeviceProvisioned}.
892 */
893 private class MyAdapter extends BaseAdapter {
894
895 public int getCount() {
896 int count = 0;
897
898 for (int i = 0; i < mItems.size(); i++) {
899 final Action action = mItems.get(i);
900
901 if (mKeyguardShowing && !action.showDuringKeyguard()) {
902 continue;
903 }
904 if (!mDeviceProvisioned && !action.showBeforeProvisioning()) {
905 continue;
906 }
907 count++;
908 }
909 return count;
910 }
911
912 @Override
913 public boolean isEnabled(int position) {
914 return getItem(position).isEnabled();
915 }
916
917 @Override
918 public boolean areAllItemsEnabled() {
919 return false;
920 }
921
922 public Action getItem(int position) {
923
924 int filteredPos = 0;
925 for (int i = 0; i < mItems.size(); i++) {
926 final Action action = mItems.get(i);
927 if (mKeyguardShowing && !action.showDuringKeyguard()) {
928 continue;
929 }
930 if (!mDeviceProvisioned && !action.showBeforeProvisioning()) {
931 continue;
932 }
933 if (filteredPos == position) {
934 return action;
935 }
936 filteredPos++;
937 }
938
939 throw new IllegalArgumentException("position " + position
940 + " out of range of showable actions"
941 + ", filtered count=" + getCount()
942 + ", keyguardshowing=" + mKeyguardShowing
943 + ", provisioned=" + mDeviceProvisioned);
944 }
945
946
947 public long getItemId(int position) {
948 return position;
949 }
950
951 public View getView(int position, View convertView, ViewGroup parent) {
952 Action action = getItem(position);
Jason Monk16fbd9d2017-04-27 14:28:49 -0400953 View view = action.create(mContext, convertView, parent, LayoutInflater.from(mContext));
Alison Cichowlas3be52db2018-03-06 19:48:06 -0500954 // Everything but screenshot, the last item, gets white background.
955 if (position == getCount() - 1) {
Jason Monk16fbd9d2017-04-27 14:28:49 -0400956 HardwareUiLayout.get(parent).setDivisionView(view);
957 }
958 return view;
Jason Monk361915c2017-03-21 20:33:59 -0400959 }
960 }
961
962 // note: the scheme below made more sense when we were planning on having
963 // 8 different things in the global actions dialog. seems overkill with
964 // only 3 items now, but may as well keep this flexible approach so it will
965 // be easy should someone decide at the last minute to include something
966 // else, such as 'enable wifi', or 'enable bluetooth'
967
968 /**
969 * What each item in the global actions dialog must be able to support.
970 */
971 private interface Action {
972 /**
973 * @return Text that will be announced when dialog is created. null
Jason Monk16fbd9d2017-04-27 14:28:49 -0400974 * for none.
Jason Monk361915c2017-03-21 20:33:59 -0400975 */
976 CharSequence getLabelForAccessibility(Context context);
977
978 View create(Context context, View convertView, ViewGroup parent, LayoutInflater inflater);
979
980 void onPress();
981
982 /**
983 * @return whether this action should appear in the dialog when the keygaurd
Jason Monk16fbd9d2017-04-27 14:28:49 -0400984 * is showing.
Jason Monk361915c2017-03-21 20:33:59 -0400985 */
986 boolean showDuringKeyguard();
987
988 /**
989 * @return whether this action should appear in the dialog before the
Jason Monk16fbd9d2017-04-27 14:28:49 -0400990 * device is provisioned.
Jason Monk361915c2017-03-21 20:33:59 -0400991 */
992 boolean showBeforeProvisioning();
993
994 boolean isEnabled();
995 }
996
997 /**
998 * An action that also supports long press.
999 */
1000 private interface LongPressAction extends Action {
1001 boolean onLongPress();
1002 }
1003
1004 /**
1005 * A single press action maintains no state, just responds to a press
1006 * and takes an action.
1007 */
1008 private static abstract class SinglePressAction implements Action {
1009 private final int mIconResId;
1010 private final Drawable mIcon;
1011 private final int mMessageResId;
1012 private final CharSequence mMessage;
1013
1014 protected SinglePressAction(int iconResId, int messageResId) {
1015 mIconResId = iconResId;
1016 mMessageResId = messageResId;
1017 mMessage = null;
1018 mIcon = null;
1019 }
1020
1021 protected SinglePressAction(int iconResId, Drawable icon, CharSequence message) {
1022 mIconResId = iconResId;
1023 mMessageResId = 0;
1024 mMessage = message;
1025 mIcon = icon;
1026 }
1027
1028 public boolean isEnabled() {
1029 return true;
1030 }
1031
1032 public String getStatus() {
1033 return null;
1034 }
1035
1036 abstract public void onPress();
1037
1038 public CharSequence getLabelForAccessibility(Context context) {
1039 if (mMessage != null) {
1040 return mMessage;
1041 } else {
1042 return context.getString(mMessageResId);
1043 }
1044 }
1045
1046 public View create(
1047 Context context, View convertView, ViewGroup parent, LayoutInflater inflater) {
Jason Monk16fbd9d2017-04-27 14:28:49 -04001048 View v = inflater.inflate(com.android.systemui.R.layout.global_actions_item, parent,
1049 false);
Jason Monk361915c2017-03-21 20:33:59 -04001050
1051 ImageView icon = (ImageView) v.findViewById(R.id.icon);
1052 TextView messageView = (TextView) v.findViewById(R.id.message);
1053
1054 TextView statusView = (TextView) v.findViewById(R.id.status);
1055 final String status = getStatus();
1056 if (!TextUtils.isEmpty(status)) {
1057 statusView.setText(status);
1058 } else {
1059 statusView.setVisibility(View.GONE);
1060 }
1061 if (mIcon != null) {
1062 icon.setImageDrawable(mIcon);
1063 icon.setScaleType(ScaleType.CENTER_CROP);
1064 } else if (mIconResId != 0) {
1065 icon.setImageDrawable(context.getDrawable(mIconResId));
1066 }
1067 if (mMessage != null) {
1068 messageView.setText(mMessage);
1069 } else {
1070 messageView.setText(mMessageResId);
1071 }
1072
1073 return v;
1074 }
1075 }
1076
1077 /**
1078 * A toggle action knows whether it is on or off, and displays an icon
1079 * and status message accordingly.
1080 */
1081 private static abstract class ToggleAction implements Action {
1082
1083 enum State {
1084 Off(false),
1085 TurningOn(true),
1086 TurningOff(true),
1087 On(false);
1088
1089 private final boolean inTransition;
1090
1091 State(boolean intermediate) {
1092 inTransition = intermediate;
1093 }
1094
1095 public boolean inTransition() {
1096 return inTransition;
1097 }
1098 }
1099
1100 protected State mState = State.Off;
1101
1102 // prefs
1103 protected int mEnabledIconResId;
1104 protected int mDisabledIconResid;
1105 protected int mMessageResId;
1106 protected int mEnabledStatusMessageResId;
1107 protected int mDisabledStatusMessageResId;
1108
1109 /**
Jason Monk16fbd9d2017-04-27 14:28:49 -04001110 * @param enabledIconResId The icon for when this action is on.
1111 * @param disabledIconResid The icon for when this action is off.
1112 * @param message The general information message, e.g 'Silent Mode'
1113 * @param enabledStatusMessageResId The on status message, e.g 'sound disabled'
Jason Monk361915c2017-03-21 20:33:59 -04001114 * @param disabledStatusMessageResId The off status message, e.g. 'sound enabled'
1115 */
1116 public ToggleAction(int enabledIconResId,
1117 int disabledIconResid,
1118 int message,
1119 int enabledStatusMessageResId,
1120 int disabledStatusMessageResId) {
1121 mEnabledIconResId = enabledIconResId;
1122 mDisabledIconResid = disabledIconResid;
1123 mMessageResId = message;
1124 mEnabledStatusMessageResId = enabledStatusMessageResId;
1125 mDisabledStatusMessageResId = disabledStatusMessageResId;
1126 }
1127
1128 /**
1129 * Override to make changes to resource IDs just before creating the
1130 * View.
1131 */
1132 void willCreate() {
1133
1134 }
1135
1136 @Override
1137 public CharSequence getLabelForAccessibility(Context context) {
1138 return context.getString(mMessageResId);
1139 }
1140
1141 public View create(Context context, View convertView, ViewGroup parent,
1142 LayoutInflater inflater) {
1143 willCreate();
1144
1145 View v = inflater.inflate(R
Jason Monk16fbd9d2017-04-27 14:28:49 -04001146 .layout.global_actions_item, parent, false);
Jason Monk361915c2017-03-21 20:33:59 -04001147
1148 ImageView icon = (ImageView) v.findViewById(R.id.icon);
1149 TextView messageView = (TextView) v.findViewById(R.id.message);
1150 TextView statusView = (TextView) v.findViewById(R.id.status);
1151 final boolean enabled = isEnabled();
1152
1153 if (messageView != null) {
1154 messageView.setText(mMessageResId);
1155 messageView.setEnabled(enabled);
1156 }
1157
1158 boolean on = ((mState == State.On) || (mState == State.TurningOn));
1159 if (icon != null) {
1160 icon.setImageDrawable(context.getDrawable(
1161 (on ? mEnabledIconResId : mDisabledIconResid)));
1162 icon.setEnabled(enabled);
1163 }
1164
1165 if (statusView != null) {
1166 statusView.setText(on ? mEnabledStatusMessageResId : mDisabledStatusMessageResId);
1167 statusView.setVisibility(View.VISIBLE);
1168 statusView.setEnabled(enabled);
1169 }
1170 v.setEnabled(enabled);
1171
1172 return v;
1173 }
1174
1175 public final void onPress() {
1176 if (mState.inTransition()) {
1177 Log.w(TAG, "shouldn't be able to toggle when in transition");
1178 return;
1179 }
1180
1181 final boolean nowOn = !(mState == State.On);
1182 onToggle(nowOn);
1183 changeStateFromPress(nowOn);
1184 }
1185
1186 public boolean isEnabled() {
1187 return !mState.inTransition();
1188 }
1189
1190 /**
1191 * Implementations may override this if their state can be in on of the intermediate
1192 * states until some notification is received (e.g airplane mode is 'turning off' until
1193 * we know the wireless connections are back online
Jason Monk16fbd9d2017-04-27 14:28:49 -04001194 *
Jason Monk361915c2017-03-21 20:33:59 -04001195 * @param buttonOn Whether the button was turned on or off
1196 */
1197 protected void changeStateFromPress(boolean buttonOn) {
1198 mState = buttonOn ? State.On : State.Off;
1199 }
1200
1201 abstract void onToggle(boolean on);
1202
1203 public void updateState(State state) {
1204 mState = state;
1205 }
1206 }
1207
1208 private class SilentModeToggleAction extends ToggleAction {
1209 public SilentModeToggleAction() {
1210 super(R.drawable.ic_audio_vol_mute,
1211 R.drawable.ic_audio_vol,
1212 R.string.global_action_toggle_silent_mode,
1213 R.string.global_action_silent_mode_on_status,
1214 R.string.global_action_silent_mode_off_status);
1215 }
1216
1217 void onToggle(boolean on) {
1218 if (on) {
1219 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
1220 } else {
1221 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
1222 }
1223 }
1224
1225 public boolean showDuringKeyguard() {
1226 return true;
1227 }
1228
1229 public boolean showBeforeProvisioning() {
1230 return false;
1231 }
1232 }
1233
1234 private static class SilentModeTriStateAction implements Action, View.OnClickListener {
1235
Jason Monk16fbd9d2017-04-27 14:28:49 -04001236 private final int[] ITEM_IDS = {R.id.option1, R.id.option2, R.id.option3};
Jason Monk361915c2017-03-21 20:33:59 -04001237
1238 private final AudioManager mAudioManager;
1239 private final Handler mHandler;
Jason Monk361915c2017-03-21 20:33:59 -04001240
Lucas Dupin40ec6b782018-06-05 19:07:16 -07001241 SilentModeTriStateAction(AudioManager audioManager, Handler handler) {
Jason Monk361915c2017-03-21 20:33:59 -04001242 mAudioManager = audioManager;
1243 mHandler = handler;
Jason Monk361915c2017-03-21 20:33:59 -04001244 }
1245
1246 private int ringerModeToIndex(int ringerMode) {
1247 // They just happen to coincide
1248 return ringerMode;
1249 }
1250
1251 private int indexToRingerMode(int index) {
1252 // They just happen to coincide
1253 return index;
1254 }
1255
1256 @Override
1257 public CharSequence getLabelForAccessibility(Context context) {
1258 return null;
1259 }
1260
1261 public View create(Context context, View convertView, ViewGroup parent,
1262 LayoutInflater inflater) {
1263 View v = inflater.inflate(R.layout.global_actions_silent_mode, parent, false);
1264
1265 int selectedIndex = ringerModeToIndex(mAudioManager.getRingerMode());
1266 for (int i = 0; i < 3; i++) {
1267 View itemView = v.findViewById(ITEM_IDS[i]);
1268 itemView.setSelected(selectedIndex == i);
1269 // Set up click handler
1270 itemView.setTag(i);
1271 itemView.setOnClickListener(this);
1272 }
1273 return v;
1274 }
1275
1276 public void onPress() {
1277 }
1278
1279 public boolean showDuringKeyguard() {
1280 return true;
1281 }
1282
1283 public boolean showBeforeProvisioning() {
1284 return false;
1285 }
1286
1287 public boolean isEnabled() {
1288 return true;
1289 }
1290
1291 void willCreate() {
1292 }
1293
1294 public void onClick(View v) {
1295 if (!(v.getTag() instanceof Integer)) return;
1296
1297 int index = (Integer) v.getTag();
1298 mAudioManager.setRingerMode(indexToRingerMode(index));
1299 mHandler.sendEmptyMessageDelayed(MESSAGE_DISMISS, DIALOG_DISMISS_DELAY);
1300 }
1301 }
1302
1303 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
1304 public void onReceive(Context context, Intent intent) {
1305 String action = intent.getAction();
1306 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
1307 || Intent.ACTION_SCREEN_OFF.equals(action)) {
1308 String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
1309 if (!SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS.equals(reason)) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001310 mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_DISMISS, reason));
Jason Monk361915c2017-03-21 20:33:59 -04001311 }
1312 } else if (TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED.equals(action)) {
1313 // Airplane mode can be changed after ECM exits if airplane toggle button
1314 // is pressed during ECM mode
1315 if (!(intent.getBooleanExtra("PHONE_IN_ECM_STATE", false)) &&
1316 mIsWaitingForEcmExit) {
1317 mIsWaitingForEcmExit = false;
1318 changeAirplaneModeSystemSetting(true);
1319 }
1320 }
1321 }
1322 };
1323
1324 PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
1325 @Override
1326 public void onServiceStateChanged(ServiceState serviceState) {
1327 if (!mHasTelephony) return;
1328 final boolean inAirplaneMode = serviceState.getState() == ServiceState.STATE_POWER_OFF;
1329 mAirplaneState = inAirplaneMode ? ToggleAction.State.On : ToggleAction.State.Off;
1330 mAirplaneModeOn.updateState(mAirplaneState);
1331 mAdapter.notifyDataSetChanged();
1332 }
1333 };
1334
1335 private BroadcastReceiver mRingerModeReceiver = new BroadcastReceiver() {
1336 @Override
1337 public void onReceive(Context context, Intent intent) {
1338 if (intent.getAction().equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
1339 mHandler.sendEmptyMessage(MESSAGE_REFRESH);
1340 }
1341 }
1342 };
1343
1344 private ContentObserver mAirplaneModeObserver = new ContentObserver(new Handler()) {
1345 @Override
1346 public void onChange(boolean selfChange) {
1347 onAirplaneModeChanged();
1348 }
1349 };
1350
1351 private static final int MESSAGE_DISMISS = 0;
1352 private static final int MESSAGE_REFRESH = 1;
1353 private static final int MESSAGE_SHOW = 2;
1354 private static final int DIALOG_DISMISS_DELAY = 300; // ms
1355
1356 private Handler mHandler = new Handler() {
1357 public void handleMessage(Message msg) {
1358 switch (msg.what) {
Jason Monk16fbd9d2017-04-27 14:28:49 -04001359 case MESSAGE_DISMISS:
1360 if (mDialog != null) {
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001361 if (SYSTEM_DIALOG_REASON_DREAM.equals(msg.obj)) {
1362 mDialog.dismissImmediately();
1363 } else {
1364 mDialog.dismiss();
1365 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001366 mDialog = null;
1367 }
1368 break;
1369 case MESSAGE_REFRESH:
1370 refreshSilentMode();
1371 mAdapter.notifyDataSetChanged();
1372 break;
1373 case MESSAGE_SHOW:
1374 handleShow();
1375 break;
Jason Monk361915c2017-03-21 20:33:59 -04001376 }
1377 }
1378 };
1379
1380 private void onAirplaneModeChanged() {
1381 // Let the service state callbacks handle the state.
1382 if (mHasTelephony) return;
1383
1384 boolean airplaneModeOn = Settings.Global.getInt(
1385 mContext.getContentResolver(),
1386 Settings.Global.AIRPLANE_MODE_ON,
1387 0) == 1;
1388 mAirplaneState = airplaneModeOn ? ToggleAction.State.On : ToggleAction.State.Off;
1389 mAirplaneModeOn.updateState(mAirplaneState);
1390 }
1391
1392 /**
1393 * Change the airplane mode system setting
1394 */
1395 private void changeAirplaneModeSystemSetting(boolean on) {
1396 Settings.Global.putInt(
1397 mContext.getContentResolver(),
1398 Settings.Global.AIRPLANE_MODE_ON,
1399 on ? 1 : 0);
1400 Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
1401 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
1402 intent.putExtra("state", on);
1403 mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
1404 if (!mHasTelephony) {
1405 mAirplaneState = on ? ToggleAction.State.On : ToggleAction.State.Off;
1406 }
1407 }
1408
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001409 private static final class ActionsDialog extends Dialog implements DialogInterface,
1410 ColorExtractor.OnColorsChangedListener {
Jason Monk361915c2017-03-21 20:33:59 -04001411
Jason Monk16fbd9d2017-04-27 14:28:49 -04001412 private final Context mContext;
1413 private final MyAdapter mAdapter;
1414 private final LinearLayout mListView;
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +08001415 private final FrameLayout mSeparatedView;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001416 private final HardwareUiLayout mHardwareLayout;
1417 private final OnClickListener mClickListener;
1418 private final OnItemLongClickListener mLongClickListener;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001419 private final GradientDrawable mGradientDrawable;
1420 private final ColorExtractor mColorExtractor;
1421 private boolean mKeyguardShowing;
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +08001422 private boolean mShouldDisplaySeparatedButton;
Beverly526d2d62018-08-15 12:55:33 -04001423 private boolean mShowing;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001424
1425 public ActionsDialog(Context context, OnClickListener clickListener, MyAdapter adapter,
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +08001426 OnItemLongClickListener longClickListener, boolean shouldDisplaySeparatedButton) {
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001427 super(context, com.android.systemui.R.style.Theme_SystemUI_Dialog_GlobalActions);
Lucas Dupin448786c2017-07-24 17:44:25 -07001428 mContext = context;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001429 mAdapter = adapter;
1430 mClickListener = clickListener;
1431 mLongClickListener = longClickListener;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001432 mGradientDrawable = new GradientDrawable(mContext);
Lucas Dupin1ead7fc2017-05-24 14:14:44 -07001433 mColorExtractor = Dependency.get(SysuiColorExtractor.class);
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +08001434 mShouldDisplaySeparatedButton = shouldDisplaySeparatedButton;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001435
1436 // Window initialization
1437 Window window = getWindow();
1438 window.requestFeature(Window.FEATURE_NO_TITLE);
Adrian Roosedfab3b2018-03-08 18:39:20 +01001439 // Inflate the decor view, so the attributes below are not overwritten by the theme.
1440 window.getDecorView();
1441 window.getAttributes().systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1442 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1443 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1444 window.setLayout(MATCH_PARENT, MATCH_PARENT);
1445 window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
Alison Cichowlas4f19f4a2017-07-25 10:56:16 -04001446 window.addFlags(
1447 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001448 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
Adrian Roosedfab3b2018-03-08 18:39:20 +01001449 | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001450 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
1451 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
1452 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
1453 window.setBackgroundDrawable(mGradientDrawable);
1454 window.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY);
1455
Jason Monk16fbd9d2017-04-27 14:28:49 -04001456 setContentView(com.android.systemui.R.layout.global_actions_wrapped);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001457 mListView = findViewById(android.R.id.list);
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +08001458 mSeparatedView = findViewById(com.android.systemui.R.id.separated_button);
1459 if (!mShouldDisplaySeparatedButton) {
1460 mSeparatedView.setVisibility(View.GONE);
1461 }
Jason Monk16fbd9d2017-04-27 14:28:49 -04001462 mHardwareLayout = HardwareUiLayout.get(mListView);
1463 mHardwareLayout.setOutsideTouchListener(view -> dismiss());
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +08001464 mHardwareLayout.setHasSeparatedButton(mShouldDisplaySeparatedButton);
Phil Weaver8583ae82018-02-13 11:01:24 -08001465 setTitle(R.string.global_actions);
Phil Weaver9054e092018-04-27 16:28:50 -07001466 mListView.setAccessibilityDelegate(new View.AccessibilityDelegate() {
1467 @Override
1468 public boolean dispatchPopulateAccessibilityEvent(
1469 View host, AccessibilityEvent event) {
1470 // Populate the title here, just as Activity does
1471 event.getText().add(mContext.getString(R.string.global_actions));
1472 return true;
1473 }
1474 });
Jason Monk361915c2017-03-21 20:33:59 -04001475 }
1476
Jason Monk16fbd9d2017-04-27 14:28:49 -04001477 private void updateList() {
1478 mListView.removeAllViews();
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +08001479 mSeparatedView.removeAllViews();
Jason Monk16fbd9d2017-04-27 14:28:49 -04001480 for (int i = 0; i < mAdapter.getCount(); i++) {
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +08001481 ViewGroup parentView = mShouldDisplaySeparatedButton && i == mAdapter.getCount() - 1
1482 ? mSeparatedView : mListView;
1483 View v = mAdapter.getView(i, null, parentView);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001484 final int pos = i;
1485 v.setOnClickListener(view -> mClickListener.onClick(this, pos));
1486 v.setOnLongClickListener(view ->
1487 mLongClickListener.onItemLongClick(null, v, pos, 0));
Wesley.CW Wang3004fcb2018-06-15 16:24:57 +08001488 parentView.addView(v);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001489 }
Jason Monk361915c2017-03-21 20:33:59 -04001490 }
1491
1492 @Override
1493 protected void onStart() {
1494 super.setCanceledOnTouchOutside(true);
1495 super.onStart();
Jason Monk16fbd9d2017-04-27 14:28:49 -04001496 updateList();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001497
1498 Point displaySize = new Point();
1499 mContext.getDisplay().getRealSize(displaySize);
1500 mColorExtractor.addOnColorsChangedListener(this);
1501 mGradientDrawable.setScreenSize(displaySize.x, displaySize.y);
1502 GradientColors colors = mColorExtractor.getColors(mKeyguardShowing ?
1503 WallpaperManager.FLAG_LOCK : WallpaperManager.FLAG_SYSTEM);
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001504 updateColors(colors, false /* animate */);
1505 }
1506
1507 /**
1508 * Updates background and system bars according to current GradientColors.
1509 * @param colors Colors and hints to use.
1510 * @param animate Interpolates gradient if true, just sets otherwise.
1511 */
1512 private void updateColors(GradientColors colors, boolean animate) {
1513 mGradientDrawable.setColors(colors, animate);
1514 View decorView = getWindow().getDecorView();
1515 if (colors.supportsDarkText()) {
1516 decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR |
1517 View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
1518 } else {
1519 decorView.setSystemUiVisibility(0);
1520 }
Jason Monk361915c2017-03-21 20:33:59 -04001521 }
1522
1523 @Override
Jason Monk16fbd9d2017-04-27 14:28:49 -04001524 protected void onStop() {
1525 super.onStop();
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001526 mColorExtractor.removeOnColorsChangedListener(this);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001527 }
1528
1529 @Override
1530 public void show() {
1531 super.show();
Beverly526d2d62018-08-15 12:55:33 -04001532 mShowing = true;
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001533 mGradientDrawable.setAlpha(0);
Jason Monk16fbd9d2017-04-27 14:28:49 -04001534 mHardwareLayout.setTranslationX(getAnimTranslation());
1535 mHardwareLayout.setAlpha(0);
1536 mHardwareLayout.animate()
1537 .alpha(1)
1538 .translationX(0)
1539 .setDuration(300)
Lucas Dupinde9db422017-07-19 17:15:41 -07001540 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001541 .setUpdateListener(animation -> {
1542 int alpha = (int) ((Float) animation.getAnimatedValue()
1543 * ScrimController.GRADIENT_SCRIM_ALPHA * 255);
1544 mGradientDrawable.setAlpha(alpha);
1545 })
Jason Monka7af3b62017-07-07 11:35:13 -04001546 .withEndAction(() -> getWindow().getDecorView().requestAccessibilityFocus())
Jason Monk16fbd9d2017-04-27 14:28:49 -04001547 .start();
1548 }
1549
1550 @Override
1551 public void dismiss() {
Beverly526d2d62018-08-15 12:55:33 -04001552 if (!mShowing) {
1553 return;
1554 }
1555 mShowing = false;
Jason Monk16fbd9d2017-04-27 14:28:49 -04001556 mHardwareLayout.setTranslationX(0);
1557 mHardwareLayout.setAlpha(1);
1558 mHardwareLayout.animate()
1559 .alpha(0)
1560 .translationX(getAnimTranslation())
1561 .setDuration(300)
1562 .withEndAction(() -> super.dismiss())
1563 .setInterpolator(new LogAccelerateInterpolator())
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001564 .setUpdateListener(animation -> {
1565 int alpha = (int) ((1f - (Float) animation.getAnimatedValue())
1566 * ScrimController.GRADIENT_SCRIM_ALPHA * 255);
1567 mGradientDrawable.setAlpha(alpha);
1568 })
Jason Monk16fbd9d2017-04-27 14:28:49 -04001569 .start();
1570 }
1571
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001572 void dismissImmediately() {
1573 super.dismiss();
Beverly526d2d62018-08-15 12:55:33 -04001574 mShowing = false;
Lucas Dupin1d4a5792018-04-02 15:14:59 -07001575 }
1576
Jason Monk16fbd9d2017-04-27 14:28:49 -04001577 private float getAnimTranslation() {
1578 return getContext().getResources().getDimension(
1579 com.android.systemui.R.dimen.global_actions_panel_width) / 2;
Jason Monk361915c2017-03-21 20:33:59 -04001580 }
1581
1582 @Override
Lucas Dupin7aaa3532017-05-28 08:51:07 -07001583 public void onColorsChanged(ColorExtractor extractor, int which) {
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001584 if (mKeyguardShowing) {
1585 if ((WallpaperManager.FLAG_LOCK & which) != 0) {
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001586 updateColors(extractor.getColors(WallpaperManager.FLAG_LOCK),
1587 true /* animate */);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001588 }
1589 } else {
1590 if ((WallpaperManager.FLAG_SYSTEM & which) != 0) {
Lucas Dupinb5f59fe2017-09-14 17:09:39 -07001591 updateColors(extractor.getColors(WallpaperManager.FLAG_SYSTEM),
1592 true /* animate */);
Lucas Dupinc1cc7592017-05-22 15:56:16 -07001593 }
1594 }
1595 }
1596
1597 public void setKeyguardShowing(boolean keyguardShowing) {
1598 mKeyguardShowing = keyguardShowing;
1599 }
Jason Monk361915c2017-03-21 20:33:59 -04001600 }
1601}