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

Commit ea495d4c authored by Joe Onorato's avatar Joe Onorato
Browse files

Move around the HDMI switch detection so we don't try to get the status if we can't listen to it.

Change-Id: I46f4e92923ba010f68109b6d043c817e25dfe650
parent 782c9d87
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);
        }
    }

    /**