summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Zhe Song <zhesong@google.com> 2024-02-22 18:57:36 +0800
committer Zhe Song <zhesong@google.com> 2024-02-26 15:51:16 +0800
commitbe89444a1450d4c57a3b51fbc228d3ecff9d1f6c (patch)
tree422925f9f98664b475e2591daaecffa6d813df10
parentab438ccca1ef50aadf20ac7a7d43894c6bad9e2a (diff)
Introduce AssistRepository,Interactor to model the state.
Bug: 325771449 Flag: NA Test: unit test passed Test: mp droid succeeded in local device. Change-Id: Id92f27bccb16014d1e232281a20b377d264ca7ff
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/assist/data/repository/AssistRepositoryTest.kt50
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/assist/domain/interactor/AssistInteractorTest.kt53
-rw-r--r--packages/SystemUI/src/com/android/systemui/assist/AssistManager.java7
-rw-r--r--packages/SystemUI/src/com/android/systemui/assist/data/repository/AssistRepository.kt37
-rw-r--r--packages/SystemUI/src/com/android/systemui/assist/domain/interactor/AssistInteractor.kt40
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/assist/data/repository/AssistRepositoryKosmos.kt21
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/assist/domain/interactor/AssistInteractorKosmos.kt22
7 files changed, 229 insertions, 1 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/assist/data/repository/AssistRepositoryTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/assist/data/repository/AssistRepositoryTest.kt
new file mode 100644
index 000000000000..80077a21f985
--- /dev/null
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/assist/data/repository/AssistRepositoryTest.kt
@@ -0,0 +1,50 @@
+/*
+ * 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.assist.data.repository
+
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.SmallTest
+import com.android.systemui.SysuiTestCase
+import com.android.systemui.coroutines.collectLastValue
+import com.android.systemui.kosmos.testScope
+import com.android.systemui.testKosmos
+import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.test.runCurrent
+import kotlinx.coroutines.test.runTest
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@OptIn(ExperimentalCoroutinesApi::class)
+@SmallTest
+@RunWith(AndroidJUnit4::class)
+class AssistRepositoryTest : SysuiTestCase() {
+ private val kosmos = testKosmos()
+ private val testScope = kosmos.testScope
+
+ private val underTest = kosmos.assistRepository
+
+ @Test
+ fun invocationType() =
+ testScope.runTest {
+ val invocationType by collectLastValue(underTest.latestInvocationType)
+ underTest.setLatestInvocationType(2)
+ runCurrent()
+
+ assertThat(invocationType).isEqualTo(2)
+ }
+}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/assist/domain/interactor/AssistInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/assist/domain/interactor/AssistInteractorTest.kt
new file mode 100644
index 000000000000..c12f1aca350a
--- /dev/null
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/assist/domain/interactor/AssistInteractorTest.kt
@@ -0,0 +1,53 @@
+/*
+ * 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.assist.domain.interactor
+
+import android.platform.test.annotations.EnableFlags
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.SmallTest
+import com.android.systemui.Flags
+import com.android.systemui.SysuiTestCase
+import com.android.systemui.coroutines.collectLastValue
+import com.android.systemui.kosmos.testScope
+import com.android.systemui.testKosmos
+import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.test.runCurrent
+import kotlinx.coroutines.test.runTest
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@OptIn(ExperimentalCoroutinesApi::class)
+@RunWith(AndroidJUnit4::class)
+@SmallTest
+class AssistInteractorTest : SysuiTestCase() {
+ private val kosmos = testKosmos()
+ private val testScope = kosmos.testScope
+
+ private val underTest = kosmos.assistInteractor
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENABLE_CONTEXTUAL_TIPS, Flags.FLAG_ENABLE_CONTEXTUAL_TIP_FOR_POWER_OFF)
+ fun onAssistantStarted() =
+ testScope.runTest {
+ val invocationType by collectLastValue(underTest.latestInvocationType)
+ underTest.onAssistantStarted(3)
+ runCurrent()
+
+ assertThat(invocationType).isEqualTo(3)
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/assist/AssistManager.java b/packages/SystemUI/src/com/android/systemui/assist/AssistManager.java
index 74ea58caf8b6..d30f33f5ba2c 100644
--- a/packages/SystemUI/src/com/android/systemui/assist/AssistManager.java
+++ b/packages/SystemUI/src/com/android/systemui/assist/AssistManager.java
@@ -31,6 +31,7 @@ import com.android.internal.app.IVisualQueryRecognitionStatusListener;
import com.android.internal.app.IVoiceInteractionSessionListener;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.systemui.assist.domain.interactor.AssistInteractor;
import com.android.systemui.assist.ui.DefaultUiController;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Main;
@@ -149,6 +150,7 @@ public class AssistManager {
private final SecureSettings mSecureSettings;
private final SelectedUserInteractor mSelectedUserInteractor;
private final ActivityManager mActivityManager;
+ private final AssistInteractor mInteractor;
private final DeviceProvisionedController mDeviceProvisionedController;
@@ -192,7 +194,8 @@ public class AssistManager {
DisplayTracker displayTracker,
SecureSettings secureSettings,
SelectedUserInteractor selectedUserInteractor,
- ActivityManager activityManager) {
+ ActivityManager activityManager,
+ AssistInteractor interactor) {
mContext = context;
mDeviceProvisionedController = controller;
mCommandQueue = commandQueue;
@@ -206,6 +209,7 @@ public class AssistManager {
mSecureSettings = secureSettings;
mSelectedUserInteractor = selectedUserInteractor;
mActivityManager = activityManager;
+ mInteractor = interactor;
registerVoiceInteractionSessionListener();
registerVisualQueryRecognitionStatusListener();
@@ -314,6 +318,7 @@ public class AssistManager {
assistComponent,
legacyDeviceState);
logStartAssistLegacy(legacyInvocationType, legacyDeviceState);
+ mInteractor.onAssistantStarted(legacyInvocationType);
startAssistInternal(args, assistComponent, isService);
}
diff --git a/packages/SystemUI/src/com/android/systemui/assist/data/repository/AssistRepository.kt b/packages/SystemUI/src/com/android/systemui/assist/data/repository/AssistRepository.kt
new file mode 100644
index 000000000000..c416c249dec4
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/assist/data/repository/AssistRepository.kt
@@ -0,0 +1,37 @@
+/*
+ * 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.assist.data.repository
+
+import com.android.systemui.dagger.SysUISingleton
+import javax.inject.Inject
+import kotlinx.coroutines.channels.BufferOverflow
+import kotlinx.coroutines.flow.MutableSharedFlow
+import kotlinx.coroutines.flow.SharedFlow
+import kotlinx.coroutines.flow.asSharedFlow
+
+@SysUISingleton
+class AssistRepository @Inject constructor() {
+ private val _latestInvocationType =
+ MutableSharedFlow<Int>(replay = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST)
+ /** The type of the latest invocation of the assistant. */
+ val latestInvocationType: SharedFlow<Int> = _latestInvocationType.asSharedFlow()
+
+ /** Sets the type of the latest invocation of the assistant. */
+ fun setLatestInvocationType(type: Int) {
+ _latestInvocationType.tryEmit(type)
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/assist/domain/interactor/AssistInteractor.kt b/packages/SystemUI/src/com/android/systemui/assist/domain/interactor/AssistInteractor.kt
new file mode 100644
index 000000000000..d9e46aabf539
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/assist/domain/interactor/AssistInteractor.kt
@@ -0,0 +1,40 @@
+/*
+ * 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.assist.domain.interactor
+
+import com.android.systemui.Flags
+import com.android.systemui.assist.data.repository.AssistRepository
+import com.android.systemui.dagger.SysUISingleton
+import javax.inject.Inject
+import kotlinx.coroutines.flow.SharedFlow
+
+@SysUISingleton
+class AssistInteractor
+@Inject
+constructor(
+ private val repository: AssistRepository,
+) {
+ /** The type of the latest invocation of the assistant. */
+ val latestInvocationType: SharedFlow<Int> = repository.latestInvocationType
+
+ /** Notifies that Assistant has been started. */
+ fun onAssistantStarted(type: Int) {
+ if (Flags.enableContextualTips() && Flags.enableContextualTipForPowerOff()) {
+ repository.setLatestInvocationType(type)
+ }
+ }
+}
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/assist/data/repository/AssistRepositoryKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/assist/data/repository/AssistRepositoryKosmos.kt
new file mode 100644
index 000000000000..96155ed1ec9f
--- /dev/null
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/assist/data/repository/AssistRepositoryKosmos.kt
@@ -0,0 +1,21 @@
+/*
+ * 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.assist.data.repository
+
+import com.android.systemui.kosmos.Kosmos
+
+val Kosmos.assistRepository by Kosmos.Fixture { AssistRepository() }
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/assist/domain/interactor/AssistInteractorKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/assist/domain/interactor/AssistInteractorKosmos.kt
new file mode 100644
index 000000000000..c3c11318b0cc
--- /dev/null
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/assist/domain/interactor/AssistInteractorKosmos.kt
@@ -0,0 +1,22 @@
+/*
+ * 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.assist.domain.interactor
+
+import com.android.systemui.assist.data.repository.assistRepository
+import com.android.systemui.kosmos.Kosmos
+
+val Kosmos.assistInteractor by Kosmos.Fixture { AssistInteractor(assistRepository) }