The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 1 | /* //device/content/providers/telephony/TelephonyProvider.java |
| 2 | ** |
| 3 | ** Copyright 2006, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | package com.android.providers.telephony; |
| 19 | |
Jaikumar Ganesh | 8e1a4f9 | 2009-10-26 13:07:37 -0700 | [diff] [blame] | 20 | import android.content.ContentProvider; |
| 21 | import android.content.ContentUris; |
| 22 | import android.content.ContentValues; |
| 23 | import android.content.Context; |
| 24 | import android.content.SharedPreferences; |
| 25 | import android.content.UriMatcher; |
Shishir Agrawal | acf787b | 2014-07-14 17:13:51 -0700 | [diff] [blame] | 26 | import android.content.pm.PackageManager; |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 27 | import android.content.res.Resources; |
| 28 | import android.content.res.XmlResourceParser; |
| 29 | import android.database.Cursor; |
jewon.lee | 4167fcc | 2013-01-17 13:10:37 +0900 | [diff] [blame] | 30 | import android.database.SQLException; |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 31 | import android.database.sqlite.SQLiteDatabase; |
Wink Saville | 6de1027 | 2014-06-22 07:38:43 -0700 | [diff] [blame] | 32 | import android.database.sqlite.SQLiteException; |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 33 | import android.database.sqlite.SQLiteOpenHelper; |
| 34 | import android.database.sqlite.SQLiteQueryBuilder; |
| 35 | import android.net.Uri; |
Shishir Agrawal | acf787b | 2014-07-14 17:13:51 -0700 | [diff] [blame] | 36 | import android.os.Binder; |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 37 | import android.os.Environment; |
Amith Yamasani | 2708517 | 2014-11-06 09:01:20 -0800 | [diff] [blame] | 38 | import android.os.UserHandle; |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 39 | import android.provider.Telephony; |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 40 | import android.telephony.SubscriptionManager; |
| 41 | import android.telephony.TelephonyManager; |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 42 | import android.util.Log; |
| 43 | import android.util.Xml; |
Jaikumar Ganesh | 8e1a4f9 | 2009-10-26 13:07:37 -0700 | [diff] [blame] | 44 | |
Wink Saville | d7c9350 | 2011-06-04 07:17:01 -0700 | [diff] [blame] | 45 | import com.android.internal.telephony.BaseCommands; |
| 46 | import com.android.internal.telephony.Phone; |
Wink Saville | bf7c617 | 2012-06-14 12:43:28 -0700 | [diff] [blame] | 47 | import com.android.internal.telephony.PhoneConstants; |
Dianne Hackborn | 49f22d3 | 2010-02-24 19:58:29 -0800 | [diff] [blame] | 48 | import com.android.internal.util.XmlUtils; |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 49 | |
| 50 | import org.xmlpull.v1.XmlPullParser; |
| 51 | import org.xmlpull.v1.XmlPullParserException; |
| 52 | |
| 53 | import java.io.File; |
| 54 | import java.io.FileNotFoundException; |
| 55 | import java.io.FileReader; |
| 56 | import java.io.IOException; |
w19976 | e9a6c45 | 2014-07-18 16:43:00 -0700 | [diff] [blame] | 57 | import java.lang.NumberFormatException; |
Wink Saville | d7c9350 | 2011-06-04 07:17:01 -0700 | [diff] [blame] | 58 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 59 | public class TelephonyProvider extends ContentProvider |
| 60 | { |
| 61 | private static final String DATABASE_NAME = "telephony.db"; |
Wink Saville | d7c9350 | 2011-06-04 07:17:01 -0700 | [diff] [blame] | 62 | private static final boolean DBG = true; |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 63 | private static final boolean VDBG = false; |
Jaikumar Ganesh | 8e1a4f9 | 2009-10-26 13:07:37 -0700 | [diff] [blame] | 64 | |
Sindhu Kanathur | a625988 | 2015-01-29 18:50:51 +0530 | [diff] [blame] | 65 | private static final int DATABASE_VERSION = 13 << 16; |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 66 | private static final int URL_UNKNOWN = 0; |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 67 | private static final int URL_TELEPHONY = 1; |
| 68 | private static final int URL_CURRENT = 2; |
| 69 | private static final int URL_ID = 3; |
| 70 | private static final int URL_RESTOREAPN = 4; |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 71 | private static final int URL_PREFERAPN = 5; |
Kazuhiro Ondo | d616ee6 | 2012-01-10 17:12:59 -0600 | [diff] [blame] | 72 | private static final int URL_PREFERAPN_NO_UPDATE = 6; |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 73 | private static final int URL_SIMINFO = 7; |
| 74 | private static final int URL_TELEPHONY_USING_SUBID = 8; |
| 75 | private static final int URL_CURRENT_USING_SUBID = 9; |
| 76 | private static final int URL_RESTOREAPN_USING_SUBID = 10; |
| 77 | private static final int URL_PREFERAPN_USING_SUBID = 11; |
| 78 | private static final int URL_PREFERAPN_NO_UPDATE_USING_SUBID = 12; |
| 79 | private static final int URL_SIMINFO_USING_SUBID = 13; |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 80 | |
| 81 | private static final String TAG = "TelephonyProvider"; |
| 82 | private static final String CARRIERS_TABLE = "carriers"; |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 83 | private static final String SIMINFO_TABLE = "siminfo"; |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 84 | |
| 85 | private static final String PREF_FILE = "preferred-apn"; |
| 86 | private static final String COLUMN_APN_ID = "apn_id"; |
| 87 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 88 | private static final String PARTNER_APNS_PATH = "etc/apns-conf.xml"; |
Legler Wu | 3678880 | 2014-12-29 13:20:29 +0800 | [diff] [blame] | 89 | private static final String OEM_APNS_PATH = "telephony/apns-conf.xml"; |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 90 | |
kaiyiz | 663a670 | 2014-07-31 15:50:20 +0800 | [diff] [blame] | 91 | private static final String READ_ONLY = "read_only"; |
| 92 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 93 | private static final UriMatcher s_urlMatcher = new UriMatcher(UriMatcher.NO_MATCH); |
| 94 | |
| 95 | private static final ContentValues s_currentNullMap; |
| 96 | private static final ContentValues s_currentSetMap; |
| 97 | |
| 98 | static { |
| 99 | s_urlMatcher.addURI("telephony", "carriers", URL_TELEPHONY); |
| 100 | s_urlMatcher.addURI("telephony", "carriers/current", URL_CURRENT); |
| 101 | s_urlMatcher.addURI("telephony", "carriers/#", URL_ID); |
| 102 | s_urlMatcher.addURI("telephony", "carriers/restore", URL_RESTOREAPN); |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 103 | s_urlMatcher.addURI("telephony", "carriers/preferapn", URL_PREFERAPN); |
Kazuhiro Ondo | d616ee6 | 2012-01-10 17:12:59 -0600 | [diff] [blame] | 104 | s_urlMatcher.addURI("telephony", "carriers/preferapn_no_update", URL_PREFERAPN_NO_UPDATE); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 105 | |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 106 | s_urlMatcher.addURI("telephony", "siminfo", URL_SIMINFO); |
| 107 | |
| 108 | s_urlMatcher.addURI("telephony", "carriers/subId/*", URL_TELEPHONY_USING_SUBID); |
| 109 | s_urlMatcher.addURI("telephony", "carriers/current/subId/*", URL_CURRENT_USING_SUBID); |
| 110 | s_urlMatcher.addURI("telephony", "carriers/restore/subId/*", URL_RESTOREAPN_USING_SUBID); |
| 111 | s_urlMatcher.addURI("telephony", "carriers/preferapn/subId/*", URL_PREFERAPN_USING_SUBID); |
| 112 | s_urlMatcher.addURI("telephony", "carriers/preferapn_no_update/subId/*", |
| 113 | URL_PREFERAPN_NO_UPDATE_USING_SUBID); |
| 114 | |
| 115 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 116 | s_currentNullMap = new ContentValues(1); |
| 117 | s_currentNullMap.put("current", (Long) null); |
| 118 | |
| 119 | s_currentSetMap = new ContentValues(1); |
| 120 | s_currentSetMap.put("current", "1"); |
| 121 | } |
| 122 | |
| 123 | private static class DatabaseHelper extends SQLiteOpenHelper { |
| 124 | // Context to access resources with |
| 125 | private Context mContext; |
| 126 | |
| 127 | /** |
| 128 | * DatabaseHelper helper class for loading apns into a database. |
| 129 | * |
Wink Saville | d7c9350 | 2011-06-04 07:17:01 -0700 | [diff] [blame] | 130 | * @param context of the user. |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 131 | */ |
| 132 | public DatabaseHelper(Context context) { |
| 133 | super(context, DATABASE_NAME, null, getVersion(context)); |
| 134 | mContext = context; |
| 135 | } |
| 136 | |
| 137 | private static int getVersion(Context context) { |
Wink Saville | 6de1027 | 2014-06-22 07:38:43 -0700 | [diff] [blame] | 138 | if (VDBG) log("getVersion:+"); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 139 | // Get the database version, combining a static schema version and the XML version |
| 140 | Resources r = context.getResources(); |
| 141 | XmlResourceParser parser = r.getXml(com.android.internal.R.xml.apns); |
| 142 | try { |
| 143 | XmlUtils.beginDocument(parser, "apns"); |
| 144 | int publicversion = Integer.parseInt(parser.getAttributeValue(null, "version")); |
Wink Saville | 6de1027 | 2014-06-22 07:38:43 -0700 | [diff] [blame] | 145 | int version = DATABASE_VERSION | publicversion; |
| 146 | if (VDBG) log("getVersion:- version=0x" + Integer.toHexString(version)); |
| 147 | return version; |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 148 | } catch (Exception e) { |
Wink Saville | 6de1027 | 2014-06-22 07:38:43 -0700 | [diff] [blame] | 149 | loge("Can't get version of APN database" + e + " return version=" + |
| 150 | Integer.toHexString(DATABASE_VERSION)); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 151 | return DATABASE_VERSION; |
| 152 | } finally { |
| 153 | parser.close(); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | @Override |
| 158 | public void onCreate(SQLiteDatabase db) { |
Wink Saville | 6de1027 | 2014-06-22 07:38:43 -0700 | [diff] [blame] | 159 | if (DBG) log("dbh.onCreate:+ db=" + db); |
| 160 | createSimInfoTable(db); |
| 161 | createCarriersTable(db); |
| 162 | initDatabase(db); |
| 163 | if (DBG) log("dbh.onCreate:- db=" + db); |
| 164 | } |
| 165 | |
| 166 | @Override |
| 167 | public void onOpen(SQLiteDatabase db) { |
| 168 | if (VDBG) log("dbh.onOpen:+ db=" + db); |
| 169 | try { |
| 170 | // Try to access the table and create it if "no such table" |
| 171 | db.query(SIMINFO_TABLE, null, null, null, null, null, null); |
| 172 | if (DBG) log("dbh.onOpen: ok, queried table=" + SIMINFO_TABLE); |
| 173 | } catch (SQLiteException e) { |
| 174 | loge("Exception " + SIMINFO_TABLE + "e=" + e); |
| 175 | if (e.getMessage().startsWith("no such table")) { |
| 176 | createSimInfoTable(db); |
| 177 | } |
| 178 | } |
| 179 | try { |
| 180 | db.query(CARRIERS_TABLE, null, null, null, null, null, null); |
| 181 | if (DBG) log("dbh.onOpen: ok, queried table=" + CARRIERS_TABLE); |
| 182 | } catch (SQLiteException e) { |
| 183 | loge("Exception " + CARRIERS_TABLE + " e=" + e); |
| 184 | if (e.getMessage().startsWith("no such table")) { |
| 185 | createCarriersTable(db); |
| 186 | } |
| 187 | } |
| 188 | if (VDBG) log("dbh.onOpen:- db=" + db); |
| 189 | } |
| 190 | |
| 191 | private void createSimInfoTable(SQLiteDatabase db) { |
| 192 | if (DBG) log("dbh.createSimInfoTable:+"); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 193 | db.execSQL("CREATE TABLE " + SIMINFO_TABLE + "(" |
Wink Saville | 8ca608c | 2014-11-15 12:49:01 -0800 | [diff] [blame] | 194 | + SubscriptionManager.UNIQUE_KEY_SUBSCRIPTION_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 195 | + SubscriptionManager.ICC_ID + " TEXT NOT NULL," |
Wink Saville | 8ca608c | 2014-11-15 12:49:01 -0800 | [diff] [blame] | 196 | + SubscriptionManager.SIM_SLOT_INDEX + " INTEGER DEFAULT " + SubscriptionManager.SIM_NOT_INSERTED + "," |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 197 | + SubscriptionManager.DISPLAY_NAME + " TEXT," |
Sanket Padawe | 0f8d669 | 2014-11-06 11:50:40 -0800 | [diff] [blame] | 198 | + SubscriptionManager.CARRIER_NAME + " TEXT," |
Wink Saville | d3b87ec | 2014-09-02 22:45:38 -0700 | [diff] [blame] | 199 | + SubscriptionManager.NAME_SOURCE + " INTEGER DEFAULT " + SubscriptionManager.NAME_SOURCE_DEFAULT_SOURCE + "," |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 200 | + SubscriptionManager.COLOR + " INTEGER DEFAULT " + SubscriptionManager.COLOR_DEFAULT + "," |
| 201 | + SubscriptionManager.NUMBER + " TEXT," |
Yashdev Singh | 9c60180 | 2015-02-24 23:03:06 -0800 | [diff] [blame] | 202 | + SubscriptionManager.DISPLAY_NUMBER_FORMAT + " INTEGER NOT NULL DEFAULT " + SubscriptionManager.DISPLAY_NUMBER_DEFAULT + "," |
Tom Taylor | 7c6edbe | 2014-09-04 12:02:34 -0700 | [diff] [blame] | 203 | + SubscriptionManager.DATA_ROAMING + " INTEGER DEFAULT " + SubscriptionManager.DATA_ROAMING_DEFAULT + "," |
| 204 | + SubscriptionManager.MCC + " INTEGER DEFAULT 0," |
Rakesh Pallerla | c69605f | 2014-07-18 17:17:29 +0530 | [diff] [blame] | 205 | + SubscriptionManager.MNC + " INTEGER DEFAULT 0" + "," |
Rakesh Pallerla | fdaecc7 | 2014-09-26 16:15:33 +0530 | [diff] [blame] | 206 | + SubscriptionManager.SUB_STATE + " INTEGER DEFAULT " + SubscriptionManager.ACTIVE + "," |
| 207 | + SubscriptionManager.NETWORK_MODE+ " INTEGER DEFAULT " + SubscriptionManager.DEFAULT_NW_MODE |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 208 | + ");"); |
Wink Saville | 6de1027 | 2014-06-22 07:38:43 -0700 | [diff] [blame] | 209 | if (DBG) log("dbh.createSimInfoTable:-"); |
| 210 | } |
| 211 | |
| 212 | private void createCarriersTable(SQLiteDatabase db) { |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 213 | // Set up the database schema |
Wink Saville | 6de1027 | 2014-06-22 07:38:43 -0700 | [diff] [blame] | 214 | if (DBG) log("dbh.createCarriersTable:+"); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 215 | db.execSQL("CREATE TABLE " + CARRIERS_TABLE + |
| 216 | "(_id INTEGER PRIMARY KEY," + |
| 217 | "name TEXT," + |
| 218 | "numeric TEXT," + |
| 219 | "mcc TEXT," + |
| 220 | "mnc TEXT," + |
| 221 | "apn TEXT," + |
| 222 | "user TEXT," + |
| 223 | "server TEXT," + |
| 224 | "password TEXT," + |
| 225 | "proxy TEXT," + |
| 226 | "port TEXT," + |
| 227 | "mmsproxy TEXT," + |
| 228 | "mmsport TEXT," + |
| 229 | "mmsc TEXT," + |
Jaikumar Ganesh | 8e1a4f9 | 2009-10-26 13:07:37 -0700 | [diff] [blame] | 230 | "authtype INTEGER," + |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 231 | "type TEXT," + |
Lorenzo Colitti | 9dd054f | 2010-12-29 15:54:00 -0800 | [diff] [blame] | 232 | "current INTEGER," + |
| 233 | "protocol TEXT," + |
sinikang | bae4b07 | 2011-09-02 09:49:37 +0900 | [diff] [blame] | 234 | "roaming_protocol TEXT," + |
| 235 | "carrier_enabled BOOLEAN," + |
Sungmin Choi | 27045ef | 2013-01-25 17:48:06 +0900 | [diff] [blame] | 236 | "bearer INTEGER," + |
| 237 | "mvno_type TEXT," + |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 238 | "mvno_match_data TEXT," + |
Wink Saville | 8ca608c | 2014-11-15 12:49:01 -0800 | [diff] [blame] | 239 | "sub_id INTEGER DEFAULT " + SubscriptionManager.INVALID_SUBSCRIPTION_ID + "," + |
Amit Mahajan | b068886 | 2014-08-13 16:53:51 +0000 | [diff] [blame] | 240 | "profile_id INTEGER default 0," + |
| 241 | "modem_cognitive BOOLEAN default 0," + |
| 242 | "max_conns INTEGER default 0," + |
| 243 | "wait_time INTEGER default 0," + |
w19976 | e9a6c45 | 2014-07-18 16:43:00 -0700 | [diff] [blame] | 244 | "max_conns_time INTEGER default 0," + |
kaiyiz | 663a670 | 2014-07-31 15:50:20 +0800 | [diff] [blame] | 245 | "read_only BOOLEAN DEFAULT 0," + |
w19976 | e9a6c45 | 2014-07-18 16:43:00 -0700 | [diff] [blame] | 246 | "mtu INTEGER);"); |
Wink Saville | 6de1027 | 2014-06-22 07:38:43 -0700 | [diff] [blame] | 247 | if (DBG) log("dbh.createCarriersTable:-"); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 248 | } |
Shri Borde | 4b471cc | 2014-09-15 13:46:01 -0700 | [diff] [blame] | 249 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 250 | private void initDatabase(SQLiteDatabase db) { |
Wink Saville | 6de1027 | 2014-06-22 07:38:43 -0700 | [diff] [blame] | 251 | if (VDBG) log("dbh.initDatabase:+ db=" + db); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 252 | // Read internal APNS data |
| 253 | Resources r = mContext.getResources(); |
| 254 | XmlResourceParser parser = r.getXml(com.android.internal.R.xml.apns); |
| 255 | int publicversion = -1; |
| 256 | try { |
| 257 | XmlUtils.beginDocument(parser, "apns"); |
| 258 | publicversion = Integer.parseInt(parser.getAttributeValue(null, "version")); |
| 259 | loadApns(db, parser); |
| 260 | } catch (Exception e) { |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 261 | loge("Got exception while loading APN database." + e); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 262 | } finally { |
| 263 | parser.close(); |
| 264 | } |
| 265 | |
Sungmin Choi | 22b6306 | 2013-01-25 15:53:15 +0900 | [diff] [blame] | 266 | // Read external APNS data (partner-provided) |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 267 | XmlPullParser confparser = null; |
| 268 | // Environment.getRootDirectory() is a fancy way of saying ANDROID_ROOT or "/system". |
| 269 | File confFile = new File(Environment.getRootDirectory(), PARTNER_APNS_PATH); |
Legler Wu | 3678880 | 2014-12-29 13:20:29 +0800 | [diff] [blame] | 270 | File oemConfFile = new File(Environment.getOemDirectory(), OEM_APNS_PATH); |
| 271 | if (oemConfFile.exists()) { |
| 272 | // OEM image exist APN xml, get the timestamp from OEM & System image for comparison |
| 273 | long oemApnTime = oemConfFile.lastModified(); |
| 274 | long sysApnTime = confFile.lastModified(); |
| 275 | if (DBG) log("APNs Timestamp: oemTime = " + oemApnTime + " sysTime = " |
| 276 | + sysApnTime); |
| 277 | |
| 278 | // To get the latest version from OEM or System image |
| 279 | if (oemApnTime > sysApnTime) { |
| 280 | if (DBG) log("APNs Timestamp: OEM image is greater than System image"); |
| 281 | confFile = oemConfFile; |
| 282 | } |
| 283 | } else { |
| 284 | // No Apn in OEM image, so load it from system image. |
| 285 | if (DBG) log("No APNs in OEM image = " + oemConfFile.getPath() + |
| 286 | " Load APNs from system image"); |
| 287 | } |
| 288 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 289 | FileReader confreader = null; |
Legler Wu | 3678880 | 2014-12-29 13:20:29 +0800 | [diff] [blame] | 290 | if (DBG) log("confFile = " + confFile); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 291 | try { |
| 292 | confreader = new FileReader(confFile); |
| 293 | confparser = Xml.newPullParser(); |
| 294 | confparser.setInput(confreader); |
| 295 | XmlUtils.beginDocument(confparser, "apns"); |
| 296 | |
| 297 | // Sanity check. Force internal version and confidential versions to agree |
| 298 | int confversion = Integer.parseInt(confparser.getAttributeValue(null, "version")); |
| 299 | if (publicversion != confversion) { |
| 300 | throw new IllegalStateException("Internal APNS file version doesn't match " |
| 301 | + confFile.getAbsolutePath()); |
| 302 | } |
| 303 | |
| 304 | loadApns(db, confparser); |
| 305 | } catch (FileNotFoundException e) { |
| 306 | // It's ok if the file isn't found. It means there isn't a confidential file |
| 307 | // Log.e(TAG, "File not found: '" + confFile.getAbsolutePath() + "'"); |
| 308 | } catch (Exception e) { |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 309 | loge("Exception while parsing '" + confFile.getAbsolutePath() + "'" + e); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 310 | } finally { |
| 311 | try { if (confreader != null) confreader.close(); } catch (IOException e) { } |
| 312 | } |
Wink Saville | 6de1027 | 2014-06-22 07:38:43 -0700 | [diff] [blame] | 313 | if (VDBG) log("dbh.initDatabase:- db=" + db); |
Amit Mahajan | b068886 | 2014-08-13 16:53:51 +0000 | [diff] [blame] | 314 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | @Override |
| 318 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { |
Wink Saville | 6de1027 | 2014-06-22 07:38:43 -0700 | [diff] [blame] | 319 | if (DBG) { |
| 320 | log("dbh.onUpgrade:+ db=" + db + " oldV=" + oldVersion + " newV=" + newVersion); |
| 321 | } |
| 322 | |
Jaikumar Ganesh | 8e1a4f9 | 2009-10-26 13:07:37 -0700 | [diff] [blame] | 323 | if (oldVersion < (5 << 16 | 6)) { |
| 324 | // 5 << 16 is the Database version and 6 in the xml version. |
| 325 | |
| 326 | // This change adds a new authtype column to the database. |
| 327 | // The auth type column can have 4 values: 0 (None), 1 (PAP), 2 (CHAP) |
| 328 | // 3 (PAP or CHAP). To avoid breaking compatibility, with already working |
| 329 | // APNs, the unset value (-1) will be used. If the value is -1. |
| 330 | // the authentication will default to 0 (if no user / password) is specified |
| 331 | // or to 3. Currently, there have been no reported problems with |
| 332 | // pre-configured APNs and hence it is set to -1 for them. Similarly, |
| 333 | // if the user, has added a new APN, we set the authentication type |
| 334 | // to -1. |
| 335 | |
| 336 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + |
| 337 | " ADD COLUMN authtype INTEGER DEFAULT -1;"); |
| 338 | |
| 339 | oldVersion = 5 << 16 | 6; |
| 340 | } |
Lorenzo Colitti | 9dd054f | 2010-12-29 15:54:00 -0800 | [diff] [blame] | 341 | if (oldVersion < (6 << 16 | 6)) { |
| 342 | // Add protcol fields to the APN. The XML file does not change. |
| 343 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + |
| 344 | " ADD COLUMN protocol TEXT DEFAULT IP;"); |
| 345 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + |
| 346 | " ADD COLUMN roaming_protocol TEXT DEFAULT IP;"); |
| 347 | oldVersion = 6 << 16 | 6; |
| 348 | } |
sinikang | bae4b07 | 2011-09-02 09:49:37 +0900 | [diff] [blame] | 349 | if (oldVersion < (7 << 16 | 6)) { |
Sungmin Choi | 22b6306 | 2013-01-25 15:53:15 +0900 | [diff] [blame] | 350 | // Add carrier_enabled, bearer fields to the APN. The XML file does not change. |
sinikang | bae4b07 | 2011-09-02 09:49:37 +0900 | [diff] [blame] | 351 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + |
| 352 | " ADD COLUMN carrier_enabled BOOLEAN DEFAULT 1;"); |
| 353 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + |
| 354 | " ADD COLUMN bearer INTEGER DEFAULT 0;"); |
| 355 | oldVersion = 7 << 16 | 6; |
| 356 | } |
Sungmin Choi | 27045ef | 2013-01-25 17:48:06 +0900 | [diff] [blame] | 357 | if (oldVersion < (8 << 16 | 6)) { |
| 358 | // Add mvno_type, mvno_match_data fields to the APN. |
| 359 | // The XML file does not change. |
| 360 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + |
| 361 | " ADD COLUMN mvno_type TEXT DEFAULT '';"); |
| 362 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + |
| 363 | " ADD COLUMN mvno_match_data TEXT DEFAULT '';"); |
| 364 | oldVersion = 8 << 16 | 6; |
| 365 | } |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 366 | if (oldVersion < (9 << 16 | 6)) { |
| 367 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + |
Tom Taylor | bb50ace | 2014-10-28 13:35:34 -0700 | [diff] [blame] | 368 | " ADD COLUMN sub_id INTEGER DEFAULT " + |
Wink Saville | 8ca608c | 2014-11-15 12:49:01 -0800 | [diff] [blame] | 369 | SubscriptionManager.INVALID_SUBSCRIPTION_ID + ";"); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 370 | oldVersion = 9 << 16 | 6; |
| 371 | } |
Amit Mahajan | b068886 | 2014-08-13 16:53:51 +0000 | [diff] [blame] | 372 | if (oldVersion < (10 << 16 | 6)) { |
| 373 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + |
| 374 | " ADD COLUMN profile_id INTEGER DEFAULT 0;"); |
| 375 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + |
| 376 | " ADD COLUMN modem_cognitive BOOLEAN DEFAULT 0;"); |
| 377 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + |
| 378 | " ADD COLUMN max_conns INTEGER DEFAULT 0;"); |
| 379 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + |
| 380 | " ADD COLUMN wait_time INTEGER DEFAULT 0;"); |
| 381 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + |
| 382 | " ADD COLUMN max_conns_time INTEGER DEFAULT 0;"); |
| 383 | oldVersion = 10 << 16 | 6; |
| 384 | } |
w19976 | e9a6c45 | 2014-07-18 16:43:00 -0700 | [diff] [blame] | 385 | if (oldVersion < (11 << 16 | 6)) { |
| 386 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + |
| 387 | " ADD COLUMN mtu INTEGER DEFAULT 0;"); |
| 388 | oldVersion = 11 << 16 | 6; |
| 389 | } |
Tom Taylor | 7c6edbe | 2014-09-04 12:02:34 -0700 | [diff] [blame] | 390 | if (oldVersion < (12 << 16 | 6)) { |
Tom Taylor | c55054d | 2014-09-10 11:01:44 -0700 | [diff] [blame] | 391 | try { |
| 392 | // Try to update the siminfo table. It might not be there. |
| 393 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + |
| 394 | " ADD COLUMN " + SubscriptionManager.MCC + " INTEGER DEFAULT 0;"); |
| 395 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + |
| 396 | " ADD COLUMN " + SubscriptionManager.MNC + " INTEGER DEFAULT 0;"); |
| 397 | } catch (SQLiteException e) { |
| 398 | if (DBG) { |
| 399 | log("onUpgrade skipping " + SIMINFO_TABLE + " upgrade. " + |
| 400 | " The table will get created in onOpen."); |
| 401 | } |
| 402 | } |
Tom Taylor | 7c6edbe | 2014-09-04 12:02:34 -0700 | [diff] [blame] | 403 | oldVersion = 12 << 16 | 6; |
| 404 | } |
Sindhu Kanathur | a625988 | 2015-01-29 18:50:51 +0530 | [diff] [blame] | 405 | if (oldVersion < (13 << 16 | 6)) { |
| 406 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + |
| 407 | " ADD COLUMN "+READ_ONLY+" BOOLEAN DEFAULT 0;"); |
Sanket Padawe | 0f8d669 | 2014-11-06 11:50:40 -0800 | [diff] [blame] | 408 | try { |
| 409 | // Try to update the siminfo table. It might not be there. |
| 410 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + |
| 411 | " ADD COLUMN " + SubscriptionManager.CARRIER_NAME + " TEXT DEFAULT '';"); |
| 412 | } catch (SQLiteException e) { |
| 413 | if (DBG) { |
| 414 | log("onUpgrade skipping " + SIMINFO_TABLE + " upgrade. " + |
| 415 | " The table will get created in onOpen."); |
| 416 | } |
| 417 | } |
| 418 | oldVersion = 13 << 16 | 6; |
Sindhu Kanathur | a625988 | 2015-01-29 18:50:51 +0530 | [diff] [blame] | 419 | } |
Wink Saville | 6de1027 | 2014-06-22 07:38:43 -0700 | [diff] [blame] | 420 | if (DBG) { |
| 421 | log("dbh.onUpgrade:- db=" + db + " oldV=" + oldVersion + " newV=" + newVersion); |
| 422 | } |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | /** |
| 426 | * Gets the next row of apn values. |
| 427 | * |
| 428 | * @param parser the parser |
| 429 | * @return the row or null if it's not an apn |
| 430 | */ |
| 431 | private ContentValues getRow(XmlPullParser parser) { |
| 432 | if (!"apn".equals(parser.getName())) { |
| 433 | return null; |
| 434 | } |
| 435 | |
| 436 | ContentValues map = new ContentValues(); |
| 437 | |
| 438 | String mcc = parser.getAttributeValue(null, "mcc"); |
| 439 | String mnc = parser.getAttributeValue(null, "mnc"); |
| 440 | String numeric = mcc + mnc; |
| 441 | |
| 442 | map.put(Telephony.Carriers.NUMERIC,numeric); |
| 443 | map.put(Telephony.Carriers.MCC, mcc); |
| 444 | map.put(Telephony.Carriers.MNC, mnc); |
| 445 | map.put(Telephony.Carriers.NAME, parser.getAttributeValue(null, "carrier")); |
| 446 | map.put(Telephony.Carriers.APN, parser.getAttributeValue(null, "apn")); |
| 447 | map.put(Telephony.Carriers.USER, parser.getAttributeValue(null, "user")); |
| 448 | map.put(Telephony.Carriers.SERVER, parser.getAttributeValue(null, "server")); |
| 449 | map.put(Telephony.Carriers.PASSWORD, parser.getAttributeValue(null, "password")); |
| 450 | |
| 451 | // do not add NULL to the map so that insert() will set the default value |
| 452 | String proxy = parser.getAttributeValue(null, "proxy"); |
| 453 | if (proxy != null) { |
| 454 | map.put(Telephony.Carriers.PROXY, proxy); |
| 455 | } |
| 456 | String port = parser.getAttributeValue(null, "port"); |
| 457 | if (port != null) { |
| 458 | map.put(Telephony.Carriers.PORT, port); |
| 459 | } |
| 460 | String mmsproxy = parser.getAttributeValue(null, "mmsproxy"); |
| 461 | if (mmsproxy != null) { |
| 462 | map.put(Telephony.Carriers.MMSPROXY, mmsproxy); |
| 463 | } |
| 464 | String mmsport = parser.getAttributeValue(null, "mmsport"); |
| 465 | if (mmsport != null) { |
| 466 | map.put(Telephony.Carriers.MMSPORT, mmsport); |
| 467 | } |
| 468 | map.put(Telephony.Carriers.MMSC, parser.getAttributeValue(null, "mmsc")); |
| 469 | String type = parser.getAttributeValue(null, "type"); |
| 470 | if (type != null) { |
| 471 | map.put(Telephony.Carriers.TYPE, type); |
| 472 | } |
| 473 | |
Jaikumar Ganesh | 8e1a4f9 | 2009-10-26 13:07:37 -0700 | [diff] [blame] | 474 | String auth = parser.getAttributeValue(null, "authtype"); |
| 475 | if (auth != null) { |
| 476 | map.put(Telephony.Carriers.AUTH_TYPE, Integer.parseInt(auth)); |
| 477 | } |
| 478 | |
Lorenzo Colitti | 9dd054f | 2010-12-29 15:54:00 -0800 | [diff] [blame] | 479 | String protocol = parser.getAttributeValue(null, "protocol"); |
| 480 | if (protocol != null) { |
| 481 | map.put(Telephony.Carriers.PROTOCOL, protocol); |
| 482 | } |
| 483 | |
| 484 | String roamingProtocol = parser.getAttributeValue(null, "roaming_protocol"); |
| 485 | if (roamingProtocol != null) { |
| 486 | map.put(Telephony.Carriers.ROAMING_PROTOCOL, roamingProtocol); |
| 487 | } |
| 488 | |
sinikang | bae4b07 | 2011-09-02 09:49:37 +0900 | [diff] [blame] | 489 | String carrierEnabled = parser.getAttributeValue(null, "carrier_enabled"); |
| 490 | if (carrierEnabled != null) { |
| 491 | map.put(Telephony.Carriers.CARRIER_ENABLED, Boolean.parseBoolean(carrierEnabled)); |
| 492 | } |
| 493 | |
| 494 | String bearer = parser.getAttributeValue(null, "bearer"); |
| 495 | if (bearer != null) { |
| 496 | map.put(Telephony.Carriers.BEARER, Integer.parseInt(bearer)); |
| 497 | } |
Sungmin Choi | 27045ef | 2013-01-25 17:48:06 +0900 | [diff] [blame] | 498 | |
| 499 | String mvno_type = parser.getAttributeValue(null, "mvno_type"); |
| 500 | if (mvno_type != null) { |
| 501 | String mvno_match_data = parser.getAttributeValue(null, "mvno_match_data"); |
| 502 | if (mvno_match_data != null) { |
| 503 | map.put(Telephony.Carriers.MVNO_TYPE, mvno_type); |
| 504 | map.put(Telephony.Carriers.MVNO_MATCH_DATA, mvno_match_data); |
| 505 | } |
| 506 | } |
Amit Mahajan | b068886 | 2014-08-13 16:53:51 +0000 | [diff] [blame] | 507 | |
| 508 | String profileId = parser.getAttributeValue(null, "profile_id"); |
| 509 | if (profileId != null) { |
| 510 | map.put(Telephony.Carriers.PROFILE_ID, Integer.parseInt(profileId)); |
| 511 | } |
| 512 | |
| 513 | String modemCognitive = parser.getAttributeValue(null, "modem_cognitive"); |
Hui Wang | a1045b0 | 2014-10-01 16:18:50 -0500 | [diff] [blame] | 514 | if (modemCognitive != null) { |
Amit Mahajan | b068886 | 2014-08-13 16:53:51 +0000 | [diff] [blame] | 515 | map.put(Telephony.Carriers.MODEM_COGNITIVE, Boolean.parseBoolean(modemCognitive)); |
| 516 | } |
| 517 | |
| 518 | String maxConns = parser.getAttributeValue(null, "max_conns"); |
| 519 | if (maxConns != null) { |
| 520 | map.put(Telephony.Carriers.MAX_CONNS, Integer.parseInt(maxConns)); |
| 521 | } |
| 522 | |
| 523 | String waitTime = parser.getAttributeValue(null, "wait_time"); |
| 524 | if (waitTime != null) { |
| 525 | map.put(Telephony.Carriers.WAIT_TIME, Integer.parseInt(waitTime)); |
| 526 | } |
| 527 | |
| 528 | String maxConnsTime = parser.getAttributeValue(null, "max_conns_time"); |
| 529 | if (maxConnsTime != null) { |
| 530 | map.put(Telephony.Carriers.MAX_CONNS_TIME, Integer.parseInt(maxConnsTime)); |
| 531 | } |
| 532 | |
w19976 | e9a6c45 | 2014-07-18 16:43:00 -0700 | [diff] [blame] | 533 | String mtu = parser.getAttributeValue(null, "mtu"); |
| 534 | if (mtu != null) { |
| 535 | map.put(Telephony.Carriers.MTU, Integer.parseInt(mtu)); |
| 536 | } |
| 537 | |
kaiyiz | 663a670 | 2014-07-31 15:50:20 +0800 | [diff] [blame] | 538 | String readOnly = parser.getAttributeValue(null, "read_only"); |
| 539 | if (readOnly != null) { |
| 540 | map.put(mContext.getString(R.string.read_only), Boolean. |
| 541 | parseBoolean(readOnly)); |
| 542 | } |
| 543 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 544 | return map; |
| 545 | } |
| 546 | |
| 547 | /* |
| 548 | * Loads apns from xml file into the database |
| 549 | * |
| 550 | * @param db the sqlite database to write to |
| 551 | * @param parser the xml parser |
| 552 | * |
| 553 | */ |
| 554 | private void loadApns(SQLiteDatabase db, XmlPullParser parser) { |
| 555 | if (parser != null) { |
| 556 | try { |
jewon.lee | 4167fcc | 2013-01-17 13:10:37 +0900 | [diff] [blame] | 557 | db.beginTransaction(); |
Hyejin Kim | 7e7c274 | 2013-02-11 20:02:18 +0900 | [diff] [blame] | 558 | XmlUtils.nextElement(parser); |
| 559 | while (parser.getEventType() != XmlPullParser.END_DOCUMENT) { |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 560 | ContentValues row = getRow(parser); |
Hyejin Kim | 7e7c274 | 2013-02-11 20:02:18 +0900 | [diff] [blame] | 561 | if (row == null) { |
| 562 | throw new XmlPullParserException("Expected 'apn' tag", parser, null); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 563 | } |
Hyejin Kim | 7e7c274 | 2013-02-11 20:02:18 +0900 | [diff] [blame] | 564 | insertAddingDefaults(db, CARRIERS_TABLE, row); |
| 565 | XmlUtils.nextElement(parser); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 566 | } |
jewon.lee | 4167fcc | 2013-01-17 13:10:37 +0900 | [diff] [blame] | 567 | db.setTransactionSuccessful(); |
Hyejin Kim | 7e7c274 | 2013-02-11 20:02:18 +0900 | [diff] [blame] | 568 | } catch (XmlPullParserException e) { |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 569 | loge("Got XmlPullParserException while loading apns." + e); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 570 | } catch (IOException e) { |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 571 | loge("Got IOException while loading apns." + e); |
Hyejin Kim | 7e7c274 | 2013-02-11 20:02:18 +0900 | [diff] [blame] | 572 | } catch (SQLException e) { |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 573 | loge("Got SQLException while loading apns." + e); |
jewon.lee | 4167fcc | 2013-01-17 13:10:37 +0900 | [diff] [blame] | 574 | } finally { |
| 575 | db.endTransaction(); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 576 | } |
| 577 | } |
| 578 | } |
Jaikumar Ganesh | 8e1a4f9 | 2009-10-26 13:07:37 -0700 | [diff] [blame] | 579 | |
Amit Mahajan | b068886 | 2014-08-13 16:53:51 +0000 | [diff] [blame] | 580 | static public ContentValues setDefaultValue(ContentValues values) { |
| 581 | if (!values.containsKey(Telephony.Carriers.NAME)) { |
| 582 | values.put(Telephony.Carriers.NAME, ""); |
| 583 | } |
| 584 | if (!values.containsKey(Telephony.Carriers.APN)) { |
| 585 | values.put(Telephony.Carriers.APN, ""); |
| 586 | } |
| 587 | if (!values.containsKey(Telephony.Carriers.PORT)) { |
| 588 | values.put(Telephony.Carriers.PORT, ""); |
| 589 | } |
| 590 | if (!values.containsKey(Telephony.Carriers.PROXY)) { |
| 591 | values.put(Telephony.Carriers.PROXY, ""); |
| 592 | } |
| 593 | if (!values.containsKey(Telephony.Carriers.USER)) { |
| 594 | values.put(Telephony.Carriers.USER, ""); |
| 595 | } |
| 596 | if (!values.containsKey(Telephony.Carriers.SERVER)) { |
| 597 | values.put(Telephony.Carriers.SERVER, ""); |
| 598 | } |
| 599 | if (!values.containsKey(Telephony.Carriers.PASSWORD)) { |
| 600 | values.put(Telephony.Carriers.PASSWORD, ""); |
| 601 | } |
| 602 | if (!values.containsKey(Telephony.Carriers.MMSPORT)) { |
| 603 | values.put(Telephony.Carriers.MMSPORT, ""); |
| 604 | } |
| 605 | if (!values.containsKey(Telephony.Carriers.MMSPROXY)) { |
| 606 | values.put(Telephony.Carriers.MMSPROXY, ""); |
| 607 | } |
| 608 | if (!values.containsKey(Telephony.Carriers.AUTH_TYPE)) { |
| 609 | values.put(Telephony.Carriers.AUTH_TYPE, -1); |
| 610 | } |
| 611 | if (!values.containsKey(Telephony.Carriers.PROTOCOL)) { |
| 612 | values.put(Telephony.Carriers.PROTOCOL, "IP"); |
| 613 | } |
| 614 | if (!values.containsKey(Telephony.Carriers.ROAMING_PROTOCOL)) { |
| 615 | values.put(Telephony.Carriers.ROAMING_PROTOCOL, "IP"); |
| 616 | } |
| 617 | if (!values.containsKey(Telephony.Carriers.CARRIER_ENABLED)) { |
| 618 | values.put(Telephony.Carriers.CARRIER_ENABLED, true); |
| 619 | } |
| 620 | if (!values.containsKey(Telephony.Carriers.BEARER)) { |
| 621 | values.put(Telephony.Carriers.BEARER, 0); |
| 622 | } |
| 623 | if (!values.containsKey(Telephony.Carriers.MVNO_TYPE)) { |
| 624 | values.put(Telephony.Carriers.MVNO_TYPE, ""); |
| 625 | } |
| 626 | if (!values.containsKey(Telephony.Carriers.MVNO_MATCH_DATA)) { |
| 627 | values.put(Telephony.Carriers.MVNO_MATCH_DATA, ""); |
| 628 | } |
| 629 | |
Wink Saville | 85477f6 | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 630 | int subId = SubscriptionManager.getDefaultDataSubId(); |
Wink Saville | 8ca608c | 2014-11-15 12:49:01 -0800 | [diff] [blame] | 631 | if (!values.containsKey(Telephony.Carriers.SUBSCRIPTION_ID)) { |
| 632 | values.put(Telephony.Carriers.SUBSCRIPTION_ID, subId); |
Amit Mahajan | b068886 | 2014-08-13 16:53:51 +0000 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | if (!values.containsKey(Telephony.Carriers.PROFILE_ID)) { |
| 636 | values.put(Telephony.Carriers.PROFILE_ID, 0); |
| 637 | } |
| 638 | if (!values.containsKey(Telephony.Carriers.MODEM_COGNITIVE)) { |
| 639 | values.put(Telephony.Carriers.MODEM_COGNITIVE, false); |
| 640 | } |
| 641 | if (!values.containsKey(Telephony.Carriers.MAX_CONNS)) { |
| 642 | values.put(Telephony.Carriers.MAX_CONNS, 0); |
| 643 | } |
| 644 | if (!values.containsKey(Telephony.Carriers.WAIT_TIME)) { |
| 645 | values.put(Telephony.Carriers.WAIT_TIME, 0); |
| 646 | } |
| 647 | if (!values.containsKey(Telephony.Carriers.MAX_CONNS_TIME)) { |
| 648 | values.put(Telephony.Carriers.MAX_CONNS_TIME, 0); |
| 649 | } |
| 650 | |
kaiyiz | 663a670 | 2014-07-31 15:50:20 +0800 | [diff] [blame] | 651 | if (!values.containsKey(READ_ONLY)) { |
| 652 | values.put(READ_ONLY, false); |
| 653 | } |
Amit Mahajan | b068886 | 2014-08-13 16:53:51 +0000 | [diff] [blame] | 654 | return values; |
| 655 | } |
| 656 | |
Jaikumar Ganesh | 8e1a4f9 | 2009-10-26 13:07:37 -0700 | [diff] [blame] | 657 | private void insertAddingDefaults(SQLiteDatabase db, String table, ContentValues row) { |
Amit Mahajan | b068886 | 2014-08-13 16:53:51 +0000 | [diff] [blame] | 658 | row = setDefaultValue(row); |
Jaikumar Ganesh | 8e1a4f9 | 2009-10-26 13:07:37 -0700 | [diff] [blame] | 659 | db.insert(CARRIERS_TABLE, null, row); |
| 660 | } |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | @Override |
| 664 | public boolean onCreate() { |
Wink Saville | 6de1027 | 2014-06-22 07:38:43 -0700 | [diff] [blame] | 665 | if (VDBG) log("onCreate:+"); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 666 | mOpenHelper = new DatabaseHelper(getContext()); |
Wink Saville | 6de1027 | 2014-06-22 07:38:43 -0700 | [diff] [blame] | 667 | if (VDBG) log("onCreate:- ret true"); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 668 | return true; |
| 669 | } |
| 670 | |
Wink Saville | 85477f6 | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 671 | private void setPreferredApnId(Long id, int subId) { |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 672 | SharedPreferences sp = getContext().getSharedPreferences( |
| 673 | PREF_FILE + subId, Context.MODE_PRIVATE); |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 674 | SharedPreferences.Editor editor = sp.edit(); |
Jaikumar Ganesh | 8e1a4f9 | 2009-10-26 13:07:37 -0700 | [diff] [blame] | 675 | editor.putLong(COLUMN_APN_ID, id != null ? id.longValue() : -1); |
Brad Fitzpatrick | 2227c4a | 2010-08-30 17:42:39 -0700 | [diff] [blame] | 676 | editor.apply(); |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 677 | } |
| 678 | |
Wink Saville | 85477f6 | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 679 | private long getPreferredApnId(int subId) { |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 680 | SharedPreferences sp = getContext().getSharedPreferences( |
| 681 | PREF_FILE + subId, Context.MODE_PRIVATE); |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 682 | return sp.getLong(COLUMN_APN_ID, -1); |
| 683 | } |
| 684 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 685 | @Override |
| 686 | public Cursor query(Uri url, String[] projectionIn, String selection, |
| 687 | String[] selectionArgs, String sort) { |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 688 | TelephonyManager mTelephonyManager = |
| 689 | (TelephonyManager)getContext().getSystemService(Context.TELEPHONY_SERVICE); |
Wink Saville | 85477f6 | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 690 | int subId = SubscriptionManager.getDefaultDataSubId(); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 691 | String subIdString; |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 692 | SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); |
Robert Greenwalt | 429cf07 | 2013-05-21 17:04:09 -0700 | [diff] [blame] | 693 | qb.setStrict(true); // a little protection from injection attacks |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 694 | qb.setTables("carriers"); |
| 695 | |
| 696 | int match = s_urlMatcher.match(url); |
| 697 | switch (match) { |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 698 | case URL_TELEPHONY_USING_SUBID: { |
| 699 | subIdString = url.getLastPathSegment(); |
| 700 | try { |
Wink Saville | 85477f6 | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 701 | subId = Integer.parseInt(subIdString); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 702 | } catch (NumberFormatException e) { |
| 703 | loge("NumberFormatException" + e); |
| 704 | return null; |
| 705 | } |
| 706 | if (DBG) log("subIdString = " + subIdString + " subId = " + subId); |
Susheel nyamala | 3372c2e | 2014-09-24 20:55:57 +0530 | [diff] [blame] | 707 | qb.appendWhere("numeric = '" + |
| 708 | mTelephonyManager.getIccOperatorNumeric(subId)+"'"); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 709 | // FIXME alter the selection to pass subId |
| 710 | // selection = selection + "and subId = " |
| 711 | } |
| 712 | //intentional fall through from above case |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 713 | // do nothing |
| 714 | case URL_TELEPHONY: { |
| 715 | break; |
| 716 | } |
| 717 | |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 718 | case URL_CURRENT_USING_SUBID: { |
| 719 | subIdString = url.getLastPathSegment(); |
| 720 | try { |
Wink Saville | 85477f6 | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 721 | subId = Integer.parseInt(subIdString); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 722 | } catch (NumberFormatException e) { |
| 723 | loge("NumberFormatException" + e); |
| 724 | return null; |
| 725 | } |
| 726 | if (DBG) log("subIdString = " + subIdString + " subId = " + subId); |
| 727 | // FIXME alter the selection to pass subId |
| 728 | // selection = selection + "and subId = " |
| 729 | } |
| 730 | //intentional fall through from above case |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 731 | case URL_CURRENT: { |
| 732 | qb.appendWhere("current IS NOT NULL"); |
Sangcheol Lee | 4e18088 | 2011-04-01 19:24:52 -0700 | [diff] [blame] | 733 | // do not ignore the selection since MMS may use it. |
| 734 | //selection = null; |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 735 | break; |
| 736 | } |
| 737 | |
| 738 | case URL_ID: { |
| 739 | qb.appendWhere("_id = " + url.getPathSegments().get(1)); |
| 740 | break; |
| 741 | } |
| 742 | |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 743 | case URL_PREFERAPN_USING_SUBID: |
| 744 | case URL_PREFERAPN_NO_UPDATE_USING_SUBID: { |
| 745 | subIdString = url.getLastPathSegment(); |
| 746 | try { |
Wink Saville | 85477f6 | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 747 | subId = Integer.parseInt(subIdString); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 748 | } catch (NumberFormatException e) { |
| 749 | loge("NumberFormatException" + e); |
| 750 | return null; |
| 751 | } |
| 752 | if (DBG) log("subIdString = " + subIdString + " subId = " + subId); |
| 753 | } |
| 754 | //intentional fall through from above case |
Kazuhiro Ondo | d616ee6 | 2012-01-10 17:12:59 -0600 | [diff] [blame] | 755 | case URL_PREFERAPN: |
| 756 | case URL_PREFERAPN_NO_UPDATE: { |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 757 | qb.appendWhere("_id = " + getPreferredApnId(subId)); |
| 758 | break; |
| 759 | } |
| 760 | |
| 761 | case URL_SIMINFO: { |
| 762 | qb.setTables(SIMINFO_TABLE); |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 763 | break; |
| 764 | } |
| 765 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 766 | default: { |
| 767 | return null; |
| 768 | } |
| 769 | } |
| 770 | |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 771 | if (match != URL_SIMINFO) { |
| 772 | if (projectionIn != null) { |
| 773 | for (String column : projectionIn) { |
| 774 | if (Telephony.Carriers.TYPE.equals(column) || |
| 775 | Telephony.Carriers.MMSC.equals(column) || |
| 776 | Telephony.Carriers.MMSPROXY.equals(column) || |
| 777 | Telephony.Carriers.MMSPORT.equals(column) || |
| 778 | Telephony.Carriers.APN.equals(column)) { |
| 779 | // noop |
| 780 | } else { |
| 781 | checkPermission(); |
| 782 | break; |
| 783 | } |
Robert Greenwalt | 429cf07 | 2013-05-21 17:04:09 -0700 | [diff] [blame] | 784 | } |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 785 | } else { |
| 786 | // null returns all columns, so need permission check |
| 787 | checkPermission(); |
Robert Greenwalt | 429cf07 | 2013-05-21 17:04:09 -0700 | [diff] [blame] | 788 | } |
Robert Greenwalt | 429cf07 | 2013-05-21 17:04:09 -0700 | [diff] [blame] | 789 | } |
| 790 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 791 | SQLiteDatabase db = mOpenHelper.getReadableDatabase(); |
Hyejin Kim | cfdb743 | 2013-02-16 00:58:37 +0900 | [diff] [blame] | 792 | Cursor ret = null; |
| 793 | try { |
| 794 | ret = qb.query(db, projectionIn, selection, selectionArgs, null, null, sort); |
| 795 | } catch (SQLException e) { |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 796 | loge("got exception when querying: " + e); |
Hyejin Kim | cfdb743 | 2013-02-16 00:58:37 +0900 | [diff] [blame] | 797 | } |
| 798 | if (ret != null) |
| 799 | ret.setNotificationUri(getContext().getContentResolver(), url); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 800 | return ret; |
| 801 | } |
| 802 | |
| 803 | @Override |
| 804 | public String getType(Uri url) |
| 805 | { |
| 806 | switch (s_urlMatcher.match(url)) { |
| 807 | case URL_TELEPHONY: |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 808 | case URL_TELEPHONY_USING_SUBID: |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 809 | return "vnd.android.cursor.dir/telephony-carrier"; |
| 810 | |
| 811 | case URL_ID: |
| 812 | return "vnd.android.cursor.item/telephony-carrier"; |
| 813 | |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 814 | case URL_PREFERAPN_USING_SUBID: |
| 815 | case URL_PREFERAPN_NO_UPDATE_USING_SUBID: |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 816 | case URL_PREFERAPN: |
Kazuhiro Ondo | d616ee6 | 2012-01-10 17:12:59 -0600 | [diff] [blame] | 817 | case URL_PREFERAPN_NO_UPDATE: |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 818 | return "vnd.android.cursor.item/telephony-carrier"; |
| 819 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 820 | default: |
| 821 | throw new IllegalArgumentException("Unknown URL " + url); |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | @Override |
| 826 | public Uri insert(Uri url, ContentValues initialValues) |
| 827 | { |
| 828 | Uri result = null; |
Wink Saville | 85477f6 | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 829 | int subId = SubscriptionManager.getDefaultDataSubId(); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 830 | |
| 831 | checkPermission(); |
| 832 | |
| 833 | SQLiteDatabase db = mOpenHelper.getWritableDatabase(); |
| 834 | int match = s_urlMatcher.match(url); |
| 835 | boolean notify = false; |
| 836 | switch (match) |
| 837 | { |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 838 | case URL_TELEPHONY_USING_SUBID: |
| 839 | { |
| 840 | String subIdString = url.getLastPathSegment(); |
| 841 | try { |
Wink Saville | 85477f6 | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 842 | subId = Integer.parseInt(subIdString); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 843 | } catch (NumberFormatException e) { |
| 844 | loge("NumberFormatException" + e); |
| 845 | return result; |
| 846 | } |
| 847 | if (DBG) log("subIdString = " + subIdString + " subId = " + subId); |
| 848 | } |
| 849 | //intentional fall through from above case |
| 850 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 851 | case URL_TELEPHONY: |
| 852 | { |
| 853 | ContentValues values; |
| 854 | if (initialValues != null) { |
| 855 | values = new ContentValues(initialValues); |
| 856 | } else { |
| 857 | values = new ContentValues(); |
| 858 | } |
| 859 | |
Amit Mahajan | b068886 | 2014-08-13 16:53:51 +0000 | [diff] [blame] | 860 | values = DatabaseHelper.setDefaultValue(values); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 861 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 862 | long rowID = db.insert(CARRIERS_TABLE, null, values); |
| 863 | if (rowID > 0) |
| 864 | { |
| 865 | result = ContentUris.withAppendedId(Telephony.Carriers.CONTENT_URI, rowID); |
| 866 | notify = true; |
| 867 | } |
| 868 | |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 869 | if (VDBG) log("inserted " + values.toString() + " rowID = " + rowID); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 870 | break; |
| 871 | } |
| 872 | |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 873 | case URL_CURRENT_USING_SUBID: |
| 874 | { |
| 875 | String subIdString = url.getLastPathSegment(); |
| 876 | try { |
Wink Saville | 85477f6 | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 877 | subId = Integer.parseInt(subIdString); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 878 | } catch (NumberFormatException e) { |
| 879 | loge("NumberFormatException" + e); |
| 880 | return result; |
| 881 | } |
| 882 | if (DBG) log("subIdString = " + subIdString + " subId = " + subId); |
| 883 | // FIXME use subId in the query |
| 884 | } |
| 885 | //intentional fall through from above case |
| 886 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 887 | case URL_CURRENT: |
| 888 | { |
| 889 | // null out the previous operator |
| 890 | db.update("carriers", s_currentNullMap, "current IS NOT NULL", null); |
| 891 | |
| 892 | String numeric = initialValues.getAsString("numeric"); |
| 893 | int updated = db.update("carriers", s_currentSetMap, |
| 894 | "numeric = '" + numeric + "'", null); |
| 895 | |
| 896 | if (updated > 0) |
| 897 | { |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 898 | if (VDBG) log("Setting numeric '" + numeric + "' to be the current operator"); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 899 | } |
| 900 | else |
| 901 | { |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 902 | loge("Failed setting numeric '" + numeric + "' to the current operator"); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 903 | } |
| 904 | break; |
| 905 | } |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 906 | |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 907 | case URL_PREFERAPN_USING_SUBID: |
| 908 | case URL_PREFERAPN_NO_UPDATE_USING_SUBID: |
| 909 | { |
| 910 | String subIdString = url.getLastPathSegment(); |
| 911 | try { |
Wink Saville | 85477f6 | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 912 | subId = Integer.parseInt(subIdString); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 913 | } catch (NumberFormatException e) { |
| 914 | loge("NumberFormatException" + e); |
| 915 | return result; |
| 916 | } |
| 917 | if (DBG) log("subIdString = " + subIdString + " subId = " + subId); |
| 918 | } |
| 919 | //intentional fall through from above case |
| 920 | |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 921 | case URL_PREFERAPN: |
Kazuhiro Ondo | d616ee6 | 2012-01-10 17:12:59 -0600 | [diff] [blame] | 922 | case URL_PREFERAPN_NO_UPDATE: |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 923 | { |
| 924 | if (initialValues != null) { |
| 925 | if(initialValues.containsKey(COLUMN_APN_ID)) { |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 926 | setPreferredApnId(initialValues.getAsLong(COLUMN_APN_ID), subId); |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 927 | } |
| 928 | } |
| 929 | break; |
| 930 | } |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 931 | |
| 932 | case URL_SIMINFO: { |
| 933 | long id = db.insert(SIMINFO_TABLE, null, initialValues); |
| 934 | result = ContentUris.withAppendedId(SubscriptionManager.CONTENT_URI, id); |
| 935 | break; |
| 936 | } |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | if (notify) { |
Amith Yamasani | 2708517 | 2014-11-06 09:01:20 -0800 | [diff] [blame] | 940 | getContext().getContentResolver().notifyChange(Telephony.Carriers.CONTENT_URI, null, |
| 941 | true, UserHandle.USER_ALL); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | return result; |
| 945 | } |
| 946 | |
| 947 | @Override |
| 948 | public int delete(Uri url, String where, String[] whereArgs) |
| 949 | { |
Kazuhiro Ondo | d616ee6 | 2012-01-10 17:12:59 -0600 | [diff] [blame] | 950 | int count = 0; |
Wink Saville | 85477f6 | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 951 | int subId = SubscriptionManager.getDefaultDataSubId(); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 952 | |
| 953 | checkPermission(); |
Jaikumar Ganesh | 8e1a4f9 | 2009-10-26 13:07:37 -0700 | [diff] [blame] | 954 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 955 | SQLiteDatabase db = mOpenHelper.getWritableDatabase(); |
| 956 | int match = s_urlMatcher.match(url); |
| 957 | switch (match) |
| 958 | { |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 959 | case URL_TELEPHONY_USING_SUBID: |
| 960 | { |
| 961 | String subIdString = url.getLastPathSegment(); |
| 962 | try { |
Wink Saville | 85477f6 | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 963 | subId = Integer.parseInt(subIdString); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 964 | } catch (NumberFormatException e) { |
| 965 | loge("NumberFormatException" + e); |
| 966 | throw new IllegalArgumentException("Invalid subId " + url); |
| 967 | } |
| 968 | if (DBG) log("subIdString = " + subIdString + " subId = " + subId); |
| 969 | // FIXME use subId in query |
| 970 | } |
| 971 | //intentional fall through from above case |
| 972 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 973 | case URL_TELEPHONY: |
| 974 | { |
| 975 | count = db.delete(CARRIERS_TABLE, where, whereArgs); |
| 976 | break; |
| 977 | } |
| 978 | |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 979 | case URL_CURRENT_USING_SUBID: { |
| 980 | String subIdString = url.getLastPathSegment(); |
| 981 | try { |
Wink Saville | 85477f6 | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 982 | subId = Integer.parseInt(subIdString); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 983 | } catch (NumberFormatException e) { |
| 984 | loge("NumberFormatException" + e); |
| 985 | throw new IllegalArgumentException("Invalid subId " + url); |
| 986 | } |
| 987 | if (DBG) log("subIdString = " + subIdString + " subId = " + subId); |
| 988 | // FIXME use subId in query |
| 989 | } |
| 990 | //intentional fall through from above case |
| 991 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 992 | case URL_CURRENT: |
| 993 | { |
| 994 | count = db.delete(CARRIERS_TABLE, where, whereArgs); |
| 995 | break; |
| 996 | } |
Jaikumar Ganesh | 8e1a4f9 | 2009-10-26 13:07:37 -0700 | [diff] [blame] | 997 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 998 | case URL_ID: |
| 999 | { |
| 1000 | count = db.delete(CARRIERS_TABLE, Telephony.Carriers._ID + "=?", |
| 1001 | new String[] { url.getLastPathSegment() }); |
| 1002 | break; |
| 1003 | } |
| 1004 | |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 1005 | case URL_RESTOREAPN_USING_SUBID: { |
| 1006 | String subIdString = url.getLastPathSegment(); |
| 1007 | try { |
Wink Saville | 85477f6 | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 1008 | subId = Integer.parseInt(subIdString); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 1009 | } catch (NumberFormatException e) { |
| 1010 | loge("NumberFormatException" + e); |
| 1011 | throw new IllegalArgumentException("Invalid subId " + url); |
| 1012 | } |
| 1013 | if (DBG) log("subIdString = " + subIdString + " subId = " + subId); |
| 1014 | // FIXME use subId in query |
| 1015 | } |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 1016 | case URL_RESTOREAPN: { |
| 1017 | count = 1; |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 1018 | restoreDefaultAPN(subId); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 1019 | break; |
| 1020 | } |
| 1021 | |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 1022 | case URL_PREFERAPN_USING_SUBID: |
| 1023 | case URL_PREFERAPN_NO_UPDATE_USING_SUBID: { |
| 1024 | String subIdString = url.getLastPathSegment(); |
| 1025 | try { |
Wink Saville | 85477f6 | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 1026 | subId = Integer.parseInt(subIdString); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 1027 | } catch (NumberFormatException e) { |
| 1028 | loge("NumberFormatException" + e); |
| 1029 | throw new IllegalArgumentException("Invalid subId " + url); |
| 1030 | } |
| 1031 | if (DBG) log("subIdString = " + subIdString + " subId = " + subId); |
| 1032 | } |
| 1033 | //intentional fall through from above case |
| 1034 | |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 1035 | case URL_PREFERAPN: |
Kazuhiro Ondo | d616ee6 | 2012-01-10 17:12:59 -0600 | [diff] [blame] | 1036 | case URL_PREFERAPN_NO_UPDATE: |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 1037 | { |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 1038 | setPreferredApnId((long)-1, subId); |
| 1039 | if ((match == URL_PREFERAPN) || (match == URL_PREFERAPN_USING_SUBID)) count = 1; |
| 1040 | break; |
| 1041 | } |
| 1042 | |
| 1043 | case URL_SIMINFO: { |
| 1044 | count = db.delete(SIMINFO_TABLE, where, whereArgs); |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 1045 | break; |
| 1046 | } |
| 1047 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 1048 | default: { |
| 1049 | throw new UnsupportedOperationException("Cannot delete that URL: " + url); |
| 1050 | } |
| 1051 | } |
| 1052 | |
| 1053 | if (count > 0) { |
Amith Yamasani | 2708517 | 2014-11-06 09:01:20 -0800 | [diff] [blame] | 1054 | getContext().getContentResolver().notifyChange(Telephony.Carriers.CONTENT_URI, null, |
| 1055 | true, UserHandle.USER_ALL); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | return count; |
| 1059 | } |
| 1060 | |
| 1061 | @Override |
| 1062 | public int update(Uri url, ContentValues values, String where, String[] whereArgs) |
| 1063 | { |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 1064 | int count = 0; |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 1065 | int uriType = URL_UNKNOWN; |
Wink Saville | 85477f6 | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 1066 | int subId = SubscriptionManager.getDefaultDataSubId(); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 1067 | |
| 1068 | checkPermission(); |
| 1069 | |
| 1070 | SQLiteDatabase db = mOpenHelper.getWritableDatabase(); |
| 1071 | int match = s_urlMatcher.match(url); |
| 1072 | switch (match) |
| 1073 | { |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 1074 | case URL_TELEPHONY_USING_SUBID: |
| 1075 | { |
| 1076 | String subIdString = url.getLastPathSegment(); |
| 1077 | try { |
Wink Saville | 85477f6 | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 1078 | subId = Integer.parseInt(subIdString); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 1079 | } catch (NumberFormatException e) { |
| 1080 | loge("NumberFormatException" + e); |
| 1081 | throw new IllegalArgumentException("Invalid subId " + url); |
| 1082 | } |
| 1083 | if (DBG) log("subIdString = " + subIdString + " subId = " + subId); |
| 1084 | //FIXME use subId in the query |
| 1085 | } |
| 1086 | //intentional fall through from above case |
| 1087 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 1088 | case URL_TELEPHONY: |
| 1089 | { |
| 1090 | count = db.update(CARRIERS_TABLE, values, where, whereArgs); |
| 1091 | break; |
| 1092 | } |
| 1093 | |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 1094 | case URL_CURRENT_USING_SUBID: |
| 1095 | { |
| 1096 | String subIdString = url.getLastPathSegment(); |
| 1097 | try { |
Wink Saville | 85477f6 | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 1098 | subId = Integer.parseInt(subIdString); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 1099 | } catch (NumberFormatException e) { |
| 1100 | loge("NumberFormatException" + e); |
| 1101 | throw new IllegalArgumentException("Invalid subId " + url); |
| 1102 | } |
| 1103 | if (DBG) log("subIdString = " + subIdString + " subId = " + subId); |
| 1104 | //FIXME use subId in the query |
| 1105 | } |
| 1106 | //intentional fall through from above case |
| 1107 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 1108 | case URL_CURRENT: |
| 1109 | { |
| 1110 | count = db.update(CARRIERS_TABLE, values, where, whereArgs); |
| 1111 | break; |
| 1112 | } |
| 1113 | |
| 1114 | case URL_ID: |
| 1115 | { |
| 1116 | if (where != null || whereArgs != null) { |
| 1117 | throw new UnsupportedOperationException( |
| 1118 | "Cannot update URL " + url + " with a where clause"); |
| 1119 | } |
| 1120 | count = db.update(CARRIERS_TABLE, values, Telephony.Carriers._ID + "=?", |
| 1121 | new String[] { url.getLastPathSegment() }); |
| 1122 | break; |
| 1123 | } |
| 1124 | |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 1125 | case URL_PREFERAPN_USING_SUBID: |
| 1126 | case URL_PREFERAPN_NO_UPDATE_USING_SUBID: |
| 1127 | { |
| 1128 | String subIdString = url.getLastPathSegment(); |
| 1129 | try { |
Wink Saville | 85477f6 | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 1130 | subId = Integer.parseInt(subIdString); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 1131 | } catch (NumberFormatException e) { |
| 1132 | loge("NumberFormatException" + e); |
| 1133 | throw new IllegalArgumentException("Invalid subId " + url); |
| 1134 | } |
| 1135 | if (DBG) log("subIdString = " + subIdString + " subId = " + subId); |
| 1136 | } |
| 1137 | |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 1138 | case URL_PREFERAPN: |
Kazuhiro Ondo | d616ee6 | 2012-01-10 17:12:59 -0600 | [diff] [blame] | 1139 | case URL_PREFERAPN_NO_UPDATE: |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 1140 | { |
| 1141 | if (values != null) { |
| 1142 | if (values.containsKey(COLUMN_APN_ID)) { |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 1143 | setPreferredApnId(values.getAsLong(COLUMN_APN_ID), subId); |
| 1144 | if ((match == URL_PREFERAPN) || |
| 1145 | (match == URL_PREFERAPN_USING_SUBID)) { |
| 1146 | count = 1; |
| 1147 | } |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 1148 | } |
| 1149 | } |
| 1150 | break; |
| 1151 | } |
| 1152 | |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 1153 | case URL_SIMINFO: { |
| 1154 | count = db.update(SIMINFO_TABLE, values, where, whereArgs); |
| 1155 | uriType = URL_SIMINFO; |
| 1156 | break; |
| 1157 | } |
| 1158 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 1159 | default: { |
| 1160 | throw new UnsupportedOperationException("Cannot update that URL: " + url); |
| 1161 | } |
| 1162 | } |
| 1163 | |
| 1164 | if (count > 0) { |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 1165 | switch (uriType) { |
| 1166 | case URL_SIMINFO: |
| 1167 | getContext().getContentResolver().notifyChange( |
Amith Yamasani | 2708517 | 2014-11-06 09:01:20 -0800 | [diff] [blame] | 1168 | SubscriptionManager.CONTENT_URI, null, true, UserHandle.USER_ALL); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 1169 | break; |
| 1170 | default: |
| 1171 | getContext().getContentResolver().notifyChange( |
Amith Yamasani | 2708517 | 2014-11-06 09:01:20 -0800 | [diff] [blame] | 1172 | Telephony.Carriers.CONTENT_URI, null, true, UserHandle.USER_ALL); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 1173 | } |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | return count; |
| 1177 | } |
| 1178 | |
| 1179 | private void checkPermission() { |
Shishir Agrawal | acf787b | 2014-07-14 17:13:51 -0700 | [diff] [blame] | 1180 | int status = getContext().checkCallingOrSelfPermission( |
| 1181 | "android.permission.WRITE_APN_SETTINGS"); |
| 1182 | if (status == PackageManager.PERMISSION_GRANTED) { |
| 1183 | return; |
| 1184 | } |
| 1185 | |
| 1186 | PackageManager packageManager = getContext().getPackageManager(); |
| 1187 | String[] packages = packageManager.getPackagesForUid(Binder.getCallingUid()); |
| 1188 | |
| 1189 | TelephonyManager telephonyManager = |
| 1190 | (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE); |
| 1191 | for (String pkg : packages) { |
| 1192 | if (telephonyManager.checkCarrierPrivilegesForPackage(pkg) == |
| 1193 | TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 1194 | return; |
| 1195 | } |
| 1196 | } |
| 1197 | throw new SecurityException("No permission to write APN settings"); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 1198 | } |
| 1199 | |
Wink Saville | d7c9350 | 2011-06-04 07:17:01 -0700 | [diff] [blame] | 1200 | private DatabaseHelper mOpenHelper; |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 1201 | |
Wink Saville | 85477f6 | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 1202 | private void restoreDefaultAPN(int subId) { |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 1203 | SQLiteDatabase db = mOpenHelper.getWritableDatabase(); |
| 1204 | |
Hyejin Kim | cfdb743 | 2013-02-16 00:58:37 +0900 | [diff] [blame] | 1205 | try { |
| 1206 | db.delete(CARRIERS_TABLE, null, null); |
| 1207 | } catch (SQLException e) { |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 1208 | loge("got exception when deleting to restore: " + e); |
Hyejin Kim | cfdb743 | 2013-02-16 00:58:37 +0900 | [diff] [blame] | 1209 | } |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 1210 | setPreferredApnId((long)-1, subId); |
Wink Saville | d7c9350 | 2011-06-04 07:17:01 -0700 | [diff] [blame] | 1211 | mOpenHelper.initDatabase(db); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 1212 | } |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 1213 | |
| 1214 | /** |
| 1215 | * Log with debug |
| 1216 | * |
| 1217 | * @param s is string log |
| 1218 | */ |
| 1219 | private static void log(String s) { |
| 1220 | Log.d(TAG, s); |
| 1221 | } |
| 1222 | |
| 1223 | private static void loge(String s) { |
| 1224 | Log.e(TAG, s); |
| 1225 | } |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 1226 | } |