summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Nate Myren <ntmyren@google.com> 2024-05-21 10:41:39 -0700
committer Nate Myren <ntmyren@google.com> 2024-05-21 13:32:34 -0700
commit02f4520f2933e2d54e99a178e61619fa1b3d7439 (patch)
tree53d6e9b5f6945586ba8ac9a06c9d10bc4f9501a5
parentaf9c0cfd2f6560c42aeae00a7ddfdf980ea4de66 (diff)
Keep the deviceId in AttributionSource in sync with Context
Also re-registers the AttributionSource if needed Change-Id: I81bbba6a041cc87aef77cfa1f21c1016b35a10a2 Fix: 333272850 Test: presubmit
-rw-r--r--core/java/android/app/ContextImpl.java23
1 files changed, 20 insertions, 3 deletions
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java
index e3380e0bf12a..3b9a5d3b2cf2 100644
--- a/core/java/android/app/ContextImpl.java
+++ b/core/java/android/app/ContextImpl.java
@@ -19,6 +19,7 @@ package android.app;
import static android.content.pm.PackageManager.PERMISSION_DENIED;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.os.StrictMode.vmIncorrectContextUseEnabled;
+import static android.permission.flags.Flags.shouldRegisterAttributionSource;
import static android.view.WindowManager.LayoutParams.WindowType;
import android.Manifest;
@@ -3157,7 +3158,8 @@ class ContextImpl extends Context {
int deviceId = vdm.getDeviceIdForDisplayId(displayId);
if (deviceId != mDeviceId) {
mDeviceId = deviceId;
- mAttributionSource = mAttributionSource.withDeviceId(mDeviceId);
+ mAttributionSource =
+ createAttributionSourceWithDeviceId(mAttributionSource, mDeviceId);
notifyOnDeviceChangedListeners(mDeviceId);
}
}
@@ -3180,6 +3182,7 @@ class ContextImpl extends Context {
if (mDeviceId != updatedDeviceId) {
mDeviceId = updatedDeviceId;
+ mAttributionSource = createAttributionSourceWithDeviceId(mAttributionSource, mDeviceId);
notifyOnDeviceChangedListeners(updatedDeviceId);
}
}
@@ -3548,8 +3551,22 @@ class ContextImpl extends Context {
deviceId, nextAttributionSource);
// If we want to access protected data on behalf of another app we need to
// tell the OS that we opt in to participate in the attribution chain.
- if (nextAttributionSource != null || shouldRegister) {
- attributionSource = getSystemService(PermissionManager.class)
+ return registerAttributionSourceIfNeeded(attributionSource, shouldRegister);
+ }
+
+ private @NonNull AttributionSource createAttributionSourceWithDeviceId(
+ @NonNull AttributionSource oldSource, int deviceId) {
+ boolean shouldRegister = false;
+ if (shouldRegisterAttributionSource()) {
+ shouldRegister = mParams.shouldRegisterAttributionSource();
+ }
+ return registerAttributionSourceIfNeeded(oldSource.withDeviceId(deviceId), shouldRegister);
+ }
+
+ private @NonNull AttributionSource registerAttributionSourceIfNeeded(
+ @NonNull AttributionSource attributionSource, boolean shouldRegister) {
+ if (shouldRegister || attributionSource.getNext() != null) {
+ return getSystemService(PermissionManager.class)
.registerAttributionSource(attributionSource);
}
return attributionSource;