Merge "Don't cache suspend_control service" am: 1371e73894 am: da3a84e731

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1360077

Change-Id: I18605eee1565df6476ea53990eaecf726335c6c0
This commit is contained in:
Kalesh Singh
2020-07-13 18:09:39 +00:00
committed by Automerger Merge Worker

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 {