Merge "Don't cache suspend_control service"

This commit is contained in:
Kalesh Singh
2020-07-13 17:39:22 +00:00
committed by Gerrit Code Review

View File

@@ -152,20 +152,33 @@ 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. * On success, returns the updated stats from SystemSupend, else returns null.
*/ */
private KernelWakelockStats getWakelockStatsFromSystemSuspend( private KernelWakelockStats getWakelockStatsFromSystemSuspend(
final KernelWakelockStats staleStats) { final KernelWakelockStats staleStats) {
WakeLockInfo[] wlStats = null; WakeLockInfo[] wlStats = null;
if (mSuspendControlService == null) { try {
try { mSuspendControlService = waitForSuspendControlService();
mSuspendControlService = ISuspendControlService.Stub.asInterface( } catch (ServiceNotFoundException e) {
ServiceManager.getServiceOrThrow("suspend_control")); Slog.wtf(TAG, "Required service suspend_control not available", e);
} catch (ServiceNotFoundException e) { return null;
Slog.wtf(TAG, "Required service suspend_control not available", e);
return null;
}
} }
try { try {