From 951f99ba02eee6086ea82d97b536765ef90965b5 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Wed, 15 May 2019 19:19:59 -0600 Subject: [PATCH] Cache resolved details about remote callers. The logic in MediaProvider is technically correct, but it's sometimes inefficient in calling into the OS multiple times with the same questions, such as validating getCallingPackage(). To mitigate this overhead, and start paving the way for more dynamic delegation of permission checks, collect these details into a LocalCallingIdentity object. We carefully perform all permissions checking against this new object, and avoid using any other thread-local values from ContentProvider or Binder. Local tests show this CL improves performance of a test app that takes 100 rapid shots by 37%. This change is a no-op refactoring. Bug: 130758409, 115619667 Test: atest --test-mapping packages/providers/MediaProvider Change-Id: If250a7675f2246cd10881acf615619d6d6061f3d --- core/java/android/content/ContentProvider.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/java/android/content/ContentProvider.java b/core/java/android/content/ContentProvider.java index 71242fbac9a5e..7cdd2683905f2 100644 --- a/core/java/android/content/ContentProvider.java +++ b/core/java/android/content/ContentProvider.java @@ -820,6 +820,7 @@ public abstract class ContentProvider implements ContentInterface, ComponentCall private String setCallingPackage(String callingPackage) { final String original = mCallingPackage.get(); mCallingPackage.set(callingPackage); + onCallingPackageChanged(); return original; } @@ -845,6 +846,15 @@ public abstract class ContentProvider implements ContentInterface, ComponentCall return pkg; } + /** {@hide} */ + public final @Nullable String getCallingPackageUnchecked() { + return mCallingPackage.get(); + } + + /** {@hide} */ + public void onCallingPackageChanged() { + } + /** * Opaque token representing the identity of an incoming IPC. */