summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author 1 <mrcasey@google.com> 2023-03-28 15:28:00 +0000
committer 1 <mrcasey@google.com> 2023-03-28 16:37:07 +0000
commitdf5ea9d3683947c09c53c632d1e4822b31b88a88 (patch)
tree161bea1fa2318771a352e7fee48645706c0dbe5d
parent3fb79ddddd491d2960ebc90414b976345ef70a15 (diff)
Hide all system actions if there are custom actions.
Nearby will have a separate home for launch, the others are intentionally hidden per product feedback. Bug: 274645844 Test: atest ContentPreviewUiTest Test: atest CtsSharesheetDeviceTest Change-Id: I5cd9157bc3ab6fd38a9993e470604633fd41c7e2
-rw-r--r--java/src/com/android/intentresolver/contentpreview/ContentPreviewUi.java6
-rw-r--r--java/tests/src/com/android/intentresolver/contentpreview/ContentPreviewUiTest.kt80
2 files changed, 84 insertions, 2 deletions
diff --git a/java/src/com/android/intentresolver/contentpreview/ContentPreviewUi.java b/java/src/com/android/intentresolver/contentpreview/ContentPreviewUi.java
index a6bc2164..2a6bff5c 100644
--- a/java/src/com/android/intentresolver/contentpreview/ContentPreviewUi.java
+++ b/java/src/com/android/intentresolver/contentpreview/ContentPreviewUi.java
@@ -75,9 +75,11 @@ abstract class ContentPreviewUi {
FeatureFlagRepository featureFlagRepository) {
ArrayList<ActionRow.Action> actions =
new ArrayList<>(systemActions.size() + customActions.size());
- actions.addAll(systemActions);
- if (featureFlagRepository.isEnabled(Flags.SHARESHEET_CUSTOM_ACTIONS)) {
+ if (featureFlagRepository.isEnabled(Flags.SHARESHEET_CUSTOM_ACTIONS)
+ && customActions != null && !customActions.isEmpty()) {
actions.addAll(customActions);
+ } else {
+ actions.addAll(systemActions);
}
return actions;
}
diff --git a/java/tests/src/com/android/intentresolver/contentpreview/ContentPreviewUiTest.kt b/java/tests/src/com/android/intentresolver/contentpreview/ContentPreviewUiTest.kt
new file mode 100644
index 00000000..2b78a262
--- /dev/null
+++ b/java/tests/src/com/android/intentresolver/contentpreview/ContentPreviewUiTest.kt
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2023 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.intentresolver.contentpreview
+
+import android.content.res.Resources
+import android.view.LayoutInflater
+import android.view.ViewGroup
+import com.android.intentresolver.TestFeatureFlagRepository
+import com.android.intentresolver.flags.FeatureFlagRepository
+import com.android.intentresolver.flags.Flags
+import com.android.intentresolver.widget.ActionRow
+import com.google.common.truth.Truth.assertThat
+import org.junit.Test
+
+class ContentPreviewUiTest {
+ private class TestablePreview(private val flags: FeatureFlagRepository) : ContentPreviewUi() {
+ override fun getType() = 0
+
+ override fun display(
+ resources: Resources?,
+ layoutInflater: LayoutInflater?,
+ parent: ViewGroup?
+ ): ViewGroup {
+ throw IllegalStateException()
+ }
+
+ // exposing for testing
+ fun makeActions(
+ system: List<ActionRow.Action>,
+ custom: List<ActionRow.Action>
+ ): List<ActionRow.Action> {
+ return createActions(system, custom, flags)
+ }
+ }
+
+ @Test
+ fun testCreateActions() {
+ val featureFlagRepository = TestFeatureFlagRepository(
+ mapOf(
+ Flags.SHARESHEET_CUSTOM_ACTIONS to true
+ )
+ )
+ val preview = TestablePreview(featureFlagRepository)
+
+ val system = listOf(ActionRow.Action(label="system", icon=null) {})
+ val custom = listOf(ActionRow.Action(label="custom", icon=null) {})
+
+ assertThat(preview.makeActions(system, custom)).isEqualTo(custom)
+ assertThat(preview.makeActions(system, listOf())).isEqualTo(system)
+ }
+
+ @Test
+ fun testCreateActions_flagDisabled() {
+ val featureFlagRepository = TestFeatureFlagRepository(
+ mapOf(
+ Flags.SHARESHEET_CUSTOM_ACTIONS to false
+ )
+ )
+ val preview = TestablePreview(featureFlagRepository)
+
+ val system = listOf(ActionRow.Action(label="system", icon=null) {})
+ val custom = listOf(ActionRow.Action(label="custom", icon=null) {})
+
+ assertThat(preview.makeActions(system, custom)).isEqualTo(system)
+ }
+}