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

Commit 7f7d8fb5 authored by Shubang Lu's avatar Shubang Lu Committed by Android (Google) Code Review
Browse files

Merge changes I8197a919,I61b0398c,Id0d1d4ba,Ibf9d162e,I01058504, ...

* changes:
  Fix NPE when Audio System is not registered.
  Fix service thread crash in HdmiControlService getActiveSource
  Fix NPE in HdmiControlService
  Send out <Set Stream Path> regardless of the port the remote device is connected to
  Change the restriction on sending out <Standby> command
  Fix NPE in HdmiControlService when set routing control on Unregistered device.
  Fix switching back home on OneTouchPlay.
  Make getActiveSource in HdmiControlService work for non-TV device.
  Fix feature abort command handlers.
  Keep the device info when power status/OSD is unknown.
parents 8b08542a 7e3b6d9a
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -51,6 +51,13 @@ public class ArcInitiationActionFromAvr extends HdmiCecFeatureAction {
        }
        switch (cmd.getOpcode()) {
            case Constants.MESSAGE_FEATURE_ABORT:
                if ((cmd.getParams()[0] & 0xFF) == Constants.MESSAGE_INITIATE_ARC) {
                    audioSystem().setArcStatus(false);
                    finish();
                    return true;
                } else {
                    return false;
                }
            case Constants.MESSAGE_REPORT_ARC_TERMINATED:
                audioSystem().setArcStatus(false);
                finish();
+4 −2
Original line number Diff line number Diff line
@@ -50,9 +50,11 @@ public class DetectTvSystemAudioModeSupportAction extends HdmiCecFeatureAction {
            if (mState != STATE_WAITING_FOR_FEATURE_ABORT) {
                return false;
            }
            if ((cmd.getParams()[0] & 0xFF) == Constants.MESSAGE_SET_SYSTEM_AUDIO_MODE) {
                finishAction(false);
                return true;
            }
        }
        return false;
    }

+5 −1
Original line number Diff line number Diff line
@@ -333,6 +333,7 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction {
        current.mPhysicalAddress = HdmiUtils.twoBytesToInt(params);
        current.mPortId = getPortId(current.mPhysicalAddress);
        current.mDeviceType = params[2] & 0xFF;
        current.mDisplayName = HdmiUtils.getDefaultDeviceName(current.mDeviceType);

        // TODO(amyjojo): check if non-TV device needs to update cec switch info.
        // This is to manager CEC device separately in case they don't have address.
@@ -511,7 +512,10 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction {
        }
        mTimeoutRetry = 0;
        Slog.v(TAG, "Timeout[State=" + mState + ", Processed=" + mProcessedDeviceCount);
        if (mState != STATE_WAITING_FOR_POWER) {
        if (mState != STATE_WAITING_FOR_POWER && mState != STATE_WAITING_FOR_OSD_NAME) {
            // We don't need to remove the device info if the power status is unknown.
            // Some device does not have preferred OSD name and does not respond to Give OSD name.
            // Like LG TV. We can give it default device name and not remove it.
            removeDevice(mProcessedDeviceCount);
        } else {
            increaseProcessedDeviceCount();
+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
+52 −11
Original line number Diff line number Diff line
@@ -614,11 +614,21 @@ public class HdmiControlService extends SystemService {
                        tv().setSystemAudioControlFeatureEnabled(enabled);
                    }
                    if (isAudioSystemDevice()) {
                        if (audioSystem() == null) {
                            Slog.e(TAG, "Audio System device has not registered yet."
                                    + " Can't turn system audio mode on.");
                            break;
                        }
                        audioSystem().onSystemAduioControlFeatureSupportChanged(enabled);
                    }
                    break;
                case Global.HDMI_CEC_SWITCH_ENABLED:
                    if (isAudioSystemDevice()) {
                        if (audioSystem() == null) {
                            Slog.w(TAG, "Switch device has not registered yet."
                                    + " Can't turn routing on.");
                            break;
                        }
                        audioSystem().setRoutingControlFeatureEnables(enabled);
                    }
                    break;
@@ -847,7 +857,10 @@ public class HdmiControlService extends SystemService {
    int pathToPortId(int path) {
        int mask = 0xF000;
        int finalMask = 0xF000;
        int physicalAddress = getPhysicalAddress();
        int physicalAddress;
        synchronized (mLock) {
            physicalAddress = mPhysicalAddress;
        }
        int maskedAddress = physicalAddress;

        while (maskedAddress != 0) {
@@ -1155,7 +1168,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 +1387,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();
@@ -1636,13 +1676,11 @@ public class HdmiControlService extends SystemService {
            runOnServiceThread(new Runnable() {
                @Override
                public void run() {
                    if (powerStatus == HdmiControlManager.POWER_STATUS_ON
                            || powerStatus == HdmiControlManager.POWER_STATUS_TRANSIENT_TO_ON) {
                    Slog.w(TAG, "Device "
                            + logicalAddress + " power status is " + powerStatus
                            + " before standby command sent out");
                    sendCecCommand(HdmiCecMessageBuilder.buildStandby(
                            getRemoteControlSourceAddress(), logicalAddress));
                    } else {
                        Slog.w(TAG, "Device " + logicalAddress + " is already off " + powerStatus);
                    }
                }
            });
        }
@@ -1667,9 +1705,8 @@ public class HdmiControlService extends SystemService {
                        } else {
                            Slog.e(TAG, "Can't get the correct local device to handle routing.");
                        }
                    } else {
                        sendCecCommand(setStreamPath);
                    }
                    sendCecCommand(setStreamPath);
                }
            });
        }
@@ -1928,6 +1965,10 @@ public class HdmiControlService extends SystemService {
                        Slog.e(TAG, "Not an audio system device. Won't set system audio mode on");
                        return;
                    }
                    if (audioSystem() == null) {
                        Slog.e(TAG, "Audio System local device is not registered");
                        return;
                    }
                    if (!audioSystem().checkSupportAndSetSystemAudioMode(true)) {
                        Slog.e(TAG, "System Audio Mode is not supported.");
                        return;
Loading