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

Commit c51fb14c authored by Oleg Petšjonkin's avatar Oleg Petšjonkin Committed by Android (Google) Code Review
Browse files

Merge "Creating HDR_OVERRIDE plugin type for display manager" into main

parents 7b8ccec4 f773939d
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -245,6 +245,12 @@ public class DisplayManagerFlags {
            Flags.FLAG_ENABLE_PLUGIN_MANAGER,
            Flags::enablePluginManager
    );

    private final FlagState mEnableHdrOverridePluginTypeFlagState = new FlagState(
            Flags.FLAG_ENABLE_HDR_OVERRIDE_PLUGIN_TYPE,
            Flags::enableHdrOverridePluginType
    );

    private final FlagState mDisplayListenerPerformanceImprovementsFlagState = new FlagState(
            Flags.FLAG_DISPLAY_LISTENER_PERFORMANCE_IMPROVEMENTS,
            Flags::displayListenerPerformanceImprovements
@@ -550,6 +556,10 @@ public class DisplayManagerFlags {
        return mEnablePluginManagerFlagState.isEnabled();
    }

    public boolean isHdrOverrideEnabled() {
        return mEnableHdrOverridePluginTypeFlagState.isEnabled();
    }

    /**
     * @return {@code true} if the flag for display listener performance improvements is enabled
     */
+8 −0
Original line number Diff line number Diff line
@@ -453,6 +453,14 @@ flag {
    is_fixed_read_only: true
}

flag {
    name: "enable_hdr_override_plugin_type"
    namespace: "display_manager"
    description: "Enable hdr override plugin type"
    bug: "389873155"
    is_fixed_read_only: true
}

flag {
    name: "enable_display_content_mode_management"
    namespace: "lse_desktop_experience"
+21 −9
Original line number Diff line number Diff line
@@ -30,7 +30,9 @@ import dalvik.system.PathClassLoader;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Responsible for loading Plugins. Plugins and PluginSupplier are loaded from
@@ -43,7 +45,6 @@ public class PluginManager {
            "com.android.server.display.plugin.PluginsProviderImpl";
    private static final String TAG = "PluginManager";

    private final DisplayManagerFlags mFlags;
    private final PluginStorage mPluginStorage;
    private final List<Plugin> mPlugins;

@@ -53,10 +54,11 @@ public class PluginManager {

    @VisibleForTesting
    PluginManager(Context context, DisplayManagerFlags flags, Injector injector) {
        mFlags = flags;
        mPluginStorage = injector.getPluginStorage();
        if (mFlags.isPluginManagerEnabled()) {
            mPlugins = Collections.unmodifiableList(injector.loadPlugins(context, mPluginStorage));
        Set<PluginType<?>> enabledTypes = injector.getEnabledPluginTypes(flags);
        mPluginStorage = injector.getPluginStorage(enabledTypes);
        if (flags.isPluginManagerEnabled()) {
            mPlugins = Collections.unmodifiableList(injector.loadPlugins(
                    context, mPluginStorage, enabledTypes));
            Slog.d(TAG, "loaded Plugins:" + mPlugins);
        } else {
            mPlugins = List.of();
@@ -110,11 +112,21 @@ public class PluginManager {
    }

    static class Injector {
        PluginStorage getPluginStorage() {
            return new PluginStorage();

        Set<PluginType<?>> getEnabledPluginTypes(DisplayManagerFlags flags) {
            Set<PluginType<?>> enabledTypes = new HashSet<>();
            if (flags.isHdrOverrideEnabled()) {
                enabledTypes.add(PluginType.HDR_BOOST_OVERRIDE);
            }
            return enabledTypes;
        }

        PluginStorage getPluginStorage(Set<PluginType<?>> enabledTypes) {
            return new PluginStorage(enabledTypes);
        }

        List<Plugin> loadPlugins(Context context, PluginStorage storage) {
        List<Plugin> loadPlugins(Context context, PluginStorage storage,
                Set<PluginType<?>> enabledTypes) {
            String providerJarPath = context
                    .getString(com.android.internal.R.string.config_pluginsProviderJarPath);
            Slog.d(TAG, "loading plugins from:" + providerJarPath);
@@ -129,7 +141,7 @@ public class PluginManager {
                Class<? extends PluginsProvider> cp = pathClassLoader.loadClass(PROVIDER_IMPL_CLASS)
                        .asSubclass(PluginsProvider.class);
                PluginsProvider provider = cp.getDeclaredConstructor().newInstance();
                return provider.getPlugins(context, storage);
                return provider.getPlugins(context, storage, enabledTypes);
            } catch (ClassNotFoundException e) {
                Slog.e(TAG, "loading failed: " + PROVIDER_IMPL_CLASS + " is not found in"
                        + providerJarPath, e);
+23 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.tools.r8.keepanno.annotations.KeepForApi;

import java.io.PrintWriter;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
@@ -62,6 +63,12 @@ public class PluginStorage {
        updateValue(type, GLOBAL_ID, value);
    }

    private final Set<PluginType<?>> mEnabledTypes;

    PluginStorage(Set<PluginType<?>> enabledTypes) {
        mEnabledTypes = Collections.unmodifiableSet(enabledTypes);
    }

    /**
     * Updates value in storage and forwards it to corresponding listeners for specific display.
     * Should be called by OEM Plugin implementation in order to communicate with Framework
@@ -71,6 +78,10 @@ public class PluginStorage {
     */
    @KeepForApi
    public <T> void updateValue(PluginType<T> type, String uniqueDisplayId, @Nullable T value) {
        if (isTypeDisabled(type)) {
            Slog.d(TAG, "updateValue ignored for disabled type=" + type.mName);
            return;
        }
        Slog.d(TAG, "updateValue, type=" + type.mName + "; value=" + value
                + "; displayId=" + uniqueDisplayId);
        Set<PluginManager.PluginChangeListener<T>> localListeners;
@@ -119,6 +130,10 @@ public class PluginStorage {
     */
    <T> void addListener(PluginType<T> type, String uniqueDisplayId,
            PluginManager.PluginChangeListener<T> listener) {
        if (isTypeDisabled(type)) {
            Slog.d(TAG, "addListener ignored for disabled type=" + type.mName);
            return;
        }
        if (GLOBAL_ID.equals(uniqueDisplayId)) {
            Slog.d(TAG, "addListener ignored for GLOBAL_ID, type=" + type.mName);
            return;
@@ -141,6 +156,10 @@ public class PluginStorage {
     */
    <T> void removeListener(PluginType<T> type, String uniqueDisplayId,
            PluginManager.PluginChangeListener<T> listener) {
        if (isTypeDisabled(type)) {
            Slog.d(TAG, "removeListener ignored for disabled type=" + type.mName);
            return;
        }
        if (GLOBAL_ID.equals(uniqueDisplayId)) {
            Slog.d(TAG, "removeListener ignored for GLOBAL_ID, type=" + type.mName);
            return;
@@ -183,6 +202,10 @@ public class PluginStorage {
        }
    }

    private boolean isTypeDisabled(PluginType<?> type) {
        return !mEnabledTypes.contains(type);
    }

    @GuardedBy("mLock")
    @SuppressWarnings("unchecked")
    private <T> ListenersContainer<T> getListenersContainerLocked(PluginType<T> type) {
+10 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.display.plugin;

import com.android.internal.annotations.Keep;
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.display.plugin.types.HdrBoostOverride;

/**
 * Represent customisation entry point to Framework. OEM and Framework team should define
@@ -28,6 +29,15 @@ import com.android.internal.annotations.VisibleForTesting;
 */
@Keep
public class PluginType<T> {
    /*
    * PluginType for HDR boost override. If set, system will use overridden value instead
    * system default parameters. To switch back to default system behaviour, Plugin should set
    * this type value to null.
    * Value change will trigger whole power state recalculation, so plugins should not update
    * value for this type too often.
    */
    public static final PluginType<HdrBoostOverride> HDR_BOOST_OVERRIDE = new PluginType<>(
            HdrBoostOverride.class, "hdr_boost_override");

    final Class<T> mType;
    final String mName;
Loading