diff options
| author | 2024-01-04 01:33:24 +0000 | |
|---|---|---|
| committer | 2024-01-04 01:33:24 +0000 | |
| commit | 90ad0dcfc7a3f0dd944d49fcded4b7cbc04c8011 (patch) | |
| tree | 2d77b4a9064e4acdb7b69bf522af9124192384e1 | |
| parent | 01b01af6c19bec1947690990d91535582061a357 (diff) | |
| parent | b6f3f88440f394a5168578b13683b03b55ee85ab (diff) | |
Merge "Cache StrictMode handle to IStorageManager" into main
| -rw-r--r-- | core/java/android/os/StrictMode.java | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/core/java/android/os/StrictMode.java b/core/java/android/os/StrictMode.java index e32a8f32ce95..8c8af0ead227 100644 --- a/core/java/android/os/StrictMode.java +++ b/core/java/android/os/StrictMode.java @@ -2373,13 +2373,29 @@ public final class StrictMode { /** Assume locked until we hear otherwise */ private static volatile boolean sCeStorageUnlocked = false; + /** + * Avoid (potentially) costly and repeated lookups to the same mount service. + * Note that we don't use the Singleton wrapper as lookup may fail early during boot. + */ + private static volatile IStorageManager sStorageManager; + private static boolean isCeStorageUnlocked(int userId) { - final IStorageManager storage = IStorageManager.Stub + IStorageManager storage = sStorageManager; + if (storage == null) { + storage = IStorageManager.Stub .asInterface(ServiceManager.getService("mount")); + // As the queried handle may be null early during boot, only stash valid handles, + // avoiding races with concurrent service queries. + if (storage != null) { + sStorageManager = storage; + } + } if (storage != null) { try { return storage.isCeStorageUnlocked(userId); } catch (RemoteException ignored) { + // Conservatively clear the ref, allowing refresh if the remote process restarts. + sStorageManager = null; } } return false; |