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

Commit 7a833884 authored by Paul Colta's avatar Paul Colta Committed by Android (Google) Code Review
Browse files

Merge "HDMI: Stop actions on device type mismatch" into main

parents c5fe1f6c 673f3a95
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -175,14 +175,15 @@ final class HdmiUtils {
     *
     * @param logicalAddress the logical address to verify
     * @param deviceType the device type to check
     * @throws IllegalArgumentException
     */
    static void verifyAddressType(int logicalAddress, int deviceType) {
    static boolean verifyAddressType(int logicalAddress, int deviceType) {
        List<Integer> actualDeviceTypes = getTypeFromAddress(logicalAddress);
        if (!actualDeviceTypes.contains(deviceType)) {
            throw new IllegalArgumentException("Device type missmatch:[Expected:" + deviceType
                    + ", Actual:" + actualDeviceTypes);
            Slog.w(TAG,"Device type mismatch:[Expected:" + deviceType
                    + ", Actual:" + actualDeviceTypes + "]");
            return false;
        }
        return true;
    }

    /**
+6 −4
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.server.hdmi;
import android.hardware.hdmi.HdmiControlManager;
import android.hardware.hdmi.HdmiDeviceInfo;
import android.hardware.hdmi.IHdmiControlCallback;
import android.util.Slog;

/**
 * Base feature action class for &lt;Request ARC Initiation&gt;/&lt;Request ARC Termination&gt;.
@@ -38,13 +39,14 @@ abstract class RequestArcAction extends HdmiCecFeatureAction {
     * @param source {@link HdmiCecLocalDevice} instance
     * @param avrAddress address of AV receiver. It should be AUDIO_SYSTEM type
     * @param callback callback to inform about the status of the action
     * @throws IllegalArgumentException if device type of sourceAddress and avrAddress
     *                      is invalid
     */
    RequestArcAction(HdmiCecLocalDevice source, int avrAddress, IHdmiControlCallback callback) {
        super(source, callback);
        HdmiUtils.verifyAddressType(getSourceAddress(), HdmiDeviceInfo.DEVICE_TV);
        HdmiUtils.verifyAddressType(avrAddress, HdmiDeviceInfo.DEVICE_AUDIO_SYSTEM);
        if (!HdmiUtils.verifyAddressType(getSourceAddress(), HdmiDeviceInfo.DEVICE_TV) ||
                !HdmiUtils.verifyAddressType(avrAddress, HdmiDeviceInfo.DEVICE_AUDIO_SYSTEM)) {
            Slog.w(TAG, "Device type mismatch, stop the action.");
            finish();
        }
        mAvrAddress = avrAddress;
    }

+5 −2
Original line number Diff line number Diff line
@@ -47,8 +47,11 @@ final class SetArcTransmissionStateAction extends HdmiCecFeatureAction {
    SetArcTransmissionStateAction(HdmiCecLocalDevice source, int avrAddress,
            boolean enabled) {
        super(source);
        HdmiUtils.verifyAddressType(getSourceAddress(), HdmiDeviceInfo.DEVICE_TV);
        HdmiUtils.verifyAddressType(avrAddress, HdmiDeviceInfo.DEVICE_AUDIO_SYSTEM);
        if (!HdmiUtils.verifyAddressType(getSourceAddress(), HdmiDeviceInfo.DEVICE_TV) ||
                !HdmiUtils.verifyAddressType(avrAddress, HdmiDeviceInfo.DEVICE_AUDIO_SYSTEM)) {
            Slog.w(TAG, "Device type mismatch, stop the action.");
            finish();
        }
        mAvrAddress = avrAddress;
        mEnabled = enabled;
    }
+5 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.hardware.hdmi.HdmiControlManager;
import android.hardware.hdmi.HdmiDeviceInfo;
import android.hardware.hdmi.IHdmiControlCallback;
import android.hardware.tv.cec.V1_0.SendMessageResult;
import android.util.Slog;

import java.util.List;

@@ -56,12 +57,14 @@ abstract class SystemAudioAction extends HdmiCecFeatureAction {
     * @param avrAddress logical address of AVR device
     * @param targetStatus Whether to enable the system audio mode or not
     * @param callback callback interface to be notified when it's done
     * @throws IllegalArgumentException if device type of sourceAddress and avrAddress is invalid
     */
    SystemAudioAction(HdmiCecLocalDevice source, int avrAddress, boolean targetStatus,
            IHdmiControlCallback callback) {
        super(source, callback);
        HdmiUtils.verifyAddressType(avrAddress, HdmiDeviceInfo.DEVICE_AUDIO_SYSTEM);
        if (!HdmiUtils.verifyAddressType(avrAddress, HdmiDeviceInfo.DEVICE_AUDIO_SYSTEM)) {
            Slog.w(TAG, "Device type mismatch, stop the action.");
            finish();
        }
        mAvrLogicalAddress = avrAddress;
        mTargetAudioStatus = targetStatus;
    }
+6 −2
Original line number Diff line number Diff line
@@ -19,12 +19,14 @@ package com.android.server.hdmi;
import android.hardware.hdmi.HdmiControlManager;
import android.hardware.hdmi.HdmiDeviceInfo;
import android.hardware.hdmi.IHdmiControlCallback;
import android.util.Slog;

/**
 * Feature action that handles System Audio initiated by AVR devices.
 */
// Seq #33
final class SystemAudioActionFromAvr extends SystemAudioAction {
    private static final String TAG = "SystemAudioActionFromAvr";
    /**
     * Constructor
     *
@@ -32,12 +34,14 @@ final class SystemAudioActionFromAvr extends SystemAudioAction {
     * @param avrAddress logical address of AVR device
     * @param targetStatus Whether to enable the system audio mode or not
     * @param callback callback interface to be notified when it's done
     * @throws IllegalArgumentException if device type of tvAddress and avrAddress is invalid
     */
    SystemAudioActionFromAvr(HdmiCecLocalDevice source, int avrAddress,
            boolean targetStatus, IHdmiControlCallback callback) {
        super(source, avrAddress, targetStatus, callback);
        HdmiUtils.verifyAddressType(getSourceAddress(), HdmiDeviceInfo.DEVICE_TV);
        if (!HdmiUtils.verifyAddressType(getSourceAddress(), HdmiDeviceInfo.DEVICE_TV)) {
            Slog.w(TAG, "Device type mismatch, stop the action.");
            finish();
        }
    }

    @Override
Loading