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

Commit 0ad71d43 authored by William Escande's avatar William Escande
Browse files

Errorprone: WakelockReleasedDangerously

[WakelockReleasedDangerously] a wakelock acquired with a timeout may be
released by the system before calling `release`, even after checking
`isHeld()`.
If so, it will throw a RuntimeException.
Please wrap in a try/catch block.

Test: m Bluetooth
Bug: 344658662
Flag: Exempt, preventing crash
Change-Id: I893db9cab69e88a7eb007eb5b26c3d3101e9925a
parent 0858ed46
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -363,6 +363,7 @@ android_app {
            "-Xep:UnusedNestedClass:ERROR",
            "-Xep:UnusedVariable:ERROR",
            "-Xep:WaitNotInLoop:ERROR",
            "-Xep:WakelockReleasedDangerously:ERROR",

            // After fixing this errorprone, we decided to not merge the change.
            // It is not very readable and the benefits are minimal when looking
+20 −4
Original line number Diff line number Diff line
@@ -258,7 +258,11 @@ public class HeadsetService extends ProfileService {
                mStateMachinesThreadHandler.removeCallbacks(mVoiceRecognitionTimeoutEvent);
                mVoiceRecognitionTimeoutEvent = null;
                if (mSystemInterface.getVoiceRecognitionWakeLock().isHeld()) {
                    try {
                        mSystemInterface.getVoiceRecognitionWakeLock().release();
                    } catch (RuntimeException e) {
                        Log.d(TAG, "non properly release getVoiceRecognitionWakeLock", e);
                    }
                }
            }
            // Step 5: Destroy state machines
@@ -1120,7 +1124,11 @@ public class HeadsetService extends ProfileService {
                mStateMachinesThreadHandler.removeCallbacks(mVoiceRecognitionTimeoutEvent);
                mVoiceRecognitionTimeoutEvent = null;
                if (mSystemInterface.getVoiceRecognitionWakeLock().isHeld()) {
                    try {
                        mSystemInterface.getVoiceRecognitionWakeLock().release();
                    } catch (RuntimeException e) {
                        Log.d(TAG, "non properly release getVoiceRecognitionWakeLock", e);
                    }
                }
                pendingRequestByHeadset = true;
            }
@@ -1795,7 +1803,11 @@ public class HeadsetService extends ProfileService {
        public void run() {
            synchronized (mStateMachines) {
                if (mSystemInterface.getVoiceRecognitionWakeLock().isHeld()) {
                    try {
                        mSystemInterface.getVoiceRecognitionWakeLock().release();
                    } catch (RuntimeException e) {
                        Log.d(TAG, "non properly release getVoiceRecognitionWakeLock", e);
                    }
                }
                mVoiceRecognitionTimeoutEvent = null;
                doForStateMachine(
@@ -1918,7 +1930,11 @@ public class HeadsetService extends ProfileService {
            }
            if (mVoiceRecognitionTimeoutEvent != null) {
                if (mSystemInterface.getVoiceRecognitionWakeLock().isHeld()) {
                    try {
                        mSystemInterface.getVoiceRecognitionWakeLock().release();
                    } catch (RuntimeException e) {
                        Log.d(TAG, "non properly release getVoiceRecognitionWakeLock", e);
                    }
                }
                mStateMachinesThreadHandler.removeCallbacks(mVoiceRecognitionTimeoutEvent);