diff options
author | 2023-03-28 20:59:31 +0000 | |
---|---|---|
committer | 2023-03-28 20:59:31 +0000 | |
commit | ea863c413f569f5ed2609d54b16271328c7da3ce (patch) | |
tree | 84931de50a9d26402e3cca7522dba97f83338d3b | |
parent | ebc5d9c2c4200519f62a235eba748bcdc68177d8 (diff) | |
parent | 35828ea4afb4e23fa47c3c6e7c5772c0e59b15ea (diff) |
Merge "Hide all system actions if there are custom actions." into udc-dev am: 35828ea4af
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/modules/IntentResolver/+/22314884
Change-Id: I04c918a6914fab287558828377579edfc29bd0d5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | java/src/com/android/intentresolver/contentpreview/ContentPreviewUi.java | 6 | ||||
-rw-r--r-- | java/tests/src/com/android/intentresolver/contentpreview/ContentPreviewUiTest.kt | 80 |
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) + } +} |