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

Commit 94ab0f70 authored by Hui Wang's avatar Hui Wang
Browse files

Add logs for Telecom metrics stage 2

Flag: com.android.server.telecom.flags.telecom_metrics_support
Bug: 397554282
Test: atest TeleServiceTests
Test: manual
Change-Id: I47300ddf9205ee2f8812b840445402d4093e176a
parent 4bad2c65
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -14,6 +14,8 @@ message PulledAtoms {
  optional int64 telecom_api_stats_pull_timestamp_millis = 6;
  repeated TelecomErrorStats telecom_error_stats = 7;
  optional int64 telecom_error_stats_pull_timestamp_millis = 8;
  repeated TelecomEventStats telecom_event_stats = 9;
  optional int64 telecom_event_stats_pull_timestamp_millis = 10;
}

/**
@@ -48,6 +50,15 @@ message CallStats {

    // Average elapsed time between CALL_STATE_ACTIVE to CALL_STATE_DISCONNECTED.
    optional int32 average_duration_ms = 8;

    // The disconnect cause of the call. Eg. ERROR, LOCAL, REMOTE, etc.
    // From frameworks/proto_logging/stats/enums/telecomm/enums.proto
    optional int32 disconnect_cause = 9;

    // The type of simultaneous call type. Eg. SINGLE, DUAL_SAME_ACCOUNT,
    // DUAL_DIFF_ACCOUNT, etc.
    // From frameworks/proto_logging/stats/enums/telecomm/enums.proto
    optional int32 simultaneous_type = 10;
}

/**
@@ -112,3 +123,22 @@ message TelecomErrorStats {
    // The number of times this error occurs
    optional int32 count = 3;
}

/**
 * Pulled atom to capture stats of Telecom critical events
 */
message TelecomEventStats {
    // The event name
    // From frameworks/proto_logging/stats/enums/telecomm/enums.proto
    optional int32 event = 1;

    // UID of the caller. This is always -1/unknown for the private space.
    optional int32 uid = 2;

    // The cause related to the event
    // From frameworks/proto_logging/stats/enums/telecomm/enums.proto
    optional int32 event_cause = 3;

    // The number of times this event occurs
    optional int32 count = 4;
}
+17 −0
Original line number Diff line number Diff line
@@ -131,6 +131,10 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,

    private static final char NO_DTMF_TONE = '\0';

    public static final int CALL_SIMULTANEOUS_UNKNOWN = 0;
    public static final int CALL_SIMULTANEOUS_SINGLE = 1;
    public static final int CALL_DIRECTION_DUAL_SAME_ACCOUNT = 2;
    public static final int CALL_DIRECTION_DUAL_DIFF_ACCOUNT = 3;

    /**
     * Listener for CallState changes which can be leveraged by a Transaction.
@@ -501,6 +505,11 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
     */
    private DisconnectCause mOverrideDisconnectCause = new DisconnectCause(DisconnectCause.UNKNOWN);

    /**
     * Simultaneous type of the call.
     */
    private int mSimultaneousType = CALL_SIMULTANEOUS_UNKNOWN;

    private Bundle mIntentExtras = new Bundle();

    /**
@@ -5064,4 +5073,12 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
            }
        }
    }

    public void setSimultaneousType(int simultaneousType) {
        mSimultaneousType = simultaneousType;
    }

    public int getSimultaneousType() {
        return mSimultaneousType;
    }
}
+17 −3
Original line number Diff line number Diff line
@@ -84,6 +84,8 @@ import com.android.server.telecom.callsequencing.voip.VoipCallMonitor;
import com.android.server.telecom.components.UserCallIntentProcessorFactory;
import com.android.server.telecom.flags.FeatureFlags;
import com.android.server.telecom.metrics.ApiStats;
import com.android.server.telecom.metrics.EventStats;
import com.android.server.telecom.metrics.EventStats.CriticalEvent;
import com.android.server.telecom.metrics.TelecomMetricsController;
import com.android.server.telecom.settings.BlockedNumbersActivity;
import com.android.server.telecom.callsequencing.TransactionManager;
@@ -195,8 +197,9 @@ public class TelecomServiceImpl {
        @Override
        public void addCall(CallAttributes callAttributes, ICallEventCallback callEventCallback,
                String callId, String callingPackage) {
            int uid = Binder.getCallingUid();
            ApiStats.ApiEvent event = new ApiStats.ApiEvent(ApiStats.API_ADDCALL,
                    Binder.getCallingUid(), ApiStats.RESULT_PERMISSION);
                    uid, ApiStats.RESULT_PERMISSION);
            try {
                Log.startSession("TSI.aC", Log.getPackageAbbreviation(callingPackage));
                Log.i(TAG, "addCall: id=[%s], attributes=[%s]", callId, callAttributes);
@@ -213,8 +216,8 @@ public class TelecomServiceImpl {

                // add extras about info used for FGS delegation
                Bundle extras = new Bundle();
                extras.putInt(CallAttributes.CALLER_UID_KEY, Binder.getCallingUid());
                extras.putInt(CallAttributes.CALLER_PID_KEY, Binder.getCallingPid());
                extras.putInt(CallAttributes.CALLER_UID_KEY, uid);
                extras.putInt(CallAttributes.CALLER_PID_KEY, uid);


                CompletableFuture<CallTransaction> transactionFuture;
@@ -233,6 +236,11 @@ public class TelecomServiceImpl {
                            public void onResult(CallTransactionResult result) {
                                Log.d(TAG, "addCall: onResult");
                                Call call = result.getCall();
                                if (mFeatureFlags.telecomMetricsSupport()) {
                                    mMetricsController.getEventStats().log(new CriticalEvent(
                                            EventStats.ID_ADD_CALL, uid,
                                            EventStats.CAUSE_CALL_TRANSACTION_SUCCESS));
                                }

                                if (call == null || !call.getId().equals(callId)) {
                                    Log.i(TAG, "addCall: onResult: call is null or id mismatch");
@@ -278,6 +286,12 @@ public class TelecomServiceImpl {
                                            ADD_CALL_ON_ERROR_UUID,
                                            exception.getMessage());
                                }
                                if (mFeatureFlags.telecomMetricsSupport()) {
                                    mMetricsController.getEventStats().log(new CriticalEvent(
                                            EventStats.ID_ADD_CALL, uid,
                                            EventStats.CAUSE_CALL_TRANSACTION_BASE
                                                    + exception.getCode()));
                                }
                            }
                        });
                    }
+1 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import com.android.server.telecom.callfiltering.IncomingCallFilterGraph;
import com.android.server.telecom.components.UserCallIntentProcessor;
import com.android.server.telecom.components.UserCallIntentProcessorFactory;
import com.android.server.telecom.flags.FeatureFlags;
import com.android.server.telecom.metrics.EventStats;
import com.android.server.telecom.metrics.TelecomMetricsController;
import com.android.server.telecom.ui.AudioProcessingNotification;
import com.android.server.telecom.ui.CallStreamingNotification;
+36 −12
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import com.android.server.telecom.Call;
import com.android.server.telecom.TelecomStatsLog;
import com.android.server.telecom.nano.PulledAtomsClass;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
@@ -82,7 +83,8 @@ public class CallStats extends TelecomPulledAtom {
                    TelecomStatsLog.buildStatsEvent(getTag(),
                            v.getCallDirection(), v.getExternalCall(), v.getEmergencyCall(),
                            v.getMultipleAudioAvailable(), v.getAccountType(), v.getUid(),
                            v.getCount(), v.getAverageDurationMs())));
                            v.getCount(), v.getAverageDurationMs(), v.getDisconnectCause(),
                            v.getSimultaneousType())));
            mCallStatsMap.clear();
            onAggregate();
            return StatsManager.PULL_SUCCESS;
@@ -98,9 +100,10 @@ public class CallStats extends TelecomPulledAtom {
            for (PulledAtomsClass.CallStats v : mPulledAtoms.callStats) {
                mCallStatsMap.put(new CallStatsKey(v.getCallDirection(),
                        v.getExternalCall(), v.getEmergencyCall(),
                                v.getMultipleAudioAvailable(),
                                v.getAccountType(), v.getUid()),
                        new CallStatsData(v.getCount(), v.getAverageDurationMs()));
                        v.getMultipleAudioAvailable(), v.getAccountType(),
                        v.getUid(), v.getDisconnectCause(), v.getSimultaneousType()),
                        new CallStatsData(
                                v.getCount(), v.getAverageDurationMs()));
            }
            mLastPulledTimestamps = mPulledAtoms.getCallStatsPullTimestampMillis();
        }
@@ -125,6 +128,8 @@ public class CallStats extends TelecomPulledAtom {
            mPulledAtoms.callStats[index[0]].setMultipleAudioAvailable(k.mIsMultipleAudioAvailable);
            mPulledAtoms.callStats[index[0]].setAccountType(k.mAccountType);
            mPulledAtoms.callStats[index[0]].setUid(k.mUid);
            mPulledAtoms.callStats[index[0]].setDisconnectCause(k.mCause);
            mPulledAtoms.callStats[index[0]].setSimultaneousType(k.mSimultaneousType);
            mPulledAtoms.callStats[index[0]].setCount(v.mCount);
            mPulledAtoms.callStats[index[0]].setAverageDurationMs(v.mAverageDuration);
            index[0]++;
@@ -134,9 +139,15 @@ public class CallStats extends TelecomPulledAtom {

    public void log(int direction, boolean isExternal, boolean isEmergency,
        boolean isMultipleAudioAvailable, int accountType, int uid, int duration) {
        log(direction, isExternal, isEmergency, isMultipleAudioAvailable, accountType, uid,
                0, 0, duration);
    }
    public void log(int direction, boolean isExternal, boolean isEmergency,
            boolean isMultipleAudioAvailable, int accountType, int uid,
            int disconnectCause, int simultaneousType, int duration) {
        post(() -> {
            CallStatsKey key = new CallStatsKey(direction, isExternal, isEmergency,
                    isMultipleAudioAvailable, accountType, uid);
                    isMultipleAudioAvailable, accountType, uid, disconnectCause, simultaneousType);
            CallStatsData data = mCallStatsMap.computeIfAbsent(key, k -> new CallStatsData(0, 0));
            data.add(duration);
            onAggregate();
@@ -171,7 +182,8 @@ public class CallStats extends TelecomPulledAtom {
            }

            log(direction, call.isExternalCall(), call.isEmergencyCall(), hasMultipleAudioDevices,
                    accountType, uid, duration);
                    accountType, uid, call.getDisconnectCause().getCode(),
                    call.getSimultaneousType(), duration);
        });
    }

@@ -236,15 +248,26 @@ public class CallStats extends TelecomPulledAtom {
        final boolean mIsMultipleAudioAvailable;
        final int mAccountType;
        final int mUid;
        final int mCause;
        final int mSimultaneousType;

        CallStatsKey(int direction, boolean isExternal, boolean isEmergency,
            boolean isMultipleAudioAvailable, int accountType, int uid) {
            this(direction, isExternal, isEmergency, isMultipleAudioAvailable, accountType, uid,
                    0, 0);
        }

        CallStatsKey(int direction, boolean isExternal, boolean isEmergency,
                boolean isMultipleAudioAvailable, int accountType, int uid,
                int cause, int simultaneousType) {
            mDirection = direction;
            mIsExternal = isExternal;
            mIsEmergency = isEmergency;
            mIsMultipleAudioAvailable = isMultipleAudioAvailable;
            mAccountType = accountType;
            mUid = uid;
            mCause = cause;
            mSimultaneousType = simultaneousType;
        }

        @Override
@@ -258,13 +281,14 @@ public class CallStats extends TelecomPulledAtom {
            return this.mDirection == obj.mDirection && this.mIsExternal == obj.mIsExternal
                    && this.mIsEmergency == obj.mIsEmergency
                    && this.mIsMultipleAudioAvailable == obj.mIsMultipleAudioAvailable
                    && this.mAccountType == obj.mAccountType && this.mUid == obj.mUid;
                    && this.mAccountType == obj.mAccountType && this.mUid == obj.mUid
                    && this.mCause == obj.mCause && this.mSimultaneousType == obj.mSimultaneousType;
        }

        @Override
        public int hashCode() {
            return Objects.hash(mDirection, mIsExternal, mIsEmergency, mIsMultipleAudioAvailable,
                    mAccountType, mUid);
                    mAccountType, mUid, mCause, mSimultaneousType);
        }

        @Override
@@ -272,7 +296,7 @@ public class CallStats extends TelecomPulledAtom {
            return "[CallStatsKey: mDirection=" + mDirection + ", mIsExternal=" + mIsExternal
                    + ", mIsEmergency=" + mIsEmergency + ", mIsMultipleAudioAvailable="
                    + mIsMultipleAudioAvailable + ", mAccountType=" + mAccountType + ", mUid="
                    + mUid + "]";
                    + mUid + ", mCause=" + mCause + ", mScType=" + mSimultaneousType + "]";
        }
    }

Loading