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

Commit 5f311355 authored by Kunal Malhotra's avatar Kunal Malhotra
Browse files

Adding in FGS metrics logging proto

Test: manual testing and unit testing
Change-Id: I9a6d780e2ef9a0c606ce783ad4f6346fa67c9d05
parent ab84e005
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -7786,7 +7786,10 @@ public final class ActiveServices {
                r.mIsFgsDelegate,
                r.mFgsDelegation != null ? r.mFgsDelegation.mOptions.mClientUid : INVALID_UID,
                r.mFgsDelegation != null ? r.mFgsDelegation.mOptions.mDelegationService
                        : ForegroundServiceDelegationOptions.DELEGATION_SERVICE_DEFAULT);
                        : ForegroundServiceDelegationOptions.DELEGATION_SERVICE_DEFAULT,
                0,
                null,
                null);

        int event = 0;
        if (state == FOREGROUND_SERVICE_STATE_CHANGED__STATE__ENTER) {
+53 −52
Original line number Diff line number Diff line
@@ -25,9 +25,11 @@ import static android.app.ActivityManager.FOREGROUND_SERVICE_API_TYPE_MEDIA_PLAY
import static android.app.ActivityManager.FOREGROUND_SERVICE_API_TYPE_MICROPHONE;
import static android.app.ActivityManager.FOREGROUND_SERVICE_API_TYPE_PHONE_CALL;
import static android.app.ActivityManager.FOREGROUND_SERVICE_API_TYPE_USB;
import static android.os.Process.INVALID_UID;

import android.annotation.IntDef;
import android.app.ActivityManager.ForegroundServiceApiType;
import android.app.ForegroundServiceDelegationOptions;
import android.content.ComponentName;
import android.content.pm.ServiceInfo;
import android.util.ArrayMap;
@@ -35,6 +37,7 @@ import android.util.Log;
import android.util.SparseArray;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.FrameworkStatsLog;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -430,33 +433,32 @@ public class ForegroundServiceTypeLoggerModule {
    public void logFgsApiEvent(ServiceRecord r, int fgsState,
            @FgsApiState int apiState,
            @ForegroundServiceApiType int[] apiType, long[] timestamp) {
        // TODO: Uncomment when atom changes are in
//        FrameworkStatsLog.write(FrameworkStatsLog.FOREGROUND_SERVICE_STATE_CHANGED,
//                r.appInfo.uid,
//                r.shortInstanceName,
//                fgsState, // FGS State
//                r.mAllowWhileInUsePermissionInFgs, // allowWhileInUsePermissionInFgs
//                r.mAllowStartForeground, // fgsStartReasonCode
//                r.appInfo.targetSdkVersion,
//                r.mRecentCallingUid,
//                0, // callerTargetSdkVersion
//                r.mInfoTempFgsAllowListReason != null
//                        ? r.mInfoTempFgsAllowListReason.mCallingUid : INVALID_UID,
//                r.mFgsNotificationWasDeferred,
//                r.mFgsNotificationShown,
//                0, // durationMs
//                r.mStartForegroundCount,
//                ActivityManagerUtils.hashComponentNameForAtom(r.shortInstanceName),
//                r.mFgsHasNotificationPermission,
//                r.foregroundServiceType,
//                0,
//                r.mIsFgsDelegate,
//                r.mFgsDelegation != null ? r.mFgsDelegation.mOptions.mClientUid : INVALID_UID,
//                r.mFgsDelegation != null ? r.mFgsDelegation.mOptions.mDelegationService
//                        : ForegroundServiceDelegationOptions.DELEGATION_SERVICE_DEFAULT,
//                apiState,
//                apiType,
//                timestamp);
        FrameworkStatsLog.write(FrameworkStatsLog.FOREGROUND_SERVICE_STATE_CHANGED,
                r.appInfo.uid,
                r.shortInstanceName,
                fgsState, // FGS State
                r.mAllowWhileInUsePermissionInFgs, // allowWhileInUsePermissionInFgs
                r.mAllowStartForeground, // fgsStartReasonCode
                r.appInfo.targetSdkVersion,
                r.mRecentCallingUid,
                0, // callerTargetSdkVersion
                r.mInfoTempFgsAllowListReason != null
                        ? r.mInfoTempFgsAllowListReason.mCallingUid : INVALID_UID,
                r.mFgsNotificationWasDeferred,
                r.mFgsNotificationShown,
                0, // durationMs
                r.mStartForegroundCount,
                ActivityManagerUtils.hashComponentNameForAtom(r.shortInstanceName),
                r.mFgsHasNotificationPermission,
                r.foregroundServiceType,
                0,
                r.mIsFgsDelegate,
                r.mFgsDelegation != null ? r.mFgsDelegation.mOptions.mClientUid : INVALID_UID,
                r.mFgsDelegation != null ? r.mFgsDelegation.mOptions.mDelegationService
                        : ForegroundServiceDelegationOptions.DELEGATION_SERVICE_DEFAULT,
                apiState,
                apiType,
                timestamp);
    }

    /**
@@ -467,31 +469,30 @@ public class ForegroundServiceTypeLoggerModule {
    public void logFgsApiEventWithNoFgs(int uid,
            @FgsApiState int apiState,
            @ForegroundServiceApiType int[] apiType, long[] timestamp) {
        // TODO: Uncomment when atom changes are in
//        FrameworkStatsLog.write(FrameworkStatsLog.FOREGROUND_SERVICE_STATE_CHANGED,
//                uid,
//                null,
//                FGS_STATE_CHANGED_API_CALL,
//                false, // allowWhileInUsePermissionInFgs
//                0, // fgsStartReasonCode
//                0,
//                uid,
//                0, // callerTargetSdkVersion
//                0,
//                false,
//                false,
//                0, // durationMs
//                0,
//                0,
//                false,
//                0,
//                0,
//                false,
//                0,
//                0,
//                apiState,
//                apiType,
//                timestamp);
        FrameworkStatsLog.write(FrameworkStatsLog.FOREGROUND_SERVICE_STATE_CHANGED,
                uid,
                null,
                FGS_STATE_CHANGED_API_CALL,
                false, // allowWhileInUsePermissionInFgs
                0, // fgsStartReasonCode
                0,
                uid,
                0, // callerTargetSdkVersion
                0,
                false,
                false,
                0, // durationMs
                0,
                0,
                false,
                0,
                0,
                false,
                0,
                0,
                apiState,
                apiType,
                timestamp);
    }

    /**