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

Commit cc2212d2 authored by Mark Renouf's avatar Mark Renouf Committed by Android (Google) Code Review
Browse files

Merge "Adds system property for developer option for force-enable burn-in...

Merge "Adds system property for developer option for force-enable burn-in protection" into lmp-mr1-modular-dev
parents 1d0b0edd 77ac63b0
Loading
Loading
Loading
Loading
+15 −17
Original line number Diff line number Diff line
@@ -9,8 +9,10 @@ import android.content.IntentFilter;
import android.content.res.Resources;
import android.hardware.display.DisplayManager;
import android.hardware.display.DisplayManagerInternal;
import android.os.Build;
import android.os.Handler;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.util.Log;
import android.view.Display;

@@ -23,7 +25,7 @@ public class BurnInProtectionHelper implements DisplayManager.DisplayListener {
    private static final String TAG = "BurnInProtection";

    // Default value when max burnin radius is not set.
    public static final int BURN_IN_RADIUS_MAX_DEFAULT = -1;
    public static final int BURN_IN_MAX_RADIUS_DEFAULT = -1;

    private static final long BURNIN_PROTECTION_WAKEUP_INTERVAL_MS = TimeUnit.MINUTES.toMillis(1);
    private static final long BURNIN_PROTECTION_MINIMAL_INTERVAL_MS = TimeUnit.SECONDS.toMillis(10);
@@ -61,22 +63,18 @@ public class BurnInProtectionHelper implements DisplayManager.DisplayListener {
        }
    };
    
    public BurnInProtectionHelper(Context context) {
    public BurnInProtectionHelper(Context context, int minHorizontalOffset,
            int maxHorizontalOffset, int minVerticalOffset, int maxVerticalOffset,
            int maxOffsetRadius) {
        final Resources resources = context.getResources();
        mMinHorizontalBurnInOffset = resources.getInteger(
                com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
        mMaxHorizontalBurnInOffset = resources.getInteger(
                com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
        mMinVerticalBurnInOffset = resources.getInteger(
                com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
        mMaxVerticalBurnInOffset = resources.getInteger(
                com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
        int burnInRadiusMax = resources.getInteger(
                com.android.internal.R.integer.config_burnInProtectionMaxRadius);
        if (burnInRadiusMax != BURN_IN_RADIUS_MAX_DEFAULT) {
            mBurnInRadiusMaxSquared = burnInRadiusMax * burnInRadiusMax;
        mMinHorizontalBurnInOffset = minHorizontalOffset;
        mMaxHorizontalBurnInOffset = maxHorizontalOffset;
        mMinVerticalBurnInOffset = minVerticalOffset;
        mMaxVerticalBurnInOffset = maxHorizontalOffset;
        if (maxOffsetRadius != BURN_IN_MAX_RADIUS_DEFAULT) {
            mBurnInRadiusMaxSquared = maxOffsetRadius * maxOffsetRadius;
        } else {
            mBurnInRadiusMaxSquared = BURN_IN_RADIUS_MAX_DEFAULT;
            mBurnInRadiusMaxSquared = BURN_IN_MAX_RADIUS_DEFAULT;
        }

        mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class);
@@ -161,7 +159,7 @@ public class BurnInProtectionHelper implements DisplayManager.DisplayListener {
                }
            }
            // If we are outside of the radius, let's try again.
        } while (mBurnInRadiusMaxSquared != BURN_IN_RADIUS_MAX_DEFAULT
        } while (mBurnInRadiusMaxSquared != BURN_IN_MAX_RADIUS_DEFAULT
                && mLastBurnInXOffset * mLastBurnInXOffset + mLastBurnInYOffset * mLastBurnInYOffset
                        > mBurnInRadiusMaxSquared);
    }
+42 −3
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import android.media.IAudioService;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.media.session.MediaSessionLegacyHelper;
import android.os.Build;
import android.os.Bundle;
import android.os.Debug;
import android.os.FactoryTest;
@@ -91,6 +92,7 @@ import android.view.MotionEvent;
import android.view.Surface;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewRootImpl;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManagerGlobal;
@@ -1187,6 +1189,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
    };

    private boolean isRoundWindow() {
        return mContext.getResources().getBoolean(com.android.internal.R.bool.config_windowIsRound)
                || (Build.HARDWARE.contains("goldfish")
                && SystemProperties.getBoolean(ViewRootImpl.PROPERTY_EMULATOR_CIRCULAR, false));
    }

    /** {@inheritDoc} */
    @Override
    public void init(Context context, IWindowManager windowManager,
@@ -1196,9 +1204,40 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        mWindowManagerFuncs = windowManagerFuncs;
        mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
        mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
        if (context.getResources().getBoolean(
                com.android.internal.R.bool.config_enableBurnInProtection)){
            mBurnInProtectionHelper = new BurnInProtectionHelper(context);

        // Init display burn-in protection
        boolean burnInProtectionEnabled = context.getResources().getBoolean(
                com.android.internal.R.bool.config_enableBurnInProtection);
        // Allow a system property to override this. Used by developer settings.
        boolean burnInProtectionDevMode =
                SystemProperties.getBoolean("persist.debug.force_burn_in", false);
        if (burnInProtectionEnabled || burnInProtectionDevMode) {
            final int minHorizontal;
            final int maxHorizontal;
            final int minVertical;
            final int maxVertical;
            final int maxRadius;
            if (burnInProtectionDevMode) {
                minHorizontal = -8;
                maxHorizontal = 8;
                minVertical = -8;
                maxVertical = -4;
                maxRadius = (isRoundWindow()) ? 6 : -1;
            } else {
                Resources resources = context.getResources();
                minHorizontal = resources.getInteger(
                        com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
                maxHorizontal = resources.getInteger(
                        com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
                minVertical = resources.getInteger(
                        com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
                maxVertical = resources.getInteger(
                        com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
                maxRadius = resources.getInteger(
                        com.android.internal.R.integer.config_burnInProtectionMaxRadius);
            }
            mBurnInProtectionHelper = new BurnInProtectionHelper(
                    context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
        }

        mHandler = new PolicyHandler();