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

Commit 088d7c09 authored by Galia Peycheva's avatar Galia Peycheva
Browse files

Add minimal post processing flag in Settings.Secure

Minimal post processing might not be very well supported on all TV
displays (e.g.the switch to/out of the low latency mode might be too
slow or there might be flickering on the screen or some color
interference, etc). This depends on the vendor implementation of minimal
post processing. In such cases, we want to give the user an option to
disable this feature in the settings menu. This means that any calls to
the API (Window.setMinimalPostProcessing) will be ignored and no signals
will be sent to the display.

This CL adds the necessary flag to Settings.Secure. The value is read
from DisplayManagerService, which combines it with the information from
the WindowManager and the display capabilities to request the right low
latency mode on the display.

Bug: 144356279

Test: m && ./vendor/google/tools/flashall
      1. adb shell settings put secure minimal_post_processing_allowed 1
      2. Open Activity that prefers minimal post processing
      3. adb shell settings put secure minimal_post_processing_allowed 0
         -> this should turn ALLM off
      4. adb shell settings put secure minimal_post_processing_allowed 1
         -> this should turn ALLM back on
      5. Exit Activity
         -> this should turn ALLM off

Change-Id: I2d24a9a004d4939b0439d466ef2ca279803fd67f
parent 8021efab
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -7378,6 +7378,21 @@ public final class Settings {
        @UnsupportedAppUsage
        public static final String INCALL_POWER_BUTTON_BEHAVIOR = "incall_power_button_behavior";
        /**
         * Whether the user allows minimal post processing or not.
         *
         * <p>Values:
         * 0 - Not allowed. Any preferences set through the Window.setPreferMinimalPostProcessing
         *     API will be ignored.
         * 1 - Allowed. Any preferences set through the Window.setPreferMinimalPostProcessing API
         *     will be respected and the appropriate signals will be sent to display.
         *     (Default behaviour)
         *
         * @hide
         */
        public static final String MINIMAL_POST_PROCESSING_ALLOWED =
                "minimal_post_processing_allowed";
        /**
         * INCALL_POWER_BUTTON_BEHAVIOR value for "turn off screen".
         * @hide
+1 −0
Original line number Diff line number Diff line
@@ -85,6 +85,7 @@ public class SecureSettings {
        Settings.Secure.TTY_MODE_ENABLED,
        Settings.Secure.RTT_CALLING_MODE,
        Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
        Settings.Secure.MINIMAL_POST_PROCESSING_ALLOWED,
        Settings.Secure.NIGHT_DISPLAY_CUSTOM_START_TIME,
        Settings.Secure.NIGHT_DISPLAY_CUSTOM_END_TIME,
        Settings.Secure.NIGHT_DISPLAY_COLOR_TEMPERATURE,
+1 −0
Original line number Diff line number Diff line
@@ -131,6 +131,7 @@ public class SecureSettingsValidators {
        VALIDATORS.put(
                Secure.INCALL_POWER_BUTTON_BEHAVIOR,
                new DiscreteValueValidator(new String[] {"1", "2"}));
        VALIDATORS.put(Secure.MINIMAL_POST_PROCESSING_ALLOWED, BOOLEAN_VALIDATOR);
        VALIDATORS.put(Secure.NIGHT_DISPLAY_CUSTOM_START_TIME, NON_NEGATIVE_INTEGER_VALIDATOR);
        VALIDATORS.put(Secure.NIGHT_DISPLAY_CUSTOM_END_TIME, NON_NEGATIVE_INTEGER_VALIDATOR);
        VALIDATORS.put(Secure.NIGHT_DISPLAY_COLOR_TEMPERATURE, NON_NEGATIVE_INTEGER_VALIDATOR);
+49 −8
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.content.pm.PackageManager;
import android.content.pm.ParceledListSlice;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.database.ContentObserver;
import android.graphics.ColorSpace;
import android.graphics.Point;
import android.graphics.Rect;
@@ -60,6 +61,7 @@ import android.hardware.display.WifiDisplayStatus;
import android.hardware.input.InputManagerInternal;
import android.media.projection.IMediaProjection;
import android.media.projection.IMediaProjectionManager;
import android.net.Uri;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
@@ -77,6 +79,7 @@ import android.os.SystemProperties;
import android.os.Trace;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.IntArray;
import android.util.Pair;
@@ -304,6 +307,13 @@ public final class DisplayManagerService extends SystemService {

    private SensorManager mSensorManager;

    // Whether minimal post processing is allowed by the user.
    @GuardedBy("mSyncRoot")
    private boolean mMinimalPostProcessingAllowed;

    // Receives notifications about changes to Settings.
    private SettingsObserver mSettingsObserver;

    public DisplayManagerService(Context context) {
        this(context, new Injector());
    }
@@ -403,6 +413,7 @@ public final class DisplayManagerService extends SystemService {
                BrightnessConfiguration config =
                        mPersistentDataStore.getBrightnessConfiguration(userSerial);
                mDisplayPowerController.setBrightnessConfiguration(config);
                handleSettingsChange();
            }
            mDisplayPowerController.onSwitchUser(newUserId);
        }
@@ -428,6 +439,8 @@ public final class DisplayManagerService extends SystemService {
            // Just in case the top inset changed before the system was ready. At this point, any
            // relevant configuration should be in place.
            recordTopInsetLocked(mLogicalDisplays.get(Display.DEFAULT_DISPLAY));

            updateSettingsLocked();
        }

        mDisplayModeDirector.setDesiredDisplayModeSpecsListener(
@@ -435,6 +448,8 @@ public final class DisplayManagerService extends SystemService {
        mDisplayModeDirector.start(mSensorManager);

        mHandler.sendEmptyMessage(MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS);

        mSettingsObserver = new SettingsObserver();
    }

    @VisibleForTesting
@@ -569,6 +584,33 @@ public final class DisplayManagerService extends SystemService {
        }
    }

    private class SettingsObserver extends ContentObserver {
        SettingsObserver() {
            super(mHandler);

            mContext.getContentResolver().registerContentObserver(
                    Settings.Secure.getUriFor(
                        Settings.Secure.MINIMAL_POST_PROCESSING_ALLOWED), false, this);
        }

        @Override
        public void onChange(boolean selfChange, Uri uri) {
            handleSettingsChange();
        }
    }

    private void handleSettingsChange() {
        synchronized (mSyncRoot) {
            updateSettingsLocked();
            scheduleTraversalLocked(false);
        }
    }

    private void updateSettingsLocked() {
        mMinimalPostProcessingAllowed = Settings.Secure.getIntForUser(mContext.getContentResolver(),
                Settings.Secure.MINIMAL_POST_PROCESSING_ALLOWED, 1, UserHandle.USER_CURRENT) != 0;
    }

    private DisplayInfo getDisplayInfoInternal(int displayId, int callingUid) {
        synchronized (mSyncRoot) {
            LogicalDisplay display = mLogicalDisplays.get(displayId);
@@ -1192,7 +1234,7 @@ public final class DisplayManagerService extends SystemService {
    }

    private void setDisplayPropertiesInternal(int displayId, boolean hasContent,
            float requestedRefreshRate, int requestedModeId, boolean requestedMinimalPostProcessing,
            float requestedRefreshRate, int requestedModeId, boolean preferMinimalPostProcessing,
            boolean inTraversal) {
        synchronized (mSyncRoot) {
            LogicalDisplay display = mLogicalDisplays.get(displayId);
@@ -1220,15 +1262,14 @@ public final class DisplayManagerService extends SystemService {
            mDisplayModeDirector.getAppRequestObserver().setAppRequestedMode(
                    displayId, requestedModeId);

            if (display.getDisplayInfoLocked().minimalPostProcessingSupported) {
                boolean mppRequest = mMinimalPostProcessingAllowed && preferMinimalPostProcessing;

            if (display.getDisplayInfoLocked().minimalPostProcessingSupported
                    && (display.getRequestedMinimalPostProcessingLocked()
                    != requestedMinimalPostProcessing)) {

                display.setRequestedMinimalPostProcessingLocked(requestedMinimalPostProcessing);

                if (display.getRequestedMinimalPostProcessingLocked() != mppRequest) {
                    display.setRequestedMinimalPostProcessingLocked(mppRequest);
                    shouldScheduleTraversal = true;
                }
            }

            if (shouldScheduleTraversal) {
                scheduleTraversalLocked(inTraversal);