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