Loading core/java/android/content/AttributionSource.java +24 −7 Original line number Diff line number Diff line Loading @@ -211,6 +211,11 @@ public final class AttributionSource implements Parcelable { token, mAttributionSourceState.renouncedPermissions, getNext()); } /** @hide */ public AttributionSource withDefaultToken() { return withToken(sDefaultToken); } /** @hide */ public AttributionSource withPid(int pid) { return new AttributionSource(getUid(), pid, getPackageName(), getAttributionTag(), Loading Loading @@ -520,16 +525,28 @@ public final class AttributionSource implements Parcelable { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; AttributionSource that = (AttributionSource) o; return mAttributionSourceState.uid == that.mAttributionSourceState.uid return equalsExceptToken(that) && Objects.equals( mAttributionSourceState.token, that.mAttributionSourceState.token); } /** * We store trusted attribution sources without their token (the token is the key to the map) * to avoid having a strong reference to the token. This means, when checking the equality of a * supplied AttributionSource in PermissionManagerService.isTrustedAttributionSource, we want to * compare everything except the token. * * @hide */ public boolean equalsExceptToken(@Nullable AttributionSource o) { if (o == null) return false; return mAttributionSourceState.uid == o.mAttributionSourceState.uid && Objects.equals(mAttributionSourceState.packageName, that.mAttributionSourceState.packageName) o.mAttributionSourceState.packageName) && Objects.equals(mAttributionSourceState.attributionTag, that.mAttributionSourceState.attributionTag) && Objects.equals(mAttributionSourceState.token, that.mAttributionSourceState.token) o.mAttributionSourceState.attributionTag) && Arrays.equals(mAttributionSourceState.renouncedPermissions, that.mAttributionSourceState.renouncedPermissions) && Objects.equals(getNext(), that.getNext()); o.mAttributionSourceState.renouncedPermissions) && Objects.equals(getNext(), o.getNext()); } @Override Loading services/core/java/com/android/server/pm/permission/PermissionManagerService.java +4 −2 Original line number Diff line number Diff line Loading @@ -1001,7 +1001,9 @@ public class PermissionManagerService extends IPermissionManager.Stub { } synchronized (mLock) { mAttributions.put(source.getToken(), source); // Change the token for the AttributionSource we're storing, so that we don't store // a strong reference to the original token inside the map itself. mAttributions.put(source.getToken(), source.withDefaultToken()); } } Loading @@ -1009,7 +1011,7 @@ public class PermissionManagerService extends IPermissionManager.Stub { synchronized (mLock) { final AttributionSource cachedSource = mAttributions.get(source.getToken()); if (cachedSource != null) { return cachedSource.equals(source); return cachedSource.equalsExceptToken(source); } return false; } Loading Loading
core/java/android/content/AttributionSource.java +24 −7 Original line number Diff line number Diff line Loading @@ -211,6 +211,11 @@ public final class AttributionSource implements Parcelable { token, mAttributionSourceState.renouncedPermissions, getNext()); } /** @hide */ public AttributionSource withDefaultToken() { return withToken(sDefaultToken); } /** @hide */ public AttributionSource withPid(int pid) { return new AttributionSource(getUid(), pid, getPackageName(), getAttributionTag(), Loading Loading @@ -520,16 +525,28 @@ public final class AttributionSource implements Parcelable { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; AttributionSource that = (AttributionSource) o; return mAttributionSourceState.uid == that.mAttributionSourceState.uid return equalsExceptToken(that) && Objects.equals( mAttributionSourceState.token, that.mAttributionSourceState.token); } /** * We store trusted attribution sources without their token (the token is the key to the map) * to avoid having a strong reference to the token. This means, when checking the equality of a * supplied AttributionSource in PermissionManagerService.isTrustedAttributionSource, we want to * compare everything except the token. * * @hide */ public boolean equalsExceptToken(@Nullable AttributionSource o) { if (o == null) return false; return mAttributionSourceState.uid == o.mAttributionSourceState.uid && Objects.equals(mAttributionSourceState.packageName, that.mAttributionSourceState.packageName) o.mAttributionSourceState.packageName) && Objects.equals(mAttributionSourceState.attributionTag, that.mAttributionSourceState.attributionTag) && Objects.equals(mAttributionSourceState.token, that.mAttributionSourceState.token) o.mAttributionSourceState.attributionTag) && Arrays.equals(mAttributionSourceState.renouncedPermissions, that.mAttributionSourceState.renouncedPermissions) && Objects.equals(getNext(), that.getNext()); o.mAttributionSourceState.renouncedPermissions) && Objects.equals(getNext(), o.getNext()); } @Override Loading
services/core/java/com/android/server/pm/permission/PermissionManagerService.java +4 −2 Original line number Diff line number Diff line Loading @@ -1001,7 +1001,9 @@ public class PermissionManagerService extends IPermissionManager.Stub { } synchronized (mLock) { mAttributions.put(source.getToken(), source); // Change the token for the AttributionSource we're storing, so that we don't store // a strong reference to the original token inside the map itself. mAttributions.put(source.getToken(), source.withDefaultToken()); } } Loading @@ -1009,7 +1011,7 @@ public class PermissionManagerService extends IPermissionManager.Stub { synchronized (mLock) { final AttributionSource cachedSource = mAttributions.get(source.getToken()); if (cachedSource != null) { return cachedSource.equals(source); return cachedSource.equalsExceptToken(source); } return false; } Loading