blob: 1081bad9bf1c2d82fc5195f9b3d18bd29b716381 [file] [log] [blame]
Daniel Sandlerc4f2a562012-05-04 11:55:46 -04001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.systemui.statusbar.phone;
18
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070019import android.annotation.ColorInt;
20import android.annotation.DrawableRes;
21import android.annotation.LayoutRes;
John Spurlock257f2832013-09-21 18:41:53 -040022import android.app.StatusBarManager;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040023import android.content.Context;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070024import android.content.res.Configuration;
Adrian Roos2f2bd9a2015-06-04 18:11:14 -070025import android.content.res.TypedArray;
Daniel Sandler198a0302012-08-17 16:04:31 -040026import android.graphics.Canvas;
27import android.graphics.Paint;
Selim Cineka0fad3b2014-09-19 17:20:05 +020028import android.graphics.PorterDuff;
29import android.graphics.PorterDuffXfermode;
John Spurlockfba91202014-04-22 12:58:26 -040030import android.graphics.Rect;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070031import android.graphics.drawable.Drawable;
Issei Suzukica19e6e2019-02-26 12:39:11 +010032import android.hardware.display.AmbientDisplayConfiguration;
Jaewan Kim50269362016-12-23 11:22:02 +090033import android.media.AudioManager;
John Spurlock0b99ea92014-10-01 15:32:22 -040034import android.media.session.MediaSessionLegacyHelper;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070035import android.net.Uri;
36import android.os.Bundle;
Adrian Roos8008bd12017-02-22 15:02:09 +010037import android.os.SystemClock;
Lucas Dupin34f6d962019-02-22 14:47:50 -080038import android.os.UserHandle;
39import android.provider.Settings;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040040import android.util.AttributeSet;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070041import android.view.ActionMode;
felkachang7749c9a2018-06-11 15:56:15 +080042import android.view.DisplayCutout;
Lucas Dupin34f6d962019-02-22 14:47:50 -080043import android.view.GestureDetector;
Selim Cinek48a92a52017-05-02 20:02:30 -070044import android.view.InputDevice;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070045import android.view.InputQueue;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040046import android.view.KeyEvent;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070047import android.view.LayoutInflater;
48import android.view.Menu;
49import android.view.MenuItem;
Chris Wren5de6e942012-05-16 14:22:21 -040050import android.view.MotionEvent;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070051import android.view.SurfaceHolder;
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070052import android.view.View;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070053import android.view.ViewGroup;
54import android.view.ViewTreeObserver;
55import android.view.Window;
Jorim Jaggib6030952018-10-23 18:31:52 +020056import android.view.WindowInsetsController;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040057import android.widget.FrameLayout;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -040058
Selim Cinekf8c4add2017-06-08 09:54:58 -070059import com.android.internal.annotations.VisibleForTesting;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070060import com.android.internal.view.FloatingActionMode;
61import com.android.internal.widget.FloatingToolbar;
Jason Monk1fd3fc32018-08-14 17:20:09 -040062import com.android.systemui.Dependency;
Aaron Heuckrothcd944dc2018-10-01 16:31:08 -040063import com.android.systemui.ExpandHelper;
Chris Wren5de6e942012-05-16 14:22:21 -040064import com.android.systemui.R;
Dave Mankoffdde5ee62019-05-02 17:36:11 -040065import com.android.systemui.classifier.FalsingManagerFactory;
Dave Mankoff468d4f62019-05-08 14:56:29 -040066import com.android.systemui.plugins.FalsingManager;
Beverly8fdb5332019-02-04 14:29:49 -050067import com.android.systemui.plugins.statusbar.StatusBarStateController;
Jorim Jaggiecbab362014-04-23 16:13:15 +020068import com.android.systemui.statusbar.DragDownHelper;
69import com.android.systemui.statusbar.StatusBarState;
Selim Cinek5454a0d2019-07-30 17:14:50 -070070import com.android.systemui.statusbar.notification.DynamicPrivacyController;
Rohan Shah20790b82018-07-02 17:21:04 -070071import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout;
Lucas Dupincdbb1cb2019-05-16 19:48:30 -070072import com.android.systemui.statusbar.phone.ScrimController.ScrimVisibility;
Lucas Dupin34f6d962019-02-22 14:47:50 -080073import com.android.systemui.tuner.TunerService;
Chris Wren5de6e942012-05-16 14:22:21 -040074
Selim Cinekfc5c1992018-01-29 12:40:32 -080075import java.io.FileDescriptor;
76import java.io.PrintWriter;
77
Lucas Dupin34f6d962019-02-22 14:47:50 -080078/**
79 * Combined status bar and notification panel view. Also holding backdrop and scrims.
80 */
Jorim Jaggiecbab362014-04-23 16:13:15 +020081public class StatusBarWindowView extends FrameLayout {
Daniel Sandler198a0302012-08-17 16:04:31 -040082 public static final String TAG = "StatusBarWindowView";
Jason Monk2a6ea9c2017-01-26 11:14:51 -050083 public static final boolean DEBUG = StatusBar.DEBUG;
Chris Wren5de6e942012-05-16 14:22:21 -040084
Lucas Dupin34f6d962019-02-22 14:47:50 -080085 private final GestureDetector mGestureDetector;
86 private final StatusBarStateController mStatusBarStateController;
87 private boolean mDoubleTapEnabled;
88 private boolean mSingleTapEnabled;
Jorim Jaggiecbab362014-04-23 16:13:15 +020089 private DragDownHelper mDragDownHelper;
Selim Cinekb6d85eb2014-03-28 20:21:01 +010090 private NotificationStackScrollLayout mStackScrollLayout;
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -070091 private NotificationPanelView mNotificationPanel;
Adrian Roos9dc32092014-09-02 23:34:10 +020092 private View mBrightnessMirror;
Lucas Dupin2e838ac2019-04-17 16:50:58 -070093 private LockIcon mLockIcon;
Jorim Jaggif0c38072018-06-19 17:27:08 +020094 private PhoneStatusBarView mStatusBarView;
Chris Wren5de6e942012-05-16 14:22:21 -040095
Adrian Roos2f2bd9a2015-06-04 18:11:14 -070096 private int mRightInset = 0;
Adrian Roos85d202b2016-06-02 16:27:47 -070097 private int mLeftInset = 0;
Adrian Roos2f2bd9a2015-06-04 18:11:14 -070098
Jason Monk2a6ea9c2017-01-26 11:14:51 -050099 private StatusBar mService;
Selim Cineka0fad3b2014-09-19 17:20:05 +0200100 private final Paint mTransparentSrcPaint = new Paint();
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700101 private FalsingManager mFalsingManager;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400102
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700103 // Implements the floating action mode for TextView's Cut/Copy/Past menu. Normally provided by
104 // DecorView, but since this is a special window we have to roll our own.
105 private View mFloatingActionModeOriginatingView;
106 private ActionMode mFloatingActionMode;
107 private FloatingToolbar mFloatingToolbar;
108 private ViewTreeObserver.OnPreDrawListener mFloatingToolbarPreDrawListener;
Selim Cinek48a92a52017-05-02 20:02:30 -0700109 private boolean mTouchCancelled;
110 private boolean mTouchActive;
Selim Cinek2627d722018-01-19 12:16:49 -0800111 private boolean mExpandAnimationRunning;
Selim Cinek7e222c3c2018-01-25 12:22:41 -0800112 private boolean mExpandAnimationPending;
Jerry Changf89d8572019-04-18 11:09:13 +0800113 private boolean mSuppressingWakeUpGesture;
Lucas Dupin34f6d962019-02-22 14:47:50 -0800114
115 private final GestureDetector.SimpleOnGestureListener mGestureListener =
116 new GestureDetector.SimpleOnGestureListener() {
117 @Override
118 public boolean onSingleTapConfirmed(MotionEvent e) {
Jerry Changf89d8572019-04-18 11:09:13 +0800119 if (mSingleTapEnabled && !mSuppressingWakeUpGesture) {
Lucas Dupin34f6d962019-02-22 14:47:50 -0800120 mService.wakeUpIfDozing(SystemClock.uptimeMillis(), StatusBarWindowView.this,
121 "SINGLE_TAP");
Lucas Dupin3bab3d82019-03-22 14:38:28 -0700122 return true;
Lucas Dupin34f6d962019-02-22 14:47:50 -0800123 }
Lucas Dupin3bab3d82019-03-22 14:38:28 -0700124 return false;
Lucas Dupin34f6d962019-02-22 14:47:50 -0800125 }
126
127 @Override
128 public boolean onDoubleTap(MotionEvent e) {
Lucas Dupin3bab3d82019-03-22 14:38:28 -0700129 if (mDoubleTapEnabled || mSingleTapEnabled) {
Lucas Dupin34f6d962019-02-22 14:47:50 -0800130 mService.wakeUpIfDozing(SystemClock.uptimeMillis(), StatusBarWindowView.this,
131 "DOUBLE_TAP");
Lucas Dupin3bab3d82019-03-22 14:38:28 -0700132 return true;
Lucas Dupin34f6d962019-02-22 14:47:50 -0800133 }
Lucas Dupin3bab3d82019-03-22 14:38:28 -0700134 return false;
Lucas Dupin34f6d962019-02-22 14:47:50 -0800135 }
136 };
137 private final TunerService.Tunable mTunable = (key, newValue) -> {
138 AmbientDisplayConfiguration configuration = new AmbientDisplayConfiguration(mContext);
139 switch (key) {
140 case Settings.Secure.DOZE_DOUBLE_TAP_GESTURE:
141 mDoubleTapEnabled = configuration.doubleTapGestureEnabled(UserHandle.USER_CURRENT);
142 break;
143 case Settings.Secure.DOZE_TAP_SCREEN_GESTURE:
144 mSingleTapEnabled = configuration.tapGestureEnabled(UserHandle.USER_CURRENT);
145 }
146 };
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700147
Jorim Jaggi0d4a9952018-06-06 17:22:56 +0200148 /**
149 * If set to true, the current gesture started below the notch and we need to dispatch touch
150 * events manually as it's outside of the regular view bounds.
151 */
152 private boolean mExpandingBelowNotch;
Selim Cinekb8cc6ef2019-06-14 16:37:53 -0700153 private KeyguardBypassController mBypassController;
Jorim Jaggi0d4a9952018-06-06 17:22:56 +0200154
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400155 public StatusBarWindowView(Context context, AttributeSet attrs) {
156 super(context, attrs);
Chris Wren5de6e942012-05-16 14:22:21 -0400157 setMotionEventSplittingEnabled(false);
Selim Cineka0fad3b2014-09-19 17:20:05 +0200158 mTransparentSrcPaint.setColor(0);
159 mTransparentSrcPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
Dave Mankoffdde5ee62019-05-02 17:36:11 -0400160 mFalsingManager = FalsingManagerFactory.getInstance(context);
Lucas Dupin34f6d962019-02-22 14:47:50 -0800161 mGestureDetector = new GestureDetector(context, mGestureListener);
162 mStatusBarStateController = Dependency.get(StatusBarStateController.class);
163 Dependency.get(TunerService.class).addTunable(mTunable,
164 Settings.Secure.DOZE_DOUBLE_TAP_GESTURE,
165 Settings.Secure.DOZE_TAP_SCREEN_GESTURE);
Chris Wren5de6e942012-05-16 14:22:21 -0400166 }
167
168 @Override
John Spurlockfba91202014-04-22 12:58:26 -0400169 protected boolean fitSystemWindows(Rect insets) {
170 if (getFitsSystemWindows()) {
Adrian Roos85d202b2016-06-02 16:27:47 -0700171 boolean paddingChanged = insets.top != getPaddingTop()
Jorim Jaggi416493b2014-09-13 03:57:32 +0200172 || insets.bottom != getPaddingBottom();
Jorim Jaggiaa806142015-05-20 18:04:16 -0700173
felkachang7749c9a2018-06-11 15:56:15 +0800174 int rightCutout = 0;
175 int leftCutout = 0;
176 DisplayCutout displayCutout = getRootWindowInsets().getDisplayCutout();
177 if (displayCutout != null) {
178 leftCutout = displayCutout.getSafeInsetLeft();
179 rightCutout = displayCutout.getSafeInsetRight();
180 }
181
182 int targetLeft = Math.max(insets.left, leftCutout);
183 int targetRight = Math.max(insets.right, rightCutout);
184
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700185 // Super-special right inset handling, because scrims and backdrop need to ignore it.
felkachang7749c9a2018-06-11 15:56:15 +0800186 if (targetRight != mRightInset || targetLeft != mLeftInset) {
187 mRightInset = targetRight;
188 mLeftInset = targetLeft;
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700189 applyMargins();
190 }
Adrian Roos85d202b2016-06-02 16:27:47 -0700191 // Drop top inset, and pass through bottom inset.
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700192 if (paddingChanged) {
Adrian Roos85d202b2016-06-02 16:27:47 -0700193 setPadding(0, 0, 0, 0);
Jorim Jaggi416493b2014-09-13 03:57:32 +0200194 }
Jorim Jaggid7daab72014-05-06 22:22:20 +0200195 insets.left = 0;
196 insets.top = 0;
197 insets.right = 0;
John Spurlockfba91202014-04-22 12:58:26 -0400198 } else {
Adrian Roos85d202b2016-06-02 16:27:47 -0700199 if (mRightInset != 0 || mLeftInset != 0) {
Adrian Roose49e4092015-06-10 18:50:18 -0700200 mRightInset = 0;
Adrian Roos85d202b2016-06-02 16:27:47 -0700201 mLeftInset = 0;
Adrian Roose49e4092015-06-10 18:50:18 -0700202 applyMargins();
203 }
Jorim Jaggi416493b2014-09-13 03:57:32 +0200204 boolean changed = getPaddingLeft() != 0
205 || getPaddingRight() != 0
206 || getPaddingTop() != 0
207 || getPaddingBottom() != 0;
208 if (changed) {
209 setPadding(0, 0, 0, 0);
210 }
Jorim Jaggiaa806142015-05-20 18:04:16 -0700211 insets.top = 0;
John Spurlockfba91202014-04-22 12:58:26 -0400212 }
Jorim Jaggid7daab72014-05-06 22:22:20 +0200213 return false;
John Spurlockfba91202014-04-22 12:58:26 -0400214 }
215
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700216 private void applyMargins() {
217 final int N = getChildCount();
218 for (int i = 0; i < N; i++) {
219 View child = getChildAt(i);
220 if (child.getLayoutParams() instanceof LayoutParams) {
221 LayoutParams lp = (LayoutParams) child.getLayoutParams();
Adrian Roos85d202b2016-06-02 16:27:47 -0700222 if (!lp.ignoreRightInset
223 && (lp.rightMargin != mRightInset || lp.leftMargin != mLeftInset)) {
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700224 lp.rightMargin = mRightInset;
Adrian Roos85d202b2016-06-02 16:27:47 -0700225 lp.leftMargin = mLeftInset;
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700226 child.requestLayout();
227 }
228 }
229 }
230 }
231
Aaron Heuckrothcd944dc2018-10-01 16:31:08 -0400232 @VisibleForTesting
233 protected NotificationStackScrollLayout getStackScrollLayout() {
234 return mStackScrollLayout;
235 }
236
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700237 @Override
238 public FrameLayout.LayoutParams generateLayoutParams(AttributeSet attrs) {
239 return new LayoutParams(getContext(), attrs);
240 }
241
242 @Override
243 protected FrameLayout.LayoutParams generateDefaultLayoutParams() {
244 return new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
245 }
246
John Spurlockfba91202014-04-22 12:58:26 -0400247 @Override
Selim Cinek4e6b2d32015-06-25 20:15:33 -0400248 protected void onFinishInflate() {
249 super.onFinishInflate();
Lucas Dupin2e838ac2019-04-17 16:50:58 -0700250 mStackScrollLayout = findViewById(R.id.notification_stack_scroller);
251 mNotificationPanel = findViewById(R.id.notification_panel);
Adrian Roos9dc32092014-09-02 23:34:10 +0200252 mBrightnessMirror = findViewById(R.id.brightness_mirror);
Lucas Dupin2e838ac2019-04-17 16:50:58 -0700253 mLockIcon = findViewById(R.id.lock_icon);
Selim Cinek4e6b2d32015-06-25 20:15:33 -0400254 }
255
dooyoung.hwange4b841e2016-11-16 08:59:23 +0900256 @Override
257 public void onViewAdded(View child) {
258 super.onViewAdded(child);
259 if (child.getId() == R.id.brightness_mirror) {
260 mBrightnessMirror = child;
261 }
262 }
263
Lucas Dupin2e838ac2019-04-17 16:50:58 -0700264 /**
265 * Propagate {@link StatusBar} pulsing state.
266 */
267 public void setPulsing(boolean pulsing) {
Lucas Dupin2d336632019-05-14 12:13:26 -0700268 if (mLockIcon != null) {
269 mLockIcon.setPulsing(pulsing);
270 }
Lucas Dupin2e838ac2019-04-17 16:50:58 -0700271 }
272
Lucas Dupin71f38042019-05-10 16:23:04 -0700273 /**
274 * Called when the biometric authentication mode changes.
275 * @param wakeAndUnlock If the type is {@link BiometricUnlockController#isWakeAndUnlock()}
Selim Cinek390f1b92019-06-28 18:07:28 -0700276 * @param isUnlock If the type is {@link BiometricUnlockController#isBiometricUnlock()} ()
Lucas Dupin71f38042019-05-10 16:23:04 -0700277 */
Selim Cinek390f1b92019-06-28 18:07:28 -0700278 public void onBiometricAuthModeChanged(boolean wakeAndUnlock, boolean isUnlock) {
Lucas Dupin2d336632019-05-14 12:13:26 -0700279 if (mLockIcon != null) {
Selim Cinek390f1b92019-06-28 18:07:28 -0700280 mLockIcon.onBiometricAuthModeChanged(wakeAndUnlock, isUnlock);
Lucas Dupin2d336632019-05-14 12:13:26 -0700281 }
Lucas Dupin71f38042019-05-10 16:23:04 -0700282 }
283
Jorim Jaggif0c38072018-06-19 17:27:08 +0200284 public void setStatusBarView(PhoneStatusBarView statusBarView) {
285 mStatusBarView = statusBarView;
286 }
287
Jason Monk2a6ea9c2017-01-26 11:14:51 -0500288 public void setService(StatusBar service) {
Selim Cinek4e6b2d32015-06-25 20:15:33 -0400289 mService = service;
Aaron Heuckrothcd944dc2018-10-01 16:31:08 -0400290 NotificationStackScrollLayout stackScrollLayout = getStackScrollLayout();
291 ExpandHelper.Callback expandHelperCallback = stackScrollLayout.getExpandHelperCallback();
292 DragDownHelper.DragDownCallback dragDownCallback = stackScrollLayout.getDragDownCallback();
293 setDragDownHelper(new DragDownHelper(getContext(), this, expandHelperCallback,
294 dragDownCallback));
Selim Cinekf8c4add2017-06-08 09:54:58 -0700295 }
296
297 @VisibleForTesting
298 void setDragDownHelper(DragDownHelper dragDownHelper) {
299 mDragDownHelper = dragDownHelper;
Selim Cinek4e6b2d32015-06-25 20:15:33 -0400300 }
301
302 @Override
303 protected void onAttachedToWindow () {
304 super.onAttachedToWindow();
Lucas Dupin90a38dd2018-09-05 09:37:37 -0700305 setWillNotDraw(!DEBUG);
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400306 }
307
308 @Override
309 public boolean dispatchKeyEvent(KeyEvent event) {
Adrian Roos56cf73a2016-07-18 14:23:32 -0700310 if (mService.interceptMediaKey(event)) {
311 return true;
312 }
313 if (super.dispatchKeyEvent(event)) {
314 return true;
315 }
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400316 boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
317 switch (event.getKeyCode()) {
Jorim Jaggi8c8bcc12014-04-16 21:36:51 +0200318 case KeyEvent.KEYCODE_BACK:
319 if (!down) {
320 mService.onBackPressed();
321 }
322 return true;
323 case KeyEvent.KEYCODE_MENU:
324 if (!down) {
325 return mService.onMenuPressed();
326 }
Jorim Jaggi34250762014-07-03 23:51:19 +0200327 case KeyEvent.KEYCODE_SPACE:
328 if (!down) {
329 return mService.onSpacePressed();
330 }
John Spurlock0b99ea92014-10-01 15:32:22 -0400331 break;
John Spurlockd06aa572014-09-10 10:40:49 -0400332 case KeyEvent.KEYCODE_VOLUME_DOWN:
333 case KeyEvent.KEYCODE_VOLUME_UP:
John Spurlock0b99ea92014-10-01 15:32:22 -0400334 if (mService.isDozing()) {
Jaewan Kim50269362016-12-23 11:22:02 +0900335 MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent(
336 event, AudioManager.USE_DEFAULT_STREAM_TYPE, true);
John Spurlock0b99ea92014-10-01 15:32:22 -0400337 return true;
John Spurlockd06aa572014-09-10 10:40:49 -0400338 }
John Spurlock0b99ea92014-10-01 15:32:22 -0400339 break;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400340 }
Adrian Roos56cf73a2016-07-18 14:23:32 -0700341 return false;
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400342 }
Chris Wren5de6e942012-05-16 14:22:21 -0400343
Selim Cinekd95ca7c2017-07-26 12:20:38 -0700344 public void setTouchActive(boolean touchActive) {
345 mTouchActive = touchActive;
Selim Cinekd95ca7c2017-07-26 12:20:38 -0700346 }
347
Jerry Changf89d8572019-04-18 11:09:13 +0800348 void suppressWakeUpGesture(boolean suppress) {
349 mSuppressingWakeUpGesture = suppress;
350 }
351
Chris Wren5de6e942012-05-16 14:22:21 -0400352 @Override
Adrian Roos9dc32092014-09-02 23:34:10 +0200353 public boolean dispatchTouchEvent(MotionEvent ev) {
Selim Cinek48a92a52017-05-02 20:02:30 -0700354 boolean isDown = ev.getActionMasked() == MotionEvent.ACTION_DOWN;
Jorim Jaggi0d4a9952018-06-06 17:22:56 +0200355 boolean isUp = ev.getActionMasked() == MotionEvent.ACTION_UP;
Adrian Roosa6c03f82017-07-26 16:20:30 +0200356 boolean isCancel = ev.getActionMasked() == MotionEvent.ACTION_CANCEL;
Jorim Jaggi0d4a9952018-06-06 17:22:56 +0200357
358 // Reset manual touch dispatch state here but make sure the UP/CANCEL event still gets
359 // delivered.
360 boolean expandingBelowNotch = mExpandingBelowNotch;
361 if (isUp || isCancel) {
362 mExpandingBelowNotch = false;
363 }
364
Adrian Roosa6c03f82017-07-26 16:20:30 +0200365 if (!isCancel && mService.shouldIgnoreTouch()) {
366 return false;
367 }
Selim Cinek48a92a52017-05-02 20:02:30 -0700368 if (isDown && mNotificationPanel.isFullyCollapsed()) {
Jorim Jaggie05256e2016-09-08 14:58:20 -0700369 mNotificationPanel.startExpandLatencyTracking();
370 }
Selim Cinek48a92a52017-05-02 20:02:30 -0700371 if (isDown) {
Selim Cinekd95ca7c2017-07-26 12:20:38 -0700372 setTouchActive(true);
Selim Cinek48a92a52017-05-02 20:02:30 -0700373 mTouchCancelled = false;
374 } else if (ev.getActionMasked() == MotionEvent.ACTION_UP
375 || ev.getActionMasked() == MotionEvent.ACTION_CANCEL) {
Selim Cinekd95ca7c2017-07-26 12:20:38 -0700376 setTouchActive(false);
Selim Cinek48a92a52017-05-02 20:02:30 -0700377 }
Selim Cinek7e222c3c2018-01-25 12:22:41 -0800378 if (mTouchCancelled || mExpandAnimationRunning || mExpandAnimationPending) {
Selim Cinek48a92a52017-05-02 20:02:30 -0700379 return false;
380 }
Blazej Magnowski0e2ffbd2015-09-10 14:37:17 -0700381 mFalsingManager.onTouchEvent(ev, getWidth(), getHeight());
Lucas Dupin34f6d962019-02-22 14:47:50 -0800382 mGestureDetector.onTouchEvent(ev);
Adrian Roos9dc32092014-09-02 23:34:10 +0200383 if (mBrightnessMirror != null && mBrightnessMirror.getVisibility() == VISIBLE) {
384 // Disallow new pointers while the brightness mirror is visible. This is so that you
385 // can't touch anything other than the brightness slider while the mirror is showing
386 // and the rest of the panel is transparent.
387 if (ev.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) {
388 return false;
389 }
390 }
Selim Cinek48a92a52017-05-02 20:02:30 -0700391 if (isDown) {
Aaron Heuckrothcd944dc2018-10-01 16:31:08 -0400392 getStackScrollLayout().closeControlsIfOutsideTouch(ev);
Mady Mellor7a9b2a62016-03-23 07:41:47 -0700393 }
Adrian Roos67cca742017-04-13 16:52:51 -0700394 if (mService.isDozing()) {
395 mService.mDozeScrimController.extendPulse();
396 }
Mady Mellor7a9b2a62016-03-23 07:41:47 -0700397
Jorim Jaggi0d4a9952018-06-06 17:22:56 +0200398 // In case we start outside of the view bounds (below the status bar), we need to dispatch
399 // the touch manually as the view system can't accomodate for touches outside of the
400 // regular view bounds.
401 if (isDown && ev.getY() >= mBottom) {
402 mExpandingBelowNotch = true;
403 expandingBelowNotch = true;
404 }
405 if (expandingBelowNotch) {
Jorim Jaggif0c38072018-06-19 17:27:08 +0200406 return mStatusBarView.dispatchTouchEvent(ev);
Jorim Jaggi0d4a9952018-06-06 17:22:56 +0200407 }
408
Adrian Roos9dc32092014-09-02 23:34:10 +0200409 return super.dispatchTouchEvent(ev);
410 }
411
412 @Override
Chris Wren5de6e942012-05-16 14:22:21 -0400413 public boolean onInterceptTouchEvent(MotionEvent ev) {
Aaron Heuckrothcd944dc2018-10-01 16:31:08 -0400414 NotificationStackScrollLayout stackScrollLayout = getStackScrollLayout();
Lucas Dupin1c327432019-01-03 13:37:53 -0800415 if (mService.isDozing() && !mService.isPulsing()) {
Adrian Roos8008bd12017-02-22 15:02:09 +0100416 // Capture all touch events in always-on.
Adrian Roosebea7a72016-10-26 12:51:26 -0700417 return true;
418 }
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700419 boolean intercept = false;
Selim Cinekfab078b2014-03-27 22:45:58 +0100420 if (mNotificationPanel.isFullyExpanded()
Selim Cinek5454a0d2019-07-30 17:14:50 -0700421 && mDragDownHelper.isDragDownEnabled()
Selim Cinek3d6ae232019-01-04 14:14:33 -0800422 && !mService.isBouncerShowing()
423 && !mService.isDozing()) {
Jorim Jaggiecbab362014-04-23 16:13:15 +0200424 intercept = mDragDownHelper.onInterceptTouchEvent(ev);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700425 }
426 if (!intercept) {
427 super.onInterceptTouchEvent(ev);
428 }
Chris Wren5de6e942012-05-16 14:22:21 -0400429 if (intercept) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700430 MotionEvent cancellation = MotionEvent.obtain(ev);
431 cancellation.setAction(MotionEvent.ACTION_CANCEL);
Aaron Heuckrothcd944dc2018-10-01 16:31:08 -0400432 stackScrollLayout.onInterceptTouchEvent(cancellation);
Selim Cinek31094df2014-08-14 19:28:15 +0200433 mNotificationPanel.onInterceptTouchEvent(cancellation);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700434 cancellation.recycle();
Chris Wren5de6e942012-05-16 14:22:21 -0400435 }
436 return intercept;
437 }
438
439 @Override
440 public boolean onTouchEvent(MotionEvent ev) {
Adrian Roos8008bd12017-02-22 15:02:09 +0100441 boolean handled = false;
442 if (mService.isDozing()) {
Lucas Dupin1c327432019-01-03 13:37:53 -0800443 handled = !mService.isPulsing();
Adrian Roos8008bd12017-02-22 15:02:09 +0100444 }
Selim Cinek5454a0d2019-07-30 17:14:50 -0700445 if ((mDragDownHelper.isDragDownEnabled() && !handled) || mDragDownHelper.isDraggingDown()) {
Selim Cinek740c1112016-12-22 16:39:54 +0100446 // we still want to finish our drag down gesture when locking the screen
Jorim Jaggiecbab362014-04-23 16:13:15 +0200447 handled = mDragDownHelper.onTouchEvent(ev);
Daniel Sandlerb4e56ed2012-09-12 23:07:44 -0700448 }
449 if (!handled) {
450 handled = super.onTouchEvent(ev);
451 }
John Spurlock257f2832013-09-21 18:41:53 -0400452 final int action = ev.getAction();
John Spurlockd157ca02013-11-04 10:28:05 -0500453 if (!handled && (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL)) {
John Spurlock257f2832013-09-21 18:41:53 -0400454 mService.setInteracting(StatusBarManager.WINDOW_STATUS_BAR, false);
455 }
Chris Wren5de6e942012-05-16 14:22:21 -0400456 return handled;
457 }
Daniel Sandler198a0302012-08-17 16:04:31 -0400458
459 @Override
460 public void onDraw(Canvas canvas) {
461 super.onDraw(canvas);
462 if (DEBUG) {
463 Paint pt = new Paint();
464 pt.setColor(0x80FFFF00);
465 pt.setStrokeWidth(12.0f);
466 pt.setStyle(Paint.Style.STROKE);
467 canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt);
468 }
469 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400470
471 public void cancelExpandHelper() {
Aaron Heuckrothcd944dc2018-10-01 16:31:08 -0400472 NotificationStackScrollLayout stackScrollLayout = getStackScrollLayout();
473 if (stackScrollLayout != null) {
474 stackScrollLayout.cancelExpandHelper();
Daniel Sandler1a3bdd52012-10-23 19:21:20 -0400475 }
Daniel Sandlerac47ff72012-10-23 10:41:44 -0400476 }
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700477
Selim Cinek48a92a52017-05-02 20:02:30 -0700478 public void cancelCurrentTouch() {
479 if (mTouchActive) {
480 final long now = SystemClock.uptimeMillis();
481 MotionEvent event = MotionEvent.obtain(now, now,
482 MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0);
483 event.setSource(InputDevice.SOURCE_TOUCHSCREEN);
484 dispatchTouchEvent(event);
485 event.recycle();
486 mTouchCancelled = true;
487 }
488 }
489
Selim Cinek2627d722018-01-19 12:16:49 -0800490 public void setExpandAnimationRunning(boolean expandAnimationRunning) {
491 mExpandAnimationRunning = expandAnimationRunning;
492 }
493
Selim Cinek7e222c3c2018-01-25 12:22:41 -0800494 public void setExpandAnimationPending(boolean pending) {
495 mExpandAnimationPending = pending;
496 }
497
Selim Cinekfc5c1992018-01-29 12:40:32 -0800498 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
499 pw.print(" mExpandAnimationPending="); pw.println(mExpandAnimationPending);
500 pw.print(" mExpandAnimationRunning="); pw.println(mExpandAnimationRunning);
501 pw.print(" mTouchCancelled="); pw.println(mTouchCancelled);
502 pw.print(" mTouchActive="); pw.println(mTouchActive);
503 }
504
Lucas Dupincdbb1cb2019-05-16 19:48:30 -0700505 /**
506 * Called whenever the scrims become opaque, transparent or semi-transparent.
507 */
508 public void onScrimVisibilityChanged(@ScrimVisibility int scrimsVisible) {
509 if (mLockIcon != null) {
510 mLockIcon.onScrimVisibilityChanged(scrimsVisible);
511 }
512 }
513
Lucas Dupin23964c72019-05-21 16:12:45 -0700514 /**
515 * When we're launching an affordance, like double pressing power to open camera.
516 */
517 public void onShowingLaunchAffordanceChanged(boolean showing) {
518 if (mLockIcon != null) {
519 mLockIcon.onShowingLaunchAffordanceChanged(showing);
520 }
521 }
522
Selim Cinekb8cc6ef2019-06-14 16:37:53 -0700523 public void setBypassController(KeyguardBypassController bypassController) {
524 mBypassController = bypassController;
525 }
526
Selim Cinek60ee7fd2019-06-26 13:06:00 -0700527 public void setBouncerShowingScrimmed(boolean bouncerShowing) {
Selim Cinek820ba2d2019-06-18 18:59:09 -0700528 if (mLockIcon != null) {
Selim Cinek60ee7fd2019-06-26 13:06:00 -0700529 mLockIcon.setBouncerShowingScrimmed(bouncerShowing);
Selim Cinek820ba2d2019-06-18 18:59:09 -0700530 }
531 }
532
Adrian Roos2f2bd9a2015-06-04 18:11:14 -0700533 public class LayoutParams extends FrameLayout.LayoutParams {
534
535 public boolean ignoreRightInset;
536
537 public LayoutParams(int width, int height) {
538 super(width, height);
539 }
540
541 public LayoutParams(Context c, AttributeSet attrs) {
542 super(c, attrs);
543
544 TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.StatusBarWindowView_Layout);
545 ignoreRightInset = a.getBoolean(
546 R.styleable.StatusBarWindowView_Layout_ignoreRightInset, false);
547 a.recycle();
548 }
549 }
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700550
551 @Override
552 public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback,
553 int type) {
554 if (type == ActionMode.TYPE_FLOATING) {
555 return startActionMode(originalView, callback, type);
556 }
557 return super.startActionModeForChild(originalView, callback, type);
558 }
559
560 private ActionMode createFloatingActionMode(
561 View originatingView, ActionMode.Callback2 callback) {
562 if (mFloatingActionMode != null) {
563 mFloatingActionMode.finish();
564 }
565 cleanupFloatingActionModeViews();
Tarandeep Singhc9c83a92017-08-29 14:39:22 -0700566 mFloatingToolbar = new FloatingToolbar(mFakeWindow);
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700567 final FloatingActionMode mode =
Abodunrinwa Toki17293cc2017-05-22 14:16:04 +0100568 new FloatingActionMode(mContext, callback, originatingView, mFloatingToolbar);
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700569 mFloatingActionModeOriginatingView = originatingView;
570 mFloatingToolbarPreDrawListener =
571 new ViewTreeObserver.OnPreDrawListener() {
572 @Override
573 public boolean onPreDraw() {
574 mode.updateViewLocationInWindow();
575 return true;
576 }
577 };
578 return mode;
579 }
580
581 private void setHandledFloatingActionMode(ActionMode mode) {
582 mFloatingActionMode = mode;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700583 mFloatingActionMode.invalidate(); // Will show the floating toolbar if necessary.
584 mFloatingActionModeOriginatingView.getViewTreeObserver()
585 .addOnPreDrawListener(mFloatingToolbarPreDrawListener);
586 }
587
588 private void cleanupFloatingActionModeViews() {
589 if (mFloatingToolbar != null) {
590 mFloatingToolbar.dismiss();
591 mFloatingToolbar = null;
592 }
593 if (mFloatingActionModeOriginatingView != null) {
594 if (mFloatingToolbarPreDrawListener != null) {
595 mFloatingActionModeOriginatingView.getViewTreeObserver()
596 .removeOnPreDrawListener(mFloatingToolbarPreDrawListener);
597 mFloatingToolbarPreDrawListener = null;
598 }
599 mFloatingActionModeOriginatingView = null;
600 }
601 }
602
603 private ActionMode startActionMode(
604 View originatingView, ActionMode.Callback callback, int type) {
605 ActionMode.Callback2 wrappedCallback = new ActionModeCallback2Wrapper(callback);
606 ActionMode mode = createFloatingActionMode(originatingView, wrappedCallback);
607 if (mode != null && wrappedCallback.onCreateActionMode(mode, mode.getMenu())) {
608 setHandledFloatingActionMode(mode);
609 } else {
610 mode = null;
611 }
612 return mode;
613 }
614
615 private class ActionModeCallback2Wrapper extends ActionMode.Callback2 {
616 private final ActionMode.Callback mWrapped;
617
618 public ActionModeCallback2Wrapper(ActionMode.Callback wrapped) {
619 mWrapped = wrapped;
620 }
621
622 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
623 return mWrapped.onCreateActionMode(mode, menu);
624 }
625
626 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
627 requestFitSystemWindows();
628 return mWrapped.onPrepareActionMode(mode, menu);
629 }
630
631 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
632 return mWrapped.onActionItemClicked(mode, item);
633 }
634
635 public void onDestroyActionMode(ActionMode mode) {
636 mWrapped.onDestroyActionMode(mode);
637 if (mode == mFloatingActionMode) {
638 cleanupFloatingActionModeViews();
639 mFloatingActionMode = null;
640 }
641 requestFitSystemWindows();
642 }
643
644 @Override
645 public void onGetContentRect(ActionMode mode, View view, Rect outRect) {
646 if (mWrapped instanceof ActionMode.Callback2) {
647 ((ActionMode.Callback2) mWrapped).onGetContentRect(mode, view, outRect);
648 } else {
649 super.onGetContentRect(mode, view, outRect);
650 }
651 }
652 }
653
654 /**
655 * Minimal window to satisfy FloatingToolbar.
656 */
657 private Window mFakeWindow = new Window(mContext) {
658 @Override
659 public void takeSurface(SurfaceHolder.Callback2 callback) {
660 }
661
662 @Override
663 public void takeInputQueue(InputQueue.Callback callback) {
664 }
665
666 @Override
667 public boolean isFloating() {
668 return false;
669 }
670
671 @Override
672 public void alwaysReadCloseOnTouchAttr() {
673 }
674
675 @Override
676 public void setContentView(@LayoutRes int layoutResID) {
677 }
678
679 @Override
680 public void setContentView(View view) {
681 }
682
683 @Override
684 public void setContentView(View view, ViewGroup.LayoutParams params) {
685 }
686
687 @Override
688 public void addContentView(View view, ViewGroup.LayoutParams params) {
689 }
690
691 @Override
692 public void clearContentView() {
693 }
694
695 @Override
696 public View getCurrentFocus() {
697 return null;
698 }
699
700 @Override
701 public LayoutInflater getLayoutInflater() {
702 return null;
703 }
704
705 @Override
706 public void setTitle(CharSequence title) {
707 }
708
709 @Override
710 public void setTitleColor(@ColorInt int textColor) {
711 }
712
713 @Override
714 public void openPanel(int featureId, KeyEvent event) {
715 }
716
717 @Override
718 public void closePanel(int featureId) {
719 }
720
721 @Override
722 public void togglePanel(int featureId, KeyEvent event) {
723 }
724
725 @Override
726 public void invalidatePanelMenu(int featureId) {
727 }
728
729 @Override
730 public boolean performPanelShortcut(int featureId, int keyCode, KeyEvent event, int flags) {
731 return false;
732 }
733
734 @Override
735 public boolean performPanelIdentifierAction(int featureId, int id, int flags) {
736 return false;
737 }
738
739 @Override
740 public void closeAllPanels() {
741 }
742
743 @Override
744 public boolean performContextMenuIdentifierAction(int id, int flags) {
745 return false;
746 }
747
748 @Override
749 public void onConfigurationChanged(Configuration newConfig) {
750 }
751
752 @Override
753 public void setBackgroundDrawable(Drawable drawable) {
754 }
755
756 @Override
757 public void setFeatureDrawableResource(int featureId, @DrawableRes int resId) {
758 }
759
760 @Override
761 public void setFeatureDrawableUri(int featureId, Uri uri) {
762 }
763
764 @Override
765 public void setFeatureDrawable(int featureId, Drawable drawable) {
766 }
767
768 @Override
769 public void setFeatureDrawableAlpha(int featureId, int alpha) {
770 }
771
772 @Override
773 public void setFeatureInt(int featureId, int value) {
774 }
775
776 @Override
777 public void takeKeyEvents(boolean get) {
778 }
779
780 @Override
781 public boolean superDispatchKeyEvent(KeyEvent event) {
782 return false;
783 }
784
785 @Override
786 public boolean superDispatchKeyShortcutEvent(KeyEvent event) {
787 return false;
788 }
789
790 @Override
791 public boolean superDispatchTouchEvent(MotionEvent event) {
792 return false;
793 }
794
795 @Override
796 public boolean superDispatchTrackballEvent(MotionEvent event) {
797 return false;
798 }
799
800 @Override
801 public boolean superDispatchGenericMotionEvent(MotionEvent event) {
802 return false;
803 }
804
805 @Override
806 public View getDecorView() {
807 return StatusBarWindowView.this;
808 }
809
810 @Override
811 public View peekDecorView() {
812 return null;
813 }
814
815 @Override
816 public Bundle saveHierarchyState() {
817 return null;
818 }
819
820 @Override
821 public void restoreHierarchyState(Bundle savedInstanceState) {
822 }
823
824 @Override
825 protected void onActive() {
826 }
827
828 @Override
829 public void setChildDrawable(int featureId, Drawable drawable) {
830 }
831
832 @Override
833 public void setChildInt(int featureId, int value) {
834 }
835
836 @Override
837 public boolean isShortcutKey(int keyCode, KeyEvent event) {
838 return false;
839 }
840
841 @Override
842 public void setVolumeControlStream(int streamType) {
843 }
844
845 @Override
846 public int getVolumeControlStream() {
847 return 0;
848 }
849
850 @Override
851 public int getStatusBarColor() {
852 return 0;
853 }
854
855 @Override
856 public void setStatusBarColor(@ColorInt int color) {
857 }
858
859 @Override
860 public int getNavigationBarColor() {
861 return 0;
862 }
863
864 @Override
865 public void setNavigationBarColor(@ColorInt int color) {
866 }
867
868 @Override
869 public void setDecorCaptionShade(int decorCaptionShade) {
870 }
871
872 @Override
873 public void setResizingCaptionDrawable(Drawable drawable) {
874 }
875
876 @Override
Andrii Kulian933076d2016-03-29 17:04:42 -0700877 public void onMultiWindowModeChanged() {
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700878 }
879
880 @Override
Winson Chung4d8681f2017-05-23 16:22:08 -0700881 public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
882 }
883
884 @Override
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700885 public void reportActivityRelaunched() {
886 }
Jorim Jaggib6030952018-10-23 18:31:52 +0200887
888 @Override
889 public WindowInsetsController getInsetsController() {
890 return null;
891 }
Adrian Roos0bd8a4b2016-03-14 16:21:44 -0700892 };
893
Daniel Sandlerc4f2a562012-05-04 11:55:46 -0400894}
895