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

Commit bb17446b authored by Omair Kamil's avatar Omair Kamil
Browse files

Include attribution tag if available in dumpsys for LE clients.

Bug: 372576833
Fix: 372576833
Test: atest BluetoothInstrumentationTests
Flag: EXEMPT, dumpsys change only
Change-Id: I43329cf14da63fd1ea56b3d2c768f599e098e088
parent fb194e85
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@ import android.bluetooth.le.AdvertiseData;
import android.bluetooth.le.AdvertisingSetParameters;
import android.bluetooth.le.AdvertisingSetParameters;
import android.bluetooth.le.IAdvertisingSetCallback;
import android.bluetooth.le.IAdvertisingSetCallback;
import android.bluetooth.le.PeriodicAdvertisingParameters;
import android.bluetooth.le.PeriodicAdvertisingParameters;
import android.content.AttributionSource;
import android.os.Binder;
import android.os.Binder;
import android.os.Handler;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.HandlerThread;
@@ -246,7 +247,8 @@ public class AdvertiseManager {
            int duration,
            int duration,
            int maxExtAdvEvents,
            int maxExtAdvEvents,
            int serverIf,
            int serverIf,
            IAdvertisingSetCallback callback) {
            IAdvertisingSetCallback callback,
            AttributionSource attrSource) {
        // If we are using an isolated server, force usage of an NRPA
        // If we are using an isolated server, force usage of an NRPA
        if (serverIf != 0
        if (serverIf != 0
                && parameters.getOwnAddressType()
                && parameters.getOwnAddressType()
@@ -294,7 +296,7 @@ public class AdvertiseManager {


            Log.d(TAG, "startAdvertisingSet() - reg_id=" + cbId + ", callback: " + binder);
            Log.d(TAG, "startAdvertisingSet() - reg_id=" + cbId + ", callback: " + binder);


            mAdvertiserMap.addAppAdvertiseStats(cbId, mService);
            mAdvertiserMap.addAppAdvertiseStats(cbId, mService, attrSource);
            mAdvertiserMap.recordAdvertiseStart(
            mAdvertiserMap.recordAdvertiseStart(
                    cbId,
                    cbId,
                    parameters,
                    parameters,
+3 −2
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.bluetooth.gatt;
import android.bluetooth.le.AdvertiseData;
import android.bluetooth.le.AdvertiseData;
import android.bluetooth.le.AdvertisingSetParameters;
import android.bluetooth.le.AdvertisingSetParameters;
import android.bluetooth.le.PeriodicAdvertisingParameters;
import android.bluetooth.le.PeriodicAdvertisingParameters;
import android.content.AttributionSource;
import android.content.Context;
import android.content.Context;
import android.os.Binder;
import android.os.Binder;
import android.util.Log;
import android.util.Log;
@@ -45,7 +46,7 @@ class AdvertiserMap {
            EvictingQueue.create(ADVERTISE_STATE_MAX_SIZE);
            EvictingQueue.create(ADVERTISE_STATE_MAX_SIZE);


    /** Add an entry to the stats map if it doesn't already exist. */
    /** Add an entry to the stats map if it doesn't already exist. */
    void addAppAdvertiseStats(int id, Context context) {
    void addAppAdvertiseStats(int id, Context context, AttributionSource attrSource) {
        int appUid = Binder.getCallingUid();
        int appUid = Binder.getCallingUid();
        String appName = context.getPackageManager().getNameForUid(appUid);
        String appName = context.getPackageManager().getNameForUid(appUid);
        if (appName == null) {
        if (appName == null) {
@@ -55,7 +56,7 @@ class AdvertiserMap {


        synchronized (this) {
        synchronized (this) {
            if (!mAppAdvertiseStats.containsKey(id)) {
            if (!mAppAdvertiseStats.containsKey(id)) {
                addAppAdvertiseStats(id, new AppAdvertiseStats(appUid, id, appName));
                addAppAdvertiseStats(id, new AppAdvertiseStats(appUid, id, appName, attrSource));
            }
            }
        }
        }
    }
    }
+14 −4
Original line number Original line Diff line number Diff line
@@ -15,12 +15,16 @@
 */
 */
package com.android.bluetooth.gatt;
package com.android.bluetooth.gatt;


import static com.android.bluetooth.util.AttributionSourceUtil.getLastAttributionTag;

import android.annotation.Nullable;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProtoEnums;
import android.bluetooth.BluetoothProtoEnums;
import android.bluetooth.le.AdvertiseData;
import android.bluetooth.le.AdvertiseData;
import android.bluetooth.le.AdvertisingSetCallback;
import android.bluetooth.le.AdvertisingSetCallback;
import android.bluetooth.le.AdvertisingSetParameters;
import android.bluetooth.le.AdvertisingSetParameters;
import android.bluetooth.le.PeriodicAdvertisingParameters;
import android.bluetooth.le.PeriodicAdvertisingParameters;
import android.content.AttributionSource;
import android.os.ParcelUuid;
import android.os.ParcelUuid;
import android.util.SparseArray;
import android.util.SparseArray;


@@ -82,6 +86,7 @@ class AppAdvertiseStats {


    private int mAppUid;
    private int mAppUid;
    @VisibleForTesting String mAppName;
    @VisibleForTesting String mAppName;
    @Nullable private String mAttributionTag;
    private int mId;
    private int mId;
    private boolean mAdvertisingEnabled = false;
    private boolean mAdvertisingEnabled = false;
    private boolean mPeriodicAdvertisingEnabled = false;
    private boolean mPeriodicAdvertisingEnabled = false;
@@ -93,17 +98,18 @@ class AppAdvertiseStats {
    private boolean mAnonymous = false;
    private boolean mAnonymous = false;
    private boolean mConnectable = false;
    private boolean mConnectable = false;
    private boolean mScannable = false;
    private boolean mScannable = false;
    private AppAdvertiserData mAdvertisingData = null;
    @Nullable private AppAdvertiserData mAdvertisingData = null;
    private AppAdvertiserData mScanResponseData = null;
    @Nullable private AppAdvertiserData mScanResponseData = null;
    private AppAdvertiserData mPeriodicAdvertisingData = null;
    @Nullable private AppAdvertiserData mPeriodicAdvertisingData = null;
    private boolean mPeriodicIncludeTxPower = false;
    private boolean mPeriodicIncludeTxPower = false;
    private int mPeriodicInterval = 0;
    private int mPeriodicInterval = 0;
    public ArrayList<AppAdvertiserRecord> mAdvertiserRecords = new ArrayList<AppAdvertiserRecord>();
    public ArrayList<AppAdvertiserRecord> mAdvertiserRecords = new ArrayList<AppAdvertiserRecord>();


    AppAdvertiseStats(int appUid, int id, String name) {
    AppAdvertiseStats(int appUid, int id, String name, AttributionSource attrSource) {
        this.mAppUid = appUid;
        this.mAppUid = appUid;
        this.mId = id;
        this.mId = id;
        this.mAppName = name;
        this.mAppName = name;
        this.mAttributionTag = getLastAttributionTag(attrSource);
    }
    }


    void recordAdvertiseStart(
    void recordAdvertiseStart(
@@ -553,6 +559,10 @@ class AppAdvertiseStats {
        Instant currentTime = Instant.now();
        Instant currentTime = Instant.now();


        sb.append("\n    ").append(stats.mAppName);
        sb.append("\n    ").append(stats.mAppName);
        if (stats.mAttributionTag != null) {
            sb.append("\n     Tag                                                : ")
                    .append(stats.mAttributionTag);
        }
        sb.append("\n     Advertising ID                                     : ").append(stats.mId);
        sb.append("\n     Advertising ID                                     : ").append(stats.mId);
        for (int i = 0; i < stats.mAdvertiserRecords.size(); i++) {
        for (int i = 0; i < stats.mAdvertiserRecords.size(); i++) {
            AppAdvertiserRecord record = stats.mAdvertiserRecords.get(i);
            AppAdvertiserRecord record = stats.mAdvertiserRecords.get(i);
+11 −3
Original line number Original line Diff line number Diff line
@@ -15,6 +15,10 @@
 */
 */
package com.android.bluetooth.gatt;
package com.android.bluetooth.gatt;


import static com.android.bluetooth.util.AttributionSourceUtil.getLastAttributionTag;

import android.annotation.Nullable;
import android.content.AttributionSource;
import android.content.Context;
import android.content.Context;
import android.os.Binder;
import android.os.Binder;
import android.os.IBinder;
import android.os.IBinder;
@@ -75,6 +79,9 @@ public class ContextMap<C> {
        /** The package name of the application */
        /** The package name of the application */
        public final String name;
        public final String name;


        /** The last attribution tag of the caller */
        @Nullable public final String attributionTag;

        /** Application callbacks */
        /** Application callbacks */
        public C callback;
        public C callback;


@@ -88,11 +95,12 @@ public class ContextMap<C> {
        private List<CallbackInfo> mCongestionQueue = new ArrayList<>();
        private List<CallbackInfo> mCongestionQueue = new ArrayList<>();


        /** Creates a new app context. */
        /** Creates a new app context. */
        App(UUID uuid, C callback, int appUid, String name) {
        App(UUID uuid, C callback, int appUid, String name, AttributionSource attrSource) {
            this.uuid = uuid;
            this.uuid = uuid;
            this.callback = callback;
            this.callback = callback;
            this.appUid = appUid;
            this.appUid = appUid;
            this.name = name;
            this.name = name;
            this.attributionTag = getLastAttributionTag(attrSource);
        }
        }


        /** Link death recipient */
        /** Link death recipient */
@@ -146,7 +154,7 @@ public class ContextMap<C> {
    private final Object mConnectionsLock = new Object();
    private final Object mConnectionsLock = new Object();


    /** Add an entry to the application context list. */
    /** Add an entry to the application context list. */
    public App add(UUID uuid, C callback, Context context) {
    public App add(UUID uuid, C callback, Context context, AttributionSource attrSource) {
        int appUid = Binder.getCallingUid();
        int appUid = Binder.getCallingUid();
        String appName = context.getPackageManager().getNameForUid(appUid);
        String appName = context.getPackageManager().getNameForUid(appUid);
        if (appName == null) {
        if (appName == null) {
@@ -154,7 +162,7 @@ public class ContextMap<C> {
            appName = "Unknown App (UID: " + appUid + ")";
            appName = "Unknown App (UID: " + appUid + ")";
        }
        }
        synchronized (mAppsLock) {
        synchronized (mAppsLock) {
            App app = new App(uuid, callback, appUid, appName);
            App app = new App(uuid, callback, appUid, appName, attrSource);
            mApps.add(app);
            mApps.add(app);
            return app;
            return app;
        }
        }
+20 −5
Original line number Original line Diff line number Diff line
@@ -1943,7 +1943,8 @@ public class GattService extends ProfileService {
                duration,
                duration,
                maxExtAdvEvents,
                maxExtAdvEvents,
                serverIf,
                serverIf,
                callback);
                callback,
                attributionSource);
    }
    }


    @RequiresPermission(BLUETOOTH_ADVERTISE)
    @RequiresPermission(BLUETOOTH_ADVERTISE)
@@ -2102,7 +2103,7 @@ public class GattService extends ProfileService {
        }
        }


        Log.d(TAG, "registerClient() - UUID=" + uuid);
        Log.d(TAG, "registerClient() - UUID=" + uuid);
        mClientMap.add(uuid, callback, this);
        mClientMap.add(uuid, callback, this, attributionSource);
        mNativeInterface.gattClientRegisterApp(
        mNativeInterface.gattClientRegisterApp(
                uuid.getLeastSignificantBits(), uuid.getMostSignificantBits(), eatt_support);
                uuid.getLeastSignificantBits(), uuid.getMostSignificantBits(), eatt_support);
    }
    }
@@ -3161,7 +3162,7 @@ public class GattService extends ProfileService {
        }
        }


        Log.d(TAG, "registerServer() - UUID=" + uuid);
        Log.d(TAG, "registerServer() - UUID=" + uuid);
        mServerMap.add(uuid, callback, this);
        mServerMap.add(uuid, callback, this, attributionSource);
        mNativeInterface.gattServerRegisterApp(
        mNativeInterface.gattServerRegisterApp(
                uuid.getLeastSignificantBits(), uuid.getMostSignificantBits(), eatt_support);
                uuid.getLeastSignificantBits(), uuid.getMostSignificantBits(), eatt_support);
    }
    }
@@ -3551,11 +3552,25 @@ public class GattService extends ProfileService {
        mTransitionalScanHelper.getScannerMap().dumpApps(sb, ProfileService::println);
        mTransitionalScanHelper.getScannerMap().dumpApps(sb, ProfileService::println);
        sb.append("  Client:\n");
        sb.append("  Client:\n");
        for (Integer appId : mClientMap.getAllAppsIds()) {
        for (Integer appId : mClientMap.getAllAppsIds()) {
            println(sb, "    app_if: " + appId + ", appName: " + mClientMap.getById(appId).name);
            ContextMap.App app = mClientMap.getById(appId);
            println(
                    sb,
                    "    app_if: "
                            + appId
                            + ", appName: "
                            + app.name
                            + (app.attributionTag == null ? "" : ", tag: " + app.attributionTag));
        }
        }
        sb.append("  Server:\n");
        sb.append("  Server:\n");
        for (Integer appId : mServerMap.getAllAppsIds()) {
        for (Integer appId : mServerMap.getAllAppsIds()) {
            println(sb, "    app_if: " + appId + ", appName: " + mServerMap.getById(appId).name);
            ContextMap.App app = mServerMap.getById(appId);
            println(
                    sb,
                    "    app_if: "
                            + appId
                            + ", appName: "
                            + app.name
                            + (app.attributionTag == null ? "" : ", tag: " + app.attributionTag));
        }
        }
        sb.append("\n\n");
        sb.append("\n\n");
    }
    }
Loading