Search in sources :

Example 1 with TestableLooper

use of android.testing.TestableLooper in project android_frameworks_opt_telephony by LineageOS.

the class ImsResolverTest method setupResolver.

private void setupResolver(int numSlots, String deviceMmTelPkgName, String deviceRcsPkgName) {
    // all tests call setupResolver before running
    when(mMockContext.getPackageManager()).thenReturn(mMockPM);
    when(mMockContext.createContextAsUser(any(), eq(0))).thenReturn(mMockContext);
    when(mMockContext.getSystemService(eq(Context.CARRIER_CONFIG_SERVICE))).thenReturn(mMockCarrierConfigManager);
    when(mMockContext.getSystemService(eq(Context.USER_SERVICE))).thenReturn(mMockUserManager);
    // If this is not false, then HANDLER_BOOT_COMPLETE is fired now but the controller factories
    // used in the test methods aren't created in time.
    when(mMockUserManager.isUserUnlocked()).thenReturn(false);
    // Support configs for MSIM always in case we are testing dynamic sim slot config changes.
    mCarrierConfigs = new PersistableBundle[NUM_MAX_SLOTS];
    for (int i = 0; i < NUM_MAX_SLOTS; i++) {
        mCarrierConfigs[i] = new PersistableBundle();
        when(mMockCarrierConfigManager.getConfigForSubId(eq(i))).thenReturn(mCarrierConfigs[i]);
        when(mTestSubscriptionManagerProxy.getSlotIndex(eq(i))).thenReturn(i);
        when(mTestSubscriptionManagerProxy.getSubId(eq(i))).thenReturn(i);
        when(mTestTelephonyManagerProxy.getSimState(any(Context.class), eq(i))).thenReturn(TelephonyManager.SIM_STATE_READY);
    }
    mTestImsResolver = new ImsResolver(mMockContext, deviceMmTelPkgName, deviceRcsPkgName, numSlots);
    try {
        mLooper = new TestableLooper(mTestImsResolver.getHandler().getLooper());
    } catch (Exception e) {
        fail("Unable to create looper from handler.");
    }
    ArgumentCaptor<BroadcastReceiver> receiversCaptor = ArgumentCaptor.forClass(BroadcastReceiver.class);
    verify(mMockContext, times(3)).registerReceiver(receiversCaptor.capture(), any());
    mTestPackageBroadcastReceiver = receiversCaptor.getAllValues().get(0);
    mTestCarrierConfigReceiver = receiversCaptor.getAllValues().get(1);
    mTestBootCompleteReceiver = receiversCaptor.getAllValues().get(2);
    mTestImsResolver.setSubscriptionManagerProxy(mTestSubscriptionManagerProxy);
    mTestImsResolver.setTelephonyManagerProxy(mTestTelephonyManagerProxy);
    when(mMockQueryManagerFactory.create(any(Context.class), any(ImsServiceFeatureQueryManager.Listener.class))).thenReturn(mMockQueryManager);
    mTestImsResolver.setImsDynamicQueryManagerFactory(mMockQueryManagerFactory);
    mLooper.processAllMessages();
}
Also used : Context(android.content.Context) PersistableBundle(android.os.PersistableBundle) TestableLooper(android.testing.TestableLooper) BroadcastReceiver(android.content.BroadcastReceiver) RemoteException(android.os.RemoteException)

Example 2 with TestableLooper

use of android.testing.TestableLooper in project android_frameworks_opt_telephony by LineageOS.

the class TelephonyTest method tearDown.

protected void tearDown() throws Exception {
    // Ensure there are no references to handlers between tests.
    PhoneConfigurationManager.unregisterAllMultiSimConfigChangeRegistrants();
    // unmonitor TestableLooper for TelephonyTest class
    if (mTestableLooper != null) {
        unmonitorTestableLooper(mTestableLooper);
    }
    // destroy all newly created TestableLoopers so they can be reused
    for (TestableLooper looper : mTestableLoopers) {
        looper.destroy();
    }
    TestableLooper.remove(TelephonyTest.this);
    mSimulatedCommands.dispose();
    SharedPreferences sharedPreferences = mContext.getSharedPreferences((String) null, 0);
    sharedPreferences.edit().clear().commit();
    restoreInstances();
    TelephonyManager.enableServiceHandleCaching();
    SubscriptionController.enableCaching();
}
Also used : SharedPreferences(android.content.SharedPreferences) TestableLooper(android.testing.TestableLooper)

Example 3 with TestableLooper

use of android.testing.TestableLooper in project android_frameworks_opt_telephony by LineageOS.

the class TelephonyTest method moveTimeForward.

/**
 * Effectively moves time forward by reducing the time of all messages
 * for all monitored TestableLoopers
 * @param milliSeconds number of milliseconds to move time forward by
 */
public void moveTimeForward(long milliSeconds) {
    for (TestableLooper looper : mTestableLoopers) {
        MessageQueue queue = looper.getLooper().getQueue();
        try {
            Message msg = (Message) MESSAGE_QUEUE_FIELD.get(queue);
            while (msg != null) {
                long updatedWhen = msg.getWhen() - milliSeconds;
                if (updatedWhen < 0) {
                    updatedWhen = 0;
                }
                MESSAGE_WHEN_FIELD.set(msg, updatedWhen);
                msg = (Message) MESSAGE_NEXT_FIELD.get(msg);
            }
        } catch (IllegalAccessException e) {
            throw new RuntimeException("Access failed in TelephonyTest", e);
        }
    }
}
Also used : MessageQueue(android.os.MessageQueue) Message(android.os.Message) TestableLooper(android.testing.TestableLooper)

Example 4 with TestableLooper

use of android.testing.TestableLooper in project android_frameworks_opt_telephony by LineageOS.

the class TelephonyTest method setUp.

protected void setUp(String tag) throws Exception {
    TAG = tag;
    MockitoAnnotations.initMocks(this);
    TelephonyManager.disableServiceHandleCaching();
    SubscriptionController.disableCaching();
    mPhones = new Phone[] { mPhone };
    mImsCallProfile = new ImsCallProfile();
    mImsCallProfile.setCallerNumberVerificationStatus(ImsCallProfile.VERIFICATION_STATUS_PASSED);
    mSimulatedCommands = new SimulatedCommands();
    mContextFixture = new ContextFixture();
    mContext = mContextFixture.getTestDouble();
    mFakeBlockedNumberContentProvider = new FakeBlockedNumberContentProvider();
    ((MockContentResolver) mContext.getContentResolver()).addProvider(BlockedNumberContract.AUTHORITY, mFakeBlockedNumberContentProvider);
    mPhone.mCi = mSimulatedCommands;
    mCT.mCi = mSimulatedCommands;
    doReturn(mUiccCard).when(mPhone).getUiccCard();
    doReturn(mUiccProfile).when(mUiccCard).getUiccProfile();
    mTelephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
    mActivityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
    mTelephonyRegistryManager = (TelephonyRegistryManager) mContext.getSystemService(Context.TELEPHONY_REGISTRY_SERVICE);
    mSubscriptionManager = (SubscriptionManager) mContext.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
    mEuiccManager = (EuiccManager) mContext.getSystemService(Context.EUICC_SERVICE);
    mConnectivityManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    mPackageManager = mContext.getPackageManager();
    mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
    mCarrierConfigManager = (CarrierConfigManager) mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE);
    mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
    // mTelephonyComponentFactory
    doReturn(mTelephonyComponentFactory).when(mTelephonyComponentFactory).inject(anyString());
    doReturn(mSST).when(mTelephonyComponentFactory).makeServiceStateTracker(nullable(GsmCdmaPhone.class), nullable(CommandsInterface.class));
    doReturn(mEmergencyNumberTracker).when(mTelephonyComponentFactory).makeEmergencyNumberTracker(nullable(Phone.class), nullable(CommandsInterface.class));
    doReturn(getTestEmergencyNumber()).when(mEmergencyNumberTracker).getEmergencyNumber(any());
    doReturn(mUiccProfile).when(mTelephonyComponentFactory).makeUiccProfile(nullable(Context.class), nullable(CommandsInterface.class), nullable(IccCardStatus.class), anyInt(), nullable(UiccCard.class), nullable(Object.class));
    doReturn(mCT).when(mTelephonyComponentFactory).makeGsmCdmaCallTracker(nullable(GsmCdmaPhone.class));
    doReturn(mIccPhoneBookIntManager).when(mTelephonyComponentFactory).makeIccPhoneBookInterfaceManager(nullable(Phone.class));
    doReturn(mDcTracker).when(mTelephonyComponentFactory).makeDcTracker(nullable(Phone.class), anyInt());
    doReturn(mDisplayInfoController).when(mTelephonyComponentFactory).makeDisplayInfoController(nullable(Phone.class));
    doReturn(mWspTypeDecoder).when(mTelephonyComponentFactory).makeWspTypeDecoder(nullable(byte[].class));
    doReturn(mImsCT).when(mTelephonyComponentFactory).makeImsPhoneCallTracker(nullable(ImsPhone.class));
    doReturn(mCdmaSSM).when(mTelephonyComponentFactory).getCdmaSubscriptionSourceManagerInstance(nullable(Context.class), nullable(CommandsInterface.class), nullable(Handler.class), anyInt(), nullable(Object.class));
    doReturn(mImsExternalCallTracker).when(mTelephonyComponentFactory).makeImsExternalCallTracker(nullable(ImsPhone.class));
    doReturn(mAppSmsManager).when(mTelephonyComponentFactory).makeAppSmsManager(nullable(Context.class));
    doReturn(mCarrierSignalAgent).when(mTelephonyComponentFactory).makeCarrierSignalAgent(nullable(Phone.class));
    doReturn(mCarrierActionAgent).when(mTelephonyComponentFactory).makeCarrierActionAgent(nullable(Phone.class));
    doReturn(mDeviceStateMonitor).when(mTelephonyComponentFactory).makeDeviceStateMonitor(nullable(Phone.class));
    doReturn(mTransportManager).when(mTelephonyComponentFactory).makeTransportManager(nullable(Phone.class));
    doReturn(mNitzStateMachine).when(mTelephonyComponentFactory).makeNitzStateMachine(nullable(GsmCdmaPhone.class));
    doReturn(mLocaleTracker).when(mTelephonyComponentFactory).makeLocaleTracker(nullable(Phone.class), nullable(NitzStateMachine.class), nullable(Looper.class));
    doReturn(mDataEnabledSettings).when(mTelephonyComponentFactory).makeDataEnabledSettings(nullable(Phone.class));
    doReturn(mEriManager).when(mTelephonyComponentFactory).makeEriManager(nullable(Phone.class), anyInt());
    // mPhone
    doReturn(mContext).when(mPhone).getContext();
    doReturn(mContext).when(mImsPhone).getContext();
    doReturn(true).when(mPhone).getUnitTestMode();
    doReturn(mUiccProfile).when(mPhone).getIccCard();
    doReturn(mServiceState).when(mPhone).getServiceState();
    doReturn(mServiceState).when(mImsPhone).getServiceState();
    doReturn(mPhone).when(mImsPhone).getDefaultPhone();
    doReturn(true).when(mPhone).isPhoneTypeGsm();
    doReturn(PhoneConstants.PHONE_TYPE_GSM).when(mPhone).getPhoneType();
    doReturn(mCT).when(mPhone).getCallTracker();
    doReturn(mSST).when(mPhone).getServiceStateTracker();
    doReturn(mDeviceStateMonitor).when(mPhone).getDeviceStateMonitor();
    doReturn(mDisplayInfoController).when(mPhone).getDisplayInfoController();
    doReturn(mEmergencyNumberTracker).when(mPhone).getEmergencyNumberTracker();
    doReturn(mCarrierSignalAgent).when(mPhone).getCarrierSignalAgent();
    doReturn(mCarrierActionAgent).when(mPhone).getCarrierActionAgent();
    doReturn(mAppSmsManager).when(mPhone).getAppSmsManager();
    doReturn(mIccSmsInterfaceManager).when(mPhone).getIccSmsInterfaceManager();
    doReturn(mTransportManager).when(mPhone).getTransportManager();
    doReturn(mDataEnabledSettings).when(mPhone).getDataEnabledSettings();
    doReturn(mDcTracker).when(mPhone).getDcTracker(anyInt());
    doReturn(mCarrierPrivilegesTracker).when(mPhone).getCarrierPrivilegesTracker();
    doReturn(mVoiceCallSessionStats).when(mPhone).getVoiceCallSessionStats();
    doReturn(mVoiceCallSessionStats).when(mImsPhone).getVoiceCallSessionStats();
    mIccSmsInterfaceManager.mDispatchersController = mSmsDispatchersController;
    // mUiccController
    doReturn(mUiccCardApplication3gpp).when(mUiccController).getUiccCardApplication(anyInt(), eq(UiccController.APP_FAM_3GPP));
    doReturn(mUiccCardApplication3gpp2).when(mUiccController).getUiccCardApplication(anyInt(), eq(UiccController.APP_FAM_3GPP2));
    doReturn(mUiccCardApplicationIms).when(mUiccController).getUiccCardApplication(anyInt(), eq(UiccController.APP_FAM_IMS));
    doAnswer(new Answer<IccRecords>() {

        public IccRecords answer(InvocationOnMock invocation) {
            switch((Integer) invocation.getArguments()[1]) {
                case UiccController.APP_FAM_3GPP:
                    return mSimRecords;
                case UiccController.APP_FAM_3GPP2:
                    return mRuimRecords;
                case UiccController.APP_FAM_IMS:
                    return mIsimUiccRecords;
                default:
                    logd("Unrecognized family " + invocation.getArguments()[1]);
                    return null;
            }
        }
    }).when(mUiccController).getIccRecords(anyInt(), anyInt());
    // UiccCardApplication
    doReturn(mSimRecords).when(mUiccCardApplication3gpp).getIccRecords();
    doReturn(mRuimRecords).when(mUiccCardApplication3gpp2).getIccRecords();
    doReturn(mIsimUiccRecords).when(mUiccCardApplicationIms).getIccRecords();
    // mUiccProfile
    doReturn(mSimRecords).when(mUiccProfile).getIccRecords();
    doAnswer(new Answer<IccRecords>() {

        public IccRecords answer(InvocationOnMock invocation) {
            return (mPhone.isPhoneTypeGsm()) ? mSimRecords : mRuimRecords;
        }
    }).when(mUiccProfile).getIccRecords();
    // mUiccProfile
    doReturn(mUiccCardApplication3gpp).when(mUiccProfile).getApplication(eq(UiccController.APP_FAM_3GPP));
    doReturn(mUiccCardApplication3gpp2).when(mUiccProfile).getApplication(eq(UiccController.APP_FAM_3GPP2));
    doReturn(mUiccCardApplicationIms).when(mUiccProfile).getApplication(eq(UiccController.APP_FAM_IMS));
    // SMS
    doReturn(true).when(mSmsStorageMonitor).isStorageAvailable();
    doReturn(true).when(mSmsUsageMonitor).check(nullable(String.class), anyInt());
    doReturn(true).when(mTelephonyManager).getSmsReceiveCapableForPhone(anyInt(), anyBoolean());
    doReturn(true).when(mTelephonyManager).getSmsSendCapableForPhone(anyInt(), anyBoolean());
    // Misc
    doReturn(ServiceState.RIL_RADIO_TECHNOLOGY_UMTS).when(mServiceState).getRilDataRadioTechnology();
    doReturn(mPhone).when(mCT).getPhone();
    mImsManagerInstances.put(mPhone.getPhoneId(), mImsManager);
    doReturn(mImsEcbm).when(mImsManager).getEcbmInterface();
    doReturn(mPhone).when(mInboundSmsHandler).getPhone();
    doReturn(mImsCallProfile).when(mImsCall).getCallProfile();
    doReturn(mIBinder).when(mIIntentSender).asBinder();
    doReturn(mIIntentSender).when(mIActivityManager).getIntentSenderWithFeature(anyInt(), nullable(String.class), nullable(String.class), nullable(IBinder.class), nullable(String.class), anyInt(), nullable(Intent[].class), nullable(String[].class), anyInt(), nullable(Bundle.class), anyInt());
    doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(anyInt());
    doReturn(true).when(mTelephonyManager).isDataCapable();
    doReturn(TelephonyManager.PHONE_TYPE_GSM).when(mTelephonyManager).getPhoneType();
    doReturn(mServiceState).when(mSST).getServiceState();
    mSST.mSS = mServiceState;
    mSST.mRestrictedState = mRestrictedState;
    mServiceManagerMockedServices.put("connectivity_metrics_logger", mConnMetLoggerBinder);
    mServiceManagerMockedServices.put("package", mMockPackageManager);
    mServiceManagerMockedServices.put("permissionmgr", mMockPermissionManager);
    logd("mMockPermissionManager replaced");
    doReturn(new int[] { AccessNetworkConstants.TRANSPORT_TYPE_WWAN, AccessNetworkConstants.TRANSPORT_TYPE_WLAN }).when(mTransportManager).getAvailableTransports();
    doReturn(AccessNetworkConstants.TRANSPORT_TYPE_WWAN).when(mTransportManager).getCurrentTransport(anyInt());
    doReturn(true).when(mDataEnabledSettings).isDataEnabled();
    doReturn(true).when(mDataEnabledSettings).isDataEnabled(anyInt());
    doReturn(true).when(mDataEnabledSettings).isInternalDataEnabled();
    doReturn(mNetworkRegistrationInfo).when(mServiceState).getNetworkRegistrationInfo(anyInt(), anyInt());
    doReturn(new HalVersion(1, 4)).when(mPhone).getHalVersion();
    // SIM
    doReturn(1).when(mTelephonyManager).getSimCount();
    doReturn(1).when(mTelephonyManager).getPhoneCount();
    doReturn(1).when(mTelephonyManager).getActiveModemCount();
    // Have getMaxPhoneCount always return the same value with getPhoneCount by default.
    doAnswer((invocation) -> Math.max(mTelephonyManager.getActiveModemCount(), mTelephonyManager.getPhoneCount())).when(mTelephonyManager).getSupportedModemCount();
    doReturn(mStatsManager).when(mContext).getSystemService(eq(Context.NETWORK_STATS_SERVICE));
    // Data
    // Initial state is: userData enabled, provisioned.
    ContentResolver resolver = mContext.getContentResolver();
    Settings.Global.putInt(resolver, Settings.Global.MOBILE_DATA, 1);
    Settings.Global.putInt(resolver, Settings.Global.DEVICE_PROVISIONED, 1);
    Settings.Global.putInt(resolver, Settings.Global.DEVICE_PROVISIONING_MOBILE_DATA_ENABLED, 1);
    // CellularNetworkValidator
    doReturn(SubscriptionManager.INVALID_PHONE_INDEX).when(mCellularNetworkValidator).getSubIdInValidation();
    doReturn(true).when(mCellularNetworkValidator).isValidationFeatureSupported();
    // Metrics
    doReturn(null).when(mContext).getFileStreamPath(anyString());
    doReturn(mPersistAtomsStorage).when(mMetricsCollector).getAtomsStorage();
    // Use reflection to mock singletons
    replaceInstance(CallManager.class, "INSTANCE", null, mCallManager);
    replaceInstance(TelephonyComponentFactory.class, "sInstance", null, mTelephonyComponentFactory);
    replaceInstance(UiccController.class, "mInstance", null, mUiccController);
    replaceInstance(CdmaSubscriptionSourceManager.class, "sInstance", null, mCdmaSSM);
    replaceInstance(ImsManager.class, "sImsManagerInstances", null, mImsManagerInstances);
    replaceInstance(SubscriptionController.class, "sInstance", null, mSubscriptionController);
    replaceInstance(ProxyController.class, "sProxyController", null, mProxyController);
    replaceInstance(ActivityManager.class, "IActivityManagerSingleton", null, mIActivityManagerSingleton);
    replaceInstance(CdmaSubscriptionSourceManager.class, "mCdmaSubscriptionSourceChangedRegistrants", mCdmaSSM, mRegistrantList);
    replaceInstance(SimulatedCommandsVerifier.class, "sInstance", null, mSimulatedCommandsVerifier);
    replaceInstance(Singleton.class, "mInstance", mIActivityManagerSingleton, mIActivityManager);
    replaceInstance(ServiceManager.class, "sCache", null, mServiceManagerMockedServices);
    replaceInstance(IntentBroadcaster.class, "sIntentBroadcaster", null, mIntentBroadcaster);
    replaceInstance(TelephonyManager.class, "sInstance", null, mContext.getSystemService(Context.TELEPHONY_SERVICE));
    replaceInstance(TelephonyManager.class, "sServiceHandleCacheEnabled", null, false);
    replaceInstance(PhoneFactory.class, "sMadeDefaults", null, true);
    replaceInstance(PhoneFactory.class, "sPhone", null, mPhone);
    replaceInstance(PhoneFactory.class, "sPhones", null, mPhones);
    replaceInstance(PhoneFactory.class, "sSubInfoRecordUpdater", null, mSubInfoRecordUpdater);
    replaceInstance(RadioConfig.class, "sRadioConfig", null, mMockRadioConfig);
    replaceInstance(PhoneConfigurationManager.class, "sInstance", null, mPhoneConfigurationManager);
    replaceInstance(CellularNetworkValidator.class, "sInstance", null, mCellularNetworkValidator);
    replaceInstance(MultiSimSettingController.class, "sInstance", null, mMultiSimSettingController);
    replaceInstance(SubscriptionInfoUpdater.class, "sIsSubInfoInitialized", null, true);
    replaceInstance(PhoneFactory.class, "sCommandsInterfaces", null, new CommandsInterface[] { mSimulatedCommands });
    replaceInstance(PhoneFactory.class, "sMetricsCollector", null, mMetricsCollector);
    assertNotNull("Failed to set up SubscriptionController singleton", SubscriptionController.getInstance());
    setReady(false);
    // create default TestableLooper for test and add to list of monitored loopers
    mTestableLooper = TestableLooper.get(TelephonyTest.this);
    if (mTestableLooper != null) {
        monitorTestableLooper(mTestableLooper);
    }
}
Also used : Context(android.content.Context) IccCardStatus(com.android.internal.telephony.uicc.IccCardStatus) SimulatedCommands(com.android.internal.telephony.test.SimulatedCommands) IccRecords(com.android.internal.telephony.uicc.IccRecords) Bundle(android.os.Bundle) Handler(android.os.Handler) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MockContentResolver(android.test.mock.MockContentResolver) ImsPhone(com.android.internal.telephony.imsphone.ImsPhone) MockContentResolver(android.test.mock.MockContentResolver) ContentResolver(android.content.ContentResolver) UiccCard(com.android.internal.telephony.uicc.UiccCard) Looper(android.os.Looper) TestableLooper(android.testing.TestableLooper) IBinder(android.os.IBinder) ImsCallProfile(android.telephony.ims.ImsCallProfile) ImsPhone(com.android.internal.telephony.imsphone.ImsPhone) InvocationOnMock(org.mockito.invocation.InvocationOnMock)

Example 5 with TestableLooper

use of android.testing.TestableLooper in project android_frameworks_opt_telephony by LineageOS.

the class CdmaInboundSmsHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp("CdmaInboundSmsHandlerTest");
    Field field = SmsMessage.class.getDeclaredField("mEnvelope");
    field.setAccessible(true);
    field.set(mCdmaSmsMessage, mSmsEnvelope);
    UserManager userManager = (UserManager) mContextFixture.getTestDouble().getSystemService(Context.USER_SERVICE);
    doReturn(true).when(userManager).isUserUnlocked();
    try {
        doReturn(new int[] { UserHandle.USER_SYSTEM }).when(mIActivityManager).getRunningUserIds();
    } catch (RemoteException re) {
        fail("Unexpected RemoteException: " + re.getStackTrace());
    }
    mSmsMessage.mWrappedSmsMessage = mCdmaSmsMessage;
    doReturn(mSmsPdu).when(mCdmaSmsMessage).getPdu();
    doReturn(true).when(mTelephonyManager).getSmsReceiveCapableForPhone(anyInt(), anyBoolean());
    doReturn(true).when(mSmsStorageMonitor).isStorageAvailable();
    mInboundSmsTracker = new InboundSmsTracker(mContext, mSmsPdu, /* pdu */
    System.currentTimeMillis(), /* timestamp */
    -1, /* destPort */
    true, /* is3gpp2 */
    false, /* is3gpp2WapPdu */
    "1234567890", /* address */
    "1234567890", /* displayAddress */
    "This is the message body of a single-part message", /* messageBody */
    false, /* isClass0 */
    mSubId0);
    doReturn(mInboundSmsTracker).when(mTelephonyComponentFactory).makeInboundSmsTracker(any(Context.class), nullable(byte[].class), anyLong(), anyInt(), anyBoolean(), anyBoolean(), nullable(String.class), nullable(String.class), nullable(String.class), anyBoolean(), anyInt());
    doReturn(mInboundSmsTracker).when(mTelephonyComponentFactory).makeInboundSmsTracker(any(Context.class), nullable(byte[].class), anyLong(), anyInt(), anyBoolean(), nullable(String.class), nullable(String.class), anyInt(), anyInt(), anyInt(), anyBoolean(), nullable(String.class), anyBoolean(), anyInt());
    doReturn(mInboundSmsTracker).when(mTelephonyComponentFactory).makeInboundSmsTracker(any(Context.class), nullable(Cursor.class), anyBoolean());
    mContentProvider = new FakeSmsContentProvider();
    ((MockContentResolver) mContext.getContentResolver()).addProvider(Telephony.Sms.CONTENT_URI.getAuthority(), mContentProvider);
    mCdmaInboundSmsHandler = CdmaInboundSmsHandler.makeInboundSmsHandler(mContext, mSmsStorageMonitor, mPhone, null);
    monitorTestableLooper(new TestableLooper(mCdmaInboundSmsHandler.getHandler().getLooper()));
    processAllMessages();
}
Also used : Context(android.content.Context) FakeSmsContentProvider(com.android.internal.telephony.FakeSmsContentProvider) Field(java.lang.reflect.Field) UserManager(android.os.UserManager) RemoteException(android.os.RemoteException) Cursor(android.database.Cursor) MockContentResolver(android.test.mock.MockContentResolver) TestableLooper(android.testing.TestableLooper) InboundSmsTracker(com.android.internal.telephony.InboundSmsTracker) Before(org.junit.Before)

Aggregations

TestableLooper (android.testing.TestableLooper)6 Context (android.content.Context)4 MockContentResolver (android.test.mock.MockContentResolver)3 RemoteException (android.os.RemoteException)2 UserManager (android.os.UserManager)2 FakeSmsContentProvider (com.android.internal.telephony.FakeSmsContentProvider)2 InboundSmsTracker (com.android.internal.telephony.InboundSmsTracker)2 Before (org.junit.Before)2 BroadcastReceiver (android.content.BroadcastReceiver)1 ContentResolver (android.content.ContentResolver)1 SharedPreferences (android.content.SharedPreferences)1 Cursor (android.database.Cursor)1 Bundle (android.os.Bundle)1 Handler (android.os.Handler)1 IBinder (android.os.IBinder)1 Looper (android.os.Looper)1 Message (android.os.Message)1 MessageQueue (android.os.MessageQueue)1 PersistableBundle (android.os.PersistableBundle)1 UserHandle (android.os.UserHandle)1