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

Commit b589f47d authored by Joe Onorato's avatar Joe Onorato Committed by Android (Google) Code Review
Browse files

Merge "Move around the HDMI switch detection so we don't try to get the status...

Merge "Move around the HDMI switch detection so we don't try to get the status if we can't listen to it."
parents 78e0618d ea495d4c
Loading
Loading
Loading
Loading
+32 −30
Original line number Diff line number Diff line
@@ -728,15 +728,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
                com.android.internal.R.array.config_safeModeEnabledVibePattern);

        // watch for HDMI plug messages if the hdmi switch exists
        if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
            mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
        }
        mHdmiPlugged = !readHdmiState();
        setHdmiPlugged(!mHdmiPlugged);

        // Note: the Configuration is not stable here, so we cannot load mStatusBarCanHide from
        // config_statusBarCanHide because the latter depends on the screen size

        // Controls rotation and the like.
        initializeHdmiState();
    }

    public void updateSettings() {
@@ -2075,7 +2071,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
    }

    boolean readHdmiState() {
    void initializeHdmiState() {
        // watch for HDMI plug messages if the hdmi switch exists
        if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
            mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");

            boolean plugged = false;
            final String filename = "/sys/class/switch/hdmi/state";
            FileReader reader = null;
            try {
@@ -2083,16 +2084,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                char[] buf = new char[15];
                int n = reader.read(buf);
                if (n > 1) {
                return 0 != Integer.parseInt(new String(buf, 0, n-1));
            } else {
                return false;
                    plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
                }
            } catch (IOException ex) {
            Slog.d(TAG, "couldn't read hdmi state from " + filename + ": " + ex);
            return false;
                Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
            } catch (NumberFormatException ex) {
            Slog.d(TAG, "couldn't read hdmi state from " + filename + ": " + ex);
            return false;
                Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
            } finally {
                if (reader != null) {
                    try {
@@ -2101,6 +2098,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    }
                }
            }

            // This dance forces the code in setHdmiPlugged to run.
            mHdmiPlugged = !plugged;
            setHdmiPlugged(!mHdmiPlugged);
        }
    }

    /**