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

Commit ccf14643 authored by hyosun's avatar hyosun Committed by Hyunho
Browse files

Add RCS metrics for GBA event

Bug: http://b/174871215
Test: atest GbaManagerTest.

Change-Id: I823c1681d7242fbf29ecbf77679f177414c589ed
Merged-In: I823c1681d7242fbf29ecbf77679f177414c589ed
parent 559bf020
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.text.TextUtils;
import android.util.SparseArray;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.metrics.RcsStats;
import com.android.telephony.Rlog;

import java.util.concurrent.ConcurrentLinkedQueue;
@@ -60,6 +61,7 @@ public class GbaManager {
    public static final int MAX_RETRY = 5;
    @VisibleForTesting
    public static final int REQUEST_TIMEOUT_MS = 5000;
    private final RcsStats mRcsStats;

    private final String mLogTag;
    private final Context mContext;
@@ -191,7 +193,8 @@ public class GbaManager {
    }

    @VisibleForTesting
    public GbaManager(Context context, int subId, String servicePackageName, int releaseTime) {
    public GbaManager(Context context, int subId, String servicePackageName, int releaseTime,
            RcsStats rcsStats) {
        mContext = context;
        mSubId = subId;
        mLogTag = "GbaManager[" + subId + "]";
@@ -206,6 +209,7 @@ public class GbaManager {
        if (mReleaseTime < 0) {
            mHandler.sendEmptyMessage(EVENT_BIND_SERVICE);
        }
        mRcsStats = rcsStats;
    }

    /**
@@ -213,7 +217,8 @@ public class GbaManager {
     */
    public static GbaManager make(Context context, int subId,
            String servicePackageName, int releaseTime) {
        GbaManager gm = new GbaManager(context, subId, servicePackageName, releaseTime);
        GbaManager gm = new GbaManager(context, subId, servicePackageName, releaseTime,
                RcsStats.getInstance());
        synchronized (sGbaManagers) {
            sGbaManagers.put(subId, gm);
        }
@@ -267,6 +272,7 @@ public class GbaManager {
                    if (cb != null) {
                        try {
                            cb.onKeysAvailable(token, gbaKey, btId);
                            mRcsStats.onGbaSuccessEvent(mSubId);
                        } catch (RemoteException exception) {
                            logd("RemoteException " + exception);
                        }
@@ -291,6 +297,7 @@ public class GbaManager {
                    if (cb != null) {
                        try {
                            cb.onAuthenticationFailure(token, reason);
                            mRcsStats.onGbaFailureEvent(mSubId, reason);
                        } catch (RemoteException exception) {
                            logd("RemoteException " + exception);
                        }
+45 −1
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.internal.telephony;

import static com.android.internal.telephony.TelephonyStatsLog.GBA_EVENT__FAILED_REASON__FEATURE_NOT_READY;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
@@ -50,6 +52,8 @@ import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.util.Log;

import com.android.internal.telephony.metrics.RcsStats;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -79,6 +83,7 @@ public final class GbaManagerTest {
    @Mock IBinder mMockBinder;
    @Mock IGbaService mMockGbaServiceBinder;
    @Mock IBootstrapAuthenticationCallback mMockCallback;
    @Mock RcsStats mMockRcsStats;
    private GbaManager mTestGbaManager;
    private Handler mHandler;
    private TestableLooper mLooper;
@@ -92,7 +97,7 @@ public final class GbaManagerTest {
        }
        when(mMockContext.bindService(any(), any(), anyInt())).thenReturn(true);
        when(mMockGbaServiceBinder.asBinder()).thenReturn(mMockBinder);
        mTestGbaManager = new GbaManager(mMockContext, TEST_SUB_ID, null, 0);
        mTestGbaManager = new GbaManager(mMockContext, TEST_SUB_ID, null, 0, mMockRcsStats);
        mHandler = mTestGbaManager.getHandler();
        try {
            mLooper = new TestableLooper(mHandler.getLooper());
@@ -216,6 +221,45 @@ public final class GbaManagerTest {
        assertTrue(!mTestGbaManager.isServiceConnected());
    }

    @Test
    @SmallTest
    public void testMetricsGbaEvent() throws Exception {
        mTestGbaManager.overrideServicePackage(TEST_DEFAULT_SERVICE_NAME.getPackageName());
        mTestGbaManager.overrideReleaseTime(RELEASE_NEVER);

        mLooper.processAllMessages();
        bindAndConnectService(TEST_DEFAULT_SERVICE_NAME);
        GbaAuthRequest request = createDefaultRequest();

        // Failure case
        mTestGbaManager.bootstrapAuthenticationRequest(request);
        mLooper.processAllMessages();

        ArgumentCaptor<GbaAuthRequest> captor = ArgumentCaptor.forClass(GbaAuthRequest.class);
        verify(mMockGbaServiceBinder, times(1)).authenticationRequest(captor.capture());

        GbaAuthRequest capturedRequest = captor.getValue();
        IBootstrapAuthenticationCallback callback = capturedRequest.getCallback();
        callback.onAuthenticationFailure(capturedRequest.getToken(),
                GBA_EVENT__FAILED_REASON__FEATURE_NOT_READY);

        verify(mMockRcsStats).onGbaFailureEvent(anyInt(),
                eq(GBA_EVENT__FAILED_REASON__FEATURE_NOT_READY));

        // Success case
        mTestGbaManager.bootstrapAuthenticationRequest(request);
        mLooper.processAllMessages();

        ArgumentCaptor<GbaAuthRequest> captor2 = ArgumentCaptor.forClass(GbaAuthRequest.class);
        verify(mMockGbaServiceBinder, times(2)).authenticationRequest(captor2.capture());

        GbaAuthRequest capturedRequest2 = captor2.getValue();
        IBootstrapAuthenticationCallback callback2 = capturedRequest2.getCallback();
        callback2.onKeysAvailable(capturedRequest2.getToken(), "".getBytes(), "");

        verify(mMockRcsStats).onGbaSuccessEvent(anyInt());
    }

    private ServiceConnection bindAndConnectService(ComponentName component) {
        ServiceConnection connection = bindService(component);
        IGbaService.Stub serviceStub = mock(IGbaService.Stub.class);