Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 1 | /* |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 2 | * 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 Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 17 | package com.android.phone; |
| 18 | |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 19 | import static android.service.carrier.CarrierService.ICarrierServiceWrapper.KEY_CONFIG_BUNDLE; |
| 20 | import static android.service.carrier.CarrierService.ICarrierServiceWrapper.RESULT_ERROR; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 21 | |
Jonathan Basseri | 11f8957 | 2015-05-05 11:57:39 -0700 | [diff] [blame] | 22 | import android.annotation.NonNull; |
Torbjorn Eklund | 723527a | 2019-02-13 11:16:25 +0100 | [diff] [blame] | 23 | import android.annotation.Nullable; |
Hunter Knepshield | e601f43 | 2020-02-19 10:16:04 -0800 | [diff] [blame] | 24 | import android.app.AppOpsManager; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 25 | import android.content.BroadcastReceiver; |
| 26 | import android.content.ComponentName; |
| 27 | import android.content.Context; |
| 28 | import android.content.Intent; |
| 29 | import android.content.IntentFilter; |
| 30 | import android.content.ServiceConnection; |
Jonathan Basseri | 7697cae | 2015-07-06 15:49:23 -0700 | [diff] [blame] | 31 | import android.content.SharedPreferences; |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 32 | import android.content.pm.PackageInfo; |
Jonathan Basseri | c31f1f3 | 2015-05-12 10:13:03 -0700 | [diff] [blame] | 33 | import android.content.pm.PackageManager; |
Junda Liu | 43d723a | 2015-05-12 17:23:45 -0700 | [diff] [blame] | 34 | import android.os.Binder; |
Jonathan Basseri | 7697cae | 2015-07-06 15:49:23 -0700 | [diff] [blame] | 35 | import android.os.Build; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 36 | import android.os.Bundle; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 37 | import android.os.Handler; |
| 38 | import android.os.IBinder; |
| 39 | import android.os.Message; |
Jonathan Basseri | c31f1f3 | 2015-05-12 10:13:03 -0700 | [diff] [blame] | 40 | import android.os.PersistableBundle; |
Hunter Knepshield | e601f43 | 2020-02-19 10:16:04 -0800 | [diff] [blame] | 41 | import android.os.Process; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 42 | import android.os.RemoteException; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 43 | import android.os.ResultReceiver; |
Meng Wang | 97a6a46 | 2020-01-23 16:22:16 -0800 | [diff] [blame] | 44 | import android.os.UserHandle; |
Jonathan Basseri | 7697cae | 2015-07-06 15:49:23 -0700 | [diff] [blame] | 45 | import android.preference.PreferenceManager; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 46 | import android.service.carrier.CarrierIdentifier; |
Zach Johnson | 36d7aab | 2015-05-22 15:43:00 -0700 | [diff] [blame] | 47 | import android.service.carrier.CarrierService; |
| 48 | import android.service.carrier.ICarrierService; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 49 | import android.telephony.CarrierConfigManager; |
| 50 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 51 | import android.telephony.TelephonyFrameworkInitializer; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 52 | import android.telephony.TelephonyManager; |
Hunter Knepshield | d0ed621 | 2020-01-28 17:43:16 -0800 | [diff] [blame] | 53 | import android.text.TextUtils; |
Hunter Knepshield | eefb31b | 2020-02-19 15:30:54 -0800 | [diff] [blame] | 54 | import android.util.ArraySet; |
chen xu | db04c29 | 2019-03-26 17:01:15 -0700 | [diff] [blame] | 55 | import android.util.LocalLog; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 56 | import android.util.Log; |
| 57 | |
| 58 | import com.android.internal.telephony.ICarrierConfigLoader; |
| 59 | import com.android.internal.telephony.IccCardConstants; |
| 60 | import com.android.internal.telephony.Phone; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 61 | import com.android.internal.telephony.PhoneFactory; |
Nathan Harold | 48ac097 | 2019-03-13 22:33:01 -0700 | [diff] [blame] | 62 | import com.android.internal.telephony.SubscriptionInfoUpdater; |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 63 | import com.android.internal.telephony.TelephonyPermissions; |
Meng Wang | a320b94 | 2019-11-25 11:21:26 -0800 | [diff] [blame] | 64 | import com.android.internal.telephony.util.ArrayUtils; |
shuoq | 26a3a4c | 2016-12-16 11:06:48 -0800 | [diff] [blame] | 65 | import com.android.internal.util.IndentingPrintWriter; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 66 | |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 67 | import java.io.File; |
Junda Liu | 43d723a | 2015-05-12 17:23:45 -0700 | [diff] [blame] | 68 | import java.io.FileDescriptor; |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 69 | import java.io.FileInputStream; |
| 70 | import java.io.FileNotFoundException; |
| 71 | import java.io.FileOutputStream; |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 72 | import java.io.FilenameFilter; |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 73 | import java.io.IOException; |
Junda Liu | 43d723a | 2015-05-12 17:23:45 -0700 | [diff] [blame] | 74 | import java.io.PrintWriter; |
shuoq | 26a3a4c | 2016-12-16 11:06:48 -0800 | [diff] [blame] | 75 | import java.util.ArrayList; |
| 76 | import java.util.Arrays; |
| 77 | import java.util.Collections; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 78 | import java.util.List; |
Hunter Knepshield | eefb31b | 2020-02-19 15:30:54 -0800 | [diff] [blame] | 79 | import java.util.Set; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 80 | |
| 81 | /** |
| 82 | * CarrierConfigLoader binds to privileged carrier apps to fetch carrier config overlays. |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 83 | */ |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 84 | public class CarrierConfigLoader extends ICarrierConfigLoader.Stub { |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 85 | private static final String LOG_TAG = "CarrierConfigLoader"; |
Meng Wang | 33ad2bc | 2017-03-16 20:21:20 -0700 | [diff] [blame] | 86 | |
| 87 | // Package name for platform carrier config app, bundled with system image. |
| 88 | private final String mPlatformCarrierConfigPackage; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 89 | |
| 90 | /** The singleton instance. */ |
| 91 | private static CarrierConfigLoader sInstance; |
| 92 | // The context for phone app, passed from PhoneGlobals. |
| 93 | private Context mContext; |
| 94 | // Carrier configs from default app, indexed by phoneID. |
Jonathan Basseri | c31f1f3 | 2015-05-12 10:13:03 -0700 | [diff] [blame] | 95 | private PersistableBundle[] mConfigFromDefaultApp; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 96 | // Carrier configs from privileged carrier config app, indexed by phoneID. |
Jonathan Basseri | c31f1f3 | 2015-05-12 10:13:03 -0700 | [diff] [blame] | 97 | private PersistableBundle[] mConfigFromCarrierApp; |
Torbjorn Eklund | 723527a | 2019-02-13 11:16:25 +0100 | [diff] [blame] | 98 | // Persistent Carrier configs that are provided via the override test API, indexed by phone ID. |
| 99 | private PersistableBundle[] mPersistentOverrideConfigs; |
Hall Liu | 506724b | 2018-10-22 18:16:14 -0700 | [diff] [blame] | 100 | // Carrier configs that are provided via the override test API, indexed by phone ID. |
| 101 | private PersistableBundle[] mOverrideConfigs; |
Jayachandran C | 645ec61 | 2020-01-10 10:30:25 -0800 | [diff] [blame] | 102 | // Carrier configs to override code default when there is no SIM inserted |
| 103 | private PersistableBundle mNoSimConfig; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 104 | // Service connection for binding to config app. |
Zach Johnson | 36d7aab | 2015-05-22 15:43:00 -0700 | [diff] [blame] | 105 | private CarrierServiceConnection[] mServiceConnection; |
Jayachandran C | 645ec61 | 2020-01-10 10:30:25 -0800 | [diff] [blame] | 106 | // Service connection for binding to carrier config app for no SIM config. |
| 107 | private CarrierServiceConnection[] mServiceConnectionForNoSimConfig; |
Jordan Liu | 178430d | 2020-02-10 14:32:15 -0800 | [diff] [blame] | 108 | // Whether we are bound to a service for each phone |
| 109 | private boolean[] mServiceBound; |
Jayachandran C | 645ec61 | 2020-01-10 10:30:25 -0800 | [diff] [blame] | 110 | // Whether we are bound to a service for no SIM config |
| 111 | private boolean[] mServiceBoundForNoSimConfig; |
Sarah Chin | 807d5c6 | 2020-03-30 17:21:09 -0700 | [diff] [blame] | 112 | // Whether we have sent config change broadcast for each phone id. |
Junda Liu | 03aad76 | 2017-07-21 13:32:17 -0700 | [diff] [blame] | 113 | private boolean[] mHasSentConfigChange; |
Sarah Chin | 807d5c6 | 2020-03-30 17:21:09 -0700 | [diff] [blame] | 114 | // Whether the broadcast was sent from EVENT_SYSTEM_UNLOCKED, to track rebroadcasts |
| 115 | private boolean[] mFromSystemUnlocked; |
Nathan Harold | 48ac097 | 2019-03-13 22:33:01 -0700 | [diff] [blame] | 116 | // SubscriptionInfoUpdater |
| 117 | private final SubscriptionInfoUpdater mSubscriptionInfoUpdater; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 118 | |
Nanxi Chen | 3d67050 | 2016-03-17 16:32:09 -0700 | [diff] [blame] | 119 | // Broadcast receiver for Boot intents, register intent filter in construtor. |
| 120 | private final BroadcastReceiver mBootReceiver = new ConfigLoaderBroadcastReceiver(); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 121 | // Broadcast receiver for SIM and pkg intents, register intent filter in constructor. |
Nanxi Chen | 3d67050 | 2016-03-17 16:32:09 -0700 | [diff] [blame] | 122 | private final BroadcastReceiver mPackageReceiver = new ConfigLoaderBroadcastReceiver(); |
Jack Yu | 67663de | 2019-10-17 15:19:48 -0700 | [diff] [blame] | 123 | private final LocalLog mCarrierConfigLoadingLog = new LocalLog(100); |
chen xu | db04c29 | 2019-03-26 17:01:15 -0700 | [diff] [blame] | 124 | |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 125 | |
| 126 | // Message codes; see mHandler below. |
| 127 | // Request from SubscriptionInfoUpdater when SIM becomes absent or error. |
| 128 | private static final int EVENT_CLEAR_CONFIG = 0; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 129 | // Has connected to default app. |
| 130 | private static final int EVENT_CONNECTED_TO_DEFAULT = 3; |
| 131 | // Has connected to carrier app. |
| 132 | private static final int EVENT_CONNECTED_TO_CARRIER = 4; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 133 | // Config has been loaded from default app (or cache). |
| 134 | private static final int EVENT_FETCH_DEFAULT_DONE = 5; |
| 135 | // Config has been loaded from carrier app (or cache). |
| 136 | private static final int EVENT_FETCH_CARRIER_DONE = 6; |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 137 | // Attempt to fetch from default app or read from XML. |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 138 | private static final int EVENT_DO_FETCH_DEFAULT = 7; |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 139 | // Attempt to fetch from carrier app or read from XML. |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 140 | private static final int EVENT_DO_FETCH_CARRIER = 8; |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 141 | // A package has been installed, uninstalled, or updated. |
| 142 | private static final int EVENT_PACKAGE_CHANGED = 9; |
Jonathan Basseri | 930701e | 2015-06-11 20:56:43 -0700 | [diff] [blame] | 143 | // Bind timed out for the default app. |
| 144 | private static final int EVENT_BIND_DEFAULT_TIMEOUT = 10; |
| 145 | // Bind timed out for a carrier app. |
| 146 | private static final int EVENT_BIND_CARRIER_TIMEOUT = 11; |
Jonathan Basseri | 7697cae | 2015-07-06 15:49:23 -0700 | [diff] [blame] | 147 | // Check if the system fingerprint has changed. |
| 148 | private static final int EVENT_CHECK_SYSTEM_UPDATE = 12; |
Nanxi Chen | 3d67050 | 2016-03-17 16:32:09 -0700 | [diff] [blame] | 149 | // Rerun carrier config binding after system is unlocked. |
| 150 | private static final int EVENT_SYSTEM_UNLOCKED = 13; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 151 | // Fetching config timed out from the default app. |
| 152 | private static final int EVENT_FETCH_DEFAULT_TIMEOUT = 14; |
| 153 | // Fetching config timed out from a carrier app. |
| 154 | private static final int EVENT_FETCH_CARRIER_TIMEOUT = 15; |
Nathan Harold | 48ac097 | 2019-03-13 22:33:01 -0700 | [diff] [blame] | 155 | // SubscriptionInfoUpdater has finished updating the sub for the carrier config. |
| 156 | private static final int EVENT_SUBSCRIPTION_INFO_UPDATED = 16; |
Malcolm Chen | 5ea1853 | 2019-10-24 19:55:44 -0700 | [diff] [blame] | 157 | // Multi-SIM config changed. |
| 158 | private static final int EVENT_MULTI_SIM_CONFIG_CHANGED = 17; |
Jayachandran C | 645ec61 | 2020-01-10 10:30:25 -0800 | [diff] [blame] | 159 | // Attempt to fetch from default app or read from XML for no SIM case. |
| 160 | private static final int EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG = 18; |
| 161 | // No SIM config has been loaded from default app (or cache). |
| 162 | private static final int EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE = 19; |
| 163 | // Has connected to default app for no SIM config. |
| 164 | private static final int EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG = 20; |
| 165 | // Bind timed out for the default app when trying to fetch no SIM config. |
| 166 | private static final int EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT = 21; |
| 167 | // Fetching config timed out from the default app for no SIM config. |
| 168 | private static final int EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT = 22; |
Jonathan Basseri | 930701e | 2015-06-11 20:56:43 -0700 | [diff] [blame] | 169 | |
Junda Liu | 6cb4500 | 2016-03-22 17:18:20 -0700 | [diff] [blame] | 170 | private static final int BIND_TIMEOUT_MILLIS = 30000; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 171 | |
Meng Wang | 0f6b2ea | 2020-01-06 18:31:16 -0800 | [diff] [blame] | 172 | // Keys used for saving and restoring config bundle from file. |
| 173 | private static final String KEY_VERSION = "__carrier_config_package_version__"; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 174 | |
Torbjorn Eklund | 723527a | 2019-02-13 11:16:25 +0100 | [diff] [blame] | 175 | private static final String OVERRIDE_PACKAGE_ADDITION = "-override"; |
| 176 | |
Jonathan Basseri | 7697cae | 2015-07-06 15:49:23 -0700 | [diff] [blame] | 177 | // SharedPreferences key for last known build fingerprint. |
| 178 | private static final String KEY_FINGERPRINT = "build_fingerprint"; |
| 179 | |
Hunter Knepshield | d0ed621 | 2020-01-28 17:43:16 -0800 | [diff] [blame] | 180 | // Argument for #dump that indicates we should also call the default and specified carrier |
| 181 | // service's #dump method. In multi-SIM devices, it's possible that carrier A is on SIM 1 and |
| 182 | // carrier B is on SIM 2, in which case we should not dump carrier B's service when carrier A |
| 183 | // requested the dump. |
| 184 | private static final String DUMP_ARG_REQUESTING_PACKAGE = "--requesting-package"; |
| 185 | |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 186 | // Handler to process various events. |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 187 | // |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 188 | // For each phoneId, the event sequence should be: |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 189 | // fetch default, connected to default, fetch default (async), fetch default done, |
| 190 | // fetch carrier, connected to carrier, fetch carrier (async), fetch carrier done. |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 191 | // |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 192 | // If there is a saved config file for either the default app or the carrier app, we skip |
| 193 | // binding to the app and go straight from fetch to loaded. |
| 194 | // |
| 195 | // At any time, at most one connection is active. If events are not in this order, previous |
| 196 | // connection will be unbound, so only latest event takes effect. |
| 197 | // |
| 198 | // We broadcast ACTION_CARRIER_CONFIG_CHANGED after: |
| 199 | // 1. loading from carrier app (even if read from a file) |
| 200 | // 2. loading from default app if there is no carrier app (even if read from a file) |
| 201 | // 3. clearing config (e.g. due to sim removal) |
| 202 | // 4. encountering bind or IPC error |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 203 | private class ConfigHandler extends Handler { |
| 204 | @Override |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 205 | public void handleMessage(Message msg) { |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 206 | final int phoneId = msg.arg1; |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 207 | logdWithLocalLog("mHandler: " + msg.what + " phoneId: " + phoneId); |
Malcolm Chen | 5ea1853 | 2019-10-24 19:55:44 -0700 | [diff] [blame] | 208 | if (!SubscriptionManager.isValidPhoneId(phoneId) |
| 209 | && msg.what != EVENT_MULTI_SIM_CONFIG_CHANGED) { |
| 210 | return; |
| 211 | } |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 212 | switch (msg.what) { |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 213 | case EVENT_CLEAR_CONFIG: { |
Malcolm Chen | 5ea1853 | 2019-10-24 19:55:44 -0700 | [diff] [blame] | 214 | clearConfigForPhone(phoneId, true); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 215 | break; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 216 | } |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 217 | |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 218 | case EVENT_SYSTEM_UNLOCKED: { |
Malcolm Chen | 5ea1853 | 2019-10-24 19:55:44 -0700 | [diff] [blame] | 219 | for (int i = 0; i < TelephonyManager.from(mContext).getActiveModemCount(); |
| 220 | ++i) { |
Sarah Chin | 807d5c6 | 2020-03-30 17:21:09 -0700 | [diff] [blame] | 221 | // When the user unlocks the device, send the broadcast again (with a |
| 222 | // rebroadcast extra) if we have sent it before unlock. This will avoid |
| 223 | // trying to load the carrier config when the SIM is still loading when the |
| 224 | // unlock happens. |
Junda Liu | 03aad76 | 2017-07-21 13:32:17 -0700 | [diff] [blame] | 225 | if (mHasSentConfigChange[i]) { |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 226 | logdWithLocalLog("System unlocked"); |
Sarah Chin | 807d5c6 | 2020-03-30 17:21:09 -0700 | [diff] [blame] | 227 | mFromSystemUnlocked[i] = true; |
Junda Liu | 03aad76 | 2017-07-21 13:32:17 -0700 | [diff] [blame] | 228 | updateConfigForPhoneId(i); |
| 229 | } |
Nanxi Chen | 3d67050 | 2016-03-17 16:32:09 -0700 | [diff] [blame] | 230 | } |
| 231 | break; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 232 | } |
Nanxi Chen | 3d67050 | 2016-03-17 16:32:09 -0700 | [diff] [blame] | 233 | |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 234 | case EVENT_PACKAGE_CHANGED: { |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 235 | final String carrierPackageName = (String) msg.obj; |
| 236 | // Only update if there are cached config removed to avoid updating config for |
| 237 | // unrelated packages. |
Jonathan Basseri | 7697cae | 2015-07-06 15:49:23 -0700 | [diff] [blame] | 238 | if (clearCachedConfigForPackage(carrierPackageName)) { |
Malcolm Chen | 5ea1853 | 2019-10-24 19:55:44 -0700 | [diff] [blame] | 239 | int numPhones = TelephonyManager.from(mContext).getActiveModemCount(); |
Junda Liu | 8a8a53a | 2015-05-15 16:19:57 -0700 | [diff] [blame] | 240 | for (int i = 0; i < numPhones; ++i) { |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 241 | logdWithLocalLog("Package changed: " + carrierPackageName |
Jack Yu | 67663de | 2019-10-17 15:19:48 -0700 | [diff] [blame] | 242 | + ", phone=" + i); |
Junda Liu | 8a8a53a | 2015-05-15 16:19:57 -0700 | [diff] [blame] | 243 | updateConfigForPhoneId(i); |
| 244 | } |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 245 | } |
| 246 | break; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 247 | } |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 248 | |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 249 | case EVENT_DO_FETCH_DEFAULT: { |
Torbjorn Eklund | 723527a | 2019-02-13 11:16:25 +0100 | [diff] [blame] | 250 | // Restore persistent override values. |
| 251 | PersistableBundle config = restoreConfigFromXml( |
| 252 | mPlatformCarrierConfigPackage, OVERRIDE_PACKAGE_ADDITION, phoneId); |
| 253 | if (config != null) { |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 254 | logd("Loaded persistent override config from XML. package=" |
Torbjorn Eklund | 723527a | 2019-02-13 11:16:25 +0100 | [diff] [blame] | 255 | + mPlatformCarrierConfigPackage |
| 256 | + " phoneId=" + phoneId); |
| 257 | mPersistentOverrideConfigs[phoneId] = config; |
| 258 | } |
| 259 | |
| 260 | config = restoreConfigFromXml(mPlatformCarrierConfigPackage, "", phoneId); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 261 | if (config != null) { |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 262 | logd( |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 263 | "Loaded config from XML. package=" |
| 264 | + mPlatformCarrierConfigPackage |
| 265 | + " phoneId=" |
| 266 | + phoneId); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 267 | mConfigFromDefaultApp[phoneId] = config; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 268 | Message newMsg = obtainMessage(EVENT_FETCH_DEFAULT_DONE, phoneId, -1); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 269 | newMsg.getData().putBoolean("loaded_from_xml", true); |
| 270 | mHandler.sendMessage(newMsg); |
| 271 | } else { |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 272 | // No cached config, so fetch it from the default app. |
| 273 | if (bindToConfigPackage( |
| 274 | mPlatformCarrierConfigPackage, |
| 275 | phoneId, |
| 276 | EVENT_CONNECTED_TO_DEFAULT)) { |
| 277 | sendMessageDelayed( |
| 278 | obtainMessage(EVENT_BIND_DEFAULT_TIMEOUT, phoneId, -1), |
Jonathan Basseri | 930701e | 2015-06-11 20:56:43 -0700 | [diff] [blame] | 279 | BIND_TIMEOUT_MILLIS); |
| 280 | } else { |
Nathan Harold | 1122e3d | 2021-01-22 15:45:24 -0800 | [diff] [blame^] | 281 | // Put a stub bundle in place so that the rest of the logic continues |
| 282 | // smoothly. |
| 283 | mConfigFromDefaultApp[phoneId] = new PersistableBundle(); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 284 | // Send broadcast if bind fails. |
Nathan Harold | 48ac097 | 2019-03-13 22:33:01 -0700 | [diff] [blame] | 285 | notifySubscriptionInfoUpdater(phoneId); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 286 | // TODO: We *must* call unbindService even if bindService returns false. |
| 287 | // (And possibly if SecurityException was thrown.) |
chen xu | db04c29 | 2019-03-26 17:01:15 -0700 | [diff] [blame] | 288 | loge("binding to default app: " |
| 289 | + mPlatformCarrierConfigPackage + " fails"); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 290 | } |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 291 | } |
| 292 | break; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 293 | } |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 294 | |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 295 | case EVENT_CONNECTED_TO_DEFAULT: { |
Jonathan Basseri | 930701e | 2015-06-11 20:56:43 -0700 | [diff] [blame] | 296 | removeMessages(EVENT_BIND_DEFAULT_TIMEOUT); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 297 | final CarrierServiceConnection conn = (CarrierServiceConnection) msg.obj; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 298 | // If new service connection has been created, unbind. |
| 299 | if (mServiceConnection[phoneId] != conn || conn.service == null) { |
Jordan Liu | 178430d | 2020-02-10 14:32:15 -0800 | [diff] [blame] | 300 | unbindIfBound(mContext, conn, phoneId); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 301 | break; |
| 302 | } |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 303 | final CarrierIdentifier carrierId = getCarrierIdentifierForPhoneId(phoneId); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 304 | // ResultReceiver callback will execute in this Handler's thread. |
| 305 | final ResultReceiver resultReceiver = |
| 306 | new ResultReceiver(this) { |
| 307 | @Override |
| 308 | public void onReceiveResult(int resultCode, Bundle resultData) { |
Jordan Liu | 178430d | 2020-02-10 14:32:15 -0800 | [diff] [blame] | 309 | unbindIfBound(mContext, conn, phoneId); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 310 | // If new service connection has been created, this is stale. |
| 311 | if (mServiceConnection[phoneId] != conn) { |
| 312 | loge("Received response for stale request."); |
| 313 | return; |
| 314 | } |
| 315 | removeMessages(EVENT_FETCH_DEFAULT_TIMEOUT); |
| 316 | if (resultCode == RESULT_ERROR || resultData == null) { |
| 317 | // On error, abort config fetching. |
| 318 | loge("Failed to get carrier config"); |
Nathan Harold | 48ac097 | 2019-03-13 22:33:01 -0700 | [diff] [blame] | 319 | notifySubscriptionInfoUpdater(phoneId); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 320 | return; |
| 321 | } |
| 322 | PersistableBundle config = |
| 323 | resultData.getParcelable(KEY_CONFIG_BUNDLE); |
Torbjorn Eklund | 723527a | 2019-02-13 11:16:25 +0100 | [diff] [blame] | 324 | saveConfigToXml(mPlatformCarrierConfigPackage, "", phoneId, |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 325 | carrierId, config); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 326 | mConfigFromDefaultApp[phoneId] = config; |
| 327 | sendMessage( |
| 328 | obtainMessage( |
| 329 | EVENT_FETCH_DEFAULT_DONE, phoneId, -1)); |
| 330 | } |
| 331 | }; |
| 332 | // Now fetch the config asynchronously from the ICarrierService. |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 333 | try { |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 334 | ICarrierService carrierService = |
| 335 | ICarrierService.Stub.asInterface(conn.service); |
| 336 | carrierService.getCarrierConfig(carrierId, resultReceiver); |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 337 | logdWithLocalLog("Fetch config for default app: " |
chen xu | db04c29 | 2019-03-26 17:01:15 -0700 | [diff] [blame] | 338 | + mPlatformCarrierConfigPackage |
| 339 | + " carrierid: " + carrierId.toString()); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 340 | } catch (RemoteException e) { |
chen xu | db04c29 | 2019-03-26 17:01:15 -0700 | [diff] [blame] | 341 | loge("Failed to get carrier config from default app: " + |
| 342 | mPlatformCarrierConfigPackage + " err: " + e.toString()); |
Jordan Liu | 178430d | 2020-02-10 14:32:15 -0800 | [diff] [blame] | 343 | unbindIfBound(mContext, conn, phoneId); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 344 | break; // So we don't set a timeout. |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 345 | } |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 346 | sendMessageDelayed( |
| 347 | obtainMessage(EVENT_FETCH_DEFAULT_TIMEOUT, phoneId, -1), |
| 348 | BIND_TIMEOUT_MILLIS); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 349 | break; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 350 | } |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 351 | |
Jonathan Basseri | 930701e | 2015-06-11 20:56:43 -0700 | [diff] [blame] | 352 | case EVENT_BIND_DEFAULT_TIMEOUT: |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 353 | case EVENT_FETCH_DEFAULT_TIMEOUT: { |
| 354 | loge("Bind/fetch time out from " + mPlatformCarrierConfigPackage); |
chen xu | f60b316 | 2019-05-01 21:31:05 -0700 | [diff] [blame] | 355 | removeMessages(EVENT_FETCH_DEFAULT_TIMEOUT); |
| 356 | // If we attempted to bind to the app, but the service connection is null due to |
| 357 | // the race condition that clear config event happens before bind/fetch complete |
| 358 | // then config was cleared while we were waiting and we should not continue. |
| 359 | if (mServiceConnection[phoneId] != null) { |
| 360 | // If a ResponseReceiver callback is in the queue when this happens, we will |
| 361 | // unbind twice and throw an exception. |
Jordan Liu | 178430d | 2020-02-10 14:32:15 -0800 | [diff] [blame] | 362 | unbindIfBound(mContext, mServiceConnection[phoneId], phoneId); |
chen xu | f60b316 | 2019-05-01 21:31:05 -0700 | [diff] [blame] | 363 | broadcastConfigChangedIntent(phoneId); |
| 364 | } |
Nathan Harold | 1122e3d | 2021-01-22 15:45:24 -0800 | [diff] [blame^] | 365 | // Put a stub bundle in place so that the rest of the logic continues smoothly. |
| 366 | mConfigFromDefaultApp[phoneId] = new PersistableBundle(); |
Nathan Harold | 48ac097 | 2019-03-13 22:33:01 -0700 | [diff] [blame] | 367 | notifySubscriptionInfoUpdater(phoneId); |
Jonathan Basseri | 930701e | 2015-06-11 20:56:43 -0700 | [diff] [blame] | 368 | break; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 369 | } |
Jonathan Basseri | 930701e | 2015-06-11 20:56:43 -0700 | [diff] [blame] | 370 | |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 371 | case EVENT_FETCH_DEFAULT_DONE: { |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 372 | // If we attempted to bind to the app, but the service connection is null, then |
| 373 | // config was cleared while we were waiting and we should not continue. |
| 374 | if (!msg.getData().getBoolean("loaded_from_xml", false) |
| 375 | && mServiceConnection[phoneId] == null) { |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 376 | break; |
| 377 | } |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 378 | final String carrierPackageName = getCarrierPackageForPhoneId(phoneId); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 379 | if (carrierPackageName != null) { |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 380 | logd("Found carrier config app: " + carrierPackageName); |
Jordan Liu | 38a614c | 2019-03-20 15:01:17 -0700 | [diff] [blame] | 381 | sendMessage(obtainMessage(EVENT_DO_FETCH_CARRIER, phoneId, -1)); |
Jonathan Basseri | b919e93 | 2015-05-27 16:53:08 +0000 | [diff] [blame] | 382 | } else { |
Nathan Harold | 48ac097 | 2019-03-13 22:33:01 -0700 | [diff] [blame] | 383 | notifySubscriptionInfoUpdater(phoneId); |
Jonathan Basseri | 4ae2e7c | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 384 | } |
| 385 | break; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 386 | } |
Jonathan Basseri | 4ae2e7c | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 387 | |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 388 | case EVENT_DO_FETCH_CARRIER: { |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 389 | final String carrierPackageName = getCarrierPackageForPhoneId(phoneId); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 390 | final PersistableBundle config = |
Torbjorn Eklund | 723527a | 2019-02-13 11:16:25 +0100 | [diff] [blame] | 391 | restoreConfigFromXml(carrierPackageName, "", phoneId); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 392 | if (config != null) { |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 393 | logd( |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 394 | "Loaded config from XML. package=" |
| 395 | + carrierPackageName |
| 396 | + " phoneId=" |
| 397 | + phoneId); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 398 | mConfigFromCarrierApp[phoneId] = config; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 399 | Message newMsg = obtainMessage(EVENT_FETCH_CARRIER_DONE, phoneId, -1); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 400 | newMsg.getData().putBoolean("loaded_from_xml", true); |
| 401 | sendMessage(newMsg); |
| 402 | } else { |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 403 | // No cached config, so fetch it from a carrier app. |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 404 | if (carrierPackageName != null && bindToConfigPackage(carrierPackageName, |
| 405 | phoneId, EVENT_CONNECTED_TO_CARRIER)) { |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 406 | sendMessageDelayed( |
| 407 | obtainMessage(EVENT_BIND_CARRIER_TIMEOUT, phoneId, -1), |
Jonathan Basseri | 930701e | 2015-06-11 20:56:43 -0700 | [diff] [blame] | 408 | BIND_TIMEOUT_MILLIS); |
| 409 | } else { |
Nathan Harold | 1122e3d | 2021-01-22 15:45:24 -0800 | [diff] [blame^] | 410 | // Put a stub bundle in place so that the rest of the logic continues |
| 411 | // smoothly. |
| 412 | mConfigFromCarrierApp[phoneId] = new PersistableBundle(); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 413 | // Send broadcast if bind fails. |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 414 | broadcastConfigChangedIntent(phoneId); |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 415 | loge("Bind to carrier app: " + carrierPackageName + " fails"); |
Nathan Harold | 48ac097 | 2019-03-13 22:33:01 -0700 | [diff] [blame] | 416 | notifySubscriptionInfoUpdater(phoneId); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 417 | } |
| 418 | } |
| 419 | break; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 420 | } |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 421 | |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 422 | case EVENT_CONNECTED_TO_CARRIER: { |
Jonathan Basseri | 930701e | 2015-06-11 20:56:43 -0700 | [diff] [blame] | 423 | removeMessages(EVENT_BIND_CARRIER_TIMEOUT); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 424 | final CarrierServiceConnection conn = (CarrierServiceConnection) msg.obj; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 425 | // If new service connection has been created, unbind. |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 426 | if (mServiceConnection[phoneId] != conn || conn.service == null) { |
Jordan Liu | 178430d | 2020-02-10 14:32:15 -0800 | [diff] [blame] | 427 | unbindIfBound(mContext, conn, phoneId); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 428 | break; |
| 429 | } |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 430 | final CarrierIdentifier carrierId = getCarrierIdentifierForPhoneId(phoneId); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 431 | // ResultReceiver callback will execute in this Handler's thread. |
| 432 | final ResultReceiver resultReceiver = |
| 433 | new ResultReceiver(this) { |
| 434 | @Override |
| 435 | public void onReceiveResult(int resultCode, Bundle resultData) { |
Jordan Liu | 178430d | 2020-02-10 14:32:15 -0800 | [diff] [blame] | 436 | unbindIfBound(mContext, conn, phoneId); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 437 | // If new service connection has been created, this is stale. |
| 438 | if (mServiceConnection[phoneId] != conn) { |
| 439 | loge("Received response for stale request."); |
| 440 | return; |
| 441 | } |
| 442 | removeMessages(EVENT_FETCH_CARRIER_TIMEOUT); |
| 443 | if (resultCode == RESULT_ERROR || resultData == null) { |
| 444 | // On error, abort config fetching. |
chen xu | db04c29 | 2019-03-26 17:01:15 -0700 | [diff] [blame] | 445 | loge("Failed to get carrier config from carrier app: " |
| 446 | + getCarrierPackageForPhoneId(phoneId)); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 447 | broadcastConfigChangedIntent(phoneId); |
Nathan Harold | 48ac097 | 2019-03-13 22:33:01 -0700 | [diff] [blame] | 448 | notifySubscriptionInfoUpdater(phoneId); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 449 | return; |
| 450 | } |
| 451 | PersistableBundle config = |
| 452 | resultData.getParcelable(KEY_CONFIG_BUNDLE); |
Torbjorn Eklund | 723527a | 2019-02-13 11:16:25 +0100 | [diff] [blame] | 453 | saveConfigToXml(getCarrierPackageForPhoneId(phoneId), "", |
| 454 | phoneId, carrierId, config); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 455 | mConfigFromCarrierApp[phoneId] = config; |
| 456 | sendMessage( |
| 457 | obtainMessage( |
| 458 | EVENT_FETCH_CARRIER_DONE, phoneId, -1)); |
| 459 | } |
| 460 | }; |
| 461 | // Now fetch the config asynchronously from the ICarrierService. |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 462 | try { |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 463 | ICarrierService carrierService = |
| 464 | ICarrierService.Stub.asInterface(conn.service); |
| 465 | carrierService.getCarrierConfig(carrierId, resultReceiver); |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 466 | logdWithLocalLog("Fetch config for carrier app: " |
chen xu | db04c29 | 2019-03-26 17:01:15 -0700 | [diff] [blame] | 467 | + getCarrierPackageForPhoneId(phoneId) |
| 468 | + " carrierid: " + carrierId.toString()); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 469 | } catch (RemoteException e) { |
| 470 | loge("Failed to get carrier config: " + e.toString()); |
Jordan Liu | 178430d | 2020-02-10 14:32:15 -0800 | [diff] [blame] | 471 | unbindIfBound(mContext, conn, phoneId); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 472 | break; // So we don't set a timeout. |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 473 | } |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 474 | sendMessageDelayed( |
| 475 | obtainMessage(EVENT_FETCH_CARRIER_TIMEOUT, phoneId, -1), |
| 476 | BIND_TIMEOUT_MILLIS); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 477 | break; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 478 | } |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 479 | |
Jonathan Basseri | 930701e | 2015-06-11 20:56:43 -0700 | [diff] [blame] | 480 | case EVENT_BIND_CARRIER_TIMEOUT: |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 481 | case EVENT_FETCH_CARRIER_TIMEOUT: { |
Nathan Harold | 1122e3d | 2021-01-22 15:45:24 -0800 | [diff] [blame^] | 482 | loge("Bind/fetch from carrier app timeout, package=" |
| 483 | + getCarrierPackageForPhoneId(phoneId)); |
chen xu | f60b316 | 2019-05-01 21:31:05 -0700 | [diff] [blame] | 484 | removeMessages(EVENT_FETCH_CARRIER_TIMEOUT); |
| 485 | // If we attempted to bind to the app, but the service connection is null due to |
| 486 | // the race condition that clear config event happens before bind/fetch complete |
| 487 | // then config was cleared while we were waiting and we should not continue. |
| 488 | if (mServiceConnection[phoneId] != null) { |
| 489 | // If a ResponseReceiver callback is in the queue when this happens, we will |
| 490 | // unbind twice and throw an exception. |
Jordan Liu | 178430d | 2020-02-10 14:32:15 -0800 | [diff] [blame] | 491 | unbindIfBound(mContext, mServiceConnection[phoneId], phoneId); |
chen xu | f60b316 | 2019-05-01 21:31:05 -0700 | [diff] [blame] | 492 | broadcastConfigChangedIntent(phoneId); |
| 493 | } |
Nathan Harold | 1122e3d | 2021-01-22 15:45:24 -0800 | [diff] [blame^] | 494 | // Put a stub bundle in place so that the rest of the logic continues smoothly. |
| 495 | mConfigFromCarrierApp[phoneId] = new PersistableBundle(); |
Nathan Harold | 48ac097 | 2019-03-13 22:33:01 -0700 | [diff] [blame] | 496 | notifySubscriptionInfoUpdater(phoneId); |
Jonathan Basseri | 930701e | 2015-06-11 20:56:43 -0700 | [diff] [blame] | 497 | break; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 498 | } |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 499 | case EVENT_FETCH_CARRIER_DONE: { |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 500 | // If we attempted to bind to the app, but the service connection is null, then |
| 501 | // config was cleared while we were waiting and we should not continue. |
| 502 | if (!msg.getData().getBoolean("loaded_from_xml", false) |
| 503 | && mServiceConnection[phoneId] == null) { |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 504 | break; |
| 505 | } |
Nathan Harold | 48ac097 | 2019-03-13 22:33:01 -0700 | [diff] [blame] | 506 | notifySubscriptionInfoUpdater(phoneId); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 507 | break; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 508 | } |
Jonathan Basseri | 7697cae | 2015-07-06 15:49:23 -0700 | [diff] [blame] | 509 | |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 510 | case EVENT_CHECK_SYSTEM_UPDATE: { |
Jonathan Basseri | 7697cae | 2015-07-06 15:49:23 -0700 | [diff] [blame] | 511 | SharedPreferences sharedPrefs = |
| 512 | PreferenceManager.getDefaultSharedPreferences(mContext); |
| 513 | final String lastFingerprint = sharedPrefs.getString(KEY_FINGERPRINT, null); |
| 514 | if (!Build.FINGERPRINT.equals(lastFingerprint)) { |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 515 | logd( |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 516 | "Build fingerprint changed. old: " |
| 517 | + lastFingerprint |
| 518 | + " new: " |
| 519 | + Build.FINGERPRINT); |
Jonathan Basseri | 7697cae | 2015-07-06 15:49:23 -0700 | [diff] [blame] | 520 | clearCachedConfigForPackage(null); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 521 | sharedPrefs |
| 522 | .edit() |
| 523 | .putString(KEY_FINGERPRINT, Build.FINGERPRINT) |
| 524 | .apply(); |
Jonathan Basseri | 7697cae | 2015-07-06 15:49:23 -0700 | [diff] [blame] | 525 | } |
| 526 | break; |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 527 | } |
Nathan Harold | 48ac097 | 2019-03-13 22:33:01 -0700 | [diff] [blame] | 528 | |
| 529 | case EVENT_SUBSCRIPTION_INFO_UPDATED: |
| 530 | broadcastConfigChangedIntent(phoneId); |
| 531 | break; |
Malcolm Chen | 5ea1853 | 2019-10-24 19:55:44 -0700 | [diff] [blame] | 532 | case EVENT_MULTI_SIM_CONFIG_CHANGED: |
| 533 | onMultiSimConfigChanged(); |
| 534 | break; |
Jayachandran C | 645ec61 | 2020-01-10 10:30:25 -0800 | [diff] [blame] | 535 | |
| 536 | case EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG: { |
| 537 | PersistableBundle config = |
| 538 | restoreNoSimConfigFromXml(mPlatformCarrierConfigPackage); |
| 539 | |
| 540 | if (config != null) { |
| 541 | logd("Loaded no SIM config from XML. package=" |
| 542 | + mPlatformCarrierConfigPackage); |
| 543 | mNoSimConfig = config; |
| 544 | sendMessage( |
| 545 | obtainMessage( |
| 546 | EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE, |
| 547 | phoneId, -1)); |
| 548 | } else { |
| 549 | // No cached config, so fetch it from the default app. |
| 550 | if (bindToConfigPackage( |
| 551 | mPlatformCarrierConfigPackage, |
| 552 | phoneId, |
| 553 | EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG)) { |
| 554 | sendMessageDelayed( |
| 555 | obtainMessage( |
| 556 | EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT, |
| 557 | phoneId, -1), BIND_TIMEOUT_MILLIS); |
| 558 | } else { |
| 559 | broadcastConfigChangedIntent(phoneId, false); |
| 560 | // TODO: We *must* call unbindService even if bindService returns false. |
| 561 | // (And possibly if SecurityException was thrown.) |
| 562 | loge("binding to default app to fetch no SIM config: " |
| 563 | + mPlatformCarrierConfigPackage + " fails"); |
| 564 | } |
| 565 | } |
| 566 | break; |
| 567 | } |
| 568 | |
| 569 | case EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE: { |
| 570 | broadcastConfigChangedIntent(phoneId, false); |
| 571 | break; |
| 572 | } |
| 573 | |
| 574 | case EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT: |
| 575 | case EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT: { |
| 576 | loge("Bind/fetch time out for no SIM config from " |
| 577 | + mPlatformCarrierConfigPackage); |
| 578 | removeMessages(EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT); |
| 579 | // If we attempted to bind to the app, but the service connection is null due to |
| 580 | // the race condition that clear config event happens before bind/fetch complete |
| 581 | // then config was cleared while we were waiting and we should not continue. |
| 582 | if (mServiceConnectionForNoSimConfig[phoneId] != null) { |
| 583 | // If a ResponseReceiver callback is in the queue when this happens, we will |
| 584 | // unbind twice and throw an exception. |
| 585 | unbindIfBoundForNoSimConfig(mContext, |
| 586 | mServiceConnectionForNoSimConfig[phoneId], phoneId); |
| 587 | } |
| 588 | broadcastConfigChangedIntent(phoneId, false); |
| 589 | break; |
| 590 | } |
| 591 | |
| 592 | case EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG: { |
| 593 | removeMessages(EVENT_BIND_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT); |
| 594 | final CarrierServiceConnection conn = (CarrierServiceConnection) msg.obj; |
| 595 | // If new service connection has been created, unbind. |
| 596 | if (mServiceConnectionForNoSimConfig[phoneId] != conn || conn.service == null) { |
| 597 | unbindIfBoundForNoSimConfig(mContext, conn, phoneId); |
| 598 | break; |
| 599 | } |
| 600 | |
| 601 | // ResultReceiver callback will execute in this Handler's thread. |
| 602 | final ResultReceiver resultReceiver = |
| 603 | new ResultReceiver(this) { |
| 604 | @Override |
| 605 | public void onReceiveResult(int resultCode, Bundle resultData) { |
| 606 | unbindIfBoundForNoSimConfig(mContext, conn, phoneId); |
| 607 | // If new service connection has been created, this is stale. |
| 608 | if (mServiceConnectionForNoSimConfig[phoneId] != conn) { |
| 609 | loge("Received response for stale request."); |
| 610 | return; |
| 611 | } |
| 612 | removeMessages(EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT); |
| 613 | if (resultCode == RESULT_ERROR || resultData == null) { |
| 614 | // On error, abort config fetching. |
| 615 | loge("Failed to get no SIM carrier config"); |
| 616 | return; |
| 617 | } |
| 618 | PersistableBundle config = |
| 619 | resultData.getParcelable(KEY_CONFIG_BUNDLE); |
| 620 | saveNoSimConfigToXml(mPlatformCarrierConfigPackage, config); |
| 621 | mNoSimConfig = config; |
| 622 | sendMessage( |
| 623 | obtainMessage( |
| 624 | EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_DONE, |
| 625 | phoneId, -1)); |
| 626 | } |
| 627 | }; |
| 628 | // Now fetch the config asynchronously from the ICarrierService. |
| 629 | try { |
| 630 | ICarrierService carrierService = |
| 631 | ICarrierService.Stub.asInterface(conn.service); |
| 632 | carrierService.getCarrierConfig(null, resultReceiver); |
| 633 | logdWithLocalLog("Fetch no sim config from default app: " |
| 634 | + mPlatformCarrierConfigPackage); |
| 635 | } catch (RemoteException e) { |
| 636 | loge("Failed to get no sim carrier config from default app: " + |
| 637 | mPlatformCarrierConfigPackage + " err: " + e.toString()); |
| 638 | unbindIfBoundForNoSimConfig(mContext, conn, phoneId); |
| 639 | break; // So we don't set a timeout. |
| 640 | } |
| 641 | sendMessageDelayed( |
| 642 | obtainMessage( |
| 643 | EVENT_FETCH_DEFAULT_FOR_NO_SIM_CONFIG_TIMEOUT, |
| 644 | phoneId, -1), BIND_TIMEOUT_MILLIS); |
| 645 | break; |
| 646 | } |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 647 | } |
| 648 | } |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | private final Handler mHandler; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 652 | |
| 653 | /** |
| 654 | * Constructs a CarrierConfigLoader, registers it as a service, and registers a broadcast |
| 655 | * receiver for relevant events. |
| 656 | */ |
| 657 | private CarrierConfigLoader(Context context) { |
| 658 | mContext = context; |
Meng Wang | 33ad2bc | 2017-03-16 20:21:20 -0700 | [diff] [blame] | 659 | mPlatformCarrierConfigPackage = |
| 660 | mContext.getString(R.string.platform_carrier_config_package); |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 661 | mHandler = new ConfigHandler(); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 662 | |
Nanxi Chen | 3d67050 | 2016-03-17 16:32:09 -0700 | [diff] [blame] | 663 | IntentFilter bootFilter = new IntentFilter(); |
| 664 | bootFilter.addAction(Intent.ACTION_BOOT_COMPLETED); |
| 665 | context.registerReceiver(mBootReceiver, bootFilter); |
| 666 | |
Junda Liu | 8a8a53a | 2015-05-15 16:19:57 -0700 | [diff] [blame] | 667 | // Register for package updates. Update app or uninstall app update will have all 3 intents, |
| 668 | // in the order or removed, added, replaced, all with extra_replace set to true. |
| 669 | IntentFilter pkgFilter = new IntentFilter(); |
| 670 | pkgFilter.addAction(Intent.ACTION_PACKAGE_ADDED); |
| 671 | pkgFilter.addAction(Intent.ACTION_PACKAGE_REMOVED); |
| 672 | pkgFilter.addAction(Intent.ACTION_PACKAGE_REPLACED); |
| 673 | pkgFilter.addDataScheme("package"); |
Jordan Liu | 5ca2476 | 2019-07-10 12:51:09 -0700 | [diff] [blame] | 674 | context.registerReceiver(mPackageReceiver, pkgFilter); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 675 | |
Malcolm Chen | 978dda5 | 2019-10-08 18:15:25 -0700 | [diff] [blame] | 676 | int numPhones = TelephonyManager.from(context).getSupportedModemCount(); |
Jonathan Basseri | c31f1f3 | 2015-05-12 10:13:03 -0700 | [diff] [blame] | 677 | mConfigFromDefaultApp = new PersistableBundle[numPhones]; |
| 678 | mConfigFromCarrierApp = new PersistableBundle[numPhones]; |
Torbjorn Eklund | 723527a | 2019-02-13 11:16:25 +0100 | [diff] [blame] | 679 | mPersistentOverrideConfigs = new PersistableBundle[numPhones]; |
Hall Liu | 506724b | 2018-10-22 18:16:14 -0700 | [diff] [blame] | 680 | mOverrideConfigs = new PersistableBundle[numPhones]; |
Jayachandran C | 645ec61 | 2020-01-10 10:30:25 -0800 | [diff] [blame] | 681 | mNoSimConfig = new PersistableBundle(); |
Zach Johnson | 36d7aab | 2015-05-22 15:43:00 -0700 | [diff] [blame] | 682 | mServiceConnection = new CarrierServiceConnection[numPhones]; |
Jordan Liu | 178430d | 2020-02-10 14:32:15 -0800 | [diff] [blame] | 683 | mServiceBound = new boolean[numPhones]; |
Junda Liu | 03aad76 | 2017-07-21 13:32:17 -0700 | [diff] [blame] | 684 | mHasSentConfigChange = new boolean[numPhones]; |
Sarah Chin | 807d5c6 | 2020-03-30 17:21:09 -0700 | [diff] [blame] | 685 | mFromSystemUnlocked = new boolean[numPhones]; |
Jayachandran C | 645ec61 | 2020-01-10 10:30:25 -0800 | [diff] [blame] | 686 | mServiceConnectionForNoSimConfig = new CarrierServiceConnection[numPhones]; |
| 687 | mServiceBoundForNoSimConfig = new boolean[numPhones]; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 688 | // Make this service available through ServiceManager. |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 689 | TelephonyFrameworkInitializer |
| 690 | .getTelephonyServiceManager().getCarrierConfigServiceRegisterer().register(this); |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 691 | logd("CarrierConfigLoader has started"); |
Nathan Harold | 48ac097 | 2019-03-13 22:33:01 -0700 | [diff] [blame] | 692 | mSubscriptionInfoUpdater = PhoneFactory.getSubscriptionInfoUpdater(); |
Jonathan Basseri | 7697cae | 2015-07-06 15:49:23 -0700 | [diff] [blame] | 693 | mHandler.sendEmptyMessage(EVENT_CHECK_SYSTEM_UPDATE); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | /** |
| 697 | * Initialize the singleton CarrierConfigLoader instance. |
| 698 | * |
| 699 | * This is only done once, at startup, from {@link com.android.phone.PhoneApp#onCreate}. |
| 700 | */ |
| 701 | /* package */ |
| 702 | static CarrierConfigLoader init(Context context) { |
| 703 | synchronized (CarrierConfigLoader.class) { |
| 704 | if (sInstance == null) { |
| 705 | sInstance = new CarrierConfigLoader(context); |
| 706 | } else { |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 707 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 708 | } |
| 709 | return sInstance; |
| 710 | } |
| 711 | } |
| 712 | |
Jayachandran C | 645ec61 | 2020-01-10 10:30:25 -0800 | [diff] [blame] | 713 | private void clearConfigForPhone(int phoneId, boolean fetchNoSimConfig) { |
Malcolm Chen | 5ea1853 | 2019-10-24 19:55:44 -0700 | [diff] [blame] | 714 | /* Ignore clear configuration request if device is being shutdown. */ |
| 715 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 716 | if (phone != null) { |
| 717 | if (phone.isShuttingDown()) { |
| 718 | return; |
| 719 | } |
| 720 | } |
| 721 | |
| 722 | mConfigFromDefaultApp[phoneId] = null; |
| 723 | mConfigFromCarrierApp[phoneId] = null; |
| 724 | mServiceConnection[phoneId] = null; |
| 725 | mHasSentConfigChange[phoneId] = false; |
| 726 | |
Jayachandran C | 645ec61 | 2020-01-10 10:30:25 -0800 | [diff] [blame] | 727 | if (fetchNoSimConfig) { |
| 728 | // To fetch no SIM config |
| 729 | mHandler.sendMessage( |
| 730 | mHandler.obtainMessage( |
| 731 | EVENT_DO_FETCH_DEFAULT_FOR_NO_SIM_CONFIG, phoneId, -1)); |
| 732 | } |
Malcolm Chen | 5ea1853 | 2019-10-24 19:55:44 -0700 | [diff] [blame] | 733 | } |
| 734 | |
Nathan Harold | 48ac097 | 2019-03-13 22:33:01 -0700 | [diff] [blame] | 735 | private void notifySubscriptionInfoUpdater(int phoneId) { |
| 736 | String configPackagename; |
| 737 | PersistableBundle configToSend; |
| 738 | int carrierId = getSpecificCarrierIdForPhoneId(phoneId); |
| 739 | // Prefer the carrier privileged carrier app, but if there is not one, use the platform |
| 740 | // default carrier app. |
| 741 | if (mConfigFromCarrierApp[phoneId] != null) { |
| 742 | configPackagename = getCarrierPackageForPhoneId(phoneId); |
| 743 | configToSend = mConfigFromCarrierApp[phoneId]; |
| 744 | } else { |
| 745 | configPackagename = mPlatformCarrierConfigPackage; |
| 746 | configToSend = mConfigFromDefaultApp[phoneId]; |
| 747 | } |
Nazanin Bakhshi | 6fcc334 | 2019-09-18 17:54:01 -0700 | [diff] [blame] | 748 | |
Malcolm Chen | efafd1c | 2020-02-20 13:27:08 -0800 | [diff] [blame] | 749 | if (configToSend == null) { |
| 750 | configToSend = new PersistableBundle(); |
| 751 | } |
| 752 | |
Nazanin Bakhshi | 6fcc334 | 2019-09-18 17:54:01 -0700 | [diff] [blame] | 753 | // mOverrideConfigs is for testing. And it will override current configs. |
| 754 | PersistableBundle config = mOverrideConfigs[phoneId]; |
| 755 | if (config != null) { |
Torbjorn Eklund | 1050cb0 | 2018-11-16 14:05:38 +0100 | [diff] [blame] | 756 | configToSend = new PersistableBundle(configToSend); |
Nazanin Bakhshi | 6fcc334 | 2019-09-18 17:54:01 -0700 | [diff] [blame] | 757 | configToSend.putAll(config); |
| 758 | } |
| 759 | |
Nathan Harold | 48ac097 | 2019-03-13 22:33:01 -0700 | [diff] [blame] | 760 | mSubscriptionInfoUpdater.updateSubscriptionByCarrierConfigAndNotifyComplete( |
| 761 | phoneId, configPackagename, configToSend, |
| 762 | mHandler.obtainMessage(EVENT_SUBSCRIPTION_INFO_UPDATED, phoneId, -1)); |
| 763 | } |
| 764 | |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 765 | private void broadcastConfigChangedIntent(int phoneId) { |
Amit Mahajan | f8088ab | 2018-03-02 15:24:07 -0800 | [diff] [blame] | 766 | broadcastConfigChangedIntent(phoneId, true); |
| 767 | } |
| 768 | |
| 769 | private void broadcastConfigChangedIntent(int phoneId, boolean addSubIdExtra) { |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 770 | Intent intent = new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED); |
Christopher Tate | 38f55eb | 2017-02-14 14:43:49 -0800 | [diff] [blame] | 771 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT | |
chen xu | f9db49f | 2019-03-31 23:04:42 -0700 | [diff] [blame] | 772 | Intent.FLAG_RECEIVER_FOREGROUND); |
Qiongcheng Luo | e7de61b | 2018-08-06 10:20:09 +0800 | [diff] [blame] | 773 | if (addSubIdExtra) { |
| 774 | int simApplicationState = TelephonyManager.SIM_STATE_UNKNOWN; |
| 775 | int[] subIds = SubscriptionManager.getSubId(phoneId); |
| 776 | if (!ArrayUtils.isEmpty(subIds)) { |
| 777 | TelephonyManager telMgr = TelephonyManager.from(mContext) |
| 778 | .createForSubscriptionId(subIds[0]); |
| 779 | simApplicationState = telMgr.getSimApplicationState(); |
| 780 | } |
Malcolm Chen | f7635ec | 2020-04-15 15:45:00 -0700 | [diff] [blame] | 781 | logd("Broadcast CARRIER_CONFIG_CHANGED for phone " + phoneId |
| 782 | + " simApplicationState " + simApplicationState); |
Qiongcheng Luo | e7de61b | 2018-08-06 10:20:09 +0800 | [diff] [blame] | 783 | // Include subId/carrier id extra only if SIM records are loaded |
| 784 | if (simApplicationState != TelephonyManager.SIM_STATE_UNKNOWN |
| 785 | && simApplicationState != TelephonyManager.SIM_STATE_NOT_READY) { |
| 786 | SubscriptionManager.putPhoneIdAndSubIdExtra(intent, phoneId); |
| 787 | intent.putExtra(TelephonyManager.EXTRA_SPECIFIC_CARRIER_ID, |
| 788 | getSpecificCarrierIdForPhoneId(phoneId)); |
| 789 | intent.putExtra(TelephonyManager.EXTRA_CARRIER_ID, getCarrierIdForPhoneId(phoneId)); |
| 790 | } |
Amit Mahajan | f8088ab | 2018-03-02 15:24:07 -0800 | [diff] [blame] | 791 | } |
Amit Mahajan | b33bcda | 2018-01-24 12:56:44 -0800 | [diff] [blame] | 792 | intent.putExtra(CarrierConfigManager.EXTRA_SLOT_INDEX, phoneId); |
Sarah Chin | 807d5c6 | 2020-03-30 17:21:09 -0700 | [diff] [blame] | 793 | intent.putExtra(CarrierConfigManager.EXTRA_REBROADCAST_ON_UNLOCK, |
| 794 | mFromSystemUnlocked[phoneId]); |
Meng Wang | 97a6a46 | 2020-01-23 16:22:16 -0800 | [diff] [blame] | 795 | mContext.sendBroadcastAsUser(intent, UserHandle.ALL); |
Jack Yu | e9e95be | 2020-03-22 10:56:06 -0700 | [diff] [blame] | 796 | int[] subIds = SubscriptionManager.getSubId(phoneId); |
| 797 | if (subIds != null && subIds.length > 0) { |
| 798 | logd("Broadcast CARRIER_CONFIG_CHANGED for phone " + phoneId + ", subId=" + subIds[0]); |
| 799 | } else { |
| 800 | logd("Broadcast CARRIER_CONFIG_CHANGED for phone " + phoneId); |
| 801 | } |
Junda Liu | 03aad76 | 2017-07-21 13:32:17 -0700 | [diff] [blame] | 802 | mHasSentConfigChange[phoneId] = true; |
Sarah Chin | 807d5c6 | 2020-03-30 17:21:09 -0700 | [diff] [blame] | 803 | mFromSystemUnlocked[phoneId] = false; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | /** Binds to the default or carrier config app. */ |
| 807 | private boolean bindToConfigPackage(String pkgName, int phoneId, int eventId) { |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 808 | logdWithLocalLog("Binding to " + pkgName + " for phone " + phoneId); |
Zach Johnson | fca8a8d | 2015-06-19 18:21:37 -0700 | [diff] [blame] | 809 | Intent carrierService = new Intent(CarrierService.CARRIER_SERVICE_INTERFACE); |
Zach Johnson | 36d7aab | 2015-05-22 15:43:00 -0700 | [diff] [blame] | 810 | carrierService.setPackage(pkgName); |
Jayachandran C | 645ec61 | 2020-01-10 10:30:25 -0800 | [diff] [blame] | 811 | CarrierServiceConnection serviceConnection = new CarrierServiceConnection( |
| 812 | phoneId, pkgName, eventId); |
| 813 | if (eventId == EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG) { |
| 814 | mServiceConnectionForNoSimConfig[phoneId] = serviceConnection; |
| 815 | } else { |
| 816 | mServiceConnection[phoneId] = serviceConnection; |
| 817 | } |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 818 | try { |
Jayachandran C | 645ec61 | 2020-01-10 10:30:25 -0800 | [diff] [blame] | 819 | if (mContext.bindService(carrierService, serviceConnection, |
Jordan Liu | 178430d | 2020-02-10 14:32:15 -0800 | [diff] [blame] | 820 | Context.BIND_AUTO_CREATE)) { |
Jayachandran C | 645ec61 | 2020-01-10 10:30:25 -0800 | [diff] [blame] | 821 | if (eventId == EVENT_CONNECTED_TO_DEFAULT_FOR_NO_SIM_CONFIG) { |
| 822 | mServiceBoundForNoSimConfig[phoneId] = true; |
| 823 | } else { |
| 824 | mServiceBound[phoneId] = true; |
| 825 | } |
Jordan Liu | 178430d | 2020-02-10 14:32:15 -0800 | [diff] [blame] | 826 | return true; |
| 827 | } else { |
| 828 | return false; |
| 829 | } |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 830 | } catch (SecurityException ex) { |
| 831 | return false; |
| 832 | } |
| 833 | } |
| 834 | |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 835 | private CarrierIdentifier getCarrierIdentifierForPhoneId(int phoneId) { |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 836 | String mcc = ""; |
| 837 | String mnc = ""; |
| 838 | String imsi = ""; |
| 839 | String gid1 = ""; |
| 840 | String gid2 = ""; |
| 841 | String spn = TelephonyManager.from(mContext).getSimOperatorNameForPhone(phoneId); |
| 842 | String simOperator = TelephonyManager.from(mContext).getSimOperatorNumericForPhone(phoneId); |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 843 | int carrierId = TelephonyManager.UNKNOWN_CARRIER_ID; |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 844 | int specificCarrierId = TelephonyManager.UNKNOWN_CARRIER_ID; |
Jonathan Basseri | 1fa437c | 2015-04-20 11:08:18 -0700 | [diff] [blame] | 845 | // A valid simOperator should be 5 or 6 digits, depending on the length of the MNC. |
| 846 | if (simOperator != null && simOperator.length() >= 3) { |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 847 | mcc = simOperator.substring(0, 3); |
| 848 | mnc = simOperator.substring(3); |
| 849 | } |
| 850 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 851 | if (phone != null) { |
| 852 | imsi = phone.getSubscriberId(); |
| 853 | gid1 = phone.getGroupIdLevel1(); |
Junda Liu | 7318353 | 2015-05-14 13:55:40 -0700 | [diff] [blame] | 854 | gid2 = phone.getGroupIdLevel2(); |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 855 | carrierId = phone.getCarrierId(); |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 856 | specificCarrierId = phone.getSpecificCarrierId(); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 857 | } |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 858 | return new CarrierIdentifier(mcc, mnc, spn, imsi, gid1, gid2, carrierId, specificCarrierId); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 859 | } |
| 860 | |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 861 | /** Returns the package name of a priveleged carrier app, or null if there is none. */ |
Nathan Harold | 1122e3d | 2021-01-22 15:45:24 -0800 | [diff] [blame^] | 862 | @Nullable |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 863 | private String getCarrierPackageForPhoneId(int phoneId) { |
| 864 | List<String> carrierPackageNames = TelephonyManager.from(mContext) |
| 865 | .getCarrierPackageNamesForIntentAndPhone( |
Zach Johnson | fca8a8d | 2015-06-19 18:21:37 -0700 | [diff] [blame] | 866 | new Intent(CarrierService.CARRIER_SERVICE_INTERFACE), phoneId); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 867 | if (carrierPackageNames != null && carrierPackageNames.size() > 0) { |
| 868 | return carrierPackageNames.get(0); |
| 869 | } else { |
| 870 | return null; |
| 871 | } |
| 872 | } |
| 873 | |
| 874 | private String getIccIdForPhoneId(int phoneId) { |
| 875 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 876 | return null; |
| 877 | } |
| 878 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 879 | if (phone == null) { |
| 880 | return null; |
| 881 | } |
| 882 | return phone.getIccSerialNumber(); |
| 883 | } |
| 884 | |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 885 | /** |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 886 | * Get the sim specific carrier id {@link TelephonyManager#getSimSpecificCarrierId()} |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 887 | */ |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 888 | private int getSpecificCarrierIdForPhoneId(int phoneId) { |
Naina Nalluri | 86fc7b0 | 2018-08-03 10:38:30 -0700 | [diff] [blame] | 889 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 890 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
Naina Nalluri | 86fc7b0 | 2018-08-03 10:38:30 -0700 | [diff] [blame] | 891 | } |
| 892 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 893 | if (phone == null) { |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 894 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
Naina Nalluri | 86fc7b0 | 2018-08-03 10:38:30 -0700 | [diff] [blame] | 895 | } |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 896 | return phone.getSpecificCarrierId(); |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | /** |
| 900 | * Get the sim carrier id {@link TelephonyManager#getSimCarrierId() } |
| 901 | */ |
| 902 | private int getCarrierIdForPhoneId(int phoneId) { |
| 903 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 904 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
Naina Nalluri | 86fc7b0 | 2018-08-03 10:38:30 -0700 | [diff] [blame] | 905 | } |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 906 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 907 | if (phone == null) { |
| 908 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 909 | } |
| 910 | return phone.getCarrierId(); |
Naina Nalluri | 86fc7b0 | 2018-08-03 10:38:30 -0700 | [diff] [blame] | 911 | } |
| 912 | |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 913 | /** |
| 914 | * Writes a bundle to an XML file. |
| 915 | * |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 916 | * The bundle will be written to a file named after the package name, ICCID and |
chen xu | a31f22b | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 917 | * specific carrier id {@link TelephonyManager#getSimSpecificCarrierId()}. the same carrier |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 918 | * should have a single copy of XML file named after carrier id. However, it's still possible |
| 919 | * that platform doesn't recognize the current sim carrier, we will use iccid + carrierid as |
| 920 | * the canonical file name. carrierid can also handle the cases SIM OTA resolves to different |
| 921 | * carrier while iccid remains the same. |
| 922 | * |
| 923 | * The file can be restored later with {@link @restoreConfigFromXml}. The XML output will |
| 924 | * include the bundle and the current version of the specified package. |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 925 | * |
| 926 | * In case of errors or invalid input, no file will be written. |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 927 | * |
Jayachandran C | 645ec61 | 2020-01-10 10:30:25 -0800 | [diff] [blame] | 928 | * @param packageName the name of the package from which we fetched this bundle. |
| 929 | * @param extraString An extra string to be used in the XML file name. |
| 930 | * @param phoneId the phone ID. |
| 931 | * @param carrierId contains all carrier-identifying information. |
| 932 | * @param config the bundle to be written. Null will be treated as an empty bundle. |
| 933 | * @param isNoSimConfig whether this is invoked for noSimConfig or not. |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 934 | */ |
Torbjorn Eklund | 723527a | 2019-02-13 11:16:25 +0100 | [diff] [blame] | 935 | private void saveConfigToXml(String packageName, @NonNull String extraString, int phoneId, |
Jayachandran C | 645ec61 | 2020-01-10 10:30:25 -0800 | [diff] [blame] | 936 | CarrierIdentifier carrierId, PersistableBundle config, boolean isNoSimConfig) { |
| 937 | if (packageName == null) { |
| 938 | loge("Cannot save config with null packageName"); |
Yuchen Dong | c15afed | 2018-04-26 17:05:22 +0800 | [diff] [blame] | 939 | return; |
| 940 | } |
| 941 | |
Jayachandran C | 645ec61 | 2020-01-10 10:30:25 -0800 | [diff] [blame] | 942 | String fileName; |
| 943 | if (isNoSimConfig) { |
| 944 | fileName = getFilenameForNoSimConfig(packageName); |
| 945 | } else { |
| 946 | if (SubscriptionManager.getSimStateForSlotIndex(phoneId) |
| 947 | != TelephonyManager.SIM_STATE_LOADED) { |
| 948 | loge("Skip save config because SIM records are not loaded."); |
| 949 | return; |
| 950 | } |
| 951 | |
| 952 | final String iccid = getIccIdForPhoneId(phoneId); |
| 953 | final int cid = carrierId.getSpecificCarrierId(); |
| 954 | if (iccid == null) { |
| 955 | loge("Cannot save config with null iccid."); |
| 956 | return; |
| 957 | } |
| 958 | fileName = getFilenameForConfig(packageName, extraString, iccid, cid); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 959 | } |
Jayachandran C | 645ec61 | 2020-01-10 10:30:25 -0800 | [diff] [blame] | 960 | |
Junda Liu | 0259650 | 2016-11-15 13:46:43 -0800 | [diff] [blame] | 961 | // b/32668103 Only save to file if config isn't empty. |
| 962 | // In case of failure, not caching an empty bundle will |
| 963 | // try loading config again on next power on or sim loaded. |
| 964 | // Downside is for genuinely empty bundle, will bind and load |
| 965 | // on every power on. |
| 966 | if (config == null || config.isEmpty()) { |
| 967 | return; |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 968 | } |
| 969 | |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 970 | final String version = getPackageVersion(packageName); |
| 971 | if (version == null) { |
| 972 | loge("Failed to get package version for: " + packageName); |
| 973 | return; |
| 974 | } |
| 975 | |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 976 | logdWithLocalLog( |
| 977 | "Save config to xml, packagename: " + packageName + " phoneId: " + phoneId); |
chen xu | db04c29 | 2019-03-26 17:01:15 -0700 | [diff] [blame] | 978 | |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 979 | FileOutputStream outFile = null; |
| 980 | try { |
Jayachandran C | 645ec61 | 2020-01-10 10:30:25 -0800 | [diff] [blame] | 981 | outFile = new FileOutputStream(new File(mContext.getFilesDir(), fileName)); |
Meng Wang | 0f6b2ea | 2020-01-06 18:31:16 -0800 | [diff] [blame] | 982 | config.putString(KEY_VERSION, version); |
| 983 | config.writeToStream(outFile); |
| 984 | outFile.flush(); |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 985 | outFile.close(); |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 986 | } catch (IOException e) { |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 987 | loge(e.toString()); |
| 988 | } |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 989 | } |
| 990 | |
Jayachandran C | 645ec61 | 2020-01-10 10:30:25 -0800 | [diff] [blame] | 991 | private void saveConfigToXml(String packageName, @NonNull String extraString, int phoneId, |
| 992 | CarrierIdentifier carrierId, PersistableBundle config) { |
| 993 | saveConfigToXml(packageName, extraString, phoneId, carrierId, config, false); |
| 994 | } |
| 995 | |
| 996 | private void saveNoSimConfigToXml(String packageName, PersistableBundle config) { |
| 997 | saveConfigToXml(packageName, "", -1, null, config, true); |
| 998 | } |
| 999 | |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 1000 | /** |
| 1001 | * Reads a bundle from an XML file. |
| 1002 | * |
| 1003 | * This restores a bundle that was written with {@link #saveConfigToXml}. This returns the saved |
Yuchen Dong | c15afed | 2018-04-26 17:05:22 +0800 | [diff] [blame] | 1004 | * config bundle for the given package and phone ID. |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 1005 | * |
| 1006 | * In case of errors, or if the saved config is from a different package version than the |
| 1007 | * current version, then null will be returned. |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 1008 | * |
Jayachandran C | 645ec61 | 2020-01-10 10:30:25 -0800 | [diff] [blame] | 1009 | * @param packageName the name of the package from which we fetched this bundle. |
| 1010 | * @param extraString An extra string to be used in the XML file name. |
| 1011 | * @param phoneId the phone ID. |
| 1012 | * @param isNoSimConfig whether this is invoked for noSimConfig or not. |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 1013 | * @return the bundle from the XML file. Returns null if there is no saved config, the saved |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 1014 | * version does not match, or reading config fails. |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 1015 | */ |
Torbjorn Eklund | 723527a | 2019-02-13 11:16:25 +0100 | [diff] [blame] | 1016 | private PersistableBundle restoreConfigFromXml(String packageName, @NonNull String extraString, |
Jayachandran C | 645ec61 | 2020-01-10 10:30:25 -0800 | [diff] [blame] | 1017 | int phoneId, boolean isNoSimConfig) { |
| 1018 | if (packageName == null) { |
| 1019 | loge("Cannot restore config with null packageName"); |
| 1020 | } |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 1021 | final String version = getPackageVersion(packageName); |
| 1022 | if (version == null) { |
| 1023 | loge("Failed to get package version for: " + packageName); |
| 1024 | return null; |
| 1025 | } |
Yuchen Dong | c15afed | 2018-04-26 17:05:22 +0800 | [diff] [blame] | 1026 | |
Jayachandran C | 645ec61 | 2020-01-10 10:30:25 -0800 | [diff] [blame] | 1027 | String fileName; |
| 1028 | if (isNoSimConfig) { |
| 1029 | fileName = getFilenameForNoSimConfig(packageName); |
| 1030 | } else { |
| 1031 | if (SubscriptionManager.getSimStateForSlotIndex(phoneId) |
| 1032 | != TelephonyManager.SIM_STATE_LOADED) { |
| 1033 | loge("Skip restore config because SIM records are not loaded."); |
| 1034 | return null; |
| 1035 | } |
| 1036 | |
| 1037 | final String iccid = getIccIdForPhoneId(phoneId); |
| 1038 | final int cid = getSpecificCarrierIdForPhoneId(phoneId); |
| 1039 | if (iccid == null) { |
| 1040 | loge("Cannot restore config with null iccid."); |
| 1041 | return null; |
| 1042 | } |
| 1043 | fileName = getFilenameForConfig(packageName, extraString, iccid, cid); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 1044 | } |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 1045 | |
| 1046 | PersistableBundle restoredBundle = null; |
Torbjorn Eklund | 723527a | 2019-02-13 11:16:25 +0100 | [diff] [blame] | 1047 | File file = null; |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 1048 | FileInputStream inFile = null; |
| 1049 | try { |
Jayachandran C | 645ec61 | 2020-01-10 10:30:25 -0800 | [diff] [blame] | 1050 | file = new File(mContext.getFilesDir(),fileName); |
Torbjorn Eklund | 723527a | 2019-02-13 11:16:25 +0100 | [diff] [blame] | 1051 | inFile = new FileInputStream(file); |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 1052 | |
Meng Wang | 0f6b2ea | 2020-01-06 18:31:16 -0800 | [diff] [blame] | 1053 | restoredBundle = PersistableBundle.readFromStream(inFile); |
| 1054 | String savedVersion = restoredBundle.getString(KEY_VERSION); |
| 1055 | restoredBundle.remove(KEY_VERSION); |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 1056 | |
Meng Wang | 0f6b2ea | 2020-01-06 18:31:16 -0800 | [diff] [blame] | 1057 | if (!version.equals(savedVersion)) { |
| 1058 | loge("Saved version mismatch: " + version + " vs " + savedVersion); |
| 1059 | restoredBundle = null; |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 1060 | } |
Meng Wang | 0f6b2ea | 2020-01-06 18:31:16 -0800 | [diff] [blame] | 1061 | |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 1062 | inFile.close(); |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 1063 | } catch (FileNotFoundException e) { |
Torbjorn Eklund | 723527a | 2019-02-13 11:16:25 +0100 | [diff] [blame] | 1064 | // Missing file is normal occurrence that might occur with a new sim or when restoring |
| 1065 | // an override file during boot and should not be treated as an error. |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 1066 | if (file != null) logd("File not found: " + file.getPath()); |
| 1067 | } catch (IOException e) { |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 1068 | loge(e.toString()); |
| 1069 | } |
| 1070 | |
| 1071 | return restoredBundle; |
| 1072 | } |
| 1073 | |
Jayachandran C | 645ec61 | 2020-01-10 10:30:25 -0800 | [diff] [blame] | 1074 | private PersistableBundle restoreConfigFromXml(String packageName, @NonNull String extraString, |
| 1075 | int phoneId) { |
| 1076 | return restoreConfigFromXml(packageName, extraString, phoneId, false); |
| 1077 | } |
| 1078 | |
| 1079 | private PersistableBundle restoreNoSimConfigFromXml(String packageName) { |
| 1080 | return restoreConfigFromXml(packageName, "", -1, true); |
| 1081 | } |
| 1082 | |
Junda Liu | 8a8a53a | 2015-05-15 16:19:57 -0700 | [diff] [blame] | 1083 | /** |
Jonathan Basseri | 7697cae | 2015-07-06 15:49:23 -0700 | [diff] [blame] | 1084 | * Clears cached carrier config. |
| 1085 | * This deletes all saved XML files associated with the given package name. If packageName is |
| 1086 | * null, then it deletes all saved XML files. |
| 1087 | * |
| 1088 | * @param packageName the name of a carrier package, or null if all cached config should be |
| 1089 | * cleared. |
| 1090 | * @return true iff one or more files were deleted. |
Junda Liu | 8a8a53a | 2015-05-15 16:19:57 -0700 | [diff] [blame] | 1091 | */ |
Jonathan Basseri | 7697cae | 2015-07-06 15:49:23 -0700 | [diff] [blame] | 1092 | private boolean clearCachedConfigForPackage(final String packageName) { |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 1093 | File dir = mContext.getFilesDir(); |
| 1094 | File[] packageFiles = dir.listFiles(new FilenameFilter() { |
| 1095 | public boolean accept(File dir, String filename) { |
Jonathan Basseri | 7697cae | 2015-07-06 15:49:23 -0700 | [diff] [blame] | 1096 | if (packageName != null) { |
| 1097 | return filename.startsWith("carrierconfig-" + packageName + "-"); |
| 1098 | } else { |
| 1099 | return filename.startsWith("carrierconfig-"); |
| 1100 | } |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 1101 | } |
| 1102 | }); |
Junda Liu | 8a8a53a | 2015-05-15 16:19:57 -0700 | [diff] [blame] | 1103 | if (packageFiles == null || packageFiles.length < 1) return false; |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 1104 | for (File f : packageFiles) { |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 1105 | logd("Deleting " + f.getName()); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 1106 | f.delete(); |
| 1107 | } |
Junda Liu | 8a8a53a | 2015-05-15 16:19:57 -0700 | [diff] [blame] | 1108 | return true; |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 1109 | } |
| 1110 | |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 1111 | /** Builds a canonical file name for a config file. */ |
Jayachandran C | 645ec61 | 2020-01-10 10:30:25 -0800 | [diff] [blame] | 1112 | private static String getFilenameForConfig( |
| 1113 | @NonNull String packageName, @NonNull String extraString, |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 1114 | @NonNull String iccid, int cid) { |
chen xu | 0258169 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 1115 | // the same carrier should have a single copy of XML file named after carrier id. |
| 1116 | // However, it's still possible that platform doesn't recognize the current sim carrier, |
| 1117 | // we will use iccid + carrierid as the canonical file name. carrierid can also handle the |
| 1118 | // cases SIM OTA resolves to different carrier while iccid remains the same. |
Torbjorn Eklund | 723527a | 2019-02-13 11:16:25 +0100 | [diff] [blame] | 1119 | return "carrierconfig-" + packageName + extraString + "-" + iccid + "-" + cid + ".xml"; |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 1120 | } |
| 1121 | |
Jayachandran C | 645ec61 | 2020-01-10 10:30:25 -0800 | [diff] [blame] | 1122 | /** Builds a canonical file name for no SIM config file. */ |
| 1123 | private String getFilenameForNoSimConfig(@NonNull String packageName) { |
| 1124 | return "carrierconfig-" + packageName + "-" + "nosim" + ".xml"; |
| 1125 | } |
| 1126 | |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 1127 | /** Return the current version code of a package, or null if the name is not found. */ |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 1128 | private String getPackageVersion(String packageName) { |
| 1129 | try { |
| 1130 | PackageInfo info = mContext.getPackageManager().getPackageInfo(packageName, 0); |
Dianne Hackborn | b76ab20 | 2017-11-28 17:44:50 -0800 | [diff] [blame] | 1131 | return Long.toString(info.getLongVersionCode()); |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 1132 | } catch (PackageManager.NameNotFoundException e) { |
| 1133 | return null; |
| 1134 | } |
| 1135 | } |
| 1136 | |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 1137 | /** |
| 1138 | * Read up to date config. |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 1139 | * |
| 1140 | * This reads config bundles for the given phoneId. That means getting the latest bundle from |
| 1141 | * the default app and a privileged carrier app, if present. This will not bind to an app if we |
| 1142 | * have a saved config file to use instead. |
| 1143 | */ |
| 1144 | private void updateConfigForPhoneId(int phoneId) { |
Junda Liu | 8a8a53a | 2015-05-15 16:19:57 -0700 | [diff] [blame] | 1145 | // Clear in-memory cache for carrier app config, so when carrier app gets uninstalled, no |
| 1146 | // stale config is left. |
| 1147 | if (mConfigFromCarrierApp[phoneId] != null && |
| 1148 | getCarrierPackageForPhoneId(phoneId) == null) { |
| 1149 | mConfigFromCarrierApp[phoneId] = null; |
| 1150 | } |
Jonathan Basseri | 65273c8 | 2017-07-25 15:08:42 -0700 | [diff] [blame] | 1151 | mHandler.sendMessage(mHandler.obtainMessage(EVENT_DO_FETCH_DEFAULT, phoneId, -1)); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 1152 | } |
| 1153 | |
Malcolm Chen | 5ea1853 | 2019-10-24 19:55:44 -0700 | [diff] [blame] | 1154 | private void onMultiSimConfigChanged() { |
| 1155 | for (int i = TelephonyManager.from(mContext).getActiveModemCount(); |
| 1156 | i < mConfigFromDefaultApp.length; i++) { |
| 1157 | clearConfigForPhone(i, false); |
| 1158 | } |
| 1159 | } |
| 1160 | |
Hall Liu | 506724b | 2018-10-22 18:16:14 -0700 | [diff] [blame] | 1161 | @Override |
Hunter Knepshield | d0ed621 | 2020-01-28 17:43:16 -0800 | [diff] [blame] | 1162 | @NonNull |
| 1163 | public PersistableBundle getConfigForSubId(int subId, String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1164 | return getConfigForSubIdWithFeature(subId, callingPackage, null); |
| 1165 | } |
| 1166 | |
| 1167 | @Override |
Hunter Knepshield | d0ed621 | 2020-01-28 17:43:16 -0800 | [diff] [blame] | 1168 | @NonNull |
| 1169 | public PersistableBundle getConfigForSubIdWithFeature(int subId, String callingPackage, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1170 | String callingFeatureId) { |
| 1171 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mContext, subId, callingPackage, |
| 1172 | callingFeatureId, "getCarrierConfig")) { |
Malcolm Chen | 6d3d6b3 | 2018-03-01 13:58:03 -0800 | [diff] [blame] | 1173 | return new PersistableBundle(); |
Amit Mahajan | 40b3fa5 | 2015-07-14 10:27:19 -0700 | [diff] [blame] | 1174 | } |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 1175 | |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 1176 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Jonathan Basseri | c31f1f3 | 2015-05-12 10:13:03 -0700 | [diff] [blame] | 1177 | PersistableBundle retConfig = CarrierConfigManager.getDefaultConfig(); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 1178 | if (SubscriptionManager.isValidPhoneId(phoneId)) { |
Jonathan Basseri | c31f1f3 | 2015-05-12 10:13:03 -0700 | [diff] [blame] | 1179 | PersistableBundle config = mConfigFromDefaultApp[phoneId]; |
yinxu | c5e2762 | 2017-11-29 15:08:50 -0800 | [diff] [blame] | 1180 | if (config != null) { |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 1181 | retConfig.putAll(config); |
yinxu | c5e2762 | 2017-11-29 15:08:50 -0800 | [diff] [blame] | 1182 | } |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 1183 | config = mConfigFromCarrierApp[phoneId]; |
yinxu | c5e2762 | 2017-11-29 15:08:50 -0800 | [diff] [blame] | 1184 | if (config != null) { |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 1185 | retConfig.putAll(config); |
yinxu | c5e2762 | 2017-11-29 15:08:50 -0800 | [diff] [blame] | 1186 | } |
Torbjorn Eklund | 723527a | 2019-02-13 11:16:25 +0100 | [diff] [blame] | 1187 | config = mPersistentOverrideConfigs[phoneId]; |
| 1188 | if (config != null) { |
| 1189 | retConfig.putAll(config); |
Torbjorn Eklund | 723527a | 2019-02-13 11:16:25 +0100 | [diff] [blame] | 1190 | } |
Hall Liu | 506724b | 2018-10-22 18:16:14 -0700 | [diff] [blame] | 1191 | config = mOverrideConfigs[phoneId]; |
| 1192 | if (config != null) { |
| 1193 | retConfig.putAll(config); |
Hall Liu | 506724b | 2018-10-22 18:16:14 -0700 | [diff] [blame] | 1194 | } |
Nathan Harold | 1122e3d | 2021-01-22 15:45:24 -0800 | [diff] [blame^] | 1195 | // Ignore the theoretical case of the default app not being present since that won't |
| 1196 | // work in CarrierConfigLoader today. |
| 1197 | final boolean allConfigsApplied = |
| 1198 | (mConfigFromCarrierApp[phoneId] != null |
| 1199 | || getCarrierPackageForPhoneId(phoneId) == null) |
| 1200 | && mConfigFromDefaultApp[phoneId] != null; |
| 1201 | retConfig.putBoolean( |
| 1202 | CarrierConfigManager.KEY_CARRIER_CONFIG_APPLIED_BOOL, allConfigsApplied); |
Jayachandran C | 645ec61 | 2020-01-10 10:30:25 -0800 | [diff] [blame] | 1203 | } else { |
| 1204 | if (mNoSimConfig != null) { |
| 1205 | retConfig.putAll(mNoSimConfig); |
| 1206 | } |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 1207 | } |
| 1208 | return retConfig; |
| 1209 | } |
| 1210 | |
| 1211 | @Override |
Torbjorn Eklund | 723527a | 2019-02-13 11:16:25 +0100 | [diff] [blame] | 1212 | public void overrideConfig(int subscriptionId, @Nullable PersistableBundle overrides, |
| 1213 | boolean persistent) { |
Hall Liu | 506724b | 2018-10-22 18:16:14 -0700 | [diff] [blame] | 1214 | mContext.enforceCallingOrSelfPermission( |
| 1215 | android.Manifest.permission.MODIFY_PHONE_STATE, null); |
Brad Ebinger | f6281ad | 2019-04-25 11:02:04 -0700 | [diff] [blame] | 1216 | //TODO: Also check for SHELL UID to restrict this method to testing only (b/131326259) |
Hall Liu | 506724b | 2018-10-22 18:16:14 -0700 | [diff] [blame] | 1217 | int phoneId = SubscriptionManager.getPhoneId(subscriptionId); |
| 1218 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 1219 | logd("Ignore invalid phoneId: " + phoneId + " for subId: " + subscriptionId); |
Hall Liu | 506724b | 2018-10-22 18:16:14 -0700 | [diff] [blame] | 1220 | return; |
| 1221 | } |
Torbjorn Eklund | 723527a | 2019-02-13 11:16:25 +0100 | [diff] [blame] | 1222 | overrideConfig(mOverrideConfigs, phoneId, overrides); |
Hall Liu | 506724b | 2018-10-22 18:16:14 -0700 | [diff] [blame] | 1223 | |
Torbjorn Eklund | 723527a | 2019-02-13 11:16:25 +0100 | [diff] [blame] | 1224 | if (persistent) { |
| 1225 | overrideConfig(mPersistentOverrideConfigs, phoneId, overrides); |
| 1226 | |
| 1227 | if (overrides != null) { |
| 1228 | final CarrierIdentifier carrierId = getCarrierIdentifierForPhoneId(phoneId); |
| 1229 | saveConfigToXml(mPlatformCarrierConfigPackage, OVERRIDE_PACKAGE_ADDITION, phoneId, |
| 1230 | carrierId, mPersistentOverrideConfigs[phoneId]); |
| 1231 | } else { |
| 1232 | final String iccid = getIccIdForPhoneId(phoneId); |
| 1233 | final int cid = getSpecificCarrierIdForPhoneId(phoneId); |
| 1234 | String fileName = getFilenameForConfig(mPlatformCarrierConfigPackage, |
| 1235 | OVERRIDE_PACKAGE_ADDITION, iccid, cid); |
| 1236 | File fileToDelete = new File(mContext.getFilesDir(), fileName); |
| 1237 | fileToDelete.delete(); |
| 1238 | } |
Hall Liu | 506724b | 2018-10-22 18:16:14 -0700 | [diff] [blame] | 1239 | } |
Brad Ebinger | c9d1fa1 | 2019-04-17 15:21:18 -0700 | [diff] [blame] | 1240 | notifySubscriptionInfoUpdater(phoneId); |
Hall Liu | 506724b | 2018-10-22 18:16:14 -0700 | [diff] [blame] | 1241 | } |
| 1242 | |
Torbjorn Eklund | 723527a | 2019-02-13 11:16:25 +0100 | [diff] [blame] | 1243 | private void overrideConfig(@NonNull PersistableBundle[] currentOverrides, int phoneId, |
| 1244 | @Nullable PersistableBundle overrides) { |
| 1245 | if (overrides == null) { |
| 1246 | currentOverrides[phoneId] = new PersistableBundle(); |
| 1247 | } else if (currentOverrides[phoneId] == null) { |
| 1248 | currentOverrides[phoneId] = overrides; |
| 1249 | } else { |
| 1250 | currentOverrides[phoneId].putAll(overrides); |
| 1251 | } |
| 1252 | } |
| 1253 | |
Hall Liu | 506724b | 2018-10-22 18:16:14 -0700 | [diff] [blame] | 1254 | @Override |
Jonathan Basseri | 8603035 | 2015-06-08 12:27:56 -0700 | [diff] [blame] | 1255 | public void notifyConfigChangedForSubId(int subId) { |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 1256 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 1257 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 1258 | logd("Ignore invalid phoneId: " + phoneId + " for subId: " + subId); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 1259 | return; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 1260 | } |
Jordan Liu | d7d57fe | 2019-04-16 12:29:43 -0700 | [diff] [blame] | 1261 | |
| 1262 | // Requires the calling app to be either a carrier privileged app for this subId or |
Junda Liu | fbd2bcb | 2016-06-15 11:15:42 -0700 | [diff] [blame] | 1263 | // system privileged app with MODIFY_PHONE_STATE permission. |
Jordan Liu | d7d57fe | 2019-04-16 12:29:43 -0700 | [diff] [blame] | 1264 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mContext, subId, |
| 1265 | "Require carrier privileges or MODIFY_PHONE_STATE permission."); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 1266 | |
| 1267 | // This method should block until deleting has completed, so that an error which prevents us |
| 1268 | // from clearing the cache is passed back to the carrier app. With the files successfully |
| 1269 | // deleted, this can return and we will eventually bind to the carrier app. |
Jordan Liu | d7d57fe | 2019-04-16 12:29:43 -0700 | [diff] [blame] | 1270 | String callingPackageName = mContext.getPackageManager().getNameForUid( |
| 1271 | Binder.getCallingUid()); |
Jonathan Basseri | 7697cae | 2015-07-06 15:49:23 -0700 | [diff] [blame] | 1272 | clearCachedConfigForPackage(callingPackageName); |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 1273 | updateConfigForPhoneId(phoneId); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | @Override |
| 1277 | public void updateConfigForPhoneId(int phoneId, String simState) { |
Junda Liu | 1f2b34d | 2015-06-18 15:26:56 -0700 | [diff] [blame] | 1278 | mContext.enforceCallingOrSelfPermission( |
| 1279 | android.Manifest.permission.MODIFY_PHONE_STATE, null); |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 1280 | logdWithLocalLog("Update config for phoneId: " + phoneId + " simState: " + simState); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 1281 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 1282 | return; |
| 1283 | } |
| 1284 | // requires Java 7 for switch on string. |
| 1285 | switch (simState) { |
| 1286 | case IccCardConstants.INTENT_VALUE_ICC_ABSENT: |
| 1287 | case IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR: |
Junda Liu | 6f5fddf | 2016-05-24 16:14:41 -0700 | [diff] [blame] | 1288 | case IccCardConstants.INTENT_VALUE_ICC_CARD_RESTRICTED: |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 1289 | case IccCardConstants.INTENT_VALUE_ICC_UNKNOWN: |
Malcolm Chen | db66de1 | 2019-12-09 18:57:07 -0800 | [diff] [blame] | 1290 | case IccCardConstants.INTENT_VALUE_ICC_NOT_READY: |
Junda Liu | 9f2d271 | 2015-05-15 14:22:45 -0700 | [diff] [blame] | 1291 | mHandler.sendMessage(mHandler.obtainMessage(EVENT_CLEAR_CONFIG, phoneId, -1)); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 1292 | break; |
| 1293 | case IccCardConstants.INTENT_VALUE_ICC_LOADED: |
| 1294 | case IccCardConstants.INTENT_VALUE_ICC_LOCKED: |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 1295 | updateConfigForPhoneId(phoneId); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 1296 | break; |
| 1297 | } |
| 1298 | } |
| 1299 | |
Junda Liu | 43d723a | 2015-05-12 17:23:45 -0700 | [diff] [blame] | 1300 | @Override |
Jeff Sharkey | a6fcfed | 2017-07-20 14:18:39 -0600 | [diff] [blame] | 1301 | public String getDefaultCarrierServicePackageName() { |
Shuo Qian | efdb796 | 2019-12-19 15:54:27 -0800 | [diff] [blame] | 1302 | mContext.enforceCallingOrSelfPermission( |
| 1303 | android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 1304 | "getDefaultCarrierServicePackageName"); |
Jeff Sharkey | a6fcfed | 2017-07-20 14:18:39 -0600 | [diff] [blame] | 1305 | return mPlatformCarrierConfigPackage; |
| 1306 | } |
| 1307 | |
Hunter Knepshield | d0ed621 | 2020-01-28 17:43:16 -0800 | [diff] [blame] | 1308 | private void unbindIfBound(Context context, CarrierServiceConnection conn, |
| 1309 | int phoneId) { |
| 1310 | if (mServiceBound[phoneId]) { |
| 1311 | mServiceBound[phoneId] = false; |
| 1312 | context.unbindService(conn); |
| 1313 | } |
| 1314 | } |
| 1315 | |
Jayachandran C | 645ec61 | 2020-01-10 10:30:25 -0800 | [diff] [blame] | 1316 | private void unbindIfBoundForNoSimConfig(Context context, CarrierServiceConnection conn, |
| 1317 | int phoneId) { |
| 1318 | if (mServiceBoundForNoSimConfig[phoneId]) { |
| 1319 | mServiceBoundForNoSimConfig[phoneId] = false; |
| 1320 | context.unbindService(conn); |
| 1321 | } |
| 1322 | } |
| 1323 | |
Hunter Knepshield | d0ed621 | 2020-01-28 17:43:16 -0800 | [diff] [blame] | 1324 | /** |
| 1325 | * If {@code args} contains {@link #DUMP_ARG_REQUESTING_PACKAGE} and a following package name, |
| 1326 | * we'll also call {@link IBinder#dump} on the default carrier service (if bound) and the |
| 1327 | * specified carrier service (if bound). Typically, this is done for connectivity bug reports |
| 1328 | * where we don't call {@code dumpsys activity service all-non-platform} because that contains |
| 1329 | * too much info, but we still want to let carrier apps include their diagnostics. |
| 1330 | */ |
Jeff Sharkey | a6fcfed | 2017-07-20 14:18:39 -0600 | [diff] [blame] | 1331 | @Override |
Junda Liu | 43d723a | 2015-05-12 17:23:45 -0700 | [diff] [blame] | 1332 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 1333 | IndentingPrintWriter indentPW = new IndentingPrintWriter(pw, " "); |
Junda Liu | 43d723a | 2015-05-12 17:23:45 -0700 | [diff] [blame] | 1334 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 1335 | != PackageManager.PERMISSION_GRANTED) { |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 1336 | indentPW.println("Permission Denial: can't dump carrierconfig from from pid=" |
Junda Liu | 43d723a | 2015-05-12 17:23:45 -0700 | [diff] [blame] | 1337 | + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()); |
| 1338 | return; |
| 1339 | } |
Hunter Knepshield | eefb31b | 2020-02-19 15:30:54 -0800 | [diff] [blame] | 1340 | String requestingPackage = null; |
| 1341 | int requestingPackageIndex = ArrayUtils.indexOf(args, DUMP_ARG_REQUESTING_PACKAGE); |
| 1342 | if (requestingPackageIndex >= 0 && requestingPackageIndex < args.length - 1 |
| 1343 | && !TextUtils.isEmpty(args[requestingPackageIndex + 1])) { |
| 1344 | requestingPackage = args[requestingPackageIndex + 1]; |
| 1345 | // Throws a SecurityException if the caller is impersonating another app in an effort to |
| 1346 | // dump extra info (which may contain PII the caller doesn't have a right to). |
| 1347 | enforceCallerIsSystemOrRequestingPackage(requestingPackage); |
| 1348 | } |
| 1349 | |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 1350 | indentPW.println("CarrierConfigLoader: " + this); |
Hunter Knepshield | eefb31b | 2020-02-19 15:30:54 -0800 | [diff] [blame] | 1351 | for (int i = 0; i < TelephonyManager.from(mContext).getActiveModemCount(); i++) { |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 1352 | indentPW.println("Phone Id = " + i); |
shuoq | 26a3a4c | 2016-12-16 11:06:48 -0800 | [diff] [blame] | 1353 | // display default values in CarrierConfigManager |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 1354 | printConfig(CarrierConfigManager.getDefaultConfig(), indentPW, |
shuoq | 26a3a4c | 2016-12-16 11:06:48 -0800 | [diff] [blame] | 1355 | "Default Values from CarrierConfigManager"); |
shuoq | 26a3a4c | 2016-12-16 11:06:48 -0800 | [diff] [blame] | 1356 | // display ConfigFromDefaultApp |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 1357 | printConfig(mConfigFromDefaultApp[i], indentPW, "mConfigFromDefaultApp"); |
shuoq | 26a3a4c | 2016-12-16 11:06:48 -0800 | [diff] [blame] | 1358 | // display ConfigFromCarrierApp |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 1359 | printConfig(mConfigFromCarrierApp[i], indentPW, "mConfigFromCarrierApp"); |
| 1360 | printConfig(mPersistentOverrideConfigs[i], indentPW, "mPersistentOverrideConfigs"); |
| 1361 | printConfig(mOverrideConfigs[i], indentPW, "mOverrideConfigs"); |
shuoq | 26a3a4c | 2016-12-16 11:06:48 -0800 | [diff] [blame] | 1362 | } |
chen xu | db04c29 | 2019-03-26 17:01:15 -0700 | [diff] [blame] | 1363 | |
Jayachandran C | 645ec61 | 2020-01-10 10:30:25 -0800 | [diff] [blame] | 1364 | printConfig(mNoSimConfig, indentPW, "mNoSimConfig"); |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 1365 | indentPW.println("CarrierConfigLoadingLog="); |
| 1366 | mCarrierConfigLoadingLog.dump(fd, indentPW, args); |
Hunter Knepshield | d0ed621 | 2020-01-28 17:43:16 -0800 | [diff] [blame] | 1367 | |
Hunter Knepshield | eefb31b | 2020-02-19 15:30:54 -0800 | [diff] [blame] | 1368 | if (requestingPackage != null) { |
Hunter Knepshield | d0ed621 | 2020-01-28 17:43:16 -0800 | [diff] [blame] | 1369 | logd("Including default and requesting package " + requestingPackage |
| 1370 | + " carrier services in dump"); |
Hunter Knepshield | eefb31b | 2020-02-19 15:30:54 -0800 | [diff] [blame] | 1371 | indentPW.println(""); |
Hunter Knepshield | d0ed621 | 2020-01-28 17:43:16 -0800 | [diff] [blame] | 1372 | indentPW.println("Connected services"); |
| 1373 | dumpCarrierServiceIfBound(fd, indentPW, "Default config package", |
Hunter Knepshield | eefb31b | 2020-02-19 15:30:54 -0800 | [diff] [blame] | 1374 | mPlatformCarrierConfigPackage, false /* considerCarrierPrivileges */); |
| 1375 | dumpCarrierServiceIfBound(fd, indentPW, "Requesting package", requestingPackage, |
| 1376 | true /* considerCarrierPrivileges */); |
Hunter Knepshield | d0ed621 | 2020-01-28 17:43:16 -0800 | [diff] [blame] | 1377 | } |
shuoq | 26a3a4c | 2016-12-16 11:06:48 -0800 | [diff] [blame] | 1378 | } |
| 1379 | |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 1380 | private void printConfig(PersistableBundle configApp, IndentingPrintWriter indentPW, |
| 1381 | String name) { |
| 1382 | indentPW.increaseIndent(); |
shuoq | 26a3a4c | 2016-12-16 11:06:48 -0800 | [diff] [blame] | 1383 | if (configApp == null) { |
shuoq | 26a3a4c | 2016-12-16 11:06:48 -0800 | [diff] [blame] | 1384 | indentPW.println(name + " : null "); |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 1385 | indentPW.decreaseIndent(); |
| 1386 | indentPW.println(""); |
shuoq | 26a3a4c | 2016-12-16 11:06:48 -0800 | [diff] [blame] | 1387 | return; |
| 1388 | } |
shuoq | 26a3a4c | 2016-12-16 11:06:48 -0800 | [diff] [blame] | 1389 | indentPW.println(name + " : "); |
| 1390 | List<String> sortedKeys = new ArrayList<String>(configApp.keySet()); |
| 1391 | Collections.sort(sortedKeys); |
| 1392 | indentPW.increaseIndent(); |
| 1393 | indentPW.increaseIndent(); |
| 1394 | for (String key : sortedKeys) { |
| 1395 | if (configApp.get(key) != null && configApp.get(key) instanceof Object[]) { |
| 1396 | indentPW.println(key + " = " + |
| 1397 | Arrays.toString((Object[]) configApp.get(key))); |
| 1398 | } else if (configApp.get(key) != null && configApp.get(key) instanceof int[]) { |
| 1399 | indentPW.println(key + " = " + Arrays.toString((int[]) configApp.get(key))); |
| 1400 | } else { |
| 1401 | indentPW.println(key + " = " + configApp.get(key)); |
| 1402 | } |
Junda Liu | 43d723a | 2015-05-12 17:23:45 -0700 | [diff] [blame] | 1403 | } |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 1404 | indentPW.decreaseIndent(); |
| 1405 | indentPW.decreaseIndent(); |
| 1406 | indentPW.decreaseIndent(); |
| 1407 | indentPW.println(""); |
Junda Liu | 43d723a | 2015-05-12 17:23:45 -0700 | [diff] [blame] | 1408 | } |
| 1409 | |
Hunter Knepshield | e601f43 | 2020-02-19 10:16:04 -0800 | [diff] [blame] | 1410 | /** |
| 1411 | * Passes without problem when one of these conditions is true: |
| 1412 | * - The caller is a privileged UID (e.g. for dumpstate.cpp generating a bug report, where the |
| 1413 | * system knows the true caller plumbed in through the {@link android.os.BugreportManager} API). |
| 1414 | * - The caller's UID matches the supplied package. |
| 1415 | * |
| 1416 | * @throws SecurityException if none of the above conditions are met. |
| 1417 | */ |
| 1418 | private void enforceCallerIsSystemOrRequestingPackage(String requestingPackage) |
| 1419 | throws SecurityException { |
| 1420 | final int callingUid = Binder.getCallingUid(); |
| 1421 | if (callingUid == Process.ROOT_UID || callingUid == Process.SYSTEM_UID |
| 1422 | || callingUid == Process.SHELL_UID || callingUid == Process.PHONE_UID) { |
| 1423 | // Bug reports (dumpstate.cpp) run as SHELL, and let some other privileged UIDs through |
| 1424 | // as well. |
| 1425 | return; |
| 1426 | } |
| 1427 | // An app is trying to dump extra detail, block it if they aren't who they claim to be. |
| 1428 | AppOpsManager appOps = mContext.getSystemService(AppOpsManager.class); |
| 1429 | if (appOps == null) { |
| 1430 | throw new SecurityException("No AppOps"); |
| 1431 | } |
| 1432 | // Will throw a SecurityException if the UID and package don't match. |
| 1433 | appOps.checkPackage(callingUid, requestingPackage); |
| 1434 | } |
| 1435 | |
Hunter Knepshield | eefb31b | 2020-02-19 15:30:54 -0800 | [diff] [blame] | 1436 | /** |
| 1437 | * Searches for one or more appropriate {@link CarrierService} instances to dump based on the |
| 1438 | * current connections. |
| 1439 | * |
| 1440 | * @param targetPkgName the target package name to dump carrier services for |
| 1441 | * @param considerCarrierPrivileges if true, allow a carrier service to be dumped if it shares |
| 1442 | * carrier privileges with {@code targetPkgName}; |
| 1443 | * otherwise, only dump a carrier service if it is {@code |
| 1444 | * targetPkgName} |
| 1445 | */ |
Hunter Knepshield | d0ed621 | 2020-01-28 17:43:16 -0800 | [diff] [blame] | 1446 | private void dumpCarrierServiceIfBound(FileDescriptor fd, IndentingPrintWriter indentPW, |
Hunter Knepshield | eefb31b | 2020-02-19 15:30:54 -0800 | [diff] [blame] | 1447 | String prefix, String targetPkgName, boolean considerCarrierPrivileges) { |
Hunter Knepshield | d0ed621 | 2020-01-28 17:43:16 -0800 | [diff] [blame] | 1448 | // Null package is possible if it's early in the boot process, there was a recent crash, we |
| 1449 | // loaded the config from XML most recently, or a SIM slot is empty. Carrier apps with |
| 1450 | // long-lived bindings should typically get dumped here regardless. Even if an app is being |
| 1451 | // used for multiple phoneIds, we assume that it's smart enough to handle that on its own, |
| 1452 | // and that in most cases we'd just be dumping duplicate information and bloating a report. |
| 1453 | indentPW.increaseIndent(); |
Hunter Knepshield | eefb31b | 2020-02-19 15:30:54 -0800 | [diff] [blame] | 1454 | indentPW.println(prefix + " : " + targetPkgName); |
| 1455 | Set<String> dumpedPkgNames = new ArraySet<>(mServiceConnection.length); |
Hunter Knepshield | d0ed621 | 2020-01-28 17:43:16 -0800 | [diff] [blame] | 1456 | for (CarrierServiceConnection connection : mServiceConnection) { |
Hunter Knepshield | eefb31b | 2020-02-19 15:30:54 -0800 | [diff] [blame] | 1457 | if (connection == null || !SubscriptionManager.isValidPhoneId(connection.phoneId) |
| 1458 | || TextUtils.isEmpty(connection.pkgName)) { |
| 1459 | continue; |
Hunter Knepshield | d0ed621 | 2020-01-28 17:43:16 -0800 | [diff] [blame] | 1460 | } |
Hunter Knepshield | eefb31b | 2020-02-19 15:30:54 -0800 | [diff] [blame] | 1461 | final String servicePkgName = connection.pkgName; |
| 1462 | // Note: we intentionally ignore system components here because we should NOT match the |
| 1463 | // shell caller that's typically used for bug reports via non-BugreportManager triggers. |
| 1464 | final boolean exactPackageMatch = TextUtils.equals(targetPkgName, servicePkgName); |
| 1465 | final boolean carrierPrivilegesMatch = |
| 1466 | considerCarrierPrivileges && hasCarrierPrivileges(targetPkgName, |
| 1467 | connection.phoneId); |
| 1468 | if (!exactPackageMatch && !carrierPrivilegesMatch) continue; |
| 1469 | // Make sure this service is actually alive before trying to dump it. We don't pay |
| 1470 | // attention to mServiceBound[connection.phoneId] because typically carrier apps will |
| 1471 | // request long-lived bindings, and even if we unbind the app, it may still be alive due |
| 1472 | // to CarrierServiceBindHelper. Pull it out as a reference so even if it gets set to |
| 1473 | // null within the ServiceConnection during unbinding we can avoid an NPE. |
| 1474 | final IBinder service = connection.service; |
| 1475 | if (service == null || !service.isBinderAlive() || !service.pingBinder()) continue; |
| 1476 | // We've got a live service. Last check is just to make sure we don't dump a package |
| 1477 | // multiple times. |
| 1478 | if (!dumpedPkgNames.add(servicePkgName)) continue; |
| 1479 | if (!exactPackageMatch) { |
| 1480 | logd(targetPkgName + " has carrier privileges on phoneId " + connection.phoneId |
| 1481 | + ", service provided by " + servicePkgName); |
| 1482 | indentPW.increaseIndent(); |
| 1483 | indentPW.println("Proxy : " + servicePkgName); |
| 1484 | indentPW.decreaseIndent(); |
| 1485 | } |
| 1486 | // Flush before we let the app output anything to ensure correct ordering of output. |
| 1487 | // Internally, Binder#dump calls flush on its printer after finishing so we don't |
| 1488 | // need to do anything after. |
| 1489 | indentPW.flush(); |
| 1490 | try { |
| 1491 | logd("Dumping " + servicePkgName); |
| 1492 | // We don't need to give the carrier service any args. |
| 1493 | connection.service.dump(fd, null /* args */); |
| 1494 | logd("Done with " + servicePkgName); |
| 1495 | } catch (RemoteException e) { |
| 1496 | logd("RemoteException from " + servicePkgName, e); |
| 1497 | indentPW.increaseIndent(); |
| 1498 | indentPW.println("RemoteException"); |
| 1499 | indentPW.increaseIndent(); |
| 1500 | e.printStackTrace(indentPW); |
| 1501 | indentPW.decreaseIndent(); |
| 1502 | indentPW.decreaseIndent(); |
| 1503 | // We won't retry this package again because now it's in dumpedPkgNames. |
| 1504 | } |
| 1505 | indentPW.println(""); |
Jordan Liu | 46ed5db | 2020-01-28 08:55:20 -0800 | [diff] [blame] | 1506 | } |
Hunter Knepshield | eefb31b | 2020-02-19 15:30:54 -0800 | [diff] [blame] | 1507 | if (dumpedPkgNames.isEmpty()) { |
| 1508 | indentPW.increaseIndent(); |
| 1509 | indentPW.println("Not bound"); |
| 1510 | indentPW.decreaseIndent(); |
| 1511 | indentPW.println(""); |
| 1512 | } |
Hunter Knepshield | d0ed621 | 2020-01-28 17:43:16 -0800 | [diff] [blame] | 1513 | indentPW.decreaseIndent(); |
Hunter Knepshield | eefb31b | 2020-02-19 15:30:54 -0800 | [diff] [blame] | 1514 | } |
| 1515 | |
| 1516 | private boolean hasCarrierPrivileges(String pkgName, int phoneId) { |
| 1517 | int[] subIds = SubscriptionManager.getSubId(phoneId); |
| 1518 | if (ArrayUtils.isEmpty(subIds)) { |
| 1519 | return false; |
| 1520 | } |
| 1521 | return TelephonyManager.from(mContext).createForSubscriptionId( |
| 1522 | subIds[0]).checkCarrierPrivilegesForPackage(pkgName) |
| 1523 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Jordan Liu | 46ed5db | 2020-01-28 08:55:20 -0800 | [diff] [blame] | 1524 | } |
| 1525 | |
Zach Johnson | 36d7aab | 2015-05-22 15:43:00 -0700 | [diff] [blame] | 1526 | private class CarrierServiceConnection implements ServiceConnection { |
Hunter Knepshield | eefb31b | 2020-02-19 15:30:54 -0800 | [diff] [blame] | 1527 | final int phoneId; |
| 1528 | final String pkgName; |
| 1529 | final int eventId; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 1530 | IBinder service; |
| 1531 | |
Hunter Knepshield | d0ed621 | 2020-01-28 17:43:16 -0800 | [diff] [blame] | 1532 | CarrierServiceConnection(int phoneId, String pkgName, int eventId) { |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 1533 | this.phoneId = phoneId; |
Hunter Knepshield | d0ed621 | 2020-01-28 17:43:16 -0800 | [diff] [blame] | 1534 | this.pkgName = pkgName; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 1535 | this.eventId = eventId; |
| 1536 | } |
| 1537 | |
| 1538 | @Override |
| 1539 | public void onServiceConnected(ComponentName name, IBinder service) { |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 1540 | logd("Connected to config app: " + name.flattenToShortString()); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 1541 | this.service = service; |
| 1542 | mHandler.sendMessage(mHandler.obtainMessage(eventId, phoneId, -1, this)); |
| 1543 | } |
| 1544 | |
| 1545 | @Override |
| 1546 | public void onServiceDisconnected(ComponentName name) { |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 1547 | logd("Disconnected from config app: " + name.flattenToShortString()); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 1548 | this.service = null; |
Jordan Liu | 46ed5db | 2020-01-28 08:55:20 -0800 | [diff] [blame] | 1549 | } |
| 1550 | |
| 1551 | @Override |
| 1552 | public void onBindingDied(ComponentName name) { |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 1553 | logd("Binding died from config app: " + name.flattenToShortString()); |
Jordan Liu | 46ed5db | 2020-01-28 08:55:20 -0800 | [diff] [blame] | 1554 | this.service = null; |
Jordan Liu | 46ed5db | 2020-01-28 08:55:20 -0800 | [diff] [blame] | 1555 | } |
| 1556 | |
| 1557 | @Override |
| 1558 | public void onNullBinding(ComponentName name) { |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 1559 | logd("Null binding from config app: " + name.flattenToShortString()); |
Jordan Liu | 46ed5db | 2020-01-28 08:55:20 -0800 | [diff] [blame] | 1560 | this.service = null; |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 1561 | } |
| 1562 | } |
| 1563 | |
| 1564 | private class ConfigLoaderBroadcastReceiver extends BroadcastReceiver { |
| 1565 | @Override |
| 1566 | public void onReceive(Context context, Intent intent) { |
| 1567 | String action = intent.getAction(); |
Junda Liu | 8a8a53a | 2015-05-15 16:19:57 -0700 | [diff] [blame] | 1568 | boolean replace = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false); |
| 1569 | // If replace is true, only care ACTION_PACKAGE_REPLACED. |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 1570 | if (replace && !Intent.ACTION_PACKAGE_REPLACED.equals(action)) { |
Junda Liu | 8a8a53a | 2015-05-15 16:19:57 -0700 | [diff] [blame] | 1571 | return; |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 1572 | } |
Junda Liu | 8a8a53a | 2015-05-15 16:19:57 -0700 | [diff] [blame] | 1573 | |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 1574 | switch (action) { |
Nanxi Chen | 3d67050 | 2016-03-17 16:32:09 -0700 | [diff] [blame] | 1575 | case Intent.ACTION_BOOT_COMPLETED: |
| 1576 | mHandler.sendMessage(mHandler.obtainMessage(EVENT_SYSTEM_UNLOCKED, null)); |
| 1577 | break; |
| 1578 | |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 1579 | case Intent.ACTION_PACKAGE_ADDED: |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 1580 | case Intent.ACTION_PACKAGE_REMOVED: |
Junda Liu | 8a8a53a | 2015-05-15 16:19:57 -0700 | [diff] [blame] | 1581 | case Intent.ACTION_PACKAGE_REPLACED: |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 1582 | int uid = intent.getIntExtra(Intent.EXTRA_UID, -1); |
| 1583 | String packageName = mContext.getPackageManager().getNameForUid(uid); |
Junda Liu | 8a8a53a | 2015-05-15 16:19:57 -0700 | [diff] [blame] | 1584 | if (packageName != null) { |
| 1585 | // We don't have a phoneId for arg1. |
| 1586 | mHandler.sendMessage( |
| 1587 | mHandler.obtainMessage(EVENT_PACKAGE_CHANGED, packageName)); |
| 1588 | } |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 1589 | break; |
Jonathan Basseri | 1f743c9 | 2015-05-15 00:19:46 -0700 | [diff] [blame] | 1590 | } |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 1591 | } |
| 1592 | } |
| 1593 | |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 1594 | private void logd(String msg) { |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 1595 | Log.d(LOG_TAG, msg); |
| 1596 | } |
| 1597 | |
Hunter Knepshield | d0ed621 | 2020-01-28 17:43:16 -0800 | [diff] [blame] | 1598 | private void logd(String msg, Throwable tr) { |
| 1599 | Log.d(LOG_TAG, msg, tr); |
| 1600 | } |
| 1601 | |
Hunter Knepshield | 9f091fc | 2020-01-28 17:41:43 -0800 | [diff] [blame] | 1602 | private void logdWithLocalLog(String msg) { |
chen xu | db04c29 | 2019-03-26 17:01:15 -0700 | [diff] [blame] | 1603 | Log.d(LOG_TAG, msg); |
| 1604 | mCarrierConfigLoadingLog.log(msg); |
| 1605 | } |
| 1606 | |
| 1607 | private void loge(String msg) { |
Jonathan Basseri | 6b50e9f | 2015-05-12 20:18:31 -0700 | [diff] [blame] | 1608 | Log.e(LOG_TAG, msg); |
chen xu | db04c29 | 2019-03-26 17:01:15 -0700 | [diff] [blame] | 1609 | mCarrierConfigLoadingLog.log(msg); |
Jonathan Basseri | 6465afd | 2015-02-25 13:05:57 -0800 | [diff] [blame] | 1610 | } |
| 1611 | } |