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