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

Commit 70d456d0 authored by Etienne Ruffieux's avatar Etienne Ruffieux Committed by Gerrit Code Review
Browse files

Merge "Moved AttributionSource related APIs in AttributionSource"

parents d089108e 770d50ed
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -10091,6 +10091,7 @@ package android.content {
    method @Nullable public String getPackageName();
    method @Nullable public String getPackageName();
    method public int getUid();
    method public int getUid();
    method public boolean isTrusted(@NonNull android.content.Context);
    method public boolean isTrusted(@NonNull android.content.Context);
    method @NonNull public static android.content.AttributionSource myAttributionSource();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.content.AttributionSource> CREATOR;
    field @NonNull public static final android.os.Parcelable.Creator<android.content.AttributionSource> CREATOR;
  }
  }
+1 −1
Original line number Original line Diff line number Diff line
@@ -786,7 +786,7 @@ public final class BluetoothAdapter {
    @RequiresNoPermission
    @RequiresNoPermission
    public static synchronized BluetoothAdapter getDefaultAdapter() {
    public static synchronized BluetoothAdapter getDefaultAdapter() {
        if (sAdapter == null) {
        if (sAdapter == null) {
            sAdapter = createAdapter(BluetoothManager.resolveAttributionSource(null));
            sAdapter = createAdapter(AttributionSource.myAttributionSource());
        }
        }
        return sAdapter;
        return sAdapter;
    }
    }
+1 −1
Original line number Original line Diff line number Diff line
@@ -1177,7 +1177,7 @@ public final class BluetoothDevice implements Parcelable, Attributable {


        mAddress = address;
        mAddress = address;
        mAddressType = ADDRESS_TYPE_PUBLIC;
        mAddressType = ADDRESS_TYPE_PUBLIC;
        mAttributionSource = BluetoothManager.resolveAttributionSource(null);
        mAttributionSource = AttributionSource.myAttributionSource();
    }
    }


    /** {@hide} */
    /** {@hide} */
+2 −32
Original line number Original line Diff line number Diff line
@@ -16,14 +16,10 @@


package android.bluetooth;
package android.bluetooth;


import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresFeature;
import android.annotation.RequiresFeature;
import android.annotation.RequiresNoPermission;
import android.annotation.RequiresNoPermission;
import android.annotation.RequiresPermission;
import android.annotation.RequiresPermission;
import android.annotation.SystemService;
import android.annotation.SystemService;
import android.app.ActivityThread;
import android.app.AppGlobals;
import android.bluetooth.annotations.RequiresBluetoothConnectPermission;
import android.bluetooth.annotations.RequiresBluetoothConnectPermission;
import android.bluetooth.annotations.RequiresLegacyBluetoothPermission;
import android.bluetooth.annotations.RequiresLegacyBluetoothPermission;
import android.content.AttributionSource;
import android.content.AttributionSource;
@@ -68,37 +64,11 @@ public final class BluetoothManager {
     * @hide
     * @hide
     */
     */
    public BluetoothManager(Context context) {
    public BluetoothManager(Context context) {
        mAttributionSource = resolveAttributionSource(context);
        mAttributionSource = (context != null) ? context.getAttributionSource() :
                AttributionSource.myAttributionSource();
        mAdapter = BluetoothAdapter.createAdapter(mAttributionSource);
        mAdapter = BluetoothAdapter.createAdapter(mAttributionSource);
    }
    }


    /** {@hide} */
    public static @NonNull AttributionSource resolveAttributionSource(@Nullable Context context) {
        AttributionSource res = null;
        if (context != null) {
            res = context.getAttributionSource();
        }
        if (res == null) {
            res = ActivityThread.currentAttributionSource();
        }
        if (res == null) {
            int uid = android.os.Process.myUid();
            if (uid == android.os.Process.ROOT_UID) {
                uid = android.os.Process.SYSTEM_UID;
            }
            try {
                res = new AttributionSource.Builder(uid)
                    .setPackageName(AppGlobals.getPackageManager().getPackagesForUid(uid)[0])
                    .build();
            } catch (RemoteException ignored) {
            }
        }
        if (res == null) {
            throw new IllegalStateException("Failed to resolve AttributionSource");
        }
        return res;
    }

    /**
    /**
     * Get the BLUETOOTH Adapter for this device.
     * Get the BLUETOOTH Adapter for this device.
     *
     *
+38 −5
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.annotation.TestApi;
import android.app.ActivityThread;
import android.app.ActivityThread;
import android.app.AppGlobals;
import android.os.Binder;
import android.os.Binder;
import android.os.Build;
import android.os.Build;
import android.os.IBinder;
import android.os.IBinder;
@@ -191,10 +192,42 @@ public final class AttributionSource implements Parcelable {
        return new ScopedParcelState(this);
        return new ScopedParcelState(this);
    }
    }


    /** @hide */
    /**
    public static AttributionSource myAttributionSource() {
     * Returns a generic {@link AttributionSource} that represents the entire
        return new AttributionSource(Process.myUid(), ActivityThread.currentOpPackageName(),
     * calling process.
                /*attributionTag*/ null, (String[]) /*renouncedPermissions*/ null, /*next*/ null);
     *
     * <p>Callers are <em>strongly</em> encouraged to use a more specific
     * attribution source whenever possible, such as from
     * {@link Context#getAttributionSource()}, since that enables developers to
     * have more detailed and scoped control over attribution within
     * sub-components of their app.
     *
     * @see Context#createAttributionContext(String)
     * @see Context#getAttributionTag()
     * @return a generic {@link AttributionSource} representing the entire
     *         calling process
     * @throws IllegalStateException when no accurate {@link AttributionSource}
     *         can be determined
     */
    public static @NonNull AttributionSource myAttributionSource() {

        final AttributionSource globalSource = ActivityThread.currentAttributionSource();
        if (globalSource != null) {
            return globalSource;
        }

        int uid = Process.myUid();
        if (uid == Process.ROOT_UID) {
            uid = Process.SYSTEM_UID;
        }
        try {
            return new AttributionSource.Builder(uid)
                .setPackageName(AppGlobals.getPackageManager().getPackagesForUid(uid)[0])
                .build();
        } catch (Exception ignored) {
        }

        throw new IllegalStateException("Failed to resolve AttributionSource");
    }
    }


    /**
    /**
@@ -247,7 +280,7 @@ public final class AttributionSource implements Parcelable {
     * whether the attribution source is one for the calling app to prevent the caller
     * whether the attribution source is one for the calling app to prevent the caller
     * to pass you a source from another app without including themselves in the
     * to pass you a source from another app without including themselves in the
     * attribution chain.
     * attribution chain.
     *f
     *
     * @return if the attribution source cannot be trusted to be from the caller.
     * @return if the attribution source cannot be trusted to be from the caller.
     */
     */
    public boolean checkCallingUid() {
    public boolean checkCallingUid() {