Loading src/java/android/provider/Telephony.java +2 −2 Original line number Original line Diff line number Diff line Loading @@ -1165,7 +1165,7 @@ public final class Telephony { for (int i = 0; i < pduCount; i++) { for (int i = 0; i < pduCount; i++) { byte[] pdu = (byte[]) messages[i]; byte[] pdu = (byte[]) messages[i]; msgs[i] = SmsMessage.createFromPdu(pdu, format); msgs[i] = SmsMessage.createFromPdu(pdu, format); msgs[i].setSubId(subId); if (msgs[i] != null) msgs[i].setSubId(subId); } } return msgs; return msgs; } } Loading src/java/android/telephony/SmsMessage.java +18 −3 Original line number Original line Diff line number Diff line Loading @@ -204,7 +204,12 @@ public class SmsMessage { return null; return null; } } if (wrappedMessage != null) { return new SmsMessage(wrappedMessage); return new SmsMessage(wrappedMessage); } else { Rlog.e(LOG_TAG, "createFromPdu(): wrappedMessage is null"); return null; } } } /** /** Loading @@ -221,7 +226,12 @@ public class SmsMessage { SmsMessageBase wrappedMessage = SmsMessageBase wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.newFromCMT(lines); com.android.internal.telephony.gsm.SmsMessage.newFromCMT(lines); if (wrappedMessage != null) { return new SmsMessage(wrappedMessage); return new SmsMessage(wrappedMessage); } else { Rlog.e(LOG_TAG, "newFromCMT(): wrappedMessage is null"); return null; } } } /** @hide */ /** @hide */ Loading Loading @@ -254,7 +264,12 @@ public class SmsMessage { index, data); index, data); } } return wrappedMessage != null ? new SmsMessage(wrappedMessage) : null; if (wrappedMessage != null) { return new SmsMessage(wrappedMessage); } else { Rlog.e(LOG_TAG, "createFromEfRecord(): wrappedMessage is null"); return null; } } } /** /** Loading src/java/com/android/internal/telephony/ImsSMSDispatcher.java +10 −3 Original line number Original line Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.os.Message; import android.provider.Telephony.Sms.Intents; import android.provider.Telephony.Sms.Intents; import android.telephony.Rlog; import android.telephony.Rlog; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.telephony.cdma.CdmaInboundSmsHandler; import com.android.internal.telephony.cdma.CdmaInboundSmsHandler; import com.android.internal.telephony.cdma.CdmaSMSDispatcher; import com.android.internal.telephony.cdma.CdmaSMSDispatcher; import com.android.internal.telephony.gsm.GsmInboundSmsHandler; import com.android.internal.telephony.gsm.GsmInboundSmsHandler; Loading Loading @@ -208,8 +209,9 @@ public class ImsSMSDispatcher extends SMSDispatcher { } } } } @VisibleForTesting @Override @Override protected void injectSmsPdu(byte[] pdu, String format, PendingIntent receivedIntent) { public void injectSmsPdu(byte[] pdu, String format, PendingIntent receivedIntent) { Rlog.d(TAG, "ImsSMSDispatcher:injectSmsPdu"); Rlog.d(TAG, "ImsSMSDispatcher:injectSmsPdu"); try { try { // TODO We need to decide whether we should allow injecting GSM(3gpp) // TODO We need to decide whether we should allow injecting GSM(3gpp) Loading @@ -218,9 +220,14 @@ public class ImsSMSDispatcher extends SMSDispatcher { android.telephony.SmsMessage.createFromPdu(pdu, format); android.telephony.SmsMessage.createFromPdu(pdu, format); // Only class 1 SMS are allowed to be injected. // Only class 1 SMS are allowed to be injected. if (msg.getMessageClass() != android.telephony.SmsMessage.MessageClass.CLASS_1) { if (msg == null || if (receivedIntent != null) msg.getMessageClass() != android.telephony.SmsMessage.MessageClass.CLASS_1) { if (msg == null) { Rlog.e(TAG, "injectSmsPdu: createFromPdu returned null"); } if (receivedIntent != null) { receivedIntent.send(Intents.RESULT_SMS_GENERIC_ERROR); receivedIntent.send(Intents.RESULT_SMS_GENERIC_ERROR); } return; return; } } Loading tests/telephonytests/src/com/android/internal/telephony/ImsSMSDispatcherTest.java +41 −2 Original line number Original line Diff line number Diff line Loading @@ -28,9 +28,16 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.times; import android.app.ActivityManagerNative; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.HandlerThread; import android.os.HandlerThread; import android.os.Message; import android.os.Message; import android.test.suitebuilder.annotation.SmallTest; import android.test.suitebuilder.annotation.SmallTest; import android.util.Singleton; import static com.android.internal.telephony.TelephonyTestUtils.waitForMs; import static com.android.internal.telephony.TelephonyTestUtils.waitForMs; Loading @@ -45,6 +52,18 @@ public class ImsSMSDispatcherTest extends TelephonyTest { private SMSDispatcher.SmsTracker mTracker; private SMSDispatcher.SmsTracker mTracker; private ImsSMSDispatcher mImsSmsDispatcher; private ImsSMSDispatcher mImsSmsDispatcher; private boolean mReceivedTestIntent = false; private Object mLock = new Object(); private static final String TEST_INTENT = "com.android.internal.telephony.TEST_INTENT"; private BroadcastReceiver mTestReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { logd("onReceive"); synchronized (mLock) { mReceivedTestIntent = true; } } }; private class ImsSmsDispatcherTestHandler extends HandlerThread { private class ImsSmsDispatcherTestHandler extends HandlerThread { Loading Loading @@ -145,6 +164,27 @@ public class ImsSMSDispatcherTest extends TelephonyTest { eq(0), any(Message.class)); eq(0), any(Message.class)); } } @Test @SmallTest public void testInjectNullSmsPdu() throws Exception { // unmock ActivityManager to be able to register receiver, create real PendingIntent and // receive TEST_INTENT restoreInstance(Singleton.class, "mInstance", mIActivityManagerSingleton); restoreInstance(ActivityManagerNative.class, "gDefault", null); Context realContext = TestApplication.getAppContext(); realContext.registerReceiver(mTestReceiver, new IntentFilter(TEST_INTENT)); PendingIntent pendingIntent = PendingIntent.getBroadcast(realContext, 0, new Intent(TEST_INTENT), 0); // inject null sms pdu. This should cause intent to be received since pdu is null. mImsSmsDispatcher.injectSmsPdu(null, SmsConstants.FORMAT_3GPP, pendingIntent); waitForMs(100); synchronized (mLock) { assertEquals(true, mReceivedTestIntent); } } private void switchImsSmsFormat(int phoneType) { private void switchImsSmsFormat(int phoneType) { mSimulatedCommands.setImsRegistrationState(new int[]{1, phoneType}); mSimulatedCommands.setImsRegistrationState(new int[]{1, phoneType}); mSimulatedCommands.notifyImsNetworkStateChanged(); mSimulatedCommands.notifyImsNetworkStateChanged(); Loading @@ -152,4 +192,3 @@ public class ImsSMSDispatcherTest extends TelephonyTest { waitForMs(200); waitForMs(200); } } } } No newline at end of file tests/telephonytests/src/java/android/telephony/SmsMessageTest.java 0 → 100644 +37 −0 Original line number Original line 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 java.android.telephony; import android.telephony.SmsMessage; import android.test.suitebuilder.annotation.SmallTest; import com.android.internal.telephony.SmsConstants; import org.junit.After; import org.junit.Before; import org.junit.Test; import static org.junit.Assert.assertEquals; public class SmsMessageTest { @Test @SmallTest public void testCreateInvalidSmsMessage() { // should return null instead of SmsMessage with null wrappedMessage assertEquals(null, SmsMessage.createFromPdu(null, SmsConstants.FORMAT_3GPP2)); assertEquals(null, SmsMessage.createFromPdu(null, SmsConstants.FORMAT_3GPP)); assertEquals(null, SmsMessage.createFromPdu(null)); assertEquals(null, SmsMessage.newFromCMT(null)); } } Loading
src/java/android/provider/Telephony.java +2 −2 Original line number Original line Diff line number Diff line Loading @@ -1165,7 +1165,7 @@ public final class Telephony { for (int i = 0; i < pduCount; i++) { for (int i = 0; i < pduCount; i++) { byte[] pdu = (byte[]) messages[i]; byte[] pdu = (byte[]) messages[i]; msgs[i] = SmsMessage.createFromPdu(pdu, format); msgs[i] = SmsMessage.createFromPdu(pdu, format); msgs[i].setSubId(subId); if (msgs[i] != null) msgs[i].setSubId(subId); } } return msgs; return msgs; } } Loading
src/java/android/telephony/SmsMessage.java +18 −3 Original line number Original line Diff line number Diff line Loading @@ -204,7 +204,12 @@ public class SmsMessage { return null; return null; } } if (wrappedMessage != null) { return new SmsMessage(wrappedMessage); return new SmsMessage(wrappedMessage); } else { Rlog.e(LOG_TAG, "createFromPdu(): wrappedMessage is null"); return null; } } } /** /** Loading @@ -221,7 +226,12 @@ public class SmsMessage { SmsMessageBase wrappedMessage = SmsMessageBase wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.newFromCMT(lines); com.android.internal.telephony.gsm.SmsMessage.newFromCMT(lines); if (wrappedMessage != null) { return new SmsMessage(wrappedMessage); return new SmsMessage(wrappedMessage); } else { Rlog.e(LOG_TAG, "newFromCMT(): wrappedMessage is null"); return null; } } } /** @hide */ /** @hide */ Loading Loading @@ -254,7 +264,12 @@ public class SmsMessage { index, data); index, data); } } return wrappedMessage != null ? new SmsMessage(wrappedMessage) : null; if (wrappedMessage != null) { return new SmsMessage(wrappedMessage); } else { Rlog.e(LOG_TAG, "createFromEfRecord(): wrappedMessage is null"); return null; } } } /** /** Loading
src/java/com/android/internal/telephony/ImsSMSDispatcher.java +10 −3 Original line number Original line Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.os.Message; import android.provider.Telephony.Sms.Intents; import android.provider.Telephony.Sms.Intents; import android.telephony.Rlog; import android.telephony.Rlog; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.telephony.cdma.CdmaInboundSmsHandler; import com.android.internal.telephony.cdma.CdmaInboundSmsHandler; import com.android.internal.telephony.cdma.CdmaSMSDispatcher; import com.android.internal.telephony.cdma.CdmaSMSDispatcher; import com.android.internal.telephony.gsm.GsmInboundSmsHandler; import com.android.internal.telephony.gsm.GsmInboundSmsHandler; Loading Loading @@ -208,8 +209,9 @@ public class ImsSMSDispatcher extends SMSDispatcher { } } } } @VisibleForTesting @Override @Override protected void injectSmsPdu(byte[] pdu, String format, PendingIntent receivedIntent) { public void injectSmsPdu(byte[] pdu, String format, PendingIntent receivedIntent) { Rlog.d(TAG, "ImsSMSDispatcher:injectSmsPdu"); Rlog.d(TAG, "ImsSMSDispatcher:injectSmsPdu"); try { try { // TODO We need to decide whether we should allow injecting GSM(3gpp) // TODO We need to decide whether we should allow injecting GSM(3gpp) Loading @@ -218,9 +220,14 @@ public class ImsSMSDispatcher extends SMSDispatcher { android.telephony.SmsMessage.createFromPdu(pdu, format); android.telephony.SmsMessage.createFromPdu(pdu, format); // Only class 1 SMS are allowed to be injected. // Only class 1 SMS are allowed to be injected. if (msg.getMessageClass() != android.telephony.SmsMessage.MessageClass.CLASS_1) { if (msg == null || if (receivedIntent != null) msg.getMessageClass() != android.telephony.SmsMessage.MessageClass.CLASS_1) { if (msg == null) { Rlog.e(TAG, "injectSmsPdu: createFromPdu returned null"); } if (receivedIntent != null) { receivedIntent.send(Intents.RESULT_SMS_GENERIC_ERROR); receivedIntent.send(Intents.RESULT_SMS_GENERIC_ERROR); } return; return; } } Loading
tests/telephonytests/src/com/android/internal/telephony/ImsSMSDispatcherTest.java +41 −2 Original line number Original line Diff line number Diff line Loading @@ -28,9 +28,16 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.times; import android.app.ActivityManagerNative; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.HandlerThread; import android.os.HandlerThread; import android.os.Message; import android.os.Message; import android.test.suitebuilder.annotation.SmallTest; import android.test.suitebuilder.annotation.SmallTest; import android.util.Singleton; import static com.android.internal.telephony.TelephonyTestUtils.waitForMs; import static com.android.internal.telephony.TelephonyTestUtils.waitForMs; Loading @@ -45,6 +52,18 @@ public class ImsSMSDispatcherTest extends TelephonyTest { private SMSDispatcher.SmsTracker mTracker; private SMSDispatcher.SmsTracker mTracker; private ImsSMSDispatcher mImsSmsDispatcher; private ImsSMSDispatcher mImsSmsDispatcher; private boolean mReceivedTestIntent = false; private Object mLock = new Object(); private static final String TEST_INTENT = "com.android.internal.telephony.TEST_INTENT"; private BroadcastReceiver mTestReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { logd("onReceive"); synchronized (mLock) { mReceivedTestIntent = true; } } }; private class ImsSmsDispatcherTestHandler extends HandlerThread { private class ImsSmsDispatcherTestHandler extends HandlerThread { Loading Loading @@ -145,6 +164,27 @@ public class ImsSMSDispatcherTest extends TelephonyTest { eq(0), any(Message.class)); eq(0), any(Message.class)); } } @Test @SmallTest public void testInjectNullSmsPdu() throws Exception { // unmock ActivityManager to be able to register receiver, create real PendingIntent and // receive TEST_INTENT restoreInstance(Singleton.class, "mInstance", mIActivityManagerSingleton); restoreInstance(ActivityManagerNative.class, "gDefault", null); Context realContext = TestApplication.getAppContext(); realContext.registerReceiver(mTestReceiver, new IntentFilter(TEST_INTENT)); PendingIntent pendingIntent = PendingIntent.getBroadcast(realContext, 0, new Intent(TEST_INTENT), 0); // inject null sms pdu. This should cause intent to be received since pdu is null. mImsSmsDispatcher.injectSmsPdu(null, SmsConstants.FORMAT_3GPP, pendingIntent); waitForMs(100); synchronized (mLock) { assertEquals(true, mReceivedTestIntent); } } private void switchImsSmsFormat(int phoneType) { private void switchImsSmsFormat(int phoneType) { mSimulatedCommands.setImsRegistrationState(new int[]{1, phoneType}); mSimulatedCommands.setImsRegistrationState(new int[]{1, phoneType}); mSimulatedCommands.notifyImsNetworkStateChanged(); mSimulatedCommands.notifyImsNetworkStateChanged(); Loading @@ -152,4 +192,3 @@ public class ImsSMSDispatcherTest extends TelephonyTest { waitForMs(200); waitForMs(200); } } } } No newline at end of file
tests/telephonytests/src/java/android/telephony/SmsMessageTest.java 0 → 100644 +37 −0 Original line number Original line 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 java.android.telephony; import android.telephony.SmsMessage; import android.test.suitebuilder.annotation.SmallTest; import com.android.internal.telephony.SmsConstants; import org.junit.After; import org.junit.Before; import org.junit.Test; import static org.junit.Assert.assertEquals; public class SmsMessageTest { @Test @SmallTest public void testCreateInvalidSmsMessage() { // should return null instead of SmsMessage with null wrappedMessage assertEquals(null, SmsMessage.createFromPdu(null, SmsConstants.FORMAT_3GPP2)); assertEquals(null, SmsMessage.createFromPdu(null, SmsConstants.FORMAT_3GPP)); assertEquals(null, SmsMessage.createFromPdu(null)); assertEquals(null, SmsMessage.newFromCMT(null)); } }