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