blob: 2b91a246f4cbf289a2fe1fcc62ad7289eddab8e6 [file] [log] [blame]
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001/*
Jonathan Basseri6465afd2015-02-25 13:05:57 -08002 * Copyright (c) 2015, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jonathan Basseri6465afd2015-02-25 13:05:57 -080017package com.android.phone;
18
Jonathan Basseri65273c82017-07-25 15:08:42 -070019import static android.service.carrier.CarrierService.ICarrierServiceWrapper.KEY_CONFIG_BUNDLE;
20import static android.service.carrier.CarrierService.ICarrierServiceWrapper.RESULT_ERROR;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080021
Jonathan Basseri11f89572015-05-05 11:57:39 -070022import android.annotation.NonNull;
Torbjorn Eklund723527a2019-02-13 11:16:25 +010023import android.annotation.Nullable;
Hunter Knepshielde601f432020-02-19 10:16:04 -080024import android.app.AppOpsManager;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080025import android.content.BroadcastReceiver;
26import android.content.ComponentName;
27import android.content.Context;
28import android.content.Intent;
29import android.content.IntentFilter;
30import android.content.ServiceConnection;
Jonathan Basseri7697cae2015-07-06 15:49:23 -070031import android.content.SharedPreferences;
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -070032import android.content.pm.PackageInfo;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070033import android.content.pm.PackageManager;
Junda Liu43d723a2015-05-12 17:23:45 -070034import android.os.Binder;
Jonathan Basseri7697cae2015-07-06 15:49:23 -070035import android.os.Build;
Jonathan Basseri65273c82017-07-25 15:08:42 -070036import android.os.Bundle;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080037import android.os.Handler;
38import android.os.IBinder;
Rambo Wang7e3bc122021-03-23 09:24:38 -070039import android.os.Looper;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080040import android.os.Message;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070041import android.os.PersistableBundle;
Hunter Knepshielde601f432020-02-19 10:16:04 -080042import android.os.Process;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080043import android.os.RemoteException;
Jonathan Basseri65273c82017-07-25 15:08:42 -070044import android.os.ResultReceiver;
Meng Wang97a6a462020-01-23 16:22:16 -080045import android.os.UserHandle;
Jonathan Basseri7697cae2015-07-06 15:49:23 -070046import android.preference.PreferenceManager;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080047import android.service.carrier.CarrierIdentifier;
Zach Johnson36d7aab2015-05-22 15:43:00 -070048import android.service.carrier.CarrierService;
49import android.service.carrier.ICarrierService;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080050import android.telephony.CarrierConfigManager;
51import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080052import android.telephony.TelephonyFrameworkInitializer;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080053import android.telephony.TelephonyManager;
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -080054import android.text.TextUtils;
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -080055import android.util.ArraySet;
chen xudb04c292019-03-26 17:01:15 -070056import android.util.LocalLog;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080057import android.util.Log;
58
Rambo Wang7e3bc122021-03-23 09:24:38 -070059import com.android.internal.annotations.VisibleForTesting;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080060import com.android.internal.telephony.ICarrierConfigLoader;
61import com.android.internal.telephony.IccCardConstants;
62import com.android.internal.telephony.Phone;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080063import com.android.internal.telephony.PhoneFactory;
Nathan Harold48ac0972019-03-13 22:33:01 -070064import com.android.internal.telephony.SubscriptionInfoUpdater;
Jeff Davidsona8e4e242018-03-15 17:16:18 -070065import com.android.internal.telephony.TelephonyPermissions;
Meng Wanga320b942019-11-25 11:21:26 -080066import com.android.internal.telephony.util.ArrayUtils;
shuoq26a3a4c2016-12-16 11:06:48 -080067import com.android.internal.util.IndentingPrintWriter;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080068
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -070069import java.io.File;
Junda Liu43d723a2015-05-12 17:23:45 -070070import java.io.FileDescriptor;
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -070071import java.io.FileInputStream;
72import java.io.FileNotFoundException;
73import java.io.FileOutputStream;
Jonathan Basseri1f743c92015-05-15 00:19:46 -070074import java.io.FilenameFilter;
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -070075import java.io.IOException;
Junda Liu43d723a2015-05-12 17:23:45 -070076import java.io.PrintWriter;
shuoq26a3a4c2016-12-16 11:06:48 -080077import java.util.ArrayList;
78import java.util.Arrays;
79import java.util.Collections;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080080import java.util.List;
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -080081import java.util.Set;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080082
83/**
84 * CarrierConfigLoader binds to privileged carrier apps to fetch carrier config overlays.
Jonathan Basseri6465afd2015-02-25 13:05:57 -080085 */
Jonathan Basseri6465afd2015-02-25 13:05:57 -080086public class CarrierConfigLoader extends ICarrierConfigLoader.Stub {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -070087 private static final String LOG_TAG = "CarrierConfigLoader";
Meng Wang33ad2bc2017-03-16 20:21:20 -070088
89 // Package name for platform carrier config app, bundled with system image.
90 private final String mPlatformCarrierConfigPackage;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080091
92 /** The singleton instance. */
93 private static CarrierConfigLoader sInstance;
94 // The context for phone app, passed from PhoneGlobals.
95 private Context mContext;
96 // Carrier configs from default app, indexed by phoneID.
Jonathan Basseric31f1f32015-05-12 10:13:03 -070097 private PersistableBundle[] mConfigFromDefaultApp;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080098 // Carrier configs from privileged carrier config app, indexed by phoneID.
Jonathan Basseric31f1f32015-05-12 10:13:03 -070099 private PersistableBundle[] mConfigFromCarrierApp;
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100100 // Persistent Carrier configs that are provided via the override test API, indexed by phone ID.
101 private PersistableBundle[] mPersistentOverrideConfigs;
Hall Liu506724b2018-10-22 18:16:14 -0700102 // Carrier configs that are provided via the override test API, indexed by phone ID.
103 private PersistableBundle[] mOverrideConfigs;
Jayachandran C645ec612020-01-10 10:30:25 -0800104 // Carrier configs to override code default when there is no SIM inserted
105 private PersistableBundle mNoSimConfig;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800106 // Service connection for binding to config app.
Zach Johnson36d7aab2015-05-22 15:43:00 -0700107 private CarrierServiceConnection[] mServiceConnection;
Jayachandran C645ec612020-01-10 10:30:25 -0800108 // Service connection for binding to carrier config app for no SIM config.
109 private CarrierServiceConnection[] mServiceConnectionForNoSimConfig;
Jordan Liu178430d2020-02-10 14:32:15 -0800110 // Whether we are bound to a service for each phone
111 private boolean[] mServiceBound;
Jayachandran C645ec612020-01-10 10:30:25 -0800112 // Whether we are bound to a service for no SIM config
113 private boolean[] mServiceBoundForNoSimConfig;
Sarah Chin807d5c62020-03-30 17:21:09 -0700114 // Whether we have sent config change broadcast for each phone id.
Junda Liu03aad762017-07-21 13:32:17 -0700115 private boolean[] mHasSentConfigChange;
Sarah Chin807d5c62020-03-30 17:21:09 -0700116 // Whether the broadcast was sent from EVENT_SYSTEM_UNLOCKED, to track rebroadcasts
117 private boolean[] mFromSystemUnlocked;
Nathan Harold48ac0972019-03-13 22:33:01 -0700118 // SubscriptionInfoUpdater
119 private final SubscriptionInfoUpdater mSubscriptionInfoUpdater;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800120
Nanxi Chen3d670502016-03-17 16:32:09 -0700121 // Broadcast receiver for Boot intents, register intent filter in construtor.
122 private final BroadcastReceiver mBootReceiver = new ConfigLoaderBroadcastReceiver();
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800123 // Broadcast receiver for SIM and pkg intents, register intent filter in constructor.
Nanxi Chen3d670502016-03-17 16:32:09 -0700124 private final BroadcastReceiver mPackageReceiver = new ConfigLoaderBroadcastReceiver();
Jack Yu67663de2019-10-17 15:19:48 -0700125 private final LocalLog mCarrierConfigLoadingLog = new LocalLog(100);
chen xudb04c292019-03-26 17:01:15 -0700126
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800127
128 // Message codes; see mHandler below.
129 // Request from SubscriptionInfoUpdater when SIM becomes absent or error.
130 private static final int EVENT_CLEAR_CONFIG = 0;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800131 // Has connected to default app.
132 private static final int EVENT_CONNECTED_TO_DEFAULT = 3;
133 // Has connected to carrier app.
134 private static final int EVENT_CONNECTED_TO_CARRIER = 4;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700135 // Config has been loaded from default app (or cache).
136 private static final int EVENT_FETCH_DEFAULT_DONE = 5;
137 // Config has been loaded from carrier app (or cache).
138 private static final int EVENT_FETCH_CARRIER_DONE = 6;
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700139 // Attempt to fetch from default app or read from XML.
Jonathan Basseri65273c82017-07-25 15:08:42 -0700140 private static final int EVENT_DO_FETCH_DEFAULT = 7;
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700141 // Attempt to fetch from carrier app or read from XML.
Jonathan Basseri65273c82017-07-25 15:08:42 -0700142 private static final int EVENT_DO_FETCH_CARRIER = 8;
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700143 // A package has been installed, uninstalled, or updated.
144 private static final int EVENT_PACKAGE_CHANGED = 9;
Jonathan Basseri930701e2015-06-11 20:56:43 -0700145 // Bind timed out for the default app.
146 private static final int EVENT_BIND_DEFAULT_TIMEOUT = 10;
147 // Bind timed out for a carrier app.
148 private static final int EVENT_BIND_CARRIER_TIMEOUT = 11;
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700149 // Check if the system fingerprint has changed.
150 private static final int EVENT_CHECK_SYSTEM_UPDATE = 12;
Nanxi Chen3d670502016-03-17 16:32:09 -0700151 // Rerun carrier config binding after system is unlocked.
152 private static final int EVENT_SYSTEM_UNLOCKED = 13;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700153 // Fetching config timed out from the default app.
154 private static final int EVENT_FETCH_DEFAULT_TIMEOUT = 14;
155 // Fetching config timed out from a carrier app.
156 private static final int EVENT_FETCH_CARRIER_TIMEOUT = 15;
Nathan Harold48ac0972019-03-13 22:33:01 -0700157 // SubscriptionInfoUpdater has finished updating the sub for the carrier config.
158 private static final int EVENT_SUBSCRIPTION_INFO_UPDATED = 16;
Malcolm Chen5ea18532019-10-24 19:55:44 -0700159 // Multi-SIM config changed.
160 private static final int EVENT_MULTI_SIM_CONFIG_CHANGED = 17;
Jayachandran C645ec612020-01-10 10:30:25 -0800161 // Attempt to fetch from default app or read from XML for no SIM case.
162 private static final int EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG = 18;
163 // No SIM config has been loaded from default app (or cache).
164 private static final int EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE = 19;
165 // Has connected to default app for no SIM config.
166 private static final int EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG = 20;
167 // Bind timed out for the default app when trying to fetch no SIM config.
168 private static final int EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT = 21;
169 // Fetching config timed out from the default app for no SIM config.
170 private static final int EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT = 22;
Rambo Wangab13e3e2021-04-08 15:01:06 -0700171 // NOTE: any new EVENT_* values must be added to method eventToString().
Jonathan Basseri930701e2015-06-11 20:56:43 -0700172
Junda Liu6cb45002016-03-22 17:18:20 -0700173 private static final int BIND_TIMEOUT_MILLIS = 30000;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800174
Meng Wang0f6b2ea2020-01-06 18:31:16 -0800175 // Keys used for saving and restoring config bundle from file.
176 private static final String KEY_VERSION = "__carrier_config_package_version__";
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800177
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100178 private static final String OVERRIDE_PACKAGE_ADDITION = "-override";
179
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700180 // SharedPreferences key for last known build fingerprint.
181 private static final String KEY_FINGERPRINT = "build_fingerprint";
182
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -0800183 // Argument for #dump that indicates we should also call the default and specified carrier
184 // service's #dump method. In multi-SIM devices, it's possible that carrier A is on SIM 1 and
185 // carrier B is on SIM 2, in which case we should not dump carrier B's service when carrier A
186 // requested the dump.
187 private static final String DUMP_ARG_REQUESTING_PACKAGE = "--requesting-package";
188
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800189 // Handler to process various events.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700190 //
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700191 // For each phoneId, the event sequence should be:
Jonathan Basseri65273c82017-07-25 15:08:42 -0700192 // fetch default, connected to default, fetch default (async), fetch default done,
193 // fetch carrier, connected to carrier, fetch carrier (async), fetch carrier done.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700194 //
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700195 // If there is a saved config file for either the default app or the carrier app, we skip
196 // binding to the app and go straight from fetch to loaded.
197 //
198 // At any time, at most one connection is active. If events are not in this order, previous
199 // connection will be unbound, so only latest event takes effect.
200 //
201 // We broadcast ACTION_CARRIER_CONFIG_CHANGED after:
202 // 1. loading from carrier app (even if read from a file)
203 // 2. loading from default app if there is no carrier app (even if read from a file)
204 // 3. clearing config (e.g. due to sim removal)
205 // 4. encountering bind or IPC error
Jonathan Basseri65273c82017-07-25 15:08:42 -0700206 private class ConfigHandler extends Handler {
Rambo Wang7e3bc122021-03-23 09:24:38 -0700207 ConfigHandler(@NonNull Looper looper) {
208 super(looper);
209 }
210
Jonathan Basseri65273c82017-07-25 15:08:42 -0700211 @Override
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800212 public void handleMessage(Message msg) {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700213 final int phoneId = msg.arg1;
Rambo Wangab13e3e2021-04-08 15:01:06 -0700214 logdWithLocalLog("mHandler: " + eventToString(msg.what) + " phoneId: " + phoneId);
Malcolm Chen5ea18532019-10-24 19:55:44 -0700215 if (!SubscriptionManager.isValidPhoneId(phoneId)
216 && msg.what != EVENT_MULTI_SIM_CONFIG_CHANGED) {
217 return;
218 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800219 switch (msg.what) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800220 case EVENT_CLEAR_CONFIG: {
Malcolm Chen5ea18532019-10-24 19:55:44 -0700221 clearConfigForPhone(phoneId, true);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800222 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700223 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700224
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800225 case EVENT_SYSTEM_UNLOCKED: {
Malcolm Chen5ea18532019-10-24 19:55:44 -0700226 for (int i = 0; i < TelephonyManager.from(mContext).getActiveModemCount();
227 ++i) {
Sarah Chin807d5c62020-03-30 17:21:09 -0700228 // When the user unlocks the device, send the broadcast again (with a
229 // rebroadcast extra) if we have sent it before unlock. This will avoid
230 // trying to load the carrier config when the SIM is still loading when the
231 // unlock happens.
Junda Liu03aad762017-07-21 13:32:17 -0700232 if (mHasSentConfigChange[i]) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800233 logdWithLocalLog("System unlocked");
Sarah Chin807d5c62020-03-30 17:21:09 -0700234 mFromSystemUnlocked[i] = true;
Junda Liu03aad762017-07-21 13:32:17 -0700235 updateConfigForPhoneId(i);
236 }
Nanxi Chen3d670502016-03-17 16:32:09 -0700237 }
238 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700239 }
Nanxi Chen3d670502016-03-17 16:32:09 -0700240
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800241 case EVENT_PACKAGE_CHANGED: {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700242 final String carrierPackageName = (String) msg.obj;
243 // Only update if there are cached config removed to avoid updating config for
244 // unrelated packages.
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700245 if (clearCachedConfigForPackage(carrierPackageName)) {
Malcolm Chen5ea18532019-10-24 19:55:44 -0700246 int numPhones = TelephonyManager.from(mContext).getActiveModemCount();
Junda Liu8a8a53a2015-05-15 16:19:57 -0700247 for (int i = 0; i < numPhones; ++i) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800248 logdWithLocalLog("Package changed: " + carrierPackageName
Jack Yu67663de2019-10-17 15:19:48 -0700249 + ", phone=" + i);
Junda Liu8a8a53a2015-05-15 16:19:57 -0700250 updateConfigForPhoneId(i);
251 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700252 }
253 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700254 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700255
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800256 case EVENT_DO_FETCH_DEFAULT: {
Rambo Wang9bc7d362021-03-09 09:10:58 -0800257 // Clear in-memory cache for carrier app config, so when carrier app gets
258 // uninstalled, no stale config is left.
259 if (mConfigFromCarrierApp[phoneId] != null
260 && getCarrierPackageForPhoneId(phoneId) == null) {
261 mConfigFromCarrierApp[phoneId] = null;
262 }
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100263 // Restore persistent override values.
264 PersistableBundle config = restoreConfigFromXml(
265 mPlatformCarrierConfigPackage, OVERRIDE_PACKAGE_ADDITION, phoneId);
266 if (config != null) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800267 logd("Loaded persistent override config from XML. package="
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100268 + mPlatformCarrierConfigPackage
269 + " phoneId=" + phoneId);
270 mPersistentOverrideConfigs[phoneId] = config;
271 }
272
273 config = restoreConfigFromXml(mPlatformCarrierConfigPackage, "", phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700274 if (config != null) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800275 logd(
Jonathan Basseri65273c82017-07-25 15:08:42 -0700276 "Loaded config from XML. package="
277 + mPlatformCarrierConfigPackage
278 + " phoneId="
279 + phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700280 mConfigFromDefaultApp[phoneId] = config;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700281 Message newMsg = obtainMessage(EVENT_FETCH_DEFAULT_DONE, phoneId, -1);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700282 newMsg.getData().putBoolean("loaded_from_xml", true);
283 mHandler.sendMessage(newMsg);
284 } else {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700285 // No cached config, so fetch it from the default app.
286 if (bindToConfigPackage(
287 mPlatformCarrierConfigPackage,
288 phoneId,
289 EVENT_CONNECTED_TO_DEFAULT)) {
290 sendMessageDelayed(
Rambo Wang610fdf62021-03-08 21:37:11 -0800291 obtainMessage(EVENT_BIND_DEFAULT_TIMEOUT, phoneId, -1 /*arg2*/,
292 getMessageToken(phoneId)),
Jonathan Basseri930701e2015-06-11 20:56:43 -0700293 BIND_TIMEOUT_MILLIS);
294 } else {
Nathan Harold1122e3d2021-01-22 15:45:24 -0800295 // Put a stub bundle in place so that the rest of the logic continues
296 // smoothly.
Rambo Wang42026112021-04-07 20:57:28 +0000297 mConfigFromDefaultApp[phoneId] = new PersistableBundle();
Jonathan Basseri65273c82017-07-25 15:08:42 -0700298 // Send broadcast if bind fails.
Nathan Harold48ac0972019-03-13 22:33:01 -0700299 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700300 // TODO: We *must* call unbindService even if bindService returns false.
301 // (And possibly if SecurityException was thrown.)
chen xudb04c292019-03-26 17:01:15 -0700302 loge("binding to default app: "
303 + mPlatformCarrierConfigPackage + " fails");
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700304 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800305 }
306 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700307 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800308
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800309 case EVENT_CONNECTED_TO_DEFAULT: {
Rambo Wang610fdf62021-03-08 21:37:11 -0800310 removeMessages(EVENT_BIND_DEFAULT_TIMEOUT, getMessageToken(phoneId));
Jonathan Basseri65273c82017-07-25 15:08:42 -0700311 final CarrierServiceConnection conn = (CarrierServiceConnection) msg.obj;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800312 // If new service connection has been created, unbind.
313 if (mServiceConnection[phoneId] != conn || conn.service == null) {
Jordan Liu178430d2020-02-10 14:32:15 -0800314 unbindIfBound(mContext, conn, phoneId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800315 break;
316 }
chen xu02581692018-11-11 19:03:44 -0800317 final CarrierIdentifier carrierId = getCarrierIdentifierForPhoneId(phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700318 // ResultReceiver callback will execute in this Handler's thread.
319 final ResultReceiver resultReceiver =
320 new ResultReceiver(this) {
321 @Override
322 public void onReceiveResult(int resultCode, Bundle resultData) {
Jordan Liu178430d2020-02-10 14:32:15 -0800323 unbindIfBound(mContext, conn, phoneId);
Rambo Wanga9d27a52021-04-09 16:17:33 -0700324 removeMessages(EVENT_FETCH_DEFAULT_TIMEOUT,
325 getMessageToken(phoneId));
Jonathan Basseri65273c82017-07-25 15:08:42 -0700326 // If new service connection has been created, this is stale.
327 if (mServiceConnection[phoneId] != conn) {
328 loge("Received response for stale request.");
329 return;
330 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700331 if (resultCode == RESULT_ERROR || resultData == null) {
332 // On error, abort config fetching.
333 loge("Failed to get carrier config");
Nathan Harold48ac0972019-03-13 22:33:01 -0700334 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700335 return;
336 }
337 PersistableBundle config =
338 resultData.getParcelable(KEY_CONFIG_BUNDLE);
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100339 saveConfigToXml(mPlatformCarrierConfigPackage, "", phoneId,
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800340 carrierId, config);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700341 mConfigFromDefaultApp[phoneId] = config;
342 sendMessage(
343 obtainMessage(
344 EVENT_FETCH_DEFAULT_DONE, phoneId, -1));
345 }
346 };
347 // Now fetch the config asynchronously from the ICarrierService.
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800348 try {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700349 ICarrierService carrierService =
350 ICarrierService.Stub.asInterface(conn.service);
351 carrierService.getCarrierConfig(carrierId, resultReceiver);
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800352 logdWithLocalLog("Fetch config for default app: "
chen xudb04c292019-03-26 17:01:15 -0700353 + mPlatformCarrierConfigPackage
354 + " carrierid: " + carrierId.toString());
Jonathan Basseri65273c82017-07-25 15:08:42 -0700355 } catch (RemoteException e) {
chen xudb04c292019-03-26 17:01:15 -0700356 loge("Failed to get carrier config from default app: " +
357 mPlatformCarrierConfigPackage + " err: " + e.toString());
Jordan Liu178430d2020-02-10 14:32:15 -0800358 unbindIfBound(mContext, conn, phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700359 break; // So we don't set a timeout.
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800360 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700361 sendMessageDelayed(
Rambo Wang610fdf62021-03-08 21:37:11 -0800362 obtainMessage(EVENT_FETCH_DEFAULT_TIMEOUT, phoneId, -1 /*arg2*/,
363 getMessageToken(phoneId)),
Jonathan Basseri65273c82017-07-25 15:08:42 -0700364 BIND_TIMEOUT_MILLIS);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800365 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700366 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800367
Jonathan Basseri930701e2015-06-11 20:56:43 -0700368 case EVENT_BIND_DEFAULT_TIMEOUT:
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800369 case EVENT_FETCH_DEFAULT_TIMEOUT: {
370 loge("Bind/fetch time out from " + mPlatformCarrierConfigPackage);
Rambo Wang610fdf62021-03-08 21:37:11 -0800371 removeMessages(EVENT_FETCH_DEFAULT_TIMEOUT, getMessageToken(phoneId));
chen xuf60b3162019-05-01 21:31:05 -0700372 // If we attempted to bind to the app, but the service connection is null due to
373 // the race condition that clear config event happens before bind/fetch complete
374 // then config was cleared while we were waiting and we should not continue.
375 if (mServiceConnection[phoneId] != null) {
376 // If a ResponseReceiver callback is in the queue when this happens, we will
377 // unbind twice and throw an exception.
Jordan Liu178430d2020-02-10 14:32:15 -0800378 unbindIfBound(mContext, mServiceConnection[phoneId], phoneId);
chen xuf60b3162019-05-01 21:31:05 -0700379 broadcastConfigChangedIntent(phoneId);
380 }
Nathan Harold1122e3d2021-01-22 15:45:24 -0800381 // Put a stub bundle in place so that the rest of the logic continues smoothly.
Rambo Wang42026112021-04-07 20:57:28 +0000382 mConfigFromDefaultApp[phoneId] = new PersistableBundle();
Nathan Harold48ac0972019-03-13 22:33:01 -0700383 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri930701e2015-06-11 20:56:43 -0700384 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700385 }
Jonathan Basseri930701e2015-06-11 20:56:43 -0700386
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800387 case EVENT_FETCH_DEFAULT_DONE: {
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700388 // If we attempted to bind to the app, but the service connection is null, then
389 // config was cleared while we were waiting and we should not continue.
390 if (!msg.getData().getBoolean("loaded_from_xml", false)
391 && mServiceConnection[phoneId] == null) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800392 break;
393 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700394 final String carrierPackageName = getCarrierPackageForPhoneId(phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700395 if (carrierPackageName != null) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800396 logd("Found carrier config app: " + carrierPackageName);
Jordan Liu38a614c2019-03-20 15:01:17 -0700397 sendMessage(obtainMessage(EVENT_DO_FETCH_CARRIER, phoneId, -1));
Jonathan Basserib919e932015-05-27 16:53:08 +0000398 } else {
Nathan Harold48ac0972019-03-13 22:33:01 -0700399 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri4ae2e7c2015-05-15 00:19:46 -0700400 }
401 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700402 }
Jonathan Basseri4ae2e7c2015-05-15 00:19:46 -0700403
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800404 case EVENT_DO_FETCH_CARRIER: {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700405 final String carrierPackageName = getCarrierPackageForPhoneId(phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700406 final PersistableBundle config =
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100407 restoreConfigFromXml(carrierPackageName, "", phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700408 if (config != null) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800409 logd(
Jonathan Basseri65273c82017-07-25 15:08:42 -0700410 "Loaded config from XML. package="
411 + carrierPackageName
412 + " phoneId="
413 + phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700414 mConfigFromCarrierApp[phoneId] = config;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700415 Message newMsg = obtainMessage(EVENT_FETCH_CARRIER_DONE, phoneId, -1);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700416 newMsg.getData().putBoolean("loaded_from_xml", true);
417 sendMessage(newMsg);
418 } else {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700419 // No cached config, so fetch it from a carrier app.
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800420 if (carrierPackageName != null && bindToConfigPackage(carrierPackageName,
421 phoneId, EVENT_CONNECTED_TO_CARRIER)) {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700422 sendMessageDelayed(
Rambo Wang610fdf62021-03-08 21:37:11 -0800423 obtainMessage(EVENT_BIND_CARRIER_TIMEOUT, phoneId, -1 /*arg2*/,
424 getMessageToken(phoneId)),
Jonathan Basseri930701e2015-06-11 20:56:43 -0700425 BIND_TIMEOUT_MILLIS);
426 } else {
Nathan Harold1122e3d2021-01-22 15:45:24 -0800427 // Put a stub bundle in place so that the rest of the logic continues
428 // smoothly.
Rambo Wang42026112021-04-07 20:57:28 +0000429 mConfigFromCarrierApp[phoneId] = new PersistableBundle();
Jonathan Basseri65273c82017-07-25 15:08:42 -0700430 // Send broadcast if bind fails.
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700431 broadcastConfigChangedIntent(phoneId);
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800432 loge("Bind to carrier app: " + carrierPackageName + " fails");
Nathan Harold48ac0972019-03-13 22:33:01 -0700433 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700434 }
435 }
436 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700437 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700438
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800439 case EVENT_CONNECTED_TO_CARRIER: {
Rambo Wang610fdf62021-03-08 21:37:11 -0800440 removeMessages(EVENT_BIND_CARRIER_TIMEOUT, getMessageToken(phoneId));
Jonathan Basseri65273c82017-07-25 15:08:42 -0700441 final CarrierServiceConnection conn = (CarrierServiceConnection) msg.obj;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800442 // If new service connection has been created, unbind.
Jonathan Basseri65273c82017-07-25 15:08:42 -0700443 if (mServiceConnection[phoneId] != conn || conn.service == null) {
Jordan Liu178430d2020-02-10 14:32:15 -0800444 unbindIfBound(mContext, conn, phoneId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800445 break;
446 }
chen xu02581692018-11-11 19:03:44 -0800447 final CarrierIdentifier carrierId = getCarrierIdentifierForPhoneId(phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700448 // ResultReceiver callback will execute in this Handler's thread.
449 final ResultReceiver resultReceiver =
450 new ResultReceiver(this) {
451 @Override
452 public void onReceiveResult(int resultCode, Bundle resultData) {
Jordan Liu178430d2020-02-10 14:32:15 -0800453 unbindIfBound(mContext, conn, phoneId);
Rambo Wanga9d27a52021-04-09 16:17:33 -0700454 removeMessages(EVENT_FETCH_CARRIER_TIMEOUT,
455 getMessageToken(phoneId));
Jonathan Basseri65273c82017-07-25 15:08:42 -0700456 // If new service connection has been created, this is stale.
457 if (mServiceConnection[phoneId] != conn) {
458 loge("Received response for stale request.");
459 return;
460 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700461 if (resultCode == RESULT_ERROR || resultData == null) {
462 // On error, abort config fetching.
chen xudb04c292019-03-26 17:01:15 -0700463 loge("Failed to get carrier config from carrier app: "
464 + getCarrierPackageForPhoneId(phoneId));
Jonathan Basseri65273c82017-07-25 15:08:42 -0700465 broadcastConfigChangedIntent(phoneId);
Nathan Harold48ac0972019-03-13 22:33:01 -0700466 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700467 return;
468 }
469 PersistableBundle config =
470 resultData.getParcelable(KEY_CONFIG_BUNDLE);
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100471 saveConfigToXml(getCarrierPackageForPhoneId(phoneId), "",
472 phoneId, carrierId, config);
Amit Mahajan304e92b2021-04-08 14:03:30 -0700473 if (config != null) {
474 mConfigFromCarrierApp[phoneId] = config;
475 } else {
476 logdWithLocalLog("Config from carrier app is null "
477 + "for phoneId " + phoneId);
478 // Put a stub bundle in place so that the rest of the logic
479 // continues smoothly.
480 mConfigFromCarrierApp[phoneId] = new PersistableBundle();
481 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700482 sendMessage(
483 obtainMessage(
484 EVENT_FETCH_CARRIER_DONE, phoneId, -1));
485 }
486 };
487 // Now fetch the config asynchronously from the ICarrierService.
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800488 try {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700489 ICarrierService carrierService =
490 ICarrierService.Stub.asInterface(conn.service);
491 carrierService.getCarrierConfig(carrierId, resultReceiver);
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800492 logdWithLocalLog("Fetch config for carrier app: "
chen xudb04c292019-03-26 17:01:15 -0700493 + getCarrierPackageForPhoneId(phoneId)
494 + " carrierid: " + carrierId.toString());
Jonathan Basseri65273c82017-07-25 15:08:42 -0700495 } catch (RemoteException e) {
496 loge("Failed to get carrier config: " + e.toString());
Jordan Liu178430d2020-02-10 14:32:15 -0800497 unbindIfBound(mContext, conn, phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700498 break; // So we don't set a timeout.
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800499 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700500 sendMessageDelayed(
Rambo Wang610fdf62021-03-08 21:37:11 -0800501 obtainMessage(EVENT_FETCH_CARRIER_TIMEOUT, phoneId, -1 /*arg2*/,
502 getMessageToken(phoneId)),
Jonathan Basseri65273c82017-07-25 15:08:42 -0700503 BIND_TIMEOUT_MILLIS);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800504 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700505 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800506
Jonathan Basseri930701e2015-06-11 20:56:43 -0700507 case EVENT_BIND_CARRIER_TIMEOUT:
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800508 case EVENT_FETCH_CARRIER_TIMEOUT: {
Nathan Harold1122e3d2021-01-22 15:45:24 -0800509 loge("Bind/fetch from carrier app timeout, package="
510 + getCarrierPackageForPhoneId(phoneId));
Rambo Wang610fdf62021-03-08 21:37:11 -0800511 removeMessages(EVENT_FETCH_CARRIER_TIMEOUT, getMessageToken(phoneId));
chen xuf60b3162019-05-01 21:31:05 -0700512 // If we attempted to bind to the app, but the service connection is null due to
513 // the race condition that clear config event happens before bind/fetch complete
514 // then config was cleared while we were waiting and we should not continue.
515 if (mServiceConnection[phoneId] != null) {
516 // If a ResponseReceiver callback is in the queue when this happens, we will
517 // unbind twice and throw an exception.
Jordan Liu178430d2020-02-10 14:32:15 -0800518 unbindIfBound(mContext, mServiceConnection[phoneId], phoneId);
chen xuf60b3162019-05-01 21:31:05 -0700519 broadcastConfigChangedIntent(phoneId);
520 }
Nathan Harold1122e3d2021-01-22 15:45:24 -0800521 // Put a stub bundle in place so that the rest of the logic continues smoothly.
Rambo Wang42026112021-04-07 20:57:28 +0000522 mConfigFromCarrierApp[phoneId] = new PersistableBundle();
Nathan Harold48ac0972019-03-13 22:33:01 -0700523 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri930701e2015-06-11 20:56:43 -0700524 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700525 }
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800526 case EVENT_FETCH_CARRIER_DONE: {
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700527 // If we attempted to bind to the app, but the service connection is null, then
528 // config was cleared while we were waiting and we should not continue.
529 if (!msg.getData().getBoolean("loaded_from_xml", false)
530 && mServiceConnection[phoneId] == null) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800531 break;
532 }
Nathan Harold48ac0972019-03-13 22:33:01 -0700533 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800534 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700535 }
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700536
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800537 case EVENT_CHECK_SYSTEM_UPDATE: {
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700538 SharedPreferences sharedPrefs =
539 PreferenceManager.getDefaultSharedPreferences(mContext);
540 final String lastFingerprint = sharedPrefs.getString(KEY_FINGERPRINT, null);
541 if (!Build.FINGERPRINT.equals(lastFingerprint)) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800542 logd(
Jonathan Basseri65273c82017-07-25 15:08:42 -0700543 "Build fingerprint changed. old: "
544 + lastFingerprint
545 + " new: "
546 + Build.FINGERPRINT);
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700547 clearCachedConfigForPackage(null);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700548 sharedPrefs
549 .edit()
550 .putString(KEY_FINGERPRINT, Build.FINGERPRINT)
551 .apply();
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700552 }
553 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700554 }
Nathan Harold48ac0972019-03-13 22:33:01 -0700555
556 case EVENT_SUBSCRIPTION_INFO_UPDATED:
557 broadcastConfigChangedIntent(phoneId);
558 break;
Malcolm Chen5ea18532019-10-24 19:55:44 -0700559 case EVENT_MULTI_SIM_CONFIG_CHANGED:
560 onMultiSimConfigChanged();
561 break;
Jayachandran C645ec612020-01-10 10:30:25 -0800562
563 case EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG: {
564 PersistableBundle config =
565 restoreNoSimConfigFromXml(mPlatformCarrierConfigPackage);
566
567 if (config != null) {
568 logd("Loaded no SIM config from XML. package="
569 + mPlatformCarrierConfigPackage);
570 mNoSimConfig = config;
571 sendMessage(
572 obtainMessage(
573 EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE,
574 phoneId, -1));
575 } else {
576 // No cached config, so fetch it from the default app.
577 if (bindToConfigPackage(
578 mPlatformCarrierConfigPackage,
579 phoneId,
580 EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG)) {
581 sendMessageDelayed(
582 obtainMessage(
583 EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT,
584 phoneId, -1), BIND_TIMEOUT_MILLIS);
585 } else {
586 broadcastConfigChangedIntent(phoneId, false);
587 // TODO: We *must* call unbindService even if bindService returns false.
588 // (And possibly if SecurityException was thrown.)
589 loge("binding to default app to fetch no SIM config: "
590 + mPlatformCarrierConfigPackage + " fails");
591 }
592 }
593 break;
594 }
595
596 case EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE: {
597 broadcastConfigChangedIntent(phoneId, false);
598 break;
599 }
600
601 case EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT:
602 case EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT: {
603 loge("Bind/fetch time out for no SIM config from "
604 + mPlatformCarrierConfigPackage);
605 removeMessages(EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT);
606 // If we attempted to bind to the app, but the service connection is null due to
607 // the race condition that clear config event happens before bind/fetch complete
608 // then config was cleared while we were waiting and we should not continue.
609 if (mServiceConnectionForNoSimConfig[phoneId] != null) {
610 // If a ResponseReceiver callback is in the queue when this happens, we will
611 // unbind twice and throw an exception.
612 unbindIfBoundForNoSimConfig(mContext,
613 mServiceConnectionForNoSimConfig[phoneId], phoneId);
614 }
615 broadcastConfigChangedIntent(phoneId, false);
616 break;
617 }
618
619 case EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG: {
620 removeMessages(EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT);
621 final CarrierServiceConnection conn = (CarrierServiceConnection) msg.obj;
622 // If new service connection has been created, unbind.
623 if (mServiceConnectionForNoSimConfig[phoneId] != conn || conn.service == null) {
624 unbindIfBoundForNoSimConfig(mContext, conn, phoneId);
625 break;
626 }
627
628 // ResultReceiver callback will execute in this Handler's thread.
629 final ResultReceiver resultReceiver =
630 new ResultReceiver(this) {
631 @Override
632 public void onReceiveResult(int resultCode, Bundle resultData) {
633 unbindIfBoundForNoSimConfig(mContext, conn, phoneId);
634 // If new service connection has been created, this is stale.
635 if (mServiceConnectionForNoSimConfig[phoneId] != conn) {
636 loge("Received response for stale request.");
637 return;
638 }
639 removeMessages(EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT);
640 if (resultCode == RESULT_ERROR || resultData == null) {
641 // On error, abort config fetching.
642 loge("Failed to get no SIM carrier config");
643 return;
644 }
645 PersistableBundle config =
646 resultData.getParcelable(KEY_CONFIG_BUNDLE);
647 saveNoSimConfigToXml(mPlatformCarrierConfigPackage, config);
648 mNoSimConfig = config;
649 sendMessage(
650 obtainMessage(
651 EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE,
652 phoneId, -1));
653 }
654 };
655 // Now fetch the config asynchronously from the ICarrierService.
656 try {
657 ICarrierService carrierService =
658 ICarrierService.Stub.asInterface(conn.service);
659 carrierService.getCarrierConfig(null, resultReceiver);
660 logdWithLocalLog("Fetch no sim config from default app: "
661 + mPlatformCarrierConfigPackage);
662 } catch (RemoteException e) {
663 loge("Failed to get no sim carrier config from default app: " +
664 mPlatformCarrierConfigPackage + " err: " + e.toString());
665 unbindIfBoundForNoSimConfig(mContext, conn, phoneId);
666 break; // So we don't set a timeout.
667 }
668 sendMessageDelayed(
669 obtainMessage(
670 EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT,
671 phoneId, -1), BIND_TIMEOUT_MILLIS);
672 break;
673 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800674 }
675 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700676 }
677
678 private final Handler mHandler;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800679
680 /**
681 * Constructs a CarrierConfigLoader, registers it as a service, and registers a broadcast
682 * receiver for relevant events.
683 */
Rambo Wang7e3bc122021-03-23 09:24:38 -0700684 @VisibleForTesting
685 /* package */ CarrierConfigLoader(Context context,
686 SubscriptionInfoUpdater subscriptionInfoUpdater, @NonNull Looper looper) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800687 mContext = context;
Meng Wang33ad2bc2017-03-16 20:21:20 -0700688 mPlatformCarrierConfigPackage =
689 mContext.getString(R.string.platform_carrier_config_package);
Rambo Wang7e3bc122021-03-23 09:24:38 -0700690 mHandler = new ConfigHandler(looper);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800691
Nanxi Chen3d670502016-03-17 16:32:09 -0700692 IntentFilter bootFilter = new IntentFilter();
693 bootFilter.addAction(Intent.ACTION_BOOT_COMPLETED);
694 context.registerReceiver(mBootReceiver, bootFilter);
695
Junda Liu8a8a53a2015-05-15 16:19:57 -0700696 // Register for package updates. Update app or uninstall app update will have all 3 intents,
697 // in the order or removed, added, replaced, all with extra_replace set to true.
698 IntentFilter pkgFilter = new IntentFilter();
699 pkgFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
700 pkgFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
701 pkgFilter.addAction(Intent.ACTION_PACKAGE_REPLACED);
702 pkgFilter.addDataScheme("package");
Jordan Liu5ca24762019-07-10 12:51:09 -0700703 context.registerReceiver(mPackageReceiver, pkgFilter);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800704
Malcolm Chen978dda52019-10-08 18:15:25 -0700705 int numPhones = TelephonyManager.from(context).getSupportedModemCount();
Jonathan Basseric31f1f32015-05-12 10:13:03 -0700706 mConfigFromDefaultApp = new PersistableBundle[numPhones];
707 mConfigFromCarrierApp = new PersistableBundle[numPhones];
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100708 mPersistentOverrideConfigs = new PersistableBundle[numPhones];
Hall Liu506724b2018-10-22 18:16:14 -0700709 mOverrideConfigs = new PersistableBundle[numPhones];
Rambo Wang42026112021-04-07 20:57:28 +0000710 mNoSimConfig = new PersistableBundle();
Zach Johnson36d7aab2015-05-22 15:43:00 -0700711 mServiceConnection = new CarrierServiceConnection[numPhones];
Jordan Liu178430d2020-02-10 14:32:15 -0800712 mServiceBound = new boolean[numPhones];
Junda Liu03aad762017-07-21 13:32:17 -0700713 mHasSentConfigChange = new boolean[numPhones];
Sarah Chin807d5c62020-03-30 17:21:09 -0700714 mFromSystemUnlocked = new boolean[numPhones];
Jayachandran C645ec612020-01-10 10:30:25 -0800715 mServiceConnectionForNoSimConfig = new CarrierServiceConnection[numPhones];
716 mServiceBoundForNoSimConfig = new boolean[numPhones];
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800717 // Make this service available through ServiceManager.
Peter Wangc035ce42020-01-08 21:00:22 -0800718 TelephonyFrameworkInitializer
719 .getTelephonyServiceManager().getCarrierConfigServiceRegisterer().register(this);
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800720 logd("CarrierConfigLoader has started");
Rambo Wang7e3bc122021-03-23 09:24:38 -0700721 mSubscriptionInfoUpdater = subscriptionInfoUpdater;
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700722 mHandler.sendEmptyMessage(EVENT_CHECK_SYSTEM_UPDATE);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800723 }
724
725 /**
726 * Initialize the singleton CarrierConfigLoader instance.
727 *
728 * This is only done once, at startup, from {@link com.android.phone.PhoneApp#onCreate}.
729 */
Rambo Wang7e3bc122021-03-23 09:24:38 -0700730 /* package */ static CarrierConfigLoader init(Context context) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800731 synchronized (CarrierConfigLoader.class) {
732 if (sInstance == null) {
Rambo Wang7e3bc122021-03-23 09:24:38 -0700733 sInstance = new CarrierConfigLoader(context,
734 PhoneFactory.getSubscriptionInfoUpdater(), Looper.myLooper());
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800735 } else {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700736 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800737 }
738 return sInstance;
739 }
740 }
741
Rambo Wang7e3bc122021-03-23 09:24:38 -0700742 @VisibleForTesting
743 /* package */ void clearConfigForPhone(int phoneId, boolean fetchNoSimConfig) {
Malcolm Chen5ea18532019-10-24 19:55:44 -0700744 /* Ignore clear configuration request if device is being shutdown. */
745 Phone phone = PhoneFactory.getPhone(phoneId);
746 if (phone != null) {
747 if (phone.isShuttingDown()) {
748 return;
749 }
750 }
751
752 mConfigFromDefaultApp[phoneId] = null;
753 mConfigFromCarrierApp[phoneId] = null;
754 mServiceConnection[phoneId] = null;
755 mHasSentConfigChange[phoneId] = false;
756
Jayachandran C645ec612020-01-10 10:30:25 -0800757 if (fetchNoSimConfig) {
758 // To fetch no SIM config
759 mHandler.sendMessage(
760 mHandler.obtainMessage(
761 EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG, phoneId, -1));
762 }
Malcolm Chen5ea18532019-10-24 19:55:44 -0700763 }
764
Nathan Harold48ac0972019-03-13 22:33:01 -0700765 private void notifySubscriptionInfoUpdater(int phoneId) {
766 String configPackagename;
767 PersistableBundle configToSend;
768 int carrierId = getSpecificCarrierIdForPhoneId(phoneId);
769 // Prefer the carrier privileged carrier app, but if there is not one, use the platform
770 // default carrier app.
771 if (mConfigFromCarrierApp[phoneId] != null) {
772 configPackagename = getCarrierPackageForPhoneId(phoneId);
773 configToSend = mConfigFromCarrierApp[phoneId];
774 } else {
775 configPackagename = mPlatformCarrierConfigPackage;
776 configToSend = mConfigFromDefaultApp[phoneId];
777 }
Nazanin Bakhshi6fcc3342019-09-18 17:54:01 -0700778
Malcolm Chenefafd1c2020-02-20 13:27:08 -0800779 if (configToSend == null) {
Rambo Wang42026112021-04-07 20:57:28 +0000780 configToSend = new PersistableBundle();
Malcolm Chenefafd1c2020-02-20 13:27:08 -0800781 }
782
Nazanin Bakhshi6fcc3342019-09-18 17:54:01 -0700783 // mOverrideConfigs is for testing. And it will override current configs.
784 PersistableBundle config = mOverrideConfigs[phoneId];
785 if (config != null) {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +0100786 configToSend = new PersistableBundle(configToSend);
Nazanin Bakhshi6fcc3342019-09-18 17:54:01 -0700787 configToSend.putAll(config);
788 }
789
Nathan Harold48ac0972019-03-13 22:33:01 -0700790 mSubscriptionInfoUpdater.updateSubscriptionByCarrierConfigAndNotifyComplete(
791 phoneId, configPackagename, configToSend,
792 mHandler.obtainMessage(EVENT_SUBSCRIPTION_INFO_UPDATED, phoneId, -1));
793 }
794
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800795 private void broadcastConfigChangedIntent(int phoneId) {
Amit Mahajanf8088ab2018-03-02 15:24:07 -0800796 broadcastConfigChangedIntent(phoneId, true);
797 }
798
799 private void broadcastConfigChangedIntent(int phoneId, boolean addSubIdExtra) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800800 Intent intent = new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Christopher Tate38f55eb2017-02-14 14:43:49 -0800801 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT |
chen xuf9db49f2019-03-31 23:04:42 -0700802 Intent.FLAG_RECEIVER_FOREGROUND);
Qiongcheng Luoe7de61b2018-08-06 10:20:09 +0800803 if (addSubIdExtra) {
804 int simApplicationState = TelephonyManager.SIM_STATE_UNKNOWN;
805 int[] subIds = SubscriptionManager.getSubId(phoneId);
806 if (!ArrayUtils.isEmpty(subIds)) {
807 TelephonyManager telMgr = TelephonyManager.from(mContext)
808 .createForSubscriptionId(subIds[0]);
809 simApplicationState = telMgr.getSimApplicationState();
810 }
Malcolm Chenf7635ec2020-04-15 15:45:00 -0700811 logd("Broadcast CARRIER_CONFIG_CHANGED for phone " + phoneId
812 + " simApplicationState " + simApplicationState);
Qiongcheng Luoe7de61b2018-08-06 10:20:09 +0800813 // Include subId/carrier id extra only if SIM records are loaded
814 if (simApplicationState != TelephonyManager.SIM_STATE_UNKNOWN
815 && simApplicationState != TelephonyManager.SIM_STATE_NOT_READY) {
816 SubscriptionManager.putPhoneIdAndSubIdExtra(intent, phoneId);
817 intent.putExtra(TelephonyManager.EXTRA_SPECIFIC_CARRIER_ID,
818 getSpecificCarrierIdForPhoneId(phoneId));
819 intent.putExtra(TelephonyManager.EXTRA_CARRIER_ID, getCarrierIdForPhoneId(phoneId));
820 }
Amit Mahajanf8088ab2018-03-02 15:24:07 -0800821 }
Amit Mahajanb33bcda2018-01-24 12:56:44 -0800822 intent.putExtra(CarrierConfigManager.EXTRA_SLOT_INDEX, phoneId);
Sarah Chin807d5c62020-03-30 17:21:09 -0700823 intent.putExtra(CarrierConfigManager.EXTRA_REBROADCAST_ON_UNLOCK,
824 mFromSystemUnlocked[phoneId]);
Meng Wang97a6a462020-01-23 16:22:16 -0800825 mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
Jack Yue9e95be2020-03-22 10:56:06 -0700826 int[] subIds = SubscriptionManager.getSubId(phoneId);
827 if (subIds != null && subIds.length > 0) {
828 logd("Broadcast CARRIER_CONFIG_CHANGED for phone " + phoneId + ", subId=" + subIds[0]);
829 } else {
830 logd("Broadcast CARRIER_CONFIG_CHANGED for phone " + phoneId);
831 }
Junda Liu03aad762017-07-21 13:32:17 -0700832 mHasSentConfigChange[phoneId] = true;
Sarah Chin807d5c62020-03-30 17:21:09 -0700833 mFromSystemUnlocked[phoneId] = false;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800834 }
835
836 /** Binds to the default or carrier config app. */
837 private boolean bindToConfigPackage(String pkgName, int phoneId, int eventId) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800838 logdWithLocalLog("Binding to " + pkgName + " for phone " + phoneId);
Zach Johnsonfca8a8d2015-06-19 18:21:37 -0700839 Intent carrierService = new Intent(CarrierService.CARRIER_SERVICE_INTERFACE);
Zach Johnson36d7aab2015-05-22 15:43:00 -0700840 carrierService.setPackage(pkgName);
Jayachandran C645ec612020-01-10 10:30:25 -0800841 CarrierServiceConnection serviceConnection = new CarrierServiceConnection(
842 phoneId, pkgName, eventId);
843 if (eventId == EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG) {
844 mServiceConnectionForNoSimConfig[phoneId] = serviceConnection;
845 } else {
846 mServiceConnection[phoneId] = serviceConnection;
847 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800848 try {
Jayachandran C645ec612020-01-10 10:30:25 -0800849 if (mContext.bindService(carrierService, serviceConnection,
Jordan Liu178430d2020-02-10 14:32:15 -0800850 Context.BIND_AUTO_CREATE)) {
Jayachandran C645ec612020-01-10 10:30:25 -0800851 if (eventId == EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG) {
852 mServiceBoundForNoSimConfig[phoneId] = true;
853 } else {
854 mServiceBound[phoneId] = true;
855 }
Jordan Liu178430d2020-02-10 14:32:15 -0800856 return true;
857 } else {
858 return false;
859 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800860 } catch (SecurityException ex) {
861 return false;
862 }
863 }
864
Rambo Wang7e3bc122021-03-23 09:24:38 -0700865 @VisibleForTesting
866 /* package */ CarrierIdentifier getCarrierIdentifierForPhoneId(int phoneId) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800867 String mcc = "";
868 String mnc = "";
869 String imsi = "";
870 String gid1 = "";
871 String gid2 = "";
872 String spn = TelephonyManager.from(mContext).getSimOperatorNameForPhone(phoneId);
873 String simOperator = TelephonyManager.from(mContext).getSimOperatorNumericForPhone(phoneId);
chen xu02581692018-11-11 19:03:44 -0800874 int carrierId = TelephonyManager.UNKNOWN_CARRIER_ID;
chen xua31f22b2019-03-06 15:28:50 -0800875 int specificCarrierId = TelephonyManager.UNKNOWN_CARRIER_ID;
Jonathan Basseri1fa437c2015-04-20 11:08:18 -0700876 // A valid simOperator should be 5 or 6 digits, depending on the length of the MNC.
877 if (simOperator != null && simOperator.length() >= 3) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800878 mcc = simOperator.substring(0, 3);
879 mnc = simOperator.substring(3);
880 }
881 Phone phone = PhoneFactory.getPhone(phoneId);
882 if (phone != null) {
883 imsi = phone.getSubscriberId();
884 gid1 = phone.getGroupIdLevel1();
Junda Liu73183532015-05-14 13:55:40 -0700885 gid2 = phone.getGroupIdLevel2();
chen xu02581692018-11-11 19:03:44 -0800886 carrierId = phone.getCarrierId();
chen xua31f22b2019-03-06 15:28:50 -0800887 specificCarrierId = phone.getSpecificCarrierId();
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800888 }
chen xua31f22b2019-03-06 15:28:50 -0800889 return new CarrierIdentifier(mcc, mnc, spn, imsi, gid1, gid2, carrierId, specificCarrierId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800890 }
891
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700892 /** Returns the package name of a priveleged carrier app, or null if there is none. */
Nathan Harold1122e3d2021-01-22 15:45:24 -0800893 @Nullable
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700894 private String getCarrierPackageForPhoneId(int phoneId) {
895 List<String> carrierPackageNames = TelephonyManager.from(mContext)
896 .getCarrierPackageNamesForIntentAndPhone(
Zach Johnsonfca8a8d2015-06-19 18:21:37 -0700897 new Intent(CarrierService.CARRIER_SERVICE_INTERFACE), phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700898 if (carrierPackageNames != null && carrierPackageNames.size() > 0) {
899 return carrierPackageNames.get(0);
900 } else {
901 return null;
902 }
903 }
904
905 private String getIccIdForPhoneId(int phoneId) {
906 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
907 return null;
908 }
909 Phone phone = PhoneFactory.getPhone(phoneId);
910 if (phone == null) {
911 return null;
912 }
913 return phone.getIccSerialNumber();
914 }
915
chen xu02581692018-11-11 19:03:44 -0800916 /**
chen xua31f22b2019-03-06 15:28:50 -0800917 * Get the sim specific carrier id {@link TelephonyManager#getSimSpecificCarrierId()}
chen xu02581692018-11-11 19:03:44 -0800918 */
chen xua31f22b2019-03-06 15:28:50 -0800919 private int getSpecificCarrierIdForPhoneId(int phoneId) {
Naina Nalluri86fc7b02018-08-03 10:38:30 -0700920 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
chen xu02581692018-11-11 19:03:44 -0800921 return TelephonyManager.UNKNOWN_CARRIER_ID;
Naina Nalluri86fc7b02018-08-03 10:38:30 -0700922 }
923 Phone phone = PhoneFactory.getPhone(phoneId);
924 if (phone == null) {
chen xu02581692018-11-11 19:03:44 -0800925 return TelephonyManager.UNKNOWN_CARRIER_ID;
Naina Nalluri86fc7b02018-08-03 10:38:30 -0700926 }
chen xua31f22b2019-03-06 15:28:50 -0800927 return phone.getSpecificCarrierId();
chen xu02581692018-11-11 19:03:44 -0800928 }
929
930 /**
931 * Get the sim carrier id {@link TelephonyManager#getSimCarrierId() }
932 */
933 private int getCarrierIdForPhoneId(int phoneId) {
934 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
935 return TelephonyManager.UNKNOWN_CARRIER_ID;
Naina Nalluri86fc7b02018-08-03 10:38:30 -0700936 }
chen xu02581692018-11-11 19:03:44 -0800937 Phone phone = PhoneFactory.getPhone(phoneId);
938 if (phone == null) {
939 return TelephonyManager.UNKNOWN_CARRIER_ID;
940 }
941 return phone.getCarrierId();
Naina Nalluri86fc7b02018-08-03 10:38:30 -0700942 }
943
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700944 /**
945 * Writes a bundle to an XML file.
946 *
chen xu02581692018-11-11 19:03:44 -0800947 * The bundle will be written to a file named after the package name, ICCID and
chen xua31f22b2019-03-06 15:28:50 -0800948 * specific carrier id {@link TelephonyManager#getSimSpecificCarrierId()}. the same carrier
chen xu02581692018-11-11 19:03:44 -0800949 * should have a single copy of XML file named after carrier id. However, it's still possible
950 * that platform doesn't recognize the current sim carrier, we will use iccid + carrierid as
951 * the canonical file name. carrierid can also handle the cases SIM OTA resolves to different
952 * carrier while iccid remains the same.
953 *
954 * The file can be restored later with {@link @restoreConfigFromXml}. The XML output will
955 * include the bundle and the current version of the specified package.
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700956 *
957 * In case of errors or invalid input, no file will be written.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700958 *
Jayachandran C645ec612020-01-10 10:30:25 -0800959 * @param packageName the name of the package from which we fetched this bundle.
960 * @param extraString An extra string to be used in the XML file name.
961 * @param phoneId the phone ID.
962 * @param carrierId contains all carrier-identifying information.
963 * @param config the bundle to be written. Null will be treated as an empty bundle.
964 * @param isNoSimConfig whether this is invoked for noSimConfig or not.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700965 */
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100966 private void saveConfigToXml(String packageName, @NonNull String extraString, int phoneId,
Jayachandran C645ec612020-01-10 10:30:25 -0800967 CarrierIdentifier carrierId, PersistableBundle config, boolean isNoSimConfig) {
968 if (packageName == null) {
969 loge("Cannot save config with null packageName");
Yuchen Dongc15afed2018-04-26 17:05:22 +0800970 return;
971 }
972
Jayachandran C645ec612020-01-10 10:30:25 -0800973 String fileName;
974 if (isNoSimConfig) {
975 fileName = getFilenameForNoSimConfig(packageName);
976 } else {
977 if (SubscriptionManager.getSimStateForSlotIndex(phoneId)
978 != TelephonyManager.SIM_STATE_LOADED) {
979 loge("Skip save config because SIM records are not loaded.");
980 return;
981 }
982
983 final String iccid = getIccIdForPhoneId(phoneId);
984 final int cid = carrierId.getSpecificCarrierId();
985 if (iccid == null) {
986 loge("Cannot save config with null iccid.");
987 return;
988 }
989 fileName = getFilenameForConfig(packageName, extraString, iccid, cid);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700990 }
Jayachandran C645ec612020-01-10 10:30:25 -0800991
Junda Liu02596502016-11-15 13:46:43 -0800992 // b/32668103 Only save to file if config isn't empty.
993 // In case of failure, not caching an empty bundle will
994 // try loading config again on next power on or sim loaded.
995 // Downside is for genuinely empty bundle, will bind and load
996 // on every power on.
997 if (config == null || config.isEmpty()) {
998 return;
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700999 }
1000
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001001 final String version = getPackageVersion(packageName);
1002 if (version == null) {
1003 loge("Failed to get package version for: " + packageName);
1004 return;
1005 }
1006
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001007 logdWithLocalLog(
1008 "Save config to xml, packagename: " + packageName + " phoneId: " + phoneId);
chen xudb04c292019-03-26 17:01:15 -07001009
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001010 FileOutputStream outFile = null;
1011 try {
Jayachandran C645ec612020-01-10 10:30:25 -08001012 outFile = new FileOutputStream(new File(mContext.getFilesDir(), fileName));
Meng Wang0f6b2ea2020-01-06 18:31:16 -08001013 config.putString(KEY_VERSION, version);
1014 config.writeToStream(outFile);
1015 outFile.flush();
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001016 outFile.close();
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001017 } catch (IOException e) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001018 loge(e.toString());
1019 }
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001020 }
1021
Rambo Wang7e3bc122021-03-23 09:24:38 -07001022 @VisibleForTesting
1023 /* package */ void saveConfigToXml(String packageName, @NonNull String extraString, int phoneId,
Jayachandran C645ec612020-01-10 10:30:25 -08001024 CarrierIdentifier carrierId, PersistableBundle config) {
1025 saveConfigToXml(packageName, extraString, phoneId, carrierId, config, false);
1026 }
1027
Rambo Wang7e3bc122021-03-23 09:24:38 -07001028 @VisibleForTesting
1029 /* package */ void saveNoSimConfigToXml(String packageName, PersistableBundle config) {
Jayachandran C645ec612020-01-10 10:30:25 -08001030 saveConfigToXml(packageName, "", -1, null, config, true);
1031 }
1032
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001033 /**
1034 * Reads a bundle from an XML file.
1035 *
1036 * This restores a bundle that was written with {@link #saveConfigToXml}. This returns the saved
Yuchen Dongc15afed2018-04-26 17:05:22 +08001037 * config bundle for the given package and phone ID.
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001038 *
1039 * In case of errors, or if the saved config is from a different package version than the
1040 * current version, then null will be returned.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001041 *
Jayachandran C645ec612020-01-10 10:30:25 -08001042 * @param packageName the name of the package from which we fetched this bundle.
1043 * @param extraString An extra string to be used in the XML file name.
1044 * @param phoneId the phone ID.
1045 * @param isNoSimConfig whether this is invoked for noSimConfig or not.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001046 * @return the bundle from the XML file. Returns null if there is no saved config, the saved
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001047 * version does not match, or reading config fails.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001048 */
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001049 private PersistableBundle restoreConfigFromXml(String packageName, @NonNull String extraString,
Jayachandran C645ec612020-01-10 10:30:25 -08001050 int phoneId, boolean isNoSimConfig) {
1051 if (packageName == null) {
1052 loge("Cannot restore config with null packageName");
1053 }
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001054 final String version = getPackageVersion(packageName);
1055 if (version == null) {
1056 loge("Failed to get package version for: " + packageName);
1057 return null;
1058 }
Yuchen Dongc15afed2018-04-26 17:05:22 +08001059
Jayachandran C645ec612020-01-10 10:30:25 -08001060 String fileName;
1061 if (isNoSimConfig) {
1062 fileName = getFilenameForNoSimConfig(packageName);
1063 } else {
1064 if (SubscriptionManager.getSimStateForSlotIndex(phoneId)
1065 != TelephonyManager.SIM_STATE_LOADED) {
1066 loge("Skip restore config because SIM records are not loaded.");
1067 return null;
1068 }
1069
1070 final String iccid = getIccIdForPhoneId(phoneId);
1071 final int cid = getSpecificCarrierIdForPhoneId(phoneId);
1072 if (iccid == null) {
1073 loge("Cannot restore config with null iccid.");
1074 return null;
1075 }
1076 fileName = getFilenameForConfig(packageName, extraString, iccid, cid);
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001077 }
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001078
1079 PersistableBundle restoredBundle = null;
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001080 File file = null;
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001081 FileInputStream inFile = null;
1082 try {
Jayachandran C645ec612020-01-10 10:30:25 -08001083 file = new File(mContext.getFilesDir(),fileName);
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001084 inFile = new FileInputStream(file);
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001085
Meng Wang0f6b2ea2020-01-06 18:31:16 -08001086 restoredBundle = PersistableBundle.readFromStream(inFile);
1087 String savedVersion = restoredBundle.getString(KEY_VERSION);
1088 restoredBundle.remove(KEY_VERSION);
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001089
Meng Wang0f6b2ea2020-01-06 18:31:16 -08001090 if (!version.equals(savedVersion)) {
1091 loge("Saved version mismatch: " + version + " vs " + savedVersion);
1092 restoredBundle = null;
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001093 }
Meng Wang0f6b2ea2020-01-06 18:31:16 -08001094
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001095 inFile.close();
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001096 } catch (FileNotFoundException e) {
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001097 // Missing file is normal occurrence that might occur with a new sim or when restoring
1098 // an override file during boot and should not be treated as an error.
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001099 if (file != null) logd("File not found: " + file.getPath());
1100 } catch (IOException e) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001101 loge(e.toString());
1102 }
1103
1104 return restoredBundle;
1105 }
1106
Jayachandran C645ec612020-01-10 10:30:25 -08001107 private PersistableBundle restoreConfigFromXml(String packageName, @NonNull String extraString,
1108 int phoneId) {
1109 return restoreConfigFromXml(packageName, extraString, phoneId, false);
1110 }
1111
1112 private PersistableBundle restoreNoSimConfigFromXml(String packageName) {
1113 return restoreConfigFromXml(packageName, "", -1, true);
1114 }
1115
Junda Liu8a8a53a2015-05-15 16:19:57 -07001116 /**
Jonathan Basseri7697cae2015-07-06 15:49:23 -07001117 * Clears cached carrier config.
1118 * This deletes all saved XML files associated with the given package name. If packageName is
1119 * null, then it deletes all saved XML files.
1120 *
1121 * @param packageName the name of a carrier package, or null if all cached config should be
1122 * cleared.
1123 * @return true iff one or more files were deleted.
Junda Liu8a8a53a2015-05-15 16:19:57 -07001124 */
Jonathan Basseri7697cae2015-07-06 15:49:23 -07001125 private boolean clearCachedConfigForPackage(final String packageName) {
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001126 File dir = mContext.getFilesDir();
1127 File[] packageFiles = dir.listFiles(new FilenameFilter() {
1128 public boolean accept(File dir, String filename) {
Jonathan Basseri7697cae2015-07-06 15:49:23 -07001129 if (packageName != null) {
1130 return filename.startsWith("carrierconfig-" + packageName + "-");
1131 } else {
1132 return filename.startsWith("carrierconfig-");
1133 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001134 }
1135 });
Junda Liu8a8a53a2015-05-15 16:19:57 -07001136 if (packageFiles == null || packageFiles.length < 1) return false;
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001137 for (File f : packageFiles) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001138 logd("Deleting " + f.getName());
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001139 f.delete();
1140 }
Junda Liu8a8a53a2015-05-15 16:19:57 -07001141 return true;
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001142 }
1143
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001144 /** Builds a canonical file name for a config file. */
Jayachandran C645ec612020-01-10 10:30:25 -08001145 private static String getFilenameForConfig(
1146 @NonNull String packageName, @NonNull String extraString,
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001147 @NonNull String iccid, int cid) {
chen xu02581692018-11-11 19:03:44 -08001148 // the same carrier should have a single copy of XML file named after carrier id.
1149 // However, it's still possible that platform doesn't recognize the current sim carrier,
1150 // we will use iccid + carrierid as the canonical file name. carrierid can also handle the
1151 // cases SIM OTA resolves to different carrier while iccid remains the same.
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001152 return "carrierconfig-" + packageName + extraString + "-" + iccid + "-" + cid + ".xml";
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001153 }
1154
Jayachandran C645ec612020-01-10 10:30:25 -08001155 /** Builds a canonical file name for no SIM config file. */
1156 private String getFilenameForNoSimConfig(@NonNull String packageName) {
1157 return "carrierconfig-" + packageName + "-" + "nosim" + ".xml";
1158 }
1159
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001160 /** Return the current version code of a package, or null if the name is not found. */
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001161 private String getPackageVersion(String packageName) {
1162 try {
1163 PackageInfo info = mContext.getPackageManager().getPackageInfo(packageName, 0);
Dianne Hackbornb76ab202017-11-28 17:44:50 -08001164 return Long.toString(info.getLongVersionCode());
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001165 } catch (PackageManager.NameNotFoundException e) {
1166 return null;
1167 }
1168 }
1169
Jonathan Basseri65273c82017-07-25 15:08:42 -07001170 /**
1171 * Read up to date config.
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001172 *
1173 * This reads config bundles for the given phoneId. That means getting the latest bundle from
1174 * the default app and a privileged carrier app, if present. This will not bind to an app if we
1175 * have a saved config file to use instead.
1176 */
1177 private void updateConfigForPhoneId(int phoneId) {
Jonathan Basseri65273c82017-07-25 15:08:42 -07001178 mHandler.sendMessage(mHandler.obtainMessage(EVENT_DO_FETCH_DEFAULT, phoneId, -1));
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001179 }
1180
Malcolm Chen5ea18532019-10-24 19:55:44 -07001181 private void onMultiSimConfigChanged() {
1182 for (int i = TelephonyManager.from(mContext).getActiveModemCount();
1183 i < mConfigFromDefaultApp.length; i++) {
1184 clearConfigForPhone(i, false);
1185 }
1186 }
1187
Hall Liu506724b2018-10-22 18:16:14 -07001188 @Override
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001189 @NonNull
Rambo Wangd2b004b2021-03-30 10:10:23 -07001190 public PersistableBundle getConfigForSubId(int subscriptionId, String callingPackage) {
1191 return getConfigForSubIdWithFeature(subscriptionId, callingPackage, null);
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001192 }
1193
1194 @Override
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001195 @NonNull
Rambo Wangd2b004b2021-03-30 10:10:23 -07001196 public PersistableBundle getConfigForSubIdWithFeature(int subscriptionId, String callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001197 String callingFeatureId) {
Rambo Wangd2b004b2021-03-30 10:10:23 -07001198 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mContext, subscriptionId,
1199 callingPackage, callingFeatureId, "getCarrierConfig")) {
Rambo Wang42026112021-04-07 20:57:28 +00001200 return new PersistableBundle();
Amit Mahajan40b3fa52015-07-14 10:27:19 -07001201 }
Jeff Davidsona8e4e242018-03-15 17:16:18 -07001202
Rambo Wangd2b004b2021-03-30 10:10:23 -07001203 int phoneId = SubscriptionManager.getPhoneId(subscriptionId);
Jonathan Basseric31f1f32015-05-12 10:13:03 -07001204 PersistableBundle retConfig = CarrierConfigManager.getDefaultConfig();
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001205 if (SubscriptionManager.isValidPhoneId(phoneId)) {
Jonathan Basseric31f1f32015-05-12 10:13:03 -07001206 PersistableBundle config = mConfigFromDefaultApp[phoneId];
yinxuc5e27622017-11-29 15:08:50 -08001207 if (config != null) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001208 retConfig.putAll(config);
yinxuc5e27622017-11-29 15:08:50 -08001209 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001210 config = mConfigFromCarrierApp[phoneId];
yinxuc5e27622017-11-29 15:08:50 -08001211 if (config != null) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001212 retConfig.putAll(config);
yinxuc5e27622017-11-29 15:08:50 -08001213 }
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001214 config = mPersistentOverrideConfigs[phoneId];
1215 if (config != null) {
1216 retConfig.putAll(config);
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001217 }
Hall Liu506724b2018-10-22 18:16:14 -07001218 config = mOverrideConfigs[phoneId];
1219 if (config != null) {
1220 retConfig.putAll(config);
Hall Liu506724b2018-10-22 18:16:14 -07001221 }
Nathan Harold1122e3d2021-01-22 15:45:24 -08001222 // Ignore the theoretical case of the default app not being present since that won't
1223 // work in CarrierConfigLoader today.
1224 final boolean allConfigsApplied =
1225 (mConfigFromCarrierApp[phoneId] != null
1226 || getCarrierPackageForPhoneId(phoneId) == null)
1227 && mConfigFromDefaultApp[phoneId] != null;
1228 retConfig.putBoolean(
1229 CarrierConfigManager.KEY_CARRIER_CONFIG_APPLIED_BOOL, allConfigsApplied);
Jayachandran C645ec612020-01-10 10:30:25 -08001230 } else {
1231 if (mNoSimConfig != null) {
1232 retConfig.putAll(mNoSimConfig);
1233 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001234 }
1235 return retConfig;
1236 }
1237
1238 @Override
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001239 public void overrideConfig(int subscriptionId, @Nullable PersistableBundle overrides,
1240 boolean persistent) {
Hall Liu506724b2018-10-22 18:16:14 -07001241 mContext.enforceCallingOrSelfPermission(
1242 android.Manifest.permission.MODIFY_PHONE_STATE, null);
Brad Ebingerf6281ad2019-04-25 11:02:04 -07001243 //TODO: Also check for SHELL UID to restrict this method to testing only (b/131326259)
Hall Liu506724b2018-10-22 18:16:14 -07001244 int phoneId = SubscriptionManager.getPhoneId(subscriptionId);
1245 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001246 logd("Ignore invalid phoneId: " + phoneId + " for subId: " + subscriptionId);
Rambo Wangd2b004b2021-03-30 10:10:23 -07001247 throw new IllegalArgumentException(
1248 "Invalid phoneId " + phoneId + " for subId " + subscriptionId);
Hall Liu506724b2018-10-22 18:16:14 -07001249 }
Rambo Wang38eb5cd2021-03-29 16:39:14 -07001250 // Post to run on handler thread on which all states should be confined.
1251 mHandler.post(() -> {
1252 overrideConfig(mOverrideConfigs, phoneId, overrides);
Hall Liu506724b2018-10-22 18:16:14 -07001253
Rambo Wang38eb5cd2021-03-29 16:39:14 -07001254 if (persistent) {
1255 overrideConfig(mPersistentOverrideConfigs, phoneId, overrides);
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001256
Rambo Wang38eb5cd2021-03-29 16:39:14 -07001257 if (overrides != null) {
1258 final CarrierIdentifier carrierId = getCarrierIdentifierForPhoneId(phoneId);
1259 saveConfigToXml(mPlatformCarrierConfigPackage, OVERRIDE_PACKAGE_ADDITION,
1260 phoneId,
1261 carrierId, mPersistentOverrideConfigs[phoneId]);
1262 } else {
1263 final String iccid = getIccIdForPhoneId(phoneId);
1264 final int cid = getSpecificCarrierIdForPhoneId(phoneId);
1265 String fileName = getFilenameForConfig(mPlatformCarrierConfigPackage,
1266 OVERRIDE_PACKAGE_ADDITION, iccid, cid);
1267 File fileToDelete = new File(mContext.getFilesDir(), fileName);
1268 fileToDelete.delete();
1269 }
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001270 }
Rambo Wang38eb5cd2021-03-29 16:39:14 -07001271 notifySubscriptionInfoUpdater(phoneId);
1272 });
Hall Liu506724b2018-10-22 18:16:14 -07001273 }
1274
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001275 private void overrideConfig(@NonNull PersistableBundle[] currentOverrides, int phoneId,
1276 @Nullable PersistableBundle overrides) {
1277 if (overrides == null) {
Rambo Wang42026112021-04-07 20:57:28 +00001278 currentOverrides[phoneId] = new PersistableBundle();
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001279 } else if (currentOverrides[phoneId] == null) {
1280 currentOverrides[phoneId] = overrides;
1281 } else {
1282 currentOverrides[phoneId].putAll(overrides);
1283 }
1284 }
1285
Hall Liu506724b2018-10-22 18:16:14 -07001286 @Override
Rambo Wangd2b004b2021-03-30 10:10:23 -07001287 public void notifyConfigChangedForSubId(int subscriptionId) {
Jordan Liud7d57fe2019-04-16 12:29:43 -07001288 // Requires the calling app to be either a carrier privileged app for this subId or
Junda Liufbd2bcb2016-06-15 11:15:42 -07001289 // system privileged app with MODIFY_PHONE_STATE permission.
Rambo Wangd2b004b2021-03-30 10:10:23 -07001290 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mContext,
1291 subscriptionId, "Require carrier privileges or MODIFY_PHONE_STATE permission.");
1292
1293 int phoneId = SubscriptionManager.getPhoneId(subscriptionId);
1294 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
1295 logd("Ignore invalid phoneId: " + phoneId + " for subId: " + subscriptionId);
1296 throw new IllegalArgumentException(
1297 "Invalid phoneId " + phoneId + " for subId " + subscriptionId);
1298 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001299
1300 // This method should block until deleting has completed, so that an error which prevents us
1301 // from clearing the cache is passed back to the carrier app. With the files successfully
1302 // deleted, this can return and we will eventually bind to the carrier app.
Jordan Liud7d57fe2019-04-16 12:29:43 -07001303 String callingPackageName = mContext.getPackageManager().getNameForUid(
1304 Binder.getCallingUid());
Jonathan Basseri7697cae2015-07-06 15:49:23 -07001305 clearCachedConfigForPackage(callingPackageName);
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001306 updateConfigForPhoneId(phoneId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001307 }
1308
1309 @Override
1310 public void updateConfigForPhoneId(int phoneId, String simState) {
Junda Liu1f2b34d2015-06-18 15:26:56 -07001311 mContext.enforceCallingOrSelfPermission(
1312 android.Manifest.permission.MODIFY_PHONE_STATE, null);
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001313 logdWithLocalLog("Update config for phoneId: " + phoneId + " simState: " + simState);
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001314 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
Rambo Wangd2b004b2021-03-30 10:10:23 -07001315 throw new IllegalArgumentException("Invalid phoneId: " + phoneId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001316 }
1317 // requires Java 7 for switch on string.
1318 switch (simState) {
1319 case IccCardConstants.INTENT_VALUE_ICC_ABSENT:
1320 case IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR:
Junda Liu6f5fddf2016-05-24 16:14:41 -07001321 case IccCardConstants.INTENT_VALUE_ICC_CARD_RESTRICTED:
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001322 case IccCardConstants.INTENT_VALUE_ICC_UNKNOWN:
Malcolm Chendb66de12019-12-09 18:57:07 -08001323 case IccCardConstants.INTENT_VALUE_ICC_NOT_READY:
Junda Liu9f2d2712015-05-15 14:22:45 -07001324 mHandler.sendMessage(mHandler.obtainMessage(EVENT_CLEAR_CONFIG, phoneId, -1));
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001325 break;
1326 case IccCardConstants.INTENT_VALUE_ICC_LOADED:
1327 case IccCardConstants.INTENT_VALUE_ICC_LOCKED:
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001328 updateConfigForPhoneId(phoneId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001329 break;
1330 }
1331 }
1332
Junda Liu43d723a2015-05-12 17:23:45 -07001333 @Override
Jeff Sharkeya6fcfed2017-07-20 14:18:39 -06001334 public String getDefaultCarrierServicePackageName() {
Shuo Qianefdb7962019-12-19 15:54:27 -08001335 mContext.enforceCallingOrSelfPermission(
1336 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
1337 "getDefaultCarrierServicePackageName");
Jeff Sharkeya6fcfed2017-07-20 14:18:39 -06001338 return mPlatformCarrierConfigPackage;
1339 }
1340
Rambo Wang7e3bc122021-03-23 09:24:38 -07001341 @VisibleForTesting
1342 /* package */ Handler getHandler() {
1343 return mHandler;
1344 }
1345
1346 @VisibleForTesting
1347 /* package */ PersistableBundle getConfigFromDefaultApp(int phoneId) {
1348 return mConfigFromDefaultApp[phoneId];
1349 }
1350
1351 @VisibleForTesting
1352 /* package */ PersistableBundle getConfigFromCarrierApp(int phoneId) {
1353 return mConfigFromCarrierApp[phoneId];
1354 }
1355
1356 @VisibleForTesting
1357 /* package */ PersistableBundle getNoSimConfig() {
1358 return mNoSimConfig;
1359 }
1360
1361 @VisibleForTesting
1362 /* package */ PersistableBundle getOverrideConfig(int phoneId) {
1363 return mOverrideConfigs[phoneId];
1364 }
1365
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001366 private void unbindIfBound(Context context, CarrierServiceConnection conn,
1367 int phoneId) {
1368 if (mServiceBound[phoneId]) {
1369 mServiceBound[phoneId] = false;
1370 context.unbindService(conn);
1371 }
1372 }
1373
Jayachandran C645ec612020-01-10 10:30:25 -08001374 private void unbindIfBoundForNoSimConfig(Context context, CarrierServiceConnection conn,
1375 int phoneId) {
1376 if (mServiceBoundForNoSimConfig[phoneId]) {
1377 mServiceBoundForNoSimConfig[phoneId] = false;
1378 context.unbindService(conn);
1379 }
1380 }
1381
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001382 /**
Rambo Wang610fdf62021-03-08 21:37:11 -08001383 * Returns a boxed Integer object for phoneId, services as message token to distinguish messages
1384 * with same code when calling {@link Handler#removeMessages(int, Object)}.
1385 */
1386 private Integer getMessageToken(int phoneId) {
1387 if (phoneId < -128 || phoneId > 127) {
1388 throw new IllegalArgumentException("phoneId should be in range [-128, 127], inclusive");
1389 }
1390 // Integer#valueOf guarantees the integers within [-128, 127] are cached and thus memory
1391 // comparison (==) returns true for the same integer.
1392 return Integer.valueOf(phoneId);
1393 }
1394
1395 /**
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001396 * If {@code args} contains {@link #DUMP_ARG_REQUESTING_PACKAGE} and a following package name,
1397 * we'll also call {@link IBinder#dump} on the default carrier service (if bound) and the
1398 * specified carrier service (if bound). Typically, this is done for connectivity bug reports
1399 * where we don't call {@code dumpsys activity service all-non-platform} because that contains
1400 * too much info, but we still want to let carrier apps include their diagnostics.
1401 */
Jeff Sharkeya6fcfed2017-07-20 14:18:39 -06001402 @Override
Junda Liu43d723a2015-05-12 17:23:45 -07001403 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001404 IndentingPrintWriter indentPW = new IndentingPrintWriter(pw, " ");
Junda Liu43d723a2015-05-12 17:23:45 -07001405 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
1406 != PackageManager.PERMISSION_GRANTED) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001407 indentPW.println("Permission Denial: can't dump carrierconfig from from pid="
Junda Liu43d723a2015-05-12 17:23:45 -07001408 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
1409 return;
1410 }
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001411 String requestingPackage = null;
1412 int requestingPackageIndex = ArrayUtils.indexOf(args, DUMP_ARG_REQUESTING_PACKAGE);
1413 if (requestingPackageIndex >= 0 && requestingPackageIndex < args.length - 1
1414 && !TextUtils.isEmpty(args[requestingPackageIndex + 1])) {
1415 requestingPackage = args[requestingPackageIndex + 1];
1416 // Throws a SecurityException if the caller is impersonating another app in an effort to
1417 // dump extra info (which may contain PII the caller doesn't have a right to).
1418 enforceCallerIsSystemOrRequestingPackage(requestingPackage);
1419 }
1420
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001421 indentPW.println("CarrierConfigLoader: " + this);
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001422 for (int i = 0; i < TelephonyManager.from(mContext).getActiveModemCount(); i++) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001423 indentPW.println("Phone Id = " + i);
shuoq26a3a4c2016-12-16 11:06:48 -08001424 // display default values in CarrierConfigManager
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001425 printConfig(CarrierConfigManager.getDefaultConfig(), indentPW,
shuoq26a3a4c2016-12-16 11:06:48 -08001426 "Default Values from CarrierConfigManager");
shuoq26a3a4c2016-12-16 11:06:48 -08001427 // display ConfigFromDefaultApp
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001428 printConfig(mConfigFromDefaultApp[i], indentPW, "mConfigFromDefaultApp");
shuoq26a3a4c2016-12-16 11:06:48 -08001429 // display ConfigFromCarrierApp
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001430 printConfig(mConfigFromCarrierApp[i], indentPW, "mConfigFromCarrierApp");
1431 printConfig(mPersistentOverrideConfigs[i], indentPW, "mPersistentOverrideConfigs");
1432 printConfig(mOverrideConfigs[i], indentPW, "mOverrideConfigs");
shuoq26a3a4c2016-12-16 11:06:48 -08001433 }
chen xudb04c292019-03-26 17:01:15 -07001434
Jayachandran C645ec612020-01-10 10:30:25 -08001435 printConfig(mNoSimConfig, indentPW, "mNoSimConfig");
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001436 indentPW.println("CarrierConfigLoadingLog=");
1437 mCarrierConfigLoadingLog.dump(fd, indentPW, args);
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001438
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001439 if (requestingPackage != null) {
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001440 logd("Including default and requesting package " + requestingPackage
1441 + " carrier services in dump");
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001442 indentPW.println("");
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001443 indentPW.println("Connected services");
1444 dumpCarrierServiceIfBound(fd, indentPW, "Default config package",
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001445 mPlatformCarrierConfigPackage, false /* considerCarrierPrivileges */);
1446 dumpCarrierServiceIfBound(fd, indentPW, "Requesting package", requestingPackage,
1447 true /* considerCarrierPrivileges */);
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001448 }
shuoq26a3a4c2016-12-16 11:06:48 -08001449 }
1450
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001451 private void printConfig(PersistableBundle configApp, IndentingPrintWriter indentPW,
1452 String name) {
1453 indentPW.increaseIndent();
shuoq26a3a4c2016-12-16 11:06:48 -08001454 if (configApp == null) {
shuoq26a3a4c2016-12-16 11:06:48 -08001455 indentPW.println(name + " : null ");
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001456 indentPW.decreaseIndent();
1457 indentPW.println("");
shuoq26a3a4c2016-12-16 11:06:48 -08001458 return;
1459 }
shuoq26a3a4c2016-12-16 11:06:48 -08001460 indentPW.println(name + " : ");
1461 List<String> sortedKeys = new ArrayList<String>(configApp.keySet());
1462 Collections.sort(sortedKeys);
1463 indentPW.increaseIndent();
1464 indentPW.increaseIndent();
1465 for (String key : sortedKeys) {
1466 if (configApp.get(key) != null && configApp.get(key) instanceof Object[]) {
1467 indentPW.println(key + " = " +
1468 Arrays.toString((Object[]) configApp.get(key)));
1469 } else if (configApp.get(key) != null && configApp.get(key) instanceof int[]) {
1470 indentPW.println(key + " = " + Arrays.toString((int[]) configApp.get(key)));
1471 } else {
1472 indentPW.println(key + " = " + configApp.get(key));
1473 }
Junda Liu43d723a2015-05-12 17:23:45 -07001474 }
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001475 indentPW.decreaseIndent();
1476 indentPW.decreaseIndent();
1477 indentPW.decreaseIndent();
1478 indentPW.println("");
Junda Liu43d723a2015-05-12 17:23:45 -07001479 }
1480
Hunter Knepshielde601f432020-02-19 10:16:04 -08001481 /**
1482 * Passes without problem when one of these conditions is true:
1483 * - The caller is a privileged UID (e.g. for dumpstate.cpp generating a bug report, where the
1484 * system knows the true caller plumbed in through the {@link android.os.BugreportManager} API).
1485 * - The caller's UID matches the supplied package.
1486 *
1487 * @throws SecurityException if none of the above conditions are met.
1488 */
1489 private void enforceCallerIsSystemOrRequestingPackage(String requestingPackage)
1490 throws SecurityException {
1491 final int callingUid = Binder.getCallingUid();
1492 if (callingUid == Process.ROOT_UID || callingUid == Process.SYSTEM_UID
1493 || callingUid == Process.SHELL_UID || callingUid == Process.PHONE_UID) {
1494 // Bug reports (dumpstate.cpp) run as SHELL, and let some other privileged UIDs through
1495 // as well.
1496 return;
1497 }
1498 // An app is trying to dump extra detail, block it if they aren't who they claim to be.
1499 AppOpsManager appOps = mContext.getSystemService(AppOpsManager.class);
1500 if (appOps == null) {
1501 throw new SecurityException("No AppOps");
1502 }
1503 // Will throw a SecurityException if the UID and package don't match.
1504 appOps.checkPackage(callingUid, requestingPackage);
1505 }
1506
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001507 /**
1508 * Searches for one or more appropriate {@link CarrierService} instances to dump based on the
1509 * current connections.
1510 *
1511 * @param targetPkgName the target package name to dump carrier services for
1512 * @param considerCarrierPrivileges if true, allow a carrier service to be dumped if it shares
1513 * carrier privileges with {@code targetPkgName};
1514 * otherwise, only dump a carrier service if it is {@code
1515 * targetPkgName}
1516 */
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001517 private void dumpCarrierServiceIfBound(FileDescriptor fd, IndentingPrintWriter indentPW,
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001518 String prefix, String targetPkgName, boolean considerCarrierPrivileges) {
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001519 // Null package is possible if it's early in the boot process, there was a recent crash, we
1520 // loaded the config from XML most recently, or a SIM slot is empty. Carrier apps with
1521 // long-lived bindings should typically get dumped here regardless. Even if an app is being
1522 // used for multiple phoneIds, we assume that it's smart enough to handle that on its own,
1523 // and that in most cases we'd just be dumping duplicate information and bloating a report.
1524 indentPW.increaseIndent();
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001525 indentPW.println(prefix + " : " + targetPkgName);
1526 Set<String> dumpedPkgNames = new ArraySet<>(mServiceConnection.length);
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001527 for (CarrierServiceConnection connection : mServiceConnection) {
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001528 if (connection == null || !SubscriptionManager.isValidPhoneId(connection.phoneId)
1529 || TextUtils.isEmpty(connection.pkgName)) {
1530 continue;
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001531 }
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001532 final String servicePkgName = connection.pkgName;
1533 // Note: we intentionally ignore system components here because we should NOT match the
1534 // shell caller that's typically used for bug reports via non-BugreportManager triggers.
1535 final boolean exactPackageMatch = TextUtils.equals(targetPkgName, servicePkgName);
1536 final boolean carrierPrivilegesMatch =
1537 considerCarrierPrivileges && hasCarrierPrivileges(targetPkgName,
1538 connection.phoneId);
1539 if (!exactPackageMatch && !carrierPrivilegesMatch) continue;
1540 // Make sure this service is actually alive before trying to dump it. We don't pay
1541 // attention to mServiceBound[connection.phoneId] because typically carrier apps will
1542 // request long-lived bindings, and even if we unbind the app, it may still be alive due
1543 // to CarrierServiceBindHelper. Pull it out as a reference so even if it gets set to
1544 // null within the ServiceConnection during unbinding we can avoid an NPE.
1545 final IBinder service = connection.service;
1546 if (service == null || !service.isBinderAlive() || !service.pingBinder()) continue;
1547 // We've got a live service. Last check is just to make sure we don't dump a package
1548 // multiple times.
1549 if (!dumpedPkgNames.add(servicePkgName)) continue;
1550 if (!exactPackageMatch) {
1551 logd(targetPkgName + " has carrier privileges on phoneId " + connection.phoneId
1552 + ", service provided by " + servicePkgName);
1553 indentPW.increaseIndent();
1554 indentPW.println("Proxy : " + servicePkgName);
1555 indentPW.decreaseIndent();
1556 }
1557 // Flush before we let the app output anything to ensure correct ordering of output.
1558 // Internally, Binder#dump calls flush on its printer after finishing so we don't
1559 // need to do anything after.
1560 indentPW.flush();
1561 try {
1562 logd("Dumping " + servicePkgName);
1563 // We don't need to give the carrier service any args.
1564 connection.service.dump(fd, null /* args */);
1565 logd("Done with " + servicePkgName);
1566 } catch (RemoteException e) {
1567 logd("RemoteException from " + servicePkgName, e);
1568 indentPW.increaseIndent();
1569 indentPW.println("RemoteException");
1570 indentPW.increaseIndent();
1571 e.printStackTrace(indentPW);
1572 indentPW.decreaseIndent();
1573 indentPW.decreaseIndent();
1574 // We won't retry this package again because now it's in dumpedPkgNames.
1575 }
1576 indentPW.println("");
Jordan Liu46ed5db2020-01-28 08:55:20 -08001577 }
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001578 if (dumpedPkgNames.isEmpty()) {
1579 indentPW.increaseIndent();
1580 indentPW.println("Not bound");
1581 indentPW.decreaseIndent();
1582 indentPW.println("");
1583 }
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001584 indentPW.decreaseIndent();
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001585 }
1586
1587 private boolean hasCarrierPrivileges(String pkgName, int phoneId) {
1588 int[] subIds = SubscriptionManager.getSubId(phoneId);
1589 if (ArrayUtils.isEmpty(subIds)) {
1590 return false;
1591 }
1592 return TelephonyManager.from(mContext).createForSubscriptionId(
1593 subIds[0]).checkCarrierPrivilegesForPackage(pkgName)
1594 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Jordan Liu46ed5db2020-01-28 08:55:20 -08001595 }
1596
Zach Johnson36d7aab2015-05-22 15:43:00 -07001597 private class CarrierServiceConnection implements ServiceConnection {
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001598 final int phoneId;
1599 final String pkgName;
1600 final int eventId;
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001601 IBinder service;
1602
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001603 CarrierServiceConnection(int phoneId, String pkgName, int eventId) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001604 this.phoneId = phoneId;
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001605 this.pkgName = pkgName;
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001606 this.eventId = eventId;
1607 }
1608
1609 @Override
1610 public void onServiceConnected(ComponentName name, IBinder service) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001611 logd("Connected to config app: " + name.flattenToShortString());
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001612 this.service = service;
1613 mHandler.sendMessage(mHandler.obtainMessage(eventId, phoneId, -1, this));
1614 }
1615
1616 @Override
1617 public void onServiceDisconnected(ComponentName name) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001618 logd("Disconnected from config app: " + name.flattenToShortString());
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001619 this.service = null;
Jordan Liu46ed5db2020-01-28 08:55:20 -08001620 }
1621
1622 @Override
1623 public void onBindingDied(ComponentName name) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001624 logd("Binding died from config app: " + name.flattenToShortString());
Jordan Liu46ed5db2020-01-28 08:55:20 -08001625 this.service = null;
Jordan Liu46ed5db2020-01-28 08:55:20 -08001626 }
1627
1628 @Override
1629 public void onNullBinding(ComponentName name) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001630 logd("Null binding from config app: " + name.flattenToShortString());
Jordan Liu46ed5db2020-01-28 08:55:20 -08001631 this.service = null;
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001632 }
1633 }
1634
1635 private class ConfigLoaderBroadcastReceiver extends BroadcastReceiver {
1636 @Override
1637 public void onReceive(Context context, Intent intent) {
1638 String action = intent.getAction();
Junda Liu8a8a53a2015-05-15 16:19:57 -07001639 boolean replace = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
1640 // If replace is true, only care ACTION_PACKAGE_REPLACED.
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001641 if (replace && !Intent.ACTION_PACKAGE_REPLACED.equals(action)) {
Junda Liu8a8a53a2015-05-15 16:19:57 -07001642 return;
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001643 }
Junda Liu8a8a53a2015-05-15 16:19:57 -07001644
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001645 switch (action) {
Nanxi Chen3d670502016-03-17 16:32:09 -07001646 case Intent.ACTION_BOOT_COMPLETED:
1647 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SYSTEM_UNLOCKED, null));
1648 break;
1649
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001650 case Intent.ACTION_PACKAGE_ADDED:
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001651 case Intent.ACTION_PACKAGE_REMOVED:
Junda Liu8a8a53a2015-05-15 16:19:57 -07001652 case Intent.ACTION_PACKAGE_REPLACED:
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001653 int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
1654 String packageName = mContext.getPackageManager().getNameForUid(uid);
Junda Liu8a8a53a2015-05-15 16:19:57 -07001655 if (packageName != null) {
1656 // We don't have a phoneId for arg1.
1657 mHandler.sendMessage(
1658 mHandler.obtainMessage(EVENT_PACKAGE_CHANGED, packageName));
1659 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001660 break;
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001661 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001662 }
1663 }
1664
Rambo Wangab13e3e2021-04-08 15:01:06 -07001665 // Get readable string for the message code supported in this class.
1666 private static String eventToString(int code) {
1667 switch (code) {
1668 case EVENT_CLEAR_CONFIG:
1669 return "EVENT_CLEAR_CONFIG";
1670 case EVENT_CONNECTED_TO_DEFAULT:
1671 return "EVENT_CONNECTED_TO_DEFAULT";
1672 case EVENT_CONNECTED_TO_CARRIER:
1673 return "EVENT_CONNECTED_TO_CARRIER";
1674 case EVENT_FETCH_DEFAULT_DONE:
1675 return "EVENT_FETCH_DEFAULT_DONE";
1676 case EVENT_FETCH_CARRIER_DONE:
1677 return "EVENT_FETCH_CARRIER_DONE";
1678 case EVENT_DO_FETCH_DEFAULT:
1679 return "EVENT_DO_FETCH_DEFAULT";
1680 case EVENT_DO_FETCH_CARRIER:
1681 return "EVENT_DO_FETCH_CARRIER";
1682 case EVENT_PACKAGE_CHANGED:
1683 return "EVENT_PACKAGE_CHANGED";
1684 case EVENT_BIND_DEFAULT_TIMEOUT:
1685 return "EVENT_BIND_DEFAULT_TIMEOUT";
1686 case EVENT_BIND_CARRIER_TIMEOUT:
1687 return "EVENT_BIND_CARRIER_TIMEOUT";
1688 case EVENT_CHECK_SYSTEM_UPDATE:
1689 return "EVENT_CHECK_SYSTEM_UPDATE";
1690 case EVENT_SYSTEM_UNLOCKED:
1691 return "EVENT_SYSTEM_UNLOCKED";
1692 case EVENT_FETCH_DEFAULT_TIMEOUT:
1693 return "EVENT_FETCH_DEFAULT_TIMEOUT";
1694 case EVENT_FETCH_CARRIER_TIMEOUT:
1695 return "EVENT_FETCH_CARRIER_TIMEOUT";
1696 case EVENT_SUBSCRIPTION_INFO_UPDATED:
1697 return "EVENT_SUBSCRIPTION_INFO_UPDATED";
1698 case EVENT_MULTI_SIM_CONFIG_CHANGED:
1699 return "EVENT_MULTI_SIM_CONFIG_CHANGED";
1700 case EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG:
1701 return "EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG";
1702 case EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE:
1703 return "EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE";
1704 case EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG:
1705 return "EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG";
1706 case EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT:
1707 return "EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT";
1708 case EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT:
1709 return "EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT";
1710 default:
1711 return "UNKNOWN(" + code + ")";
1712 }
1713 }
1714
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001715 private void logd(String msg) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001716 Log.d(LOG_TAG, msg);
1717 }
1718
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001719 private void logd(String msg, Throwable tr) {
1720 Log.d(LOG_TAG, msg, tr);
1721 }
1722
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001723 private void logdWithLocalLog(String msg) {
chen xudb04c292019-03-26 17:01:15 -07001724 Log.d(LOG_TAG, msg);
1725 mCarrierConfigLoadingLog.log(msg);
1726 }
1727
1728 private void loge(String msg) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001729 Log.e(LOG_TAG, msg);
chen xudb04c292019-03-26 17:01:15 -07001730 mCarrierConfigLoadingLog.log(msg);
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001731 }
1732}