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

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

Add api, setArcMode, used to turn on/off ARC.

Usual TV can switch on and off of ARC feature in its settings page.
Along with it, removed locking block from the code,
because arc flags are accessed by actions and internal services.

Change-Id: I737ac0c2671b537551eaac202d2065cc99c6d0a0
parent f2d4fa8c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -49,4 +49,5 @@ interface IHdmiControlService {
    void addSystemAudioModeChangeListener(IHdmiSystemAudioModeChangeListener listener);
    void removeSystemAudioModeChangeListener(IHdmiSystemAudioModeChangeListener listener);
    void setControlEnabled(boolean enabled);
    void setArcMode(boolean enabled);
}
+2 −2
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ public class HdmiAnnotations {
     * whether it's called from service thread.
     */
    @Retention(RetentionPolicy.RUNTIME)
    @Target(ElementType.METHOD)
    @Target({ElementType.METHOD, ElementType.FIELD})
    public @interface ServiceThreadOnly {
    }

@@ -41,7 +41,7 @@ public class HdmiAnnotations {
     * whether it's called from io thread.
     */
    @Retention(RetentionPolicy.RUNTIME)
    @Target(ElementType.METHOD)
    @Target({ElementType.METHOD, ElementType.FIELD})
    public @interface IoThreadOnly {
    }
}
+71 −19
Original line number Diff line number Diff line
@@ -40,9 +40,13 @@ import java.util.Locale;
final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
    private static final String TAG = "HdmiCecLocalDeviceTv";

    // Whether ARC is "enabled" or not.
    @GuardedBy("mLock")
    private boolean mArcStatusEnabled = false;
    // Whether ARC is available or not. "true" means that ARC is estabilished between TV and
    // AVR as audio receiver.
    @ServiceThreadOnly
    private boolean mArcEstablished = false;

    // Whether ARC feature is enabled or not.
    private boolean mArcFeatureEnabled = false;

    // Whether SystemAudioMode is "On" or not.
    @GuardedBy("mLock")
@@ -462,9 +466,8 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
                        if (avrInfo != null) {
                            addAndStartAction(new SystemAudioAutoInitiationAction(
                                    HdmiCecLocalDeviceTv.this, avrInfo.getLogicalAddress()));
                            if (isConnectedToArcPort(avrInfo.getPhysicalAddress())) {
                                addAndStartAction(new RequestArcInitiationAction(
                                        HdmiCecLocalDeviceTv.this, avrInfo.getLogicalAddress()));
                            if (mArcEstablished) {
                                startArcAction(true);
                            }
                        }
                    }
@@ -514,18 +517,18 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
     *
     * @return {@code true} if ARC was in "Enabled" status
     */
    @ServiceThreadOnly
    boolean setArcStatus(boolean enabled) {
        synchronized (mLock) {
            boolean oldStatus = mArcStatusEnabled;
        assertRunOnServiceThread();
        boolean oldStatus = mArcEstablished;
        // 1. Enable/disable ARC circuit.
        mService.setAudioReturnChannel(enabled);
        // 2. Notify arc status to audio service.
        notifyArcStatusToAudioService(enabled);
        // 3. Update arc status;
            mArcStatusEnabled = enabled;
        mArcEstablished = enabled;
        return oldStatus;
    }
    }

    private void notifyArcStatusToAudioService(boolean enabled) {
        // Note that we don't set any name to ARC.
@@ -537,9 +540,58 @@ final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
    /**
     * Returns whether ARC is enabled or not.
     */
    boolean getArcStatus() {
        synchronized (mLock) {
            return mArcStatusEnabled;
    @ServiceThreadOnly
    boolean isArcEstabilished() {
        assertRunOnServiceThread();
        return mArcFeatureEnabled && mArcEstablished;
    }

    @ServiceThreadOnly
    void changeArcFeatureEnabled(boolean enabled) {
        assertRunOnServiceThread();

        if (mArcFeatureEnabled != enabled) {
            if (enabled) {
                if (!mArcEstablished) {
                    startArcAction(true);
                }
            } else {
                if (mArcEstablished) {
                    startArcAction(false);
                }
            }
            mArcFeatureEnabled = enabled;
        }
    }

    @ServiceThreadOnly
    boolean isArcFeatureEnabled() {
        assertRunOnServiceThread();
        return mArcFeatureEnabled;
    }

    @ServiceThreadOnly
    private void startArcAction(boolean enabled) {
        assertRunOnServiceThread();
        HdmiCecDeviceInfo info = getAvrDeviceInfo();
        if (info == null) {
            return;
        }
        if (!isConnectedToArcPort(info.getPhysicalAddress())) {
            return;
        }

        // Terminate opposite action and start action if not exist.
        if (enabled) {
            removeAction(RequestArcTerminationAction.class);
            if (!hasAction(RequestArcInitiationAction.class)) {
                addAndStartAction(new RequestArcInitiationAction(this, info.getLogicalAddress()));
            }
        } else {
            removeAction(RequestArcInitiationAction.class);
            if (!hasAction(RequestArcTerminationAction.class)) {
                addAndStartAction(new RequestArcTerminationAction(this, info.getLogicalAddress()));
            }
        }
    }

+15 −0
Original line number Diff line number Diff line
@@ -745,6 +745,21 @@ public final class HdmiControlService extends SystemService {
                }
            });
        }

        @Override
        public void setArcMode(final boolean enabled) {
            enforceAccessPermission();
            runOnServiceThread(new Runnable() {
                @Override
                public void run() {
                    HdmiCecLocalDeviceTv tv = tv();
                    if (tv == null) {
                        Slog.w(TAG, "Local tv device not available to change arc mode.");
                        return;
                    }
                }
            });
        }
    }

    @ServiceThreadOnly
+1 −1
Original line number Diff line number Diff line
@@ -240,7 +240,7 @@ final class HotplugDetectionAction extends FeatureAction {

        // Turn off system audio mode.
        tv().setSystemAudioMode(false);
        if (tv().getArcStatus()) {
        if (tv().isArcEstabilished()) {
            addAndStartAction(new RequestArcTerminationAction(localDevice(), address));
        }
    }
Loading