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

Commit a9f10629 authored by Jungshik Jang's avatar Jungshik Jang
Browse files

Start address allocation when hdmi cec is re-enabled.

When a user turns hdmi cec on from system settings or other possible way,
hdmi control service should start over from logical address allocation.
As device discovery action from bootup is slightly different from
one from enabling hdmi cec, added additional params to all notification
method which is called when logical address allocation is done.

Bug: 16222082

Change-Id: Ib73be5f642646918b470d769dc563753c4ff48d3
parent 7ecfbaed
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -115,7 +115,7 @@ abstract class HdmiCecLocalDevice {
    /**
     * Called once a logical address of the local device is allocated.
     */
    protected abstract void onAddressAllocated(int logicalAddress);
    protected abstract void onAddressAllocated(int logicalAddress, boolean fromBootup);

    /**
     * Dispatch incoming message.
@@ -394,10 +394,10 @@ abstract class HdmiCecLocalDevice {
    }

    @ServiceThreadOnly
    final void handleAddressAllocated(int logicalAddress) {
    final void handleAddressAllocated(int logicalAddress, boolean fromBootup) {
        assertRunOnServiceThread();
        mAddress = mPreferredAddress = logicalAddress;
        onAddressAllocated(logicalAddress);
        onAddressAllocated(logicalAddress, fromBootup);
    }

    @ServiceThreadOnly
+1 −1
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ final class HdmiCecLocalDevicePlayback extends HdmiCecLocalDevice {

    @Override
    @ServiceThreadOnly
    protected void onAddressAllocated(int logicalAddress) {
    protected void onAddressAllocated(int logicalAddress, boolean fromBootup) {
        assertRunOnServiceThread();
        mService.sendCecCommand(HdmiCecMessageBuilder.buildReportPhysicalAddressCommand(
                mAddress, mService.getPhysicalAddress(), mDeviceType));
+2 −2
Original line number Diff line number Diff line
@@ -94,14 +94,14 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {

    @Override
    @ServiceThreadOnly
    protected void onAddressAllocated(int logicalAddress) {
    protected void onAddressAllocated(int logicalAddress, boolean fromBootup) {
        assertRunOnServiceThread();
        mService.sendCecCommand(HdmiCecMessageBuilder.buildReportPhysicalAddressCommand(
                mAddress, mService.getPhysicalAddress(), mDeviceType));
        mService.sendCecCommand(HdmiCecMessageBuilder.buildDeviceVendorIdCommand(
                mAddress, mService.getVendorId()));
        mSystemAudioMode = mService.readBooleanSetting(Global.HDMI_SYSTEM_AUDIO_ENABLED, false);
        launchRoutingControl(true);
        launchRoutingControl(fromBootup);
        launchDeviceDiscovery();
        registerAudioPortUpdateListener();
        // TODO: unregister audio port update listener if local device is released.
+20 −16
Original line number Diff line number Diff line
@@ -211,16 +211,17 @@ public final class HdmiControlService extends SystemService {
        mPowerStatus = HdmiControlManager.POWER_STATUS_TRANSIENT_TO_ON;
        mProhibitMode = false;
        mHdmiControlEnabled = readBooleanSetting(Global.HDMI_CONTROL_ENABLED, true);
        mCecController = HdmiCecController.create(this);

        mCecController = HdmiCecController.create(this);
        if (mCecController != null) {
            // TODO: Remove this as soon as OEM's HAL implementation is corrected.
            mCecController.setOption(HdmiTvClient.OPTION_CEC_ENABLE,
                    HdmiTvClient.ENABLED);

            mCecController.setOption(HdmiTvClient.OPTION_CEC_SERVICE_CONTROL,
                    HdmiTvClient.ENABLED);
            initializeLocalDevices(mLocalDevices);
            // TODO: load value for mHdmiControlEnabled from preference.
            if (mHdmiControlEnabled) {
                initializeCec(true);
            }
        } else {
            Slog.i(TAG, "Device does not support HDMI-CEC.");
        }
@@ -252,8 +253,14 @@ public final class HdmiControlService extends SystemService {
        Global.putInt(cr, key, value ? Constants.TRUE : Constants.FALSE);
    }

    private void initializeCec(boolean fromBootup) {
        mCecController.setOption(HdmiTvClient.OPTION_CEC_SERVICE_CONTROL,
                HdmiTvClient.ENABLED);
        initializeLocalDevices(mLocalDevices, fromBootup);
    }

    @ServiceThreadOnly
    private void initializeLocalDevices(final List<Integer> deviceTypes) {
    private void initializeLocalDevices(final List<Integer> deviceTypes, final boolean fromBootup) {
        assertRunOnServiceThread();
        // A container for [Logical Address, Local device info].
        final SparseArray<HdmiCecLocalDevice> devices = new SparseArray<>();
@@ -282,7 +289,7 @@ public final class HdmiControlService extends SystemService {
                        if (mPowerStatus == HdmiControlManager.POWER_STATUS_TRANSIENT_TO_ON) {
                            mPowerStatus = HdmiControlManager.POWER_STATUS_ON;
                        }
                        notifyAddressAllocated(devices);
                        notifyAddressAllocated(devices, fromBootup);
                    }
                }
            });
@@ -290,12 +297,13 @@ public final class HdmiControlService extends SystemService {
    }

    @ServiceThreadOnly
    private void notifyAddressAllocated(SparseArray<HdmiCecLocalDevice> devices) {
    private void notifyAddressAllocated(SparseArray<HdmiCecLocalDevice> devices,
            boolean fromBootup) {
        assertRunOnServiceThread();
        for (int i = 0; i < devices.size(); ++i) {
            int address = devices.keyAt(i);
            HdmiCecLocalDevice device = devices.valueAt(i);
            device.handleAddressAllocated(address);
            device.handleAddressAllocated(address, fromBootup);
        }
    }

@@ -1223,8 +1231,9 @@ public final class HdmiControlService extends SystemService {
        assertRunOnServiceThread();
        mPowerStatus = HdmiControlManager.POWER_STATUS_TRANSIENT_TO_ON;
        if (mCecController != null) {
            mCecController.setOption(HdmiTvClient.OPTION_CEC_SERVICE_CONTROL, HdmiTvClient.ENABLED);
            initializeLocalDevices(mLocalDevices);
            if (mHdmiControlEnabled) {
                initializeCec(true);
            }
        } else {
            Slog.i(TAG, "Device does not support HDMI-CEC.");
        }
@@ -1338,12 +1347,7 @@ public final class HdmiControlService extends SystemService {
        }

        if (enabled) {
            // TODO: call initalizedLocalDevice with additional param once putting
            // it to address allocation result.
            HdmiCecLocalDeviceTv tv = tv();
            if (tv != null) {
                tv.launchRoutingControl(false);
            }
            initializeCec(false);
        } else {
            disableDevices(new PendingActionClearedCallback() {
                @Override