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

Commit 44462857 authored by Kihong Seong's avatar Kihong Seong Committed by Automerger Merge Worker
Browse files

Merge "[BluetoothMetrics] Adding Counter Metrics for running in foreground"...

Merge "[BluetoothMetrics] Adding Counter Metrics for running in foreground" into main am: 0ba7a72e

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2651599



Change-Id: Iad4219ab889ce03e5a2a570dc0cdc91a50b4b934
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents b6800caa 0ba7a72e
Loading
Loading
Loading
Loading
+31 −2
Original line number Diff line number Diff line
@@ -16,12 +16,15 @@

package com.android.bluetooth.gatt;

import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND_SERVICE;

import static com.android.bluetooth.Utils.callerIsSystemOrActiveOrManagedUser;
import static com.android.bluetooth.Utils.checkCallerTargetSdk;
import static com.android.bluetooth.Utils.enforceBluetoothPrivilegedPermission;

import android.annotation.RequiresPermission;
import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.app.AppOpsManager;
import android.app.PendingIntent;
import android.app.Service;
@@ -289,6 +292,7 @@ public class GattService extends ProfileService {
    private CompanionDeviceManager mCompanionManager;
    private String mExposureNotificationPackage;
    private Handler mTestModeHandler;
    private ActivityManager mActivityManager;
    private final Object mTestModeLock = new Object();

    public GattService(Context ctx) {
@@ -365,6 +369,8 @@ public class GattService extends ProfileService {
                .createDistanceMeasurementManager(mAdapterService);
        mDistanceMeasurementManager.start();

        mActivityManager = getSystemService(ActivityManager.class);

        return true;
    }

@@ -3602,11 +3608,34 @@ public class GattService extends ProfileService {
                    + opportunistic + ", phy=" + phy);
        }
        statsLogAppPackage(address, attributionSource.getUid(), clientIf);

        boolean isForegroundService =
                mActivityManager.getUidImportance(attributionSource.getUid())
                        == IMPORTANCE_FOREGROUND_SERVICE;

        if (isDirect) {
            MetricsLogger.getInstance().count(BluetoothProtoEnums.GATT_CLIENT_CONNECT_IS_DIRECT, 1);
            MetricsLogger.getInstance()
                    .count(
                            isForegroundService
                                    ? BluetoothProtoEnums
                                            .GATT_CLIENT_CONNECT_IS_DIRECT_IN_FOREGROUND
                                    : BluetoothProtoEnums
                                            .GATT_CLIENT_CONNECT_IS_DIRECT_NOT_IN_FOREGROUND,
                            1);
        } else {
          MetricsLogger.getInstance().count(BluetoothProtoEnums.GATT_CLIENT_CONNECT_IS_AUTOCONNECT, 1);
            MetricsLogger.getInstance()
                    .count(BluetoothProtoEnums.GATT_CLIENT_CONNECT_IS_AUTOCONNECT, 1);
            MetricsLogger.getInstance()
                    .count(
                            isForegroundService
                                    ? BluetoothProtoEnums
                                            .GATT_CLIENT_CONNECT_IS_AUTOCONNECT_IN_FOREGROUND
                                    : BluetoothProtoEnums
                                            .GATT_CLIENT_CONNECT_IS_AUTOCONNECT_NOT_IN_FOREGROUND,
                            1);
        }

        statsLogGattConnectionStateChange(
                BluetoothProfile.GATT, address, clientIf,
                BluetoothProtoEnums.CONNECTION_STATE_CONNECTING, -1);