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

Commit f456e872 authored by Mingguang Xu's avatar Mingguang Xu Committed by Gerrit Code Review
Browse files

Merge changes from topic "app_based_btaa"

* changes:
  BTAA: notify the App information when starting and stopping service
  BTAA: Add methods to propagate uid and package name from Java to native
  BTAA: Add app-activity aggregation dumpsys data
  BTAA: app based activity attribution
  BTAA: add FlatBuffer tables for app-activity based attribution
  BTAA: propagate app uid and package name to BTAA module
parents cc4e82be 8294cfcd
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -157,10 +157,41 @@ static void cleanupNative(JNIEnv* env, jobject object) {
  }
}

static void notifyActivityAttributionInfoNative(JNIEnv* env, jobject object,
                                                jint uid, jstring packageName,
                                                jstring deviceAddress) {
  const bt_interface_t* btInf = getBluetoothInterface();
  if (btInf == nullptr) {
    LOG(ERROR) << "Bluetooth module is not loaded";
    return;
  }
  sActivityAttributionInterface =
      (ActivityAttributionInterface*)btInf->get_profile_interface(
          BT_ACTIVITY_ATTRIBUTION_ID);
  if (sActivityAttributionInterface == nullptr) {
    LOG(ERROR) << "Failed to get ActivityAttribution Interface";
    return;
  }

  if (packageName == nullptr || deviceAddress == nullptr) {
    LOG(ERROR) << "Failed to get package name or device address";
    return;
  }
  const char* nativeName = env->GetStringUTFChars(packageName, nullptr);
  const char* nativeAddress = env->GetStringUTFChars(deviceAddress, nullptr);
  sActivityAttributionInterface->NotifyActivityAttributionInfo(uid, nativeName,
                                                               nativeAddress);
  env->ReleaseStringUTFChars(packageName, nativeName);
  env->ReleaseStringUTFChars(deviceAddress, nativeAddress);
}

static JNINativeMethod sMethods[] = {
    {"classInitNative", "()V", (void*)classInitNative},
    {"initNative", "()V", (void*)initNative},
    {"cleanupNative", "()V", (void*)cleanupNative},
    {"notifyActivityAttributionInfoNative",
     "(ILjava/lang/String;Ljava/lang/String;)V",
     (void*)notifyActivityAttributionInfoNative},
};

int register_com_android_bluetooth_btservice_activity_attribution(JNIEnv* env) {
+10 −0
Original line number Diff line number Diff line
@@ -161,6 +161,11 @@ public class A2dpService extends ProfileService {

        // Step 8: Mark service as started
        setA2dpService(this);
        BluetoothDevice activeDevice = getActiveDevice();
        String deviceAddress = activeDevice != null ?
                activeDevice.getAddress() :
                AdapterService.ACTIVITY_ATTRIBUTION_NO_ACTIVE_DEVICE_ADDRESS;
        mAdapterService.notifyActivityAttributionInfo(getAttributionSource(), deviceAddress);

        // Step 9: Clear active device
        setActiveDevice(null);
@@ -180,6 +185,11 @@ public class A2dpService extends ProfileService {
        removeActiveDevice(true);

        // Step 8: Mark service as stopped
        BluetoothDevice activeDevice = getActiveDevice();
        String deviceAddress = activeDevice != null ?
                activeDevice.getAddress() :
                AdapterService.ACTIVITY_ATTRIBUTION_NO_ACTIVE_DEVICE_ADDRESS;
        mAdapterService.notifyActivityAttributionInfo(getAttributionSource(), deviceAddress);
        setA2dpService(null);

        // Step 7: Unregister broadcast receivers
+10 −0
Original line number Diff line number Diff line
@@ -78,11 +78,21 @@ public class A2dpSinkService extends ProfileService {
        }

        setA2dpSinkService(this);
        BluetoothDevice activeDevice = getActiveDevice();
        String deviceAddress = activeDevice != null ?
                activeDevice.getAddress() :
                AdapterService.ACTIVITY_ATTRIBUTION_NO_ACTIVE_DEVICE_ADDRESS;
        mAdapterService.notifyActivityAttributionInfo(getAttributionSource(), deviceAddress);
        return true;
    }

    @Override
    protected boolean stop() {
        BluetoothDevice activeDevice = getActiveDevice();
        String deviceAddress = activeDevice != null ?
                activeDevice.getAddress() :
                AdapterService.ACTIVITY_ATTRIBUTION_NO_ACTIVE_DEVICE_ADDRESS;
        mAdapterService.notifyActivityAttributionInfo(getAttributionSource(), deviceAddress);
        setA2dpSinkService(null);
        mNativeInterface.cleanup();
        for (A2dpSinkStateMachine stateMachine : mDeviceStateMap.values()) {
+13 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import com.android.bluetooth.audio_util.MediaPlayerWrapper;
import com.android.bluetooth.audio_util.Metadata;
import com.android.bluetooth.audio_util.PlayStatus;
import com.android.bluetooth.audio_util.PlayerInfo;
import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.MetricsLogger;
import com.android.bluetooth.btservice.ProfileService;
import com.android.bluetooth.btservice.ServiceFactory;
@@ -244,6 +245,12 @@ public class AvrcpTargetService extends ProfileService {

        // Only allow the service to be used once it is initialized
        sInstance = this;
        BluetoothDevice activeDevice = getA2dpActiveDevice();
        String deviceAddress = activeDevice != null ?
                activeDevice.getAddress() :
                AdapterService.ACTIVITY_ATTRIBUTION_NO_ACTIVE_DEVICE_ADDRESS;
        AdapterService.getAdapterService().notifyActivityAttributionInfo(
                getAttributionSource(), deviceAddress);

        return true;
    }
@@ -261,6 +268,12 @@ public class AvrcpTargetService extends ProfileService {
            mAvrcpCoverArtService.stop();
        }
        mAvrcpCoverArtService = null;
        BluetoothDevice activeDevice = getA2dpActiveDevice();
        String deviceAddress = activeDevice != null ?
                activeDevice.getAddress() :
                AdapterService.ACTIVITY_ATTRIBUTION_NO_ACTIVE_DEVICE_ADDRESS;
        AdapterService.getAdapterService().notifyActivityAttributionInfo(
                getAttributionSource(), deviceAddress);

        sInstance = null;
        unregisterReceiver(mReceiver);
+14 −0
Original line number Diff line number Diff line
@@ -199,6 +199,9 @@ public class AdapterService extends Service {
            new ComponentName("com.android.bluetooth",
                    BluetoothInCallService.class.getCanonicalName());

    public static final String ACTIVITY_ATTRIBUTION_NO_ACTIVE_DEVICE_ADDRESS =
            "no_active_device_address";

    // Report ID definition
    public enum BqrQualityReportId {
        QUALITY_REPORT_ID_MONITOR_MODE(0x01),
@@ -3518,6 +3521,17 @@ public class AdapterService extends Service {
        return mAdapterProperties.getTotalNumOfTrackableAdvertisements();
    }

    /**
     * Notify the UID and package name of the app, and the address of associated active device
     *
     * @param source The attribution source that starts the activity
     * @param deviceAddress The address of the active device associated with the app
     */
    public void notifyActivityAttributionInfo(AttributionSource source, String deviceAddress) {
        mActivityAttributionService.notifyActivityAttributionInfo(
                source.getUid(), source.getPackageName(), deviceAddress);
    }

    private static int convertScanModeToHal(int mode) {
        switch (mode) {
            case BluetoothAdapter.SCAN_MODE_NONE:
Loading