Search in sources :

Example 1 with FakeSmsContentProvider

use of com.android.internal.telephony.FakeSmsContentProvider 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)

Example 2 with FakeSmsContentProvider

use of com.android.internal.telephony.FakeSmsContentProvider in project android_frameworks_opt_telephony by LineageOS.

the class GsmInboundSmsHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp("GsmInboundSmsHandlerTest");
    doReturn(true).when(mTelephonyManager).getSmsReceiveCapableForPhone(anyInt(), anyBoolean());
    doReturn(true).when(mSmsStorageMonitor).isStorageAvailable();
    UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
    doReturn(true).when(userManager).isUserUnlocked();
    doReturn(true).when(userManager).isUserRunning(any(UserHandle.class));
    List<UserHandle> userHandles = new ArrayList();
    userHandles.add(UserHandle.SYSTEM);
    doReturn(userHandles).when(userManager).getUserHandles(anyBoolean());
    mSmsMessage.mWrappedSmsMessage = mGsmSmsMessage;
    mInboundSmsTracker = new InboundSmsTracker(mContext, mSmsPdu, /* pdu */
    System.currentTimeMillis(), /* timestamp */
    -1, /* destPort */
    false, /* is3gpp2 */
    false, /* is3gpp2WapPdu */
    "1234567890", /* address */
    "1234567890", /* displayAddress */
    mMessageBody, /* 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());
    createMockInboundSmsTracker();
    mContentProvider = new FakeSmsContentProvider();
    ((MockContentResolver) mContext.getContentResolver()).addProvider(Telephony.Sms.CONTENT_URI.getAuthority(), mContentProvider);
    mGsmInboundSmsHandler = GsmInboundSmsHandler.makeInboundSmsHandler(mContext, mSmsStorageMonitor, mPhone);
    mSmsFilters = new ArrayList<>();
    mSmsFilters.add(mSmsFilter);
    mSmsFilters.add(mSmsFilter2);
    mGsmInboundSmsHandler.setSmsFiltersForTesting(mSmsFilters);
    monitorTestableLooper(new TestableLooper(mGsmInboundSmsHandler.getHandler().getLooper()));
    processAllMessages();
}
Also used : Context(android.content.Context) FakeSmsContentProvider(com.android.internal.telephony.FakeSmsContentProvider) UserManager(android.os.UserManager) UserHandle(android.os.UserHandle) ArrayList(java.util.ArrayList) MockContentResolver(android.test.mock.MockContentResolver) TestableLooper(android.testing.TestableLooper) InboundSmsTracker(com.android.internal.telephony.InboundSmsTracker) Before(org.junit.Before)

Aggregations

Context (android.content.Context)2 UserManager (android.os.UserManager)2 MockContentResolver (android.test.mock.MockContentResolver)2 TestableLooper (android.testing.TestableLooper)2 FakeSmsContentProvider (com.android.internal.telephony.FakeSmsContentProvider)2 InboundSmsTracker (com.android.internal.telephony.InboundSmsTracker)2 Before (org.junit.Before)2 Cursor (android.database.Cursor)1 RemoteException (android.os.RemoteException)1 UserHandle (android.os.UserHandle)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1