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

Commit 5c183921 authored by Aditya Chitnis's avatar Aditya Chitnis Committed by Android (Google) Code Review
Browse files

Merge "Simplify mWakeLock logic in ContextHubClientBroker" into main

parents 835a50f1 b98dad62
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;
                        }
                    }
                    }
                });
    }
}