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

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

Fix missing iteration policy on device discover action

Device polling requires both pick policy and pick iteration policy,
however, device discovery action has no iteration policy.
Along with fix, move send result and pick policy constants
to HdmiConstants package

Change-Id: Ibbcfdc482a189bbc3aa2c61143422541da78447d
parent 8db85ab7
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -119,7 +119,8 @@ final class DeviceDiscoveryAction extends FeatureAction {
                allocateDevices(ackedAddress);
                startPhysicalAddressStage();
            }
        }, HdmiControlService.POLL_STRATEGY_REMOTES_DEVICES, DEVICE_POLLING_RETRY);
        }, HdmiConstants.POLL_ITERATION_REVERSE_ORDER
            | HdmiConstants.POLL_STRATEGY_REMOTES_DEVICES, DEVICE_POLLING_RETRY);
        return true;
    }

+8 −8
Original line number Diff line number Diff line
@@ -366,29 +366,29 @@ final class HdmiCecController {
    }

    private List<Integer> pickPollCandidates(int pickStrategy) {
        int strategy = pickStrategy & HdmiControlService.POLL_STRATEGY_MASK;
        int strategy = pickStrategy & HdmiConstants.POLL_STRATEGY_MASK;
        Predicate<Integer> pickPredicate = null;
        switch (strategy) {
            case HdmiControlService.POLL_STRATEGY_SYSTEM_AUDIO:
            case HdmiConstants.POLL_STRATEGY_SYSTEM_AUDIO:
                pickPredicate = mSystemAudioAddressPredicate;
                break;
            case HdmiControlService.POLL_STRATEGY_REMOTES_DEVICES:
            case HdmiConstants.POLL_STRATEGY_REMOTES_DEVICES:
            default:  // The default is POLL_STRATEGY_REMOTES_DEVICES.
                pickPredicate = mRemoteDeviceAddressPredicate;
                break;
        }

        int iterationStrategy = pickStrategy & HdmiControlService.POLL_ITERATION_STRATEGY_MASK;
        int iterationStrategy = pickStrategy & HdmiConstants.POLL_ITERATION_STRATEGY_MASK;
        ArrayList<Integer> pollingCandidates = new ArrayList<>();
        switch (iterationStrategy) {
            case HdmiControlService.POLL_ITERATION_IN_ORDER:
            case HdmiConstants.POLL_ITERATION_IN_ORDER:
                for (int i = HdmiCec.ADDR_TV; i <= HdmiCec.ADDR_SPECIFIC_USE; ++i) {
                    if (pickPredicate.apply(i)) {
                        pollingCandidates.add(i);
                    }
                }
                break;
            case HdmiControlService.POLL_ITERATION_REVERSE_ORDER:
            case HdmiConstants.POLL_ITERATION_REVERSE_ORDER:
            default:  // The default is reverse order.
                for (int i = HdmiCec.ADDR_SPECIFIC_USE; i >= HdmiCec.ADDR_TV; --i) {
                    if (pickPredicate.apply(i)) {
@@ -442,7 +442,7 @@ final class HdmiCecController {
            // new logical address for the device because no device uses
            // it as logical address of the device.
            if (nativeSendCecCommand(mNativePtr, address, address, EMPTY_BODY)
                    == HdmiControlService.SEND_RESULT_SUCCESS) {
                    == HdmiConstants.SEND_RESULT_SUCCESS) {
                return true;
            }
        }
@@ -509,7 +509,7 @@ final class HdmiCecController {
                byte[] body = buildBody(cecMessage.getOpcode(), cecMessage.getParams());
                final int error = nativeSendCecCommand(mNativePtr, cecMessage.getSource(),
                        cecMessage.getDestination(), body);
                if (error != HdmiControlService.SEND_RESULT_SUCCESS) {
                if (error != HdmiConstants.SEND_RESULT_SUCCESS) {
                    Slog.w(TAG, "Failed to send " + cecMessage);
                }
                if (callback != null) {
+15 −0
Original line number Diff line number Diff line
@@ -80,5 +80,20 @@ final class HdmiConstants {
    static final int INVALID_PORT_ID = -1;
    static final int INVALID_PHYSICAL_ADDRESS = 0xFFFF;

    // Send result codes.
    static final int SEND_RESULT_SUCCESS = 0;
    static final int SEND_RESULT_NAK = -1;
    static final int SEND_RESULT_FAILURE = -2;

    // Strategy for device polling.
    // Should use "OR(|) operation of POLL_STRATEGY_XXX and POLL_ITERATION_XXX.
    static final int POLL_STRATEGY_MASK = 0x3;  // first and second bit.
    static final int POLL_STRATEGY_REMOTES_DEVICES = 0x1;
    static final int POLL_STRATEGY_SYSTEM_AUDIO = 0x2;

    static final int POLL_ITERATION_STRATEGY_MASK = 0x30000;  // first and second bit.
    static final int POLL_ITERATION_IN_ORDER = 0x10000;
    static final int POLL_ITERATION_REVERSE_ORDER = 0x20000;

    private HdmiConstants() { /* cannot be instantiated */ }
}
+2 −14
Original line number Diff line number Diff line
@@ -54,18 +54,6 @@ public final class HdmiControlService extends SystemService {
    // TODO: Rename the permission to HDMI_CONTROL.
    private static final String PERMISSION = "android.permission.HDMI_CEC";

    static final int SEND_RESULT_SUCCESS = 0;
    static final int SEND_RESULT_NAK = -1;
    static final int SEND_RESULT_FAILURE = -2;

    static final int POLL_STRATEGY_MASK = 0x3;  // first and second bit.
    static final int POLL_STRATEGY_REMOTES_DEVICES = 0x1;
    static final int POLL_STRATEGY_SYSTEM_AUDIO = 0x2;

    static final int POLL_ITERATION_STRATEGY_MASK = 0x30000;  // first and second bit.
    static final int POLL_ITERATION_IN_ORDER = 0x10000;
    static final int POLL_ITERATION_REVERSE_ORDER = 0x20000;

    /**
     * Interface to report send result.
     */
@@ -430,11 +418,11 @@ public final class HdmiControlService extends SystemService {
    }

    private int checkPollStrategy(int pickStrategy) {
        int strategy = pickStrategy & POLL_STRATEGY_MASK;
        int strategy = pickStrategy & HdmiConstants.POLL_STRATEGY_MASK;
        if (strategy == 0) {
            throw new IllegalArgumentException("Invalid poll strategy:" + pickStrategy);
        }
        int iterationStrategy = pickStrategy & POLL_ITERATION_STRATEGY_MASK;
        int iterationStrategy = pickStrategy & HdmiConstants.POLL_ITERATION_STRATEGY_MASK;
        if (iterationStrategy == 0) {
            throw new IllegalArgumentException("Invalid iteration strategy:" + pickStrategy);
        }
+4 −4
Original line number Diff line number Diff line
@@ -125,8 +125,8 @@ final class HotplugDetectionAction extends FeatureAction {
            public void onPollingFinished(List<Integer> ackedAddress) {
                checkHotplug(ackedAddress, false);
            }
        }, HdmiControlService.POLL_ITERATION_IN_ORDER
                | HdmiControlService.POLL_STRATEGY_REMOTES_DEVICES, POLL_RETRY_COUNT);
        }, HdmiConstants.POLL_ITERATION_IN_ORDER
                | HdmiConstants.POLL_STRATEGY_REMOTES_DEVICES, POLL_RETRY_COUNT);
    }

    private void pollAudioSystem() {
@@ -137,8 +137,8 @@ final class HotplugDetectionAction extends FeatureAction {
            public void onPollingFinished(List<Integer> ackedAddress) {
                checkHotplug(ackedAddress, true);
            }
        }, HdmiControlService.POLL_ITERATION_IN_ORDER
                | HdmiControlService.POLL_STRATEGY_SYSTEM_AUDIO, POLL_RETRY_COUNT);
        }, HdmiConstants.POLL_ITERATION_IN_ORDER
                | HdmiConstants.POLL_STRATEGY_SYSTEM_AUDIO, POLL_RETRY_COUNT);
    }

    private void checkHotplug(List<Integer> ackedAddress, boolean audioOnly) {
Loading