diff options
| author | Kalesh Singh <kaleshsingh@google.com> | 2020-07-13 18:21:59 +0000 |
|---|---|---|
| committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-07-13 18:21:59 +0000 |
| commit | afe17a7045c352e1925b2b7ea4f54f0f0efaf5b4 (patch) | |
| tree | c20e4e24bbd88d61b5b0a122646ab8cde8066918 /core/java | |
| parent | b0de7eaa80b4630d46f8ef92225fecd421b5bd65 (diff) | |
| parent | cc42fcbbc8cdc465233177feb959e2b24c60e76a (diff) | |
Merge "Don't cache suspend_control service" am: 1371e73894 am: da3a84e731 am: cc42fcbbc8
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1360077
Change-Id: I3cd64a03cc508e4894a174155e27e3137b10ee6f
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/com/android/internal/os/KernelWakelockReader.java | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/core/java/com/android/internal/os/KernelWakelockReader.java b/core/java/com/android/internal/os/KernelWakelockReader.java index cffb0ad9fdb9..3d35d2fbaa82 100644 --- a/core/java/com/android/internal/os/KernelWakelockReader.java +++ b/core/java/com/android/internal/os/KernelWakelockReader.java @@ -153,19 +153,32 @@ 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")); - } catch (ServiceNotFoundException e) { - Slog.wtf(TAG, "Required service suspend_control not available", e); - return null; - } + try { + mSuspendControlService = waitForSuspendControlService(); + } catch (ServiceNotFoundException e) { + Slog.wtf(TAG, "Required service suspend_control not available", e); + return null; } try { |
