summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPeter Ljungdahl <peter.ljungdahl@sonymobile.com>2015-11-16 13:03:23 +0100
committerJohan Redestig <johan.redestig@sonymobile.com>2016-11-10 09:18:47 +0100
commit2f9d2a5054c643d29168c0090dbed3da4695c019 (patch)
tree16d32b569f2113b1699190ab9d3d23527638630a /src
parent930462e09fe56df3475990cf1ac6e18f71c1885c (diff)
downloadandroid_packages_apps_CarrierConfig-2f9d2a5054c643d29168c0090dbed3da4695c019.tar.gz
android_packages_apps_CarrierConfig-2f9d2a5054c643d29168c0090dbed3da4695c019.tar.bz2
android_packages_apps_CarrierConfig-2f9d2a5054c643d29168c0090dbed3da4695c019.zip
Add IMSI and SPN regexp filtering for MVNO support
The filtering criterias for selecting carrier configurations are extended to cover IMSI. The reason for this to support MVNO configuration for IMSI ranges (i.e. when the only way to identify a MVNO is by the IMSI) The xml arguments for IMSI and SPN can be designed as regular expressions in order to add flexibility. Some operators do not have SPN defined on there SIM card, but the MVNOs in their network might have. This is indicated in the xml by setting the spn argument to "null". Bug: 32398239 Test: Verified on target with MVNO configs. Change-Id: Ib4fd87fe484a50fd808fbe9843061ab894703531
Diffstat (limited to 'src')
-rw-r--r--src/com/android/carrierconfig/DefaultCarrierConfigService.java63
1 files changed, 62 insertions, 1 deletions
diff --git a/src/com/android/carrierconfig/DefaultCarrierConfigService.java b/src/com/android/carrierconfig/DefaultCarrierConfigService.java
index 9081821..c4c6431 100644
--- a/src/com/android/carrierconfig/DefaultCarrierConfigService.java
+++ b/src/com/android/carrierconfig/DefaultCarrierConfigService.java
@@ -7,6 +7,7 @@ import android.service.carrier.CarrierIdentifier;
import android.service.carrier.CarrierService;
import android.telephony.CarrierConfigManager;
import android.telephony.TelephonyManager;
+import android.text.TextUtils;
import android.util.Log;
import org.xmlpull.v1.XmlPullParser;
@@ -18,6 +19,8 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import com.android.internal.util.FastXmlSerializer;
@@ -33,6 +36,8 @@ import com.android.internal.util.FastXmlSerializer;
*/
public class DefaultCarrierConfigService extends CarrierService {
+ private static final String SPN_EMPTY_MATCH = "null";
+
private static final String TAG = "DefaultCarrierConfigService";
private XmlPullParserFactory mFactory;
@@ -154,10 +159,17 @@ public class DefaultCarrierConfigService extends CarrierService {
* <li>gid1: {@link CarrierIdentifier#getGid1}</li>
* <li>gid2: {@link CarrierIdentifier#getGid2}</li>
* <li>spn: {@link CarrierIdentifier#getSpn}</li>
+ * <li>imsi: {@link CarrierIdentifier#getImsi}</li>
* <li>device: {@link Build.DEVICE}</li>
* </ul>
* </p>
*
+ * <p>
+ * The attributes imsi and spn can be expressed as regexp to filter on patterns.
+ * The spn attribute can be set to the string "null" to allow matching against a SIM
+ * with no spn set.
+ * </p>
+ *
* @param parser an XmlPullParser pointing at a START_TAG with the attributes to check.
* @param id the carrier details to check against.
* @return false if any XML attribute does not match the corresponding value.
@@ -181,7 +193,10 @@ public class DefaultCarrierConfigService extends CarrierService {
result = result && value.equals(id.getGid2());
break;
case "spn":
- result = result && value.equals(id.getSpn());
+ result = result && matchOnSP(value, id);
+ break;
+ case "imsi":
+ result = result && matchOnImsi(value, id);
break;
case "device":
result = result && value.equals(Build.DEVICE);
@@ -194,4 +209,50 @@ public class DefaultCarrierConfigService extends CarrierService {
}
return result;
}
+
+ /**
+ * Check to see if the IMSI expression from the XML matches the IMSI of the
+ * Carrier.
+ *
+ * @param xmlImsi IMSI expression fetched from the resource XML
+ * @param id Id of the evaluated CarrierIdentifier
+ * @return true if the XML IMSI matches the IMSI of CarrierIdentifier, false
+ * otherwise.
+ */
+ static boolean matchOnImsi(String xmlImsi, CarrierIdentifier id) {
+ boolean matchFound = false;
+
+ String currentImsi = id.getImsi();
+ // If we were able to retrieve current IMSI, see if it matches.
+ if (currentImsi != null) {
+ Pattern imsiPattern = Pattern.compile(xmlImsi);
+ Matcher matcher = imsiPattern.matcher(currentImsi);
+ matchFound = matcher.matches();
+ }
+ return matchFound;
+ }
+
+ /**
+ * Check to see if the service provider name expression from the XML matches the
+ * CarrierIdentifier.
+ *
+ * @param xmlSP SP expression fetched from the resource XML
+ * @param id Id of the evaluated CarrierIdentifier
+ * @return true if the XML SP matches the phone's SP, false otherwise.
+ */
+ static boolean matchOnSP(String xmlSP, CarrierIdentifier id) {
+ boolean matchFound = false;
+
+ String currentSP = id.getSpn();
+ if (SPN_EMPTY_MATCH.equalsIgnoreCase(xmlSP)) {
+ if (TextUtils.isEmpty(currentSP)) {
+ matchFound = true;
+ }
+ } else if (currentSP != null) {
+ Pattern spPattern = Pattern.compile(xmlSP);
+ Matcher matcher = spPattern.matcher(currentSP);
+ matchFound = matcher.matches();
+ }
+ return matchFound;
+ }
}