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

Commit 0361dd75 authored by Amy's avatar Amy Committed by shubang
Browse files

Make getActiveSource in HdmiControlService work for non-TV device.

ag/5463663

Adding a getSafeDeviceInfo() to get the local device info since the
getDeviceInfo() is service thread only.

This device info is returned when the current device is the Active
Source. Otherwise we look for the device info in the remote device list
maintained by the switch device type.

Test: manual
Bug: 119041273
Change-Id: Iaa2e87eaa9e430205a92a30ebd4506a6e8ef5f2b
parent f4b66f62
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ abstract class HdmiCecLocalDevice {
    protected final int mDeviceType;
    protected int mAddress;
    protected int mPreferredAddress;
    @GuardedBy("mLock")
    protected HdmiDeviceInfo mDeviceInfo;
    protected int mLastKeycode = HdmiCecKeycode.UNSUPPORTED_KEYCODE;
    protected int mLastKeyRepeatCount = 0;
@@ -717,17 +718,19 @@ abstract class HdmiCecLocalDevice {
        return mDeviceType;
    }

    @ServiceThreadOnly
    @GuardedBy("mLock")
    HdmiDeviceInfo getDeviceInfo() {
        assertRunOnServiceThread();
        synchronized (mLock) {
            return mDeviceInfo;
        }
    }

    @ServiceThreadOnly
    @GuardedBy("mLock")
    void setDeviceInfo(HdmiDeviceInfo info) {
        assertRunOnServiceThread();
        synchronized (mLock) {
            mDeviceInfo = info;
        }
    }

    // Returns true if the logical address is same as the argument.
    @ServiceThreadOnly
+28 −1
Original line number Diff line number Diff line
@@ -1155,7 +1155,7 @@ public class HdmiControlService extends SystemService {
        String displayName = Build.MODEL;
        return new HdmiDeviceInfo(logicalAddress,
                getPhysicalAddress(), pathToPortId(getPhysicalAddress()), deviceType,
                getVendorId(), displayName);
                getVendorId(), displayName, powerStatus);
    }

    @ServiceThreadOnly
@@ -1374,6 +1374,33 @@ public class HdmiControlService extends SystemService {
            HdmiCecLocalDeviceTv tv = tv();
            if (tv == null) {
                Slog.w(TAG, "Local tv device not available");
                if (isPlaybackDevice()) {
                    // if playback device itself is the active source,
                    // return its own device info.
                    if (playback() != null && playback().mIsActiveSource) {
                        return playback().getDeviceInfo();
                    }
                    // Otherwise get the active source and look for it from the device list
                    ActiveSource activeSource = mActiveSource;
                    // If the active source is not set yet, return null
                    if (!activeSource.isValid()) {
                        return null;
                    }
                    if (audioSystem() != null) {
                        HdmiCecLocalDeviceAudioSystem audioSystem = audioSystem();
                        for (HdmiDeviceInfo info : audioSystem.getSafeCecDevicesLocked()) {
                            if (info.getLogicalAddress() == activeSource.logicalAddress) {
                                return info;
                            }
                        }
                    }
                    // If the device info is not in the list yet, return a device info with minimum
                    // information from mActiveSource.
                    return new HdmiDeviceInfo(activeSource.logicalAddress,
                        activeSource.physicalAddress, pathToPortId(activeSource.physicalAddress),
                        HdmiUtils.getTypeFromAddress(activeSource.logicalAddress), 0,
                        HdmiUtils.getDefaultDeviceName(activeSource.logicalAddress));
                }
                return null;
            }
            ActiveSource activeSource = tv.getActiveSource();