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

Commit 1371e738 authored by Kalesh Singh's avatar Kalesh Singh Committed by Gerrit Code Review
Browse files

Merge "Don't cache suspend_control service"

parents 59d12aa8 d781ff68
Loading
Loading
Loading
Loading
+21 −8
Original line number Diff line number Diff line
@@ -152,21 +152,34 @@ public class KernelWakelockReader {
        }
    }

    /**
     * Attempt to wait for suspend_control service if not immediately available.
     */
    private ISuspendControlService waitForSuspendControlService() throws ServiceNotFoundException {
        final String name = "suspend_control";
        final int numRetries = 5;
        for (int i = 0; i < numRetries; i++) {
            mSuspendControlService = ISuspendControlService.Stub.asInterface(
                                        ServiceManager.getService(name));
            if (mSuspendControlService != null) {
                return mSuspendControlService;
            }
        }
        throw new ServiceNotFoundException(name);
    }

    /**
     * On success, returns the updated stats from SystemSupend, else returns null.
     */
    private KernelWakelockStats getWakelockStatsFromSystemSuspend(
            final KernelWakelockStats staleStats) {
        WakeLockInfo[] wlStats = null;
        if (mSuspendControlService == null) {
        try {
                mSuspendControlService = ISuspendControlService.Stub.asInterface(
                    ServiceManager.getServiceOrThrow("suspend_control"));
            mSuspendControlService = waitForSuspendControlService();
        } catch (ServiceNotFoundException e) {
            Slog.wtf(TAG, "Required service suspend_control not available", e);
            return null;
        }
        }

        try {
            wlStats = mSuspendControlService.getWakeLockStats();