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

Commit 6a58a34e authored by Amy's avatar Amy
Browse files

Exposing getPortInfo in HdmiControlService as an HdmiSwitchClient API

Test: manual
Bug: 132724598
Change-Id: I482295728ef19ba0eca26a4349dc1ea8ce93fe2c
parent dade0d26
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2224,6 +2224,7 @@ package android.hardware.hdmi {
  public class HdmiSwitchClient extends android.hardware.hdmi.HdmiClient {
    method public int getDeviceType();
    method @NonNull public java.util.List<android.hardware.hdmi.HdmiPortInfo> getPortInfo();
    method public void selectPort(int, @NonNull android.hardware.hdmi.HdmiSwitchClient.OnSelectListener);
    method public void selectPort(int, @NonNull java.util.concurrent.Executor, @NonNull android.hardware.hdmi.HdmiSwitchClient.OnSelectListener);
  }
+20 −0
Original line number Diff line number Diff line
@@ -182,6 +182,26 @@ public class HdmiSwitchClient extends HdmiClient {
        }
    }

    /**
     * Get the list of the HDMI input port configuration.
     *
     * <p>This returns an empty list when the current device does not have HDMI input.
     *
     * @return a list of {@link HdmiPortInfo}
     *
     * @hide
     */
    @NonNull
    @SystemApi
    public List<HdmiPortInfo> getPortInfo() {
        try {
            return mService.getPortInfo();
        } catch (RemoteException e) {
            Log.e("TAG", "Failed to call getPortInfo():", e);
            return Collections.<HdmiPortInfo>emptyList();
        }
    }

    /**
     * Listener interface used to get the result of {@link #deviceSelect} or {@link #portSelect}.
     *
+18 −6
Original line number Diff line number Diff line
@@ -300,7 +300,9 @@ public class HdmiControlService extends SystemService {

    // HDMI port information. Stored in the unmodifiable list to keep the static information
    // from being modified.
    private List<HdmiPortInfo> mPortInfo;
    // This variable is null if the current device does not have hdmi input.
    @GuardedBy("mLock")
    private List<HdmiPortInfo> mPortInfo = null;

    // Map from path(physical address) to port ID.
    private UnmodifiableSparseIntArray mPortIdMap;
@@ -827,7 +829,7 @@ public class HdmiControlService extends SystemService {
        // Build HDMI port info list with CEC port info plus MHL supported flag. We can just use
        // cec port info if we do not have have port that supports MHL.
        if (mhlSupportedPorts.isEmpty()) {
            mPortInfo = Collections.unmodifiableList(Arrays.asList(cecPortInfo));
            setPortInfo(Collections.unmodifiableList(Arrays.asList(cecPortInfo)));
            return;
        }
        ArrayList<HdmiPortInfo> result = new ArrayList<>(cecPortInfo.length);
@@ -839,12 +841,20 @@ public class HdmiControlService extends SystemService {
                result.add(info);
            }
        }
        mPortInfo = Collections.unmodifiableList(result);
        setPortInfo(Collections.unmodifiableList(result));
    }

    List<HdmiPortInfo> getPortInfo() {
        synchronized (mLock) {
            return mPortInfo;
        }
    }

    void setPortInfo(List<HdmiPortInfo> portInfo) {
        synchronized (mLock) {
            mPortInfo = portInfo;
        }
    }

    /**
     * Returns HDMI port information for the given port id.
@@ -1641,7 +1651,9 @@ public class HdmiControlService extends SystemService {
        @Override
        public List<HdmiPortInfo> getPortInfo() {
            enforceAccessPermission();
            return HdmiControlService.this.getPortInfo();
            return HdmiControlService.this.getPortInfo() == null
                ? Collections.<HdmiPortInfo>emptyList()
                : HdmiControlService.this.getPortInfo();
        }

        @Override
@@ -2155,7 +2167,7 @@ public class HdmiControlService extends SystemService {
                synchronized (mLock) {
                    if (!mHotplugEventListenerRecords.contains(record)) return;
                }
                for (HdmiPortInfo port : mPortInfo) {
                for (HdmiPortInfo port : getPortInfo()) {
                    HdmiHotplugEvent event = new HdmiHotplugEvent(port.getId(),
                            mCecController.isConnected(port.getId()));
                    synchronized (mLock) {