1/* 2 * Copyright 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16package com.android.internal.telephony; 17 18import static junit.framework.Assert.fail; 19 20import android.content.Intent; 21import android.provider.Telephony.Sms.Intents; 22import android.telephony.SmsMessage; 23 24import com.android.internal.telephony.uicc.IccUtils; 25 26import org.junit.After; 27import org.junit.Before; 28import org.junit.Test; 29 30public class AppSmsManagerTest extends TelephonyTest { 31 32 /** 33 * The sms message information represent by the {@link #PDU}. 34 * 35 * SMSC#+31624000000 36 * Sender:+31641600986 37 * TimeStamp:26/08/02 19:37:41 38 * TP_PID:00 39 * TP_DCS:00 40 * TP_DCS-popis:Uncompressed Text 41 * class:0 42 * Alphabet:Default 43 * How are you? 44 * Length:12 45 */ 46 private static final String PDU = 47 "07911326040000F0040B911346610089F60000208062917314080CC8F71D14969741F977FD07"; 48 49 private AppSmsManager mAppSmsManagerUT; 50 51 @Before 52 public void setUp() throws Exception { 53 super.setUp("AppSmsManagerTest"); 54 mAppSmsManagerUT = new AppSmsManager(mContextFixture.getTestDouble()); 55 } 56 57 @After 58 public void tearDown() throws Exception { 59 super.tearDown(); 60 } 61 62 @Test 63 public void testHandleSmsReceivedIntent() { 64 Intent intent = new Intent(); 65 intent.setAction(Intents.SMS_DELIVER_ACTION); 66 intent.putExtra("pdus", new byte[][]{IccUtils.hexStringToBytes(PDU), null, null}); 67 intent.putExtra("format", SmsMessage.FORMAT_3GPP); 68 69 try { 70 // Assumes the AppSmsManager can handle the null pdu. 71 mAppSmsManagerUT.handleSmsReceivedIntent(intent); 72 } catch (NullPointerException ex) { 73 fail("Test failed because of null pointer exception " + ex); 74 } 75 } 76} 77