Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (c) 2015, The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 17 | package com.android.phone; |
| 18 | |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 19 | import static android.service.carrier.CarrierService.ICarrierServiceWrapper.KEY_CONFIG_BUNDLE; |
| 20 | import static android.service.carrier.CarrierService.ICarrierServiceWrapper.RESULT_ERROR; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 21 | |
Jonathan Basseri | 11f8957 | 2015-05-05 11:57:39 -0700 | [diff] [blame] | 22 | import android.annotation.NonNull; |
Sudheer Shanka | bb03c63 | 2016-11-10 15:29:41 -0800 | [diff] [blame] | 23 | import android.app.ActivityManager; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 24 | import android.content.BroadcastReceiver; |
| 25 | import android.content.ComponentName; |
| 26 | import android.content.Context; |
| 27 | import android.content.Intent; |
| 28 | import android.content.IntentFilter; |
| 29 | import android.content.ServiceConnection; |
Jonathan Basseri | 7697cae | 2015-07-06 15:49:23 -0700 | [diff] [blame] | 30 | import android.content.SharedPreferences; |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 31 | import android.content.pm.PackageInfo; |
Jonathan Basseri | c31f1f3 | 2015-05-12 10:13:03 -0700 | [diff] [blame] | 32 | import android.content.pm.PackageManager; |
Junda Liu | 43d723a | 2015-05-12 17:23:45 -0700 | [diff] [blame] | 33 | import android.os.Binder; |
Jonathan Basseri | 7697cae | 2015-07-06 15:49:23 -0700 | [diff] [blame] | 34 | import android.os.Build; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 35 | import android.os.Bundle; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 36 | import android.os.Handler; |
| 37 | import android.os.IBinder; |
| 38 | import android.os.Message; |
Jonathan Basseri | c31f1f3 | 2015-05-12 10:13:03 -0700 | [diff] [blame] | 39 | import android.os.PersistableBundle; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 40 | import android.os.RemoteException; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 41 | import android.os.ResultReceiver; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 42 | import android.os.ServiceManager; |
| 43 | import android.os.UserHandle; |
Jonathan Basseri | 7697cae | 2015-07-06 15:49:23 -0700 | [diff] [blame] | 44 | import android.preference.PreferenceManager; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 45 | import android.service.carrier.CarrierIdentifier; |
Zach Johnson | 36d7aab | 2015-05-22 15:43:00 -0700 | [diff] [blame] | 46 | import android.service.carrier.CarrierService; |
| 47 | import android.service.carrier.ICarrierService; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 48 | import android.telephony.CarrierConfigManager; |
| 49 | import android.telephony.SubscriptionManager; |
| 50 | import android.telephony.TelephonyManager; |
chen xu | db04c29 | 2019-03-26 17:01:15 -0700 | [diff] [blame] | 51 | import android.util.LocalLog; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 52 | import android.util.Log; |
| 53 | |
| 54 | import com.android.internal.telephony.ICarrierConfigLoader; |
| 55 | import com.android.internal.telephony.IccCardConstants; |
| 56 | import com.android.internal.telephony.Phone; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 57 | import com.android.internal.telephony.PhoneFactory; |
Nathan Harold | 48ac097 | 2019-03-13 22:33:01 -0700 | [diff] [blame] | 58 | import com.android.internal.telephony.SubscriptionInfoUpdater; |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 59 | import com.android.internal.telephony.TelephonyPermissions; |
Qiongcheng Luo | a0f6e90 | 2018-08-06 10:20:09 +0800 | [diff] [blame] | 60 | import com.android.internal.util.ArrayUtils; |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 61 | import com.android.internal.util.FastXmlSerializer; |
shuoq | 26a3a4c | 2016-12-16 11:06:48 -0800 | [diff] [blame] | 62 | import com.android.internal.util.IndentingPrintWriter; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 63 | |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 64 | import org.xmlpull.v1.XmlPullParser; |
| 65 | import org.xmlpull.v1.XmlPullParserException; |
| 66 | import org.xmlpull.v1.XmlPullParserFactory; |
| 67 | |
| 68 | import java.io.File; |
Junda Liu | 43d723a | 2015-05-12 17:23:45 -0700 | [diff] [blame] | 69 | import java.io.FileDescriptor; |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 70 | import java.io.FileInputStream; |
| 71 | import java.io.FileNotFoundException; |
| 72 | import java.io.FileOutputStream; |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 73 | import java.io.FilenameFilter; |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 74 | import java.io.IOException; |
Junda Liu | 43d723a | 2015-05-12 17:23:45 -0700 | [diff] [blame] | 75 | import java.io.PrintWriter; |
shuoq | 26a3a4c | 2016-12-16 11:06:48 -0800 | [diff] [blame] | 76 | import java.util.ArrayList; |
| 77 | import java.util.Arrays; |
| 78 | import java.util.Collections; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 79 | import java.util.List; |
| 80 | |
| 81 | /** |
| 82 | * CarrierConfigLoader binds to privileged carrier apps to fetch carrier config overlays. |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 83 | */ |
| 84 | |
| 85 | public class CarrierConfigLoader extends ICarrierConfigLoader.Stub { |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 86 | private static final String LOG_TAG = "CarrierConfigLoader"; |
Meng Wang | 33ad2bc | 2017-03-16 20:21:20 -0700 | [diff] [blame] | 87 | |
| 88 | // Package name for platform carrier config app, bundled with system image. |
| 89 | private final String mPlatformCarrierConfigPackage; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 90 | |
| 91 | /** The singleton instance. */ |
| 92 | private static CarrierConfigLoader sInstance; |
| 93 | // The context for phone app, passed from PhoneGlobals. |
| 94 | private Context mContext; |
| 95 | // Carrier configs from default app, indexed by phoneID. |
Jonathan Basseri | c31f1f3 | 2015-05-12 10:13:03 -0700 | [diff] [blame] | 96 | private PersistableBundle[] mConfigFromDefaultApp; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 97 | // Carrier configs from privileged carrier config app, indexed by phoneID. |
Jonathan Basseri | c31f1f3 | 2015-05-12 10:13:03 -0700 | [diff] [blame] | 98 | private PersistableBundle[] mConfigFromCarrierApp; |
Hall Liu | 506724b | 2018-10-22 18:16:14 -0700 | [diff] [blame] | 99 | // Carrier configs that are provided via the override test API, indexed by phone ID. |
| 100 | private PersistableBundle[] mOverrideConfigs; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 101 | // Service connection for binding to config app. |
Zach Johnson | 36d7aab | 2015-05-22 15:43:00 -0700 | [diff] [blame] | 102 | private CarrierServiceConnection[] mServiceConnection; |
Junda Liu | 03aad76 | 2017-07-21 13:32:17 -0700 | [diff] [blame] | 103 | // Whether we have sent config change bcast for each phone id. |
| 104 | private boolean[] mHasSentConfigChange; |
Nathan Harold | 48ac097 | 2019-03-13 22:33:01 -0700 | [diff] [blame] | 105 | // SubscriptionInfoUpdater |
| 106 | private final SubscriptionInfoUpdater mSubscriptionInfoUpdater; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 107 | |
Nanxi Chen | 3d67050 | 2016-03-17 16:32:09 -0700 | [diff] [blame] | 108 | // Broadcast receiver for Boot intents, register intent filter in construtor. |
| 109 | private final BroadcastReceiver mBootReceiver = new ConfigLoaderBroadcastReceiver(); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 110 | // Broadcast receiver for SIM and pkg intents, register intent filter in constructor. |
Nanxi Chen | 3d67050 | 2016-03-17 16:32:09 -0700 | [diff] [blame] | 111 | private final BroadcastReceiver mPackageReceiver = new ConfigLoaderBroadcastReceiver(); |
chen xu | db04c29 | 2019-03-26 17:01:15 -0700 | [diff] [blame] | 112 | private final LocalLog mCarrierConfigLoadingLog = new LocalLog(50); |
| 113 | |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 114 | |
| 115 | // Message codes; see mHandler below. |
| 116 | // Request from SubscriptionInfoUpdater when SIM becomes absent or error. |
| 117 | private static final int EVENT_CLEAR_CONFIG = 0; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 118 | // Has connected to default app. |
| 119 | private static final int EVENT_CONNECTED_TO_DEFAULT = 3; |
| 120 | // Has connected to carrier app. |
| 121 | private static final int EVENT_CONNECTED_TO_CARRIER = 4; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 122 | // Config has been loaded from default app (or cache). |
| 123 | private static final int EVENT_FETCH_DEFAULT_DONE = 5; |
| 124 | // Config has been loaded from carrier app (or cache). |
| 125 | private static final int EVENT_FETCH_CARRIER_DONE = 6; |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 126 | // Attempt to fetch from default app or read from XML. |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 127 | private static final int EVENT_DO_FETCH_DEFAULT = 7; |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 128 | // Attempt to fetch from carrier app or read from XML. |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 129 | private static final int EVENT_DO_FETCH_CARRIER = 8; |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 130 | // A package has been installed, uninstalled, or updated. |
| 131 | private static final int EVENT_PACKAGE_CHANGED = 9; |
Jonathan Basseri | 930701e | 2015-06-11 20:56:43 -0700 | [diff] [blame] | 132 | // Bind timed out for the default app. |
| 133 | private static final int EVENT_BIND_DEFAULT_TIMEOUT = 10; |
| 134 | // Bind timed out for a carrier app. |
| 135 | private static final int EVENT_BIND_CARRIER_TIMEOUT = 11; |
Jonathan Basseri | 7697cae | 2015-07-06 15:49:23 -0700 | [diff] [blame] | 136 | // Check if the system fingerprint has changed. |
| 137 | private static final int EVENT_CHECK_SYSTEM_UPDATE = 12; |
Nanxi Chen | 3d67050 | 2016-03-17 16:32:09 -0700 | [diff] [blame] | 138 | // Rerun carrier config binding after system is unlocked. |
| 139 | private static final int EVENT_SYSTEM_UNLOCKED = 13; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 140 | // Fetching config timed out from the default app. |
| 141 | private static final int EVENT_FETCH_DEFAULT_TIMEOUT = 14; |
| 142 | // Fetching config timed out from a carrier app. |
| 143 | private static final int EVENT_FETCH_CARRIER_TIMEOUT = 15; |
Nathan Harold | 48ac097 | 2019-03-13 22:33:01 -0700 | [diff] [blame] | 144 | // SubscriptionInfoUpdater has finished updating the sub for the carrier config. |
| 145 | private static final int EVENT_SUBSCRIPTION_INFO_UPDATED = 16; |
Jonathan Basseri | 930701e | 2015-06-11 20:56:43 -0700 | [diff] [blame] | 146 | |
Junda Liu | 6cb4500 | 2016-03-22 17:18:20 -0700 | [diff] [blame] | 147 | private static final int BIND_TIMEOUT_MILLIS = 30000; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 148 | |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 149 | // Tags used for saving and restoring XML documents. |
| 150 | private static final String TAG_DOCUMENT = "carrier_config"; |
| 151 | private static final String TAG_VERSION = "package_version"; |
| 152 | private static final String TAG_BUNDLE = "bundle_data"; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 153 | |
Jonathan Basseri | 7697cae | 2015-07-06 15:49:23 -0700 | [diff] [blame] | 154 | // SharedPreferences key for last known build fingerprint. |
| 155 | private static final String KEY_FINGERPRINT = "build_fingerprint"; |
| 156 | |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 157 | // Handler to process various events. |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 158 | // |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 159 | // For each phoneId, the event sequence should be: |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 160 | // fetch default, connected to default, fetch default (async), fetch default done, |
| 161 | // fetch carrier, connected to carrier, fetch carrier (async), fetch carrier done. |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 162 | // |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 163 | // If there is a saved config file for either the default app or the carrier app, we skip |
| 164 | // binding to the app and go straight from fetch to loaded. |
| 165 | // |
| 166 | // At any time, at most one connection is active. If events are not in this order, previous |
| 167 | // connection will be unbound, so only latest event takes effect. |
| 168 | // |
| 169 | // We broadcast ACTION_CARRIER_CONFIG_CHANGED after: |
| 170 | // 1. loading from carrier app (even if read from a file) |
| 171 | // 2. loading from default app if there is no carrier app (even if read from a file) |
| 172 | // 3. clearing config (e.g. due to sim removal) |
| 173 | // 4. encountering bind or IPC error |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 174 | private class ConfigHandler extends Handler { |
| 175 | @Override |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 176 | public void handleMessage(Message msg) { |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 177 | final int phoneId = msg.arg1; |
chen xu | c481097 | 2019-04-17 23:44:43 -0700 | [diff] [blame] | 178 | logWithLocalLog("mHandler: " + msg.what + " phoneId: " + phoneId); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 179 | switch (msg.what) { |
| 180 | case EVENT_CLEAR_CONFIG: |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 181 | { |
Sooraj Sasindran | 52119cd | 2017-10-23 16:24:28 -0700 | [diff] [blame] | 182 | /* Ignore clear configuration request if device is being shutdown. */ |
| 183 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 184 | if (phone != null) { |
| 185 | if (phone.isShuttingDown()) { |
| 186 | break; |
| 187 | } |
| 188 | } |
| 189 | |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 190 | mConfigFromDefaultApp[phoneId] = null; |
| 191 | mConfigFromCarrierApp[phoneId] = null; |
| 192 | mServiceConnection[phoneId] = null; |
Amit Mahajan | f8088ab | 2018-03-02 15:24:07 -0800 | [diff] [blame] | 193 | broadcastConfigChangedIntent(phoneId, false); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 194 | break; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 195 | } |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 196 | |
Nanxi Chen | 3d67050 | 2016-03-17 16:32:09 -0700 | [diff] [blame] | 197 | case EVENT_SYSTEM_UNLOCKED: |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 198 | { |
Nanxi Chen | 3d67050 | 2016-03-17 16:32:09 -0700 | [diff] [blame] | 199 | for (int i = 0; i < TelephonyManager.from(mContext).getPhoneCount(); ++i) { |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 200 | // When user unlock device, we should only try to send broadcast again if we |
| 201 | // have sent it before unlock. This will avoid we try to load carrier config |
| 202 | // when SIM is still loading when unlock happens. |
Junda Liu | 03aad76 | 2017-07-21 13:32:17 -0700 | [diff] [blame] | 203 | if (mHasSentConfigChange[i]) { |
| 204 | updateConfigForPhoneId(i); |
| 205 | } |
Nanxi Chen | 3d67050 | 2016-03-17 16:32:09 -0700 | [diff] [blame] | 206 | } |
| 207 | break; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 208 | } |
Nanxi Chen | 3d67050 | 2016-03-17 16:32:09 -0700 | [diff] [blame] | 209 | |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 210 | case EVENT_PACKAGE_CHANGED: |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 211 | { |
| 212 | final String carrierPackageName = (String) msg.obj; |
| 213 | // Only update if there are cached config removed to avoid updating config for |
| 214 | // unrelated packages. |
Jonathan Basseri | 7697cae | 2015-07-06 15:49:23 -0700 | [diff] [blame] | 215 | if (clearCachedConfigForPackage(carrierPackageName)) { |
Junda Liu | 8a8a53a | 2015-05-15 16:19:57 -0700 | [diff] [blame] | 216 | int numPhones = TelephonyManager.from(mContext).getPhoneCount(); |
| 217 | for (int i = 0; i < numPhones; ++i) { |
| 218 | updateConfigForPhoneId(i); |
| 219 | } |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 220 | } |
| 221 | break; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 222 | } |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 223 | |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 224 | case EVENT_DO_FETCH_DEFAULT: |
| 225 | { |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 226 | final PersistableBundle config = |
Yuchen Dong | c15afed | 2018-04-26 17:05:22 +0800 | [diff] [blame] | 227 | restoreConfigFromXml(mPlatformCarrierConfigPackage, phoneId); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 228 | if (config != null) { |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 229 | log( |
| 230 | "Loaded config from XML. package=" |
| 231 | + mPlatformCarrierConfigPackage |
| 232 | + " phoneId=" |
| 233 | + phoneId); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 234 | mConfigFromDefaultApp[phoneId] = config; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 235 | Message newMsg = obtainMessage(EVENT_FETCH_DEFAULT_DONE, phoneId, -1); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 236 | newMsg.getData().putBoolean("loaded_from_xml", true); |
| 237 | mHandler.sendMessage(newMsg); |
| 238 | } else { |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 239 | // No cached config, so fetch it from the default app. |
| 240 | if (bindToConfigPackage( |
| 241 | mPlatformCarrierConfigPackage, |
| 242 | phoneId, |
| 243 | EVENT_CONNECTED_TO_DEFAULT)) { |
| 244 | sendMessageDelayed( |
| 245 | obtainMessage(EVENT_BIND_DEFAULT_TIMEOUT, phoneId, -1), |
Jonathan Basseri | 930701e | 2015-06-11 20:56:43 -0700 | [diff] [blame] | 246 | BIND_TIMEOUT_MILLIS); |
| 247 | } else { |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 248 | // Send broadcast if bind fails. |
Nathan Harold | 48ac097 | 2019-03-13 22:33:01 -0700 | [diff] [blame] | 249 | notifySubscriptionInfoUpdater(phoneId); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 250 | // TODO: We *must* call unbindService even if bindService returns false. |
| 251 | // (And possibly if SecurityException was thrown.) |
chen xu | db04c29 | 2019-03-26 17:01:15 -0700 | [diff] [blame] | 252 | loge("binding to default app: " |
| 253 | + mPlatformCarrierConfigPackage + " fails"); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 254 | } |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 255 | } |
| 256 | break; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 257 | } |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 258 | |
| 259 | case EVENT_CONNECTED_TO_DEFAULT: |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 260 | { |
Jonathan Basseri | 930701e | 2015-06-11 20:56:43 -0700 | [diff] [blame] | 261 | removeMessages(EVENT_BIND_DEFAULT_TIMEOUT); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 262 | final CarrierServiceConnection conn = (CarrierServiceConnection) msg.obj; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 263 | // If new service connection has been created, unbind. |
| 264 | if (mServiceConnection[phoneId] != conn || conn.service == null) { |
| 265 | mContext.unbindService(conn); |
| 266 | break; |
| 267 | } |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 268 | final CarrierIdentifier carrierId = getCarrierIdentifierForPhoneId(phoneId); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 269 | // ResultReceiver callback will execute in this Handler's thread. |
| 270 | final ResultReceiver resultReceiver = |
| 271 | new ResultReceiver(this) { |
| 272 | @Override |
| 273 | public void onReceiveResult(int resultCode, Bundle resultData) { |
| 274 | mContext.unbindService(conn); |
| 275 | // If new service connection has been created, this is stale. |
| 276 | if (mServiceConnection[phoneId] != conn) { |
| 277 | loge("Received response for stale request."); |
| 278 | return; |
| 279 | } |
| 280 | removeMessages(EVENT_FETCH_DEFAULT_TIMEOUT); |
| 281 | if (resultCode == RESULT_ERROR || resultData == null) { |
| 282 | // On error, abort config fetching. |
| 283 | loge("Failed to get carrier config"); |
Nathan Harold | 48ac097 | 2019-03-13 22:33:01 -0700 | [diff] [blame] | 284 | notifySubscriptionInfoUpdater(phoneId); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 285 | return; |
| 286 | } |
| 287 | PersistableBundle config = |
| 288 | resultData.getParcelable(KEY_CONFIG_BUNDLE); |
Chen Xu | cd4a637 | 2019-07-29 16:34:52 -0700 | [diff] [blame^] | 289 | saveConfigToXml(mPlatformCarrierConfigPackage, phoneId, |
| 290 | carrierId, config); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 291 | mConfigFromDefaultApp[phoneId] = config; |
| 292 | sendMessage( |
| 293 | obtainMessage( |
| 294 | EVENT_FETCH_DEFAULT_DONE, phoneId, -1)); |
| 295 | } |
| 296 | }; |
| 297 | // Now fetch the config asynchronously from the ICarrierService. |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 298 | try { |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 299 | ICarrierService carrierService = |
| 300 | ICarrierService.Stub.asInterface(conn.service); |
| 301 | carrierService.getCarrierConfig(carrierId, resultReceiver); |
chen xu | db04c29 | 2019-03-26 17:01:15 -0700 | [diff] [blame] | 302 | logWithLocalLog("fetch config for default app: " |
| 303 | + mPlatformCarrierConfigPackage |
| 304 | + " carrierid: " + carrierId.toString()); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 305 | } catch (RemoteException e) { |
chen xu | db04c29 | 2019-03-26 17:01:15 -0700 | [diff] [blame] | 306 | loge("Failed to get carrier config from default app: " + |
| 307 | mPlatformCarrierConfigPackage + " err: " + e.toString()); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 308 | mContext.unbindService(conn); |
| 309 | break; // So we don't set a timeout. |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 310 | } |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 311 | sendMessageDelayed( |
| 312 | obtainMessage(EVENT_FETCH_DEFAULT_TIMEOUT, phoneId, -1), |
| 313 | BIND_TIMEOUT_MILLIS); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 314 | break; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 315 | } |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 316 | |
Jonathan Basseri | 930701e | 2015-06-11 20:56:43 -0700 | [diff] [blame] | 317 | case EVENT_BIND_DEFAULT_TIMEOUT: |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 318 | case EVENT_FETCH_DEFAULT_TIMEOUT: |
| 319 | { |
chen xu | db04c29 | 2019-03-26 17:01:15 -0700 | [diff] [blame] | 320 | loge("bind/fetch time out from " + mPlatformCarrierConfigPackage); |
chen xu | f60b316 | 2019-05-01 21:31:05 -0700 | [diff] [blame] | 321 | removeMessages(EVENT_FETCH_DEFAULT_TIMEOUT); |
| 322 | // If we attempted to bind to the app, but the service connection is null due to |
| 323 | // the race condition that clear config event happens before bind/fetch complete |
| 324 | // then config was cleared while we were waiting and we should not continue. |
| 325 | if (mServiceConnection[phoneId] != null) { |
| 326 | // If a ResponseReceiver callback is in the queue when this happens, we will |
| 327 | // unbind twice and throw an exception. |
| 328 | mContext.unbindService(mServiceConnection[phoneId]); |
| 329 | broadcastConfigChangedIntent(phoneId); |
| 330 | } |
Nathan Harold | 48ac097 | 2019-03-13 22:33:01 -0700 | [diff] [blame] | 331 | notifySubscriptionInfoUpdater(phoneId); |
Jonathan Basseri | 930701e | 2015-06-11 20:56:43 -0700 | [diff] [blame] | 332 | break; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 333 | } |
Jonathan Basseri | 930701e | 2015-06-11 20:56:43 -0700 | [diff] [blame] | 334 | |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 335 | case EVENT_FETCH_DEFAULT_DONE: |
| 336 | { |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 337 | // If we attempted to bind to the app, but the service connection is null, then |
| 338 | // config was cleared while we were waiting and we should not continue. |
| 339 | if (!msg.getData().getBoolean("loaded_from_xml", false) |
| 340 | && mServiceConnection[phoneId] == null) { |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 341 | break; |
| 342 | } |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 343 | final String carrierPackageName = getCarrierPackageForPhoneId(phoneId); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 344 | if (carrierPackageName != null) { |
| 345 | log("Found carrier config app: " + carrierPackageName); |
Jordan Liu | 38a614c | 2019-03-20 15:01:17 -0700 | [diff] [blame] | 346 | sendMessage(obtainMessage(EVENT_DO_FETCH_CARRIER, phoneId, -1)); |
Jonathan Basseri | b919e93 | 2015-05-27 16:53:08 +0000 | [diff] [blame] | 347 | } else { |
Nathan Harold | 48ac097 | 2019-03-13 22:33:01 -0700 | [diff] [blame] | 348 | notifySubscriptionInfoUpdater(phoneId); |
Jonathan Basseri | 4ae2e7c | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 349 | } |
| 350 | break; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 351 | } |
Jonathan Basseri | 4ae2e7c | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 352 | |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 353 | case EVENT_DO_FETCH_CARRIER: |
| 354 | { |
| 355 | final String carrierPackageName = getCarrierPackageForPhoneId(phoneId); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 356 | final PersistableBundle config = |
Yuchen Dong | c15afed | 2018-04-26 17:05:22 +0800 | [diff] [blame] | 357 | restoreConfigFromXml(carrierPackageName, phoneId); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 358 | if (config != null) { |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 359 | log( |
| 360 | "Loaded config from XML. package=" |
| 361 | + carrierPackageName |
| 362 | + " phoneId=" |
| 363 | + phoneId); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 364 | mConfigFromCarrierApp[phoneId] = config; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 365 | Message newMsg = obtainMessage(EVENT_FETCH_CARRIER_DONE, phoneId, -1); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 366 | newMsg.getData().putBoolean("loaded_from_xml", true); |
| 367 | sendMessage(newMsg); |
| 368 | } else { |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 369 | // No cached config, so fetch it from a carrier app. |
Jonathan Basseri | 40473a5 | 2015-08-14 14:36:29 -0700 | [diff] [blame] | 370 | if (carrierPackageName != null |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 371 | && bindToConfigPackage( |
| 372 | carrierPackageName, |
| 373 | phoneId, |
| 374 | EVENT_CONNECTED_TO_CARRIER)) { |
| 375 | sendMessageDelayed( |
| 376 | obtainMessage(EVENT_BIND_CARRIER_TIMEOUT, phoneId, -1), |
Jonathan Basseri | 930701e | 2015-06-11 20:56:43 -0700 | [diff] [blame] | 377 | BIND_TIMEOUT_MILLIS); |
| 378 | } else { |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 379 | // Send broadcast if bind fails. |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 380 | broadcastConfigChangedIntent(phoneId); |
chen xu | db04c29 | 2019-03-26 17:01:15 -0700 | [diff] [blame] | 381 | loge("bind to carrier app: " + carrierPackageName + " fails"); |
Nathan Harold | 48ac097 | 2019-03-13 22:33:01 -0700 | [diff] [blame] | 382 | notifySubscriptionInfoUpdater(phoneId); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 383 | } |
| 384 | } |
| 385 | break; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 386 | } |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 387 | |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 388 | case EVENT_CONNECTED_TO_CARRIER: |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 389 | { |
Jonathan Basseri | 930701e | 2015-06-11 20:56:43 -0700 | [diff] [blame] | 390 | removeMessages(EVENT_BIND_CARRIER_TIMEOUT); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 391 | final CarrierServiceConnection conn = (CarrierServiceConnection) msg.obj; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 392 | // If new service connection has been created, unbind. |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 393 | if (mServiceConnection[phoneId] != conn || conn.service == null) { |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 394 | mContext.unbindService(conn); |
| 395 | break; |
| 396 | } |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 397 | final CarrierIdentifier carrierId = getCarrierIdentifierForPhoneId(phoneId); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 398 | // ResultReceiver callback will execute in this Handler's thread. |
| 399 | final ResultReceiver resultReceiver = |
| 400 | new ResultReceiver(this) { |
| 401 | @Override |
| 402 | public void onReceiveResult(int resultCode, Bundle resultData) { |
| 403 | mContext.unbindService(conn); |
| 404 | // If new service connection has been created, this is stale. |
| 405 | if (mServiceConnection[phoneId] != conn) { |
| 406 | loge("Received response for stale request."); |
| 407 | return; |
| 408 | } |
| 409 | removeMessages(EVENT_FETCH_CARRIER_TIMEOUT); |
| 410 | if (resultCode == RESULT_ERROR || resultData == null) { |
| 411 | // On error, abort config fetching. |
chen xu | db04c29 | 2019-03-26 17:01:15 -0700 | [diff] [blame] | 412 | loge("Failed to get carrier config from carrier app: " |
| 413 | + getCarrierPackageForPhoneId(phoneId)); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 414 | broadcastConfigChangedIntent(phoneId); |
Nathan Harold | 48ac097 | 2019-03-13 22:33:01 -0700 | [diff] [blame] | 415 | notifySubscriptionInfoUpdater(phoneId); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 416 | return; |
| 417 | } |
| 418 | PersistableBundle config = |
| 419 | resultData.getParcelable(KEY_CONFIG_BUNDLE); |
Chen Xu | cd4a637 | 2019-07-29 16:34:52 -0700 | [diff] [blame^] | 420 | saveConfigToXml(getCarrierPackageForPhoneId(phoneId), phoneId, |
| 421 | carrierId, config); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 422 | mConfigFromCarrierApp[phoneId] = config; |
| 423 | sendMessage( |
| 424 | obtainMessage( |
| 425 | EVENT_FETCH_CARRIER_DONE, phoneId, -1)); |
| 426 | } |
| 427 | }; |
| 428 | // Now fetch the config asynchronously from the ICarrierService. |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 429 | try { |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 430 | ICarrierService carrierService = |
| 431 | ICarrierService.Stub.asInterface(conn.service); |
| 432 | carrierService.getCarrierConfig(carrierId, resultReceiver); |
chen xu | db04c29 | 2019-03-26 17:01:15 -0700 | [diff] [blame] | 433 | logWithLocalLog("fetch config for carrier app: " |
| 434 | + getCarrierPackageForPhoneId(phoneId) |
| 435 | + " carrierid: " + carrierId.toString()); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 436 | } catch (RemoteException e) { |
| 437 | loge("Failed to get carrier config: " + e.toString()); |
| 438 | mContext.unbindService(conn); |
| 439 | break; // So we don't set a timeout. |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 440 | } |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 441 | sendMessageDelayed( |
| 442 | obtainMessage(EVENT_FETCH_CARRIER_TIMEOUT, phoneId, -1), |
| 443 | BIND_TIMEOUT_MILLIS); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 444 | break; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 445 | } |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 446 | |
Jonathan Basseri | 930701e | 2015-06-11 20:56:43 -0700 | [diff] [blame] | 447 | case EVENT_BIND_CARRIER_TIMEOUT: |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 448 | case EVENT_FETCH_CARRIER_TIMEOUT: |
| 449 | { |
chen xu | db04c29 | 2019-03-26 17:01:15 -0700 | [diff] [blame] | 450 | loge("bind/fetch from carrier app timeout"); |
chen xu | f60b316 | 2019-05-01 21:31:05 -0700 | [diff] [blame] | 451 | removeMessages(EVENT_FETCH_CARRIER_TIMEOUT); |
| 452 | // If we attempted to bind to the app, but the service connection is null due to |
| 453 | // the race condition that clear config event happens before bind/fetch complete |
| 454 | // then config was cleared while we were waiting and we should not continue. |
| 455 | if (mServiceConnection[phoneId] != null) { |
| 456 | // If a ResponseReceiver callback is in the queue when this happens, we will |
| 457 | // unbind twice and throw an exception. |
| 458 | mContext.unbindService(mServiceConnection[phoneId]); |
| 459 | broadcastConfigChangedIntent(phoneId); |
| 460 | } |
Nathan Harold | 48ac097 | 2019-03-13 22:33:01 -0700 | [diff] [blame] | 461 | notifySubscriptionInfoUpdater(phoneId); |
Jonathan Basseri | 930701e | 2015-06-11 20:56:43 -0700 | [diff] [blame] | 462 | break; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 463 | } |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 464 | case EVENT_FETCH_CARRIER_DONE: |
| 465 | { |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 466 | // If we attempted to bind to the app, but the service connection is null, then |
| 467 | // config was cleared while we were waiting and we should not continue. |
| 468 | if (!msg.getData().getBoolean("loaded_from_xml", false) |
| 469 | && mServiceConnection[phoneId] == null) { |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 470 | break; |
| 471 | } |
Nathan Harold | 48ac097 | 2019-03-13 22:33:01 -0700 | [diff] [blame] | 472 | notifySubscriptionInfoUpdater(phoneId); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 473 | break; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 474 | } |
Jonathan Basseri | 7697cae | 2015-07-06 15:49:23 -0700 | [diff] [blame] | 475 | |
| 476 | case EVENT_CHECK_SYSTEM_UPDATE: |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 477 | { |
Jonathan Basseri | 7697cae | 2015-07-06 15:49:23 -0700 | [diff] [blame] | 478 | SharedPreferences sharedPrefs = |
| 479 | PreferenceManager.getDefaultSharedPreferences(mContext); |
| 480 | final String lastFingerprint = sharedPrefs.getString(KEY_FINGERPRINT, null); |
| 481 | if (!Build.FINGERPRINT.equals(lastFingerprint)) { |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 482 | log( |
| 483 | "Build fingerprint changed. old: " |
| 484 | + lastFingerprint |
| 485 | + " new: " |
| 486 | + Build.FINGERPRINT); |
Jonathan Basseri | 7697cae | 2015-07-06 15:49:23 -0700 | [diff] [blame] | 487 | clearCachedConfigForPackage(null); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 488 | sharedPrefs |
| 489 | .edit() |
| 490 | .putString(KEY_FINGERPRINT, Build.FINGERPRINT) |
| 491 | .apply(); |
Jonathan Basseri | 7697cae | 2015-07-06 15:49:23 -0700 | [diff] [blame] | 492 | } |
| 493 | break; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 494 | } |
Nathan Harold | 48ac097 | 2019-03-13 22:33:01 -0700 | [diff] [blame] | 495 | |
| 496 | case EVENT_SUBSCRIPTION_INFO_UPDATED: |
| 497 | broadcastConfigChangedIntent(phoneId); |
| 498 | break; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 499 | } |
| 500 | } |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | private final Handler mHandler; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 504 | |
| 505 | /** |
| 506 | * Constructs a CarrierConfigLoader, registers it as a service, and registers a broadcast |
| 507 | * receiver for relevant events. |
| 508 | */ |
| 509 | private CarrierConfigLoader(Context context) { |
| 510 | mContext = context; |
Meng Wang | 33ad2bc | 2017-03-16 20:21:20 -0700 | [diff] [blame] | 511 | mPlatformCarrierConfigPackage = |
| 512 | mContext.getString(R.string.platform_carrier_config_package); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 513 | mHandler = new ConfigHandler(); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 514 | |
Nanxi Chen | 3d67050 | 2016-03-17 16:32:09 -0700 | [diff] [blame] | 515 | IntentFilter bootFilter = new IntentFilter(); |
| 516 | bootFilter.addAction(Intent.ACTION_BOOT_COMPLETED); |
| 517 | context.registerReceiver(mBootReceiver, bootFilter); |
| 518 | |
Junda Liu | 8a8a53a | 2015-05-15 16:19:57 -0700 | [diff] [blame] | 519 | // Register for package updates. Update app or uninstall app update will have all 3 intents, |
| 520 | // in the order or removed, added, replaced, all with extra_replace set to true. |
| 521 | IntentFilter pkgFilter = new IntentFilter(); |
| 522 | pkgFilter.addAction(Intent.ACTION_PACKAGE_ADDED); |
| 523 | pkgFilter.addAction(Intent.ACTION_PACKAGE_REMOVED); |
| 524 | pkgFilter.addAction(Intent.ACTION_PACKAGE_REPLACED); |
| 525 | pkgFilter.addDataScheme("package"); |
Nanxi Chen | 3d67050 | 2016-03-17 16:32:09 -0700 | [diff] [blame] | 526 | context.registerReceiverAsUser(mPackageReceiver, UserHandle.ALL, pkgFilter, null, null); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 527 | |
| 528 | int numPhones = TelephonyManager.from(context).getPhoneCount(); |
Jonathan Basseri | c31f1f3 | 2015-05-12 10:13:03 -0700 | [diff] [blame] | 529 | mConfigFromDefaultApp = new PersistableBundle[numPhones]; |
| 530 | mConfigFromCarrierApp = new PersistableBundle[numPhones]; |
Hall Liu | 506724b | 2018-10-22 18:16:14 -0700 | [diff] [blame] | 531 | mOverrideConfigs = new PersistableBundle[numPhones]; |
Zach Johnson | 36d7aab | 2015-05-22 15:43:00 -0700 | [diff] [blame] | 532 | mServiceConnection = new CarrierServiceConnection[numPhones]; |
Junda Liu | 03aad76 | 2017-07-21 13:32:17 -0700 | [diff] [blame] | 533 | mHasSentConfigChange = new boolean[numPhones]; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 534 | // Make this service available through ServiceManager. |
| 535 | ServiceManager.addService(Context.CARRIER_CONFIG_SERVICE, this); |
| 536 | log("CarrierConfigLoader has started"); |
Nathan Harold | 48ac097 | 2019-03-13 22:33:01 -0700 | [diff] [blame] | 537 | mSubscriptionInfoUpdater = PhoneFactory.getSubscriptionInfoUpdater(); |
Jonathan Basseri | 7697cae | 2015-07-06 15:49:23 -0700 | [diff] [blame] | 538 | mHandler.sendEmptyMessage(EVENT_CHECK_SYSTEM_UPDATE); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | /** |
| 542 | * Initialize the singleton CarrierConfigLoader instance. |
| 543 | * |
| 544 | * This is only done once, at startup, from {@link com.android.phone.PhoneApp#onCreate}. |
| 545 | */ |
| 546 | /* package */ |
| 547 | static CarrierConfigLoader init(Context context) { |
| 548 | synchronized (CarrierConfigLoader.class) { |
| 549 | if (sInstance == null) { |
| 550 | sInstance = new CarrierConfigLoader(context); |
| 551 | } else { |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 552 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 553 | } |
| 554 | return sInstance; |
| 555 | } |
| 556 | } |
| 557 | |
Nathan Harold | 48ac097 | 2019-03-13 22:33:01 -0700 | [diff] [blame] | 558 | private void notifySubscriptionInfoUpdater(int phoneId) { |
| 559 | String configPackagename; |
| 560 | PersistableBundle configToSend; |
| 561 | int carrierId = getSpecificCarrierIdForPhoneId(phoneId); |
| 562 | // Prefer the carrier privileged carrier app, but if there is not one, use the platform |
| 563 | // default carrier app. |
| 564 | if (mConfigFromCarrierApp[phoneId] != null) { |
| 565 | configPackagename = getCarrierPackageForPhoneId(phoneId); |
| 566 | configToSend = mConfigFromCarrierApp[phoneId]; |
| 567 | } else { |
| 568 | configPackagename = mPlatformCarrierConfigPackage; |
| 569 | configToSend = mConfigFromDefaultApp[phoneId]; |
| 570 | } |
| 571 | mSubscriptionInfoUpdater.updateSubscriptionByCarrierConfigAndNotifyComplete( |
| 572 | phoneId, configPackagename, configToSend, |
| 573 | mHandler.obtainMessage(EVENT_SUBSCRIPTION_INFO_UPDATED, phoneId, -1)); |
| 574 | } |
| 575 | |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 576 | private void broadcastConfigChangedIntent(int phoneId) { |
Amit Mahajan | f8088ab | 2018-03-02 15:24:07 -0800 | [diff] [blame] | 577 | broadcastConfigChangedIntent(phoneId, true); |
| 578 | } |
| 579 | |
| 580 | private void broadcastConfigChangedIntent(int phoneId, boolean addSubIdExtra) { |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 581 | Intent intent = new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED); |
Christopher Tate | 38f55eb | 2017-02-14 14:43:49 -0800 | [diff] [blame] | 582 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT | |
chen xu | f9db49f | 2019-03-31 23:04:42 -0700 | [diff] [blame] | 583 | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND | |
| 584 | Intent.FLAG_RECEIVER_FOREGROUND); |
Qiongcheng Luo | a0f6e90 | 2018-08-06 10:20:09 +0800 | [diff] [blame] | 585 | if (addSubIdExtra) { |
| 586 | int simApplicationState = TelephonyManager.SIM_STATE_UNKNOWN; |
| 587 | int[] subIds = SubscriptionManager.getSubId(phoneId); |
| 588 | if (!ArrayUtils.isEmpty(subIds)) { |
| 589 | TelephonyManager telMgr = TelephonyManager.from(mContext) |
| 590 | .createForSubscriptionId(subIds[0]); |
| 591 | simApplicationState = telMgr.getSimApplicationState(); |
| 592 | } |
| 593 | // Include subId/carrier id extra only if SIM records are loaded |
| 594 | if (simApplicationState != TelephonyManager.SIM_STATE_UNKNOWN |
| 595 | && simApplicationState != TelephonyManager.SIM_STATE_NOT_READY) { |
| 596 | SubscriptionManager.putPhoneIdAndSubIdExtra(intent, phoneId); |
| 597 | intent.putExtra(TelephonyManager.EXTRA_SPECIFIC_CARRIER_ID, |
| 598 | getSpecificCarrierIdForPhoneId(phoneId)); |
| 599 | intent.putExtra(TelephonyManager.EXTRA_CARRIER_ID, getCarrierIdForPhoneId(phoneId)); |
| 600 | } |
Amit Mahajan | f8088ab | 2018-03-02 15:24:07 -0800 | [diff] [blame] | 601 | } |
Amit Mahajan | b33bcda | 2018-01-24 12:56:44 -0800 | [diff] [blame] | 602 | intent.putExtra(CarrierConfigManager.EXTRA_SLOT_INDEX, phoneId); |
Jack Yu | f166132 | 2019-04-06 00:37:23 -0700 | [diff] [blame] | 603 | log("Broadcast CARRIER_CONFIG_CHANGED for phone " + phoneId); |
Sudheer Shanka | bb03c63 | 2016-11-10 15:29:41 -0800 | [diff] [blame] | 604 | ActivityManager.broadcastStickyIntent(intent, UserHandle.USER_ALL); |
Junda Liu | 03aad76 | 2017-07-21 13:32:17 -0700 | [diff] [blame] | 605 | mHasSentConfigChange[phoneId] = true; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | /** Binds to the default or carrier config app. */ |
| 609 | private boolean bindToConfigPackage(String pkgName, int phoneId, int eventId) { |
chen xu | db04c29 | 2019-03-26 17:01:15 -0700 | [diff] [blame] | 610 | logWithLocalLog("Binding to " + pkgName + " for phone " + phoneId); |
Zach Johnson | fca8a8d | 2015-06-19 18:21:37 -0700 | [diff] [blame] | 611 | Intent carrierService = new Intent(CarrierService.CARRIER_SERVICE_INTERFACE); |
Zach Johnson | 36d7aab | 2015-05-22 15:43:00 -0700 | [diff] [blame] | 612 | carrierService.setPackage(pkgName); |
| 613 | mServiceConnection[phoneId] = new CarrierServiceConnection(phoneId, eventId); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 614 | try { |
Zach Johnson | 36d7aab | 2015-05-22 15:43:00 -0700 | [diff] [blame] | 615 | return mContext.bindService(carrierService, mServiceConnection[phoneId], |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 616 | Context.BIND_AUTO_CREATE); |
| 617 | } catch (SecurityException ex) { |
| 618 | return false; |
| 619 | } |
| 620 | } |
| 621 | |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 622 | private CarrierIdentifier getCarrierIdentifierForPhoneId(int phoneId) { |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 623 | String mcc = ""; |
| 624 | String mnc = ""; |
| 625 | String imsi = ""; |
| 626 | String gid1 = ""; |
| 627 | String gid2 = ""; |
| 628 | String spn = TelephonyManager.from(mContext).getSimOperatorNameForPhone(phoneId); |
| 629 | String simOperator = TelephonyManager.from(mContext).getSimOperatorNumericForPhone(phoneId); |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 630 | int carrierId = TelephonyManager.UNKNOWN_CARRIER_ID; |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 631 | int specificCarrierId = TelephonyManager.UNKNOWN_CARRIER_ID; |
Jonathan Basseri | 1fa437c | 2015-04-20 11:08:18 -0700 | [diff] [blame] | 632 | // A valid simOperator should be 5 or 6 digits, depending on the length of the MNC. |
| 633 | if (simOperator != null && simOperator.length() >= 3) { |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 634 | mcc = simOperator.substring(0, 3); |
| 635 | mnc = simOperator.substring(3); |
| 636 | } |
| 637 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 638 | if (phone != null) { |
| 639 | imsi = phone.getSubscriberId(); |
| 640 | gid1 = phone.getGroupIdLevel1(); |
Junda Liu | 7318353 | 2015-05-14 13:55:40 -0700 | [diff] [blame] | 641 | gid2 = phone.getGroupIdLevel2(); |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 642 | carrierId = phone.getCarrierId(); |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 643 | specificCarrierId = phone.getSpecificCarrierId(); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 644 | } |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 645 | return new CarrierIdentifier(mcc, mnc, spn, imsi, gid1, gid2, carrierId, specificCarrierId); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 646 | } |
| 647 | |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 648 | /** Returns the package name of a priveleged carrier app, or null if there is none. */ |
| 649 | private String getCarrierPackageForPhoneId(int phoneId) { |
| 650 | List<String> carrierPackageNames = TelephonyManager.from(mContext) |
| 651 | .getCarrierPackageNamesForIntentAndPhone( |
Zach Johnson | fca8a8d | 2015-06-19 18:21:37 -0700 | [diff] [blame] | 652 | new Intent(CarrierService.CARRIER_SERVICE_INTERFACE), phoneId); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 653 | if (carrierPackageNames != null && carrierPackageNames.size() > 0) { |
| 654 | return carrierPackageNames.get(0); |
| 655 | } else { |
| 656 | return null; |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | private String getIccIdForPhoneId(int phoneId) { |
| 661 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 662 | return null; |
| 663 | } |
| 664 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 665 | if (phone == null) { |
| 666 | return null; |
| 667 | } |
| 668 | return phone.getIccSerialNumber(); |
| 669 | } |
| 670 | |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 671 | /** |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 672 | * Get the sim specific carrier id {@link TelephonyManager#getSimSpecificCarrierId()} |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 673 | */ |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 674 | private int getSpecificCarrierIdForPhoneId(int phoneId) { |
Naina Nalluri | 86fc7b0 | 2018-08-03 10:38:30 -0700 | [diff] [blame] | 675 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 676 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
Naina Nalluri | 86fc7b0 | 2018-08-03 10:38:30 -0700 | [diff] [blame] | 677 | } |
| 678 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 679 | if (phone == null) { |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 680 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
Naina Nalluri | 86fc7b0 | 2018-08-03 10:38:30 -0700 | [diff] [blame] | 681 | } |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 682 | return phone.getSpecificCarrierId(); |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | /** |
| 686 | * Get the sim carrier id {@link TelephonyManager#getSimCarrierId() } |
| 687 | */ |
| 688 | private int getCarrierIdForPhoneId(int phoneId) { |
| 689 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 690 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
Naina Nalluri | 86fc7b0 | 2018-08-03 10:38:30 -0700 | [diff] [blame] | 691 | } |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 692 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 693 | if (phone == null) { |
| 694 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 695 | } |
| 696 | return phone.getCarrierId(); |
Naina Nalluri | 86fc7b0 | 2018-08-03 10:38:30 -0700 | [diff] [blame] | 697 | } |
| 698 | |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 699 | /** |
| 700 | * Writes a bundle to an XML file. |
| 701 | * |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 702 | * The bundle will be written to a file named after the package name, ICCID and |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 703 | * specific carrier id {@link TelephonyManager#getSimSpecificCarrierId()}. the same carrier |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 704 | * should have a single copy of XML file named after carrier id. However, it's still possible |
| 705 | * that platform doesn't recognize the current sim carrier, we will use iccid + carrierid as |
| 706 | * the canonical file name. carrierid can also handle the cases SIM OTA resolves to different |
| 707 | * carrier while iccid remains the same. |
| 708 | * |
| 709 | * The file can be restored later with {@link @restoreConfigFromXml}. The XML output will |
| 710 | * include the bundle and the current version of the specified package. |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 711 | * |
| 712 | * In case of errors or invalid input, no file will be written. |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 713 | * |
| 714 | * @param packageName the name of the package from which we fetched this bundle. |
Yuchen Dong | c15afed | 2018-04-26 17:05:22 +0800 | [diff] [blame] | 715 | * @param phoneId the phone ID. |
Chen Xu | cd4a637 | 2019-07-29 16:34:52 -0700 | [diff] [blame^] | 716 | * @param carrierId contains all carrier-identifying information. |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 717 | * @param config the bundle to be written. Null will be treated as an empty bundle. |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 718 | */ |
Chen Xu | cd4a637 | 2019-07-29 16:34:52 -0700 | [diff] [blame^] | 719 | private void saveConfigToXml(String packageName, int phoneId, CarrierIdentifier carrierId, |
| 720 | PersistableBundle config) { |
Yuchen Dong | c15afed | 2018-04-26 17:05:22 +0800 | [diff] [blame] | 721 | if (SubscriptionManager.getSimStateForSlotIndex(phoneId) |
| 722 | != TelephonyManager.SIM_STATE_LOADED) { |
chen xu | db04c29 | 2019-03-26 17:01:15 -0700 | [diff] [blame] | 723 | loge("Skip save config because SIM records are not loaded."); |
Yuchen Dong | c15afed | 2018-04-26 17:05:22 +0800 | [diff] [blame] | 724 | return; |
| 725 | } |
| 726 | |
| 727 | final String iccid = getIccIdForPhoneId(phoneId); |
Chen Xu | cd4a637 | 2019-07-29 16:34:52 -0700 | [diff] [blame^] | 728 | final int cid = carrierId.getSpecificCarrierId(); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 729 | if (packageName == null || iccid == null) { |
| 730 | loge("Cannot save config with null packageName or iccid."); |
| 731 | return; |
| 732 | } |
Junda Liu | 0259650 | 2016-11-15 13:46:43 -0800 | [diff] [blame] | 733 | // b/32668103 Only save to file if config isn't empty. |
| 734 | // In case of failure, not caching an empty bundle will |
| 735 | // try loading config again on next power on or sim loaded. |
| 736 | // Downside is for genuinely empty bundle, will bind and load |
| 737 | // on every power on. |
| 738 | if (config == null || config.isEmpty()) { |
| 739 | return; |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 740 | } |
| 741 | |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 742 | final String version = getPackageVersion(packageName); |
| 743 | if (version == null) { |
| 744 | loge("Failed to get package version for: " + packageName); |
| 745 | return; |
| 746 | } |
| 747 | |
chen xu | db04c29 | 2019-03-26 17:01:15 -0700 | [diff] [blame] | 748 | logWithLocalLog("save config to xml, packagename: " + packageName + " phoneId: " + phoneId); |
| 749 | |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 750 | FileOutputStream outFile = null; |
| 751 | try { |
| 752 | outFile = new FileOutputStream( |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 753 | new File(mContext.getFilesDir(), |
| 754 | getFilenameForConfig(packageName, iccid, cid))); |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 755 | FastXmlSerializer out = new FastXmlSerializer(); |
| 756 | out.setOutput(outFile, "utf-8"); |
| 757 | out.startDocument("utf-8", true); |
| 758 | out.startTag(null, TAG_DOCUMENT); |
| 759 | out.startTag(null, TAG_VERSION); |
| 760 | out.text(version); |
| 761 | out.endTag(null, TAG_VERSION); |
| 762 | out.startTag(null, TAG_BUNDLE); |
| 763 | config.saveToXml(out); |
| 764 | out.endTag(null, TAG_BUNDLE); |
| 765 | out.endTag(null, TAG_DOCUMENT); |
| 766 | out.endDocument(); |
| 767 | out.flush(); |
| 768 | outFile.close(); |
| 769 | } |
| 770 | catch (IOException e) { |
| 771 | loge(e.toString()); |
| 772 | } |
| 773 | catch (XmlPullParserException e) { |
| 774 | loge(e.toString()); |
| 775 | } |
| 776 | } |
| 777 | |
| 778 | /** |
| 779 | * Reads a bundle from an XML file. |
| 780 | * |
| 781 | * This restores a bundle that was written with {@link #saveConfigToXml}. This returns the saved |
Yuchen Dong | c15afed | 2018-04-26 17:05:22 +0800 | [diff] [blame] | 782 | * config bundle for the given package and phone ID. |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 783 | * |
| 784 | * In case of errors, or if the saved config is from a different package version than the |
| 785 | * current version, then null will be returned. |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 786 | * |
| 787 | * @param packageName the name of the package from which we fetched this bundle. |
Yuchen Dong | c15afed | 2018-04-26 17:05:22 +0800 | [diff] [blame] | 788 | * @param phoneId the phone ID. |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 789 | * @return the bundle from the XML file. Returns null if there is no saved config, the saved |
| 790 | * version does not match, or reading config fails. |
| 791 | */ |
Yuchen Dong | c15afed | 2018-04-26 17:05:22 +0800 | [diff] [blame] | 792 | private PersistableBundle restoreConfigFromXml(String packageName, int phoneId) { |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 793 | final String version = getPackageVersion(packageName); |
| 794 | if (version == null) { |
| 795 | loge("Failed to get package version for: " + packageName); |
| 796 | return null; |
| 797 | } |
Yuchen Dong | c15afed | 2018-04-26 17:05:22 +0800 | [diff] [blame] | 798 | if (SubscriptionManager.getSimStateForSlotIndex(phoneId) |
| 799 | != TelephonyManager.SIM_STATE_LOADED) { |
chen xu | db04c29 | 2019-03-26 17:01:15 -0700 | [diff] [blame] | 800 | loge("Skip restoring config because SIM records are not yet loaded."); |
Yuchen Dong | c15afed | 2018-04-26 17:05:22 +0800 | [diff] [blame] | 801 | return null; |
| 802 | } |
| 803 | |
| 804 | final String iccid = getIccIdForPhoneId(phoneId); |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 805 | final int cid = getSpecificCarrierIdForPhoneId(phoneId); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 806 | if (packageName == null || iccid == null) { |
| 807 | loge("Cannot restore config with null packageName or iccid."); |
| 808 | return null; |
| 809 | } |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 810 | |
| 811 | PersistableBundle restoredBundle = null; |
| 812 | FileInputStream inFile = null; |
| 813 | try { |
| 814 | inFile = new FileInputStream( |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 815 | new File(mContext.getFilesDir(), |
| 816 | getFilenameForConfig(packageName, iccid, cid))); |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 817 | XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser(); |
| 818 | parser.setInput(inFile, "utf-8"); |
| 819 | |
| 820 | int event; |
| 821 | while (((event = parser.next()) != XmlPullParser.END_DOCUMENT)) { |
| 822 | |
| 823 | if (event == XmlPullParser.START_TAG && TAG_VERSION.equals(parser.getName())) { |
| 824 | String savedVersion = parser.nextText(); |
| 825 | if (!version.equals(savedVersion)) { |
chen xu | db04c29 | 2019-03-26 17:01:15 -0700 | [diff] [blame] | 826 | loge("Saved version mismatch: " + version + " vs " + savedVersion); |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 827 | break; |
| 828 | } |
| 829 | } |
| 830 | |
| 831 | if (event == XmlPullParser.START_TAG && TAG_BUNDLE.equals(parser.getName())) { |
| 832 | restoredBundle = PersistableBundle.restoreFromXml(parser); |
| 833 | } |
| 834 | } |
| 835 | inFile.close(); |
| 836 | } |
| 837 | catch (FileNotFoundException e) { |
| 838 | loge(e.toString()); |
| 839 | } |
| 840 | catch (XmlPullParserException e) { |
| 841 | loge(e.toString()); |
| 842 | } |
| 843 | catch (IOException e) { |
| 844 | loge(e.toString()); |
| 845 | } |
| 846 | |
| 847 | return restoredBundle; |
| 848 | } |
| 849 | |
Junda Liu | 8a8a53a | 2015-05-15 16:19:57 -0700 | [diff] [blame] | 850 | /** |
Jonathan Basseri | 7697cae | 2015-07-06 15:49:23 -0700 | [diff] [blame] | 851 | * Clears cached carrier config. |
| 852 | * This deletes all saved XML files associated with the given package name. If packageName is |
| 853 | * null, then it deletes all saved XML files. |
| 854 | * |
| 855 | * @param packageName the name of a carrier package, or null if all cached config should be |
| 856 | * cleared. |
| 857 | * @return true iff one or more files were deleted. |
Junda Liu | 8a8a53a | 2015-05-15 16:19:57 -0700 | [diff] [blame] | 858 | */ |
Jonathan Basseri | 7697cae | 2015-07-06 15:49:23 -0700 | [diff] [blame] | 859 | private boolean clearCachedConfigForPackage(final String packageName) { |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 860 | File dir = mContext.getFilesDir(); |
| 861 | File[] packageFiles = dir.listFiles(new FilenameFilter() { |
| 862 | public boolean accept(File dir, String filename) { |
Jonathan Basseri | 7697cae | 2015-07-06 15:49:23 -0700 | [diff] [blame] | 863 | if (packageName != null) { |
| 864 | return filename.startsWith("carrierconfig-" + packageName + "-"); |
| 865 | } else { |
| 866 | return filename.startsWith("carrierconfig-"); |
| 867 | } |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 868 | } |
| 869 | }); |
Junda Liu | 8a8a53a | 2015-05-15 16:19:57 -0700 | [diff] [blame] | 870 | if (packageFiles == null || packageFiles.length < 1) return false; |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 871 | for (File f : packageFiles) { |
| 872 | log("deleting " + f.getName()); |
| 873 | f.delete(); |
| 874 | } |
Junda Liu | 8a8a53a | 2015-05-15 16:19:57 -0700 | [diff] [blame] | 875 | return true; |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 876 | } |
| 877 | |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 878 | /** Builds a canonical file name for a config file. */ |
Naina Nalluri | 86fc7b0 | 2018-08-03 10:38:30 -0700 | [diff] [blame] | 879 | private String getFilenameForConfig(@NonNull String packageName, @NonNull String iccid, |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 880 | int cid) { |
| 881 | // the same carrier should have a single copy of XML file named after carrier id. |
| 882 | // However, it's still possible that platform doesn't recognize the current sim carrier, |
| 883 | // we will use iccid + carrierid as the canonical file name. carrierid can also handle the |
| 884 | // cases SIM OTA resolves to different carrier while iccid remains the same. |
| 885 | return "carrierconfig-" + packageName + "-" + iccid + "-" + cid + ".xml"; |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 886 | } |
| 887 | |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 888 | /** Return the current version code of a package, or null if the name is not found. */ |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 889 | private String getPackageVersion(String packageName) { |
| 890 | try { |
| 891 | PackageInfo info = mContext.getPackageManager().getPackageInfo(packageName, 0); |
Dianne Hackborn | b76ab20 | 2017-11-28 17:44:50 -0800 | [diff] [blame] | 892 | return Long.toString(info.getLongVersionCode()); |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 893 | } catch (PackageManager.NameNotFoundException e) { |
| 894 | return null; |
| 895 | } |
| 896 | } |
| 897 | |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 898 | /** |
| 899 | * Read up to date config. |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 900 | * |
| 901 | * This reads config bundles for the given phoneId. That means getting the latest bundle from |
| 902 | * the default app and a privileged carrier app, if present. This will not bind to an app if we |
| 903 | * have a saved config file to use instead. |
| 904 | */ |
| 905 | private void updateConfigForPhoneId(int phoneId) { |
Junda Liu | 8a8a53a | 2015-05-15 16:19:57 -0700 | [diff] [blame] | 906 | // Clear in-memory cache for carrier app config, so when carrier app gets uninstalled, no |
| 907 | // stale config is left. |
| 908 | if (mConfigFromCarrierApp[phoneId] != null && |
| 909 | getCarrierPackageForPhoneId(phoneId) == null) { |
| 910 | mConfigFromCarrierApp[phoneId] = null; |
| 911 | } |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 912 | mHandler.sendMessage(mHandler.obtainMessage(EVENT_DO_FETCH_DEFAULT, phoneId, -1)); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 913 | } |
| 914 | |
Hall Liu | 506724b | 2018-10-22 18:16:14 -0700 | [diff] [blame] | 915 | @Override |
| 916 | public @NonNull PersistableBundle getConfigForSubId(int subId, String callingPackage) { |
Malcolm Chen | 6d3d6b3 | 2018-03-01 13:58:03 -0800 | [diff] [blame] | 917 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 918 | mContext, subId, callingPackage, "getCarrierConfig")) { |
| 919 | return new PersistableBundle(); |
Amit Mahajan | 40b3fa5 | 2015-07-14 10:27:19 -0700 | [diff] [blame] | 920 | } |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 921 | |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 922 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Jonathan Basseri | c31f1f3 | 2015-05-12 10:13:03 -0700 | [diff] [blame] | 923 | PersistableBundle retConfig = CarrierConfigManager.getDefaultConfig(); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 924 | if (SubscriptionManager.isValidPhoneId(phoneId)) { |
Jonathan Basseri | c31f1f3 | 2015-05-12 10:13:03 -0700 | [diff] [blame] | 925 | PersistableBundle config = mConfigFromDefaultApp[phoneId]; |
yinxu | c5e2762 | 2017-11-29 15:08:50 -0800 | [diff] [blame] | 926 | if (config != null) { |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 927 | retConfig.putAll(config); |
yinxu | c5e2762 | 2017-11-29 15:08:50 -0800 | [diff] [blame] | 928 | retConfig.putBoolean(CarrierConfigManager.KEY_CARRIER_CONFIG_APPLIED_BOOL, true); |
| 929 | } |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 930 | config = mConfigFromCarrierApp[phoneId]; |
yinxu | c5e2762 | 2017-11-29 15:08:50 -0800 | [diff] [blame] | 931 | if (config != null) { |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 932 | retConfig.putAll(config); |
yinxu | c5e2762 | 2017-11-29 15:08:50 -0800 | [diff] [blame] | 933 | retConfig.putBoolean(CarrierConfigManager.KEY_CARRIER_CONFIG_APPLIED_BOOL, true); |
| 934 | } |
Hall Liu | 506724b | 2018-10-22 18:16:14 -0700 | [diff] [blame] | 935 | config = mOverrideConfigs[phoneId]; |
| 936 | if (config != null) { |
| 937 | retConfig.putAll(config); |
| 938 | retConfig.putBoolean(CarrierConfigManager.KEY_CARRIER_CONFIG_APPLIED_BOOL, true); |
| 939 | } |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 940 | } |
| 941 | return retConfig; |
| 942 | } |
| 943 | |
| 944 | @Override |
Hall Liu | 506724b | 2018-10-22 18:16:14 -0700 | [diff] [blame] | 945 | public void overrideConfig(int subscriptionId, PersistableBundle overrides) { |
| 946 | mContext.enforceCallingOrSelfPermission( |
| 947 | android.Manifest.permission.MODIFY_PHONE_STATE, null); |
Brad Ebinger | f6281ad | 2019-04-25 11:02:04 -0700 | [diff] [blame] | 948 | //TODO: Also check for SHELL UID to restrict this method to testing only (b/131326259) |
Hall Liu | 506724b | 2018-10-22 18:16:14 -0700 | [diff] [blame] | 949 | int phoneId = SubscriptionManager.getPhoneId(subscriptionId); |
| 950 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 951 | log("Ignore invalid phoneId: " + phoneId + " for subId: " + subscriptionId); |
| 952 | return; |
| 953 | } |
| 954 | |
| 955 | if (overrides == null) { |
| 956 | mOverrideConfigs[phoneId] = new PersistableBundle(); |
Brad Ebinger | 725edf6 | 2019-05-15 18:24:13 -0700 | [diff] [blame] | 957 | } else if (mOverrideConfigs[phoneId] == null) { |
Hall Liu | 506724b | 2018-10-22 18:16:14 -0700 | [diff] [blame] | 958 | mOverrideConfigs[phoneId] = overrides; |
| 959 | } else { |
| 960 | mOverrideConfigs[phoneId].putAll(overrides); |
| 961 | } |
Brad Ebinger | c9d1fa1 | 2019-04-17 15:21:18 -0700 | [diff] [blame] | 962 | |
| 963 | notifySubscriptionInfoUpdater(phoneId); |
Hall Liu | 506724b | 2018-10-22 18:16:14 -0700 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | @Override |
Jonathan Basseri | 8603035 | 2015-06-08 12:27:56 -0700 | [diff] [blame] | 967 | public void notifyConfigChangedForSubId(int subId) { |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 968 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 969 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 970 | log("Ignore invalid phoneId: " + phoneId + " for subId: " + subId); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 971 | return; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 972 | } |
Jordan Liu | d7d57fe | 2019-04-16 12:29:43 -0700 | [diff] [blame] | 973 | |
| 974 | // Requires the calling app to be either a carrier privileged app for this subId or |
Junda Liu | fbd2bcb | 2016-06-15 11:15:42 -0700 | [diff] [blame] | 975 | // system privileged app with MODIFY_PHONE_STATE permission. |
Jordan Liu | d7d57fe | 2019-04-16 12:29:43 -0700 | [diff] [blame] | 976 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mContext, subId, |
| 977 | "Require carrier privileges or MODIFY_PHONE_STATE permission."); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 978 | |
| 979 | // This method should block until deleting has completed, so that an error which prevents us |
| 980 | // from clearing the cache is passed back to the carrier app. With the files successfully |
| 981 | // deleted, this can return and we will eventually bind to the carrier app. |
Jordan Liu | d7d57fe | 2019-04-16 12:29:43 -0700 | [diff] [blame] | 982 | String callingPackageName = mContext.getPackageManager().getNameForUid( |
| 983 | Binder.getCallingUid()); |
Jonathan Basseri | 7697cae | 2015-07-06 15:49:23 -0700 | [diff] [blame] | 984 | clearCachedConfigForPackage(callingPackageName); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 985 | updateConfigForPhoneId(phoneId); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | @Override |
| 989 | public void updateConfigForPhoneId(int phoneId, String simState) { |
Junda Liu | 1f2b34d | 2015-06-18 15:26:56 -0700 | [diff] [blame] | 990 | mContext.enforceCallingOrSelfPermission( |
| 991 | android.Manifest.permission.MODIFY_PHONE_STATE, null); |
chen xu | c481097 | 2019-04-17 23:44:43 -0700 | [diff] [blame] | 992 | logWithLocalLog("update config for phoneId: " + phoneId + " simState: " + simState); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 993 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 994 | return; |
| 995 | } |
| 996 | // requires Java 7 for switch on string. |
| 997 | switch (simState) { |
| 998 | case IccCardConstants.INTENT_VALUE_ICC_ABSENT: |
| 999 | case IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR: |
Junda Liu | 6f5fddf | 2016-05-24 16:14:41 -0700 | [diff] [blame] | 1000 | case IccCardConstants.INTENT_VALUE_ICC_CARD_RESTRICTED: |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 1001 | case IccCardConstants.INTENT_VALUE_ICC_UNKNOWN: |
Junda Liu | 9f2d271 | 2015-05-15 14:22:45 -0700 | [diff] [blame] | 1002 | mHandler.sendMessage(mHandler.obtainMessage(EVENT_CLEAR_CONFIG, phoneId, -1)); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 1003 | break; |
| 1004 | case IccCardConstants.INTENT_VALUE_ICC_LOADED: |
| 1005 | case IccCardConstants.INTENT_VALUE_ICC_LOCKED: |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 1006 | updateConfigForPhoneId(phoneId); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 1007 | break; |
| 1008 | } |
| 1009 | } |
| 1010 | |
Junda Liu | 43d723a | 2015-05-12 17:23:45 -0700 | [diff] [blame] | 1011 | @Override |
Jeff Sharkey | a6fcfed | 2017-07-20 14:18:39 -0600 | [diff] [blame] | 1012 | public String getDefaultCarrierServicePackageName() { |
| 1013 | return mPlatformCarrierConfigPackage; |
| 1014 | } |
| 1015 | |
| 1016 | @Override |
Junda Liu | 43d723a | 2015-05-12 17:23:45 -0700 | [diff] [blame] | 1017 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 1018 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 1019 | != PackageManager.PERMISSION_GRANTED) { |
| 1020 | pw.println("Permission Denial: can't dump carrierconfig from from pid=" |
| 1021 | + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()); |
| 1022 | return; |
| 1023 | } |
| 1024 | pw.println("CarrierConfigLoader: " + this); |
| 1025 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
shuoq | 26a3a4c | 2016-12-16 11:06:48 -0800 | [diff] [blame] | 1026 | pw.println("Phone Id = " + i); |
| 1027 | // display default values in CarrierConfigManager |
| 1028 | printConfig(CarrierConfigManager.getDefaultConfig(), pw, |
| 1029 | "Default Values from CarrierConfigManager"); |
| 1030 | pw.println(""); |
| 1031 | // display ConfigFromDefaultApp |
| 1032 | printConfig(mConfigFromDefaultApp[i], pw, "mConfigFromDefaultApp"); |
| 1033 | pw.println(""); |
| 1034 | // display ConfigFromCarrierApp |
| 1035 | printConfig(mConfigFromCarrierApp[i], pw, "mConfigFromCarrierApp"); |
Hall Liu | 506724b | 2018-10-22 18:16:14 -0700 | [diff] [blame] | 1036 | pw.println(""); |
| 1037 | printConfig(mOverrideConfigs[i], pw, "mOverrideConfigs"); |
shuoq | 26a3a4c | 2016-12-16 11:06:48 -0800 | [diff] [blame] | 1038 | } |
chen xu | db04c29 | 2019-03-26 17:01:15 -0700 | [diff] [blame] | 1039 | |
| 1040 | pw.println("CarrierConfigLoadingLog="); |
| 1041 | mCarrierConfigLoadingLog.dump(fd, pw, args); |
shuoq | 26a3a4c | 2016-12-16 11:06:48 -0800 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | private void printConfig(PersistableBundle configApp, PrintWriter pw, String name) { |
| 1045 | IndentingPrintWriter indentPW = new IndentingPrintWriter(pw, " "); |
| 1046 | if (configApp == null) { |
| 1047 | indentPW.increaseIndent(); |
| 1048 | indentPW.println(name + " : null "); |
| 1049 | return; |
| 1050 | } |
| 1051 | indentPW.increaseIndent(); |
| 1052 | indentPW.println(name + " : "); |
| 1053 | List<String> sortedKeys = new ArrayList<String>(configApp.keySet()); |
| 1054 | Collections.sort(sortedKeys); |
| 1055 | indentPW.increaseIndent(); |
| 1056 | indentPW.increaseIndent(); |
| 1057 | for (String key : sortedKeys) { |
| 1058 | if (configApp.get(key) != null && configApp.get(key) instanceof Object[]) { |
| 1059 | indentPW.println(key + " = " + |
| 1060 | Arrays.toString((Object[]) configApp.get(key))); |
| 1061 | } else if (configApp.get(key) != null && configApp.get(key) instanceof int[]) { |
| 1062 | indentPW.println(key + " = " + Arrays.toString((int[]) configApp.get(key))); |
| 1063 | } else { |
| 1064 | indentPW.println(key + " = " + configApp.get(key)); |
| 1065 | } |
Junda Liu | 43d723a | 2015-05-12 17:23:45 -0700 | [diff] [blame] | 1066 | } |
| 1067 | } |
| 1068 | |
Zach Johnson | 36d7aab | 2015-05-22 15:43:00 -0700 | [diff] [blame] | 1069 | private class CarrierServiceConnection implements ServiceConnection { |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 1070 | int phoneId; |
| 1071 | int eventId; |
| 1072 | IBinder service; |
| 1073 | |
Zach Johnson | 36d7aab | 2015-05-22 15:43:00 -0700 | [diff] [blame] | 1074 | public CarrierServiceConnection(int phoneId, int eventId) { |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 1075 | this.phoneId = phoneId; |
| 1076 | this.eventId = eventId; |
| 1077 | } |
| 1078 | |
| 1079 | @Override |
| 1080 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 1081 | log("Connected to config app: " + name.flattenToString()); |
| 1082 | this.service = service; |
| 1083 | mHandler.sendMessage(mHandler.obtainMessage(eventId, phoneId, -1, this)); |
| 1084 | } |
| 1085 | |
| 1086 | @Override |
| 1087 | public void onServiceDisconnected(ComponentName name) { |
| 1088 | this.service = null; |
| 1089 | } |
| 1090 | } |
| 1091 | |
| 1092 | private class ConfigLoaderBroadcastReceiver extends BroadcastReceiver { |
| 1093 | @Override |
| 1094 | public void onReceive(Context context, Intent intent) { |
| 1095 | String action = intent.getAction(); |
Junda Liu | 8a8a53a | 2015-05-15 16:19:57 -0700 | [diff] [blame] | 1096 | boolean replace = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false); |
| 1097 | // If replace is true, only care ACTION_PACKAGE_REPLACED. |
| 1098 | if (replace && !Intent.ACTION_PACKAGE_REPLACED.equals(action)) |
| 1099 | return; |
| 1100 | |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 1101 | switch (action) { |
Nanxi Chen | 3d67050 | 2016-03-17 16:32:09 -0700 | [diff] [blame] | 1102 | case Intent.ACTION_BOOT_COMPLETED: |
| 1103 | mHandler.sendMessage(mHandler.obtainMessage(EVENT_SYSTEM_UNLOCKED, null)); |
| 1104 | break; |
| 1105 | |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 1106 | case Intent.ACTION_PACKAGE_ADDED: |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 1107 | case Intent.ACTION_PACKAGE_REMOVED: |
Junda Liu | 8a8a53a | 2015-05-15 16:19:57 -0700 | [diff] [blame] | 1108 | case Intent.ACTION_PACKAGE_REPLACED: |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 1109 | int uid = intent.getIntExtra(Intent.EXTRA_UID, -1); |
| 1110 | String packageName = mContext.getPackageManager().getNameForUid(uid); |
Junda Liu | 8a8a53a | 2015-05-15 16:19:57 -0700 | [diff] [blame] | 1111 | if (packageName != null) { |
| 1112 | // We don't have a phoneId for arg1. |
| 1113 | mHandler.sendMessage( |
| 1114 | mHandler.obtainMessage(EVENT_PACKAGE_CHANGED, packageName)); |
| 1115 | } |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 1116 | break; |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 1117 | } |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 1118 | } |
| 1119 | } |
| 1120 | |
chen xu | db04c29 | 2019-03-26 17:01:15 -0700 | [diff] [blame] | 1121 | private void log(String msg) { |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 1122 | Log.d(LOG_TAG, msg); |
| 1123 | } |
| 1124 | |
chen xu | db04c29 | 2019-03-26 17:01:15 -0700 | [diff] [blame] | 1125 | private void logWithLocalLog(String msg) { |
| 1126 | Log.d(LOG_TAG, msg); |
| 1127 | mCarrierConfigLoadingLog.log(msg); |
| 1128 | } |
| 1129 | |
| 1130 | private void loge(String msg) { |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 1131 | Log.e(LOG_TAG, msg); |
chen xu | db04c29 | 2019-03-26 17:01:15 -0700 | [diff] [blame] | 1132 | mCarrierConfigLoadingLog.log(msg); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 1133 | } |
| 1134 | } |