Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b5c4b28f authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Migrate ShortcutHelper from Activity to BottomSheet Dialog." into main

parents 45c4fcbf 8b87e1af
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -1139,11 +1139,5 @@
                android:name="android.service.dream"
                android:resource="@xml/home_controls_dream_metadata" />
        </service>

        <activity android:name="com.android.systemui.keyboard.shortcut.ui.view.ShortcutHelperActivity"
            android:exported="false"
            android:showForAllUsers="true"
            android:theme="@style/ShortcutHelperTheme"
            android:excludeFromRecents="true" />
    </application>
</manifest>
+36 −43
Original line number Diff line number Diff line
@@ -16,25 +16,26 @@

package com.android.systemui.keyboard.shortcut.ui

import android.content.Intent
import androidx.test.annotation.UiThreadTest
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.keyboard.shortcut.data.source.FakeKeyboardShortcutGroupsSource
import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts
import com.android.systemui.keyboard.shortcut.fakeShortcutHelperStartActivity
import com.android.systemui.keyboard.shortcut.shortcutHelperActivityStarter
import com.android.systemui.keyboard.shortcut.shortcutHelperAppCategoriesShortcutsSource
import com.android.systemui.keyboard.shortcut.shortcutHelperCurrentAppShortcutsSource
import com.android.systemui.keyboard.shortcut.shortcutHelperInputShortcutsSource
import com.android.systemui.keyboard.shortcut.shortcutHelperMultiTaskingShortcutsSource
import com.android.systemui.keyboard.shortcut.shortcutHelperSystemShortcutsSource
import com.android.systemui.keyboard.shortcut.shortcutHelperTestHelper
import com.android.systemui.keyboard.shortcut.ui.view.ShortcutHelperActivity
import com.android.systemui.keyboard.shortcut.shortcutHelperViewModel
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.applicationCoroutineScope
import com.android.systemui.kosmos.testCase
import com.android.systemui.kosmos.testDispatcher
import com.android.systemui.kosmos.testScope
import com.android.systemui.plugins.activityStarter
import com.android.systemui.statusbar.phone.systemUIDialogFactory
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.UnconfinedTestDispatcher
@@ -46,7 +47,7 @@ import org.junit.runner.RunWith
@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
@RunWith(AndroidJUnit4::class)
class ShortcutHelperActivityStarterTest : SysuiTestCase() {
class ShortcutHelperDialogStarterTest : SysuiTestCase() {

    private val fakeSystemSource = FakeKeyboardShortcutGroupsSource()
    private val fakeMultiTaskingSource = FakeKeyboardShortcutGroupsSource()
@@ -64,8 +65,14 @@ class ShortcutHelperActivityStarterTest : SysuiTestCase() {

    private val testScope = kosmos.testScope
    private val testHelper = kosmos.shortcutHelperTestHelper
    private val fakeStartActivity = kosmos.fakeShortcutHelperStartActivity
    private val starter = kosmos.shortcutHelperActivityStarter
    private val dialogFactory = kosmos.systemUIDialogFactory
    private val coroutineScope = kosmos.applicationCoroutineScope
    private val viewModel = kosmos.shortcutHelperViewModel

    private val starter: ShortcutHelperDialogStarter =
        with(kosmos) {
            ShortcutHelperDialogStarter(coroutineScope, viewModel, dialogFactory, activityStarter)
        }

    @Before
    fun setUp() {
@@ -74,21 +81,22 @@ class ShortcutHelperActivityStarterTest : SysuiTestCase() {
    }

    @Test
    fun start_doesNotStartByDefault() =
    fun start_doesNotShowDialogByDefault() =
        testScope.runTest {
            starter.start()

            assertThat(fakeStartActivity.startIntents).isEmpty()
            assertThat(starter.dialog).isNull()
        }

    @Test
    fun start_onToggle_startsActivity() =
    @UiThreadTest
    fun start_onToggle_showsDialog() =
        testScope.runTest {
            starter.start()

            testHelper.toggle(deviceId = 456)

            verifyShortcutHelperActivityStarted()
            assertThat(starter.dialog?.isShowing).isTrue()
        }

    @Test
@@ -101,34 +109,18 @@ class ShortcutHelperActivityStarterTest : SysuiTestCase() {

            testHelper.toggle(deviceId = 456)

            assertThat(fakeStartActivity.startIntents).isEmpty()
        }

    @Test
    fun start_onToggle_multipleTimesStartsActivityOnlyWhenNotStarted() =
        testScope.runTest {
            starter.start()

            // Starts
            testHelper.toggle(deviceId = 456)
            // Stops
            testHelper.toggle(deviceId = 456)
            // Starts again
            testHelper.toggle(deviceId = 456)
            // Stops
            testHelper.toggle(deviceId = 456)

            verifyShortcutHelperActivityStarted(numTimes = 2)
            assertThat(starter.dialog).isNull()
        }

    @Test
    @UiThreadTest
    fun start_onRequestShowShortcuts_startsActivity() =
        testScope.runTest {
            starter.start()

            testHelper.showFromActivity()

            verifyShortcutHelperActivityStarted()
            assertThat(starter.dialog?.isShowing).isTrue()
        }

    @Test
@@ -140,10 +132,11 @@ class ShortcutHelperActivityStarterTest : SysuiTestCase() {

            testHelper.showFromActivity()

            assertThat(fakeStartActivity.startIntents).isEmpty()
            assertThat(starter.dialog).isNull()
        }

    @Test
    @UiThreadTest
    fun start_onRequestShowShortcuts_multipleTimes_startsActivityOnlyOnce() =
        testScope.runTest {
            starter.start()
@@ -152,40 +145,40 @@ class ShortcutHelperActivityStarterTest : SysuiTestCase() {
            testHelper.showFromActivity()
            testHelper.showFromActivity()

            verifyShortcutHelperActivityStarted(numTimes = 1)
            assertThat(starter.dialog?.isShowing).isTrue()
        }

    @Test
    @UiThreadTest
    fun start_onRequestShowShortcuts_multipleTimes_startsActivityOnlyWhenNotStarted() =
        testScope.runTest {
            starter.start()

            assertThat(starter.dialog).isNull()
            // No-op. Already hidden.
            testHelper.hideFromActivity()
            assertThat(starter.dialog).isNull()
            // No-op. Already hidden.
            testHelper.hideForSystem()
            assertThat(starter.dialog).isNull()
            // Show 1st time.
            testHelper.toggle(deviceId = 987)
            assertThat(starter.dialog).isNotNull()
            assertThat(starter.dialog?.isShowing).isTrue()
            // No-op. Already shown.
            testHelper.showFromActivity()
            assertThat(starter.dialog?.isShowing).isTrue()
            // Hidden.
            testHelper.hideFromActivity()
            assertThat(starter.dialog?.isShowing).isFalse()
            // No-op. Already hidden.
            testHelper.hideForSystem()
            assertThat(starter.dialog?.isShowing).isFalse()
            // Show 2nd time.
            testHelper.toggle(deviceId = 456)
            assertThat(starter.dialog?.isShowing).isTrue()
            // No-op. Already shown.
            testHelper.showFromActivity()

            verifyShortcutHelperActivityStarted(numTimes = 2)
        }

    private fun verifyShortcutHelperActivityStarted(numTimes: Int = 1) {
        assertThat(fakeStartActivity.startIntents).hasSize(numTimes)
        fakeStartActivity.startIntents.forEach { intent ->
            assertThat(intent.flags).isEqualTo(Intent.FLAG_ACTIVITY_NEW_TASK)
            assertThat(intent.filterEquals(Intent(context, ShortcutHelperActivity::class.java)))
                .isTrue()
        }
            assertThat(starter.dialog?.isShowing).isTrue()
        }
}
+0 −26
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2024 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.
  -->

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:zAdjustment="top">

    <translate
        android:fromYDelta="0"
        android:toYDelta="100%"
        android:duration="@android:integer/config_shortAnimTime" />
</set>
+0 −27
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2024 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.
  -->

<!-- Animation for when a dock window at the bottom of the screen is entering. -->
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator"
    android:zAdjustment="top">

    <translate android:fromYDelta="100%"
        android:toYDelta="0"
        android:startOffset="@android:integer/config_shortAnimTime"
        android:duration="@android:integer/config_mediumAnimTime"/>
</set>
+0 −4
Original line number Diff line number Diff line
@@ -59,8 +59,4 @@
        -->
        <item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>
    </style>

    <style name="ShortcutHelperTheme" parent="@style/ShortcutHelperThemeCommon">
        <item name="android:windowLightNavigationBar">false</item>
    </style>
</resources>
Loading