Merge "Moved AttributionSource related APIs in AttributionSource" am: 70d456d06c am: 52ddc063b0 am: e5d5eefb16
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1922817 Change-Id: Id6bcfb0cca120540dd251dda22c713539c5c2b8c
This commit is contained in:
@@ -10098,6 +10098,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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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} */
|
||||||
|
|||||||
@@ -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.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -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() {
|
||||||
|
|||||||
Reference in New Issue
Block a user