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

Commit 79858c3a authored by Sherry Huang's avatar Sherry Huang
Browse files

HDMI: clean up duplicate actions running

There are many places checking if the action is running/removing action
if is running. This CL intends to clean up the duplication.
Invalidate second device selection action for the same decice if the
action for the frist action is ongoing.

Bug: b/353803923, b/379739489
Test: run cts -m CtsHdmiCecHostTestCases and atest com.android.server.hdmi
Flag: EXEMPT internal cleanup

Change-Id: I9f3d9544704bbcd477b89b82621a05a6c0bef14b
parent d897df47
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -1029,11 +1029,21 @@ abstract class HdmiCecLocalDevice extends HdmiLocalDevice {
        action.start();
    }

    @ServiceThreadOnly
    void addAndStartAction(final HdmiCecFeatureAction action, final boolean remove) {
        assertRunOnServiceThread();
        if (hasAction(action.getClass()) && remove) {
            // If the action is currently running, remove it and restart it.
            Slog.i(TAG, action.getClass().getName() + " is in progress. Restarting.");
            removeAction(action.getClass());
        }
        addAndStartAction(action);
    }

    @ServiceThreadOnly
    void startNewAvbAudioStatusAction(int targetAddress) {
        assertRunOnServiceThread();
        removeAction(AbsoluteVolumeAudioStatusAction.class);
        addAndStartAction(new AbsoluteVolumeAudioStatusAction(this, targetAddress));
        addAndStartAction(new AbsoluteVolumeAudioStatusAction(this, targetAddress), true);
    }

    @ServiceThreadOnly
+7 −21
Original line number Diff line number Diff line
@@ -317,11 +317,7 @@ public class HdmiCecLocalDeviceAudioSystem extends HdmiCecLocalDeviceSource {
        if ((systemAudioOnPowerOnProp == ALWAYS_SYSTEM_AUDIO_CONTROL_ON_POWER_ON)
                || ((systemAudioOnPowerOnProp == USE_LAST_STATE_SYSTEM_AUDIO_CONTROL_ON_POWER_ON)
                && lastSystemAudioControlStatus && isSystemAudioControlFeatureEnabled())) {
            if (hasAction(SystemAudioInitiationActionFromAvr.class)) {
                Slog.i(TAG, "SystemAudioInitiationActionFromAvr is in progress. Restarting.");
                removeAction(SystemAudioInitiationActionFromAvr.class);
            }
            addAndStartAction(new SystemAudioInitiationActionFromAvr(this));
            addAndStartAction(new SystemAudioInitiationActionFromAvr(this), true);
        }
    }

@@ -457,6 +453,7 @@ public class HdmiCecLocalDeviceAudioSystem extends HdmiCecLocalDeviceSource {
            HdmiLogger.debug("AVR device is not directly connected with TV");
            return Constants.ABORT_NOT_IN_CORRECT_MODE;
        } else {
            // Action has been removed if it existed, do not attempt to remove again before start.
            addAndStartAction(new ArcInitiationActionFromAvr(this));
            return Constants.HANDLED;
        }
@@ -477,11 +474,9 @@ public class HdmiCecLocalDeviceAudioSystem extends HdmiCecLocalDeviceSource {
                    && !getActions(ArcTerminationActionFromAvr.class).get(0).mCallbacks.isEmpty()) {
                IHdmiControlCallback callback =
                        getActions(ArcTerminationActionFromAvr.class).get(0).mCallbacks.get(0);
                removeAction(ArcTerminationActionFromAvr.class);
                addAndStartAction(new ArcTerminationActionFromAvr(this, callback));
                addAndStartAction(new ArcTerminationActionFromAvr(this, callback), true);
            } else {
                removeAction(ArcTerminationActionFromAvr.class);
                addAndStartAction(new ArcTerminationActionFromAvr(this));
                addAndStartAction(new ArcTerminationActionFromAvr(this), true);
            }
            return Constants.HANDLED;
        }
@@ -1036,11 +1031,7 @@ public class HdmiCecLocalDeviceAudioSystem extends HdmiCecLocalDeviceSource {
    void onSystemAudioControlFeatureSupportChanged(boolean enabled) {
        setSystemAudioControlFeatureEnabled(enabled);
        if (enabled) {
            if (hasAction(SystemAudioInitiationActionFromAvr.class)) {
                Slog.i(TAG, "SystemAudioInitiationActionFromAvr is in progress. Restarting.");
                removeAction(SystemAudioInitiationActionFromAvr.class);
            }
            addAndStartAction(new SystemAudioInitiationActionFromAvr(this));
            addAndStartAction(new SystemAudioInitiationActionFromAvr(this), true);
        }
    }

@@ -1221,8 +1212,7 @@ public class HdmiCecLocalDeviceAudioSystem extends HdmiCecLocalDeviceSource {
        removeAction(ArcTerminationActionFromAvr.class);
        if (SystemProperties.getBoolean(Constants.PROPERTY_ARC_SUPPORT, true)
                && isDirectConnectToTv() && !isArcEnabled()) {
            removeAction(ArcInitiationActionFromAvr.class);
            addAndStartAction(new ArcInitiationActionFromAvr(this));
            addAndStartAction(new ArcInitiationActionFromAvr(this), true);
        }
    }

@@ -1367,10 +1357,6 @@ public class HdmiCecLocalDeviceAudioSystem extends HdmiCecLocalDeviceSource {
        if (mService.isDeviceDiscoveryHandledByPlayback()) {
            return;
        }
        if (hasAction(DeviceDiscoveryAction.class)) {
            Slog.i(TAG, "Device Discovery Action is in progress. Restarting.");
            removeAction(DeviceDiscoveryAction.class);
        }
        DeviceDiscoveryAction action = new DeviceDiscoveryAction(this,
                new DeviceDiscoveryCallback() {
                    @Override
@@ -1380,7 +1366,7 @@ public class HdmiCecLocalDeviceAudioSystem extends HdmiCecLocalDeviceSource {
                        }
                    }
                });
        addAndStartAction(action);
        addAndStartAction(action, true);
    }

    @Override
+18 −20
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.hardware.display.DeviceProductInfo;
import android.hardware.hdmi.HdmiControlManager;
import android.hardware.hdmi.HdmiDeviceInfo;
import android.hardware.hdmi.IHdmiControlCallback;
@@ -32,7 +31,6 @@ import android.os.PowerManager;
import android.os.SystemProperties;
import android.sysprop.HdmiProperties;
import android.util.Slog;
import android.view.Display;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.LocalePicker;
@@ -151,10 +149,6 @@ public class HdmiCecLocalDevicePlayback extends HdmiCecLocalDeviceSource {
    private void launchDeviceDiscovery() {
        assertRunOnServiceThread();
        clearDeviceInfoList();
        if (hasAction(DeviceDiscoveryAction.class)) {
            Slog.i(TAG, "Device Discovery Action is in progress. Restarting.");
            removeAction(DeviceDiscoveryAction.class);
        }
        DeviceDiscoveryAction action = new DeviceDiscoveryAction(this,
                new DeviceDiscoveryAction.DeviceDiscoveryCallback() {
                    @Override
@@ -163,25 +157,21 @@ public class HdmiCecLocalDevicePlayback extends HdmiCecLocalDeviceSource {
                            mService.getHdmiCecNetwork().addCecDevice(info);
                        }

                        // Since we removed all devices when it starts and device discovery action
                        // does not poll local devices, we should put device info of local device
                        // manually here.
                        // Since we removed all devices when it starts and device discovery
                        // action does not poll local devices, we should put device info of
                        // local device manually here.
                        for (HdmiCecLocalDevice device : mService.getAllCecLocalDevices()) {
                            mService.getHdmiCecNetwork().addCecDevice(device.getDeviceInfo());
                        }

                        List<HotplugDetectionAction> hotplugActions =
                                getActions(HotplugDetectionAction.class);
                        if (hotplugActions.isEmpty()) {
                        if (!hasAction(HotplugDetectionAction.class)) {
                            addAndStartAction(
                                    new HotplugDetectionAction(HdmiCecLocalDevicePlayback.this));
                                    new HotplugDetectionAction(
                                            HdmiCecLocalDevicePlayback.this));
                        }

                        if (mService.isHdmiControlEnhancedBehaviorFlagEnabled()) {
                            List<PowerStatusMonitorActionFromPlayback>
                                    powerStatusMonitorActionsFromPlayback =
                                    getActions(PowerStatusMonitorActionFromPlayback.class);
                            if (powerStatusMonitorActionsFromPlayback.isEmpty()) {
                            if (!hasAction(PowerStatusMonitorActionFromPlayback.class)) {
                                addAndStartAction(
                                        new PowerStatusMonitorActionFromPlayback(
                                                HdmiCecLocalDevicePlayback.this));
@@ -189,7 +179,7 @@ public class HdmiCecLocalDevicePlayback extends HdmiCecLocalDeviceSource {
                        }
                    }
                });
        addAndStartAction(action);
        addAndStartAction(action, true);
    }

    @Override
@@ -235,8 +225,16 @@ public class HdmiCecLocalDevicePlayback extends HdmiCecLocalDeviceSource {
            invokeCallback(callback, HdmiControlManager.RESULT_INCORRECT_MODE);
            return;
        }
        removeAction(DeviceSelectActionFromPlayback.class);
        addAndStartAction(new DeviceSelectActionFromPlayback(this, targetDevice, callback));
        List<DeviceSelectActionFromPlayback> actions = getActions(
                DeviceSelectActionFromPlayback.class);
        if (!actions.isEmpty()) {
            DeviceSelectActionFromPlayback action = actions.get(0);
            if (action.getTargetAddress() == targetDevice.getLogicalAddress()) {
                return;
            }
        }
        addAndStartAction(new DeviceSelectActionFromPlayback(this, targetDevice, callback),
                true);
    }

    @Override
+13 −15
Original line number Diff line number Diff line
@@ -220,10 +220,6 @@ public class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
        List<HdmiCecMessage> bufferedActiveSource = mDelayedMessageBuffer
                .getBufferedMessagesWithOpcode(Constants.MESSAGE_ACTIVE_SOURCE);
        if (bufferedActiveSource.isEmpty()) {
            if (hasAction(RequestActiveSourceAction.class)) {
                Slog.i(TAG, "RequestActiveSourceAction is in progress. Restarting.");
                removeAction(RequestActiveSourceAction.class);
            }
            addAndStartAction(new RequestActiveSourceAction(this, new IHdmiControlCallback.Stub() {
                @Override
                public void onComplete(int result) {
@@ -231,7 +227,7 @@ public class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
                        launchRoutingControl(routingForBootup);
                    }
                }
            }));
            }), true);
        } else {
            addCecDeviceForBufferedActiveSource(bufferedActiveSource.get(0));
        }
@@ -328,8 +324,15 @@ public class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
            invokeCallback(callback, HdmiControlManager.RESULT_INCORRECT_MODE);
            return;
        }
        removeAction(DeviceSelectActionFromTv.class);
        addAndStartAction(new DeviceSelectActionFromTv(this, targetDevice, callback));
        List<DeviceSelectActionFromTv> actions = getActions(DeviceSelectActionFromTv.class);
        if (!actions.isEmpty()) {
            DeviceSelectActionFromTv action = actions.get(0);
            if (action.getTargetAddress() == targetDevice.getLogicalAddress()) {
                return;
            }
        }
        addAndStartAction(new DeviceSelectActionFromTv(this, targetDevice, callback),
                true);
    }

    @ServiceThreadOnly
@@ -475,9 +478,8 @@ public class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
                HdmiCecMessageBuilder.buildRoutingChange(
                        getDeviceInfo().getLogicalAddress(), oldPath, newPath);
        mService.sendCecCommand(routingChange);
        removeAction(RoutingControlAction.class);
        addAndStartAction(
                new RoutingControlAction(this, newPath, callback));
                new RoutingControlAction(this, newPath, callback), true);
    }

    @ServiceThreadOnly
@@ -801,16 +803,12 @@ public class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
                        mSelectRequestBuffer.process();
                        resetSelectRequestBuffer();

                        List<HotplugDetectionAction> hotplugActions
                                = getActions(HotplugDetectionAction.class);
                        if (hotplugActions.isEmpty()) {
                        if (!hasAction(HotplugDetectionAction.class)) {
                            addAndStartAction(
                                    new HotplugDetectionAction(HdmiCecLocalDeviceTv.this));
                        }

                        List<PowerStatusMonitorAction> powerStatusActions
                                = getActions(PowerStatusMonitorAction.class);
                        if (powerStatusActions.isEmpty()) {
                        if (!hasAction(PowerStatusMonitorAction.class)) {
                            addAndStartAction(
                                    new PowerStatusMonitorAction(HdmiCecLocalDeviceTv.this));
                        }
+1 −6
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.server.hdmi;

import static android.media.tv.flags.Flags.hdmiControlEnhancedBehavior;

import static android.hardware.hdmi.HdmiControlManager.DEVICE_EVENT_ADD_DEVICE;
import static android.hardware.hdmi.HdmiControlManager.DEVICE_EVENT_REMOVE_DEVICE;
import static android.hardware.hdmi.HdmiControlManager.EARC_FEATURE_DISABLED;
@@ -107,7 +106,6 @@ import android.util.Slog;
import android.util.SparseArray;
import android.view.Display;
import android.view.KeyEvent;
import android.view.WindowManager;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
@@ -1218,9 +1216,6 @@ public class HdmiControlService extends SystemService {
                audioSystem.terminateSystemAudioMode();
            }
            if (isArcEnabled) {
                if (audioSystem.hasAction(ArcTerminationActionFromAvr.class)) {
                    audioSystem.removeAction(ArcTerminationActionFromAvr.class);
                }
                audioSystem.addAndStartAction(new ArcTerminationActionFromAvr(audioSystem,
                        new IHdmiControlCallback.Stub() {
                            @Override
@@ -1228,7 +1223,7 @@ public class HdmiControlService extends SystemService {
                                mAddressAllocated = false;
                                initializeCecLocalDevices(INITIATED_BY_SOUNDBAR_MODE);
                            }
                        }));
                        }), true);
            }
        }
        if (!isArcEnabled) {
Loading