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 | |
Jeff Davidson | b114ed2 | 2017-04-09 14:55:23 -0700 | [diff] [blame] | 20 | import static android.provider.Telephony.Carriers.APN; |
Jordan Liu | 92da8c8 | 2018-04-10 16:00:06 -0700 | [diff] [blame] | 21 | import static android.provider.Telephony.Carriers.APN_SET_ID; |
Jeff Davidson | b114ed2 | 2017-04-09 14:55:23 -0700 | [diff] [blame] | 22 | import static android.provider.Telephony.Carriers.AUTH_TYPE; |
| 23 | import static android.provider.Telephony.Carriers.BEARER; |
| 24 | import static android.provider.Telephony.Carriers.BEARER_BITMASK; |
| 25 | import static android.provider.Telephony.Carriers.CARRIER_DELETED; |
| 26 | import static android.provider.Telephony.Carriers.CARRIER_DELETED_BUT_PRESENT_IN_XML; |
| 27 | import static android.provider.Telephony.Carriers.CARRIER_EDITED; |
| 28 | import static android.provider.Telephony.Carriers.CARRIER_ENABLED; |
calvinpan | 2b41944 | 2018-10-23 15:05:11 +0800 | [diff] [blame] | 29 | import static android.provider.Telephony.Carriers.CARRIER_ID; |
Jeff Davidson | b114ed2 | 2017-04-09 14:55:23 -0700 | [diff] [blame] | 30 | import static android.provider.Telephony.Carriers.CONTENT_URI; |
| 31 | import static android.provider.Telephony.Carriers.CURRENT; |
Chaitanya Saggurthi | 58ab3ad | 2017-12-05 22:09:09 +0900 | [diff] [blame] | 32 | import static android.provider.Telephony.Carriers.DEFAULT_SORT_ORDER; |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 33 | import static android.provider.Telephony.Carriers.EDITED_STATUS; |
| 34 | import static android.provider.Telephony.Carriers.MAX_CONNECTIONS; |
| 35 | import static android.provider.Telephony.Carriers.TIME_LIMIT_FOR_MAX_CONNECTIONS; |
Jeff Davidson | b114ed2 | 2017-04-09 14:55:23 -0700 | [diff] [blame] | 36 | import static android.provider.Telephony.Carriers.MCC; |
| 37 | import static android.provider.Telephony.Carriers.MMSC; |
| 38 | import static android.provider.Telephony.Carriers.MMSPORT; |
| 39 | import static android.provider.Telephony.Carriers.MMSPROXY; |
| 40 | import static android.provider.Telephony.Carriers.MNC; |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 41 | import static android.provider.Telephony.Carriers.MODEM_PERSIST; |
Jeff Davidson | b114ed2 | 2017-04-09 14:55:23 -0700 | [diff] [blame] | 42 | import static android.provider.Telephony.Carriers.MTU; |
| 43 | import static android.provider.Telephony.Carriers.MVNO_MATCH_DATA; |
| 44 | import static android.provider.Telephony.Carriers.MVNO_TYPE; |
| 45 | import static android.provider.Telephony.Carriers.NAME; |
Cassie | a58ce71 | 2017-12-06 16:21:50 -0800 | [diff] [blame] | 46 | import static android.provider.Telephony.Carriers.NETWORK_TYPE_BITMASK; |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 47 | import static android.provider.Telephony.Carriers.NO_APN_SET_ID; |
Jeff Davidson | b114ed2 | 2017-04-09 14:55:23 -0700 | [diff] [blame] | 48 | import static android.provider.Telephony.Carriers.NUMERIC; |
yuemingw | c4d40a7 | 2017-11-08 14:14:37 +0000 | [diff] [blame] | 49 | import static android.provider.Telephony.Carriers.OWNED_BY; |
yuemingw | c4d40a7 | 2017-11-08 14:14:37 +0000 | [diff] [blame] | 50 | import static android.provider.Telephony.Carriers.OWNED_BY_DPC; |
calvinpan | ba94b59 | 2018-11-01 09:09:30 +0800 | [diff] [blame] | 51 | import static android.provider.Telephony.Carriers.OWNED_BY_OTHERS; |
Jeff Davidson | b114ed2 | 2017-04-09 14:55:23 -0700 | [diff] [blame] | 52 | import static android.provider.Telephony.Carriers.PASSWORD; |
| 53 | import static android.provider.Telephony.Carriers.PORT; |
| 54 | import static android.provider.Telephony.Carriers.PROFILE_ID; |
| 55 | import static android.provider.Telephony.Carriers.PROTOCOL; |
| 56 | import static android.provider.Telephony.Carriers.PROXY; |
| 57 | import static android.provider.Telephony.Carriers.ROAMING_PROTOCOL; |
| 58 | import static android.provider.Telephony.Carriers.SERVER; |
Yuuki Habu | 95aacb1 | 2019-02-22 10:49:06 +0900 | [diff] [blame] | 59 | import static android.provider.Telephony.Carriers.SKIP_464XLAT; |
| 60 | import static android.provider.Telephony.Carriers.SKIP_464XLAT_DEFAULT; |
Jeff Davidson | b114ed2 | 2017-04-09 14:55:23 -0700 | [diff] [blame] | 61 | import static android.provider.Telephony.Carriers.SUBSCRIPTION_ID; |
| 62 | import static android.provider.Telephony.Carriers.TYPE; |
| 63 | import static android.provider.Telephony.Carriers.UNEDITED; |
| 64 | import static android.provider.Telephony.Carriers.USER; |
| 65 | import static android.provider.Telephony.Carriers.USER_DELETED; |
| 66 | import static android.provider.Telephony.Carriers.USER_DELETED_BUT_PRESENT_IN_XML; |
Amit Mahajan | 460d703 | 2017-07-17 14:42:33 -0700 | [diff] [blame] | 67 | import static android.provider.Telephony.Carriers.USER_EDITABLE; |
Jeff Davidson | b114ed2 | 2017-04-09 14:55:23 -0700 | [diff] [blame] | 68 | import static android.provider.Telephony.Carriers.USER_EDITED; |
| 69 | import static android.provider.Telephony.Carriers.USER_VISIBLE; |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 70 | import static android.provider.Telephony.Carriers.WAIT_TIME_RETRY; |
Jeff Davidson | b114ed2 | 2017-04-09 14:55:23 -0700 | [diff] [blame] | 71 | import static android.provider.Telephony.Carriers._ID; |
| 72 | |
calvinpan | 33a10a0 | 2019-11-04 21:36:12 +0800 | [diff] [blame] | 73 | import android.annotation.NonNull; |
Hall Liu | 018f8b1 | 2020-02-25 15:58:56 -0800 | [diff] [blame] | 74 | import android.app.compat.CompatChanges; |
Jordan Liu | 3de76f8 | 2017-05-15 15:21:01 -0700 | [diff] [blame] | 75 | import android.content.ComponentName; |
Jaikumar Ganesh | 8e1a4f9 | 2009-10-26 13:07:37 -0700 | [diff] [blame] | 76 | import android.content.ContentProvider; |
chen xu | 4590bd7 | 2018-10-18 14:07:02 -0700 | [diff] [blame] | 77 | import android.content.ContentResolver; |
Jaikumar Ganesh | 8e1a4f9 | 2009-10-26 13:07:37 -0700 | [diff] [blame] | 78 | import android.content.ContentUris; |
| 79 | import android.content.ContentValues; |
| 80 | import android.content.Context; |
Jordan Liu | 3de76f8 | 2017-05-15 15:21:01 -0700 | [diff] [blame] | 81 | import android.content.Intent; |
| 82 | import android.content.ServiceConnection; |
Jaikumar Ganesh | 8e1a4f9 | 2009-10-26 13:07:37 -0700 | [diff] [blame] | 83 | import android.content.SharedPreferences; |
| 84 | import android.content.UriMatcher; |
Shishir Agrawal | acf787b | 2014-07-14 17:13:51 -0700 | [diff] [blame] | 85 | import android.content.pm.PackageManager; |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 86 | import android.content.res.Resources; |
| 87 | import android.content.res.XmlResourceParser; |
| 88 | import android.database.Cursor; |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 89 | import android.database.MatrixCursor; |
jewon.lee | 4167fcc | 2013-01-17 13:10:37 +0900 | [diff] [blame] | 90 | import android.database.SQLException; |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 91 | import android.database.sqlite.SQLiteDatabase; |
Wink Saville | 6de1027 | 2014-06-22 07:38:43 -0700 | [diff] [blame] | 92 | import android.database.sqlite.SQLiteException; |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 93 | import android.database.sqlite.SQLiteOpenHelper; |
| 94 | import android.database.sqlite.SQLiteQueryBuilder; |
| 95 | import android.net.Uri; |
Shishir Agrawal | acf787b | 2014-07-14 17:13:51 -0700 | [diff] [blame] | 96 | import android.os.Binder; |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 97 | import android.os.Environment; |
Jordan Liu | 3de76f8 | 2017-05-15 15:21:01 -0700 | [diff] [blame] | 98 | import android.os.IBinder; |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 99 | import android.os.Process; |
Jordan Liu | 3de76f8 | 2017-05-15 15:21:01 -0700 | [diff] [blame] | 100 | import android.os.RemoteException; |
Hall Liu | 7ee663d | 2019-11-21 16:30:47 -0800 | [diff] [blame] | 101 | import android.os.ServiceManager; |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 102 | import android.os.SystemProperties; |
Amith Yamasani | 887288c | 2014-11-06 09:01:20 -0800 | [diff] [blame] | 103 | import android.os.UserHandle; |
Hall Liu | 5479f4d | 2018-07-14 00:31:13 +0000 | [diff] [blame] | 104 | import android.provider.Telephony; |
SongFerngWang | 64fb3dd | 2019-12-02 20:59:47 +0800 | [diff] [blame] | 105 | import android.telephony.Annotation; |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 106 | import android.telephony.SubscriptionManager; |
| 107 | import android.telephony.TelephonyManager; |
yuemingw | b9d42b5 | 2018-06-13 12:56:32 +0100 | [diff] [blame] | 108 | import android.telephony.data.ApnSetting; |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 109 | import android.text.TextUtils; |
zoey chen | 715880a | 2019-11-12 18:47:02 +0800 | [diff] [blame] | 110 | import android.util.ArrayMap; |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 111 | import android.util.Log; |
Jordan Liu | 6cf9bda | 2017-05-19 11:42:55 -0700 | [diff] [blame] | 112 | import android.util.Pair; |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 113 | import android.util.Xml; |
Jaikumar Ganesh | 8e1a4f9 | 2009-10-26 13:07:37 -0700 | [diff] [blame] | 114 | |
Jordan Liu | 3de76f8 | 2017-05-15 15:21:01 -0700 | [diff] [blame] | 115 | import com.android.internal.annotations.GuardedBy; |
Jordan Liu | e6f0bce | 2016-09-21 18:31:43 -0700 | [diff] [blame] | 116 | import com.android.internal.annotations.VisibleForTesting; |
Amit Mahajan | 0c1d0dd | 2020-04-21 20:38:29 +0000 | [diff] [blame] | 117 | import com.android.internal.telephony.PhoneFactory; |
Jeff Davidson | b114ed2 | 2017-04-09 14:55:23 -0700 | [diff] [blame] | 118 | import com.android.internal.util.XmlUtils; |
Chen Xu | 9e3e019 | 2019-09-16 18:26:19 -0700 | [diff] [blame] | 119 | import android.service.carrier.IApnSourceService; |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 120 | |
| 121 | import org.xmlpull.v1.XmlPullParser; |
| 122 | import org.xmlpull.v1.XmlPullParserException; |
| 123 | |
Niklas Lindgren | 9392c70 | 2018-05-03 15:58:06 +0200 | [diff] [blame] | 124 | import java.io.ByteArrayOutputStream; |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 125 | import java.io.File; |
Jayachandran C | 0c685ce | 2019-10-17 11:11:56 -0700 | [diff] [blame] | 126 | import java.io.FileInputStream; |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 127 | import java.io.FileNotFoundException; |
| 128 | import java.io.FileReader; |
| 129 | import java.io.IOException; |
Niklas Lindgren | 9392c70 | 2018-05-03 15:58:06 +0200 | [diff] [blame] | 130 | import java.io.InputStream; |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 131 | import java.util.ArrayList; |
| 132 | import java.util.Arrays; |
James.cf Lin | 90f42ec | 2020-04-21 22:23:31 +0800 | [diff] [blame] | 133 | import java.util.concurrent.atomic.AtomicBoolean; |
Jordan Liu | 5d66621 | 2017-11-13 15:07:52 -0800 | [diff] [blame] | 134 | import java.util.HashMap; |
Jordan Liu | 8b78f71 | 2018-05-21 11:10:48 -0700 | [diff] [blame] | 135 | import java.util.HashSet; |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 136 | import java.util.List; |
Hall Liu | 5479f4d | 2018-07-14 00:31:13 +0000 | [diff] [blame] | 137 | import java.util.Locale; |
Amit Mahajan | 91c5dff | 2015-10-20 11:13:19 -0700 | [diff] [blame] | 138 | import java.util.Map; |
Jordan Liu | 8b78f71 | 2018-05-21 11:10:48 -0700 | [diff] [blame] | 139 | import java.util.Set; |
Jayachandran C | 0c685ce | 2019-10-17 11:11:56 -0700 | [diff] [blame] | 140 | import java.util.zip.CheckedInputStream; |
calvinpan | ba94b59 | 2018-11-01 09:09:30 +0800 | [diff] [blame] | 141 | import java.util.zip.CRC32; |
Wink Saville | d7c9350 | 2011-06-04 07:17:01 -0700 | [diff] [blame] | 142 | |
xiangyu.deng | 233d88c | 2021-07-16 14:09:40 +0800 | [diff] [blame] | 143 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
| 144 | import com.android.internal.telephony.uicc.IccRecords; |
| 145 | import com.android.internal.telephony.uicc.UiccController; |
| 146 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 147 | public class TelephonyProvider extends ContentProvider |
| 148 | { |
| 149 | private static final String DATABASE_NAME = "telephony.db"; |
Fyodor Kupolov | 66304f6 | 2017-09-01 16:13:49 -0700 | [diff] [blame] | 150 | private static final int IDLE_CONNECTION_TIMEOUT_MS = 30000; |
Wink Saville | d7c9350 | 2011-06-04 07:17:01 -0700 | [diff] [blame] | 151 | private static final boolean DBG = true; |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 152 | private static final boolean VDBG = false; // STOPSHIP if true |
Jaikumar Ganesh | 8e1a4f9 | 2009-10-26 13:07:37 -0700 | [diff] [blame] | 153 | |
Brad Ebinger | 748c762 | 2020-01-22 16:12:04 -0800 | [diff] [blame] | 154 | private static final int DATABASE_VERSION = 45 << 16; |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 155 | private static final int URL_UNKNOWN = 0; |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 156 | private static final int URL_TELEPHONY = 1; |
| 157 | private static final int URL_CURRENT = 2; |
| 158 | private static final int URL_ID = 3; |
| 159 | private static final int URL_RESTOREAPN = 4; |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 160 | private static final int URL_PREFERAPN = 5; |
Kazuhiro Ondo | d616ee6 | 2012-01-10 17:12:59 -0600 | [diff] [blame] | 161 | private static final int URL_PREFERAPN_NO_UPDATE = 6; |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 162 | private static final int URL_SIMINFO = 7; |
| 163 | private static final int URL_TELEPHONY_USING_SUBID = 8; |
| 164 | private static final int URL_CURRENT_USING_SUBID = 9; |
| 165 | private static final int URL_RESTOREAPN_USING_SUBID = 10; |
| 166 | private static final int URL_PREFERAPN_USING_SUBID = 11; |
| 167 | private static final int URL_PREFERAPN_NO_UPDATE_USING_SUBID = 12; |
| 168 | private static final int URL_SIMINFO_USING_SUBID = 13; |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 169 | private static final int URL_UPDATE_DB = 14; |
Amit Mahajan | 7005be8 | 2017-04-26 10:35:18 -0700 | [diff] [blame] | 170 | private static final int URL_DELETE = 15; |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 171 | private static final int URL_DPC = 16; |
| 172 | private static final int URL_DPC_ID = 17; |
| 173 | private static final int URL_FILTERED = 18; |
yuemingw | cd80d17 | 2018-01-15 14:08:55 +0000 | [diff] [blame] | 174 | private static final int URL_FILTERED_ID = 19; |
| 175 | private static final int URL_ENFORCE_MANAGED = 20; |
Jordan Liu | 748c832 | 2020-07-15 15:09:12 -0700 | [diff] [blame] | 176 | // URL_PREFERAPNSET and URL_PREFERAPNSET_USING_SUBID return all APNs for the current |
| 177 | // carrier which have an apn_set_id equal to the preferred APN |
| 178 | // (if no preferred APN, or preferred APN has no set id, the query will return null) |
Jordan Liu | c6078b7 | 2018-05-01 11:34:21 -0700 | [diff] [blame] | 179 | private static final int URL_PREFERAPNSET = 21; |
| 180 | private static final int URL_PREFERAPNSET_USING_SUBID = 22; |
calvinpan | ba94b59 | 2018-11-01 09:09:30 +0800 | [diff] [blame] | 181 | private static final int URL_SIM_APN_LIST = 23; |
| 182 | private static final int URL_SIM_APN_LIST_ID = 24; |
Malcolm Chen | 09ebf8d | 2018-12-07 13:45:54 -0800 | [diff] [blame] | 183 | private static final int URL_FILTERED_USING_SUBID = 25; |
Josh Hou | 42049bb | 2018-12-10 22:22:05 +0800 | [diff] [blame] | 184 | private static final int URL_SIM_APN_LIST_FILTERED = 26; |
| 185 | private static final int URL_SIM_APN_LIST_FILTERED_ID = 27; |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 186 | |
zoey chen | 715880a | 2019-11-12 18:47:02 +0800 | [diff] [blame] | 187 | /** |
| 188 | * Default value for mtu if it's not set. Moved from PhoneConstants. |
| 189 | */ |
| 190 | private static final int UNSPECIFIED_INT = -1; |
| 191 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 192 | private static final String TAG = "TelephonyProvider"; |
| 193 | private static final String CARRIERS_TABLE = "carriers"; |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 194 | private static final String CARRIERS_TABLE_TMP = "carriers_tmp"; |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 195 | private static final String SIMINFO_TABLE = "siminfo"; |
yinxu | 3d98b6c | 2018-01-05 16:27:30 -0800 | [diff] [blame] | 196 | private static final String SIMINFO_TABLE_TMP = "siminfo_tmp"; |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 197 | |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 198 | private static final String PREF_FILE_APN = "preferred-apn"; |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 199 | private static final String COLUMN_APN_ID = "apn_id"; |
Amit Mahajan | bf7144e | 2017-08-29 11:39:48 -0700 | [diff] [blame] | 200 | private static final String EXPLICIT_SET_CALLED = "explicit_set_called"; |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 201 | |
Amit Mahajan | 91c5dff | 2015-10-20 11:13:19 -0700 | [diff] [blame] | 202 | private static final String PREF_FILE_FULL_APN = "preferred-full-apn"; |
| 203 | private static final String DB_VERSION_KEY = "version"; |
| 204 | |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 205 | private static final String BUILD_ID_FILE = "build-id"; |
| 206 | private static final String RO_BUILD_ID = "ro_build_id"; |
| 207 | |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 208 | private static final String ENFORCED_FILE = "dpc-apn-enforced"; |
| 209 | private static final String ENFORCED_KEY = "enforced"; |
| 210 | |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 211 | private static final String PREF_FILE = "telephonyprovider"; |
| 212 | private static final String APN_CONF_CHECKSUM = "apn_conf_checksum"; |
| 213 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 214 | private static final String PARTNER_APNS_PATH = "etc/apns-conf.xml"; |
Legler Wu | b16a120 | 2014-12-29 13:20:29 +0800 | [diff] [blame] | 215 | private static final String OEM_APNS_PATH = "telephony/apns-conf.xml"; |
Niklas Lindgren | 648f12e | 2018-05-21 16:48:20 +0200 | [diff] [blame] | 216 | private static final String OTA_UPDATED_APNS_PATH = "misc/apns/apns-conf.xml"; |
Amit Mahajan | 899cc60 | 2015-05-14 17:22:09 -0700 | [diff] [blame] | 217 | private static final String OLD_APNS_PATH = "etc/old-apns-conf.xml"; |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 218 | |
yuemingw | e0101b8 | 2017-12-13 21:49:09 +0000 | [diff] [blame] | 219 | private static final String DEFAULT_PROTOCOL = "IP"; |
| 220 | private static final String DEFAULT_ROAMING_PROTOCOL = "IP"; |
| 221 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 222 | private static final UriMatcher s_urlMatcher = new UriMatcher(UriMatcher.NO_MATCH); |
| 223 | |
| 224 | private static final ContentValues s_currentNullMap; |
| 225 | private static final ContentValues s_currentSetMap; |
| 226 | |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 227 | private static final String IS_UNEDITED = EDITED_STATUS + "=" + UNEDITED; |
| 228 | private static final String IS_EDITED = EDITED_STATUS + "!=" + UNEDITED; |
| 229 | private static final String IS_USER_EDITED = EDITED_STATUS + "=" + USER_EDITED; |
| 230 | private static final String IS_NOT_USER_EDITED = EDITED_STATUS + "!=" + USER_EDITED; |
| 231 | private static final String IS_USER_DELETED = EDITED_STATUS + "=" + USER_DELETED; |
| 232 | private static final String IS_NOT_USER_DELETED = EDITED_STATUS + "!=" + USER_DELETED; |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 233 | private static final String IS_USER_DELETED_BUT_PRESENT_IN_XML = |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 234 | EDITED_STATUS + "=" + USER_DELETED_BUT_PRESENT_IN_XML; |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 235 | private static final String IS_NOT_USER_DELETED_BUT_PRESENT_IN_XML = |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 236 | EDITED_STATUS + "!=" + USER_DELETED_BUT_PRESENT_IN_XML; |
| 237 | private static final String IS_CARRIER_EDITED = EDITED_STATUS + "=" + CARRIER_EDITED; |
| 238 | private static final String IS_NOT_CARRIER_EDITED = EDITED_STATUS + "!=" + CARRIER_EDITED; |
| 239 | private static final String IS_CARRIER_DELETED = EDITED_STATUS + "=" + CARRIER_DELETED; |
| 240 | private static final String IS_NOT_CARRIER_DELETED = EDITED_STATUS + "!=" + CARRIER_DELETED; |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 241 | private static final String IS_CARRIER_DELETED_BUT_PRESENT_IN_XML = |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 242 | EDITED_STATUS + "=" + CARRIER_DELETED_BUT_PRESENT_IN_XML; |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 243 | private static final String IS_NOT_CARRIER_DELETED_BUT_PRESENT_IN_XML = |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 244 | EDITED_STATUS + "!=" + CARRIER_DELETED_BUT_PRESENT_IN_XML; |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 245 | private static final String IS_OWNED_BY_DPC = OWNED_BY + "=" + OWNED_BY_DPC; |
| 246 | private static final String IS_NOT_OWNED_BY_DPC = OWNED_BY + "!=" + OWNED_BY_DPC; |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 247 | |
Brad Ebinger | 1c69fea | 2018-03-27 11:33:16 -0700 | [diff] [blame] | 248 | private static final String ORDER_BY_SUB_ID = |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 249 | Telephony.SimInfo.COLUMN_UNIQUE_KEY_SUBSCRIPTION_ID + " ASC"; |
Brad Ebinger | 1c69fea | 2018-03-27 11:33:16 -0700 | [diff] [blame] | 250 | |
Amit Mahajan | 91c5dff | 2015-10-20 11:13:19 -0700 | [diff] [blame] | 251 | private static final int INVALID_APN_ID = -1; |
| 252 | private static final List<String> CARRIERS_UNIQUE_FIELDS = new ArrayList<String>(); |
Jordan Liu | 8b78f71 | 2018-05-21 11:10:48 -0700 | [diff] [blame] | 253 | private static final Set<String> CARRIERS_BOOLEAN_FIELDS = new HashSet<String>(); |
Jordan Liu | 5d66621 | 2017-11-13 15:07:52 -0800 | [diff] [blame] | 254 | private static final Map<String, String> CARRIERS_UNIQUE_FIELDS_DEFAULTS = new HashMap(); |
Amit Mahajan | 91c5dff | 2015-10-20 11:13:19 -0700 | [diff] [blame] | 255 | |
Chaitanya Saggurthi | 58ab3ad | 2017-12-05 22:09:09 +0900 | [diff] [blame] | 256 | @VisibleForTesting |
| 257 | static Boolean s_apnSourceServiceExists; |
Jordan Liu | 3de76f8 | 2017-05-15 15:21:01 -0700 | [diff] [blame] | 258 | |
| 259 | protected final Object mLock = new Object(); |
| 260 | @GuardedBy("mLock") |
| 261 | private IApnSourceService mIApnSourceService; |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 262 | private Injector mInjector; |
| 263 | |
| 264 | private boolean mManagedApnEnforced; |
Jordan Liu | 3de76f8 | 2017-05-15 15:21:01 -0700 | [diff] [blame] | 265 | |
SongFerngWang | 64fb3dd | 2019-12-02 20:59:47 +0800 | [diff] [blame] | 266 | /** |
| 267 | * Available radio technologies for GSM, UMTS and CDMA. |
| 268 | * Duplicates the constants from hardware/radio/include/ril.h |
| 269 | * This should only be used by agents working with the ril. Others |
| 270 | * should use the equivalent TelephonyManager.NETWORK_TYPE_* |
| 271 | */ |
| 272 | private static final int RIL_RADIO_TECHNOLOGY_UNKNOWN = 0; |
| 273 | private static final int RIL_RADIO_TECHNOLOGY_GPRS = 1; |
| 274 | private static final int RIL_RADIO_TECHNOLOGY_EDGE = 2; |
| 275 | private static final int RIL_RADIO_TECHNOLOGY_UMTS = 3; |
| 276 | private static final int RIL_RADIO_TECHNOLOGY_IS95A = 4; |
| 277 | private static final int RIL_RADIO_TECHNOLOGY_IS95B = 5; |
| 278 | private static final int RIL_RADIO_TECHNOLOGY_1xRTT = 6; |
| 279 | private static final int RIL_RADIO_TECHNOLOGY_EVDO_0 = 7; |
| 280 | private static final int RIL_RADIO_TECHNOLOGY_EVDO_A = 8; |
| 281 | private static final int RIL_RADIO_TECHNOLOGY_HSDPA = 9; |
| 282 | private static final int RIL_RADIO_TECHNOLOGY_HSUPA = 10; |
| 283 | private static final int RIL_RADIO_TECHNOLOGY_HSPA = 11; |
| 284 | private static final int RIL_RADIO_TECHNOLOGY_EVDO_B = 12; |
| 285 | private static final int RIL_RADIO_TECHNOLOGY_EHRPD = 13; |
| 286 | private static final int RIL_RADIO_TECHNOLOGY_LTE = 14; |
| 287 | private static final int RIL_RADIO_TECHNOLOGY_HSPAP = 15; |
| 288 | |
| 289 | /** |
| 290 | * GSM radio technology only supports voice. It does not support data. |
| 291 | */ |
| 292 | private static final int RIL_RADIO_TECHNOLOGY_GSM = 16; |
| 293 | private static final int RIL_RADIO_TECHNOLOGY_TD_SCDMA = 17; |
| 294 | |
| 295 | /** |
| 296 | * IWLAN |
| 297 | */ |
| 298 | private static final int RIL_RADIO_TECHNOLOGY_IWLAN = 18; |
| 299 | |
| 300 | /** |
| 301 | * LTE_CA |
| 302 | */ |
| 303 | private static final int RIL_RADIO_TECHNOLOGY_LTE_CA = 19; |
| 304 | |
| 305 | /** |
| 306 | * NR(New Radio) 5G. |
| 307 | */ |
| 308 | private static final int RIL_RADIO_TECHNOLOGY_NR = 20; |
| 309 | |
| 310 | /** |
| 311 | * The number of the radio technologies. |
| 312 | */ |
| 313 | private static final int NEXT_RIL_RADIO_TECHNOLOGY = 21; |
| 314 | |
zoey chen | 715880a | 2019-11-12 18:47:02 +0800 | [diff] [blame] | 315 | private static final Map<String, Integer> MVNO_TYPE_STRING_MAP; |
| 316 | |
Amit Mahajan | 91c5dff | 2015-10-20 11:13:19 -0700 | [diff] [blame] | 317 | static { |
| 318 | // Columns not included in UNIQUE constraint: name, current, edited, user, server, password, |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 319 | // authtype, type, protocol, roaming_protocol, sub_id, modem_cognitive, max_conns, |
Yuuki Habu | 95aacb1 | 2019-02-22 10:49:06 +0900 | [diff] [blame] | 320 | // wait_time, max_conns_time, mtu, bearer_bitmask, user_visible, network_type_bitmask, |
| 321 | // skip_464xlat |
Jordan Liu | 5d66621 | 2017-11-13 15:07:52 -0800 | [diff] [blame] | 322 | CARRIERS_UNIQUE_FIELDS_DEFAULTS.put(NUMERIC, ""); |
| 323 | CARRIERS_UNIQUE_FIELDS_DEFAULTS.put(MCC, ""); |
| 324 | CARRIERS_UNIQUE_FIELDS_DEFAULTS.put(MNC, ""); |
| 325 | CARRIERS_UNIQUE_FIELDS_DEFAULTS.put(APN, ""); |
| 326 | CARRIERS_UNIQUE_FIELDS_DEFAULTS.put(PROXY, ""); |
| 327 | CARRIERS_UNIQUE_FIELDS_DEFAULTS.put(PORT, ""); |
| 328 | CARRIERS_UNIQUE_FIELDS_DEFAULTS.put(MMSPROXY, ""); |
| 329 | CARRIERS_UNIQUE_FIELDS_DEFAULTS.put(MMSPORT, ""); |
| 330 | CARRIERS_UNIQUE_FIELDS_DEFAULTS.put(MMSC, ""); |
| 331 | CARRIERS_UNIQUE_FIELDS_DEFAULTS.put(CARRIER_ENABLED, "1"); |
| 332 | CARRIERS_UNIQUE_FIELDS_DEFAULTS.put(BEARER, "0"); |
| 333 | CARRIERS_UNIQUE_FIELDS_DEFAULTS.put(MVNO_TYPE, ""); |
| 334 | CARRIERS_UNIQUE_FIELDS_DEFAULTS.put(MVNO_MATCH_DATA, ""); |
| 335 | CARRIERS_UNIQUE_FIELDS_DEFAULTS.put(PROFILE_ID, "0"); |
| 336 | CARRIERS_UNIQUE_FIELDS_DEFAULTS.put(PROTOCOL, "IP"); |
| 337 | CARRIERS_UNIQUE_FIELDS_DEFAULTS.put(ROAMING_PROTOCOL, "IP"); |
| 338 | CARRIERS_UNIQUE_FIELDS_DEFAULTS.put(USER_EDITABLE, "1"); |
| 339 | CARRIERS_UNIQUE_FIELDS_DEFAULTS.put(OWNED_BY, String.valueOf(OWNED_BY_OTHERS)); |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 340 | CARRIERS_UNIQUE_FIELDS_DEFAULTS.put(APN_SET_ID, String.valueOf(NO_APN_SET_ID)); |
calvinpan | 2b41944 | 2018-10-23 15:05:11 +0800 | [diff] [blame] | 341 | CARRIERS_UNIQUE_FIELDS_DEFAULTS.put(CARRIER_ID, |
| 342 | String.valueOf(TelephonyManager.UNKNOWN_CARRIER_ID)); |
Jordan Liu | 5d66621 | 2017-11-13 15:07:52 -0800 | [diff] [blame] | 343 | |
| 344 | CARRIERS_UNIQUE_FIELDS.addAll(CARRIERS_UNIQUE_FIELDS_DEFAULTS.keySet()); |
Jordan Liu | 8b78f71 | 2018-05-21 11:10:48 -0700 | [diff] [blame] | 345 | |
| 346 | // SQLite databases store bools as ints but the ContentValues objects passed in through |
| 347 | // queries use bools. As a result there is some special handling of boolean fields within |
| 348 | // the TelephonyProvider. |
| 349 | CARRIERS_BOOLEAN_FIELDS.add(CARRIER_ENABLED); |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 350 | CARRIERS_BOOLEAN_FIELDS.add(MODEM_PERSIST); |
Jordan Liu | 8b78f71 | 2018-05-21 11:10:48 -0700 | [diff] [blame] | 351 | CARRIERS_BOOLEAN_FIELDS.add(USER_VISIBLE); |
| 352 | CARRIERS_BOOLEAN_FIELDS.add(USER_EDITABLE); |
zoey chen | 715880a | 2019-11-12 18:47:02 +0800 | [diff] [blame] | 353 | |
| 354 | MVNO_TYPE_STRING_MAP = new ArrayMap<String, Integer>(); |
| 355 | MVNO_TYPE_STRING_MAP.put("spn", ApnSetting.MVNO_TYPE_SPN); |
| 356 | MVNO_TYPE_STRING_MAP.put("imsi", ApnSetting.MVNO_TYPE_IMSI); |
| 357 | MVNO_TYPE_STRING_MAP.put("gid", ApnSetting.MVNO_TYPE_GID); |
| 358 | MVNO_TYPE_STRING_MAP.put("iccid", ApnSetting.MVNO_TYPE_ICCID); |
Amit Mahajan | 91c5dff | 2015-10-20 11:13:19 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Jordan Liu | e6f0bce | 2016-09-21 18:31:43 -0700 | [diff] [blame] | 361 | @VisibleForTesting |
pkanwar | e08f3ac | 2017-02-02 18:26:32 -0800 | [diff] [blame] | 362 | public static String getStringForCarrierTableCreation(String tableName) { |
| 363 | return "CREATE TABLE " + tableName + |
| 364 | "(_id INTEGER PRIMARY KEY," + |
| 365 | NAME + " TEXT DEFAULT ''," + |
| 366 | NUMERIC + " TEXT DEFAULT ''," + |
| 367 | MCC + " TEXT DEFAULT ''," + |
| 368 | MNC + " TEXT DEFAULT ''," + |
calvinpan | 2b41944 | 2018-10-23 15:05:11 +0800 | [diff] [blame] | 369 | CARRIER_ID + " INTEGER DEFAULT " + TelephonyManager.UNKNOWN_CARRIER_ID + "," + |
pkanwar | e08f3ac | 2017-02-02 18:26:32 -0800 | [diff] [blame] | 370 | APN + " TEXT DEFAULT ''," + |
| 371 | USER + " TEXT DEFAULT ''," + |
| 372 | SERVER + " TEXT DEFAULT ''," + |
| 373 | PASSWORD + " TEXT DEFAULT ''," + |
| 374 | PROXY + " TEXT DEFAULT ''," + |
| 375 | PORT + " TEXT DEFAULT ''," + |
| 376 | MMSPROXY + " TEXT DEFAULT ''," + |
| 377 | MMSPORT + " TEXT DEFAULT ''," + |
| 378 | MMSC + " TEXT DEFAULT ''," + |
| 379 | AUTH_TYPE + " INTEGER DEFAULT -1," + |
| 380 | TYPE + " TEXT DEFAULT ''," + |
| 381 | CURRENT + " INTEGER," + |
yuemingw | e0101b8 | 2017-12-13 21:49:09 +0000 | [diff] [blame] | 382 | PROTOCOL + " TEXT DEFAULT " + DEFAULT_PROTOCOL + "," + |
| 383 | ROAMING_PROTOCOL + " TEXT DEFAULT " + DEFAULT_ROAMING_PROTOCOL + "," + |
Jordan Liu | 8b78f71 | 2018-05-21 11:10:48 -0700 | [diff] [blame] | 384 | CARRIER_ENABLED + " BOOLEAN DEFAULT 1," + // SQLite databases store bools as ints |
pkanwar | e08f3ac | 2017-02-02 18:26:32 -0800 | [diff] [blame] | 385 | BEARER + " INTEGER DEFAULT 0," + |
| 386 | BEARER_BITMASK + " INTEGER DEFAULT 0," + |
Cassie | a58ce71 | 2017-12-06 16:21:50 -0800 | [diff] [blame] | 387 | NETWORK_TYPE_BITMASK + " INTEGER DEFAULT 0," + |
pkanwar | e08f3ac | 2017-02-02 18:26:32 -0800 | [diff] [blame] | 388 | MVNO_TYPE + " TEXT DEFAULT ''," + |
| 389 | MVNO_MATCH_DATA + " TEXT DEFAULT ''," + |
calvinpan | 2b41944 | 2018-10-23 15:05:11 +0800 | [diff] [blame] | 390 | SUBSCRIPTION_ID + " INTEGER DEFAULT " + |
| 391 | SubscriptionManager.INVALID_SUBSCRIPTION_ID + "," + |
pkanwar | e08f3ac | 2017-02-02 18:26:32 -0800 | [diff] [blame] | 392 | PROFILE_ID + " INTEGER DEFAULT 0," + |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 393 | MODEM_PERSIST + " BOOLEAN DEFAULT 0," + |
| 394 | MAX_CONNECTIONS + " INTEGER DEFAULT 0," + |
| 395 | WAIT_TIME_RETRY + " INTEGER DEFAULT 0," + |
| 396 | TIME_LIMIT_FOR_MAX_CONNECTIONS + " INTEGER DEFAULT 0," + |
pkanwar | e08f3ac | 2017-02-02 18:26:32 -0800 | [diff] [blame] | 397 | MTU + " INTEGER DEFAULT 0," + |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 398 | EDITED_STATUS + " INTEGER DEFAULT " + UNEDITED + "," + |
pkanwar | e08f3ac | 2017-02-02 18:26:32 -0800 | [diff] [blame] | 399 | USER_VISIBLE + " BOOLEAN DEFAULT 1," + |
Amit Mahajan | 460d703 | 2017-07-17 14:42:33 -0700 | [diff] [blame] | 400 | USER_EDITABLE + " BOOLEAN DEFAULT 1," + |
yuemingw | c4d40a7 | 2017-11-08 14:14:37 +0000 | [diff] [blame] | 401 | OWNED_BY + " INTEGER DEFAULT " + OWNED_BY_OTHERS + "," + |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 402 | APN_SET_ID + " INTEGER DEFAULT " + NO_APN_SET_ID + "," + |
Yuuki Habu | 95aacb1 | 2019-02-22 10:49:06 +0900 | [diff] [blame] | 403 | SKIP_464XLAT + " INTEGER DEFAULT " + SKIP_464XLAT_DEFAULT + "," + |
pkanwar | e08f3ac | 2017-02-02 18:26:32 -0800 | [diff] [blame] | 404 | // Uniqueness collisions are used to trigger merge code so if a field is listed |
| 405 | // here it means we will accept both (user edited + new apn_conf definition) |
| 406 | // Columns not included in UNIQUE constraint: name, current, edited, |
| 407 | // user, server, password, authtype, type, sub_id, modem_cognitive, max_conns, |
Cassie | a58ce71 | 2017-12-06 16:21:50 -0800 | [diff] [blame] | 408 | // wait_time, max_conns_time, mtu, bearer_bitmask, user_visible, |
Yuuki Habu | 95aacb1 | 2019-02-22 10:49:06 +0900 | [diff] [blame] | 409 | // network_type_bitmask, skip_464xlat. |
pkanwar | e08f3ac | 2017-02-02 18:26:32 -0800 | [diff] [blame] | 410 | "UNIQUE (" + TextUtils.join(", ", CARRIERS_UNIQUE_FIELDS) + "));"; |
| 411 | } |
Jordan Liu | e6f0bce | 2016-09-21 18:31:43 -0700 | [diff] [blame] | 412 | |
| 413 | @VisibleForTesting |
yinxu | 3d98b6c | 2018-01-05 16:27:30 -0800 | [diff] [blame] | 414 | public static String getStringForSimInfoTableCreation(String tableName) { |
| 415 | return "CREATE TABLE " + tableName + "(" |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 416 | + Telephony.SimInfo.COLUMN_UNIQUE_KEY_SUBSCRIPTION_ID |
Jordan Liu | e6f0bce | 2016-09-21 18:31:43 -0700 | [diff] [blame] | 417 | + " INTEGER PRIMARY KEY AUTOINCREMENT," |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 418 | + Telephony.SimInfo.COLUMN_ICC_ID + " TEXT NOT NULL," |
| 419 | + Telephony.SimInfo.COLUMN_SIM_SLOT_INDEX |
Peter Wang | b097cb6 | 2019-12-05 11:01:18 -0800 | [diff] [blame] | 420 | + " INTEGER DEFAULT " + Telephony.SimInfo.SIM_NOT_INSERTED + "," |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 421 | + Telephony.SimInfo.COLUMN_DISPLAY_NAME + " TEXT," |
| 422 | + Telephony.SimInfo.COLUMN_CARRIER_NAME + " TEXT," |
| 423 | + Telephony.SimInfo.COLUMN_NAME_SOURCE |
| 424 | + " INTEGER DEFAULT " + Telephony.SimInfo.NAME_SOURCE_CARRIER_ID + "," |
| 425 | + Telephony.SimInfo.COLUMN_COLOR + " INTEGER DEFAULT " |
Peter Wang | b097cb6 | 2019-12-05 11:01:18 -0800 | [diff] [blame] | 426 | + Telephony.SimInfo.COLOR_DEFAULT + "," |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 427 | + Telephony.SimInfo.COLUMN_NUMBER + " TEXT," |
| 428 | + Telephony.SimInfo.COLUMN_DISPLAY_NUMBER_FORMAT |
Peter Wang | b097cb6 | 2019-12-05 11:01:18 -0800 | [diff] [blame] | 429 | + " INTEGER NOT NULL DEFAULT " + Telephony.SimInfo.DISPLAY_NUMBER_DEFAULT + "," |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 430 | + Telephony.SimInfo.COLUMN_DATA_ROAMING |
| 431 | + " INTEGER DEFAULT " + Telephony.SimInfo.DATA_ROAMING_DISABLE + "," |
| 432 | + Telephony.SimInfo.COLUMN_MCC + " INTEGER DEFAULT 0," |
| 433 | + Telephony.SimInfo.COLUMN_MNC + " INTEGER DEFAULT 0," |
| 434 | + Telephony.SimInfo.COLUMN_MCC_STRING + " TEXT," |
| 435 | + Telephony.SimInfo.COLUMN_MNC_STRING + " TEXT," |
| 436 | + Telephony.SimInfo.COLUMN_EHPLMNS + " TEXT," |
| 437 | + Telephony.SimInfo.COLUMN_HPLMNS + " TEXT," |
| 438 | + Telephony.SimInfo.COLUMN_SIM_PROVISIONING_STATUS |
Peter Wang | b097cb6 | 2019-12-05 11:01:18 -0800 | [diff] [blame] | 439 | + " INTEGER DEFAULT " + Telephony.SimInfo.SIM_PROVISIONED + "," |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 440 | + Telephony.SimInfo.COLUMN_IS_EMBEDDED + " INTEGER DEFAULT 0," |
| 441 | + Telephony.SimInfo.COLUMN_CARD_ID + " TEXT NOT NULL," |
| 442 | + Telephony.SimInfo.COLUMN_ACCESS_RULES + " BLOB," |
| 443 | + Telephony.SimInfo.COLUMN_ACCESS_RULES_FROM_CARRIER_CONFIGS + " BLOB," |
| 444 | + Telephony.SimInfo.COLUMN_IS_REMOVABLE + " INTEGER DEFAULT 0," |
| 445 | + Telephony.SimInfo.COLUMN_CB_EXTREME_THREAT_ALERT + " INTEGER DEFAULT 1," |
| 446 | + Telephony.SimInfo.COLUMN_CB_SEVERE_THREAT_ALERT + " INTEGER DEFAULT 1," |
| 447 | + Telephony.SimInfo.COLUMN_CB_AMBER_ALERT + " INTEGER DEFAULT 1," |
| 448 | + Telephony.SimInfo.COLUMN_CB_EMERGENCY_ALERT + " INTEGER DEFAULT 1," |
| 449 | + Telephony.SimInfo.COLUMN_CB_ALERT_SOUND_DURATION + " INTEGER DEFAULT 4," |
| 450 | + Telephony.SimInfo.COLUMN_CB_ALERT_REMINDER_INTERVAL + " INTEGER DEFAULT 0," |
| 451 | + Telephony.SimInfo.COLUMN_CB_ALERT_VIBRATE + " INTEGER DEFAULT 1," |
| 452 | + Telephony.SimInfo.COLUMN_CB_ALERT_SPEECH + " INTEGER DEFAULT 1," |
| 453 | + Telephony.SimInfo.COLUMN_CB_ETWS_TEST_ALERT + " INTEGER DEFAULT 0," |
| 454 | + Telephony.SimInfo.COLUMN_CB_CHANNEL_50_ALERT + " INTEGER DEFAULT 1," |
| 455 | + Telephony.SimInfo.COLUMN_CB_CMAS_TEST_ALERT + " INTEGER DEFAULT 0," |
| 456 | + Telephony.SimInfo.COLUMN_CB_OPT_OUT_DIALOG + " INTEGER DEFAULT 1," |
| 457 | + Telephony.SimInfo.COLUMN_ENHANCED_4G_MODE_ENABLED + " INTEGER DEFAULT -1," |
| 458 | + Telephony.SimInfo.COLUMN_VT_IMS_ENABLED + " INTEGER DEFAULT -1," |
| 459 | + Telephony.SimInfo.COLUMN_WFC_IMS_ENABLED + " INTEGER DEFAULT -1," |
| 460 | + Telephony.SimInfo.COLUMN_WFC_IMS_MODE + " INTEGER DEFAULT -1," |
| 461 | + Telephony.SimInfo.COLUMN_WFC_IMS_ROAMING_MODE + " INTEGER DEFAULT -1," |
| 462 | + Telephony.SimInfo.COLUMN_WFC_IMS_ROAMING_ENABLED + " INTEGER DEFAULT -1," |
| 463 | + Telephony.SimInfo.COLUMN_IS_OPPORTUNISTIC + " INTEGER DEFAULT 0," |
| 464 | + Telephony.SimInfo.COLUMN_GROUP_UUID + " TEXT," |
| 465 | + Telephony.SimInfo.COLUMN_IS_METERED + " INTEGER DEFAULT 1," |
| 466 | + Telephony.SimInfo.COLUMN_ISO_COUNTRY_CODE + " TEXT," |
| 467 | + Telephony.SimInfo.COLUMN_CARRIER_ID + " INTEGER DEFAULT -1," |
| 468 | + Telephony.SimInfo.COLUMN_PROFILE_CLASS + " INTEGER DEFAULT " |
| 469 | + Telephony.SimInfo.PROFILE_CLASS_UNSET + "," |
| 470 | + Telephony.SimInfo.COLUMN_SUBSCRIPTION_TYPE + " INTEGER DEFAULT " |
Peter Wang | b097cb6 | 2019-12-05 11:01:18 -0800 | [diff] [blame] | 471 | + Telephony.SimInfo.SUBSCRIPTION_TYPE_LOCAL_SIM + "," |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 472 | + Telephony.SimInfo.COLUMN_GROUP_OWNER + " TEXT," |
| 473 | + Telephony.SimInfo.COLUMN_DATA_ENABLED_OVERRIDE_RULES + " TEXT," |
| 474 | + Telephony.SimInfo.COLUMN_IMSI + " TEXT," |
| 475 | + Telephony.SimInfo.COLUMN_UICC_APPLICATIONS_ENABLED + " INTEGER DEFAULT 1," |
| 476 | + Telephony.SimInfo.COLUMN_ALLOWED_NETWORK_TYPES + " BIGINT DEFAULT -1," |
| 477 | + Telephony.SimInfo.COLUMN_IMS_RCS_UCE_ENABLED + " INTEGER DEFAULT 0" |
yinxu | 3d98b6c | 2018-01-05 16:27:30 -0800 | [diff] [blame] | 478 | + ");"; |
| 479 | } |
Jordan Liu | e6f0bce | 2016-09-21 18:31:43 -0700 | [diff] [blame] | 480 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 481 | static { |
| 482 | s_urlMatcher.addURI("telephony", "carriers", URL_TELEPHONY); |
| 483 | s_urlMatcher.addURI("telephony", "carriers/current", URL_CURRENT); |
| 484 | s_urlMatcher.addURI("telephony", "carriers/#", URL_ID); |
| 485 | s_urlMatcher.addURI("telephony", "carriers/restore", URL_RESTOREAPN); |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 486 | s_urlMatcher.addURI("telephony", "carriers/preferapn", URL_PREFERAPN); |
Kazuhiro Ondo | d616ee6 | 2012-01-10 17:12:59 -0600 | [diff] [blame] | 487 | s_urlMatcher.addURI("telephony", "carriers/preferapn_no_update", URL_PREFERAPN_NO_UPDATE); |
Jordan Liu | c6078b7 | 2018-05-01 11:34:21 -0700 | [diff] [blame] | 488 | s_urlMatcher.addURI("telephony", "carriers/preferapnset", URL_PREFERAPNSET); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 489 | |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 490 | s_urlMatcher.addURI("telephony", "siminfo", URL_SIMINFO); |
chen xu | 195e2ec | 2018-10-02 18:42:41 -0700 | [diff] [blame] | 491 | s_urlMatcher.addURI("telephony", "siminfo/#", URL_SIMINFO_USING_SUBID); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 492 | |
| 493 | s_urlMatcher.addURI("telephony", "carriers/subId/*", URL_TELEPHONY_USING_SUBID); |
| 494 | s_urlMatcher.addURI("telephony", "carriers/current/subId/*", URL_CURRENT_USING_SUBID); |
| 495 | s_urlMatcher.addURI("telephony", "carriers/restore/subId/*", URL_RESTOREAPN_USING_SUBID); |
| 496 | s_urlMatcher.addURI("telephony", "carriers/preferapn/subId/*", URL_PREFERAPN_USING_SUBID); |
| 497 | s_urlMatcher.addURI("telephony", "carriers/preferapn_no_update/subId/*", |
| 498 | URL_PREFERAPN_NO_UPDATE_USING_SUBID); |
Jordan Liu | c6078b7 | 2018-05-01 11:34:21 -0700 | [diff] [blame] | 499 | s_urlMatcher.addURI("telephony", "carriers/preferapnset/subId/*", |
| 500 | URL_PREFERAPNSET_USING_SUBID); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 501 | |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 502 | s_urlMatcher.addURI("telephony", "carriers/update_db", URL_UPDATE_DB); |
Amit Mahajan | 7005be8 | 2017-04-26 10:35:18 -0700 | [diff] [blame] | 503 | s_urlMatcher.addURI("telephony", "carriers/delete", URL_DELETE); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 504 | |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 505 | // Only called by DevicePolicyManager to manipulate DPC records. |
| 506 | s_urlMatcher.addURI("telephony", "carriers/dpc", URL_DPC); |
| 507 | // Only called by DevicePolicyManager to manipulate a DPC record with certain _ID. |
| 508 | s_urlMatcher.addURI("telephony", "carriers/dpc/#", URL_DPC_ID); |
| 509 | // Only called by Settings app, DcTracker and other telephony components to get APN list |
| 510 | // according to whether DPC records are enforced. |
| 511 | s_urlMatcher.addURI("telephony", "carriers/filtered", URL_FILTERED); |
yuemingw | cd80d17 | 2018-01-15 14:08:55 +0000 | [diff] [blame] | 512 | // Only called by Settings app, DcTracker and other telephony components to get a |
| 513 | // single APN according to whether DPC records are enforced. |
| 514 | s_urlMatcher.addURI("telephony", "carriers/filtered/#", URL_FILTERED_ID); |
Malcolm Chen | 09ebf8d | 2018-12-07 13:45:54 -0800 | [diff] [blame] | 515 | // Used by DcTracker to pass a subId. |
| 516 | s_urlMatcher.addURI("telephony", "carriers/filtered/subId/*", URL_FILTERED_USING_SUBID); |
| 517 | |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 518 | // Only Called by DevicePolicyManager to enforce DPC records. |
| 519 | s_urlMatcher.addURI("telephony", "carriers/enforce_managed", URL_ENFORCE_MANAGED); |
calvinpan | ba94b59 | 2018-11-01 09:09:30 +0800 | [diff] [blame] | 520 | s_urlMatcher.addURI("telephony", "carriers/sim_apn_list", URL_SIM_APN_LIST); |
| 521 | s_urlMatcher.addURI("telephony", "carriers/sim_apn_list/#", URL_SIM_APN_LIST_ID); |
Josh Hou | 42049bb | 2018-12-10 22:22:05 +0800 | [diff] [blame] | 522 | s_urlMatcher.addURI("telephony", "carriers/sim_apn_list/filtered", |
| 523 | URL_SIM_APN_LIST_FILTERED); |
| 524 | s_urlMatcher.addURI("telephony", "carriers/sim_apn_list/filtered/subId/*", |
| 525 | URL_SIM_APN_LIST_FILTERED_ID); |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 526 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 527 | s_currentNullMap = new ContentValues(1); |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 528 | s_currentNullMap.put(CURRENT, "0"); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 529 | |
| 530 | s_currentSetMap = new ContentValues(1); |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 531 | s_currentSetMap.put(CURRENT, "1"); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 532 | } |
| 533 | |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 534 | /** |
| 535 | * Unit test will subclass it to inject mocks. |
| 536 | */ |
| 537 | @VisibleForTesting |
| 538 | static class Injector { |
| 539 | int binderGetCallingUid() { |
| 540 | return Binder.getCallingUid(); |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | public TelephonyProvider() { |
| 545 | this(new Injector()); |
| 546 | } |
| 547 | |
| 548 | @VisibleForTesting |
| 549 | public TelephonyProvider(Injector injector) { |
| 550 | mInjector = injector; |
| 551 | } |
| 552 | |
Jordan Liu | c591b11 | 2018-05-02 16:35:03 -0700 | [diff] [blame] | 553 | @VisibleForTesting |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 554 | public static int getVersion(Context context) { |
| 555 | if (VDBG) log("getVersion:+"); |
| 556 | // Get the database version, combining a static schema version and the XML version |
| 557 | Resources r = context.getResources(); |
| 558 | if (r == null) { |
| 559 | loge("resources=null, return version=" + Integer.toHexString(DATABASE_VERSION)); |
| 560 | return DATABASE_VERSION; |
| 561 | } |
| 562 | XmlResourceParser parser = r.getXml(com.android.internal.R.xml.apns); |
| 563 | try { |
| 564 | XmlUtils.beginDocument(parser, "apns"); |
| 565 | int publicversion = Integer.parseInt(parser.getAttributeValue(null, "version")); |
| 566 | int version = DATABASE_VERSION | publicversion; |
| 567 | if (VDBG) log("getVersion:- version=0x" + Integer.toHexString(version)); |
| 568 | return version; |
| 569 | } catch (Exception e) { |
| 570 | loge("Can't get version of APN database" + e + " return version=" + |
| 571 | Integer.toHexString(DATABASE_VERSION)); |
| 572 | return DATABASE_VERSION; |
| 573 | } finally { |
| 574 | parser.close(); |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | static public ContentValues setDefaultValue(ContentValues values) { |
| 579 | if (!values.containsKey(SUBSCRIPTION_ID)) { |
| 580 | int subId = SubscriptionManager.getDefaultSubscriptionId(); |
| 581 | values.put(SUBSCRIPTION_ID, subId); |
| 582 | } |
| 583 | |
| 584 | return values; |
| 585 | } |
| 586 | |
| 587 | @VisibleForTesting |
| 588 | public class DatabaseHelper extends SQLiteOpenHelper { |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 589 | // Context to access resources with |
| 590 | private Context mContext; |
| 591 | |
| 592 | /** |
| 593 | * DatabaseHelper helper class for loading apns into a database. |
| 594 | * |
Wink Saville | d7c9350 | 2011-06-04 07:17:01 -0700 | [diff] [blame] | 595 | * @param context of the user. |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 596 | */ |
| 597 | public DatabaseHelper(Context context) { |
| 598 | super(context, DATABASE_NAME, null, getVersion(context)); |
| 599 | mContext = context; |
Fyodor Kupolov | 66304f6 | 2017-09-01 16:13:49 -0700 | [diff] [blame] | 600 | // Memory optimization - close idle connections after 30s of inactivity |
| 601 | setIdleConnectionTimeout(IDLE_CONNECTION_TIMEOUT_MS); |
Makoto Onuki | e6842ee | 2018-09-07 11:32:47 -0700 | [diff] [blame] | 602 | setWriteAheadLoggingEnabled(false); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 603 | } |
| 604 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 605 | @Override |
| 606 | public void onCreate(SQLiteDatabase db) { |
Wink Saville | 6de1027 | 2014-06-22 07:38:43 -0700 | [diff] [blame] | 607 | if (DBG) log("dbh.onCreate:+ db=" + db); |
yinxu | 3d98b6c | 2018-01-05 16:27:30 -0800 | [diff] [blame] | 608 | createSimInfoTable(db, SIMINFO_TABLE); |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 609 | createCarriersTable(db, CARRIERS_TABLE); |
Jordan Liu | 3de76f8 | 2017-05-15 15:21:01 -0700 | [diff] [blame] | 610 | // if CarrierSettings app is installed, we expect it to do the initializiation instead |
| 611 | if (apnSourceServiceExists(mContext)) { |
| 612 | log("dbh.onCreate: Skipping apply APNs from xml."); |
| 613 | } else { |
| 614 | log("dbh.onCreate: Apply apns from xml."); |
| 615 | initDatabase(db); |
| 616 | } |
Wink Saville | 6de1027 | 2014-06-22 07:38:43 -0700 | [diff] [blame] | 617 | if (DBG) log("dbh.onCreate:- db=" + db); |
| 618 | } |
| 619 | |
| 620 | @Override |
| 621 | public void onOpen(SQLiteDatabase db) { |
| 622 | if (VDBG) log("dbh.onOpen:+ db=" + db); |
| 623 | try { |
| 624 | // Try to access the table and create it if "no such table" |
| 625 | db.query(SIMINFO_TABLE, null, null, null, null, null, null); |
| 626 | if (DBG) log("dbh.onOpen: ok, queried table=" + SIMINFO_TABLE); |
| 627 | } catch (SQLiteException e) { |
| 628 | loge("Exception " + SIMINFO_TABLE + "e=" + e); |
| 629 | if (e.getMessage().startsWith("no such table")) { |
yinxu | 3d98b6c | 2018-01-05 16:27:30 -0800 | [diff] [blame] | 630 | createSimInfoTable(db, SIMINFO_TABLE); |
Wink Saville | 6de1027 | 2014-06-22 07:38:43 -0700 | [diff] [blame] | 631 | } |
| 632 | } |
| 633 | try { |
| 634 | db.query(CARRIERS_TABLE, null, null, null, null, null, null); |
| 635 | if (DBG) log("dbh.onOpen: ok, queried table=" + CARRIERS_TABLE); |
| 636 | } catch (SQLiteException e) { |
| 637 | loge("Exception " + CARRIERS_TABLE + " e=" + e); |
| 638 | if (e.getMessage().startsWith("no such table")) { |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 639 | createCarriersTable(db, CARRIERS_TABLE); |
Wink Saville | 6de1027 | 2014-06-22 07:38:43 -0700 | [diff] [blame] | 640 | } |
| 641 | } |
| 642 | if (VDBG) log("dbh.onOpen:- db=" + db); |
| 643 | } |
| 644 | |
yinxu | 3d98b6c | 2018-01-05 16:27:30 -0800 | [diff] [blame] | 645 | private void createSimInfoTable(SQLiteDatabase db, String tableName) { |
| 646 | if (DBG) log("dbh.createSimInfoTable:+ " + tableName); |
| 647 | db.execSQL(getStringForSimInfoTableCreation(tableName)); |
Wink Saville | 6de1027 | 2014-06-22 07:38:43 -0700 | [diff] [blame] | 648 | if (DBG) log("dbh.createSimInfoTable:-"); |
| 649 | } |
| 650 | |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 651 | private void createCarriersTable(SQLiteDatabase db, String tableName) { |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 652 | // Set up the database schema |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 653 | if (DBG) log("dbh.createCarriersTable: " + tableName); |
pkanwar | e08f3ac | 2017-02-02 18:26:32 -0800 | [diff] [blame] | 654 | db.execSQL(getStringForCarrierTableCreation(tableName)); |
Wink Saville | 6de1027 | 2014-06-22 07:38:43 -0700 | [diff] [blame] | 655 | if (DBG) log("dbh.createCarriersTable:-"); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 656 | } |
Shri Borde | 7ed9c33 | 2014-09-15 13:46:01 -0700 | [diff] [blame] | 657 | |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 658 | private long getChecksum(File file) { |
Jayachandran C | 0c685ce | 2019-10-17 11:11:56 -0700 | [diff] [blame] | 659 | CRC32 checkSummer = new CRC32(); |
| 660 | long checkSum = -1; |
| 661 | try (CheckedInputStream cis = |
| 662 | new CheckedInputStream(new FileInputStream(file), checkSummer)){ |
| 663 | byte[] buf = new byte[128]; |
| 664 | if(cis != null) { |
| 665 | while(cis.read(buf) >= 0) { |
| 666 | // Just read for checksum to get calculated. |
| 667 | } |
| 668 | } |
| 669 | checkSum = checkSummer.getValue(); |
| 670 | if (DBG) log("Checksum for " + file.getAbsolutePath() + " is " + checkSum); |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 671 | } catch (FileNotFoundException e) { |
| 672 | loge("FileNotFoundException for " + file.getAbsolutePath() + ":" + e); |
| 673 | } catch (IOException e) { |
| 674 | loge("IOException for " + file.getAbsolutePath() + ":" + e); |
| 675 | } |
Niklas Lindgren | 9392c70 | 2018-05-03 15:58:06 +0200 | [diff] [blame] | 676 | |
| 677 | // The RRO may have been updated in a firmware upgrade. Add checksum for the |
| 678 | // resources to the total checksum so that apns in an RRO update is not missed. |
| 679 | try (InputStream inputStream = mContext.getResources(). |
| 680 | openRawResource(com.android.internal.R.xml.apns)) { |
| 681 | byte[] array = toByteArray(inputStream); |
Jayachandran C | 0c685ce | 2019-10-17 11:11:56 -0700 | [diff] [blame] | 682 | checkSummer.reset(); |
| 683 | checkSummer.update(array); |
| 684 | checkSum += checkSummer.getValue(); |
| 685 | if (DBG) log("Checksum after adding resource is " + checkSummer.getValue()); |
Niklas Lindgren | 9392c70 | 2018-05-03 15:58:06 +0200 | [diff] [blame] | 686 | } catch (IOException | Resources.NotFoundException e) { |
| 687 | loge("Exception when calculating checksum for internal apn resources: " + e); |
| 688 | } |
Jayachandran C | 0c685ce | 2019-10-17 11:11:56 -0700 | [diff] [blame] | 689 | return checkSum; |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 690 | } |
| 691 | |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 692 | private byte[] toByteArray(InputStream input) throws IOException { |
Niklas Lindgren | 9392c70 | 2018-05-03 15:58:06 +0200 | [diff] [blame] | 693 | byte[] buffer = new byte[128]; |
| 694 | int bytesRead; |
| 695 | ByteArrayOutputStream output = new ByteArrayOutputStream(); |
| 696 | while ((bytesRead = input.read(buffer)) != -1) { |
| 697 | output.write(buffer, 0, bytesRead); |
| 698 | } |
| 699 | return output.toByteArray(); |
| 700 | } |
| 701 | |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 702 | private long getApnConfChecksum() { |
| 703 | SharedPreferences sp = mContext.getSharedPreferences(PREF_FILE, Context.MODE_PRIVATE); |
| 704 | return sp.getLong(APN_CONF_CHECKSUM, -1); |
| 705 | } |
| 706 | |
| 707 | private void setApnConfChecksum(long checksum) { |
| 708 | SharedPreferences sp = mContext.getSharedPreferences(PREF_FILE, Context.MODE_PRIVATE); |
| 709 | SharedPreferences.Editor editor = sp.edit(); |
| 710 | editor.putLong(APN_CONF_CHECKSUM, checksum); |
| 711 | editor.apply(); |
| 712 | } |
| 713 | |
| 714 | private File getApnConfFile() { |
| 715 | // Environment.getRootDirectory() is a fancy way of saying ANDROID_ROOT or "/system". |
| 716 | File confFile = new File(Environment.getRootDirectory(), PARTNER_APNS_PATH); |
| 717 | File oemConfFile = new File(Environment.getOemDirectory(), OEM_APNS_PATH); |
| 718 | File updatedConfFile = new File(Environment.getDataDirectory(), OTA_UPDATED_APNS_PATH); |
Miao | cf39f06 | 2018-12-14 08:50:03 +0800 | [diff] [blame] | 719 | File productConfFile = new File(Environment.getProductDirectory(), PARTNER_APNS_PATH); |
bohu | 075ee99 | 2018-05-24 14:20:28 -0700 | [diff] [blame] | 720 | confFile = pickSecondIfExists(confFile, oemConfFile); |
Miao | cf39f06 | 2018-12-14 08:50:03 +0800 | [diff] [blame] | 721 | confFile = pickSecondIfExists(confFile, productConfFile); |
bohu | 075ee99 | 2018-05-24 14:20:28 -0700 | [diff] [blame] | 722 | confFile = pickSecondIfExists(confFile, updatedConfFile); |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 723 | return confFile; |
| 724 | } |
| 725 | |
| 726 | /** |
| 727 | * This function computes checksum for the file to be read and compares it against the |
| 728 | * last read file. DB needs to be updated only if checksum has changed, or old checksum does |
| 729 | * not exist. |
| 730 | * @return true if DB should be updated with new conf file, false otherwise |
| 731 | */ |
| 732 | private boolean apnDbUpdateNeeded() { |
| 733 | File confFile = getApnConfFile(); |
| 734 | long newChecksum = getChecksum(confFile); |
| 735 | long oldChecksum = getApnConfChecksum(); |
| 736 | if (DBG) log("newChecksum: " + newChecksum); |
| 737 | if (DBG) log("oldChecksum: " + oldChecksum); |
| 738 | if (newChecksum == oldChecksum) { |
| 739 | return false; |
| 740 | } else { |
| 741 | return true; |
| 742 | } |
| 743 | } |
| 744 | |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 745 | /** |
| 746 | * This function adds APNs from xml file(s) to db. The db may or may not be empty to begin |
| 747 | * with. |
| 748 | */ |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 749 | private void initDatabase(SQLiteDatabase db) { |
Wink Saville | 6de1027 | 2014-06-22 07:38:43 -0700 | [diff] [blame] | 750 | if (VDBG) log("dbh.initDatabase:+ db=" + db); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 751 | // Read internal APNS data |
| 752 | Resources r = mContext.getResources(); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 753 | int publicversion = -1; |
Jordan Liu | c591b11 | 2018-05-02 16:35:03 -0700 | [diff] [blame] | 754 | if (r != null) { |
| 755 | XmlResourceParser parser = r.getXml(com.android.internal.R.xml.apns); |
| 756 | try { |
| 757 | XmlUtils.beginDocument(parser, "apns"); |
| 758 | publicversion = Integer.parseInt(parser.getAttributeValue(null, "version")); |
| 759 | loadApns(db, parser); |
| 760 | } catch (Exception e) { |
| 761 | loge("Got exception while loading APN database." + e); |
| 762 | } finally { |
| 763 | parser.close(); |
| 764 | } |
| 765 | } else { |
| 766 | loge("initDatabase: resources=null"); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 767 | } |
| 768 | |
Sungmin Choi | 22b6306 | 2013-01-25 15:53:15 +0900 | [diff] [blame] | 769 | // Read external APNS data (partner-provided) |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 770 | XmlPullParser confparser = null; |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 771 | File confFile = getApnConfFile(); |
Legler Wu | b16a120 | 2014-12-29 13:20:29 +0800 | [diff] [blame] | 772 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 773 | FileReader confreader = null; |
Legler Wu | b16a120 | 2014-12-29 13:20:29 +0800 | [diff] [blame] | 774 | if (DBG) log("confFile = " + confFile); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 775 | try { |
| 776 | confreader = new FileReader(confFile); |
| 777 | confparser = Xml.newPullParser(); |
| 778 | confparser.setInput(confreader); |
| 779 | XmlUtils.beginDocument(confparser, "apns"); |
| 780 | |
| 781 | // Sanity check. Force internal version and confidential versions to agree |
| 782 | int confversion = Integer.parseInt(confparser.getAttributeValue(null, "version")); |
| 783 | if (publicversion != confversion) { |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 784 | log("initDatabase: throwing exception due to version mismatch"); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 785 | throw new IllegalStateException("Internal APNS file version doesn't match " |
| 786 | + confFile.getAbsolutePath()); |
| 787 | } |
| 788 | |
| 789 | loadApns(db, confparser); |
| 790 | } catch (FileNotFoundException e) { |
| 791 | // It's ok if the file isn't found. It means there isn't a confidential file |
| 792 | // Log.e(TAG, "File not found: '" + confFile.getAbsolutePath() + "'"); |
| 793 | } catch (Exception e) { |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 794 | loge("initDatabase: Exception while parsing '" + confFile.getAbsolutePath() + "'" + |
| 795 | e); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 796 | } finally { |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 797 | // Get rid of user/carrier deleted entries that are not present in apn xml file. |
Amit Mahajan | b80f733 | 2015-04-16 10:02:52 -0700 | [diff] [blame] | 798 | // Those entries have edited value USER_DELETED/CARRIER_DELETED. |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 799 | if (VDBG) { |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 800 | log("initDatabase: deleting USER_DELETED and replacing " |
| 801 | + "DELETED_BUT_PRESENT_IN_XML with DELETED"); |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 802 | } |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 803 | |
| 804 | // Delete USER_DELETED |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 805 | db.delete(CARRIERS_TABLE, IS_USER_DELETED + " or " + IS_CARRIER_DELETED, null); |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 806 | |
| 807 | // Change USER_DELETED_BUT_PRESENT_IN_XML to USER_DELETED |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 808 | ContentValues cv = new ContentValues(); |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 809 | cv.put(EDITED_STATUS, USER_DELETED); |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 810 | db.update(CARRIERS_TABLE, cv, IS_USER_DELETED_BUT_PRESENT_IN_XML, null); |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 811 | |
| 812 | // Change CARRIER_DELETED_BUT_PRESENT_IN_XML to CARRIER_DELETED |
| 813 | cv = new ContentValues(); |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 814 | cv.put(EDITED_STATUS, CARRIER_DELETED); |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 815 | db.update(CARRIERS_TABLE, cv, IS_CARRIER_DELETED_BUT_PRESENT_IN_XML, null); |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 816 | |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 817 | if (confreader != null) { |
| 818 | try { |
| 819 | confreader.close(); |
| 820 | } catch (IOException e) { |
| 821 | // do nothing |
| 822 | } |
| 823 | } |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 824 | |
| 825 | // Update the stored checksum |
| 826 | setApnConfChecksum(getChecksum(confFile)); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 827 | } |
Wink Saville | 6de1027 | 2014-06-22 07:38:43 -0700 | [diff] [blame] | 828 | if (VDBG) log("dbh.initDatabase:- db=" + db); |
Amit Mahajan | b068886 | 2014-08-13 16:53:51 +0000 | [diff] [blame] | 829 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 830 | } |
| 831 | |
bohu | 075ee99 | 2018-05-24 14:20:28 -0700 | [diff] [blame] | 832 | private File pickSecondIfExists(File sysApnFile, File altApnFile) { |
Amit Mahajan | b80f733 | 2015-04-16 10:02:52 -0700 | [diff] [blame] | 833 | if (altApnFile.exists()) { |
bohu | 075ee99 | 2018-05-24 14:20:28 -0700 | [diff] [blame] | 834 | if (DBG) log("Load APNs from " + altApnFile.getPath() + |
| 835 | " instead of " + sysApnFile.getPath()); |
| 836 | return altApnFile; |
Amit Mahajan | b80f733 | 2015-04-16 10:02:52 -0700 | [diff] [blame] | 837 | } else { |
bohu | 075ee99 | 2018-05-24 14:20:28 -0700 | [diff] [blame] | 838 | if (DBG) log("Load APNs from " + sysApnFile.getPath() + |
| 839 | " instead of " + altApnFile.getPath()); |
| 840 | return sysApnFile; |
Amit Mahajan | b80f733 | 2015-04-16 10:02:52 -0700 | [diff] [blame] | 841 | } |
Amit Mahajan | b80f733 | 2015-04-16 10:02:52 -0700 | [diff] [blame] | 842 | } |
| 843 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 844 | @Override |
| 845 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { |
Wink Saville | 6de1027 | 2014-06-22 07:38:43 -0700 | [diff] [blame] | 846 | if (DBG) { |
| 847 | log("dbh.onUpgrade:+ db=" + db + " oldV=" + oldVersion + " newV=" + newVersion); |
| 848 | } |
| 849 | |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 850 | deletePreferredApnId(mContext); |
| 851 | |
Jaikumar Ganesh | 8e1a4f9 | 2009-10-26 13:07:37 -0700 | [diff] [blame] | 852 | if (oldVersion < (5 << 16 | 6)) { |
| 853 | // 5 << 16 is the Database version and 6 in the xml version. |
| 854 | |
| 855 | // This change adds a new authtype column to the database. |
| 856 | // The auth type column can have 4 values: 0 (None), 1 (PAP), 2 (CHAP) |
| 857 | // 3 (PAP or CHAP). To avoid breaking compatibility, with already working |
| 858 | // APNs, the unset value (-1) will be used. If the value is -1. |
| 859 | // the authentication will default to 0 (if no user / password) is specified |
| 860 | // or to 3. Currently, there have been no reported problems with |
| 861 | // pre-configured APNs and hence it is set to -1 for them. Similarly, |
| 862 | // if the user, has added a new APN, we set the authentication type |
| 863 | // to -1. |
| 864 | |
| 865 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + |
| 866 | " ADD COLUMN authtype INTEGER DEFAULT -1;"); |
| 867 | |
| 868 | oldVersion = 5 << 16 | 6; |
| 869 | } |
Lorenzo Colitti | 9dd054f | 2010-12-29 15:54:00 -0800 | [diff] [blame] | 870 | if (oldVersion < (6 << 16 | 6)) { |
| 871 | // Add protcol fields to the APN. The XML file does not change. |
| 872 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + |
| 873 | " ADD COLUMN protocol TEXT DEFAULT IP;"); |
| 874 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + |
| 875 | " ADD COLUMN roaming_protocol TEXT DEFAULT IP;"); |
| 876 | oldVersion = 6 << 16 | 6; |
| 877 | } |
sinikang | bae4b07 | 2011-09-02 09:49:37 +0900 | [diff] [blame] | 878 | if (oldVersion < (7 << 16 | 6)) { |
Sungmin Choi | 22b6306 | 2013-01-25 15:53:15 +0900 | [diff] [blame] | 879 | // 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] | 880 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + |
| 881 | " ADD COLUMN carrier_enabled BOOLEAN DEFAULT 1;"); |
| 882 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + |
| 883 | " ADD COLUMN bearer INTEGER DEFAULT 0;"); |
| 884 | oldVersion = 7 << 16 | 6; |
| 885 | } |
Sungmin Choi | 27045ef | 2013-01-25 17:48:06 +0900 | [diff] [blame] | 886 | if (oldVersion < (8 << 16 | 6)) { |
| 887 | // Add mvno_type, mvno_match_data fields to the APN. |
| 888 | // The XML file does not change. |
| 889 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + |
| 890 | " ADD COLUMN mvno_type TEXT DEFAULT '';"); |
| 891 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + |
| 892 | " ADD COLUMN mvno_match_data TEXT DEFAULT '';"); |
| 893 | oldVersion = 8 << 16 | 6; |
| 894 | } |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 895 | if (oldVersion < (9 << 16 | 6)) { |
| 896 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + |
Tom Taylor | 1ad5f91 | 2014-10-28 13:35:34 -0700 | [diff] [blame] | 897 | " ADD COLUMN sub_id INTEGER DEFAULT " + |
Wink Saville | 72b1473 | 2014-11-20 13:06:04 -0800 | [diff] [blame] | 898 | SubscriptionManager.INVALID_SUBSCRIPTION_ID + ";"); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 899 | oldVersion = 9 << 16 | 6; |
| 900 | } |
Amit Mahajan | b068886 | 2014-08-13 16:53:51 +0000 | [diff] [blame] | 901 | if (oldVersion < (10 << 16 | 6)) { |
| 902 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + |
| 903 | " ADD COLUMN profile_id INTEGER DEFAULT 0;"); |
| 904 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + |
| 905 | " ADD COLUMN modem_cognitive BOOLEAN DEFAULT 0;"); |
| 906 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + |
| 907 | " ADD COLUMN max_conns INTEGER DEFAULT 0;"); |
| 908 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + |
| 909 | " ADD COLUMN wait_time INTEGER DEFAULT 0;"); |
| 910 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + |
| 911 | " ADD COLUMN max_conns_time INTEGER DEFAULT 0;"); |
| 912 | oldVersion = 10 << 16 | 6; |
| 913 | } |
w19976 | e9a6c45 | 2014-07-18 16:43:00 -0700 | [diff] [blame] | 914 | if (oldVersion < (11 << 16 | 6)) { |
| 915 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + |
| 916 | " ADD COLUMN mtu INTEGER DEFAULT 0;"); |
| 917 | oldVersion = 11 << 16 | 6; |
| 918 | } |
Tom Taylor | 7c6edbe | 2014-09-04 12:02:34 -0700 | [diff] [blame] | 919 | if (oldVersion < (12 << 16 | 6)) { |
Tom Taylor | c55054d | 2014-09-10 11:01:44 -0700 | [diff] [blame] | 920 | try { |
| 921 | // Try to update the siminfo table. It might not be there. |
| 922 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 923 | " ADD COLUMN " + Telephony.SimInfo.COLUMN_MCC + " INTEGER DEFAULT 0;"); |
Tom Taylor | c55054d | 2014-09-10 11:01:44 -0700 | [diff] [blame] | 924 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 925 | " ADD COLUMN " + Telephony.SimInfo.COLUMN_MNC + " INTEGER DEFAULT 0;"); |
Tom Taylor | c55054d | 2014-09-10 11:01:44 -0700 | [diff] [blame] | 926 | } catch (SQLiteException e) { |
| 927 | if (DBG) { |
| 928 | log("onUpgrade skipping " + SIMINFO_TABLE + " upgrade. " + |
| 929 | " The table will get created in onOpen."); |
| 930 | } |
| 931 | } |
Tom Taylor | 7c6edbe | 2014-09-04 12:02:34 -0700 | [diff] [blame] | 932 | oldVersion = 12 << 16 | 6; |
| 933 | } |
Sanket Padawe | 7e633bd | 2014-11-06 11:50:40 -0800 | [diff] [blame] | 934 | if (oldVersion < (13 << 16 | 6)) { |
| 935 | try { |
| 936 | // Try to update the siminfo table. It might not be there. |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 937 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " + |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 938 | Telephony.SimInfo.COLUMN_CARRIER_NAME + " TEXT DEFAULT '';"); |
Sanket Padawe | 7e633bd | 2014-11-06 11:50:40 -0800 | [diff] [blame] | 939 | } catch (SQLiteException e) { |
| 940 | if (DBG) { |
| 941 | log("onUpgrade skipping " + SIMINFO_TABLE + " upgrade. " + |
| 942 | " The table will get created in onOpen."); |
| 943 | } |
| 944 | } |
| 945 | oldVersion = 13 << 16 | 6; |
| 946 | } |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 947 | if (oldVersion < (14 << 16 | 6)) { |
Amit Mahajan | b80f733 | 2015-04-16 10:02:52 -0700 | [diff] [blame] | 948 | // Do nothing. This is to avoid recreating table twice. Table is anyway recreated |
| 949 | // for next version and that takes care of updates for this version as well. |
| 950 | // This version added a new column user_edited to carriers db. |
| 951 | } |
| 952 | if (oldVersion < (15 << 16 | 6)) { |
Amit Mahajan | 899cc60 | 2015-05-14 17:22:09 -0700 | [diff] [blame] | 953 | // Most devices should be upgrading from version 13. On upgrade new db will be |
| 954 | // populated from the xml included in OTA but user and carrier edited/added entries |
| 955 | // need to be preserved. This new version also adds new columns EDITED and |
| 956 | // BEARER_BITMASK to the table. Upgrade steps from version 13 are: |
| 957 | // 1. preserve user and carrier added/edited APNs (by comparing against |
| 958 | // old-apns-conf.xml included in OTA) - done in preserveUserAndCarrierApns() |
| 959 | // 2. add new columns EDITED and BEARER_BITMASK (create a new table for that) - done |
| 960 | // in createCarriersTable() |
| 961 | // 3. copy over preserved APNs from old table to new table - done in |
| 962 | // copyPreservedApnsToNewTable() |
| 963 | // The only exception if upgrading from version 14 is that EDITED field is already |
| 964 | // present (but is called USER_EDITED) |
Amit Mahajan | d4091e0 | 2015-10-28 12:32:28 -0700 | [diff] [blame] | 965 | /********************************************************************************* |
| 966 | * IMPORTANT NOTE: SINCE CARRIERS TABLE IS RECREATED HERE, IT WILL BE THE LATEST |
| 967 | * VERSION AFTER THIS. AS A RESULT ANY SUBSEQUENT UPDATES TO THE TABLE WILL FAIL |
| 968 | * (DUE TO COLUMN-ALREADY-EXISTS KIND OF EXCEPTION). ALL SUBSEQUENT UPDATES SHOULD |
| 969 | * HANDLE THAT GRACEFULLY. |
| 970 | *********************************************************************************/ |
Amit Mahajan | 899cc60 | 2015-05-14 17:22:09 -0700 | [diff] [blame] | 971 | Cursor c; |
| 972 | String[] proj = {"_id"}; |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 973 | if (VDBG) { |
Amit Mahajan | 899cc60 | 2015-05-14 17:22:09 -0700 | [diff] [blame] | 974 | c = db.query(CARRIERS_TABLE, proj, null, null, null, null, null); |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 975 | log("dbh.onUpgrade:- before upgrading total number of rows: " + c.getCount()); |
| 976 | } |
Amit Mahajan | 899cc60 | 2015-05-14 17:22:09 -0700 | [diff] [blame] | 977 | |
| 978 | // Compare db with old apns xml file so that any user or carrier edited/added |
| 979 | // entries can be preserved across upgrade |
| 980 | preserveUserAndCarrierApns(db); |
| 981 | |
| 982 | c = db.query(CARRIERS_TABLE, null, null, null, null, null, null); |
| 983 | |
| 984 | if (VDBG) { |
| 985 | log("dbh.onUpgrade:- after preserveUserAndCarrierApns() total number of " + |
| 986 | "rows: " + ((c == null) ? 0 : c.getCount())); |
| 987 | } |
| 988 | |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 989 | createCarriersTable(db, CARRIERS_TABLE_TMP); |
| 990 | |
Sanket Padawe | b6fe085 | 2015-07-13 13:37:48 -0700 | [diff] [blame] | 991 | copyPreservedApnsToNewTable(db, c); |
Amit Mahajan | 899cc60 | 2015-05-14 17:22:09 -0700 | [diff] [blame] | 992 | c.close(); |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 993 | |
| 994 | db.execSQL("DROP TABLE IF EXISTS " + CARRIERS_TABLE); |
| 995 | |
| 996 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE_TMP + " rename to " + CARRIERS_TABLE + |
| 997 | ";"); |
| 998 | |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 999 | if (VDBG) { |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 1000 | c = db.query(CARRIERS_TABLE, proj, null, null, null, null, null); |
| 1001 | log("dbh.onUpgrade:- after upgrading total number of rows: " + c.getCount()); |
| 1002 | c.close(); |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 1003 | c = db.query(CARRIERS_TABLE, proj, IS_UNEDITED, null, null, null, null); |
| 1004 | log("dbh.onUpgrade:- after upgrading total number of rows with " + IS_UNEDITED + |
| 1005 | ": " + c.getCount()); |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 1006 | c.close(); |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 1007 | c = db.query(CARRIERS_TABLE, proj, IS_EDITED, null, null, null, null); |
| 1008 | log("dbh.onUpgrade:- after upgrading total number of rows with " + IS_EDITED + |
| 1009 | ": " + c.getCount()); |
Amit Mahajan | 899cc60 | 2015-05-14 17:22:09 -0700 | [diff] [blame] | 1010 | c.close(); |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 1011 | } |
Amit Mahajan | b80f733 | 2015-04-16 10:02:52 -0700 | [diff] [blame] | 1012 | |
| 1013 | oldVersion = 15 << 16 | 6; |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 1014 | } |
Sanket Padawe | b6fe085 | 2015-07-13 13:37:48 -0700 | [diff] [blame] | 1015 | if (oldVersion < (16 << 16 | 6)) { |
| 1016 | try { |
| 1017 | // Try to update the siminfo table. It might not be there. |
| 1018 | // These columns may already be present in which case execSQL will throw an |
| 1019 | // exception |
| 1020 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1021 | + Telephony.SimInfo.COLUMN_CB_EXTREME_THREAT_ALERT |
| 1022 | + " INTEGER DEFAULT 1;"); |
Sanket Padawe | b6fe085 | 2015-07-13 13:37:48 -0700 | [diff] [blame] | 1023 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1024 | + Telephony.SimInfo.COLUMN_CB_SEVERE_THREAT_ALERT |
| 1025 | + " INTEGER DEFAULT 1;"); |
Sanket Padawe | b6fe085 | 2015-07-13 13:37:48 -0700 | [diff] [blame] | 1026 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1027 | + Telephony.SimInfo.COLUMN_CB_AMBER_ALERT + " INTEGER DEFAULT 1;"); |
Sanket Padawe | b6fe085 | 2015-07-13 13:37:48 -0700 | [diff] [blame] | 1028 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1029 | + Telephony.SimInfo.COLUMN_CB_EMERGENCY_ALERT + " INTEGER DEFAULT 1;"); |
Sanket Padawe | b6fe085 | 2015-07-13 13:37:48 -0700 | [diff] [blame] | 1030 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1031 | + Telephony.SimInfo.COLUMN_CB_ALERT_SOUND_DURATION |
| 1032 | + " INTEGER DEFAULT 4;"); |
Sanket Padawe | b6fe085 | 2015-07-13 13:37:48 -0700 | [diff] [blame] | 1033 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1034 | + Telephony.SimInfo.COLUMN_CB_ALERT_REMINDER_INTERVAL |
| 1035 | + " INTEGER DEFAULT 0;"); |
Sanket Padawe | b6fe085 | 2015-07-13 13:37:48 -0700 | [diff] [blame] | 1036 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1037 | + Telephony.SimInfo.COLUMN_CB_ALERT_VIBRATE + " INTEGER DEFAULT 1;"); |
Sanket Padawe | b6fe085 | 2015-07-13 13:37:48 -0700 | [diff] [blame] | 1038 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1039 | + Telephony.SimInfo.COLUMN_CB_ALERT_SPEECH + " INTEGER DEFAULT 1;"); |
Sanket Padawe | b6fe085 | 2015-07-13 13:37:48 -0700 | [diff] [blame] | 1040 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1041 | + Telephony.SimInfo.COLUMN_CB_ETWS_TEST_ALERT + " INTEGER DEFAULT 0;"); |
Sanket Padawe | b6fe085 | 2015-07-13 13:37:48 -0700 | [diff] [blame] | 1042 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1043 | + Telephony.SimInfo.COLUMN_CB_CHANNEL_50_ALERT + " INTEGER DEFAULT 1;"); |
Sanket Padawe | b6fe085 | 2015-07-13 13:37:48 -0700 | [diff] [blame] | 1044 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1045 | + Telephony.SimInfo.COLUMN_CB_CMAS_TEST_ALERT + " INTEGER DEFAULT 0;"); |
Sanket Padawe | b6fe085 | 2015-07-13 13:37:48 -0700 | [diff] [blame] | 1046 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1047 | + Telephony.SimInfo.COLUMN_CB_OPT_OUT_DIALOG + " INTEGER DEFAULT 1;"); |
Sanket Padawe | b6fe085 | 2015-07-13 13:37:48 -0700 | [diff] [blame] | 1048 | } catch (SQLiteException e) { |
| 1049 | if (DBG) { |
| 1050 | log("onUpgrade skipping " + SIMINFO_TABLE + " upgrade. " + |
| 1051 | " The table will get created in onOpen."); |
| 1052 | } |
| 1053 | } |
| 1054 | oldVersion = 16 << 16 | 6; |
| 1055 | } |
Amit Mahajan | da60721 | 2015-10-08 09:13:00 -0700 | [diff] [blame] | 1056 | if (oldVersion < (17 << 16 | 6)) { |
Amit Mahajan | d4091e0 | 2015-10-28 12:32:28 -0700 | [diff] [blame] | 1057 | Cursor c = null; |
| 1058 | try { |
| 1059 | c = db.query(CARRIERS_TABLE, null, null, null, null, null, null, |
| 1060 | String.valueOf(1)); |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 1061 | if (c == null || c.getColumnIndex(USER_VISIBLE) == -1) { |
Amit Mahajan | d4091e0 | 2015-10-28 12:32:28 -0700 | [diff] [blame] | 1062 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + " ADD COLUMN " + |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 1063 | USER_VISIBLE + " BOOLEAN DEFAULT 1;"); |
Amit Mahajan | d4091e0 | 2015-10-28 12:32:28 -0700 | [diff] [blame] | 1064 | } else { |
| 1065 | if (DBG) { |
| 1066 | log("onUpgrade skipping " + CARRIERS_TABLE + " upgrade. Column " + |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 1067 | USER_VISIBLE + " already exists."); |
Amit Mahajan | d4091e0 | 2015-10-28 12:32:28 -0700 | [diff] [blame] | 1068 | } |
| 1069 | } |
| 1070 | } finally { |
| 1071 | if (c != null) { |
| 1072 | c.close(); |
| 1073 | } |
| 1074 | } |
Amit Mahajan | da60721 | 2015-10-08 09:13:00 -0700 | [diff] [blame] | 1075 | oldVersion = 17 << 16 | 6; |
| 1076 | } |
fionaxu | e58c160 | 2016-04-11 01:40:19 -0700 | [diff] [blame] | 1077 | if (oldVersion < (18 << 16 | 6)) { |
| 1078 | try { |
| 1079 | // Try to update the siminfo table. It might not be there. |
| 1080 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " + |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1081 | Telephony.SimInfo.COLUMN_SIM_PROVISIONING_STATUS + " INTEGER DEFAULT " + |
Peter Wang | b097cb6 | 2019-12-05 11:01:18 -0800 | [diff] [blame] | 1082 | Telephony.SimInfo.SIM_PROVISIONED + ";"); |
fionaxu | e58c160 | 2016-04-11 01:40:19 -0700 | [diff] [blame] | 1083 | } catch (SQLiteException e) { |
| 1084 | if (DBG) { |
| 1085 | log("onUpgrade skipping " + SIMINFO_TABLE + " upgrade. " + |
| 1086 | " The table will get created in onOpen."); |
| 1087 | } |
| 1088 | } |
| 1089 | oldVersion = 18 << 16 | 6; |
| 1090 | } |
pkanwar | e08f3ac | 2017-02-02 18:26:32 -0800 | [diff] [blame] | 1091 | if (oldVersion < (19 << 16 | 6)) { |
Cassie | a58ce71 | 2017-12-06 16:21:50 -0800 | [diff] [blame] | 1092 | // Do nothing. This is to avoid recreating table twice. Table is anyway recreated |
| 1093 | // for version 24 and that takes care of updates for this version as well. |
| 1094 | // This version added more fields protocol and roaming protocol to the primary key. |
pkanwar | e08f3ac | 2017-02-02 18:26:32 -0800 | [diff] [blame] | 1095 | } |
Jeff Davidson | b114ed2 | 2017-04-09 14:55:23 -0700 | [diff] [blame] | 1096 | if (oldVersion < (20 << 16 | 6)) { |
| 1097 | try { |
| 1098 | // Try to update the siminfo table. It might not be there. |
| 1099 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " + |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1100 | Telephony.SimInfo.COLUMN_IS_EMBEDDED + " INTEGER DEFAULT 0;"); |
Jeff Davidson | b114ed2 | 2017-04-09 14:55:23 -0700 | [diff] [blame] | 1101 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " + |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1102 | Telephony.SimInfo.COLUMN_ACCESS_RULES + " BLOB;"); |
Jeff Davidson | b114ed2 | 2017-04-09 14:55:23 -0700 | [diff] [blame] | 1103 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " + |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1104 | Telephony.SimInfo.COLUMN_IS_REMOVABLE + " INTEGER DEFAULT 0;"); |
Jeff Davidson | b114ed2 | 2017-04-09 14:55:23 -0700 | [diff] [blame] | 1105 | } catch (SQLiteException e) { |
| 1106 | if (DBG) { |
| 1107 | log("onUpgrade skipping " + SIMINFO_TABLE + " upgrade. " + |
Amit Mahajan | 460d703 | 2017-07-17 14:42:33 -0700 | [diff] [blame] | 1108 | "The table will get created in onOpen."); |
Jeff Davidson | b114ed2 | 2017-04-09 14:55:23 -0700 | [diff] [blame] | 1109 | } |
| 1110 | } |
| 1111 | oldVersion = 20 << 16 | 6; |
| 1112 | } |
Amit Mahajan | 460d703 | 2017-07-17 14:42:33 -0700 | [diff] [blame] | 1113 | if (oldVersion < (21 << 16 | 6)) { |
| 1114 | try { |
yuemingw | c4d40a7 | 2017-11-08 14:14:37 +0000 | [diff] [blame] | 1115 | // Try to update the carriers table. It might not be there. |
Amit Mahajan | 460d703 | 2017-07-17 14:42:33 -0700 | [diff] [blame] | 1116 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + " ADD COLUMN " + |
| 1117 | USER_EDITABLE + " INTEGER DEFAULT 1;"); |
| 1118 | } catch (SQLiteException e) { |
| 1119 | // This is possible if the column already exists which may be the case if the |
| 1120 | // table was just created as part of upgrade to version 19 |
| 1121 | if (DBG) { |
| 1122 | log("onUpgrade skipping " + CARRIERS_TABLE + " upgrade. " + |
| 1123 | "The table will get created in onOpen."); |
| 1124 | } |
| 1125 | } |
| 1126 | oldVersion = 21 << 16 | 6; |
| 1127 | } |
yuemingw | c4d40a7 | 2017-11-08 14:14:37 +0000 | [diff] [blame] | 1128 | if (oldVersion < (22 << 16 | 6)) { |
| 1129 | try { |
Malcolm Chen | adb3e38 | 2017-10-02 16:07:42 -0700 | [diff] [blame] | 1130 | // Try to update the siminfo table. It might not be there. |
| 1131 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1132 | + Telephony.SimInfo.COLUMN_ENHANCED_4G_MODE_ENABLED |
Malcolm Chen | adb3e38 | 2017-10-02 16:07:42 -0700 | [diff] [blame] | 1133 | + " INTEGER DEFAULT -1;"); |
| 1134 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1135 | + Telephony.SimInfo.COLUMN_VT_IMS_ENABLED + " INTEGER DEFAULT -1;"); |
Malcolm Chen | adb3e38 | 2017-10-02 16:07:42 -0700 | [diff] [blame] | 1136 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1137 | + Telephony.SimInfo.COLUMN_WFC_IMS_ENABLED + " INTEGER DEFAULT -1;"); |
Malcolm Chen | adb3e38 | 2017-10-02 16:07:42 -0700 | [diff] [blame] | 1138 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1139 | + Telephony.SimInfo.COLUMN_WFC_IMS_MODE + " INTEGER DEFAULT -1;"); |
Malcolm Chen | adb3e38 | 2017-10-02 16:07:42 -0700 | [diff] [blame] | 1140 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1141 | + Telephony.SimInfo.COLUMN_WFC_IMS_ROAMING_MODE + " INTEGER DEFAULT -1;"); |
Malcolm Chen | adb3e38 | 2017-10-02 16:07:42 -0700 | [diff] [blame] | 1142 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1143 | + Telephony.SimInfo.COLUMN_WFC_IMS_ROAMING_ENABLED + " INTEGER DEFAULT -1;"); |
Malcolm Chen | adb3e38 | 2017-10-02 16:07:42 -0700 | [diff] [blame] | 1144 | } catch (SQLiteException e) { |
| 1145 | if (DBG) { |
| 1146 | log("onUpgrade skipping " + CARRIERS_TABLE + " upgrade. " + |
| 1147 | "The table will get created in onOpen."); |
| 1148 | } |
| 1149 | } |
| 1150 | oldVersion = 22 << 16 | 6; |
| 1151 | } |
| 1152 | if (oldVersion < (23 << 16 | 6)) { |
| 1153 | try { |
yuemingw | c4d40a7 | 2017-11-08 14:14:37 +0000 | [diff] [blame] | 1154 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + " ADD COLUMN " + |
| 1155 | OWNED_BY + " INTEGER DEFAULT " + OWNED_BY_OTHERS + ";"); |
| 1156 | } catch (SQLiteException e) { |
| 1157 | if (DBG) { |
| 1158 | log("onUpgrade skipping " + CARRIERS_TABLE + " upgrade. " + |
| 1159 | "The table will get created in onOpen."); |
| 1160 | } |
| 1161 | } |
Malcolm Chen | adb3e38 | 2017-10-02 16:07:42 -0700 | [diff] [blame] | 1162 | oldVersion = 23 << 16 | 6; |
yuemingw | c4d40a7 | 2017-11-08 14:14:37 +0000 | [diff] [blame] | 1163 | } |
Cassie | a58ce71 | 2017-12-06 16:21:50 -0800 | [diff] [blame] | 1164 | if (oldVersion < (24 << 16 | 6)) { |
| 1165 | Cursor c = null; |
| 1166 | String[] proj = {"_id"}; |
calvinpan | 2b41944 | 2018-10-23 15:05:11 +0800 | [diff] [blame] | 1167 | recreateDB(db, proj, /* version */24); |
Cassie | a58ce71 | 2017-12-06 16:21:50 -0800 | [diff] [blame] | 1168 | if (VDBG) { |
| 1169 | c = db.query(CARRIERS_TABLE, proj, null, null, null, null, null); |
| 1170 | log("dbh.onUpgrade:- after upgrading total number of rows: " + c.getCount()); |
| 1171 | c.close(); |
yinxu | 3d98b6c | 2018-01-05 16:27:30 -0800 | [diff] [blame] | 1172 | c = db.query( |
| 1173 | CARRIERS_TABLE, proj, NETWORK_TYPE_BITMASK, null, null, null, null); |
Cassie | a58ce71 | 2017-12-06 16:21:50 -0800 | [diff] [blame] | 1174 | log("dbh.onUpgrade:- after upgrading total number of rows with " |
| 1175 | + NETWORK_TYPE_BITMASK + ": " + c.getCount()); |
| 1176 | c.close(); |
| 1177 | } |
| 1178 | oldVersion = 24 << 16 | 6; |
| 1179 | } |
yinxu | 3d98b6c | 2018-01-05 16:27:30 -0800 | [diff] [blame] | 1180 | if (oldVersion < (25 << 16 | 6)) { |
| 1181 | // Add a new column SubscriptionManager.CARD_ID into the database and set the value |
| 1182 | // to be the same as the existing column SubscriptionManager.ICC_ID. In order to do |
| 1183 | // this, we need to first make a copy of the existing SIMINFO_TABLE, set the value |
| 1184 | // of the new column SubscriptionManager.CARD_ID, and replace the SIMINFO_TABLE with |
| 1185 | // the new table. |
| 1186 | Cursor c = null; |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1187 | String[] proj = {Telephony.SimInfo.COLUMN_UNIQUE_KEY_SUBSCRIPTION_ID}; |
yinxu | 3d98b6c | 2018-01-05 16:27:30 -0800 | [diff] [blame] | 1188 | recreateSimInfoDB(c, db, proj); |
| 1189 | if (VDBG) { |
| 1190 | c = db.query(SIMINFO_TABLE, proj, null, null, null, null, null); |
| 1191 | log("dbh.onUpgrade:- after upgrading " + SIMINFO_TABLE |
| 1192 | + " total number of rows: " + c.getCount()); |
| 1193 | c.close(); |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1194 | c = db.query(SIMINFO_TABLE, proj, Telephony.SimInfo.COLUMN_CARD_ID |
| 1195 | + " IS NOT NULL", null, null, null, null); |
yinxu | 3d98b6c | 2018-01-05 16:27:30 -0800 | [diff] [blame] | 1196 | log("dbh.onUpgrade:- after upgrading total number of rows with " |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1197 | + Telephony.SimInfo.COLUMN_CARD_ID + ": " + c.getCount()); |
yinxu | 3d98b6c | 2018-01-05 16:27:30 -0800 | [diff] [blame] | 1198 | c.close(); |
| 1199 | } |
| 1200 | oldVersion = 25 << 16 | 6; |
| 1201 | } |
Jordan Liu | 92da8c8 | 2018-04-10 16:00:06 -0700 | [diff] [blame] | 1202 | if (oldVersion < (26 << 16 | 6)) { |
| 1203 | // Add a new column Carriers.APN_SET_ID into the database and set the value to |
| 1204 | // Carriers.NO_SET_SET by default. |
| 1205 | try { |
| 1206 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + " ADD COLUMN " + |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 1207 | APN_SET_ID + " INTEGER DEFAULT " + NO_APN_SET_ID + ";"); |
Jordan Liu | 92da8c8 | 2018-04-10 16:00:06 -0700 | [diff] [blame] | 1208 | } catch (SQLiteException e) { |
| 1209 | if (DBG) { |
| 1210 | log("onUpgrade skipping " + CARRIERS_TABLE + " upgrade. " + |
| 1211 | "The table will get created in onOpen."); |
| 1212 | } |
| 1213 | } |
| 1214 | oldVersion = 26 << 16 | 6; |
| 1215 | } |
Hall Liu | 5479f4d | 2018-07-14 00:31:13 +0000 | [diff] [blame] | 1216 | |
| 1217 | if (oldVersion < (27 << 16 | 6)) { |
| 1218 | // Add the new MCC_STRING and MNC_STRING columns into the subscription table, |
| 1219 | // and attempt to populate them. |
| 1220 | try { |
| 1221 | // Try to update the siminfo table. It might not be there. |
| 1222 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1223 | " ADD COLUMN " + Telephony.SimInfo.COLUMN_MCC_STRING + " TEXT;"); |
Hall Liu | 5479f4d | 2018-07-14 00:31:13 +0000 | [diff] [blame] | 1224 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1225 | " ADD COLUMN " + Telephony.SimInfo.COLUMN_MNC_STRING + " TEXT;"); |
Hall Liu | 5479f4d | 2018-07-14 00:31:13 +0000 | [diff] [blame] | 1226 | } catch (SQLiteException e) { |
| 1227 | if (DBG) { |
| 1228 | log("onUpgrade skipping " + SIMINFO_TABLE + " upgrade. " + |
| 1229 | " The table will get created in onOpen."); |
| 1230 | } |
| 1231 | } |
| 1232 | // Migrate the old integer values over to strings |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1233 | String[] proj = {Telephony.SimInfo.COLUMN_UNIQUE_KEY_SUBSCRIPTION_ID, |
| 1234 | Telephony.SimInfo.COLUMN_MCC, Telephony.SimInfo.COLUMN_MNC}; |
Hall Liu | 5479f4d | 2018-07-14 00:31:13 +0000 | [diff] [blame] | 1235 | try (Cursor c = db.query(SIMINFO_TABLE, proj, null, null, null, null, null)) { |
| 1236 | while (c.moveToNext()) { |
| 1237 | fillInMccMncStringAtCursor(mContext, db, c); |
| 1238 | } |
| 1239 | } |
| 1240 | oldVersion = 27 << 16 | 6; |
| 1241 | } |
Malcolm Chen | 26b8412 | 2018-08-07 15:25:14 -0700 | [diff] [blame] | 1242 | |
| 1243 | if (oldVersion < (28 << 16 | 6)) { |
| 1244 | try { |
| 1245 | // Try to update the siminfo table. It might not be there. |
| 1246 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1247 | + Telephony.SimInfo.COLUMN_IS_OPPORTUNISTIC + " INTEGER DEFAULT 0;"); |
Malcolm Chen | 26b8412 | 2018-08-07 15:25:14 -0700 | [diff] [blame] | 1248 | } catch (SQLiteException e) { |
| 1249 | if (DBG) { |
| 1250 | log("onUpgrade skipping " + SIMINFO_TABLE + " upgrade. " + |
| 1251 | "The table will get created in onOpen."); |
| 1252 | } |
| 1253 | } |
| 1254 | oldVersion = 28 << 16 | 6; |
| 1255 | } |
calvinpan | 2b41944 | 2018-10-23 15:05:11 +0800 | [diff] [blame] | 1256 | |
| 1257 | if (oldVersion < (29 << 16 | 6)) { |
| 1258 | try { |
| 1259 | // Add a new column Telephony.CARRIER_ID into the database and add UNIQUE |
| 1260 | // constraint into table. However, sqlite cannot add constraints to an existing |
| 1261 | // table, so recreate the table. |
| 1262 | String[] proj = {"_id"}; |
| 1263 | recreateDB(db, proj, /* version */29); |
| 1264 | } catch (SQLiteException e) { |
| 1265 | if (DBG) { |
| 1266 | log("onUpgrade skipping " + CARRIERS_TABLE + " upgrade. " + |
| 1267 | "The table will get created in onOpen."); |
| 1268 | } |
| 1269 | } |
| 1270 | oldVersion = 29 << 16 | 6; |
| 1271 | } |
Malcolm Chen | c5630dd | 2018-10-31 20:19:33 -0700 | [diff] [blame] | 1272 | |
| 1273 | if (oldVersion < (30 << 16 | 6)) { |
| 1274 | try { |
Malcolm Chen | c5630dd | 2018-10-31 20:19:33 -0700 | [diff] [blame] | 1275 | // Try to update the siminfo table. It might not be there. |
| 1276 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1277 | + Telephony.SimInfo.COLUMN_GROUP_UUID + " TEXT;"); |
Nazanin Bakhshi | 77e0f79 | 2018-11-26 13:32:48 -0800 | [diff] [blame] | 1278 | } catch (SQLiteException e) { |
| 1279 | if (DBG) { |
| 1280 | log("onUpgrade skipping " + SIMINFO_TABLE + " upgrade. " + |
| 1281 | "The table will get created in onOpen."); |
| 1282 | } |
| 1283 | } |
| 1284 | oldVersion = 30 << 16 | 6; |
| 1285 | } |
Grace Chen | 04fc1b2 | 2018-12-21 18:19:43 -0800 | [diff] [blame] | 1286 | |
Nazanin Bakhshi | 77e0f79 | 2018-11-26 13:32:48 -0800 | [diff] [blame] | 1287 | if (oldVersion < (31 << 16 | 6)) { |
| 1288 | try { |
| 1289 | // Try to update the siminfo table. It might not be there. |
| 1290 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1291 | + Telephony.SimInfo.COLUMN_IS_METERED + " INTEGER DEFAULT 1;"); |
Malcolm Chen | c5630dd | 2018-10-31 20:19:33 -0700 | [diff] [blame] | 1292 | } catch (SQLiteException e) { |
| 1293 | if (DBG) { |
| 1294 | log("onUpgrade skipping " + SIMINFO_TABLE + " upgrade. " + |
| 1295 | "The table will get created in onOpen."); |
| 1296 | } |
| 1297 | } |
Nazanin Bakhshi | 77e0f79 | 2018-11-26 13:32:48 -0800 | [diff] [blame] | 1298 | oldVersion = 31 << 16 | 6; |
Malcolm Chen | c5630dd | 2018-10-31 20:19:33 -0700 | [diff] [blame] | 1299 | } |
Nazanin Bakhshi | 77e0f79 | 2018-11-26 13:32:48 -0800 | [diff] [blame] | 1300 | |
chen xu | 3d1f5a8 | 2018-12-02 17:06:39 -0800 | [diff] [blame] | 1301 | if (oldVersion < (32 << 16 | 6)) { |
| 1302 | try { |
| 1303 | // Try to update the siminfo table. It might not be there. |
| 1304 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1305 | + Telephony.SimInfo.COLUMN_ISO_COUNTRY_CODE + " TEXT;"); |
chen xu | 3d1f5a8 | 2018-12-02 17:06:39 -0800 | [diff] [blame] | 1306 | } catch (SQLiteException e) { |
| 1307 | if (DBG) { |
| 1308 | log("onUpgrade skipping " + SIMINFO_TABLE + " upgrade. " + |
| 1309 | "The table will get created in onOpen."); |
| 1310 | } |
| 1311 | } |
| 1312 | oldVersion = 32 << 16 | 6; |
| 1313 | } |
| 1314 | |
chen xu | 63dd990 | 2018-12-14 00:11:50 -0800 | [diff] [blame] | 1315 | if (oldVersion < (33 << 16 | 6)) { |
| 1316 | try { |
| 1317 | // Try to update the siminfo table. It might not be there. |
| 1318 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1319 | + Telephony.SimInfo.COLUMN_CARRIER_ID + " INTEGER DEFAULT -1;"); |
chen xu | 63dd990 | 2018-12-14 00:11:50 -0800 | [diff] [blame] | 1320 | } catch (SQLiteException e) { |
| 1321 | if (DBG) { |
| 1322 | log("onUpgrade skipping " + SIMINFO_TABLE + " upgrade. " + |
| 1323 | "The table will get created in onOpen."); |
| 1324 | } |
| 1325 | } |
| 1326 | oldVersion = 33 << 16 | 6; |
| 1327 | } |
| 1328 | |
Grace Chen | 04fc1b2 | 2018-12-21 18:19:43 -0800 | [diff] [blame] | 1329 | if (oldVersion < (34 << 16 | 6)) { |
| 1330 | try { |
| 1331 | // Try to update the siminfo table. It might not be there. |
| 1332 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " + |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1333 | Telephony.SimInfo.COLUMN_PROFILE_CLASS + " INTEGER DEFAULT " + |
| 1334 | Telephony.SimInfo.PROFILE_CLASS_UNSET + ";"); |
Grace Chen | 04fc1b2 | 2018-12-21 18:19:43 -0800 | [diff] [blame] | 1335 | } catch (SQLiteException e) { |
| 1336 | if (DBG) { |
| 1337 | log("onUpgrade skipping " + SIMINFO_TABLE + " upgrade. " + |
| 1338 | "The table will get created in onOpen."); |
| 1339 | } |
| 1340 | } |
| 1341 | oldVersion = 34 << 16 | 6; |
| 1342 | } |
| 1343 | |
Vasu Nori | 815b42f | 2018-09-25 10:07:14 -0700 | [diff] [blame] | 1344 | if (oldVersion < (35 << 16 | 6)) { |
| 1345 | try { |
| 1346 | // Try to update the siminfo table. It might not be there. |
| 1347 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1348 | + Telephony.SimInfo.COLUMN_SUBSCRIPTION_TYPE + " INTEGER DEFAULT " |
Peter Wang | b097cb6 | 2019-12-05 11:01:18 -0800 | [diff] [blame] | 1349 | + Telephony.SimInfo.SUBSCRIPTION_TYPE_LOCAL_SIM + ";"); |
Vasu Nori | 815b42f | 2018-09-25 10:07:14 -0700 | [diff] [blame] | 1350 | } catch (SQLiteException e) { |
| 1351 | if (DBG) { |
| 1352 | log("onUpgrade skipping " + SIMINFO_TABLE + " upgrade. " + |
| 1353 | "The table will get created in onOpen."); |
| 1354 | } |
| 1355 | } |
Scott Randolph | db81103 | 2019-02-21 18:11:24 -0800 | [diff] [blame] | 1356 | oldVersion = 35 << 16 | 6; |
Vasu Nori | 815b42f | 2018-09-25 10:07:14 -0700 | [diff] [blame] | 1357 | } |
| 1358 | |
Yuuki Habu | 95aacb1 | 2019-02-22 10:49:06 +0900 | [diff] [blame] | 1359 | if (oldVersion < (36 << 16 | 6)) { |
| 1360 | // Add a new column Carriers.SKIP_464XLAT into the database and set the value to |
| 1361 | // SKIP_464XLAT_DEFAULT. |
| 1362 | try { |
| 1363 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE + " ADD COLUMN " + |
| 1364 | SKIP_464XLAT + " INTEGER DEFAULT " + SKIP_464XLAT_DEFAULT + ";"); |
| 1365 | } catch (SQLiteException e) { |
| 1366 | if (DBG) { |
| 1367 | log("onUpgrade skipping " + CARRIERS_TABLE + " upgrade. " + |
| 1368 | "The table will get created in onOpen."); |
| 1369 | } |
| 1370 | } |
| 1371 | oldVersion = 36 << 16 | 6; |
| 1372 | } |
| 1373 | |
Hall Liu | afbe11c | 2019-04-11 15:29:47 -0700 | [diff] [blame] | 1374 | if (oldVersion < (37 << 16 | 6)) { |
Peter Wang | b097cb6 | 2019-12-05 11:01:18 -0800 | [diff] [blame] | 1375 | // Add new columns Telephony.SimInfo.EHPLMNS and Telephony.SimInfo.HPLMNS into |
Hall Liu | afbe11c | 2019-04-11 15:29:47 -0700 | [diff] [blame] | 1376 | // the database. |
| 1377 | try { |
| 1378 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1379 | " ADD COLUMN " + Telephony.SimInfo.COLUMN_EHPLMNS + " TEXT;"); |
Hall Liu | afbe11c | 2019-04-11 15:29:47 -0700 | [diff] [blame] | 1380 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1381 | " ADD COLUMN " + Telephony.SimInfo.COLUMN_HPLMNS + " TEXT;"); |
Hall Liu | afbe11c | 2019-04-11 15:29:47 -0700 | [diff] [blame] | 1382 | } catch (SQLiteException e) { |
| 1383 | if (DBG) { |
| 1384 | log("onUpgrade skipping " + SIMINFO_TABLE + " upgrade for ehplmns. " + |
| 1385 | "The table will get created in onOpen."); |
| 1386 | } |
| 1387 | } |
| 1388 | oldVersion = 37 << 16 | 6; |
| 1389 | } |
| 1390 | |
Malcolm Chen | 7000a1a | 2019-03-31 13:29:10 -0700 | [diff] [blame] | 1391 | if (oldVersion < (39 << 16 | 6)) { |
| 1392 | try { |
| 1393 | // Try to update the siminfo table. It might not be there. |
| 1394 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1395 | + Telephony.SimInfo.COLUMN_GROUP_OWNER + " TEXT;"); |
Malcolm Chen | 7000a1a | 2019-03-31 13:29:10 -0700 | [diff] [blame] | 1396 | } catch (SQLiteException e) { |
| 1397 | if (DBG) { |
| 1398 | log("onUpgrade skipping " + SIMINFO_TABLE + " upgrade. " + |
| 1399 | "The table will get created in onOpen."); |
| 1400 | } |
| 1401 | } |
| 1402 | oldVersion = 39 << 16 | 6; |
| 1403 | } |
| 1404 | |
Jack Yu | e9e9cb3 | 2019-05-23 16:37:52 -0700 | [diff] [blame] | 1405 | if (oldVersion < (40 << 16 | 6)) { |
| 1406 | try { |
| 1407 | // Try to update the siminfo table. It might not be there. |
| 1408 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1409 | + Telephony.SimInfo.COLUMN_DATA_ENABLED_OVERRIDE_RULES + " TEXT;"); |
Jack Yu | e9e9cb3 | 2019-05-23 16:37:52 -0700 | [diff] [blame] | 1410 | } catch (SQLiteException e) { |
| 1411 | if (DBG) { |
| 1412 | log("onUpgrade skipping " + SIMINFO_TABLE + " upgrade. " + |
| 1413 | "The table will get created in onOpen."); |
| 1414 | } |
| 1415 | } |
| 1416 | oldVersion = 40 << 16 | 6; |
| 1417 | } |
| 1418 | |
Nazanin Bakhshi | cf1ea8f | 2019-05-31 16:29:08 -0700 | [diff] [blame] | 1419 | if (oldVersion < (41 << 16 | 6)) { |
| 1420 | try { |
| 1421 | // Try to update the siminfo table. It might not be there. |
| 1422 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1423 | + Telephony.SimInfo.COLUMN_IMSI + " TEXT;"); |
Nazanin Bakhshi | cf1ea8f | 2019-05-31 16:29:08 -0700 | [diff] [blame] | 1424 | } catch (SQLiteException e) { |
| 1425 | if (DBG) { |
| 1426 | log("onUpgrade skipping " + SIMINFO_TABLE + " upgrade. " + |
| 1427 | "The table will get created in onOpen."); |
| 1428 | } |
| 1429 | } |
| 1430 | oldVersion = 41 << 16 | 6; |
| 1431 | } |
| 1432 | |
Nazanin Bakhshi | da72e98 | 2019-08-13 12:38:22 -0700 | [diff] [blame] | 1433 | if (oldVersion < (42 << 16 | 6)) { |
| 1434 | try { |
| 1435 | // Try to update the siminfo table. It might not be there. |
| 1436 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " + |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1437 | Telephony.SimInfo.COLUMN_ACCESS_RULES_FROM_CARRIER_CONFIGS + " BLOB;"); |
Nazanin Bakhshi | da72e98 | 2019-08-13 12:38:22 -0700 | [diff] [blame] | 1438 | } catch (SQLiteException e) { |
| 1439 | if (DBG) { |
| 1440 | log("onUpgrade skipping " + SIMINFO_TABLE + " upgrade. " + |
| 1441 | "The table will get created in onOpen."); |
| 1442 | } |
| 1443 | } |
| 1444 | } |
| 1445 | |
Malcolm Chen | 7c60228 | 2019-12-04 18:38:17 -0800 | [diff] [blame] | 1446 | if (oldVersion < (43 << 16 | 6)) { |
| 1447 | try { |
| 1448 | // Try to update the siminfo table. It might not be there. |
| 1449 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1450 | + Telephony.SimInfo.COLUMN_UICC_APPLICATIONS_ENABLED |
Malcolm Chen | 7c60228 | 2019-12-04 18:38:17 -0800 | [diff] [blame] | 1451 | + " INTEGER DEFAULT 1;"); |
| 1452 | } catch (SQLiteException e) { |
| 1453 | if (DBG) { |
| 1454 | log("onUpgrade skipping " + SIMINFO_TABLE + " upgrade. " + |
| 1455 | "The table will get created in onOpen."); |
| 1456 | } |
| 1457 | } |
| 1458 | oldVersion = 43 << 16 | 6; |
| 1459 | } |
| 1460 | |
calvinpan | 846d964 | 2020-01-14 14:48:29 +0800 | [diff] [blame] | 1461 | if (oldVersion < (44 << 16 | 6)) { |
| 1462 | try { |
| 1463 | // Try to update the siminfo table. It might not be there. |
| 1464 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1465 | + Telephony.SimInfo.COLUMN_ALLOWED_NETWORK_TYPES |
calvinpan | 846d964 | 2020-01-14 14:48:29 +0800 | [diff] [blame] | 1466 | + " BIGINT DEFAULT -1;"); |
| 1467 | } catch (SQLiteException e) { |
| 1468 | if (DBG) { |
| 1469 | log("onUpgrade skipping " + SIMINFO_TABLE + " upgrade. " + |
| 1470 | "The table will get created in onOpen."); |
| 1471 | } |
| 1472 | } |
| 1473 | oldVersion = 44 << 16 | 6; |
| 1474 | } |
Nazanin Bakhshi | cf1ea8f | 2019-05-31 16:29:08 -0700 | [diff] [blame] | 1475 | |
Brad Ebinger | 748c762 | 2020-01-22 16:12:04 -0800 | [diff] [blame] | 1476 | if (oldVersion < (45 << 16 | 6)) { |
| 1477 | try { |
| 1478 | // Try to update the siminfo table. It might not be there. |
| 1479 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE + " ADD COLUMN " |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1480 | + Telephony.SimInfo.COLUMN_IMS_RCS_UCE_ENABLED |
Brad Ebinger | 748c762 | 2020-01-22 16:12:04 -0800 | [diff] [blame] | 1481 | + " INTEGER DEFAULT 0;"); |
| 1482 | } catch (SQLiteException e) { |
| 1483 | if (DBG) { |
| 1484 | log("onUpgrade skipping " + SIMINFO_TABLE + " upgrade. " + |
| 1485 | "The table will get created in onOpen."); |
| 1486 | } |
| 1487 | } |
| 1488 | oldVersion = 45 << 16 | 6; |
| 1489 | } |
| 1490 | |
Wink Saville | 6de1027 | 2014-06-22 07:38:43 -0700 | [diff] [blame] | 1491 | if (DBG) { |
| 1492 | log("dbh.onUpgrade:- db=" + db + " oldV=" + oldVersion + " newV=" + newVersion); |
| 1493 | } |
Jordan Liu | c591b11 | 2018-05-02 16:35:03 -0700 | [diff] [blame] | 1494 | // when adding fields to onUpgrade, also add a unit test to TelephonyDatabaseHelperTest |
calvinpan | 2b41944 | 2018-10-23 15:05:11 +0800 | [diff] [blame] | 1495 | // and update the DATABASE_VERSION field and add a column in copyAllApnValues |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 1496 | } |
| 1497 | |
yinxu | 3d98b6c | 2018-01-05 16:27:30 -0800 | [diff] [blame] | 1498 | private void recreateSimInfoDB(Cursor c, SQLiteDatabase db, String[] proj) { |
| 1499 | if (VDBG) { |
| 1500 | c = db.query(SIMINFO_TABLE, proj, null, null, null, null, null); |
| 1501 | log("dbh.onUpgrade:+ before upgrading " + SIMINFO_TABLE + |
| 1502 | " total number of rows: " + c.getCount()); |
| 1503 | c.close(); |
| 1504 | } |
| 1505 | |
Brad Ebinger | 1c69fea | 2018-03-27 11:33:16 -0700 | [diff] [blame] | 1506 | // Sort in ascending order by subscription id to make sure the rows do not get flipped |
| 1507 | // during the query and added in the new sim info table in another order (sub id is |
| 1508 | // stored in settings between migrations). |
| 1509 | c = db.query(SIMINFO_TABLE, null, null, null, null, null, ORDER_BY_SUB_ID); |
yinxu | 3d98b6c | 2018-01-05 16:27:30 -0800 | [diff] [blame] | 1510 | |
| 1511 | db.execSQL("DROP TABLE IF EXISTS " + SIMINFO_TABLE_TMP); |
| 1512 | |
| 1513 | createSimInfoTable(db, SIMINFO_TABLE_TMP); |
| 1514 | |
| 1515 | copySimInfoDataToTmpTable(db, c); |
| 1516 | c.close(); |
| 1517 | |
| 1518 | db.execSQL("DROP TABLE IF EXISTS " + SIMINFO_TABLE); |
| 1519 | |
| 1520 | db.execSQL("ALTER TABLE " + SIMINFO_TABLE_TMP + " rename to " + SIMINFO_TABLE + ";"); |
| 1521 | |
| 1522 | } |
| 1523 | |
| 1524 | private void copySimInfoDataToTmpTable(SQLiteDatabase db, Cursor c) { |
| 1525 | // Move entries from SIMINFO_TABLE to SIMINFO_TABLE_TMP |
| 1526 | if (c != null) { |
| 1527 | while (c.moveToNext()) { |
| 1528 | ContentValues cv = new ContentValues(); |
| 1529 | copySimInfoValuesV24(cv, c); |
| 1530 | // The card ID is supposed to be the ICCID of the profile for UICC card, and |
| 1531 | // the EID of the card for eUICC card. Since EID is unknown for old entries in |
| 1532 | // SIMINFO_TABLE, we use ICCID as the card ID for all the old entries while |
| 1533 | // upgrading the SIMINFO_TABLE. In UiccController, both the card ID and ICCID |
| 1534 | // will be checked when user queries the slot information using the card ID |
| 1535 | // from the database. |
| 1536 | getCardIdfromIccid(cv, c); |
| 1537 | try { |
| 1538 | db.insert(SIMINFO_TABLE_TMP, null, cv); |
| 1539 | if (VDBG) { |
| 1540 | log("dbh.copySimInfoDataToTmpTable: db.insert returned >= 0; " + |
| 1541 | "insert successful for cv " + cv); |
| 1542 | } |
| 1543 | } catch (SQLException e) { |
| 1544 | if (VDBG) |
| 1545 | log("dbh.copySimInfoDataToTmpTable insertWithOnConflict exception " + |
| 1546 | e + " for cv " + cv); |
| 1547 | } |
| 1548 | } |
| 1549 | } |
| 1550 | } |
| 1551 | |
| 1552 | private void copySimInfoValuesV24(ContentValues cv, Cursor c) { |
| 1553 | // String vals |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1554 | getStringValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_ICC_ID); |
| 1555 | getStringValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_DISPLAY_NAME); |
| 1556 | getStringValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_CARRIER_NAME); |
| 1557 | getStringValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_NUMBER); |
yinxu | 3d98b6c | 2018-01-05 16:27:30 -0800 | [diff] [blame] | 1558 | |
| 1559 | // bool/int vals |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1560 | getIntValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_SIM_SLOT_INDEX); |
| 1561 | getIntValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_NAME_SOURCE); |
| 1562 | getIntValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_COLOR); |
| 1563 | getIntValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_DISPLAY_NUMBER_FORMAT); |
| 1564 | getIntValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_DATA_ROAMING); |
| 1565 | getIntValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_MCC); |
| 1566 | getIntValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_MNC); |
| 1567 | getIntValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_SIM_PROVISIONING_STATUS); |
| 1568 | getIntValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_IS_EMBEDDED); |
| 1569 | getIntValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_IS_REMOVABLE); |
| 1570 | getIntValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_CB_EXTREME_THREAT_ALERT); |
| 1571 | getIntValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_CB_SEVERE_THREAT_ALERT); |
| 1572 | getIntValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_CB_AMBER_ALERT); |
| 1573 | getIntValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_CB_EMERGENCY_ALERT); |
| 1574 | getIntValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_CB_ALERT_SOUND_DURATION); |
| 1575 | getIntValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_CB_ALERT_REMINDER_INTERVAL); |
| 1576 | getIntValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_CB_ALERT_VIBRATE); |
| 1577 | getIntValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_CB_ALERT_SPEECH); |
| 1578 | getIntValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_CB_ETWS_TEST_ALERT); |
| 1579 | getIntValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_CB_CHANNEL_50_ALERT); |
| 1580 | getIntValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_CB_CMAS_TEST_ALERT); |
| 1581 | getIntValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_CB_OPT_OUT_DIALOG); |
| 1582 | getIntValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_ENHANCED_4G_MODE_ENABLED); |
| 1583 | getIntValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_VT_IMS_ENABLED); |
| 1584 | getIntValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_WFC_IMS_ENABLED); |
| 1585 | getIntValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_WFC_IMS_MODE); |
| 1586 | getIntValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_WFC_IMS_ROAMING_MODE); |
| 1587 | getIntValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_WFC_IMS_ROAMING_ENABLED); |
yinxu | 3d98b6c | 2018-01-05 16:27:30 -0800 | [diff] [blame] | 1588 | |
| 1589 | // Blob vals |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1590 | getBlobValueFromCursor(cv, c, Telephony.SimInfo.COLUMN_ACCESS_RULES); |
yinxu | 3d98b6c | 2018-01-05 16:27:30 -0800 | [diff] [blame] | 1591 | } |
| 1592 | |
| 1593 | private void getCardIdfromIccid(ContentValues cv, Cursor c) { |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1594 | int columnIndex = c.getColumnIndex(Telephony.SimInfo.COLUMN_ICC_ID); |
yinxu | 3d98b6c | 2018-01-05 16:27:30 -0800 | [diff] [blame] | 1595 | if (columnIndex != -1) { |
| 1596 | String fromCursor = c.getString(columnIndex); |
| 1597 | if (!TextUtils.isEmpty(fromCursor)) { |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 1598 | cv.put(Telephony.SimInfo.COLUMN_CARD_ID, fromCursor); |
yinxu | 3d98b6c | 2018-01-05 16:27:30 -0800 | [diff] [blame] | 1599 | } |
| 1600 | } |
| 1601 | } |
| 1602 | |
calvinpan | 2b41944 | 2018-10-23 15:05:11 +0800 | [diff] [blame] | 1603 | private void recreateDB(SQLiteDatabase db, String[] proj, int version) { |
Cassie | a58ce71 | 2017-12-06 16:21:50 -0800 | [diff] [blame] | 1604 | // Upgrade steps are: |
| 1605 | // 1. Create a temp table- done in createCarriersTable() |
| 1606 | // 2. copy over APNs from old table to new table - done in copyDataToTmpTable() |
| 1607 | // 3. Drop the existing table. |
| 1608 | // 4. Copy over the tmp table. |
calvinpan | 2b41944 | 2018-10-23 15:05:11 +0800 | [diff] [blame] | 1609 | Cursor c; |
Cassie | a58ce71 | 2017-12-06 16:21:50 -0800 | [diff] [blame] | 1610 | if (VDBG) { |
| 1611 | c = db.query(CARRIERS_TABLE, proj, null, null, null, null, null); |
| 1612 | log("dbh.onUpgrade:- before upgrading total number of rows: " + c.getCount()); |
| 1613 | c.close(); |
| 1614 | } |
| 1615 | |
| 1616 | c = db.query(CARRIERS_TABLE, null, null, null, null, null, null); |
| 1617 | |
| 1618 | if (VDBG) { |
| 1619 | log("dbh.onUpgrade:- starting data copy of existing rows: " + |
| 1620 | + ((c == null) ? 0 : c.getCount())); |
| 1621 | } |
| 1622 | |
| 1623 | db.execSQL("DROP TABLE IF EXISTS " + CARRIERS_TABLE_TMP); |
| 1624 | |
| 1625 | createCarriersTable(db, CARRIERS_TABLE_TMP); |
| 1626 | |
calvinpan | 2b41944 | 2018-10-23 15:05:11 +0800 | [diff] [blame] | 1627 | copyDataToTmpTable(db, c, version); |
Cassie | a58ce71 | 2017-12-06 16:21:50 -0800 | [diff] [blame] | 1628 | c.close(); |
| 1629 | |
| 1630 | db.execSQL("DROP TABLE IF EXISTS " + CARRIERS_TABLE); |
| 1631 | |
| 1632 | db.execSQL("ALTER TABLE " + CARRIERS_TABLE_TMP + " rename to " + CARRIERS_TABLE + ";"); |
| 1633 | } |
| 1634 | |
Amit Mahajan | 899cc60 | 2015-05-14 17:22:09 -0700 | [diff] [blame] | 1635 | private void preserveUserAndCarrierApns(SQLiteDatabase db) { |
| 1636 | if (VDBG) log("preserveUserAndCarrierApns"); |
| 1637 | XmlPullParser confparser; |
| 1638 | File confFile = new File(Environment.getRootDirectory(), OLD_APNS_PATH); |
| 1639 | FileReader confreader = null; |
| 1640 | try { |
| 1641 | confreader = new FileReader(confFile); |
| 1642 | confparser = Xml.newPullParser(); |
| 1643 | confparser.setInput(confreader); |
| 1644 | XmlUtils.beginDocument(confparser, "apns"); |
| 1645 | |
| 1646 | deleteMatchingApns(db, confparser); |
| 1647 | } catch (FileNotFoundException e) { |
| 1648 | // This function is called only when upgrading db to version 15. Details about the |
| 1649 | // upgrade are mentioned in onUpgrade(). This file missing means user/carrier added |
Amit Mahajan | 5cc51a5 | 2015-10-23 17:32:32 -0700 | [diff] [blame] | 1650 | // APNs cannot be preserved. Log an error message so that OEMs know they need to |
Amit Mahajan | 899cc60 | 2015-05-14 17:22:09 -0700 | [diff] [blame] | 1651 | // include old apns file for comparison. |
Amit Mahajan | 5cc51a5 | 2015-10-23 17:32:32 -0700 | [diff] [blame] | 1652 | loge("PRESERVEUSERANDCARRIERAPNS: " + OLD_APNS_PATH + |
| 1653 | " NOT FOUND. IT IS NEEDED TO UPGRADE FROM OLDER VERSIONS OF APN " + |
| 1654 | "DB WHILE PRESERVING USER/CARRIER ADDED/EDITED ENTRIES."); |
Amit Mahajan | 899cc60 | 2015-05-14 17:22:09 -0700 | [diff] [blame] | 1655 | } catch (Exception e) { |
| 1656 | loge("preserveUserAndCarrierApns: Exception while parsing '" + |
| 1657 | confFile.getAbsolutePath() + "'" + e); |
| 1658 | } finally { |
| 1659 | if (confreader != null) { |
| 1660 | try { |
| 1661 | confreader.close(); |
| 1662 | } catch (IOException e) { |
| 1663 | // do nothing |
| 1664 | } |
| 1665 | } |
| 1666 | } |
| 1667 | } |
| 1668 | |
| 1669 | private void deleteMatchingApns(SQLiteDatabase db, XmlPullParser parser) { |
| 1670 | if (VDBG) log("deleteMatchingApns"); |
| 1671 | if (parser != null) { |
| 1672 | if (VDBG) log("deleteMatchingApns: parser != null"); |
| 1673 | try { |
| 1674 | XmlUtils.nextElement(parser); |
| 1675 | while (parser.getEventType() != XmlPullParser.END_DOCUMENT) { |
| 1676 | ContentValues row = getRow(parser); |
| 1677 | if (row == null) { |
| 1678 | throw new XmlPullParserException("Expected 'apn' tag", parser, null); |
| 1679 | } |
| 1680 | deleteRow(db, row); |
| 1681 | XmlUtils.nextElement(parser); |
| 1682 | } |
| 1683 | } catch (XmlPullParserException e) { |
| 1684 | loge("deleteMatchingApns: Got XmlPullParserException while deleting apns." + e); |
| 1685 | } catch (IOException e) { |
| 1686 | loge("deleteMatchingApns: Got IOException while deleting apns." + e); |
| 1687 | } catch (SQLException e) { |
| 1688 | loge("deleteMatchingApns: Got SQLException while deleting apns." + e); |
| 1689 | } |
| 1690 | } |
| 1691 | } |
| 1692 | |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 1693 | private String queryValFirst(String field) { |
| 1694 | return field + "=?"; |
| 1695 | } |
| 1696 | |
| 1697 | private String queryVal(String field) { |
| 1698 | return " and " + field + "=?"; |
| 1699 | } |
| 1700 | |
| 1701 | private String queryValOrNull(String field) { |
| 1702 | return " and (" + field + "=? or " + field + " is null)"; |
| 1703 | } |
| 1704 | |
| 1705 | private String queryVal2OrNull(String field) { |
| 1706 | return " and (" + field + "=? or " + field + "=? or " + field + " is null)"; |
| 1707 | } |
| 1708 | |
Amit Mahajan | 899cc60 | 2015-05-14 17:22:09 -0700 | [diff] [blame] | 1709 | private void deleteRow(SQLiteDatabase db, ContentValues values) { |
| 1710 | if (VDBG) log("deleteRow"); |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 1711 | String where = queryValFirst(NUMERIC) + |
| 1712 | queryVal(MNC) + |
| 1713 | queryVal(MNC) + |
| 1714 | queryValOrNull(APN) + |
| 1715 | queryValOrNull(USER) + |
| 1716 | queryValOrNull(SERVER) + |
| 1717 | queryValOrNull(PASSWORD) + |
| 1718 | queryValOrNull(PROXY) + |
| 1719 | queryValOrNull(PORT) + |
| 1720 | queryValOrNull(MMSPROXY) + |
| 1721 | queryValOrNull(MMSPORT) + |
| 1722 | queryValOrNull(MMSC) + |
| 1723 | queryValOrNull(AUTH_TYPE) + |
| 1724 | queryValOrNull(TYPE) + |
| 1725 | queryValOrNull(PROTOCOL) + |
| 1726 | queryValOrNull(ROAMING_PROTOCOL) + |
| 1727 | queryVal2OrNull(CARRIER_ENABLED) + |
| 1728 | queryValOrNull(BEARER) + |
| 1729 | queryValOrNull(MVNO_TYPE) + |
| 1730 | queryValOrNull(MVNO_MATCH_DATA) + |
| 1731 | queryValOrNull(PROFILE_ID) + |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 1732 | queryVal2OrNull(MODEM_PERSIST) + |
| 1733 | queryValOrNull(MAX_CONNECTIONS) + |
| 1734 | queryValOrNull(WAIT_TIME_RETRY) + |
| 1735 | queryValOrNull(TIME_LIMIT_FOR_MAX_CONNECTIONS) + |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 1736 | queryValOrNull(MTU); |
Amit Mahajan | 899cc60 | 2015-05-14 17:22:09 -0700 | [diff] [blame] | 1737 | String[] whereArgs = new String[29]; |
| 1738 | int i = 0; |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 1739 | whereArgs[i++] = values.getAsString(NUMERIC); |
| 1740 | whereArgs[i++] = values.getAsString(MCC); |
| 1741 | whereArgs[i++] = values.getAsString(MNC); |
| 1742 | whereArgs[i++] = values.getAsString(NAME); |
| 1743 | whereArgs[i++] = values.containsKey(APN) ? |
| 1744 | values.getAsString(APN) : ""; |
| 1745 | whereArgs[i++] = values.containsKey(USER) ? |
| 1746 | values.getAsString(USER) : ""; |
| 1747 | whereArgs[i++] = values.containsKey(SERVER) ? |
| 1748 | values.getAsString(SERVER) : ""; |
| 1749 | whereArgs[i++] = values.containsKey(PASSWORD) ? |
| 1750 | values.getAsString(PASSWORD) : ""; |
| 1751 | whereArgs[i++] = values.containsKey(PROXY) ? |
| 1752 | values.getAsString(PROXY) : ""; |
| 1753 | whereArgs[i++] = values.containsKey(PORT) ? |
| 1754 | values.getAsString(PORT) : ""; |
| 1755 | whereArgs[i++] = values.containsKey(MMSPROXY) ? |
| 1756 | values.getAsString(MMSPROXY) : ""; |
| 1757 | whereArgs[i++] = values.containsKey(MMSPORT) ? |
| 1758 | values.getAsString(MMSPORT) : ""; |
| 1759 | whereArgs[i++] = values.containsKey(MMSC) ? |
| 1760 | values.getAsString(MMSC) : ""; |
| 1761 | whereArgs[i++] = values.containsKey(AUTH_TYPE) ? |
| 1762 | values.getAsString(AUTH_TYPE) : "-1"; |
| 1763 | whereArgs[i++] = values.containsKey(TYPE) ? |
| 1764 | values.getAsString(TYPE) : ""; |
| 1765 | whereArgs[i++] = values.containsKey(PROTOCOL) ? |
yuemingw | e0101b8 | 2017-12-13 21:49:09 +0000 | [diff] [blame] | 1766 | values.getAsString(PROTOCOL) : DEFAULT_PROTOCOL; |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 1767 | whereArgs[i++] = values.containsKey(ROAMING_PROTOCOL) ? |
yuemingw | e0101b8 | 2017-12-13 21:49:09 +0000 | [diff] [blame] | 1768 | values.getAsString(ROAMING_PROTOCOL) : DEFAULT_ROAMING_PROTOCOL; |
Amit Mahajan | 899cc60 | 2015-05-14 17:22:09 -0700 | [diff] [blame] | 1769 | |
Jordan Liu | 8b78f71 | 2018-05-21 11:10:48 -0700 | [diff] [blame] | 1770 | if (values.containsKey(CARRIER_ENABLED)) { |
| 1771 | whereArgs[i++] = convertStringToBoolString(values.getAsString(CARRIER_ENABLED)); |
| 1772 | whereArgs[i++] = convertStringToIntString(values.getAsString(CARRIER_ENABLED)); |
Amit Mahajan | 899cc60 | 2015-05-14 17:22:09 -0700 | [diff] [blame] | 1773 | } else { |
Jordan Liu | 8b78f71 | 2018-05-21 11:10:48 -0700 | [diff] [blame] | 1774 | String defaultIntString = CARRIERS_UNIQUE_FIELDS_DEFAULTS.get(CARRIER_ENABLED); |
| 1775 | whereArgs[i++] = convertStringToBoolString(defaultIntString); |
| 1776 | whereArgs[i++] = defaultIntString; |
Amit Mahajan | 899cc60 | 2015-05-14 17:22:09 -0700 | [diff] [blame] | 1777 | } |
| 1778 | |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 1779 | whereArgs[i++] = values.containsKey(BEARER) ? |
| 1780 | values.getAsString(BEARER) : "0"; |
| 1781 | whereArgs[i++] = values.containsKey(MVNO_TYPE) ? |
| 1782 | values.getAsString(MVNO_TYPE) : ""; |
| 1783 | whereArgs[i++] = values.containsKey(MVNO_MATCH_DATA) ? |
| 1784 | values.getAsString(MVNO_MATCH_DATA) : ""; |
| 1785 | whereArgs[i++] = values.containsKey(PROFILE_ID) ? |
| 1786 | values.getAsString(PROFILE_ID) : "0"; |
Amit Mahajan | 899cc60 | 2015-05-14 17:22:09 -0700 | [diff] [blame] | 1787 | |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 1788 | if (values.containsKey(MODEM_PERSIST) && |
| 1789 | (values.getAsString(MODEM_PERSIST). |
Amit Mahajan | 899cc60 | 2015-05-14 17:22:09 -0700 | [diff] [blame] | 1790 | equalsIgnoreCase("true") || |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 1791 | values.getAsString(MODEM_PERSIST).equals("1"))) { |
Amit Mahajan | 899cc60 | 2015-05-14 17:22:09 -0700 | [diff] [blame] | 1792 | whereArgs[i++] = "true"; |
| 1793 | whereArgs[i++] = "1"; |
| 1794 | } else { |
| 1795 | whereArgs[i++] = "false"; |
| 1796 | whereArgs[i++] = "0"; |
| 1797 | } |
| 1798 | |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 1799 | whereArgs[i++] = values.containsKey(MAX_CONNECTIONS) ? |
| 1800 | values.getAsString(MAX_CONNECTIONS) : "0"; |
| 1801 | whereArgs[i++] = values.containsKey(WAIT_TIME_RETRY) ? |
| 1802 | values.getAsString(WAIT_TIME_RETRY) : "0"; |
| 1803 | whereArgs[i++] = values.containsKey(TIME_LIMIT_FOR_MAX_CONNECTIONS) ? |
| 1804 | values.getAsString(TIME_LIMIT_FOR_MAX_CONNECTIONS) : "0"; |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 1805 | whereArgs[i++] = values.containsKey(MTU) ? |
| 1806 | values.getAsString(MTU) : "0"; |
Amit Mahajan | 899cc60 | 2015-05-14 17:22:09 -0700 | [diff] [blame] | 1807 | |
| 1808 | if (VDBG) { |
| 1809 | log("deleteRow: where: " + where); |
| 1810 | |
| 1811 | StringBuilder builder = new StringBuilder(); |
| 1812 | for (String s : whereArgs) { |
| 1813 | builder.append(s + ", "); |
| 1814 | } |
| 1815 | |
| 1816 | log("deleteRow: whereArgs: " + builder.toString()); |
| 1817 | } |
| 1818 | db.delete(CARRIERS_TABLE, where, whereArgs); |
| 1819 | } |
| 1820 | |
calvinpan | 2b41944 | 2018-10-23 15:05:11 +0800 | [diff] [blame] | 1821 | private void copyDataToTmpTable(SQLiteDatabase db, Cursor c, int version) { |
pkanwar | e08f3ac | 2017-02-02 18:26:32 -0800 | [diff] [blame] | 1822 | // Move entries from CARRIERS_TABLE to CARRIERS_TABLE_TMP |
| 1823 | if (c != null) { |
| 1824 | while (c.moveToNext()) { |
| 1825 | ContentValues cv = new ContentValues(); |
calvinpan | 2b41944 | 2018-10-23 15:05:11 +0800 | [diff] [blame] | 1826 | copyAllApnValues(cv, c); |
| 1827 | if (version == 24) { |
| 1828 | // Sync bearer bitmask and network type bitmask |
| 1829 | getNetworkTypeBitmaskFromCursor(cv, c); |
| 1830 | } |
pkanwar | e08f3ac | 2017-02-02 18:26:32 -0800 | [diff] [blame] | 1831 | try { |
| 1832 | db.insertWithOnConflict(CARRIERS_TABLE_TMP, null, cv, |
| 1833 | SQLiteDatabase.CONFLICT_ABORT); |
| 1834 | if (VDBG) { |
| 1835 | log("dbh.copyPreservedApnsToNewTable: db.insert returned >= 0; " + |
| 1836 | "insert successful for cv " + cv); |
| 1837 | } |
| 1838 | } catch (SQLException e) { |
| 1839 | if (VDBG) |
| 1840 | log("dbh.copyPreservedApnsToNewTable insertWithOnConflict exception " + |
| 1841 | e + " for cv " + cv); |
| 1842 | } |
| 1843 | } |
| 1844 | } |
| 1845 | } |
| 1846 | |
Amit Mahajan | 4768823 | 2017-04-09 16:08:19 -0700 | [diff] [blame] | 1847 | private void copyApnValuesV17(ContentValues cv, Cursor c) { |
pkanwar | e08f3ac | 2017-02-02 18:26:32 -0800 | [diff] [blame] | 1848 | // Include only non-null values in cv so that null values can be replaced |
| 1849 | // with default if there's a default value for the field |
| 1850 | |
| 1851 | // String vals |
| 1852 | getStringValueFromCursor(cv, c, NAME); |
| 1853 | getStringValueFromCursor(cv, c, NUMERIC); |
| 1854 | getStringValueFromCursor(cv, c, MCC); |
| 1855 | getStringValueFromCursor(cv, c, MNC); |
| 1856 | getStringValueFromCursor(cv, c, APN); |
| 1857 | getStringValueFromCursor(cv, c, USER); |
| 1858 | getStringValueFromCursor(cv, c, SERVER); |
| 1859 | getStringValueFromCursor(cv, c, PASSWORD); |
| 1860 | getStringValueFromCursor(cv, c, PROXY); |
| 1861 | getStringValueFromCursor(cv, c, PORT); |
| 1862 | getStringValueFromCursor(cv, c, MMSPROXY); |
| 1863 | getStringValueFromCursor(cv, c, MMSPORT); |
| 1864 | getStringValueFromCursor(cv, c, MMSC); |
| 1865 | getStringValueFromCursor(cv, c, TYPE); |
| 1866 | getStringValueFromCursor(cv, c, PROTOCOL); |
| 1867 | getStringValueFromCursor(cv, c, ROAMING_PROTOCOL); |
| 1868 | getStringValueFromCursor(cv, c, MVNO_TYPE); |
| 1869 | getStringValueFromCursor(cv, c, MVNO_MATCH_DATA); |
| 1870 | |
| 1871 | // bool/int vals |
| 1872 | getIntValueFromCursor(cv, c, AUTH_TYPE); |
| 1873 | getIntValueFromCursor(cv, c, CURRENT); |
| 1874 | getIntValueFromCursor(cv, c, CARRIER_ENABLED); |
| 1875 | getIntValueFromCursor(cv, c, BEARER); |
| 1876 | getIntValueFromCursor(cv, c, SUBSCRIPTION_ID); |
| 1877 | getIntValueFromCursor(cv, c, PROFILE_ID); |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 1878 | getIntValueFromCursor(cv, c, MODEM_PERSIST); |
| 1879 | getIntValueFromCursor(cv, c, MAX_CONNECTIONS); |
| 1880 | getIntValueFromCursor(cv, c, WAIT_TIME_RETRY); |
| 1881 | getIntValueFromCursor(cv, c, TIME_LIMIT_FOR_MAX_CONNECTIONS); |
pkanwar | e08f3ac | 2017-02-02 18:26:32 -0800 | [diff] [blame] | 1882 | getIntValueFromCursor(cv, c, MTU); |
| 1883 | getIntValueFromCursor(cv, c, BEARER_BITMASK); |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 1884 | getIntValueFromCursor(cv, c, EDITED_STATUS); |
Amit Mahajan | 4768823 | 2017-04-09 16:08:19 -0700 | [diff] [blame] | 1885 | getIntValueFromCursor(cv, c, USER_VISIBLE); |
pkanwar | e08f3ac | 2017-02-02 18:26:32 -0800 | [diff] [blame] | 1886 | } |
| 1887 | |
calvinpan | 2b41944 | 2018-10-23 15:05:11 +0800 | [diff] [blame] | 1888 | private void copyAllApnValues(ContentValues cv, Cursor c) { |
| 1889 | // String vals |
| 1890 | getStringValueFromCursor(cv, c, NAME); |
| 1891 | getStringValueFromCursor(cv, c, NUMERIC); |
| 1892 | getStringValueFromCursor(cv, c, MCC); |
| 1893 | getStringValueFromCursor(cv, c, MNC); |
| 1894 | getStringValueFromCursor(cv, c, APN); |
| 1895 | getStringValueFromCursor(cv, c, USER); |
| 1896 | getStringValueFromCursor(cv, c, SERVER); |
| 1897 | getStringValueFromCursor(cv, c, PASSWORD); |
| 1898 | getStringValueFromCursor(cv, c, PROXY); |
| 1899 | getStringValueFromCursor(cv, c, PORT); |
| 1900 | getStringValueFromCursor(cv, c, MMSPROXY); |
| 1901 | getStringValueFromCursor(cv, c, MMSPORT); |
| 1902 | getStringValueFromCursor(cv, c, MMSC); |
| 1903 | getStringValueFromCursor(cv, c, TYPE); |
| 1904 | getStringValueFromCursor(cv, c, PROTOCOL); |
| 1905 | getStringValueFromCursor(cv, c, ROAMING_PROTOCOL); |
| 1906 | getStringValueFromCursor(cv, c, MVNO_TYPE); |
| 1907 | getStringValueFromCursor(cv, c, MVNO_MATCH_DATA); |
| 1908 | |
| 1909 | // bool/int vals |
| 1910 | getIntValueFromCursor(cv, c, AUTH_TYPE); |
| 1911 | getIntValueFromCursor(cv, c, CURRENT); |
| 1912 | getIntValueFromCursor(cv, c, CARRIER_ENABLED); |
| 1913 | getIntValueFromCursor(cv, c, BEARER); |
| 1914 | getIntValueFromCursor(cv, c, SUBSCRIPTION_ID); |
| 1915 | getIntValueFromCursor(cv, c, PROFILE_ID); |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 1916 | getIntValueFromCursor(cv, c, MODEM_PERSIST); |
| 1917 | getIntValueFromCursor(cv, c, MAX_CONNECTIONS); |
| 1918 | getIntValueFromCursor(cv, c, WAIT_TIME_RETRY); |
| 1919 | getIntValueFromCursor(cv, c, TIME_LIMIT_FOR_MAX_CONNECTIONS); |
calvinpan | 2b41944 | 2018-10-23 15:05:11 +0800 | [diff] [blame] | 1920 | getIntValueFromCursor(cv, c, MTU); |
| 1921 | getIntValueFromCursor(cv, c, NETWORK_TYPE_BITMASK); |
| 1922 | getIntValueFromCursor(cv, c, BEARER_BITMASK); |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 1923 | getIntValueFromCursor(cv, c, EDITED_STATUS); |
calvinpan | 2b41944 | 2018-10-23 15:05:11 +0800 | [diff] [blame] | 1924 | getIntValueFromCursor(cv, c, USER_VISIBLE); |
| 1925 | getIntValueFromCursor(cv, c, USER_EDITABLE); |
| 1926 | getIntValueFromCursor(cv, c, OWNED_BY); |
| 1927 | getIntValueFromCursor(cv, c, APN_SET_ID); |
Yuuki Habu | 95aacb1 | 2019-02-22 10:49:06 +0900 | [diff] [blame] | 1928 | getIntValueFromCursor(cv, c, SKIP_464XLAT); |
calvinpan | 2b41944 | 2018-10-23 15:05:11 +0800 | [diff] [blame] | 1929 | } |
pkanwar | e08f3ac | 2017-02-02 18:26:32 -0800 | [diff] [blame] | 1930 | |
Sanket Padawe | b6fe085 | 2015-07-13 13:37:48 -0700 | [diff] [blame] | 1931 | private void copyPreservedApnsToNewTable(SQLiteDatabase db, Cursor c) { |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 1932 | // Move entries from CARRIERS_TABLE to CARRIERS_TABLE_TMP |
Jordan Liu | c591b11 | 2018-05-02 16:35:03 -0700 | [diff] [blame] | 1933 | if (c != null && mContext.getResources() != null) { |
| 1934 | try { |
| 1935 | String[] persistApnsForPlmns = mContext.getResources().getStringArray( |
| 1936 | R.array.persist_apns_for_plmn); |
| 1937 | while (c.moveToNext()) { |
| 1938 | ContentValues cv = new ContentValues(); |
| 1939 | String val; |
| 1940 | // Using V17 copy function for V15 upgrade. This should be fine since it handles |
| 1941 | // columns that may not exist properly (getStringValueFromCursor() and |
| 1942 | // getIntValueFromCursor() handle column index -1) |
| 1943 | copyApnValuesV17(cv, c); |
| 1944 | // Change bearer to a bitmask |
| 1945 | String bearerStr = c.getString(c.getColumnIndex(BEARER)); |
| 1946 | if (!TextUtils.isEmpty(bearerStr)) { |
SongFerngWang | 64fb3dd | 2019-12-02 20:59:47 +0800 | [diff] [blame] | 1947 | int bearer_bitmask = getBitmaskForTech(Integer.parseInt(bearerStr)); |
Jordan Liu | c591b11 | 2018-05-02 16:35:03 -0700 | [diff] [blame] | 1948 | cv.put(BEARER_BITMASK, bearer_bitmask); |
Cassie | a58ce71 | 2017-12-06 16:21:50 -0800 | [diff] [blame] | 1949 | |
SongFerngWang | 64fb3dd | 2019-12-02 20:59:47 +0800 | [diff] [blame] | 1950 | int networkTypeBitmask = rilRadioTechnologyToNetworkTypeBitmask( |
| 1951 | Integer.parseInt(bearerStr)); |
Jordan Liu | c591b11 | 2018-05-02 16:35:03 -0700 | [diff] [blame] | 1952 | cv.put(NETWORK_TYPE_BITMASK, networkTypeBitmask); |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 1953 | } |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 1954 | |
Jordan Liu | c591b11 | 2018-05-02 16:35:03 -0700 | [diff] [blame] | 1955 | int userEditedColumnIdx = c.getColumnIndex("user_edited"); |
| 1956 | if (userEditedColumnIdx != -1) { |
| 1957 | String user_edited = c.getString(userEditedColumnIdx); |
| 1958 | if (!TextUtils.isEmpty(user_edited)) { |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 1959 | cv.put(EDITED_STATUS, new Integer(user_edited)); |
Amit Mahajan | 899cc60 | 2015-05-14 17:22:09 -0700 | [diff] [blame] | 1960 | } |
Jordan Liu | c591b11 | 2018-05-02 16:35:03 -0700 | [diff] [blame] | 1961 | } else { |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 1962 | cv.put(EDITED_STATUS, CARRIER_EDITED); |
Jordan Liu | c591b11 | 2018-05-02 16:35:03 -0700 | [diff] [blame] | 1963 | } |
Amit Mahajan | b80f733 | 2015-04-16 10:02:52 -0700 | [diff] [blame] | 1964 | |
Jordan Liu | c591b11 | 2018-05-02 16:35:03 -0700 | [diff] [blame] | 1965 | // New EDITED column. Default value (UNEDITED) will |
| 1966 | // be used for all rows except for non-mvno entries for plmns indicated |
| 1967 | // by resource: those will be set to CARRIER_EDITED to preserve |
| 1968 | // their current values |
| 1969 | val = c.getString(c.getColumnIndex(NUMERIC)); |
| 1970 | for (String s : persistApnsForPlmns) { |
| 1971 | if (!TextUtils.isEmpty(val) && val.equals(s) && |
| 1972 | (!cv.containsKey(MVNO_TYPE) || |
| 1973 | TextUtils.isEmpty(cv.getAsString(MVNO_TYPE)))) { |
| 1974 | if (userEditedColumnIdx == -1) { |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 1975 | cv.put(EDITED_STATUS, CARRIER_EDITED); |
Jordan Liu | c591b11 | 2018-05-02 16:35:03 -0700 | [diff] [blame] | 1976 | } else { // if (oldVersion == 14) -- if db had user_edited column |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 1977 | if (cv.getAsInteger(EDITED_STATUS) == USER_EDITED) { |
| 1978 | cv.put(EDITED_STATUS, CARRIER_EDITED); |
Jordan Liu | c591b11 | 2018-05-02 16:35:03 -0700 | [diff] [blame] | 1979 | } |
| 1980 | } |
| 1981 | |
| 1982 | break; |
| 1983 | } |
| 1984 | } |
| 1985 | |
| 1986 | try { |
| 1987 | db.insertWithOnConflict(CARRIERS_TABLE_TMP, null, cv, |
| 1988 | SQLiteDatabase.CONFLICT_ABORT); |
| 1989 | if (VDBG) { |
| 1990 | log("dbh.copyPreservedApnsToNewTable: db.insert returned >= 0; " + |
| 1991 | "insert successful for cv " + cv); |
| 1992 | } |
| 1993 | } catch (SQLException e) { |
| 1994 | if (VDBG) |
| 1995 | log("dbh.copyPreservedApnsToNewTable insertWithOnConflict exception " + |
| 1996 | e + " for cv " + cv); |
| 1997 | // Insertion failed which could be due to a conflict. Check if that is |
| 1998 | // the case and merge the entries |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 1999 | Cursor oldRow = selectConflictingRow(db, |
Jordan Liu | c591b11 | 2018-05-02 16:35:03 -0700 | [diff] [blame] | 2000 | CARRIERS_TABLE_TMP, cv); |
| 2001 | if (oldRow != null) { |
| 2002 | ContentValues mergedValues = new ContentValues(); |
| 2003 | mergeFieldsAndUpdateDb(db, CARRIERS_TABLE_TMP, oldRow, cv, |
| 2004 | mergedValues, true, mContext); |
| 2005 | oldRow.close(); |
| 2006 | } |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 2007 | } |
| 2008 | } |
Jordan Liu | c591b11 | 2018-05-02 16:35:03 -0700 | [diff] [blame] | 2009 | } catch (Resources.NotFoundException e) { |
| 2010 | loge("array.persist_apns_for_plmn is not found"); |
| 2011 | return; |
Amit Mahajan | b80f733 | 2015-04-16 10:02:52 -0700 | [diff] [blame] | 2012 | } |
| 2013 | } |
Amit Mahajan | b80f733 | 2015-04-16 10:02:52 -0700 | [diff] [blame] | 2014 | } |
| 2015 | |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 2016 | private void getStringValueFromCursor(ContentValues cv, Cursor c, String key) { |
Amit Mahajan | 4768823 | 2017-04-09 16:08:19 -0700 | [diff] [blame] | 2017 | int columnIndex = c.getColumnIndex(key); |
| 2018 | if (columnIndex != -1) { |
| 2019 | String fromCursor = c.getString(columnIndex); |
| 2020 | if (!TextUtils.isEmpty(fromCursor)) { |
| 2021 | cv.put(key, fromCursor); |
| 2022 | } |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 2023 | } |
| 2024 | } |
| 2025 | |
Cassie | a58ce71 | 2017-12-06 16:21:50 -0800 | [diff] [blame] | 2026 | /** |
| 2027 | * If NETWORK_TYPE_BITMASK does not exist (upgrade from version 23 to version 24), generate |
| 2028 | * NETWORK_TYPE_BITMASK with the use of BEARER_BITMASK. If NETWORK_TYPE_BITMASK existed |
| 2029 | * (upgrade from version 24 to forward), always map NETWORK_TYPE_BITMASK to BEARER_BITMASK. |
| 2030 | */ |
| 2031 | private void getNetworkTypeBitmaskFromCursor(ContentValues cv, Cursor c) { |
| 2032 | int columnIndex = c.getColumnIndex(NETWORK_TYPE_BITMASK); |
| 2033 | if (columnIndex != -1) { |
| 2034 | getStringValueFromCursor(cv, c, NETWORK_TYPE_BITMASK); |
| 2035 | // Map NETWORK_TYPE_BITMASK to BEARER_BITMASK if NETWORK_TYPE_BITMASK existed; |
| 2036 | String fromCursor = c.getString(columnIndex); |
| 2037 | if (!TextUtils.isEmpty(fromCursor) && fromCursor.matches("\\d+")) { |
| 2038 | int networkBitmask = Integer.valueOf(fromCursor); |
SongFerngWang | 64fb3dd | 2019-12-02 20:59:47 +0800 | [diff] [blame] | 2039 | int bearerBitmask = convertNetworkTypeBitmaskToBearerBitmask(networkBitmask); |
Cassie | a58ce71 | 2017-12-06 16:21:50 -0800 | [diff] [blame] | 2040 | cv.put(BEARER_BITMASK, String.valueOf(bearerBitmask)); |
| 2041 | } |
| 2042 | return; |
| 2043 | } |
| 2044 | columnIndex = c.getColumnIndex(BEARER_BITMASK); |
| 2045 | if (columnIndex != -1) { |
| 2046 | String fromCursor = c.getString(columnIndex); |
| 2047 | if (!TextUtils.isEmpty(fromCursor) && fromCursor.matches("\\d+")) { |
| 2048 | int bearerBitmask = Integer.valueOf(fromCursor); |
SongFerngWang | 64fb3dd | 2019-12-02 20:59:47 +0800 | [diff] [blame] | 2049 | int networkBitmask = convertBearerBitmaskToNetworkTypeBitmask(bearerBitmask); |
Cassie | a58ce71 | 2017-12-06 16:21:50 -0800 | [diff] [blame] | 2050 | cv.put(NETWORK_TYPE_BITMASK, String.valueOf(networkBitmask)); |
| 2051 | } |
| 2052 | } |
| 2053 | } |
| 2054 | |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 2055 | private void getIntValueFromCursor(ContentValues cv, Cursor c, String key) { |
Amit Mahajan | 4768823 | 2017-04-09 16:08:19 -0700 | [diff] [blame] | 2056 | int columnIndex = c.getColumnIndex(key); |
| 2057 | if (columnIndex != -1) { |
| 2058 | String fromCursor = c.getString(columnIndex); |
| 2059 | if (!TextUtils.isEmpty(fromCursor)) { |
| 2060 | try { |
| 2061 | cv.put(key, new Integer(fromCursor)); |
| 2062 | } catch (NumberFormatException nfe) { |
| 2063 | // do nothing |
| 2064 | } |
Amit Mahajan | 24223db | 2015-04-21 14:22:40 -0700 | [diff] [blame] | 2065 | } |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 2066 | } |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 2067 | } |
| 2068 | |
yinxu | 3d98b6c | 2018-01-05 16:27:30 -0800 | [diff] [blame] | 2069 | private void getBlobValueFromCursor(ContentValues cv, Cursor c, String key) { |
| 2070 | int columnIndex = c.getColumnIndex(key); |
| 2071 | if (columnIndex != -1) { |
| 2072 | byte[] fromCursor = c.getBlob(columnIndex); |
| 2073 | if (fromCursor != null) { |
| 2074 | cv.put(key, fromCursor); |
| 2075 | } |
| 2076 | } |
| 2077 | } |
| 2078 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 2079 | /** |
| 2080 | * Gets the next row of apn values. |
| 2081 | * |
| 2082 | * @param parser the parser |
| 2083 | * @return the row or null if it's not an apn |
| 2084 | */ |
| 2085 | private ContentValues getRow(XmlPullParser parser) { |
| 2086 | if (!"apn".equals(parser.getName())) { |
| 2087 | return null; |
| 2088 | } |
| 2089 | |
| 2090 | ContentValues map = new ContentValues(); |
| 2091 | |
| 2092 | String mcc = parser.getAttributeValue(null, "mcc"); |
| 2093 | String mnc = parser.getAttributeValue(null, "mnc"); |
| 2094 | String numeric = mcc + mnc; |
| 2095 | |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 2096 | map.put(NUMERIC, numeric); |
| 2097 | map.put(MCC, mcc); |
| 2098 | map.put(MNC, mnc); |
| 2099 | map.put(NAME, parser.getAttributeValue(null, "carrier")); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 2100 | |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 2101 | // do not add NULL to the map so that default values can be inserted in db |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 2102 | addStringAttribute(parser, "apn", map, APN); |
| 2103 | addStringAttribute(parser, "user", map, USER); |
| 2104 | addStringAttribute(parser, "server", map, SERVER); |
| 2105 | addStringAttribute(parser, "password", map, PASSWORD); |
| 2106 | addStringAttribute(parser, "proxy", map, PROXY); |
| 2107 | addStringAttribute(parser, "port", map, PORT); |
| 2108 | addStringAttribute(parser, "mmsproxy", map, MMSPROXY); |
| 2109 | addStringAttribute(parser, "mmsport", map, MMSPORT); |
| 2110 | addStringAttribute(parser, "mmsc", map, MMSC); |
Naveen Kalla | 14154db | 2016-12-05 16:07:03 -0800 | [diff] [blame] | 2111 | |
| 2112 | String apnType = parser.getAttributeValue(null, "type"); |
| 2113 | if (apnType != null) { |
| 2114 | // Remove spaces before putting it in the map. |
| 2115 | apnType = apnType.replaceAll("\\s+", ""); |
| 2116 | map.put(TYPE, apnType); |
| 2117 | } |
| 2118 | |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 2119 | addStringAttribute(parser, "protocol", map, PROTOCOL); |
| 2120 | addStringAttribute(parser, "roaming_protocol", map, ROAMING_PROTOCOL); |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 2121 | |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 2122 | addIntAttribute(parser, "authtype", map, AUTH_TYPE); |
| 2123 | addIntAttribute(parser, "bearer", map, BEARER); |
| 2124 | addIntAttribute(parser, "profile_id", map, PROFILE_ID); |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 2125 | addIntAttribute(parser, "max_conns", map, MAX_CONNECTIONS); |
| 2126 | addIntAttribute(parser, "wait_time", map, WAIT_TIME_RETRY); |
| 2127 | addIntAttribute(parser, "max_conns_time", map, TIME_LIMIT_FOR_MAX_CONNECTIONS); |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 2128 | addIntAttribute(parser, "mtu", map, MTU); |
Jordan Liu | 92da8c8 | 2018-04-10 16:00:06 -0700 | [diff] [blame] | 2129 | addIntAttribute(parser, "apn_set_id", map, APN_SET_ID); |
calvinpan | f83cb47 | 2018-12-20 16:31:02 +0800 | [diff] [blame] | 2130 | addIntAttribute(parser, "carrier_id", map, CARRIER_ID); |
Yuuki Habu | 95aacb1 | 2019-02-22 10:49:06 +0900 | [diff] [blame] | 2131 | addIntAttribute(parser, "skip_464xlat", map, SKIP_464XLAT); |
Amit Mahajan | da60721 | 2015-10-08 09:13:00 -0700 | [diff] [blame] | 2132 | |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 2133 | addBoolAttribute(parser, "carrier_enabled", map, CARRIER_ENABLED); |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 2134 | addBoolAttribute(parser, "modem_cognitive", map, MODEM_PERSIST); |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 2135 | addBoolAttribute(parser, "user_visible", map, USER_VISIBLE); |
Amit Mahajan | 460d703 | 2017-07-17 14:42:33 -0700 | [diff] [blame] | 2136 | addBoolAttribute(parser, "user_editable", map, USER_EDITABLE); |
Sungmin Choi | 27045ef | 2013-01-25 17:48:06 +0900 | [diff] [blame] | 2137 | |
Cassie | a58ce71 | 2017-12-06 16:21:50 -0800 | [diff] [blame] | 2138 | int networkTypeBitmask = 0; |
| 2139 | String networkTypeList = parser.getAttributeValue(null, "network_type_bitmask"); |
| 2140 | if (networkTypeList != null) { |
SongFerngWang | 64fb3dd | 2019-12-02 20:59:47 +0800 | [diff] [blame] | 2141 | networkTypeBitmask = getBitmaskFromString(networkTypeList); |
Cassie | a58ce71 | 2017-12-06 16:21:50 -0800 | [diff] [blame] | 2142 | } |
| 2143 | map.put(NETWORK_TYPE_BITMASK, networkTypeBitmask); |
| 2144 | |
Amit Mahajan | ed3e747 | 2016-04-13 17:46:42 -0700 | [diff] [blame] | 2145 | int bearerBitmask = 0; |
Cassie | a58ce71 | 2017-12-06 16:21:50 -0800 | [diff] [blame] | 2146 | if (networkTypeList != null) { |
SongFerngWang | 64fb3dd | 2019-12-02 20:59:47 +0800 | [diff] [blame] | 2147 | bearerBitmask = convertNetworkTypeBitmaskToBearerBitmask(networkTypeBitmask); |
Cassie | a58ce71 | 2017-12-06 16:21:50 -0800 | [diff] [blame] | 2148 | } else { |
| 2149 | String bearerList = parser.getAttributeValue(null, "bearer_bitmask"); |
| 2150 | if (bearerList != null) { |
SongFerngWang | 64fb3dd | 2019-12-02 20:59:47 +0800 | [diff] [blame] | 2151 | bearerBitmask = getBitmaskFromString(bearerList); |
Cassie | a58ce71 | 2017-12-06 16:21:50 -0800 | [diff] [blame] | 2152 | } |
| 2153 | // Update the network type bitmask to keep them sync. |
SongFerngWang | 64fb3dd | 2019-12-02 20:59:47 +0800 | [diff] [blame] | 2154 | networkTypeBitmask = convertBearerBitmaskToNetworkTypeBitmask(bearerBitmask); |
Mengjun Leng | 374ce6d | 2019-04-22 13:59:59 +0800 | [diff] [blame] | 2155 | // Legacy bearer is deprecated, in order to be compatible with bearer_bitmask till |
| 2156 | // both are removed (bearer_bitmask is marked as deprecated now), just appends |
| 2157 | // bearer into bearer_bitmask only. |
| 2158 | // Use the constant string BEARER instead of the "bearer" by hard code. |
| 2159 | final String apnBearer = parser.getAttributeValue(null, BEARER); |
| 2160 | if (apnBearer != null) { |
| 2161 | final int legacyBearerBitmask = |
Steven Laver | 915f556 | 2020-01-17 18:07:46 -0800 | [diff] [blame] | 2162 | getBitmaskForTech(Integer.parseInt(apnBearer)); |
| 2163 | networkTypeBitmask |= |
| 2164 | convertBearerBitmaskToNetworkTypeBitmask(legacyBearerBitmask); |
Mengjun Leng | 374ce6d | 2019-04-22 13:59:59 +0800 | [diff] [blame] | 2165 | } |
Cassie | a58ce71 | 2017-12-06 16:21:50 -0800 | [diff] [blame] | 2166 | map.put(NETWORK_TYPE_BITMASK, networkTypeBitmask); |
Amit Mahajan | b80f733 | 2015-04-16 10:02:52 -0700 | [diff] [blame] | 2167 | } |
Amit Mahajan | ed3e747 | 2016-04-13 17:46:42 -0700 | [diff] [blame] | 2168 | map.put(BEARER_BITMASK, bearerBitmask); |
Amit Mahajan | b80f733 | 2015-04-16 10:02:52 -0700 | [diff] [blame] | 2169 | |
Sungmin Choi | 27045ef | 2013-01-25 17:48:06 +0900 | [diff] [blame] | 2170 | String mvno_type = parser.getAttributeValue(null, "mvno_type"); |
| 2171 | if (mvno_type != null) { |
| 2172 | String mvno_match_data = parser.getAttributeValue(null, "mvno_match_data"); |
| 2173 | if (mvno_match_data != null) { |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 2174 | map.put(MVNO_TYPE, mvno_type); |
| 2175 | map.put(MVNO_MATCH_DATA, mvno_match_data); |
Sungmin Choi | 27045ef | 2013-01-25 17:48:06 +0900 | [diff] [blame] | 2176 | } |
| 2177 | } |
Amit Mahajan | b068886 | 2014-08-13 16:53:51 +0000 | [diff] [blame] | 2178 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 2179 | return map; |
| 2180 | } |
| 2181 | |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 2182 | private void addStringAttribute(XmlPullParser parser, String att, |
| 2183 | ContentValues map, String key) { |
| 2184 | String val = parser.getAttributeValue(null, att); |
| 2185 | if (val != null) { |
| 2186 | map.put(key, val); |
| 2187 | } |
| 2188 | } |
| 2189 | |
| 2190 | private void addIntAttribute(XmlPullParser parser, String att, |
| 2191 | ContentValues map, String key) { |
| 2192 | String val = parser.getAttributeValue(null, att); |
| 2193 | if (val != null) { |
| 2194 | map.put(key, Integer.parseInt(val)); |
| 2195 | } |
| 2196 | } |
| 2197 | |
| 2198 | private void addBoolAttribute(XmlPullParser parser, String att, |
| 2199 | ContentValues map, String key) { |
| 2200 | String val = parser.getAttributeValue(null, att); |
| 2201 | if (val != null) { |
| 2202 | map.put(key, Boolean.parseBoolean(val)); |
| 2203 | } |
| 2204 | } |
| 2205 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 2206 | /* |
| 2207 | * Loads apns from xml file into the database |
| 2208 | * |
| 2209 | * @param db the sqlite database to write to |
| 2210 | * @param parser the xml parser |
| 2211 | * |
| 2212 | */ |
| 2213 | private void loadApns(SQLiteDatabase db, XmlPullParser parser) { |
| 2214 | if (parser != null) { |
| 2215 | try { |
jewon.lee | 4167fcc | 2013-01-17 13:10:37 +0900 | [diff] [blame] | 2216 | db.beginTransaction(); |
Hyejin Kim | 7e7c274 | 2013-02-11 20:02:18 +0900 | [diff] [blame] | 2217 | XmlUtils.nextElement(parser); |
| 2218 | while (parser.getEventType() != XmlPullParser.END_DOCUMENT) { |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 2219 | ContentValues row = getRow(parser); |
Hyejin Kim | 7e7c274 | 2013-02-11 20:02:18 +0900 | [diff] [blame] | 2220 | if (row == null) { |
| 2221 | throw new XmlPullParserException("Expected 'apn' tag", parser, null); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 2222 | } |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 2223 | insertAddingDefaults(db, row); |
Hyejin Kim | 7e7c274 | 2013-02-11 20:02:18 +0900 | [diff] [blame] | 2224 | XmlUtils.nextElement(parser); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 2225 | } |
jewon.lee | 4167fcc | 2013-01-17 13:10:37 +0900 | [diff] [blame] | 2226 | db.setTransactionSuccessful(); |
Hyejin Kim | 7e7c274 | 2013-02-11 20:02:18 +0900 | [diff] [blame] | 2227 | } catch (XmlPullParserException e) { |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 2228 | loge("Got XmlPullParserException while loading apns." + e); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 2229 | } catch (IOException e) { |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 2230 | loge("Got IOException while loading apns." + e); |
Hyejin Kim | 7e7c274 | 2013-02-11 20:02:18 +0900 | [diff] [blame] | 2231 | } catch (SQLException e) { |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 2232 | loge("Got SQLException while loading apns." + e); |
jewon.lee | 4167fcc | 2013-01-17 13:10:37 +0900 | [diff] [blame] | 2233 | } finally { |
| 2234 | db.endTransaction(); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 2235 | } |
| 2236 | } |
| 2237 | } |
Jaikumar Ganesh | 8e1a4f9 | 2009-10-26 13:07:37 -0700 | [diff] [blame] | 2238 | |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 2239 | private void insertAddingDefaults(SQLiteDatabase db, ContentValues row) { |
Amit Mahajan | b068886 | 2014-08-13 16:53:51 +0000 | [diff] [blame] | 2240 | row = setDefaultValue(row); |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 2241 | try { |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 2242 | db.insertWithOnConflict(CARRIERS_TABLE, null, row, SQLiteDatabase.CONFLICT_ABORT); |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 2243 | if (VDBG) log("dbh.insertAddingDefaults: db.insert returned >= 0; insert " + |
| 2244 | "successful for cv " + row); |
| 2245 | } catch (SQLException e) { |
| 2246 | if (VDBG) log("dbh.insertAddingDefaults: exception " + e); |
| 2247 | // Insertion failed which could be due to a conflict. Check if that is the case and |
Amit Mahajan | b80f733 | 2015-04-16 10:02:52 -0700 | [diff] [blame] | 2248 | // update edited field accordingly. |
| 2249 | // Search for the exact same entry and update edited field. |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 2250 | // If it is USER_EDITED/CARRIER_EDITED change it to UNEDITED, |
| 2251 | // and if USER/CARRIER_DELETED change it to USER/CARRIER_DELETED_BUT_PRESENT_IN_XML. |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 2252 | Cursor oldRow = selectConflictingRow(db, CARRIERS_TABLE, row); |
| 2253 | if (oldRow != null) { |
| 2254 | // Update the row |
| 2255 | ContentValues mergedValues = new ContentValues(); |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 2256 | int edited = oldRow.getInt(oldRow.getColumnIndex(EDITED_STATUS)); |
Amit Mahajan | b80f733 | 2015-04-16 10:02:52 -0700 | [diff] [blame] | 2257 | int old_edited = edited; |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 2258 | if (edited != UNEDITED) { |
| 2259 | if (edited == USER_DELETED) { |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 2260 | // USER_DELETED_BUT_PRESENT_IN_XML indicates entry has been deleted |
| 2261 | // by user but present in apn xml file. |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 2262 | edited = USER_DELETED_BUT_PRESENT_IN_XML; |
| 2263 | } else if (edited == CARRIER_DELETED) { |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 2264 | // CARRIER_DELETED_BUT_PRESENT_IN_XML indicates entry has been deleted |
| 2265 | // by user but present in apn xml file. |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 2266 | edited = CARRIER_DELETED_BUT_PRESENT_IN_XML; |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 2267 | } |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 2268 | mergedValues.put(EDITED_STATUS, edited); |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 2269 | } |
| 2270 | |
Amit Mahajan | b80f733 | 2015-04-16 10:02:52 -0700 | [diff] [blame] | 2271 | mergeFieldsAndUpdateDb(db, CARRIERS_TABLE, oldRow, row, mergedValues, false, |
| 2272 | mContext); |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 2273 | |
Amit Mahajan | b80f733 | 2015-04-16 10:02:52 -0700 | [diff] [blame] | 2274 | if (VDBG) log("dbh.insertAddingDefaults: old edited = " + old_edited |
| 2275 | + " new edited = " + edited); |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 2276 | |
| 2277 | oldRow.close(); |
| 2278 | } |
| 2279 | } |
| 2280 | } |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 2281 | } |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 2282 | |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 2283 | public static void mergeFieldsAndUpdateDb(SQLiteDatabase db, String table, Cursor oldRow, |
| 2284 | ContentValues newRow, ContentValues mergedValues, |
| 2285 | boolean onUpgrade, Context context) { |
| 2286 | if (newRow.containsKey(TYPE)) { |
| 2287 | // Merge the types |
| 2288 | String oldType = oldRow.getString(oldRow.getColumnIndex(TYPE)); |
| 2289 | String newType = newRow.getAsString(TYPE); |
Amit Mahajan | b80f733 | 2015-04-16 10:02:52 -0700 | [diff] [blame] | 2290 | |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 2291 | if (!oldType.equalsIgnoreCase(newType)) { |
| 2292 | if (oldType.equals("") || newType.equals("")) { |
| 2293 | newRow.put(TYPE, ""); |
| 2294 | } else { |
| 2295 | String[] oldTypes = oldType.toLowerCase().split(","); |
| 2296 | String[] newTypes = newType.toLowerCase().split(","); |
Amit Mahajan | b80f733 | 2015-04-16 10:02:52 -0700 | [diff] [blame] | 2297 | |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 2298 | if (VDBG) { |
| 2299 | log("mergeFieldsAndUpdateDb: Calling separateRowsNeeded() oldType=" + |
| 2300 | oldType + " old bearer=" + oldRow.getInt(oldRow.getColumnIndex( |
| 2301 | BEARER_BITMASK)) + " old networkType=" + |
| 2302 | oldRow.getInt(oldRow.getColumnIndex(NETWORK_TYPE_BITMASK)) + |
| 2303 | " old profile_id=" + oldRow.getInt(oldRow.getColumnIndex( |
| 2304 | PROFILE_ID)) + " newRow " + newRow); |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 2305 | } |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 2306 | |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 2307 | // If separate rows are needed, do not need to merge any further |
| 2308 | if (separateRowsNeeded(db, table, oldRow, newRow, context, oldTypes, |
| 2309 | newTypes)) { |
| 2310 | if (VDBG) log("mergeFieldsAndUpdateDb: separateRowsNeeded() returned " + |
| 2311 | "true"); |
| 2312 | return; |
Amit Mahajan | b80f733 | 2015-04-16 10:02:52 -0700 | [diff] [blame] | 2313 | } |
Amit Mahajan | b80f733 | 2015-04-16 10:02:52 -0700 | [diff] [blame] | 2314 | |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 2315 | // Merge the 2 types |
| 2316 | ArrayList<String> mergedTypes = new ArrayList<String>(); |
| 2317 | mergedTypes.addAll(Arrays.asList(oldTypes)); |
| 2318 | for (String s : newTypes) { |
| 2319 | if (!mergedTypes.contains(s.trim())) { |
| 2320 | mergedTypes.add(s); |
| 2321 | } |
Cassie | a58ce71 | 2017-12-06 16:21:50 -0800 | [diff] [blame] | 2322 | } |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 2323 | StringBuilder mergedType = new StringBuilder(); |
| 2324 | for (int i = 0; i < mergedTypes.size(); i++) { |
| 2325 | mergedType.append((i == 0 ? "" : ",") + mergedTypes.get(i)); |
Jordan Liu | 31b99ad | 2018-01-08 13:38:38 -0800 | [diff] [blame] | 2326 | } |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 2327 | newRow.put(TYPE, mergedType.toString()); |
Jordan Liu | 31b99ad | 2018-01-08 13:38:38 -0800 | [diff] [blame] | 2328 | } |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 2329 | } |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 2330 | mergedValues.put(TYPE, newRow.getAsString(TYPE)); |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 2331 | } |
| 2332 | |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 2333 | if (newRow.containsKey(BEARER_BITMASK)) { |
| 2334 | int oldBearer = oldRow.getInt(oldRow.getColumnIndex(BEARER_BITMASK)); |
| 2335 | int newBearer = newRow.getAsInteger(BEARER_BITMASK); |
| 2336 | if (oldBearer != newBearer) { |
| 2337 | if (oldBearer == 0 || newBearer == 0) { |
| 2338 | newRow.put(BEARER_BITMASK, 0); |
| 2339 | } else { |
| 2340 | newRow.put(BEARER_BITMASK, (oldBearer | newBearer)); |
Amit Mahajan | b80f733 | 2015-04-16 10:02:52 -0700 | [diff] [blame] | 2341 | } |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 2342 | } |
| 2343 | mergedValues.put(BEARER_BITMASK, newRow.getAsInteger(BEARER_BITMASK)); |
| 2344 | } |
| 2345 | |
| 2346 | if (newRow.containsKey(NETWORK_TYPE_BITMASK)) { |
| 2347 | int oldBitmask = oldRow.getInt(oldRow.getColumnIndex(NETWORK_TYPE_BITMASK)); |
| 2348 | int newBitmask = newRow.getAsInteger(NETWORK_TYPE_BITMASK); |
| 2349 | if (oldBitmask != newBitmask) { |
| 2350 | if (oldBitmask == 0 || newBitmask == 0) { |
| 2351 | newRow.put(NETWORK_TYPE_BITMASK, 0); |
| 2352 | } else { |
| 2353 | newRow.put(NETWORK_TYPE_BITMASK, (oldBitmask | newBitmask)); |
| 2354 | } |
| 2355 | } |
| 2356 | mergedValues.put(NETWORK_TYPE_BITMASK, newRow.getAsInteger(NETWORK_TYPE_BITMASK)); |
| 2357 | } |
| 2358 | |
| 2359 | if (newRow.containsKey(BEARER_BITMASK) |
| 2360 | && newRow.containsKey(NETWORK_TYPE_BITMASK)) { |
| 2361 | syncBearerBitmaskAndNetworkTypeBitmask(mergedValues); |
| 2362 | } |
| 2363 | |
| 2364 | if (!onUpgrade) { |
| 2365 | // Do not overwrite a carrier or user edit with EDITED=UNEDITED |
| 2366 | if (newRow.containsKey(EDITED_STATUS)) { |
| 2367 | int oldEdited = oldRow.getInt(oldRow.getColumnIndex(EDITED_STATUS)); |
| 2368 | int newEdited = newRow.getAsInteger(EDITED_STATUS); |
| 2369 | if (newEdited == UNEDITED && (oldEdited == CARRIER_EDITED |
| 2370 | || oldEdited == CARRIER_DELETED |
| 2371 | || oldEdited == CARRIER_DELETED_BUT_PRESENT_IN_XML |
| 2372 | || oldEdited == USER_EDITED |
| 2373 | || oldEdited == USER_DELETED |
| 2374 | || oldEdited == USER_DELETED_BUT_PRESENT_IN_XML)) { |
| 2375 | newRow.remove(EDITED_STATUS); |
| 2376 | } |
| 2377 | } |
| 2378 | mergedValues.putAll(newRow); |
| 2379 | } |
| 2380 | |
| 2381 | if (mergedValues.size() > 0) { |
| 2382 | db.update(table, mergedValues, "_id=" + oldRow.getInt(oldRow.getColumnIndex("_id")), |
| 2383 | null); |
| 2384 | } |
| 2385 | } |
| 2386 | |
| 2387 | private static boolean separateRowsNeeded(SQLiteDatabase db, String table, Cursor oldRow, |
| 2388 | ContentValues newRow, Context context, |
| 2389 | String[] oldTypes, String[] newTypes) { |
| 2390 | // If this APN falls under persist_apns_for_plmn, and the |
| 2391 | // only difference between old type and new type is that one has dun, and |
| 2392 | // the APNs have profile_id 0 or not set, then set the profile_id to 1 for |
| 2393 | // the dun APN/remove dun from type. This will ensure both oldRow and newRow exist |
| 2394 | // separately in db. |
| 2395 | |
| 2396 | boolean match = false; |
| 2397 | |
| 2398 | // Check if APN falls under persist_apns_for_plmn |
| 2399 | if (context.getResources() != null) { |
| 2400 | String[] persistApnsForPlmns = context.getResources().getStringArray( |
| 2401 | R.array.persist_apns_for_plmn); |
| 2402 | for (String s : persistApnsForPlmns) { |
| 2403 | if (s.equalsIgnoreCase(newRow.getAsString(NUMERIC))) { |
| 2404 | match = true; |
| 2405 | break; |
| 2406 | } |
| 2407 | } |
| 2408 | } else { |
| 2409 | loge("separateRowsNeeded: resources=null"); |
| 2410 | } |
| 2411 | |
| 2412 | if (!match) return false; |
| 2413 | |
| 2414 | // APN falls under persist_apns_for_plmn |
| 2415 | // Check if only difference between old type and new type is that |
| 2416 | // one has dun |
| 2417 | ArrayList<String> oldTypesAl = new ArrayList<String>(Arrays.asList(oldTypes)); |
| 2418 | ArrayList<String> newTypesAl = new ArrayList<String>(Arrays.asList(newTypes)); |
| 2419 | ArrayList<String> listWithDun = null; |
| 2420 | ArrayList<String> listWithoutDun = null; |
| 2421 | boolean dunInOld = false; |
| 2422 | if (oldTypesAl.size() == newTypesAl.size() + 1) { |
| 2423 | listWithDun = oldTypesAl; |
| 2424 | listWithoutDun = newTypesAl; |
| 2425 | dunInOld = true; |
| 2426 | } else if (oldTypesAl.size() + 1 == newTypesAl.size()) { |
| 2427 | listWithDun = newTypesAl; |
| 2428 | listWithoutDun = oldTypesAl; |
| 2429 | } else { |
| 2430 | return false; |
| 2431 | } |
| 2432 | |
| 2433 | if (listWithDun.contains("dun") && !listWithoutDun.contains("dun")) { |
| 2434 | listWithoutDun.add("dun"); |
| 2435 | if (!listWithDun.containsAll(listWithoutDun)) { |
| 2436 | return false; |
Amit Mahajan | b80f733 | 2015-04-16 10:02:52 -0700 | [diff] [blame] | 2437 | } |
| 2438 | |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 2439 | // Only difference between old type and new type is that |
Amit Mahajan | b80f733 | 2015-04-16 10:02:52 -0700 | [diff] [blame] | 2440 | // one has dun |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 2441 | // Check if profile_id is 0/not set |
| 2442 | if (oldRow.getInt(oldRow.getColumnIndex(PROFILE_ID)) == 0) { |
| 2443 | if (dunInOld) { |
| 2444 | // Update oldRow to remove dun from its type field |
| 2445 | ContentValues updateOldRow = new ContentValues(); |
| 2446 | StringBuilder sb = new StringBuilder(); |
| 2447 | boolean first = true; |
| 2448 | for (String s : listWithDun) { |
| 2449 | if (!s.equalsIgnoreCase("dun")) { |
| 2450 | sb.append(first ? s : "," + s); |
| 2451 | first = false; |
| 2452 | } |
| 2453 | } |
| 2454 | String updatedType = sb.toString(); |
| 2455 | if (VDBG) { |
| 2456 | log("separateRowsNeeded: updating type in oldRow to " + updatedType); |
| 2457 | } |
| 2458 | updateOldRow.put(TYPE, updatedType); |
| 2459 | db.update(table, updateOldRow, |
| 2460 | "_id=" + oldRow.getInt(oldRow.getColumnIndex("_id")), null); |
| 2461 | return true; |
| 2462 | } else { |
| 2463 | if (VDBG) log("separateRowsNeeded: adding profile id 1 to newRow"); |
| 2464 | // Update newRow to set profile_id to 1 |
| 2465 | newRow.put(PROFILE_ID, new Integer(1)); |
| 2466 | } |
Amit Mahajan | b80f733 | 2015-04-16 10:02:52 -0700 | [diff] [blame] | 2467 | } else { |
| 2468 | return false; |
| 2469 | } |
| 2470 | |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 2471 | // If match was found, both oldRow and newRow need to exist |
| 2472 | // separately in db. Add newRow to db. |
| 2473 | try { |
| 2474 | db.insertWithOnConflict(table, null, newRow, SQLiteDatabase.CONFLICT_REPLACE); |
| 2475 | if (VDBG) log("separateRowsNeeded: added newRow with profile id 1 to db"); |
| 2476 | return true; |
| 2477 | } catch (SQLException e) { |
| 2478 | loge("Exception on trying to add new row after updating profile_id"); |
Amit Mahajan | b80f733 | 2015-04-16 10:02:52 -0700 | [diff] [blame] | 2479 | } |
Amit Mahajan | b80f733 | 2015-04-16 10:02:52 -0700 | [diff] [blame] | 2480 | } |
| 2481 | |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 2482 | return false; |
| 2483 | } |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 2484 | |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 2485 | public static Cursor selectConflictingRow(SQLiteDatabase db, String table, |
| 2486 | ContentValues row) { |
| 2487 | // Conflict is possible only when numeric, mcc, mnc (fields without any default value) |
| 2488 | // are set in the new row |
| 2489 | if (!row.containsKey(NUMERIC) || !row.containsKey(MCC) || !row.containsKey(MNC)) { |
| 2490 | loge("dbh.selectConflictingRow: called for non-conflicting row: " + row); |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 2491 | return null; |
Jaikumar Ganesh | 8e1a4f9 | 2009-10-26 13:07:37 -0700 | [diff] [blame] | 2492 | } |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 2493 | |
| 2494 | String[] columns = { "_id", |
| 2495 | TYPE, |
| 2496 | EDITED_STATUS, |
| 2497 | BEARER_BITMASK, |
| 2498 | NETWORK_TYPE_BITMASK, |
| 2499 | PROFILE_ID }; |
| 2500 | String selection = TextUtils.join("=? AND ", CARRIERS_UNIQUE_FIELDS) + "=?"; |
| 2501 | int i = 0; |
| 2502 | String[] selectionArgs = new String[CARRIERS_UNIQUE_FIELDS.size()]; |
| 2503 | for (String field : CARRIERS_UNIQUE_FIELDS) { |
| 2504 | if (!row.containsKey(field)) { |
| 2505 | selectionArgs[i++] = CARRIERS_UNIQUE_FIELDS_DEFAULTS.get(field); |
| 2506 | } else { |
| 2507 | if (CARRIERS_BOOLEAN_FIELDS.contains(field)) { |
| 2508 | // for boolean fields we overwrite the strings "true" and "false" with "1" |
| 2509 | // and "0" |
| 2510 | selectionArgs[i++] = convertStringToIntString(row.getAsString(field)); |
| 2511 | } else { |
| 2512 | selectionArgs[i++] = row.getAsString(field); |
| 2513 | } |
| 2514 | } |
| 2515 | } |
| 2516 | |
| 2517 | Cursor c = db.query(table, columns, selection, selectionArgs, null, null, null); |
| 2518 | |
| 2519 | if (c != null) { |
| 2520 | if (c.getCount() == 1) { |
| 2521 | if (VDBG) log("dbh.selectConflictingRow: " + c.getCount() + " conflicting " + |
| 2522 | "row found"); |
| 2523 | if (c.moveToFirst()) { |
| 2524 | return c; |
| 2525 | } else { |
| 2526 | loge("dbh.selectConflictingRow: moveToFirst() failed"); |
| 2527 | } |
| 2528 | } else { |
| 2529 | loge("dbh.selectConflictingRow: Expected 1 but found " + c.getCount() + |
| 2530 | " matching rows found for cv " + row); |
| 2531 | } |
| 2532 | c.close(); |
| 2533 | } else { |
| 2534 | loge("dbh.selectConflictingRow: Error - c is null; no matching row found for " + |
| 2535 | "cv " + row); |
| 2536 | } |
| 2537 | |
| 2538 | return null; |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 2539 | } |
| 2540 | |
Jordan Liu | e6f0bce | 2016-09-21 18:31:43 -0700 | [diff] [blame] | 2541 | /** |
Jordan Liu | 8b78f71 | 2018-05-21 11:10:48 -0700 | [diff] [blame] | 2542 | * Convert "true" and "false" to "1" and "0". |
| 2543 | * If the passed in string is already "1" or "0" returns the passed in string. |
| 2544 | */ |
| 2545 | private static String convertStringToIntString(String boolString) { |
| 2546 | if ("0".equals(boolString) || "false".equalsIgnoreCase(boolString)) return "0"; |
| 2547 | return "1"; |
| 2548 | } |
| 2549 | |
| 2550 | /** |
| 2551 | * Convert "1" and "0" to "true" and "false". |
| 2552 | * If the passed in string is already "true" or "false" returns the passed in string. |
| 2553 | */ |
| 2554 | private static String convertStringToBoolString(String intString) { |
| 2555 | if ("0".equals(intString) || "false".equalsIgnoreCase(intString)) return "false"; |
| 2556 | return "true"; |
| 2557 | } |
| 2558 | |
| 2559 | /** |
Jordan Liu | e6f0bce | 2016-09-21 18:31:43 -0700 | [diff] [blame] | 2560 | * These methods can be overridden in a subclass for testing TelephonyProvider using an |
| 2561 | * in-memory database. |
| 2562 | */ |
| 2563 | SQLiteDatabase getReadableDatabase() { |
| 2564 | return mOpenHelper.getReadableDatabase(); |
| 2565 | } |
| 2566 | SQLiteDatabase getWritableDatabase() { |
| 2567 | return mOpenHelper.getWritableDatabase(); |
| 2568 | } |
| 2569 | void initDatabaseWithDatabaseHelper(SQLiteDatabase db) { |
| 2570 | mOpenHelper.initDatabase(db); |
| 2571 | } |
| 2572 | boolean needApnDbUpdate() { |
| 2573 | return mOpenHelper.apnDbUpdateNeeded(); |
| 2574 | } |
| 2575 | |
Jordan Liu | 3de76f8 | 2017-05-15 15:21:01 -0700 | [diff] [blame] | 2576 | private static boolean apnSourceServiceExists(Context context) { |
| 2577 | if (s_apnSourceServiceExists != null) { |
| 2578 | return s_apnSourceServiceExists; |
| 2579 | } |
| 2580 | try { |
| 2581 | String service = context.getResources().getString(R.string.apn_source_service); |
| 2582 | if (TextUtils.isEmpty(service)) { |
| 2583 | s_apnSourceServiceExists = false; |
| 2584 | } else { |
| 2585 | s_apnSourceServiceExists = context.getPackageManager().getServiceInfo( |
| 2586 | ComponentName.unflattenFromString(service), 0) |
| 2587 | != null; |
| 2588 | } |
| 2589 | } catch (PackageManager.NameNotFoundException e) { |
| 2590 | s_apnSourceServiceExists = false; |
| 2591 | } |
| 2592 | return s_apnSourceServiceExists; |
| 2593 | } |
| 2594 | |
Jordan Liu | 11c113e | 2018-11-13 12:19:11 -0800 | [diff] [blame] | 2595 | private void restoreApnsWithService(int subId) { |
Jordan Liu | 3de76f8 | 2017-05-15 15:21:01 -0700 | [diff] [blame] | 2596 | Context context = getContext(); |
| 2597 | Resources r = context.getResources(); |
James.cf Lin | 90f42ec | 2020-04-21 22:23:31 +0800 | [diff] [blame] | 2598 | AtomicBoolean connectionBindingInvalid = new AtomicBoolean(false); |
Jordan Liu | 3de76f8 | 2017-05-15 15:21:01 -0700 | [diff] [blame] | 2599 | ServiceConnection connection = new ServiceConnection() { |
| 2600 | @Override |
| 2601 | public void onServiceConnected(ComponentName className, |
| 2602 | IBinder service) { |
| 2603 | log("restoreApnsWithService: onServiceConnected"); |
| 2604 | synchronized (mLock) { |
| 2605 | mIApnSourceService = IApnSourceService.Stub.asInterface(service); |
| 2606 | mLock.notifyAll(); |
| 2607 | } |
| 2608 | } |
| 2609 | |
| 2610 | @Override |
| 2611 | public void onServiceDisconnected(ComponentName arg0) { |
| 2612 | loge("mIApnSourceService has disconnected unexpectedly"); |
| 2613 | synchronized (mLock) { |
| 2614 | mIApnSourceService = null; |
| 2615 | } |
| 2616 | } |
James.cf Lin | 90f42ec | 2020-04-21 22:23:31 +0800 | [diff] [blame] | 2617 | |
| 2618 | @Override |
| 2619 | public void onBindingDied(ComponentName name) { |
| 2620 | loge("The binding to the apn service connection is dead: " + name); |
| 2621 | synchronized (mLock) { |
| 2622 | connectionBindingInvalid.set(true); |
| 2623 | mLock.notifyAll(); |
| 2624 | } |
| 2625 | } |
| 2626 | |
| 2627 | @Override |
| 2628 | public void onNullBinding(ComponentName name) { |
| 2629 | loge("Null binding: " + name); |
| 2630 | synchronized (mLock) { |
| 2631 | connectionBindingInvalid.set(true); |
| 2632 | mLock.notifyAll(); |
| 2633 | } |
| 2634 | } |
Jordan Liu | 3de76f8 | 2017-05-15 15:21:01 -0700 | [diff] [blame] | 2635 | }; |
| 2636 | |
| 2637 | Intent intent = new Intent(IApnSourceService.class.getName()); |
| 2638 | intent.setComponent(ComponentName.unflattenFromString( |
| 2639 | r.getString(R.string.apn_source_service))); |
| 2640 | log("binding to service to restore apns, intent=" + intent); |
| 2641 | try { |
Jordan Liu | 198704f | 2018-09-19 16:34:25 -0700 | [diff] [blame] | 2642 | if (context.bindService(intent, connection, Context.BIND_IMPORTANT | |
| 2643 | Context.BIND_AUTO_CREATE)) { |
Jordan Liu | 3de76f8 | 2017-05-15 15:21:01 -0700 | [diff] [blame] | 2644 | synchronized (mLock) { |
James.cf Lin | 90f42ec | 2020-04-21 22:23:31 +0800 | [diff] [blame] | 2645 | while (mIApnSourceService == null && !connectionBindingInvalid.get()) { |
Jordan Liu | 3de76f8 | 2017-05-15 15:21:01 -0700 | [diff] [blame] | 2646 | try { |
| 2647 | mLock.wait(); |
| 2648 | } catch (InterruptedException e) { |
| 2649 | loge("Error while waiting for service connection: " + e); |
| 2650 | } |
| 2651 | } |
James.cf Lin | 90f42ec | 2020-04-21 22:23:31 +0800 | [diff] [blame] | 2652 | if (connectionBindingInvalid.get()) { |
| 2653 | loge("The binding is invalid."); |
| 2654 | return; |
| 2655 | } |
Jordan Liu | 3de76f8 | 2017-05-15 15:21:01 -0700 | [diff] [blame] | 2656 | try { |
Jordan Liu | 11c113e | 2018-11-13 12:19:11 -0800 | [diff] [blame] | 2657 | ContentValues[] values = mIApnSourceService.getApns(subId); |
Jordan Liu | 3de76f8 | 2017-05-15 15:21:01 -0700 | [diff] [blame] | 2658 | if (values != null) { |
| 2659 | // we use the unsynchronized insert because this function is called |
| 2660 | // within the syncrhonized function delete() |
| 2661 | unsynchronizedBulkInsert(CONTENT_URI, values); |
| 2662 | log("restoreApnsWithService: restored"); |
| 2663 | } |
| 2664 | } catch (RemoteException e) { |
| 2665 | loge("Error applying apns from service: " + e); |
| 2666 | } |
| 2667 | } |
| 2668 | } else { |
| 2669 | loge("unable to bind to service from intent=" + intent); |
| 2670 | } |
| 2671 | } catch (SecurityException e) { |
| 2672 | loge("Error applying apns from service: " + e); |
| 2673 | } finally { |
| 2674 | if (connection != null) { |
| 2675 | context.unbindService(connection); |
| 2676 | } |
| 2677 | synchronized (mLock) { |
| 2678 | mIApnSourceService = null; |
| 2679 | } |
| 2680 | } |
| 2681 | } |
| 2682 | |
Jordan Liu | e6f0bce | 2016-09-21 18:31:43 -0700 | [diff] [blame] | 2683 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 2684 | @Override |
| 2685 | public boolean onCreate() { |
| 2686 | mOpenHelper = new DatabaseHelper(getContext()); |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 2687 | |
Amit Mahajan | 0c1d0dd | 2020-04-21 20:38:29 +0000 | [diff] [blame] | 2688 | try { |
| 2689 | PhoneFactory.addLocalLog(TAG, 100); |
| 2690 | } catch (IllegalArgumentException e) { |
| 2691 | // ignore |
| 2692 | } |
| 2693 | |
Amit Mahajan | f5eae59 | 2019-05-22 12:27:51 -0700 | [diff] [blame] | 2694 | boolean isNewBuild = false; |
| 2695 | String newBuildId = SystemProperties.get("ro.build.id", null); |
| 2696 | if (!TextUtils.isEmpty(newBuildId)) { |
| 2697 | // Check if build id has changed |
| 2698 | SharedPreferences sp = getContext().getSharedPreferences(BUILD_ID_FILE, |
| 2699 | Context.MODE_PRIVATE); |
| 2700 | String oldBuildId = sp.getString(RO_BUILD_ID, ""); |
| 2701 | if (!newBuildId.equals(oldBuildId)) { |
| 2702 | localLog("onCreate: build id changed from " + oldBuildId + " to " + newBuildId); |
| 2703 | isNewBuild = true; |
| 2704 | } else { |
| 2705 | if (VDBG) log("onCreate: build id did not change: " + oldBuildId); |
| 2706 | } |
| 2707 | sp.edit().putString(RO_BUILD_ID, newBuildId).apply(); |
| 2708 | } else { |
| 2709 | if (VDBG) log("onCreate: newBuildId is empty"); |
| 2710 | } |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 2711 | |
Amit Mahajan | f5eae59 | 2019-05-22 12:27:51 -0700 | [diff] [blame] | 2712 | if (isNewBuild) { |
| 2713 | if (!apnSourceServiceExists(getContext())) { |
Amit Mahajan | f5eae59 | 2019-05-22 12:27:51 -0700 | [diff] [blame] | 2714 | // Update APN DB |
| 2715 | updateApnDb(); |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 2716 | } |
Amit Mahajan | f5eae59 | 2019-05-22 12:27:51 -0700 | [diff] [blame] | 2717 | |
| 2718 | // Add all APN related shared prefs to local log for dumpsys |
| 2719 | if (DBG) addAllApnSharedPrefToLocalLog(); |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 2720 | } |
| 2721 | |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 2722 | SharedPreferences sp = getContext().getSharedPreferences(ENFORCED_FILE, |
| 2723 | Context.MODE_PRIVATE); |
| 2724 | mManagedApnEnforced = sp.getBoolean(ENFORCED_KEY, false); |
| 2725 | |
Wink Saville | 6de1027 | 2014-06-22 07:38:43 -0700 | [diff] [blame] | 2726 | if (VDBG) log("onCreate:- ret true"); |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 2727 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 2728 | return true; |
| 2729 | } |
| 2730 | |
Amit Mahajan | f5eae59 | 2019-05-22 12:27:51 -0700 | [diff] [blame] | 2731 | private void addAllApnSharedPrefToLocalLog() { |
| 2732 | localLog("addAllApnSharedPrefToLocalLog"); |
| 2733 | SharedPreferences spApn = getContext().getSharedPreferences(PREF_FILE_APN, |
| 2734 | Context.MODE_PRIVATE); |
| 2735 | |
| 2736 | Map<String, ?> allPrefApnId = spApn.getAll(); |
| 2737 | for (String key : allPrefApnId.keySet()) { |
| 2738 | try { |
| 2739 | localLog(key + ":" + allPrefApnId.get(key).toString()); |
| 2740 | } catch (Exception e) { |
| 2741 | localLog("Skipping over key " + key + " due to exception " + e); |
| 2742 | } |
| 2743 | } |
| 2744 | |
| 2745 | SharedPreferences spFullApn = getContext().getSharedPreferences(PREF_FILE_FULL_APN, |
| 2746 | Context.MODE_PRIVATE); |
| 2747 | |
| 2748 | Map<String, ?> allPrefFullApn = spFullApn.getAll(); |
| 2749 | for (String key : allPrefFullApn.keySet()) { |
| 2750 | try { |
| 2751 | localLog(key + ":" + allPrefFullApn.get(key).toString()); |
| 2752 | } catch (Exception e) { |
| 2753 | localLog("Skipping over key " + key + " due to exception " + e); |
| 2754 | } |
| 2755 | } |
| 2756 | } |
| 2757 | |
| 2758 | private static void localLog(String logMsg) { |
| 2759 | Log.d(TAG, logMsg); |
Amit Mahajan | 0c1d0dd | 2020-04-21 20:38:29 +0000 | [diff] [blame] | 2760 | PhoneFactory.localLog(TAG, logMsg); |
Amit Mahajan | f5eae59 | 2019-05-22 12:27:51 -0700 | [diff] [blame] | 2761 | } |
| 2762 | |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 2763 | private synchronized boolean isManagedApnEnforced() { |
| 2764 | return mManagedApnEnforced; |
| 2765 | } |
| 2766 | |
| 2767 | private void setManagedApnEnforced(boolean enforced) { |
| 2768 | SharedPreferences sp = getContext().getSharedPreferences(ENFORCED_FILE, |
| 2769 | Context.MODE_PRIVATE); |
| 2770 | SharedPreferences.Editor editor = sp.edit(); |
| 2771 | editor.putBoolean(ENFORCED_KEY, enforced); |
| 2772 | editor.apply(); |
| 2773 | synchronized (this) { |
| 2774 | mManagedApnEnforced = enforced; |
| 2775 | } |
| 2776 | } |
| 2777 | |
Amit Mahajan | bf7144e | 2017-08-29 11:39:48 -0700 | [diff] [blame] | 2778 | private void setPreferredApnId(Long id, int subId, boolean saveApn) { |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 2779 | SharedPreferences sp = getContext().getSharedPreferences(PREF_FILE_APN, |
| 2780 | Context.MODE_PRIVATE); |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 2781 | SharedPreferences.Editor editor = sp.edit(); |
Amit Mahajan | bf7144e | 2017-08-29 11:39:48 -0700 | [diff] [blame] | 2782 | editor.putLong(COLUMN_APN_ID + subId, id != null ? id : INVALID_APN_ID); |
Amit Mahajan | f5eae59 | 2019-05-22 12:27:51 -0700 | [diff] [blame] | 2783 | localLog("setPreferredApnId: " + COLUMN_APN_ID + subId + ":" |
| 2784 | + (id != null ? id : INVALID_APN_ID)); |
Amit Mahajan | bf7144e | 2017-08-29 11:39:48 -0700 | [diff] [blame] | 2785 | // This is for debug purposes. It indicates if this APN was set by DcTracker or user (true) |
| 2786 | // or if this was restored from APN saved in PREF_FILE_FULL_APN (false). |
| 2787 | editor.putBoolean(EXPLICIT_SET_CALLED + subId, saveApn); |
Amit Mahajan | f5eae59 | 2019-05-22 12:27:51 -0700 | [diff] [blame] | 2788 | localLog("setPreferredApnId: " + EXPLICIT_SET_CALLED + subId + ":" + saveApn); |
Brad Fitzpatrick | 2227c4a | 2010-08-30 17:42:39 -0700 | [diff] [blame] | 2789 | editor.apply(); |
Amit Mahajan | 91c5dff | 2015-10-20 11:13:19 -0700 | [diff] [blame] | 2790 | if (id == null || id.longValue() == INVALID_APN_ID) { |
| 2791 | deletePreferredApn(subId); |
Amit Mahajan | bf7144e | 2017-08-29 11:39:48 -0700 | [diff] [blame] | 2792 | } else { |
| 2793 | // If id is not invalid, and saveApn is true, save the actual APN in PREF_FILE_FULL_APN |
| 2794 | // too. |
| 2795 | if (saveApn) { |
| 2796 | setPreferredApn(id, subId); |
| 2797 | } |
Amit Mahajan | 91c5dff | 2015-10-20 11:13:19 -0700 | [diff] [blame] | 2798 | } |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 2799 | } |
| 2800 | |
Amit Mahajan | 91c5dff | 2015-10-20 11:13:19 -0700 | [diff] [blame] | 2801 | private long getPreferredApnId(int subId, boolean checkApnSp) { |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 2802 | SharedPreferences sp = getContext().getSharedPreferences(PREF_FILE_APN, |
| 2803 | Context.MODE_PRIVATE); |
Amit Mahajan | 91c5dff | 2015-10-20 11:13:19 -0700 | [diff] [blame] | 2804 | long apnId = sp.getLong(COLUMN_APN_ID + subId, INVALID_APN_ID); |
| 2805 | if (apnId == INVALID_APN_ID && checkApnSp) { |
| 2806 | apnId = getPreferredApnIdFromApn(subId); |
| 2807 | if (apnId != INVALID_APN_ID) { |
Amit Mahajan | bf7144e | 2017-08-29 11:39:48 -0700 | [diff] [blame] | 2808 | setPreferredApnId(apnId, subId, false); |
Amit Mahajan | 91c5dff | 2015-10-20 11:13:19 -0700 | [diff] [blame] | 2809 | } |
| 2810 | } |
| 2811 | return apnId; |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 2812 | } |
| 2813 | |
Jordan Liu | c6078b7 | 2018-05-01 11:34:21 -0700 | [diff] [blame] | 2814 | private int getPreferredApnSetId(int subId) { |
| 2815 | SharedPreferences sp = getContext().getSharedPreferences(PREF_FILE_FULL_APN, |
| 2816 | Context.MODE_PRIVATE); |
| 2817 | try { |
| 2818 | return Integer.parseInt(sp.getString(APN_SET_ID + subId, null)); |
| 2819 | } catch (NumberFormatException e) { |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 2820 | return NO_APN_SET_ID; |
Jordan Liu | c6078b7 | 2018-05-01 11:34:21 -0700 | [diff] [blame] | 2821 | } |
| 2822 | } |
| 2823 | |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 2824 | private void deletePreferredApnId(Context context) { |
| 2825 | SharedPreferences sp = context.getSharedPreferences(PREF_FILE_APN, |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 2826 | Context.MODE_PRIVATE); |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 2827 | SharedPreferences.Editor editor = sp.edit(); |
| 2828 | editor.clear(); |
| 2829 | editor.apply(); |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 2830 | } |
| 2831 | |
Amit Mahajan | 91c5dff | 2015-10-20 11:13:19 -0700 | [diff] [blame] | 2832 | private void setPreferredApn(Long id, int subId) { |
Amit Mahajan | f5eae59 | 2019-05-22 12:27:51 -0700 | [diff] [blame] | 2833 | localLog("setPreferredApn: _id " + id + " subId " + subId); |
Jordan Liu | e6f0bce | 2016-09-21 18:31:43 -0700 | [diff] [blame] | 2834 | SQLiteDatabase db = getWritableDatabase(); |
Amit Mahajan | 91c5dff | 2015-10-20 11:13:19 -0700 | [diff] [blame] | 2835 | // query all unique fields from id |
| 2836 | String[] proj = CARRIERS_UNIQUE_FIELDS.toArray(new String[CARRIERS_UNIQUE_FIELDS.size()]); |
yuemingw | e0101b8 | 2017-12-13 21:49:09 +0000 | [diff] [blame] | 2837 | |
Amit Mahajan | 91c5dff | 2015-10-20 11:13:19 -0700 | [diff] [blame] | 2838 | Cursor c = db.query(CARRIERS_TABLE, proj, "_id=" + id, null, null, null, null); |
| 2839 | if (c != null) { |
| 2840 | if (c.getCount() == 1) { |
| 2841 | c.moveToFirst(); |
| 2842 | SharedPreferences sp = getContext().getSharedPreferences(PREF_FILE_FULL_APN, |
| 2843 | Context.MODE_PRIVATE); |
| 2844 | SharedPreferences.Editor editor = sp.edit(); |
| 2845 | // store values of all unique fields to SP |
| 2846 | for (String key : CARRIERS_UNIQUE_FIELDS) { |
| 2847 | editor.putString(key + subId, c.getString(c.getColumnIndex(key))); |
Amit Mahajan | f5eae59 | 2019-05-22 12:27:51 -0700 | [diff] [blame] | 2848 | localLog("setPreferredApn: " + key + subId + ":" |
| 2849 | + c.getString(c.getColumnIndex(key))); |
Amit Mahajan | 91c5dff | 2015-10-20 11:13:19 -0700 | [diff] [blame] | 2850 | } |
| 2851 | // also store the version number |
| 2852 | editor.putString(DB_VERSION_KEY + subId, "" + DATABASE_VERSION); |
Amit Mahajan | f5eae59 | 2019-05-22 12:27:51 -0700 | [diff] [blame] | 2853 | localLog("setPreferredApn: " + DB_VERSION_KEY + subId + ":" + DATABASE_VERSION); |
Amit Mahajan | 91c5dff | 2015-10-20 11:13:19 -0700 | [diff] [blame] | 2854 | editor.apply(); |
| 2855 | } else { |
| 2856 | log("setPreferredApn: # matching APNs found " + c.getCount()); |
| 2857 | } |
| 2858 | c.close(); |
| 2859 | } else { |
| 2860 | log("setPreferredApn: No matching APN found"); |
| 2861 | } |
| 2862 | } |
| 2863 | |
| 2864 | private long getPreferredApnIdFromApn(int subId) { |
| 2865 | log("getPreferredApnIdFromApn: for subId " + subId); |
Jordan Liu | 6500c40 | 2018-03-13 11:59:43 -0700 | [diff] [blame] | 2866 | SQLiteDatabase db = getReadableDatabase(); |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 2867 | |
| 2868 | List<String> whereList = new ArrayList<>(); |
| 2869 | List<String> whereArgsList = new ArrayList<>(); |
Amit Mahajan | 91c5dff | 2015-10-20 11:13:19 -0700 | [diff] [blame] | 2870 | SharedPreferences sp = getContext().getSharedPreferences(PREF_FILE_FULL_APN, |
| 2871 | Context.MODE_PRIVATE); |
Amit Mahajan | 91c5dff | 2015-10-20 11:13:19 -0700 | [diff] [blame] | 2872 | for (String key : CARRIERS_UNIQUE_FIELDS) { |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 2873 | String value = sp.getString(key + subId, null); |
| 2874 | if (value == null) { |
| 2875 | continue; |
| 2876 | } else { |
| 2877 | whereList.add(key); |
| 2878 | whereArgsList.add(value); |
Amit Mahajan | 91c5dff | 2015-10-20 11:13:19 -0700 | [diff] [blame] | 2879 | } |
Amit Mahajan | 91c5dff | 2015-10-20 11:13:19 -0700 | [diff] [blame] | 2880 | } |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 2881 | if (whereList.size() == 0) return INVALID_APN_ID; |
| 2882 | |
| 2883 | String where = TextUtils.join("=? and ", whereList) + "=?"; |
| 2884 | String[] whereArgs = new String[whereArgsList.size()]; |
| 2885 | whereArgs = whereArgsList.toArray(whereArgs); |
| 2886 | |
| 2887 | long apnId = INVALID_APN_ID; |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 2888 | Cursor c = db.query(CARRIERS_TABLE, new String[]{"_id"}, where, whereArgs, null, null, |
| 2889 | null); |
Amit Mahajan | 91c5dff | 2015-10-20 11:13:19 -0700 | [diff] [blame] | 2890 | if (c != null) { |
| 2891 | if (c.getCount() == 1) { |
| 2892 | c.moveToFirst(); |
| 2893 | apnId = c.getInt(c.getColumnIndex("_id")); |
| 2894 | } else { |
| 2895 | log("getPreferredApnIdFromApn: returning INVALID. # matching APNs found " + |
| 2896 | c.getCount()); |
| 2897 | } |
| 2898 | c.close(); |
| 2899 | } else { |
| 2900 | log("getPreferredApnIdFromApn: returning INVALID. No matching APN found"); |
| 2901 | } |
| 2902 | return apnId; |
| 2903 | } |
| 2904 | |
| 2905 | private void deletePreferredApn(int subId) { |
| 2906 | log("deletePreferredApn: for subId " + subId); |
| 2907 | SharedPreferences sp = getContext().getSharedPreferences(PREF_FILE_FULL_APN, |
| 2908 | Context.MODE_PRIVATE); |
| 2909 | if (sp.contains(DB_VERSION_KEY + subId)) { |
| 2910 | log("deletePreferredApn: apn is stored. Deleting it now for subId " + subId); |
| 2911 | SharedPreferences.Editor editor = sp.edit(); |
| 2912 | editor.remove(DB_VERSION_KEY + subId); |
| 2913 | for (String key : CARRIERS_UNIQUE_FIELDS) { |
| 2914 | editor.remove(key + subId); |
| 2915 | } |
Amit Mahajan | 91c5dff | 2015-10-20 11:13:19 -0700 | [diff] [blame] | 2916 | editor.apply(); |
| 2917 | } |
| 2918 | } |
| 2919 | |
yuemingw | cd80d17 | 2018-01-15 14:08:55 +0000 | [diff] [blame] | 2920 | boolean isCallingFromSystemOrPhoneUid() { |
| 2921 | return mInjector.binderGetCallingUid() == Process.SYSTEM_UID || |
| 2922 | mInjector.binderGetCallingUid() == Process.PHONE_UID; |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 2923 | } |
| 2924 | |
yuemingw | cd80d17 | 2018-01-15 14:08:55 +0000 | [diff] [blame] | 2925 | void ensureCallingFromSystemOrPhoneUid(String message) { |
| 2926 | if (!isCallingFromSystemOrPhoneUid()) { |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 2927 | throw new SecurityException(message); |
| 2928 | } |
| 2929 | } |
| 2930 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 2931 | @Override |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 2932 | public synchronized Cursor query(Uri url, String[] projectionIn, String selection, |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 2933 | String[] selectionArgs, String sort) { |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 2934 | if (VDBG) log("query: url=" + url + ", projectionIn=" + projectionIn + ", selection=" |
calvinpan | 2b41944 | 2018-10-23 15:05:11 +0800 | [diff] [blame] | 2935 | + selection + "selectionArgs=" + selectionArgs + ", sort=" + sort); |
Shishir Agrawal | de98fc1 | 2016-01-25 14:06:08 -0800 | [diff] [blame] | 2936 | int subId = SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 2937 | String subIdString; |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 2938 | SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); |
Robert Greenwalt | 429cf07 | 2013-05-21 17:04:09 -0700 | [diff] [blame] | 2939 | qb.setStrict(true); // a little protection from injection attacks |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 2940 | qb.setTables(CARRIERS_TABLE); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 2941 | |
Jordan Liu | 9a7cea1 | 2017-11-16 14:45:07 -0800 | [diff] [blame] | 2942 | List<String> constraints = new ArrayList<String>(); |
| 2943 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 2944 | int match = s_urlMatcher.match(url); |
Hall Liu | 018f8b1 | 2020-02-25 15:58:56 -0800 | [diff] [blame] | 2945 | checkPermissionCompat(match, projectionIn); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 2946 | switch (match) { |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 2947 | case URL_TELEPHONY_USING_SUBID: { |
| 2948 | subIdString = url.getLastPathSegment(); |
| 2949 | try { |
Wink Saville | 830a40f | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 2950 | subId = Integer.parseInt(subIdString); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 2951 | } catch (NumberFormatException e) { |
| 2952 | loge("NumberFormatException" + e); |
| 2953 | return null; |
| 2954 | } |
| 2955 | if (DBG) log("subIdString = " + subIdString + " subId = " + subId); |
changbetty | faa1d7a | 2019-11-26 18:06:24 +0800 | [diff] [blame] | 2956 | TelephonyManager telephonyManager = getContext() |
| 2957 | .getSystemService(TelephonyManager.class).createForSubscriptionId(subId); |
| 2958 | constraints.add(NUMERIC + " = '" + telephonyManager.getSimOperator() + "'"); |
Jordan Liu | b8fec05 | 2018-03-14 10:42:06 -0700 | [diff] [blame] | 2959 | // TODO b/74213956 turn this back on once insertion includes correct sub id |
| 2960 | // constraints.add(SUBSCRIPTION_ID + "=" + subIdString); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 2961 | } |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 2962 | // intentional fall through from above case |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 2963 | case URL_TELEPHONY: { |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 2964 | constraints.add(IS_NOT_OWNED_BY_DPC); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 2965 | break; |
| 2966 | } |
| 2967 | |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 2968 | case URL_CURRENT_USING_SUBID: { |
| 2969 | subIdString = url.getLastPathSegment(); |
| 2970 | try { |
Wink Saville | 830a40f | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 2971 | subId = Integer.parseInt(subIdString); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 2972 | } catch (NumberFormatException e) { |
| 2973 | loge("NumberFormatException" + e); |
| 2974 | return null; |
| 2975 | } |
| 2976 | if (DBG) log("subIdString = " + subIdString + " subId = " + subId); |
Jordan Liu | b8fec05 | 2018-03-14 10:42:06 -0700 | [diff] [blame] | 2977 | // TODO b/74213956 turn this back on once insertion includes correct sub id |
| 2978 | // constraints.add(SUBSCRIPTION_ID + "=" + subIdString); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 2979 | } |
| 2980 | //intentional fall through from above case |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 2981 | case URL_CURRENT: { |
Jordan Liu | 9a7cea1 | 2017-11-16 14:45:07 -0800 | [diff] [blame] | 2982 | constraints.add("current IS NOT NULL"); |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 2983 | constraints.add(IS_NOT_OWNED_BY_DPC); |
Sangcheol Lee | 4e18088 | 2011-04-01 19:24:52 -0700 | [diff] [blame] | 2984 | // do not ignore the selection since MMS may use it. |
| 2985 | //selection = null; |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 2986 | break; |
| 2987 | } |
| 2988 | |
| 2989 | case URL_ID: { |
Jordan Liu | 9a7cea1 | 2017-11-16 14:45:07 -0800 | [diff] [blame] | 2990 | constraints.add("_id = " + url.getPathSegments().get(1)); |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 2991 | constraints.add(IS_NOT_OWNED_BY_DPC); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 2992 | break; |
| 2993 | } |
| 2994 | |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 2995 | case URL_PREFERAPN_USING_SUBID: |
| 2996 | case URL_PREFERAPN_NO_UPDATE_USING_SUBID: { |
| 2997 | subIdString = url.getLastPathSegment(); |
| 2998 | try { |
Wink Saville | 830a40f | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 2999 | subId = Integer.parseInt(subIdString); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3000 | } catch (NumberFormatException e) { |
| 3001 | loge("NumberFormatException" + e); |
| 3002 | return null; |
| 3003 | } |
| 3004 | if (DBG) log("subIdString = " + subIdString + " subId = " + subId); |
Jordan Liu | b8fec05 | 2018-03-14 10:42:06 -0700 | [diff] [blame] | 3005 | // TODO b/74213956 turn this back on once insertion includes correct sub id |
| 3006 | // constraints.add(SUBSCRIPTION_ID + "=" + subIdString); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3007 | } |
| 3008 | //intentional fall through from above case |
Kazuhiro Ondo | d616ee6 | 2012-01-10 17:12:59 -0600 | [diff] [blame] | 3009 | case URL_PREFERAPN: |
| 3010 | case URL_PREFERAPN_NO_UPDATE: { |
Jordan Liu | 9a7cea1 | 2017-11-16 14:45:07 -0800 | [diff] [blame] | 3011 | constraints.add("_id = " + getPreferredApnId(subId, true)); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3012 | break; |
| 3013 | } |
| 3014 | |
Jordan Liu | c6078b7 | 2018-05-01 11:34:21 -0700 | [diff] [blame] | 3015 | case URL_PREFERAPNSET_USING_SUBID: { |
| 3016 | subIdString = url.getLastPathSegment(); |
| 3017 | try { |
| 3018 | subId = Integer.parseInt(subIdString); |
| 3019 | } catch (NumberFormatException e) { |
| 3020 | loge("NumberFormatException" + e); |
| 3021 | return null; |
| 3022 | } |
| 3023 | if (DBG) log("subIdString = " + subIdString + " subId = " + subId); |
| 3024 | // TODO b/74213956 turn this back on once insertion includes correct sub id |
| 3025 | // constraints.add(SUBSCRIPTION_ID + "=" + subIdString); |
| 3026 | } |
| 3027 | // intentional fall through from above case |
| 3028 | case URL_PREFERAPNSET: { |
| 3029 | final int set = getPreferredApnSetId(subId); |
Jordan Liu | 748c832 | 2020-07-15 15:09:12 -0700 | [diff] [blame] | 3030 | if (set == NO_APN_SET_ID) { |
| 3031 | return null; |
Jordan Liu | c6078b7 | 2018-05-01 11:34:21 -0700 | [diff] [blame] | 3032 | } |
Jordan Liu | 748c832 | 2020-07-15 15:09:12 -0700 | [diff] [blame] | 3033 | constraints.add(APN_SET_ID + "=" + set); |
| 3034 | qb.appendWhere(TextUtils.join(" AND ", constraints)); |
| 3035 | return getSubscriptionMatchingAPNList(qb, projectionIn, selection, selectionArgs, |
| 3036 | sort, subId); |
Jordan Liu | c6078b7 | 2018-05-01 11:34:21 -0700 | [diff] [blame] | 3037 | } |
| 3038 | |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3039 | case URL_DPC: { |
yuemingw | cd80d17 | 2018-01-15 14:08:55 +0000 | [diff] [blame] | 3040 | ensureCallingFromSystemOrPhoneUid("URL_DPC called from non SYSTEM_UID."); |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3041 | // DPC query only returns DPC records. |
| 3042 | constraints.add(IS_OWNED_BY_DPC); |
| 3043 | break; |
| 3044 | } |
| 3045 | |
Malcolm Chen | 09ebf8d | 2018-12-07 13:45:54 -0800 | [diff] [blame] | 3046 | case URL_FILTERED_ID: |
| 3047 | case URL_FILTERED_USING_SUBID: { |
| 3048 | String idString = url.getLastPathSegment(); |
| 3049 | if (match == URL_FILTERED_ID) { |
Josh Hou | 42049bb | 2018-12-10 22:22:05 +0800 | [diff] [blame] | 3050 | constraints.add("_id = " + idString); |
Malcolm Chen | 09ebf8d | 2018-12-07 13:45:54 -0800 | [diff] [blame] | 3051 | } else { |
| 3052 | try { |
| 3053 | subId = Integer.parseInt(idString); |
Josh Hou | 42049bb | 2018-12-10 22:22:05 +0800 | [diff] [blame] | 3054 | // TODO b/74213956 turn this back on once insertion includes correct sub id |
| 3055 | // constraints.add(SUBSCRIPTION_ID + "=" + subIdString); |
Malcolm Chen | 09ebf8d | 2018-12-07 13:45:54 -0800 | [diff] [blame] | 3056 | } catch (NumberFormatException e) { |
| 3057 | loge("NumberFormatException" + e); |
| 3058 | return null; |
| 3059 | } |
| 3060 | } |
yuemingw | cd80d17 | 2018-01-15 14:08:55 +0000 | [diff] [blame] | 3061 | } |
| 3062 | //intentional fall through from above case |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3063 | case URL_FILTERED: { |
calvinpan | 2b41944 | 2018-10-23 15:05:11 +0800 | [diff] [blame] | 3064 | if (isManagedApnEnforced()) { |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3065 | // If enforced, return DPC records only. |
Josh Hou | 42049bb | 2018-12-10 22:22:05 +0800 | [diff] [blame] | 3066 | constraints.add(IS_OWNED_BY_DPC); |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3067 | } else { |
| 3068 | // Otherwise return non-DPC records only. |
Josh Hou | 42049bb | 2018-12-10 22:22:05 +0800 | [diff] [blame] | 3069 | constraints.add(IS_NOT_OWNED_BY_DPC); |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3070 | } |
Josh Hou | 42049bb | 2018-12-10 22:22:05 +0800 | [diff] [blame] | 3071 | break; |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3072 | } |
| 3073 | |
| 3074 | case URL_ENFORCE_MANAGED: { |
yuemingw | cd80d17 | 2018-01-15 14:08:55 +0000 | [diff] [blame] | 3075 | ensureCallingFromSystemOrPhoneUid( |
| 3076 | "URL_ENFORCE_MANAGED called from non SYSTEM_UID."); |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3077 | MatrixCursor cursor = new MatrixCursor(new String[]{ENFORCED_KEY}); |
| 3078 | cursor.addRow(new Object[]{isManagedApnEnforced() ? 1 : 0}); |
| 3079 | return cursor; |
| 3080 | } |
| 3081 | |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3082 | case URL_SIMINFO: { |
| 3083 | qb.setTables(SIMINFO_TABLE); |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 3084 | break; |
| 3085 | } |
calvinpan | ba94b59 | 2018-11-01 09:09:30 +0800 | [diff] [blame] | 3086 | case URL_SIM_APN_LIST_ID: { |
| 3087 | subIdString = url.getLastPathSegment(); |
| 3088 | try { |
| 3089 | subId = Integer.parseInt(subIdString); |
| 3090 | } catch (NumberFormatException e) { |
| 3091 | loge("NumberFormatException" + e); |
| 3092 | return null; |
| 3093 | } |
| 3094 | } |
| 3095 | //intentional fall through from above case |
| 3096 | case URL_SIM_APN_LIST: { |
calvinpan | c4bff40 | 2018-11-12 15:57:19 +0800 | [diff] [blame] | 3097 | qb.appendWhere(IS_NOT_OWNED_BY_DPC); |
| 3098 | return getSubscriptionMatchingAPNList(qb, projectionIn, selection, selectionArgs, |
| 3099 | sort, subId); |
calvinpan | ba94b59 | 2018-11-01 09:09:30 +0800 | [diff] [blame] | 3100 | } |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 3101 | |
Josh Hou | 42049bb | 2018-12-10 22:22:05 +0800 | [diff] [blame] | 3102 | case URL_SIM_APN_LIST_FILTERED_ID: { |
| 3103 | subIdString = url.getLastPathSegment(); |
| 3104 | try { |
| 3105 | subId = Integer.parseInt(subIdString); |
| 3106 | } catch (NumberFormatException e) { |
| 3107 | loge("NumberFormatException" + e); |
| 3108 | return null; |
| 3109 | } |
| 3110 | } |
| 3111 | //intentional fall through from above case |
| 3112 | case URL_SIM_APN_LIST_FILTERED: { |
| 3113 | if (isManagedApnEnforced()) { |
| 3114 | // If enforced, return DPC records only. |
| 3115 | qb.appendWhereStandalone(IS_OWNED_BY_DPC); |
| 3116 | } else { |
| 3117 | // Otherwise return non-DPC records only. |
| 3118 | qb.appendWhereStandalone(IS_NOT_OWNED_BY_DPC); |
| 3119 | } |
| 3120 | return getSubscriptionMatchingAPNList(qb, projectionIn, selection, selectionArgs, |
| 3121 | sort, subId); |
| 3122 | } |
| 3123 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3124 | default: { |
| 3125 | return null; |
| 3126 | } |
| 3127 | } |
| 3128 | |
Jordan Liu | 9a7cea1 | 2017-11-16 14:45:07 -0800 | [diff] [blame] | 3129 | // appendWhere doesn't add ANDs so we do it ourselves |
| 3130 | if (constraints.size() > 0) { |
| 3131 | qb.appendWhere(TextUtils.join(" AND ", constraints)); |
| 3132 | } |
| 3133 | |
Jordan Liu | e6f0bce | 2016-09-21 18:31:43 -0700 | [diff] [blame] | 3134 | SQLiteDatabase db = getReadableDatabase(); |
Hyejin Kim | cfdb743 | 2013-02-16 00:58:37 +0900 | [diff] [blame] | 3135 | Cursor ret = null; |
| 3136 | try { |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 3137 | // Exclude entries marked deleted |
| 3138 | if (CARRIERS_TABLE.equals(qb.getTables())) { |
| 3139 | if (TextUtils.isEmpty(selection)) { |
| 3140 | selection = ""; |
| 3141 | } else { |
| 3142 | selection += " and "; |
| 3143 | } |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 3144 | selection += IS_NOT_USER_DELETED + " and " + |
| 3145 | IS_NOT_USER_DELETED_BUT_PRESENT_IN_XML + " and " + |
| 3146 | IS_NOT_CARRIER_DELETED + " and " + |
| 3147 | IS_NOT_CARRIER_DELETED_BUT_PRESENT_IN_XML; |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 3148 | if (VDBG) log("query: selection modified to " + selection); |
| 3149 | } |
Amit Mahajan | 7b50f24 | 2016-08-14 19:47:49 +0000 | [diff] [blame] | 3150 | ret = qb.query(db, projectionIn, selection, selectionArgs, null, null, sort); |
Hyejin Kim | cfdb743 | 2013-02-16 00:58:37 +0900 | [diff] [blame] | 3151 | } catch (SQLException e) { |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3152 | loge("got exception when querying: " + e); |
Hyejin Kim | cfdb743 | 2013-02-16 00:58:37 +0900 | [diff] [blame] | 3153 | } |
| 3154 | if (ret != null) |
| 3155 | ret.setNotificationUri(getContext().getContentResolver(), url); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3156 | return ret; |
| 3157 | } |
| 3158 | |
calvinpan | ba94b59 | 2018-11-01 09:09:30 +0800 | [diff] [blame] | 3159 | /** |
calvinpan | 33a10a0 | 2019-11-04 21:36:12 +0800 | [diff] [blame] | 3160 | * To find the current sim APN. Query APN based on {MCC, MNC, MVNO} and {Carrier_ID}. |
calvinpan | ba94b59 | 2018-11-01 09:09:30 +0800 | [diff] [blame] | 3161 | * |
| 3162 | * There has three steps: |
calvinpan | 33a10a0 | 2019-11-04 21:36:12 +0800 | [diff] [blame] | 3163 | * 1. Query the APN based on { MCC, MNC, MVNO } and if has results jump to step 3, else jump to |
| 3164 | * step 2. |
| 3165 | * 2. Fallback to query the parent APN that query based on { MCC, MNC }. |
| 3166 | * 3. Append the result with the APN that query based on { Carrier_ID } |
calvinpan | ba94b59 | 2018-11-01 09:09:30 +0800 | [diff] [blame] | 3167 | */ |
| 3168 | private Cursor getSubscriptionMatchingAPNList(SQLiteQueryBuilder qb, String[] projectionIn, |
calvinpan | c4bff40 | 2018-11-12 15:57:19 +0800 | [diff] [blame] | 3169 | String selection, String[] selectionArgs, String sort, int subId) { |
calvinpan | ba94b59 | 2018-11-01 09:09:30 +0800 | [diff] [blame] | 3170 | Cursor ret; |
Nazanin | b2a1628 | 2020-07-07 15:41:28 -0700 | [diff] [blame] | 3171 | Context context = getContext(); |
| 3172 | SubscriptionManager subscriptionManager = (SubscriptionManager) context |
| 3173 | .getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 3174 | if (!subscriptionManager.isActiveSubscriptionId(subId)) { |
| 3175 | return null; |
| 3176 | } |
| 3177 | |
| 3178 | final TelephonyManager tm = ((TelephonyManager) context |
calvinpan | 33a10a0 | 2019-11-04 21:36:12 +0800 | [diff] [blame] | 3179 | .getSystemService(Context.TELEPHONY_SERVICE)) |
calvinpan | ba94b59 | 2018-11-01 09:09:30 +0800 | [diff] [blame] | 3180 | .createForSubscriptionId(subId); |
| 3181 | SQLiteDatabase db = getReadableDatabase(); |
calvinpan | ba94b59 | 2018-11-01 09:09:30 +0800 | [diff] [blame] | 3182 | String mccmnc = tm.getSimOperator(); |
calvinpan | 33a10a0 | 2019-11-04 21:36:12 +0800 | [diff] [blame] | 3183 | int carrierId = tm.getSimCarrierId(); |
calvinpan | ba94b59 | 2018-11-01 09:09:30 +0800 | [diff] [blame] | 3184 | |
calvinpan | 3d8a61e | 2019-03-12 12:46:42 +0800 | [diff] [blame] | 3185 | qb.appendWhereStandalone(IS_NOT_USER_DELETED + " and " + |
| 3186 | IS_NOT_USER_DELETED_BUT_PRESENT_IN_XML + " and " + |
| 3187 | IS_NOT_CARRIER_DELETED + " and " + |
| 3188 | IS_NOT_CARRIER_DELETED_BUT_PRESENT_IN_XML); |
| 3189 | |
calvinpan | 33a10a0 | 2019-11-04 21:36:12 +0800 | [diff] [blame] | 3190 | // For query db one time, append all conditions in one selection and separate results after |
| 3191 | // the query is completed. IMSI has special match rule, so just query the MCC / MNC and |
| 3192 | // filter the MVNO by ourselves |
xiangyu.deng | 233d88c | 2021-07-16 14:09:40 +0800 | [diff] [blame] | 3193 | if (carrierId != TelephonyManager.UNKNOWN_CARRIER_ID) { |
| 3194 | qb.appendWhereStandalone(NUMERIC + " = '" + mccmnc + "' OR " + |
calvinpan | 33a10a0 | 2019-11-04 21:36:12 +0800 | [diff] [blame] | 3195 | CARRIER_ID + " = '" + carrierId + "'"); |
xiangyu.deng | 233d88c | 2021-07-16 14:09:40 +0800 | [diff] [blame] | 3196 | } |
| 3197 | else { |
| 3198 | qb.appendWhereStandalone(NUMERIC + " = '" + mccmnc + "'"); |
| 3199 | } |
calvinpan | ba94b59 | 2018-11-01 09:09:30 +0800 | [diff] [blame] | 3200 | |
calvinpan | c4bff40 | 2018-11-12 15:57:19 +0800 | [diff] [blame] | 3201 | ret = qb.query(db, null, selection, selectionArgs, null, null, sort); |
calvinpan | 066ce1d | 2018-12-05 16:21:26 +0800 | [diff] [blame] | 3202 | if (ret == null) { |
| 3203 | loge("query current APN but cursor is null."); |
| 3204 | return null; |
| 3205 | } |
calvinpan | ba94b59 | 2018-11-01 09:09:30 +0800 | [diff] [blame] | 3206 | |
| 3207 | if (DBG) log("match current APN size: " + ret.getCount()); |
| 3208 | |
xiangyu.deng | 233d88c | 2021-07-16 14:09:40 +0800 | [diff] [blame] | 3209 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 3210 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 3211 | if (iccRecords == null) { |
| 3212 | loge("iccRecords is null"); |
| 3213 | return null; |
| 3214 | } |
| 3215 | |
calvinpan | 33a10a0 | 2019-11-04 21:36:12 +0800 | [diff] [blame] | 3216 | String[] columnNames = projectionIn != null ? projectionIn : ret.getColumnNames(); |
| 3217 | MatrixCursor currentCursor = new MatrixCursor(columnNames); |
| 3218 | MatrixCursor parentCursor = new MatrixCursor(columnNames); |
| 3219 | MatrixCursor carrierIdCursor = new MatrixCursor(columnNames); |
calvinpan | ba94b59 | 2018-11-01 09:09:30 +0800 | [diff] [blame] | 3220 | |
calvinpan | ba94b59 | 2018-11-01 09:09:30 +0800 | [diff] [blame] | 3221 | int numericIndex = ret.getColumnIndex(NUMERIC); |
| 3222 | int mvnoIndex = ret.getColumnIndex(MVNO_TYPE); |
| 3223 | int mvnoDataIndex = ret.getColumnIndex(MVNO_MATCH_DATA); |
calvinpan | 33a10a0 | 2019-11-04 21:36:12 +0800 | [diff] [blame] | 3224 | int carrierIdIndex = ret.getColumnIndex(CARRIER_ID); |
calvinpan | ba94b59 | 2018-11-01 09:09:30 +0800 | [diff] [blame] | 3225 | |
calvinpan | 0fb0efc | 2020-01-06 16:17:40 +0800 | [diff] [blame] | 3226 | // Separate the result into MatrixCursor |
calvinpan | ba94b59 | 2018-11-01 09:09:30 +0800 | [diff] [blame] | 3227 | while (ret.moveToNext()) { |
| 3228 | List<String> data = new ArrayList<>(); |
calvinpan | 33a10a0 | 2019-11-04 21:36:12 +0800 | [diff] [blame] | 3229 | for (String column : columnNames) { |
calvinpan | ba94b59 | 2018-11-01 09:09:30 +0800 | [diff] [blame] | 3230 | data.add(ret.getString(ret.getColumnIndex(column))); |
| 3231 | } |
| 3232 | |
calvinpan | 0fb0efc | 2020-01-06 16:17:40 +0800 | [diff] [blame] | 3233 | boolean isMVNOAPN = !TextUtils.isEmpty(ret.getString(numericIndex)) |
xiangyu.deng | 233d88c | 2021-07-16 14:09:40 +0800 | [diff] [blame] | 3234 | && ApnSettingUtils.mvnoMatches(iccRecords, |
| 3235 | ret.getString(mvnoIndex), ret.getString(mvnoDataIndex), subId); |
calvinpan | 0fb0efc | 2020-01-06 16:17:40 +0800 | [diff] [blame] | 3236 | boolean isMNOAPN = !TextUtils.isEmpty(ret.getString(numericIndex)) |
| 3237 | && ret.getString(numericIndex).equals(mccmnc) |
| 3238 | && TextUtils.isEmpty(ret.getString(mvnoIndex)); |
| 3239 | boolean isCarrierIdAPN = !TextUtils.isEmpty(ret.getString(carrierIdIndex)) |
| 3240 | && ret.getString(carrierIdIndex).equals(String.valueOf(carrierId)) |
| 3241 | && carrierId != TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3242 | |
| 3243 | if (isMVNOAPN) { |
calvinpan | 33a10a0 | 2019-11-04 21:36:12 +0800 | [diff] [blame] | 3244 | // 1. The APN that query based on legacy SIM MCC/MCC and MVNO |
calvinpan | ba94b59 | 2018-11-01 09:09:30 +0800 | [diff] [blame] | 3245 | currentCursor.addRow(data); |
calvinpan | 0fb0efc | 2020-01-06 16:17:40 +0800 | [diff] [blame] | 3246 | } else if (isMNOAPN) { |
calvinpan | 33a10a0 | 2019-11-04 21:36:12 +0800 | [diff] [blame] | 3247 | // 2. The APN that query based on SIM MCC/MNC |
calvinpan | ba94b59 | 2018-11-01 09:09:30 +0800 | [diff] [blame] | 3248 | parentCursor.addRow(data); |
calvinpan | 0fb0efc | 2020-01-06 16:17:40 +0800 | [diff] [blame] | 3249 | } else if (isCarrierIdAPN) { |
calvinpan | 33a10a0 | 2019-11-04 21:36:12 +0800 | [diff] [blame] | 3250 | // The APN that query based on carrier Id (not include the MVNO or MNO APN) |
| 3251 | carrierIdCursor.addRow(data); |
calvinpan | ba94b59 | 2018-11-01 09:09:30 +0800 | [diff] [blame] | 3252 | } |
| 3253 | } |
calvinpan | 066ce1d | 2018-12-05 16:21:26 +0800 | [diff] [blame] | 3254 | ret.close(); |
calvinpan | ba94b59 | 2018-11-01 09:09:30 +0800 | [diff] [blame] | 3255 | |
calvinpan | 33a10a0 | 2019-11-04 21:36:12 +0800 | [diff] [blame] | 3256 | MatrixCursor result; |
calvinpan | ba94b59 | 2018-11-01 09:09:30 +0800 | [diff] [blame] | 3257 | if (currentCursor.getCount() > 0) { |
calvinpan | 3d8a61e | 2019-03-12 12:46:42 +0800 | [diff] [blame] | 3258 | if (DBG) log("match MVNO APN: " + currentCursor.getCount()); |
calvinpan | 33a10a0 | 2019-11-04 21:36:12 +0800 | [diff] [blame] | 3259 | result = currentCursor; |
calvinpan | ba94b59 | 2018-11-01 09:09:30 +0800 | [diff] [blame] | 3260 | } else if (parentCursor.getCount() > 0) { |
calvinpan | 3d8a61e | 2019-03-12 12:46:42 +0800 | [diff] [blame] | 3261 | if (DBG) log("match MNO APN: " + parentCursor.getCount()); |
calvinpan | 33a10a0 | 2019-11-04 21:36:12 +0800 | [diff] [blame] | 3262 | result = parentCursor; |
calvinpan | ba94b59 | 2018-11-01 09:09:30 +0800 | [diff] [blame] | 3263 | } else { |
calvinpan | 33a10a0 | 2019-11-04 21:36:12 +0800 | [diff] [blame] | 3264 | if (DBG) log("can't find the MVNO and MNO APN"); |
| 3265 | result = new MatrixCursor(columnNames); |
| 3266 | } |
| 3267 | |
| 3268 | if (DBG) log("match carrier id APN: " + carrierIdCursor.getCount()); |
| 3269 | appendCursorData(result, carrierIdCursor); |
| 3270 | return result; |
| 3271 | } |
| 3272 | |
| 3273 | private static void appendCursorData(@NonNull MatrixCursor from, @NonNull MatrixCursor to) { |
| 3274 | while (to.moveToNext()) { |
| 3275 | List<Object> data = new ArrayList<>(); |
| 3276 | for (String column : to.getColumnNames()) { |
| 3277 | int index = to.getColumnIndex(column); |
| 3278 | switch (to.getType(index)) { |
calvinpan | 33a10a0 | 2019-11-04 21:36:12 +0800 | [diff] [blame] | 3279 | case Cursor.FIELD_TYPE_INTEGER: |
| 3280 | data.add(to.getInt(index)); |
| 3281 | break; |
| 3282 | case Cursor.FIELD_TYPE_FLOAT: |
| 3283 | data.add(to.getFloat(index)); |
| 3284 | break; |
| 3285 | case Cursor.FIELD_TYPE_BLOB: |
| 3286 | data.add(to.getBlob(index)); |
| 3287 | break; |
| 3288 | case Cursor.FIELD_TYPE_STRING: |
calvinpan | 04ece1e | 2020-01-06 16:17:40 +0800 | [diff] [blame] | 3289 | case Cursor.FIELD_TYPE_NULL: |
calvinpan | 33a10a0 | 2019-11-04 21:36:12 +0800 | [diff] [blame] | 3290 | data.add(to.getString(index)); |
| 3291 | break; |
| 3292 | } |
| 3293 | } |
| 3294 | from.addRow(data); |
calvinpan | ba94b59 | 2018-11-01 09:09:30 +0800 | [diff] [blame] | 3295 | } |
| 3296 | } |
| 3297 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3298 | @Override |
| 3299 | public String getType(Uri url) |
| 3300 | { |
| 3301 | switch (s_urlMatcher.match(url)) { |
| 3302 | case URL_TELEPHONY: |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3303 | case URL_TELEPHONY_USING_SUBID: |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3304 | return "vnd.android.cursor.dir/telephony-carrier"; |
| 3305 | |
| 3306 | case URL_ID: |
yuemingw | cd80d17 | 2018-01-15 14:08:55 +0000 | [diff] [blame] | 3307 | case URL_FILTERED_ID: |
Malcolm Chen | 09ebf8d | 2018-12-07 13:45:54 -0800 | [diff] [blame] | 3308 | case URL_FILTERED_USING_SUBID: |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3309 | return "vnd.android.cursor.item/telephony-carrier"; |
| 3310 | |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3311 | case URL_PREFERAPN_USING_SUBID: |
| 3312 | case URL_PREFERAPN_NO_UPDATE_USING_SUBID: |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 3313 | case URL_PREFERAPN: |
Kazuhiro Ondo | d616ee6 | 2012-01-10 17:12:59 -0600 | [diff] [blame] | 3314 | case URL_PREFERAPN_NO_UPDATE: |
Jordan Liu | c6078b7 | 2018-05-01 11:34:21 -0700 | [diff] [blame] | 3315 | case URL_PREFERAPNSET: |
| 3316 | case URL_PREFERAPNSET_USING_SUBID: |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 3317 | return "vnd.android.cursor.item/telephony-carrier"; |
| 3318 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3319 | default: |
| 3320 | throw new IllegalArgumentException("Unknown URL " + url); |
| 3321 | } |
| 3322 | } |
| 3323 | |
Jordan Liu | 3de76f8 | 2017-05-15 15:21:01 -0700 | [diff] [blame] | 3324 | /** |
| 3325 | * Insert an array of ContentValues and call notifyChange at the end. |
| 3326 | */ |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3327 | @Override |
Jordan Liu | 6cf9bda | 2017-05-19 11:42:55 -0700 | [diff] [blame] | 3328 | public synchronized int bulkInsert(Uri url, ContentValues[] values) { |
Jordan Liu | 3de76f8 | 2017-05-15 15:21:01 -0700 | [diff] [blame] | 3329 | return unsynchronizedBulkInsert(url, values); |
| 3330 | } |
| 3331 | |
| 3332 | /** |
| 3333 | * Do a bulk insert while inside a synchronized function. This is typically not safe and should |
| 3334 | * only be done when you are sure there will be no conflict. |
| 3335 | */ |
| 3336 | private int unsynchronizedBulkInsert(Uri url, ContentValues[] values) { |
Jordan Liu | 6cf9bda | 2017-05-19 11:42:55 -0700 | [diff] [blame] | 3337 | int count = 0; |
| 3338 | boolean notify = false; |
| 3339 | for (ContentValues value : values) { |
| 3340 | Pair<Uri, Boolean> rowAndNotify = insertSingleRow(url, value); |
| 3341 | if (rowAndNotify.first != null) { |
| 3342 | count++; |
| 3343 | } |
| 3344 | if (rowAndNotify.second == true) { |
| 3345 | notify = true; |
| 3346 | } |
| 3347 | } |
| 3348 | if (notify) { |
| 3349 | getContext().getContentResolver().notifyChange(CONTENT_URI, null, |
| 3350 | true, UserHandle.USER_ALL); |
| 3351 | } |
| 3352 | return count; |
| 3353 | } |
| 3354 | |
| 3355 | @Override |
| 3356 | public synchronized Uri insert(Uri url, ContentValues initialValues) { |
| 3357 | Pair<Uri, Boolean> rowAndNotify = insertSingleRow(url, initialValues); |
| 3358 | if (rowAndNotify.second) { |
| 3359 | getContext().getContentResolver().notifyChange(CONTENT_URI, null, |
| 3360 | true, UserHandle.USER_ALL); |
| 3361 | } |
| 3362 | return rowAndNotify.first; |
| 3363 | } |
| 3364 | |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3365 | /** |
| 3366 | * Internal insert function to prevent code duplication for URL_TELEPHONY and URL_DPC. |
| 3367 | * |
| 3368 | * @param values the value that caller wants to insert |
| 3369 | * @return a pair in which the first element refers to the Uri for the row inserted, the second |
| 3370 | * element refers to whether sends out nofitication. |
| 3371 | */ |
| 3372 | private Pair<Uri, Boolean> insertRowWithValue(ContentValues values) { |
| 3373 | Uri result = null; |
| 3374 | boolean notify = false; |
| 3375 | SQLiteDatabase db = getWritableDatabase(); |
| 3376 | |
| 3377 | try { |
Jordan Liu | c655dec | 2018-02-13 11:16:53 -0800 | [diff] [blame] | 3378 | // Abort on conflict of unique fields and attempt merge |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3379 | long rowID = db.insertWithOnConflict(CARRIERS_TABLE, null, values, |
| 3380 | SQLiteDatabase.CONFLICT_ABORT); |
| 3381 | if (rowID >= 0) { |
| 3382 | result = ContentUris.withAppendedId(CONTENT_URI, rowID); |
| 3383 | notify = true; |
| 3384 | } |
| 3385 | if (VDBG) log("insert: inserted " + values.toString() + " rowID = " + rowID); |
| 3386 | } catch (SQLException e) { |
| 3387 | log("insert: exception " + e); |
| 3388 | // Insertion failed which could be due to a conflict. Check if that is the case |
| 3389 | // and merge the entries |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 3390 | Cursor oldRow = selectConflictingRow(db, CARRIERS_TABLE, values); |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3391 | if (oldRow != null) { |
| 3392 | ContentValues mergedValues = new ContentValues(); |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 3393 | mergeFieldsAndUpdateDb(db, CARRIERS_TABLE, oldRow, values, |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3394 | mergedValues, false, getContext()); |
| 3395 | oldRow.close(); |
| 3396 | notify = true; |
| 3397 | } |
| 3398 | } |
| 3399 | return Pair.create(result, notify); |
| 3400 | } |
| 3401 | |
Jordan Liu | 6cf9bda | 2017-05-19 11:42:55 -0700 | [diff] [blame] | 3402 | private Pair<Uri, Boolean> insertSingleRow(Uri url, ContentValues initialValues) { |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3403 | Uri result = null; |
Shishir Agrawal | de98fc1 | 2016-01-25 14:06:08 -0800 | [diff] [blame] | 3404 | int subId = SubscriptionManager.getDefaultSubscriptionId(); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3405 | |
| 3406 | checkPermission(); |
Cassie | a58ce71 | 2017-12-06 16:21:50 -0800 | [diff] [blame] | 3407 | syncBearerBitmaskAndNetworkTypeBitmask(initialValues); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3408 | |
Jordan Liu | 6cf9bda | 2017-05-19 11:42:55 -0700 | [diff] [blame] | 3409 | boolean notify = false; |
Jordan Liu | e6f0bce | 2016-09-21 18:31:43 -0700 | [diff] [blame] | 3410 | SQLiteDatabase db = getWritableDatabase(); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3411 | int match = s_urlMatcher.match(url); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3412 | switch (match) |
| 3413 | { |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3414 | case URL_TELEPHONY_USING_SUBID: |
| 3415 | { |
| 3416 | String subIdString = url.getLastPathSegment(); |
| 3417 | try { |
Wink Saville | 830a40f | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 3418 | subId = Integer.parseInt(subIdString); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3419 | } catch (NumberFormatException e) { |
| 3420 | loge("NumberFormatException" + e); |
Jordan Liu | 6cf9bda | 2017-05-19 11:42:55 -0700 | [diff] [blame] | 3421 | return Pair.create(result, notify); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3422 | } |
| 3423 | if (DBG) log("subIdString = " + subIdString + " subId = " + subId); |
| 3424 | } |
| 3425 | //intentional fall through from above case |
| 3426 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3427 | case URL_TELEPHONY: |
| 3428 | { |
| 3429 | ContentValues values; |
| 3430 | if (initialValues != null) { |
| 3431 | values = new ContentValues(initialValues); |
| 3432 | } else { |
| 3433 | values = new ContentValues(); |
| 3434 | } |
| 3435 | |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 3436 | values = setDefaultValue(values); |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 3437 | if (!values.containsKey(EDITED_STATUS)) { |
| 3438 | values.put(EDITED_STATUS, CARRIER_EDITED); |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 3439 | } |
yuemingw | c4d40a7 | 2017-11-08 14:14:37 +0000 | [diff] [blame] | 3440 | // Owned_by should be others if inserted via general uri. |
| 3441 | values.put(OWNED_BY, OWNED_BY_OTHERS); |
| 3442 | |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3443 | Pair<Uri, Boolean> ret = insertRowWithValue(values); |
| 3444 | result = ret.first; |
| 3445 | notify = ret.second; |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3446 | break; |
| 3447 | } |
| 3448 | |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3449 | case URL_CURRENT_USING_SUBID: |
| 3450 | { |
| 3451 | String subIdString = url.getLastPathSegment(); |
| 3452 | try { |
Wink Saville | 830a40f | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 3453 | subId = Integer.parseInt(subIdString); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3454 | } catch (NumberFormatException e) { |
| 3455 | loge("NumberFormatException" + e); |
Jordan Liu | 6cf9bda | 2017-05-19 11:42:55 -0700 | [diff] [blame] | 3456 | return Pair.create(result, notify); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3457 | } |
| 3458 | if (DBG) log("subIdString = " + subIdString + " subId = " + subId); |
| 3459 | // FIXME use subId in the query |
| 3460 | } |
| 3461 | //intentional fall through from above case |
| 3462 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3463 | case URL_CURRENT: |
| 3464 | { |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 3465 | // zero out the previous operator |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 3466 | db.update(CARRIERS_TABLE, s_currentNullMap, CURRENT + "!=0", null); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3467 | |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 3468 | String numeric = initialValues.getAsString(NUMERIC); |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 3469 | int updated = db.update(CARRIERS_TABLE, s_currentSetMap, |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 3470 | NUMERIC + " = '" + numeric + "'", null); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3471 | |
| 3472 | if (updated > 0) |
| 3473 | { |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3474 | 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] | 3475 | } |
| 3476 | else |
| 3477 | { |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3478 | loge("Failed setting numeric '" + numeric + "' to the current operator"); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3479 | } |
| 3480 | break; |
| 3481 | } |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 3482 | |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3483 | case URL_PREFERAPN_USING_SUBID: |
| 3484 | case URL_PREFERAPN_NO_UPDATE_USING_SUBID: |
| 3485 | { |
| 3486 | String subIdString = url.getLastPathSegment(); |
| 3487 | try { |
Wink Saville | 830a40f | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 3488 | subId = Integer.parseInt(subIdString); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3489 | } catch (NumberFormatException e) { |
| 3490 | loge("NumberFormatException" + e); |
Jordan Liu | 6cf9bda | 2017-05-19 11:42:55 -0700 | [diff] [blame] | 3491 | return Pair.create(result, notify); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3492 | } |
| 3493 | if (DBG) log("subIdString = " + subIdString + " subId = " + subId); |
| 3494 | } |
| 3495 | //intentional fall through from above case |
| 3496 | |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 3497 | case URL_PREFERAPN: |
Kazuhiro Ondo | d616ee6 | 2012-01-10 17:12:59 -0600 | [diff] [blame] | 3498 | case URL_PREFERAPN_NO_UPDATE: |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 3499 | { |
| 3500 | if (initialValues != null) { |
| 3501 | if(initialValues.containsKey(COLUMN_APN_ID)) { |
Amit Mahajan | bf7144e | 2017-08-29 11:39:48 -0700 | [diff] [blame] | 3502 | setPreferredApnId(initialValues.getAsLong(COLUMN_APN_ID), subId, true); |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 3503 | } |
| 3504 | } |
| 3505 | break; |
| 3506 | } |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3507 | |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3508 | case URL_DPC: { |
yuemingw | cd80d17 | 2018-01-15 14:08:55 +0000 | [diff] [blame] | 3509 | ensureCallingFromSystemOrPhoneUid("URL_DPC called from non SYSTEM_UID."); |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3510 | |
| 3511 | ContentValues values; |
| 3512 | if (initialValues != null) { |
| 3513 | values = new ContentValues(initialValues); |
| 3514 | } else { |
| 3515 | values = new ContentValues(); |
| 3516 | } |
| 3517 | |
| 3518 | // Owned_by should be DPC if inserted via URL_DPC. |
| 3519 | values.put(OWNED_BY, OWNED_BY_DPC); |
| 3520 | // DPC records should not be user editable. |
| 3521 | values.put(USER_EDITABLE, false); |
yuemingw | da96ee6 | 2018-02-21 14:58:04 +0000 | [diff] [blame] | 3522 | |
| 3523 | final long rowID = db.insertWithOnConflict(CARRIERS_TABLE, null, values, |
| 3524 | SQLiteDatabase.CONFLICT_IGNORE); |
| 3525 | if (rowID >= 0) { |
| 3526 | result = ContentUris.withAppendedId(CONTENT_URI, rowID); |
| 3527 | notify = true; |
| 3528 | } |
| 3529 | if (VDBG) log("insert: inserted " + values.toString() + " rowID = " + rowID); |
| 3530 | |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3531 | break; |
| 3532 | } |
| 3533 | |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3534 | case URL_SIMINFO: { |
| 3535 | long id = db.insert(SIMINFO_TABLE, null, initialValues); |
changbetty | 004eceb | 2019-12-02 15:53:49 +0800 | [diff] [blame] | 3536 | result = ContentUris.withAppendedId(Telephony.SimInfo.CONTENT_URI, id); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3537 | break; |
| 3538 | } |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3539 | } |
| 3540 | |
Jordan Liu | 6cf9bda | 2017-05-19 11:42:55 -0700 | [diff] [blame] | 3541 | return Pair.create(result, notify); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3542 | } |
| 3543 | |
| 3544 | @Override |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3545 | public synchronized int delete(Uri url, String where, String[] whereArgs) { |
Kazuhiro Ondo | d616ee6 | 2012-01-10 17:12:59 -0600 | [diff] [blame] | 3546 | int count = 0; |
Shishir Agrawal | de98fc1 | 2016-01-25 14:06:08 -0800 | [diff] [blame] | 3547 | int subId = SubscriptionManager.getDefaultSubscriptionId(); |
Amit Mahajan | 7b8040a | 2015-06-15 18:11:01 -0700 | [diff] [blame] | 3548 | String userOrCarrierEdited = ") and (" + |
Amit Mahajan | 7005be8 | 2017-04-26 10:35:18 -0700 | [diff] [blame] | 3549 | IS_USER_EDITED + " or " + |
| 3550 | IS_CARRIER_EDITED + ")"; |
Amit Mahajan | 7b8040a | 2015-06-15 18:11:01 -0700 | [diff] [blame] | 3551 | String notUserOrCarrierEdited = ") and (" + |
Amit Mahajan | 7005be8 | 2017-04-26 10:35:18 -0700 | [diff] [blame] | 3552 | IS_NOT_USER_EDITED + " and " + |
| 3553 | IS_NOT_CARRIER_EDITED + ")"; |
| 3554 | String unedited = ") and " + IS_UNEDITED; |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 3555 | ContentValues cv = new ContentValues(); |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 3556 | cv.put(EDITED_STATUS, USER_DELETED); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3557 | |
| 3558 | checkPermission(); |
Jaikumar Ganesh | 8e1a4f9 | 2009-10-26 13:07:37 -0700 | [diff] [blame] | 3559 | |
Jordan Liu | e6f0bce | 2016-09-21 18:31:43 -0700 | [diff] [blame] | 3560 | SQLiteDatabase db = getWritableDatabase(); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3561 | int match = s_urlMatcher.match(url); |
| 3562 | switch (match) |
| 3563 | { |
Amit Mahajan | 7005be8 | 2017-04-26 10:35:18 -0700 | [diff] [blame] | 3564 | case URL_DELETE: |
| 3565 | { |
Amit Mahajan | bf7144e | 2017-08-29 11:39:48 -0700 | [diff] [blame] | 3566 | // Delete preferred APN for all subIds |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 3567 | deletePreferredApnId(getContext()); |
Amit Mahajan | 7005be8 | 2017-04-26 10:35:18 -0700 | [diff] [blame] | 3568 | // Delete unedited entries |
yuemingw | c4d40a7 | 2017-11-08 14:14:37 +0000 | [diff] [blame] | 3569 | count = db.delete(CARRIERS_TABLE, "(" + where + unedited + " and " + |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3570 | IS_NOT_OWNED_BY_DPC, whereArgs); |
Amit Mahajan | 7005be8 | 2017-04-26 10:35:18 -0700 | [diff] [blame] | 3571 | break; |
| 3572 | } |
| 3573 | |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3574 | case URL_TELEPHONY_USING_SUBID: |
| 3575 | { |
| 3576 | String subIdString = url.getLastPathSegment(); |
| 3577 | try { |
Wink Saville | 830a40f | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 3578 | subId = Integer.parseInt(subIdString); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3579 | } catch (NumberFormatException e) { |
| 3580 | loge("NumberFormatException" + e); |
| 3581 | throw new IllegalArgumentException("Invalid subId " + url); |
| 3582 | } |
| 3583 | if (DBG) log("subIdString = " + subIdString + " subId = " + subId); |
| 3584 | // FIXME use subId in query |
| 3585 | } |
| 3586 | //intentional fall through from above case |
| 3587 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3588 | case URL_TELEPHONY: |
| 3589 | { |
Amit Mahajan | 7b8040a | 2015-06-15 18:11:01 -0700 | [diff] [blame] | 3590 | // Delete user/carrier edited entries |
yuemingw | c4d40a7 | 2017-11-08 14:14:37 +0000 | [diff] [blame] | 3591 | count = db.delete(CARRIERS_TABLE, "(" + where + userOrCarrierEdited |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3592 | + " and " + IS_NOT_OWNED_BY_DPC, whereArgs); |
Amit Mahajan | 7b8040a | 2015-06-15 18:11:01 -0700 | [diff] [blame] | 3593 | // Otherwise mark as user deleted instead of deleting |
yuemingw | c4d40a7 | 2017-11-08 14:14:37 +0000 | [diff] [blame] | 3594 | count += db.update(CARRIERS_TABLE, cv, "(" + where + |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3595 | notUserOrCarrierEdited + " and " + IS_NOT_OWNED_BY_DPC, whereArgs); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3596 | break; |
| 3597 | } |
| 3598 | |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3599 | case URL_CURRENT_USING_SUBID: { |
| 3600 | String subIdString = url.getLastPathSegment(); |
| 3601 | try { |
Wink Saville | 830a40f | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 3602 | subId = Integer.parseInt(subIdString); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3603 | } catch (NumberFormatException e) { |
| 3604 | loge("NumberFormatException" + e); |
| 3605 | throw new IllegalArgumentException("Invalid subId " + url); |
| 3606 | } |
| 3607 | if (DBG) log("subIdString = " + subIdString + " subId = " + subId); |
| 3608 | // FIXME use subId in query |
| 3609 | } |
| 3610 | //intentional fall through from above case |
| 3611 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3612 | case URL_CURRENT: |
| 3613 | { |
Amit Mahajan | 7b8040a | 2015-06-15 18:11:01 -0700 | [diff] [blame] | 3614 | // Delete user/carrier edited entries |
yuemingw | c4d40a7 | 2017-11-08 14:14:37 +0000 | [diff] [blame] | 3615 | count = db.delete(CARRIERS_TABLE, "(" + where + userOrCarrierEdited |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3616 | + " and " + IS_NOT_OWNED_BY_DPC, whereArgs); |
Amit Mahajan | 7b8040a | 2015-06-15 18:11:01 -0700 | [diff] [blame] | 3617 | // Otherwise mark as user deleted instead of deleting |
yuemingw | c4d40a7 | 2017-11-08 14:14:37 +0000 | [diff] [blame] | 3618 | count += db.update(CARRIERS_TABLE, cv, "(" + where + |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3619 | notUserOrCarrierEdited + " and " + IS_NOT_OWNED_BY_DPC, whereArgs); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3620 | break; |
| 3621 | } |
Jaikumar Ganesh | 8e1a4f9 | 2009-10-26 13:07:37 -0700 | [diff] [blame] | 3622 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3623 | case URL_ID: |
| 3624 | { |
Amit Mahajan | 7b8040a | 2015-06-15 18:11:01 -0700 | [diff] [blame] | 3625 | // Delete user/carrier edited entries |
| 3626 | count = db.delete(CARRIERS_TABLE, |
yuemingw | c4d40a7 | 2017-11-08 14:14:37 +0000 | [diff] [blame] | 3627 | "(" + _ID + "=?" + userOrCarrierEdited + |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3628 | " and " + IS_NOT_OWNED_BY_DPC, |
Amit Mahajan | 7b8040a | 2015-06-15 18:11:01 -0700 | [diff] [blame] | 3629 | new String[] { url.getLastPathSegment() }); |
| 3630 | // Otherwise mark as user deleted instead of deleting |
| 3631 | count += db.update(CARRIERS_TABLE, cv, |
yuemingw | c4d40a7 | 2017-11-08 14:14:37 +0000 | [diff] [blame] | 3632 | "(" + _ID + "=?" + notUserOrCarrierEdited + |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3633 | " and " + IS_NOT_OWNED_BY_DPC, |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 3634 | new String[]{url.getLastPathSegment() }); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3635 | break; |
| 3636 | } |
| 3637 | |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3638 | case URL_RESTOREAPN_USING_SUBID: { |
| 3639 | String subIdString = url.getLastPathSegment(); |
| 3640 | try { |
Wink Saville | 830a40f | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 3641 | subId = Integer.parseInt(subIdString); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3642 | } catch (NumberFormatException e) { |
| 3643 | loge("NumberFormatException" + e); |
| 3644 | throw new IllegalArgumentException("Invalid subId " + url); |
| 3645 | } |
| 3646 | if (DBG) log("subIdString = " + subIdString + " subId = " + subId); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3647 | } |
Jordan Liu | c2b5247 | 2018-03-05 15:44:01 -0800 | [diff] [blame] | 3648 | // intentional fall through from above case |
| 3649 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3650 | case URL_RESTOREAPN: { |
| 3651 | count = 1; |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3652 | restoreDefaultAPN(subId); |
Jordan Liu | c2b5247 | 2018-03-05 15:44:01 -0800 | [diff] [blame] | 3653 | getContext().getContentResolver().notifyChange( |
| 3654 | Uri.withAppendedPath(CONTENT_URI, "restore/subId/" + subId), null, |
| 3655 | true, UserHandle.USER_ALL); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3656 | break; |
| 3657 | } |
| 3658 | |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3659 | case URL_PREFERAPN_USING_SUBID: |
| 3660 | case URL_PREFERAPN_NO_UPDATE_USING_SUBID: { |
| 3661 | String subIdString = url.getLastPathSegment(); |
| 3662 | try { |
Wink Saville | 830a40f | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 3663 | subId = Integer.parseInt(subIdString); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3664 | } catch (NumberFormatException e) { |
| 3665 | loge("NumberFormatException" + e); |
| 3666 | throw new IllegalArgumentException("Invalid subId " + url); |
| 3667 | } |
| 3668 | if (DBG) log("subIdString = " + subIdString + " subId = " + subId); |
| 3669 | } |
| 3670 | //intentional fall through from above case |
| 3671 | |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 3672 | case URL_PREFERAPN: |
Kazuhiro Ondo | d616ee6 | 2012-01-10 17:12:59 -0600 | [diff] [blame] | 3673 | case URL_PREFERAPN_NO_UPDATE: |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 3674 | { |
Amit Mahajan | bf7144e | 2017-08-29 11:39:48 -0700 | [diff] [blame] | 3675 | setPreferredApnId((long)INVALID_APN_ID, subId, true); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3676 | if ((match == URL_PREFERAPN) || (match == URL_PREFERAPN_USING_SUBID)) count = 1; |
| 3677 | break; |
| 3678 | } |
| 3679 | |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3680 | case URL_DPC_ID: { |
yuemingw | cd80d17 | 2018-01-15 14:08:55 +0000 | [diff] [blame] | 3681 | ensureCallingFromSystemOrPhoneUid("URL_DPC_ID called from non SYSTEM_UID."); |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3682 | |
| 3683 | // Only delete if owned by DPC. |
| 3684 | count = db.delete(CARRIERS_TABLE, "(" + _ID + "=?)" + " and " + IS_OWNED_BY_DPC, |
| 3685 | new String[] { url.getLastPathSegment() }); |
| 3686 | break; |
| 3687 | } |
| 3688 | |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3689 | case URL_SIMINFO: { |
| 3690 | count = db.delete(SIMINFO_TABLE, where, whereArgs); |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 3691 | break; |
| 3692 | } |
| 3693 | |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 3694 | case URL_UPDATE_DB: { |
| 3695 | updateApnDb(); |
| 3696 | count = 1; |
| 3697 | break; |
| 3698 | } |
| 3699 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3700 | default: { |
| 3701 | throw new UnsupportedOperationException("Cannot delete that URL: " + url); |
| 3702 | } |
| 3703 | } |
| 3704 | |
| 3705 | if (count > 0) { |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 3706 | getContext().getContentResolver().notifyChange(CONTENT_URI, null, |
Amith Yamasani | 887288c | 2014-11-06 09:01:20 -0800 | [diff] [blame] | 3707 | true, UserHandle.USER_ALL); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3708 | } |
| 3709 | |
| 3710 | return count; |
| 3711 | } |
| 3712 | |
| 3713 | @Override |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 3714 | public synchronized int update(Uri url, ContentValues values, String where, String[] whereArgs) |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3715 | { |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 3716 | int count = 0; |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3717 | int uriType = URL_UNKNOWN; |
Shishir Agrawal | de98fc1 | 2016-01-25 14:06:08 -0800 | [diff] [blame] | 3718 | int subId = SubscriptionManager.getDefaultSubscriptionId(); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3719 | |
| 3720 | checkPermission(); |
Cassie | a58ce71 | 2017-12-06 16:21:50 -0800 | [diff] [blame] | 3721 | syncBearerBitmaskAndNetworkTypeBitmask(values); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3722 | |
Jordan Liu | e6f0bce | 2016-09-21 18:31:43 -0700 | [diff] [blame] | 3723 | SQLiteDatabase db = getWritableDatabase(); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3724 | int match = s_urlMatcher.match(url); |
| 3725 | switch (match) |
| 3726 | { |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3727 | case URL_TELEPHONY_USING_SUBID: |
| 3728 | { |
| 3729 | String subIdString = url.getLastPathSegment(); |
| 3730 | try { |
Wink Saville | 830a40f | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 3731 | subId = Integer.parseInt(subIdString); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3732 | } catch (NumberFormatException e) { |
| 3733 | loge("NumberFormatException" + e); |
| 3734 | throw new IllegalArgumentException("Invalid subId " + url); |
| 3735 | } |
| 3736 | if (DBG) log("subIdString = " + subIdString + " subId = " + subId); |
| 3737 | //FIXME use subId in the query |
| 3738 | } |
| 3739 | //intentional fall through from above case |
| 3740 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3741 | case URL_TELEPHONY: |
| 3742 | { |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 3743 | if (!values.containsKey(EDITED_STATUS)) { |
| 3744 | values.put(EDITED_STATUS, CARRIER_EDITED); |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 3745 | } |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 3746 | |
Amit Mahajan | b80f733 | 2015-04-16 10:02:52 -0700 | [diff] [blame] | 3747 | // Replace on conflict so that if same APN is present in db with edited |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 3748 | // as UNEDITED or USER/CARRIER_DELETED, it is replaced with |
Amit Mahajan | b80f733 | 2015-04-16 10:02:52 -0700 | [diff] [blame] | 3749 | // edited USER/CARRIER_EDITED |
yuemingw | c4d40a7 | 2017-11-08 14:14:37 +0000 | [diff] [blame] | 3750 | count = db.updateWithOnConflict(CARRIERS_TABLE, values, where + |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3751 | " and " + IS_NOT_OWNED_BY_DPC, whereArgs, |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 3752 | SQLiteDatabase.CONFLICT_REPLACE); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3753 | break; |
| 3754 | } |
| 3755 | |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3756 | case URL_CURRENT_USING_SUBID: |
| 3757 | { |
| 3758 | String subIdString = url.getLastPathSegment(); |
| 3759 | try { |
Wink Saville | 830a40f | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 3760 | subId = Integer.parseInt(subIdString); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3761 | } catch (NumberFormatException e) { |
| 3762 | loge("NumberFormatException" + e); |
| 3763 | throw new IllegalArgumentException("Invalid subId " + url); |
| 3764 | } |
| 3765 | if (DBG) log("subIdString = " + subIdString + " subId = " + subId); |
| 3766 | //FIXME use subId in the query |
| 3767 | } |
| 3768 | //intentional fall through from above case |
| 3769 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3770 | case URL_CURRENT: |
| 3771 | { |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 3772 | if (!values.containsKey(EDITED_STATUS)) { |
| 3773 | values.put(EDITED_STATUS, CARRIER_EDITED); |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 3774 | } |
Amit Mahajan | b80f733 | 2015-04-16 10:02:52 -0700 | [diff] [blame] | 3775 | // Replace on conflict so that if same APN is present in db with edited |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 3776 | // as UNEDITED or USER/CARRIER_DELETED, it is replaced with |
Amit Mahajan | b80f733 | 2015-04-16 10:02:52 -0700 | [diff] [blame] | 3777 | // edited USER/CARRIER_EDITED |
yuemingw | c4d40a7 | 2017-11-08 14:14:37 +0000 | [diff] [blame] | 3778 | count = db.updateWithOnConflict(CARRIERS_TABLE, values, where + |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3779 | " and " + IS_NOT_OWNED_BY_DPC, |
yuemingw | c4d40a7 | 2017-11-08 14:14:37 +0000 | [diff] [blame] | 3780 | whereArgs, SQLiteDatabase.CONFLICT_REPLACE); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3781 | break; |
| 3782 | } |
| 3783 | |
| 3784 | case URL_ID: |
| 3785 | { |
Jordan Liu | 18d0d93 | 2018-03-28 18:33:37 -0700 | [diff] [blame] | 3786 | String rowID = url.getLastPathSegment(); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3787 | if (where != null || whereArgs != null) { |
| 3788 | throw new UnsupportedOperationException( |
| 3789 | "Cannot update URL " + url + " with a where clause"); |
| 3790 | } |
chen xu | 3e30394 | 2018-11-28 00:23:01 -0800 | [diff] [blame] | 3791 | if (!values.containsKey(EDITED_STATUS)) { |
| 3792 | values.put(EDITED_STATUS, CARRIER_EDITED); |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 3793 | } |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3794 | |
yuemingw | e0101b8 | 2017-12-13 21:49:09 +0000 | [diff] [blame] | 3795 | try { |
Jordan Liu | 18d0d93 | 2018-03-28 18:33:37 -0700 | [diff] [blame] | 3796 | count = db.updateWithOnConflict(CARRIERS_TABLE, values, _ID + "=?" + " and " + |
| 3797 | IS_NOT_OWNED_BY_DPC, new String[] { rowID }, |
| 3798 | SQLiteDatabase.CONFLICT_ABORT); |
yuemingw | e0101b8 | 2017-12-13 21:49:09 +0000 | [diff] [blame] | 3799 | } catch (SQLException e) { |
| 3800 | // Update failed which could be due to a conflict. Check if that is |
| 3801 | // the case and merge the entries |
Jordan Liu | 18d0d93 | 2018-03-28 18:33:37 -0700 | [diff] [blame] | 3802 | log("update: exception " + e); |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 3803 | Cursor oldRow = selectConflictingRow(db, CARRIERS_TABLE, values); |
yuemingw | e0101b8 | 2017-12-13 21:49:09 +0000 | [diff] [blame] | 3804 | if (oldRow != null) { |
| 3805 | ContentValues mergedValues = new ContentValues(); |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 3806 | mergeFieldsAndUpdateDb(db, CARRIERS_TABLE, oldRow, values, |
yuemingw | e0101b8 | 2017-12-13 21:49:09 +0000 | [diff] [blame] | 3807 | mergedValues, false, getContext()); |
| 3808 | oldRow.close(); |
Jordan Liu | 18d0d93 | 2018-03-28 18:33:37 -0700 | [diff] [blame] | 3809 | db.delete(CARRIERS_TABLE, _ID + "=?" + " and " + IS_NOT_OWNED_BY_DPC, |
| 3810 | new String[] { rowID }); |
yuemingw | e0101b8 | 2017-12-13 21:49:09 +0000 | [diff] [blame] | 3811 | } |
| 3812 | } |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3813 | break; |
| 3814 | } |
| 3815 | |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3816 | case URL_PREFERAPN_USING_SUBID: |
| 3817 | case URL_PREFERAPN_NO_UPDATE_USING_SUBID: |
| 3818 | { |
| 3819 | String subIdString = url.getLastPathSegment(); |
| 3820 | try { |
Wink Saville | 830a40f | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 3821 | subId = Integer.parseInt(subIdString); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3822 | } catch (NumberFormatException e) { |
| 3823 | loge("NumberFormatException" + e); |
| 3824 | throw new IllegalArgumentException("Invalid subId " + url); |
| 3825 | } |
| 3826 | if (DBG) log("subIdString = " + subIdString + " subId = " + subId); |
| 3827 | } |
| 3828 | |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 3829 | case URL_PREFERAPN: |
Kazuhiro Ondo | d616ee6 | 2012-01-10 17:12:59 -0600 | [diff] [blame] | 3830 | case URL_PREFERAPN_NO_UPDATE: |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 3831 | { |
| 3832 | if (values != null) { |
| 3833 | if (values.containsKey(COLUMN_APN_ID)) { |
Amit Mahajan | bf7144e | 2017-08-29 11:39:48 -0700 | [diff] [blame] | 3834 | setPreferredApnId(values.getAsLong(COLUMN_APN_ID), subId, true); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3835 | if ((match == URL_PREFERAPN) || |
| 3836 | (match == URL_PREFERAPN_USING_SUBID)) { |
| 3837 | count = 1; |
| 3838 | } |
John Huang | b1bc16d | 2009-03-24 18:26:28 -0700 | [diff] [blame] | 3839 | } |
| 3840 | } |
| 3841 | break; |
| 3842 | } |
| 3843 | |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3844 | case URL_DPC_ID: |
| 3845 | { |
yuemingw | cd80d17 | 2018-01-15 14:08:55 +0000 | [diff] [blame] | 3846 | ensureCallingFromSystemOrPhoneUid("URL_DPC_ID called from non SYSTEM_UID."); |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3847 | |
| 3848 | if (where != null || whereArgs != null) { |
| 3849 | throw new UnsupportedOperationException( |
| 3850 | "Cannot update URL " + url + " with a where clause"); |
| 3851 | } |
| 3852 | count = db.updateWithOnConflict(CARRIERS_TABLE, values, |
| 3853 | _ID + "=?" + " and " + IS_OWNED_BY_DPC, |
yuemingw | da96ee6 | 2018-02-21 14:58:04 +0000 | [diff] [blame] | 3854 | new String[] { url.getLastPathSegment() }, SQLiteDatabase.CONFLICT_IGNORE); |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3855 | break; |
| 3856 | } |
| 3857 | |
| 3858 | case URL_ENFORCE_MANAGED: { |
yuemingw | cd80d17 | 2018-01-15 14:08:55 +0000 | [diff] [blame] | 3859 | ensureCallingFromSystemOrPhoneUid( |
| 3860 | "URL_ENFORCE_MANAGED called from non SYSTEM_UID."); |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 3861 | if (values != null) { |
| 3862 | if (values.containsKey(ENFORCED_KEY)) { |
| 3863 | setManagedApnEnforced(values.getAsBoolean(ENFORCED_KEY)); |
| 3864 | count = 1; |
| 3865 | } |
| 3866 | } |
| 3867 | break; |
| 3868 | } |
| 3869 | |
chen xu | 195e2ec | 2018-10-02 18:42:41 -0700 | [diff] [blame] | 3870 | case URL_SIMINFO_USING_SUBID: |
| 3871 | String subIdString = url.getLastPathSegment(); |
| 3872 | try { |
| 3873 | subId = Integer.parseInt(subIdString); |
| 3874 | } catch (NumberFormatException e) { |
| 3875 | loge("NumberFormatException" + e); |
| 3876 | throw new IllegalArgumentException("Invalid subId " + url); |
| 3877 | } |
| 3878 | if (DBG) log("subIdString = " + subIdString + " subId = " + subId); |
| 3879 | if (where != null || whereArgs != null) { |
| 3880 | throw new UnsupportedOperationException( |
| 3881 | "Cannot update URL " + url + " with a where clause"); |
| 3882 | } |
| 3883 | count = db.update(SIMINFO_TABLE, values, _ID + "=?", |
| 3884 | new String[] { subIdString}); |
| 3885 | uriType = URL_SIMINFO_USING_SUBID; |
| 3886 | break; |
| 3887 | |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3888 | case URL_SIMINFO: { |
| 3889 | count = db.update(SIMINFO_TABLE, values, where, whereArgs); |
| 3890 | uriType = URL_SIMINFO; |
| 3891 | break; |
| 3892 | } |
| 3893 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3894 | default: { |
| 3895 | throw new UnsupportedOperationException("Cannot update that URL: " + url); |
| 3896 | } |
| 3897 | } |
| 3898 | |
| 3899 | if (count > 0) { |
chen xu | 1f8d589 | 2018-11-01 00:13:42 -0700 | [diff] [blame] | 3900 | boolean usingSubId = false; |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3901 | switch (uriType) { |
chen xu | 195e2ec | 2018-10-02 18:42:41 -0700 | [diff] [blame] | 3902 | case URL_SIMINFO_USING_SUBID: |
chen xu | 1f8d589 | 2018-11-01 00:13:42 -0700 | [diff] [blame] | 3903 | usingSubId = true; |
chen xu | 195e2ec | 2018-10-02 18:42:41 -0700 | [diff] [blame] | 3904 | // intentional fall through from above case |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3905 | case URL_SIMINFO: |
chen xu | 4590bd7 | 2018-10-18 14:07:02 -0700 | [diff] [blame] | 3906 | // skip notifying descendant URLs to avoid unneccessary wake up. |
| 3907 | // If not set, any change to SIMINFO will notify observers which listens to |
| 3908 | // specific field of SIMINFO. |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3909 | getContext().getContentResolver().notifyChange( |
changbetty | 004eceb | 2019-12-02 15:53:49 +0800 | [diff] [blame] | 3910 | Telephony.SimInfo.CONTENT_URI, null, |
chen xu | 4590bd7 | 2018-10-18 14:07:02 -0700 | [diff] [blame] | 3911 | ContentResolver.NOTIFY_SYNC_TO_NETWORK |
| 3912 | | ContentResolver.NOTIFY_SKIP_NOTIFY_FOR_DESCENDANTS, |
| 3913 | UserHandle.USER_ALL); |
chen xu | 195e2ec | 2018-10-02 18:42:41 -0700 | [diff] [blame] | 3914 | // notify observers on specific user settings changes. |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 3915 | if (values.containsKey(Telephony.SimInfo.COLUMN_WFC_IMS_ENABLED)) { |
chen xu | 195e2ec | 2018-10-02 18:42:41 -0700 | [diff] [blame] | 3916 | getContext().getContentResolver().notifyChange( |
chen xu | 1f8d589 | 2018-11-01 00:13:42 -0700 | [diff] [blame] | 3917 | getNotifyContentUri(SubscriptionManager.WFC_ENABLED_CONTENT_URI, |
| 3918 | usingSubId, subId), null, true, UserHandle.USER_ALL); |
chen xu | 195e2ec | 2018-10-02 18:42:41 -0700 | [diff] [blame] | 3919 | } |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 3920 | if (values.containsKey(Telephony.SimInfo.COLUMN_ENHANCED_4G_MODE_ENABLED)) { |
chen xu | 195e2ec | 2018-10-02 18:42:41 -0700 | [diff] [blame] | 3921 | getContext().getContentResolver().notifyChange( |
chen xu | 1f8d589 | 2018-11-01 00:13:42 -0700 | [diff] [blame] | 3922 | getNotifyContentUri(SubscriptionManager |
| 3923 | .ADVANCED_CALLING_ENABLED_CONTENT_URI, |
| 3924 | usingSubId, subId), null, true, UserHandle.USER_ALL); |
| 3925 | } |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 3926 | if (values.containsKey(Telephony.SimInfo.COLUMN_VT_IMS_ENABLED)) { |
chen xu | 1f8d589 | 2018-11-01 00:13:42 -0700 | [diff] [blame] | 3927 | getContext().getContentResolver().notifyChange( |
| 3928 | getNotifyContentUri(SubscriptionManager.VT_ENABLED_CONTENT_URI, |
| 3929 | usingSubId, subId), null, true, UserHandle.USER_ALL); |
| 3930 | } |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 3931 | if (values.containsKey(Telephony.SimInfo.COLUMN_WFC_IMS_MODE)) { |
chen xu | 1f8d589 | 2018-11-01 00:13:42 -0700 | [diff] [blame] | 3932 | getContext().getContentResolver().notifyChange( |
| 3933 | getNotifyContentUri(SubscriptionManager.WFC_MODE_CONTENT_URI, |
| 3934 | usingSubId, subId), null, true, UserHandle.USER_ALL); |
| 3935 | } |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 3936 | if (values.containsKey(Telephony.SimInfo.COLUMN_WFC_IMS_ROAMING_MODE)) { |
chen xu | 1f8d589 | 2018-11-01 00:13:42 -0700 | [diff] [blame] | 3937 | getContext().getContentResolver().notifyChange(getNotifyContentUri( |
| 3938 | SubscriptionManager.WFC_ROAMING_MODE_CONTENT_URI, |
| 3939 | usingSubId, subId), null, true, UserHandle.USER_ALL); |
| 3940 | } |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 3941 | if (values.containsKey(Telephony.SimInfo.COLUMN_WFC_IMS_ROAMING_ENABLED)) { |
chen xu | 1f8d589 | 2018-11-01 00:13:42 -0700 | [diff] [blame] | 3942 | getContext().getContentResolver().notifyChange(getNotifyContentUri( |
| 3943 | SubscriptionManager.WFC_ROAMING_ENABLED_CONTENT_URI, |
| 3944 | usingSubId, subId), null, true, UserHandle.USER_ALL); |
chen xu | 195e2ec | 2018-10-02 18:42:41 -0700 | [diff] [blame] | 3945 | } |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 3946 | if (values.containsKey(Telephony.SimInfo.COLUMN_IMS_RCS_UCE_ENABLED)) { |
Brad Ebinger | 748c762 | 2020-01-22 16:12:04 -0800 | [diff] [blame] | 3947 | getContext().getContentResolver().notifyChange(getNotifyContentUri( |
| 3948 | Uri.withAppendedPath(Telephony.SimInfo.CONTENT_URI, |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 3949 | Telephony.SimInfo.COLUMN_IMS_RCS_UCE_ENABLED), usingSubId, subId), |
Brad Ebinger | 748c762 | 2020-01-22 16:12:04 -0800 | [diff] [blame] | 3950 | null, true, UserHandle.USER_ALL); |
| 3951 | } |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3952 | break; |
| 3953 | default: |
| 3954 | getContext().getContentResolver().notifyChange( |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 3955 | CONTENT_URI, null, true, UserHandle.USER_ALL); |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 3956 | } |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3957 | } |
| 3958 | |
| 3959 | return count; |
| 3960 | } |
| 3961 | |
chen xu | 1f8d589 | 2018-11-01 00:13:42 -0700 | [diff] [blame] | 3962 | private static Uri getNotifyContentUri(Uri uri, boolean usingSubId, int subId) { |
| 3963 | return (usingSubId) ? Uri.withAppendedPath(uri, "" + subId) : uri; |
| 3964 | } |
| 3965 | |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3966 | private void checkPermission() { |
Shishir Agrawal | acf787b | 2014-07-14 17:13:51 -0700 | [diff] [blame] | 3967 | int status = getContext().checkCallingOrSelfPermission( |
| 3968 | "android.permission.WRITE_APN_SETTINGS"); |
| 3969 | if (status == PackageManager.PERMISSION_GRANTED) { |
| 3970 | return; |
| 3971 | } |
| 3972 | |
| 3973 | PackageManager packageManager = getContext().getPackageManager(); |
| 3974 | String[] packages = packageManager.getPackagesForUid(Binder.getCallingUid()); |
| 3975 | |
| 3976 | TelephonyManager telephonyManager = |
| 3977 | (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE); |
| 3978 | for (String pkg : packages) { |
Cassie | 29b3b29 | 2018-09-24 09:26:51 -0700 | [diff] [blame] | 3979 | if (telephonyManager.checkCarrierPrivilegesForPackageAnyPhone(pkg) == |
Shishir Agrawal | acf787b | 2014-07-14 17:13:51 -0700 | [diff] [blame] | 3980 | TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 3981 | return; |
| 3982 | } |
| 3983 | } |
Hall Liu | 7ee663d | 2019-11-21 16:30:47 -0800 | [diff] [blame] | 3984 | |
Hall Liu | 7ee663d | 2019-11-21 16:30:47 -0800 | [diff] [blame] | 3985 | |
| 3986 | throw new SecurityException("No permission to access APN settings"); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 3987 | } |
| 3988 | |
Hall Liu | 018f8b1 | 2020-02-25 15:58:56 -0800 | [diff] [blame] | 3989 | /** |
| 3990 | * Check permission to query the database based on PlatformCompat settings -- if the compat |
| 3991 | * change is enabled, check WRITE_APN_SETTINGS or carrier privs for all queries. Otherwise, |
| 3992 | * use the legacy checkQueryPermission method to see if the query should be allowed. |
| 3993 | */ |
| 3994 | private void checkPermissionCompat(int match, String[] projectionIn) { |
| 3995 | boolean useNewBehavior = CompatChanges.isChangeEnabled( |
| 3996 | Telephony.Carriers.APN_READING_PERMISSION_CHANGE_ID, |
| 3997 | Binder.getCallingUid()); |
| 3998 | |
| 3999 | if (!useNewBehavior) { |
| 4000 | log("Using old permission behavior for telephony provider compat"); |
| 4001 | checkQueryPermission(match, projectionIn); |
| 4002 | } else { |
| 4003 | checkPermission(); |
| 4004 | } |
| 4005 | } |
| 4006 | |
| 4007 | private void checkQueryPermission(int match, String[] projectionIn) { |
| 4008 | if (match != URL_SIMINFO) { |
| 4009 | if (projectionIn != null) { |
| 4010 | for (String column : projectionIn) { |
| 4011 | if (TYPE.equals(column) || |
| 4012 | MMSC.equals(column) || |
| 4013 | MMSPROXY.equals(column) || |
| 4014 | MMSPORT.equals(column) || |
| 4015 | MVNO_TYPE.equals(column) || |
| 4016 | MVNO_MATCH_DATA.equals(column) || |
| 4017 | APN.equals(column)) { |
| 4018 | // noop |
| 4019 | } else { |
| 4020 | checkPermission(); |
| 4021 | break; |
| 4022 | } |
| 4023 | } |
| 4024 | } else { |
| 4025 | // null returns all columns, so need permission check |
| 4026 | checkPermission(); |
| 4027 | } |
| 4028 | } |
| 4029 | } |
| 4030 | |
Wink Saville | d7c9350 | 2011-06-04 07:17:01 -0700 | [diff] [blame] | 4031 | private DatabaseHelper mOpenHelper; |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 4032 | |
Wink Saville | 830a40f | 2014-10-23 10:16:47 -0700 | [diff] [blame] | 4033 | private void restoreDefaultAPN(int subId) { |
Jordan Liu | e6f0bce | 2016-09-21 18:31:43 -0700 | [diff] [blame] | 4034 | SQLiteDatabase db = getWritableDatabase(); |
Chaitanya Saggurthi | 58ab3ad | 2017-12-05 22:09:09 +0900 | [diff] [blame] | 4035 | TelephonyManager telephonyManager = |
| 4036 | (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE); |
| 4037 | String where = null; |
| 4038 | if (telephonyManager.getPhoneCount() > 1) { |
| 4039 | where = getWhereClauseForRestoreDefaultApn(db, subId); |
| 4040 | } |
| 4041 | if (TextUtils.isEmpty(where)) { |
| 4042 | where = IS_NOT_OWNED_BY_DPC; |
| 4043 | } |
| 4044 | log("restoreDefaultAPN: where: " + where); |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 4045 | |
Hyejin Kim | cfdb743 | 2013-02-16 00:58:37 +0900 | [diff] [blame] | 4046 | try { |
Chaitanya Saggurthi | 58ab3ad | 2017-12-05 22:09:09 +0900 | [diff] [blame] | 4047 | db.delete(CARRIERS_TABLE, where, null); |
Hyejin Kim | cfdb743 | 2013-02-16 00:58:37 +0900 | [diff] [blame] | 4048 | } catch (SQLException e) { |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 4049 | loge("got exception when deleting to restore: " + e); |
Hyejin Kim | cfdb743 | 2013-02-16 00:58:37 +0900 | [diff] [blame] | 4050 | } |
Amit Mahajan | 262ed50 | 2016-05-12 16:01:43 -0700 | [diff] [blame] | 4051 | |
| 4052 | // delete preferred apn ids and preferred apns (both stored in diff SharedPref) for all |
| 4053 | // subIds |
| 4054 | SharedPreferences spApnId = getContext().getSharedPreferences(PREF_FILE_APN, |
| 4055 | Context.MODE_PRIVATE); |
| 4056 | SharedPreferences.Editor editorApnId = spApnId.edit(); |
| 4057 | editorApnId.clear(); |
| 4058 | editorApnId.apply(); |
| 4059 | |
| 4060 | SharedPreferences spApn = getContext().getSharedPreferences(PREF_FILE_FULL_APN, |
| 4061 | Context.MODE_PRIVATE); |
| 4062 | SharedPreferences.Editor editorApn = spApn.edit(); |
| 4063 | editorApn.clear(); |
| 4064 | editorApn.apply(); |
| 4065 | |
Jordan Liu | 3de76f8 | 2017-05-15 15:21:01 -0700 | [diff] [blame] | 4066 | if (apnSourceServiceExists(getContext())) { |
Jordan Liu | 11c113e | 2018-11-13 12:19:11 -0800 | [diff] [blame] | 4067 | restoreApnsWithService(subId); |
Jordan Liu | 3de76f8 | 2017-05-15 15:21:01 -0700 | [diff] [blame] | 4068 | } else { |
| 4069 | initDatabaseWithDatabaseHelper(db); |
| 4070 | } |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 4071 | } |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 4072 | |
Chaitanya Saggurthi | 58ab3ad | 2017-12-05 22:09:09 +0900 | [diff] [blame] | 4073 | private String getWhereClauseForRestoreDefaultApn(SQLiteDatabase db, int subId) { |
Chaitanya Saggurthi | 58ab3ad | 2017-12-05 22:09:09 +0900 | [diff] [blame] | 4074 | TelephonyManager telephonyManager = |
changbetty | faa1d7a | 2019-11-26 18:06:24 +0800 | [diff] [blame] | 4075 | getContext().getSystemService(TelephonyManager.class).createForSubscriptionId(subId); |
| 4076 | String simOperator = telephonyManager.getSimOperator(); |
Chaitanya Saggurthi | 58ab3ad | 2017-12-05 22:09:09 +0900 | [diff] [blame] | 4077 | Cursor cursor = db.query(CARRIERS_TABLE, new String[] {MVNO_TYPE, MVNO_MATCH_DATA}, |
| 4078 | NUMERIC + "='" + simOperator + "'", null, null, null, DEFAULT_SORT_ORDER); |
| 4079 | String where = null; |
| 4080 | |
| 4081 | if (cursor != null) { |
| 4082 | cursor.moveToFirst(); |
| 4083 | while (!cursor.isAfterLast()) { |
| 4084 | String mvnoType = cursor.getString(0 /* MVNO_TYPE index */); |
| 4085 | String mvnoMatchData = cursor.getString(1 /* MVNO_MATCH_DATA index */); |
| 4086 | if (!TextUtils.isEmpty(mvnoType) && !TextUtils.isEmpty(mvnoMatchData) |
changbetty | 2351c17 | 2020-02-25 18:25:44 +0800 | [diff] [blame] | 4087 | && telephonyManager.matchesCurrentSimOperator(simOperator, |
changbetty | a98edab | 2019-12-06 18:26:12 +0800 | [diff] [blame] | 4088 | getMvnoTypeIntFromString(mvnoType), mvnoMatchData)) { |
Chaitanya Saggurthi | 58ab3ad | 2017-12-05 22:09:09 +0900 | [diff] [blame] | 4089 | where = NUMERIC + "='" + simOperator + "'" |
| 4090 | + " AND " + MVNO_TYPE + "='" + mvnoType + "'" |
| 4091 | + " AND " + MVNO_MATCH_DATA + "='" + mvnoMatchData + "'" |
| 4092 | + " AND " + IS_NOT_OWNED_BY_DPC; |
| 4093 | break; |
| 4094 | } |
| 4095 | cursor.moveToNext(); |
| 4096 | } |
| 4097 | cursor.close(); |
| 4098 | |
| 4099 | if (TextUtils.isEmpty(where)) { |
| 4100 | where = NUMERIC + "='" + simOperator + "'" |
| 4101 | + " AND (" + MVNO_TYPE + "='' OR " + MVNO_MATCH_DATA + "='')" |
| 4102 | + " AND " + IS_NOT_OWNED_BY_DPC; |
| 4103 | } |
| 4104 | } |
xiangyu.deng | 233d88c | 2021-07-16 14:09:40 +0800 | [diff] [blame] | 4105 | |
| 4106 | where = NUMERIC + "='" + simOperator + "'" |
| 4107 | + " AND " + IS_NOT_OWNED_BY_DPC; |
Chaitanya Saggurthi | 58ab3ad | 2017-12-05 22:09:09 +0900 | [diff] [blame] | 4108 | return where; |
| 4109 | } |
| 4110 | |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 4111 | private synchronized void updateApnDb() { |
Jordan Liu | 3de76f8 | 2017-05-15 15:21:01 -0700 | [diff] [blame] | 4112 | if (apnSourceServiceExists(getContext())) { |
| 4113 | loge("called updateApnDb when apn source service exists"); |
| 4114 | return; |
| 4115 | } |
| 4116 | |
Jordan Liu | e6f0bce | 2016-09-21 18:31:43 -0700 | [diff] [blame] | 4117 | if (!needApnDbUpdate()) { |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 4118 | log("Skipping apn db update since apn-conf has not changed."); |
| 4119 | return; |
| 4120 | } |
| 4121 | |
Jordan Liu | e6f0bce | 2016-09-21 18:31:43 -0700 | [diff] [blame] | 4122 | SQLiteDatabase db = getWritableDatabase(); |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 4123 | |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 4124 | // Delete preferred APN for all subIds |
Amit Mahajan | 9e7e3bb | 2019-08-26 12:35:32 -0700 | [diff] [blame] | 4125 | deletePreferredApnId(getContext()); |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 4126 | |
| 4127 | // Delete entries in db |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 4128 | try { |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 4129 | if (VDBG) log("updateApnDb: deleting edited=UNEDITED entries"); |
yuemingw | c41e5c8 | 2017-11-09 13:30:33 +0000 | [diff] [blame] | 4130 | db.delete(CARRIERS_TABLE, IS_UNEDITED + " and " + IS_NOT_OWNED_BY_DPC, null); |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 4131 | } catch (SQLException e) { |
| 4132 | loge("got exception when deleting to update: " + e); |
| 4133 | } |
| 4134 | |
Jordan Liu | e6f0bce | 2016-09-21 18:31:43 -0700 | [diff] [blame] | 4135 | initDatabaseWithDatabaseHelper(db); |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 4136 | |
Hall Liu | 5479f4d | 2018-07-14 00:31:13 +0000 | [diff] [blame] | 4137 | // Notify listeners of DB change since DB has been updated |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 4138 | getContext().getContentResolver().notifyChange( |
Amit Mahajan | 28a5d00 | 2016-03-02 11:34:28 -0800 | [diff] [blame] | 4139 | CONTENT_URI, null, true, UserHandle.USER_ALL); |
Amit Mahajan | bc1edc2 | 2015-04-09 13:53:33 -0700 | [diff] [blame] | 4140 | |
Amit Mahajan | 3f2e68a | 2015-02-27 15:40:41 -0800 | [diff] [blame] | 4141 | } |
| 4142 | |
Hall Liu | 5479f4d | 2018-07-14 00:31:13 +0000 | [diff] [blame] | 4143 | public static void fillInMccMncStringAtCursor(Context context, SQLiteDatabase db, Cursor c) { |
| 4144 | int mcc, mnc; |
| 4145 | String subId; |
| 4146 | try { |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 4147 | mcc = c.getInt(c.getColumnIndexOrThrow(Telephony.SimInfo.COLUMN_MCC)); |
| 4148 | mnc = c.getInt(c.getColumnIndexOrThrow(Telephony.SimInfo.COLUMN_MNC)); |
Hall Liu | 5479f4d | 2018-07-14 00:31:13 +0000 | [diff] [blame] | 4149 | subId = c.getString(c.getColumnIndexOrThrow( |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 4150 | Telephony.SimInfo.COLUMN_UNIQUE_KEY_SUBSCRIPTION_ID)); |
Hall Liu | 5479f4d | 2018-07-14 00:31:13 +0000 | [diff] [blame] | 4151 | } catch (IllegalArgumentException e) { |
| 4152 | Log.e(TAG, "Possible database corruption -- some columns not found."); |
| 4153 | return; |
| 4154 | } |
| 4155 | |
| 4156 | String mccString = String.format(Locale.getDefault(), "%03d", mcc); |
| 4157 | String mncString = getBestStringMnc(context, mccString, mnc); |
| 4158 | ContentValues cv = new ContentValues(2); |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 4159 | cv.put(Telephony.SimInfo.COLUMN_MCC_STRING, mccString); |
| 4160 | cv.put(Telephony.SimInfo.COLUMN_MNC_STRING, mncString); |
Hall Liu | 5479f4d | 2018-07-14 00:31:13 +0000 | [diff] [blame] | 4161 | db.update(SIMINFO_TABLE, cv, |
Peter Wang | b8e281d | 2020-01-31 18:50:00 -0800 | [diff] [blame] | 4162 | Telephony.SimInfo.COLUMN_UNIQUE_KEY_SUBSCRIPTION_ID + "=?", |
Hall Liu | 5479f4d | 2018-07-14 00:31:13 +0000 | [diff] [blame] | 4163 | new String[]{subId}); |
| 4164 | } |
| 4165 | |
| 4166 | /* |
| 4167 | * Find the best string-form mnc by looking up possibilities in the carrier id db. |
| 4168 | * Default to the three-digit version if neither/both are valid. |
| 4169 | */ |
| 4170 | private static String getBestStringMnc(Context context, String mcc, int mnc) { |
| 4171 | if (mnc >= 100 && mnc <= 999) { |
| 4172 | return String.valueOf(mnc); |
| 4173 | } |
| 4174 | String twoDigitMnc = String.format(Locale.getDefault(), "%02d", mnc); |
| 4175 | String threeDigitMnc = "0" + twoDigitMnc; |
| 4176 | |
| 4177 | try ( |
| 4178 | Cursor twoDigitMncCursor = context.getContentResolver().query( |
| 4179 | Telephony.CarrierId.All.CONTENT_URI, |
| 4180 | /* projection */ null, |
| 4181 | /* selection */ Telephony.CarrierId.All.MCCMNC + "=?", |
| 4182 | /* selectionArgs */ new String[]{mcc + twoDigitMnc}, null) |
| 4183 | ) { |
| 4184 | if (twoDigitMncCursor.getCount() > 0) { |
| 4185 | return twoDigitMnc; |
| 4186 | } |
| 4187 | return threeDigitMnc; |
| 4188 | } |
| 4189 | } |
| 4190 | |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 4191 | /** |
Cassie | a58ce71 | 2017-12-06 16:21:50 -0800 | [diff] [blame] | 4192 | * Sync the bearer bitmask and network type bitmask when inserting and updating. |
| 4193 | * Since bearerBitmask is deprecating, map the networkTypeBitmask to bearerBitmask if |
| 4194 | * networkTypeBitmask was provided. But if networkTypeBitmask was not provided, map the |
| 4195 | * bearerBitmask to networkTypeBitmask. |
| 4196 | */ |
| 4197 | private static void syncBearerBitmaskAndNetworkTypeBitmask(ContentValues values) { |
| 4198 | if (values.containsKey(NETWORK_TYPE_BITMASK)) { |
SongFerngWang | 64fb3dd | 2019-12-02 20:59:47 +0800 | [diff] [blame] | 4199 | int convertedBitmask = convertNetworkTypeBitmaskToBearerBitmask( |
Cassie | a58ce71 | 2017-12-06 16:21:50 -0800 | [diff] [blame] | 4200 | values.getAsInteger(NETWORK_TYPE_BITMASK)); |
| 4201 | if (values.containsKey(BEARER_BITMASK) |
| 4202 | && convertedBitmask != values.getAsInteger(BEARER_BITMASK)) { |
| 4203 | loge("Network type bitmask and bearer bitmask are not compatible."); |
| 4204 | } |
SongFerngWang | 64fb3dd | 2019-12-02 20:59:47 +0800 | [diff] [blame] | 4205 | values.put(BEARER_BITMASK, convertNetworkTypeBitmaskToBearerBitmask( |
Cassie | a58ce71 | 2017-12-06 16:21:50 -0800 | [diff] [blame] | 4206 | values.getAsInteger(NETWORK_TYPE_BITMASK))); |
| 4207 | } else { |
| 4208 | if (values.containsKey(BEARER_BITMASK)) { |
SongFerngWang | 64fb3dd | 2019-12-02 20:59:47 +0800 | [diff] [blame] | 4209 | int convertedBitmask = convertBearerBitmaskToNetworkTypeBitmask( |
Cassie | a58ce71 | 2017-12-06 16:21:50 -0800 | [diff] [blame] | 4210 | values.getAsInteger(BEARER_BITMASK)); |
| 4211 | values.put(NETWORK_TYPE_BITMASK, convertedBitmask); |
| 4212 | } |
| 4213 | } |
| 4214 | } |
| 4215 | |
| 4216 | /** |
Wink Saville | e84c0a8 | 2014-06-09 21:04:39 -0700 | [diff] [blame] | 4217 | * Log with debug |
| 4218 | * |
| 4219 | * @param s is string log |
| 4220 | */ |
| 4221 | private static void log(String s) { |
| 4222 | Log.d(TAG, s); |
| 4223 | } |
| 4224 | |
| 4225 | private static void loge(String s) { |
| 4226 | Log.e(TAG, s); |
| 4227 | } |
zoey chen | 715880a | 2019-11-12 18:47:02 +0800 | [diff] [blame] | 4228 | |
| 4229 | private static int getMvnoTypeIntFromString(String mvnoType) { |
| 4230 | String mvnoTypeString = TextUtils.isEmpty(mvnoType) ? mvnoType : mvnoType.toLowerCase(); |
| 4231 | Integer mvnoTypeInt = MVNO_TYPE_STRING_MAP.get(mvnoTypeString); |
| 4232 | return mvnoTypeInt == null ? UNSPECIFIED_INT : mvnoTypeInt; |
| 4233 | } |
SongFerngWang | 64fb3dd | 2019-12-02 20:59:47 +0800 | [diff] [blame] | 4234 | |
| 4235 | private static int getBitmaskFromString(String bearerList) { |
| 4236 | String[] bearers = bearerList.split("\\|"); |
| 4237 | int bearerBitmask = 0; |
| 4238 | for (String bearer : bearers) { |
| 4239 | int bearerInt = 0; |
| 4240 | try { |
| 4241 | bearerInt = Integer.parseInt(bearer.trim()); |
| 4242 | } catch (NumberFormatException nfe) { |
| 4243 | return 0; |
| 4244 | } |
| 4245 | |
| 4246 | if (bearerInt == 0) { |
| 4247 | return 0; |
| 4248 | } |
| 4249 | bearerBitmask |= getBitmaskForTech(bearerInt); |
| 4250 | } |
| 4251 | return bearerBitmask; |
| 4252 | } |
| 4253 | |
| 4254 | /** |
| 4255 | * Transform RIL radio technology value to Network |
| 4256 | * type bitmask{@link android.telephony.TelephonyManager.NetworkTypeBitMask}. |
| 4257 | * |
| 4258 | * @param rat The RIL radio technology. |
| 4259 | * @return The network type |
| 4260 | * bitmask{@link android.telephony.TelephonyManager.NetworkTypeBitMask}. |
| 4261 | */ |
| 4262 | private static int rilRadioTechnologyToNetworkTypeBitmask(int rat) { |
| 4263 | switch (rat) { |
| 4264 | case RIL_RADIO_TECHNOLOGY_GPRS: |
| 4265 | return (int) TelephonyManager.NETWORK_TYPE_BITMASK_GPRS; |
| 4266 | case RIL_RADIO_TECHNOLOGY_EDGE: |
| 4267 | return (int) TelephonyManager.NETWORK_TYPE_BITMASK_EDGE; |
| 4268 | case RIL_RADIO_TECHNOLOGY_UMTS: |
| 4269 | return (int) TelephonyManager.NETWORK_TYPE_BITMASK_UMTS; |
| 4270 | case RIL_RADIO_TECHNOLOGY_HSDPA: |
| 4271 | return (int) TelephonyManager.NETWORK_TYPE_BITMASK_HSDPA; |
| 4272 | case RIL_RADIO_TECHNOLOGY_HSUPA: |
| 4273 | return (int) TelephonyManager.NETWORK_TYPE_BITMASK_HSUPA; |
| 4274 | case RIL_RADIO_TECHNOLOGY_HSPA: |
| 4275 | return (int) TelephonyManager.NETWORK_TYPE_BITMASK_HSPA; |
| 4276 | case RIL_RADIO_TECHNOLOGY_IS95A: |
| 4277 | case RIL_RADIO_TECHNOLOGY_IS95B: |
| 4278 | return (int) TelephonyManager.NETWORK_TYPE_BITMASK_CDMA; |
| 4279 | case RIL_RADIO_TECHNOLOGY_1xRTT: |
| 4280 | return (int) TelephonyManager.NETWORK_TYPE_BITMASK_1xRTT; |
| 4281 | case RIL_RADIO_TECHNOLOGY_EVDO_0: |
| 4282 | return (int) TelephonyManager.NETWORK_TYPE_BITMASK_EVDO_0; |
| 4283 | case RIL_RADIO_TECHNOLOGY_EVDO_A: |
| 4284 | return (int) TelephonyManager.NETWORK_TYPE_BITMASK_EVDO_A; |
| 4285 | case RIL_RADIO_TECHNOLOGY_EVDO_B: |
| 4286 | return (int) TelephonyManager.NETWORK_TYPE_BITMASK_EVDO_B; |
| 4287 | case RIL_RADIO_TECHNOLOGY_EHRPD: |
| 4288 | return (int) TelephonyManager.NETWORK_TYPE_BITMASK_EHRPD; |
| 4289 | case RIL_RADIO_TECHNOLOGY_LTE: |
| 4290 | return (int) TelephonyManager.NETWORK_TYPE_BITMASK_LTE; |
| 4291 | case RIL_RADIO_TECHNOLOGY_HSPAP: |
| 4292 | return (int) TelephonyManager.NETWORK_TYPE_BITMASK_HSPAP; |
| 4293 | case RIL_RADIO_TECHNOLOGY_GSM: |
| 4294 | return (int) TelephonyManager.NETWORK_TYPE_BITMASK_GSM; |
| 4295 | case RIL_RADIO_TECHNOLOGY_TD_SCDMA: |
| 4296 | return (int) TelephonyManager.NETWORK_TYPE_BITMASK_TD_SCDMA; |
| 4297 | case RIL_RADIO_TECHNOLOGY_IWLAN: |
| 4298 | return (int) TelephonyManager.NETWORK_TYPE_BITMASK_IWLAN; |
| 4299 | case RIL_RADIO_TECHNOLOGY_LTE_CA: |
| 4300 | return (int) TelephonyManager.NETWORK_TYPE_BITMASK_LTE_CA; |
| 4301 | case RIL_RADIO_TECHNOLOGY_NR: |
| 4302 | return (int) TelephonyManager.NETWORK_TYPE_BITMASK_NR; |
| 4303 | default: |
| 4304 | return (int) TelephonyManager.NETWORK_TYPE_BITMASK_UNKNOWN; |
| 4305 | } |
| 4306 | } |
| 4307 | |
| 4308 | /** |
| 4309 | * Convert network type bitmask to bearer bitmask. |
| 4310 | * |
| 4311 | * @param networkTypeBitmask The network type bitmask value |
| 4312 | * @return The bearer bitmask value. |
| 4313 | */ |
| 4314 | private static int convertNetworkTypeBitmaskToBearerBitmask(int networkTypeBitmask) { |
| 4315 | if (networkTypeBitmask == 0) { |
| 4316 | return 0; |
| 4317 | } |
| 4318 | |
| 4319 | int bearerBitmask = 0; |
| 4320 | for (int bearerInt = 0; bearerInt < NEXT_RIL_RADIO_TECHNOLOGY; bearerInt++) { |
| 4321 | if (bitmaskHasTarget(networkTypeBitmask, |
| 4322 | rilRadioTechnologyToNetworkTypeBitmask(bearerInt))) { |
| 4323 | bearerBitmask |= getBitmaskForTech(bearerInt); |
| 4324 | } |
| 4325 | } |
| 4326 | return bearerBitmask; |
| 4327 | } |
| 4328 | |
| 4329 | /** |
| 4330 | * Convert bearer bitmask to network type bitmask. |
| 4331 | * |
| 4332 | * @param bearerBitmask The bearer bitmask value. |
| 4333 | * @return The network type bitmask value. |
| 4334 | */ |
| 4335 | private static int convertBearerBitmaskToNetworkTypeBitmask(int bearerBitmask) { |
| 4336 | if (bearerBitmask == 0) { |
| 4337 | return 0; |
| 4338 | } |
| 4339 | |
| 4340 | int networkTypeBitmask = 0; |
| 4341 | for (int bearerUnitInt = 0; bearerUnitInt < NEXT_RIL_RADIO_TECHNOLOGY; bearerUnitInt++) { |
| 4342 | int bearerUnitBitmask = getBitmaskForTech(bearerUnitInt); |
| 4343 | if (bitmaskHasTarget(bearerBitmask, bearerUnitBitmask)) { |
| 4344 | networkTypeBitmask |= rilRadioTechnologyToNetworkTypeBitmask(bearerUnitInt); |
| 4345 | } |
| 4346 | } |
| 4347 | return networkTypeBitmask; |
| 4348 | } |
| 4349 | |
| 4350 | private static boolean bitmaskHasTarget(int bearerBitmask, int targetBitmask) { |
| 4351 | if (bearerBitmask == 0) { |
| 4352 | return true; |
| 4353 | } else if (targetBitmask != 0) { |
| 4354 | return ((bearerBitmask & targetBitmask) != 0); |
| 4355 | } |
| 4356 | return false; |
| 4357 | } |
| 4358 | |
| 4359 | private static int getBitmaskForTech(int radioTech) { |
| 4360 | if (radioTech >= 1) { |
| 4361 | return (1 << (radioTech - 1)); |
| 4362 | } |
| 4363 | return 0; |
| 4364 | } |
The Android Open Source Project | 7236c3a | 2009-03-03 19:32:44 -0800 | [diff] [blame] | 4365 | } |