Loading src/java/com/android/internal/telephony/ImsSMSDispatcher.java +3 −3 Original line number Diff line number Diff line Loading @@ -156,7 +156,7 @@ public class ImsSMSDispatcher extends SMSDispatcher { } @Override protected void sendData(String destAddr, String scAddr, int destPort, public void sendData(String destAddr, String scAddr, int destPort, byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent) { if (isCdmaMo()) { mCdmaDispatcher.sendData(destAddr, scAddr, destPort, Loading @@ -168,7 +168,7 @@ public class ImsSMSDispatcher extends SMSDispatcher { } @Override protected void sendMultipartText(String destAddr, String scAddr, public void sendMultipartText(String destAddr, String scAddr, ArrayList<String> parts, ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents, Uri messageUri, String callingPkg, boolean persistMessage) { Loading @@ -195,7 +195,7 @@ public class ImsSMSDispatcher extends SMSDispatcher { } @Override protected void sendText(String destAddr, String scAddr, String text, PendingIntent sentIntent, public void sendText(String destAddr, String scAddr, String text, PendingIntent sentIntent, PendingIntent deliveryIntent, Uri messageUri, String callingPkg, boolean persistMessage) { Rlog.d(TAG, "sendText"); Loading src/java/com/android/internal/telephony/cdma/SmsMessage.java +9 −5 Original line number Diff line number Diff line Loading @@ -837,12 +837,16 @@ public class SmsMessage extends SmsMessageBase { // Hence, avoid 0 -- constraining the range to 1..65535. int msgId = SystemProperties.getInt(TelephonyProperties.PROPERTY_CDMA_MSG_ID, 1); String nextMsgId = Integer.toString((msgId % 0xFFFF) + 1); try{ SystemProperties.set(TelephonyProperties.PROPERTY_CDMA_MSG_ID, nextMsgId); if (Rlog.isLoggable(LOGGABLE_TAG, Log.VERBOSE)) { Rlog.d(LOG_TAG, "next " + TelephonyProperties.PROPERTY_CDMA_MSG_ID + " = " + nextMsgId); Rlog.d(LOG_TAG, "readback gets " + SystemProperties.get(TelephonyProperties.PROPERTY_CDMA_MSG_ID)); } } catch(RuntimeException ex) { Rlog.e(LOG_TAG, "set nextMessage ID failed: " + ex); } return msgId; } Loading src/java/com/android/internal/telephony/test/SimulatedCommands.java +13 −3 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import com.android.internal.annotations.VisibleForTesting; import com.android.internal.telephony.BaseCommands; import com.android.internal.telephony.CommandException; import com.android.internal.telephony.CommandsInterface; import com.android.internal.telephony.PhoneConstants; import com.android.internal.telephony.SmsResponse; import com.android.internal.telephony.RadioCapability; import com.android.internal.telephony.cdma.CdmaSmsBroadcastConfigInfo; Loading Loading @@ -1833,7 +1834,7 @@ public class SimulatedCommands extends BaseCommands @Override public void getImsRegistrationState(Message response) { if (mImsRegState == null) { mImsRegState = new int[]{1}; mImsRegState = new int[]{1, PhoneConstants.PHONE_TYPE_NONE}; } resultSuccess(response, mImsRegState); Loading @@ -1842,13 +1843,16 @@ public class SimulatedCommands extends BaseCommands @Override public void sendImsCdmaSms(byte[] pdu, int retry, int messageRef, Message response){ unimplemented(response); SimulatedCommandsVerifier.getInstance().sendImsCdmaSms(pdu, retry, messageRef, response); resultSuccess(response, new SmsResponse(0 /*messageRef*/, null, 0)); } @Override public void sendImsGsmSms(String smscPDU, String pdu, int retry, int messageRef, Message response){ unimplemented(response); SimulatedCommandsVerifier.getInstance().sendImsGsmSms(smscPDU, pdu, retry, messageRef, response); resultSuccess(response, new SmsResponse(0 /*messageRef*/, null, 0)); } @Override Loading Loading @@ -1976,6 +1980,12 @@ public class SimulatedCommands extends BaseCommands } } public void notifyImsNetworkStateChanged() { if(mImsNetworkStateChangedRegistrants != null) { mImsNetworkStateChangedRegistrants.notifyRegistrants(); } } @Override public void registerForExitEmergencyCallbackMode(Handler h, int what, Object obj) { SimulatedCommandsVerifier.getInstance().registerForExitEmergencyCallbackMode(h, what, obj); Loading tests/telephonytests/src/com/android/internal/telephony/ImsSMSDispatcherTest.java 0 → 100644 +172 −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 static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.isNull; import static org.mockito.Mockito.anyBoolean; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.times; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.os.HandlerThread; import android.os.Message; import android.telephony.TelephonyManager; import android.test.suitebuilder.annotation.SmallTest; import static com.android.internal.telephony.TelephonyTestUtils.waitForMs; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; public class ImsSMSDispatcherTest extends TelephonyTest { @Mock private SmsStorageMonitor mSmsStorageMonitor; @Mock private SmsUsageMonitor mSmsUsageMonitor; @Mock private PackageInfo mPackageInfo; @Mock private SMSDispatcher.SmsTracker mTracker; private ImsSMSDispatcher mImsSmsDispatcher; private TelephonyManager mTelephonyManager; private class ImsSmsDispatcherTestHandler extends HandlerThread { private ImsSmsDispatcherTestHandler(String name) { super(name); } @Override public void onLooperPrepared() { mImsSmsDispatcher = new ImsSMSDispatcher(mPhone, mSmsStorageMonitor, mSmsUsageMonitor); //Initial state of RIL is power on, need to wait util RADIO_ON msg get handled waitForMs(200); setReady(true); } } @Before public void setUp() throws Exception { super.setUp(getClass().getSimpleName()); mTelephonyManager = TelephonyManager.from(mContextFixture.getTestDouble()); doReturn(true).when(mTelephonyManager).getSmsSendCapableForPhone(anyInt(), anyBoolean()); PackageManager mockPackageManager = mContextFixture.getTestDouble().getPackageManager(); doReturn(new String[]{TAG}).when(mockPackageManager).getPackagesForUid(anyInt()); doReturn(mPackageInfo).when(mockPackageManager).getPackageInfo(eq(TAG), anyInt()); doReturn(true).when(mSmsUsageMonitor).check(anyString(), anyInt()); new ImsSmsDispatcherTestHandler(getClass().getSimpleName()).start(); waitUntilReady(); } @After public void tearDown() throws Exception { mImsSmsDispatcher = null; super.tearDown(); } @Test @SmallTest public void testSmsHandleStateUpdate() throws Exception { assertEquals(SmsConstants.FORMAT_UNKNOWN, mImsSmsDispatcher.getImsSmsFormat()); //Mock ImsNetWorkStateChange with GSM phone type switchImsSmsFormat(PhoneConstants.PHONE_TYPE_GSM); assertEquals(SmsConstants.FORMAT_3GPP, mImsSmsDispatcher.getImsSmsFormat()); assertTrue(mImsSmsDispatcher.isIms()); //Mock ImsNetWorkStateChange with Cdma Phone type switchImsSmsFormat(PhoneConstants.PHONE_TYPE_CDMA); assertEquals(SmsConstants.FORMAT_3GPP2, mImsSmsDispatcher.getImsSmsFormat()); assertTrue(mImsSmsDispatcher.isIms()); } @Test @SmallTest public void testSendImsGmsTest() throws Exception { switchImsSmsFormat(PhoneConstants.PHONE_TYPE_GSM); mImsSmsDispatcher.sendText("111"/* desAddr*/, "222" /*scAddr*/, TAG, null, null, null, null, false); verify(mSimulatedCommandsVerifier).sendImsGsmSms(eq("038122f2"), eq("0100038111f1000014c9f67cda9c12d37378983e4697e5d4f29c0e"), eq(0), eq(0), any(Message.class)); } @Test @SmallTest public void testSendImsGmsTestWithOutDesAddr() throws Exception { switchImsSmsFormat(PhoneConstants.PHONE_TYPE_GSM); mImsSmsDispatcher.sendText(null, "222" /*scAddr*/, TAG, null, null, null, null, false); verify(mSimulatedCommandsVerifier, times(0)).sendImsGsmSms(anyString(), anyString(), anyInt(), anyInt(), any(Message.class)); } @Test @SmallTest public void testSendImsCdmaTest() throws Exception { ArgumentCaptor<byte[]> captor = ArgumentCaptor.forClass(byte[].class); switchImsSmsFormat(PhoneConstants.PHONE_TYPE_CDMA); mImsSmsDispatcher.sendText("111"/* desAddr*/, "222" /*scAddr*/, TAG, null, null, null, null, false); verify(mSimulatedCommandsVerifier).sendImsCdmaSms((byte[])any(), eq(0), eq(0), any(Message.class)); } @Test @SmallTest public void testSendRetrySmsCdmaTest() throws Exception { // newFormat will be based on voice technology ArgumentCaptor<byte[]> captor = ArgumentCaptor.forClass(byte[].class);; switchImsSmsFormat(PhoneConstants.PHONE_TYPE_CDMA); replaceInstance(SMSDispatcher.SmsTracker.class, "mFormat", mTracker, SmsConstants.FORMAT_3GPP2); doReturn(PhoneConstants.PHONE_TYPE_CDMA).when(mPhone).getPhoneType(); mImsSmsDispatcher.sendRetrySms(mTracker); verify(mSimulatedCommandsVerifier).sendImsCdmaSms(captor.capture(), eq(0), eq(0), any(Message.class)); assertEquals(1, captor.getAllValues().size()); assertNull(captor.getAllValues().get(0)); } @Test @SmallTest public void testSendRetrySmsGsmTest() throws Exception { // newFormat will be based on voice technology will be GSM if phone type is not CDMA switchImsSmsFormat(PhoneConstants.PHONE_TYPE_GSM); replaceInstance(SMSDispatcher.SmsTracker.class, "mFormat", mTracker, SmsConstants.FORMAT_3GPP); mImsSmsDispatcher.sendRetrySms(mTracker); verify(mSimulatedCommandsVerifier).sendImsGsmSms((String)isNull(), (String)isNull(), eq(0), eq(0), any(Message.class)); } private void switchImsSmsFormat(int phoneType) { mSimulatedCommands.setImsRegistrationState(new int[]{1, phoneType}); mSimulatedCommands.notifyImsNetworkStateChanged(); /* wait for async msg get handled */ waitForMs(200); } } Loading
src/java/com/android/internal/telephony/ImsSMSDispatcher.java +3 −3 Original line number Diff line number Diff line Loading @@ -156,7 +156,7 @@ public class ImsSMSDispatcher extends SMSDispatcher { } @Override protected void sendData(String destAddr, String scAddr, int destPort, public void sendData(String destAddr, String scAddr, int destPort, byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent) { if (isCdmaMo()) { mCdmaDispatcher.sendData(destAddr, scAddr, destPort, Loading @@ -168,7 +168,7 @@ public class ImsSMSDispatcher extends SMSDispatcher { } @Override protected void sendMultipartText(String destAddr, String scAddr, public void sendMultipartText(String destAddr, String scAddr, ArrayList<String> parts, ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents, Uri messageUri, String callingPkg, boolean persistMessage) { Loading @@ -195,7 +195,7 @@ public class ImsSMSDispatcher extends SMSDispatcher { } @Override protected void sendText(String destAddr, String scAddr, String text, PendingIntent sentIntent, public void sendText(String destAddr, String scAddr, String text, PendingIntent sentIntent, PendingIntent deliveryIntent, Uri messageUri, String callingPkg, boolean persistMessage) { Rlog.d(TAG, "sendText"); Loading
src/java/com/android/internal/telephony/cdma/SmsMessage.java +9 −5 Original line number Diff line number Diff line Loading @@ -837,12 +837,16 @@ public class SmsMessage extends SmsMessageBase { // Hence, avoid 0 -- constraining the range to 1..65535. int msgId = SystemProperties.getInt(TelephonyProperties.PROPERTY_CDMA_MSG_ID, 1); String nextMsgId = Integer.toString((msgId % 0xFFFF) + 1); try{ SystemProperties.set(TelephonyProperties.PROPERTY_CDMA_MSG_ID, nextMsgId); if (Rlog.isLoggable(LOGGABLE_TAG, Log.VERBOSE)) { Rlog.d(LOG_TAG, "next " + TelephonyProperties.PROPERTY_CDMA_MSG_ID + " = " + nextMsgId); Rlog.d(LOG_TAG, "readback gets " + SystemProperties.get(TelephonyProperties.PROPERTY_CDMA_MSG_ID)); } } catch(RuntimeException ex) { Rlog.e(LOG_TAG, "set nextMessage ID failed: " + ex); } return msgId; } Loading
src/java/com/android/internal/telephony/test/SimulatedCommands.java +13 −3 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import com.android.internal.annotations.VisibleForTesting; import com.android.internal.telephony.BaseCommands; import com.android.internal.telephony.CommandException; import com.android.internal.telephony.CommandsInterface; import com.android.internal.telephony.PhoneConstants; import com.android.internal.telephony.SmsResponse; import com.android.internal.telephony.RadioCapability; import com.android.internal.telephony.cdma.CdmaSmsBroadcastConfigInfo; Loading Loading @@ -1833,7 +1834,7 @@ public class SimulatedCommands extends BaseCommands @Override public void getImsRegistrationState(Message response) { if (mImsRegState == null) { mImsRegState = new int[]{1}; mImsRegState = new int[]{1, PhoneConstants.PHONE_TYPE_NONE}; } resultSuccess(response, mImsRegState); Loading @@ -1842,13 +1843,16 @@ public class SimulatedCommands extends BaseCommands @Override public void sendImsCdmaSms(byte[] pdu, int retry, int messageRef, Message response){ unimplemented(response); SimulatedCommandsVerifier.getInstance().sendImsCdmaSms(pdu, retry, messageRef, response); resultSuccess(response, new SmsResponse(0 /*messageRef*/, null, 0)); } @Override public void sendImsGsmSms(String smscPDU, String pdu, int retry, int messageRef, Message response){ unimplemented(response); SimulatedCommandsVerifier.getInstance().sendImsGsmSms(smscPDU, pdu, retry, messageRef, response); resultSuccess(response, new SmsResponse(0 /*messageRef*/, null, 0)); } @Override Loading Loading @@ -1976,6 +1980,12 @@ public class SimulatedCommands extends BaseCommands } } public void notifyImsNetworkStateChanged() { if(mImsNetworkStateChangedRegistrants != null) { mImsNetworkStateChangedRegistrants.notifyRegistrants(); } } @Override public void registerForExitEmergencyCallbackMode(Handler h, int what, Object obj) { SimulatedCommandsVerifier.getInstance().registerForExitEmergencyCallbackMode(h, what, obj); Loading
tests/telephonytests/src/com/android/internal/telephony/ImsSMSDispatcherTest.java 0 → 100644 +172 −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 static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.isNull; import static org.mockito.Mockito.anyBoolean; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.times; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.os.HandlerThread; import android.os.Message; import android.telephony.TelephonyManager; import android.test.suitebuilder.annotation.SmallTest; import static com.android.internal.telephony.TelephonyTestUtils.waitForMs; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; public class ImsSMSDispatcherTest extends TelephonyTest { @Mock private SmsStorageMonitor mSmsStorageMonitor; @Mock private SmsUsageMonitor mSmsUsageMonitor; @Mock private PackageInfo mPackageInfo; @Mock private SMSDispatcher.SmsTracker mTracker; private ImsSMSDispatcher mImsSmsDispatcher; private TelephonyManager mTelephonyManager; private class ImsSmsDispatcherTestHandler extends HandlerThread { private ImsSmsDispatcherTestHandler(String name) { super(name); } @Override public void onLooperPrepared() { mImsSmsDispatcher = new ImsSMSDispatcher(mPhone, mSmsStorageMonitor, mSmsUsageMonitor); //Initial state of RIL is power on, need to wait util RADIO_ON msg get handled waitForMs(200); setReady(true); } } @Before public void setUp() throws Exception { super.setUp(getClass().getSimpleName()); mTelephonyManager = TelephonyManager.from(mContextFixture.getTestDouble()); doReturn(true).when(mTelephonyManager).getSmsSendCapableForPhone(anyInt(), anyBoolean()); PackageManager mockPackageManager = mContextFixture.getTestDouble().getPackageManager(); doReturn(new String[]{TAG}).when(mockPackageManager).getPackagesForUid(anyInt()); doReturn(mPackageInfo).when(mockPackageManager).getPackageInfo(eq(TAG), anyInt()); doReturn(true).when(mSmsUsageMonitor).check(anyString(), anyInt()); new ImsSmsDispatcherTestHandler(getClass().getSimpleName()).start(); waitUntilReady(); } @After public void tearDown() throws Exception { mImsSmsDispatcher = null; super.tearDown(); } @Test @SmallTest public void testSmsHandleStateUpdate() throws Exception { assertEquals(SmsConstants.FORMAT_UNKNOWN, mImsSmsDispatcher.getImsSmsFormat()); //Mock ImsNetWorkStateChange with GSM phone type switchImsSmsFormat(PhoneConstants.PHONE_TYPE_GSM); assertEquals(SmsConstants.FORMAT_3GPP, mImsSmsDispatcher.getImsSmsFormat()); assertTrue(mImsSmsDispatcher.isIms()); //Mock ImsNetWorkStateChange with Cdma Phone type switchImsSmsFormat(PhoneConstants.PHONE_TYPE_CDMA); assertEquals(SmsConstants.FORMAT_3GPP2, mImsSmsDispatcher.getImsSmsFormat()); assertTrue(mImsSmsDispatcher.isIms()); } @Test @SmallTest public void testSendImsGmsTest() throws Exception { switchImsSmsFormat(PhoneConstants.PHONE_TYPE_GSM); mImsSmsDispatcher.sendText("111"/* desAddr*/, "222" /*scAddr*/, TAG, null, null, null, null, false); verify(mSimulatedCommandsVerifier).sendImsGsmSms(eq("038122f2"), eq("0100038111f1000014c9f67cda9c12d37378983e4697e5d4f29c0e"), eq(0), eq(0), any(Message.class)); } @Test @SmallTest public void testSendImsGmsTestWithOutDesAddr() throws Exception { switchImsSmsFormat(PhoneConstants.PHONE_TYPE_GSM); mImsSmsDispatcher.sendText(null, "222" /*scAddr*/, TAG, null, null, null, null, false); verify(mSimulatedCommandsVerifier, times(0)).sendImsGsmSms(anyString(), anyString(), anyInt(), anyInt(), any(Message.class)); } @Test @SmallTest public void testSendImsCdmaTest() throws Exception { ArgumentCaptor<byte[]> captor = ArgumentCaptor.forClass(byte[].class); switchImsSmsFormat(PhoneConstants.PHONE_TYPE_CDMA); mImsSmsDispatcher.sendText("111"/* desAddr*/, "222" /*scAddr*/, TAG, null, null, null, null, false); verify(mSimulatedCommandsVerifier).sendImsCdmaSms((byte[])any(), eq(0), eq(0), any(Message.class)); } @Test @SmallTest public void testSendRetrySmsCdmaTest() throws Exception { // newFormat will be based on voice technology ArgumentCaptor<byte[]> captor = ArgumentCaptor.forClass(byte[].class);; switchImsSmsFormat(PhoneConstants.PHONE_TYPE_CDMA); replaceInstance(SMSDispatcher.SmsTracker.class, "mFormat", mTracker, SmsConstants.FORMAT_3GPP2); doReturn(PhoneConstants.PHONE_TYPE_CDMA).when(mPhone).getPhoneType(); mImsSmsDispatcher.sendRetrySms(mTracker); verify(mSimulatedCommandsVerifier).sendImsCdmaSms(captor.capture(), eq(0), eq(0), any(Message.class)); assertEquals(1, captor.getAllValues().size()); assertNull(captor.getAllValues().get(0)); } @Test @SmallTest public void testSendRetrySmsGsmTest() throws Exception { // newFormat will be based on voice technology will be GSM if phone type is not CDMA switchImsSmsFormat(PhoneConstants.PHONE_TYPE_GSM); replaceInstance(SMSDispatcher.SmsTracker.class, "mFormat", mTracker, SmsConstants.FORMAT_3GPP); mImsSmsDispatcher.sendRetrySms(mTracker); verify(mSimulatedCommandsVerifier).sendImsGsmSms((String)isNull(), (String)isNull(), eq(0), eq(0), any(Message.class)); } private void switchImsSmsFormat(int phoneType) { mSimulatedCommands.setImsRegistrationState(new int[]{1, phoneType}); mSimulatedCommands.notifyImsNetworkStateChanged(); /* wait for async msg get handled */ waitForMs(200); } }