diff options
| author | 2024-09-10 16:33:37 +0000 | |
|---|---|---|
| committer | 2024-09-10 16:33:37 +0000 | |
| commit | a96e6294ac9f142bbb70c0c3aecbf2e18f19a8e8 (patch) | |
| tree | cff4ef70512af8f0196ce177313ba3267b128349 | |
| parent | 22e0975e95d97706d56591434223b90f68a7a962 (diff) | |
| parent | 6e521b228d5d9b26636a4189d8b68cd5bb5cfff9 (diff) | |
Merge "Add broadcast listener launching tutorial for keyboard and touchpad" into main
2 files changed, 94 insertions, 2 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/KeyboardTouchpadTutorialCoreStartable.kt b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/KeyboardTouchpadTutorialCoreStartable.kt index 7ecacdc7cf16..092a25aa1cad 100644 --- a/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/KeyboardTouchpadTutorialCoreStartable.kt +++ b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/KeyboardTouchpadTutorialCoreStartable.kt @@ -16,9 +16,17 @@ package com.android.systemui.inputdevice.tutorial +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import android.content.IntentFilter +import android.os.UserHandle import com.android.systemui.CoreStartable +import com.android.systemui.broadcast.BroadcastDispatcher import com.android.systemui.dagger.SysUISingleton +import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.inputdevice.tutorial.ui.TutorialNotificationCoordinator +import com.android.systemui.inputdevice.tutorial.ui.view.KeyboardTouchpadTutorialActivity import com.android.systemui.shared.Flags.newTouchpadGesturesTutorial import dagger.Lazy import javax.inject.Inject @@ -27,11 +35,35 @@ import javax.inject.Inject @SysUISingleton class KeyboardTouchpadTutorialCoreStartable @Inject -constructor(private val tutorialNotificationCoordinator: Lazy<TutorialNotificationCoordinator>) : - CoreStartable { +constructor( + private val tutorialNotificationCoordinator: Lazy<TutorialNotificationCoordinator>, + private val broadcastDispatcher: BroadcastDispatcher, + @Application private val applicationContext: Context, +) : CoreStartable { override fun start() { if (newTouchpadGesturesTutorial()) { tutorialNotificationCoordinator.get().start() + registerTutorialBroadcastReceiver() } } + + private fun registerTutorialBroadcastReceiver() { + broadcastDispatcher.registerReceiver( + receiver = + object : BroadcastReceiver() { + override fun onReceive(context: Context, intent: Intent) { + applicationContext.startActivityAsUser( + Intent( + applicationContext, + KeyboardTouchpadTutorialActivity::class.java + ), + UserHandle.SYSTEM + ) + } + }, + filter = IntentFilter("com.android.systemui.action.KEYBOARD_TOUCHPAD_TUTORIAL"), + flags = Context.RECEIVER_EXPORTED, + user = UserHandle.ALL, + ) + } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/inputdevice/tutorial/KeyboardTouchpadTutorialCoreStartableTest.kt b/packages/SystemUI/tests/src/com/android/systemui/inputdevice/tutorial/KeyboardTouchpadTutorialCoreStartableTest.kt new file mode 100644 index 000000000000..9da68853a5aa --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/systemui/inputdevice/tutorial/KeyboardTouchpadTutorialCoreStartableTest.kt @@ -0,0 +1,60 @@ +/* + * 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. + */ + +package com.android.systemui.inputdevice.tutorial + +import android.content.Context +import android.content.Intent +import android.os.UserHandle +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.SmallTest +import com.android.systemui.SysuiTestCase +import com.android.systemui.broadcast.broadcastDispatcher +import com.android.systemui.inputdevice.tutorial.ui.TutorialNotificationCoordinator +import com.android.systemui.testKosmos +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.kotlin.any +import org.mockito.kotlin.eq +import org.mockito.kotlin.mock +import org.mockito.kotlin.verify + +@SmallTest +@RunWith(AndroidJUnit4::class) +class KeyboardTouchpadTutorialCoreStartableTest : SysuiTestCase() { + + private val kosmos = testKosmos() + private val broadcastDispatcher = kosmos.broadcastDispatcher + private val context = mock<Context>() + private val underTest = + KeyboardTouchpadTutorialCoreStartable( + { mock<TutorialNotificationCoordinator>() }, + broadcastDispatcher, + context + ) + + @Test + fun registersBroadcastReceiverStartingActivityAsSystemUser() { + underTest.start() + + broadcastDispatcher.sendIntentToMatchingReceiversOnly( + context, + Intent("com.android.systemui.action.KEYBOARD_TOUCHPAD_TUTORIAL") + ) + + verify(context).startActivityAsUser(any(), eq(UserHandle.SYSTEM)) + } +} |