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

Commit 95f1673c authored by Pierre Barbier de Reuille's avatar Pierre Barbier de Reuille
Browse files

Use Flags and SystemProperties on debug builds.

This will allow us to turn the feature on and off using `adb` commands
without rebuilding.

We'll limit this to debug builds to be safe.

After this CL, the feature can be enabled with:

```
adb shell setprop \
persist.sys.com.android.server.display.feature.flags.enable_connected_display_management \
true && adb reboot
```

Test: Manually tested that changing the flag enable the feature
Bug: 297159910
Change-Id: I5bcc03183cef047ae4ed3c1c0fff9450bbe996dd
parent 1f5b8523
Loading
Loading
Loading
Loading
+27 −14
Original line number Diff line number Diff line
@@ -16,20 +16,39 @@

package com.android.server.display.feature;

import android.os.Build;
import android.os.SystemProperties;
import android.util.Slog;

import com.android.server.display.feature.flags.Flags;

import java.util.function.Supplier;

/**
 * Utility class to read the flags used in the display manager server.
 */
public class DisplayManagerFlags {
    private static final boolean DEBUG = false;
    private static final String TAG = "DisplayManagerFlags";
    private static final boolean DEFAULT_IS_CONNECTED_DISPLAY_MANAGEMENT_ENABLED = false;
    private boolean mIsConnectedDisplayManagementEnabled = false;
    private boolean mIsConnectedDisplayManagementEnabledSet = false;

    private boolean flagOrSystemProperty(Supplier<Boolean> flagFunction, String flagName) {
        // TODO(b/299462337) Remove when the infrastructure is ready.
        if ((Build.IS_ENG || Build.IS_USERDEBUG)
                    && SystemProperties.getBoolean("persist.sys." + flagName, false)) {
            return true;
        }
        try {
            return flagFunction.get();
        } catch (Throwable ex) {
            if (DEBUG) {
                Slog.i(TAG, "Flags not ready yet. Return false for " + flagName, ex);
            }
            return false;
        }
    }

    // TODO(b/297159910): Simplify using READ-ONLY flags when available.
    /** Returns whether connected display management is enabled or not. */
    public boolean isConnectedDisplayManagementEnabled() {
@@ -40,19 +59,13 @@ public class DisplayManagerFlags {
            }
            return mIsConnectedDisplayManagementEnabled;
        }
        try {
            mIsConnectedDisplayManagementEnabled = Flags.enableConnectedDisplayManagement();
        mIsConnectedDisplayManagementEnabled =
                flagOrSystemProperty(Flags::enableConnectedDisplayManagement,
                        Flags.FLAG_ENABLE_CONNECTED_DISPLAY_MANAGEMENT);
        if (DEBUG) {
            Slog.d(TAG, "isConnectedDisplayManagementEnabled. Flag value = "
                                + mIsConnectedDisplayManagementEnabled);
        }
        } catch (Throwable ex) {
            if (DEBUG) {
                Slog.i(TAG, "isConnectedDisplayManagementEnabled not available: set to "
                        + DEFAULT_IS_CONNECTED_DISPLAY_MANAGEMENT_ENABLED, ex);
            }
            mIsConnectedDisplayManagementEnabled = DEFAULT_IS_CONNECTED_DISPLAY_MANAGEMENT_ENABLED;
        }
        mIsConnectedDisplayManagementEnabledSet = true;
        return mIsConnectedDisplayManagementEnabled;
    }