Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5d4eee6c authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add shouldRegisterAttributionSource to ContextParams" into main

parents 56f66a27 f2e0678f
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -10560,6 +10560,7 @@ package android.content {
  public final class ContextParams {
    method @Nullable public String getAttributionTag();
    method @Nullable public android.content.AttributionSource getNextAttributionSource();
    method @NonNull public boolean shouldRegisterAttributionSource();
  }
  public static final class ContextParams.Builder {
@@ -10568,6 +10569,7 @@ package android.content {
    method @NonNull public android.content.ContextParams build();
    method @NonNull public android.content.ContextParams.Builder setAttributionTag(@Nullable String);
    method @NonNull public android.content.ContextParams.Builder setNextAttributionSource(@Nullable android.content.AttributionSource);
    method @NonNull public android.content.ContextParams.Builder setShouldRegisterAttributionSource(boolean);
  }
  public class ContextWrapper extends android.content.Context {
+3 −3
Original line number Diff line number Diff line
@@ -3455,20 +3455,20 @@ class ContextImpl extends Context {
        mOpPackageName = overrideOpPackageName != null ? overrideOpPackageName : opPackageName;
        mParams = Objects.requireNonNull(params);
        mAttributionSource = createAttributionSource(attributionTag, nextAttributionSource,
                params.getRenouncedPermissions());
                params.getRenouncedPermissions(), params.shouldRegisterAttributionSource());
        mContentResolver = new ApplicationContentResolver(this, mainThread);
    }

    private @NonNull AttributionSource createAttributionSource(@Nullable String attributionTag,
            @Nullable AttributionSource nextAttributionSource,
            @Nullable Set<String> renouncedPermissions) {
            @Nullable Set<String> renouncedPermissions, boolean shouldRegister) {
        AttributionSource attributionSource = new AttributionSource(Process.myUid(),
                Process.myPid(), mOpPackageName, attributionTag,
                (renouncedPermissions != null) ? renouncedPermissions.toArray(new String[0]) : null,
                getDeviceId(), 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) {
        if (nextAttributionSource != null || shouldRegister) {
            attributionSource = getSystemService(PermissionManager.class)
                    .registerAttributionSource(attributionSource);
        }
+28 −2
Original line number Diff line number Diff line
@@ -50,17 +50,20 @@ public final class ContextParams {
    private final @Nullable String mAttributionTag;
    private final @Nullable AttributionSource mNext;
    private final @NonNull Set<String> mRenouncedPermissions;
    private final boolean mShouldRegisterAttributionSource;

    /** {@hide} */
    public static final ContextParams EMPTY = new ContextParams.Builder().build();

    private ContextParams(@Nullable String attributionTag,
            @Nullable AttributionSource next,
            @Nullable Set<String> renouncedPermissions) {
            @Nullable Set<String> renouncedPermissions,
            boolean shouldRegister) {
        mAttributionTag = attributionTag;
        mNext = next;
        mRenouncedPermissions = (renouncedPermissions != null)
                ? renouncedPermissions : Collections.emptySet();
        mShouldRegisterAttributionSource = shouldRegister;
    }

    /**
@@ -94,6 +97,15 @@ public final class ContextParams {
        return mNext;
    }

    /**
     * @return Whether the attribution source associated with the Context being created should be
     * registered.
     */
    @NonNull
    public boolean shouldRegisterAttributionSource() {
        return mShouldRegisterAttributionSource;
    }

    /**
     * Builder for creating a {@link ContextParams}.
     */
@@ -101,6 +113,7 @@ public final class ContextParams {
        private @Nullable String mAttributionTag;
        private @NonNull Set<String> mRenouncedPermissions = Collections.emptySet();
        private @Nullable AttributionSource mNext;
        private boolean mShouldRegisterAttributionSource;

        /**
         * Create a new builder.
@@ -158,6 +171,19 @@ public final class ContextParams {
            return this;
        }

        /**
         * Sets whether the attribution source associated with the context created from these params
         * should be registered.
         *
         * @param shouldRegister Whether the attribution source associated with the Context being
         *                       created should be registered.
         */
        @NonNull
        public Builder setShouldRegisterAttributionSource(boolean shouldRegister) {
            mShouldRegisterAttributionSource = shouldRegister;
            return this;
        }

        /**
         * Sets permissions which have been voluntarily "renounced" by the
         * calling app.
@@ -205,7 +231,7 @@ public final class ContextParams {
        @NonNull
        public ContextParams build() {
            return new ContextParams(mAttributionTag, mNext,
                    mRenouncedPermissions);
                    mRenouncedPermissions, mShouldRegisterAttributionSource);
        }
    }
}