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

Commit 3ef57d99 authored by Jungshik Jang's avatar Jungshik Jang
Browse files

DO NOT MERGE: Start Device Discovery after logical address allocation.

Usually TV initiates Device Discovery sequence after logical address
allocation of local devices. For that added new callback interface
to AddressAllocationCallback to HdmiCecDevice.
Along with this, add onAddressAllocated to HdmiLocalDevice so that
start sending local device information once logical allocation is done.

Change-Id: I4cdc5dd7770674a17a0f23c383a6c1ca221e3104
parent af9d45e8
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -115,12 +115,12 @@ final class DeviceDiscoveryAction extends FeatureAction {
            @Override
            public void onPollingFinished(List<Integer> ackedAddress) {
                if (ackedAddress.isEmpty()) {
                    Slog.i(TAG, "No device is detected.");
                    Slog.v(TAG, "No device is detected.");
                    finish();
                    return;
                }

                Slog.i(TAG, "Device detected: " + ackedAddress);
                Slog.v(TAG, "Device detected: " + ackedAddress);
                allocateDevices(ackedAddress);
                startPhysicalAddressStage();
            }
@@ -136,6 +136,7 @@ final class DeviceDiscoveryAction extends FeatureAction {
    }

    private void startPhysicalAddressStage() {
        Slog.v(TAG, "Start [Physical Address Stage]:" + mDevices.size());
        mProcessedDeviceCount = 0;
        mState = STATE_WAITING_FOR_PHYSICAL_ADDRESS;

@@ -158,6 +159,7 @@ final class DeviceDiscoveryAction extends FeatureAction {
    }

    private void startOsdNameStage() {
        Slog.v(TAG, "Start [Osd Name Stage]:" + mDevices.size());
        mProcessedDeviceCount = 0;
        mState = STATE_WAITING_FOR_OSD_NAME;

@@ -176,6 +178,8 @@ final class DeviceDiscoveryAction extends FeatureAction {
    }

    private void startVendorIdStage() {
        Slog.v(TAG, "Start [Vendor Id Stage]:" + mDevices.size());

        mProcessedDeviceCount = 0;
        mState = STATE_WAITING_FOR_VENDOR_ID;

@@ -301,11 +305,14 @@ final class DeviceDiscoveryAction extends FeatureAction {
    }

    private void wrapUpAndFinish() {
        Slog.v(TAG, "---------Wrap up Device Discovery:[" + mDevices.size() + "]---------");
        ArrayList<HdmiCecDeviceInfo> result = new ArrayList<>();
        for (DeviceInfo info : mDevices) {
            HdmiCecDeviceInfo cecDeviceInfo = info.toHdmiCecDeviceInfo();
            Slog.v(TAG, " DeviceInfo: " + cecDeviceInfo);
            result.add(cecDeviceInfo);
        }
        Slog.v(TAG, "--------------------------------------------");
        mCallback.onDeviceDiscoveryDone(result);
        finish();
    }
@@ -355,6 +362,7 @@ final class DeviceDiscoveryAction extends FeatureAction {
            return;
        }

        Slog.v(TAG, "Timeout[State=" + mState + ", Processed=" + mProcessedDeviceCount);
        removeDevice(mProcessedDeviceCount);
        checkAndProceedStage();
    }
+3 −2
Original line number Diff line number Diff line
@@ -121,10 +121,11 @@ final class HdmiCecController {
     *
     * @param deviceTypes array of device types
     */
    void initializeLocalDevices(int[] deviceTypes) {
    void initializeLocalDevices(int[] deviceTypes,
            HdmiCecLocalDevice.AddressAllocationCallback callback) {
        assertRunOnServiceThread();
        for (int type : deviceTypes) {
            HdmiCecLocalDevice device = HdmiCecLocalDevice.create(this, type);
            HdmiCecLocalDevice device = HdmiCecLocalDevice.create(this, type, callback);
            if (device == null) {
                continue;
            }
+32 −4
Original line number Diff line number Diff line
@@ -29,23 +29,41 @@ abstract class HdmiCecLocalDevice {

    protected final HdmiCecController mController;
    protected final int mDeviceType;
    protected final AddressAllocationCallback mAllocationCallback;
    protected int mAddress;
    protected int mPreferredAddress;
    protected HdmiCecDeviceInfo mDeviceInfo;

    protected HdmiCecLocalDevice(HdmiCecController controller, int deviceType) {
    /**
     * Callback interface to notify newly allocated logical address of the given
     * local device.
     */
    interface AddressAllocationCallback {
        /**
         * Called when a logical address of the given device is allocated.
         *
         * @param deviceType original device type
         * @param logicalAddress newly allocated logical address
         */
        void onAddressAllocated(int deviceType, int logicalAddress);
    }

    protected HdmiCecLocalDevice(HdmiCecController controller, int deviceType,
            AddressAllocationCallback callback) {
        mController = controller;
        mDeviceType = deviceType;
        mAllocationCallback = callback;
        mAddress = HdmiCec.ADDR_UNREGISTERED;
    }

    // Factory method that returns HdmiCecLocalDevice of corresponding type.
    static HdmiCecLocalDevice create(HdmiCecController controller, int deviceType) {
    static HdmiCecLocalDevice create(HdmiCecController controller, int deviceType,
            AddressAllocationCallback callback) {
        switch (deviceType) {
        case HdmiCec.DEVICE_TV:
            return new HdmiCecLocalDeviceTv(controller);
            return new HdmiCecLocalDeviceTv(controller, callback);
        case HdmiCec.DEVICE_PLAYBACK:
            return new HdmiCecLocalDevicePlayback(controller);
            return new HdmiCecLocalDevicePlayback(controller, callback);
        default:
            return null;
        }
@@ -53,6 +71,12 @@ abstract class HdmiCecLocalDevice {

    abstract void init();

    /**
     * Called when a logical address of the local device is allocated.
     * Note that internal variables are updated before it's called.
     */
    protected abstract void onAddressAllocated(int logicalAddress);

    protected void allocateAddress(int type) {
        mController.allocateLogicalAddress(type, mPreferredAddress,
                new AllocateLogicalAddressCallback() {
@@ -66,6 +90,10 @@ abstract class HdmiCecLocalDevice {
                mController.addDeviceInfo(deviceInfo);

                mController.addLogicalAddress(logicalAddress);
                onAddressAllocated(logicalAddress);
                if (mAllocationCallback != null) {
                    mAllocationCallback.onAddressAllocated(deviceType, logicalAddress);
                }
            }
        });
    }
+6 −2
Original line number Diff line number Diff line
@@ -23,13 +23,17 @@ import android.hardware.hdmi.HdmiCec;
 */
final class HdmiCecLocalDevicePlayback extends HdmiCecLocalDevice {

    HdmiCecLocalDevicePlayback(HdmiCecController controller) {
        super(controller, HdmiCec.DEVICE_PLAYBACK);
    HdmiCecLocalDevicePlayback(HdmiCecController controller, AddressAllocationCallback callback) {
        super(controller, HdmiCec.DEVICE_PLAYBACK, callback);
    }

    @Override
    void init() {
        allocateAddress(mDeviceType);
    }

    @Override
    protected void onAddressAllocated(int logicalAddress) {
        mController.sendCommand(HdmiCecMessageBuilder.buildReportPhysicalAddressCommand(
                mAddress, mController.getPhysicalAddress(), mDeviceType));
    }
+5 −2
Original line number Diff line number Diff line
@@ -23,14 +23,17 @@ import android.hardware.hdmi.HdmiCec;
 */
final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {

    HdmiCecLocalDeviceTv(HdmiCecController controller) {
        super(controller, HdmiCec.DEVICE_TV);
    HdmiCecLocalDeviceTv(HdmiCecController controller, AddressAllocationCallback callback) {
        super(controller, HdmiCec.DEVICE_TV, callback);
    }

    @Override
    void init() {
        allocateAddress(mDeviceType);
    }

    @Override
    protected void onAddressAllocated(int logicalAddress) {
        // TODO: vendor-specific initialization here.

        mController.sendCommand(HdmiCecMessageBuilder.buildReportPhysicalAddressCommand(
Loading