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

Commit 688e9896 authored by Ryan Lothian's avatar Ryan Lothian
Browse files

Groundwork for runtime-toggleable feature flags

This is the first step in adding a flag toggler UI to launcher.
The change migrates a single flag (QSB_ON_FIRST_SCREEN) from a
boolean constant to a boolean method. In future, that will allow
us to return different values at runtime.

Bug: 117223984
Change-Id: I1e62c91dd941b8145166021bc0aa157733e62ea0
parent cd72d37a
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -16,10 +16,17 @@

package com.android.launcher3.config;

import android.content.Context;

/**
 * Defines a set of flags used to control various launcher behaviors
 */
public final class FeatureFlags extends BaseFlags {
    private static FeatureFlags instance = new FeatureFlags();

    public static FeatureFlags getInstance(Context context) {
        return instance;
    }

    private FeatureFlags() {}

+5 −3
Original line number Diff line number Diff line
@@ -1752,12 +1752,13 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
    @Override
    public void bindScreens(ArrayList<Long> orderedScreenIds) {
        // Make sure the first screen is always at the start.
        if (FeatureFlags.QSB_ON_FIRST_SCREEN &&
        if (FeatureFlags.getInstance(this).isQsbOnFirstScreenEnabled() &&
                orderedScreenIds.indexOf(Workspace.FIRST_SCREEN_ID) != 0) {
            orderedScreenIds.remove(Workspace.FIRST_SCREEN_ID);
            orderedScreenIds.add(0, Workspace.FIRST_SCREEN_ID);
            LauncherModel.updateWorkspaceScreenOrder(this, orderedScreenIds);
        } else if (!FeatureFlags.QSB_ON_FIRST_SCREEN && orderedScreenIds.isEmpty()) {
        } else if (!FeatureFlags.getInstance(this).isQsbOnFirstScreenEnabled()
                && orderedScreenIds.isEmpty()) {
            // If there are no screens, we need to have an empty screen
            mWorkspace.addExtraEmptyScreen();
        }
@@ -1773,7 +1774,8 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
        int count = orderedScreenIds.size();
        for (int i = 0; i < count; i++) {
            long screenId = orderedScreenIds.get(i);
            if (!FeatureFlags.QSB_ON_FIRST_SCREEN || screenId != Workspace.FIRST_SCREEN_ID) {
            if (!FeatureFlags.getInstance(this).isQsbOnFirstScreenEnabled()
                    || screenId != Workspace.FIRST_SCREEN_ID) {
                // No need to bind the first screen, as its always bound.
                mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(screenId);
            }
+1 −1
Original line number Diff line number Diff line
@@ -789,7 +789,7 @@ public class LauncherProvider extends ContentProvider {
                    convertShortcutsToLauncherActivities(db);
                case 26:
                    // QSB was moved to the grid. Clear the first row on screen 0.
                    if (FeatureFlags.QSB_ON_FIRST_SCREEN &&
                    if (FeatureFlags.getInstance(mContext).isQsbOnFirstScreenEnabled() &&
                            !LauncherDbUtils.prepareScreenZeroToHostQsb(mContext, db)) {
                        break;
                    }
+4 −2
Original line number Diff line number Diff line
@@ -479,7 +479,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
     * @param qsb an existing qsb to recycle or null.
     */
    public void bindAndInitFirstWorkspaceScreen(View qsb) {
        if (!FeatureFlags.QSB_ON_FIRST_SCREEN) {
        if (!FeatureFlags.getInstance(getContext()).isQsbOnFirstScreenEnabled()) {
            return;
        }
        // Add the first page
@@ -778,7 +778,9 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
            long id = mWorkspaceScreens.keyAt(i);
            CellLayout cl = mWorkspaceScreens.valueAt(i);
            // FIRST_SCREEN_ID can never be removed.
            if ((!FeatureFlags.QSB_ON_FIRST_SCREEN || id > FIRST_SCREEN_ID)
            boolean qsbFirstScreenEnabled = 
                    FeatureFlags.getInstance(getContext()).isQsbOnFirstScreenEnabled();
            if ((!qsbFirstScreenEnabled || id > FIRST_SCREEN_ID)
                    && cl.getShortcutsAndWidgets().getChildCount() == 0) {
                removeScreens.add(id);
            }
+10 −6
Original line number Diff line number Diff line
@@ -19,14 +19,16 @@ package com.android.launcher3.config;
/**
 * Defines a set of flags used to control various launcher behaviors.
 *
 * All the flags should be defined here with appropriate default values. To override a value,
 * redefine it in {@link FeatureFlags}.
 * <p>All the flags should be defined here with appropriate default values.
 *
 * This class is kept package-private to prevent direct access.
 * <p>This class is kept package-private to prevent direct access.
 */
abstract class BaseFlags {

    BaseFlags() {}
    private static final String TAG = "FeatureFlags";

    BaseFlags() {
    }

    public static final boolean IS_DOGFOOD_BUILD = false;
    public static final String AUTHORITY = "com.android.launcher3.settings".intern();
@@ -34,8 +36,10 @@ abstract class BaseFlags {
    // When enabled the promise icon is visible in all apps while installation an app.
    public static final boolean LAUNCHER3_PROMISE_APPS_IN_ALL_APPS = false;

    // Feature flag to enable moving the QSB on the 0th screen of the workspace.
    public static final boolean QSB_ON_FIRST_SCREEN = true;
    /** Feature flag to enable moving the QSB on the 0th screen of the workspace. */
    public boolean isQsbOnFirstScreenEnabled() {
        return true;
    }

    //Feature flag to enable pulling down navigation shade from workspace.
    public static final boolean PULL_DOWN_STATUS_BAR = true;
Loading