From f8c4add85188a90940d9d7045ab4c945375fcff2 Mon Sep 17 00:00:00 2001 From: Selim Cinek Date: Thu, 8 Jun 2017 09:54:58 -0700 Subject: [PATCH] Fixed an issue where the notification could stay userlocked When collapsing the shade while draging down (using fingerprint) notifications would stay userlocked and would appear in a small height instead of their regular size. Test: runtest -x packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarWindowViewTest.java Change-Id: Ibd97a6ce063bc2fcd76f11e010e781a61bd76b5f Fixes: 36469584 --- .../android/systemui/analytics/DataCollector.java | 3 +- .../systemui/classifier/FalsingManager.java | 3 +- .../classifier/HumanInteractionClassifier.java | 3 +- .../systemui/statusbar/phone/StatusBar.java | 3 +- .../statusbar/phone/StatusBarWindowView.java | 12 +++- .../statusbar/phone/StatusBarWindowViewTest.java | 70 ++++++++++++++++++++++ 6 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarWindowViewTest.java diff --git a/packages/SystemUI/src/com/android/systemui/analytics/DataCollector.java b/packages/SystemUI/src/com/android/systemui/analytics/DataCollector.java index 965ded5beaff..931a99415615 100644 --- a/packages/SystemUI/src/com/android/systemui/analytics/DataCollector.java +++ b/packages/SystemUI/src/com/android/systemui/analytics/DataCollector.java @@ -25,6 +25,7 @@ import android.net.Uri; import android.os.AsyncTask; import android.os.Build; import android.os.Handler; +import android.os.Looper; import android.os.UserHandle; import android.provider.Settings; import android.util.Log; @@ -56,7 +57,7 @@ public class DataCollector implements SensorEventListener { private static final long TIMEOUT_MILLIS = 11000; // 11 seconds. public static final boolean DEBUG = false; - private final Handler mHandler = new Handler(); + private final Handler mHandler = new Handler(Looper.getMainLooper()); private final Context mContext; // Err on the side of caution, so logging is not started after a crash even tough the screen diff --git a/packages/SystemUI/src/com/android/systemui/classifier/FalsingManager.java b/packages/SystemUI/src/com/android/systemui/classifier/FalsingManager.java index a129acea40b0..8506734036dc 100644 --- a/packages/SystemUI/src/com/android/systemui/classifier/FalsingManager.java +++ b/packages/SystemUI/src/com/android/systemui/classifier/FalsingManager.java @@ -24,6 +24,7 @@ import android.hardware.SensorEventListener; import android.hardware.SensorManager; import android.net.Uri; import android.os.Handler; +import android.os.Looper; import android.os.PowerManager; import android.os.UserHandle; import android.provider.Settings; @@ -59,7 +60,7 @@ public class FalsingManager implements SensorEventListener { Sensor.TYPE_ROTATION_VECTOR, }; - private final Handler mHandler = new Handler(); + private final Handler mHandler = new Handler(Looper.getMainLooper()); private final Context mContext; private final SensorManager mSensorManager; diff --git a/packages/SystemUI/src/com/android/systemui/classifier/HumanInteractionClassifier.java b/packages/SystemUI/src/com/android/systemui/classifier/HumanInteractionClassifier.java index 851ab7718820..2e9ba567c74d 100644 --- a/packages/SystemUI/src/com/android/systemui/classifier/HumanInteractionClassifier.java +++ b/packages/SystemUI/src/com/android/systemui/classifier/HumanInteractionClassifier.java @@ -20,6 +20,7 @@ import android.content.Context; import android.database.ContentObserver; import android.hardware.SensorEvent; import android.os.Handler; +import android.os.Looper; import android.os.UserHandle; import android.provider.Settings; import android.util.DisplayMetrics; @@ -41,7 +42,7 @@ public class HumanInteractionClassifier extends Classifier { private static HumanInteractionClassifier sInstance = null; - private final Handler mHandler = new Handler(); + private final Handler mHandler = new Handler(Looper.getMainLooper()); private final Context mContext; private final StrokeClassifier[] mStrokeClassifiers; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index f4f48a38e654..cfbdc9241a98 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -4633,7 +4633,8 @@ public class StatusBar extends SystemUI implements DemoMode, /* Only ever called as a consequence of a lockscreen expansion gesture. */ @Override public boolean onDraggedDown(View startingChild, int dragLengthY) { - if (hasActiveNotifications() && (!isDozing() || isPulsing())) { + if (mState == StatusBarState.KEYGUARD + && hasActiveNotifications() && (!isDozing() || isPulsing())) { mLockscreenGestureLogger.write( MetricsEvent.ACTION_LS_SHADE, (int) (dragLengthY / mDisplayMetrics.density), diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowView.java index f58a91b8b369..adc33a144689 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowView.java @@ -53,6 +53,7 @@ import android.view.WindowManager; import android.view.WindowManagerGlobal; import android.widget.FrameLayout; +import com.android.internal.annotations.VisibleForTesting; import com.android.internal.view.FloatingActionMode; import com.android.internal.widget.FloatingToolbar; import com.android.systemui.R; @@ -182,7 +183,12 @@ public class StatusBarWindowView extends FrameLayout { public void setService(StatusBar service) { mService = service; - mDragDownHelper = new DragDownHelper(getContext(), this, mStackScrollLayout, mService); + setDragDownHelper(new DragDownHelper(getContext(), this, mStackScrollLayout, mService)); + } + + @VisibleForTesting + void setDragDownHelper(DragDownHelper dragDownHelper) { + mDragDownHelper = dragDownHelper; } @Override @@ -309,8 +315,8 @@ public class StatusBarWindowView extends FrameLayout { mDoubleTapHelper.onTouchEvent(ev); handled = true; } - if (mService.getBarState() == StatusBarState.KEYGUARD - && (!handled || mDragDownHelper.isDraggingDown())) { + if ((mService.getBarState() == StatusBarState.KEYGUARD && !handled) + || mDragDownHelper.isDraggingDown()) { // we still want to finish our drag down gesture when locking the screen handled = mDragDownHelper.onTouchEvent(ev); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarWindowViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarWindowViewTest.java new file mode 100644 index 000000000000..a068a5e574eb --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarWindowViewTest.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.statusbar.phone; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import android.content.Context; +import android.os.SystemClock; +import android.service.notification.StatusBarNotification; +import android.support.test.InstrumentationRegistry; +import android.support.test.filters.SmallTest; +import android.support.test.runner.AndroidJUnit4; +import android.view.MotionEvent; +import android.view.View; + +import com.android.systemui.SysuiTestCase; +import com.android.systemui.statusbar.DragDownHelper; +import com.android.systemui.statusbar.ExpandableNotificationRow; +import com.android.systemui.statusbar.NotificationData; +import com.android.systemui.statusbar.StatusBarState; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(AndroidJUnit4.class) +@SmallTest +public class StatusBarWindowViewTest extends SysuiTestCase { + + private StatusBarWindowView mView; + private StatusBar mStatusBar; + private DragDownHelper mDragDownHelper; + + @Before + public void setUp() { + mView = new StatusBarWindowView(getContext(), null); + mStatusBar = mock(StatusBar.class); + mView.setService(mStatusBar); + mDragDownHelper = mock(DragDownHelper.class); + mView.setDragDownHelper(mDragDownHelper); + } + + @Test + public void testDragDownHelperCalledWhenDraggingDown() throws Exception { + when(mStatusBar.getBarState()).thenReturn(StatusBarState.SHADE); + when(mDragDownHelper.isDraggingDown()).thenReturn(true); + long now = SystemClock.elapsedRealtime(); + MotionEvent ev = MotionEvent.obtain(now, now, MotionEvent.ACTION_UP, 0 /* x */, 0 /* y */, + 0 /* meta */); + mView.onTouchEvent(ev); + verify(mDragDownHelper).onTouchEvent(ev); + ev.recycle(); + } +} -- 2.11.0