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

Commit 9f5ec0c7 authored by Aravind Angadi's avatar Aravind Angadi Committed by Yan Han
Browse files

CEC: Remove HdmiControlManager#mLocalPhysicalAddress variable

Remove the cached physical address variable and use physical address
returned by the service when HdmiControlManager is queried for physical
address.

Bug: 159806029
Test: atest CtsHdmiCecHostTestCases
Test: atest FrameworksServicesTests:com.android.server.hdmi
Change-Id: I6c51521ce39df8d1be3f9923c9430112c0cfc584
parent e73d2061
Loading
Loading
Loading
Loading
+7 −62
Original line number Original line Diff line number Diff line
@@ -36,12 +36,10 @@ import android.sysprop.HdmiProperties;
import android.util.ArrayMap;
import android.util.ArrayMap;
import android.util.Log;
import android.util.Log;


import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.ConcurrentUtils;
import com.android.internal.util.ConcurrentUtils;


import java.lang.annotation.Retention;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Arrays;
import java.util.List;
import java.util.List;
import java.util.Objects;
import java.util.Objects;
@@ -70,32 +68,6 @@ public final class HdmiControlManager {


    private static final int INVALID_PHYSICAL_ADDRESS = 0xFFFF;
    private static final int INVALID_PHYSICAL_ADDRESS = 0xFFFF;


    /**
     * A cache of the current device's physical address. When device's HDMI out port
     * is not connected to any device, it is set to {@link #INVALID_PHYSICAL_ADDRESS}.
     *
     * <p>Otherwise it is updated by the {@link ClientHotplugEventListener} registered
     * with {@link com.android.server.hdmi.HdmiControlService} by the
     * {@link #addHotplugEventListener(HotplugEventListener)} and the address is from
     * {@link com.android.server.hdmi.HdmiControlService#getPortInfo()}
     */
    @GuardedBy("mLock")
    private int mLocalPhysicalAddress = INVALID_PHYSICAL_ADDRESS;

    private void setLocalPhysicalAddress(int physicalAddress) {
        synchronized (mLock) {
            mLocalPhysicalAddress = physicalAddress;
        }
    }

    private int getLocalPhysicalAddress() {
        synchronized (mLock) {
            return mLocalPhysicalAddress;
        }
    }

    private final Object mLock = new Object();

    /**
    /**
     * Broadcast Action: Display OSD message.
     * Broadcast Action: Display OSD message.
     * <p>Send when the service has a message to display on screen for events
     * <p>Send when the service has a message to display on screen for events
@@ -972,37 +944,6 @@ public final class HdmiControlManager {
        mHasAudioSystemDevice = hasDeviceType(types, HdmiDeviceInfo.DEVICE_AUDIO_SYSTEM);
        mHasAudioSystemDevice = hasDeviceType(types, HdmiDeviceInfo.DEVICE_AUDIO_SYSTEM);
        mHasSwitchDevice = hasDeviceType(types, HdmiDeviceInfo.DEVICE_PURE_CEC_SWITCH);
        mHasSwitchDevice = hasDeviceType(types, HdmiDeviceInfo.DEVICE_PURE_CEC_SWITCH);
        mIsSwitchDevice = HdmiProperties.is_switch().orElse(false);
        mIsSwitchDevice = HdmiProperties.is_switch().orElse(false);
        addHotplugEventListener(new ClientHotplugEventListener());
    }

    private final class ClientHotplugEventListener implements HotplugEventListener {

        @Override
        public void onReceived(HdmiHotplugEvent event) {
            List<HdmiPortInfo> ports = new ArrayList<>();
            try {
                ports = mService.getPortInfo();
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
            if (ports.isEmpty()) {
                Log.e(TAG, "Can't find port info, not updating connected status. "
                        + "Hotplug event:" + event);
                return;
            }
            // If the HDMI OUT port is plugged or unplugged, update the mLocalPhysicalAddress
            for (HdmiPortInfo port : ports) {
                if (port.getId() == event.getPort()) {
                    if (port.getType() == HdmiPortInfo.PORT_OUTPUT) {
                        setLocalPhysicalAddress(
                                event.isConnected()
                                        ? port.getAddress()
                                        : INVALID_PHYSICAL_ADDRESS);
                    }
                    break;
                }
            }
        }
    }
    }


    private static boolean hasDeviceType(int[] types, int type) {
    private static boolean hasDeviceType(int[] types, int type) {
@@ -1404,7 +1345,11 @@ public final class HdmiControlManager {
     */
     */
    @SystemApi
    @SystemApi
    public int getPhysicalAddress() {
    public int getPhysicalAddress() {
        return getLocalPhysicalAddress();
        try {
            return mService.getPhysicalAddress();
        } catch (RemoteException e) {
            return INVALID_PHYSICAL_ADDRESS;
        }
    }
    }


    /**
    /**
@@ -1421,7 +1366,7 @@ public final class HdmiControlManager {
    @SystemApi
    @SystemApi
    public boolean isDeviceConnected(@NonNull HdmiDeviceInfo targetDevice) {
    public boolean isDeviceConnected(@NonNull HdmiDeviceInfo targetDevice) {
        Objects.requireNonNull(targetDevice);
        Objects.requireNonNull(targetDevice);
        int physicalAddress = getLocalPhysicalAddress();
        int physicalAddress = getPhysicalAddress();
        if (physicalAddress == INVALID_PHYSICAL_ADDRESS) {
        if (physicalAddress == INVALID_PHYSICAL_ADDRESS) {
            return false;
            return false;
        }
        }
@@ -1442,7 +1387,7 @@ public final class HdmiControlManager {
    @SystemApi
    @SystemApi
    public boolean isRemoteDeviceConnected(@NonNull HdmiDeviceInfo targetDevice) {
    public boolean isRemoteDeviceConnected(@NonNull HdmiDeviceInfo targetDevice) {
        Objects.requireNonNull(targetDevice);
        Objects.requireNonNull(targetDevice);
        int physicalAddress = getLocalPhysicalAddress();
        int physicalAddress = getPhysicalAddress();
        if (physicalAddress == INVALID_PHYSICAL_ADDRESS) {
        if (physicalAddress == INVALID_PHYSICAL_ADDRESS) {
            return false;
            return false;
        }
        }