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

Commit b98dad62 authored by Aditya Chitnis's avatar Aditya Chitnis
Browse files

Simplify mWakeLock logic in ContextHubClientBroker

Remove synchronized blocks when operating on wakelocks since mWakeLock
tokens all use synchronized blocks for all operations.

Bug: 268228873
Test: Presubmit
Change-Id: I118b32fec92491209794c1d288e42d5bcb901cd7
parent 86e546f9
Loading
Loading
Loading
Loading
+19 −26
Original line number Diff line number Diff line
@@ -185,8 +185,7 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
     * True if {@link #mWakeLock} is open for acquisition. It is set to false after the client is
     * unregistered.
     */
    @GuardedBy("mWakeLock")
    private boolean mIsWakelockUsable = true;
    private AtomicBoolean mIsWakelockUsable = new AtomicBoolean(true);

    /*
     * Internal interface used to invoke client callbacks.
@@ -529,7 +528,7 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
    @VisibleForTesting
    boolean isWakelockUsable() {
        synchronized (mWakeLock) {
            return mIsWakelockUsable;
            return mIsWakelockUsable.get();
        }
    }

@@ -1103,11 +1102,9 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
    private void acquireWakeLock() {
        Binder.withCleanCallingIdentity(
                () -> {
                    synchronized (mWakeLock) {
                        if (mIsWakelockUsable) {
                    if (mIsWakelockUsable.get()) {
                        mWakeLock.acquire(WAKELOCK_TIMEOUT_MILLIS);
                    }
                    }
                });
    }

@@ -1119,7 +1116,6 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
    private void releaseWakeLock() {
        Binder.withCleanCallingIdentity(
                () -> {
                    synchronized (mWakeLock) {
                    if (mWakeLock.isHeld()) {
                        try {
                            mWakeLock.release();
@@ -1127,7 +1123,6 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
                            Log.e(TAG, "Releasing the wakelock fails - ", e);
                        }
                    }
                    }
                });
    }

@@ -1139,8 +1134,7 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
    private void releaseWakeLockOnExit() {
        Binder.withCleanCallingIdentity(
                () -> {
                    synchronized (mWakeLock) {
                        mIsWakelockUsable = false;
                    mIsWakelockUsable.set(false);
                    while (mWakeLock.isHeld()) {
                        try {
                            mWakeLock.release();
@@ -1152,7 +1146,6 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
                            break;
                        }
                    }
                    }
                });
    }
}