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

Commit 490db5dd authored by Nick Chalko's avatar Nick Chalko Committed by Android (Google) Code Review
Browse files

Merge "Use extcon to listen for hdmi state changes"

parents 68060c69 cc863e43
Loading
Loading
Loading
Loading
+7 −21
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.os.FileUtils;
import android.util.Slog;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
@@ -36,31 +35,18 @@ public abstract class ExtconStateObserver<S> extends ExtconUEventObserver {
    private static final boolean LOG = false;

    /**
     * Parses the current state from the state file for {@code extconInfo} and calls {@link
     * #updateState(ExtconInfo, String, Object)}
     * Parses the current state from the state file for {@code extconInfo}.
     *
     * @param extconInfo the extconInfo to update state for
     * @param extconInfo the extconInfo to parse state for
     * @see #parseState(ExtconInfo, String)
     * @see ExtconInfo#getStatePath()
     */
    public void updateStateFromFile(ExtconInfo extconInfo) {
    @Nullable
    public S parseStateFromFile(ExtconInfo extconInfo) throws IOException {
        String statePath = extconInfo.getStatePath();
        try {
            S state =
                    parseState(
        return parseState(
                extconInfo,
                FileUtils.readTextFile(new File(statePath), 0, null).trim());
            if (state != null) {
                updateState(extconInfo, extconInfo.getName(), state);
            }
        } catch (FileNotFoundException e) {
            Slog.w(TAG, statePath + " not found while attempting to determine initial state", e);
        } catch (IOException e) {
            Slog.e(
                    TAG,
                    "Error reading " + statePath + " while attempting to determine initial state ",
                    e);
        }
    }

    @Override
+44 −1
Original line number Diff line number Diff line
@@ -275,6 +275,8 @@ import com.android.internal.util.ArrayUtils;
import com.android.internal.util.ScreenShapeHelper;
import com.android.internal.util.ScreenshotHelper;
import com.android.internal.widget.PointerLocationView;
import com.android.server.ExtconStateObserver;
import com.android.server.ExtconUEventObserver;
import com.android.server.GestureLauncherService;
import com.android.server.LocalServices;
import com.android.server.SystemServiceManager;
@@ -296,6 +298,7 @@ import com.android.server.wm.WindowManagerInternal.AppTransitionListener;
import com.android.server.wm.utils.InsetUtils;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
@@ -5721,6 +5724,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    }
                }
            }
        } else if (ExtconUEventObserver.extconExists()) {
            HdmiVideoExtconUEventObserver observer = new HdmiVideoExtconUEventObserver();
            plugged = observer.init();
            mHDMIObserver = observer;
        }
        // This dance forces the code in setHdmiPlugged to run.
        // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
@@ -8315,4 +8322,40 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
        return false;
    }

    private class HdmiVideoExtconUEventObserver extends ExtconStateObserver<Boolean> {
        private static final String HDMI_EXIST = "HDMI=1";
        private final ExtconInfo mHdmi = new ExtconInfo("hdmi");

        private boolean init() {
            boolean plugged = false;
            try {
                plugged = parseStateFromFile(mHdmi);
            } catch (FileNotFoundException e) {
                Slog.w(TAG, mHdmi.getStatePath()
                        + " not found while attempting to determine initial state", e);
            } catch (IOException e) {
                Slog.e(
                        TAG,
                        "Error reading " + mHdmi.getStatePath()
                                + " while attempting to determine initial state",
                        e);
            }
            startObserving(mHdmi);
            return plugged;
        }

        @Override
        public void updateState(ExtconInfo extconInfo, String eventName, Boolean state) {
            mDefaultDisplayPolicy.setHdmiPlugged(state);
        }

        @Override
        public Boolean parseState(ExtconInfo extconIfno, String state) {
            // extcon event state changes from kernel4.9
            // new state will be like STATE=HDMI=1
            return state.contains(HDMI_EXIST);
        }
    }

}