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

Commit c00cd4e0 authored by Amy's avatar Amy Committed by shubang
Browse files

Add launchDeviceDiscovery when devices just plugged into the current device or the

current device just conneted to a TV.

ag/5288659

Also modified DeviceDiscoveryAction to apply to both TV and Source devices.

Test: local tested.
Bug: 117291910
Change-Id: Iac5d191d1c78560807a408fc30cbf3f160260138
parent 3eaa85f1
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ import java.util.List;

/**
 * Feature action that handles device discovery sequences.
 * Device discovery is launched when TV device is woken from "Standby" state
 * Device discovery is launched when device is woken from "Standby" state
 * or enabled "Control for Hdmi" from disabled state.
 *
 * <p>Device discovery goes through the following steps.
@@ -89,6 +89,7 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction {
    private final DeviceDiscoveryCallback mCallback;
    private int mProcessedDeviceCount = 0;
    private int mTimeoutRetry = 0;
    private boolean mIsTvDevice = source().mService.isTvDevice();

    /**
     * Constructor.
@@ -266,15 +267,19 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction {
        current.mPortId = getPortId(current.mPhysicalAddress);
        current.mDeviceType = params[2] & 0xFF;

        // 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.
        if (mIsTvDevice) {
            tv().updateCecSwitchInfo(current.mLogicalAddress, current.mDeviceType,
                    current.mPhysicalAddress);

        }
        increaseProcessedDeviceCount();
        checkAndProceedStage();
    }

    private int getPortId(int physicalAddress) {
        return tv().getPortId(physicalAddress);
        return mIsTvDevice ? tv().getPortId(physicalAddress)
            : source().getPortId(physicalAddress);
    }

    private void handleSetOsdName(HdmiCecMessage cmd) {
@@ -345,8 +350,10 @@ final class DeviceDiscoveryAction extends HdmiCecFeatureAction {
        mCallback.onDeviceDiscoveryDone(result);
        finish();
        // Process any commands buffered while device discovery action was in progress.
        if (mIsTvDevice) {
            tv().processAllDelayedMessages();
        }
    }

    private void checkAndProceedStage() {
        if (mDevices.isEmpty()) {
+5 −0
Original line number Diff line number Diff line
@@ -916,6 +916,11 @@ abstract class HdmiCecLocalDevice {
        setActivePath(mService.portIdToPath(portId));
    }

    // Returns the id of the port that the target device is connected to.
    int getPortId(int physicalAddress) {
        return mService.pathToPortId(physicalAddress);
    }

    @ServiceThreadOnly
    HdmiCecMessageCache getCecMessageCache() {
        assertRunOnServiceThread();
+33 −1
Original line number Diff line number Diff line
@@ -36,10 +36,12 @@ import android.util.SparseArray;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.hdmi.Constants.AudioCodec;
import com.android.server.hdmi.DeviceDiscoveryAction.DeviceDiscoveryCallback;
import com.android.server.hdmi.HdmiAnnotations.ServiceThreadOnly;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;

/**
 * Represent a logical device of type {@link HdmiDeviceInfo#DEVICE_AUDIO_SYSTEM} residing in Android
@@ -213,7 +215,7 @@ public class HdmiCecLocalDeviceAudioSystem extends HdmiCecLocalDeviceSource {
            mCecMessageCache.flushAll();
        } else {
            if (connected) {
                // TODO(amyjojo): start the device discovery action
                launchDeviceDiscovery();
            } else {
                // TODO(amyjojo): remove device from mDeviceInfo
            }
@@ -250,6 +252,8 @@ public class HdmiCecLocalDeviceAudioSystem extends HdmiCecLocalDeviceSource {
        boolean lastSystemAudioControlStatus =
                SystemProperties.getBoolean(Constants.PROPERTY_LAST_SYSTEM_AUDIO_CONTROL, true);
        systemAudioControlOnPowerOn(systemAudioControlOnPowerOnProp, lastSystemAudioControlStatus);
        clearDeviceInfoList();
        launchDeviceDiscovery();
        startQueuedActions();
    }

@@ -946,4 +950,32 @@ public class HdmiCecLocalDeviceAudioSystem extends HdmiCecLocalDeviceSource {

        invokeDeviceEventListener(newInfo, HdmiControlManager.DEVICE_EVENT_UPDATE_DEVICE);
    }

    @ServiceThreadOnly
    private void launchDeviceDiscovery() {
        assertRunOnServiceThread();
        DeviceDiscoveryAction action = new DeviceDiscoveryAction(this,
                new DeviceDiscoveryCallback() {
                    @Override
                    public void onDeviceDiscoveryDone(List<HdmiDeviceInfo> deviceInfos) {
                        for (HdmiDeviceInfo info : deviceInfos) {
                            addCecDevice(info);
                        }
                    }
                });
        addAndStartAction(action);
    }

    // Clear all device info.
    @ServiceThreadOnly
    private void clearDeviceInfoList() {
        assertRunOnServiceThread();
        for (HdmiDeviceInfo info : HdmiUtils.sparseArrayToList(mDeviceInfos)) {
            if (info.getPhysicalAddress() == mService.getPhysicalAddress()) {
                continue;
            }
            invokeDeviceEventListener(info, HdmiControlManager.DEVICE_EVENT_REMOVE_DEVICE);
        }
        mDeviceInfos.clear();
    }
}
+0 −4
Original line number Diff line number Diff line
@@ -346,10 +346,6 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
        }
    }

    int getPortId(int physicalAddress) {
        return mService.pathToPortId(physicalAddress);
    }

    /**
     * Returns the previous port id kept to handle input switching on <Inactive Source>.
     */