blob: d5b697a2648ce792b831369fd752b57a3244395c [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);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700473 mConfigFromCarrierApp[phoneId] = config;
474 sendMessage(
475 obtainMessage(
476 EVENT_FETCH_CARRIER_DONE, phoneId, -1));
477 }
478 };
479 // Now fetch the config asynchronously from the ICarrierService.
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800480 try {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700481 ICarrierService carrierService =
482 ICarrierService.Stub.asInterface(conn.service);
483 carrierService.getCarrierConfig(carrierId, resultReceiver);
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800484 logdWithLocalLog("Fetch config for carrier app: "
chen xudb04c292019-03-26 17:01:15 -0700485 + getCarrierPackageForPhoneId(phoneId)
486 + " carrierid: " + carrierId.toString());
Jonathan Basseri65273c82017-07-25 15:08:42 -0700487 } catch (RemoteException e) {
488 loge("Failed to get carrier config: " + e.toString());
Jordan Liu178430d2020-02-10 14:32:15 -0800489 unbindIfBound(mContext, conn, phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700490 break; // So we don't set a timeout.
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800491 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700492 sendMessageDelayed(
Rambo Wang610fdf62021-03-08 21:37:11 -0800493 obtainMessage(EVENT_FETCH_CARRIER_TIMEOUT, phoneId, -1 /*arg2*/,
494 getMessageToken(phoneId)),
Jonathan Basseri65273c82017-07-25 15:08:42 -0700495 BIND_TIMEOUT_MILLIS);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800496 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700497 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800498
Jonathan Basseri930701e2015-06-11 20:56:43 -0700499 case EVENT_BIND_CARRIER_TIMEOUT:
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800500 case EVENT_FETCH_CARRIER_TIMEOUT: {
Nathan Harold1122e3d2021-01-22 15:45:24 -0800501 loge("Bind/fetch from carrier app timeout, package="
502 + getCarrierPackageForPhoneId(phoneId));
Rambo Wang610fdf62021-03-08 21:37:11 -0800503 removeMessages(EVENT_FETCH_CARRIER_TIMEOUT, getMessageToken(phoneId));
chen xuf60b3162019-05-01 21:31:05 -0700504 // If we attempted to bind to the app, but the service connection is null due to
505 // the race condition that clear config event happens before bind/fetch complete
506 // then config was cleared while we were waiting and we should not continue.
507 if (mServiceConnection[phoneId] != null) {
508 // If a ResponseReceiver callback is in the queue when this happens, we will
509 // unbind twice and throw an exception.
Jordan Liu178430d2020-02-10 14:32:15 -0800510 unbindIfBound(mContext, mServiceConnection[phoneId], phoneId);
chen xuf60b3162019-05-01 21:31:05 -0700511 broadcastConfigChangedIntent(phoneId);
512 }
Nathan Harold1122e3d2021-01-22 15:45:24 -0800513 // Put a stub bundle in place so that the rest of the logic continues smoothly.
Rambo Wang42026112021-04-07 20:57:28 +0000514 mConfigFromCarrierApp[phoneId] = new PersistableBundle();
Nathan Harold48ac0972019-03-13 22:33:01 -0700515 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri930701e2015-06-11 20:56:43 -0700516 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700517 }
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800518 case EVENT_FETCH_CARRIER_DONE: {
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700519 // If we attempted to bind to the app, but the service connection is null, then
520 // config was cleared while we were waiting and we should not continue.
521 if (!msg.getData().getBoolean("loaded_from_xml", false)
522 && mServiceConnection[phoneId] == null) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800523 break;
524 }
Nathan Harold48ac0972019-03-13 22:33:01 -0700525 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800526 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700527 }
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700528
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800529 case EVENT_CHECK_SYSTEM_UPDATE: {
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700530 SharedPreferences sharedPrefs =
531 PreferenceManager.getDefaultSharedPreferences(mContext);
532 final String lastFingerprint = sharedPrefs.getString(KEY_FINGERPRINT, null);
533 if (!Build.FINGERPRINT.equals(lastFingerprint)) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800534 logd(
Jonathan Basseri65273c82017-07-25 15:08:42 -0700535 "Build fingerprint changed. old: "
536 + lastFingerprint
537 + " new: "
538 + Build.FINGERPRINT);
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700539 clearCachedConfigForPackage(null);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700540 sharedPrefs
541 .edit()
542 .putString(KEY_FINGERPRINT, Build.FINGERPRINT)
543 .apply();
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700544 }
545 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700546 }
Nathan Harold48ac0972019-03-13 22:33:01 -0700547
548 case EVENT_SUBSCRIPTION_INFO_UPDATED:
549 broadcastConfigChangedIntent(phoneId);
550 break;
Malcolm Chen5ea18532019-10-24 19:55:44 -0700551 case EVENT_MULTI_SIM_CONFIG_CHANGED:
552 onMultiSimConfigChanged();
553 break;
Jayachandran C645ec612020-01-10 10:30:25 -0800554
555 case EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG: {
556 PersistableBundle config =
557 restoreNoSimConfigFromXml(mPlatformCarrierConfigPackage);
558
559 if (config != null) {
560 logd("Loaded no SIM config from XML. package="
561 + mPlatformCarrierConfigPackage);
562 mNoSimConfig = config;
563 sendMessage(
564 obtainMessage(
565 EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE,
566 phoneId, -1));
567 } else {
568 // No cached config, so fetch it from the default app.
569 if (bindToConfigPackage(
570 mPlatformCarrierConfigPackage,
571 phoneId,
572 EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG)) {
573 sendMessageDelayed(
574 obtainMessage(
575 EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT,
576 phoneId, -1), BIND_TIMEOUT_MILLIS);
577 } else {
578 broadcastConfigChangedIntent(phoneId, false);
579 // TODO: We *must* call unbindService even if bindService returns false.
580 // (And possibly if SecurityException was thrown.)
581 loge("binding to default app to fetch no SIM config: "
582 + mPlatformCarrierConfigPackage + " fails");
583 }
584 }
585 break;
586 }
587
588 case EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE: {
589 broadcastConfigChangedIntent(phoneId, false);
590 break;
591 }
592
593 case EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT:
594 case EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT: {
595 loge("Bind/fetch time out for no SIM config from "
596 + mPlatformCarrierConfigPackage);
597 removeMessages(EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT);
598 // If we attempted to bind to the app, but the service connection is null due to
599 // the race condition that clear config event happens before bind/fetch complete
600 // then config was cleared while we were waiting and we should not continue.
601 if (mServiceConnectionForNoSimConfig[phoneId] != null) {
602 // If a ResponseReceiver callback is in the queue when this happens, we will
603 // unbind twice and throw an exception.
604 unbindIfBoundForNoSimConfig(mContext,
605 mServiceConnectionForNoSimConfig[phoneId], phoneId);
606 }
607 broadcastConfigChangedIntent(phoneId, false);
608 break;
609 }
610
611 case EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG: {
612 removeMessages(EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT);
613 final CarrierServiceConnection conn = (CarrierServiceConnection) msg.obj;
614 // If new service connection has been created, unbind.
615 if (mServiceConnectionForNoSimConfig[phoneId] != conn || conn.service == null) {
616 unbindIfBoundForNoSimConfig(mContext, conn, phoneId);
617 break;
618 }
619
620 // ResultReceiver callback will execute in this Handler's thread.
621 final ResultReceiver resultReceiver =
622 new ResultReceiver(this) {
623 @Override
624 public void onReceiveResult(int resultCode, Bundle resultData) {
625 unbindIfBoundForNoSimConfig(mContext, conn, phoneId);
626 // If new service connection has been created, this is stale.
627 if (mServiceConnectionForNoSimConfig[phoneId] != conn) {
628 loge("Received response for stale request.");
629 return;
630 }
631 removeMessages(EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT);
632 if (resultCode == RESULT_ERROR || resultData == null) {
633 // On error, abort config fetching.
634 loge("Failed to get no SIM carrier config");
635 return;
636 }
637 PersistableBundle config =
638 resultData.getParcelable(KEY_CONFIG_BUNDLE);
639 saveNoSimConfigToXml(mPlatformCarrierConfigPackage, config);
640 mNoSimConfig = config;
641 sendMessage(
642 obtainMessage(
643 EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE,
644 phoneId, -1));
645 }
646 };
647 // Now fetch the config asynchronously from the ICarrierService.
648 try {
649 ICarrierService carrierService =
650 ICarrierService.Stub.asInterface(conn.service);
651 carrierService.getCarrierConfig(null, resultReceiver);
652 logdWithLocalLog("Fetch no sim config from default app: "
653 + mPlatformCarrierConfigPackage);
654 } catch (RemoteException e) {
655 loge("Failed to get no sim carrier config from default app: " +
656 mPlatformCarrierConfigPackage + " err: " + e.toString());
657 unbindIfBoundForNoSimConfig(mContext, conn, phoneId);
658 break; // So we don't set a timeout.
659 }
660 sendMessageDelayed(
661 obtainMessage(
662 EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT,
663 phoneId, -1), BIND_TIMEOUT_MILLIS);
664 break;
665 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800666 }
667 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700668 }
669
670 private final Handler mHandler;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800671
672 /**
673 * Constructs a CarrierConfigLoader, registers it as a service, and registers a broadcast
674 * receiver for relevant events.
675 */
Rambo Wang7e3bc122021-03-23 09:24:38 -0700676 @VisibleForTesting
677 /* package */ CarrierConfigLoader(Context context,
678 SubscriptionInfoUpdater subscriptionInfoUpdater, @NonNull Looper looper) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800679 mContext = context;
Meng Wang33ad2bc2017-03-16 20:21:20 -0700680 mPlatformCarrierConfigPackage =
681 mContext.getString(R.string.platform_carrier_config_package);
Rambo Wang7e3bc122021-03-23 09:24:38 -0700682 mHandler = new ConfigHandler(looper);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800683
Nanxi Chen3d670502016-03-17 16:32:09 -0700684 IntentFilter bootFilter = new IntentFilter();
685 bootFilter.addAction(Intent.ACTION_BOOT_COMPLETED);
686 context.registerReceiver(mBootReceiver, bootFilter);
687
Junda Liu8a8a53a2015-05-15 16:19:57 -0700688 // Register for package updates. Update app or uninstall app update will have all 3 intents,
689 // in the order or removed, added, replaced, all with extra_replace set to true.
690 IntentFilter pkgFilter = new IntentFilter();
691 pkgFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
692 pkgFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
693 pkgFilter.addAction(Intent.ACTION_PACKAGE_REPLACED);
694 pkgFilter.addDataScheme("package");
Jordan Liu5ca24762019-07-10 12:51:09 -0700695 context.registerReceiver(mPackageReceiver, pkgFilter);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800696
Malcolm Chen978dda52019-10-08 18:15:25 -0700697 int numPhones = TelephonyManager.from(context).getSupportedModemCount();
Jonathan Basseric31f1f32015-05-12 10:13:03 -0700698 mConfigFromDefaultApp = new PersistableBundle[numPhones];
699 mConfigFromCarrierApp = new PersistableBundle[numPhones];
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100700 mPersistentOverrideConfigs = new PersistableBundle[numPhones];
Hall Liu506724b2018-10-22 18:16:14 -0700701 mOverrideConfigs = new PersistableBundle[numPhones];
Rambo Wang42026112021-04-07 20:57:28 +0000702 mNoSimConfig = new PersistableBundle();
Zach Johnson36d7aab2015-05-22 15:43:00 -0700703 mServiceConnection = new CarrierServiceConnection[numPhones];
Jordan Liu178430d2020-02-10 14:32:15 -0800704 mServiceBound = new boolean[numPhones];
Junda Liu03aad762017-07-21 13:32:17 -0700705 mHasSentConfigChange = new boolean[numPhones];
Sarah Chin807d5c62020-03-30 17:21:09 -0700706 mFromSystemUnlocked = new boolean[numPhones];
Jayachandran C645ec612020-01-10 10:30:25 -0800707 mServiceConnectionForNoSimConfig = new CarrierServiceConnection[numPhones];
708 mServiceBoundForNoSimConfig = new boolean[numPhones];
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800709 // Make this service available through ServiceManager.
Peter Wangc035ce42020-01-08 21:00:22 -0800710 TelephonyFrameworkInitializer
711 .getTelephonyServiceManager().getCarrierConfigServiceRegisterer().register(this);
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800712 logd("CarrierConfigLoader has started");
Rambo Wang7e3bc122021-03-23 09:24:38 -0700713 mSubscriptionInfoUpdater = subscriptionInfoUpdater;
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700714 mHandler.sendEmptyMessage(EVENT_CHECK_SYSTEM_UPDATE);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800715 }
716
717 /**
718 * Initialize the singleton CarrierConfigLoader instance.
719 *
720 * This is only done once, at startup, from {@link com.android.phone.PhoneApp#onCreate}.
721 */
Rambo Wang7e3bc122021-03-23 09:24:38 -0700722 /* package */ static CarrierConfigLoader init(Context context) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800723 synchronized (CarrierConfigLoader.class) {
724 if (sInstance == null) {
Rambo Wang7e3bc122021-03-23 09:24:38 -0700725 sInstance = new CarrierConfigLoader(context,
726 PhoneFactory.getSubscriptionInfoUpdater(), Looper.myLooper());
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800727 } else {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700728 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800729 }
730 return sInstance;
731 }
732 }
733
Rambo Wang7e3bc122021-03-23 09:24:38 -0700734 @VisibleForTesting
735 /* package */ void clearConfigForPhone(int phoneId, boolean fetchNoSimConfig) {
Malcolm Chen5ea18532019-10-24 19:55:44 -0700736 /* Ignore clear configuration request if device is being shutdown. */
737 Phone phone = PhoneFactory.getPhone(phoneId);
738 if (phone != null) {
739 if (phone.isShuttingDown()) {
740 return;
741 }
742 }
743
744 mConfigFromDefaultApp[phoneId] = null;
745 mConfigFromCarrierApp[phoneId] = null;
746 mServiceConnection[phoneId] = null;
747 mHasSentConfigChange[phoneId] = false;
748
Jayachandran C645ec612020-01-10 10:30:25 -0800749 if (fetchNoSimConfig) {
750 // To fetch no SIM config
751 mHandler.sendMessage(
752 mHandler.obtainMessage(
753 EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG, phoneId, -1));
754 }
Malcolm Chen5ea18532019-10-24 19:55:44 -0700755 }
756
Nathan Harold48ac0972019-03-13 22:33:01 -0700757 private void notifySubscriptionInfoUpdater(int phoneId) {
758 String configPackagename;
759 PersistableBundle configToSend;
760 int carrierId = getSpecificCarrierIdForPhoneId(phoneId);
761 // Prefer the carrier privileged carrier app, but if there is not one, use the platform
762 // default carrier app.
763 if (mConfigFromCarrierApp[phoneId] != null) {
764 configPackagename = getCarrierPackageForPhoneId(phoneId);
765 configToSend = mConfigFromCarrierApp[phoneId];
766 } else {
767 configPackagename = mPlatformCarrierConfigPackage;
768 configToSend = mConfigFromDefaultApp[phoneId];
769 }
Nazanin Bakhshi6fcc3342019-09-18 17:54:01 -0700770
Malcolm Chenefafd1c2020-02-20 13:27:08 -0800771 if (configToSend == null) {
Rambo Wang42026112021-04-07 20:57:28 +0000772 configToSend = new PersistableBundle();
Malcolm Chenefafd1c2020-02-20 13:27:08 -0800773 }
774
Nazanin Bakhshi6fcc3342019-09-18 17:54:01 -0700775 // mOverrideConfigs is for testing. And it will override current configs.
776 PersistableBundle config = mOverrideConfigs[phoneId];
777 if (config != null) {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +0100778 configToSend = new PersistableBundle(configToSend);
Nazanin Bakhshi6fcc3342019-09-18 17:54:01 -0700779 configToSend.putAll(config);
780 }
781
Nathan Harold48ac0972019-03-13 22:33:01 -0700782 mSubscriptionInfoUpdater.updateSubscriptionByCarrierConfigAndNotifyComplete(
783 phoneId, configPackagename, configToSend,
784 mHandler.obtainMessage(EVENT_SUBSCRIPTION_INFO_UPDATED, phoneId, -1));
785 }
786
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800787 private void broadcastConfigChangedIntent(int phoneId) {
Amit Mahajanf8088ab2018-03-02 15:24:07 -0800788 broadcastConfigChangedIntent(phoneId, true);
789 }
790
791 private void broadcastConfigChangedIntent(int phoneId, boolean addSubIdExtra) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800792 Intent intent = new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Christopher Tate38f55eb2017-02-14 14:43:49 -0800793 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT |
chen xuf9db49f2019-03-31 23:04:42 -0700794 Intent.FLAG_RECEIVER_FOREGROUND);
Qiongcheng Luoe7de61b2018-08-06 10:20:09 +0800795 if (addSubIdExtra) {
796 int simApplicationState = TelephonyManager.SIM_STATE_UNKNOWN;
797 int[] subIds = SubscriptionManager.getSubId(phoneId);
798 if (!ArrayUtils.isEmpty(subIds)) {
799 TelephonyManager telMgr = TelephonyManager.from(mContext)
800 .createForSubscriptionId(subIds[0]);
801 simApplicationState = telMgr.getSimApplicationState();
802 }
Malcolm Chenf7635ec2020-04-15 15:45:00 -0700803 logd("Broadcast CARRIER_CONFIG_CHANGED for phone " + phoneId
804 + " simApplicationState " + simApplicationState);
Qiongcheng Luoe7de61b2018-08-06 10:20:09 +0800805 // Include subId/carrier id extra only if SIM records are loaded
806 if (simApplicationState != TelephonyManager.SIM_STATE_UNKNOWN
807 && simApplicationState != TelephonyManager.SIM_STATE_NOT_READY) {
808 SubscriptionManager.putPhoneIdAndSubIdExtra(intent, phoneId);
809 intent.putExtra(TelephonyManager.EXTRA_SPECIFIC_CARRIER_ID,
810 getSpecificCarrierIdForPhoneId(phoneId));
811 intent.putExtra(TelephonyManager.EXTRA_CARRIER_ID, getCarrierIdForPhoneId(phoneId));
812 }
Amit Mahajanf8088ab2018-03-02 15:24:07 -0800813 }
Amit Mahajanb33bcda2018-01-24 12:56:44 -0800814 intent.putExtra(CarrierConfigManager.EXTRA_SLOT_INDEX, phoneId);
Sarah Chin807d5c62020-03-30 17:21:09 -0700815 intent.putExtra(CarrierConfigManager.EXTRA_REBROADCAST_ON_UNLOCK,
816 mFromSystemUnlocked[phoneId]);
Meng Wang97a6a462020-01-23 16:22:16 -0800817 mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
Jack Yue9e95be2020-03-22 10:56:06 -0700818 int[] subIds = SubscriptionManager.getSubId(phoneId);
819 if (subIds != null && subIds.length > 0) {
820 logd("Broadcast CARRIER_CONFIG_CHANGED for phone " + phoneId + ", subId=" + subIds[0]);
821 } else {
822 logd("Broadcast CARRIER_CONFIG_CHANGED for phone " + phoneId);
823 }
Junda Liu03aad762017-07-21 13:32:17 -0700824 mHasSentConfigChange[phoneId] = true;
Sarah Chin807d5c62020-03-30 17:21:09 -0700825 mFromSystemUnlocked[phoneId] = false;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800826 }
827
828 /** Binds to the default or carrier config app. */
829 private boolean bindToConfigPackage(String pkgName, int phoneId, int eventId) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800830 logdWithLocalLog("Binding to " + pkgName + " for phone " + phoneId);
Zach Johnsonfca8a8d2015-06-19 18:21:37 -0700831 Intent carrierService = new Intent(CarrierService.CARRIER_SERVICE_INTERFACE);
Zach Johnson36d7aab2015-05-22 15:43:00 -0700832 carrierService.setPackage(pkgName);
Jayachandran C645ec612020-01-10 10:30:25 -0800833 CarrierServiceConnection serviceConnection = new CarrierServiceConnection(
834 phoneId, pkgName, eventId);
835 if (eventId == EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG) {
836 mServiceConnectionForNoSimConfig[phoneId] = serviceConnection;
837 } else {
838 mServiceConnection[phoneId] = serviceConnection;
839 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800840 try {
Jayachandran C645ec612020-01-10 10:30:25 -0800841 if (mContext.bindService(carrierService, serviceConnection,
Jordan Liu178430d2020-02-10 14:32:15 -0800842 Context.BIND_AUTO_CREATE)) {
Jayachandran C645ec612020-01-10 10:30:25 -0800843 if (eventId == EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG) {
844 mServiceBoundForNoSimConfig[phoneId] = true;
845 } else {
846 mServiceBound[phoneId] = true;
847 }
Jordan Liu178430d2020-02-10 14:32:15 -0800848 return true;
849 } else {
850 return false;
851 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800852 } catch (SecurityException ex) {
853 return false;
854 }
855 }
856
Rambo Wang7e3bc122021-03-23 09:24:38 -0700857 @VisibleForTesting
858 /* package */ CarrierIdentifier getCarrierIdentifierForPhoneId(int phoneId) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800859 String mcc = "";
860 String mnc = "";
861 String imsi = "";
862 String gid1 = "";
863 String gid2 = "";
864 String spn = TelephonyManager.from(mContext).getSimOperatorNameForPhone(phoneId);
865 String simOperator = TelephonyManager.from(mContext).getSimOperatorNumericForPhone(phoneId);
chen xu02581692018-11-11 19:03:44 -0800866 int carrierId = TelephonyManager.UNKNOWN_CARRIER_ID;
chen xua31f22b2019-03-06 15:28:50 -0800867 int specificCarrierId = TelephonyManager.UNKNOWN_CARRIER_ID;
Jonathan Basseri1fa437c2015-04-20 11:08:18 -0700868 // A valid simOperator should be 5 or 6 digits, depending on the length of the MNC.
869 if (simOperator != null && simOperator.length() >= 3) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800870 mcc = simOperator.substring(0, 3);
871 mnc = simOperator.substring(3);
872 }
873 Phone phone = PhoneFactory.getPhone(phoneId);
874 if (phone != null) {
875 imsi = phone.getSubscriberId();
876 gid1 = phone.getGroupIdLevel1();
Junda Liu73183532015-05-14 13:55:40 -0700877 gid2 = phone.getGroupIdLevel2();
chen xu02581692018-11-11 19:03:44 -0800878 carrierId = phone.getCarrierId();
chen xua31f22b2019-03-06 15:28:50 -0800879 specificCarrierId = phone.getSpecificCarrierId();
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800880 }
chen xua31f22b2019-03-06 15:28:50 -0800881 return new CarrierIdentifier(mcc, mnc, spn, imsi, gid1, gid2, carrierId, specificCarrierId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800882 }
883
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700884 /** Returns the package name of a priveleged carrier app, or null if there is none. */
Nathan Harold1122e3d2021-01-22 15:45:24 -0800885 @Nullable
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700886 private String getCarrierPackageForPhoneId(int phoneId) {
887 List<String> carrierPackageNames = TelephonyManager.from(mContext)
888 .getCarrierPackageNamesForIntentAndPhone(
Zach Johnsonfca8a8d2015-06-19 18:21:37 -0700889 new Intent(CarrierService.CARRIER_SERVICE_INTERFACE), phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700890 if (carrierPackageNames != null && carrierPackageNames.size() > 0) {
891 return carrierPackageNames.get(0);
892 } else {
893 return null;
894 }
895 }
896
897 private String getIccIdForPhoneId(int phoneId) {
898 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
899 return null;
900 }
901 Phone phone = PhoneFactory.getPhone(phoneId);
902 if (phone == null) {
903 return null;
904 }
905 return phone.getIccSerialNumber();
906 }
907
chen xu02581692018-11-11 19:03:44 -0800908 /**
chen xua31f22b2019-03-06 15:28:50 -0800909 * Get the sim specific carrier id {@link TelephonyManager#getSimSpecificCarrierId()}
chen xu02581692018-11-11 19:03:44 -0800910 */
chen xua31f22b2019-03-06 15:28:50 -0800911 private int getSpecificCarrierIdForPhoneId(int phoneId) {
Naina Nalluri86fc7b02018-08-03 10:38:30 -0700912 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
chen xu02581692018-11-11 19:03:44 -0800913 return TelephonyManager.UNKNOWN_CARRIER_ID;
Naina Nalluri86fc7b02018-08-03 10:38:30 -0700914 }
915 Phone phone = PhoneFactory.getPhone(phoneId);
916 if (phone == null) {
chen xu02581692018-11-11 19:03:44 -0800917 return TelephonyManager.UNKNOWN_CARRIER_ID;
Naina Nalluri86fc7b02018-08-03 10:38:30 -0700918 }
chen xua31f22b2019-03-06 15:28:50 -0800919 return phone.getSpecificCarrierId();
chen xu02581692018-11-11 19:03:44 -0800920 }
921
922 /**
923 * Get the sim carrier id {@link TelephonyManager#getSimCarrierId() }
924 */
925 private int getCarrierIdForPhoneId(int phoneId) {
926 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
927 return TelephonyManager.UNKNOWN_CARRIER_ID;
Naina Nalluri86fc7b02018-08-03 10:38:30 -0700928 }
chen xu02581692018-11-11 19:03:44 -0800929 Phone phone = PhoneFactory.getPhone(phoneId);
930 if (phone == null) {
931 return TelephonyManager.UNKNOWN_CARRIER_ID;
932 }
933 return phone.getCarrierId();
Naina Nalluri86fc7b02018-08-03 10:38:30 -0700934 }
935
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700936 /**
937 * Writes a bundle to an XML file.
938 *
chen xu02581692018-11-11 19:03:44 -0800939 * The bundle will be written to a file named after the package name, ICCID and
chen xua31f22b2019-03-06 15:28:50 -0800940 * specific carrier id {@link TelephonyManager#getSimSpecificCarrierId()}. the same carrier
chen xu02581692018-11-11 19:03:44 -0800941 * should have a single copy of XML file named after carrier id. However, it's still possible
942 * that platform doesn't recognize the current sim carrier, we will use iccid + carrierid as
943 * the canonical file name. carrierid can also handle the cases SIM OTA resolves to different
944 * carrier while iccid remains the same.
945 *
946 * The file can be restored later with {@link @restoreConfigFromXml}. The XML output will
947 * include the bundle and the current version of the specified package.
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700948 *
949 * In case of errors or invalid input, no file will be written.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700950 *
Jayachandran C645ec612020-01-10 10:30:25 -0800951 * @param packageName the name of the package from which we fetched this bundle.
952 * @param extraString An extra string to be used in the XML file name.
953 * @param phoneId the phone ID.
954 * @param carrierId contains all carrier-identifying information.
955 * @param config the bundle to be written. Null will be treated as an empty bundle.
956 * @param isNoSimConfig whether this is invoked for noSimConfig or not.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700957 */
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100958 private void saveConfigToXml(String packageName, @NonNull String extraString, int phoneId,
Jayachandran C645ec612020-01-10 10:30:25 -0800959 CarrierIdentifier carrierId, PersistableBundle config, boolean isNoSimConfig) {
960 if (packageName == null) {
961 loge("Cannot save config with null packageName");
Yuchen Dongc15afed2018-04-26 17:05:22 +0800962 return;
963 }
964
Jayachandran C645ec612020-01-10 10:30:25 -0800965 String fileName;
966 if (isNoSimConfig) {
967 fileName = getFilenameForNoSimConfig(packageName);
968 } else {
969 if (SubscriptionManager.getSimStateForSlotIndex(phoneId)
970 != TelephonyManager.SIM_STATE_LOADED) {
971 loge("Skip save config because SIM records are not loaded.");
972 return;
973 }
974
975 final String iccid = getIccIdForPhoneId(phoneId);
976 final int cid = carrierId.getSpecificCarrierId();
977 if (iccid == null) {
978 loge("Cannot save config with null iccid.");
979 return;
980 }
981 fileName = getFilenameForConfig(packageName, extraString, iccid, cid);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700982 }
Jayachandran C645ec612020-01-10 10:30:25 -0800983
Junda Liu02596502016-11-15 13:46:43 -0800984 // b/32668103 Only save to file if config isn't empty.
985 // In case of failure, not caching an empty bundle will
986 // try loading config again on next power on or sim loaded.
987 // Downside is for genuinely empty bundle, will bind and load
988 // on every power on.
989 if (config == null || config.isEmpty()) {
990 return;
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700991 }
992
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700993 final String version = getPackageVersion(packageName);
994 if (version == null) {
995 loge("Failed to get package version for: " + packageName);
996 return;
997 }
998
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800999 logdWithLocalLog(
1000 "Save config to xml, packagename: " + packageName + " phoneId: " + phoneId);
chen xudb04c292019-03-26 17:01:15 -07001001
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001002 FileOutputStream outFile = null;
1003 try {
Jayachandran C645ec612020-01-10 10:30:25 -08001004 outFile = new FileOutputStream(new File(mContext.getFilesDir(), fileName));
Meng Wang0f6b2ea2020-01-06 18:31:16 -08001005 config.putString(KEY_VERSION, version);
1006 config.writeToStream(outFile);
1007 outFile.flush();
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001008 outFile.close();
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001009 } catch (IOException e) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001010 loge(e.toString());
1011 }
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001012 }
1013
Rambo Wang7e3bc122021-03-23 09:24:38 -07001014 @VisibleForTesting
1015 /* package */ void saveConfigToXml(String packageName, @NonNull String extraString, int phoneId,
Jayachandran C645ec612020-01-10 10:30:25 -08001016 CarrierIdentifier carrierId, PersistableBundle config) {
1017 saveConfigToXml(packageName, extraString, phoneId, carrierId, config, false);
1018 }
1019
Rambo Wang7e3bc122021-03-23 09:24:38 -07001020 @VisibleForTesting
1021 /* package */ void saveNoSimConfigToXml(String packageName, PersistableBundle config) {
Jayachandran C645ec612020-01-10 10:30:25 -08001022 saveConfigToXml(packageName, "", -1, null, config, true);
1023 }
1024
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001025 /**
1026 * Reads a bundle from an XML file.
1027 *
1028 * This restores a bundle that was written with {@link #saveConfigToXml}. This returns the saved
Yuchen Dongc15afed2018-04-26 17:05:22 +08001029 * config bundle for the given package and phone ID.
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001030 *
1031 * In case of errors, or if the saved config is from a different package version than the
1032 * current version, then null will be returned.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001033 *
Jayachandran C645ec612020-01-10 10:30:25 -08001034 * @param packageName the name of the package from which we fetched this bundle.
1035 * @param extraString An extra string to be used in the XML file name.
1036 * @param phoneId the phone ID.
1037 * @param isNoSimConfig whether this is invoked for noSimConfig or not.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001038 * @return the bundle from the XML file. Returns null if there is no saved config, the saved
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001039 * version does not match, or reading config fails.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001040 */
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001041 private PersistableBundle restoreConfigFromXml(String packageName, @NonNull String extraString,
Jayachandran C645ec612020-01-10 10:30:25 -08001042 int phoneId, boolean isNoSimConfig) {
1043 if (packageName == null) {
1044 loge("Cannot restore config with null packageName");
1045 }
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001046 final String version = getPackageVersion(packageName);
1047 if (version == null) {
1048 loge("Failed to get package version for: " + packageName);
1049 return null;
1050 }
Yuchen Dongc15afed2018-04-26 17:05:22 +08001051
Jayachandran C645ec612020-01-10 10:30:25 -08001052 String fileName;
1053 if (isNoSimConfig) {
1054 fileName = getFilenameForNoSimConfig(packageName);
1055 } else {
1056 if (SubscriptionManager.getSimStateForSlotIndex(phoneId)
1057 != TelephonyManager.SIM_STATE_LOADED) {
1058 loge("Skip restore config because SIM records are not loaded.");
1059 return null;
1060 }
1061
1062 final String iccid = getIccIdForPhoneId(phoneId);
1063 final int cid = getSpecificCarrierIdForPhoneId(phoneId);
1064 if (iccid == null) {
1065 loge("Cannot restore config with null iccid.");
1066 return null;
1067 }
1068 fileName = getFilenameForConfig(packageName, extraString, iccid, cid);
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001069 }
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001070
1071 PersistableBundle restoredBundle = null;
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001072 File file = null;
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001073 FileInputStream inFile = null;
1074 try {
Jayachandran C645ec612020-01-10 10:30:25 -08001075 file = new File(mContext.getFilesDir(),fileName);
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001076 inFile = new FileInputStream(file);
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001077
Meng Wang0f6b2ea2020-01-06 18:31:16 -08001078 restoredBundle = PersistableBundle.readFromStream(inFile);
1079 String savedVersion = restoredBundle.getString(KEY_VERSION);
1080 restoredBundle.remove(KEY_VERSION);
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001081
Meng Wang0f6b2ea2020-01-06 18:31:16 -08001082 if (!version.equals(savedVersion)) {
1083 loge("Saved version mismatch: " + version + " vs " + savedVersion);
1084 restoredBundle = null;
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001085 }
Meng Wang0f6b2ea2020-01-06 18:31:16 -08001086
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001087 inFile.close();
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001088 } catch (FileNotFoundException e) {
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001089 // Missing file is normal occurrence that might occur with a new sim or when restoring
1090 // an override file during boot and should not be treated as an error.
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001091 if (file != null) logd("File not found: " + file.getPath());
1092 } catch (IOException e) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001093 loge(e.toString());
1094 }
1095
1096 return restoredBundle;
1097 }
1098
Jayachandran C645ec612020-01-10 10:30:25 -08001099 private PersistableBundle restoreConfigFromXml(String packageName, @NonNull String extraString,
1100 int phoneId) {
1101 return restoreConfigFromXml(packageName, extraString, phoneId, false);
1102 }
1103
1104 private PersistableBundle restoreNoSimConfigFromXml(String packageName) {
1105 return restoreConfigFromXml(packageName, "", -1, true);
1106 }
1107
Junda Liu8a8a53a2015-05-15 16:19:57 -07001108 /**
Jonathan Basseri7697cae2015-07-06 15:49:23 -07001109 * Clears cached carrier config.
1110 * This deletes all saved XML files associated with the given package name. If packageName is
1111 * null, then it deletes all saved XML files.
1112 *
1113 * @param packageName the name of a carrier package, or null if all cached config should be
1114 * cleared.
1115 * @return true iff one or more files were deleted.
Junda Liu8a8a53a2015-05-15 16:19:57 -07001116 */
Jonathan Basseri7697cae2015-07-06 15:49:23 -07001117 private boolean clearCachedConfigForPackage(final String packageName) {
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001118 File dir = mContext.getFilesDir();
1119 File[] packageFiles = dir.listFiles(new FilenameFilter() {
1120 public boolean accept(File dir, String filename) {
Jonathan Basseri7697cae2015-07-06 15:49:23 -07001121 if (packageName != null) {
1122 return filename.startsWith("carrierconfig-" + packageName + "-");
1123 } else {
1124 return filename.startsWith("carrierconfig-");
1125 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001126 }
1127 });
Junda Liu8a8a53a2015-05-15 16:19:57 -07001128 if (packageFiles == null || packageFiles.length < 1) return false;
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001129 for (File f : packageFiles) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001130 logd("Deleting " + f.getName());
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001131 f.delete();
1132 }
Junda Liu8a8a53a2015-05-15 16:19:57 -07001133 return true;
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001134 }
1135
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001136 /** Builds a canonical file name for a config file. */
Jayachandran C645ec612020-01-10 10:30:25 -08001137 private static String getFilenameForConfig(
1138 @NonNull String packageName, @NonNull String extraString,
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001139 @NonNull String iccid, int cid) {
chen xu02581692018-11-11 19:03:44 -08001140 // the same carrier should have a single copy of XML file named after carrier id.
1141 // However, it's still possible that platform doesn't recognize the current sim carrier,
1142 // we will use iccid + carrierid as the canonical file name. carrierid can also handle the
1143 // cases SIM OTA resolves to different carrier while iccid remains the same.
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001144 return "carrierconfig-" + packageName + extraString + "-" + iccid + "-" + cid + ".xml";
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001145 }
1146
Jayachandran C645ec612020-01-10 10:30:25 -08001147 /** Builds a canonical file name for no SIM config file. */
1148 private String getFilenameForNoSimConfig(@NonNull String packageName) {
1149 return "carrierconfig-" + packageName + "-" + "nosim" + ".xml";
1150 }
1151
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001152 /** Return the current version code of a package, or null if the name is not found. */
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001153 private String getPackageVersion(String packageName) {
1154 try {
1155 PackageInfo info = mContext.getPackageManager().getPackageInfo(packageName, 0);
Dianne Hackbornb76ab202017-11-28 17:44:50 -08001156 return Long.toString(info.getLongVersionCode());
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001157 } catch (PackageManager.NameNotFoundException e) {
1158 return null;
1159 }
1160 }
1161
Jonathan Basseri65273c82017-07-25 15:08:42 -07001162 /**
1163 * Read up to date config.
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001164 *
1165 * This reads config bundles for the given phoneId. That means getting the latest bundle from
1166 * the default app and a privileged carrier app, if present. This will not bind to an app if we
1167 * have a saved config file to use instead.
1168 */
1169 private void updateConfigForPhoneId(int phoneId) {
Jonathan Basseri65273c82017-07-25 15:08:42 -07001170 mHandler.sendMessage(mHandler.obtainMessage(EVENT_DO_FETCH_DEFAULT, phoneId, -1));
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001171 }
1172
Malcolm Chen5ea18532019-10-24 19:55:44 -07001173 private void onMultiSimConfigChanged() {
1174 for (int i = TelephonyManager.from(mContext).getActiveModemCount();
1175 i < mConfigFromDefaultApp.length; i++) {
1176 clearConfigForPhone(i, false);
1177 }
1178 }
1179
Hall Liu506724b2018-10-22 18:16:14 -07001180 @Override
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001181 @NonNull
Rambo Wangd2b004b2021-03-30 10:10:23 -07001182 public PersistableBundle getConfigForSubId(int subscriptionId, String callingPackage) {
1183 return getConfigForSubIdWithFeature(subscriptionId, callingPackage, null);
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001184 }
1185
1186 @Override
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001187 @NonNull
Rambo Wangd2b004b2021-03-30 10:10:23 -07001188 public PersistableBundle getConfigForSubIdWithFeature(int subscriptionId, String callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001189 String callingFeatureId) {
Rambo Wangd2b004b2021-03-30 10:10:23 -07001190 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mContext, subscriptionId,
1191 callingPackage, callingFeatureId, "getCarrierConfig")) {
Rambo Wang42026112021-04-07 20:57:28 +00001192 return new PersistableBundle();
Amit Mahajan40b3fa52015-07-14 10:27:19 -07001193 }
Jeff Davidsona8e4e242018-03-15 17:16:18 -07001194
Rambo Wangd2b004b2021-03-30 10:10:23 -07001195 int phoneId = SubscriptionManager.getPhoneId(subscriptionId);
Jonathan Basseric31f1f32015-05-12 10:13:03 -07001196 PersistableBundle retConfig = CarrierConfigManager.getDefaultConfig();
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001197 if (SubscriptionManager.isValidPhoneId(phoneId)) {
Jonathan Basseric31f1f32015-05-12 10:13:03 -07001198 PersistableBundle config = mConfigFromDefaultApp[phoneId];
yinxuc5e27622017-11-29 15:08:50 -08001199 if (config != null) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001200 retConfig.putAll(config);
yinxuc5e27622017-11-29 15:08:50 -08001201 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001202 config = mConfigFromCarrierApp[phoneId];
yinxuc5e27622017-11-29 15:08:50 -08001203 if (config != null) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001204 retConfig.putAll(config);
yinxuc5e27622017-11-29 15:08:50 -08001205 }
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001206 config = mPersistentOverrideConfigs[phoneId];
1207 if (config != null) {
1208 retConfig.putAll(config);
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001209 }
Hall Liu506724b2018-10-22 18:16:14 -07001210 config = mOverrideConfigs[phoneId];
1211 if (config != null) {
1212 retConfig.putAll(config);
Hall Liu506724b2018-10-22 18:16:14 -07001213 }
Nathan Harold1122e3d2021-01-22 15:45:24 -08001214 // Ignore the theoretical case of the default app not being present since that won't
1215 // work in CarrierConfigLoader today.
1216 final boolean allConfigsApplied =
1217 (mConfigFromCarrierApp[phoneId] != null
1218 || getCarrierPackageForPhoneId(phoneId) == null)
1219 && mConfigFromDefaultApp[phoneId] != null;
1220 retConfig.putBoolean(
1221 CarrierConfigManager.KEY_CARRIER_CONFIG_APPLIED_BOOL, allConfigsApplied);
Jayachandran C645ec612020-01-10 10:30:25 -08001222 } else {
1223 if (mNoSimConfig != null) {
1224 retConfig.putAll(mNoSimConfig);
1225 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001226 }
1227 return retConfig;
1228 }
1229
1230 @Override
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001231 public void overrideConfig(int subscriptionId, @Nullable PersistableBundle overrides,
1232 boolean persistent) {
Hall Liu506724b2018-10-22 18:16:14 -07001233 mContext.enforceCallingOrSelfPermission(
1234 android.Manifest.permission.MODIFY_PHONE_STATE, null);
Brad Ebingerf6281ad2019-04-25 11:02:04 -07001235 //TODO: Also check for SHELL UID to restrict this method to testing only (b/131326259)
Hall Liu506724b2018-10-22 18:16:14 -07001236 int phoneId = SubscriptionManager.getPhoneId(subscriptionId);
1237 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001238 logd("Ignore invalid phoneId: " + phoneId + " for subId: " + subscriptionId);
Rambo Wangd2b004b2021-03-30 10:10:23 -07001239 throw new IllegalArgumentException(
1240 "Invalid phoneId " + phoneId + " for subId " + subscriptionId);
Hall Liu506724b2018-10-22 18:16:14 -07001241 }
Rambo Wang38eb5cd2021-03-29 16:39:14 -07001242 // Post to run on handler thread on which all states should be confined.
1243 mHandler.post(() -> {
1244 overrideConfig(mOverrideConfigs, phoneId, overrides);
Hall Liu506724b2018-10-22 18:16:14 -07001245
Rambo Wang38eb5cd2021-03-29 16:39:14 -07001246 if (persistent) {
1247 overrideConfig(mPersistentOverrideConfigs, phoneId, overrides);
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001248
Rambo Wang38eb5cd2021-03-29 16:39:14 -07001249 if (overrides != null) {
1250 final CarrierIdentifier carrierId = getCarrierIdentifierForPhoneId(phoneId);
1251 saveConfigToXml(mPlatformCarrierConfigPackage, OVERRIDE_PACKAGE_ADDITION,
1252 phoneId,
1253 carrierId, mPersistentOverrideConfigs[phoneId]);
1254 } else {
1255 final String iccid = getIccIdForPhoneId(phoneId);
1256 final int cid = getSpecificCarrierIdForPhoneId(phoneId);
1257 String fileName = getFilenameForConfig(mPlatformCarrierConfigPackage,
1258 OVERRIDE_PACKAGE_ADDITION, iccid, cid);
1259 File fileToDelete = new File(mContext.getFilesDir(), fileName);
1260 fileToDelete.delete();
1261 }
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001262 }
Rambo Wang38eb5cd2021-03-29 16:39:14 -07001263 notifySubscriptionInfoUpdater(phoneId);
1264 });
Hall Liu506724b2018-10-22 18:16:14 -07001265 }
1266
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001267 private void overrideConfig(@NonNull PersistableBundle[] currentOverrides, int phoneId,
1268 @Nullable PersistableBundle overrides) {
1269 if (overrides == null) {
Rambo Wang42026112021-04-07 20:57:28 +00001270 currentOverrides[phoneId] = new PersistableBundle();
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001271 } else if (currentOverrides[phoneId] == null) {
1272 currentOverrides[phoneId] = overrides;
1273 } else {
1274 currentOverrides[phoneId].putAll(overrides);
1275 }
1276 }
1277
Hall Liu506724b2018-10-22 18:16:14 -07001278 @Override
Rambo Wangd2b004b2021-03-30 10:10:23 -07001279 public void notifyConfigChangedForSubId(int subscriptionId) {
Jordan Liud7d57fe2019-04-16 12:29:43 -07001280 // Requires the calling app to be either a carrier privileged app for this subId or
Junda Liufbd2bcb2016-06-15 11:15:42 -07001281 // system privileged app with MODIFY_PHONE_STATE permission.
Rambo Wangd2b004b2021-03-30 10:10:23 -07001282 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mContext,
1283 subscriptionId, "Require carrier privileges or MODIFY_PHONE_STATE permission.");
1284
1285 int phoneId = SubscriptionManager.getPhoneId(subscriptionId);
1286 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
1287 logd("Ignore invalid phoneId: " + phoneId + " for subId: " + subscriptionId);
1288 throw new IllegalArgumentException(
1289 "Invalid phoneId " + phoneId + " for subId " + subscriptionId);
1290 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001291
1292 // This method should block until deleting has completed, so that an error which prevents us
1293 // from clearing the cache is passed back to the carrier app. With the files successfully
1294 // deleted, this can return and we will eventually bind to the carrier app.
Jordan Liud7d57fe2019-04-16 12:29:43 -07001295 String callingPackageName = mContext.getPackageManager().getNameForUid(
1296 Binder.getCallingUid());
Jonathan Basseri7697cae2015-07-06 15:49:23 -07001297 clearCachedConfigForPackage(callingPackageName);
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001298 updateConfigForPhoneId(phoneId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001299 }
1300
1301 @Override
1302 public void updateConfigForPhoneId(int phoneId, String simState) {
Junda Liu1f2b34d2015-06-18 15:26:56 -07001303 mContext.enforceCallingOrSelfPermission(
1304 android.Manifest.permission.MODIFY_PHONE_STATE, null);
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001305 logdWithLocalLog("Update config for phoneId: " + phoneId + " simState: " + simState);
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001306 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
Rambo Wangd2b004b2021-03-30 10:10:23 -07001307 throw new IllegalArgumentException("Invalid phoneId: " + phoneId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001308 }
1309 // requires Java 7 for switch on string.
1310 switch (simState) {
1311 case IccCardConstants.INTENT_VALUE_ICC_ABSENT:
1312 case IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR:
Junda Liu6f5fddf2016-05-24 16:14:41 -07001313 case IccCardConstants.INTENT_VALUE_ICC_CARD_RESTRICTED:
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001314 case IccCardConstants.INTENT_VALUE_ICC_UNKNOWN:
Malcolm Chendb66de12019-12-09 18:57:07 -08001315 case IccCardConstants.INTENT_VALUE_ICC_NOT_READY:
Junda Liu9f2d2712015-05-15 14:22:45 -07001316 mHandler.sendMessage(mHandler.obtainMessage(EVENT_CLEAR_CONFIG, phoneId, -1));
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001317 break;
1318 case IccCardConstants.INTENT_VALUE_ICC_LOADED:
1319 case IccCardConstants.INTENT_VALUE_ICC_LOCKED:
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001320 updateConfigForPhoneId(phoneId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001321 break;
1322 }
1323 }
1324
Junda Liu43d723a2015-05-12 17:23:45 -07001325 @Override
Jeff Sharkeya6fcfed2017-07-20 14:18:39 -06001326 public String getDefaultCarrierServicePackageName() {
Shuo Qianefdb7962019-12-19 15:54:27 -08001327 mContext.enforceCallingOrSelfPermission(
1328 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
1329 "getDefaultCarrierServicePackageName");
Jeff Sharkeya6fcfed2017-07-20 14:18:39 -06001330 return mPlatformCarrierConfigPackage;
1331 }
1332
Rambo Wang7e3bc122021-03-23 09:24:38 -07001333 @VisibleForTesting
1334 /* package */ Handler getHandler() {
1335 return mHandler;
1336 }
1337
1338 @VisibleForTesting
1339 /* package */ PersistableBundle getConfigFromDefaultApp(int phoneId) {
1340 return mConfigFromDefaultApp[phoneId];
1341 }
1342
1343 @VisibleForTesting
1344 /* package */ PersistableBundle getConfigFromCarrierApp(int phoneId) {
1345 return mConfigFromCarrierApp[phoneId];
1346 }
1347
1348 @VisibleForTesting
1349 /* package */ PersistableBundle getNoSimConfig() {
1350 return mNoSimConfig;
1351 }
1352
1353 @VisibleForTesting
1354 /* package */ PersistableBundle getOverrideConfig(int phoneId) {
1355 return mOverrideConfigs[phoneId];
1356 }
1357
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001358 private void unbindIfBound(Context context, CarrierServiceConnection conn,
1359 int phoneId) {
1360 if (mServiceBound[phoneId]) {
1361 mServiceBound[phoneId] = false;
1362 context.unbindService(conn);
1363 }
1364 }
1365
Jayachandran C645ec612020-01-10 10:30:25 -08001366 private void unbindIfBoundForNoSimConfig(Context context, CarrierServiceConnection conn,
1367 int phoneId) {
1368 if (mServiceBoundForNoSimConfig[phoneId]) {
1369 mServiceBoundForNoSimConfig[phoneId] = false;
1370 context.unbindService(conn);
1371 }
1372 }
1373
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001374 /**
Rambo Wang610fdf62021-03-08 21:37:11 -08001375 * Returns a boxed Integer object for phoneId, services as message token to distinguish messages
1376 * with same code when calling {@link Handler#removeMessages(int, Object)}.
1377 */
1378 private Integer getMessageToken(int phoneId) {
1379 if (phoneId < -128 || phoneId > 127) {
1380 throw new IllegalArgumentException("phoneId should be in range [-128, 127], inclusive");
1381 }
1382 // Integer#valueOf guarantees the integers within [-128, 127] are cached and thus memory
1383 // comparison (==) returns true for the same integer.
1384 return Integer.valueOf(phoneId);
1385 }
1386
1387 /**
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001388 * If {@code args} contains {@link #DUMP_ARG_REQUESTING_PACKAGE} and a following package name,
1389 * we'll also call {@link IBinder#dump} on the default carrier service (if bound) and the
1390 * specified carrier service (if bound). Typically, this is done for connectivity bug reports
1391 * where we don't call {@code dumpsys activity service all-non-platform} because that contains
1392 * too much info, but we still want to let carrier apps include their diagnostics.
1393 */
Jeff Sharkeya6fcfed2017-07-20 14:18:39 -06001394 @Override
Junda Liu43d723a2015-05-12 17:23:45 -07001395 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001396 IndentingPrintWriter indentPW = new IndentingPrintWriter(pw, " ");
Junda Liu43d723a2015-05-12 17:23:45 -07001397 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
1398 != PackageManager.PERMISSION_GRANTED) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001399 indentPW.println("Permission Denial: can't dump carrierconfig from from pid="
Junda Liu43d723a2015-05-12 17:23:45 -07001400 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
1401 return;
1402 }
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001403 String requestingPackage = null;
1404 int requestingPackageIndex = ArrayUtils.indexOf(args, DUMP_ARG_REQUESTING_PACKAGE);
1405 if (requestingPackageIndex >= 0 && requestingPackageIndex < args.length - 1
1406 && !TextUtils.isEmpty(args[requestingPackageIndex + 1])) {
1407 requestingPackage = args[requestingPackageIndex + 1];
1408 // Throws a SecurityException if the caller is impersonating another app in an effort to
1409 // dump extra info (which may contain PII the caller doesn't have a right to).
1410 enforceCallerIsSystemOrRequestingPackage(requestingPackage);
1411 }
1412
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001413 indentPW.println("CarrierConfigLoader: " + this);
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001414 for (int i = 0; i < TelephonyManager.from(mContext).getActiveModemCount(); i++) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001415 indentPW.println("Phone Id = " + i);
shuoq26a3a4c2016-12-16 11:06:48 -08001416 // display default values in CarrierConfigManager
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001417 printConfig(CarrierConfigManager.getDefaultConfig(), indentPW,
shuoq26a3a4c2016-12-16 11:06:48 -08001418 "Default Values from CarrierConfigManager");
shuoq26a3a4c2016-12-16 11:06:48 -08001419 // display ConfigFromDefaultApp
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001420 printConfig(mConfigFromDefaultApp[i], indentPW, "mConfigFromDefaultApp");
shuoq26a3a4c2016-12-16 11:06:48 -08001421 // display ConfigFromCarrierApp
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001422 printConfig(mConfigFromCarrierApp[i], indentPW, "mConfigFromCarrierApp");
1423 printConfig(mPersistentOverrideConfigs[i], indentPW, "mPersistentOverrideConfigs");
1424 printConfig(mOverrideConfigs[i], indentPW, "mOverrideConfigs");
shuoq26a3a4c2016-12-16 11:06:48 -08001425 }
chen xudb04c292019-03-26 17:01:15 -07001426
Jayachandran C645ec612020-01-10 10:30:25 -08001427 printConfig(mNoSimConfig, indentPW, "mNoSimConfig");
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001428 indentPW.println("CarrierConfigLoadingLog=");
1429 mCarrierConfigLoadingLog.dump(fd, indentPW, args);
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001430
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001431 if (requestingPackage != null) {
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001432 logd("Including default and requesting package " + requestingPackage
1433 + " carrier services in dump");
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001434 indentPW.println("");
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001435 indentPW.println("Connected services");
1436 dumpCarrierServiceIfBound(fd, indentPW, "Default config package",
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001437 mPlatformCarrierConfigPackage, false /* considerCarrierPrivileges */);
1438 dumpCarrierServiceIfBound(fd, indentPW, "Requesting package", requestingPackage,
1439 true /* considerCarrierPrivileges */);
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001440 }
shuoq26a3a4c2016-12-16 11:06:48 -08001441 }
1442
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001443 private void printConfig(PersistableBundle configApp, IndentingPrintWriter indentPW,
1444 String name) {
1445 indentPW.increaseIndent();
shuoq26a3a4c2016-12-16 11:06:48 -08001446 if (configApp == null) {
shuoq26a3a4c2016-12-16 11:06:48 -08001447 indentPW.println(name + " : null ");
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001448 indentPW.decreaseIndent();
1449 indentPW.println("");
shuoq26a3a4c2016-12-16 11:06:48 -08001450 return;
1451 }
shuoq26a3a4c2016-12-16 11:06:48 -08001452 indentPW.println(name + " : ");
1453 List<String> sortedKeys = new ArrayList<String>(configApp.keySet());
1454 Collections.sort(sortedKeys);
1455 indentPW.increaseIndent();
1456 indentPW.increaseIndent();
1457 for (String key : sortedKeys) {
1458 if (configApp.get(key) != null && configApp.get(key) instanceof Object[]) {
1459 indentPW.println(key + " = " +
1460 Arrays.toString((Object[]) configApp.get(key)));
1461 } else if (configApp.get(key) != null && configApp.get(key) instanceof int[]) {
1462 indentPW.println(key + " = " + Arrays.toString((int[]) configApp.get(key)));
1463 } else {
1464 indentPW.println(key + " = " + configApp.get(key));
1465 }
Junda Liu43d723a2015-05-12 17:23:45 -07001466 }
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001467 indentPW.decreaseIndent();
1468 indentPW.decreaseIndent();
1469 indentPW.decreaseIndent();
1470 indentPW.println("");
Junda Liu43d723a2015-05-12 17:23:45 -07001471 }
1472
Hunter Knepshielde601f432020-02-19 10:16:04 -08001473 /**
1474 * Passes without problem when one of these conditions is true:
1475 * - The caller is a privileged UID (e.g. for dumpstate.cpp generating a bug report, where the
1476 * system knows the true caller plumbed in through the {@link android.os.BugreportManager} API).
1477 * - The caller's UID matches the supplied package.
1478 *
1479 * @throws SecurityException if none of the above conditions are met.
1480 */
1481 private void enforceCallerIsSystemOrRequestingPackage(String requestingPackage)
1482 throws SecurityException {
1483 final int callingUid = Binder.getCallingUid();
1484 if (callingUid == Process.ROOT_UID || callingUid == Process.SYSTEM_UID
1485 || callingUid == Process.SHELL_UID || callingUid == Process.PHONE_UID) {
1486 // Bug reports (dumpstate.cpp) run as SHELL, and let some other privileged UIDs through
1487 // as well.
1488 return;
1489 }
1490 // An app is trying to dump extra detail, block it if they aren't who they claim to be.
1491 AppOpsManager appOps = mContext.getSystemService(AppOpsManager.class);
1492 if (appOps == null) {
1493 throw new SecurityException("No AppOps");
1494 }
1495 // Will throw a SecurityException if the UID and package don't match.
1496 appOps.checkPackage(callingUid, requestingPackage);
1497 }
1498
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001499 /**
1500 * Searches for one or more appropriate {@link CarrierService} instances to dump based on the
1501 * current connections.
1502 *
1503 * @param targetPkgName the target package name to dump carrier services for
1504 * @param considerCarrierPrivileges if true, allow a carrier service to be dumped if it shares
1505 * carrier privileges with {@code targetPkgName};
1506 * otherwise, only dump a carrier service if it is {@code
1507 * targetPkgName}
1508 */
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001509 private void dumpCarrierServiceIfBound(FileDescriptor fd, IndentingPrintWriter indentPW,
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001510 String prefix, String targetPkgName, boolean considerCarrierPrivileges) {
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001511 // Null package is possible if it's early in the boot process, there was a recent crash, we
1512 // loaded the config from XML most recently, or a SIM slot is empty. Carrier apps with
1513 // long-lived bindings should typically get dumped here regardless. Even if an app is being
1514 // used for multiple phoneIds, we assume that it's smart enough to handle that on its own,
1515 // and that in most cases we'd just be dumping duplicate information and bloating a report.
1516 indentPW.increaseIndent();
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001517 indentPW.println(prefix + " : " + targetPkgName);
1518 Set<String> dumpedPkgNames = new ArraySet<>(mServiceConnection.length);
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001519 for (CarrierServiceConnection connection : mServiceConnection) {
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001520 if (connection == null || !SubscriptionManager.isValidPhoneId(connection.phoneId)
1521 || TextUtils.isEmpty(connection.pkgName)) {
1522 continue;
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001523 }
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001524 final String servicePkgName = connection.pkgName;
1525 // Note: we intentionally ignore system components here because we should NOT match the
1526 // shell caller that's typically used for bug reports via non-BugreportManager triggers.
1527 final boolean exactPackageMatch = TextUtils.equals(targetPkgName, servicePkgName);
1528 final boolean carrierPrivilegesMatch =
1529 considerCarrierPrivileges && hasCarrierPrivileges(targetPkgName,
1530 connection.phoneId);
1531 if (!exactPackageMatch && !carrierPrivilegesMatch) continue;
1532 // Make sure this service is actually alive before trying to dump it. We don't pay
1533 // attention to mServiceBound[connection.phoneId] because typically carrier apps will
1534 // request long-lived bindings, and even if we unbind the app, it may still be alive due
1535 // to CarrierServiceBindHelper. Pull it out as a reference so even if it gets set to
1536 // null within the ServiceConnection during unbinding we can avoid an NPE.
1537 final IBinder service = connection.service;
1538 if (service == null || !service.isBinderAlive() || !service.pingBinder()) continue;
1539 // We've got a live service. Last check is just to make sure we don't dump a package
1540 // multiple times.
1541 if (!dumpedPkgNames.add(servicePkgName)) continue;
1542 if (!exactPackageMatch) {
1543 logd(targetPkgName + " has carrier privileges on phoneId " + connection.phoneId
1544 + ", service provided by " + servicePkgName);
1545 indentPW.increaseIndent();
1546 indentPW.println("Proxy : " + servicePkgName);
1547 indentPW.decreaseIndent();
1548 }
1549 // Flush before we let the app output anything to ensure correct ordering of output.
1550 // Internally, Binder#dump calls flush on its printer after finishing so we don't
1551 // need to do anything after.
1552 indentPW.flush();
1553 try {
1554 logd("Dumping " + servicePkgName);
1555 // We don't need to give the carrier service any args.
1556 connection.service.dump(fd, null /* args */);
1557 logd("Done with " + servicePkgName);
1558 } catch (RemoteException e) {
1559 logd("RemoteException from " + servicePkgName, e);
1560 indentPW.increaseIndent();
1561 indentPW.println("RemoteException");
1562 indentPW.increaseIndent();
1563 e.printStackTrace(indentPW);
1564 indentPW.decreaseIndent();
1565 indentPW.decreaseIndent();
1566 // We won't retry this package again because now it's in dumpedPkgNames.
1567 }
1568 indentPW.println("");
Jordan Liu46ed5db2020-01-28 08:55:20 -08001569 }
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001570 if (dumpedPkgNames.isEmpty()) {
1571 indentPW.increaseIndent();
1572 indentPW.println("Not bound");
1573 indentPW.decreaseIndent();
1574 indentPW.println("");
1575 }
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001576 indentPW.decreaseIndent();
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001577 }
1578
1579 private boolean hasCarrierPrivileges(String pkgName, int phoneId) {
1580 int[] subIds = SubscriptionManager.getSubId(phoneId);
1581 if (ArrayUtils.isEmpty(subIds)) {
1582 return false;
1583 }
1584 return TelephonyManager.from(mContext).createForSubscriptionId(
1585 subIds[0]).checkCarrierPrivilegesForPackage(pkgName)
1586 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Jordan Liu46ed5db2020-01-28 08:55:20 -08001587 }
1588
Zach Johnson36d7aab2015-05-22 15:43:00 -07001589 private class CarrierServiceConnection implements ServiceConnection {
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001590 final int phoneId;
1591 final String pkgName;
1592 final int eventId;
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001593 IBinder service;
1594
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001595 CarrierServiceConnection(int phoneId, String pkgName, int eventId) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001596 this.phoneId = phoneId;
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001597 this.pkgName = pkgName;
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001598 this.eventId = eventId;
1599 }
1600
1601 @Override
1602 public void onServiceConnected(ComponentName name, IBinder service) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001603 logd("Connected to config app: " + name.flattenToShortString());
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001604 this.service = service;
1605 mHandler.sendMessage(mHandler.obtainMessage(eventId, phoneId, -1, this));
1606 }
1607
1608 @Override
1609 public void onServiceDisconnected(ComponentName name) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001610 logd("Disconnected from config app: " + name.flattenToShortString());
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001611 this.service = null;
Jordan Liu46ed5db2020-01-28 08:55:20 -08001612 }
1613
1614 @Override
1615 public void onBindingDied(ComponentName name) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001616 logd("Binding died from config app: " + name.flattenToShortString());
Jordan Liu46ed5db2020-01-28 08:55:20 -08001617 this.service = null;
Jordan Liu46ed5db2020-01-28 08:55:20 -08001618 }
1619
1620 @Override
1621 public void onNullBinding(ComponentName name) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001622 logd("Null binding from config app: " + name.flattenToShortString());
Jordan Liu46ed5db2020-01-28 08:55:20 -08001623 this.service = null;
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001624 }
1625 }
1626
1627 private class ConfigLoaderBroadcastReceiver extends BroadcastReceiver {
1628 @Override
1629 public void onReceive(Context context, Intent intent) {
1630 String action = intent.getAction();
Junda Liu8a8a53a2015-05-15 16:19:57 -07001631 boolean replace = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
1632 // If replace is true, only care ACTION_PACKAGE_REPLACED.
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001633 if (replace && !Intent.ACTION_PACKAGE_REPLACED.equals(action)) {
Junda Liu8a8a53a2015-05-15 16:19:57 -07001634 return;
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001635 }
Junda Liu8a8a53a2015-05-15 16:19:57 -07001636
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001637 switch (action) {
Nanxi Chen3d670502016-03-17 16:32:09 -07001638 case Intent.ACTION_BOOT_COMPLETED:
1639 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SYSTEM_UNLOCKED, null));
1640 break;
1641
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001642 case Intent.ACTION_PACKAGE_ADDED:
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001643 case Intent.ACTION_PACKAGE_REMOVED:
Junda Liu8a8a53a2015-05-15 16:19:57 -07001644 case Intent.ACTION_PACKAGE_REPLACED:
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001645 int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
1646 String packageName = mContext.getPackageManager().getNameForUid(uid);
Junda Liu8a8a53a2015-05-15 16:19:57 -07001647 if (packageName != null) {
1648 // We don't have a phoneId for arg1.
1649 mHandler.sendMessage(
1650 mHandler.obtainMessage(EVENT_PACKAGE_CHANGED, packageName));
1651 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001652 break;
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001653 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001654 }
1655 }
1656
Rambo Wangab13e3e2021-04-08 15:01:06 -07001657 // Get readable string for the message code supported in this class.
1658 private static String eventToString(int code) {
1659 switch (code) {
1660 case EVENT_CLEAR_CONFIG:
1661 return "EVENT_CLEAR_CONFIG";
1662 case EVENT_CONNECTED_TO_DEFAULT:
1663 return "EVENT_CONNECTED_TO_DEFAULT";
1664 case EVENT_CONNECTED_TO_CARRIER:
1665 return "EVENT_CONNECTED_TO_CARRIER";
1666 case EVENT_FETCH_DEFAULT_DONE:
1667 return "EVENT_FETCH_DEFAULT_DONE";
1668 case EVENT_FETCH_CARRIER_DONE:
1669 return "EVENT_FETCH_CARRIER_DONE";
1670 case EVENT_DO_FETCH_DEFAULT:
1671 return "EVENT_DO_FETCH_DEFAULT";
1672 case EVENT_DO_FETCH_CARRIER:
1673 return "EVENT_DO_FETCH_CARRIER";
1674 case EVENT_PACKAGE_CHANGED:
1675 return "EVENT_PACKAGE_CHANGED";
1676 case EVENT_BIND_DEFAULT_TIMEOUT:
1677 return "EVENT_BIND_DEFAULT_TIMEOUT";
1678 case EVENT_BIND_CARRIER_TIMEOUT:
1679 return "EVENT_BIND_CARRIER_TIMEOUT";
1680 case EVENT_CHECK_SYSTEM_UPDATE:
1681 return "EVENT_CHECK_SYSTEM_UPDATE";
1682 case EVENT_SYSTEM_UNLOCKED:
1683 return "EVENT_SYSTEM_UNLOCKED";
1684 case EVENT_FETCH_DEFAULT_TIMEOUT:
1685 return "EVENT_FETCH_DEFAULT_TIMEOUT";
1686 case EVENT_FETCH_CARRIER_TIMEOUT:
1687 return "EVENT_FETCH_CARRIER_TIMEOUT";
1688 case EVENT_SUBSCRIPTION_INFO_UPDATED:
1689 return "EVENT_SUBSCRIPTION_INFO_UPDATED";
1690 case EVENT_MULTI_SIM_CONFIG_CHANGED:
1691 return "EVENT_MULTI_SIM_CONFIG_CHANGED";
1692 case EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG:
1693 return "EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG";
1694 case EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE:
1695 return "EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE";
1696 case EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG:
1697 return "EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG";
1698 case EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT:
1699 return "EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT";
1700 case EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT:
1701 return "EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT";
1702 default:
1703 return "UNKNOWN(" + code + ")";
1704 }
1705 }
1706
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001707 private void logd(String msg) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001708 Log.d(LOG_TAG, msg);
1709 }
1710
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001711 private void logd(String msg, Throwable tr) {
1712 Log.d(LOG_TAG, msg, tr);
1713 }
1714
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001715 private void logdWithLocalLog(String msg) {
chen xudb04c292019-03-26 17:01:15 -07001716 Log.d(LOG_TAG, msg);
1717 mCarrierConfigLoadingLog.log(msg);
1718 }
1719
1720 private void loge(String msg) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001721 Log.e(LOG_TAG, msg);
chen xudb04c292019-03-26 17:01:15 -07001722 mCarrierConfigLoadingLog.log(msg);
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001723 }
1724}