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

Commit 2746db0c authored by Arthur Ishiguro's avatar Arthur Ishiguro
Browse files

Release all pending wakelocks on endpoint unregistration

Bug: 383556228
Flag: android.chre.flags.offload_implementation
Test: Confirm desired wakelock behavior through dumpsys power
Change-Id: I16c3c5055fde312a9264a16b71fc24a48900c80a
parent a696e9bb
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -248,6 +248,7 @@ public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub
            }
        }
        mEndpointManager.unregisterEndpoint(mEndpointInfo.getIdentifier().getEndpoint());
        releaseWakeLockOnExit();
    }

    @Override
@@ -559,6 +560,23 @@ public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub
                });
    }

    private void releaseWakeLockOnExit() {
        Binder.withCleanCallingIdentity(
                () -> {
                    while (mWakeLock.isHeld()) {
                        try {
                            mWakeLock.release();
                        } catch (RuntimeException e) {
                            Log.e(
                                    TAG,
                                    "Releasing the wakelock for all acquisitions fails - ",
                                    e);
                            break;
                        }
                    }
                });
    }

    /**
     * Invokes a callback and acquires a wakelock.
     *