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

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

Change-Id: I83bcaf82bd7a53f97112daf043c75601c99ffa34
This commit is contained in:
Kalesh Singh
2020-07-13 17:59:41 +00:00
committed by Automerger Merge Worker

View File

@@ -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. * 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 = ISuspendControlService.Stub.asInterface( mSuspendControlService = waitForSuspendControlService();
ServiceManager.getServiceOrThrow("suspend_control"));
} catch (ServiceNotFoundException e) { } catch (ServiceNotFoundException e) {
Slog.wtf(TAG, "Required service suspend_control not available", e); Slog.wtf(TAG, "Required service suspend_control not available", e);
return null; return null;
} }
}
try { try {
wlStats = mSuspendControlService.getWakeLockStats(); wlStats = mSuspendControlService.getWakeLockStats();