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

Commit 60a81bdb authored by Amit Mahajan's avatar Amit Mahajan
Browse files

Unit test for WapPushOverSms

Bug: 25691379
Change-Id: I26eebb8711c9369c5ab85e740254a86483125bf5
parent defb36a0
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -79,6 +79,10 @@ public class TelephonyComponentFactory {
        return new EriManager(phone, context, eriFileSource);
    }

    public WspTypeDecoder makeWspTypeDecoder(byte[] pdu) {
        return new WspTypeDecoder(pdu);
    }

    public CdmaSubscriptionSourceManager
    getCdmaSubscriptionSourceManagerInstance(Context context, CommandsInterface ci, Handler h,
                                             int what, Object obj) {
+7 −7
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ public class WapPushOverSms implements ServiceConnection {
    private static final boolean DBG = false;

    private final Context mContext;
    IDeviceIdleController mDeviceIdleController;
    private IDeviceIdleController mDeviceIdleController;

    private String mWapPushManagerPackage;

@@ -87,8 +87,7 @@ public class WapPushOverSms implements ServiceConnection {

    public WapPushOverSms(Context context) {
        mContext = context;
        mDeviceIdleController = IDeviceIdleController.Stub.asInterface(
                ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
        mDeviceIdleController = TelephonyComponentFactory.getInstance().getIDeviceIdleController();
        Intent intent = new Intent(IWapPushManager.class.getName());
        ComponentName comp = intent.resolveSystemService(context.getPackageManager(), 0);
        intent.setComponent(comp);
@@ -100,7 +99,7 @@ public class WapPushOverSms implements ServiceConnection {
        }
    }

    void dispose() {
    public void dispose() {
        if (mWapPushManager != null) {
            if (DBG) Rlog.v(TAG, "dispose: unbind wappush manager");
            mContext.unbindService(this);
@@ -153,7 +152,8 @@ public class WapPushOverSms implements ServiceConnection {
                }
            }

            WspTypeDecoder pduDecoder = new WspTypeDecoder(pdu);
            WspTypeDecoder pduDecoder =
                    TelephonyComponentFactory.getInstance().makeWspTypeDecoder(pdu);

            /**
             * Parse HeaderLen(unsigned integer).
@@ -483,7 +483,7 @@ public class WapPushOverSms implements ServiceConnection {
        return false;
    }

    protected static String getPermissionForType(String mimeType) {
    public static String getPermissionForType(String mimeType) {
        String permission;
        if (WspTypeDecoder.CONTENT_TYPE_B_MMS.equals(mimeType)) {
            permission = android.Manifest.permission.RECEIVE_MMS;
@@ -493,7 +493,7 @@ public class WapPushOverSms implements ServiceConnection {
        return permission;
    }

    protected static int getAppOpsPermissionForIntent(String mimeType) {
    public static int getAppOpsPermissionForIntent(String mimeType) {
        int appOp;
        if (WspTypeDecoder.CONTENT_TYPE_B_MMS.equals(mimeType)) {
            appOp = AppOpsManager.OP_RECEIVE_MMS;
+11 −1
Original line number Diff line number Diff line
@@ -92,6 +92,10 @@ public abstract class TelephonyTest {
    protected SimulatedCommandsVerifier mSimulatedCommandsVerifier;
    @Mock
    protected IDeviceIdleController mIDeviceIdleController;
    @Mock
    protected InboundSmsHandler mInboundSmsHandler;
    @Mock
    protected WspTypeDecoder mWspTypeDecoder;

    protected SimulatedCommands mSimulatedCommands;
    protected ContextFixture mContextFixture;
@@ -170,11 +174,17 @@ public abstract class TelephonyTest {
                makeIccPhoneBookInterfaceManager(any(Phone.class));
        doReturn(mDcTracker).when(mTelephonyComponentFactory).
                makeDcTracker(any(Phone.class));
        doReturn(true).when(mImsManagerInstances).containsKey(anyInt());
        doReturn(mIDeviceIdleController).when(mTelephonyComponentFactory).
                getIDeviceIdleController();
        doReturn(mWspTypeDecoder).when(mTelephonyComponentFactory).
                makeWspTypeDecoder(any(byte[].class));

        doReturn(mContextFixture.getTestDouble()).when(mPhone).getContext();

        doReturn(true).when(mImsManagerInstances).containsKey(anyInt());

        doReturn(mPhone).when(mInboundSmsHandler).getPhone();

        setReady(false);
    }

+82 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.telephony;

import android.app.AppOpsManager;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.os.Bundle;
import android.os.UserHandle;
import android.provider.Telephony;
import android.test.suitebuilder.annotation.SmallTest;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.MockitoAnnotations;

public class WapPushOverSmsTest extends TelephonyTest {
    private WapPushOverSms mWapPushOverSmsUT;

    @Before
    public void setUp() throws Exception {
        super.setUp("WapPushOverSmsTest");

        mWapPushOverSmsUT = new WapPushOverSms(mContextFixture.getTestDouble());
    }

    @After
    public void tearDown() throws Exception {
        mWapPushOverSmsUT = null;
    }

    @Test @SmallTest
    public void testDispatchWapPdu() {
        doReturn(true).when(mWspTypeDecoder).decodeUintvarInteger(anyInt());
        doReturn((long)2).when(mWspTypeDecoder).getValue32();
        doReturn(2).when(mWspTypeDecoder).getDecodedDataLength();
        doReturn(WspTypeDecoder.CONTENT_TYPE_B_PUSH_CO).when(mWspTypeDecoder).getValueString();
        byte[] pdu = new byte[]{
                (byte) 0xFF,
                (byte) 0x06,
                (byte) 0xFF,
                (byte) 0xFF,
                (byte) 0xFF,
                (byte) 0xFF,
                (byte) 0xFF
        };

        mWapPushOverSmsUT.dispatchWapPdu(pdu, null, mInboundSmsHandler);

        ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class);
        verify(mInboundSmsHandler).dispatchIntent(intentArgumentCaptor.capture(),
                eq(android.Manifest.permission.RECEIVE_MMS), eq(AppOpsManager.OP_RECEIVE_MMS),
                any(Bundle.class), isNull(BroadcastReceiver.class), eq(UserHandle.SYSTEM));
        Intent intent = intentArgumentCaptor.getValue();
        assertEquals(Telephony.Sms.Intents.WAP_PUSH_DELIVER_ACTION, intent.getAction());
        assertEquals(0xFF, intent.getIntExtra("transactionId", 0));
        assertEquals(0x06, intent.getIntExtra("pduType", 0));
        assertEquals(new byte[]{(byte) 0xFF, (byte) 0xFF}, intent.getByteArrayExtra("header"));
        assertEquals(pdu, intent.getByteArrayExtra("data"));
        assertEquals(mWspTypeDecoder.getContentParameters(),
                intent.getSerializableExtra("contentTypeParameters"));
    }
}
 No newline at end of file