Loading src/com/android/launcher3/config/FeatureFlags.java +12 −2 Original line number Diff line number Diff line Loading @@ -21,9 +21,14 @@ import static com.android.launcher3.uioverrides.flags.FlagsFactory.getReleaseFla import android.content.Context; import androidx.annotation.VisibleForTesting; import com.android.launcher3.BuildConfig; import com.android.launcher3.Utilities; import java.util.function.Predicate; import java.util.function.ToIntFunction; /** * Defines a set of flags used to control various launcher behaviors. * Loading @@ -33,6 +38,11 @@ public final class FeatureFlags { public static final String FLAGS_PREF_NAME = "featureFlags"; @VisibleForTesting public static Predicate<BooleanFlag> sBooleanReader = f -> f.mCurrentValue; @VisibleForTesting public static ToIntFunction<IntFlag> sIntReader = f -> f.mCurrentValue; private FeatureFlags() { } public static boolean showFlagTogglerUi(Context context) { Loading Loading @@ -385,7 +395,7 @@ public final class FeatureFlags { } public boolean get() { return mCurrentValue; return sBooleanReader.test(this); } } Loading @@ -401,7 +411,7 @@ public final class FeatureFlags { } public int get() { return mCurrentValue; return sIntReader.applyAsInt(this); } } } tests/src/com/android/launcher3/util/TestUtil.java +36 −0 Original line number Diff line number Diff line Loading @@ -27,12 +27,18 @@ import android.os.UserHandle; import androidx.test.uiautomator.UiDevice; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.config.FeatureFlags.BooleanFlag; import com.android.launcher3.config.FeatureFlags.IntFlag; import org.junit.Assert; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.concurrent.CountDownLatch; import java.util.function.Predicate; import java.util.function.ToIntFunction; public class TestUtil { public static final String DUMMY_PACKAGE = "com.example.android.aardwolf"; Loading Loading @@ -68,6 +74,36 @@ public class TestUtil { } } /** * Utility class to override a boolean flag during test. Note that the returned SafeCloseable * must be closed to restore the original state */ public static SafeCloseable overrideFlag(BooleanFlag flag, boolean value) { Predicate<BooleanFlag> originalProxy = FeatureFlags.sBooleanReader; Predicate<BooleanFlag> testProxy = f -> f == flag ? value : originalProxy.test(f); FeatureFlags.sBooleanReader = testProxy; return () -> { if (FeatureFlags.sBooleanReader == testProxy) { FeatureFlags.sBooleanReader = originalProxy; } }; } /** * Utility class to override a int flag during test. Note that the returned SafeCloseable * must be closed to restore the original state */ public static SafeCloseable overrideFlag(IntFlag flag, int value) { ToIntFunction<IntFlag> originalProxy = FeatureFlags.sIntReader; ToIntFunction<IntFlag> testProxy = f -> f == flag ? value : originalProxy.applyAsInt(f); FeatureFlags.sIntReader = testProxy; return () -> { if (FeatureFlags.sIntReader == testProxy) { FeatureFlags.sIntReader = originalProxy; } }; } public static void uninstallDummyApp() throws IOException { UiDevice.getInstance(getInstrumentation()).executeShellCommand( "pm uninstall " + DUMMY_PACKAGE); Loading Loading
src/com/android/launcher3/config/FeatureFlags.java +12 −2 Original line number Diff line number Diff line Loading @@ -21,9 +21,14 @@ import static com.android.launcher3.uioverrides.flags.FlagsFactory.getReleaseFla import android.content.Context; import androidx.annotation.VisibleForTesting; import com.android.launcher3.BuildConfig; import com.android.launcher3.Utilities; import java.util.function.Predicate; import java.util.function.ToIntFunction; /** * Defines a set of flags used to control various launcher behaviors. * Loading @@ -33,6 +38,11 @@ public final class FeatureFlags { public static final String FLAGS_PREF_NAME = "featureFlags"; @VisibleForTesting public static Predicate<BooleanFlag> sBooleanReader = f -> f.mCurrentValue; @VisibleForTesting public static ToIntFunction<IntFlag> sIntReader = f -> f.mCurrentValue; private FeatureFlags() { } public static boolean showFlagTogglerUi(Context context) { Loading Loading @@ -385,7 +395,7 @@ public final class FeatureFlags { } public boolean get() { return mCurrentValue; return sBooleanReader.test(this); } } Loading @@ -401,7 +411,7 @@ public final class FeatureFlags { } public int get() { return mCurrentValue; return sIntReader.applyAsInt(this); } } }
tests/src/com/android/launcher3/util/TestUtil.java +36 −0 Original line number Diff line number Diff line Loading @@ -27,12 +27,18 @@ import android.os.UserHandle; import androidx.test.uiautomator.UiDevice; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.config.FeatureFlags.BooleanFlag; import com.android.launcher3.config.FeatureFlags.IntFlag; import org.junit.Assert; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.concurrent.CountDownLatch; import java.util.function.Predicate; import java.util.function.ToIntFunction; public class TestUtil { public static final String DUMMY_PACKAGE = "com.example.android.aardwolf"; Loading Loading @@ -68,6 +74,36 @@ public class TestUtil { } } /** * Utility class to override a boolean flag during test. Note that the returned SafeCloseable * must be closed to restore the original state */ public static SafeCloseable overrideFlag(BooleanFlag flag, boolean value) { Predicate<BooleanFlag> originalProxy = FeatureFlags.sBooleanReader; Predicate<BooleanFlag> testProxy = f -> f == flag ? value : originalProxy.test(f); FeatureFlags.sBooleanReader = testProxy; return () -> { if (FeatureFlags.sBooleanReader == testProxy) { FeatureFlags.sBooleanReader = originalProxy; } }; } /** * Utility class to override a int flag during test. Note that the returned SafeCloseable * must be closed to restore the original state */ public static SafeCloseable overrideFlag(IntFlag flag, int value) { ToIntFunction<IntFlag> originalProxy = FeatureFlags.sIntReader; ToIntFunction<IntFlag> testProxy = f -> f == flag ? value : originalProxy.applyAsInt(f); FeatureFlags.sIntReader = testProxy; return () -> { if (FeatureFlags.sIntReader == testProxy) { FeatureFlags.sIntReader = originalProxy; } }; } public static void uninstallDummyApp() throws IOException { UiDevice.getInstance(getInstrumentation()).executeShellCommand( "pm uninstall " + DUMMY_PACKAGE); Loading