diff options
| author | Svet Ganov <svetoslavganov@google.com> | 2021-07-09 22:07:12 +0000 |
|---|---|---|
| committer | Svet Ganov <svetoslavganov@google.com> | 2021-07-10 00:24:30 +0000 |
| commit | 1babd5bf516be8ffbd649a59dc136a9cdac24ba4 (patch) | |
| tree | d63bc9ab793397739457fc407b217eece1a33642 /core/java/android/content/AttributionSource.java | |
| parent | dc7452c45f9897aaca34dd09a52d1ffd4e4be7af (diff) | |
Optimize AttributionSource tokens - base
For cases where the attribution soruce doesn't need to be
registered as trusted we are now using a shares static
token since the only purpose of the token in these cases
is for watching the source process dying as opposed to that
and security for registered cases.
bug: 192415943
Test: CtsPermissionTestCases
CtsPermission2TestCases
CtsPermission3TestCases
CtsPermission4TestCases
CtsPermission5TestCases
Change-Id: I93fde9ca1cacada7929761533dcae11b2736ce1e
Diffstat (limited to 'core/java/android/content/AttributionSource.java')
| -rw-r--r-- | core/java/android/content/AttributionSource.java | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/core/java/android/content/AttributionSource.java b/core/java/android/content/AttributionSource.java index c499f691b69a..d63ce0f4a943 100644 --- a/core/java/android/content/AttributionSource.java +++ b/core/java/android/content/AttributionSource.java @@ -88,6 +88,8 @@ import java.util.Set; public final class AttributionSource implements Parcelable { private static final String DESCRIPTOR = "android.content.AttributionSource"; + private static final Binder sDefaultToken = new Binder(DESCRIPTOR); + private final @NonNull AttributionSourceState mAttributionSourceState; private @Nullable AttributionSource mNextCached; @@ -97,7 +99,7 @@ public final class AttributionSource implements Parcelable { @TestApi public AttributionSource(int uid, @Nullable String packageName, @Nullable String attributionTag) { - this(uid, packageName, attributionTag, new Binder(DESCRIPTOR)); + this(uid, packageName, attributionTag, sDefaultToken); } /** @hide */ @@ -132,7 +134,7 @@ public final class AttributionSource implements Parcelable { AttributionSource(int uid, @Nullable String packageName, @Nullable String attributionTag, @Nullable String[] renouncedPermissions, @Nullable AttributionSource next) { - this(uid, packageName, attributionTag, new Binder(DESCRIPTOR), renouncedPermissions, next); + this(uid, packageName, attributionTag, sDefaultToken, renouncedPermissions, next); } AttributionSource(int uid, @Nullable String packageName, @Nullable String attributionTag, @@ -170,6 +172,12 @@ public final class AttributionSource implements Parcelable { } /** @hide */ + public AttributionSource withToken(@NonNull Binder token) { + return new AttributionSource(getUid(), getPackageName(), getAttributionTag(), + token, mAttributionSourceState.renouncedPermissions, getNext()); + } + + /** @hide */ public @NonNull AttributionSourceState asState() { return mAttributionSourceState; } @@ -543,7 +551,9 @@ public final class AttributionSource implements Parcelable { if ((mBuilderFieldsSet & 0x10) == 0) { mAttributionSourceState.next = null; } - mAttributionSourceState.token = new Binder(DESCRIPTOR); + + mAttributionSourceState.token = sDefaultToken; + if (mAttributionSourceState.next == null) { // The NDK aidl backend doesn't support null parcelable arrays. mAttributionSourceState.next = new AttributionSourceState[0]; |
