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

Commit 3f7a4c27 authored by Pierre Barbier de Reuille's avatar Pierre Barbier de Reuille Committed by Android (Google) Code Review
Browse files

Merge "Use Flags and SystemProperties on debug builds." into main

parents c3d7bbf2 95f1673c
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;
    }