blob: 4f4b2a7d26bf9552d9d38254b1c19e2877fa8292 [file] [log] [blame]
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001/*
Jonathan Basseri6465afd2015-02-25 13:05:57 -08002 * Copyright (c) 2015, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jonathan Basseri6465afd2015-02-25 13:05:57 -080017package com.android.phone;
18
Jonathan Basseri65273c82017-07-25 15:08:42 -070019import static android.service.carrier.CarrierService.ICarrierServiceWrapper.KEY_CONFIG_BUNDLE;
20import static android.service.carrier.CarrierService.ICarrierServiceWrapper.RESULT_ERROR;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080021
Jonathan Basseri11f89572015-05-05 11:57:39 -070022import android.annotation.NonNull;
Torbjorn Eklund723527a2019-02-13 11:16:25 +010023import android.annotation.Nullable;
Hunter Knepshielde601f432020-02-19 10:16:04 -080024import android.app.AppOpsManager;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080025import android.content.BroadcastReceiver;
26import android.content.ComponentName;
27import android.content.Context;
28import android.content.Intent;
29import android.content.IntentFilter;
30import android.content.ServiceConnection;
Jonathan Basseri7697cae2015-07-06 15:49:23 -070031import android.content.SharedPreferences;
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -070032import android.content.pm.PackageInfo;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070033import android.content.pm.PackageManager;
Junda Liu43d723a2015-05-12 17:23:45 -070034import android.os.Binder;
Jonathan Basseri7697cae2015-07-06 15:49:23 -070035import android.os.Build;
Jonathan Basseri65273c82017-07-25 15:08:42 -070036import android.os.Bundle;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080037import android.os.Handler;
38import android.os.IBinder;
Rambo Wang7e3bc122021-03-23 09:24:38 -070039import android.os.Looper;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080040import android.os.Message;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070041import android.os.PersistableBundle;
Hunter Knepshielde601f432020-02-19 10:16:04 -080042import android.os.Process;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080043import android.os.RemoteException;
Jonathan Basseri65273c82017-07-25 15:08:42 -070044import android.os.ResultReceiver;
Meng Wang97a6a462020-01-23 16:22:16 -080045import android.os.UserHandle;
Jonathan Basseri7697cae2015-07-06 15:49:23 -070046import android.preference.PreferenceManager;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080047import android.service.carrier.CarrierIdentifier;
Zach Johnson36d7aab2015-05-22 15:43:00 -070048import android.service.carrier.CarrierService;
49import android.service.carrier.ICarrierService;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080050import android.telephony.CarrierConfigManager;
51import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080052import android.telephony.TelephonyFrameworkInitializer;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080053import android.telephony.TelephonyManager;
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -080054import android.text.TextUtils;
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -080055import android.util.ArraySet;
chen xudb04c292019-03-26 17:01:15 -070056import android.util.LocalLog;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080057import android.util.Log;
58
Rambo Wang7e3bc122021-03-23 09:24:38 -070059import com.android.internal.annotations.VisibleForTesting;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080060import com.android.internal.telephony.ICarrierConfigLoader;
61import com.android.internal.telephony.IccCardConstants;
62import com.android.internal.telephony.Phone;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080063import com.android.internal.telephony.PhoneFactory;
Nathan Harold48ac0972019-03-13 22:33:01 -070064import com.android.internal.telephony.SubscriptionInfoUpdater;
Jeff Davidsona8e4e242018-03-15 17:16:18 -070065import com.android.internal.telephony.TelephonyPermissions;
Meng Wanga320b942019-11-25 11:21:26 -080066import com.android.internal.telephony.util.ArrayUtils;
shuoq26a3a4c2016-12-16 11:06:48 -080067import com.android.internal.util.IndentingPrintWriter;
arunvoddu664c36a2021-10-11 20:09:28 +000068import com.android.telephony.Rlog;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080069
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -070070import java.io.File;
Junda Liu43d723a2015-05-12 17:23:45 -070071import java.io.FileDescriptor;
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -070072import java.io.FileInputStream;
73import java.io.FileNotFoundException;
74import java.io.FileOutputStream;
Jonathan Basseri1f743c92015-05-15 00:19:46 -070075import java.io.FilenameFilter;
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -070076import java.io.IOException;
Junda Liu43d723a2015-05-12 17:23:45 -070077import java.io.PrintWriter;
shuoq26a3a4c2016-12-16 11:06:48 -080078import java.util.ArrayList;
79import java.util.Arrays;
80import java.util.Collections;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080081import java.util.List;
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -080082import java.util.Set;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080083
84/**
85 * CarrierConfigLoader binds to privileged carrier apps to fetch carrier config overlays.
Jonathan Basseri6465afd2015-02-25 13:05:57 -080086 */
Jonathan Basseri6465afd2015-02-25 13:05:57 -080087public class CarrierConfigLoader extends ICarrierConfigLoader.Stub {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -070088 private static final String LOG_TAG = "CarrierConfigLoader";
Meng Wang33ad2bc2017-03-16 20:21:20 -070089
90 // Package name for platform carrier config app, bundled with system image.
91 private final String mPlatformCarrierConfigPackage;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080092
93 /** The singleton instance. */
94 private static CarrierConfigLoader sInstance;
95 // The context for phone app, passed from PhoneGlobals.
96 private Context mContext;
97 // Carrier configs from default app, indexed by phoneID.
Jonathan Basseric31f1f32015-05-12 10:13:03 -070098 private PersistableBundle[] mConfigFromDefaultApp;
Jonathan Basseri6465afd2015-02-25 13:05:57 -080099 // Carrier configs from privileged carrier config app, indexed by phoneID.
Jonathan Basseric31f1f32015-05-12 10:13:03 -0700100 private PersistableBundle[] mConfigFromCarrierApp;
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100101 // Persistent Carrier configs that are provided via the override test API, indexed by phone ID.
102 private PersistableBundle[] mPersistentOverrideConfigs;
Hall Liu506724b2018-10-22 18:16:14 -0700103 // Carrier configs that are provided via the override test API, indexed by phone ID.
104 private PersistableBundle[] mOverrideConfigs;
Jayachandran C645ec612020-01-10 10:30:25 -0800105 // Carrier configs to override code default when there is no SIM inserted
106 private PersistableBundle mNoSimConfig;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800107 // Service connection for binding to config app.
Zach Johnson36d7aab2015-05-22 15:43:00 -0700108 private CarrierServiceConnection[] mServiceConnection;
Jayachandran C645ec612020-01-10 10:30:25 -0800109 // Service connection for binding to carrier config app for no SIM config.
110 private CarrierServiceConnection[] mServiceConnectionForNoSimConfig;
Rambo Wangb0f3e2f2021-10-28 12:40:12 -0700111 // Whether we are bound to a service for each phone
112 private boolean[] mServiceBound;
113 // Whether we are bound to a service for no SIM config
114 private boolean[] mServiceBoundForNoSimConfig;
Sarah Chin807d5c62020-03-30 17:21:09 -0700115 // Whether we have sent config change broadcast for each phone id.
Junda Liu03aad762017-07-21 13:32:17 -0700116 private boolean[] mHasSentConfigChange;
Sarah Chin807d5c62020-03-30 17:21:09 -0700117 // Whether the broadcast was sent from EVENT_SYSTEM_UNLOCKED, to track rebroadcasts
118 private boolean[] mFromSystemUnlocked;
Nathan Harold48ac0972019-03-13 22:33:01 -0700119 // SubscriptionInfoUpdater
120 private final SubscriptionInfoUpdater mSubscriptionInfoUpdater;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800121
Nanxi Chen3d670502016-03-17 16:32:09 -0700122 // Broadcast receiver for Boot intents, register intent filter in construtor.
123 private final BroadcastReceiver mBootReceiver = new ConfigLoaderBroadcastReceiver();
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800124 // Broadcast receiver for SIM and pkg intents, register intent filter in constructor.
Nanxi Chen3d670502016-03-17 16:32:09 -0700125 private final BroadcastReceiver mPackageReceiver = new ConfigLoaderBroadcastReceiver();
Jack Yu67663de2019-10-17 15:19:48 -0700126 private final LocalLog mCarrierConfigLoadingLog = new LocalLog(100);
chen xudb04c292019-03-26 17:01:15 -0700127
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800128
129 // Message codes; see mHandler below.
130 // Request from SubscriptionInfoUpdater when SIM becomes absent or error.
131 private static final int EVENT_CLEAR_CONFIG = 0;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800132 // Has connected to default app.
133 private static final int EVENT_CONNECTED_TO_DEFAULT = 3;
134 // Has connected to carrier app.
135 private static final int EVENT_CONNECTED_TO_CARRIER = 4;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700136 // Config has been loaded from default app (or cache).
137 private static final int EVENT_FETCH_DEFAULT_DONE = 5;
138 // Config has been loaded from carrier app (or cache).
139 private static final int EVENT_FETCH_CARRIER_DONE = 6;
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700140 // Attempt to fetch from default app or read from XML.
Jonathan Basseri65273c82017-07-25 15:08:42 -0700141 private static final int EVENT_DO_FETCH_DEFAULT = 7;
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700142 // Attempt to fetch from carrier app or read from XML.
Jonathan Basseri65273c82017-07-25 15:08:42 -0700143 private static final int EVENT_DO_FETCH_CARRIER = 8;
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700144 // A package has been installed, uninstalled, or updated.
145 private static final int EVENT_PACKAGE_CHANGED = 9;
Jonathan Basseri930701e2015-06-11 20:56:43 -0700146 // Bind timed out for the default app.
147 private static final int EVENT_BIND_DEFAULT_TIMEOUT = 10;
148 // Bind timed out for a carrier app.
149 private static final int EVENT_BIND_CARRIER_TIMEOUT = 11;
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700150 // Check if the system fingerprint has changed.
151 private static final int EVENT_CHECK_SYSTEM_UPDATE = 12;
Nanxi Chen3d670502016-03-17 16:32:09 -0700152 // Rerun carrier config binding after system is unlocked.
153 private static final int EVENT_SYSTEM_UNLOCKED = 13;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700154 // Fetching config timed out from the default app.
155 private static final int EVENT_FETCH_DEFAULT_TIMEOUT = 14;
156 // Fetching config timed out from a carrier app.
157 private static final int EVENT_FETCH_CARRIER_TIMEOUT = 15;
Nathan Harold48ac0972019-03-13 22:33:01 -0700158 // SubscriptionInfoUpdater has finished updating the sub for the carrier config.
159 private static final int EVENT_SUBSCRIPTION_INFO_UPDATED = 16;
Malcolm Chen5ea18532019-10-24 19:55:44 -0700160 // Multi-SIM config changed.
161 private static final int EVENT_MULTI_SIM_CONFIG_CHANGED = 17;
Jayachandran C645ec612020-01-10 10:30:25 -0800162 // Attempt to fetch from default app or read from XML for no SIM case.
163 private static final int EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG = 18;
164 // No SIM config has been loaded from default app (or cache).
165 private static final int EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE = 19;
166 // Has connected to default app for no SIM config.
167 private static final int EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG = 20;
168 // Bind timed out for the default app when trying to fetch no SIM config.
169 private static final int EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT = 21;
170 // Fetching config timed out from the default app for no SIM config.
171 private static final int EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT = 22;
Rambo Wangab13e3e2021-04-08 15:01:06 -0700172 // NOTE: any new EVENT_* values must be added to method eventToString().
Jonathan Basseri930701e2015-06-11 20:56:43 -0700173
Junda Liu6cb45002016-03-22 17:18:20 -0700174 private static final int BIND_TIMEOUT_MILLIS = 30000;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800175
Meng Wang0f6b2ea2020-01-06 18:31:16 -0800176 // Keys used for saving and restoring config bundle from file.
177 private static final String KEY_VERSION = "__carrier_config_package_version__";
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800178
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100179 private static final String OVERRIDE_PACKAGE_ADDITION = "-override";
180
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700181 // SharedPreferences key for last known build fingerprint.
182 private static final String KEY_FINGERPRINT = "build_fingerprint";
183
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -0800184 // Argument for #dump that indicates we should also call the default and specified carrier
185 // service's #dump method. In multi-SIM devices, it's possible that carrier A is on SIM 1 and
186 // carrier B is on SIM 2, in which case we should not dump carrier B's service when carrier A
187 // requested the dump.
188 private static final String DUMP_ARG_REQUESTING_PACKAGE = "--requesting-package";
189
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800190 // Handler to process various events.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700191 //
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700192 // For each phoneId, the event sequence should be:
Jonathan Basseri65273c82017-07-25 15:08:42 -0700193 // fetch default, connected to default, fetch default (async), fetch default done,
194 // fetch carrier, connected to carrier, fetch carrier (async), fetch carrier done.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700195 //
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700196 // If there is a saved config file for either the default app or the carrier app, we skip
197 // binding to the app and go straight from fetch to loaded.
198 //
199 // At any time, at most one connection is active. If events are not in this order, previous
200 // connection will be unbound, so only latest event takes effect.
201 //
202 // We broadcast ACTION_CARRIER_CONFIG_CHANGED after:
203 // 1. loading from carrier app (even if read from a file)
204 // 2. loading from default app if there is no carrier app (even if read from a file)
205 // 3. clearing config (e.g. due to sim removal)
206 // 4. encountering bind or IPC error
Jonathan Basseri65273c82017-07-25 15:08:42 -0700207 private class ConfigHandler extends Handler {
Rambo Wang7e3bc122021-03-23 09:24:38 -0700208 ConfigHandler(@NonNull Looper looper) {
209 super(looper);
210 }
211
Jonathan Basseri65273c82017-07-25 15:08:42 -0700212 @Override
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800213 public void handleMessage(Message msg) {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700214 final int phoneId = msg.arg1;
Rambo Wangab13e3e2021-04-08 15:01:06 -0700215 logdWithLocalLog("mHandler: " + eventToString(msg.what) + " phoneId: " + phoneId);
Malcolm Chen5ea18532019-10-24 19:55:44 -0700216 if (!SubscriptionManager.isValidPhoneId(phoneId)
217 && msg.what != EVENT_MULTI_SIM_CONFIG_CHANGED) {
218 return;
219 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800220 switch (msg.what) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800221 case EVENT_CLEAR_CONFIG: {
Malcolm Chen5ea18532019-10-24 19:55:44 -0700222 clearConfigForPhone(phoneId, true);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800223 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700224 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700225
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800226 case EVENT_SYSTEM_UNLOCKED: {
Malcolm Chen5ea18532019-10-24 19:55:44 -0700227 for (int i = 0; i < TelephonyManager.from(mContext).getActiveModemCount();
228 ++i) {
Sarah Chin807d5c62020-03-30 17:21:09 -0700229 // When the user unlocks the device, send the broadcast again (with a
230 // rebroadcast extra) if we have sent it before unlock. This will avoid
231 // trying to load the carrier config when the SIM is still loading when the
232 // unlock happens.
Junda Liu03aad762017-07-21 13:32:17 -0700233 if (mHasSentConfigChange[i]) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800234 logdWithLocalLog("System unlocked");
Sarah Chin807d5c62020-03-30 17:21:09 -0700235 mFromSystemUnlocked[i] = true;
Junda Liu03aad762017-07-21 13:32:17 -0700236 updateConfigForPhoneId(i);
237 }
Nanxi Chen3d670502016-03-17 16:32:09 -0700238 }
239 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700240 }
Nanxi Chen3d670502016-03-17 16:32:09 -0700241
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800242 case EVENT_PACKAGE_CHANGED: {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700243 final String carrierPackageName = (String) msg.obj;
244 // Only update if there are cached config removed to avoid updating config for
245 // unrelated packages.
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700246 if (clearCachedConfigForPackage(carrierPackageName)) {
Malcolm Chen5ea18532019-10-24 19:55:44 -0700247 int numPhones = TelephonyManager.from(mContext).getActiveModemCount();
Junda Liu8a8a53a2015-05-15 16:19:57 -0700248 for (int i = 0; i < numPhones; ++i) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800249 logdWithLocalLog("Package changed: " + carrierPackageName
Jack Yu67663de2019-10-17 15:19:48 -0700250 + ", phone=" + i);
Junda Liu8a8a53a2015-05-15 16:19:57 -0700251 updateConfigForPhoneId(i);
252 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700253 }
254 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700255 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700256
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800257 case EVENT_DO_FETCH_DEFAULT: {
Rambo Wang9bc7d362021-03-09 09:10:58 -0800258 // Clear in-memory cache for carrier app config, so when carrier app gets
259 // uninstalled, no stale config is left.
260 if (mConfigFromCarrierApp[phoneId] != null
261 && getCarrierPackageForPhoneId(phoneId) == null) {
262 mConfigFromCarrierApp[phoneId] = null;
263 }
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100264 // Restore persistent override values.
265 PersistableBundle config = restoreConfigFromXml(
266 mPlatformCarrierConfigPackage, OVERRIDE_PACKAGE_ADDITION, phoneId);
267 if (config != null) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800268 logd("Loaded persistent override config from XML. package="
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100269 + mPlatformCarrierConfigPackage
270 + " phoneId=" + phoneId);
271 mPersistentOverrideConfigs[phoneId] = config;
272 }
273
274 config = restoreConfigFromXml(mPlatformCarrierConfigPackage, "", phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700275 if (config != null) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800276 logd(
Jonathan Basseri65273c82017-07-25 15:08:42 -0700277 "Loaded config from XML. package="
278 + mPlatformCarrierConfigPackage
279 + " phoneId="
280 + phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700281 mConfigFromDefaultApp[phoneId] = config;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700282 Message newMsg = obtainMessage(EVENT_FETCH_DEFAULT_DONE, phoneId, -1);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700283 newMsg.getData().putBoolean("loaded_from_xml", true);
284 mHandler.sendMessage(newMsg);
285 } else {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700286 // No cached config, so fetch it from the default app.
287 if (bindToConfigPackage(
288 mPlatformCarrierConfigPackage,
289 phoneId,
290 EVENT_CONNECTED_TO_DEFAULT)) {
291 sendMessageDelayed(
Rambo Wang610fdf62021-03-08 21:37:11 -0800292 obtainMessage(EVENT_BIND_DEFAULT_TIMEOUT, phoneId, -1 /*arg2*/,
293 getMessageToken(phoneId)),
Jonathan Basseri930701e2015-06-11 20:56:43 -0700294 BIND_TIMEOUT_MILLIS);
295 } else {
Nathan Harold1122e3d2021-01-22 15:45:24 -0800296 // Put a stub bundle in place so that the rest of the logic continues
297 // smoothly.
Rambo Wang42026112021-04-07 20:57:28 +0000298 mConfigFromDefaultApp[phoneId] = new PersistableBundle();
Jonathan Basseri65273c82017-07-25 15:08:42 -0700299 // Send broadcast if bind fails.
Nathan Harold48ac0972019-03-13 22:33:01 -0700300 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700301 // TODO: We *must* call unbindService even if bindService returns false.
302 // (And possibly if SecurityException was thrown.)
chen xudb04c292019-03-26 17:01:15 -0700303 loge("binding to default app: "
304 + mPlatformCarrierConfigPackage + " fails");
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700305 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800306 }
307 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700308 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800309
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800310 case EVENT_CONNECTED_TO_DEFAULT: {
Rambo Wang610fdf62021-03-08 21:37:11 -0800311 removeMessages(EVENT_BIND_DEFAULT_TIMEOUT, getMessageToken(phoneId));
Jonathan Basseri65273c82017-07-25 15:08:42 -0700312 final CarrierServiceConnection conn = (CarrierServiceConnection) msg.obj;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800313 // If new service connection has been created, unbind.
314 if (mServiceConnection[phoneId] != conn || conn.service == null) {
Rambo Wangb0f3e2f2021-10-28 12:40:12 -0700315 unbindIfBound(mContext, conn, phoneId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800316 break;
317 }
chen xu02581692018-11-11 19:03:44 -0800318 final CarrierIdentifier carrierId = getCarrierIdentifierForPhoneId(phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700319 // ResultReceiver callback will execute in this Handler's thread.
320 final ResultReceiver resultReceiver =
321 new ResultReceiver(this) {
322 @Override
323 public void onReceiveResult(int resultCode, Bundle resultData) {
Rambo Wangb0f3e2f2021-10-28 12:40:12 -0700324 unbindIfBound(mContext, conn, phoneId);
Rambo Wanga9d27a52021-04-09 16:17:33 -0700325 removeMessages(EVENT_FETCH_DEFAULT_TIMEOUT,
326 getMessageToken(phoneId));
Jonathan Basseri65273c82017-07-25 15:08:42 -0700327 // If new service connection has been created, this is stale.
328 if (mServiceConnection[phoneId] != conn) {
329 loge("Received response for stale request.");
330 return;
331 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700332 if (resultCode == RESULT_ERROR || resultData == null) {
333 // On error, abort config fetching.
334 loge("Failed to get carrier config");
Nathan Harold48ac0972019-03-13 22:33:01 -0700335 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700336 return;
337 }
338 PersistableBundle config =
339 resultData.getParcelable(KEY_CONFIG_BUNDLE);
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100340 saveConfigToXml(mPlatformCarrierConfigPackage, "", phoneId,
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800341 carrierId, config);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700342 mConfigFromDefaultApp[phoneId] = config;
343 sendMessage(
344 obtainMessage(
345 EVENT_FETCH_DEFAULT_DONE, phoneId, -1));
346 }
347 };
348 // Now fetch the config asynchronously from the ICarrierService.
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800349 try {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700350 ICarrierService carrierService =
351 ICarrierService.Stub.asInterface(conn.service);
Rambo Wang38bbdbe2021-11-23 13:03:34 -0800352 carrierService.getCarrierConfig(phoneId, carrierId, resultReceiver);
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800353 logdWithLocalLog("Fetch config for default app: "
chen xudb04c292019-03-26 17:01:15 -0700354 + mPlatformCarrierConfigPackage
355 + " carrierid: " + carrierId.toString());
Jonathan Basseri65273c82017-07-25 15:08:42 -0700356 } catch (RemoteException e) {
chen xudb04c292019-03-26 17:01:15 -0700357 loge("Failed to get carrier config from default app: " +
358 mPlatformCarrierConfigPackage + " err: " + e.toString());
Rambo Wangb0f3e2f2021-10-28 12:40:12 -0700359 unbindIfBound(mContext, conn, phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700360 break; // So we don't set a timeout.
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800361 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700362 sendMessageDelayed(
Rambo Wang610fdf62021-03-08 21:37:11 -0800363 obtainMessage(EVENT_FETCH_DEFAULT_TIMEOUT, phoneId, -1 /*arg2*/,
364 getMessageToken(phoneId)),
Jonathan Basseri65273c82017-07-25 15:08:42 -0700365 BIND_TIMEOUT_MILLIS);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800366 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700367 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800368
Jonathan Basseri930701e2015-06-11 20:56:43 -0700369 case EVENT_BIND_DEFAULT_TIMEOUT:
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800370 case EVENT_FETCH_DEFAULT_TIMEOUT: {
371 loge("Bind/fetch time out from " + mPlatformCarrierConfigPackage);
Rambo Wang610fdf62021-03-08 21:37:11 -0800372 removeMessages(EVENT_FETCH_DEFAULT_TIMEOUT, getMessageToken(phoneId));
chen xuf60b3162019-05-01 21:31:05 -0700373 // If we attempted to bind to the app, but the service connection is null due to
374 // the race condition that clear config event happens before bind/fetch complete
375 // then config was cleared while we were waiting and we should not continue.
376 if (mServiceConnection[phoneId] != null) {
377 // If a ResponseReceiver callback is in the queue when this happens, we will
378 // unbind twice and throw an exception.
Rambo Wangb0f3e2f2021-10-28 12:40:12 -0700379 unbindIfBound(mContext, mServiceConnection[phoneId], phoneId);
chen xuf60b3162019-05-01 21:31:05 -0700380 broadcastConfigChangedIntent(phoneId);
381 }
Nathan Harold1122e3d2021-01-22 15:45:24 -0800382 // Put a stub bundle in place so that the rest of the logic continues smoothly.
Rambo Wang42026112021-04-07 20:57:28 +0000383 mConfigFromDefaultApp[phoneId] = new PersistableBundle();
Nathan Harold48ac0972019-03-13 22:33:01 -0700384 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri930701e2015-06-11 20:56:43 -0700385 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700386 }
Jonathan Basseri930701e2015-06-11 20:56:43 -0700387
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800388 case EVENT_FETCH_DEFAULT_DONE: {
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700389 // If we attempted to bind to the app, but the service connection is null, then
390 // config was cleared while we were waiting and we should not continue.
391 if (!msg.getData().getBoolean("loaded_from_xml", false)
392 && mServiceConnection[phoneId] == null) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800393 break;
394 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700395 final String carrierPackageName = getCarrierPackageForPhoneId(phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700396 if (carrierPackageName != null) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800397 logd("Found carrier config app: " + carrierPackageName);
Jordan Liu38a614c2019-03-20 15:01:17 -0700398 sendMessage(obtainMessage(EVENT_DO_FETCH_CARRIER, phoneId, -1));
Jonathan Basserib919e932015-05-27 16:53:08 +0000399 } else {
Nathan Harold48ac0972019-03-13 22:33:01 -0700400 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri4ae2e7c2015-05-15 00:19:46 -0700401 }
402 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700403 }
Jonathan Basseri4ae2e7c2015-05-15 00:19:46 -0700404
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800405 case EVENT_DO_FETCH_CARRIER: {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700406 final String carrierPackageName = getCarrierPackageForPhoneId(phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700407 final PersistableBundle config =
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100408 restoreConfigFromXml(carrierPackageName, "", phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700409 if (config != null) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800410 logd(
Jonathan Basseri65273c82017-07-25 15:08:42 -0700411 "Loaded config from XML. package="
412 + carrierPackageName
413 + " phoneId="
414 + phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700415 mConfigFromCarrierApp[phoneId] = config;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700416 Message newMsg = obtainMessage(EVENT_FETCH_CARRIER_DONE, phoneId, -1);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700417 newMsg.getData().putBoolean("loaded_from_xml", true);
418 sendMessage(newMsg);
419 } else {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700420 // No cached config, so fetch it from a carrier app.
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800421 if (carrierPackageName != null && bindToConfigPackage(carrierPackageName,
422 phoneId, EVENT_CONNECTED_TO_CARRIER)) {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700423 sendMessageDelayed(
Rambo Wang610fdf62021-03-08 21:37:11 -0800424 obtainMessage(EVENT_BIND_CARRIER_TIMEOUT, phoneId, -1 /*arg2*/,
425 getMessageToken(phoneId)),
Jonathan Basseri930701e2015-06-11 20:56:43 -0700426 BIND_TIMEOUT_MILLIS);
427 } else {
Nathan Harold1122e3d2021-01-22 15:45:24 -0800428 // Put a stub bundle in place so that the rest of the logic continues
429 // smoothly.
Rambo Wang42026112021-04-07 20:57:28 +0000430 mConfigFromCarrierApp[phoneId] = new PersistableBundle();
Jonathan Basseri65273c82017-07-25 15:08:42 -0700431 // Send broadcast if bind fails.
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700432 broadcastConfigChangedIntent(phoneId);
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800433 loge("Bind to carrier app: " + carrierPackageName + " fails");
Nathan Harold48ac0972019-03-13 22:33:01 -0700434 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700435 }
436 }
437 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700438 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700439
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800440 case EVENT_CONNECTED_TO_CARRIER: {
Rambo Wang610fdf62021-03-08 21:37:11 -0800441 removeMessages(EVENT_BIND_CARRIER_TIMEOUT, getMessageToken(phoneId));
Jonathan Basseri65273c82017-07-25 15:08:42 -0700442 final CarrierServiceConnection conn = (CarrierServiceConnection) msg.obj;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800443 // If new service connection has been created, unbind.
Jonathan Basseri65273c82017-07-25 15:08:42 -0700444 if (mServiceConnection[phoneId] != conn || conn.service == null) {
Rambo Wangb0f3e2f2021-10-28 12:40:12 -0700445 unbindIfBound(mContext, conn, phoneId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800446 break;
447 }
chen xu02581692018-11-11 19:03:44 -0800448 final CarrierIdentifier carrierId = getCarrierIdentifierForPhoneId(phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700449 // ResultReceiver callback will execute in this Handler's thread.
450 final ResultReceiver resultReceiver =
451 new ResultReceiver(this) {
452 @Override
453 public void onReceiveResult(int resultCode, Bundle resultData) {
Rambo Wangb0f3e2f2021-10-28 12:40:12 -0700454 unbindIfBound(mContext, conn, phoneId);
Rambo Wanga9d27a52021-04-09 16:17:33 -0700455 removeMessages(EVENT_FETCH_CARRIER_TIMEOUT,
456 getMessageToken(phoneId));
Jonathan Basseri65273c82017-07-25 15:08:42 -0700457 // If new service connection has been created, this is stale.
458 if (mServiceConnection[phoneId] != conn) {
459 loge("Received response for stale request.");
460 return;
461 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700462 if (resultCode == RESULT_ERROR || resultData == null) {
463 // On error, abort config fetching.
chen xudb04c292019-03-26 17:01:15 -0700464 loge("Failed to get carrier config from carrier app: "
465 + getCarrierPackageForPhoneId(phoneId));
Jonathan Basseri65273c82017-07-25 15:08:42 -0700466 broadcastConfigChangedIntent(phoneId);
Nathan Harold48ac0972019-03-13 22:33:01 -0700467 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700468 return;
469 }
470 PersistableBundle config =
471 resultData.getParcelable(KEY_CONFIG_BUNDLE);
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100472 saveConfigToXml(getCarrierPackageForPhoneId(phoneId), "",
473 phoneId, carrierId, config);
Amit Mahajan304e92b2021-04-08 14:03:30 -0700474 if (config != null) {
475 mConfigFromCarrierApp[phoneId] = config;
476 } else {
477 logdWithLocalLog("Config from carrier app is null "
478 + "for phoneId " + phoneId);
479 // Put a stub bundle in place so that the rest of the logic
480 // continues smoothly.
481 mConfigFromCarrierApp[phoneId] = new PersistableBundle();
482 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700483 sendMessage(
484 obtainMessage(
485 EVENT_FETCH_CARRIER_DONE, phoneId, -1));
486 }
487 };
488 // Now fetch the config asynchronously from the ICarrierService.
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800489 try {
Jonathan Basseri65273c82017-07-25 15:08:42 -0700490 ICarrierService carrierService =
491 ICarrierService.Stub.asInterface(conn.service);
Rambo Wang38bbdbe2021-11-23 13:03:34 -0800492 carrierService.getCarrierConfig(phoneId, carrierId, resultReceiver);
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800493 logdWithLocalLog("Fetch config for carrier app: "
chen xudb04c292019-03-26 17:01:15 -0700494 + getCarrierPackageForPhoneId(phoneId)
495 + " carrierid: " + carrierId.toString());
Jonathan Basseri65273c82017-07-25 15:08:42 -0700496 } catch (RemoteException e) {
497 loge("Failed to get carrier config: " + e.toString());
Rambo Wangb0f3e2f2021-10-28 12:40:12 -0700498 unbindIfBound(mContext, conn, phoneId);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700499 break; // So we don't set a timeout.
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800500 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700501 sendMessageDelayed(
Rambo Wang610fdf62021-03-08 21:37:11 -0800502 obtainMessage(EVENT_FETCH_CARRIER_TIMEOUT, phoneId, -1 /*arg2*/,
503 getMessageToken(phoneId)),
Jonathan Basseri65273c82017-07-25 15:08:42 -0700504 BIND_TIMEOUT_MILLIS);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800505 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700506 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800507
Jonathan Basseri930701e2015-06-11 20:56:43 -0700508 case EVENT_BIND_CARRIER_TIMEOUT:
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800509 case EVENT_FETCH_CARRIER_TIMEOUT: {
Nathan Harold1122e3d2021-01-22 15:45:24 -0800510 loge("Bind/fetch from carrier app timeout, package="
511 + getCarrierPackageForPhoneId(phoneId));
Rambo Wang610fdf62021-03-08 21:37:11 -0800512 removeMessages(EVENT_FETCH_CARRIER_TIMEOUT, getMessageToken(phoneId));
chen xuf60b3162019-05-01 21:31:05 -0700513 // If we attempted to bind to the app, but the service connection is null due to
514 // the race condition that clear config event happens before bind/fetch complete
515 // then config was cleared while we were waiting and we should not continue.
516 if (mServiceConnection[phoneId] != null) {
517 // If a ResponseReceiver callback is in the queue when this happens, we will
518 // unbind twice and throw an exception.
Rambo Wangb0f3e2f2021-10-28 12:40:12 -0700519 unbindIfBound(mContext, mServiceConnection[phoneId], phoneId);
chen xuf60b3162019-05-01 21:31:05 -0700520 broadcastConfigChangedIntent(phoneId);
521 }
Nathan Harold1122e3d2021-01-22 15:45:24 -0800522 // Put a stub bundle in place so that the rest of the logic continues smoothly.
Rambo Wang42026112021-04-07 20:57:28 +0000523 mConfigFromCarrierApp[phoneId] = new PersistableBundle();
Nathan Harold48ac0972019-03-13 22:33:01 -0700524 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri930701e2015-06-11 20:56:43 -0700525 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700526 }
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800527 case EVENT_FETCH_CARRIER_DONE: {
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700528 // If we attempted to bind to the app, but the service connection is null, then
529 // config was cleared while we were waiting and we should not continue.
530 if (!msg.getData().getBoolean("loaded_from_xml", false)
531 && mServiceConnection[phoneId] == null) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800532 break;
533 }
Nathan Harold48ac0972019-03-13 22:33:01 -0700534 notifySubscriptionInfoUpdater(phoneId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800535 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700536 }
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700537
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800538 case EVENT_CHECK_SYSTEM_UPDATE: {
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700539 SharedPreferences sharedPrefs =
540 PreferenceManager.getDefaultSharedPreferences(mContext);
541 final String lastFingerprint = sharedPrefs.getString(KEY_FINGERPRINT, null);
542 if (!Build.FINGERPRINT.equals(lastFingerprint)) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800543 logd(
Jonathan Basseri65273c82017-07-25 15:08:42 -0700544 "Build fingerprint changed. old: "
545 + lastFingerprint
546 + " new: "
547 + Build.FINGERPRINT);
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700548 clearCachedConfigForPackage(null);
Jonathan Basseri65273c82017-07-25 15:08:42 -0700549 sharedPrefs
550 .edit()
551 .putString(KEY_FINGERPRINT, Build.FINGERPRINT)
552 .apply();
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700553 }
554 break;
Jonathan Basseri65273c82017-07-25 15:08:42 -0700555 }
Nathan Harold48ac0972019-03-13 22:33:01 -0700556
557 case EVENT_SUBSCRIPTION_INFO_UPDATED:
558 broadcastConfigChangedIntent(phoneId);
559 break;
Malcolm Chen5ea18532019-10-24 19:55:44 -0700560 case EVENT_MULTI_SIM_CONFIG_CHANGED:
561 onMultiSimConfigChanged();
562 break;
Jayachandran C645ec612020-01-10 10:30:25 -0800563
564 case EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG: {
565 PersistableBundle config =
566 restoreNoSimConfigFromXml(mPlatformCarrierConfigPackage);
567
568 if (config != null) {
569 logd("Loaded no SIM config from XML. package="
570 + mPlatformCarrierConfigPackage);
571 mNoSimConfig = config;
572 sendMessage(
573 obtainMessage(
574 EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE,
575 phoneId, -1));
576 } else {
577 // No cached config, so fetch it from the default app.
578 if (bindToConfigPackage(
579 mPlatformCarrierConfigPackage,
580 phoneId,
581 EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG)) {
582 sendMessageDelayed(
583 obtainMessage(
584 EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT,
585 phoneId, -1), BIND_TIMEOUT_MILLIS);
586 } else {
587 broadcastConfigChangedIntent(phoneId, false);
588 // TODO: We *must* call unbindService even if bindService returns false.
589 // (And possibly if SecurityException was thrown.)
590 loge("binding to default app to fetch no SIM config: "
591 + mPlatformCarrierConfigPackage + " fails");
592 }
593 }
594 break;
595 }
596
597 case EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE: {
598 broadcastConfigChangedIntent(phoneId, false);
599 break;
600 }
601
602 case EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT:
603 case EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT: {
604 loge("Bind/fetch time out for no SIM config from "
605 + mPlatformCarrierConfigPackage);
606 removeMessages(EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT);
607 // If we attempted to bind to the app, but the service connection is null due to
608 // the race condition that clear config event happens before bind/fetch complete
609 // then config was cleared while we were waiting and we should not continue.
610 if (mServiceConnectionForNoSimConfig[phoneId] != null) {
611 // If a ResponseReceiver callback is in the queue when this happens, we will
612 // unbind twice and throw an exception.
Rambo Wangb0f3e2f2021-10-28 12:40:12 -0700613 unbindIfBoundForNoSimConfig(mContext,
614 mServiceConnectionForNoSimConfig[phoneId], phoneId);
Jayachandran C645ec612020-01-10 10:30:25 -0800615 }
616 broadcastConfigChangedIntent(phoneId, false);
617 break;
618 }
619
620 case EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG: {
621 removeMessages(EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT);
622 final CarrierServiceConnection conn = (CarrierServiceConnection) msg.obj;
623 // If new service connection has been created, unbind.
624 if (mServiceConnectionForNoSimConfig[phoneId] != conn || conn.service == null) {
Rambo Wangb0f3e2f2021-10-28 12:40:12 -0700625 unbindIfBoundForNoSimConfig(mContext, conn, phoneId);
Jayachandran C645ec612020-01-10 10:30:25 -0800626 break;
627 }
628
629 // ResultReceiver callback will execute in this Handler's thread.
630 final ResultReceiver resultReceiver =
631 new ResultReceiver(this) {
632 @Override
633 public void onReceiveResult(int resultCode, Bundle resultData) {
Rambo Wangb0f3e2f2021-10-28 12:40:12 -0700634 unbindIfBoundForNoSimConfig(mContext, conn, phoneId);
Jayachandran C645ec612020-01-10 10:30:25 -0800635 // If new service connection has been created, this is stale.
636 if (mServiceConnectionForNoSimConfig[phoneId] != conn) {
637 loge("Received response for stale request.");
638 return;
639 }
640 removeMessages(EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT);
641 if (resultCode == RESULT_ERROR || resultData == null) {
642 // On error, abort config fetching.
643 loge("Failed to get no SIM carrier config");
644 return;
645 }
646 PersistableBundle config =
647 resultData.getParcelable(KEY_CONFIG_BUNDLE);
648 saveNoSimConfigToXml(mPlatformCarrierConfigPackage, config);
649 mNoSimConfig = config;
650 sendMessage(
651 obtainMessage(
652 EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE,
653 phoneId, -1));
654 }
655 };
656 // Now fetch the config asynchronously from the ICarrierService.
657 try {
658 ICarrierService carrierService =
659 ICarrierService.Stub.asInterface(conn.service);
Rambo Wang38bbdbe2021-11-23 13:03:34 -0800660 carrierService.getCarrierConfig(phoneId, null, resultReceiver);
Jayachandran C645ec612020-01-10 10:30:25 -0800661 logdWithLocalLog("Fetch no sim config from default app: "
662 + mPlatformCarrierConfigPackage);
663 } catch (RemoteException e) {
664 loge("Failed to get no sim carrier config from default app: " +
665 mPlatformCarrierConfigPackage + " err: " + e.toString());
Rambo Wangb0f3e2f2021-10-28 12:40:12 -0700666 unbindIfBoundForNoSimConfig(mContext, conn, phoneId);
Jayachandran C645ec612020-01-10 10:30:25 -0800667 break; // So we don't set a timeout.
668 }
669 sendMessageDelayed(
670 obtainMessage(
671 EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT,
672 phoneId, -1), BIND_TIMEOUT_MILLIS);
673 break;
674 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800675 }
676 }
Jonathan Basseri65273c82017-07-25 15:08:42 -0700677 }
678
679 private final Handler mHandler;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800680
681 /**
682 * Constructs a CarrierConfigLoader, registers it as a service, and registers a broadcast
683 * receiver for relevant events.
684 */
Rambo Wang7e3bc122021-03-23 09:24:38 -0700685 @VisibleForTesting
686 /* package */ CarrierConfigLoader(Context context,
687 SubscriptionInfoUpdater subscriptionInfoUpdater, @NonNull Looper looper) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800688 mContext = context;
Meng Wang33ad2bc2017-03-16 20:21:20 -0700689 mPlatformCarrierConfigPackage =
690 mContext.getString(R.string.platform_carrier_config_package);
Rambo Wang7e3bc122021-03-23 09:24:38 -0700691 mHandler = new ConfigHandler(looper);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800692
Nanxi Chen3d670502016-03-17 16:32:09 -0700693 IntentFilter bootFilter = new IntentFilter();
694 bootFilter.addAction(Intent.ACTION_BOOT_COMPLETED);
695 context.registerReceiver(mBootReceiver, bootFilter);
696
Junda Liu8a8a53a2015-05-15 16:19:57 -0700697 // Register for package updates. Update app or uninstall app update will have all 3 intents,
698 // in the order or removed, added, replaced, all with extra_replace set to true.
699 IntentFilter pkgFilter = new IntentFilter();
700 pkgFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
701 pkgFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
702 pkgFilter.addAction(Intent.ACTION_PACKAGE_REPLACED);
703 pkgFilter.addDataScheme("package");
Jordan Liu5ca24762019-07-10 12:51:09 -0700704 context.registerReceiver(mPackageReceiver, pkgFilter);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800705
Malcolm Chen978dda52019-10-08 18:15:25 -0700706 int numPhones = TelephonyManager.from(context).getSupportedModemCount();
Jonathan Basseric31f1f32015-05-12 10:13:03 -0700707 mConfigFromDefaultApp = new PersistableBundle[numPhones];
708 mConfigFromCarrierApp = new PersistableBundle[numPhones];
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100709 mPersistentOverrideConfigs = new PersistableBundle[numPhones];
Hall Liu506724b2018-10-22 18:16:14 -0700710 mOverrideConfigs = new PersistableBundle[numPhones];
Rambo Wang42026112021-04-07 20:57:28 +0000711 mNoSimConfig = new PersistableBundle();
Zach Johnson36d7aab2015-05-22 15:43:00 -0700712 mServiceConnection = new CarrierServiceConnection[numPhones];
Rambo Wangb0f3e2f2021-10-28 12:40:12 -0700713 mServiceBound = new boolean[numPhones];
Junda Liu03aad762017-07-21 13:32:17 -0700714 mHasSentConfigChange = new boolean[numPhones];
Sarah Chin807d5c62020-03-30 17:21:09 -0700715 mFromSystemUnlocked = new boolean[numPhones];
Jayachandran C645ec612020-01-10 10:30:25 -0800716 mServiceConnectionForNoSimConfig = new CarrierServiceConnection[numPhones];
Rambo Wangb0f3e2f2021-10-28 12:40:12 -0700717 mServiceBoundForNoSimConfig = new boolean[numPhones];
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800718 logd("CarrierConfigLoader has started");
Rambo Wang7e3bc122021-03-23 09:24:38 -0700719 mSubscriptionInfoUpdater = subscriptionInfoUpdater;
Jonathan Basseri7697cae2015-07-06 15:49:23 -0700720 mHandler.sendEmptyMessage(EVENT_CHECK_SYSTEM_UPDATE);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800721 }
722
723 /**
724 * Initialize the singleton CarrierConfigLoader instance.
725 *
726 * This is only done once, at startup, from {@link com.android.phone.PhoneApp#onCreate}.
727 */
Rambo Wang7e3bc122021-03-23 09:24:38 -0700728 /* package */ static CarrierConfigLoader init(Context context) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800729 synchronized (CarrierConfigLoader.class) {
730 if (sInstance == null) {
Rambo Wang7e3bc122021-03-23 09:24:38 -0700731 sInstance = new CarrierConfigLoader(context,
732 PhoneFactory.getSubscriptionInfoUpdater(), Looper.myLooper());
Brad Ebingerfa6575f2021-05-04 00:29:50 +0000733 // Make this service available through ServiceManager.
734 TelephonyFrameworkInitializer.getTelephonyServiceManager()
735 .getCarrierConfigServiceRegisterer().register(sInstance);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800736 } else {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700737 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800738 }
739 return sInstance;
740 }
741 }
742
Rambo Wang7e3bc122021-03-23 09:24:38 -0700743 @VisibleForTesting
744 /* package */ void clearConfigForPhone(int phoneId, boolean fetchNoSimConfig) {
Malcolm Chen5ea18532019-10-24 19:55:44 -0700745 /* Ignore clear configuration request if device is being shutdown. */
746 Phone phone = PhoneFactory.getPhone(phoneId);
747 if (phone != null) {
748 if (phone.isShuttingDown()) {
749 return;
750 }
751 }
752
753 mConfigFromDefaultApp[phoneId] = null;
754 mConfigFromCarrierApp[phoneId] = null;
755 mServiceConnection[phoneId] = null;
756 mHasSentConfigChange[phoneId] = false;
757
Jayachandran C645ec612020-01-10 10:30:25 -0800758 if (fetchNoSimConfig) {
759 // To fetch no SIM config
760 mHandler.sendMessage(
761 mHandler.obtainMessage(
762 EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG, phoneId, -1));
763 }
Malcolm Chen5ea18532019-10-24 19:55:44 -0700764 }
765
Nathan Harold48ac0972019-03-13 22:33:01 -0700766 private void notifySubscriptionInfoUpdater(int phoneId) {
767 String configPackagename;
768 PersistableBundle configToSend;
769 int carrierId = getSpecificCarrierIdForPhoneId(phoneId);
770 // Prefer the carrier privileged carrier app, but if there is not one, use the platform
771 // default carrier app.
772 if (mConfigFromCarrierApp[phoneId] != null) {
773 configPackagename = getCarrierPackageForPhoneId(phoneId);
774 configToSend = mConfigFromCarrierApp[phoneId];
775 } else {
776 configPackagename = mPlatformCarrierConfigPackage;
777 configToSend = mConfigFromDefaultApp[phoneId];
778 }
Nazanin Bakhshi6fcc3342019-09-18 17:54:01 -0700779
Malcolm Chenefafd1c2020-02-20 13:27:08 -0800780 if (configToSend == null) {
Rambo Wang42026112021-04-07 20:57:28 +0000781 configToSend = new PersistableBundle();
Malcolm Chenefafd1c2020-02-20 13:27:08 -0800782 }
783
Nazanin Bakhshi6fcc3342019-09-18 17:54:01 -0700784 // mOverrideConfigs is for testing. And it will override current configs.
785 PersistableBundle config = mOverrideConfigs[phoneId];
786 if (config != null) {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +0100787 configToSend = new PersistableBundle(configToSend);
Nazanin Bakhshi6fcc3342019-09-18 17:54:01 -0700788 configToSend.putAll(config);
789 }
790
Nathan Harold48ac0972019-03-13 22:33:01 -0700791 mSubscriptionInfoUpdater.updateSubscriptionByCarrierConfigAndNotifyComplete(
792 phoneId, configPackagename, configToSend,
793 mHandler.obtainMessage(EVENT_SUBSCRIPTION_INFO_UPDATED, phoneId, -1));
794 }
795
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800796 private void broadcastConfigChangedIntent(int phoneId) {
Amit Mahajanf8088ab2018-03-02 15:24:07 -0800797 broadcastConfigChangedIntent(phoneId, true);
798 }
799
800 private void broadcastConfigChangedIntent(int phoneId, boolean addSubIdExtra) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800801 Intent intent = new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
Christopher Tate38f55eb2017-02-14 14:43:49 -0800802 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT |
chen xuf9db49f2019-03-31 23:04:42 -0700803 Intent.FLAG_RECEIVER_FOREGROUND);
Qiongcheng Luoe7de61b2018-08-06 10:20:09 +0800804 if (addSubIdExtra) {
805 int simApplicationState = TelephonyManager.SIM_STATE_UNKNOWN;
806 int[] subIds = SubscriptionManager.getSubId(phoneId);
807 if (!ArrayUtils.isEmpty(subIds)) {
808 TelephonyManager telMgr = TelephonyManager.from(mContext)
809 .createForSubscriptionId(subIds[0]);
810 simApplicationState = telMgr.getSimApplicationState();
811 }
Malcolm Chenf7635ec2020-04-15 15:45:00 -0700812 logd("Broadcast CARRIER_CONFIG_CHANGED for phone " + phoneId
813 + " simApplicationState " + simApplicationState);
Qiongcheng Luoe7de61b2018-08-06 10:20:09 +0800814 // Include subId/carrier id extra only if SIM records are loaded
815 if (simApplicationState != TelephonyManager.SIM_STATE_UNKNOWN
816 && simApplicationState != TelephonyManager.SIM_STATE_NOT_READY) {
817 SubscriptionManager.putPhoneIdAndSubIdExtra(intent, phoneId);
818 intent.putExtra(TelephonyManager.EXTRA_SPECIFIC_CARRIER_ID,
819 getSpecificCarrierIdForPhoneId(phoneId));
820 intent.putExtra(TelephonyManager.EXTRA_CARRIER_ID, getCarrierIdForPhoneId(phoneId));
821 }
Amit Mahajanf8088ab2018-03-02 15:24:07 -0800822 }
Amit Mahajanb33bcda2018-01-24 12:56:44 -0800823 intent.putExtra(CarrierConfigManager.EXTRA_SLOT_INDEX, phoneId);
Sarah Chin807d5c62020-03-30 17:21:09 -0700824 intent.putExtra(CarrierConfigManager.EXTRA_REBROADCAST_ON_UNLOCK,
825 mFromSystemUnlocked[phoneId]);
Meng Wang97a6a462020-01-23 16:22:16 -0800826 mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
Jack Yue9e95be2020-03-22 10:56:06 -0700827 int[] subIds = SubscriptionManager.getSubId(phoneId);
828 if (subIds != null && subIds.length > 0) {
829 logd("Broadcast CARRIER_CONFIG_CHANGED for phone " + phoneId + ", subId=" + subIds[0]);
830 } else {
831 logd("Broadcast CARRIER_CONFIG_CHANGED for phone " + phoneId);
832 }
Junda Liu03aad762017-07-21 13:32:17 -0700833 mHasSentConfigChange[phoneId] = true;
Sarah Chin807d5c62020-03-30 17:21:09 -0700834 mFromSystemUnlocked[phoneId] = false;
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800835 }
836
837 /** Binds to the default or carrier config app. */
838 private boolean bindToConfigPackage(String pkgName, int phoneId, int eventId) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -0800839 logdWithLocalLog("Binding to " + pkgName + " for phone " + phoneId);
Zach Johnsonfca8a8d2015-06-19 18:21:37 -0700840 Intent carrierService = new Intent(CarrierService.CARRIER_SERVICE_INTERFACE);
Zach Johnson36d7aab2015-05-22 15:43:00 -0700841 carrierService.setPackage(pkgName);
Jayachandran C645ec612020-01-10 10:30:25 -0800842 CarrierServiceConnection serviceConnection = new CarrierServiceConnection(
843 phoneId, pkgName, eventId);
844 if (eventId == EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG) {
845 mServiceConnectionForNoSimConfig[phoneId] = serviceConnection;
846 } else {
847 mServiceConnection[phoneId] = serviceConnection;
848 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800849 try {
Jayachandran C645ec612020-01-10 10:30:25 -0800850 if (mContext.bindService(carrierService, serviceConnection,
Jordan Liu178430d2020-02-10 14:32:15 -0800851 Context.BIND_AUTO_CREATE)) {
Rambo Wangb0f3e2f2021-10-28 12:40:12 -0700852 if (eventId == EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG) {
853 mServiceBoundForNoSimConfig[phoneId] = true;
854 } else {
855 mServiceBound[phoneId] = true;
856 }
Jordan Liu178430d2020-02-10 14:32:15 -0800857 return true;
858 } else {
859 return false;
860 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800861 } catch (SecurityException ex) {
862 return false;
863 }
864 }
865
Rambo Wang7e3bc122021-03-23 09:24:38 -0700866 @VisibleForTesting
867 /* package */ CarrierIdentifier getCarrierIdentifierForPhoneId(int phoneId) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800868 String mcc = "";
869 String mnc = "";
870 String imsi = "";
871 String gid1 = "";
872 String gid2 = "";
873 String spn = TelephonyManager.from(mContext).getSimOperatorNameForPhone(phoneId);
874 String simOperator = TelephonyManager.from(mContext).getSimOperatorNumericForPhone(phoneId);
chen xu02581692018-11-11 19:03:44 -0800875 int carrierId = TelephonyManager.UNKNOWN_CARRIER_ID;
chen xua31f22b2019-03-06 15:28:50 -0800876 int specificCarrierId = TelephonyManager.UNKNOWN_CARRIER_ID;
Jonathan Basseri1fa437c2015-04-20 11:08:18 -0700877 // A valid simOperator should be 5 or 6 digits, depending on the length of the MNC.
878 if (simOperator != null && simOperator.length() >= 3) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800879 mcc = simOperator.substring(0, 3);
880 mnc = simOperator.substring(3);
881 }
882 Phone phone = PhoneFactory.getPhone(phoneId);
883 if (phone != null) {
884 imsi = phone.getSubscriberId();
885 gid1 = phone.getGroupIdLevel1();
Junda Liu73183532015-05-14 13:55:40 -0700886 gid2 = phone.getGroupIdLevel2();
chen xu02581692018-11-11 19:03:44 -0800887 carrierId = phone.getCarrierId();
chen xua31f22b2019-03-06 15:28:50 -0800888 specificCarrierId = phone.getSpecificCarrierId();
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800889 }
chen xua31f22b2019-03-06 15:28:50 -0800890 return new CarrierIdentifier(mcc, mnc, spn, imsi, gid1, gid2, carrierId, specificCarrierId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -0800891 }
892
Rambo Wangf7c214a2022-03-17 12:36:22 -0700893 /** Returns the package name of a privileged carrier app, or null if there is none. */
Nathan Harold1122e3d2021-01-22 15:45:24 -0800894 @Nullable
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700895 private String getCarrierPackageForPhoneId(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -0700896 final long token = Binder.clearCallingIdentity();
897 try {
Rambo Wangf7c214a2022-03-17 12:36:22 -0700898 return TelephonyManager.from(mContext)
899 .getCarrierServicePackageNameForLogicalSlot(phoneId);
Nazanin1adf4562021-03-29 15:35:30 -0700900 } finally {
901 Binder.restoreCallingIdentity(token);
902 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700903 }
904
905 private String getIccIdForPhoneId(int phoneId) {
906 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
907 return null;
908 }
909 Phone phone = PhoneFactory.getPhone(phoneId);
910 if (phone == null) {
911 return null;
912 }
913 return phone.getIccSerialNumber();
914 }
915
chen xu02581692018-11-11 19:03:44 -0800916 /**
chen xua31f22b2019-03-06 15:28:50 -0800917 * Get the sim specific carrier id {@link TelephonyManager#getSimSpecificCarrierId()}
chen xu02581692018-11-11 19:03:44 -0800918 */
chen xua31f22b2019-03-06 15:28:50 -0800919 private int getSpecificCarrierIdForPhoneId(int phoneId) {
Naina Nalluri86fc7b02018-08-03 10:38:30 -0700920 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
chen xu02581692018-11-11 19:03:44 -0800921 return TelephonyManager.UNKNOWN_CARRIER_ID;
Naina Nalluri86fc7b02018-08-03 10:38:30 -0700922 }
923 Phone phone = PhoneFactory.getPhone(phoneId);
924 if (phone == null) {
chen xu02581692018-11-11 19:03:44 -0800925 return TelephonyManager.UNKNOWN_CARRIER_ID;
Naina Nalluri86fc7b02018-08-03 10:38:30 -0700926 }
chen xua31f22b2019-03-06 15:28:50 -0800927 return phone.getSpecificCarrierId();
chen xu02581692018-11-11 19:03:44 -0800928 }
929
930 /**
931 * Get the sim carrier id {@link TelephonyManager#getSimCarrierId() }
932 */
933 private int getCarrierIdForPhoneId(int phoneId) {
934 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
935 return TelephonyManager.UNKNOWN_CARRIER_ID;
Naina Nalluri86fc7b02018-08-03 10:38:30 -0700936 }
chen xu02581692018-11-11 19:03:44 -0800937 Phone phone = PhoneFactory.getPhone(phoneId);
938 if (phone == null) {
939 return TelephonyManager.UNKNOWN_CARRIER_ID;
940 }
941 return phone.getCarrierId();
Naina Nalluri86fc7b02018-08-03 10:38:30 -0700942 }
943
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700944 /**
945 * Writes a bundle to an XML file.
946 *
chen xu02581692018-11-11 19:03:44 -0800947 * The bundle will be written to a file named after the package name, ICCID and
chen xua31f22b2019-03-06 15:28:50 -0800948 * specific carrier id {@link TelephonyManager#getSimSpecificCarrierId()}. the same carrier
chen xu02581692018-11-11 19:03:44 -0800949 * should have a single copy of XML file named after carrier id. However, it's still possible
950 * that platform doesn't recognize the current sim carrier, we will use iccid + carrierid as
951 * the canonical file name. carrierid can also handle the cases SIM OTA resolves to different
952 * carrier while iccid remains the same.
953 *
954 * The file can be restored later with {@link @restoreConfigFromXml}. The XML output will
955 * include the bundle and the current version of the specified package.
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700956 *
957 * In case of errors or invalid input, no file will be written.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700958 *
Jayachandran C645ec612020-01-10 10:30:25 -0800959 * @param packageName the name of the package from which we fetched this bundle.
960 * @param extraString An extra string to be used in the XML file name.
961 * @param phoneId the phone ID.
962 * @param carrierId contains all carrier-identifying information.
963 * @param config the bundle to be written. Null will be treated as an empty bundle.
964 * @param isNoSimConfig whether this is invoked for noSimConfig or not.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -0700965 */
Torbjorn Eklund723527a2019-02-13 11:16:25 +0100966 private void saveConfigToXml(String packageName, @NonNull String extraString, int phoneId,
Jayachandran C645ec612020-01-10 10:30:25 -0800967 CarrierIdentifier carrierId, PersistableBundle config, boolean isNoSimConfig) {
968 if (packageName == null) {
969 loge("Cannot save config with null packageName");
Yuchen Dongc15afed2018-04-26 17:05:22 +0800970 return;
971 }
972
Jayachandran C645ec612020-01-10 10:30:25 -0800973 String fileName;
974 if (isNoSimConfig) {
975 fileName = getFilenameForNoSimConfig(packageName);
976 } else {
977 if (SubscriptionManager.getSimStateForSlotIndex(phoneId)
978 != TelephonyManager.SIM_STATE_LOADED) {
979 loge("Skip save config because SIM records are not loaded.");
980 return;
981 }
982
983 final String iccid = getIccIdForPhoneId(phoneId);
984 final int cid = carrierId.getSpecificCarrierId();
985 if (iccid == null) {
986 loge("Cannot save config with null iccid.");
987 return;
988 }
989 fileName = getFilenameForConfig(packageName, extraString, iccid, cid);
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700990 }
Jayachandran C645ec612020-01-10 10:30:25 -0800991
Junda Liu02596502016-11-15 13:46:43 -0800992 // b/32668103 Only save to file if config isn't empty.
993 // In case of failure, not caching an empty bundle will
994 // try loading config again on next power on or sim loaded.
995 // Downside is for genuinely empty bundle, will bind and load
996 // on every power on.
997 if (config == null || config.isEmpty()) {
998 return;
Jonathan Basseri1f743c92015-05-15 00:19:46 -0700999 }
1000
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001001 final String version = getPackageVersion(packageName);
1002 if (version == null) {
1003 loge("Failed to get package version for: " + packageName);
1004 return;
1005 }
1006
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001007 logdWithLocalLog(
1008 "Save config to xml, packagename: " + packageName + " phoneId: " + phoneId);
chen xudb04c292019-03-26 17:01:15 -07001009
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001010 FileOutputStream outFile = null;
1011 try {
Jayachandran C645ec612020-01-10 10:30:25 -08001012 outFile = new FileOutputStream(new File(mContext.getFilesDir(), fileName));
Meng Wang0f6b2ea2020-01-06 18:31:16 -08001013 config.putString(KEY_VERSION, version);
1014 config.writeToStream(outFile);
1015 outFile.flush();
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001016 outFile.close();
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001017 } catch (IOException e) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001018 loge(e.toString());
1019 }
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001020 }
1021
Rambo Wang7e3bc122021-03-23 09:24:38 -07001022 @VisibleForTesting
1023 /* package */ void saveConfigToXml(String packageName, @NonNull String extraString, int phoneId,
Jayachandran C645ec612020-01-10 10:30:25 -08001024 CarrierIdentifier carrierId, PersistableBundle config) {
1025 saveConfigToXml(packageName, extraString, phoneId, carrierId, config, false);
1026 }
1027
Rambo Wang7e3bc122021-03-23 09:24:38 -07001028 @VisibleForTesting
1029 /* package */ void saveNoSimConfigToXml(String packageName, PersistableBundle config) {
Jayachandran C645ec612020-01-10 10:30:25 -08001030 saveConfigToXml(packageName, "", -1, null, config, true);
1031 }
1032
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001033 /**
1034 * Reads a bundle from an XML file.
1035 *
1036 * This restores a bundle that was written with {@link #saveConfigToXml}. This returns the saved
Yuchen Dongc15afed2018-04-26 17:05:22 +08001037 * config bundle for the given package and phone ID.
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001038 *
1039 * In case of errors, or if the saved config is from a different package version than the
1040 * current version, then null will be returned.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001041 *
Jayachandran C645ec612020-01-10 10:30:25 -08001042 * @param packageName the name of the package from which we fetched this bundle.
1043 * @param extraString An extra string to be used in the XML file name.
1044 * @param phoneId the phone ID.
1045 * @param isNoSimConfig whether this is invoked for noSimConfig or not.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001046 * @return the bundle from the XML file. Returns null if there is no saved config, the saved
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001047 * version does not match, or reading config fails.
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001048 */
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001049 private PersistableBundle restoreConfigFromXml(String packageName, @NonNull String extraString,
Jayachandran C645ec612020-01-10 10:30:25 -08001050 int phoneId, boolean isNoSimConfig) {
1051 if (packageName == null) {
1052 loge("Cannot restore config with null packageName");
1053 }
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001054 final String version = getPackageVersion(packageName);
1055 if (version == null) {
1056 loge("Failed to get package version for: " + packageName);
1057 return null;
1058 }
Yuchen Dongc15afed2018-04-26 17:05:22 +08001059
Jayachandran C645ec612020-01-10 10:30:25 -08001060 String fileName;
arunvoddu664c36a2021-10-11 20:09:28 +00001061 String iccid = null;
Jayachandran C645ec612020-01-10 10:30:25 -08001062 if (isNoSimConfig) {
1063 fileName = getFilenameForNoSimConfig(packageName);
1064 } else {
1065 if (SubscriptionManager.getSimStateForSlotIndex(phoneId)
1066 != TelephonyManager.SIM_STATE_LOADED) {
1067 loge("Skip restore config because SIM records are not loaded.");
1068 return null;
1069 }
1070
arunvoddu664c36a2021-10-11 20:09:28 +00001071 iccid = getIccIdForPhoneId(phoneId);
Jayachandran C645ec612020-01-10 10:30:25 -08001072 final int cid = getSpecificCarrierIdForPhoneId(phoneId);
1073 if (iccid == null) {
1074 loge("Cannot restore config with null iccid.");
1075 return null;
1076 }
1077 fileName = getFilenameForConfig(packageName, extraString, iccid, cid);
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001078 }
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001079
1080 PersistableBundle restoredBundle = null;
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001081 File file = null;
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001082 FileInputStream inFile = null;
1083 try {
Jayachandran C645ec612020-01-10 10:30:25 -08001084 file = new File(mContext.getFilesDir(),fileName);
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001085 inFile = new FileInputStream(file);
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001086
Meng Wang0f6b2ea2020-01-06 18:31:16 -08001087 restoredBundle = PersistableBundle.readFromStream(inFile);
1088 String savedVersion = restoredBundle.getString(KEY_VERSION);
1089 restoredBundle.remove(KEY_VERSION);
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001090
Meng Wang0f6b2ea2020-01-06 18:31:16 -08001091 if (!version.equals(savedVersion)) {
1092 loge("Saved version mismatch: " + version + " vs " + savedVersion);
1093 restoredBundle = null;
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001094 }
Meng Wang0f6b2ea2020-01-06 18:31:16 -08001095
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001096 inFile.close();
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001097 } catch (FileNotFoundException e) {
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001098 // Missing file is normal occurrence that might occur with a new sim or when restoring
1099 // an override file during boot and should not be treated as an error.
arunvoddu664c36a2021-10-11 20:09:28 +00001100 if (file != null) {
1101 if (isNoSimConfig) {
1102 logd("File not found: " + file.getPath());
1103 } else {
1104 String filePath = file.getPath();
1105 filePath = getFilePathForLogging(filePath, iccid);
1106 logd("File not found : " + filePath);
1107 }
1108 }
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001109 } catch (IOException e) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001110 loge(e.toString());
1111 }
1112
1113 return restoredBundle;
1114 }
1115
arunvoddu664c36a2021-10-11 20:09:28 +00001116 /**
1117 * This method will mask most part of iccid in the filepath for logging on userbuild
1118 */
1119 private String getFilePathForLogging(String filePath, String iccid) {
1120 // If loggable then return with actual file path
1121 if (Rlog.isLoggable(LOG_TAG, Log.VERBOSE)) {
1122 return filePath;
1123 }
1124 String path = filePath;
1125 int length = (iccid != null) ? iccid.length() : 0;
1126 if (length > 5 && filePath != null) {
1127 path = filePath.replace(iccid.substring(5), "***************");
1128 }
1129 return path;
1130 }
1131
Jayachandran C645ec612020-01-10 10:30:25 -08001132 private PersistableBundle restoreConfigFromXml(String packageName, @NonNull String extraString,
1133 int phoneId) {
1134 return restoreConfigFromXml(packageName, extraString, phoneId, false);
1135 }
1136
1137 private PersistableBundle restoreNoSimConfigFromXml(String packageName) {
1138 return restoreConfigFromXml(packageName, "", -1, true);
1139 }
1140
Junda Liu8a8a53a2015-05-15 16:19:57 -07001141 /**
Jonathan Basseri7697cae2015-07-06 15:49:23 -07001142 * Clears cached carrier config.
1143 * This deletes all saved XML files associated with the given package name. If packageName is
1144 * null, then it deletes all saved XML files.
1145 *
1146 * @param packageName the name of a carrier package, or null if all cached config should be
1147 * cleared.
1148 * @return true iff one or more files were deleted.
Junda Liu8a8a53a2015-05-15 16:19:57 -07001149 */
Jonathan Basseri7697cae2015-07-06 15:49:23 -07001150 private boolean clearCachedConfigForPackage(final String packageName) {
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001151 File dir = mContext.getFilesDir();
1152 File[] packageFiles = dir.listFiles(new FilenameFilter() {
1153 public boolean accept(File dir, String filename) {
Jonathan Basseri7697cae2015-07-06 15:49:23 -07001154 if (packageName != null) {
1155 return filename.startsWith("carrierconfig-" + packageName + "-");
1156 } else {
1157 return filename.startsWith("carrierconfig-");
1158 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001159 }
1160 });
Junda Liu8a8a53a2015-05-15 16:19:57 -07001161 if (packageFiles == null || packageFiles.length < 1) return false;
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001162 for (File f : packageFiles) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001163 logd("Deleting " + f.getName());
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001164 f.delete();
1165 }
Junda Liu8a8a53a2015-05-15 16:19:57 -07001166 return true;
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001167 }
1168
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001169 /** Builds a canonical file name for a config file. */
Jayachandran C645ec612020-01-10 10:30:25 -08001170 private static String getFilenameForConfig(
1171 @NonNull String packageName, @NonNull String extraString,
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001172 @NonNull String iccid, int cid) {
chen xu02581692018-11-11 19:03:44 -08001173 // the same carrier should have a single copy of XML file named after carrier id.
1174 // However, it's still possible that platform doesn't recognize the current sim carrier,
1175 // we will use iccid + carrierid as the canonical file name. carrierid can also handle the
1176 // cases SIM OTA resolves to different carrier while iccid remains the same.
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001177 return "carrierconfig-" + packageName + extraString + "-" + iccid + "-" + cid + ".xml";
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001178 }
1179
Jayachandran C645ec612020-01-10 10:30:25 -08001180 /** Builds a canonical file name for no SIM config file. */
1181 private String getFilenameForNoSimConfig(@NonNull String packageName) {
1182 return "carrierconfig-" + packageName + "-" + "nosim" + ".xml";
1183 }
1184
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001185 /** Return the current version code of a package, or null if the name is not found. */
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001186 private String getPackageVersion(String packageName) {
1187 try {
1188 PackageInfo info = mContext.getPackageManager().getPackageInfo(packageName, 0);
Dianne Hackbornb76ab202017-11-28 17:44:50 -08001189 return Long.toString(info.getLongVersionCode());
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001190 } catch (PackageManager.NameNotFoundException e) {
1191 return null;
1192 }
1193 }
1194
Jonathan Basseri65273c82017-07-25 15:08:42 -07001195 /**
1196 * Read up to date config.
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001197 *
1198 * This reads config bundles for the given phoneId. That means getting the latest bundle from
1199 * the default app and a privileged carrier app, if present. This will not bind to an app if we
1200 * have a saved config file to use instead.
1201 */
1202 private void updateConfigForPhoneId(int phoneId) {
Jonathan Basseri65273c82017-07-25 15:08:42 -07001203 mHandler.sendMessage(mHandler.obtainMessage(EVENT_DO_FETCH_DEFAULT, phoneId, -1));
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001204 }
1205
Malcolm Chen5ea18532019-10-24 19:55:44 -07001206 private void onMultiSimConfigChanged() {
1207 for (int i = TelephonyManager.from(mContext).getActiveModemCount();
1208 i < mConfigFromDefaultApp.length; i++) {
1209 clearConfigForPhone(i, false);
1210 }
1211 }
1212
Hall Liu506724b2018-10-22 18:16:14 -07001213 @Override
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001214 @NonNull
Rambo Wangd2b004b2021-03-30 10:10:23 -07001215 public PersistableBundle getConfigForSubId(int subscriptionId, String callingPackage) {
1216 return getConfigForSubIdWithFeature(subscriptionId, callingPackage, null);
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001217 }
1218
1219 @Override
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001220 @NonNull
Rambo Wangd2b004b2021-03-30 10:10:23 -07001221 public PersistableBundle getConfigForSubIdWithFeature(int subscriptionId, String callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001222 String callingFeatureId) {
Rambo Wangd2b004b2021-03-30 10:10:23 -07001223 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mContext, subscriptionId,
1224 callingPackage, callingFeatureId, "getCarrierConfig")) {
Rambo Wang42026112021-04-07 20:57:28 +00001225 return new PersistableBundle();
Amit Mahajan40b3fa52015-07-14 10:27:19 -07001226 }
Jeff Davidsona8e4e242018-03-15 17:16:18 -07001227
Rambo Wangd2b004b2021-03-30 10:10:23 -07001228 int phoneId = SubscriptionManager.getPhoneId(subscriptionId);
Jonathan Basseric31f1f32015-05-12 10:13:03 -07001229 PersistableBundle retConfig = CarrierConfigManager.getDefaultConfig();
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001230 if (SubscriptionManager.isValidPhoneId(phoneId)) {
Jonathan Basseric31f1f32015-05-12 10:13:03 -07001231 PersistableBundle config = mConfigFromDefaultApp[phoneId];
yinxuc5e27622017-11-29 15:08:50 -08001232 if (config != null) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001233 retConfig.putAll(config);
yinxuc5e27622017-11-29 15:08:50 -08001234 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001235 config = mConfigFromCarrierApp[phoneId];
yinxuc5e27622017-11-29 15:08:50 -08001236 if (config != null) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001237 retConfig.putAll(config);
yinxuc5e27622017-11-29 15:08:50 -08001238 }
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001239 config = mPersistentOverrideConfigs[phoneId];
1240 if (config != null) {
1241 retConfig.putAll(config);
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001242 }
Hall Liu506724b2018-10-22 18:16:14 -07001243 config = mOverrideConfigs[phoneId];
1244 if (config != null) {
1245 retConfig.putAll(config);
Hall Liu506724b2018-10-22 18:16:14 -07001246 }
Nathan Harold1122e3d2021-01-22 15:45:24 -08001247 // Ignore the theoretical case of the default app not being present since that won't
1248 // work in CarrierConfigLoader today.
1249 final boolean allConfigsApplied =
1250 (mConfigFromCarrierApp[phoneId] != null
1251 || getCarrierPackageForPhoneId(phoneId) == null)
1252 && mConfigFromDefaultApp[phoneId] != null;
1253 retConfig.putBoolean(
1254 CarrierConfigManager.KEY_CARRIER_CONFIG_APPLIED_BOOL, allConfigsApplied);
Jayachandran C645ec612020-01-10 10:30:25 -08001255 } else {
1256 if (mNoSimConfig != null) {
1257 retConfig.putAll(mNoSimConfig);
1258 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001259 }
1260 return retConfig;
1261 }
1262
1263 @Override
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001264 public void overrideConfig(int subscriptionId, @Nullable PersistableBundle overrides,
1265 boolean persistent) {
Hall Liu506724b2018-10-22 18:16:14 -07001266 mContext.enforceCallingOrSelfPermission(
1267 android.Manifest.permission.MODIFY_PHONE_STATE, null);
Brad Ebingerf6281ad2019-04-25 11:02:04 -07001268 //TODO: Also check for SHELL UID to restrict this method to testing only (b/131326259)
Hall Liu506724b2018-10-22 18:16:14 -07001269 int phoneId = SubscriptionManager.getPhoneId(subscriptionId);
1270 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001271 logd("Ignore invalid phoneId: " + phoneId + " for subId: " + subscriptionId);
Rambo Wangd2b004b2021-03-30 10:10:23 -07001272 throw new IllegalArgumentException(
1273 "Invalid phoneId " + phoneId + " for subId " + subscriptionId);
Hall Liu506724b2018-10-22 18:16:14 -07001274 }
Rambo Wang38eb5cd2021-03-29 16:39:14 -07001275 // Post to run on handler thread on which all states should be confined.
1276 mHandler.post(() -> {
1277 overrideConfig(mOverrideConfigs, phoneId, overrides);
Hall Liu506724b2018-10-22 18:16:14 -07001278
Rambo Wang38eb5cd2021-03-29 16:39:14 -07001279 if (persistent) {
1280 overrideConfig(mPersistentOverrideConfigs, phoneId, overrides);
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001281
Rambo Wang38eb5cd2021-03-29 16:39:14 -07001282 if (overrides != null) {
1283 final CarrierIdentifier carrierId = getCarrierIdentifierForPhoneId(phoneId);
1284 saveConfigToXml(mPlatformCarrierConfigPackage, OVERRIDE_PACKAGE_ADDITION,
1285 phoneId,
1286 carrierId, mPersistentOverrideConfigs[phoneId]);
1287 } else {
1288 final String iccid = getIccIdForPhoneId(phoneId);
1289 final int cid = getSpecificCarrierIdForPhoneId(phoneId);
1290 String fileName = getFilenameForConfig(mPlatformCarrierConfigPackage,
1291 OVERRIDE_PACKAGE_ADDITION, iccid, cid);
1292 File fileToDelete = new File(mContext.getFilesDir(), fileName);
1293 fileToDelete.delete();
1294 }
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001295 }
Rambo Wang38eb5cd2021-03-29 16:39:14 -07001296 notifySubscriptionInfoUpdater(phoneId);
1297 });
Hall Liu506724b2018-10-22 18:16:14 -07001298 }
1299
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001300 private void overrideConfig(@NonNull PersistableBundle[] currentOverrides, int phoneId,
1301 @Nullable PersistableBundle overrides) {
1302 if (overrides == null) {
Rambo Wang42026112021-04-07 20:57:28 +00001303 currentOverrides[phoneId] = new PersistableBundle();
Torbjorn Eklund723527a2019-02-13 11:16:25 +01001304 } else if (currentOverrides[phoneId] == null) {
1305 currentOverrides[phoneId] = overrides;
1306 } else {
1307 currentOverrides[phoneId].putAll(overrides);
1308 }
1309 }
1310
Hall Liu506724b2018-10-22 18:16:14 -07001311 @Override
Rambo Wangd2b004b2021-03-30 10:10:23 -07001312 public void notifyConfigChangedForSubId(int subscriptionId) {
Jordan Liud7d57fe2019-04-16 12:29:43 -07001313 // Requires the calling app to be either a carrier privileged app for this subId or
Junda Liufbd2bcb2016-06-15 11:15:42 -07001314 // system privileged app with MODIFY_PHONE_STATE permission.
Rambo Wangd2b004b2021-03-30 10:10:23 -07001315 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mContext,
1316 subscriptionId, "Require carrier privileges or MODIFY_PHONE_STATE permission.");
1317
1318 int phoneId = SubscriptionManager.getPhoneId(subscriptionId);
1319 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
1320 logd("Ignore invalid phoneId: " + phoneId + " for subId: " + subscriptionId);
1321 throw new IllegalArgumentException(
1322 "Invalid phoneId " + phoneId + " for subId " + subscriptionId);
1323 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001324
1325 // This method should block until deleting has completed, so that an error which prevents us
1326 // from clearing the cache is passed back to the carrier app. With the files successfully
1327 // deleted, this can return and we will eventually bind to the carrier app.
Jordan Liud7d57fe2019-04-16 12:29:43 -07001328 String callingPackageName = mContext.getPackageManager().getNameForUid(
1329 Binder.getCallingUid());
Jonathan Basseri7697cae2015-07-06 15:49:23 -07001330 clearCachedConfigForPackage(callingPackageName);
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001331 updateConfigForPhoneId(phoneId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001332 }
1333
1334 @Override
1335 public void updateConfigForPhoneId(int phoneId, String simState) {
Junda Liu1f2b34d2015-06-18 15:26:56 -07001336 mContext.enforceCallingOrSelfPermission(
1337 android.Manifest.permission.MODIFY_PHONE_STATE, null);
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001338 logdWithLocalLog("Update config for phoneId: " + phoneId + " simState: " + simState);
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001339 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
Rambo Wangd2b004b2021-03-30 10:10:23 -07001340 throw new IllegalArgumentException("Invalid phoneId: " + phoneId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001341 }
1342 // requires Java 7 for switch on string.
1343 switch (simState) {
1344 case IccCardConstants.INTENT_VALUE_ICC_ABSENT:
1345 case IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR:
Junda Liu6f5fddf2016-05-24 16:14:41 -07001346 case IccCardConstants.INTENT_VALUE_ICC_CARD_RESTRICTED:
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001347 case IccCardConstants.INTENT_VALUE_ICC_UNKNOWN:
Malcolm Chendb66de12019-12-09 18:57:07 -08001348 case IccCardConstants.INTENT_VALUE_ICC_NOT_READY:
Junda Liu9f2d2712015-05-15 14:22:45 -07001349 mHandler.sendMessage(mHandler.obtainMessage(EVENT_CLEAR_CONFIG, phoneId, -1));
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001350 break;
1351 case IccCardConstants.INTENT_VALUE_ICC_LOADED:
1352 case IccCardConstants.INTENT_VALUE_ICC_LOCKED:
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001353 updateConfigForPhoneId(phoneId);
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001354 break;
1355 }
1356 }
1357
Junda Liu43d723a2015-05-12 17:23:45 -07001358 @Override
Jeff Sharkeya6fcfed2017-07-20 14:18:39 -06001359 public String getDefaultCarrierServicePackageName() {
Shuo Qianefdb7962019-12-19 15:54:27 -08001360 mContext.enforceCallingOrSelfPermission(
1361 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
1362 "getDefaultCarrierServicePackageName");
Jeff Sharkeya6fcfed2017-07-20 14:18:39 -06001363 return mPlatformCarrierConfigPackage;
1364 }
1365
Rambo Wang7e3bc122021-03-23 09:24:38 -07001366 @VisibleForTesting
1367 /* package */ Handler getHandler() {
1368 return mHandler;
1369 }
1370
1371 @VisibleForTesting
1372 /* package */ PersistableBundle getConfigFromDefaultApp(int phoneId) {
1373 return mConfigFromDefaultApp[phoneId];
1374 }
1375
1376 @VisibleForTesting
1377 /* package */ PersistableBundle getConfigFromCarrierApp(int phoneId) {
1378 return mConfigFromCarrierApp[phoneId];
1379 }
1380
1381 @VisibleForTesting
1382 /* package */ PersistableBundle getNoSimConfig() {
1383 return mNoSimConfig;
1384 }
1385
1386 @VisibleForTesting
1387 /* package */ PersistableBundle getOverrideConfig(int phoneId) {
1388 return mOverrideConfigs[phoneId];
1389 }
1390
Rambo Wangb0f3e2f2021-10-28 12:40:12 -07001391 private void unbindIfBound(Context context, CarrierServiceConnection conn,
1392 int phoneId) {
1393 if (mServiceBound[phoneId]) {
1394 mServiceBound[phoneId] = false;
1395 context.unbindService(conn);
1396 }
1397 }
1398
1399 private void unbindIfBoundForNoSimConfig(Context context, CarrierServiceConnection conn,
1400 int phoneId) {
1401 if (mServiceBoundForNoSimConfig[phoneId]) {
1402 mServiceBoundForNoSimConfig[phoneId] = false;
Jayachandran C645ec612020-01-10 10:30:25 -08001403 context.unbindService(conn);
1404 }
1405 }
1406
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001407 /**
Rambo Wang610fdf62021-03-08 21:37:11 -08001408 * Returns a boxed Integer object for phoneId, services as message token to distinguish messages
1409 * with same code when calling {@link Handler#removeMessages(int, Object)}.
1410 */
1411 private Integer getMessageToken(int phoneId) {
1412 if (phoneId < -128 || phoneId > 127) {
1413 throw new IllegalArgumentException("phoneId should be in range [-128, 127], inclusive");
1414 }
1415 // Integer#valueOf guarantees the integers within [-128, 127] are cached and thus memory
1416 // comparison (==) returns true for the same integer.
1417 return Integer.valueOf(phoneId);
1418 }
1419
1420 /**
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001421 * If {@code args} contains {@link #DUMP_ARG_REQUESTING_PACKAGE} and a following package name,
1422 * we'll also call {@link IBinder#dump} on the default carrier service (if bound) and the
1423 * specified carrier service (if bound). Typically, this is done for connectivity bug reports
1424 * where we don't call {@code dumpsys activity service all-non-platform} because that contains
1425 * too much info, but we still want to let carrier apps include their diagnostics.
1426 */
Jeff Sharkeya6fcfed2017-07-20 14:18:39 -06001427 @Override
Junda Liu43d723a2015-05-12 17:23:45 -07001428 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001429 IndentingPrintWriter indentPW = new IndentingPrintWriter(pw, " ");
Junda Liu43d723a2015-05-12 17:23:45 -07001430 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
1431 != PackageManager.PERMISSION_GRANTED) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001432 indentPW.println("Permission Denial: can't dump carrierconfig from from pid="
Junda Liu43d723a2015-05-12 17:23:45 -07001433 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
1434 return;
1435 }
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001436 String requestingPackage = null;
1437 int requestingPackageIndex = ArrayUtils.indexOf(args, DUMP_ARG_REQUESTING_PACKAGE);
1438 if (requestingPackageIndex >= 0 && requestingPackageIndex < args.length - 1
1439 && !TextUtils.isEmpty(args[requestingPackageIndex + 1])) {
1440 requestingPackage = args[requestingPackageIndex + 1];
1441 // Throws a SecurityException if the caller is impersonating another app in an effort to
1442 // dump extra info (which may contain PII the caller doesn't have a right to).
1443 enforceCallerIsSystemOrRequestingPackage(requestingPackage);
1444 }
1445
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001446 indentPW.println("CarrierConfigLoader: " + this);
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001447 for (int i = 0; i < TelephonyManager.from(mContext).getActiveModemCount(); i++) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001448 indentPW.println("Phone Id = " + i);
shuoq26a3a4c2016-12-16 11:06:48 -08001449 // display default values in CarrierConfigManager
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001450 printConfig(CarrierConfigManager.getDefaultConfig(), indentPW,
shuoq26a3a4c2016-12-16 11:06:48 -08001451 "Default Values from CarrierConfigManager");
shuoq26a3a4c2016-12-16 11:06:48 -08001452 // display ConfigFromDefaultApp
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001453 printConfig(mConfigFromDefaultApp[i], indentPW, "mConfigFromDefaultApp");
shuoq26a3a4c2016-12-16 11:06:48 -08001454 // display ConfigFromCarrierApp
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001455 printConfig(mConfigFromCarrierApp[i], indentPW, "mConfigFromCarrierApp");
1456 printConfig(mPersistentOverrideConfigs[i], indentPW, "mPersistentOverrideConfigs");
1457 printConfig(mOverrideConfigs[i], indentPW, "mOverrideConfigs");
shuoq26a3a4c2016-12-16 11:06:48 -08001458 }
chen xudb04c292019-03-26 17:01:15 -07001459
Jayachandran C645ec612020-01-10 10:30:25 -08001460 printConfig(mNoSimConfig, indentPW, "mNoSimConfig");
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001461 indentPW.println("CarrierConfigLoadingLog=");
1462 mCarrierConfigLoadingLog.dump(fd, indentPW, args);
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001463
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001464 if (requestingPackage != null) {
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001465 logd("Including default and requesting package " + requestingPackage
1466 + " carrier services in dump");
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001467 indentPW.println("");
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001468 indentPW.println("Connected services");
1469 dumpCarrierServiceIfBound(fd, indentPW, "Default config package",
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001470 mPlatformCarrierConfigPackage, false /* considerCarrierPrivileges */);
1471 dumpCarrierServiceIfBound(fd, indentPW, "Requesting package", requestingPackage,
1472 true /* considerCarrierPrivileges */);
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001473 }
shuoq26a3a4c2016-12-16 11:06:48 -08001474 }
1475
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001476 private void printConfig(PersistableBundle configApp, IndentingPrintWriter indentPW,
1477 String name) {
1478 indentPW.increaseIndent();
shuoq26a3a4c2016-12-16 11:06:48 -08001479 if (configApp == null) {
shuoq26a3a4c2016-12-16 11:06:48 -08001480 indentPW.println(name + " : null ");
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001481 indentPW.decreaseIndent();
1482 indentPW.println("");
shuoq26a3a4c2016-12-16 11:06:48 -08001483 return;
1484 }
shuoq26a3a4c2016-12-16 11:06:48 -08001485 indentPW.println(name + " : ");
1486 List<String> sortedKeys = new ArrayList<String>(configApp.keySet());
1487 Collections.sort(sortedKeys);
1488 indentPW.increaseIndent();
1489 indentPW.increaseIndent();
1490 for (String key : sortedKeys) {
1491 if (configApp.get(key) != null && configApp.get(key) instanceof Object[]) {
1492 indentPW.println(key + " = " +
1493 Arrays.toString((Object[]) configApp.get(key)));
1494 } else if (configApp.get(key) != null && configApp.get(key) instanceof int[]) {
1495 indentPW.println(key + " = " + Arrays.toString((int[]) configApp.get(key)));
1496 } else {
1497 indentPW.println(key + " = " + configApp.get(key));
1498 }
Junda Liu43d723a2015-05-12 17:23:45 -07001499 }
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001500 indentPW.decreaseIndent();
1501 indentPW.decreaseIndent();
1502 indentPW.decreaseIndent();
1503 indentPW.println("");
Junda Liu43d723a2015-05-12 17:23:45 -07001504 }
1505
Hunter Knepshielde601f432020-02-19 10:16:04 -08001506 /**
1507 * Passes without problem when one of these conditions is true:
1508 * - The caller is a privileged UID (e.g. for dumpstate.cpp generating a bug report, where the
1509 * system knows the true caller plumbed in through the {@link android.os.BugreportManager} API).
1510 * - The caller's UID matches the supplied package.
1511 *
1512 * @throws SecurityException if none of the above conditions are met.
1513 */
1514 private void enforceCallerIsSystemOrRequestingPackage(String requestingPackage)
1515 throws SecurityException {
1516 final int callingUid = Binder.getCallingUid();
1517 if (callingUid == Process.ROOT_UID || callingUid == Process.SYSTEM_UID
1518 || callingUid == Process.SHELL_UID || callingUid == Process.PHONE_UID) {
1519 // Bug reports (dumpstate.cpp) run as SHELL, and let some other privileged UIDs through
1520 // as well.
1521 return;
1522 }
1523 // An app is trying to dump extra detail, block it if they aren't who they claim to be.
1524 AppOpsManager appOps = mContext.getSystemService(AppOpsManager.class);
1525 if (appOps == null) {
1526 throw new SecurityException("No AppOps");
1527 }
1528 // Will throw a SecurityException if the UID and package don't match.
1529 appOps.checkPackage(callingUid, requestingPackage);
1530 }
1531
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001532 /**
1533 * Searches for one or more appropriate {@link CarrierService} instances to dump based on the
1534 * current connections.
1535 *
1536 * @param targetPkgName the target package name to dump carrier services for
1537 * @param considerCarrierPrivileges if true, allow a carrier service to be dumped if it shares
1538 * carrier privileges with {@code targetPkgName};
1539 * otherwise, only dump a carrier service if it is {@code
1540 * targetPkgName}
1541 */
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001542 private void dumpCarrierServiceIfBound(FileDescriptor fd, IndentingPrintWriter indentPW,
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001543 String prefix, String targetPkgName, boolean considerCarrierPrivileges) {
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001544 // Null package is possible if it's early in the boot process, there was a recent crash, we
1545 // loaded the config from XML most recently, or a SIM slot is empty. Carrier apps with
1546 // long-lived bindings should typically get dumped here regardless. Even if an app is being
1547 // used for multiple phoneIds, we assume that it's smart enough to handle that on its own,
1548 // and that in most cases we'd just be dumping duplicate information and bloating a report.
1549 indentPW.increaseIndent();
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001550 indentPW.println(prefix + " : " + targetPkgName);
1551 Set<String> dumpedPkgNames = new ArraySet<>(mServiceConnection.length);
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001552 for (CarrierServiceConnection connection : mServiceConnection) {
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001553 if (connection == null || !SubscriptionManager.isValidPhoneId(connection.phoneId)
1554 || TextUtils.isEmpty(connection.pkgName)) {
1555 continue;
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001556 }
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001557 final String servicePkgName = connection.pkgName;
1558 // Note: we intentionally ignore system components here because we should NOT match the
1559 // shell caller that's typically used for bug reports via non-BugreportManager triggers.
1560 final boolean exactPackageMatch = TextUtils.equals(targetPkgName, servicePkgName);
1561 final boolean carrierPrivilegesMatch =
1562 considerCarrierPrivileges && hasCarrierPrivileges(targetPkgName,
1563 connection.phoneId);
1564 if (!exactPackageMatch && !carrierPrivilegesMatch) continue;
1565 // Make sure this service is actually alive before trying to dump it. We don't pay
1566 // attention to mServiceBound[connection.phoneId] because typically carrier apps will
1567 // request long-lived bindings, and even if we unbind the app, it may still be alive due
1568 // to CarrierServiceBindHelper. Pull it out as a reference so even if it gets set to
1569 // null within the ServiceConnection during unbinding we can avoid an NPE.
1570 final IBinder service = connection.service;
1571 if (service == null || !service.isBinderAlive() || !service.pingBinder()) continue;
1572 // We've got a live service. Last check is just to make sure we don't dump a package
1573 // multiple times.
1574 if (!dumpedPkgNames.add(servicePkgName)) continue;
1575 if (!exactPackageMatch) {
1576 logd(targetPkgName + " has carrier privileges on phoneId " + connection.phoneId
1577 + ", service provided by " + servicePkgName);
1578 indentPW.increaseIndent();
1579 indentPW.println("Proxy : " + servicePkgName);
1580 indentPW.decreaseIndent();
1581 }
1582 // Flush before we let the app output anything to ensure correct ordering of output.
1583 // Internally, Binder#dump calls flush on its printer after finishing so we don't
1584 // need to do anything after.
1585 indentPW.flush();
1586 try {
1587 logd("Dumping " + servicePkgName);
1588 // We don't need to give the carrier service any args.
1589 connection.service.dump(fd, null /* args */);
1590 logd("Done with " + servicePkgName);
1591 } catch (RemoteException e) {
1592 logd("RemoteException from " + servicePkgName, e);
1593 indentPW.increaseIndent();
1594 indentPW.println("RemoteException");
1595 indentPW.increaseIndent();
1596 e.printStackTrace(indentPW);
1597 indentPW.decreaseIndent();
1598 indentPW.decreaseIndent();
1599 // We won't retry this package again because now it's in dumpedPkgNames.
1600 }
1601 indentPW.println("");
Jordan Liu46ed5db2020-01-28 08:55:20 -08001602 }
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001603 if (dumpedPkgNames.isEmpty()) {
1604 indentPW.increaseIndent();
1605 indentPW.println("Not bound");
1606 indentPW.decreaseIndent();
1607 indentPW.println("");
1608 }
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001609 indentPW.decreaseIndent();
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001610 }
1611
1612 private boolean hasCarrierPrivileges(String pkgName, int phoneId) {
1613 int[] subIds = SubscriptionManager.getSubId(phoneId);
1614 if (ArrayUtils.isEmpty(subIds)) {
1615 return false;
1616 }
1617 return TelephonyManager.from(mContext).createForSubscriptionId(
1618 subIds[0]).checkCarrierPrivilegesForPackage(pkgName)
1619 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Jordan Liu46ed5db2020-01-28 08:55:20 -08001620 }
1621
Zach Johnson36d7aab2015-05-22 15:43:00 -07001622 private class CarrierServiceConnection implements ServiceConnection {
Hunter Knepshieldeefb31b2020-02-19 15:30:54 -08001623 final int phoneId;
1624 final String pkgName;
1625 final int eventId;
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001626 IBinder service;
1627
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001628 CarrierServiceConnection(int phoneId, String pkgName, int eventId) {
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001629 this.phoneId = phoneId;
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001630 this.pkgName = pkgName;
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001631 this.eventId = eventId;
1632 }
1633
1634 @Override
1635 public void onServiceConnected(ComponentName name, IBinder service) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001636 logd("Connected to config app: " + name.flattenToShortString());
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001637 this.service = service;
1638 mHandler.sendMessage(mHandler.obtainMessage(eventId, phoneId, -1, this));
1639 }
1640
1641 @Override
1642 public void onServiceDisconnected(ComponentName name) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001643 logd("Disconnected from config app: " + name.flattenToShortString());
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001644 this.service = null;
Jordan Liu46ed5db2020-01-28 08:55:20 -08001645 }
1646
1647 @Override
1648 public void onBindingDied(ComponentName name) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001649 logd("Binding died from config app: " + name.flattenToShortString());
Jordan Liu46ed5db2020-01-28 08:55:20 -08001650 this.service = null;
Jordan Liu46ed5db2020-01-28 08:55:20 -08001651 }
1652
1653 @Override
1654 public void onNullBinding(ComponentName name) {
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001655 logd("Null binding from config app: " + name.flattenToShortString());
Jordan Liu46ed5db2020-01-28 08:55:20 -08001656 this.service = null;
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001657 }
1658 }
1659
1660 private class ConfigLoaderBroadcastReceiver extends BroadcastReceiver {
1661 @Override
1662 public void onReceive(Context context, Intent intent) {
1663 String action = intent.getAction();
Junda Liu8a8a53a2015-05-15 16:19:57 -07001664 boolean replace = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
1665 // If replace is true, only care ACTION_PACKAGE_REPLACED.
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001666 if (replace && !Intent.ACTION_PACKAGE_REPLACED.equals(action)) {
Junda Liu8a8a53a2015-05-15 16:19:57 -07001667 return;
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001668 }
Junda Liu8a8a53a2015-05-15 16:19:57 -07001669
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001670 switch (action) {
Nanxi Chen3d670502016-03-17 16:32:09 -07001671 case Intent.ACTION_BOOT_COMPLETED:
1672 mHandler.sendMessage(mHandler.obtainMessage(EVENT_SYSTEM_UNLOCKED, null));
1673 break;
1674
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001675 case Intent.ACTION_PACKAGE_ADDED:
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001676 case Intent.ACTION_PACKAGE_REMOVED:
Junda Liu8a8a53a2015-05-15 16:19:57 -07001677 case Intent.ACTION_PACKAGE_REPLACED:
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001678 int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
1679 String packageName = mContext.getPackageManager().getNameForUid(uid);
Junda Liu8a8a53a2015-05-15 16:19:57 -07001680 if (packageName != null) {
1681 // We don't have a phoneId for arg1.
1682 mHandler.sendMessage(
1683 mHandler.obtainMessage(EVENT_PACKAGE_CHANGED, packageName));
1684 }
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001685 break;
Jonathan Basseri1f743c92015-05-15 00:19:46 -07001686 }
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001687 }
1688 }
1689
Rambo Wangab13e3e2021-04-08 15:01:06 -07001690 // Get readable string for the message code supported in this class.
1691 private static String eventToString(int code) {
1692 switch (code) {
1693 case EVENT_CLEAR_CONFIG:
1694 return "EVENT_CLEAR_CONFIG";
1695 case EVENT_CONNECTED_TO_DEFAULT:
1696 return "EVENT_CONNECTED_TO_DEFAULT";
1697 case EVENT_CONNECTED_TO_CARRIER:
1698 return "EVENT_CONNECTED_TO_CARRIER";
1699 case EVENT_FETCH_DEFAULT_DONE:
1700 return "EVENT_FETCH_DEFAULT_DONE";
1701 case EVENT_FETCH_CARRIER_DONE:
1702 return "EVENT_FETCH_CARRIER_DONE";
1703 case EVENT_DO_FETCH_DEFAULT:
1704 return "EVENT_DO_FETCH_DEFAULT";
1705 case EVENT_DO_FETCH_CARRIER:
1706 return "EVENT_DO_FETCH_CARRIER";
1707 case EVENT_PACKAGE_CHANGED:
1708 return "EVENT_PACKAGE_CHANGED";
1709 case EVENT_BIND_DEFAULT_TIMEOUT:
1710 return "EVENT_BIND_DEFAULT_TIMEOUT";
1711 case EVENT_BIND_CARRIER_TIMEOUT:
1712 return "EVENT_BIND_CARRIER_TIMEOUT";
1713 case EVENT_CHECK_SYSTEM_UPDATE:
1714 return "EVENT_CHECK_SYSTEM_UPDATE";
1715 case EVENT_SYSTEM_UNLOCKED:
1716 return "EVENT_SYSTEM_UNLOCKED";
1717 case EVENT_FETCH_DEFAULT_TIMEOUT:
1718 return "EVENT_FETCH_DEFAULT_TIMEOUT";
1719 case EVENT_FETCH_CARRIER_TIMEOUT:
1720 return "EVENT_FETCH_CARRIER_TIMEOUT";
1721 case EVENT_SUBSCRIPTION_INFO_UPDATED:
1722 return "EVENT_SUBSCRIPTION_INFO_UPDATED";
1723 case EVENT_MULTI_SIM_CONFIG_CHANGED:
1724 return "EVENT_MULTI_SIM_CONFIG_CHANGED";
1725 case EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG:
1726 return "EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG";
1727 case EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE:
1728 return "EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE";
1729 case EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG:
1730 return "EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG";
1731 case EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT:
1732 return "EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT";
1733 case EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT:
1734 return "EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT";
1735 default:
1736 return "UNKNOWN(" + code + ")";
1737 }
1738 }
1739
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001740 private void logd(String msg) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001741 Log.d(LOG_TAG, msg);
1742 }
1743
Hunter Knepshieldd0ed6212020-01-28 17:43:16 -08001744 private void logd(String msg, Throwable tr) {
1745 Log.d(LOG_TAG, msg, tr);
1746 }
1747
Hunter Knepshield9f091fc2020-01-28 17:41:43 -08001748 private void logdWithLocalLog(String msg) {
chen xudb04c292019-03-26 17:01:15 -07001749 Log.d(LOG_TAG, msg);
1750 mCarrierConfigLoadingLog.log(msg);
1751 }
1752
1753 private void loge(String msg) {
Jonathan Basseri6b50e9f2015-05-12 20:18:31 -07001754 Log.e(LOG_TAG, msg);
chen xudb04c292019-03-26 17:01:15 -07001755 mCarrierConfigLoadingLog.log(msg);
Jonathan Basseri6465afd2015-02-25 13:05:57 -08001756 }
1757}