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

Commit c1a968a8 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick
Browse files

Option to enable StrictMode flashing on userdebug builds.

Change-Id: Ifc8e733ea0e0f6bda234a18ad84bcd230879e802
parent 1e87fe85
Loading
Loading
Loading
Loading
+32 −12
Original line number Diff line number Diff line
@@ -113,6 +113,13 @@ public final class StrictMode {
    private static final boolean IS_USER_BUILD = "user".equals(Build.TYPE);
    private static final boolean IS_ENG_BUILD = "eng".equals(Build.TYPE);

    /**
     * The boolean system property to control screen flashes on violations.
     *
     * @hide
     */
    public static final String VISUAL_PROPERTY = "persist.sys.strictmode.visual";

    // Only log a duplicate stack trace to the logs every second.
    private static final long MIN_LOG_INTERVAL_MS = 1000;

@@ -718,23 +725,36 @@ public final class StrictMode {
     * @hide
     */
    public static boolean conditionallyEnableDebugLogging() {
        boolean doFlashes = SystemProperties.getBoolean(VISUAL_PROPERTY, IS_ENG_BUILD);

        // For debug builds, log event loop stalls to dropbox for analysis.
        // Similar logic also appears in ActivityThread.java for system apps.
        if (IS_USER_BUILD) {
        if (IS_USER_BUILD && !doFlashes) {
            setCloseGuardEnabled(false);
            return false;
        }
        StrictMode.setThreadPolicyMask(
            StrictMode.DETECT_DISK_WRITE |

        int threadPolicyMask = StrictMode.DETECT_DISK_WRITE |
                StrictMode.DETECT_DISK_READ |
            StrictMode.DETECT_NETWORK |
            StrictMode.PENALTY_DROPBOX |
            (IS_ENG_BUILD ? StrictMode.PENALTY_FLASH : 0)
        );
                StrictMode.DETECT_NETWORK;

        if (!IS_USER_BUILD) {
            threadPolicyMask |= StrictMode.PENALTY_DROPBOX;
        }
        if (doFlashes) {
            threadPolicyMask |= StrictMode.PENALTY_FLASH;
        }

        StrictMode.setThreadPolicyMask(threadPolicyMask);

        if (IS_USER_BUILD) {
            setCloseGuardEnabled(false);
        } else {
            sVmPolicyMask = StrictMode.DETECT_VM_CURSOR_LEAKS |
                    StrictMode.DETECT_VM_CLOSABLE_LEAKS |
                    StrictMode.PENALTY_DROPBOX;
            setCloseGuardEnabled(vmClosableObjectLeaksEnabled());
        }
        return true;
    }

+1 −1
Original line number Diff line number Diff line
@@ -93,7 +93,7 @@ public class SystemProperties
     * Get the value for the given key, returned as a boolean.
     * Values 'n', 'no', '0', 'false' or 'off' are considered false.
     * Values 'y', 'yes', '1', 'true' or 'on' are considered true.
     * (case insensitive).
     * (case sensitive).
     * If the key does not exist, or has any other value, then the default
     * result is returned.
     * @param key the key to lookup
+6 −0
Original line number Diff line number Diff line
@@ -140,6 +140,12 @@ interface IWindowManager
    // on screen)
    void showStrictModeViolation(boolean on);

    // Proxy to set the system property for whether the flashing
    // should be enabled.  The 'enabled' value is null or blank for
    // the system default (differs per build variant) or any valid
    // boolean string as parsed by SystemProperties.getBoolean().
    void setStrictModeVisualIndicatorPreference(String enabled);

    // These can only be called with the SET_ORIENTATION permission.
    /**
     * Change the current screen rotation, constants as per
+4 −0
Original line number Diff line number Diff line
@@ -4918,6 +4918,10 @@ public class WindowManagerService extends IWindowManager.Stub
        }
    }

    public void setStrictModeVisualIndicatorPreference(String value) {
        SystemProperties.set(StrictMode.VISUAL_PROPERTY, value);
    }

    public void freezeRotation() {
        if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
                "setRotation()")) {