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

Commit d46800e6 authored by Yan Han's avatar Yan Han
Browse files

Remove redundant @GuardedBy's in HdmiCecLocalDevice.

@GuardedBy is unnecessary in HdmiCecLocalDevice#getDeviceInfo and
HdmiCecLocalDevice#setDeviceInfo because those methods already acquire
the lock. This CL removes these @GuardedBy annotations and all
synchronized blocks added because of them.

Test: make
Bug: 215321161
Change-Id: Ic334fda703ef057f2e0ecd88919fa55148ac97eb
parent 37ca4345
Loading
Loading
Loading
Loading
+7 −15
Original line number Original line Diff line number Diff line
@@ -71,7 +71,7 @@ abstract class HdmiCecLocalDevice {
    protected final int mDeviceType;
    protected final int mDeviceType;
    protected int mPreferredAddress;
    protected int mPreferredAddress;
    @GuardedBy("mLock")
    @GuardedBy("mLock")
    protected HdmiDeviceInfo mDeviceInfo;
    private HdmiDeviceInfo mDeviceInfo;
    protected int mLastKeycode = HdmiCecKeycode.UNSUPPORTED_KEYCODE;
    protected int mLastKeycode = HdmiCecKeycode.UNSUPPORTED_KEYCODE;
    protected int mLastKeyRepeatCount = 0;
    protected int mLastKeyRepeatCount = 0;


@@ -666,22 +666,18 @@ abstract class HdmiCecLocalDevice {
     * Computes the set of supported device features, and updates local state to match.
     * Computes the set of supported device features, and updates local state to match.
     */
     */
    private void updateDeviceFeatures() {
    private void updateDeviceFeatures() {
        synchronized (mLock) {
        setDeviceInfo(getDeviceInfo().toBuilder()
        setDeviceInfo(getDeviceInfo().toBuilder()
                .setDeviceFeatures(computeDeviceFeatures())
                .setDeviceFeatures(computeDeviceFeatures())
                .build());
                .build());
    }
    }
    }


    /**
    /**
     * Computes and returns the set of supported device features. Updates local state to match.
     * Computes and returns the set of supported device features. Updates local state to match.
     */
     */
    protected final DeviceFeatures getDeviceFeatures() {
    protected final DeviceFeatures getDeviceFeatures() {
        updateDeviceFeatures();
        updateDeviceFeatures();
        synchronized (mLock) {
        return getDeviceInfo().getDeviceFeatures();
        return getDeviceInfo().getDeviceFeatures();
    }
    }
    }


    @Constants.HandleMessageResult
    @Constants.HandleMessageResult
    protected int handleGiveFeatures(HdmiCecMessage message) {
    protected int handleGiveFeatures(HdmiCecMessage message) {
@@ -982,14 +978,12 @@ abstract class HdmiCecLocalDevice {
        return mDeviceType;
        return mDeviceType;
    }
    }


    @GuardedBy("mLock")
    HdmiDeviceInfo getDeviceInfo() {
    HdmiDeviceInfo getDeviceInfo() {
        synchronized (mLock) {
        synchronized (mLock) {
            return mDeviceInfo;
            return mDeviceInfo;
        }
        }
    }
    }


    @GuardedBy("mLock")
    void setDeviceInfo(HdmiDeviceInfo info) {
    void setDeviceInfo(HdmiDeviceInfo info) {
        synchronized (mLock) {
        synchronized (mLock) {
            mDeviceInfo = info;
            mDeviceInfo = info;
@@ -1042,11 +1036,9 @@ abstract class HdmiCecLocalDevice {


        // Send <Give Features> if using CEC 2.0 or above.
        // Send <Give Features> if using CEC 2.0 or above.
        if (mService.getCecVersion() >= HdmiControlManager.HDMI_CEC_VERSION_2_0) {
        if (mService.getCecVersion() >= HdmiControlManager.HDMI_CEC_VERSION_2_0) {
            synchronized (mLock) {
            mService.sendCecCommand(HdmiCecMessageBuilder.buildGiveFeatures(
            mService.sendCecCommand(HdmiCecMessageBuilder.buildGiveFeatures(
                    getDeviceInfo().getLogicalAddress(), targetAddress));
                    getDeviceInfo().getLogicalAddress(), targetAddress));
        }
        }
        }


        // If we don't already have a {@link SetAudioVolumeLevelDiscoveryAction} for the target
        // If we don't already have a {@link SetAudioVolumeLevelDiscoveryAction} for the target
        // device, start one.
        // device, start one.
+4 −8
Original line number Original line Diff line number Diff line
@@ -138,10 +138,8 @@ public class HdmiCecLocalDevicePlayback extends HdmiCecLocalDeviceSource {
                        // does not poll local devices, we should put device info of local device
                        // does not poll local devices, we should put device info of local device
                        // manually here.
                        // manually here.
                        for (HdmiCecLocalDevice device : mService.getAllLocalDevices()) {
                        for (HdmiCecLocalDevice device : mService.getAllLocalDevices()) {
                            synchronized (device.mLock) {
                            mService.getHdmiCecNetwork().addCecDevice(device.getDeviceInfo());
                            mService.getHdmiCecNetwork().addCecDevice(device.getDeviceInfo());
                        }
                        }
                        }


                        List<HotplugDetectionAction> hotplugActions =
                        List<HotplugDetectionAction> hotplugActions =
                                getActions(HotplugDetectionAction.class);
                                getActions(HotplugDetectionAction.class);
@@ -179,12 +177,10 @@ public class HdmiCecLocalDevicePlayback extends HdmiCecLocalDeviceSource {
    @ServiceThreadOnly
    @ServiceThreadOnly
    void deviceSelect(int id, IHdmiControlCallback callback) {
    void deviceSelect(int id, IHdmiControlCallback callback) {
        assertRunOnServiceThread();
        assertRunOnServiceThread();
        synchronized (mLock) {
        if (id == getDeviceInfo().getId()) {
        if (id == getDeviceInfo().getId()) {
            mService.oneTouchPlay(callback);
            mService.oneTouchPlay(callback);
            return;
            return;
        }
        }
        }
        HdmiDeviceInfo targetDevice = mService.getHdmiCecNetwork().getDeviceInfo(id);
        HdmiDeviceInfo targetDevice = mService.getHdmiCecNetwork().getDeviceInfo(id);
        if (targetDevice == null) {
        if (targetDevice == null) {
            invokeCallback(callback, HdmiControlManager.RESULT_TARGET_NOT_AVAILABLE);
            invokeCallback(callback, HdmiControlManager.RESULT_TARGET_NOT_AVAILABLE);
+7 −14
Original line number Original line Diff line number Diff line
@@ -1331,7 +1331,6 @@ public class HdmiControlService extends SystemService {
     */
     */
    private boolean sourceAddressIsLocal(HdmiCecMessage message) {
    private boolean sourceAddressIsLocal(HdmiCecMessage message) {
        for (HdmiCecLocalDevice device : getAllLocalDevices()) {
        for (HdmiCecLocalDevice device : getAllLocalDevices()) {
            synchronized (device.mLock) {
            if (message.getSource() == device.getDeviceInfo().getLogicalAddress()
            if (message.getSource() == device.getDeviceInfo().getLogicalAddress()
                    && message.getSource() != Constants.ADDR_UNREGISTERED) {
                    && message.getSource() != Constants.ADDR_UNREGISTERED) {
                HdmiLogger.warning(
                HdmiLogger.warning(
@@ -1339,7 +1338,6 @@ public class HdmiControlService extends SystemService {
                return true;
                return true;
            }
            }
        }
        }
        }
        return false;
        return false;
    }
    }


@@ -1560,9 +1558,7 @@ public class HdmiControlService extends SystemService {
            if (deviceInfo.getDisplayName().equals(newDisplayName)) {
            if (deviceInfo.getDisplayName().equals(newDisplayName)) {
                continue;
                continue;
            }
            }
            synchronized (device.mLock) {
            device.setDeviceInfo(deviceInfo.toBuilder().setDisplayName(newDisplayName).build());
            device.setDeviceInfo(deviceInfo.toBuilder().setDisplayName(newDisplayName).build());
            }
            sendCecCommand(
            sendCecCommand(
                    HdmiCecMessageBuilder.buildSetOsdNameCommand(
                    HdmiCecMessageBuilder.buildSetOsdNameCommand(
                            deviceInfo.getLogicalAddress(), Constants.ADDR_TV, newDisplayName));
                            deviceInfo.getLogicalAddress(), Constants.ADDR_TV, newDisplayName));
@@ -4096,10 +4092,7 @@ public class HdmiControlService extends SystemService {
        public void onAudioDeviceVolumeChanged(
        public void onAudioDeviceVolumeChanged(
                @NonNull AudioDeviceAttributes audioDevice,
                @NonNull AudioDeviceAttributes audioDevice,
                @NonNull VolumeInfo volumeInfo) {
                @NonNull VolumeInfo volumeInfo) {
            int localDeviceAddress;
            int localDeviceAddress = mLocalDevice.getDeviceInfo().getLogicalAddress();
            synchronized (mLocalDevice.mLock) {
                localDeviceAddress = mLocalDevice.getDeviceInfo().getLogicalAddress();
            }
            sendCecCommand(SetAudioVolumeLevelMessage.build(
            sendCecCommand(SetAudioVolumeLevelMessage.build(
                            localDeviceAddress,
                            localDeviceAddress,
                            mSystemAudioDevice.getLogicalAddress(),
                            mSystemAudioDevice.getLogicalAddress(),
+1 −3
Original line number Original line Diff line number Diff line
@@ -212,10 +212,8 @@ public abstract class BaseAbsoluteVolumeControlTest {
    }
    }


    protected int getLogicalAddress() {
    protected int getLogicalAddress() {
        synchronized (mHdmiCecLocalDevice.mLock) {
        return mHdmiCecLocalDevice.getDeviceInfo().getLogicalAddress();
        return mHdmiCecLocalDevice.getDeviceInfo().getLogicalAddress();
    }
    }
    }


    /**
    /**
     * Simulates the volume behavior of {@code device} being set to {@code behavior}.
     * Simulates the volume behavior of {@code device} being set to {@code behavior}.
+3 −4
Original line number Original line Diff line number Diff line
@@ -147,10 +147,9 @@ public class DeviceSelectActionFromPlaybackTest {


        // The addresses depend on local device's LA.
        // The addresses depend on local device's LA.
        // This help the tests to pass with every local device LA.
        // This help the tests to pass with every local device LA.
        synchronized (mHdmiCecLocalDevicePlayback.mLock) {
        mPlaybackLogicalAddress1 =
        mPlaybackLogicalAddress1 =
                mHdmiCecLocalDevicePlayback.getDeviceInfo().getLogicalAddress();
                mHdmiCecLocalDevicePlayback.getDeviceInfo().getLogicalAddress();
        }

        mPlaybackLogicalAddress2 = mPlaybackLogicalAddress1 == ADDR_PLAYBACK_2
        mPlaybackLogicalAddress2 = mPlaybackLogicalAddress1 == ADDR_PLAYBACK_2
                ? ADDR_PLAYBACK_1 : ADDR_PLAYBACK_2;
                ? ADDR_PLAYBACK_1 : ADDR_PLAYBACK_2;
        mPlaybackLogicalAddress3 = mPlaybackLogicalAddress1 == ADDR_PLAYBACK_3
        mPlaybackLogicalAddress3 = mPlaybackLogicalAddress1 == ADDR_PLAYBACK_3
Loading