From 4815ed4500ac5480a6843a8cd7a6a3518ffddf4a Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Thu, 26 May 2016 09:31:04 -0600 Subject: [PATCH] Cache IMountService for isUserKeyUnlocked() calls. This avoids doing a ServiceManager lookup for every call through this hot code-path. Bug: 28946245 Change-Id: I210ce34b33e5b40a5ab4e92ddce87fc5e9964be2 --- core/java/android/os/storage/StorageManager.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/core/java/android/os/storage/StorageManager.java b/core/java/android/os/storage/StorageManager.java index fbf7b266330b5..485bbd105603b 100644 --- a/core/java/android/os/storage/StorageManager.java +++ b/core/java/android/os/storage/StorageManager.java @@ -114,6 +114,8 @@ public class StorageManager { /** {@hide} */ public static final int FLAG_INCLUDE_INVISIBLE = 1 << 10; + private static volatile IMountService sMountService = null; + private final Context mContext; private final ContentResolver mResolver; @@ -1064,15 +1066,17 @@ public class StorageManager { /** {@hide} */ public static boolean isUserKeyUnlocked(int userId) { - final IMountService mount = IMountService.Stub - .asInterface(ServiceManager.getService("mount")); - if (mount == null) { + if (sMountService == null) { + sMountService = IMountService.Stub + .asInterface(ServiceManager.getService("mount")); + } + if (sMountService == null) { Slog.w(TAG, "Early during boot, assuming locked"); return false; } final long token = Binder.clearCallingIdentity(); try { - return mount.isUserKeyUnlocked(userId); + return sMountService.isUserKeyUnlocked(userId); } catch (RemoteException e) { throw e.rethrowAsRuntimeException(); } finally {