From 2a14b978c6d6f57f40e3468ff097cb3140b46f1d Mon Sep 17 00:00:00 2001 From: Anushree Ganjam Date: Wed, 30 Aug 2023 13:31:10 -0700 Subject: [PATCH] Remove the test aconfig lib. zhidou@ from ACE team is working on AConfigFakelib which will be useful to set fake flag values in both unit tests and UI automator tests. Meanwhile, we will mock the flag values for unit tests and UI automator tests will have all flags values defaulted to false. testAConfigLib with "test:true" doesn't generate fake flags values and forces us to set the flag values using "SetFlagsRule". "SetFlagsRule" doesn't work with Out Of Proc tests and hence doesn't serve the purpose for us. AConfigFakelib and FakeFlagTargetPreparer should use for Out Of Proc tests. testAConfigLib with "test:true" is suitable for java host tests where there is no device involved. Launcher tests are instrumentation tests and tests run on actual devices. So we can use the production version of the AConfig lib and device config flag values will be fetched for UI Automator tests. Also migrating "enable_twoline_allapps" to trunk stable. Unit tests is using mockito to mock the flag value as false. The owner of "enable_twoline_allapps" can mock the value to true in unit tests as next step. Bug: 294913042 Test: Local studio build and soong build Flag: enable_twoline_allapps Change-Id: Iea42bf18197832a9ecbddc1c3aaa8c9e36169131 --- Android.bp | 31 +++---------------- aconfig/Android.bp | 6 ---- aconfig/launcher.aconfig | 7 +++++ src/com/android/launcher3/BubbleTextView.java | 5 +-- .../launcher3/allapps/BaseAllAppsAdapter.java | 9 ++++-- .../launcher3/config/FeatureFlags.java | 1 + tests/Android.bp | 4 +-- .../launcher3/ui/BubbleTextViewTest.java | 8 +++++ .../android/launcher3/ui/WorkProfileTest.java | 5 --- 9 files changed, 32 insertions(+), 44 deletions(-) diff --git a/Android.bp b/Android.bp index af0e3becbe..28eee94dae 100644 --- a/Android.bp +++ b/Android.bp @@ -167,13 +167,14 @@ android_library { // // Build rule for Launcher3 dependencies lib. // -java_defaults { - name: "Launcher3CommonDepsDefault", +android_library { + name: "Launcher3CommonDepsLib", srcs: ["src_build_config/**/*.java"], static_libs: [ "Launcher3ResLib", "launcher-testing-shared", - "animationlib" + "animationlib", + "com_android_launcher3_flags_lib", ], sdk_version: "current", min_sdk_version: min_launcher3_sdk_version, @@ -183,28 +184,6 @@ java_defaults { }, } -// -// Build rule for Launcher3 dependencies lib. -// -android_library { - name: "Launcher3CommonDepsLib", - defaults: ["Launcher3CommonDepsDefault"], - static_libs: [ - "com_android_launcher3_flags_lib", - ], -} - -// -// Build rule for Launcher3 dependencies lib for test and debug. -// -android_library { - name: "Launcher3CommonDepsLibDebug", - defaults: ["Launcher3CommonDepsDefault"], - static_libs: [ - "com_android_launcher3_flags_lib_debug", - ], -} - // // Build rule for Launcher3 app. // @@ -212,7 +191,7 @@ android_app { name: "Launcher3", static_libs: [ - "Launcher3CommonDepsLibDebug", + "Launcher3CommonDepsLib", ], srcs: [ ":launcher-src", diff --git a/aconfig/Android.bp b/aconfig/Android.bp index 9ada485f77..dc30a35eed 100644 --- a/aconfig/Android.bp +++ b/aconfig/Android.bp @@ -27,9 +27,3 @@ java_aconfig_library { name: "com_android_launcher3_flags_lib", aconfig_declarations: "com_android_launcher3_flags", } - -java_aconfig_library { - name: "com_android_launcher3_flags_lib_debug", - aconfig_declarations: "com_android_launcher3_flags", - test: true -} diff --git a/aconfig/launcher.aconfig b/aconfig/launcher.aconfig index dd3924981e..aca1b3b114 100644 --- a/aconfig/launcher.aconfig +++ b/aconfig/launcher.aconfig @@ -6,3 +6,10 @@ flag { description: "Expand and collapse pause work button while scrolling." bug: "270390779" } + +flag { + name: "enable_twoline_allapps" + namespace: "launcher" + description: "Enables two line label inside all apps." + bug: "270390937" +} diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java index abf84ddcb5..347c7af7b3 100644 --- a/src/com/android/launcher3/BubbleTextView.java +++ b/src/com/android/launcher3/BubbleTextView.java @@ -272,7 +272,7 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, mDotParams.scale = 0f; mForceHideDot = false; setBackground(null); - if (FeatureFlags.ENABLE_TWOLINE_ALLAPPS.get() + if (Flags.enableTwolineAllapps() || FeatureFlags.ENABLE_TWOLINE_ALLAPPS.get() || FeatureFlags.ENABLE_TWOLINE_DEVICESEARCH.get()) { setMaxLines(1); } @@ -405,7 +405,8 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, * Only if actual text can be displayed in two line, the {@code true} value will be effective. */ protected boolean shouldUseTwoLine() { - return (FeatureFlags.ENABLE_TWOLINE_ALLAPPS.get() && mDisplay == DISPLAY_ALL_APPS) + return ((Flags.enableTwolineAllapps() || FeatureFlags.ENABLE_TWOLINE_ALLAPPS.get()) + && mDisplay == DISPLAY_ALL_APPS) || (FeatureFlags.ENABLE_TWOLINE_DEVICESEARCH.get() && mDisplay == DISPLAY_SEARCH_RESULT); } diff --git a/src/com/android/launcher3/allapps/BaseAllAppsAdapter.java b/src/com/android/launcher3/allapps/BaseAllAppsAdapter.java index be0a898531..769c787335 100644 --- a/src/com/android/launcher3/allapps/BaseAllAppsAdapter.java +++ b/src/com/android/launcher3/allapps/BaseAllAppsAdapter.java @@ -27,6 +27,7 @@ import android.widget.TextView; import androidx.recyclerview.widget.RecyclerView; import com.android.launcher3.BubbleTextView; +import com.android.launcher3.Flags; import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.allapps.search.SearchAdapterProvider; @@ -176,8 +177,10 @@ public abstract class BaseAllAppsAdapter ex public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { switch (viewType) { case VIEW_TYPE_ICON: - int layout = !FeatureFlags.ENABLE_TWOLINE_ALLAPPS.get() ? R.layout.all_apps_icon - : R.layout.all_apps_icon_twoline; + int layout = + !(Flags.enableTwolineAllapps() || FeatureFlags.ENABLE_TWOLINE_ALLAPPS.get()) + ? R.layout.all_apps_icon + : R.layout.all_apps_icon_twoline; BubbleTextView icon = (BubbleTextView) mLayoutInflater.inflate( layout, parent, false); icon.setLongPressTimeoutFactor(1f); @@ -187,7 +190,7 @@ public abstract class BaseAllAppsAdapter ex // Ensure the all apps icon height matches the workspace icons in portrait mode. icon.getLayoutParams().height = mActivityContext.getDeviceProfile().allAppsCellHeightPx; - if (FeatureFlags.ENABLE_TWOLINE_ALLAPPS.get()) { + if (Flags.enableTwolineAllapps() || FeatureFlags.ENABLE_TWOLINE_ALLAPPS.get()) { icon.getLayoutParams().height += mExtraTextHeight; } return new ViewHolder(icon); diff --git a/src/com/android/launcher3/config/FeatureFlags.java b/src/com/android/launcher3/config/FeatureFlags.java index 21520bfcdf..0ace552d41 100644 --- a/src/com/android/launcher3/config/FeatureFlags.java +++ b/src/com/android/launcher3/config/FeatureFlags.java @@ -238,6 +238,7 @@ public final class FeatureFlags { public static final BooleanFlag COLLECT_SEARCH_HISTORY = getReleaseFlag(270391455, "COLLECT_SEARCH_HISTORY", DISABLED, "Allow launcher to collect search history for log"); + // Aconfig migration complete for ENABLE_TWOLINE_ALLAPPS. public static final BooleanFlag ENABLE_TWOLINE_ALLAPPS = getDebugFlag(270390937, "ENABLE_TWOLINE_ALLAPPS", DISABLED, "Enables two line label inside all apps."); diff --git a/tests/Android.bp b/tests/Android.bp index 5effa5c78c..d40efce9b6 100644 --- a/tests/Android.bp +++ b/tests/Android.bp @@ -88,7 +88,7 @@ android_library { "truth-prebuilt", "platform-test-rules", "testables", - "com_android_launcher3_flags_lib_debug", + "com_android_launcher3_flags_lib", ], manifest: "AndroidManifest-common.xml", platform_apis: true, @@ -107,7 +107,7 @@ android_test { ], static_libs: [ "Launcher3TestLib", - "com_android_launcher3_flags_lib_debug", + "com_android_launcher3_flags_lib", ], libs: [ "android.test.base", diff --git a/tests/src/com/android/launcher3/ui/BubbleTextViewTest.java b/tests/src/com/android/launcher3/ui/BubbleTextViewTest.java index ba17fdc8dd..bba8c89a05 100644 --- a/tests/src/com/android/launcher3/ui/BubbleTextViewTest.java +++ b/tests/src/com/android/launcher3/ui/BubbleTextViewTest.java @@ -30,16 +30,21 @@ import android.graphics.Typeface; import android.view.ViewGroup; import com.android.launcher3.BubbleTextView; +import com.android.launcher3.Flags; import com.android.launcher3.Utilities; import com.android.launcher3.model.data.ItemInfoWithIcon; import com.android.launcher3.search.StringMatcherUtility; import com.android.launcher3.util.ActivityContextWrapper; import com.android.launcher3.util.IntArray; import com.android.launcher3.util.TestUtil; +import com.android.launcher3.util.rule.StaticMockitoRule; import com.android.launcher3.views.BaseDragLayer; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; /** * Unit tests for testing modifyTitleToSupportMultiLine() in BubbleTextView.java @@ -50,6 +55,7 @@ import org.junit.Test; */ public class BubbleTextViewTest { + @Rule public StaticMockitoRule mockitoRule = new StaticMockitoRule(Flags.class); private static final StringMatcherUtility.StringMatcher MATCHER = StringMatcherUtility.StringMatcher.getInstance(); private static final int ONE_LINE = 1; @@ -77,6 +83,8 @@ public class BubbleTextViewTest { @Before public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + Mockito.when(Flags.enableTwolineAllapps()).thenReturn(false); Utilities.enableRunningInTestHarnessForTests(); mContext = new ActivityContextWrapper(getApplicationContext()); mBubbleTextView = new BubbleTextView(mContext); diff --git a/tests/src/com/android/launcher3/ui/WorkProfileTest.java b/tests/src/com/android/launcher3/ui/WorkProfileTest.java index ec62058fb2..5b9adcd80f 100644 --- a/tests/src/com/android/launcher3/ui/WorkProfileTest.java +++ b/tests/src/com/android/launcher3/ui/WorkProfileTest.java @@ -15,7 +15,6 @@ */ package com.android.launcher3.ui; -import static com.android.launcher3.Flags.FLAG_ENABLE_EXPANDING_PAUSE_WORK_BUTTON; import static com.android.launcher3.LauncherState.ALL_APPS; import static com.android.launcher3.LauncherState.NORMAL; import static com.android.launcher3.allapps.AllAppsStore.DEFER_UPDATES_TEST; @@ -27,7 +26,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; -import android.platform.test.flag.junit.SetFlagsRule; import android.util.Log; import android.view.View; @@ -46,7 +44,6 @@ import com.android.launcher3.util.rule.TestStabilityRule.Stability; import org.junit.After; import org.junit.Before; import org.junit.Ignore; -import org.junit.Rule; import org.junit.Test; import java.util.Objects; @@ -55,7 +52,6 @@ import java.util.function.Predicate; public class WorkProfileTest extends AbstractLauncherUiTest { private static final int WORK_PAGE = ActivityAllAppsContainerView.AdapterHolder.WORK; - @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); private int mProfileUserId; private boolean mWorkProfileSetupSuccessful; @@ -64,7 +60,6 @@ public class WorkProfileTest extends AbstractLauncherUiTest { @Before @Override public void setUp() throws Exception { - mSetFlagsRule.disableFlags(FLAG_ENABLE_EXPANDING_PAUSE_WORK_BUTTON); super.setUp(); String output = mDevice.executeShellCommand(