Loading packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpManager.java +21 −0 Original line number Diff line number Diff line Loading @@ -26,8 +26,10 @@ import android.database.ContentObserver; import android.provider.Settings; import android.util.ArrayMap; import android.util.Log; import android.view.accessibility.AccessibilityManager; import com.android.internal.logging.MetricsLogger; import com.android.systemui.Dependency; import com.android.systemui.R; import com.android.systemui.statusbar.AlertingNotificationManager; import com.android.systemui.statusbar.notification.collection.NotificationEntry; Loading Loading @@ -55,9 +57,11 @@ public abstract class HeadsUpManager extends AlertingNotificationManager { protected int mUser; private final ArrayMap<String, Long> mSnoozedPackages; private final AccessibilityManagerWrapper mAccessibilityMgr; public HeadsUpManager(@NonNull final Context context) { mContext = context; mAccessibilityMgr = Dependency.get(AccessibilityManagerWrapper.class); Resources resources = context.getResources(); mMinimumDisplayTime = resources.getInteger(R.integer.heads_up_notification_minimum_time); mAutoDismissNotificationDecay = resources.getInteger(R.integer.heads_up_notification_decay); Loading Loading @@ -409,5 +413,22 @@ public abstract class HeadsUpManager extends AlertingNotificationManager { // The actual post time will be just after the heads-up really slided in return super.calculatePostTime() + mTouchAcceptanceDelay; } @Override protected long calculateFinishTime() { return mPostTime + getRecommendedTimeoutMillis(); } /** * Get user-preferred or default timeout duration. The larger one will be returned. * @return milliseconds before auto-dismiss */ private int getRecommendedTimeoutMillis() { return mAccessibilityMgr.getRecommendedTimeoutMillis( mAutoDismissNotificationDecay, AccessibilityManager.FLAG_CONTENT_CONTROLS | AccessibilityManager.FLAG_CONTENT_ICONS | AccessibilityManager.FLAG_CONTENT_TEXT); } } } packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpManagerPhoneTest.java +19 −2 Original line number Diff line number Diff line Loading @@ -19,8 +19,10 @@ package com.android.systemui.statusbar.phone; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.when; import android.content.Context; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import android.view.View; Loading @@ -31,6 +33,7 @@ import com.android.systemui.statusbar.AlertingNotificationManager; import com.android.systemui.statusbar.AlertingNotificationManagerTest; import com.android.systemui.statusbar.notification.VisualStabilityManager; import com.android.systemui.statusbar.notification.collection.NotificationEntry; import com.android.systemui.statusbar.policy.AccessibilityManagerWrapper; import org.junit.Before; import org.junit.Rule; Loading @@ -53,15 +56,29 @@ public class HeadsUpManagerPhoneTest extends AlertingNotificationManagerTest { @Mock private VisualStabilityManager mVSManager; @Mock private StatusBar mBar; private final class TestableHeadsUpManagerPhone extends HeadsUpManagerPhone { TestableHeadsUpManagerPhone(Context context, View statusBarWindowView, NotificationGroupManager groupManager, StatusBar bar, VisualStabilityManager vsManager) { super(context, statusBarWindowView, groupManager, bar, vsManager); mMinimumDisplayTime = TEST_MINIMUM_DISPLAY_TIME; mAutoDismissNotificationDecay = TEST_AUTO_DISMISS_TIME; } } protected AlertingNotificationManager createAlertingNotificationManager() { return mHeadsUpManager; } @Before public void setUp() { AccessibilityManagerWrapper mAccessibilityMgr = mDependency.injectMockDependency(AccessibilityManagerWrapper.class); when(mAccessibilityMgr.getRecommendedTimeoutMillis(anyInt(), anyInt())) .thenReturn(TEST_AUTO_DISMISS_TIME); when(mVSManager.isReorderingAllowed()).thenReturn(true); mHeadsUpManager = new HeadsUpManagerPhone(mContext, mStatusBarWindowView, mGroupManager, mBar, mVSManager); mHeadsUpManager = new TestableHeadsUpManagerPhone(mContext, mStatusBarWindowView, mGroupManager, mBar, mVSManager); super.setUp(); mHeadsUpManager.mHandler = mTestHandler; } Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/HeadsUpManagerTest.java 0 → 100644 +88 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 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.policy; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.doReturn; import android.content.Context; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import androidx.test.filters.SmallTest; import com.android.systemui.statusbar.AlertingNotificationManager; import com.android.systemui.statusbar.AlertingNotificationManagerTest; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @SmallTest @RunWith(AndroidTestingRunner.class) @TestableLooper.RunWithLooper public class HeadsUpManagerTest extends AlertingNotificationManagerTest { private static final int TEST_A11Y_AUTO_DISMISS_TIME = 600; private static final int TEST_A11Y_TIMEOUT_TIME = 5_000; private AccessibilityManagerWrapper mAccessibilityMgr; private HeadsUpManager mHeadsUpManager; private boolean mLivesPastNormalTime; private final class TestableHeadsUpManager extends HeadsUpManager { TestableHeadsUpManager(Context context) { super(context); mMinimumDisplayTime = TEST_MINIMUM_DISPLAY_TIME; mAutoDismissNotificationDecay = TEST_AUTO_DISMISS_TIME; } } protected AlertingNotificationManager createAlertingNotificationManager() { return mHeadsUpManager; } @Before public void setUp() { mAccessibilityMgr = mDependency.injectMockDependency(AccessibilityManagerWrapper.class); mHeadsUpManager = new TestableHeadsUpManager(mContext); super.setUp(); mHeadsUpManager.mHandler = mTestHandler; } @Test public void testShowNotification_autoDismissesWithAccessibilityTimeout() { doReturn(TEST_A11Y_AUTO_DISMISS_TIME).when(mAccessibilityMgr) .getRecommendedTimeoutMillis(anyInt(), anyInt()); mHeadsUpManager.showNotification(mEntry); Runnable pastNormalTimeRunnable = () -> mLivesPastNormalTime = mHeadsUpManager.isAlerting(mEntry.key); mTestHandler.postDelayed(pastNormalTimeRunnable, (TEST_A11Y_AUTO_DISMISS_TIME + TEST_AUTO_DISMISS_TIME) / 2); mTestHandler.postDelayed(TEST_TIMEOUT_RUNNABLE, TEST_A11Y_TIMEOUT_TIME); TestableLooper.get(this).processMessages(2); assertFalse("Test timed out", mTimedOut); assertTrue("Heads up should live long enough", mLivesPastNormalTime); assertFalse(mHeadsUpManager.isAlerting(mEntry.key)); } } Loading
packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpManager.java +21 −0 Original line number Diff line number Diff line Loading @@ -26,8 +26,10 @@ import android.database.ContentObserver; import android.provider.Settings; import android.util.ArrayMap; import android.util.Log; import android.view.accessibility.AccessibilityManager; import com.android.internal.logging.MetricsLogger; import com.android.systemui.Dependency; import com.android.systemui.R; import com.android.systemui.statusbar.AlertingNotificationManager; import com.android.systemui.statusbar.notification.collection.NotificationEntry; Loading Loading @@ -55,9 +57,11 @@ public abstract class HeadsUpManager extends AlertingNotificationManager { protected int mUser; private final ArrayMap<String, Long> mSnoozedPackages; private final AccessibilityManagerWrapper mAccessibilityMgr; public HeadsUpManager(@NonNull final Context context) { mContext = context; mAccessibilityMgr = Dependency.get(AccessibilityManagerWrapper.class); Resources resources = context.getResources(); mMinimumDisplayTime = resources.getInteger(R.integer.heads_up_notification_minimum_time); mAutoDismissNotificationDecay = resources.getInteger(R.integer.heads_up_notification_decay); Loading Loading @@ -409,5 +413,22 @@ public abstract class HeadsUpManager extends AlertingNotificationManager { // The actual post time will be just after the heads-up really slided in return super.calculatePostTime() + mTouchAcceptanceDelay; } @Override protected long calculateFinishTime() { return mPostTime + getRecommendedTimeoutMillis(); } /** * Get user-preferred or default timeout duration. The larger one will be returned. * @return milliseconds before auto-dismiss */ private int getRecommendedTimeoutMillis() { return mAccessibilityMgr.getRecommendedTimeoutMillis( mAutoDismissNotificationDecay, AccessibilityManager.FLAG_CONTENT_CONTROLS | AccessibilityManager.FLAG_CONTENT_ICONS | AccessibilityManager.FLAG_CONTENT_TEXT); } } }
packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpManagerPhoneTest.java +19 −2 Original line number Diff line number Diff line Loading @@ -19,8 +19,10 @@ package com.android.systemui.statusbar.phone; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.when; import android.content.Context; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import android.view.View; Loading @@ -31,6 +33,7 @@ import com.android.systemui.statusbar.AlertingNotificationManager; import com.android.systemui.statusbar.AlertingNotificationManagerTest; import com.android.systemui.statusbar.notification.VisualStabilityManager; import com.android.systemui.statusbar.notification.collection.NotificationEntry; import com.android.systemui.statusbar.policy.AccessibilityManagerWrapper; import org.junit.Before; import org.junit.Rule; Loading @@ -53,15 +56,29 @@ public class HeadsUpManagerPhoneTest extends AlertingNotificationManagerTest { @Mock private VisualStabilityManager mVSManager; @Mock private StatusBar mBar; private final class TestableHeadsUpManagerPhone extends HeadsUpManagerPhone { TestableHeadsUpManagerPhone(Context context, View statusBarWindowView, NotificationGroupManager groupManager, StatusBar bar, VisualStabilityManager vsManager) { super(context, statusBarWindowView, groupManager, bar, vsManager); mMinimumDisplayTime = TEST_MINIMUM_DISPLAY_TIME; mAutoDismissNotificationDecay = TEST_AUTO_DISMISS_TIME; } } protected AlertingNotificationManager createAlertingNotificationManager() { return mHeadsUpManager; } @Before public void setUp() { AccessibilityManagerWrapper mAccessibilityMgr = mDependency.injectMockDependency(AccessibilityManagerWrapper.class); when(mAccessibilityMgr.getRecommendedTimeoutMillis(anyInt(), anyInt())) .thenReturn(TEST_AUTO_DISMISS_TIME); when(mVSManager.isReorderingAllowed()).thenReturn(true); mHeadsUpManager = new HeadsUpManagerPhone(mContext, mStatusBarWindowView, mGroupManager, mBar, mVSManager); mHeadsUpManager = new TestableHeadsUpManagerPhone(mContext, mStatusBarWindowView, mGroupManager, mBar, mVSManager); super.setUp(); mHeadsUpManager.mHandler = mTestHandler; } Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/HeadsUpManagerTest.java 0 → 100644 +88 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 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.policy; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.doReturn; import android.content.Context; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import androidx.test.filters.SmallTest; import com.android.systemui.statusbar.AlertingNotificationManager; import com.android.systemui.statusbar.AlertingNotificationManagerTest; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @SmallTest @RunWith(AndroidTestingRunner.class) @TestableLooper.RunWithLooper public class HeadsUpManagerTest extends AlertingNotificationManagerTest { private static final int TEST_A11Y_AUTO_DISMISS_TIME = 600; private static final int TEST_A11Y_TIMEOUT_TIME = 5_000; private AccessibilityManagerWrapper mAccessibilityMgr; private HeadsUpManager mHeadsUpManager; private boolean mLivesPastNormalTime; private final class TestableHeadsUpManager extends HeadsUpManager { TestableHeadsUpManager(Context context) { super(context); mMinimumDisplayTime = TEST_MINIMUM_DISPLAY_TIME; mAutoDismissNotificationDecay = TEST_AUTO_DISMISS_TIME; } } protected AlertingNotificationManager createAlertingNotificationManager() { return mHeadsUpManager; } @Before public void setUp() { mAccessibilityMgr = mDependency.injectMockDependency(AccessibilityManagerWrapper.class); mHeadsUpManager = new TestableHeadsUpManager(mContext); super.setUp(); mHeadsUpManager.mHandler = mTestHandler; } @Test public void testShowNotification_autoDismissesWithAccessibilityTimeout() { doReturn(TEST_A11Y_AUTO_DISMISS_TIME).when(mAccessibilityMgr) .getRecommendedTimeoutMillis(anyInt(), anyInt()); mHeadsUpManager.showNotification(mEntry); Runnable pastNormalTimeRunnable = () -> mLivesPastNormalTime = mHeadsUpManager.isAlerting(mEntry.key); mTestHandler.postDelayed(pastNormalTimeRunnable, (TEST_A11Y_AUTO_DISMISS_TIME + TEST_AUTO_DISMISS_TIME) / 2); mTestHandler.postDelayed(TEST_TIMEOUT_RUNNABLE, TEST_A11Y_TIMEOUT_TIME); TestableLooper.get(this).processMessages(2); assertFalse("Test timed out", mTimedOut); assertTrue("Heads up should live long enough", mLivesPastNormalTime); assertFalse(mHeadsUpManager.isAlerting(mEntry.key)); } }