diff --git a/core/java/android/hardware/hdmi/HdmiControlManager.java b/core/java/android/hardware/hdmi/HdmiControlManager.java index 9235ba15019c0..3e509e4d1c2f0 100644 --- a/core/java/android/hardware/hdmi/HdmiControlManager.java +++ b/core/java/android/hardware/hdmi/HdmiControlManager.java @@ -36,10 +36,12 @@ import android.sysprop.HdmiProperties; import android.util.ArrayMap; import android.util.Log; +import com.android.internal.annotations.GuardedBy; import com.android.internal.util.ConcurrentUtils; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Objects; @@ -68,6 +70,32 @@ public final class HdmiControlManager { 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}. + * + *
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. *
Send when the service has a message to display on screen for events
@@ -1094,6 +1122,37 @@ public final class HdmiControlManager {
mHasAudioSystemDevice = hasDeviceType(types, HdmiDeviceInfo.DEVICE_AUDIO_SYSTEM);
mHasSwitchDevice = hasDeviceType(types, HdmiDeviceInfo.DEVICE_PURE_CEC_SWITCH);
mIsSwitchDevice = HdmiProperties.is_switch().orElse(false);
+ addHotplugEventListener(new ClientHotplugEventListener());
+ }
+
+ private final class ClientHotplugEventListener implements HotplugEventListener {
+
+ @Override
+ public void onReceived(HdmiHotplugEvent event) {
+ List