summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Kondik <shade@chemlab.org>2012-05-21 23:24:06 -0700
committerSteve Kondik <steve@cyngn.com>2015-03-23 13:38:36 -0700
commit6aefb429bf93806d6b80e77cbe003107d78eb0f0 (patch)
treebecd8dd4f67e83fa6decec1b62213198620ce196
parentdc21d9bbf3af6aab2a3581294cebc5a4af7db00f (diff)
downloadandroid_packages_providers_TelephonyProvider-6aefb429bf93806d6b80e77cbe003107d78eb0f0.tar.gz
android_packages_providers_TelephonyProvider-6aefb429bf93806d6b80e77cbe003107d78eb0f0.tar.bz2
android_packages_providers_TelephonyProvider-6aefb429bf93806d6b80e77cbe003107d78eb0f0.zip
telephony: Add support for choosing a default APN
* Sometimes, the standard method of choosing the "first" available APN is not what we want. Consider the case where a certain provider has both a "normal" APN and an LTE APN. The LTE APN is what we want, but it's not chosen. * Add a new overlayable value "config_preferred_apn" to handle this. A device can override this. The format is "apn,mcc,mnc". Change-Id: Ia6ca4159491bee15b3f18ad7ad524b8b0ffce2f2
-rw-r--r--res/values/config.xml22
-rw-r--r--src/com/android/providers/telephony/TelephonyProvider.java48
2 files changed, 69 insertions, 1 deletions
diff --git a/res/values/config.xml b/res/values/config.xml
new file mode 100644
index 0000000..a8807c6
--- /dev/null
+++ b/res/values/config.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 The CyanogenMod 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.
+-->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+
+ <!-- The preferred APN to use, in the format name,mcc,mnc
+ Leave empty to choose automatically. -->
+ <string name="config_preferred_apn"></string>
+</resources>
diff --git a/src/com/android/providers/telephony/TelephonyProvider.java b/src/com/android/providers/telephony/TelephonyProvider.java
index 5e2ed90..90be05d 100644
--- a/src/com/android/providers/telephony/TelephonyProvider.java
+++ b/src/com/android/providers/telephony/TelephonyProvider.java
@@ -39,6 +39,7 @@ import android.os.UserHandle;
import android.provider.Telephony;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
+import android.text.TextUtils;
import android.util.Log;
import android.util.Xml;
@@ -252,6 +253,24 @@ public class TelephonyProvider extends ContentProvider
if (DBG) log("dbh.createCarriersTable:-");
}
+ private int getDefaultPreferredApnId(SQLiteDatabase db) {
+ int id = -1;
+ String configPref = mContext.getResources().getString(R.string.config_preferred_apn, "");
+ if (!TextUtils.isEmpty(configPref)) {
+ String[] s = configPref.split(",");
+ if (s.length == 3) {
+ Cursor c = db.query("carriers", new String[] { "_id" },
+ "apn='" + s[0] + "' AND mcc='" + s[1] + "' AND mnc='" + s[2] + "'",
+ null, null, null, null);
+ if (c.moveToFirst()) {
+ id = c.getInt(0);
+ }
+ c.close();
+ }
+ }
+ return id;
+ }
+
private void initDatabase(SQLiteDatabase db) {
if (VDBG) log("dbh.initDatabase:+ db=" + db);
// Read internal APNS data
@@ -681,7 +700,33 @@ public class TelephonyProvider extends ContentProvider
private long getPreferredApnId(int subId) {
SharedPreferences sp = getContext().getSharedPreferences(
PREF_FILE + subId, Context.MODE_PRIVATE);
- return sp.getLong(COLUMN_APN_ID, -1);
+ long id = sp.getLong(COLUMN_APN_ID, -1);
+ if (id == -1) {
+ id = getDefaultPreferredApnId();
+ if (id > -1) {
+ setPreferredApnId(id, subId);
+ }
+ }
+ return id;
+ }
+
+ private long getDefaultPreferredApnId() {
+ long id = -1;
+ String configPref = getContext().getResources().getString(R.string.config_preferred_apn, "");
+ if (!TextUtils.isEmpty(configPref)) {
+ String[] s = configPref.split(",");
+ if (s.length == 3) {
+ Cursor c = mOpenHelper.getReadableDatabase().query("carriers", new String[] { "_id" },
+ "apn='" + s[0] + "' AND mcc='" + s[1] + "' AND mnc='" + s[2] + "'",
+ null, null, null, null);
+ if (c.moveToFirst()) {
+ id = c.getLong(0);
+ }
+ c.close();
+ }
+ }
+ Log.d(TAG, "Preferred APN: " + id);
+ return id;
}
@Override
@@ -1211,6 +1256,7 @@ public class TelephonyProvider extends ContentProvider
}
setPreferredApnId((long)-1, subId);
mOpenHelper.initDatabase(db);
+ setPreferredApnId(getDefaultPreferredApnId(), subId);
}
/**