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