summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchen xu <fionaxu@google.com>2018-11-27 22:19:54 -0800
committerchen xu <fionaxu@google.com>2018-12-04 14:12:41 -0800
commitd1830391a0f22449d9b1e9bd3645b8e66e8a3b72 (patch)
tree11293fef0c768b8b84478a5fe7ec122fdea6674b
parenta75cafbf1597cb3d9f489062145cbe71816769f8 (diff)
downloadandroid_packages_apps_CarrierConfig-d1830391a0f22449d9b1e9bd3645b8e66e8a3b72.tar.gz
android_packages_apps_CarrierConfig-d1830391a0f22449d9b1e9bd3645b8e66e8a3b72.tar.bz2
android_packages_apps_CarrierConfig-d1830391a0f22449d9b1e9bd3645b8e66e8a3b72.zip
test to enforce no mccmnc.xml if there is a matching carrier id
Add unit test to enforce the rule that carrierid.xml is preferred. Otherwise people who used to add mccmnc.xml might keep doing so even there is a carrierid.xml. Bug: 110559381 Test: carrierconfigtest Change-Id: Iec84a729e7df031d897cec5999276a81938ef886
-rw-r--r--assets/carrier_config_mccmnc_311480.xml152
-rw-r--r--tests/src/com/android/carrierconfig/CarrierConfigTest.java140
2 files changed, 134 insertions, 158 deletions
diff --git a/assets/carrier_config_mccmnc_311480.xml b/assets/carrier_config_mccmnc_311480.xml
index b962330..1c2f22e 100644
--- a/assets/carrier_config_mccmnc_311480.xml
+++ b/assets/carrier_config_mccmnc_311480.xml
@@ -1,157 +1,5 @@
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<carrier_config_list>
- <carrier_config>
- <boolean name="rtt_supported_bool" value="true" />
- <boolean name="carrier_volte_provisioned_bool" value="true" />
- <boolean name="allow_hold_in_ims_call" value="false" />
- <boolean name="world_mode_enabled_bool" value="true" />
- <boolean name="sms_requires_destination_number_conversion_bool" value="true" />
- <boolean name="mdn_is_additional_voicemail_number_bool" value="true" />
- <boolean name="carrier_vt_available_bool" value="true" />
- <boolean name="support_downgrade_vt_to_audio_bool" value="false" />
- <boolean name="notify_handover_video_from_wifi_to_lte_bool" value="true" />
- <boolean name="notify_handover_video_from_lte_to_wifi_bool" value="true" />
- <boolean name="carrier_allow_turnoff_ims_bool" value="false" />
- <boolean name="carrier_volte_provisioning_required_bool" value="true" />
- <boolean name="treat_downgraded_video_calls_as_video_calls_bool" value="true" />
- <boolean name="drop_video_call_when_answering_audio_call_bool" value="true" />
- <boolean name="operator_selection_expand_bool" value="true" />
- <int name="aliasMinChars" value="2" />
- <boolean name="dtmf_type_enabled_bool" value="true" />
- <int name="smsToMmsTextThreshold" value="7" />
- <boolean name="enabledTransID" value="true" />
- <boolean name="aliasEnabled" value="true" />
- <boolean name="voicemail_notification_persistent_bool" value="true" />
- <boolean name="allowAttachAudio" value="false" />
- <boolean name="support_swap_after_merge_bool" value="false" />
- <int name="recipientLimit" value="20" />
- <string name="uaProfTagName">Profile</string>
- <int name="aliasMaxChars" value="48" />
- <int name="maxImageHeight" value="1944" />
- <int name="lte_earfcns_rsrp_boost_int" value="6" />
- <string-array name="boosted_lte_earfcns_string_array" num="2">
- <item value="600-1199" />
- <item value="1950-2399" />
- </string-array>
- <boolean name="carrier_volte_available_bool" value="true" />
- <boolean name="support_pause_ims_video_calls_bool" value="true" />
- <int name="maxSubjectLength" value="80" />
- <string name="httpParams">x-up-calling-line-id: 1##LINE1NOCOUNTRYCODE##|X-VzW-MDN: 1##LINE1NOCOUNTRYCODE##</string>
- <string name="emailGatewayNumber">6245</string>
- <int name="maxMessageSize" value="1258291" />
- <boolean name="enableMMSReadReports" value="false" />
- <boolean name="prefer_2g_bool" value="false" />
- <int name="maxImageWidth" value="2592" />
- <int name="volte_replacement_rat_int" value="6" />
- <boolean name="enabledNotifyWapMMSC" value="true" />
- <boolean name="enableMultipartSMS" value="true" />
- <boolean name="allow_adding_apns_bool" value="false" />
- <boolean name="broadcast_emergency_call_state_changes_bool" value="true" />
- <string name="carrier_eri_file_name_string">eri_311480.xml</string>
- <boolean name="carrier_wfc_ims_available_bool" value="true" />
- <int name="carrier_default_wfc_ims_mode_int" value="1"/>
- <boolean name="treat_downgraded_video_calls_as_video_calls_bool" value="true" />
- <boolean name="drop_video_call_when_answering_audio_call_bool" value="true" />
- <boolean name="editable_wfc_mode_bool" value="false"/>
- <boolean name="editable_wfc_roaming_mode_bool" value="true"/>
- <boolean name="allow_merge_wifi_calls_when_vowifi_off_bool" value="false" />
- <boolean name="wifi_calls_can_be_hd_audio" value="false" />
- <boolean name="video_calls_can_be_hd_audio" value="false" />
- <boolean name="allow_add_call_during_video_call" value="false" />
- <boolean name="persist_lpp_mode_bool" value="true" />
- <string name="default_vm_number_string">*86</string>
- <string-array name="dial_string_replace_string_array" num="2">
- <item value="*611:+19085594899" />
- <item value="*86:+1MDN" />
- </string-array>
- <string-array name="carrier_data_call_permanent_failure_strings" num="14">
- <item value="OPERATOR_BARRED" />
- <item value="MISSING_UNKNOWN_APN" />
- <item value="UNKNOWN_PDP_ADDRESS_TYPE" />
- <item value="USER_AUTHENTICATION" />
- <item value="SERVICE_OPTION_NOT_SUPPORTED" />
- <item value="SERVICE_OPTION_NOT_SUBSCRIBED" />
- <item value="NSAPI_IN_USE" />
- <item value="ONLY_IPV4_ALLOWED" />
- <item value="ONLY_IPV6_ALLOWED" />
- <item value="RADIO_POWER_OFF" />
- <item value="TETHERED_CALL_ACTIVE" />
- <item value="RADIO_NOT_AVAILABLE" />
- <item value="UNACCEPTABLE_NETWORK_PARAMETER" />
- <item value="SIGNAL_LOST" />
- </string-array>
- <boolean name="carrier_promote_wfc_on_call_fail_bool" value="true" />
- <string-array name="ims_reasoninfo_mapping_string_array" num="10">
- <item value="332|simultaneous call limit has already been reached|1403" />
- <item value="332|Forbidden: Simultaneous Call Limit Has Already Been Reached|1403" />
- <item value="338|another device sent all devices busy response|1404" />
- <item value="501|call completion elsewhere|1014" />
- <item value="501|call has been pulled by another device|1016" />
- <item value="510|call has been pulled by another device|1016" />
- <item value="501|another device sent all devices busy response|1404" />
- <item value="510|another device sent all devices busy response|1404" />
- <item value="1014|call has been pulled by another device|1016" />
- <item value="*|Call is dropped due to Wi-Fi signal is degraded|1407" />
- </string-array>
- <boolean name="disable_severe_when_extreme_disabled_bool" value="false" />
- <boolean name="mmsCloseConnection" value="true"/>
- <boolean name="notify_vt_handover_to_wifi_failure_bool" value="true" />
- <int name="wfc_spn_format_idx_int" value="1" />
- <string-array name="filtered_cnap_names_string_array" num="2">
- <item value="WIRELESS CALLER" />
- <item value="UNKNOWN NAME" />
- </string-array>
- <string-array name="read_only_apn_fields_string_array" num="20">
- <item value="name" />
- <item value="proxy" />
- <item value="port" />
- <item value="user" />
- <item value="password" />
- <item value="server" />
- <item value="mmsc" />
- <item value="mmsproxy" />
- <item value="mmsport" />
- <item value="mcc" />
- <item value="mnc" />
- <item value="authtype" />
- <item value="type" />
- <item value="protocol" />
- <item value="roaming_protocol" />
- <item value="bearer" />
- <item value="bearer_bitmask" />
- <item value="carrier_enabled" />
- <item value="mvno_type" />
- <item value="mvno_match_data" />
- </string-array>
- <string-array name="carrier_metered_apn_types_strings" num="3">
- <item value="default" />
- <item value="dun" />
- <item value="supl" />
- </string-array>
- <string-array name="carrier_metered_roaming_apn_types_strings" num="4">
- <item value="default" />
- <item value="dun" />
- <item value="mms" />
- <item value="supl" />
- </string-array>
- <boolean name="is_ims_conference_size_enforced_bool" value="true"/>
- <int name="ims_conference_size_limit_int" value="5" />
- <boolean name="support_3gpp_call_forwarding_while_roaming_bool" value="false" />
- <string-array name="call_forwarding_blocks_while_roaming_string_array" num="2">
- <item value="*71" />
- <item value="*72" />
- </string-array>
- <boolean name="disable_voice_barring_notification_bool" value="true" />
- <boolean name="carrier_name_override_bool" value="true" />
- <string name="carrier_name_string">Verizon</string>
- <int-array name="lte_rsrp_thresholds_int_array" num="4">
- <item value="-115" /> <!-- SIGNAL_STRENGTH_POOR -->
- <item value="-105" /> <!-- SIGNAL_STRENGTH_MODERATE -->
- <item value="-95" /> <!-- SIGNAL_STRENGTH_GOOD -->
- <item value="-85" /> <!-- SIGNAL_STRENGTH_GREAT -->
- </int-array>
- <boolean name="show_apn_setting_cdma_bool" value="true" />
- </carrier_config>
<!-- Tracfone Vzw shows empty string as SPN -->
<carrier_config gid1="BA01270000000000">
<boolean name="carrier_name_override_bool" value="true" />
diff --git a/tests/src/com/android/carrierconfig/CarrierConfigTest.java b/tests/src/com/android/carrierconfig/CarrierConfigTest.java
index b1be375..7b1d8f7 100644
--- a/tests/src/com/android/carrierconfig/CarrierConfigTest.java
+++ b/tests/src/com/android/carrierconfig/CarrierConfigTest.java
@@ -1,11 +1,16 @@
package com.android.carrierconfig;
+import android.Manifest;
+import android.annotation.NonNull;
import android.content.Context;
import android.content.res.AssetManager;
import android.content.res.Resources;
+import android.database.Cursor;
import android.os.PersistableBundle;
+import android.provider.Telephony;
import android.service.carrier.CarrierIdentifier;
import android.telephony.CarrierConfigManager;
+import android.telephony.TelephonyManager;
import android.test.InstrumentationTestCase;
import android.util.Log;
@@ -13,7 +18,9 @@ import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
+import java.util.ArrayList;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import junit.framework.AssertionFailedError;
@@ -23,13 +30,15 @@ import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
public class CarrierConfigTest extends InstrumentationTestCase {
+ private static final String TAG = "CarrierConfigTest";
/**
* Iterate over all XML files in assets/ and ensure they parse without error.
*/
public void testAllFilesParse() {
forEachConfigXml(new ParserChecker() {
- public void check(XmlPullParser parser) throws XmlPullParserException, IOException {
+ public void check(XmlPullParser parser, String mccmnc) throws XmlPullParserException,
+ IOException {
PersistableBundle b = DefaultCarrierConfigService.readConfigFromXml(parser,
new CarrierIdentifier("001", "001", "Test", "001001123456789", "", ""));
assertNotNull("got null bundle", b);
@@ -43,7 +52,8 @@ public class CarrierConfigTest extends InstrumentationTestCase {
*/
public void testFilterValidAttributes() {
forEachConfigXml(new ParserChecker() {
- public void check(XmlPullParser parser) throws XmlPullParserException, IOException {
+ public void check(XmlPullParser parser, String mccmnc) throws XmlPullParserException,
+ IOException {
int event;
while (((event = parser.next()) != XmlPullParser.END_DOCUMENT)) {
if (event == XmlPullParser.START_TAG
@@ -74,13 +84,79 @@ public class CarrierConfigTest extends InstrumentationTestCase {
}
/**
+ * Check that XML files named after mccmnc are those without matching carrier id.
+ * If there is a matching carrier id, all configurations should move to carrierid.xml which
+ * has a higher matching priority than mccmnc.xml
+ */
+ public void testCarrierConfigFileNaming() {
+ forEachConfigXml(new ParserChecker() {
+ public void check(XmlPullParser parser, String mccmnc) throws XmlPullParserException,
+ IOException {
+ if (mccmnc == null) {
+ // only check file named after mccmnc
+ return;
+ }
+ int event;
+ while (((event = parser.next()) != XmlPullParser.END_DOCUMENT)) {
+ if (event == XmlPullParser.START_TAG
+ && "carrier_config".equals(parser.getName())) {
+ String mcc = null;
+ String mnc = null;
+ String spn = null;
+ String gid1 = null;
+ String gid2 = null;
+ String imsi = null;
+ for (int i = 0; i < parser.getAttributeCount(); ++i) {
+ String attribute = parser.getAttributeName(i);
+ switch (attribute) {
+ case "mcc":
+ mcc = parser.getAttributeValue(i);
+ break;
+ case "mnc":
+ mnc = parser.getAttributeValue(i);
+ break;
+ case "gid1":
+ gid1 = parser.getAttributeValue(i);
+ break;
+ case "gid2":
+ gid2 = parser.getAttributeValue(i);
+ break;
+ case "spn":
+ spn = parser.getAttributeValue(i);
+ break;
+ case "imsi":
+ imsi = parser.getAttributeValue(i);
+ break;
+ default:
+ fail("Unknown attribute '" + attribute
+ + "' at " + parser.getPositionDescription());
+ break;
+ }
+ }
+ mcc = (mcc != null) ? mcc : mccmnc.substring(0, 3);
+ mnc = (mnc != null) ? mnc : mccmnc.substring(3);
+ // check if there is a valid carrier id
+ int carrierId = getCarrierId(getInstrumentation().getTargetContext(),
+ new CarrierIdentifier(mcc, mnc, spn, imsi, gid1, gid2));
+ if (carrierId != TelephonyManager.UNKNOWN_CARRIER_ID) {
+ fail("unexpected carrier_config_mccmnc.xml with matching carrier id: "
+ + carrierId + ", please move to carrier_config_carrierid.xml");
+ }
+ }
+ }
+ }
+ });
+ }
+
+ /**
* Tests that the variable names in each XML file match actual keys in CarrierConfigManager.
*/
public void testVariableNames() {
final Set<String> varXmlNames = getCarrierConfigXmlNames();
// organize them into sets by type or unknown
forEachConfigXml(new ParserChecker() {
- public void check(XmlPullParser parser) throws XmlPullParserException, IOException {
+ public void check(XmlPullParser parser, String mccmnc) throws XmlPullParserException,
+ IOException {
int event;
while (((event = parser.next()) != XmlPullParser.END_DOCUMENT)) {
if (event == XmlPullParser.START_TAG) {
@@ -128,7 +204,7 @@ public class CarrierConfigTest extends InstrumentationTestCase {
* {@link #check} should {@link #fail} if the test does not pass.
*/
private interface ParserChecker {
- void check(XmlPullParser parser) throws XmlPullParserException, IOException;
+ void check(XmlPullParser parser, String mccmnc) throws XmlPullParserException, IOException;
}
/**
@@ -136,6 +212,7 @@ public class CarrierConfigTest extends InstrumentationTestCase {
*/
private void forEachConfigXml(ParserChecker checker) {
AssetManager assetMgr = getInstrumentation().getTargetContext().getAssets();
+ String mccmnc = null;
try {
String[] files = assetMgr.list("");
assertNotNull("failed to list files", files);
@@ -143,12 +220,16 @@ public class CarrierConfigTest extends InstrumentationTestCase {
for (String fileName : files) {
try {
if (!fileName.startsWith("carrier_config_")) continue;
+ if (fileName.startsWith("carrier_config_mccmnc_")) {
+ mccmnc = fileName.substring("carrier_config_mccmnc_".length(),
+ fileName.indexOf(".xml"));
+ }
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser parser = factory.newPullParser();
parser.setInput(assetMgr.open(fileName), "utf-8");
- checker.check(parser);
+ checker.check(parser, mccmnc);
} catch (Throwable e) {
throw new AssertionError("Problem in " + fileName + ": " + e.getMessage(), e);
@@ -157,7 +238,7 @@ public class CarrierConfigTest extends InstrumentationTestCase {
// Check vendor.xml too
try {
Resources res = getInstrumentation().getTargetContext().getResources();
- checker.check(res.getXml(R.xml.vendor));
+ checker.check(res.getXml(R.xml.vendor), mccmnc);
} catch (Throwable e) {
throw new AssertionError("Problem in vendor.xml: " + e.getMessage(), e);
}
@@ -189,4 +270,51 @@ public class CarrierConfigTest extends InstrumentationTestCase {
assertTrue("Found zero keys", varXmlNames.size() > 0);
return varXmlNames;
}
+
+ // helper function to get carrier id from carrierIdentifier
+ private int getCarrierId(@NonNull Context context,
+ @NonNull CarrierIdentifier carrierIdentifier) {
+ try {
+ getInstrumentation().getUiAutomation().adoptShellPermissionIdentity(
+ Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
+ List<String> args = new ArrayList<>();
+ args.add(carrierIdentifier.getMcc() + carrierIdentifier.getMnc());
+ if (carrierIdentifier.getGid1() != null) {
+ args.add(carrierIdentifier.getGid1());
+ }
+ if (carrierIdentifier.getGid2() != null) {
+ args.add(carrierIdentifier.getGid2());
+ }
+ if (carrierIdentifier.getImsi() != null) {
+ args.add(carrierIdentifier.getImsi());
+ }
+ if (carrierIdentifier.getSpn() != null) {
+ args.add(carrierIdentifier.getSpn());
+ }
+ try (Cursor cursor = context.getContentResolver().query(
+ Telephony.CarrierId.All.CONTENT_URI,
+ /* projection */ null,
+ /* selection */ Telephony.CarrierId.All.MCCMNC + "=? AND "
+ + Telephony.CarrierId.All.GID1
+ + ((carrierIdentifier.getGid1() == null) ? " is NULL" : "=?") + " AND "
+ + Telephony.CarrierId.All.GID2
+ + ((carrierIdentifier.getGid2() == null) ? " is NULL" : "=?") + " AND "
+ + Telephony.CarrierId.All.IMSI_PREFIX_XPATTERN
+ + ((carrierIdentifier.getImsi() == null) ? " is NULL" : "=?") + " AND "
+ + Telephony.CarrierId.All.SPN
+ + ((carrierIdentifier.getSpn() == null) ? " is NULL" : "=?"),
+ /* selectionArgs */ args.toArray(new String[args.size()]), null)) {
+ if (cursor != null) {
+ while (cursor.moveToNext()) {
+ return cursor.getInt(cursor.getColumnIndex(Telephony.CarrierId.CARRIER_ID));
+ }
+ }
+ }
+ } catch (SecurityException e) {
+ fail("Should be able to access APIs protected by a permission apps cannot get");
+ } finally {
+ getInstrumentation().getUiAutomation().dropShellPermissionIdentity();
+ }
+ return TelephonyManager.UNKNOWN_CARRIER_ID;
+ }
}