Loading src/java/com/android/internal/telephony/SmsNumberUtils.java +16 −14 Original line number Diff line number Diff line Loading @@ -27,13 +27,14 @@ import android.database.SQLException; import android.telephony.PhoneNumberUtils; import android.telephony.TelephonyManager; import android.telephony.Rlog; import com.android.internal.telephony.HbpcdLookup.MccIdd; import com.android.internal.telephony.HbpcdLookup.MccLookup; /** * This class implements handle the MO SMS target address before sending. * This is special for VZW requirement. Follow the specificaitons of assisted dialing * This is special for VZW requirement. Follow the specifications of assisted dialing * of MO SMS while traveling on VZW CDMA, international CDMA or GSM markets. * {@hide} */ Loading Loading @@ -109,13 +110,13 @@ public class SmsNumberUtils { } /* Breaks the given number down and formats it according to the rules * for different number plans and differnt network. * for different number plans and different network. * * @param number destionation number which need to be format * @param number destination number which need to be format * @param activeMcc current network's mcc * @param networkType current network type * * @return the number after fromatting. * @return the number after formatting. */ private static String formatNumber(Context context, String number, String activeMcc, Loading Loading @@ -508,13 +509,13 @@ public class SmsNumberUtils { } else if (state == NP_NANP_NBPCD_HOMEIDD_CC_AREA_LOCAL) { numberPlanType = "NP_NANP_NBPCD_HOMEIDD_CC_AREA_LOCAL"; } else if (state == NP_NBPCD_HOMEIDD_CC_AREA_LOCAL) { numberPlanType = "NP_NBPCD_IDD_CC_AREA_LOCAL"; numberPlanType = "NP_NBPCD_HOMEIDD_CC_AREA_LOCAL"; } else if (state == NP_HOMEIDD_CC_AREA_LOCAL) { numberPlanType = "NP_IDD_CC_AREA_LOCAL"; numberPlanType = "NP_HOMEIDD_CC_AREA_LOCAL"; } else if (state == NP_NBPCD_CC_AREA_LOCAL) { numberPlanType = "NP_NBPCD_CC_AREA_LOCAL"; } else if (state == NP_LOCALIDD_CC_AREA_LOCAL) { numberPlanType = "NP_IDD_CC_AREA_LOCAL"; numberPlanType = "NP_LOCALIDD_CC_AREA_LOCAL"; } else if (state == NP_CC_AREA_LOCAL) { numberPlanType = "NP_CC_AREA_LOCAL"; } else { Loading @@ -534,7 +535,8 @@ public class SmsNumberUtils { return destAddr; } final String networkOperator = TelephonyManager.getDefault().getNetworkOperator(); final String networkOperator = TelephonyManager.from(phone.getContext()). getNetworkOperator(phone.getSubId()); String result = null; if (needToConvert(phone)) { Loading @@ -559,11 +561,11 @@ public class SmsNumberUtils { */ private static int getNetworkType(Phone phone) { int networkType = -1; int phoneType = TelephonyManager.getDefault().getPhoneType(); int phoneType = phone.getPhoneType(); if (phoneType == TelephonyManager.PHONE_TYPE_GSM) { if (phoneType == PhoneConstants.PHONE_TYPE_GSM) { networkType = GSM_UMTS_NETWORK; } else if (phoneType == TelephonyManager.PHONE_TYPE_CDMA) { } else if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) { if (isInternationalRoaming(phone)) { networkType = CDMA_ROAMING_NETWORK; } else { Loading @@ -577,9 +579,9 @@ public class SmsNumberUtils { } private static boolean isInternationalRoaming(Phone phone) { String operatorIsoCountry = TelephonyManager.getDefault().getNetworkCountryIsoForPhone( phone.getPhoneId()); String simIsoCountry = TelephonyManager.getDefault().getSimCountryIsoForPhone( String operatorIsoCountry = TelephonyManager.from(phone.getContext()). getNetworkCountryIsoForPhone(phone.getPhoneId()); String simIsoCountry = TelephonyManager.from(phone.getContext()).getSimCountryIsoForPhone( phone.getPhoneId()); boolean internationalRoaming = !TextUtils.isEmpty(operatorIsoCountry) && !TextUtils.isEmpty(simIsoCountry) Loading tests/telephonytests/src/com/android/internal/telephony/ServiceStateTrackerTest.java +0 −22 Original line number Diff line number Diff line Loading @@ -236,28 +236,6 @@ public class ServiceStateTrackerTest { assertEquals(SimulatedCommands.FAKE_LONG_NAME, b.getString(TelephonyIntents.EXTRA_PLMN)); } @Test @MediumTest public void testNITZupdate() { doReturn(0x02).when(mSimRecords).getDisplayRule(anyString()); sst.sendMessage(sst.obtainMessage(ServiceStateTracker.EVENT_NITZ_TIME, new AsyncResult(null, new Object[]{"16/01/22,23:24:44-32,00", Long.valueOf(41824)}, null))); waitForMs(750); ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class); verify(mContextFixture.getTestDouble(), times(4)). sendStickyBroadcastAsUser(intentArgumentCaptor.capture(), eq(UserHandle.ALL)); Intent intent = intentArgumentCaptor.getAllValues().get(1); assertEquals(intent.getAction(), TelephonyIntents.ACTION_NETWORK_SET_TIMEZONE); assertEquals(Intent.FLAG_RECEIVER_REPLACE_PENDING, intent.getFlags()); assertEquals(AMERICA_LA_TIME_ZONE, intent.getExtras().getString(KEY_TIME_ZONE)); } @Test @MediumTest public void testCellInfoList() { Loading tests/telephonytests/src/com/android/internal/telephony/SmsNumberUtilsTest.java 0 → 100644 +257 −0 Original line number Diff line number Diff line /* * Copyright (C) 2015 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.database.Cursor; import android.database.MatrixCursor; import android.net.Uri; import android.telephony.TelephonyManager; import android.test.mock.MockContentProvider; import android.test.mock.MockContentResolver; import android.test.suitebuilder.annotation.SmallTest; import android.util.Log; import org.mockito.MockitoAnnotations; import java.util.Arrays; import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.doReturn; import static org.junit.Assert.*; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; public class SmsNumberUtilsTest { private static final String TAG = "SmsNumberUtilsTest"; private static final String TMO_MCC_MNC = "310260"; private static final String TAIWAN_FET_MCC_MNC = "46602"; private static final String INDIA_AIRTEL_MCC_MNC = "40553"; private static final String JAPAN_NTTDOCOMO_MCC_MNC = "44020"; private TelephonyManager mTelephonyManager; // Simulate partial packages/providers/TelephonyProvider/res/xml/hbpcd_lookup_tables.xml public class HbpcdContentProvider extends MockContentProvider { public HbpcdContentProvider() {} @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { logd("HbpcdContentProvider: query"); logd(" uri = " + uri); logd(" projection = " + Arrays.toString(projection)); logd(" selection = " + selection); logd(" selectionArgs = " + Arrays.toString(selectionArgs)); logd(" sortOrder = " + sortOrder); if (uri.compareTo(HbpcdLookup.MccIdd.CONTENT_URI) == 0) { if (projection.length == 2 && projection[0].equals(HbpcdLookup.MccIdd.IDD) && projection[1].equals(HbpcdLookup.MccIdd.MCC) && selectionArgs.length == 1) { MatrixCursor mc = new MatrixCursor( new String[]{HbpcdLookup.MccIdd.IDD}); switch (Integer.valueOf(selectionArgs[0])) { case 310: mc.addRow(new Object[]{"011"}); // US IDD code break; case 466: mc.addRow(new Object[]{"002"}); // Taiwan IDD code break; case 440: mc.addRow(new Object[]{"010"}); // Japan IDD code break; case 405: mc.addRow(new Object[]{"010"}); // India IDD code break; default: logd("Unhandled MCC" + Integer.valueOf(selectionArgs[0])); } return mc; } else { logd("Unhandled IDD look up request."); } } else if (uri.compareTo(HbpcdLookup.MccLookup.CONTENT_URI) == 0) { if (projection.length == 1 && projection[0].equals( HbpcdLookup.MccLookup.COUNTRY_CODE) && selection == null && selectionArgs == null) { MatrixCursor mccCursor = new MatrixCursor( new String[]{HbpcdLookup.MccLookup.COUNTRY_CODE}); mccCursor.addRow(new Object[]{"1"}); mccCursor.addRow(new Object[]{"886"}); mccCursor.addRow(new Object[]{"81"}); mccCursor.addRow(new Object[]{"91"}); return mccCursor; } else { logd("Unhandled mcc look up request"); } } else { logd("Unknown URI: " + uri); } return null; } } @Mock GsmCdmaPhone mPhone; ContextFixture mContextFixture; HbpcdContentProvider mHbpcdContentProvider; @Before public void setUp() throws Exception { logd("SmsNumberUtilsTest +Setup!"); MockitoAnnotations.initMocks(this); mContextFixture = new ContextFixture(); mHbpcdContentProvider = new HbpcdContentProvider(); mTelephonyManager = TelephonyManager.from(mContextFixture.getTestDouble()); doReturn(TMO_MCC_MNC).when(mTelephonyManager).getNetworkOperator(anyInt()); doReturn(PhoneConstants.PHONE_TYPE_GSM).when(mPhone).getPhoneType(); ((MockContentResolver) mContextFixture.getTestDouble().getContentResolver()) .addProvider(HbpcdLookup.MccIdd.CONTENT_URI.getAuthority(), mHbpcdContentProvider); mContextFixture.putStringArrayResource( com.android.internal.R.array.config_sms_convert_destination_number_support, new String[]{"true"}); doReturn(mContextFixture.getTestDouble()).when(mPhone).getContext(); logd("SmsNumberUtilsTest -Setup!"); } @Test @SmallTest public void testInvalidNumberConversion() { assertEquals("123", SmsNumberUtils.filterDestAddr(mPhone, "123")); } @Test @SmallTest public void testNaPcCountryCodeAreaLocalNumberConversion() { // NP_NANP_NBPCD_CC_AREA_LOCAL tests doReturn(PhoneConstants.PHONE_TYPE_CDMA).when(mPhone).getPhoneType(); assertEquals("18583420022", SmsNumberUtils.filterDestAddr(mPhone, "+1-858-342-0022")); } @Test @SmallTest public void testPcCountryCodeAreaLocalNumberConversion() { // NP_NBPCD_CC_AREA_LOCAL tests assertEquals("01188671234567", SmsNumberUtils.filterDestAddr(mPhone, "+886-7-1234567")); } @Test @SmallTest public void testIndiaPcCountryCodeAreaLocalNumberConversion() { // NP_NBPCD_CC_AREA_LOCAL tests doReturn(INDIA_AIRTEL_MCC_MNC).when(mTelephonyManager).getNetworkOperator(anyInt()); assertEquals("0119172345678", SmsNumberUtils.filterDestAddr(mPhone, "+91-7-234-5678")); } @Test @SmallTest public void testPcHomeIddCountryCodeAreaLocalNumberConversion() { // NP_NBPCD_HOMEIDD_CC_AREA_LOCAL tests assertEquals("01188671234567", SmsNumberUtils.filterDestAddr(mPhone, "+011886-7-1234567")); } @Test @SmallTest public void testHomeIddCountryCodeAreaLocalNumberConversion() { // NP_HOMEIDD_CC_AREA_LOCAL tests assertEquals("01188671234567", SmsNumberUtils.filterDestAddr(mPhone, "011886-7-1234567")); } @Test @SmallTest public void testLocalIddCountryCodeAreaLocalNumberConversion() { // NP_LOCALIDD_CC_AREA_LOCAL tests doReturn(TAIWAN_FET_MCC_MNC).when(mTelephonyManager).getNetworkOperator(anyInt()); assertEquals("01118581234567", SmsNumberUtils.filterDestAddr(mPhone, "002-1-858-1234567")); } @Test @SmallTest public void testIndiaLocalIddCountryCodeAreaLocalNumberConversion() { // NP_LOCALIDD_CC_AREA_LOCAL tests doReturn(INDIA_AIRTEL_MCC_MNC).when(mTelephonyManager).getNetworkOperator(anyInt()); assertEquals("01118581234567", SmsNumberUtils.filterDestAddr(mPhone, "010-1-858-1234567")); } @Test @SmallTest public void testJapanLocalIddCountryCodeAreaLocalNumberConversion() { // NP_LOCALIDD_CC_AREA_LOCAL tests doReturn(JAPAN_NTTDOCOMO_MCC_MNC).when(mTelephonyManager).getNetworkOperator(anyInt()); assertEquals("01118581234567", SmsNumberUtils.filterDestAddr(mPhone, "010-1-858-1234567")); } @Test @SmallTest public void testCountryCodeAreaLocalNumberConversion() { // NP_CC_AREA_LOCAL tests assertEquals("011886286281234", SmsNumberUtils.filterDestAddr(mPhone, "886-2-86281234")); } @Test @SmallTest public void testNaLocalNumberConversion() { // NP_NANP_LOCAL assertEquals("2345678", SmsNumberUtils.filterDestAddr(mPhone, "234-5678")); } @Test @SmallTest public void testNaAreaLocalNumberConversion() { // NP_NANP_AREA_LOCAL assertEquals("8582345678", SmsNumberUtils.filterDestAddr(mPhone, "858-234-5678")); } @Test @SmallTest public void testNaNddAreaLocalNumberConversion() { // NP_NANP_NDD_AREA_LOCAL assertEquals("18582345678", SmsNumberUtils.filterDestAddr(mPhone, "1-858-234-5678")); } @Test @SmallTest public void testNaLocalIddCcAreaLocalNumberConversion() { // NP_NANP_LOCALIDD_CC_AREA_LOCAL assertEquals("+18582345678", SmsNumberUtils.filterDestAddr(mPhone, "011-1-858-234-5678")); } @Test @SmallTest public void testNaPcHomeIddCcAreaLocalNumberConversion() { // NP_NANP_NBPCD_HOMEIDD_CC_AREA_LOCAL assertEquals("01118582345678", SmsNumberUtils.filterDestAddr(mPhone, "+011-1-858-234-5678")); } private static void logd(String s) { Log.d(TAG, s); } } No newline at end of file Loading
src/java/com/android/internal/telephony/SmsNumberUtils.java +16 −14 Original line number Diff line number Diff line Loading @@ -27,13 +27,14 @@ import android.database.SQLException; import android.telephony.PhoneNumberUtils; import android.telephony.TelephonyManager; import android.telephony.Rlog; import com.android.internal.telephony.HbpcdLookup.MccIdd; import com.android.internal.telephony.HbpcdLookup.MccLookup; /** * This class implements handle the MO SMS target address before sending. * This is special for VZW requirement. Follow the specificaitons of assisted dialing * This is special for VZW requirement. Follow the specifications of assisted dialing * of MO SMS while traveling on VZW CDMA, international CDMA or GSM markets. * {@hide} */ Loading Loading @@ -109,13 +110,13 @@ public class SmsNumberUtils { } /* Breaks the given number down and formats it according to the rules * for different number plans and differnt network. * for different number plans and different network. * * @param number destionation number which need to be format * @param number destination number which need to be format * @param activeMcc current network's mcc * @param networkType current network type * * @return the number after fromatting. * @return the number after formatting. */ private static String formatNumber(Context context, String number, String activeMcc, Loading Loading @@ -508,13 +509,13 @@ public class SmsNumberUtils { } else if (state == NP_NANP_NBPCD_HOMEIDD_CC_AREA_LOCAL) { numberPlanType = "NP_NANP_NBPCD_HOMEIDD_CC_AREA_LOCAL"; } else if (state == NP_NBPCD_HOMEIDD_CC_AREA_LOCAL) { numberPlanType = "NP_NBPCD_IDD_CC_AREA_LOCAL"; numberPlanType = "NP_NBPCD_HOMEIDD_CC_AREA_LOCAL"; } else if (state == NP_HOMEIDD_CC_AREA_LOCAL) { numberPlanType = "NP_IDD_CC_AREA_LOCAL"; numberPlanType = "NP_HOMEIDD_CC_AREA_LOCAL"; } else if (state == NP_NBPCD_CC_AREA_LOCAL) { numberPlanType = "NP_NBPCD_CC_AREA_LOCAL"; } else if (state == NP_LOCALIDD_CC_AREA_LOCAL) { numberPlanType = "NP_IDD_CC_AREA_LOCAL"; numberPlanType = "NP_LOCALIDD_CC_AREA_LOCAL"; } else if (state == NP_CC_AREA_LOCAL) { numberPlanType = "NP_CC_AREA_LOCAL"; } else { Loading @@ -534,7 +535,8 @@ public class SmsNumberUtils { return destAddr; } final String networkOperator = TelephonyManager.getDefault().getNetworkOperator(); final String networkOperator = TelephonyManager.from(phone.getContext()). getNetworkOperator(phone.getSubId()); String result = null; if (needToConvert(phone)) { Loading @@ -559,11 +561,11 @@ public class SmsNumberUtils { */ private static int getNetworkType(Phone phone) { int networkType = -1; int phoneType = TelephonyManager.getDefault().getPhoneType(); int phoneType = phone.getPhoneType(); if (phoneType == TelephonyManager.PHONE_TYPE_GSM) { if (phoneType == PhoneConstants.PHONE_TYPE_GSM) { networkType = GSM_UMTS_NETWORK; } else if (phoneType == TelephonyManager.PHONE_TYPE_CDMA) { } else if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) { if (isInternationalRoaming(phone)) { networkType = CDMA_ROAMING_NETWORK; } else { Loading @@ -577,9 +579,9 @@ public class SmsNumberUtils { } private static boolean isInternationalRoaming(Phone phone) { String operatorIsoCountry = TelephonyManager.getDefault().getNetworkCountryIsoForPhone( phone.getPhoneId()); String simIsoCountry = TelephonyManager.getDefault().getSimCountryIsoForPhone( String operatorIsoCountry = TelephonyManager.from(phone.getContext()). getNetworkCountryIsoForPhone(phone.getPhoneId()); String simIsoCountry = TelephonyManager.from(phone.getContext()).getSimCountryIsoForPhone( phone.getPhoneId()); boolean internationalRoaming = !TextUtils.isEmpty(operatorIsoCountry) && !TextUtils.isEmpty(simIsoCountry) Loading
tests/telephonytests/src/com/android/internal/telephony/ServiceStateTrackerTest.java +0 −22 Original line number Diff line number Diff line Loading @@ -236,28 +236,6 @@ public class ServiceStateTrackerTest { assertEquals(SimulatedCommands.FAKE_LONG_NAME, b.getString(TelephonyIntents.EXTRA_PLMN)); } @Test @MediumTest public void testNITZupdate() { doReturn(0x02).when(mSimRecords).getDisplayRule(anyString()); sst.sendMessage(sst.obtainMessage(ServiceStateTracker.EVENT_NITZ_TIME, new AsyncResult(null, new Object[]{"16/01/22,23:24:44-32,00", Long.valueOf(41824)}, null))); waitForMs(750); ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class); verify(mContextFixture.getTestDouble(), times(4)). sendStickyBroadcastAsUser(intentArgumentCaptor.capture(), eq(UserHandle.ALL)); Intent intent = intentArgumentCaptor.getAllValues().get(1); assertEquals(intent.getAction(), TelephonyIntents.ACTION_NETWORK_SET_TIMEZONE); assertEquals(Intent.FLAG_RECEIVER_REPLACE_PENDING, intent.getFlags()); assertEquals(AMERICA_LA_TIME_ZONE, intent.getExtras().getString(KEY_TIME_ZONE)); } @Test @MediumTest public void testCellInfoList() { Loading
tests/telephonytests/src/com/android/internal/telephony/SmsNumberUtilsTest.java 0 → 100644 +257 −0 Original line number Diff line number Diff line /* * Copyright (C) 2015 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.database.Cursor; import android.database.MatrixCursor; import android.net.Uri; import android.telephony.TelephonyManager; import android.test.mock.MockContentProvider; import android.test.mock.MockContentResolver; import android.test.suitebuilder.annotation.SmallTest; import android.util.Log; import org.mockito.MockitoAnnotations; import java.util.Arrays; import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.doReturn; import static org.junit.Assert.*; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; public class SmsNumberUtilsTest { private static final String TAG = "SmsNumberUtilsTest"; private static final String TMO_MCC_MNC = "310260"; private static final String TAIWAN_FET_MCC_MNC = "46602"; private static final String INDIA_AIRTEL_MCC_MNC = "40553"; private static final String JAPAN_NTTDOCOMO_MCC_MNC = "44020"; private TelephonyManager mTelephonyManager; // Simulate partial packages/providers/TelephonyProvider/res/xml/hbpcd_lookup_tables.xml public class HbpcdContentProvider extends MockContentProvider { public HbpcdContentProvider() {} @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { logd("HbpcdContentProvider: query"); logd(" uri = " + uri); logd(" projection = " + Arrays.toString(projection)); logd(" selection = " + selection); logd(" selectionArgs = " + Arrays.toString(selectionArgs)); logd(" sortOrder = " + sortOrder); if (uri.compareTo(HbpcdLookup.MccIdd.CONTENT_URI) == 0) { if (projection.length == 2 && projection[0].equals(HbpcdLookup.MccIdd.IDD) && projection[1].equals(HbpcdLookup.MccIdd.MCC) && selectionArgs.length == 1) { MatrixCursor mc = new MatrixCursor( new String[]{HbpcdLookup.MccIdd.IDD}); switch (Integer.valueOf(selectionArgs[0])) { case 310: mc.addRow(new Object[]{"011"}); // US IDD code break; case 466: mc.addRow(new Object[]{"002"}); // Taiwan IDD code break; case 440: mc.addRow(new Object[]{"010"}); // Japan IDD code break; case 405: mc.addRow(new Object[]{"010"}); // India IDD code break; default: logd("Unhandled MCC" + Integer.valueOf(selectionArgs[0])); } return mc; } else { logd("Unhandled IDD look up request."); } } else if (uri.compareTo(HbpcdLookup.MccLookup.CONTENT_URI) == 0) { if (projection.length == 1 && projection[0].equals( HbpcdLookup.MccLookup.COUNTRY_CODE) && selection == null && selectionArgs == null) { MatrixCursor mccCursor = new MatrixCursor( new String[]{HbpcdLookup.MccLookup.COUNTRY_CODE}); mccCursor.addRow(new Object[]{"1"}); mccCursor.addRow(new Object[]{"886"}); mccCursor.addRow(new Object[]{"81"}); mccCursor.addRow(new Object[]{"91"}); return mccCursor; } else { logd("Unhandled mcc look up request"); } } else { logd("Unknown URI: " + uri); } return null; } } @Mock GsmCdmaPhone mPhone; ContextFixture mContextFixture; HbpcdContentProvider mHbpcdContentProvider; @Before public void setUp() throws Exception { logd("SmsNumberUtilsTest +Setup!"); MockitoAnnotations.initMocks(this); mContextFixture = new ContextFixture(); mHbpcdContentProvider = new HbpcdContentProvider(); mTelephonyManager = TelephonyManager.from(mContextFixture.getTestDouble()); doReturn(TMO_MCC_MNC).when(mTelephonyManager).getNetworkOperator(anyInt()); doReturn(PhoneConstants.PHONE_TYPE_GSM).when(mPhone).getPhoneType(); ((MockContentResolver) mContextFixture.getTestDouble().getContentResolver()) .addProvider(HbpcdLookup.MccIdd.CONTENT_URI.getAuthority(), mHbpcdContentProvider); mContextFixture.putStringArrayResource( com.android.internal.R.array.config_sms_convert_destination_number_support, new String[]{"true"}); doReturn(mContextFixture.getTestDouble()).when(mPhone).getContext(); logd("SmsNumberUtilsTest -Setup!"); } @Test @SmallTest public void testInvalidNumberConversion() { assertEquals("123", SmsNumberUtils.filterDestAddr(mPhone, "123")); } @Test @SmallTest public void testNaPcCountryCodeAreaLocalNumberConversion() { // NP_NANP_NBPCD_CC_AREA_LOCAL tests doReturn(PhoneConstants.PHONE_TYPE_CDMA).when(mPhone).getPhoneType(); assertEquals("18583420022", SmsNumberUtils.filterDestAddr(mPhone, "+1-858-342-0022")); } @Test @SmallTest public void testPcCountryCodeAreaLocalNumberConversion() { // NP_NBPCD_CC_AREA_LOCAL tests assertEquals("01188671234567", SmsNumberUtils.filterDestAddr(mPhone, "+886-7-1234567")); } @Test @SmallTest public void testIndiaPcCountryCodeAreaLocalNumberConversion() { // NP_NBPCD_CC_AREA_LOCAL tests doReturn(INDIA_AIRTEL_MCC_MNC).when(mTelephonyManager).getNetworkOperator(anyInt()); assertEquals("0119172345678", SmsNumberUtils.filterDestAddr(mPhone, "+91-7-234-5678")); } @Test @SmallTest public void testPcHomeIddCountryCodeAreaLocalNumberConversion() { // NP_NBPCD_HOMEIDD_CC_AREA_LOCAL tests assertEquals("01188671234567", SmsNumberUtils.filterDestAddr(mPhone, "+011886-7-1234567")); } @Test @SmallTest public void testHomeIddCountryCodeAreaLocalNumberConversion() { // NP_HOMEIDD_CC_AREA_LOCAL tests assertEquals("01188671234567", SmsNumberUtils.filterDestAddr(mPhone, "011886-7-1234567")); } @Test @SmallTest public void testLocalIddCountryCodeAreaLocalNumberConversion() { // NP_LOCALIDD_CC_AREA_LOCAL tests doReturn(TAIWAN_FET_MCC_MNC).when(mTelephonyManager).getNetworkOperator(anyInt()); assertEquals("01118581234567", SmsNumberUtils.filterDestAddr(mPhone, "002-1-858-1234567")); } @Test @SmallTest public void testIndiaLocalIddCountryCodeAreaLocalNumberConversion() { // NP_LOCALIDD_CC_AREA_LOCAL tests doReturn(INDIA_AIRTEL_MCC_MNC).when(mTelephonyManager).getNetworkOperator(anyInt()); assertEquals("01118581234567", SmsNumberUtils.filterDestAddr(mPhone, "010-1-858-1234567")); } @Test @SmallTest public void testJapanLocalIddCountryCodeAreaLocalNumberConversion() { // NP_LOCALIDD_CC_AREA_LOCAL tests doReturn(JAPAN_NTTDOCOMO_MCC_MNC).when(mTelephonyManager).getNetworkOperator(anyInt()); assertEquals("01118581234567", SmsNumberUtils.filterDestAddr(mPhone, "010-1-858-1234567")); } @Test @SmallTest public void testCountryCodeAreaLocalNumberConversion() { // NP_CC_AREA_LOCAL tests assertEquals("011886286281234", SmsNumberUtils.filterDestAddr(mPhone, "886-2-86281234")); } @Test @SmallTest public void testNaLocalNumberConversion() { // NP_NANP_LOCAL assertEquals("2345678", SmsNumberUtils.filterDestAddr(mPhone, "234-5678")); } @Test @SmallTest public void testNaAreaLocalNumberConversion() { // NP_NANP_AREA_LOCAL assertEquals("8582345678", SmsNumberUtils.filterDestAddr(mPhone, "858-234-5678")); } @Test @SmallTest public void testNaNddAreaLocalNumberConversion() { // NP_NANP_NDD_AREA_LOCAL assertEquals("18582345678", SmsNumberUtils.filterDestAddr(mPhone, "1-858-234-5678")); } @Test @SmallTest public void testNaLocalIddCcAreaLocalNumberConversion() { // NP_NANP_LOCALIDD_CC_AREA_LOCAL assertEquals("+18582345678", SmsNumberUtils.filterDestAddr(mPhone, "011-1-858-234-5678")); } @Test @SmallTest public void testNaPcHomeIddCcAreaLocalNumberConversion() { // NP_NANP_NBPCD_HOMEIDD_CC_AREA_LOCAL assertEquals("01118582345678", SmsNumberUtils.filterDestAddr(mPhone, "+011-1-858-234-5678")); } private static void logd(String s) { Log.d(TAG, s); } } No newline at end of file