blob: d3792f1a5a2f5ff12100985dd4975e59a854aa22 [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;
Sarah Chin807d5c62020-03-30 17:21:09 -0700110 // Whether we have sent config change broadcast for each phone id.
Junda Liu03aad762017-07-21 13:32:17 -0700111 private boolean[] mHasSentConfigChange;
Sarah Chin807d5c62020-03-30 17:21:09 -0700112 // Whether the broadcast was sent from EVENT_SYSTEM_UNLOCKED, to track rebroadcasts
113 private boolean[] mFromSystemUnlocked;
Nathan Harold48ac0972019-03-13 22:33:01 -0700114 // SubscriptionInfoUpdater
115 private final SubscriptionInfoUpdater mSubscriptionInfoUpdater;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800116
Nanxi Chen3d670502016-03-17 16:32:09 -0700117 // Broadcast receiver for Boot intents, register intent filter in construtor.
118 private final BroadcastReceiver mBootReceiver = new ConfigLoaderBroadcastReceiver();
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800119 // Broadcast receiver for SIM and pkg intents, register intent filter in constructor.
Nanxi Chen3d670502016-03-17 16:32:09 -0700120 private final BroadcastReceiver mPackageReceiver = new ConfigLoaderBroadcastReceiver();
Jack Yu67663de2019-10-17 15:19:48 -0700121 private final LocalLog mCarrierConfigLoadingLog = new LocalLog(100);
chen xudb04c292019-03-26 17:01:15 -0700122
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800123
124 // Message codes; see mHandler below.
125 // Request from SubscriptionInfoUpdater when SIM becomes absent or error.
126 private static final int EVENT_CLEAR_CONFIG = 0;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800127 // Has connected to default app.
128 private static final int EVENT_CONNECTED_TO_DEFAULT = 3;
129 // Has connected to carrier app.
130 private static final int EVENT_CONNECTED_TO_CARRIER = 4;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700131 // Config has been loaded from default app (or cache).
132 private static final int EVENT_FETCH_DEFAULT_DONE = 5;
133 // Config has been loaded from carrier app (or cache).
134 private static final int EVENT_FETCH_CARRIER_DONE = 6;
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700135 // Attempt to fetch from default app or read from XML.
Jonathan Basseri65273c82017-07-25 15:08:42 -0700136 private static final int EVENT_DO_FETCH_DEFAULT = 7;
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700137 // Attempt to fetch from carrier app or read from XML.
Jonathan Basseri65273c82017-07-25 15:08:42 -0700138 private static final int EVENT_DO_FETCH_CARRIER = 8;
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700139 // A package has been installed, uninstalled, or updated.
140 private static final int EVENT_PACKAGE_CHANGED = 9;
Jonathan Basseri930701e2015-06-11 20:56:43 -0700141 // Bind timed out for the default app.
142 private static final int EVENT_BIND_DEFAULT_TIMEOUT = 10;
143 // Bind timed out for a carrier app.
144 private static final int EVENT_BIND_CARRIER_TIMEOUT = 11;
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700145 // Check if the system fingerprint has changed.
146 private static final int EVENT_CHECK_SYSTEM_UPDATE = 12;
Nanxi Chen3d670502016-03-17 16:32:09 -0700147 // Rerun carrier config binding after system is unlocked.
148 private static final int EVENT_SYSTEM_UNLOCKED = 13;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700149 // Fetching config timed out from the default app.
150 private static final int EVENT_FETCH_DEFAULT_TIMEOUT = 14;
151 // Fetching config timed out from a carrier app.
152 private static final int EVENT_FETCH_CARRIER_TIMEOUT = 15;
Nathan Harold48ac0972019-03-13 22:33:01 -0700153 // SubscriptionInfoUpdater has finished updating the sub for the carrier config.
154 private static final int EVENT_SUBSCRIPTION_INFO_UPDATED = 16;
Malcolm Chen5ea18532019-10-24 19:55:44 -0700155 // Multi-SIM config changed.
156 private static final int EVENT_MULTI_SIM_CONFIG_CHANGED = 17;
Jayachandran C645ec612020-01-10 10:30:25 -0800157 // Attempt to fetch from default app or read from XML for no SIM case.
158 private static final int EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG = 18;
159 // No SIM config has been loaded from default app (or cache).
160 private static final int EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE = 19;
161 // Has connected to default app for no SIM config.
162 private static final int EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG = 20;
163 // Bind timed out for the default app when trying to fetch no SIM config.
164 private static final int EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT = 21;
165 // Fetching config timed out from the default app for no SIM config.
166 private static final int EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT = 22;
Rambo Wangab13e3e2021-04-08 15:01:06 -0700167 // NOTE: any new EVENT_* values must be added to method eventToString().
Jonathan Basseri930701e2015-06-11 20:56:43 -0700168
Junda Liu6cb45002016-03-22 17:18:20 -0700169 private static final int BIND_TIMEOUT_MILLIS = 30000;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800170
Meng Wang0f6b2ea2020-01-06 18:31:16 -0800171 // Keys used for saving and restoring config bundle from file.
172 private static final String KEY_VERSION = "__carrier_config_package_version__";
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800173
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100174 private static final String OVERRIDE_PACKAGE_ADDITION = "-override";
175
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700176 // SharedPreferences key for last known build fingerprint.
177 private static final String KEY_FINGERPRINT = "build_fingerprint";
178
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -0800179 // Argument for #dump that indicates we should also call the default and specified carrier
180 // service's #dump method. In multi-SIM devices, it's possible that carrier A is on SIM 1 and
181 // carrier B is on SIM 2, in which case we should not dump carrier B's service when carrier A
182 // requested the dump.
183 private static final String DUMP_ARG_REQUESTING_PACKAGE = "--requesting-package";
184
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800185 // Handler to process various events.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700186 //
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700187 // For each phoneId, the event sequence should be:
Jonathan Basseri65273c82017-07-25 15:08:42 -0700188 // fetch default, connected to default, fetch default (async), fetch default done,
189 // fetch carrier, connected to carrier, fetch carrier (async), fetch carrier done.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700190 //
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700191 // If there is a saved config file for either the default app or the carrier app, we skip
192 // binding to the app and go straight from fetch to loaded.
193 //
194 // At any time, at most one connection is active. If events are not in this order, previous
195 // connection will be unbound, so only latest event takes effect.
196 //
197 // We broadcast ACTION_CARRIER_CONFIG_CHANGED after:
198 // 1. loading from carrier app (even if read from a file)
199 // 2. loading from default app if there is no carrier app (even if read from a file)
200 // 3. clearing config (e.g. due to sim removal)
201 // 4. encountering bind or IPC error
Jonathan Basseri65273c82017-07-25 15:08:42 -0700202 private class ConfigHandler extends Handler {
Rambo Wang7e3bc122021-03-23 09:24:38 -0700203 ConfigHandler(@NonNull Looper looper) {
204 super(looper);
205 }
206
Jonathan Basseri65273c82017-07-25 15:08:42 -0700207 @Override
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800208 public void handleMessage(Message msg) {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700209 final int phoneId = msg.arg1;
Rambo Wangab13e3e2021-04-08 15:01:06 -0700210 logdWithLocalLog("mHandler: " + eventToString(msg.what) + " phoneId: " + phoneId);
Malcolm Chen5ea18532019-10-24 19:55:44 -0700211 if (!SubscriptionManager.isValidPhoneId(phoneId)
212 && msg.what != EVENT_MULTI_SIM_CONFIG_CHANGED) {
213 return;
214 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800215 switch (msg.what) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800216 case EVENT_CLEAR_CONFIG: {
Malcolm Chen5ea18532019-10-24 19:55:44 -0700217 clearConfigForPhone(phoneId, true);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800218 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700219 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700220
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800221 case EVENT_SYSTEM_UNLOCKED: {
Malcolm Chen5ea18532019-10-24 19:55:44 -0700222 for (int i = 0; i < TelephonyManager.from(mContext).getActiveModemCount();
223 ++i) {
Sarah Chin807d5c62020-03-30 17:21:09 -0700224 // When the user unlocks the device, send the broadcast again (with a
225 // rebroadcast extra) if we have sent it before unlock. This will avoid
226 // trying to load the carrier config when the SIM is still loading when the
227 // unlock happens.
Junda Liu03aad762017-07-21 13:32:17 -0700228 if (mHasSentConfigChange[i]) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800229 logdWithLocalLog("System unlocked");
Sarah Chin807d5c62020-03-30 17:21:09 -0700230 mFromSystemUnlocked[i] = true;
Junda Liu03aad762017-07-21 13:32:17 -0700231 updateConfigForPhoneId(i);
232 }
Nanxi Chen3d670502016-03-17 16:32:09 -0700233 }
234 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700235 }
Nanxi Chen3d670502016-03-17 16:32:09 -0700236
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800237 case EVENT_PACKAGE_CHANGED: {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700238 final String carrierPackageName = (String) msg.obj;
239 // Only update if there are cached config removed to avoid updating config for
240 // unrelated packages.
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700241 if (clearCachedConfigForPackage(carrierPackageName)) {
Malcolm Chen5ea18532019-10-24 19:55:44 -0700242 int numPhones = TelephonyManager.from(mContext).getActiveModemCount();
Junda Liu8a8a53a2015-05-15 16:19:57 -0700243 for (int i = 0; i < numPhones; ++i) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800244 logdWithLocalLog("Package changed: " + carrierPackageName
Jack Yu67663de2019-10-17 15:19:48 -0700245 + ", phone=" + i);
Junda Liu8a8a53a2015-05-15 16:19:57 -0700246 updateConfigForPhoneId(i);
247 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700248 }
249 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700250 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700251
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800252 case EVENT_DO_FETCH_DEFAULT: {
Rambo Wang9bc7d362021-03-09 09:10:58 -0800253 // Clear in-memory cache for carrier app config, so when carrier app gets
254 // uninstalled, no stale config is left.
255 if (mConfigFromCarrierApp[phoneId] != null
256 && getCarrierPackageForPhoneId(phoneId) == null) {
257 mConfigFromCarrierApp[phoneId] = null;
258 }
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100259 // Restore persistent override values.
260 PersistableBundle config = restoreConfigFromXml(
261 mPlatformCarrierConfigPackage, OVERRIDE_PACKAGE_ADDITION, phoneId);
262 if (config != null) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800263 logd("Loaded persistent override config from XML. package="
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100264 + mPlatformCarrierConfigPackage
265 + " phoneId=" + phoneId);
266 mPersistentOverrideConfigs[phoneId] = config;
267 }
268
269 config = restoreConfigFromXml(mPlatformCarrierConfigPackage, "", phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700270 if (config != null) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800271 logd(
Jonathan Basseri65273c82017-07-25 15:08:42 -0700272 "Loaded config from XML. package="
273 + mPlatformCarrierConfigPackage
274 + " phoneId="
275 + phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700276 mConfigFromDefaultApp[phoneId] = config;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700277 Message newMsg = obtainMessage(EVENT_FETCH_DEFAULT_DONE, phoneId, -1);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700278 newMsg.getData().putBoolean("loaded_from_xml", true);
279 mHandler.sendMessage(newMsg);
280 } else {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700281 // No cached config, so fetch it from the default app.
282 if (bindToConfigPackage(
283 mPlatformCarrierConfigPackage,
284 phoneId,
285 EVENT_CONNECTED_TO_DEFAULT)) {
286 sendMessageDelayed(
Rambo Wang610fdf62021-03-08 21:37:11 -0800287 obtainMessage(EVENT_BIND_DEFAULT_TIMEOUT, phoneId, -1 /*arg2*/,
288 getMessageToken(phoneId)),
Jonathan Basseri930701e2015-06-11 20:56:43 -0700289 BIND_TIMEOUT_MILLIS);
290 } else {
Nathan Harold1122e3d2021-01-22 15:45:24 -0800291 // Put a stub bundle in place so that the rest of the logic continues
292 // smoothly.
Rambo Wang42026112021-04-07 20:57:28 +0000293 mConfigFromDefaultApp[phoneId] = new PersistableBundle();
Jonathan Basseri65273c82017-07-25 15:08:42 -0700294 // Send broadcast if bind fails.
Nathan Harold48ac0972019-03-13 22:33:01 -0700295 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700296 // TODO: We *must* call unbindService even if bindService returns false.
297 // (And possibly if SecurityException was thrown.)
chen xudb04c292019-03-26 17:01:15 -0700298 loge("binding to default app: "
299 + mPlatformCarrierConfigPackage + " fails");
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700300 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800301 }
302 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700303 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800304
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800305 case EVENT_CONNECTED_TO_DEFAULT: {
Rambo Wang610fdf62021-03-08 21:37:11 -0800306 removeMessages(EVENT_BIND_DEFAULT_TIMEOUT, getMessageToken(phoneId));
Jonathan Basseri65273c82017-07-25 15:08:42 -0700307 final CarrierServiceConnection conn = (CarrierServiceConnection) msg.obj;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800308 // If new service connection has been created, unbind.
309 if (mServiceConnection[phoneId] != conn || conn.service == null) {
Rambo Wangc5901222021-09-17 13:18:35 -0700310 unbindIfBound(mContext, conn);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800311 break;
312 }
chen xu02581692018-11-11 19:03:44 -0800313 final CarrierIdentifier carrierId = getCarrierIdentifierForPhoneId(phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700314 // ResultReceiver callback will execute in this Handler's thread.
315 final ResultReceiver resultReceiver =
316 new ResultReceiver(this) {
317 @Override
318 public void onReceiveResult(int resultCode, Bundle resultData) {
Rambo Wangc5901222021-09-17 13:18:35 -0700319 unbindIfBound(mContext, conn);
Rambo Wanga9d27a52021-04-09 16:17:33 -0700320 removeMessages(EVENT_FETCH_DEFAULT_TIMEOUT,
321 getMessageToken(phoneId));
Jonathan Basseri65273c82017-07-25 15:08:42 -0700322 // If new service connection has been created, this is stale.
323 if (mServiceConnection[phoneId] != conn) {
324 loge("Received response for stale request.");
325 return;
326 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700327 if (resultCode == RESULT_ERROR || resultData == null) {
328 // On error, abort config fetching.
329 loge("Failed to get carrier config");
Nathan Harold48ac0972019-03-13 22:33:01 -0700330 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700331 return;
332 }
333 PersistableBundle config =
334 resultData.getParcelable(KEY_CONFIG_BUNDLE);
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100335 saveConfigToXml(mPlatformCarrierConfigPackage, "", phoneId,
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800336 carrierId, config);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700337 mConfigFromDefaultApp[phoneId] = config;
338 sendMessage(
339 obtainMessage(
340 EVENT_FETCH_DEFAULT_DONE, phoneId, -1));
341 }
342 };
343 // Now fetch the config asynchronously from the ICarrierService.
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800344 try {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700345 ICarrierService carrierService =
346 ICarrierService.Stub.asInterface(conn.service);
347 carrierService.getCarrierConfig(carrierId, resultReceiver);
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800348 logdWithLocalLog("Fetch config for default app: "
chen xudb04c292019-03-26 17:01:15 -0700349 + mPlatformCarrierConfigPackage
350 + " carrierid: " + carrierId.toString());
Jonathan Basseri65273c82017-07-25 15:08:42 -0700351 } catch (RemoteException e) {
chen xudb04c292019-03-26 17:01:15 -0700352 loge("Failed to get carrier config from default app: " +
353 mPlatformCarrierConfigPackage + " err: " + e.toString());
Rambo Wangc5901222021-09-17 13:18:35 -0700354 unbindIfBound(mContext, conn);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700355 break; // So we don't set a timeout.
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800356 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700357 sendMessageDelayed(
Rambo Wang610fdf62021-03-08 21:37:11 -0800358 obtainMessage(EVENT_FETCH_DEFAULT_TIMEOUT, phoneId, -1 /*arg2*/,
359 getMessageToken(phoneId)),
Jonathan Basseri65273c82017-07-25 15:08:42 -0700360 BIND_TIMEOUT_MILLIS);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800361 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700362 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800363
Jonathan Basseri930701e2015-06-11 20:56:43 -0700364 case EVENT_BIND_DEFAULT_TIMEOUT:
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800365 case EVENT_FETCH_DEFAULT_TIMEOUT: {
366 loge("Bind/fetch time out from " + mPlatformCarrierConfigPackage);
Rambo Wang610fdf62021-03-08 21:37:11 -0800367 removeMessages(EVENT_FETCH_DEFAULT_TIMEOUT, getMessageToken(phoneId));
chen xuf60b3162019-05-01 21:31:05 -0700368 // If we attempted to bind to the app, but the service connection is null due to
369 // the race condition that clear config event happens before bind/fetch complete
370 // then config was cleared while we were waiting and we should not continue.
371 if (mServiceConnection[phoneId] != null) {
372 // If a ResponseReceiver callback is in the queue when this happens, we will
373 // unbind twice and throw an exception.
Rambo Wangc5901222021-09-17 13:18:35 -0700374 unbindIfBound(mContext, mServiceConnection[phoneId]);
chen xuf60b3162019-05-01 21:31:05 -0700375 broadcastConfigChangedIntent(phoneId);
376 }
Nathan Harold1122e3d2021-01-22 15:45:24 -0800377 // Put a stub bundle in place so that the rest of the logic continues smoothly.
Rambo Wang42026112021-04-07 20:57:28 +0000378 mConfigFromDefaultApp[phoneId] = new PersistableBundle();
Nathan Harold48ac0972019-03-13 22:33:01 -0700379 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri930701e2015-06-11 20:56:43 -0700380 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700381 }
Jonathan Basseri930701e2015-06-11 20:56:43 -0700382
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800383 case EVENT_FETCH_DEFAULT_DONE: {
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700384 // If we attempted to bind to the app, but the service connection is null, then
385 // config was cleared while we were waiting and we should not continue.
386 if (!msg.getData().getBoolean("loaded_from_xml", false)
387 && mServiceConnection[phoneId] == null) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800388 break;
389 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700390 final String carrierPackageName = getCarrierPackageForPhoneId(phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700391 if (carrierPackageName != null) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800392 logd("Found carrier config app: " + carrierPackageName);
Jordan Liu38a614c2019-03-20 15:01:17 -0700393 sendMessage(obtainMessage(EVENT_DO_FETCH_CARRIER, phoneId, -1));
Jonathan Basserib919e932015-05-27 16:53:08 +0000394 } else {
Nathan Harold48ac0972019-03-13 22:33:01 -0700395 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri4ae2e7c2015-05-15 00:19:46 -0700396 }
397 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700398 }
Jonathan Basseri4ae2e7c2015-05-15 00:19:46 -0700399
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800400 case EVENT_DO_FETCH_CARRIER: {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700401 final String carrierPackageName = getCarrierPackageForPhoneId(phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700402 final PersistableBundle config =
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100403 restoreConfigFromXml(carrierPackageName, "", phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700404 if (config != null) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800405 logd(
Jonathan Basseri65273c82017-07-25 15:08:42 -0700406 "Loaded config from XML. package="
407 + carrierPackageName
408 + " phoneId="
409 + phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700410 mConfigFromCarrierApp[phoneId] = config;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700411 Message newMsg = obtainMessage(EVENT_FETCH_CARRIER_DONE, phoneId, -1);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700412 newMsg.getData().putBoolean("loaded_from_xml", true);
413 sendMessage(newMsg);
414 } else {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700415 // No cached config, so fetch it from a carrier app.
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800416 if (carrierPackageName != null && bindToConfigPackage(carrierPackageName,
417 phoneId, EVENT_CONNECTED_TO_CARRIER)) {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700418 sendMessageDelayed(
Rambo Wang610fdf62021-03-08 21:37:11 -0800419 obtainMessage(EVENT_BIND_CARRIER_TIMEOUT, phoneId, -1 /*arg2*/,
420 getMessageToken(phoneId)),
Jonathan Basseri930701e2015-06-11 20:56:43 -0700421 BIND_TIMEOUT_MILLIS);
422 } else {
Nathan Harold1122e3d2021-01-22 15:45:24 -0800423 // Put a stub bundle in place so that the rest of the logic continues
424 // smoothly.
Rambo Wang42026112021-04-07 20:57:28 +0000425 mConfigFromCarrierApp[phoneId] = new PersistableBundle();
Jonathan Basseri65273c82017-07-25 15:08:42 -0700426 // Send broadcast if bind fails.
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700427 broadcastConfigChangedIntent(phoneId);
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800428 loge("Bind to carrier app: " + carrierPackageName + " fails");
Nathan Harold48ac0972019-03-13 22:33:01 -0700429 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700430 }
431 }
432 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700433 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700434
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800435 case EVENT_CONNECTED_TO_CARRIER: {
Rambo Wang610fdf62021-03-08 21:37:11 -0800436 removeMessages(EVENT_BIND_CARRIER_TIMEOUT, getMessageToken(phoneId));
Jonathan Basseri65273c82017-07-25 15:08:42 -0700437 final CarrierServiceConnection conn = (CarrierServiceConnection) msg.obj;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800438 // If new service connection has been created, unbind.
Jonathan Basseri65273c82017-07-25 15:08:42 -0700439 if (mServiceConnection[phoneId] != conn || conn.service == null) {
Rambo Wangc5901222021-09-17 13:18:35 -0700440 unbindIfBound(mContext, conn);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800441 break;
442 }
chen xu02581692018-11-11 19:03:44 -0800443 final CarrierIdentifier carrierId = getCarrierIdentifierForPhoneId(phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700444 // ResultReceiver callback will execute in this Handler's thread.
445 final ResultReceiver resultReceiver =
446 new ResultReceiver(this) {
447 @Override
448 public void onReceiveResult(int resultCode, Bundle resultData) {
Rambo Wangc5901222021-09-17 13:18:35 -0700449 unbindIfBound(mContext, conn);
Rambo Wanga9d27a52021-04-09 16:17:33 -0700450 removeMessages(EVENT_FETCH_CARRIER_TIMEOUT,
451 getMessageToken(phoneId));
Jonathan Basseri65273c82017-07-25 15:08:42 -0700452 // If new service connection has been created, this is stale.
453 if (mServiceConnection[phoneId] != conn) {
454 loge("Received response for stale request.");
455 return;
456 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700457 if (resultCode == RESULT_ERROR || resultData == null) {
458 // On error, abort config fetching.
chen xudb04c292019-03-26 17:01:15 -0700459 loge("Failed to get carrier config from carrier app: "
460 + getCarrierPackageForPhoneId(phoneId));
Jonathan Basseri65273c82017-07-25 15:08:42 -0700461 broadcastConfigChangedIntent(phoneId);
Nathan Harold48ac0972019-03-13 22:33:01 -0700462 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700463 return;
464 }
465 PersistableBundle config =
466 resultData.getParcelable(KEY_CONFIG_BUNDLE);
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100467 saveConfigToXml(getCarrierPackageForPhoneId(phoneId), "",
468 phoneId, carrierId, config);
Amit Mahajan304e92b2021-04-08 14:03:30 -0700469 if (config != null) {
470 mConfigFromCarrierApp[phoneId] = config;
471 } else {
472 logdWithLocalLog("Config from carrier app is null "
473 + "for phoneId " + phoneId);
474 // Put a stub bundle in place so that the rest of the logic
475 // continues smoothly.
476 mConfigFromCarrierApp[phoneId] = new PersistableBundle();
477 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700478 sendMessage(
479 obtainMessage(
480 EVENT_FETCH_CARRIER_DONE, phoneId, -1));
481 }
482 };
483 // Now fetch the config asynchronously from the ICarrierService.
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800484 try {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700485 ICarrierService carrierService =
486 ICarrierService.Stub.asInterface(conn.service);
487 carrierService.getCarrierConfig(carrierId, resultReceiver);
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800488 logdWithLocalLog("Fetch config for carrier app: "
chen xudb04c292019-03-26 17:01:15 -0700489 + getCarrierPackageForPhoneId(phoneId)
490 + " carrierid: " + carrierId.toString());
Jonathan Basseri65273c82017-07-25 15:08:42 -0700491 } catch (RemoteException e) {
492 loge("Failed to get carrier config: " + e.toString());
Rambo Wangc5901222021-09-17 13:18:35 -0700493 unbindIfBound(mContext, conn);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700494 break; // So we don't set a timeout.
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800495 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700496 sendMessageDelayed(
Rambo Wang610fdf62021-03-08 21:37:11 -0800497 obtainMessage(EVENT_FETCH_CARRIER_TIMEOUT, phoneId, -1 /*arg2*/,
498 getMessageToken(phoneId)),
Jonathan Basseri65273c82017-07-25 15:08:42 -0700499 BIND_TIMEOUT_MILLIS);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800500 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700501 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800502
Jonathan Basseri930701e2015-06-11 20:56:43 -0700503 case EVENT_BIND_CARRIER_TIMEOUT:
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800504 case EVENT_FETCH_CARRIER_TIMEOUT: {
Nathan Harold1122e3d2021-01-22 15:45:24 -0800505 loge("Bind/fetch from carrier app timeout, package="
506 + getCarrierPackageForPhoneId(phoneId));
Rambo Wang610fdf62021-03-08 21:37:11 -0800507 removeMessages(EVENT_FETCH_CARRIER_TIMEOUT, getMessageToken(phoneId));
chen xuf60b3162019-05-01 21:31:05 -0700508 // If we attempted to bind to the app, but the service connection is null due to
509 // the race condition that clear config event happens before bind/fetch complete
510 // then config was cleared while we were waiting and we should not continue.
511 if (mServiceConnection[phoneId] != null) {
512 // If a ResponseReceiver callback is in the queue when this happens, we will
513 // unbind twice and throw an exception.
Rambo Wangc5901222021-09-17 13:18:35 -0700514 unbindIfBound(mContext, mServiceConnection[phoneId]);
chen xuf60b3162019-05-01 21:31:05 -0700515 broadcastConfigChangedIntent(phoneId);
516 }
Nathan Harold1122e3d2021-01-22 15:45:24 -0800517 // Put a stub bundle in place so that the rest of the logic continues smoothly.
Rambo Wang42026112021-04-07 20:57:28 +0000518 mConfigFromCarrierApp[phoneId] = new PersistableBundle();
Nathan Harold48ac0972019-03-13 22:33:01 -0700519 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri930701e2015-06-11 20:56:43 -0700520 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700521 }
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800522 case EVENT_FETCH_CARRIER_DONE: {
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700523 // If we attempted to bind to the app, but the service connection is null, then
524 // config was cleared while we were waiting and we should not continue.
525 if (!msg.getData().getBoolean("loaded_from_xml", false)
526 && mServiceConnection[phoneId] == null) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800527 break;
528 }
Nathan Harold48ac0972019-03-13 22:33:01 -0700529 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800530 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700531 }
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700532
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800533 case EVENT_CHECK_SYSTEM_UPDATE: {
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700534 SharedPreferences sharedPrefs =
535 PreferenceManager.getDefaultSharedPreferences(mContext);
536 final String lastFingerprint = sharedPrefs.getString(KEY_FINGERPRINT, null);
537 if (!Build.FINGERPRINT.equals(lastFingerprint)) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800538 logd(
Jonathan Basseri65273c82017-07-25 15:08:42 -0700539 "Build fingerprint changed. old: "
540 + lastFingerprint
541 + " new: "
542 + Build.FINGERPRINT);
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700543 clearCachedConfigForPackage(null);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700544 sharedPrefs
545 .edit()
546 .putString(KEY_FINGERPRINT, Build.FINGERPRINT)
547 .apply();
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700548 }
549 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700550 }
Nathan Harold48ac0972019-03-13 22:33:01 -0700551
552 case EVENT_SUBSCRIPTION_INFO_UPDATED:
553 broadcastConfigChangedIntent(phoneId);
554 break;
Malcolm Chen5ea18532019-10-24 19:55:44 -0700555 case EVENT_MULTI_SIM_CONFIG_CHANGED:
556 onMultiSimConfigChanged();
557 break;
Jayachandran C645ec612020-01-10 10:30:25 -0800558
559 case EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG: {
560 PersistableBundle config =
561 restoreNoSimConfigFromXml(mPlatformCarrierConfigPackage);
562
563 if (config != null) {
564 logd("Loaded no SIM config from XML. package="
565 + mPlatformCarrierConfigPackage);
566 mNoSimConfig = config;
567 sendMessage(
568 obtainMessage(
569 EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE,
570 phoneId, -1));
571 } else {
572 // No cached config, so fetch it from the default app.
573 if (bindToConfigPackage(
574 mPlatformCarrierConfigPackage,
575 phoneId,
576 EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG)) {
577 sendMessageDelayed(
578 obtainMessage(
579 EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT,
580 phoneId, -1), BIND_TIMEOUT_MILLIS);
581 } else {
582 broadcastConfigChangedIntent(phoneId, false);
583 // TODO: We *must* call unbindService even if bindService returns false.
584 // (And possibly if SecurityException was thrown.)
585 loge("binding to default app to fetch no SIM config: "
586 + mPlatformCarrierConfigPackage + " fails");
587 }
588 }
589 break;
590 }
591
592 case EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE: {
593 broadcastConfigChangedIntent(phoneId, false);
594 break;
595 }
596
597 case EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT:
598 case EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT: {
599 loge("Bind/fetch time out for no SIM config from "
600 + mPlatformCarrierConfigPackage);
601 removeMessages(EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT);
602 // If we attempted to bind to the app, but the service connection is null due to
603 // the race condition that clear config event happens before bind/fetch complete
604 // then config was cleared while we were waiting and we should not continue.
605 if (mServiceConnectionForNoSimConfig[phoneId] != null) {
606 // If a ResponseReceiver callback is in the queue when this happens, we will
607 // unbind twice and throw an exception.
Rambo Wangc5901222021-09-17 13:18:35 -0700608 unbindIfBound(mContext, mServiceConnectionForNoSimConfig[phoneId]);
Jayachandran C645ec612020-01-10 10:30:25 -0800609 }
610 broadcastConfigChangedIntent(phoneId, false);
611 break;
612 }
613
614 case EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG: {
615 removeMessages(EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT);
616 final CarrierServiceConnection conn = (CarrierServiceConnection) msg.obj;
617 // If new service connection has been created, unbind.
618 if (mServiceConnectionForNoSimConfig[phoneId] != conn || conn.service == null) {
Rambo Wangc5901222021-09-17 13:18:35 -0700619 unbindIfBound(mContext, conn);
Jayachandran C645ec612020-01-10 10:30:25 -0800620 break;
621 }
622
623 // ResultReceiver callback will execute in this Handler's thread.
624 final ResultReceiver resultReceiver =
625 new ResultReceiver(this) {
626 @Override
627 public void onReceiveResult(int resultCode, Bundle resultData) {
Rambo Wangc5901222021-09-17 13:18:35 -0700628 unbindIfBound(mContext, conn);
Jayachandran C645ec612020-01-10 10:30:25 -0800629 // If new service connection has been created, this is stale.
630 if (mServiceConnectionForNoSimConfig[phoneId] != conn) {
631 loge("Received response for stale request.");
632 return;
633 }
634 removeMessages(EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT);
635 if (resultCode == RESULT_ERROR || resultData == null) {
636 // On error, abort config fetching.
637 loge("Failed to get no SIM carrier config");
638 return;
639 }
640 PersistableBundle config =
641 resultData.getParcelable(KEY_CONFIG_BUNDLE);
642 saveNoSimConfigToXml(mPlatformCarrierConfigPackage, config);
643 mNoSimConfig = config;
644 sendMessage(
645 obtainMessage(
646 EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE,
647 phoneId, -1));
648 }
649 };
650 // Now fetch the config asynchronously from the ICarrierService.
651 try {
652 ICarrierService carrierService =
653 ICarrierService.Stub.asInterface(conn.service);
654 carrierService.getCarrierConfig(null, resultReceiver);
655 logdWithLocalLog("Fetch no sim config from default app: "
656 + mPlatformCarrierConfigPackage);
657 } catch (RemoteException e) {
658 loge("Failed to get no sim carrier config from default app: " +
659 mPlatformCarrierConfigPackage + " err: " + e.toString());
Rambo Wangc5901222021-09-17 13:18:35 -0700660 unbindIfBound(mContext, conn);
Jayachandran C645ec612020-01-10 10:30:25 -0800661 break; // So we don't set a timeout.
662 }
663 sendMessageDelayed(
664 obtainMessage(
665 EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT,
666 phoneId, -1), BIND_TIMEOUT_MILLIS);
667 break;
668 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800669 }
670 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700671 }
672
673 private final Handler mHandler;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800674
675 /**
676 * Constructs a CarrierConfigLoader, registers it as a service, and registers a broadcast
677 * receiver for relevant events.
678 */
Rambo Wang7e3bc122021-03-23 09:24:38 -0700679 @VisibleForTesting
680 /* package */ CarrierConfigLoader(Context context,
681 SubscriptionInfoUpdater subscriptionInfoUpdater, @NonNull Looper looper) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800682 mContext = context;
Meng Wang33ad2bc2017-03-16 20:21:20 -0700683 mPlatformCarrierConfigPackage =
684 mContext.getString(R.string.platform_carrier_config_package);
Rambo Wang7e3bc122021-03-23 09:24:38 -0700685 mHandler = new ConfigHandler(looper);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800686
Nanxi Chen3d670502016-03-17 16:32:09 -0700687 IntentFilter bootFilter = new IntentFilter();
688 bootFilter.addAction(Intent.ACTION_BOOT_COMPLETED);
689 context.registerReceiver(mBootReceiver, bootFilter);
690
Junda Liu8a8a53a2015-05-15 16:19:57 -0700691 // Register for package updates. Update app or uninstall app update will have all 3 intents,
692 // in the order or removed, added, replaced, all with extra_replace set to true.
693 IntentFilter pkgFilter = new IntentFilter();
694 pkgFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
695 pkgFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
696 pkgFilter.addAction(Intent.ACTION_PACKAGE_REPLACED);
697 pkgFilter.addDataScheme("package");
Jordan Liu5ca24762019-07-10 12:51:09 -0700698 context.registerReceiver(mPackageReceiver, pkgFilter);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800699
Malcolm Chen978dda52019-10-08 18:15:25 -0700700 int numPhones = TelephonyManager.from(context).getSupportedModemCount();
Jonathan Basseric31f1f32015-05-12 10:13:03 -0700701 mConfigFromDefaultApp = new PersistableBundle[numPhones];
702 mConfigFromCarrierApp = new PersistableBundle[numPhones];
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100703 mPersistentOverrideConfigs = new PersistableBundle[numPhones];
Hall Liu506724b2018-10-22 18:16:14 -0700704 mOverrideConfigs = new PersistableBundle[numPhones];
Rambo Wang42026112021-04-07 20:57:28 +0000705 mNoSimConfig = new PersistableBundle();
Zach Johnson36d7aab2015-05-22 15:43:00 -0700706 mServiceConnection = new CarrierServiceConnection[numPhones];
Junda Liu03aad762017-07-21 13:32:17 -0700707 mHasSentConfigChange = new boolean[numPhones];
Sarah Chin807d5c62020-03-30 17:21:09 -0700708 mFromSystemUnlocked = new boolean[numPhones];
Jayachandran C645ec612020-01-10 10:30:25 -0800709 mServiceConnectionForNoSimConfig = new CarrierServiceConnection[numPhones];
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800710 logd("CarrierConfigLoader has started");
Rambo Wang7e3bc122021-03-23 09:24:38 -0700711 mSubscriptionInfoUpdater = subscriptionInfoUpdater;
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700712 mHandler.sendEmptyMessage(EVENT_CHECK_SYSTEM_UPDATE);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800713 }
714
715 /**
716 * Initialize the singleton CarrierConfigLoader instance.
717 *
718 * This is only done once, at startup, from {@link com.android.phone.PhoneApp#onCreate}.
719 */
Rambo Wang7e3bc122021-03-23 09:24:38 -0700720 /* package */ static CarrierConfigLoader init(Context context) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800721 synchronized (CarrierConfigLoader.class) {
722 if (sInstance == null) {
Rambo Wang7e3bc122021-03-23 09:24:38 -0700723 sInstance = new CarrierConfigLoader(context,
724 PhoneFactory.getSubscriptionInfoUpdater(), Looper.myLooper());
Brad Ebingerfa6575f2021-05-04 00:29:50 +0000725 // Make this service available through ServiceManager.
726 TelephonyFrameworkInitializer.getTelephonyServiceManager()
727 .getCarrierConfigServiceRegisterer().register(sInstance);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800728 } else {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700729 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800730 }
731 return sInstance;
732 }
733 }
734
Rambo Wang7e3bc122021-03-23 09:24:38 -0700735 @VisibleForTesting
736 /* package */ void clearConfigForPhone(int phoneId, boolean fetchNoSimConfig) {
Malcolm Chen5ea18532019-10-24 19:55:44 -0700737 /* Ignore clear configuration request if device is being shutdown. */
738 Phone phone = PhoneFactory.getPhone(phoneId);
739 if (phone != null) {
740 if (phone.isShuttingDown()) {
741 return;
742 }
743 }
744
745 mConfigFromDefaultApp[phoneId] = null;
746 mConfigFromCarrierApp[phoneId] = null;
747 mServiceConnection[phoneId] = null;
748 mHasSentConfigChange[phoneId] = false;
749
Jayachandran C645ec612020-01-10 10:30:25 -0800750 if (fetchNoSimConfig) {
751 // To fetch no SIM config
752 mHandler.sendMessage(
753 mHandler.obtainMessage(
754 EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG, phoneId, -1));
755 }
Malcolm Chen5ea18532019-10-24 19:55:44 -0700756 }
757
Nathan Harold48ac0972019-03-13 22:33:01 -0700758 private void notifySubscriptionInfoUpdater(int phoneId) {
759 String configPackagename;
760 PersistableBundle configToSend;
761 int carrierId = getSpecificCarrierIdForPhoneId(phoneId);
762 // Prefer the carrier privileged carrier app, but if there is not one, use the platform
763 // default carrier app.
764 if (mConfigFromCarrierApp[phoneId] != null) {
765 configPackagename = getCarrierPackageForPhoneId(phoneId);
766 configToSend = mConfigFromCarrierApp[phoneId];
767 } else {
768 configPackagename = mPlatformCarrierConfigPackage;
769 configToSend = mConfigFromDefaultApp[phoneId];
770 }
Nazanin Bakhshi6fcc3342019-09-18 17:54:01 -0700771
Malcolm Chenefafd1c2020-02-20 13:27:08 -0800772 if (configToSend == null) {
Rambo Wang42026112021-04-07 20:57:28 +0000773 configToSend = new PersistableBundle();
Malcolm Chenefafd1c2020-02-20 13:27:08 -0800774 }
775
Nazanin Bakhshi6fcc3342019-09-18 17:54:01 -0700776 // mOverrideConfigs is for testing. And it will override current configs.
777 PersistableBundle config = mOverrideConfigs[phoneId];
778 if (config != null) {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +0100779 configToSend = new PersistableBundle(configToSend);
Nazanin Bakhshi6fcc3342019-09-18 17:54:01 -0700780 configToSend.putAll(config);
781 }
782
Nathan Harold48ac0972019-03-13 22:33:01 -0700783 mSubscriptionInfoUpdater.updateSubscriptionByCarrierConfigAndNotifyComplete(
784 phoneId, configPackagename, configToSend,
785 mHandler.obtainMessage(EVENT_SUBSCRIPTION_INFO_UPDATED, phoneId, -1));
786 }
787
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800788 private void broadcastConfigChangedIntent(int phoneId) {
Amit Mahajanf8088ab2018-03-02 15:24:07 -0800789 broadcastConfigChangedIntent(phoneId, true);
790 }
791
792 private void broadcastConfigChangedIntent(int phoneId, boolean addSubIdExtra) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800793 Intent intent = new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Christopher Tate38f55eb2017-02-14 14:43:49 -0800794 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT |
chen xuf9db49f2019-03-31 23:04:42 -0700795 Intent.FLAG_RECEIVER_FOREGROUND);
Qiongcheng Luoe7de61b2018-08-06 10:20:09 +0800796 if (addSubIdExtra) {
797 int simApplicationState = TelephonyManager.SIM_STATE_UNKNOWN;
798 int[] subIds = SubscriptionManager.getSubId(phoneId);
799 if (!ArrayUtils.isEmpty(subIds)) {
800 TelephonyManager telMgr = TelephonyManager.from(mContext)
801 .createForSubscriptionId(subIds[0]);
802 simApplicationState = telMgr.getSimApplicationState();
803 }
Malcolm Chenf7635ec2020-04-15 15:45:00 -0700804 logd("Broadcast CARRIER_CONFIG_CHANGED for phone " + phoneId
805 + " simApplicationState " + simApplicationState);
Qiongcheng Luoe7de61b2018-08-06 10:20:09 +0800806 // Include subId/carrier id extra only if SIM records are loaded
807 if (simApplicationState != TelephonyManager.SIM_STATE_UNKNOWN
808 && simApplicationState != TelephonyManager.SIM_STATE_NOT_READY) {
809 SubscriptionManager.putPhoneIdAndSubIdExtra(intent, phoneId);
810 intent.putExtra(TelephonyManager.EXTRA_SPECIFIC_CARRIER_ID,
811 getSpecificCarrierIdForPhoneId(phoneId));
812 intent.putExtra(TelephonyManager.EXTRA_CARRIER_ID, getCarrierIdForPhoneId(phoneId));
813 }
Amit Mahajanf8088ab2018-03-02 15:24:07 -0800814 }
Amit Mahajanb33bcda2018-01-24 12:56:44 -0800815 intent.putExtra(CarrierConfigManager.EXTRA_SLOT_INDEX, phoneId);
Sarah Chin807d5c62020-03-30 17:21:09 -0700816 intent.putExtra(CarrierConfigManager.EXTRA_REBROADCAST_ON_UNLOCK,
817 mFromSystemUnlocked[phoneId]);
Meng Wang97a6a462020-01-23 16:22:16 -0800818 mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
Jack Yue9e95be2020-03-22 10:56:06 -0700819 int[] subIds = SubscriptionManager.getSubId(phoneId);
820 if (subIds != null && subIds.length > 0) {
821 logd("Broadcast CARRIER_CONFIG_CHANGED for phone " + phoneId + ", subId=" + subIds[0]);
822 } else {
823 logd("Broadcast CARRIER_CONFIG_CHANGED for phone " + phoneId);
824 }
Junda Liu03aad762017-07-21 13:32:17 -0700825 mHasSentConfigChange[phoneId] = true;
Sarah Chin807d5c62020-03-30 17:21:09 -0700826 mFromSystemUnlocked[phoneId] = false;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800827 }
828
829 /** Binds to the default or carrier config app. */
830 private boolean bindToConfigPackage(String pkgName, int phoneId, int eventId) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800831 logdWithLocalLog("Binding to " + pkgName + " for phone " + phoneId);
Zach Johnsonfca8a8d2015-06-19 18:21:37 -0700832 Intent carrierService = new Intent(CarrierService.CARRIER_SERVICE_INTERFACE);
Zach Johnson36d7aab2015-05-22 15:43:00 -0700833 carrierService.setPackage(pkgName);
Jayachandran C645ec612020-01-10 10:30:25 -0800834 CarrierServiceConnection serviceConnection = new CarrierServiceConnection(
835 phoneId, pkgName, eventId);
836 if (eventId == EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG) {
837 mServiceConnectionForNoSimConfig[phoneId] = serviceConnection;
838 } else {
839 mServiceConnection[phoneId] = serviceConnection;
840 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800841 try {
Jayachandran C645ec612020-01-10 10:30:25 -0800842 if (mContext.bindService(carrierService, serviceConnection,
Jordan Liu178430d2020-02-10 14:32:15 -0800843 Context.BIND_AUTO_CREATE)) {
Rambo Wangc5901222021-09-17 13:18:35 -0700844 serviceConnection.isBound = true;
Jordan Liu178430d2020-02-10 14:32:15 -0800845 return true;
846 } else {
847 return false;
848 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800849 } catch (SecurityException ex) {
850 return false;
851 }
852 }
853
Rambo Wang7e3bc122021-03-23 09:24:38 -0700854 @VisibleForTesting
855 /* package */ CarrierIdentifier getCarrierIdentifierForPhoneId(int phoneId) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800856 String mcc = "";
857 String mnc = "";
858 String imsi = "";
859 String gid1 = "";
860 String gid2 = "";
861 String spn = TelephonyManager.from(mContext).getSimOperatorNameForPhone(phoneId);
862 String simOperator = TelephonyManager.from(mContext).getSimOperatorNumericForPhone(phoneId);
chen xu02581692018-11-11 19:03:44 -0800863 int carrierId = TelephonyManager.UNKNOWN_CARRIER_ID;
chen xua31f22b2019-03-06 15:28:50 -0800864 int specificCarrierId = TelephonyManager.UNKNOWN_CARRIER_ID;
Jonathan Basseri1fa437c2015-04-20 11:08:18 -0700865 // A valid simOperator should be 5 or 6 digits, depending on the length of the MNC.
866 if (simOperator != null && simOperator.length() >= 3) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800867 mcc = simOperator.substring(0, 3);
868 mnc = simOperator.substring(3);
869 }
870 Phone phone = PhoneFactory.getPhone(phoneId);
871 if (phone != null) {
872 imsi = phone.getSubscriberId();
873 gid1 = phone.getGroupIdLevel1();
Junda Liu73183532015-05-14 13:55:40 -0700874 gid2 = phone.getGroupIdLevel2();
chen xu02581692018-11-11 19:03:44 -0800875 carrierId = phone.getCarrierId();
chen xua31f22b2019-03-06 15:28:50 -0800876 specificCarrierId = phone.getSpecificCarrierId();
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800877 }
chen xua31f22b2019-03-06 15:28:50 -0800878 return new CarrierIdentifier(mcc, mnc, spn, imsi, gid1, gid2, carrierId, specificCarrierId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800879 }
880
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700881 /** Returns the package name of a priveleged carrier app, or null if there is none. */
Nathan Harold1122e3d2021-01-22 15:45:24 -0800882 @Nullable
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700883 private String getCarrierPackageForPhoneId(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -0700884 List<String> carrierPackageNames;
885 final long token = Binder.clearCallingIdentity();
886 try {
887 carrierPackageNames = TelephonyManager.from(mContext)
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700888 .getCarrierPackageNamesForIntentAndPhone(
Nazanin1adf4562021-03-29 15:35:30 -0700889 new Intent(CarrierService.CARRIER_SERVICE_INTERFACE), phoneId);
890 } finally {
891 Binder.restoreCallingIdentity(token);
892 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700893 if (carrierPackageNames != null && carrierPackageNames.size() > 0) {
894 return carrierPackageNames.get(0);
895 } else {
896 return null;
897 }
898 }
899
900 private String getIccIdForPhoneId(int phoneId) {
901 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
902 return null;
903 }
904 Phone phone = PhoneFactory.getPhone(phoneId);
905 if (phone == null) {
906 return null;
907 }
908 return phone.getIccSerialNumber();
909 }
910
chen xu02581692018-11-11 19:03:44 -0800911 /**
chen xua31f22b2019-03-06 15:28:50 -0800912 * Get the sim specific carrier id {@link TelephonyManager#getSimSpecificCarrierId()}
chen xu02581692018-11-11 19:03:44 -0800913 */
chen xua31f22b2019-03-06 15:28:50 -0800914 private int getSpecificCarrierIdForPhoneId(int phoneId) {
Naina Nalluri86fc7b02018-08-03 10:38:30 -0700915 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
chen xu02581692018-11-11 19:03:44 -0800916 return TelephonyManager.UNKNOWN_CARRIER_ID;
Naina Nalluri86fc7b02018-08-03 10:38:30 -0700917 }
918 Phone phone = PhoneFactory.getPhone(phoneId);
919 if (phone == null) {
chen xu02581692018-11-11 19:03:44 -0800920 return TelephonyManager.UNKNOWN_CARRIER_ID;
Naina Nalluri86fc7b02018-08-03 10:38:30 -0700921 }
chen xua31f22b2019-03-06 15:28:50 -0800922 return phone.getSpecificCarrierId();
chen xu02581692018-11-11 19:03:44 -0800923 }
924
925 /**
926 * Get the sim carrier id {@link TelephonyManager#getSimCarrierId() }
927 */
928 private int getCarrierIdForPhoneId(int phoneId) {
929 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
930 return TelephonyManager.UNKNOWN_CARRIER_ID;
Naina Nalluri86fc7b02018-08-03 10:38:30 -0700931 }
chen xu02581692018-11-11 19:03:44 -0800932 Phone phone = PhoneFactory.getPhone(phoneId);
933 if (phone == null) {
934 return TelephonyManager.UNKNOWN_CARRIER_ID;
935 }
936 return phone.getCarrierId();
Naina Nalluri86fc7b02018-08-03 10:38:30 -0700937 }
938
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700939 /**
940 * Writes a bundle to an XML file.
941 *
chen xu02581692018-11-11 19:03:44 -0800942 * The bundle will be written to a file named after the package name, ICCID and
chen xua31f22b2019-03-06 15:28:50 -0800943 * specific carrier id {@link TelephonyManager#getSimSpecificCarrierId()}. the same carrier
chen xu02581692018-11-11 19:03:44 -0800944 * should have a single copy of XML file named after carrier id. However, it's still possible
945 * that platform doesn't recognize the current sim carrier, we will use iccid + carrierid as
946 * the canonical file name. carrierid can also handle the cases SIM OTA resolves to different
947 * carrier while iccid remains the same.
948 *
949 * The file can be restored later with {@link @restoreConfigFromXml}. The XML output will
950 * include the bundle and the current version of the specified package.
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700951 *
952 * In case of errors or invalid input, no file will be written.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700953 *
Jayachandran C645ec612020-01-10 10:30:25 -0800954 * @param packageName the name of the package from which we fetched this bundle.
955 * @param extraString An extra string to be used in the XML file name.
956 * @param phoneId the phone ID.
957 * @param carrierId contains all carrier-identifying information.
958 * @param config the bundle to be written. Null will be treated as an empty bundle.
959 * @param isNoSimConfig whether this is invoked for noSimConfig or not.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700960 */
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100961 private void saveConfigToXml(String packageName, @NonNull String extraString, int phoneId,
Jayachandran C645ec612020-01-10 10:30:25 -0800962 CarrierIdentifier carrierId, PersistableBundle config, boolean isNoSimConfig) {
963 if (packageName == null) {
964 loge("Cannot save config with null packageName");
Yuchen Dongc15afed2018-04-26 17:05:22 +0800965 return;
966 }
967
Jayachandran C645ec612020-01-10 10:30:25 -0800968 String fileName;
969 if (isNoSimConfig) {
970 fileName = getFilenameForNoSimConfig(packageName);
971 } else {
972 if (SubscriptionManager.getSimStateForSlotIndex(phoneId)
973 != TelephonyManager.SIM_STATE_LOADED) {
974 loge("Skip save config because SIM records are not loaded.");
975 return;
976 }
977
978 final String iccid = getIccIdForPhoneId(phoneId);
979 final int cid = carrierId.getSpecificCarrierId();
980 if (iccid == null) {
981 loge("Cannot save config with null iccid.");
982 return;
983 }
984 fileName = getFilenameForConfig(packageName, extraString, iccid, cid);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700985 }
Jayachandran C645ec612020-01-10 10:30:25 -0800986
Junda Liu02596502016-11-15 13:46:43 -0800987 // b/32668103 Only save to file if config isn't empty.
988 // In case of failure, not caching an empty bundle will
989 // try loading config again on next power on or sim loaded.
990 // Downside is for genuinely empty bundle, will bind and load
991 // on every power on.
992 if (config == null || config.isEmpty()) {
993 return;
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700994 }
995
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700996 final String version = getPackageVersion(packageName);
997 if (version == null) {
998 loge("Failed to get package version for: " + packageName);
999 return;
1000 }
1001
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001002 logdWithLocalLog(
1003 "Save config to xml, packagename: " + packageName + " phoneId: " + phoneId);
chen xudb04c292019-03-26 17:01:15 -07001004
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001005 FileOutputStream outFile = null;
1006 try {
Jayachandran C645ec612020-01-10 10:30:25 -08001007 outFile = new FileOutputStream(new File(mContext.getFilesDir(), fileName));
Meng Wang0f6b2ea2020-01-06 18:31:16 -08001008 config.putString(KEY_VERSION, version);
1009 config.writeToStream(outFile);
1010 outFile.flush();
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001011 outFile.close();
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001012 } catch (IOException e) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001013 loge(e.toString());
1014 }
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001015 }
1016
Rambo Wang7e3bc122021-03-23 09:24:38 -07001017 @VisibleForTesting
1018 /* package */ void saveConfigToXml(String packageName, @NonNull String extraString, int phoneId,
Jayachandran C645ec612020-01-10 10:30:25 -08001019 CarrierIdentifier carrierId, PersistableBundle config) {
1020 saveConfigToXml(packageName, extraString, phoneId, carrierId, config, false);
1021 }
1022
Rambo Wang7e3bc122021-03-23 09:24:38 -07001023 @VisibleForTesting
1024 /* package */ void saveNoSimConfigToXml(String packageName, PersistableBundle config) {
Jayachandran C645ec612020-01-10 10:30:25 -08001025 saveConfigToXml(packageName, "", -1, null, config, true);
1026 }
1027
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001028 /**
1029 * Reads a bundle from an XML file.
1030 *
1031 * This restores a bundle that was written with {@link #saveConfigToXml}. This returns the saved
Yuchen Dongc15afed2018-04-26 17:05:22 +08001032 * config bundle for the given package and phone ID.
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001033 *
1034 * In case of errors, or if the saved config is from a different package version than the
1035 * current version, then null will be returned.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001036 *
Jayachandran C645ec612020-01-10 10:30:25 -08001037 * @param packageName the name of the package from which we fetched this bundle.
1038 * @param extraString An extra string to be used in the XML file name.
1039 * @param phoneId the phone ID.
1040 * @param isNoSimConfig whether this is invoked for noSimConfig or not.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001041 * @return the bundle from the XML file. Returns null if there is no saved config, the saved
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001042 * version does not match, or reading config fails.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001043 */
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001044 private PersistableBundle restoreConfigFromXml(String packageName, @NonNull String extraString,
Jayachandran C645ec612020-01-10 10:30:25 -08001045 int phoneId, boolean isNoSimConfig) {
1046 if (packageName == null) {
1047 loge("Cannot restore config with null packageName");
1048 }
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001049 final String version = getPackageVersion(packageName);
1050 if (version == null) {
1051 loge("Failed to get package version for: " + packageName);
1052 return null;
1053 }
Yuchen Dongc15afed2018-04-26 17:05:22 +08001054
Jayachandran C645ec612020-01-10 10:30:25 -08001055 String fileName;
1056 if (isNoSimConfig) {
1057 fileName = getFilenameForNoSimConfig(packageName);
1058 } else {
1059 if (SubscriptionManager.getSimStateForSlotIndex(phoneId)
1060 != TelephonyManager.SIM_STATE_LOADED) {
1061 loge("Skip restore config because SIM records are not loaded.");
1062 return null;
1063 }
1064
1065 final String iccid = getIccIdForPhoneId(phoneId);
1066 final int cid = getSpecificCarrierIdForPhoneId(phoneId);
1067 if (iccid == null) {
1068 loge("Cannot restore config with null iccid.");
1069 return null;
1070 }
1071 fileName = getFilenameForConfig(packageName, extraString, iccid, cid);
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001072 }
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001073
1074 PersistableBundle restoredBundle = null;
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001075 File file = null;
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001076 FileInputStream inFile = null;
1077 try {
Jayachandran C645ec612020-01-10 10:30:25 -08001078 file = new File(mContext.getFilesDir(),fileName);
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001079 inFile = new FileInputStream(file);
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001080
Meng Wang0f6b2ea2020-01-06 18:31:16 -08001081 restoredBundle = PersistableBundle.readFromStream(inFile);
1082 String savedVersion = restoredBundle.getString(KEY_VERSION);
1083 restoredBundle.remove(KEY_VERSION);
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001084
Meng Wang0f6b2ea2020-01-06 18:31:16 -08001085 if (!version.equals(savedVersion)) {
1086 loge("Saved version mismatch: " + version + " vs " + savedVersion);
1087 restoredBundle = null;
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001088 }
Meng Wang0f6b2ea2020-01-06 18:31:16 -08001089
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001090 inFile.close();
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001091 } catch (FileNotFoundException e) {
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001092 // Missing file is normal occurrence that might occur with a new sim or when restoring
1093 // an override file during boot and should not be treated as an error.
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001094 if (file != null) logd("File not found: " + file.getPath());
1095 } catch (IOException e) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001096 loge(e.toString());
1097 }
1098
1099 return restoredBundle;
1100 }
1101
Jayachandran C645ec612020-01-10 10:30:25 -08001102 private PersistableBundle restoreConfigFromXml(String packageName, @NonNull String extraString,
1103 int phoneId) {
1104 return restoreConfigFromXml(packageName, extraString, phoneId, false);
1105 }
1106
1107 private PersistableBundle restoreNoSimConfigFromXml(String packageName) {
1108 return restoreConfigFromXml(packageName, "", -1, true);
1109 }
1110
Junda Liu8a8a53a2015-05-15 16:19:57 -07001111 /**
Jonathan Basseri7697cae2015-07-06 15:49:23 -07001112 * Clears cached carrier config.
1113 * This deletes all saved XML files associated with the given package name. If packageName is
1114 * null, then it deletes all saved XML files.
1115 *
1116 * @param packageName the name of a carrier package, or null if all cached config should be
1117 * cleared.
1118 * @return true iff one or more files were deleted.
Junda Liu8a8a53a2015-05-15 16:19:57 -07001119 */
Jonathan Basseri7697cae2015-07-06 15:49:23 -07001120 private boolean clearCachedConfigForPackage(final String packageName) {
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001121 File dir = mContext.getFilesDir();
1122 File[] packageFiles = dir.listFiles(new FilenameFilter() {
1123 public boolean accept(File dir, String filename) {
Jonathan Basseri7697cae2015-07-06 15:49:23 -07001124 if (packageName != null) {
1125 return filename.startsWith("carrierconfig-" + packageName + "-");
1126 } else {
1127 return filename.startsWith("carrierconfig-");
1128 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001129 }
1130 });
Junda Liu8a8a53a2015-05-15 16:19:57 -07001131 if (packageFiles == null || packageFiles.length < 1) return false;
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001132 for (File f : packageFiles) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001133 logd("Deleting " + f.getName());
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001134 f.delete();
1135 }
Junda Liu8a8a53a2015-05-15 16:19:57 -07001136 return true;
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001137 }
1138
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001139 /** Builds a canonical file name for a config file. */
Jayachandran C645ec612020-01-10 10:30:25 -08001140 private static String getFilenameForConfig(
1141 @NonNull String packageName, @NonNull String extraString,
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001142 @NonNull String iccid, int cid) {
chen xu02581692018-11-11 19:03:44 -08001143 // the same carrier should have a single copy of XML file named after carrier id.
1144 // However, it's still possible that platform doesn't recognize the current sim carrier,
1145 // we will use iccid + carrierid as the canonical file name. carrierid can also handle the
1146 // cases SIM OTA resolves to different carrier while iccid remains the same.
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001147 return "carrierconfig-" + packageName + extraString + "-" + iccid + "-" + cid + ".xml";
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001148 }
1149
Jayachandran C645ec612020-01-10 10:30:25 -08001150 /** Builds a canonical file name for no SIM config file. */
1151 private String getFilenameForNoSimConfig(@NonNull String packageName) {
1152 return "carrierconfig-" + packageName + "-" + "nosim" + ".xml";
1153 }
1154
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001155 /** Return the current version code of a package, or null if the name is not found. */
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001156 private String getPackageVersion(String packageName) {
1157 try {
1158 PackageInfo info = mContext.getPackageManager().getPackageInfo(packageName, 0);
Dianne Hackbornb76ab202017-11-28 17:44:50 -08001159 return Long.toString(info.getLongVersionCode());
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001160 } catch (PackageManager.NameNotFoundException e) {
1161 return null;
1162 }
1163 }
1164
Jonathan Basseri65273c82017-07-25 15:08:42 -07001165 /**
1166 * Read up to date config.
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001167 *
1168 * This reads config bundles for the given phoneId. That means getting the latest bundle from
1169 * the default app and a privileged carrier app, if present. This will not bind to an app if we
1170 * have a saved config file to use instead.
1171 */
1172 private void updateConfigForPhoneId(int phoneId) {
Jonathan Basseri65273c82017-07-25 15:08:42 -07001173 mHandler.sendMessage(mHandler.obtainMessage(EVENT_DO_FETCH_DEFAULT, phoneId, -1));
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001174 }
1175
Malcolm Chen5ea18532019-10-24 19:55:44 -07001176 private void onMultiSimConfigChanged() {
1177 for (int i = TelephonyManager.from(mContext).getActiveModemCount();
1178 i < mConfigFromDefaultApp.length; i++) {
1179 clearConfigForPhone(i, false);
1180 }
1181 }
1182
Hall Liu506724b2018-10-22 18:16:14 -07001183 @Override
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001184 @NonNull
Rambo Wangd2b004b2021-03-30 10:10:23 -07001185 public PersistableBundle getConfigForSubId(int subscriptionId, String callingPackage) {
1186 return getConfigForSubIdWithFeature(subscriptionId, callingPackage, null);
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001187 }
1188
1189 @Override
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001190 @NonNull
Rambo Wangd2b004b2021-03-30 10:10:23 -07001191 public PersistableBundle getConfigForSubIdWithFeature(int subscriptionId, String callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001192 String callingFeatureId) {
Rambo Wangd2b004b2021-03-30 10:10:23 -07001193 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mContext, subscriptionId,
1194 callingPackage, callingFeatureId, "getCarrierConfig")) {
Rambo Wang42026112021-04-07 20:57:28 +00001195 return new PersistableBundle();
Amit Mahajan40b3fa52015-07-14 10:27:19 -07001196 }
Jeff Davidsona8e4e242018-03-15 17:16:18 -07001197
Rambo Wangd2b004b2021-03-30 10:10:23 -07001198 int phoneId = SubscriptionManager.getPhoneId(subscriptionId);
Jonathan Basseric31f1f32015-05-12 10:13:03 -07001199 PersistableBundle retConfig = CarrierConfigManager.getDefaultConfig();
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001200 if (SubscriptionManager.isValidPhoneId(phoneId)) {
Jonathan Basseric31f1f32015-05-12 10:13:03 -07001201 PersistableBundle config = mConfigFromDefaultApp[phoneId];
yinxuc5e27622017-11-29 15:08:50 -08001202 if (config != null) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001203 retConfig.putAll(config);
yinxuc5e27622017-11-29 15:08:50 -08001204 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001205 config = mConfigFromCarrierApp[phoneId];
yinxuc5e27622017-11-29 15:08:50 -08001206 if (config != null) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001207 retConfig.putAll(config);
yinxuc5e27622017-11-29 15:08:50 -08001208 }
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001209 config = mPersistentOverrideConfigs[phoneId];
1210 if (config != null) {
1211 retConfig.putAll(config);
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001212 }
Hall Liu506724b2018-10-22 18:16:14 -07001213 config = mOverrideConfigs[phoneId];
1214 if (config != null) {
1215 retConfig.putAll(config);
Hall Liu506724b2018-10-22 18:16:14 -07001216 }
Nathan Harold1122e3d2021-01-22 15:45:24 -08001217 // Ignore the theoretical case of the default app not being present since that won't
1218 // work in CarrierConfigLoader today.
1219 final boolean allConfigsApplied =
1220 (mConfigFromCarrierApp[phoneId] != null
1221 || getCarrierPackageForPhoneId(phoneId) == null)
1222 && mConfigFromDefaultApp[phoneId] != null;
1223 retConfig.putBoolean(
1224 CarrierConfigManager.KEY_CARRIER_CONFIG_APPLIED_BOOL, allConfigsApplied);
Jayachandran C645ec612020-01-10 10:30:25 -08001225 } else {
1226 if (mNoSimConfig != null) {
1227 retConfig.putAll(mNoSimConfig);
1228 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001229 }
1230 return retConfig;
1231 }
1232
1233 @Override
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001234 public void overrideConfig(int subscriptionId, @Nullable PersistableBundle overrides,
1235 boolean persistent) {
Hall Liu506724b2018-10-22 18:16:14 -07001236 mContext.enforceCallingOrSelfPermission(
1237 android.Manifest.permission.MODIFY_PHONE_STATE, null);
Brad Ebingerf6281ad2019-04-25 11:02:04 -07001238 //TODO: Also check for SHELL UID to restrict this method to testing only (b/131326259)
Hall Liu506724b2018-10-22 18:16:14 -07001239 int phoneId = SubscriptionManager.getPhoneId(subscriptionId);
1240 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001241 logd("Ignore invalid phoneId: " + phoneId + " for subId: " + subscriptionId);
Rambo Wangd2b004b2021-03-30 10:10:23 -07001242 throw new IllegalArgumentException(
1243 "Invalid phoneId " + phoneId + " for subId " + subscriptionId);
Hall Liu506724b2018-10-22 18:16:14 -07001244 }
Rambo Wang38eb5cd2021-03-29 16:39:14 -07001245 // Post to run on handler thread on which all states should be confined.
1246 mHandler.post(() -> {
1247 overrideConfig(mOverrideConfigs, phoneId, overrides);
Hall Liu506724b2018-10-22 18:16:14 -07001248
Rambo Wang38eb5cd2021-03-29 16:39:14 -07001249 if (persistent) {
1250 overrideConfig(mPersistentOverrideConfigs, phoneId, overrides);
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001251
Rambo Wang38eb5cd2021-03-29 16:39:14 -07001252 if (overrides != null) {
1253 final CarrierIdentifier carrierId = getCarrierIdentifierForPhoneId(phoneId);
1254 saveConfigToXml(mPlatformCarrierConfigPackage, OVERRIDE_PACKAGE_ADDITION,
1255 phoneId,
1256 carrierId, mPersistentOverrideConfigs[phoneId]);
1257 } else {
1258 final String iccid = getIccIdForPhoneId(phoneId);
1259 final int cid = getSpecificCarrierIdForPhoneId(phoneId);
1260 String fileName = getFilenameForConfig(mPlatformCarrierConfigPackage,
1261 OVERRIDE_PACKAGE_ADDITION, iccid, cid);
1262 File fileToDelete = new File(mContext.getFilesDir(), fileName);
1263 fileToDelete.delete();
1264 }
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001265 }
Rambo Wang38eb5cd2021-03-29 16:39:14 -07001266 notifySubscriptionInfoUpdater(phoneId);
1267 });
Hall Liu506724b2018-10-22 18:16:14 -07001268 }
1269
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001270 private void overrideConfig(@NonNull PersistableBundle[] currentOverrides, int phoneId,
1271 @Nullable PersistableBundle overrides) {
1272 if (overrides == null) {
Rambo Wang42026112021-04-07 20:57:28 +00001273 currentOverrides[phoneId] = new PersistableBundle();
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001274 } else if (currentOverrides[phoneId] == null) {
1275 currentOverrides[phoneId] = overrides;
1276 } else {
1277 currentOverrides[phoneId].putAll(overrides);
1278 }
1279 }
1280
Hall Liu506724b2018-10-22 18:16:14 -07001281 @Override
Rambo Wangd2b004b2021-03-30 10:10:23 -07001282 public void notifyConfigChangedForSubId(int subscriptionId) {
Jordan Liud7d57fe2019-04-16 12:29:43 -07001283 // Requires the calling app to be either a carrier privileged app for this subId or
Junda Liufbd2bcb2016-06-15 11:15:42 -07001284 // system privileged app with MODIFY_PHONE_STATE permission.
Rambo Wangd2b004b2021-03-30 10:10:23 -07001285 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mContext,
1286 subscriptionId, "Require carrier privileges or MODIFY_PHONE_STATE permission.");
1287
1288 int phoneId = SubscriptionManager.getPhoneId(subscriptionId);
1289 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
1290 logd("Ignore invalid phoneId: " + phoneId + " for subId: " + subscriptionId);
1291 throw new IllegalArgumentException(
1292 "Invalid phoneId " + phoneId + " for subId " + subscriptionId);
1293 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001294
1295 // This method should block until deleting has completed, so that an error which prevents us
1296 // from clearing the cache is passed back to the carrier app. With the files successfully
1297 // deleted, this can return and we will eventually bind to the carrier app.
Jordan Liud7d57fe2019-04-16 12:29:43 -07001298 String callingPackageName = mContext.getPackageManager().getNameForUid(
1299 Binder.getCallingUid());
Jonathan Basseri7697cae2015-07-06 15:49:23 -07001300 clearCachedConfigForPackage(callingPackageName);
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001301 updateConfigForPhoneId(phoneId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001302 }
1303
1304 @Override
1305 public void updateConfigForPhoneId(int phoneId, String simState) {
Junda Liu1f2b34d2015-06-18 15:26:56 -07001306 mContext.enforceCallingOrSelfPermission(
1307 android.Manifest.permission.MODIFY_PHONE_STATE, null);
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001308 logdWithLocalLog("Update config for phoneId: " + phoneId + " simState: " + simState);
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001309 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
Rambo Wangd2b004b2021-03-30 10:10:23 -07001310 throw new IllegalArgumentException("Invalid phoneId: " + phoneId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001311 }
1312 // requires Java 7 for switch on string.
1313 switch (simState) {
1314 case IccCardConstants.INTENT_VALUE_ICC_ABSENT:
1315 case IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR:
Junda Liu6f5fddf2016-05-24 16:14:41 -07001316 case IccCardConstants.INTENT_VALUE_ICC_CARD_RESTRICTED:
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001317 case IccCardConstants.INTENT_VALUE_ICC_UNKNOWN:
Malcolm Chendb66de12019-12-09 18:57:07 -08001318 case IccCardConstants.INTENT_VALUE_ICC_NOT_READY:
Junda Liu9f2d2712015-05-15 14:22:45 -07001319 mHandler.sendMessage(mHandler.obtainMessage(EVENT_CLEAR_CONFIG, phoneId, -1));
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001320 break;
1321 case IccCardConstants.INTENT_VALUE_ICC_LOADED:
1322 case IccCardConstants.INTENT_VALUE_ICC_LOCKED:
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001323 updateConfigForPhoneId(phoneId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001324 break;
1325 }
1326 }
1327
Junda Liu43d723a2015-05-12 17:23:45 -07001328 @Override
Jeff Sharkeya6fcfed2017-07-20 14:18:39 -06001329 public String getDefaultCarrierServicePackageName() {
Shuo Qianefdb7962019-12-19 15:54:27 -08001330 mContext.enforceCallingOrSelfPermission(
1331 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
1332 "getDefaultCarrierServicePackageName");
Jeff Sharkeya6fcfed2017-07-20 14:18:39 -06001333 return mPlatformCarrierConfigPackage;
1334 }
1335
Rambo Wang7e3bc122021-03-23 09:24:38 -07001336 @VisibleForTesting
1337 /* package */ Handler getHandler() {
1338 return mHandler;
1339 }
1340
1341 @VisibleForTesting
1342 /* package */ PersistableBundle getConfigFromDefaultApp(int phoneId) {
1343 return mConfigFromDefaultApp[phoneId];
1344 }
1345
1346 @VisibleForTesting
1347 /* package */ PersistableBundle getConfigFromCarrierApp(int phoneId) {
1348 return mConfigFromCarrierApp[phoneId];
1349 }
1350
1351 @VisibleForTesting
1352 /* package */ PersistableBundle getNoSimConfig() {
1353 return mNoSimConfig;
1354 }
1355
1356 @VisibleForTesting
1357 /* package */ PersistableBundle getOverrideConfig(int phoneId) {
1358 return mOverrideConfigs[phoneId];
1359 }
1360
Rambo Wangc5901222021-09-17 13:18:35 -07001361 private void unbindIfBound(Context context, CarrierServiceConnection conn) {
1362 if (conn.isBound) {
1363 conn.isBound = false;
Jayachandran C645ec612020-01-10 10:30:25 -08001364 context.unbindService(conn);
1365 }
1366 }
1367
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001368 /**
Rambo Wang610fdf62021-03-08 21:37:11 -08001369 * Returns a boxed Integer object for phoneId, services as message token to distinguish messages
1370 * with same code when calling {@link Handler#removeMessages(int, Object)}.
1371 */
1372 private Integer getMessageToken(int phoneId) {
1373 if (phoneId < -128 || phoneId > 127) {
1374 throw new IllegalArgumentException("phoneId should be in range [-128, 127], inclusive");
1375 }
1376 // Integer#valueOf guarantees the integers within [-128, 127] are cached and thus memory
1377 // comparison (==) returns true for the same integer.
1378 return Integer.valueOf(phoneId);
1379 }
1380
1381 /**
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001382 * If {@code args} contains {@link #DUMP_ARG_REQUESTING_PACKAGE} and a following package name,
1383 * we'll also call {@link IBinder#dump} on the default carrier service (if bound) and the
1384 * specified carrier service (if bound). Typically, this is done for connectivity bug reports
1385 * where we don't call {@code dumpsys activity service all-non-platform} because that contains
1386 * too much info, but we still want to let carrier apps include their diagnostics.
1387 */
Jeff Sharkeya6fcfed2017-07-20 14:18:39 -06001388 @Override
Junda Liu43d723a2015-05-12 17:23:45 -07001389 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001390 IndentingPrintWriter indentPW = new IndentingPrintWriter(pw, " ");
Junda Liu43d723a2015-05-12 17:23:45 -07001391 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
1392 != PackageManager.PERMISSION_GRANTED) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001393 indentPW.println("Permission Denial: can't dump carrierconfig from from pid="
Junda Liu43d723a2015-05-12 17:23:45 -07001394 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
1395 return;
1396 }
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001397 String requestingPackage = null;
1398 int requestingPackageIndex = ArrayUtils.indexOf(args, DUMP_ARG_REQUESTING_PACKAGE);
1399 if (requestingPackageIndex >= 0 && requestingPackageIndex < args.length - 1
1400 && !TextUtils.isEmpty(args[requestingPackageIndex + 1])) {
1401 requestingPackage = args[requestingPackageIndex + 1];
1402 // Throws a SecurityException if the caller is impersonating another app in an effort to
1403 // dump extra info (which may contain PII the caller doesn't have a right to).
1404 enforceCallerIsSystemOrRequestingPackage(requestingPackage);
1405 }
1406
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001407 indentPW.println("CarrierConfigLoader: " + this);
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001408 for (int i = 0; i < TelephonyManager.from(mContext).getActiveModemCount(); i++) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001409 indentPW.println("Phone Id = " + i);
shuoq26a3a4c2016-12-16 11:06:48 -08001410 // display default values in CarrierConfigManager
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001411 printConfig(CarrierConfigManager.getDefaultConfig(), indentPW,
shuoq26a3a4c2016-12-16 11:06:48 -08001412 "Default Values from CarrierConfigManager");
shuoq26a3a4c2016-12-16 11:06:48 -08001413 // display ConfigFromDefaultApp
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001414 printConfig(mConfigFromDefaultApp[i], indentPW, "mConfigFromDefaultApp");
shuoq26a3a4c2016-12-16 11:06:48 -08001415 // display ConfigFromCarrierApp
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001416 printConfig(mConfigFromCarrierApp[i], indentPW, "mConfigFromCarrierApp");
1417 printConfig(mPersistentOverrideConfigs[i], indentPW, "mPersistentOverrideConfigs");
1418 printConfig(mOverrideConfigs[i], indentPW, "mOverrideConfigs");
shuoq26a3a4c2016-12-16 11:06:48 -08001419 }
chen xudb04c292019-03-26 17:01:15 -07001420
Jayachandran C645ec612020-01-10 10:30:25 -08001421 printConfig(mNoSimConfig, indentPW, "mNoSimConfig");
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001422 indentPW.println("CarrierConfigLoadingLog=");
1423 mCarrierConfigLoadingLog.dump(fd, indentPW, args);
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001424
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001425 if (requestingPackage != null) {
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001426 logd("Including default and requesting package " + requestingPackage
1427 + " carrier services in dump");
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001428 indentPW.println("");
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001429 indentPW.println("Connected services");
1430 dumpCarrierServiceIfBound(fd, indentPW, "Default config package",
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001431 mPlatformCarrierConfigPackage, false /* considerCarrierPrivileges */);
1432 dumpCarrierServiceIfBound(fd, indentPW, "Requesting package", requestingPackage,
1433 true /* considerCarrierPrivileges */);
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001434 }
shuoq26a3a4c2016-12-16 11:06:48 -08001435 }
1436
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001437 private void printConfig(PersistableBundle configApp, IndentingPrintWriter indentPW,
1438 String name) {
1439 indentPW.increaseIndent();
shuoq26a3a4c2016-12-16 11:06:48 -08001440 if (configApp == null) {
shuoq26a3a4c2016-12-16 11:06:48 -08001441 indentPW.println(name + " : null ");
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001442 indentPW.decreaseIndent();
1443 indentPW.println("");
shuoq26a3a4c2016-12-16 11:06:48 -08001444 return;
1445 }
shuoq26a3a4c2016-12-16 11:06:48 -08001446 indentPW.println(name + " : ");
1447 List<String> sortedKeys = new ArrayList<String>(configApp.keySet());
1448 Collections.sort(sortedKeys);
1449 indentPW.increaseIndent();
1450 indentPW.increaseIndent();
1451 for (String key : sortedKeys) {
1452 if (configApp.get(key) != null && configApp.get(key) instanceof Object[]) {
1453 indentPW.println(key + " = " +
1454 Arrays.toString((Object[]) configApp.get(key)));
1455 } else if (configApp.get(key) != null && configApp.get(key) instanceof int[]) {
1456 indentPW.println(key + " = " + Arrays.toString((int[]) configApp.get(key)));
1457 } else {
1458 indentPW.println(key + " = " + configApp.get(key));
1459 }
Junda Liu43d723a2015-05-12 17:23:45 -07001460 }
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001461 indentPW.decreaseIndent();
1462 indentPW.decreaseIndent();
1463 indentPW.decreaseIndent();
1464 indentPW.println("");
Junda Liu43d723a2015-05-12 17:23:45 -07001465 }
1466
Hunter Knepshielde601f432020-02-19 10:16:04 -08001467 /**
1468 * Passes without problem when one of these conditions is true:
1469 * - The caller is a privileged UID (e.g. for dumpstate.cpp generating a bug report, where the
1470 * system knows the true caller plumbed in through the {@link android.os.BugreportManager} API).
1471 * - The caller's UID matches the supplied package.
1472 *
1473 * @throws SecurityException if none of the above conditions are met.
1474 */
1475 private void enforceCallerIsSystemOrRequestingPackage(String requestingPackage)
1476 throws SecurityException {
1477 final int callingUid = Binder.getCallingUid();
1478 if (callingUid == Process.ROOT_UID || callingUid == Process.SYSTEM_UID
1479 || callingUid == Process.SHELL_UID || callingUid == Process.PHONE_UID) {
1480 // Bug reports (dumpstate.cpp) run as SHELL, and let some other privileged UIDs through
1481 // as well.
1482 return;
1483 }
1484 // An app is trying to dump extra detail, block it if they aren't who they claim to be.
1485 AppOpsManager appOps = mContext.getSystemService(AppOpsManager.class);
1486 if (appOps == null) {
1487 throw new SecurityException("No AppOps");
1488 }
1489 // Will throw a SecurityException if the UID and package don't match.
1490 appOps.checkPackage(callingUid, requestingPackage);
1491 }
1492
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001493 /**
1494 * Searches for one or more appropriate {@link CarrierService} instances to dump based on the
1495 * current connections.
1496 *
1497 * @param targetPkgName the target package name to dump carrier services for
1498 * @param considerCarrierPrivileges if true, allow a carrier service to be dumped if it shares
1499 * carrier privileges with {@code targetPkgName};
1500 * otherwise, only dump a carrier service if it is {@code
1501 * targetPkgName}
1502 */
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001503 private void dumpCarrierServiceIfBound(FileDescriptor fd, IndentingPrintWriter indentPW,
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001504 String prefix, String targetPkgName, boolean considerCarrierPrivileges) {
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001505 // Null package is possible if it's early in the boot process, there was a recent crash, we
1506 // loaded the config from XML most recently, or a SIM slot is empty. Carrier apps with
1507 // long-lived bindings should typically get dumped here regardless. Even if an app is being
1508 // used for multiple phoneIds, we assume that it's smart enough to handle that on its own,
1509 // and that in most cases we'd just be dumping duplicate information and bloating a report.
1510 indentPW.increaseIndent();
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001511 indentPW.println(prefix + " : " + targetPkgName);
1512 Set<String> dumpedPkgNames = new ArraySet<>(mServiceConnection.length);
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001513 for (CarrierServiceConnection connection : mServiceConnection) {
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001514 if (connection == null || !SubscriptionManager.isValidPhoneId(connection.phoneId)
1515 || TextUtils.isEmpty(connection.pkgName)) {
1516 continue;
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001517 }
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001518 final String servicePkgName = connection.pkgName;
1519 // Note: we intentionally ignore system components here because we should NOT match the
1520 // shell caller that's typically used for bug reports via non-BugreportManager triggers.
1521 final boolean exactPackageMatch = TextUtils.equals(targetPkgName, servicePkgName);
1522 final boolean carrierPrivilegesMatch =
1523 considerCarrierPrivileges && hasCarrierPrivileges(targetPkgName,
1524 connection.phoneId);
1525 if (!exactPackageMatch && !carrierPrivilegesMatch) continue;
1526 // Make sure this service is actually alive before trying to dump it. We don't pay
1527 // attention to mServiceBound[connection.phoneId] because typically carrier apps will
1528 // request long-lived bindings, and even if we unbind the app, it may still be alive due
1529 // to CarrierServiceBindHelper. Pull it out as a reference so even if it gets set to
1530 // null within the ServiceConnection during unbinding we can avoid an NPE.
1531 final IBinder service = connection.service;
1532 if (service == null || !service.isBinderAlive() || !service.pingBinder()) continue;
1533 // We've got a live service. Last check is just to make sure we don't dump a package
1534 // multiple times.
1535 if (!dumpedPkgNames.add(servicePkgName)) continue;
1536 if (!exactPackageMatch) {
1537 logd(targetPkgName + " has carrier privileges on phoneId " + connection.phoneId
1538 + ", service provided by " + servicePkgName);
1539 indentPW.increaseIndent();
1540 indentPW.println("Proxy : " + servicePkgName);
1541 indentPW.decreaseIndent();
1542 }
1543 // Flush before we let the app output anything to ensure correct ordering of output.
1544 // Internally, Binder#dump calls flush on its printer after finishing so we don't
1545 // need to do anything after.
1546 indentPW.flush();
1547 try {
1548 logd("Dumping " + servicePkgName);
1549 // We don't need to give the carrier service any args.
1550 connection.service.dump(fd, null /* args */);
1551 logd("Done with " + servicePkgName);
1552 } catch (RemoteException e) {
1553 logd("RemoteException from " + servicePkgName, e);
1554 indentPW.increaseIndent();
1555 indentPW.println("RemoteException");
1556 indentPW.increaseIndent();
1557 e.printStackTrace(indentPW);
1558 indentPW.decreaseIndent();
1559 indentPW.decreaseIndent();
1560 // We won't retry this package again because now it's in dumpedPkgNames.
1561 }
1562 indentPW.println("");
Jordan Liu46ed5db2020-01-28 08:55:20 -08001563 }
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001564 if (dumpedPkgNames.isEmpty()) {
1565 indentPW.increaseIndent();
1566 indentPW.println("Not bound");
1567 indentPW.decreaseIndent();
1568 indentPW.println("");
1569 }
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001570 indentPW.decreaseIndent();
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001571 }
1572
1573 private boolean hasCarrierPrivileges(String pkgName, int phoneId) {
1574 int[] subIds = SubscriptionManager.getSubId(phoneId);
1575 if (ArrayUtils.isEmpty(subIds)) {
1576 return false;
1577 }
1578 return TelephonyManager.from(mContext).createForSubscriptionId(
1579 subIds[0]).checkCarrierPrivilegesForPackage(pkgName)
1580 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Jordan Liu46ed5db2020-01-28 08:55:20 -08001581 }
1582
Zach Johnson36d7aab2015-05-22 15:43:00 -07001583 private class CarrierServiceConnection implements ServiceConnection {
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001584 final int phoneId;
1585 final String pkgName;
1586 final int eventId;
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001587 IBinder service;
Rambo Wangc5901222021-09-17 13:18:35 -07001588 // If bindService was called and return true which means unbindService
1589 // must be called later to release the connection
1590 boolean isBound;
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001591
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001592 CarrierServiceConnection(int phoneId, String pkgName, int eventId) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001593 this.phoneId = phoneId;
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001594 this.pkgName = pkgName;
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001595 this.eventId = eventId;
Rambo Wangc5901222021-09-17 13:18:35 -07001596 this.isBound = false;
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001597 }
1598
1599 @Override
1600 public void onServiceConnected(ComponentName name, IBinder service) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001601 logd("Connected to config app: " + name.flattenToShortString());
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001602 this.service = service;
1603 mHandler.sendMessage(mHandler.obtainMessage(eventId, phoneId, -1, this));
1604 }
1605
1606 @Override
1607 public void onServiceDisconnected(ComponentName name) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001608 logd("Disconnected from config app: " + name.flattenToShortString());
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001609 this.service = null;
Jordan Liu46ed5db2020-01-28 08:55:20 -08001610 }
1611
1612 @Override
1613 public void onBindingDied(ComponentName name) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001614 logd("Binding died from config app: " + name.flattenToShortString());
Jordan Liu46ed5db2020-01-28 08:55:20 -08001615 this.service = null;
Jordan Liu46ed5db2020-01-28 08:55:20 -08001616 }
1617
1618 @Override
1619 public void onNullBinding(ComponentName name) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001620 logd("Null binding from config app: " + name.flattenToShortString());
Jordan Liu46ed5db2020-01-28 08:55:20 -08001621 this.service = null;
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001622 }
1623 }
1624
1625 private class ConfigLoaderBroadcastReceiver extends BroadcastReceiver {
1626 @Override
1627 public void onReceive(Context context, Intent intent) {
1628 String action = intent.getAction();
Junda Liu8a8a53a2015-05-15 16:19:57 -07001629 boolean replace = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
1630 // If replace is true, only care ACTION_PACKAGE_REPLACED.
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001631 if (replace && !Intent.ACTION_PACKAGE_REPLACED.equals(action)) {
Junda Liu8a8a53a2015-05-15 16:19:57 -07001632 return;
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001633 }
Junda Liu8a8a53a2015-05-15 16:19:57 -07001634
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001635 switch (action) {
Nanxi Chen3d670502016-03-17 16:32:09 -07001636 case Intent.ACTION_BOOT_COMPLETED:
1637 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SYSTEM_UNLOCKED, null));
1638 break;
1639
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001640 case Intent.ACTION_PACKAGE_ADDED:
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001641 case Intent.ACTION_PACKAGE_REMOVED:
Junda Liu8a8a53a2015-05-15 16:19:57 -07001642 case Intent.ACTION_PACKAGE_REPLACED:
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001643 int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
1644 String packageName = mContext.getPackageManager().getNameForUid(uid);
Junda Liu8a8a53a2015-05-15 16:19:57 -07001645 if (packageName != null) {
1646 // We don't have a phoneId for arg1.
1647 mHandler.sendMessage(
1648 mHandler.obtainMessage(EVENT_PACKAGE_CHANGED, packageName));
1649 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001650 break;
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001651 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001652 }
1653 }
1654
Rambo Wangab13e3e2021-04-08 15:01:06 -07001655 // Get readable string for the message code supported in this class.
1656 private static String eventToString(int code) {
1657 switch (code) {
1658 case EVENT_CLEAR_CONFIG:
1659 return "EVENT_CLEAR_CONFIG";
1660 case EVENT_CONNECTED_TO_DEFAULT:
1661 return "EVENT_CONNECTED_TO_DEFAULT";
1662 case EVENT_CONNECTED_TO_CARRIER:
1663 return "EVENT_CONNECTED_TO_CARRIER";
1664 case EVENT_FETCH_DEFAULT_DONE:
1665 return "EVENT_FETCH_DEFAULT_DONE";
1666 case EVENT_FETCH_CARRIER_DONE:
1667 return "EVENT_FETCH_CARRIER_DONE";
1668 case EVENT_DO_FETCH_DEFAULT:
1669 return "EVENT_DO_FETCH_DEFAULT";
1670 case EVENT_DO_FETCH_CARRIER:
1671 return "EVENT_DO_FETCH_CARRIER";
1672 case EVENT_PACKAGE_CHANGED:
1673 return "EVENT_PACKAGE_CHANGED";
1674 case EVENT_BIND_DEFAULT_TIMEOUT:
1675 return "EVENT_BIND_DEFAULT_TIMEOUT";
1676 case EVENT_BIND_CARRIER_TIMEOUT:
1677 return "EVENT_BIND_CARRIER_TIMEOUT";
1678 case EVENT_CHECK_SYSTEM_UPDATE:
1679 return "EVENT_CHECK_SYSTEM_UPDATE";
1680 case EVENT_SYSTEM_UNLOCKED:
1681 return "EVENT_SYSTEM_UNLOCKED";
1682 case EVENT_FETCH_DEFAULT_TIMEOUT:
1683 return "EVENT_FETCH_DEFAULT_TIMEOUT";
1684 case EVENT_FETCH_CARRIER_TIMEOUT:
1685 return "EVENT_FETCH_CARRIER_TIMEOUT";
1686 case EVENT_SUBSCRIPTION_INFO_UPDATED:
1687 return "EVENT_SUBSCRIPTION_INFO_UPDATED";
1688 case EVENT_MULTI_SIM_CONFIG_CHANGED:
1689 return "EVENT_MULTI_SIM_CONFIG_CHANGED";
1690 case EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG:
1691 return "EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG";
1692 case EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE:
1693 return "EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE";
1694 case EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG:
1695 return "EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG";
1696 case EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT:
1697 return "EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT";
1698 case EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT:
1699 return "EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT";
1700 default:
1701 return "UNKNOWN(" + code + ")";
1702 }
1703 }
1704
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001705 private void logd(String msg) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001706 Log.d(LOG_TAG, msg);
1707 }
1708
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001709 private void logd(String msg, Throwable tr) {
1710 Log.d(LOG_TAG, msg, tr);
1711 }
1712
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001713 private void logdWithLocalLog(String msg) {
chen xudb04c292019-03-26 17:01:15 -07001714 Log.d(LOG_TAG, msg);
1715 mCarrierConfigLoadingLog.log(msg);
1716 }
1717
1718 private void loge(String msg) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001719 Log.e(LOG_TAG, msg);
chen xudb04c292019-03-26 17:01:15 -07001720 mCarrierConfigLoadingLog.log(msg);
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001721 }
1722}