Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fb9c4d25 authored by Brandon Dayauon's avatar Brandon Dayauon Committed by Android (Google) Code Review
Browse files

Merge "Method to override feature flag" into tm-qpr-dev

parents 65a0ee77 533e4856
Loading
Loading
Loading
Loading
+5 −10
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import com.android.launcher3.pm.UserCache
import com.android.launcher3.provider.LauncherDbUtils
import com.android.launcher3.util.LauncherModelHelper
import com.android.launcher3.util.LauncherModelHelper.*
import com.android.launcher3.util.TestUtil
import com.google.common.truth.Truth.assertThat
import org.junit.After
import org.junit.Before
@@ -750,20 +751,14 @@ class GridSizeMigrationUtilTest {
    }

    private fun enableNewMigrationLogic(srcGridSize: String) {
        context
            .getSharedPreferences(FeatureFlags.FLAGS_PREF_NAME, Context.MODE_PRIVATE)
            .edit()
            .putBoolean(FeatureFlags.ENABLE_NEW_MIGRATION_LOGIC.key, true)
            .commit()
        LauncherPrefs.get(context).putSync(WORKSPACE_SIZE.to(srcGridSize))
        TestUtil.overrideBooleanFlagValue(context,
                FeatureFlags.ENABLE_NEW_MIGRATION_LOGIC, true);
        FeatureFlags.initialize(context)
    }

    private fun disableNewMigrationLogic() {
        context
            .getSharedPreferences(FeatureFlags.FLAGS_PREF_NAME, Context.MODE_PRIVATE)
            .edit()
            .putBoolean(FeatureFlags.ENABLE_NEW_MIGRATION_LOGIC.key, false)
            .commit()
        TestUtil.overrideBooleanFlagValue(context,
                FeatureFlags.ENABLE_NEW_MIGRATION_LOGIC, false);
    }
}
+3 −4
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.tapl.LauncherInstrumentation;
import com.android.launcher3.ui.AbstractLauncherUiTest;
import com.android.launcher3.util.LauncherModelHelper;
import com.android.launcher3.util.TestUtil;

import org.junit.After;
import org.junit.Ignore;
@@ -278,10 +279,8 @@ public final class SecondaryDisplayLauncherTest extends AbstractLauncherUiTest {

    private void setDragNDropFlag(Boolean status) {
        Context context = new LauncherModelHelper().sandboxContext;
        context.getSharedPreferences(FeatureFlags.FLAGS_PREF_NAME, Context.MODE_PRIVATE).edit()
                .putBoolean(FeatureFlags.SECONDARY_DRAG_N_DROP_TO_PIN.key, status)
                .commit();
        FeatureFlags.initialize(context);
        TestUtil.overrideBooleanFlagValue(
                context, FeatureFlags.SECONDARY_DRAG_N_DROP_TO_PIN, status);
        startSecondaryDisplayActivity();
    }
}
+16 −0
Original line number Diff line number Diff line
@@ -19,14 +19,18 @@ import static androidx.test.InstrumentationRegistry.getContext;
import static androidx.test.InstrumentationRegistry.getInstrumentation;
import static androidx.test.InstrumentationRegistry.getTargetContext;

import android.content.Context;
import android.content.pm.LauncherApps;
import android.content.res.Resources;
import android.os.Handler;
import android.os.Looper;
import android.os.UserHandle;

import androidx.annotation.VisibleForTesting;
import androidx.test.uiautomator.UiDevice;

import com.android.launcher3.config.FeatureFlags;

import org.junit.Assert;

import java.io.FileOutputStream;
@@ -68,6 +72,18 @@ public class TestUtil {
        }
    }

    @VisibleForTesting
    // Override feature flag, mainly to be used ONLY in tests
    public static void overrideBooleanFlagValue(
            Context context, FeatureFlags.BooleanFlag flagToOverride,
            boolean bool) {
        context.getSharedPreferences(FeatureFlags.FLAGS_PREF_NAME, Context.MODE_PRIVATE)
                .edit()
                .putBoolean(flagToOverride.key, bool)
                .commit();
        FeatureFlags.initialize(context);
    }

    public static void uninstallDummyApp() throws IOException {
        UiDevice.getInstance(getInstrumentation()).executeShellCommand(
                "pm uninstall " + DUMMY_PACKAGE);