blob: 8df411b2716969fda2ecae8703bb8db501fd071b [file] [log] [blame]
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001/*
Jonathan Basseri6465afd2015-02-25 13:05:57 -08002 * 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 Basseri6465afd2015-02-25 13:05:57 -080017package com.android.phone;
18
Jonathan Basseri65273c82017-07-25 15:08:42 -070019import static android.service.carrier.CarrierService.ICarrierServiceWrapper.KEY_CONFIG_BUNDLE;
20import static android.service.carrier.CarrierService.ICarrierServiceWrapper.RESULT_ERROR;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080021
Jonathan Basseri11f89572015-05-05 11:57:39 -070022import android.annotation.NonNull;
Torbjorn Eklund723527a2019-02-13 11:16:25 +010023import android.annotation.Nullable;
Hunter Knepshielde601f432020-02-19 10:16:04 -080024import android.app.AppOpsManager;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080025import android.content.BroadcastReceiver;
26import android.content.ComponentName;
27import android.content.Context;
28import android.content.Intent;
29import android.content.IntentFilter;
30import android.content.ServiceConnection;
Jonathan Basseri7697cae2015-07-06 15:49:23 -070031import android.content.SharedPreferences;
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -070032import android.content.pm.PackageInfo;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070033import android.content.pm.PackageManager;
Junda Liu43d723a2015-05-12 17:23:45 -070034import android.os.Binder;
Jonathan Basseri7697cae2015-07-06 15:49:23 -070035import android.os.Build;
Jonathan Basseri65273c82017-07-25 15:08:42 -070036import android.os.Bundle;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080037import android.os.Handler;
38import android.os.IBinder;
Rambo Wang7e3bc122021-03-23 09:24:38 -070039import android.os.Looper;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080040import android.os.Message;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070041import android.os.PersistableBundle;
Hunter Knepshielde601f432020-02-19 10:16:04 -080042import android.os.Process;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080043import android.os.RemoteException;
Jonathan Basseri65273c82017-07-25 15:08:42 -070044import android.os.ResultReceiver;
Meng Wang97a6a462020-01-23 16:22:16 -080045import android.os.UserHandle;
Jonathan Basseri7697cae2015-07-06 15:49:23 -070046import android.preference.PreferenceManager;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080047import android.service.carrier.CarrierIdentifier;
Zach Johnson36d7aab2015-05-22 15:43:00 -070048import android.service.carrier.CarrierService;
49import android.service.carrier.ICarrierService;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080050import android.telephony.CarrierConfigManager;
51import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080052import android.telephony.TelephonyFrameworkInitializer;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080053import android.telephony.TelephonyManager;
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -080054import android.text.TextUtils;
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -080055import android.util.ArraySet;
chen xudb04c292019-03-26 17:01:15 -070056import android.util.LocalLog;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080057import android.util.Log;
58
Rambo Wang7e3bc122021-03-23 09:24:38 -070059import com.android.internal.annotations.VisibleForTesting;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080060import com.android.internal.telephony.ICarrierConfigLoader;
61import com.android.internal.telephony.IccCardConstants;
62import com.android.internal.telephony.Phone;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080063import com.android.internal.telephony.PhoneFactory;
Nathan Harold48ac0972019-03-13 22:33:01 -070064import com.android.internal.telephony.SubscriptionInfoUpdater;
Jeff Davidsona8e4e242018-03-15 17:16:18 -070065import com.android.internal.telephony.TelephonyPermissions;
Meng Wanga320b942019-11-25 11:21:26 -080066import com.android.internal.telephony.util.ArrayUtils;
shuoq26a3a4c2016-12-16 11:06:48 -080067import com.android.internal.util.IndentingPrintWriter;
arunvoddu664c36a2021-10-11 20:09:28 +000068import com.android.telephony.Rlog;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080069
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -070070import java.io.File;
Junda Liu43d723a2015-05-12 17:23:45 -070071import java.io.FileDescriptor;
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -070072import java.io.FileInputStream;
73import java.io.FileNotFoundException;
74import java.io.FileOutputStream;
Jonathan Basseri1f743c92015-05-15 00:19:46 -070075import java.io.FilenameFilter;
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -070076import java.io.IOException;
Junda Liu43d723a2015-05-12 17:23:45 -070077import java.io.PrintWriter;
shuoq26a3a4c2016-12-16 11:06:48 -080078import java.util.ArrayList;
79import java.util.Arrays;
80import java.util.Collections;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080081import java.util.List;
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -080082import java.util.Set;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080083
84/**
85 * CarrierConfigLoader binds to privileged carrier apps to fetch carrier config overlays.
Jonathan Basseri6465afd2015-02-25 13:05:57 -080086 */
Jonathan Basseri6465afd2015-02-25 13:05:57 -080087public class CarrierConfigLoader extends ICarrierConfigLoader.Stub {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -070088 private static final String LOG_TAG = "CarrierConfigLoader";
Meng Wang33ad2bc2017-03-16 20:21:20 -070089
90 // Package name for platform carrier config app, bundled with system image.
91 private final String mPlatformCarrierConfigPackage;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080092
93 /** The singleton instance. */
94 private static CarrierConfigLoader sInstance;
95 // The context for phone app, passed from PhoneGlobals.
96 private Context mContext;
97 // Carrier configs from default app, indexed by phoneID.
Jonathan Basseric31f1f32015-05-12 10:13:03 -070098 private PersistableBundle[] mConfigFromDefaultApp;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080099 // Carrier configs from privileged carrier config app, indexed by phoneID.
Jonathan Basseric31f1f32015-05-12 10:13:03 -0700100 private PersistableBundle[] mConfigFromCarrierApp;
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100101 // Persistent Carrier configs that are provided via the override test API, indexed by phone ID.
102 private PersistableBundle[] mPersistentOverrideConfigs;
Hall Liu506724b2018-10-22 18:16:14 -0700103 // Carrier configs that are provided via the override test API, indexed by phone ID.
104 private PersistableBundle[] mOverrideConfigs;
Jayachandran C645ec612020-01-10 10:30:25 -0800105 // Carrier configs to override code default when there is no SIM inserted
106 private PersistableBundle mNoSimConfig;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800107 // Service connection for binding to config app.
Zach Johnson36d7aab2015-05-22 15:43:00 -0700108 private CarrierServiceConnection[] mServiceConnection;
Jayachandran C645ec612020-01-10 10:30:25 -0800109 // Service connection for binding to carrier config app for no SIM config.
110 private CarrierServiceConnection[] mServiceConnectionForNoSimConfig;
Sarah Chin807d5c62020-03-30 17:21:09 -0700111 // Whether we have sent config change broadcast for each phone id.
Junda Liu03aad762017-07-21 13:32:17 -0700112 private boolean[] mHasSentConfigChange;
Sarah Chin807d5c62020-03-30 17:21:09 -0700113 // Whether the broadcast was sent from EVENT_SYSTEM_UNLOCKED, to track rebroadcasts
114 private boolean[] mFromSystemUnlocked;
Nathan Harold48ac0972019-03-13 22:33:01 -0700115 // SubscriptionInfoUpdater
116 private final SubscriptionInfoUpdater mSubscriptionInfoUpdater;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800117
Nanxi Chen3d670502016-03-17 16:32:09 -0700118 // Broadcast receiver for Boot intents, register intent filter in construtor.
119 private final BroadcastReceiver mBootReceiver = new ConfigLoaderBroadcastReceiver();
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800120 // Broadcast receiver for SIM and pkg intents, register intent filter in constructor.
Nanxi Chen3d670502016-03-17 16:32:09 -0700121 private final BroadcastReceiver mPackageReceiver = new ConfigLoaderBroadcastReceiver();
Jack Yu67663de2019-10-17 15:19:48 -0700122 private final LocalLog mCarrierConfigLoadingLog = new LocalLog(100);
chen xudb04c292019-03-26 17:01:15 -0700123
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800124
125 // Message codes; see mHandler below.
126 // Request from SubscriptionInfoUpdater when SIM becomes absent or error.
127 private static final int EVENT_CLEAR_CONFIG = 0;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800128 // Has connected to default app.
129 private static final int EVENT_CONNECTED_TO_DEFAULT = 3;
130 // Has connected to carrier app.
131 private static final int EVENT_CONNECTED_TO_CARRIER = 4;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700132 // Config has been loaded from default app (or cache).
133 private static final int EVENT_FETCH_DEFAULT_DONE = 5;
134 // Config has been loaded from carrier app (or cache).
135 private static final int EVENT_FETCH_CARRIER_DONE = 6;
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700136 // Attempt to fetch from default app or read from XML.
Jonathan Basseri65273c82017-07-25 15:08:42 -0700137 private static final int EVENT_DO_FETCH_DEFAULT = 7;
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700138 // Attempt to fetch from carrier app or read from XML.
Jonathan Basseri65273c82017-07-25 15:08:42 -0700139 private static final int EVENT_DO_FETCH_CARRIER = 8;
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700140 // A package has been installed, uninstalled, or updated.
141 private static final int EVENT_PACKAGE_CHANGED = 9;
Jonathan Basseri930701e2015-06-11 20:56:43 -0700142 // Bind timed out for the default app.
143 private static final int EVENT_BIND_DEFAULT_TIMEOUT = 10;
144 // Bind timed out for a carrier app.
145 private static final int EVENT_BIND_CARRIER_TIMEOUT = 11;
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700146 // Check if the system fingerprint has changed.
147 private static final int EVENT_CHECK_SYSTEM_UPDATE = 12;
Nanxi Chen3d670502016-03-17 16:32:09 -0700148 // Rerun carrier config binding after system is unlocked.
149 private static final int EVENT_SYSTEM_UNLOCKED = 13;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700150 // Fetching config timed out from the default app.
151 private static final int EVENT_FETCH_DEFAULT_TIMEOUT = 14;
152 // Fetching config timed out from a carrier app.
153 private static final int EVENT_FETCH_CARRIER_TIMEOUT = 15;
Nathan Harold48ac0972019-03-13 22:33:01 -0700154 // SubscriptionInfoUpdater has finished updating the sub for the carrier config.
155 private static final int EVENT_SUBSCRIPTION_INFO_UPDATED = 16;
Malcolm Chen5ea18532019-10-24 19:55:44 -0700156 // Multi-SIM config changed.
157 private static final int EVENT_MULTI_SIM_CONFIG_CHANGED = 17;
Jayachandran C645ec612020-01-10 10:30:25 -0800158 // Attempt to fetch from default app or read from XML for no SIM case.
159 private static final int EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG = 18;
160 // No SIM config has been loaded from default app (or cache).
161 private static final int EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE = 19;
162 // Has connected to default app for no SIM config.
163 private static final int EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG = 20;
164 // Bind timed out for the default app when trying to fetch no SIM config.
165 private static final int EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT = 21;
166 // Fetching config timed out from the default app for no SIM config.
167 private static final int EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT = 22;
Rambo Wangab13e3e2021-04-08 15:01:06 -0700168 // NOTE: any new EVENT_* values must be added to method eventToString().
Jonathan Basseri930701e2015-06-11 20:56:43 -0700169
Junda Liu6cb45002016-03-22 17:18:20 -0700170 private static final int BIND_TIMEOUT_MILLIS = 30000;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800171
Meng Wang0f6b2ea2020-01-06 18:31:16 -0800172 // Keys used for saving and restoring config bundle from file.
173 private static final String KEY_VERSION = "__carrier_config_package_version__";
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800174
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100175 private static final String OVERRIDE_PACKAGE_ADDITION = "-override";
176
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700177 // SharedPreferences key for last known build fingerprint.
178 private static final String KEY_FINGERPRINT = "build_fingerprint";
179
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -0800180 // Argument for #dump that indicates we should also call the default and specified carrier
181 // service's #dump method. In multi-SIM devices, it's possible that carrier A is on SIM 1 and
182 // carrier B is on SIM 2, in which case we should not dump carrier B's service when carrier A
183 // requested the dump.
184 private static final String DUMP_ARG_REQUESTING_PACKAGE = "--requesting-package";
185
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800186 // Handler to process various events.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700187 //
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700188 // For each phoneId, the event sequence should be:
Jonathan Basseri65273c82017-07-25 15:08:42 -0700189 // fetch default, connected to default, fetch default (async), fetch default done,
190 // fetch carrier, connected to carrier, fetch carrier (async), fetch carrier done.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700191 //
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700192 // If there is a saved config file for either the default app or the carrier app, we skip
193 // binding to the app and go straight from fetch to loaded.
194 //
195 // At any time, at most one connection is active. If events are not in this order, previous
196 // connection will be unbound, so only latest event takes effect.
197 //
198 // We broadcast ACTION_CARRIER_CONFIG_CHANGED after:
199 // 1. loading from carrier app (even if read from a file)
200 // 2. loading from default app if there is no carrier app (even if read from a file)
201 // 3. clearing config (e.g. due to sim removal)
202 // 4. encountering bind or IPC error
Jonathan Basseri65273c82017-07-25 15:08:42 -0700203 private class ConfigHandler extends Handler {
Rambo Wang7e3bc122021-03-23 09:24:38 -0700204 ConfigHandler(@NonNull Looper looper) {
205 super(looper);
206 }
207
Jonathan Basseri65273c82017-07-25 15:08:42 -0700208 @Override
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800209 public void handleMessage(Message msg) {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700210 final int phoneId = msg.arg1;
Rambo Wangab13e3e2021-04-08 15:01:06 -0700211 logdWithLocalLog("mHandler: " + eventToString(msg.what) + " phoneId: " + phoneId);
Malcolm Chen5ea18532019-10-24 19:55:44 -0700212 if (!SubscriptionManager.isValidPhoneId(phoneId)
213 && msg.what != EVENT_MULTI_SIM_CONFIG_CHANGED) {
214 return;
215 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800216 switch (msg.what) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800217 case EVENT_CLEAR_CONFIG: {
Malcolm Chen5ea18532019-10-24 19:55:44 -0700218 clearConfigForPhone(phoneId, true);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800219 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700220 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700221
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800222 case EVENT_SYSTEM_UNLOCKED: {
Malcolm Chen5ea18532019-10-24 19:55:44 -0700223 for (int i = 0; i < TelephonyManager.from(mContext).getActiveModemCount();
224 ++i) {
Sarah Chin807d5c62020-03-30 17:21:09 -0700225 // When the user unlocks the device, send the broadcast again (with a
226 // rebroadcast extra) if we have sent it before unlock. This will avoid
227 // trying to load the carrier config when the SIM is still loading when the
228 // unlock happens.
Junda Liu03aad762017-07-21 13:32:17 -0700229 if (mHasSentConfigChange[i]) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800230 logdWithLocalLog("System unlocked");
Sarah Chin807d5c62020-03-30 17:21:09 -0700231 mFromSystemUnlocked[i] = true;
Junda Liu03aad762017-07-21 13:32:17 -0700232 updateConfigForPhoneId(i);
233 }
Nanxi Chen3d670502016-03-17 16:32:09 -0700234 }
235 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700236 }
Nanxi Chen3d670502016-03-17 16:32:09 -0700237
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800238 case EVENT_PACKAGE_CHANGED: {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700239 final String carrierPackageName = (String) msg.obj;
240 // Only update if there are cached config removed to avoid updating config for
241 // unrelated packages.
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700242 if (clearCachedConfigForPackage(carrierPackageName)) {
Malcolm Chen5ea18532019-10-24 19:55:44 -0700243 int numPhones = TelephonyManager.from(mContext).getActiveModemCount();
Junda Liu8a8a53a2015-05-15 16:19:57 -0700244 for (int i = 0; i < numPhones; ++i) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800245 logdWithLocalLog("Package changed: " + carrierPackageName
Jack Yu67663de2019-10-17 15:19:48 -0700246 + ", phone=" + i);
Junda Liu8a8a53a2015-05-15 16:19:57 -0700247 updateConfigForPhoneId(i);
248 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700249 }
250 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700251 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700252
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800253 case EVENT_DO_FETCH_DEFAULT: {
Rambo Wang9bc7d362021-03-09 09:10:58 -0800254 // Clear in-memory cache for carrier app config, so when carrier app gets
255 // uninstalled, no stale config is left.
256 if (mConfigFromCarrierApp[phoneId] != null
257 && getCarrierPackageForPhoneId(phoneId) == null) {
258 mConfigFromCarrierApp[phoneId] = null;
259 }
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100260 // Restore persistent override values.
261 PersistableBundle config = restoreConfigFromXml(
262 mPlatformCarrierConfigPackage, OVERRIDE_PACKAGE_ADDITION, phoneId);
263 if (config != null) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800264 logd("Loaded persistent override config from XML. package="
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100265 + mPlatformCarrierConfigPackage
266 + " phoneId=" + phoneId);
267 mPersistentOverrideConfigs[phoneId] = config;
268 }
269
270 config = restoreConfigFromXml(mPlatformCarrierConfigPackage, "", phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700271 if (config != null) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800272 logd(
Jonathan Basseri65273c82017-07-25 15:08:42 -0700273 "Loaded config from XML. package="
274 + mPlatformCarrierConfigPackage
275 + " phoneId="
276 + phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700277 mConfigFromDefaultApp[phoneId] = config;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700278 Message newMsg = obtainMessage(EVENT_FETCH_DEFAULT_DONE, phoneId, -1);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700279 newMsg.getData().putBoolean("loaded_from_xml", true);
280 mHandler.sendMessage(newMsg);
281 } else {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700282 // No cached config, so fetch it from the default app.
283 if (bindToConfigPackage(
284 mPlatformCarrierConfigPackage,
285 phoneId,
286 EVENT_CONNECTED_TO_DEFAULT)) {
287 sendMessageDelayed(
Rambo Wang610fdf62021-03-08 21:37:11 -0800288 obtainMessage(EVENT_BIND_DEFAULT_TIMEOUT, phoneId, -1 /*arg2*/,
289 getMessageToken(phoneId)),
Jonathan Basseri930701e2015-06-11 20:56:43 -0700290 BIND_TIMEOUT_MILLIS);
291 } else {
Nathan Harold1122e3d2021-01-22 15:45:24 -0800292 // Put a stub bundle in place so that the rest of the logic continues
293 // smoothly.
Rambo Wang42026112021-04-07 20:57:28 +0000294 mConfigFromDefaultApp[phoneId] = new PersistableBundle();
Jonathan Basseri65273c82017-07-25 15:08:42 -0700295 // Send broadcast if bind fails.
Nathan Harold48ac0972019-03-13 22:33:01 -0700296 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700297 // TODO: We *must* call unbindService even if bindService returns false.
298 // (And possibly if SecurityException was thrown.)
chen xudb04c292019-03-26 17:01:15 -0700299 loge("binding to default app: "
300 + mPlatformCarrierConfigPackage + " fails");
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700301 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800302 }
303 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700304 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800305
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800306 case EVENT_CONNECTED_TO_DEFAULT: {
Rambo Wang610fdf62021-03-08 21:37:11 -0800307 removeMessages(EVENT_BIND_DEFAULT_TIMEOUT, getMessageToken(phoneId));
Jonathan Basseri65273c82017-07-25 15:08:42 -0700308 final CarrierServiceConnection conn = (CarrierServiceConnection) msg.obj;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800309 // If new service connection has been created, unbind.
310 if (mServiceConnection[phoneId] != conn || conn.service == null) {
Rambo Wangc5901222021-09-17 13:18:35 -0700311 unbindIfBound(mContext, conn);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800312 break;
313 }
chen xu02581692018-11-11 19:03:44 -0800314 final CarrierIdentifier carrierId = getCarrierIdentifierForPhoneId(phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700315 // ResultReceiver callback will execute in this Handler's thread.
316 final ResultReceiver resultReceiver =
317 new ResultReceiver(this) {
318 @Override
319 public void onReceiveResult(int resultCode, Bundle resultData) {
Rambo Wangc5901222021-09-17 13:18:35 -0700320 unbindIfBound(mContext, conn);
Rambo Wanga9d27a52021-04-09 16:17:33 -0700321 removeMessages(EVENT_FETCH_DEFAULT_TIMEOUT,
322 getMessageToken(phoneId));
Jonathan Basseri65273c82017-07-25 15:08:42 -0700323 // If new service connection has been created, this is stale.
324 if (mServiceConnection[phoneId] != conn) {
325 loge("Received response for stale request.");
326 return;
327 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700328 if (resultCode == RESULT_ERROR || resultData == null) {
329 // On error, abort config fetching.
330 loge("Failed to get carrier config");
Nathan Harold48ac0972019-03-13 22:33:01 -0700331 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700332 return;
333 }
334 PersistableBundle config =
335 resultData.getParcelable(KEY_CONFIG_BUNDLE);
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100336 saveConfigToXml(mPlatformCarrierConfigPackage, "", phoneId,
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800337 carrierId, config);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700338 mConfigFromDefaultApp[phoneId] = config;
339 sendMessage(
340 obtainMessage(
341 EVENT_FETCH_DEFAULT_DONE, phoneId, -1));
342 }
343 };
344 // Now fetch the config asynchronously from the ICarrierService.
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800345 try {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700346 ICarrierService carrierService =
347 ICarrierService.Stub.asInterface(conn.service);
348 carrierService.getCarrierConfig(carrierId, resultReceiver);
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800349 logdWithLocalLog("Fetch config for default app: "
chen xudb04c292019-03-26 17:01:15 -0700350 + mPlatformCarrierConfigPackage
351 + " carrierid: " + carrierId.toString());
Jonathan Basseri65273c82017-07-25 15:08:42 -0700352 } catch (RemoteException e) {
chen xudb04c292019-03-26 17:01:15 -0700353 loge("Failed to get carrier config from default app: " +
354 mPlatformCarrierConfigPackage + " err: " + e.toString());
Rambo Wangc5901222021-09-17 13:18:35 -0700355 unbindIfBound(mContext, conn);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700356 break; // So we don't set a timeout.
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800357 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700358 sendMessageDelayed(
Rambo Wang610fdf62021-03-08 21:37:11 -0800359 obtainMessage(EVENT_FETCH_DEFAULT_TIMEOUT, phoneId, -1 /*arg2*/,
360 getMessageToken(phoneId)),
Jonathan Basseri65273c82017-07-25 15:08:42 -0700361 BIND_TIMEOUT_MILLIS);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800362 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700363 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800364
Jonathan Basseri930701e2015-06-11 20:56:43 -0700365 case EVENT_BIND_DEFAULT_TIMEOUT:
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800366 case EVENT_FETCH_DEFAULT_TIMEOUT: {
367 loge("Bind/fetch time out from " + mPlatformCarrierConfigPackage);
Rambo Wang610fdf62021-03-08 21:37:11 -0800368 removeMessages(EVENT_FETCH_DEFAULT_TIMEOUT, getMessageToken(phoneId));
chen xuf60b3162019-05-01 21:31:05 -0700369 // If we attempted to bind to the app, but the service connection is null due to
370 // the race condition that clear config event happens before bind/fetch complete
371 // then config was cleared while we were waiting and we should not continue.
372 if (mServiceConnection[phoneId] != null) {
373 // If a ResponseReceiver callback is in the queue when this happens, we will
374 // unbind twice and throw an exception.
Rambo Wangc5901222021-09-17 13:18:35 -0700375 unbindIfBound(mContext, mServiceConnection[phoneId]);
chen xuf60b3162019-05-01 21:31:05 -0700376 broadcastConfigChangedIntent(phoneId);
377 }
Nathan Harold1122e3d2021-01-22 15:45:24 -0800378 // Put a stub bundle in place so that the rest of the logic continues smoothly.
Rambo Wang42026112021-04-07 20:57:28 +0000379 mConfigFromDefaultApp[phoneId] = new PersistableBundle();
Nathan Harold48ac0972019-03-13 22:33:01 -0700380 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri930701e2015-06-11 20:56:43 -0700381 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700382 }
Jonathan Basseri930701e2015-06-11 20:56:43 -0700383
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800384 case EVENT_FETCH_DEFAULT_DONE: {
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700385 // If we attempted to bind to the app, but the service connection is null, then
386 // config was cleared while we were waiting and we should not continue.
387 if (!msg.getData().getBoolean("loaded_from_xml", false)
388 && mServiceConnection[phoneId] == null) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800389 break;
390 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700391 final String carrierPackageName = getCarrierPackageForPhoneId(phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700392 if (carrierPackageName != null) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800393 logd("Found carrier config app: " + carrierPackageName);
Jordan Liu38a614c2019-03-20 15:01:17 -0700394 sendMessage(obtainMessage(EVENT_DO_FETCH_CARRIER, phoneId, -1));
Jonathan Basserib919e932015-05-27 16:53:08 +0000395 } else {
Nathan Harold48ac0972019-03-13 22:33:01 -0700396 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri4ae2e7c2015-05-15 00:19:46 -0700397 }
398 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700399 }
Jonathan Basseri4ae2e7c2015-05-15 00:19:46 -0700400
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800401 case EVENT_DO_FETCH_CARRIER: {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700402 final String carrierPackageName = getCarrierPackageForPhoneId(phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700403 final PersistableBundle config =
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100404 restoreConfigFromXml(carrierPackageName, "", phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700405 if (config != null) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800406 logd(
Jonathan Basseri65273c82017-07-25 15:08:42 -0700407 "Loaded config from XML. package="
408 + carrierPackageName
409 + " phoneId="
410 + phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700411 mConfigFromCarrierApp[phoneId] = config;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700412 Message newMsg = obtainMessage(EVENT_FETCH_CARRIER_DONE, phoneId, -1);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700413 newMsg.getData().putBoolean("loaded_from_xml", true);
414 sendMessage(newMsg);
415 } else {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700416 // No cached config, so fetch it from a carrier app.
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800417 if (carrierPackageName != null && bindToConfigPackage(carrierPackageName,
418 phoneId, EVENT_CONNECTED_TO_CARRIER)) {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700419 sendMessageDelayed(
Rambo Wang610fdf62021-03-08 21:37:11 -0800420 obtainMessage(EVENT_BIND_CARRIER_TIMEOUT, phoneId, -1 /*arg2*/,
421 getMessageToken(phoneId)),
Jonathan Basseri930701e2015-06-11 20:56:43 -0700422 BIND_TIMEOUT_MILLIS);
423 } else {
Nathan Harold1122e3d2021-01-22 15:45:24 -0800424 // Put a stub bundle in place so that the rest of the logic continues
425 // smoothly.
Rambo Wang42026112021-04-07 20:57:28 +0000426 mConfigFromCarrierApp[phoneId] = new PersistableBundle();
Jonathan Basseri65273c82017-07-25 15:08:42 -0700427 // Send broadcast if bind fails.
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700428 broadcastConfigChangedIntent(phoneId);
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800429 loge("Bind to carrier app: " + carrierPackageName + " fails");
Nathan Harold48ac0972019-03-13 22:33:01 -0700430 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700431 }
432 }
433 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700434 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700435
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800436 case EVENT_CONNECTED_TO_CARRIER: {
Rambo Wang610fdf62021-03-08 21:37:11 -0800437 removeMessages(EVENT_BIND_CARRIER_TIMEOUT, getMessageToken(phoneId));
Jonathan Basseri65273c82017-07-25 15:08:42 -0700438 final CarrierServiceConnection conn = (CarrierServiceConnection) msg.obj;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800439 // If new service connection has been created, unbind.
Jonathan Basseri65273c82017-07-25 15:08:42 -0700440 if (mServiceConnection[phoneId] != conn || conn.service == null) {
Rambo Wangc5901222021-09-17 13:18:35 -0700441 unbindIfBound(mContext, conn);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800442 break;
443 }
chen xu02581692018-11-11 19:03:44 -0800444 final CarrierIdentifier carrierId = getCarrierIdentifierForPhoneId(phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700445 // ResultReceiver callback will execute in this Handler's thread.
446 final ResultReceiver resultReceiver =
447 new ResultReceiver(this) {
448 @Override
449 public void onReceiveResult(int resultCode, Bundle resultData) {
Rambo Wangc5901222021-09-17 13:18:35 -0700450 unbindIfBound(mContext, conn);
Rambo Wanga9d27a52021-04-09 16:17:33 -0700451 removeMessages(EVENT_FETCH_CARRIER_TIMEOUT,
452 getMessageToken(phoneId));
Jonathan Basseri65273c82017-07-25 15:08:42 -0700453 // If new service connection has been created, this is stale.
454 if (mServiceConnection[phoneId] != conn) {
455 loge("Received response for stale request.");
456 return;
457 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700458 if (resultCode == RESULT_ERROR || resultData == null) {
459 // On error, abort config fetching.
chen xudb04c292019-03-26 17:01:15 -0700460 loge("Failed to get carrier config from carrier app: "
461 + getCarrierPackageForPhoneId(phoneId));
Jonathan Basseri65273c82017-07-25 15:08:42 -0700462 broadcastConfigChangedIntent(phoneId);
Nathan Harold48ac0972019-03-13 22:33:01 -0700463 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700464 return;
465 }
466 PersistableBundle config =
467 resultData.getParcelable(KEY_CONFIG_BUNDLE);
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100468 saveConfigToXml(getCarrierPackageForPhoneId(phoneId), "",
469 phoneId, carrierId, config);
Amit Mahajan304e92b2021-04-08 14:03:30 -0700470 if (config != null) {
471 mConfigFromCarrierApp[phoneId] = config;
472 } else {
473 logdWithLocalLog("Config from carrier app is null "
474 + "for phoneId " + phoneId);
475 // Put a stub bundle in place so that the rest of the logic
476 // continues smoothly.
477 mConfigFromCarrierApp[phoneId] = new PersistableBundle();
478 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700479 sendMessage(
480 obtainMessage(
481 EVENT_FETCH_CARRIER_DONE, phoneId, -1));
482 }
483 };
484 // Now fetch the config asynchronously from the ICarrierService.
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800485 try {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700486 ICarrierService carrierService =
487 ICarrierService.Stub.asInterface(conn.service);
488 carrierService.getCarrierConfig(carrierId, resultReceiver);
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800489 logdWithLocalLog("Fetch config for carrier app: "
chen xudb04c292019-03-26 17:01:15 -0700490 + getCarrierPackageForPhoneId(phoneId)
491 + " carrierid: " + carrierId.toString());
Jonathan Basseri65273c82017-07-25 15:08:42 -0700492 } catch (RemoteException e) {
493 loge("Failed to get carrier config: " + e.toString());
Rambo Wangc5901222021-09-17 13:18:35 -0700494 unbindIfBound(mContext, conn);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700495 break; // So we don't set a timeout.
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800496 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700497 sendMessageDelayed(
Rambo Wang610fdf62021-03-08 21:37:11 -0800498 obtainMessage(EVENT_FETCH_CARRIER_TIMEOUT, phoneId, -1 /*arg2*/,
499 getMessageToken(phoneId)),
Jonathan Basseri65273c82017-07-25 15:08:42 -0700500 BIND_TIMEOUT_MILLIS);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800501 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700502 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800503
Jonathan Basseri930701e2015-06-11 20:56:43 -0700504 case EVENT_BIND_CARRIER_TIMEOUT:
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800505 case EVENT_FETCH_CARRIER_TIMEOUT: {
Nathan Harold1122e3d2021-01-22 15:45:24 -0800506 loge("Bind/fetch from carrier app timeout, package="
507 + getCarrierPackageForPhoneId(phoneId));
Rambo Wang610fdf62021-03-08 21:37:11 -0800508 removeMessages(EVENT_FETCH_CARRIER_TIMEOUT, getMessageToken(phoneId));
chen xuf60b3162019-05-01 21:31:05 -0700509 // If we attempted to bind to the app, but the service connection is null due to
510 // the race condition that clear config event happens before bind/fetch complete
511 // then config was cleared while we were waiting and we should not continue.
512 if (mServiceConnection[phoneId] != null) {
513 // If a ResponseReceiver callback is in the queue when this happens, we will
514 // unbind twice and throw an exception.
Rambo Wangc5901222021-09-17 13:18:35 -0700515 unbindIfBound(mContext, mServiceConnection[phoneId]);
chen xuf60b3162019-05-01 21:31:05 -0700516 broadcastConfigChangedIntent(phoneId);
517 }
Nathan Harold1122e3d2021-01-22 15:45:24 -0800518 // Put a stub bundle in place so that the rest of the logic continues smoothly.
Rambo Wang42026112021-04-07 20:57:28 +0000519 mConfigFromCarrierApp[phoneId] = new PersistableBundle();
Nathan Harold48ac0972019-03-13 22:33:01 -0700520 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri930701e2015-06-11 20:56:43 -0700521 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700522 }
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800523 case EVENT_FETCH_CARRIER_DONE: {
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700524 // If we attempted to bind to the app, but the service connection is null, then
525 // config was cleared while we were waiting and we should not continue.
526 if (!msg.getData().getBoolean("loaded_from_xml", false)
527 && mServiceConnection[phoneId] == null) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800528 break;
529 }
Nathan Harold48ac0972019-03-13 22:33:01 -0700530 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800531 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700532 }
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700533
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800534 case EVENT_CHECK_SYSTEM_UPDATE: {
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700535 SharedPreferences sharedPrefs =
536 PreferenceManager.getDefaultSharedPreferences(mContext);
537 final String lastFingerprint = sharedPrefs.getString(KEY_FINGERPRINT, null);
538 if (!Build.FINGERPRINT.equals(lastFingerprint)) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800539 logd(
Jonathan Basseri65273c82017-07-25 15:08:42 -0700540 "Build fingerprint changed. old: "
541 + lastFingerprint
542 + " new: "
543 + Build.FINGERPRINT);
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700544 clearCachedConfigForPackage(null);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700545 sharedPrefs
546 .edit()
547 .putString(KEY_FINGERPRINT, Build.FINGERPRINT)
548 .apply();
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700549 }
550 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700551 }
Nathan Harold48ac0972019-03-13 22:33:01 -0700552
553 case EVENT_SUBSCRIPTION_INFO_UPDATED:
554 broadcastConfigChangedIntent(phoneId);
555 break;
Malcolm Chen5ea18532019-10-24 19:55:44 -0700556 case EVENT_MULTI_SIM_CONFIG_CHANGED:
557 onMultiSimConfigChanged();
558 break;
Jayachandran C645ec612020-01-10 10:30:25 -0800559
560 case EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG: {
561 PersistableBundle config =
562 restoreNoSimConfigFromXml(mPlatformCarrierConfigPackage);
563
564 if (config != null) {
565 logd("Loaded no SIM config from XML. package="
566 + mPlatformCarrierConfigPackage);
567 mNoSimConfig = config;
568 sendMessage(
569 obtainMessage(
570 EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE,
571 phoneId, -1));
572 } else {
573 // No cached config, so fetch it from the default app.
574 if (bindToConfigPackage(
575 mPlatformCarrierConfigPackage,
576 phoneId,
577 EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG)) {
578 sendMessageDelayed(
579 obtainMessage(
580 EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT,
581 phoneId, -1), BIND_TIMEOUT_MILLIS);
582 } else {
583 broadcastConfigChangedIntent(phoneId, false);
584 // TODO: We *must* call unbindService even if bindService returns false.
585 // (And possibly if SecurityException was thrown.)
586 loge("binding to default app to fetch no SIM config: "
587 + mPlatformCarrierConfigPackage + " fails");
588 }
589 }
590 break;
591 }
592
593 case EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE: {
594 broadcastConfigChangedIntent(phoneId, false);
595 break;
596 }
597
598 case EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT:
599 case EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT: {
600 loge("Bind/fetch time out for no SIM config from "
601 + mPlatformCarrierConfigPackage);
602 removeMessages(EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT);
603 // If we attempted to bind to the app, but the service connection is null due to
604 // the race condition that clear config event happens before bind/fetch complete
605 // then config was cleared while we were waiting and we should not continue.
606 if (mServiceConnectionForNoSimConfig[phoneId] != null) {
607 // If a ResponseReceiver callback is in the queue when this happens, we will
608 // unbind twice and throw an exception.
Rambo Wangc5901222021-09-17 13:18:35 -0700609 unbindIfBound(mContext, mServiceConnectionForNoSimConfig[phoneId]);
Jayachandran C645ec612020-01-10 10:30:25 -0800610 }
611 broadcastConfigChangedIntent(phoneId, false);
612 break;
613 }
614
615 case EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG: {
616 removeMessages(EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT);
617 final CarrierServiceConnection conn = (CarrierServiceConnection) msg.obj;
618 // If new service connection has been created, unbind.
619 if (mServiceConnectionForNoSimConfig[phoneId] != conn || conn.service == null) {
Rambo Wangc5901222021-09-17 13:18:35 -0700620 unbindIfBound(mContext, conn);
Jayachandran C645ec612020-01-10 10:30:25 -0800621 break;
622 }
623
624 // ResultReceiver callback will execute in this Handler's thread.
625 final ResultReceiver resultReceiver =
626 new ResultReceiver(this) {
627 @Override
628 public void onReceiveResult(int resultCode, Bundle resultData) {
Rambo Wangc5901222021-09-17 13:18:35 -0700629 unbindIfBound(mContext, conn);
Jayachandran C645ec612020-01-10 10:30:25 -0800630 // If new service connection has been created, this is stale.
631 if (mServiceConnectionForNoSimConfig[phoneId] != conn) {
632 loge("Received response for stale request.");
633 return;
634 }
635 removeMessages(EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT);
636 if (resultCode == RESULT_ERROR || resultData == null) {
637 // On error, abort config fetching.
638 loge("Failed to get no SIM carrier config");
639 return;
640 }
641 PersistableBundle config =
642 resultData.getParcelable(KEY_CONFIG_BUNDLE);
643 saveNoSimConfigToXml(mPlatformCarrierConfigPackage, config);
644 mNoSimConfig = config;
645 sendMessage(
646 obtainMessage(
647 EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE,
648 phoneId, -1));
649 }
650 };
651 // Now fetch the config asynchronously from the ICarrierService.
652 try {
653 ICarrierService carrierService =
654 ICarrierService.Stub.asInterface(conn.service);
655 carrierService.getCarrierConfig(null, resultReceiver);
656 logdWithLocalLog("Fetch no sim config from default app: "
657 + mPlatformCarrierConfigPackage);
658 } catch (RemoteException e) {
659 loge("Failed to get no sim carrier config from default app: " +
660 mPlatformCarrierConfigPackage + " err: " + e.toString());
Rambo Wangc5901222021-09-17 13:18:35 -0700661 unbindIfBound(mContext, conn);
Jayachandran C645ec612020-01-10 10:30:25 -0800662 break; // So we don't set a timeout.
663 }
664 sendMessageDelayed(
665 obtainMessage(
666 EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT,
667 phoneId, -1), BIND_TIMEOUT_MILLIS);
668 break;
669 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800670 }
671 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700672 }
673
674 private final Handler mHandler;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800675
676 /**
677 * Constructs a CarrierConfigLoader, registers it as a service, and registers a broadcast
678 * receiver for relevant events.
679 */
Rambo Wang7e3bc122021-03-23 09:24:38 -0700680 @VisibleForTesting
681 /* package */ CarrierConfigLoader(Context context,
682 SubscriptionInfoUpdater subscriptionInfoUpdater, @NonNull Looper looper) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800683 mContext = context;
Meng Wang33ad2bc2017-03-16 20:21:20 -0700684 mPlatformCarrierConfigPackage =
685 mContext.getString(R.string.platform_carrier_config_package);
Rambo Wang7e3bc122021-03-23 09:24:38 -0700686 mHandler = new ConfigHandler(looper);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800687
Nanxi Chen3d670502016-03-17 16:32:09 -0700688 IntentFilter bootFilter = new IntentFilter();
689 bootFilter.addAction(Intent.ACTION_BOOT_COMPLETED);
690 context.registerReceiver(mBootReceiver, bootFilter);
691
Junda Liu8a8a53a2015-05-15 16:19:57 -0700692 // Register for package updates. Update app or uninstall app update will have all 3 intents,
693 // in the order or removed, added, replaced, all with extra_replace set to true.
694 IntentFilter pkgFilter = new IntentFilter();
695 pkgFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
696 pkgFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
697 pkgFilter.addAction(Intent.ACTION_PACKAGE_REPLACED);
698 pkgFilter.addDataScheme("package");
Jordan Liu5ca24762019-07-10 12:51:09 -0700699 context.registerReceiver(mPackageReceiver, pkgFilter);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800700
Malcolm Chen978dda52019-10-08 18:15:25 -0700701 int numPhones = TelephonyManager.from(context).getSupportedModemCount();
Jonathan Basseric31f1f32015-05-12 10:13:03 -0700702 mConfigFromDefaultApp = new PersistableBundle[numPhones];
703 mConfigFromCarrierApp = new PersistableBundle[numPhones];
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100704 mPersistentOverrideConfigs = new PersistableBundle[numPhones];
Hall Liu506724b2018-10-22 18:16:14 -0700705 mOverrideConfigs = new PersistableBundle[numPhones];
Rambo Wang42026112021-04-07 20:57:28 +0000706 mNoSimConfig = new PersistableBundle();
Zach Johnson36d7aab2015-05-22 15:43:00 -0700707 mServiceConnection = new CarrierServiceConnection[numPhones];
Junda Liu03aad762017-07-21 13:32:17 -0700708 mHasSentConfigChange = new boolean[numPhones];
Sarah Chin807d5c62020-03-30 17:21:09 -0700709 mFromSystemUnlocked = new boolean[numPhones];
Jayachandran C645ec612020-01-10 10:30:25 -0800710 mServiceConnectionForNoSimConfig = new CarrierServiceConnection[numPhones];
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800711 logd("CarrierConfigLoader has started");
Rambo Wang7e3bc122021-03-23 09:24:38 -0700712 mSubscriptionInfoUpdater = subscriptionInfoUpdater;
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700713 mHandler.sendEmptyMessage(EVENT_CHECK_SYSTEM_UPDATE);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800714 }
715
716 /**
717 * Initialize the singleton CarrierConfigLoader instance.
718 *
719 * This is only done once, at startup, from {@link com.android.phone.PhoneApp#onCreate}.
720 */
Rambo Wang7e3bc122021-03-23 09:24:38 -0700721 /* package */ static CarrierConfigLoader init(Context context) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800722 synchronized (CarrierConfigLoader.class) {
723 if (sInstance == null) {
Rambo Wang7e3bc122021-03-23 09:24:38 -0700724 sInstance = new CarrierConfigLoader(context,
725 PhoneFactory.getSubscriptionInfoUpdater(), Looper.myLooper());
Brad Ebingerfa6575f2021-05-04 00:29:50 +0000726 // Make this service available through ServiceManager.
727 TelephonyFrameworkInitializer.getTelephonyServiceManager()
728 .getCarrierConfigServiceRegisterer().register(sInstance);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800729 } else {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700730 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800731 }
732 return sInstance;
733 }
734 }
735
Rambo Wang7e3bc122021-03-23 09:24:38 -0700736 @VisibleForTesting
737 /* package */ void clearConfigForPhone(int phoneId, boolean fetchNoSimConfig) {
Malcolm Chen5ea18532019-10-24 19:55:44 -0700738 /* Ignore clear configuration request if device is being shutdown. */
739 Phone phone = PhoneFactory.getPhone(phoneId);
740 if (phone != null) {
741 if (phone.isShuttingDown()) {
742 return;
743 }
744 }
745
746 mConfigFromDefaultApp[phoneId] = null;
747 mConfigFromCarrierApp[phoneId] = null;
748 mServiceConnection[phoneId] = null;
749 mHasSentConfigChange[phoneId] = false;
750
Jayachandran C645ec612020-01-10 10:30:25 -0800751 if (fetchNoSimConfig) {
752 // To fetch no SIM config
753 mHandler.sendMessage(
754 mHandler.obtainMessage(
755 EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG, phoneId, -1));
756 }
Malcolm Chen5ea18532019-10-24 19:55:44 -0700757 }
758
Nathan Harold48ac0972019-03-13 22:33:01 -0700759 private void notifySubscriptionInfoUpdater(int phoneId) {
760 String configPackagename;
761 PersistableBundle configToSend;
762 int carrierId = getSpecificCarrierIdForPhoneId(phoneId);
763 // Prefer the carrier privileged carrier app, but if there is not one, use the platform
764 // default carrier app.
765 if (mConfigFromCarrierApp[phoneId] != null) {
766 configPackagename = getCarrierPackageForPhoneId(phoneId);
767 configToSend = mConfigFromCarrierApp[phoneId];
768 } else {
769 configPackagename = mPlatformCarrierConfigPackage;
770 configToSend = mConfigFromDefaultApp[phoneId];
771 }
Nazanin Bakhshi6fcc3342019-09-18 17:54:01 -0700772
Malcolm Chenefafd1c2020-02-20 13:27:08 -0800773 if (configToSend == null) {
Rambo Wang42026112021-04-07 20:57:28 +0000774 configToSend = new PersistableBundle();
Malcolm Chenefafd1c2020-02-20 13:27:08 -0800775 }
776
Nazanin Bakhshi6fcc3342019-09-18 17:54:01 -0700777 // mOverrideConfigs is for testing. And it will override current configs.
778 PersistableBundle config = mOverrideConfigs[phoneId];
779 if (config != null) {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +0100780 configToSend = new PersistableBundle(configToSend);
Nazanin Bakhshi6fcc3342019-09-18 17:54:01 -0700781 configToSend.putAll(config);
782 }
783
Nathan Harold48ac0972019-03-13 22:33:01 -0700784 mSubscriptionInfoUpdater.updateSubscriptionByCarrierConfigAndNotifyComplete(
785 phoneId, configPackagename, configToSend,
786 mHandler.obtainMessage(EVENT_SUBSCRIPTION_INFO_UPDATED, phoneId, -1));
787 }
788
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800789 private void broadcastConfigChangedIntent(int phoneId) {
Amit Mahajanf8088ab2018-03-02 15:24:07 -0800790 broadcastConfigChangedIntent(phoneId, true);
791 }
792
793 private void broadcastConfigChangedIntent(int phoneId, boolean addSubIdExtra) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800794 Intent intent = new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Christopher Tate38f55eb2017-02-14 14:43:49 -0800795 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT |
chen xuf9db49f2019-03-31 23:04:42 -0700796 Intent.FLAG_RECEIVER_FOREGROUND);
Qiongcheng Luoe7de61b2018-08-06 10:20:09 +0800797 if (addSubIdExtra) {
798 int simApplicationState = TelephonyManager.SIM_STATE_UNKNOWN;
799 int[] subIds = SubscriptionManager.getSubId(phoneId);
800 if (!ArrayUtils.isEmpty(subIds)) {
801 TelephonyManager telMgr = TelephonyManager.from(mContext)
802 .createForSubscriptionId(subIds[0]);
803 simApplicationState = telMgr.getSimApplicationState();
804 }
Malcolm Chenf7635ec2020-04-15 15:45:00 -0700805 logd("Broadcast CARRIER_CONFIG_CHANGED for phone " + phoneId
806 + " simApplicationState " + simApplicationState);
Qiongcheng Luoe7de61b2018-08-06 10:20:09 +0800807 // Include subId/carrier id extra only if SIM records are loaded
808 if (simApplicationState != TelephonyManager.SIM_STATE_UNKNOWN
809 && simApplicationState != TelephonyManager.SIM_STATE_NOT_READY) {
810 SubscriptionManager.putPhoneIdAndSubIdExtra(intent, phoneId);
811 intent.putExtra(TelephonyManager.EXTRA_SPECIFIC_CARRIER_ID,
812 getSpecificCarrierIdForPhoneId(phoneId));
813 intent.putExtra(TelephonyManager.EXTRA_CARRIER_ID, getCarrierIdForPhoneId(phoneId));
814 }
Amit Mahajanf8088ab2018-03-02 15:24:07 -0800815 }
Amit Mahajanb33bcda2018-01-24 12:56:44 -0800816 intent.putExtra(CarrierConfigManager.EXTRA_SLOT_INDEX, phoneId);
Sarah Chin807d5c62020-03-30 17:21:09 -0700817 intent.putExtra(CarrierConfigManager.EXTRA_REBROADCAST_ON_UNLOCK,
818 mFromSystemUnlocked[phoneId]);
Meng Wang97a6a462020-01-23 16:22:16 -0800819 mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
Jack Yue9e95be2020-03-22 10:56:06 -0700820 int[] subIds = SubscriptionManager.getSubId(phoneId);
821 if (subIds != null && subIds.length > 0) {
822 logd("Broadcast CARRIER_CONFIG_CHANGED for phone " + phoneId + ", subId=" + subIds[0]);
823 } else {
824 logd("Broadcast CARRIER_CONFIG_CHANGED for phone " + phoneId);
825 }
Junda Liu03aad762017-07-21 13:32:17 -0700826 mHasSentConfigChange[phoneId] = true;
Sarah Chin807d5c62020-03-30 17:21:09 -0700827 mFromSystemUnlocked[phoneId] = false;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800828 }
829
830 /** Binds to the default or carrier config app. */
831 private boolean bindToConfigPackage(String pkgName, int phoneId, int eventId) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800832 logdWithLocalLog("Binding to " + pkgName + " for phone " + phoneId);
Zach Johnsonfca8a8d2015-06-19 18:21:37 -0700833 Intent carrierService = new Intent(CarrierService.CARRIER_SERVICE_INTERFACE);
Zach Johnson36d7aab2015-05-22 15:43:00 -0700834 carrierService.setPackage(pkgName);
Jayachandran C645ec612020-01-10 10:30:25 -0800835 CarrierServiceConnection serviceConnection = new CarrierServiceConnection(
836 phoneId, pkgName, eventId);
837 if (eventId == EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG) {
838 mServiceConnectionForNoSimConfig[phoneId] = serviceConnection;
839 } else {
840 mServiceConnection[phoneId] = serviceConnection;
841 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800842 try {
Jayachandran C645ec612020-01-10 10:30:25 -0800843 if (mContext.bindService(carrierService, serviceConnection,
Jordan Liu178430d2020-02-10 14:32:15 -0800844 Context.BIND_AUTO_CREATE)) {
Rambo Wangc5901222021-09-17 13:18:35 -0700845 serviceConnection.isBound = true;
Jordan Liu178430d2020-02-10 14:32:15 -0800846 return true;
847 } else {
848 return false;
849 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800850 } catch (SecurityException ex) {
851 return false;
852 }
853 }
854
Rambo Wang7e3bc122021-03-23 09:24:38 -0700855 @VisibleForTesting
856 /* package */ CarrierIdentifier getCarrierIdentifierForPhoneId(int phoneId) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800857 String mcc = "";
858 String mnc = "";
859 String imsi = "";
860 String gid1 = "";
861 String gid2 = "";
862 String spn = TelephonyManager.from(mContext).getSimOperatorNameForPhone(phoneId);
863 String simOperator = TelephonyManager.from(mContext).getSimOperatorNumericForPhone(phoneId);
chen xu02581692018-11-11 19:03:44 -0800864 int carrierId = TelephonyManager.UNKNOWN_CARRIER_ID;
chen xua31f22b2019-03-06 15:28:50 -0800865 int specificCarrierId = TelephonyManager.UNKNOWN_CARRIER_ID;
Jonathan Basseri1fa437c2015-04-20 11:08:18 -0700866 // A valid simOperator should be 5 or 6 digits, depending on the length of the MNC.
867 if (simOperator != null && simOperator.length() >= 3) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800868 mcc = simOperator.substring(0, 3);
869 mnc = simOperator.substring(3);
870 }
871 Phone phone = PhoneFactory.getPhone(phoneId);
872 if (phone != null) {
873 imsi = phone.getSubscriberId();
874 gid1 = phone.getGroupIdLevel1();
Junda Liu73183532015-05-14 13:55:40 -0700875 gid2 = phone.getGroupIdLevel2();
chen xu02581692018-11-11 19:03:44 -0800876 carrierId = phone.getCarrierId();
chen xua31f22b2019-03-06 15:28:50 -0800877 specificCarrierId = phone.getSpecificCarrierId();
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800878 }
chen xua31f22b2019-03-06 15:28:50 -0800879 return new CarrierIdentifier(mcc, mnc, spn, imsi, gid1, gid2, carrierId, specificCarrierId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800880 }
881
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700882 /** Returns the package name of a priveleged carrier app, or null if there is none. */
Nathan Harold1122e3d2021-01-22 15:45:24 -0800883 @Nullable
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700884 private String getCarrierPackageForPhoneId(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -0700885 List<String> carrierPackageNames;
886 final long token = Binder.clearCallingIdentity();
887 try {
888 carrierPackageNames = TelephonyManager.from(mContext)
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700889 .getCarrierPackageNamesForIntentAndPhone(
Nazanin1adf4562021-03-29 15:35:30 -0700890 new Intent(CarrierService.CARRIER_SERVICE_INTERFACE), phoneId);
891 } finally {
892 Binder.restoreCallingIdentity(token);
893 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700894 if (carrierPackageNames != null && carrierPackageNames.size() > 0) {
895 return carrierPackageNames.get(0);
896 } else {
897 return null;
898 }
899 }
900
901 private String getIccIdForPhoneId(int phoneId) {
902 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
903 return null;
904 }
905 Phone phone = PhoneFactory.getPhone(phoneId);
906 if (phone == null) {
907 return null;
908 }
909 return phone.getIccSerialNumber();
910 }
911
chen xu02581692018-11-11 19:03:44 -0800912 /**
chen xua31f22b2019-03-06 15:28:50 -0800913 * Get the sim specific carrier id {@link TelephonyManager#getSimSpecificCarrierId()}
chen xu02581692018-11-11 19:03:44 -0800914 */
chen xua31f22b2019-03-06 15:28:50 -0800915 private int getSpecificCarrierIdForPhoneId(int phoneId) {
Naina Nalluri86fc7b02018-08-03 10:38:30 -0700916 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
chen xu02581692018-11-11 19:03:44 -0800917 return TelephonyManager.UNKNOWN_CARRIER_ID;
Naina Nalluri86fc7b02018-08-03 10:38:30 -0700918 }
919 Phone phone = PhoneFactory.getPhone(phoneId);
920 if (phone == null) {
chen xu02581692018-11-11 19:03:44 -0800921 return TelephonyManager.UNKNOWN_CARRIER_ID;
Naina Nalluri86fc7b02018-08-03 10:38:30 -0700922 }
chen xua31f22b2019-03-06 15:28:50 -0800923 return phone.getSpecificCarrierId();
chen xu02581692018-11-11 19:03:44 -0800924 }
925
926 /**
927 * Get the sim carrier id {@link TelephonyManager#getSimCarrierId() }
928 */
929 private int getCarrierIdForPhoneId(int phoneId) {
930 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
931 return TelephonyManager.UNKNOWN_CARRIER_ID;
Naina Nalluri86fc7b02018-08-03 10:38:30 -0700932 }
chen xu02581692018-11-11 19:03:44 -0800933 Phone phone = PhoneFactory.getPhone(phoneId);
934 if (phone == null) {
935 return TelephonyManager.UNKNOWN_CARRIER_ID;
936 }
937 return phone.getCarrierId();
Naina Nalluri86fc7b02018-08-03 10:38:30 -0700938 }
939
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700940 /**
941 * Writes a bundle to an XML file.
942 *
chen xu02581692018-11-11 19:03:44 -0800943 * The bundle will be written to a file named after the package name, ICCID and
chen xua31f22b2019-03-06 15:28:50 -0800944 * specific carrier id {@link TelephonyManager#getSimSpecificCarrierId()}. the same carrier
chen xu02581692018-11-11 19:03:44 -0800945 * should have a single copy of XML file named after carrier id. However, it's still possible
946 * that platform doesn't recognize the current sim carrier, we will use iccid + carrierid as
947 * the canonical file name. carrierid can also handle the cases SIM OTA resolves to different
948 * carrier while iccid remains the same.
949 *
950 * The file can be restored later with {@link @restoreConfigFromXml}. The XML output will
951 * include the bundle and the current version of the specified package.
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700952 *
953 * In case of errors or invalid input, no file will be written.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700954 *
Jayachandran C645ec612020-01-10 10:30:25 -0800955 * @param packageName the name of the package from which we fetched this bundle.
956 * @param extraString An extra string to be used in the XML file name.
957 * @param phoneId the phone ID.
958 * @param carrierId contains all carrier-identifying information.
959 * @param config the bundle to be written. Null will be treated as an empty bundle.
960 * @param isNoSimConfig whether this is invoked for noSimConfig or not.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700961 */
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100962 private void saveConfigToXml(String packageName, @NonNull String extraString, int phoneId,
Jayachandran C645ec612020-01-10 10:30:25 -0800963 CarrierIdentifier carrierId, PersistableBundle config, boolean isNoSimConfig) {
964 if (packageName == null) {
965 loge("Cannot save config with null packageName");
Yuchen Dongc15afed2018-04-26 17:05:22 +0800966 return;
967 }
968
Jayachandran C645ec612020-01-10 10:30:25 -0800969 String fileName;
970 if (isNoSimConfig) {
971 fileName = getFilenameForNoSimConfig(packageName);
972 } else {
973 if (SubscriptionManager.getSimStateForSlotIndex(phoneId)
974 != TelephonyManager.SIM_STATE_LOADED) {
975 loge("Skip save config because SIM records are not loaded.");
976 return;
977 }
978
979 final String iccid = getIccIdForPhoneId(phoneId);
980 final int cid = carrierId.getSpecificCarrierId();
981 if (iccid == null) {
982 loge("Cannot save config with null iccid.");
983 return;
984 }
985 fileName = getFilenameForConfig(packageName, extraString, iccid, cid);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700986 }
Jayachandran C645ec612020-01-10 10:30:25 -0800987
Junda Liu02596502016-11-15 13:46:43 -0800988 // b/32668103 Only save to file if config isn't empty.
989 // In case of failure, not caching an empty bundle will
990 // try loading config again on next power on or sim loaded.
991 // Downside is for genuinely empty bundle, will bind and load
992 // on every power on.
993 if (config == null || config.isEmpty()) {
994 return;
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700995 }
996
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700997 final String version = getPackageVersion(packageName);
998 if (version == null) {
999 loge("Failed to get package version for: " + packageName);
1000 return;
1001 }
1002
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001003 logdWithLocalLog(
1004 "Save config to xml, packagename: " + packageName + " phoneId: " + phoneId);
chen xudb04c292019-03-26 17:01:15 -07001005
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001006 FileOutputStream outFile = null;
1007 try {
Jayachandran C645ec612020-01-10 10:30:25 -08001008 outFile = new FileOutputStream(new File(mContext.getFilesDir(), fileName));
Meng Wang0f6b2ea2020-01-06 18:31:16 -08001009 config.putString(KEY_VERSION, version);
1010 config.writeToStream(outFile);
1011 outFile.flush();
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001012 outFile.close();
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001013 } catch (IOException e) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001014 loge(e.toString());
1015 }
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001016 }
1017
Rambo Wang7e3bc122021-03-23 09:24:38 -07001018 @VisibleForTesting
1019 /* package */ void saveConfigToXml(String packageName, @NonNull String extraString, int phoneId,
Jayachandran C645ec612020-01-10 10:30:25 -08001020 CarrierIdentifier carrierId, PersistableBundle config) {
1021 saveConfigToXml(packageName, extraString, phoneId, carrierId, config, false);
1022 }
1023
Rambo Wang7e3bc122021-03-23 09:24:38 -07001024 @VisibleForTesting
1025 /* package */ void saveNoSimConfigToXml(String packageName, PersistableBundle config) {
Jayachandran C645ec612020-01-10 10:30:25 -08001026 saveConfigToXml(packageName, "", -1, null, config, true);
1027 }
1028
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001029 /**
1030 * Reads a bundle from an XML file.
1031 *
1032 * This restores a bundle that was written with {@link #saveConfigToXml}. This returns the saved
Yuchen Dongc15afed2018-04-26 17:05:22 +08001033 * config bundle for the given package and phone ID.
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001034 *
1035 * In case of errors, or if the saved config is from a different package version than the
1036 * current version, then null will be returned.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001037 *
Jayachandran C645ec612020-01-10 10:30:25 -08001038 * @param packageName the name of the package from which we fetched this bundle.
1039 * @param extraString An extra string to be used in the XML file name.
1040 * @param phoneId the phone ID.
1041 * @param isNoSimConfig whether this is invoked for noSimConfig or not.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001042 * @return the bundle from the XML file. Returns null if there is no saved config, the saved
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001043 * version does not match, or reading config fails.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001044 */
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001045 private PersistableBundle restoreConfigFromXml(String packageName, @NonNull String extraString,
Jayachandran C645ec612020-01-10 10:30:25 -08001046 int phoneId, boolean isNoSimConfig) {
1047 if (packageName == null) {
1048 loge("Cannot restore config with null packageName");
1049 }
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001050 final String version = getPackageVersion(packageName);
1051 if (version == null) {
1052 loge("Failed to get package version for: " + packageName);
1053 return null;
1054 }
Yuchen Dongc15afed2018-04-26 17:05:22 +08001055
Jayachandran C645ec612020-01-10 10:30:25 -08001056 String fileName;
arunvoddu664c36a2021-10-11 20:09:28 +00001057 String iccid = null;
Jayachandran C645ec612020-01-10 10:30:25 -08001058 if (isNoSimConfig) {
1059 fileName = getFilenameForNoSimConfig(packageName);
1060 } else {
1061 if (SubscriptionManager.getSimStateForSlotIndex(phoneId)
1062 != TelephonyManager.SIM_STATE_LOADED) {
1063 loge("Skip restore config because SIM records are not loaded.");
1064 return null;
1065 }
1066
arunvoddu664c36a2021-10-11 20:09:28 +00001067 iccid = getIccIdForPhoneId(phoneId);
Jayachandran C645ec612020-01-10 10:30:25 -08001068 final int cid = getSpecificCarrierIdForPhoneId(phoneId);
1069 if (iccid == null) {
1070 loge("Cannot restore config with null iccid.");
1071 return null;
1072 }
1073 fileName = getFilenameForConfig(packageName, extraString, iccid, cid);
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001074 }
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001075
1076 PersistableBundle restoredBundle = null;
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001077 File file = null;
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001078 FileInputStream inFile = null;
1079 try {
Jayachandran C645ec612020-01-10 10:30:25 -08001080 file = new File(mContext.getFilesDir(),fileName);
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001081 inFile = new FileInputStream(file);
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001082
Meng Wang0f6b2ea2020-01-06 18:31:16 -08001083 restoredBundle = PersistableBundle.readFromStream(inFile);
1084 String savedVersion = restoredBundle.getString(KEY_VERSION);
1085 restoredBundle.remove(KEY_VERSION);
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001086
Meng Wang0f6b2ea2020-01-06 18:31:16 -08001087 if (!version.equals(savedVersion)) {
1088 loge("Saved version mismatch: " + version + " vs " + savedVersion);
1089 restoredBundle = null;
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001090 }
Meng Wang0f6b2ea2020-01-06 18:31:16 -08001091
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001092 inFile.close();
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001093 } catch (FileNotFoundException e) {
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001094 // Missing file is normal occurrence that might occur with a new sim or when restoring
1095 // an override file during boot and should not be treated as an error.
arunvoddu664c36a2021-10-11 20:09:28 +00001096 if (file != null) {
1097 if (isNoSimConfig) {
1098 logd("File not found: " + file.getPath());
1099 } else {
1100 String filePath = file.getPath();
1101 filePath = getFilePathForLogging(filePath, iccid);
1102 logd("File not found : " + filePath);
1103 }
1104 }
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001105 } catch (IOException e) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001106 loge(e.toString());
1107 }
1108
1109 return restoredBundle;
1110 }
1111
arunvoddu664c36a2021-10-11 20:09:28 +00001112 /**
1113 * This method will mask most part of iccid in the filepath for logging on userbuild
1114 */
1115 private String getFilePathForLogging(String filePath, String iccid) {
1116 // If loggable then return with actual file path
1117 if (Rlog.isLoggable(LOG_TAG, Log.VERBOSE)) {
1118 return filePath;
1119 }
1120 String path = filePath;
1121 int length = (iccid != null) ? iccid.length() : 0;
1122 if (length > 5 && filePath != null) {
1123 path = filePath.replace(iccid.substring(5), "***************");
1124 }
1125 return path;
1126 }
1127
Jayachandran C645ec612020-01-10 10:30:25 -08001128 private PersistableBundle restoreConfigFromXml(String packageName, @NonNull String extraString,
1129 int phoneId) {
1130 return restoreConfigFromXml(packageName, extraString, phoneId, false);
1131 }
1132
1133 private PersistableBundle restoreNoSimConfigFromXml(String packageName) {
1134 return restoreConfigFromXml(packageName, "", -1, true);
1135 }
1136
Junda Liu8a8a53a2015-05-15 16:19:57 -07001137 /**
Jonathan Basseri7697cae2015-07-06 15:49:23 -07001138 * Clears cached carrier config.
1139 * This deletes all saved XML files associated with the given package name. If packageName is
1140 * null, then it deletes all saved XML files.
1141 *
1142 * @param packageName the name of a carrier package, or null if all cached config should be
1143 * cleared.
1144 * @return true iff one or more files were deleted.
Junda Liu8a8a53a2015-05-15 16:19:57 -07001145 */
Jonathan Basseri7697cae2015-07-06 15:49:23 -07001146 private boolean clearCachedConfigForPackage(final String packageName) {
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001147 File dir = mContext.getFilesDir();
1148 File[] packageFiles = dir.listFiles(new FilenameFilter() {
1149 public boolean accept(File dir, String filename) {
Jonathan Basseri7697cae2015-07-06 15:49:23 -07001150 if (packageName != null) {
1151 return filename.startsWith("carrierconfig-" + packageName + "-");
1152 } else {
1153 return filename.startsWith("carrierconfig-");
1154 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001155 }
1156 });
Junda Liu8a8a53a2015-05-15 16:19:57 -07001157 if (packageFiles == null || packageFiles.length < 1) return false;
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001158 for (File f : packageFiles) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001159 logd("Deleting " + f.getName());
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001160 f.delete();
1161 }
Junda Liu8a8a53a2015-05-15 16:19:57 -07001162 return true;
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001163 }
1164
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001165 /** Builds a canonical file name for a config file. */
Jayachandran C645ec612020-01-10 10:30:25 -08001166 private static String getFilenameForConfig(
1167 @NonNull String packageName, @NonNull String extraString,
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001168 @NonNull String iccid, int cid) {
chen xu02581692018-11-11 19:03:44 -08001169 // the same carrier should have a single copy of XML file named after carrier id.
1170 // However, it's still possible that platform doesn't recognize the current sim carrier,
1171 // we will use iccid + carrierid as the canonical file name. carrierid can also handle the
1172 // cases SIM OTA resolves to different carrier while iccid remains the same.
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001173 return "carrierconfig-" + packageName + extraString + "-" + iccid + "-" + cid + ".xml";
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001174 }
1175
Jayachandran C645ec612020-01-10 10:30:25 -08001176 /** Builds a canonical file name for no SIM config file. */
1177 private String getFilenameForNoSimConfig(@NonNull String packageName) {
1178 return "carrierconfig-" + packageName + "-" + "nosim" + ".xml";
1179 }
1180
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001181 /** Return the current version code of a package, or null if the name is not found. */
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001182 private String getPackageVersion(String packageName) {
1183 try {
1184 PackageInfo info = mContext.getPackageManager().getPackageInfo(packageName, 0);
Dianne Hackbornb76ab202017-11-28 17:44:50 -08001185 return Long.toString(info.getLongVersionCode());
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001186 } catch (PackageManager.NameNotFoundException e) {
1187 return null;
1188 }
1189 }
1190
Jonathan Basseri65273c82017-07-25 15:08:42 -07001191 /**
1192 * Read up to date config.
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001193 *
1194 * This reads config bundles for the given phoneId. That means getting the latest bundle from
1195 * the default app and a privileged carrier app, if present. This will not bind to an app if we
1196 * have a saved config file to use instead.
1197 */
1198 private void updateConfigForPhoneId(int phoneId) {
Jonathan Basseri65273c82017-07-25 15:08:42 -07001199 mHandler.sendMessage(mHandler.obtainMessage(EVENT_DO_FETCH_DEFAULT, phoneId, -1));
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001200 }
1201
Malcolm Chen5ea18532019-10-24 19:55:44 -07001202 private void onMultiSimConfigChanged() {
1203 for (int i = TelephonyManager.from(mContext).getActiveModemCount();
1204 i < mConfigFromDefaultApp.length; i++) {
1205 clearConfigForPhone(i, false);
1206 }
1207 }
1208
Hall Liu506724b2018-10-22 18:16:14 -07001209 @Override
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001210 @NonNull
Rambo Wangd2b004b2021-03-30 10:10:23 -07001211 public PersistableBundle getConfigForSubId(int subscriptionId, String callingPackage) {
1212 return getConfigForSubIdWithFeature(subscriptionId, callingPackage, null);
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001213 }
1214
1215 @Override
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001216 @NonNull
Rambo Wangd2b004b2021-03-30 10:10:23 -07001217 public PersistableBundle getConfigForSubIdWithFeature(int subscriptionId, String callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001218 String callingFeatureId) {
Rambo Wangd2b004b2021-03-30 10:10:23 -07001219 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mContext, subscriptionId,
1220 callingPackage, callingFeatureId, "getCarrierConfig")) {
Rambo Wang42026112021-04-07 20:57:28 +00001221 return new PersistableBundle();
Amit Mahajan40b3fa52015-07-14 10:27:19 -07001222 }
Jeff Davidsona8e4e242018-03-15 17:16:18 -07001223
Rambo Wangd2b004b2021-03-30 10:10:23 -07001224 int phoneId = SubscriptionManager.getPhoneId(subscriptionId);
Jonathan Basseric31f1f32015-05-12 10:13:03 -07001225 PersistableBundle retConfig = CarrierConfigManager.getDefaultConfig();
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001226 if (SubscriptionManager.isValidPhoneId(phoneId)) {
Jonathan Basseric31f1f32015-05-12 10:13:03 -07001227 PersistableBundle config = mConfigFromDefaultApp[phoneId];
yinxuc5e27622017-11-29 15:08:50 -08001228 if (config != null) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001229 retConfig.putAll(config);
yinxuc5e27622017-11-29 15:08:50 -08001230 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001231 config = mConfigFromCarrierApp[phoneId];
yinxuc5e27622017-11-29 15:08:50 -08001232 if (config != null) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001233 retConfig.putAll(config);
yinxuc5e27622017-11-29 15:08:50 -08001234 }
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001235 config = mPersistentOverrideConfigs[phoneId];
1236 if (config != null) {
1237 retConfig.putAll(config);
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001238 }
Hall Liu506724b2018-10-22 18:16:14 -07001239 config = mOverrideConfigs[phoneId];
1240 if (config != null) {
1241 retConfig.putAll(config);
Hall Liu506724b2018-10-22 18:16:14 -07001242 }
Nathan Harold1122e3d2021-01-22 15:45:24 -08001243 // Ignore the theoretical case of the default app not being present since that won't
1244 // work in CarrierConfigLoader today.
1245 final boolean allConfigsApplied =
1246 (mConfigFromCarrierApp[phoneId] != null
1247 || getCarrierPackageForPhoneId(phoneId) == null)
1248 && mConfigFromDefaultApp[phoneId] != null;
1249 retConfig.putBoolean(
1250 CarrierConfigManager.KEY_CARRIER_CONFIG_APPLIED_BOOL, allConfigsApplied);
Jayachandran C645ec612020-01-10 10:30:25 -08001251 } else {
1252 if (mNoSimConfig != null) {
1253 retConfig.putAll(mNoSimConfig);
1254 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001255 }
1256 return retConfig;
1257 }
1258
1259 @Override
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001260 public void overrideConfig(int subscriptionId, @Nullable PersistableBundle overrides,
1261 boolean persistent) {
Hall Liu506724b2018-10-22 18:16:14 -07001262 mContext.enforceCallingOrSelfPermission(
1263 android.Manifest.permission.MODIFY_PHONE_STATE, null);
Brad Ebingerf6281ad2019-04-25 11:02:04 -07001264 //TODO: Also check for SHELL UID to restrict this method to testing only (b/131326259)
Hall Liu506724b2018-10-22 18:16:14 -07001265 int phoneId = SubscriptionManager.getPhoneId(subscriptionId);
1266 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001267 logd("Ignore invalid phoneId: " + phoneId + " for subId: " + subscriptionId);
Rambo Wangd2b004b2021-03-30 10:10:23 -07001268 throw new IllegalArgumentException(
1269 "Invalid phoneId " + phoneId + " for subId " + subscriptionId);
Hall Liu506724b2018-10-22 18:16:14 -07001270 }
Rambo Wang38eb5cd2021-03-29 16:39:14 -07001271 // Post to run on handler thread on which all states should be confined.
1272 mHandler.post(() -> {
1273 overrideConfig(mOverrideConfigs, phoneId, overrides);
Hall Liu506724b2018-10-22 18:16:14 -07001274
Rambo Wang38eb5cd2021-03-29 16:39:14 -07001275 if (persistent) {
1276 overrideConfig(mPersistentOverrideConfigs, phoneId, overrides);
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001277
Rambo Wang38eb5cd2021-03-29 16:39:14 -07001278 if (overrides != null) {
1279 final CarrierIdentifier carrierId = getCarrierIdentifierForPhoneId(phoneId);
1280 saveConfigToXml(mPlatformCarrierConfigPackage, OVERRIDE_PACKAGE_ADDITION,
1281 phoneId,
1282 carrierId, mPersistentOverrideConfigs[phoneId]);
1283 } else {
1284 final String iccid = getIccIdForPhoneId(phoneId);
1285 final int cid = getSpecificCarrierIdForPhoneId(phoneId);
1286 String fileName = getFilenameForConfig(mPlatformCarrierConfigPackage,
1287 OVERRIDE_PACKAGE_ADDITION, iccid, cid);
1288 File fileToDelete = new File(mContext.getFilesDir(), fileName);
1289 fileToDelete.delete();
1290 }
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001291 }
Rambo Wang38eb5cd2021-03-29 16:39:14 -07001292 notifySubscriptionInfoUpdater(phoneId);
1293 });
Hall Liu506724b2018-10-22 18:16:14 -07001294 }
1295
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001296 private void overrideConfig(@NonNull PersistableBundle[] currentOverrides, int phoneId,
1297 @Nullable PersistableBundle overrides) {
1298 if (overrides == null) {
Rambo Wang42026112021-04-07 20:57:28 +00001299 currentOverrides[phoneId] = new PersistableBundle();
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001300 } else if (currentOverrides[phoneId] == null) {
1301 currentOverrides[phoneId] = overrides;
1302 } else {
1303 currentOverrides[phoneId].putAll(overrides);
1304 }
1305 }
1306
Hall Liu506724b2018-10-22 18:16:14 -07001307 @Override
Rambo Wangd2b004b2021-03-30 10:10:23 -07001308 public void notifyConfigChangedForSubId(int subscriptionId) {
Jordan Liud7d57fe2019-04-16 12:29:43 -07001309 // Requires the calling app to be either a carrier privileged app for this subId or
Junda Liufbd2bcb2016-06-15 11:15:42 -07001310 // system privileged app with MODIFY_PHONE_STATE permission.
Rambo Wangd2b004b2021-03-30 10:10:23 -07001311 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mContext,
1312 subscriptionId, "Require carrier privileges or MODIFY_PHONE_STATE permission.");
1313
1314 int phoneId = SubscriptionManager.getPhoneId(subscriptionId);
1315 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
1316 logd("Ignore invalid phoneId: " + phoneId + " for subId: " + subscriptionId);
1317 throw new IllegalArgumentException(
1318 "Invalid phoneId " + phoneId + " for subId " + subscriptionId);
1319 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001320
1321 // This method should block until deleting has completed, so that an error which prevents us
1322 // from clearing the cache is passed back to the carrier app. With the files successfully
1323 // deleted, this can return and we will eventually bind to the carrier app.
Jordan Liud7d57fe2019-04-16 12:29:43 -07001324 String callingPackageName = mContext.getPackageManager().getNameForUid(
1325 Binder.getCallingUid());
Jonathan Basseri7697cae2015-07-06 15:49:23 -07001326 clearCachedConfigForPackage(callingPackageName);
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001327 updateConfigForPhoneId(phoneId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001328 }
1329
1330 @Override
1331 public void updateConfigForPhoneId(int phoneId, String simState) {
Junda Liu1f2b34d2015-06-18 15:26:56 -07001332 mContext.enforceCallingOrSelfPermission(
1333 android.Manifest.permission.MODIFY_PHONE_STATE, null);
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001334 logdWithLocalLog("Update config for phoneId: " + phoneId + " simState: " + simState);
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001335 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
Rambo Wangd2b004b2021-03-30 10:10:23 -07001336 throw new IllegalArgumentException("Invalid phoneId: " + phoneId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001337 }
1338 // requires Java 7 for switch on string.
1339 switch (simState) {
1340 case IccCardConstants.INTENT_VALUE_ICC_ABSENT:
1341 case IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR:
Junda Liu6f5fddf2016-05-24 16:14:41 -07001342 case IccCardConstants.INTENT_VALUE_ICC_CARD_RESTRICTED:
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001343 case IccCardConstants.INTENT_VALUE_ICC_UNKNOWN:
Malcolm Chendb66de12019-12-09 18:57:07 -08001344 case IccCardConstants.INTENT_VALUE_ICC_NOT_READY:
Junda Liu9f2d2712015-05-15 14:22:45 -07001345 mHandler.sendMessage(mHandler.obtainMessage(EVENT_CLEAR_CONFIG, phoneId, -1));
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001346 break;
1347 case IccCardConstants.INTENT_VALUE_ICC_LOADED:
1348 case IccCardConstants.INTENT_VALUE_ICC_LOCKED:
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001349 updateConfigForPhoneId(phoneId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001350 break;
1351 }
1352 }
1353
Junda Liu43d723a2015-05-12 17:23:45 -07001354 @Override
Jeff Sharkeya6fcfed2017-07-20 14:18:39 -06001355 public String getDefaultCarrierServicePackageName() {
Shuo Qianefdb7962019-12-19 15:54:27 -08001356 mContext.enforceCallingOrSelfPermission(
1357 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
1358 "getDefaultCarrierServicePackageName");
Jeff Sharkeya6fcfed2017-07-20 14:18:39 -06001359 return mPlatformCarrierConfigPackage;
1360 }
1361
Rambo Wang7e3bc122021-03-23 09:24:38 -07001362 @VisibleForTesting
1363 /* package */ Handler getHandler() {
1364 return mHandler;
1365 }
1366
1367 @VisibleForTesting
1368 /* package */ PersistableBundle getConfigFromDefaultApp(int phoneId) {
1369 return mConfigFromDefaultApp[phoneId];
1370 }
1371
1372 @VisibleForTesting
1373 /* package */ PersistableBundle getConfigFromCarrierApp(int phoneId) {
1374 return mConfigFromCarrierApp[phoneId];
1375 }
1376
1377 @VisibleForTesting
1378 /* package */ PersistableBundle getNoSimConfig() {
1379 return mNoSimConfig;
1380 }
1381
1382 @VisibleForTesting
1383 /* package */ PersistableBundle getOverrideConfig(int phoneId) {
1384 return mOverrideConfigs[phoneId];
1385 }
1386
Rambo Wangc5901222021-09-17 13:18:35 -07001387 private void unbindIfBound(Context context, CarrierServiceConnection conn) {
1388 if (conn.isBound) {
1389 conn.isBound = false;
Jayachandran C645ec612020-01-10 10:30:25 -08001390 context.unbindService(conn);
1391 }
1392 }
1393
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001394 /**
Rambo Wang610fdf62021-03-08 21:37:11 -08001395 * Returns a boxed Integer object for phoneId, services as message token to distinguish messages
1396 * with same code when calling {@link Handler#removeMessages(int, Object)}.
1397 */
1398 private Integer getMessageToken(int phoneId) {
1399 if (phoneId < -128 || phoneId > 127) {
1400 throw new IllegalArgumentException("phoneId should be in range [-128, 127], inclusive");
1401 }
1402 // Integer#valueOf guarantees the integers within [-128, 127] are cached and thus memory
1403 // comparison (==) returns true for the same integer.
1404 return Integer.valueOf(phoneId);
1405 }
1406
1407 /**
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001408 * If {@code args} contains {@link #DUMP_ARG_REQUESTING_PACKAGE} and a following package name,
1409 * we'll also call {@link IBinder#dump} on the default carrier service (if bound) and the
1410 * specified carrier service (if bound). Typically, this is done for connectivity bug reports
1411 * where we don't call {@code dumpsys activity service all-non-platform} because that contains
1412 * too much info, but we still want to let carrier apps include their diagnostics.
1413 */
Jeff Sharkeya6fcfed2017-07-20 14:18:39 -06001414 @Override
Junda Liu43d723a2015-05-12 17:23:45 -07001415 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001416 IndentingPrintWriter indentPW = new IndentingPrintWriter(pw, " ");
Junda Liu43d723a2015-05-12 17:23:45 -07001417 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
1418 != PackageManager.PERMISSION_GRANTED) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001419 indentPW.println("Permission Denial: can't dump carrierconfig from from pid="
Junda Liu43d723a2015-05-12 17:23:45 -07001420 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
1421 return;
1422 }
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001423 String requestingPackage = null;
1424 int requestingPackageIndex = ArrayUtils.indexOf(args, DUMP_ARG_REQUESTING_PACKAGE);
1425 if (requestingPackageIndex >= 0 && requestingPackageIndex < args.length - 1
1426 && !TextUtils.isEmpty(args[requestingPackageIndex + 1])) {
1427 requestingPackage = args[requestingPackageIndex + 1];
1428 // Throws a SecurityException if the caller is impersonating another app in an effort to
1429 // dump extra info (which may contain PII the caller doesn't have a right to).
1430 enforceCallerIsSystemOrRequestingPackage(requestingPackage);
1431 }
1432
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001433 indentPW.println("CarrierConfigLoader: " + this);
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001434 for (int i = 0; i < TelephonyManager.from(mContext).getActiveModemCount(); i++) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001435 indentPW.println("Phone Id = " + i);
shuoq26a3a4c2016-12-16 11:06:48 -08001436 // display default values in CarrierConfigManager
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001437 printConfig(CarrierConfigManager.getDefaultConfig(), indentPW,
shuoq26a3a4c2016-12-16 11:06:48 -08001438 "Default Values from CarrierConfigManager");
shuoq26a3a4c2016-12-16 11:06:48 -08001439 // display ConfigFromDefaultApp
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001440 printConfig(mConfigFromDefaultApp[i], indentPW, "mConfigFromDefaultApp");
shuoq26a3a4c2016-12-16 11:06:48 -08001441 // display ConfigFromCarrierApp
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001442 printConfig(mConfigFromCarrierApp[i], indentPW, "mConfigFromCarrierApp");
1443 printConfig(mPersistentOverrideConfigs[i], indentPW, "mPersistentOverrideConfigs");
1444 printConfig(mOverrideConfigs[i], indentPW, "mOverrideConfigs");
shuoq26a3a4c2016-12-16 11:06:48 -08001445 }
chen xudb04c292019-03-26 17:01:15 -07001446
Jayachandran C645ec612020-01-10 10:30:25 -08001447 printConfig(mNoSimConfig, indentPW, "mNoSimConfig");
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001448 indentPW.println("CarrierConfigLoadingLog=");
1449 mCarrierConfigLoadingLog.dump(fd, indentPW, args);
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001450
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001451 if (requestingPackage != null) {
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001452 logd("Including default and requesting package " + requestingPackage
1453 + " carrier services in dump");
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001454 indentPW.println("");
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001455 indentPW.println("Connected services");
1456 dumpCarrierServiceIfBound(fd, indentPW, "Default config package",
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001457 mPlatformCarrierConfigPackage, false /* considerCarrierPrivileges */);
1458 dumpCarrierServiceIfBound(fd, indentPW, "Requesting package", requestingPackage,
1459 true /* considerCarrierPrivileges */);
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001460 }
shuoq26a3a4c2016-12-16 11:06:48 -08001461 }
1462
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001463 private void printConfig(PersistableBundle configApp, IndentingPrintWriter indentPW,
1464 String name) {
1465 indentPW.increaseIndent();
shuoq26a3a4c2016-12-16 11:06:48 -08001466 if (configApp == null) {
shuoq26a3a4c2016-12-16 11:06:48 -08001467 indentPW.println(name + " : null ");
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001468 indentPW.decreaseIndent();
1469 indentPW.println("");
shuoq26a3a4c2016-12-16 11:06:48 -08001470 return;
1471 }
shuoq26a3a4c2016-12-16 11:06:48 -08001472 indentPW.println(name + " : ");
1473 List<String> sortedKeys = new ArrayList<String>(configApp.keySet());
1474 Collections.sort(sortedKeys);
1475 indentPW.increaseIndent();
1476 indentPW.increaseIndent();
1477 for (String key : sortedKeys) {
1478 if (configApp.get(key) != null && configApp.get(key) instanceof Object[]) {
1479 indentPW.println(key + " = " +
1480 Arrays.toString((Object[]) configApp.get(key)));
1481 } else if (configApp.get(key) != null && configApp.get(key) instanceof int[]) {
1482 indentPW.println(key + " = " + Arrays.toString((int[]) configApp.get(key)));
1483 } else {
1484 indentPW.println(key + " = " + configApp.get(key));
1485 }
Junda Liu43d723a2015-05-12 17:23:45 -07001486 }
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001487 indentPW.decreaseIndent();
1488 indentPW.decreaseIndent();
1489 indentPW.decreaseIndent();
1490 indentPW.println("");
Junda Liu43d723a2015-05-12 17:23:45 -07001491 }
1492
Hunter Knepshielde601f432020-02-19 10:16:04 -08001493 /**
1494 * Passes without problem when one of these conditions is true:
1495 * - The caller is a privileged UID (e.g. for dumpstate.cpp generating a bug report, where the
1496 * system knows the true caller plumbed in through the {@link android.os.BugreportManager} API).
1497 * - The caller's UID matches the supplied package.
1498 *
1499 * @throws SecurityException if none of the above conditions are met.
1500 */
1501 private void enforceCallerIsSystemOrRequestingPackage(String requestingPackage)
1502 throws SecurityException {
1503 final int callingUid = Binder.getCallingUid();
1504 if (callingUid == Process.ROOT_UID || callingUid == Process.SYSTEM_UID
1505 || callingUid == Process.SHELL_UID || callingUid == Process.PHONE_UID) {
1506 // Bug reports (dumpstate.cpp) run as SHELL, and let some other privileged UIDs through
1507 // as well.
1508 return;
1509 }
1510 // An app is trying to dump extra detail, block it if they aren't who they claim to be.
1511 AppOpsManager appOps = mContext.getSystemService(AppOpsManager.class);
1512 if (appOps == null) {
1513 throw new SecurityException("No AppOps");
1514 }
1515 // Will throw a SecurityException if the UID and package don't match.
1516 appOps.checkPackage(callingUid, requestingPackage);
1517 }
1518
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001519 /**
1520 * Searches for one or more appropriate {@link CarrierService} instances to dump based on the
1521 * current connections.
1522 *
1523 * @param targetPkgName the target package name to dump carrier services for
1524 * @param considerCarrierPrivileges if true, allow a carrier service to be dumped if it shares
1525 * carrier privileges with {@code targetPkgName};
1526 * otherwise, only dump a carrier service if it is {@code
1527 * targetPkgName}
1528 */
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001529 private void dumpCarrierServiceIfBound(FileDescriptor fd, IndentingPrintWriter indentPW,
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001530 String prefix, String targetPkgName, boolean considerCarrierPrivileges) {
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001531 // Null package is possible if it's early in the boot process, there was a recent crash, we
1532 // loaded the config from XML most recently, or a SIM slot is empty. Carrier apps with
1533 // long-lived bindings should typically get dumped here regardless. Even if an app is being
1534 // used for multiple phoneIds, we assume that it's smart enough to handle that on its own,
1535 // and that in most cases we'd just be dumping duplicate information and bloating a report.
1536 indentPW.increaseIndent();
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001537 indentPW.println(prefix + " : " + targetPkgName);
1538 Set<String> dumpedPkgNames = new ArraySet<>(mServiceConnection.length);
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001539 for (CarrierServiceConnection connection : mServiceConnection) {
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001540 if (connection == null || !SubscriptionManager.isValidPhoneId(connection.phoneId)
1541 || TextUtils.isEmpty(connection.pkgName)) {
1542 continue;
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001543 }
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001544 final String servicePkgName = connection.pkgName;
1545 // Note: we intentionally ignore system components here because we should NOT match the
1546 // shell caller that's typically used for bug reports via non-BugreportManager triggers.
1547 final boolean exactPackageMatch = TextUtils.equals(targetPkgName, servicePkgName);
1548 final boolean carrierPrivilegesMatch =
1549 considerCarrierPrivileges && hasCarrierPrivileges(targetPkgName,
1550 connection.phoneId);
1551 if (!exactPackageMatch && !carrierPrivilegesMatch) continue;
1552 // Make sure this service is actually alive before trying to dump it. We don't pay
1553 // attention to mServiceBound[connection.phoneId] because typically carrier apps will
1554 // request long-lived bindings, and even if we unbind the app, it may still be alive due
1555 // to CarrierServiceBindHelper. Pull it out as a reference so even if it gets set to
1556 // null within the ServiceConnection during unbinding we can avoid an NPE.
1557 final IBinder service = connection.service;
1558 if (service == null || !service.isBinderAlive() || !service.pingBinder()) continue;
1559 // We've got a live service. Last check is just to make sure we don't dump a package
1560 // multiple times.
1561 if (!dumpedPkgNames.add(servicePkgName)) continue;
1562 if (!exactPackageMatch) {
1563 logd(targetPkgName + " has carrier privileges on phoneId " + connection.phoneId
1564 + ", service provided by " + servicePkgName);
1565 indentPW.increaseIndent();
1566 indentPW.println("Proxy : " + servicePkgName);
1567 indentPW.decreaseIndent();
1568 }
1569 // Flush before we let the app output anything to ensure correct ordering of output.
1570 // Internally, Binder#dump calls flush on its printer after finishing so we don't
1571 // need to do anything after.
1572 indentPW.flush();
1573 try {
1574 logd("Dumping " + servicePkgName);
1575 // We don't need to give the carrier service any args.
1576 connection.service.dump(fd, null /* args */);
1577 logd("Done with " + servicePkgName);
1578 } catch (RemoteException e) {
1579 logd("RemoteException from " + servicePkgName, e);
1580 indentPW.increaseIndent();
1581 indentPW.println("RemoteException");
1582 indentPW.increaseIndent();
1583 e.printStackTrace(indentPW);
1584 indentPW.decreaseIndent();
1585 indentPW.decreaseIndent();
1586 // We won't retry this package again because now it's in dumpedPkgNames.
1587 }
1588 indentPW.println("");
Jordan Liu46ed5db2020-01-28 08:55:20 -08001589 }
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001590 if (dumpedPkgNames.isEmpty()) {
1591 indentPW.increaseIndent();
1592 indentPW.println("Not bound");
1593 indentPW.decreaseIndent();
1594 indentPW.println("");
1595 }
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001596 indentPW.decreaseIndent();
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001597 }
1598
1599 private boolean hasCarrierPrivileges(String pkgName, int phoneId) {
1600 int[] subIds = SubscriptionManager.getSubId(phoneId);
1601 if (ArrayUtils.isEmpty(subIds)) {
1602 return false;
1603 }
1604 return TelephonyManager.from(mContext).createForSubscriptionId(
1605 subIds[0]).checkCarrierPrivilegesForPackage(pkgName)
1606 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Jordan Liu46ed5db2020-01-28 08:55:20 -08001607 }
1608
Zach Johnson36d7aab2015-05-22 15:43:00 -07001609 private class CarrierServiceConnection implements ServiceConnection {
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001610 final int phoneId;
1611 final String pkgName;
1612 final int eventId;
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001613 IBinder service;
Rambo Wangc5901222021-09-17 13:18:35 -07001614 // If bindService was called and return true which means unbindService
1615 // must be called later to release the connection
1616 boolean isBound;
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001617
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001618 CarrierServiceConnection(int phoneId, String pkgName, int eventId) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001619 this.phoneId = phoneId;
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001620 this.pkgName = pkgName;
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001621 this.eventId = eventId;
Rambo Wangc5901222021-09-17 13:18:35 -07001622 this.isBound = false;
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001623 }
1624
1625 @Override
1626 public void onServiceConnected(ComponentName name, IBinder service) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001627 logd("Connected to config app: " + name.flattenToShortString());
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001628 this.service = service;
1629 mHandler.sendMessage(mHandler.obtainMessage(eventId, phoneId, -1, this));
1630 }
1631
1632 @Override
1633 public void onServiceDisconnected(ComponentName name) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001634 logd("Disconnected from config app: " + name.flattenToShortString());
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001635 this.service = null;
Jordan Liu46ed5db2020-01-28 08:55:20 -08001636 }
1637
1638 @Override
1639 public void onBindingDied(ComponentName name) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001640 logd("Binding died from config app: " + name.flattenToShortString());
Jordan Liu46ed5db2020-01-28 08:55:20 -08001641 this.service = null;
Jordan Liu46ed5db2020-01-28 08:55:20 -08001642 }
1643
1644 @Override
1645 public void onNullBinding(ComponentName name) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001646 logd("Null binding from config app: " + name.flattenToShortString());
Jordan Liu46ed5db2020-01-28 08:55:20 -08001647 this.service = null;
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001648 }
1649 }
1650
1651 private class ConfigLoaderBroadcastReceiver extends BroadcastReceiver {
1652 @Override
1653 public void onReceive(Context context, Intent intent) {
1654 String action = intent.getAction();
Junda Liu8a8a53a2015-05-15 16:19:57 -07001655 boolean replace = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
1656 // If replace is true, only care ACTION_PACKAGE_REPLACED.
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001657 if (replace && !Intent.ACTION_PACKAGE_REPLACED.equals(action)) {
Junda Liu8a8a53a2015-05-15 16:19:57 -07001658 return;
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001659 }
Junda Liu8a8a53a2015-05-15 16:19:57 -07001660
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001661 switch (action) {
Nanxi Chen3d670502016-03-17 16:32:09 -07001662 case Intent.ACTION_BOOT_COMPLETED:
1663 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SYSTEM_UNLOCKED, null));
1664 break;
1665
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001666 case Intent.ACTION_PACKAGE_ADDED:
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001667 case Intent.ACTION_PACKAGE_REMOVED:
Junda Liu8a8a53a2015-05-15 16:19:57 -07001668 case Intent.ACTION_PACKAGE_REPLACED:
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001669 int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
1670 String packageName = mContext.getPackageManager().getNameForUid(uid);
Junda Liu8a8a53a2015-05-15 16:19:57 -07001671 if (packageName != null) {
1672 // We don't have a phoneId for arg1.
1673 mHandler.sendMessage(
1674 mHandler.obtainMessage(EVENT_PACKAGE_CHANGED, packageName));
1675 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001676 break;
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001677 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001678 }
1679 }
1680
Rambo Wangab13e3e2021-04-08 15:01:06 -07001681 // Get readable string for the message code supported in this class.
1682 private static String eventToString(int code) {
1683 switch (code) {
1684 case EVENT_CLEAR_CONFIG:
1685 return "EVENT_CLEAR_CONFIG";
1686 case EVENT_CONNECTED_TO_DEFAULT:
1687 return "EVENT_CONNECTED_TO_DEFAULT";
1688 case EVENT_CONNECTED_TO_CARRIER:
1689 return "EVENT_CONNECTED_TO_CARRIER";
1690 case EVENT_FETCH_DEFAULT_DONE:
1691 return "EVENT_FETCH_DEFAULT_DONE";
1692 case EVENT_FETCH_CARRIER_DONE:
1693 return "EVENT_FETCH_CARRIER_DONE";
1694 case EVENT_DO_FETCH_DEFAULT:
1695 return "EVENT_DO_FETCH_DEFAULT";
1696 case EVENT_DO_FETCH_CARRIER:
1697 return "EVENT_DO_FETCH_CARRIER";
1698 case EVENT_PACKAGE_CHANGED:
1699 return "EVENT_PACKAGE_CHANGED";
1700 case EVENT_BIND_DEFAULT_TIMEOUT:
1701 return "EVENT_BIND_DEFAULT_TIMEOUT";
1702 case EVENT_BIND_CARRIER_TIMEOUT:
1703 return "EVENT_BIND_CARRIER_TIMEOUT";
1704 case EVENT_CHECK_SYSTEM_UPDATE:
1705 return "EVENT_CHECK_SYSTEM_UPDATE";
1706 case EVENT_SYSTEM_UNLOCKED:
1707 return "EVENT_SYSTEM_UNLOCKED";
1708 case EVENT_FETCH_DEFAULT_TIMEOUT:
1709 return "EVENT_FETCH_DEFAULT_TIMEOUT";
1710 case EVENT_FETCH_CARRIER_TIMEOUT:
1711 return "EVENT_FETCH_CARRIER_TIMEOUT";
1712 case EVENT_SUBSCRIPTION_INFO_UPDATED:
1713 return "EVENT_SUBSCRIPTION_INFO_UPDATED";
1714 case EVENT_MULTI_SIM_CONFIG_CHANGED:
1715 return "EVENT_MULTI_SIM_CONFIG_CHANGED";
1716 case EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG:
1717 return "EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG";
1718 case EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE:
1719 return "EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE";
1720 case EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG:
1721 return "EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG";
1722 case EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT:
1723 return "EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT";
1724 case EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT:
1725 return "EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT";
1726 default:
1727 return "UNKNOWN(" + code + ")";
1728 }
1729 }
1730
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001731 private void logd(String msg) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001732 Log.d(LOG_TAG, msg);
1733 }
1734
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001735 private void logd(String msg, Throwable tr) {
1736 Log.d(LOG_TAG, msg, tr);
1737 }
1738
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001739 private void logdWithLocalLog(String msg) {
chen xudb04c292019-03-26 17:01:15 -07001740 Log.d(LOG_TAG, msg);
1741 mCarrierConfigLoadingLog.log(msg);
1742 }
1743
1744 private void loge(String msg) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001745 Log.e(LOG_TAG, msg);
chen xudb04c292019-03-26 17:01:15 -07001746 mCarrierConfigLoadingLog.log(msg);
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001747 }
1748}