blob: 54b1054b6661f858f0ca63fb154f7607298bf864 [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;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080068
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -070069import java.io.File;
Junda Liu43d723a2015-05-12 17:23:45 -070070import java.io.FileDescriptor;
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -070071import java.io.FileInputStream;
72import java.io.FileNotFoundException;
73import java.io.FileOutputStream;
Jonathan Basseri1f743c92015-05-15 00:19:46 -070074import java.io.FilenameFilter;
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -070075import java.io.IOException;
Junda Liu43d723a2015-05-12 17:23:45 -070076import java.io.PrintWriter;
shuoq26a3a4c2016-12-16 11:06:48 -080077import java.util.ArrayList;
78import java.util.Arrays;
79import java.util.Collections;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080080import java.util.List;
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -080081import java.util.Set;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080082
83/**
84 * CarrierConfigLoader binds to privileged carrier apps to fetch carrier config overlays.
Jonathan Basseri6465afd2015-02-25 13:05:57 -080085 */
Jonathan Basseri6465afd2015-02-25 13:05:57 -080086public class CarrierConfigLoader extends ICarrierConfigLoader.Stub {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -070087 private static final String LOG_TAG = "CarrierConfigLoader";
Meng Wang33ad2bc2017-03-16 20:21:20 -070088
89 // Package name for platform carrier config app, bundled with system image.
90 private final String mPlatformCarrierConfigPackage;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080091
92 /** The singleton instance. */
93 private static CarrierConfigLoader sInstance;
94 // The context for phone app, passed from PhoneGlobals.
95 private Context mContext;
96 // Carrier configs from default app, indexed by phoneID.
Jonathan Basseric31f1f32015-05-12 10:13:03 -070097 private PersistableBundle[] mConfigFromDefaultApp;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080098 // Carrier configs from privileged carrier config app, indexed by phoneID.
Jonathan Basseric31f1f32015-05-12 10:13:03 -070099 private PersistableBundle[] mConfigFromCarrierApp;
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100100 // Persistent Carrier configs that are provided via the override test API, indexed by phone ID.
101 private PersistableBundle[] mPersistentOverrideConfigs;
Hall Liu506724b2018-10-22 18:16:14 -0700102 // Carrier configs that are provided via the override test API, indexed by phone ID.
103 private PersistableBundle[] mOverrideConfigs;
Jayachandran C645ec612020-01-10 10:30:25 -0800104 // Carrier configs to override code default when there is no SIM inserted
105 private PersistableBundle mNoSimConfig;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800106 // Service connection for binding to config app.
Zach Johnson36d7aab2015-05-22 15:43:00 -0700107 private CarrierServiceConnection[] mServiceConnection;
Jayachandran C645ec612020-01-10 10:30:25 -0800108 // Service connection for binding to carrier config app for no SIM config.
109 private CarrierServiceConnection[] mServiceConnectionForNoSimConfig;
Jordan Liu178430d2020-02-10 14:32:15 -0800110 // Whether we are bound to a service for each phone
111 private boolean[] mServiceBound;
Jayachandran C645ec612020-01-10 10:30:25 -0800112 // Whether we are bound to a service for no SIM config
113 private boolean[] mServiceBoundForNoSimConfig;
Sarah Chin807d5c62020-03-30 17:21:09 -0700114 // Whether we have sent config change broadcast for each phone id.
Junda Liu03aad762017-07-21 13:32:17 -0700115 private boolean[] mHasSentConfigChange;
Sarah Chin807d5c62020-03-30 17:21:09 -0700116 // Whether the broadcast was sent from EVENT_SYSTEM_UNLOCKED, to track rebroadcasts
117 private boolean[] mFromSystemUnlocked;
Nathan Harold48ac0972019-03-13 22:33:01 -0700118 // SubscriptionInfoUpdater
119 private final SubscriptionInfoUpdater mSubscriptionInfoUpdater;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800120
Nanxi Chen3d670502016-03-17 16:32:09 -0700121 // Broadcast receiver for Boot intents, register intent filter in construtor.
122 private final BroadcastReceiver mBootReceiver = new ConfigLoaderBroadcastReceiver();
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800123 // Broadcast receiver for SIM and pkg intents, register intent filter in constructor.
Nanxi Chen3d670502016-03-17 16:32:09 -0700124 private final BroadcastReceiver mPackageReceiver = new ConfigLoaderBroadcastReceiver();
Jack Yu67663de2019-10-17 15:19:48 -0700125 private final LocalLog mCarrierConfigLoadingLog = new LocalLog(100);
chen xudb04c292019-03-26 17:01:15 -0700126
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800127
128 // Message codes; see mHandler below.
129 // Request from SubscriptionInfoUpdater when SIM becomes absent or error.
130 private static final int EVENT_CLEAR_CONFIG = 0;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800131 // Has connected to default app.
132 private static final int EVENT_CONNECTED_TO_DEFAULT = 3;
133 // Has connected to carrier app.
134 private static final int EVENT_CONNECTED_TO_CARRIER = 4;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700135 // Config has been loaded from default app (or cache).
136 private static final int EVENT_FETCH_DEFAULT_DONE = 5;
137 // Config has been loaded from carrier app (or cache).
138 private static final int EVENT_FETCH_CARRIER_DONE = 6;
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700139 // Attempt to fetch from default app or read from XML.
Jonathan Basseri65273c82017-07-25 15:08:42 -0700140 private static final int EVENT_DO_FETCH_DEFAULT = 7;
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700141 // Attempt to fetch from carrier app or read from XML.
Jonathan Basseri65273c82017-07-25 15:08:42 -0700142 private static final int EVENT_DO_FETCH_CARRIER = 8;
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700143 // A package has been installed, uninstalled, or updated.
144 private static final int EVENT_PACKAGE_CHANGED = 9;
Jonathan Basseri930701e2015-06-11 20:56:43 -0700145 // Bind timed out for the default app.
146 private static final int EVENT_BIND_DEFAULT_TIMEOUT = 10;
147 // Bind timed out for a carrier app.
148 private static final int EVENT_BIND_CARRIER_TIMEOUT = 11;
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700149 // Check if the system fingerprint has changed.
150 private static final int EVENT_CHECK_SYSTEM_UPDATE = 12;
Nanxi Chen3d670502016-03-17 16:32:09 -0700151 // Rerun carrier config binding after system is unlocked.
152 private static final int EVENT_SYSTEM_UNLOCKED = 13;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700153 // Fetching config timed out from the default app.
154 private static final int EVENT_FETCH_DEFAULT_TIMEOUT = 14;
155 // Fetching config timed out from a carrier app.
156 private static final int EVENT_FETCH_CARRIER_TIMEOUT = 15;
Nathan Harold48ac0972019-03-13 22:33:01 -0700157 // SubscriptionInfoUpdater has finished updating the sub for the carrier config.
158 private static final int EVENT_SUBSCRIPTION_INFO_UPDATED = 16;
Malcolm Chen5ea18532019-10-24 19:55:44 -0700159 // Multi-SIM config changed.
160 private static final int EVENT_MULTI_SIM_CONFIG_CHANGED = 17;
Jayachandran C645ec612020-01-10 10:30:25 -0800161 // Attempt to fetch from default app or read from XML for no SIM case.
162 private static final int EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG = 18;
163 // No SIM config has been loaded from default app (or cache).
164 private static final int EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE = 19;
165 // Has connected to default app for no SIM config.
166 private static final int EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG = 20;
167 // Bind timed out for the default app when trying to fetch no SIM config.
168 private static final int EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT = 21;
169 // Fetching config timed out from the default app for no SIM config.
170 private static final int EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT = 22;
Rambo Wangab13e3e2021-04-08 15:01:06 -0700171 // NOTE: any new EVENT_* values must be added to method eventToString().
Jonathan Basseri930701e2015-06-11 20:56:43 -0700172
Junda Liu6cb45002016-03-22 17:18:20 -0700173 private static final int BIND_TIMEOUT_MILLIS = 30000;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800174
Meng Wang0f6b2ea2020-01-06 18:31:16 -0800175 // Keys used for saving and restoring config bundle from file.
176 private static final String KEY_VERSION = "__carrier_config_package_version__";
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800177
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100178 private static final String OVERRIDE_PACKAGE_ADDITION = "-override";
179
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700180 // SharedPreferences key for last known build fingerprint.
181 private static final String KEY_FINGERPRINT = "build_fingerprint";
182
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -0800183 // Argument for #dump that indicates we should also call the default and specified carrier
184 // service's #dump method. In multi-SIM devices, it's possible that carrier A is on SIM 1 and
185 // carrier B is on SIM 2, in which case we should not dump carrier B's service when carrier A
186 // requested the dump.
187 private static final String DUMP_ARG_REQUESTING_PACKAGE = "--requesting-package";
188
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800189 // Handler to process various events.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700190 //
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700191 // For each phoneId, the event sequence should be:
Jonathan Basseri65273c82017-07-25 15:08:42 -0700192 // fetch default, connected to default, fetch default (async), fetch default done,
193 // fetch carrier, connected to carrier, fetch carrier (async), fetch carrier done.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700194 //
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700195 // If there is a saved config file for either the default app or the carrier app, we skip
196 // binding to the app and go straight from fetch to loaded.
197 //
198 // At any time, at most one connection is active. If events are not in this order, previous
199 // connection will be unbound, so only latest event takes effect.
200 //
201 // We broadcast ACTION_CARRIER_CONFIG_CHANGED after:
202 // 1. loading from carrier app (even if read from a file)
203 // 2. loading from default app if there is no carrier app (even if read from a file)
204 // 3. clearing config (e.g. due to sim removal)
205 // 4. encountering bind or IPC error
Jonathan Basseri65273c82017-07-25 15:08:42 -0700206 private class ConfigHandler extends Handler {
Rambo Wang7e3bc122021-03-23 09:24:38 -0700207 ConfigHandler(@NonNull Looper looper) {
208 super(looper);
209 }
210
Jonathan Basseri65273c82017-07-25 15:08:42 -0700211 @Override
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800212 public void handleMessage(Message msg) {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700213 final int phoneId = msg.arg1;
Rambo Wangab13e3e2021-04-08 15:01:06 -0700214 logdWithLocalLog("mHandler: " + eventToString(msg.what) + " phoneId: " + phoneId);
Malcolm Chen5ea18532019-10-24 19:55:44 -0700215 if (!SubscriptionManager.isValidPhoneId(phoneId)
216 && msg.what != EVENT_MULTI_SIM_CONFIG_CHANGED) {
217 return;
218 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800219 switch (msg.what) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800220 case EVENT_CLEAR_CONFIG: {
Malcolm Chen5ea18532019-10-24 19:55:44 -0700221 clearConfigForPhone(phoneId, true);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800222 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700223 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700224
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800225 case EVENT_SYSTEM_UNLOCKED: {
Malcolm Chen5ea18532019-10-24 19:55:44 -0700226 for (int i = 0; i < TelephonyManager.from(mContext).getActiveModemCount();
227 ++i) {
Sarah Chin807d5c62020-03-30 17:21:09 -0700228 // When the user unlocks the device, send the broadcast again (with a
229 // rebroadcast extra) if we have sent it before unlock. This will avoid
230 // trying to load the carrier config when the SIM is still loading when the
231 // unlock happens.
Junda Liu03aad762017-07-21 13:32:17 -0700232 if (mHasSentConfigChange[i]) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800233 logdWithLocalLog("System unlocked");
Sarah Chin807d5c62020-03-30 17:21:09 -0700234 mFromSystemUnlocked[i] = true;
Junda Liu03aad762017-07-21 13:32:17 -0700235 updateConfigForPhoneId(i);
236 }
Nanxi Chen3d670502016-03-17 16:32:09 -0700237 }
238 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700239 }
Nanxi Chen3d670502016-03-17 16:32:09 -0700240
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800241 case EVENT_PACKAGE_CHANGED: {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700242 final String carrierPackageName = (String) msg.obj;
243 // Only update if there are cached config removed to avoid updating config for
244 // unrelated packages.
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700245 if (clearCachedConfigForPackage(carrierPackageName)) {
Malcolm Chen5ea18532019-10-24 19:55:44 -0700246 int numPhones = TelephonyManager.from(mContext).getActiveModemCount();
Junda Liu8a8a53a2015-05-15 16:19:57 -0700247 for (int i = 0; i < numPhones; ++i) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800248 logdWithLocalLog("Package changed: " + carrierPackageName
Jack Yu67663de2019-10-17 15:19:48 -0700249 + ", phone=" + i);
Junda Liu8a8a53a2015-05-15 16:19:57 -0700250 updateConfigForPhoneId(i);
251 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700252 }
253 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700254 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700255
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800256 case EVENT_DO_FETCH_DEFAULT: {
Rambo Wang9bc7d362021-03-09 09:10:58 -0800257 // Clear in-memory cache for carrier app config, so when carrier app gets
258 // uninstalled, no stale config is left.
259 if (mConfigFromCarrierApp[phoneId] != null
260 && getCarrierPackageForPhoneId(phoneId) == null) {
261 mConfigFromCarrierApp[phoneId] = null;
262 }
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100263 // Restore persistent override values.
264 PersistableBundle config = restoreConfigFromXml(
265 mPlatformCarrierConfigPackage, OVERRIDE_PACKAGE_ADDITION, phoneId);
266 if (config != null) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800267 logd("Loaded persistent override config from XML. package="
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100268 + mPlatformCarrierConfigPackage
269 + " phoneId=" + phoneId);
270 mPersistentOverrideConfigs[phoneId] = config;
271 }
272
273 config = restoreConfigFromXml(mPlatformCarrierConfigPackage, "", phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700274 if (config != null) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800275 logd(
Jonathan Basseri65273c82017-07-25 15:08:42 -0700276 "Loaded config from XML. package="
277 + mPlatformCarrierConfigPackage
278 + " phoneId="
279 + phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700280 mConfigFromDefaultApp[phoneId] = config;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700281 Message newMsg = obtainMessage(EVENT_FETCH_DEFAULT_DONE, phoneId, -1);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700282 newMsg.getData().putBoolean("loaded_from_xml", true);
283 mHandler.sendMessage(newMsg);
284 } else {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700285 // No cached config, so fetch it from the default app.
286 if (bindToConfigPackage(
287 mPlatformCarrierConfigPackage,
288 phoneId,
289 EVENT_CONNECTED_TO_DEFAULT)) {
290 sendMessageDelayed(
Rambo Wang610fdf62021-03-08 21:37:11 -0800291 obtainMessage(EVENT_BIND_DEFAULT_TIMEOUT, phoneId, -1 /*arg2*/,
292 getMessageToken(phoneId)),
Jonathan Basseri930701e2015-06-11 20:56:43 -0700293 BIND_TIMEOUT_MILLIS);
294 } else {
Nathan Harold1122e3d2021-01-22 15:45:24 -0800295 // Put a stub bundle in place so that the rest of the logic continues
296 // smoothly.
Rambo Wang42026112021-04-07 20:57:28 +0000297 mConfigFromDefaultApp[phoneId] = new PersistableBundle();
Jonathan Basseri65273c82017-07-25 15:08:42 -0700298 // Send broadcast if bind fails.
Nathan Harold48ac0972019-03-13 22:33:01 -0700299 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700300 // TODO: We *must* call unbindService even if bindService returns false.
301 // (And possibly if SecurityException was thrown.)
chen xudb04c292019-03-26 17:01:15 -0700302 loge("binding to default app: "
303 + mPlatformCarrierConfigPackage + " fails");
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700304 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800305 }
306 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700307 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800308
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800309 case EVENT_CONNECTED_TO_DEFAULT: {
Rambo Wang610fdf62021-03-08 21:37:11 -0800310 removeMessages(EVENT_BIND_DEFAULT_TIMEOUT, getMessageToken(phoneId));
Jonathan Basseri65273c82017-07-25 15:08:42 -0700311 final CarrierServiceConnection conn = (CarrierServiceConnection) msg.obj;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800312 // If new service connection has been created, unbind.
313 if (mServiceConnection[phoneId] != conn || conn.service == null) {
Jordan Liu178430d2020-02-10 14:32:15 -0800314 unbindIfBound(mContext, conn, phoneId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800315 break;
316 }
chen xu02581692018-11-11 19:03:44 -0800317 final CarrierIdentifier carrierId = getCarrierIdentifierForPhoneId(phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700318 // ResultReceiver callback will execute in this Handler's thread.
319 final ResultReceiver resultReceiver =
320 new ResultReceiver(this) {
321 @Override
322 public void onReceiveResult(int resultCode, Bundle resultData) {
Jordan Liu178430d2020-02-10 14:32:15 -0800323 unbindIfBound(mContext, conn, phoneId);
Rambo Wanga9d27a52021-04-09 16:17:33 -0700324 removeMessages(EVENT_FETCH_DEFAULT_TIMEOUT,
325 getMessageToken(phoneId));
Jonathan Basseri65273c82017-07-25 15:08:42 -0700326 // If new service connection has been created, this is stale.
327 if (mServiceConnection[phoneId] != conn) {
328 loge("Received response for stale request.");
329 return;
330 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700331 if (resultCode == RESULT_ERROR || resultData == null) {
332 // On error, abort config fetching.
333 loge("Failed to get carrier config");
Nathan Harold48ac0972019-03-13 22:33:01 -0700334 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700335 return;
336 }
337 PersistableBundle config =
338 resultData.getParcelable(KEY_CONFIG_BUNDLE);
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100339 saveConfigToXml(mPlatformCarrierConfigPackage, "", phoneId,
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800340 carrierId, config);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700341 mConfigFromDefaultApp[phoneId] = config;
342 sendMessage(
343 obtainMessage(
344 EVENT_FETCH_DEFAULT_DONE, phoneId, -1));
345 }
346 };
347 // Now fetch the config asynchronously from the ICarrierService.
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800348 try {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700349 ICarrierService carrierService =
350 ICarrierService.Stub.asInterface(conn.service);
351 carrierService.getCarrierConfig(carrierId, resultReceiver);
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800352 logdWithLocalLog("Fetch config for default app: "
chen xudb04c292019-03-26 17:01:15 -0700353 + mPlatformCarrierConfigPackage
354 + " carrierid: " + carrierId.toString());
Jonathan Basseri65273c82017-07-25 15:08:42 -0700355 } catch (RemoteException e) {
chen xudb04c292019-03-26 17:01:15 -0700356 loge("Failed to get carrier config from default app: " +
357 mPlatformCarrierConfigPackage + " err: " + e.toString());
Jordan Liu178430d2020-02-10 14:32:15 -0800358 unbindIfBound(mContext, conn, phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700359 break; // So we don't set a timeout.
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800360 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700361 sendMessageDelayed(
Rambo Wang610fdf62021-03-08 21:37:11 -0800362 obtainMessage(EVENT_FETCH_DEFAULT_TIMEOUT, phoneId, -1 /*arg2*/,
363 getMessageToken(phoneId)),
Jonathan Basseri65273c82017-07-25 15:08:42 -0700364 BIND_TIMEOUT_MILLIS);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800365 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700366 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800367
Jonathan Basseri930701e2015-06-11 20:56:43 -0700368 case EVENT_BIND_DEFAULT_TIMEOUT:
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800369 case EVENT_FETCH_DEFAULT_TIMEOUT: {
370 loge("Bind/fetch time out from " + mPlatformCarrierConfigPackage);
Rambo Wang610fdf62021-03-08 21:37:11 -0800371 removeMessages(EVENT_FETCH_DEFAULT_TIMEOUT, getMessageToken(phoneId));
chen xuf60b3162019-05-01 21:31:05 -0700372 // If we attempted to bind to the app, but the service connection is null due to
373 // the race condition that clear config event happens before bind/fetch complete
374 // then config was cleared while we were waiting and we should not continue.
375 if (mServiceConnection[phoneId] != null) {
376 // If a ResponseReceiver callback is in the queue when this happens, we will
377 // unbind twice and throw an exception.
Jordan Liu178430d2020-02-10 14:32:15 -0800378 unbindIfBound(mContext, mServiceConnection[phoneId], phoneId);
chen xuf60b3162019-05-01 21:31:05 -0700379 broadcastConfigChangedIntent(phoneId);
380 }
Nathan Harold1122e3d2021-01-22 15:45:24 -0800381 // Put a stub bundle in place so that the rest of the logic continues smoothly.
Rambo Wang42026112021-04-07 20:57:28 +0000382 mConfigFromDefaultApp[phoneId] = new PersistableBundle();
Nathan Harold48ac0972019-03-13 22:33:01 -0700383 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri930701e2015-06-11 20:56:43 -0700384 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700385 }
Jonathan Basseri930701e2015-06-11 20:56:43 -0700386
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800387 case EVENT_FETCH_DEFAULT_DONE: {
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700388 // If we attempted to bind to the app, but the service connection is null, then
389 // config was cleared while we were waiting and we should not continue.
390 if (!msg.getData().getBoolean("loaded_from_xml", false)
391 && mServiceConnection[phoneId] == null) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800392 break;
393 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700394 final String carrierPackageName = getCarrierPackageForPhoneId(phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700395 if (carrierPackageName != null) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800396 logd("Found carrier config app: " + carrierPackageName);
Jordan Liu38a614c2019-03-20 15:01:17 -0700397 sendMessage(obtainMessage(EVENT_DO_FETCH_CARRIER, phoneId, -1));
Jonathan Basserib919e932015-05-27 16:53:08 +0000398 } else {
Nathan Harold48ac0972019-03-13 22:33:01 -0700399 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri4ae2e7c2015-05-15 00:19:46 -0700400 }
401 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700402 }
Jonathan Basseri4ae2e7c2015-05-15 00:19:46 -0700403
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800404 case EVENT_DO_FETCH_CARRIER: {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700405 final String carrierPackageName = getCarrierPackageForPhoneId(phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700406 final PersistableBundle config =
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100407 restoreConfigFromXml(carrierPackageName, "", phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700408 if (config != null) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800409 logd(
Jonathan Basseri65273c82017-07-25 15:08:42 -0700410 "Loaded config from XML. package="
411 + carrierPackageName
412 + " phoneId="
413 + phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700414 mConfigFromCarrierApp[phoneId] = config;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700415 Message newMsg = obtainMessage(EVENT_FETCH_CARRIER_DONE, phoneId, -1);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700416 newMsg.getData().putBoolean("loaded_from_xml", true);
417 sendMessage(newMsg);
418 } else {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700419 // No cached config, so fetch it from a carrier app.
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800420 if (carrierPackageName != null && bindToConfigPackage(carrierPackageName,
421 phoneId, EVENT_CONNECTED_TO_CARRIER)) {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700422 sendMessageDelayed(
Rambo Wang610fdf62021-03-08 21:37:11 -0800423 obtainMessage(EVENT_BIND_CARRIER_TIMEOUT, phoneId, -1 /*arg2*/,
424 getMessageToken(phoneId)),
Jonathan Basseri930701e2015-06-11 20:56:43 -0700425 BIND_TIMEOUT_MILLIS);
426 } else {
Nathan Harold1122e3d2021-01-22 15:45:24 -0800427 // Put a stub bundle in place so that the rest of the logic continues
428 // smoothly.
Rambo Wang42026112021-04-07 20:57:28 +0000429 mConfigFromCarrierApp[phoneId] = new PersistableBundle();
Jonathan Basseri65273c82017-07-25 15:08:42 -0700430 // Send broadcast if bind fails.
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700431 broadcastConfigChangedIntent(phoneId);
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800432 loge("Bind to carrier app: " + carrierPackageName + " fails");
Nathan Harold48ac0972019-03-13 22:33:01 -0700433 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700434 }
435 }
436 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700437 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700438
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800439 case EVENT_CONNECTED_TO_CARRIER: {
Rambo Wang610fdf62021-03-08 21:37:11 -0800440 removeMessages(EVENT_BIND_CARRIER_TIMEOUT, getMessageToken(phoneId));
Jonathan Basseri65273c82017-07-25 15:08:42 -0700441 final CarrierServiceConnection conn = (CarrierServiceConnection) msg.obj;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800442 // If new service connection has been created, unbind.
Jonathan Basseri65273c82017-07-25 15:08:42 -0700443 if (mServiceConnection[phoneId] != conn || conn.service == null) {
Jordan Liu178430d2020-02-10 14:32:15 -0800444 unbindIfBound(mContext, conn, phoneId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800445 break;
446 }
chen xu02581692018-11-11 19:03:44 -0800447 final CarrierIdentifier carrierId = getCarrierIdentifierForPhoneId(phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700448 // ResultReceiver callback will execute in this Handler's thread.
449 final ResultReceiver resultReceiver =
450 new ResultReceiver(this) {
451 @Override
452 public void onReceiveResult(int resultCode, Bundle resultData) {
Jordan Liu178430d2020-02-10 14:32:15 -0800453 unbindIfBound(mContext, conn, phoneId);
Rambo Wanga9d27a52021-04-09 16:17:33 -0700454 removeMessages(EVENT_FETCH_CARRIER_TIMEOUT,
455 getMessageToken(phoneId));
Jonathan Basseri65273c82017-07-25 15:08:42 -0700456 // If new service connection has been created, this is stale.
457 if (mServiceConnection[phoneId] != conn) {
458 loge("Received response for stale request.");
459 return;
460 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700461 if (resultCode == RESULT_ERROR || resultData == null) {
462 // On error, abort config fetching.
chen xudb04c292019-03-26 17:01:15 -0700463 loge("Failed to get carrier config from carrier app: "
464 + getCarrierPackageForPhoneId(phoneId));
Jonathan Basseri65273c82017-07-25 15:08:42 -0700465 broadcastConfigChangedIntent(phoneId);
Nathan Harold48ac0972019-03-13 22:33:01 -0700466 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700467 return;
468 }
469 PersistableBundle config =
470 resultData.getParcelable(KEY_CONFIG_BUNDLE);
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100471 saveConfigToXml(getCarrierPackageForPhoneId(phoneId), "",
472 phoneId, carrierId, config);
Amit Mahajan304e92b2021-04-08 14:03:30 -0700473 if (config != null) {
474 mConfigFromCarrierApp[phoneId] = config;
475 } else {
476 logdWithLocalLog("Config from carrier app is null "
477 + "for phoneId " + phoneId);
478 // Put a stub bundle in place so that the rest of the logic
479 // continues smoothly.
480 mConfigFromCarrierApp[phoneId] = new PersistableBundle();
481 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700482 sendMessage(
483 obtainMessage(
484 EVENT_FETCH_CARRIER_DONE, phoneId, -1));
485 }
486 };
487 // Now fetch the config asynchronously from the ICarrierService.
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800488 try {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700489 ICarrierService carrierService =
490 ICarrierService.Stub.asInterface(conn.service);
491 carrierService.getCarrierConfig(carrierId, resultReceiver);
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800492 logdWithLocalLog("Fetch config for carrier app: "
chen xudb04c292019-03-26 17:01:15 -0700493 + getCarrierPackageForPhoneId(phoneId)
494 + " carrierid: " + carrierId.toString());
Jonathan Basseri65273c82017-07-25 15:08:42 -0700495 } catch (RemoteException e) {
496 loge("Failed to get carrier config: " + e.toString());
Jordan Liu178430d2020-02-10 14:32:15 -0800497 unbindIfBound(mContext, conn, phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700498 break; // So we don't set a timeout.
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800499 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700500 sendMessageDelayed(
Rambo Wang610fdf62021-03-08 21:37:11 -0800501 obtainMessage(EVENT_FETCH_CARRIER_TIMEOUT, phoneId, -1 /*arg2*/,
502 getMessageToken(phoneId)),
Jonathan Basseri65273c82017-07-25 15:08:42 -0700503 BIND_TIMEOUT_MILLIS);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800504 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700505 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800506
Jonathan Basseri930701e2015-06-11 20:56:43 -0700507 case EVENT_BIND_CARRIER_TIMEOUT:
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800508 case EVENT_FETCH_CARRIER_TIMEOUT: {
Nathan Harold1122e3d2021-01-22 15:45:24 -0800509 loge("Bind/fetch from carrier app timeout, package="
510 + getCarrierPackageForPhoneId(phoneId));
Rambo Wang610fdf62021-03-08 21:37:11 -0800511 removeMessages(EVENT_FETCH_CARRIER_TIMEOUT, getMessageToken(phoneId));
chen xuf60b3162019-05-01 21:31:05 -0700512 // If we attempted to bind to the app, but the service connection is null due to
513 // the race condition that clear config event happens before bind/fetch complete
514 // then config was cleared while we were waiting and we should not continue.
515 if (mServiceConnection[phoneId] != null) {
516 // If a ResponseReceiver callback is in the queue when this happens, we will
517 // unbind twice and throw an exception.
Jordan Liu178430d2020-02-10 14:32:15 -0800518 unbindIfBound(mContext, mServiceConnection[phoneId], phoneId);
chen xuf60b3162019-05-01 21:31:05 -0700519 broadcastConfigChangedIntent(phoneId);
520 }
Nathan Harold1122e3d2021-01-22 15:45:24 -0800521 // Put a stub bundle in place so that the rest of the logic continues smoothly.
Rambo Wang42026112021-04-07 20:57:28 +0000522 mConfigFromCarrierApp[phoneId] = new PersistableBundle();
Nathan Harold48ac0972019-03-13 22:33:01 -0700523 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri930701e2015-06-11 20:56:43 -0700524 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700525 }
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800526 case EVENT_FETCH_CARRIER_DONE: {
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700527 // If we attempted to bind to the app, but the service connection is null, then
528 // config was cleared while we were waiting and we should not continue.
529 if (!msg.getData().getBoolean("loaded_from_xml", false)
530 && mServiceConnection[phoneId] == null) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800531 break;
532 }
Nathan Harold48ac0972019-03-13 22:33:01 -0700533 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800534 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700535 }
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700536
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800537 case EVENT_CHECK_SYSTEM_UPDATE: {
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700538 SharedPreferences sharedPrefs =
539 PreferenceManager.getDefaultSharedPreferences(mContext);
540 final String lastFingerprint = sharedPrefs.getString(KEY_FINGERPRINT, null);
541 if (!Build.FINGERPRINT.equals(lastFingerprint)) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800542 logd(
Jonathan Basseri65273c82017-07-25 15:08:42 -0700543 "Build fingerprint changed. old: "
544 + lastFingerprint
545 + " new: "
546 + Build.FINGERPRINT);
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700547 clearCachedConfigForPackage(null);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700548 sharedPrefs
549 .edit()
550 .putString(KEY_FINGERPRINT, Build.FINGERPRINT)
551 .apply();
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700552 }
553 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700554 }
Nathan Harold48ac0972019-03-13 22:33:01 -0700555
556 case EVENT_SUBSCRIPTION_INFO_UPDATED:
557 broadcastConfigChangedIntent(phoneId);
558 break;
Malcolm Chen5ea18532019-10-24 19:55:44 -0700559 case EVENT_MULTI_SIM_CONFIG_CHANGED:
560 onMultiSimConfigChanged();
561 break;
Jayachandran C645ec612020-01-10 10:30:25 -0800562
563 case EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG: {
564 PersistableBundle config =
565 restoreNoSimConfigFromXml(mPlatformCarrierConfigPackage);
566
567 if (config != null) {
568 logd("Loaded no SIM config from XML. package="
569 + mPlatformCarrierConfigPackage);
570 mNoSimConfig = config;
571 sendMessage(
572 obtainMessage(
573 EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE,
574 phoneId, -1));
575 } else {
576 // No cached config, so fetch it from the default app.
577 if (bindToConfigPackage(
578 mPlatformCarrierConfigPackage,
579 phoneId,
580 EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG)) {
581 sendMessageDelayed(
582 obtainMessage(
583 EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT,
584 phoneId, -1), BIND_TIMEOUT_MILLIS);
585 } else {
586 broadcastConfigChangedIntent(phoneId, false);
587 // TODO: We *must* call unbindService even if bindService returns false.
588 // (And possibly if SecurityException was thrown.)
589 loge("binding to default app to fetch no SIM config: "
590 + mPlatformCarrierConfigPackage + " fails");
591 }
592 }
593 break;
594 }
595
596 case EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE: {
597 broadcastConfigChangedIntent(phoneId, false);
598 break;
599 }
600
601 case EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT:
602 case EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT: {
603 loge("Bind/fetch time out for no SIM config from "
604 + mPlatformCarrierConfigPackage);
605 removeMessages(EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT);
606 // If we attempted to bind to the app, but the service connection is null due to
607 // the race condition that clear config event happens before bind/fetch complete
608 // then config was cleared while we were waiting and we should not continue.
609 if (mServiceConnectionForNoSimConfig[phoneId] != null) {
610 // If a ResponseReceiver callback is in the queue when this happens, we will
611 // unbind twice and throw an exception.
612 unbindIfBoundForNoSimConfig(mContext,
613 mServiceConnectionForNoSimConfig[phoneId], phoneId);
614 }
615 broadcastConfigChangedIntent(phoneId, false);
616 break;
617 }
618
619 case EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG: {
620 removeMessages(EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT);
621 final CarrierServiceConnection conn = (CarrierServiceConnection) msg.obj;
622 // If new service connection has been created, unbind.
623 if (mServiceConnectionForNoSimConfig[phoneId] != conn || conn.service == null) {
624 unbindIfBoundForNoSimConfig(mContext, conn, phoneId);
625 break;
626 }
627
628 // ResultReceiver callback will execute in this Handler's thread.
629 final ResultReceiver resultReceiver =
630 new ResultReceiver(this) {
631 @Override
632 public void onReceiveResult(int resultCode, Bundle resultData) {
633 unbindIfBoundForNoSimConfig(mContext, conn, phoneId);
634 // If new service connection has been created, this is stale.
635 if (mServiceConnectionForNoSimConfig[phoneId] != conn) {
636 loge("Received response for stale request.");
637 return;
638 }
639 removeMessages(EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT);
640 if (resultCode == RESULT_ERROR || resultData == null) {
641 // On error, abort config fetching.
642 loge("Failed to get no SIM carrier config");
643 return;
644 }
645 PersistableBundle config =
646 resultData.getParcelable(KEY_CONFIG_BUNDLE);
647 saveNoSimConfigToXml(mPlatformCarrierConfigPackage, config);
648 mNoSimConfig = config;
649 sendMessage(
650 obtainMessage(
651 EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE,
652 phoneId, -1));
653 }
654 };
655 // Now fetch the config asynchronously from the ICarrierService.
656 try {
657 ICarrierService carrierService =
658 ICarrierService.Stub.asInterface(conn.service);
659 carrierService.getCarrierConfig(null, resultReceiver);
660 logdWithLocalLog("Fetch no sim config from default app: "
661 + mPlatformCarrierConfigPackage);
662 } catch (RemoteException e) {
663 loge("Failed to get no sim carrier config from default app: " +
664 mPlatformCarrierConfigPackage + " err: " + e.toString());
665 unbindIfBoundForNoSimConfig(mContext, conn, phoneId);
666 break; // So we don't set a timeout.
667 }
668 sendMessageDelayed(
669 obtainMessage(
670 EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT,
671 phoneId, -1), BIND_TIMEOUT_MILLIS);
672 break;
673 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800674 }
675 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700676 }
677
678 private final Handler mHandler;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800679
680 /**
681 * Constructs a CarrierConfigLoader, registers it as a service, and registers a broadcast
682 * receiver for relevant events.
683 */
Rambo Wang7e3bc122021-03-23 09:24:38 -0700684 @VisibleForTesting
685 /* package */ CarrierConfigLoader(Context context,
686 SubscriptionInfoUpdater subscriptionInfoUpdater, @NonNull Looper looper) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800687 mContext = context;
Meng Wang33ad2bc2017-03-16 20:21:20 -0700688 mPlatformCarrierConfigPackage =
689 mContext.getString(R.string.platform_carrier_config_package);
Rambo Wang7e3bc122021-03-23 09:24:38 -0700690 mHandler = new ConfigHandler(looper);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800691
Nanxi Chen3d670502016-03-17 16:32:09 -0700692 IntentFilter bootFilter = new IntentFilter();
693 bootFilter.addAction(Intent.ACTION_BOOT_COMPLETED);
694 context.registerReceiver(mBootReceiver, bootFilter);
695
Junda Liu8a8a53a2015-05-15 16:19:57 -0700696 // Register for package updates. Update app or uninstall app update will have all 3 intents,
697 // in the order or removed, added, replaced, all with extra_replace set to true.
698 IntentFilter pkgFilter = new IntentFilter();
699 pkgFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
700 pkgFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
701 pkgFilter.addAction(Intent.ACTION_PACKAGE_REPLACED);
702 pkgFilter.addDataScheme("package");
Jordan Liu5ca24762019-07-10 12:51:09 -0700703 context.registerReceiver(mPackageReceiver, pkgFilter);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800704
Malcolm Chen978dda52019-10-08 18:15:25 -0700705 int numPhones = TelephonyManager.from(context).getSupportedModemCount();
Jonathan Basseric31f1f32015-05-12 10:13:03 -0700706 mConfigFromDefaultApp = new PersistableBundle[numPhones];
707 mConfigFromCarrierApp = new PersistableBundle[numPhones];
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100708 mPersistentOverrideConfigs = new PersistableBundle[numPhones];
Hall Liu506724b2018-10-22 18:16:14 -0700709 mOverrideConfigs = new PersistableBundle[numPhones];
Rambo Wang42026112021-04-07 20:57:28 +0000710 mNoSimConfig = new PersistableBundle();
Zach Johnson36d7aab2015-05-22 15:43:00 -0700711 mServiceConnection = new CarrierServiceConnection[numPhones];
Jordan Liu178430d2020-02-10 14:32:15 -0800712 mServiceBound = new boolean[numPhones];
Junda Liu03aad762017-07-21 13:32:17 -0700713 mHasSentConfigChange = new boolean[numPhones];
Sarah Chin807d5c62020-03-30 17:21:09 -0700714 mFromSystemUnlocked = new boolean[numPhones];
Jayachandran C645ec612020-01-10 10:30:25 -0800715 mServiceConnectionForNoSimConfig = new CarrierServiceConnection[numPhones];
716 mServiceBoundForNoSimConfig = new boolean[numPhones];
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800717 // Make this service available through ServiceManager.
Peter Wangc035ce42020-01-08 21:00:22 -0800718 TelephonyFrameworkInitializer
719 .getTelephonyServiceManager().getCarrierConfigServiceRegisterer().register(this);
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800720 logd("CarrierConfigLoader has started");
Rambo Wang7e3bc122021-03-23 09:24:38 -0700721 mSubscriptionInfoUpdater = subscriptionInfoUpdater;
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700722 mHandler.sendEmptyMessage(EVENT_CHECK_SYSTEM_UPDATE);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800723 }
724
725 /**
726 * Initialize the singleton CarrierConfigLoader instance.
727 *
728 * This is only done once, at startup, from {@link com.android.phone.PhoneApp#onCreate}.
729 */
Rambo Wang7e3bc122021-03-23 09:24:38 -0700730 /* package */ static CarrierConfigLoader init(Context context) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800731 synchronized (CarrierConfigLoader.class) {
732 if (sInstance == null) {
Rambo Wang7e3bc122021-03-23 09:24:38 -0700733 sInstance = new CarrierConfigLoader(context,
734 PhoneFactory.getSubscriptionInfoUpdater(), Looper.myLooper());
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800735 } else {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700736 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800737 }
738 return sInstance;
739 }
740 }
741
Rambo Wang7e3bc122021-03-23 09:24:38 -0700742 @VisibleForTesting
743 /* package */ void clearConfigForPhone(int phoneId, boolean fetchNoSimConfig) {
Malcolm Chen5ea18532019-10-24 19:55:44 -0700744 /* Ignore clear configuration request if device is being shutdown. */
745 Phone phone = PhoneFactory.getPhone(phoneId);
746 if (phone != null) {
747 if (phone.isShuttingDown()) {
748 return;
749 }
750 }
751
752 mConfigFromDefaultApp[phoneId] = null;
753 mConfigFromCarrierApp[phoneId] = null;
754 mServiceConnection[phoneId] = null;
755 mHasSentConfigChange[phoneId] = false;
756
Jayachandran C645ec612020-01-10 10:30:25 -0800757 if (fetchNoSimConfig) {
758 // To fetch no SIM config
759 mHandler.sendMessage(
760 mHandler.obtainMessage(
761 EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG, phoneId, -1));
762 }
Malcolm Chen5ea18532019-10-24 19:55:44 -0700763 }
764
Nathan Harold48ac0972019-03-13 22:33:01 -0700765 private void notifySubscriptionInfoUpdater(int phoneId) {
766 String configPackagename;
767 PersistableBundle configToSend;
768 int carrierId = getSpecificCarrierIdForPhoneId(phoneId);
769 // Prefer the carrier privileged carrier app, but if there is not one, use the platform
770 // default carrier app.
771 if (mConfigFromCarrierApp[phoneId] != null) {
772 configPackagename = getCarrierPackageForPhoneId(phoneId);
773 configToSend = mConfigFromCarrierApp[phoneId];
774 } else {
775 configPackagename = mPlatformCarrierConfigPackage;
776 configToSend = mConfigFromDefaultApp[phoneId];
777 }
Nazanin Bakhshi6fcc3342019-09-18 17:54:01 -0700778
Malcolm Chenefafd1c2020-02-20 13:27:08 -0800779 if (configToSend == null) {
Rambo Wang42026112021-04-07 20:57:28 +0000780 configToSend = new PersistableBundle();
Malcolm Chenefafd1c2020-02-20 13:27:08 -0800781 }
782
Nazanin Bakhshi6fcc3342019-09-18 17:54:01 -0700783 // mOverrideConfigs is for testing. And it will override current configs.
784 PersistableBundle config = mOverrideConfigs[phoneId];
785 if (config != null) {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +0100786 configToSend = new PersistableBundle(configToSend);
Nazanin Bakhshi6fcc3342019-09-18 17:54:01 -0700787 configToSend.putAll(config);
788 }
789
Nathan Harold48ac0972019-03-13 22:33:01 -0700790 mSubscriptionInfoUpdater.updateSubscriptionByCarrierConfigAndNotifyComplete(
791 phoneId, configPackagename, configToSend,
792 mHandler.obtainMessage(EVENT_SUBSCRIPTION_INFO_UPDATED, phoneId, -1));
793 }
794
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800795 private void broadcastConfigChangedIntent(int phoneId) {
Amit Mahajanf8088ab2018-03-02 15:24:07 -0800796 broadcastConfigChangedIntent(phoneId, true);
797 }
798
799 private void broadcastConfigChangedIntent(int phoneId, boolean addSubIdExtra) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800800 Intent intent = new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Christopher Tate38f55eb2017-02-14 14:43:49 -0800801 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT |
chen xuf9db49f2019-03-31 23:04:42 -0700802 Intent.FLAG_RECEIVER_FOREGROUND);
Qiongcheng Luoe7de61b2018-08-06 10:20:09 +0800803 if (addSubIdExtra) {
804 int simApplicationState = TelephonyManager.SIM_STATE_UNKNOWN;
805 int[] subIds = SubscriptionManager.getSubId(phoneId);
806 if (!ArrayUtils.isEmpty(subIds)) {
807 TelephonyManager telMgr = TelephonyManager.from(mContext)
808 .createForSubscriptionId(subIds[0]);
809 simApplicationState = telMgr.getSimApplicationState();
810 }
Malcolm Chenf7635ec2020-04-15 15:45:00 -0700811 logd("Broadcast CARRIER_CONFIG_CHANGED for phone " + phoneId
812 + " simApplicationState " + simApplicationState);
Qiongcheng Luoe7de61b2018-08-06 10:20:09 +0800813 // Include subId/carrier id extra only if SIM records are loaded
814 if (simApplicationState != TelephonyManager.SIM_STATE_UNKNOWN
815 && simApplicationState != TelephonyManager.SIM_STATE_NOT_READY) {
816 SubscriptionManager.putPhoneIdAndSubIdExtra(intent, phoneId);
817 intent.putExtra(TelephonyManager.EXTRA_SPECIFIC_CARRIER_ID,
818 getSpecificCarrierIdForPhoneId(phoneId));
819 intent.putExtra(TelephonyManager.EXTRA_CARRIER_ID, getCarrierIdForPhoneId(phoneId));
820 }
Amit Mahajanf8088ab2018-03-02 15:24:07 -0800821 }
Amit Mahajanb33bcda2018-01-24 12:56:44 -0800822 intent.putExtra(CarrierConfigManager.EXTRA_SLOT_INDEX, phoneId);
Sarah Chin807d5c62020-03-30 17:21:09 -0700823 intent.putExtra(CarrierConfigManager.EXTRA_REBROADCAST_ON_UNLOCK,
824 mFromSystemUnlocked[phoneId]);
Meng Wang97a6a462020-01-23 16:22:16 -0800825 mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
Jack Yue9e95be2020-03-22 10:56:06 -0700826 int[] subIds = SubscriptionManager.getSubId(phoneId);
827 if (subIds != null && subIds.length > 0) {
828 logd("Broadcast CARRIER_CONFIG_CHANGED for phone " + phoneId + ", subId=" + subIds[0]);
829 } else {
830 logd("Broadcast CARRIER_CONFIG_CHANGED for phone " + phoneId);
831 }
Junda Liu03aad762017-07-21 13:32:17 -0700832 mHasSentConfigChange[phoneId] = true;
Sarah Chin807d5c62020-03-30 17:21:09 -0700833 mFromSystemUnlocked[phoneId] = false;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800834 }
835
836 /** Binds to the default or carrier config app. */
837 private boolean bindToConfigPackage(String pkgName, int phoneId, int eventId) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800838 logdWithLocalLog("Binding to " + pkgName + " for phone " + phoneId);
Zach Johnsonfca8a8d2015-06-19 18:21:37 -0700839 Intent carrierService = new Intent(CarrierService.CARRIER_SERVICE_INTERFACE);
Zach Johnson36d7aab2015-05-22 15:43:00 -0700840 carrierService.setPackage(pkgName);
Jayachandran C645ec612020-01-10 10:30:25 -0800841 CarrierServiceConnection serviceConnection = new CarrierServiceConnection(
842 phoneId, pkgName, eventId);
843 if (eventId == EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG) {
844 mServiceConnectionForNoSimConfig[phoneId] = serviceConnection;
845 } else {
846 mServiceConnection[phoneId] = serviceConnection;
847 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800848 try {
Jayachandran C645ec612020-01-10 10:30:25 -0800849 if (mContext.bindService(carrierService, serviceConnection,
Jordan Liu178430d2020-02-10 14:32:15 -0800850 Context.BIND_AUTO_CREATE)) {
Jayachandran C645ec612020-01-10 10:30:25 -0800851 if (eventId == EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG) {
852 mServiceBoundForNoSimConfig[phoneId] = true;
853 } else {
854 mServiceBound[phoneId] = true;
855 }
Jordan Liu178430d2020-02-10 14:32:15 -0800856 return true;
857 } else {
858 return false;
859 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800860 } catch (SecurityException ex) {
861 return false;
862 }
863 }
864
Rambo Wang7e3bc122021-03-23 09:24:38 -0700865 @VisibleForTesting
866 /* package */ CarrierIdentifier getCarrierIdentifierForPhoneId(int phoneId) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800867 String mcc = "";
868 String mnc = "";
869 String imsi = "";
870 String gid1 = "";
871 String gid2 = "";
872 String spn = TelephonyManager.from(mContext).getSimOperatorNameForPhone(phoneId);
873 String simOperator = TelephonyManager.from(mContext).getSimOperatorNumericForPhone(phoneId);
chen xu02581692018-11-11 19:03:44 -0800874 int carrierId = TelephonyManager.UNKNOWN_CARRIER_ID;
chen xua31f22b2019-03-06 15:28:50 -0800875 int specificCarrierId = TelephonyManager.UNKNOWN_CARRIER_ID;
Jonathan Basseri1fa437c2015-04-20 11:08:18 -0700876 // A valid simOperator should be 5 or 6 digits, depending on the length of the MNC.
877 if (simOperator != null && simOperator.length() >= 3) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800878 mcc = simOperator.substring(0, 3);
879 mnc = simOperator.substring(3);
880 }
881 Phone phone = PhoneFactory.getPhone(phoneId);
882 if (phone != null) {
883 imsi = phone.getSubscriberId();
884 gid1 = phone.getGroupIdLevel1();
Junda Liu73183532015-05-14 13:55:40 -0700885 gid2 = phone.getGroupIdLevel2();
chen xu02581692018-11-11 19:03:44 -0800886 carrierId = phone.getCarrierId();
chen xua31f22b2019-03-06 15:28:50 -0800887 specificCarrierId = phone.getSpecificCarrierId();
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800888 }
chen xua31f22b2019-03-06 15:28:50 -0800889 return new CarrierIdentifier(mcc, mnc, spn, imsi, gid1, gid2, carrierId, specificCarrierId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800890 }
891
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700892 /** Returns the package name of a priveleged carrier app, or null if there is none. */
Nathan Harold1122e3d2021-01-22 15:45:24 -0800893 @Nullable
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700894 private String getCarrierPackageForPhoneId(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -0700895 List<String> carrierPackageNames;
896 final long token = Binder.clearCallingIdentity();
897 try {
898 carrierPackageNames = TelephonyManager.from(mContext)
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700899 .getCarrierPackageNamesForIntentAndPhone(
Nazanin1adf4562021-03-29 15:35:30 -0700900 new Intent(CarrierService.CARRIER_SERVICE_INTERFACE), phoneId);
901 } finally {
902 Binder.restoreCallingIdentity(token);
903 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700904 if (carrierPackageNames != null && carrierPackageNames.size() > 0) {
905 return carrierPackageNames.get(0);
906 } else {
907 return null;
908 }
909 }
910
911 private String getIccIdForPhoneId(int phoneId) {
912 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
913 return null;
914 }
915 Phone phone = PhoneFactory.getPhone(phoneId);
916 if (phone == null) {
917 return null;
918 }
919 return phone.getIccSerialNumber();
920 }
921
chen xu02581692018-11-11 19:03:44 -0800922 /**
chen xua31f22b2019-03-06 15:28:50 -0800923 * Get the sim specific carrier id {@link TelephonyManager#getSimSpecificCarrierId()}
chen xu02581692018-11-11 19:03:44 -0800924 */
chen xua31f22b2019-03-06 15:28:50 -0800925 private int getSpecificCarrierIdForPhoneId(int phoneId) {
Naina Nalluri86fc7b02018-08-03 10:38:30 -0700926 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
chen xu02581692018-11-11 19:03:44 -0800927 return TelephonyManager.UNKNOWN_CARRIER_ID;
Naina Nalluri86fc7b02018-08-03 10:38:30 -0700928 }
929 Phone phone = PhoneFactory.getPhone(phoneId);
930 if (phone == null) {
chen xu02581692018-11-11 19:03:44 -0800931 return TelephonyManager.UNKNOWN_CARRIER_ID;
Naina Nalluri86fc7b02018-08-03 10:38:30 -0700932 }
chen xua31f22b2019-03-06 15:28:50 -0800933 return phone.getSpecificCarrierId();
chen xu02581692018-11-11 19:03:44 -0800934 }
935
936 /**
937 * Get the sim carrier id {@link TelephonyManager#getSimCarrierId() }
938 */
939 private int getCarrierIdForPhoneId(int phoneId) {
940 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
941 return TelephonyManager.UNKNOWN_CARRIER_ID;
Naina Nalluri86fc7b02018-08-03 10:38:30 -0700942 }
chen xu02581692018-11-11 19:03:44 -0800943 Phone phone = PhoneFactory.getPhone(phoneId);
944 if (phone == null) {
945 return TelephonyManager.UNKNOWN_CARRIER_ID;
946 }
947 return phone.getCarrierId();
Naina Nalluri86fc7b02018-08-03 10:38:30 -0700948 }
949
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700950 /**
951 * Writes a bundle to an XML file.
952 *
chen xu02581692018-11-11 19:03:44 -0800953 * The bundle will be written to a file named after the package name, ICCID and
chen xua31f22b2019-03-06 15:28:50 -0800954 * specific carrier id {@link TelephonyManager#getSimSpecificCarrierId()}. the same carrier
chen xu02581692018-11-11 19:03:44 -0800955 * should have a single copy of XML file named after carrier id. However, it's still possible
956 * that platform doesn't recognize the current sim carrier, we will use iccid + carrierid as
957 * the canonical file name. carrierid can also handle the cases SIM OTA resolves to different
958 * carrier while iccid remains the same.
959 *
960 * The file can be restored later with {@link @restoreConfigFromXml}. The XML output will
961 * include the bundle and the current version of the specified package.
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700962 *
963 * In case of errors or invalid input, no file will be written.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700964 *
Jayachandran C645ec612020-01-10 10:30:25 -0800965 * @param packageName the name of the package from which we fetched this bundle.
966 * @param extraString An extra string to be used in the XML file name.
967 * @param phoneId the phone ID.
968 * @param carrierId contains all carrier-identifying information.
969 * @param config the bundle to be written. Null will be treated as an empty bundle.
970 * @param isNoSimConfig whether this is invoked for noSimConfig or not.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700971 */
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100972 private void saveConfigToXml(String packageName, @NonNull String extraString, int phoneId,
Jayachandran C645ec612020-01-10 10:30:25 -0800973 CarrierIdentifier carrierId, PersistableBundle config, boolean isNoSimConfig) {
974 if (packageName == null) {
975 loge("Cannot save config with null packageName");
Yuchen Dongc15afed2018-04-26 17:05:22 +0800976 return;
977 }
978
Jayachandran C645ec612020-01-10 10:30:25 -0800979 String fileName;
980 if (isNoSimConfig) {
981 fileName = getFilenameForNoSimConfig(packageName);
982 } else {
983 if (SubscriptionManager.getSimStateForSlotIndex(phoneId)
984 != TelephonyManager.SIM_STATE_LOADED) {
985 loge("Skip save config because SIM records are not loaded.");
986 return;
987 }
988
989 final String iccid = getIccIdForPhoneId(phoneId);
990 final int cid = carrierId.getSpecificCarrierId();
991 if (iccid == null) {
992 loge("Cannot save config with null iccid.");
993 return;
994 }
995 fileName = getFilenameForConfig(packageName, extraString, iccid, cid);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700996 }
Jayachandran C645ec612020-01-10 10:30:25 -0800997
Junda Liu02596502016-11-15 13:46:43 -0800998 // b/32668103 Only save to file if config isn't empty.
999 // In case of failure, not caching an empty bundle will
1000 // try loading config again on next power on or sim loaded.
1001 // Downside is for genuinely empty bundle, will bind and load
1002 // on every power on.
1003 if (config == null || config.isEmpty()) {
1004 return;
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001005 }
1006
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001007 final String version = getPackageVersion(packageName);
1008 if (version == null) {
1009 loge("Failed to get package version for: " + packageName);
1010 return;
1011 }
1012
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001013 logdWithLocalLog(
1014 "Save config to xml, packagename: " + packageName + " phoneId: " + phoneId);
chen xudb04c292019-03-26 17:01:15 -07001015
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001016 FileOutputStream outFile = null;
1017 try {
Jayachandran C645ec612020-01-10 10:30:25 -08001018 outFile = new FileOutputStream(new File(mContext.getFilesDir(), fileName));
Meng Wang0f6b2ea2020-01-06 18:31:16 -08001019 config.putString(KEY_VERSION, version);
1020 config.writeToStream(outFile);
1021 outFile.flush();
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001022 outFile.close();
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001023 } catch (IOException e) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001024 loge(e.toString());
1025 }
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001026 }
1027
Rambo Wang7e3bc122021-03-23 09:24:38 -07001028 @VisibleForTesting
1029 /* package */ void saveConfigToXml(String packageName, @NonNull String extraString, int phoneId,
Jayachandran C645ec612020-01-10 10:30:25 -08001030 CarrierIdentifier carrierId, PersistableBundle config) {
1031 saveConfigToXml(packageName, extraString, phoneId, carrierId, config, false);
1032 }
1033
Rambo Wang7e3bc122021-03-23 09:24:38 -07001034 @VisibleForTesting
1035 /* package */ void saveNoSimConfigToXml(String packageName, PersistableBundle config) {
Jayachandran C645ec612020-01-10 10:30:25 -08001036 saveConfigToXml(packageName, "", -1, null, config, true);
1037 }
1038
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001039 /**
1040 * Reads a bundle from an XML file.
1041 *
1042 * This restores a bundle that was written with {@link #saveConfigToXml}. This returns the saved
Yuchen Dongc15afed2018-04-26 17:05:22 +08001043 * config bundle for the given package and phone ID.
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001044 *
1045 * In case of errors, or if the saved config is from a different package version than the
1046 * current version, then null will be returned.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001047 *
Jayachandran C645ec612020-01-10 10:30:25 -08001048 * @param packageName the name of the package from which we fetched this bundle.
1049 * @param extraString An extra string to be used in the XML file name.
1050 * @param phoneId the phone ID.
1051 * @param isNoSimConfig whether this is invoked for noSimConfig or not.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001052 * @return the bundle from the XML file. Returns null if there is no saved config, the saved
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001053 * version does not match, or reading config fails.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001054 */
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001055 private PersistableBundle restoreConfigFromXml(String packageName, @NonNull String extraString,
Jayachandran C645ec612020-01-10 10:30:25 -08001056 int phoneId, boolean isNoSimConfig) {
1057 if (packageName == null) {
1058 loge("Cannot restore config with null packageName");
1059 }
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001060 final String version = getPackageVersion(packageName);
1061 if (version == null) {
1062 loge("Failed to get package version for: " + packageName);
1063 return null;
1064 }
Yuchen Dongc15afed2018-04-26 17:05:22 +08001065
Jayachandran C645ec612020-01-10 10:30:25 -08001066 String fileName;
1067 if (isNoSimConfig) {
1068 fileName = getFilenameForNoSimConfig(packageName);
1069 } else {
1070 if (SubscriptionManager.getSimStateForSlotIndex(phoneId)
1071 != TelephonyManager.SIM_STATE_LOADED) {
1072 loge("Skip restore config because SIM records are not loaded.");
1073 return null;
1074 }
1075
1076 final String iccid = getIccIdForPhoneId(phoneId);
1077 final int cid = getSpecificCarrierIdForPhoneId(phoneId);
1078 if (iccid == null) {
1079 loge("Cannot restore config with null iccid.");
1080 return null;
1081 }
1082 fileName = getFilenameForConfig(packageName, extraString, iccid, cid);
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001083 }
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001084
1085 PersistableBundle restoredBundle = null;
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001086 File file = null;
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001087 FileInputStream inFile = null;
1088 try {
Jayachandran C645ec612020-01-10 10:30:25 -08001089 file = new File(mContext.getFilesDir(),fileName);
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001090 inFile = new FileInputStream(file);
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001091
Meng Wang0f6b2ea2020-01-06 18:31:16 -08001092 restoredBundle = PersistableBundle.readFromStream(inFile);
1093 String savedVersion = restoredBundle.getString(KEY_VERSION);
1094 restoredBundle.remove(KEY_VERSION);
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001095
Meng Wang0f6b2ea2020-01-06 18:31:16 -08001096 if (!version.equals(savedVersion)) {
1097 loge("Saved version mismatch: " + version + " vs " + savedVersion);
1098 restoredBundle = null;
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001099 }
Meng Wang0f6b2ea2020-01-06 18:31:16 -08001100
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001101 inFile.close();
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001102 } catch (FileNotFoundException e) {
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001103 // Missing file is normal occurrence that might occur with a new sim or when restoring
1104 // an override file during boot and should not be treated as an error.
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001105 if (file != null) logd("File not found: " + file.getPath());
1106 } catch (IOException e) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001107 loge(e.toString());
1108 }
1109
1110 return restoredBundle;
1111 }
1112
Jayachandran C645ec612020-01-10 10:30:25 -08001113 private PersistableBundle restoreConfigFromXml(String packageName, @NonNull String extraString,
1114 int phoneId) {
1115 return restoreConfigFromXml(packageName, extraString, phoneId, false);
1116 }
1117
1118 private PersistableBundle restoreNoSimConfigFromXml(String packageName) {
1119 return restoreConfigFromXml(packageName, "", -1, true);
1120 }
1121
Junda Liu8a8a53a2015-05-15 16:19:57 -07001122 /**
Jonathan Basseri7697cae2015-07-06 15:49:23 -07001123 * Clears cached carrier config.
1124 * This deletes all saved XML files associated with the given package name. If packageName is
1125 * null, then it deletes all saved XML files.
1126 *
1127 * @param packageName the name of a carrier package, or null if all cached config should be
1128 * cleared.
1129 * @return true iff one or more files were deleted.
Junda Liu8a8a53a2015-05-15 16:19:57 -07001130 */
Jonathan Basseri7697cae2015-07-06 15:49:23 -07001131 private boolean clearCachedConfigForPackage(final String packageName) {
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001132 File dir = mContext.getFilesDir();
1133 File[] packageFiles = dir.listFiles(new FilenameFilter() {
1134 public boolean accept(File dir, String filename) {
Jonathan Basseri7697cae2015-07-06 15:49:23 -07001135 if (packageName != null) {
1136 return filename.startsWith("carrierconfig-" + packageName + "-");
1137 } else {
1138 return filename.startsWith("carrierconfig-");
1139 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001140 }
1141 });
Junda Liu8a8a53a2015-05-15 16:19:57 -07001142 if (packageFiles == null || packageFiles.length < 1) return false;
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001143 for (File f : packageFiles) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001144 logd("Deleting " + f.getName());
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001145 f.delete();
1146 }
Junda Liu8a8a53a2015-05-15 16:19:57 -07001147 return true;
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001148 }
1149
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001150 /** Builds a canonical file name for a config file. */
Jayachandran C645ec612020-01-10 10:30:25 -08001151 private static String getFilenameForConfig(
1152 @NonNull String packageName, @NonNull String extraString,
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001153 @NonNull String iccid, int cid) {
chen xu02581692018-11-11 19:03:44 -08001154 // the same carrier should have a single copy of XML file named after carrier id.
1155 // However, it's still possible that platform doesn't recognize the current sim carrier,
1156 // we will use iccid + carrierid as the canonical file name. carrierid can also handle the
1157 // cases SIM OTA resolves to different carrier while iccid remains the same.
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001158 return "carrierconfig-" + packageName + extraString + "-" + iccid + "-" + cid + ".xml";
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001159 }
1160
Jayachandran C645ec612020-01-10 10:30:25 -08001161 /** Builds a canonical file name for no SIM config file. */
1162 private String getFilenameForNoSimConfig(@NonNull String packageName) {
1163 return "carrierconfig-" + packageName + "-" + "nosim" + ".xml";
1164 }
1165
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001166 /** Return the current version code of a package, or null if the name is not found. */
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001167 private String getPackageVersion(String packageName) {
1168 try {
1169 PackageInfo info = mContext.getPackageManager().getPackageInfo(packageName, 0);
Dianne Hackbornb76ab202017-11-28 17:44:50 -08001170 return Long.toString(info.getLongVersionCode());
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001171 } catch (PackageManager.NameNotFoundException e) {
1172 return null;
1173 }
1174 }
1175
Jonathan Basseri65273c82017-07-25 15:08:42 -07001176 /**
1177 * Read up to date config.
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001178 *
1179 * This reads config bundles for the given phoneId. That means getting the latest bundle from
1180 * the default app and a privileged carrier app, if present. This will not bind to an app if we
1181 * have a saved config file to use instead.
1182 */
1183 private void updateConfigForPhoneId(int phoneId) {
Jonathan Basseri65273c82017-07-25 15:08:42 -07001184 mHandler.sendMessage(mHandler.obtainMessage(EVENT_DO_FETCH_DEFAULT, phoneId, -1));
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001185 }
1186
Malcolm Chen5ea18532019-10-24 19:55:44 -07001187 private void onMultiSimConfigChanged() {
1188 for (int i = TelephonyManager.from(mContext).getActiveModemCount();
1189 i < mConfigFromDefaultApp.length; i++) {
1190 clearConfigForPhone(i, false);
1191 }
1192 }
1193
Hall Liu506724b2018-10-22 18:16:14 -07001194 @Override
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001195 @NonNull
Rambo Wangd2b004b2021-03-30 10:10:23 -07001196 public PersistableBundle getConfigForSubId(int subscriptionId, String callingPackage) {
1197 return getConfigForSubIdWithFeature(subscriptionId, callingPackage, null);
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001198 }
1199
1200 @Override
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001201 @NonNull
Rambo Wangd2b004b2021-03-30 10:10:23 -07001202 public PersistableBundle getConfigForSubIdWithFeature(int subscriptionId, String callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001203 String callingFeatureId) {
Rambo Wangd2b004b2021-03-30 10:10:23 -07001204 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mContext, subscriptionId,
1205 callingPackage, callingFeatureId, "getCarrierConfig")) {
Rambo Wang42026112021-04-07 20:57:28 +00001206 return new PersistableBundle();
Amit Mahajan40b3fa52015-07-14 10:27:19 -07001207 }
Jeff Davidsona8e4e242018-03-15 17:16:18 -07001208
Rambo Wangd2b004b2021-03-30 10:10:23 -07001209 int phoneId = SubscriptionManager.getPhoneId(subscriptionId);
Jonathan Basseric31f1f32015-05-12 10:13:03 -07001210 PersistableBundle retConfig = CarrierConfigManager.getDefaultConfig();
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001211 if (SubscriptionManager.isValidPhoneId(phoneId)) {
Jonathan Basseric31f1f32015-05-12 10:13:03 -07001212 PersistableBundle config = mConfigFromDefaultApp[phoneId];
yinxuc5e27622017-11-29 15:08:50 -08001213 if (config != null) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001214 retConfig.putAll(config);
yinxuc5e27622017-11-29 15:08:50 -08001215 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001216 config = mConfigFromCarrierApp[phoneId];
yinxuc5e27622017-11-29 15:08:50 -08001217 if (config != null) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001218 retConfig.putAll(config);
yinxuc5e27622017-11-29 15:08:50 -08001219 }
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001220 config = mPersistentOverrideConfigs[phoneId];
1221 if (config != null) {
1222 retConfig.putAll(config);
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001223 }
Hall Liu506724b2018-10-22 18:16:14 -07001224 config = mOverrideConfigs[phoneId];
1225 if (config != null) {
1226 retConfig.putAll(config);
Hall Liu506724b2018-10-22 18:16:14 -07001227 }
Nathan Harold1122e3d2021-01-22 15:45:24 -08001228 // Ignore the theoretical case of the default app not being present since that won't
1229 // work in CarrierConfigLoader today.
1230 final boolean allConfigsApplied =
1231 (mConfigFromCarrierApp[phoneId] != null
1232 || getCarrierPackageForPhoneId(phoneId) == null)
1233 && mConfigFromDefaultApp[phoneId] != null;
1234 retConfig.putBoolean(
1235 CarrierConfigManager.KEY_CARRIER_CONFIG_APPLIED_BOOL, allConfigsApplied);
Jayachandran C645ec612020-01-10 10:30:25 -08001236 } else {
1237 if (mNoSimConfig != null) {
1238 retConfig.putAll(mNoSimConfig);
1239 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001240 }
1241 return retConfig;
1242 }
1243
1244 @Override
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001245 public void overrideConfig(int subscriptionId, @Nullable PersistableBundle overrides,
1246 boolean persistent) {
Hall Liu506724b2018-10-22 18:16:14 -07001247 mContext.enforceCallingOrSelfPermission(
1248 android.Manifest.permission.MODIFY_PHONE_STATE, null);
Brad Ebingerf6281ad2019-04-25 11:02:04 -07001249 //TODO: Also check for SHELL UID to restrict this method to testing only (b/131326259)
Hall Liu506724b2018-10-22 18:16:14 -07001250 int phoneId = SubscriptionManager.getPhoneId(subscriptionId);
1251 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001252 logd("Ignore invalid phoneId: " + phoneId + " for subId: " + subscriptionId);
Rambo Wangd2b004b2021-03-30 10:10:23 -07001253 throw new IllegalArgumentException(
1254 "Invalid phoneId " + phoneId + " for subId " + subscriptionId);
Hall Liu506724b2018-10-22 18:16:14 -07001255 }
Rambo Wang38eb5cd2021-03-29 16:39:14 -07001256 // Post to run on handler thread on which all states should be confined.
1257 mHandler.post(() -> {
1258 overrideConfig(mOverrideConfigs, phoneId, overrides);
Hall Liu506724b2018-10-22 18:16:14 -07001259
Rambo Wang38eb5cd2021-03-29 16:39:14 -07001260 if (persistent) {
1261 overrideConfig(mPersistentOverrideConfigs, phoneId, overrides);
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001262
Rambo Wang38eb5cd2021-03-29 16:39:14 -07001263 if (overrides != null) {
1264 final CarrierIdentifier carrierId = getCarrierIdentifierForPhoneId(phoneId);
1265 saveConfigToXml(mPlatformCarrierConfigPackage, OVERRIDE_PACKAGE_ADDITION,
1266 phoneId,
1267 carrierId, mPersistentOverrideConfigs[phoneId]);
1268 } else {
1269 final String iccid = getIccIdForPhoneId(phoneId);
1270 final int cid = getSpecificCarrierIdForPhoneId(phoneId);
1271 String fileName = getFilenameForConfig(mPlatformCarrierConfigPackage,
1272 OVERRIDE_PACKAGE_ADDITION, iccid, cid);
1273 File fileToDelete = new File(mContext.getFilesDir(), fileName);
1274 fileToDelete.delete();
1275 }
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001276 }
Rambo Wang38eb5cd2021-03-29 16:39:14 -07001277 notifySubscriptionInfoUpdater(phoneId);
1278 });
Hall Liu506724b2018-10-22 18:16:14 -07001279 }
1280
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001281 private void overrideConfig(@NonNull PersistableBundle[] currentOverrides, int phoneId,
1282 @Nullable PersistableBundle overrides) {
1283 if (overrides == null) {
Rambo Wang42026112021-04-07 20:57:28 +00001284 currentOverrides[phoneId] = new PersistableBundle();
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001285 } else if (currentOverrides[phoneId] == null) {
1286 currentOverrides[phoneId] = overrides;
1287 } else {
1288 currentOverrides[phoneId].putAll(overrides);
1289 }
1290 }
1291
Hall Liu506724b2018-10-22 18:16:14 -07001292 @Override
Rambo Wangd2b004b2021-03-30 10:10:23 -07001293 public void notifyConfigChangedForSubId(int subscriptionId) {
Jordan Liud7d57fe2019-04-16 12:29:43 -07001294 // Requires the calling app to be either a carrier privileged app for this subId or
Junda Liufbd2bcb2016-06-15 11:15:42 -07001295 // system privileged app with MODIFY_PHONE_STATE permission.
Rambo Wangd2b004b2021-03-30 10:10:23 -07001296 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mContext,
1297 subscriptionId, "Require carrier privileges or MODIFY_PHONE_STATE permission.");
1298
1299 int phoneId = SubscriptionManager.getPhoneId(subscriptionId);
1300 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
1301 logd("Ignore invalid phoneId: " + phoneId + " for subId: " + subscriptionId);
1302 throw new IllegalArgumentException(
1303 "Invalid phoneId " + phoneId + " for subId " + subscriptionId);
1304 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001305
1306 // This method should block until deleting has completed, so that an error which prevents us
1307 // from clearing the cache is passed back to the carrier app. With the files successfully
1308 // deleted, this can return and we will eventually bind to the carrier app.
Jordan Liud7d57fe2019-04-16 12:29:43 -07001309 String callingPackageName = mContext.getPackageManager().getNameForUid(
1310 Binder.getCallingUid());
Jonathan Basseri7697cae2015-07-06 15:49:23 -07001311 clearCachedConfigForPackage(callingPackageName);
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001312 updateConfigForPhoneId(phoneId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001313 }
1314
1315 @Override
1316 public void updateConfigForPhoneId(int phoneId, String simState) {
Junda Liu1f2b34d2015-06-18 15:26:56 -07001317 mContext.enforceCallingOrSelfPermission(
1318 android.Manifest.permission.MODIFY_PHONE_STATE, null);
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001319 logdWithLocalLog("Update config for phoneId: " + phoneId + " simState: " + simState);
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001320 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
Rambo Wangd2b004b2021-03-30 10:10:23 -07001321 throw new IllegalArgumentException("Invalid phoneId: " + phoneId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001322 }
1323 // requires Java 7 for switch on string.
1324 switch (simState) {
1325 case IccCardConstants.INTENT_VALUE_ICC_ABSENT:
1326 case IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR:
Junda Liu6f5fddf2016-05-24 16:14:41 -07001327 case IccCardConstants.INTENT_VALUE_ICC_CARD_RESTRICTED:
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001328 case IccCardConstants.INTENT_VALUE_ICC_UNKNOWN:
Malcolm Chendb66de12019-12-09 18:57:07 -08001329 case IccCardConstants.INTENT_VALUE_ICC_NOT_READY:
Junda Liu9f2d2712015-05-15 14:22:45 -07001330 mHandler.sendMessage(mHandler.obtainMessage(EVENT_CLEAR_CONFIG, phoneId, -1));
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001331 break;
1332 case IccCardConstants.INTENT_VALUE_ICC_LOADED:
1333 case IccCardConstants.INTENT_VALUE_ICC_LOCKED:
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001334 updateConfigForPhoneId(phoneId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001335 break;
1336 }
1337 }
1338
Junda Liu43d723a2015-05-12 17:23:45 -07001339 @Override
Jeff Sharkeya6fcfed2017-07-20 14:18:39 -06001340 public String getDefaultCarrierServicePackageName() {
Shuo Qianefdb7962019-12-19 15:54:27 -08001341 mContext.enforceCallingOrSelfPermission(
1342 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
1343 "getDefaultCarrierServicePackageName");
Jeff Sharkeya6fcfed2017-07-20 14:18:39 -06001344 return mPlatformCarrierConfigPackage;
1345 }
1346
Rambo Wang7e3bc122021-03-23 09:24:38 -07001347 @VisibleForTesting
1348 /* package */ Handler getHandler() {
1349 return mHandler;
1350 }
1351
1352 @VisibleForTesting
1353 /* package */ PersistableBundle getConfigFromDefaultApp(int phoneId) {
1354 return mConfigFromDefaultApp[phoneId];
1355 }
1356
1357 @VisibleForTesting
1358 /* package */ PersistableBundle getConfigFromCarrierApp(int phoneId) {
1359 return mConfigFromCarrierApp[phoneId];
1360 }
1361
1362 @VisibleForTesting
1363 /* package */ PersistableBundle getNoSimConfig() {
1364 return mNoSimConfig;
1365 }
1366
1367 @VisibleForTesting
1368 /* package */ PersistableBundle getOverrideConfig(int phoneId) {
1369 return mOverrideConfigs[phoneId];
1370 }
1371
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001372 private void unbindIfBound(Context context, CarrierServiceConnection conn,
1373 int phoneId) {
1374 if (mServiceBound[phoneId]) {
1375 mServiceBound[phoneId] = false;
1376 context.unbindService(conn);
1377 }
1378 }
1379
Jayachandran C645ec612020-01-10 10:30:25 -08001380 private void unbindIfBoundForNoSimConfig(Context context, CarrierServiceConnection conn,
1381 int phoneId) {
1382 if (mServiceBoundForNoSimConfig[phoneId]) {
1383 mServiceBoundForNoSimConfig[phoneId] = false;
1384 context.unbindService(conn);
1385 }
1386 }
1387
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001388 /**
Rambo Wang610fdf62021-03-08 21:37:11 -08001389 * Returns a boxed Integer object for phoneId, services as message token to distinguish messages
1390 * with same code when calling {@link Handler#removeMessages(int, Object)}.
1391 */
1392 private Integer getMessageToken(int phoneId) {
1393 if (phoneId < -128 || phoneId > 127) {
1394 throw new IllegalArgumentException("phoneId should be in range [-128, 127], inclusive");
1395 }
1396 // Integer#valueOf guarantees the integers within [-128, 127] are cached and thus memory
1397 // comparison (==) returns true for the same integer.
1398 return Integer.valueOf(phoneId);
1399 }
1400
1401 /**
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001402 * If {@code args} contains {@link #DUMP_ARG_REQUESTING_PACKAGE} and a following package name,
1403 * we'll also call {@link IBinder#dump} on the default carrier service (if bound) and the
1404 * specified carrier service (if bound). Typically, this is done for connectivity bug reports
1405 * where we don't call {@code dumpsys activity service all-non-platform} because that contains
1406 * too much info, but we still want to let carrier apps include their diagnostics.
1407 */
Jeff Sharkeya6fcfed2017-07-20 14:18:39 -06001408 @Override
Junda Liu43d723a2015-05-12 17:23:45 -07001409 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001410 IndentingPrintWriter indentPW = new IndentingPrintWriter(pw, " ");
Junda Liu43d723a2015-05-12 17:23:45 -07001411 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
1412 != PackageManager.PERMISSION_GRANTED) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001413 indentPW.println("Permission Denial: can't dump carrierconfig from from pid="
Junda Liu43d723a2015-05-12 17:23:45 -07001414 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
1415 return;
1416 }
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001417 String requestingPackage = null;
1418 int requestingPackageIndex = ArrayUtils.indexOf(args, DUMP_ARG_REQUESTING_PACKAGE);
1419 if (requestingPackageIndex >= 0 && requestingPackageIndex < args.length - 1
1420 && !TextUtils.isEmpty(args[requestingPackageIndex + 1])) {
1421 requestingPackage = args[requestingPackageIndex + 1];
1422 // Throws a SecurityException if the caller is impersonating another app in an effort to
1423 // dump extra info (which may contain PII the caller doesn't have a right to).
1424 enforceCallerIsSystemOrRequestingPackage(requestingPackage);
1425 }
1426
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001427 indentPW.println("CarrierConfigLoader: " + this);
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001428 for (int i = 0; i < TelephonyManager.from(mContext).getActiveModemCount(); i++) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001429 indentPW.println("Phone Id = " + i);
shuoq26a3a4c2016-12-16 11:06:48 -08001430 // display default values in CarrierConfigManager
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001431 printConfig(CarrierConfigManager.getDefaultConfig(), indentPW,
shuoq26a3a4c2016-12-16 11:06:48 -08001432 "Default Values from CarrierConfigManager");
shuoq26a3a4c2016-12-16 11:06:48 -08001433 // display ConfigFromDefaultApp
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001434 printConfig(mConfigFromDefaultApp[i], indentPW, "mConfigFromDefaultApp");
shuoq26a3a4c2016-12-16 11:06:48 -08001435 // display ConfigFromCarrierApp
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001436 printConfig(mConfigFromCarrierApp[i], indentPW, "mConfigFromCarrierApp");
1437 printConfig(mPersistentOverrideConfigs[i], indentPW, "mPersistentOverrideConfigs");
1438 printConfig(mOverrideConfigs[i], indentPW, "mOverrideConfigs");
shuoq26a3a4c2016-12-16 11:06:48 -08001439 }
chen xudb04c292019-03-26 17:01:15 -07001440
Jayachandran C645ec612020-01-10 10:30:25 -08001441 printConfig(mNoSimConfig, indentPW, "mNoSimConfig");
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001442 indentPW.println("CarrierConfigLoadingLog=");
1443 mCarrierConfigLoadingLog.dump(fd, indentPW, args);
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001444
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001445 if (requestingPackage != null) {
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001446 logd("Including default and requesting package " + requestingPackage
1447 + " carrier services in dump");
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001448 indentPW.println("");
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001449 indentPW.println("Connected services");
1450 dumpCarrierServiceIfBound(fd, indentPW, "Default config package",
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001451 mPlatformCarrierConfigPackage, false /* considerCarrierPrivileges */);
1452 dumpCarrierServiceIfBound(fd, indentPW, "Requesting package", requestingPackage,
1453 true /* considerCarrierPrivileges */);
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001454 }
shuoq26a3a4c2016-12-16 11:06:48 -08001455 }
1456
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001457 private void printConfig(PersistableBundle configApp, IndentingPrintWriter indentPW,
1458 String name) {
1459 indentPW.increaseIndent();
shuoq26a3a4c2016-12-16 11:06:48 -08001460 if (configApp == null) {
shuoq26a3a4c2016-12-16 11:06:48 -08001461 indentPW.println(name + " : null ");
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001462 indentPW.decreaseIndent();
1463 indentPW.println("");
shuoq26a3a4c2016-12-16 11:06:48 -08001464 return;
1465 }
shuoq26a3a4c2016-12-16 11:06:48 -08001466 indentPW.println(name + " : ");
1467 List<String> sortedKeys = new ArrayList<String>(configApp.keySet());
1468 Collections.sort(sortedKeys);
1469 indentPW.increaseIndent();
1470 indentPW.increaseIndent();
1471 for (String key : sortedKeys) {
1472 if (configApp.get(key) != null && configApp.get(key) instanceof Object[]) {
1473 indentPW.println(key + " = " +
1474 Arrays.toString((Object[]) configApp.get(key)));
1475 } else if (configApp.get(key) != null && configApp.get(key) instanceof int[]) {
1476 indentPW.println(key + " = " + Arrays.toString((int[]) configApp.get(key)));
1477 } else {
1478 indentPW.println(key + " = " + configApp.get(key));
1479 }
Junda Liu43d723a2015-05-12 17:23:45 -07001480 }
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001481 indentPW.decreaseIndent();
1482 indentPW.decreaseIndent();
1483 indentPW.decreaseIndent();
1484 indentPW.println("");
Junda Liu43d723a2015-05-12 17:23:45 -07001485 }
1486
Hunter Knepshielde601f432020-02-19 10:16:04 -08001487 /**
1488 * Passes without problem when one of these conditions is true:
1489 * - The caller is a privileged UID (e.g. for dumpstate.cpp generating a bug report, where the
1490 * system knows the true caller plumbed in through the {@link android.os.BugreportManager} API).
1491 * - The caller's UID matches the supplied package.
1492 *
1493 * @throws SecurityException if none of the above conditions are met.
1494 */
1495 private void enforceCallerIsSystemOrRequestingPackage(String requestingPackage)
1496 throws SecurityException {
1497 final int callingUid = Binder.getCallingUid();
1498 if (callingUid == Process.ROOT_UID || callingUid == Process.SYSTEM_UID
1499 || callingUid == Process.SHELL_UID || callingUid == Process.PHONE_UID) {
1500 // Bug reports (dumpstate.cpp) run as SHELL, and let some other privileged UIDs through
1501 // as well.
1502 return;
1503 }
1504 // An app is trying to dump extra detail, block it if they aren't who they claim to be.
1505 AppOpsManager appOps = mContext.getSystemService(AppOpsManager.class);
1506 if (appOps == null) {
1507 throw new SecurityException("No AppOps");
1508 }
1509 // Will throw a SecurityException if the UID and package don't match.
1510 appOps.checkPackage(callingUid, requestingPackage);
1511 }
1512
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001513 /**
1514 * Searches for one or more appropriate {@link CarrierService} instances to dump based on the
1515 * current connections.
1516 *
1517 * @param targetPkgName the target package name to dump carrier services for
1518 * @param considerCarrierPrivileges if true, allow a carrier service to be dumped if it shares
1519 * carrier privileges with {@code targetPkgName};
1520 * otherwise, only dump a carrier service if it is {@code
1521 * targetPkgName}
1522 */
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001523 private void dumpCarrierServiceIfBound(FileDescriptor fd, IndentingPrintWriter indentPW,
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001524 String prefix, String targetPkgName, boolean considerCarrierPrivileges) {
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001525 // Null package is possible if it's early in the boot process, there was a recent crash, we
1526 // loaded the config from XML most recently, or a SIM slot is empty. Carrier apps with
1527 // long-lived bindings should typically get dumped here regardless. Even if an app is being
1528 // used for multiple phoneIds, we assume that it's smart enough to handle that on its own,
1529 // and that in most cases we'd just be dumping duplicate information and bloating a report.
1530 indentPW.increaseIndent();
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001531 indentPW.println(prefix + " : " + targetPkgName);
1532 Set<String> dumpedPkgNames = new ArraySet<>(mServiceConnection.length);
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001533 for (CarrierServiceConnection connection : mServiceConnection) {
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001534 if (connection == null || !SubscriptionManager.isValidPhoneId(connection.phoneId)
1535 || TextUtils.isEmpty(connection.pkgName)) {
1536 continue;
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001537 }
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001538 final String servicePkgName = connection.pkgName;
1539 // Note: we intentionally ignore system components here because we should NOT match the
1540 // shell caller that's typically used for bug reports via non-BugreportManager triggers.
1541 final boolean exactPackageMatch = TextUtils.equals(targetPkgName, servicePkgName);
1542 final boolean carrierPrivilegesMatch =
1543 considerCarrierPrivileges && hasCarrierPrivileges(targetPkgName,
1544 connection.phoneId);
1545 if (!exactPackageMatch && !carrierPrivilegesMatch) continue;
1546 // Make sure this service is actually alive before trying to dump it. We don't pay
1547 // attention to mServiceBound[connection.phoneId] because typically carrier apps will
1548 // request long-lived bindings, and even if we unbind the app, it may still be alive due
1549 // to CarrierServiceBindHelper. Pull it out as a reference so even if it gets set to
1550 // null within the ServiceConnection during unbinding we can avoid an NPE.
1551 final IBinder service = connection.service;
1552 if (service == null || !service.isBinderAlive() || !service.pingBinder()) continue;
1553 // We've got a live service. Last check is just to make sure we don't dump a package
1554 // multiple times.
1555 if (!dumpedPkgNames.add(servicePkgName)) continue;
1556 if (!exactPackageMatch) {
1557 logd(targetPkgName + " has carrier privileges on phoneId " + connection.phoneId
1558 + ", service provided by " + servicePkgName);
1559 indentPW.increaseIndent();
1560 indentPW.println("Proxy : " + servicePkgName);
1561 indentPW.decreaseIndent();
1562 }
1563 // Flush before we let the app output anything to ensure correct ordering of output.
1564 // Internally, Binder#dump calls flush on its printer after finishing so we don't
1565 // need to do anything after.
1566 indentPW.flush();
1567 try {
1568 logd("Dumping " + servicePkgName);
1569 // We don't need to give the carrier service any args.
1570 connection.service.dump(fd, null /* args */);
1571 logd("Done with " + servicePkgName);
1572 } catch (RemoteException e) {
1573 logd("RemoteException from " + servicePkgName, e);
1574 indentPW.increaseIndent();
1575 indentPW.println("RemoteException");
1576 indentPW.increaseIndent();
1577 e.printStackTrace(indentPW);
1578 indentPW.decreaseIndent();
1579 indentPW.decreaseIndent();
1580 // We won't retry this package again because now it's in dumpedPkgNames.
1581 }
1582 indentPW.println("");
Jordan Liu46ed5db2020-01-28 08:55:20 -08001583 }
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001584 if (dumpedPkgNames.isEmpty()) {
1585 indentPW.increaseIndent();
1586 indentPW.println("Not bound");
1587 indentPW.decreaseIndent();
1588 indentPW.println("");
1589 }
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001590 indentPW.decreaseIndent();
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001591 }
1592
1593 private boolean hasCarrierPrivileges(String pkgName, int phoneId) {
1594 int[] subIds = SubscriptionManager.getSubId(phoneId);
1595 if (ArrayUtils.isEmpty(subIds)) {
1596 return false;
1597 }
1598 return TelephonyManager.from(mContext).createForSubscriptionId(
1599 subIds[0]).checkCarrierPrivilegesForPackage(pkgName)
1600 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Jordan Liu46ed5db2020-01-28 08:55:20 -08001601 }
1602
Zach Johnson36d7aab2015-05-22 15:43:00 -07001603 private class CarrierServiceConnection implements ServiceConnection {
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001604 final int phoneId;
1605 final String pkgName;
1606 final int eventId;
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001607 IBinder service;
1608
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001609 CarrierServiceConnection(int phoneId, String pkgName, int eventId) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001610 this.phoneId = phoneId;
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001611 this.pkgName = pkgName;
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001612 this.eventId = eventId;
1613 }
1614
1615 @Override
1616 public void onServiceConnected(ComponentName name, IBinder service) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001617 logd("Connected to config app: " + name.flattenToShortString());
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001618 this.service = service;
1619 mHandler.sendMessage(mHandler.obtainMessage(eventId, phoneId, -1, this));
1620 }
1621
1622 @Override
1623 public void onServiceDisconnected(ComponentName name) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001624 logd("Disconnected from config app: " + name.flattenToShortString());
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001625 this.service = null;
Jordan Liu46ed5db2020-01-28 08:55:20 -08001626 }
1627
1628 @Override
1629 public void onBindingDied(ComponentName name) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001630 logd("Binding died from config app: " + name.flattenToShortString());
Jordan Liu46ed5db2020-01-28 08:55:20 -08001631 this.service = null;
Jordan Liu46ed5db2020-01-28 08:55:20 -08001632 }
1633
1634 @Override
1635 public void onNullBinding(ComponentName name) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001636 logd("Null binding from config app: " + name.flattenToShortString());
Jordan Liu46ed5db2020-01-28 08:55:20 -08001637 this.service = null;
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001638 }
1639 }
1640
1641 private class ConfigLoaderBroadcastReceiver extends BroadcastReceiver {
1642 @Override
1643 public void onReceive(Context context, Intent intent) {
1644 String action = intent.getAction();
Junda Liu8a8a53a2015-05-15 16:19:57 -07001645 boolean replace = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
1646 // If replace is true, only care ACTION_PACKAGE_REPLACED.
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001647 if (replace && !Intent.ACTION_PACKAGE_REPLACED.equals(action)) {
Junda Liu8a8a53a2015-05-15 16:19:57 -07001648 return;
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001649 }
Junda Liu8a8a53a2015-05-15 16:19:57 -07001650
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001651 switch (action) {
Nanxi Chen3d670502016-03-17 16:32:09 -07001652 case Intent.ACTION_BOOT_COMPLETED:
1653 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SYSTEM_UNLOCKED, null));
1654 break;
1655
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001656 case Intent.ACTION_PACKAGE_ADDED:
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001657 case Intent.ACTION_PACKAGE_REMOVED:
Junda Liu8a8a53a2015-05-15 16:19:57 -07001658 case Intent.ACTION_PACKAGE_REPLACED:
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001659 int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
1660 String packageName = mContext.getPackageManager().getNameForUid(uid);
Junda Liu8a8a53a2015-05-15 16:19:57 -07001661 if (packageName != null) {
1662 // We don't have a phoneId for arg1.
1663 mHandler.sendMessage(
1664 mHandler.obtainMessage(EVENT_PACKAGE_CHANGED, packageName));
1665 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001666 break;
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001667 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001668 }
1669 }
1670
Rambo Wangab13e3e2021-04-08 15:01:06 -07001671 // Get readable string for the message code supported in this class.
1672 private static String eventToString(int code) {
1673 switch (code) {
1674 case EVENT_CLEAR_CONFIG:
1675 return "EVENT_CLEAR_CONFIG";
1676 case EVENT_CONNECTED_TO_DEFAULT:
1677 return "EVENT_CONNECTED_TO_DEFAULT";
1678 case EVENT_CONNECTED_TO_CARRIER:
1679 return "EVENT_CONNECTED_TO_CARRIER";
1680 case EVENT_FETCH_DEFAULT_DONE:
1681 return "EVENT_FETCH_DEFAULT_DONE";
1682 case EVENT_FETCH_CARRIER_DONE:
1683 return "EVENT_FETCH_CARRIER_DONE";
1684 case EVENT_DO_FETCH_DEFAULT:
1685 return "EVENT_DO_FETCH_DEFAULT";
1686 case EVENT_DO_FETCH_CARRIER:
1687 return "EVENT_DO_FETCH_CARRIER";
1688 case EVENT_PACKAGE_CHANGED:
1689 return "EVENT_PACKAGE_CHANGED";
1690 case EVENT_BIND_DEFAULT_TIMEOUT:
1691 return "EVENT_BIND_DEFAULT_TIMEOUT";
1692 case EVENT_BIND_CARRIER_TIMEOUT:
1693 return "EVENT_BIND_CARRIER_TIMEOUT";
1694 case EVENT_CHECK_SYSTEM_UPDATE:
1695 return "EVENT_CHECK_SYSTEM_UPDATE";
1696 case EVENT_SYSTEM_UNLOCKED:
1697 return "EVENT_SYSTEM_UNLOCKED";
1698 case EVENT_FETCH_DEFAULT_TIMEOUT:
1699 return "EVENT_FETCH_DEFAULT_TIMEOUT";
1700 case EVENT_FETCH_CARRIER_TIMEOUT:
1701 return "EVENT_FETCH_CARRIER_TIMEOUT";
1702 case EVENT_SUBSCRIPTION_INFO_UPDATED:
1703 return "EVENT_SUBSCRIPTION_INFO_UPDATED";
1704 case EVENT_MULTI_SIM_CONFIG_CHANGED:
1705 return "EVENT_MULTI_SIM_CONFIG_CHANGED";
1706 case EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG:
1707 return "EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG";
1708 case EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE:
1709 return "EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE";
1710 case EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG:
1711 return "EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG";
1712 case EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT:
1713 return "EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT";
1714 case EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT:
1715 return "EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT";
1716 default:
1717 return "UNKNOWN(" + code + ")";
1718 }
1719 }
1720
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001721 private void logd(String msg) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001722 Log.d(LOG_TAG, msg);
1723 }
1724
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001725 private void logd(String msg, Throwable tr) {
1726 Log.d(LOG_TAG, msg, tr);
1727 }
1728
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001729 private void logdWithLocalLog(String msg) {
chen xudb04c292019-03-26 17:01:15 -07001730 Log.d(LOG_TAG, msg);
1731 mCarrierConfigLoadingLog.log(msg);
1732 }
1733
1734 private void loge(String msg) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001735 Log.e(LOG_TAG, msg);
chen xudb04c292019-03-26 17:01:15 -07001736 mCarrierConfigLoadingLog.log(msg);
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001737 }
1738}