Loading src/java/com/android/internal/telephony/GbaManager.java +9 −2 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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 + "]"; Loading @@ -206,6 +209,7 @@ public class GbaManager { if (mReleaseTime < 0) { mHandler.sendEmptyMessage(EVENT_BIND_SERVICE); } mRcsStats = rcsStats; } /** Loading @@ -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); } Loading Loading @@ -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); } Loading @@ -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); } Loading tests/telephonytests/src/com/android/internal/telephony/GbaManagerTest.java +45 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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; Loading @@ -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()); Loading Loading @@ -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); Loading Loading
src/java/com/android/internal/telephony/GbaManager.java +9 −2 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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 + "]"; Loading @@ -206,6 +209,7 @@ public class GbaManager { if (mReleaseTime < 0) { mHandler.sendEmptyMessage(EVENT_BIND_SERVICE); } mRcsStats = rcsStats; } /** Loading @@ -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); } Loading Loading @@ -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); } Loading @@ -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); } Loading
tests/telephonytests/src/com/android/internal/telephony/GbaManagerTest.java +45 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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; Loading @@ -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()); Loading Loading @@ -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); Loading