Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 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 | |
| 17 | package com.android.phone; |
| 18 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
| 20 | |
Shuo Qian | 479dd9e | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA; |
| 22 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 23 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 24 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 25 | |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 26 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 27 | import android.Manifest.permission; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 28 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 29 | import android.annotation.Nullable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 30 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 31 | import android.app.PendingIntent; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 32 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 33 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 34 | import android.content.Context; |
| 35 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 36 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 37 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 38 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 39 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 40 | import android.net.Uri; |
| 41 | import android.os.AsyncResult; |
| 42 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 43 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 44 | import android.os.Bundle; |
| 45 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 46 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 47 | import android.os.Looper; |
| 48 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 49 | import android.os.Messenger; |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 50 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 51 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 52 | import android.os.PersistableBundle; |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 53 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 54 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 55 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 56 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 57 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 58 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 59 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 60 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 61 | import android.preference.PreferenceManager; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 62 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 63 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 64 | import android.provider.Telephony; |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 65 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 66 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 67 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 68 | import android.telecom.TelecomManager; |
Chen Xu | c7b18ec | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 69 | import android.telephony.Annotation.ApnType; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 70 | import android.telephony.Annotation.ThermalMitigationResult; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 71 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 72 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 73 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 74 | import android.telephony.CellIdentity; |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 75 | import android.telephony.CellIdentityCdma; |
| 76 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 77 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 78 | import android.telephony.CellInfoGsm; |
| 79 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 80 | import android.telephony.ClientRequestStats; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 81 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 82 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 83 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 84 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 85 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 86 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 87 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 88 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 89 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 90 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 91 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 92 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 93 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 94 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 95 | import android.telephony.SignalStrengthUpdateRequest; |
| 96 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 97 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 98 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 99 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 100 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 101 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 102 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 103 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 104 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 105 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 106 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 107 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 108 | import android.telephony.data.ApnSetting; |
| 109 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 110 | import android.telephony.gba.GbaAuthRequest; |
| 111 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 112 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 113 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 114 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | d4c5bde | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 115 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 116 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 117 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 118 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 119 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 120 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 121 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 122 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 123 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 124 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 125 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 126 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 127 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 128 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 129 | import android.util.ArraySet; |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 130 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 131 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 132 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 133 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 134 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 135 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 136 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | 51ee2b1 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 137 | import com.android.internal.annotations.VisibleForTesting; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 138 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 142 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.CommandException; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 145 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | 479dd9e | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 148 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 149 | import com.android.internal.telephony.HalVersion; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 150 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 153 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 155 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 161 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.RIL; |
SongFerngWang | 522637d | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 166 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | fe1e6ac | 2021-03-12 10:25:03 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 171 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 172 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 173 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 175 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 177 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 179 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 180 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 181 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 183 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 184 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 185 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 186 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 187 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 188 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 189 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 190 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 191 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 192 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 193 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 194 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 195 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 196 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 197 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 198 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 199 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 200 | import com.android.services.telephony.TelecomAccountRegistry; |
| 201 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 202 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 203 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 204 | import java.io.FileDescriptor; |
| 205 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 206 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 207 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 208 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 209 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 210 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 211 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 212 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 213 | import java.util.NoSuchElementException; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 214 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 215 | import java.util.Set; |
SongFerngWang | c63cf52 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 216 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 217 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 218 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 219 | |
| 220 | /** |
| 221 | * Implementation of the ITelephony interface. |
| 222 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 223 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 224 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 225 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 226 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 227 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 228 | |
| 229 | // Message codes used with mMainThreadHandler |
| 230 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 231 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 232 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 233 | private static final int CMD_OPEN_CHANNEL = 9; |
| 234 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 235 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 236 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 237 | private static final int CMD_NV_READ_ITEM = 13; |
| 238 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 239 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 240 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 241 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 242 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 243 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 244 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 245 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 246 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 247 | private static final int CMD_SEND_ENVELOPE = 25; |
| 248 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 249 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 250 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 251 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 252 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 253 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 254 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 255 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 256 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 257 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 258 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 259 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 260 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 261 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 262 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 263 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 264 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 265 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 266 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 267 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 268 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 269 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 270 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 271 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 272 | private static final int CMD_SWITCH_SLOTS = 50; |
| 273 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 274 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 275 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 276 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 277 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 278 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 279 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 280 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 281 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 282 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 283 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 284 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 285 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 286 | private static final int CMD_MODEM_REBOOT = 64; |
| 287 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 288 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 289 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 290 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 291 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 292 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 293 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 294 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 295 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 296 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 297 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 298 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 299 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 300 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 301 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 302 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 303 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 304 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 305 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 306 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 307 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 308 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 309 | private static final int CMD_GET_CALL_WAITING = 87; |
| 310 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 311 | private static final int CMD_SET_CALL_WAITING = 89; |
| 312 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 313 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 314 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 315 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 316 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 317 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 318 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 319 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 320 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 321 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 322 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 323 | private static final int CMD_SET_SIM_POWER = 101; |
| 324 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 325 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 326 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 327 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 328 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 329 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 330 | private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 331 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 332 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 333 | // Parameters of select command. |
| 334 | private static final int SELECT_COMMAND = 0xA4; |
| 335 | private static final int SELECT_P1 = 0x04; |
| 336 | private static final int SELECT_P2 = 0; |
| 337 | private static final int SELECT_P3 = 0x10; |
| 338 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 339 | /** The singleton instance. */ |
| 340 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 341 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 342 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 343 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 344 | private CallManager mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 345 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 346 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 347 | private AppOpsManager mAppOps; |
| 348 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 349 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 350 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 351 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | fe1e6ac | 2021-03-12 10:25:03 -0800 | [diff] [blame] | 352 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 353 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 354 | /** User Activity */ |
| 355 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 356 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 357 | |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 358 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 359 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 360 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 361 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 362 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 363 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 364 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 365 | // String to store multi SIM allowed |
| 366 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 367 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 368 | // The AID of ISD-R. |
| 369 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 370 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 371 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 372 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 373 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 374 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 375 | |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 376 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 377 | private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 378 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 379 | /** |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 380 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 381 | */ |
| 382 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 383 | "reset_network_erase_modem_config_enabled"; |
| 384 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 385 | private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds |
| 386 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 387 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 388 | * A request object to use for transmitting data to an ICC. |
| 389 | */ |
| 390 | private static final class IccAPDUArgument { |
| 391 | public int channel, cla, command, p1, p2, p3; |
| 392 | public String data; |
| 393 | |
| 394 | public IccAPDUArgument(int channel, int cla, int command, |
| 395 | int p1, int p2, int p3, String data) { |
| 396 | this.channel = channel; |
| 397 | this.cla = cla; |
| 398 | this.command = command; |
| 399 | this.p1 = p1; |
| 400 | this.p2 = p2; |
| 401 | this.p3 = p3; |
| 402 | this.data = data; |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 407 | * A request object to use for transmitting data to an ICC. |
| 408 | */ |
| 409 | private static final class ManualNetworkSelectionArgument { |
| 410 | public OperatorInfo operatorInfo; |
| 411 | public boolean persistSelection; |
| 412 | |
| 413 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 414 | this.operatorInfo = operatorInfo; |
| 415 | this.persistSelection = persistSelection; |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 420 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 421 | * request after sending. The main thread will notify the request when it is complete. |
| 422 | */ |
| 423 | private static final class MainThreadRequest { |
| 424 | /** The argument to use for the request */ |
| 425 | public Object argument; |
| 426 | /** The result of the request that is run on the main thread */ |
| 427 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 428 | // The subscriber id that this request applies to. Defaults to |
| 429 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 430 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 431 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 432 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 433 | public Phone phone; |
| 434 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 435 | public WorkSource workSource; |
| 436 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 437 | public MainThreadRequest(Object argument) { |
| 438 | this.argument = argument; |
| 439 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 440 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 441 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 442 | this.argument = argument; |
| 443 | if (phone != null) { |
| 444 | this.phone = phone; |
| 445 | } |
| 446 | this.workSource = workSource; |
| 447 | } |
| 448 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 449 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 450 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 451 | if (subId != null) { |
| 452 | this.subId = subId; |
| 453 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 454 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 455 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 456 | } |
| 457 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 458 | private static final class IncomingThirdPartyCallArgs { |
| 459 | public final ComponentName component; |
| 460 | public final String callId; |
| 461 | public final String callerDisplayName; |
| 462 | |
| 463 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 464 | String callerDisplayName) { |
| 465 | this.component = component; |
| 466 | this.callId = callId; |
| 467 | this.callerDisplayName = callerDisplayName; |
| 468 | } |
| 469 | } |
| 470 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 471 | /** |
| 472 | * A handler that processes messages on the main thread in the phone process. Since many |
| 473 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 474 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 475 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 476 | * on, which will be notified when the operation completes and will contain the result of the |
| 477 | * request. |
| 478 | * |
| 479 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 480 | * note that request.result must be set to something non-null for the calling thread to |
| 481 | * unblock. |
| 482 | */ |
| 483 | private final class MainThreadHandler extends Handler { |
| 484 | @Override |
| 485 | public void handleMessage(Message msg) { |
| 486 | MainThreadRequest request; |
| 487 | Message onCompleted; |
| 488 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 489 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 490 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 491 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 492 | |
| 493 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 494 | case CMD_HANDLE_USSD_REQUEST: { |
| 495 | request = (MainThreadRequest) msg.obj; |
| 496 | final Phone phone = getPhoneFromRequest(request); |
| 497 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 498 | String ussdRequest = ussdObject.first; |
| 499 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 500 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 501 | if (!isUssdApiAllowed(request.subId)) { |
| 502 | // Carrier does not support use of this API, return failure. |
| 503 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 504 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 505 | Bundle returnData = new Bundle(); |
| 506 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 507 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 508 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 509 | request.result = true; |
| 510 | notifyRequester(request); |
| 511 | return; |
| 512 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 513 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 514 | try { |
| 515 | request.result = phone != null |
| 516 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 517 | } catch (CallStateException cse) { |
| 518 | request.result = false; |
| 519 | } |
| 520 | // Wake up the requesting thread |
| 521 | notifyRequester(request); |
| 522 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 523 | } |
| 524 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 525 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 526 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 527 | final Phone phone = getPhoneFromRequest(request); |
| 528 | request.result = phone != null ? |
| 529 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 530 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 531 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 532 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 533 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 534 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 535 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 536 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 537 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 538 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 539 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 540 | if (uiccCard == null) { |
| 541 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 542 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 543 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 544 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 545 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 546 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 547 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 548 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 549 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 550 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 551 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 552 | break; |
| 553 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 554 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 555 | ar = (AsyncResult) msg.obj; |
| 556 | request = (MainThreadRequest) ar.userObj; |
| 557 | if (ar.exception == null && ar.result != null) { |
| 558 | request.result = ar.result; |
| 559 | } else { |
| 560 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 561 | if (ar.result == null) { |
| 562 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 563 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 564 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 565 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 566 | } else { |
| 567 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 568 | } |
| 569 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 570 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 571 | break; |
| 572 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 573 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 574 | request = (MainThreadRequest) msg.obj; |
| 575 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 576 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 577 | if (uiccCard == null) { |
| 578 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 579 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 580 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 581 | } else { |
| 582 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 583 | request); |
| 584 | uiccCard.iccTransmitApduBasicChannel( |
| 585 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 586 | iccArgument.p3, iccArgument.data, onCompleted); |
| 587 | } |
| 588 | break; |
| 589 | |
| 590 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 591 | ar = (AsyncResult) msg.obj; |
| 592 | request = (MainThreadRequest) ar.userObj; |
| 593 | if (ar.exception == null && ar.result != null) { |
| 594 | request.result = ar.result; |
| 595 | } else { |
| 596 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 597 | if (ar.result == null) { |
| 598 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 599 | } else if (ar.exception instanceof CommandException) { |
| 600 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 601 | ar.exception); |
| 602 | } else { |
| 603 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 604 | } |
| 605 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 606 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 607 | break; |
| 608 | |
| 609 | case CMD_EXCHANGE_SIM_IO: |
| 610 | request = (MainThreadRequest) msg.obj; |
| 611 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 612 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 613 | if (uiccCard == null) { |
| 614 | loge("iccExchangeSimIO: No UICC"); |
| 615 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 616 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 617 | } else { |
| 618 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 619 | request); |
| 620 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 621 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 622 | iccArgument.data, onCompleted); |
| 623 | } |
| 624 | break; |
| 625 | |
| 626 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 627 | ar = (AsyncResult) msg.obj; |
| 628 | request = (MainThreadRequest) ar.userObj; |
| 629 | if (ar.exception == null && ar.result != null) { |
| 630 | request.result = ar.result; |
| 631 | } else { |
| 632 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 633 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 634 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 635 | break; |
| 636 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 637 | case CMD_SEND_ENVELOPE: |
| 638 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 639 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 640 | if (uiccCard == null) { |
| 641 | loge("sendEnvelopeWithStatus: No UICC"); |
| 642 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 643 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 644 | } else { |
| 645 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 646 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 647 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 648 | break; |
| 649 | |
| 650 | case EVENT_SEND_ENVELOPE_DONE: |
| 651 | ar = (AsyncResult) msg.obj; |
| 652 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 653 | if (ar.exception == null && ar.result != null) { |
| 654 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 655 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 656 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 657 | if (ar.result == null) { |
| 658 | loge("sendEnvelopeWithStatus: Empty response"); |
| 659 | } else if (ar.exception instanceof CommandException) { |
| 660 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 661 | ar.exception); |
| 662 | } else { |
| 663 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 664 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 665 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 666 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 667 | break; |
| 668 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 669 | case CMD_OPEN_CHANNEL: |
| 670 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 671 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 672 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 673 | if (uiccCard == null) { |
| 674 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 675 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 676 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 677 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 678 | } else { |
| 679 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 680 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 681 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 682 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 683 | break; |
| 684 | |
| 685 | case EVENT_OPEN_CHANNEL_DONE: |
| 686 | ar = (AsyncResult) msg.obj; |
| 687 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 688 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 689 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 690 | int[] result = (int[]) ar.result; |
| 691 | int channelId = result[0]; |
| 692 | byte[] selectResponse = null; |
| 693 | if (result.length > 1) { |
| 694 | selectResponse = new byte[result.length - 1]; |
| 695 | for (int i = 1; i < result.length; ++i) { |
| 696 | selectResponse[i - 1] = (byte) result[i]; |
| 697 | } |
| 698 | } |
| 699 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 700 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 701 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 702 | if (ar.result == null) { |
| 703 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 704 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 705 | if (ar.exception != null) { |
| 706 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 707 | } |
| 708 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 709 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 710 | if (ar.exception instanceof CommandException) { |
| 711 | CommandException.Error error = |
| 712 | ((CommandException) (ar.exception)).getCommandError(); |
| 713 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 714 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 715 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 716 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 717 | } |
| 718 | } |
| 719 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 720 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 721 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 722 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 723 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 724 | break; |
| 725 | |
| 726 | case CMD_CLOSE_CHANNEL: |
| 727 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 728 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 729 | if (uiccCard == null) { |
| 730 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 731 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 732 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 733 | } else { |
| 734 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 735 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 736 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 737 | break; |
| 738 | |
| 739 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 740 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 741 | break; |
| 742 | |
| 743 | case CMD_NV_READ_ITEM: |
| 744 | request = (MainThreadRequest) msg.obj; |
| 745 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 746 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 747 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 748 | break; |
| 749 | |
| 750 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 751 | ar = (AsyncResult) msg.obj; |
| 752 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 753 | if (ar.exception == null && ar.result != null) { |
| 754 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 755 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 756 | request.result = ""; |
| 757 | if (ar.result == null) { |
| 758 | loge("nvReadItem: Empty response"); |
| 759 | } else if (ar.exception instanceof CommandException) { |
| 760 | loge("nvReadItem: CommandException: " + |
| 761 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 762 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 763 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 764 | } |
| 765 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 766 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 767 | break; |
| 768 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 769 | case CMD_NV_WRITE_ITEM: |
| 770 | request = (MainThreadRequest) msg.obj; |
| 771 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 772 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 773 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 774 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 775 | break; |
| 776 | |
| 777 | case EVENT_NV_WRITE_ITEM_DONE: |
| 778 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 779 | break; |
| 780 | |
| 781 | case CMD_NV_WRITE_CDMA_PRL: |
| 782 | request = (MainThreadRequest) msg.obj; |
| 783 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 784 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 785 | break; |
| 786 | |
| 787 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 788 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 789 | break; |
| 790 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 791 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 792 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 793 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 794 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 795 | break; |
| 796 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 797 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 798 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 799 | break; |
| 800 | |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 801 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 802 | request = (MainThreadRequest) msg.obj; |
| 803 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 804 | request); |
| 805 | Phone phone = getPhoneFromRequest(request); |
| 806 | if (phone != null) { |
| 807 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 808 | } else { |
| 809 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 810 | request.result = false; |
| 811 | notifyRequester(request); |
| 812 | } |
| 813 | break; |
| 814 | } |
| 815 | |
| 816 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 817 | ar = (AsyncResult) msg.obj; |
| 818 | request = (MainThreadRequest) ar.userObj; |
| 819 | if (ar.exception == null && ar.result != null) { |
| 820 | request.result = ar.result; |
| 821 | } else { |
| 822 | // request.result must be set to something non-null |
| 823 | // for the calling thread to unblock |
| 824 | if (request.result != null) { |
| 825 | request.result = ar.result; |
| 826 | } else { |
| 827 | request.result = false; |
| 828 | } |
| 829 | if (ar.result == null) { |
| 830 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 831 | } else if (ar.exception instanceof CommandException) { |
| 832 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 833 | + ar.exception); |
| 834 | } else { |
| 835 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 836 | } |
| 837 | } |
| 838 | notifyRequester(request); |
| 839 | break; |
| 840 | |
| 841 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 842 | request = (MainThreadRequest) msg.obj; |
| 843 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 844 | Phone phone = getPhoneFromRequest(request); |
| 845 | if (phone != null) { |
| 846 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 847 | request.workSource); |
| 848 | } else { |
| 849 | loge("enableNrDualConnectivity: No phone object"); |
| 850 | request.result = |
| 851 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 852 | notifyRequester(request); |
| 853 | } |
| 854 | break; |
| 855 | } |
| 856 | |
| 857 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 858 | ar = (AsyncResult) msg.obj; |
| 859 | request = (MainThreadRequest) ar.userObj; |
| 860 | if (ar.exception == null) { |
| 861 | request.result = |
| 862 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 863 | } else { |
| 864 | request.result = |
| 865 | TelephonyManager |
| 866 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 867 | if (ar.exception instanceof CommandException) { |
| 868 | CommandException.Error error = |
| 869 | ((CommandException) (ar.exception)).getCommandError(); |
| 870 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 871 | request.result = |
| 872 | TelephonyManager |
| 873 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 874 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 875 | request.result = |
| 876 | TelephonyManager |
| 877 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 878 | } |
| 879 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 880 | + ar.exception); |
| 881 | } else { |
| 882 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 883 | } |
| 884 | } |
| 885 | notifyRequester(request); |
| 886 | break; |
| 887 | } |
| 888 | |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 889 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 890 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 891 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 892 | request); |
| 893 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 894 | break; |
| 895 | |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 896 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 897 | ar = (AsyncResult) msg.obj; |
| 898 | request = (MainThreadRequest) ar.userObj; |
| 899 | if (ar.exception == null && ar.result != null) { |
| 900 | request.result = ar.result; // Integer |
| 901 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 902 | // request.result must be set to something non-null |
| 903 | // for the calling thread to unblock |
| 904 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 905 | if (ar.result == null) { |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 906 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 907 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 908 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 909 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 910 | } else { |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 911 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 912 | } |
| 913 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 914 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 915 | break; |
| 916 | |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 917 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 918 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 919 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 920 | request); |
| 921 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 922 | (Pair<Integer, Long>) request.argument; |
| 923 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 924 | reasonWithNetworkTypes.first, |
| 925 | reasonWithNetworkTypes.second, |
| 926 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 927 | break; |
| 928 | |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 929 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 930 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 931 | break; |
| 932 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 933 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 934 | request = (MainThreadRequest)msg.obj; |
| 935 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 936 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 937 | break; |
| 938 | |
| 939 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 940 | ar = (AsyncResult)msg.obj; |
| 941 | request = (MainThreadRequest)ar.userObj; |
| 942 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 943 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 944 | break; |
| 945 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 946 | case CMD_SET_VOICEMAIL_NUMBER: |
| 947 | request = (MainThreadRequest) msg.obj; |
| 948 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 949 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 950 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 951 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 952 | break; |
| 953 | |
| 954 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 955 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 956 | break; |
| 957 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 958 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 959 | request = (MainThreadRequest) msg.obj; |
| 960 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 961 | request); |
| 962 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 963 | break; |
| 964 | |
| 965 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 966 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 967 | break; |
| 968 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 969 | case CMD_PERFORM_NETWORK_SCAN: |
| 970 | request = (MainThreadRequest) msg.obj; |
| 971 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 972 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 973 | break; |
| 974 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 975 | case CMD_GET_CALL_FORWARDING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 976 | request = (MainThreadRequest) msg.obj; |
| 977 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 978 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 979 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 980 | request.argument; |
| 981 | int callForwardingReason = args.first; |
| 982 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 983 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 984 | } |
| 985 | case EVENT_GET_CALL_FORWARDING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 986 | ar = (AsyncResult) msg.obj; |
| 987 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 988 | TelephonyManager.CallForwardingInfoCallback callback = |
| 989 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 990 | request.argument).second; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 991 | if (ar.exception == null && ar.result != null) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 992 | CallForwardingInfo callForwardingInfo = null; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 993 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 994 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 995 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 996 | // any service for voice call. |
| 997 | if ((callForwardInfo.serviceClass |
| 998 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 999 | callForwardingInfo = new CallForwardingInfo(true, |
| 1000 | callForwardInfo.reason, |
| 1001 | callForwardInfo.number, |
| 1002 | callForwardInfo.timeSeconds); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1003 | break; |
| 1004 | } |
| 1005 | } |
| 1006 | // Didn't find a call forward info for voice call. |
| 1007 | if (callForwardingInfo == null) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1008 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1009 | 0 /* reason */, null /* number */, 0 /* timeout */); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1010 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1011 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1012 | } else { |
| 1013 | if (ar.result == null) { |
| 1014 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1015 | } |
| 1016 | if (ar.exception != null) { |
| 1017 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1018 | } |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1019 | int errorCode = TelephonyManager |
| 1020 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1021 | if (ar.exception instanceof CommandException) { |
| 1022 | CommandException.Error error = |
| 1023 | ((CommandException) (ar.exception)).getCommandError(); |
| 1024 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1025 | errorCode = TelephonyManager |
| 1026 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1027 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1028 | errorCode = TelephonyManager |
| 1029 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1030 | } |
| 1031 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1032 | callback.onError(errorCode); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1033 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1034 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1035 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1036 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1037 | case CMD_SET_CALL_FORWARDING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1038 | request = (MainThreadRequest) msg.obj; |
| 1039 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1040 | request = (MainThreadRequest) msg.obj; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1041 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1042 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1043 | request.argument).first; |
| 1044 | request.phone.setCallForwardingOption( |
| 1045 | callForwardingInfoToSet.isEnabled() |
| 1046 | ? CommandsInterface.CF_ACTION_ENABLE |
| 1047 | : CommandsInterface.CF_ACTION_DISABLE, |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1048 | callForwardingInfoToSet.getReason(), |
| 1049 | callForwardingInfoToSet.getNumber(), |
| 1050 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1051 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1052 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1053 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1054 | case EVENT_SET_CALL_FORWARDING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1055 | ar = (AsyncResult) msg.obj; |
| 1056 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1057 | Consumer<Integer> callback = |
| 1058 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1059 | request.argument).second; |
| 1060 | if (ar.exception != null) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1061 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1062 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1063 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1064 | if (ar.exception instanceof CommandException) { |
| 1065 | CommandException.Error error = |
| 1066 | ((CommandException) (ar.exception)).getCommandError(); |
| 1067 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1068 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1069 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1070 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1071 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1072 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1073 | } |
| 1074 | } |
| 1075 | callback.accept(errorCode); |
| 1076 | } else { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1077 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1078 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1079 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1080 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1081 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1082 | case CMD_GET_CALL_WAITING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1083 | request = (MainThreadRequest) msg.obj; |
| 1084 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1085 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1086 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1087 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1088 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1089 | case EVENT_GET_CALL_WAITING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1090 | ar = (AsyncResult) msg.obj; |
| 1091 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1092 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1093 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1094 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1095 | int[] callForwardResults = (int[]) ar.result; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1096 | // Service Class is a bit mask per 3gpp 27.007. |
| 1097 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1098 | if (callForwardResults.length > 1 |
| 1099 | && ((callForwardResults[1] |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1100 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1101 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1102 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1103 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1104 | } else { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1105 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1106 | } |
| 1107 | } else { |
| 1108 | if (ar.result == null) { |
| 1109 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1110 | } |
| 1111 | if (ar.exception != null) { |
| 1112 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1113 | } |
| 1114 | if (ar.exception instanceof CommandException) { |
| 1115 | CommandException.Error error = |
| 1116 | ((CommandException) (ar.exception)).getCommandError(); |
| 1117 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1118 | callForwardingStatus = |
| 1119 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1120 | } |
| 1121 | } |
| 1122 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1123 | callback.accept(callForwardingStatus); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1124 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1125 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1126 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1127 | case CMD_SET_CALL_WAITING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1128 | request = (MainThreadRequest) msg.obj; |
| 1129 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1130 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1131 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1132 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1133 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1134 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1135 | case EVENT_SET_CALL_WAITING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1136 | ar = (AsyncResult) msg.obj; |
| 1137 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1138 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1139 | Consumer<Integer> callback = |
| 1140 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1141 | if (ar.exception != null) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1142 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1143 | if (ar.exception instanceof CommandException) { |
| 1144 | CommandException.Error error = |
| 1145 | ((CommandException) (ar.exception)).getCommandError(); |
| 1146 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1147 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1148 | } else { |
| 1149 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1150 | } |
| 1151 | } else { |
| 1152 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1153 | } |
| 1154 | } else { |
| 1155 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1156 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1157 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1158 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1159 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1160 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1161 | ar = (AsyncResult) msg.obj; |
| 1162 | request = (MainThreadRequest) ar.userObj; |
| 1163 | CellNetworkScanResult cellScanResult; |
| 1164 | if (ar.exception == null && ar.result != null) { |
| 1165 | cellScanResult = new CellNetworkScanResult( |
| 1166 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1167 | (List<OperatorInfo>) ar.result); |
| 1168 | } else { |
| 1169 | if (ar.result == null) { |
| 1170 | loge("getCellNetworkScanResults: Empty response"); |
| 1171 | } |
| 1172 | if (ar.exception != null) { |
| 1173 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1174 | } |
| 1175 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1176 | if (ar.exception instanceof CommandException) { |
| 1177 | CommandException.Error error = |
| 1178 | ((CommandException) (ar.exception)).getCommandError(); |
| 1179 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1180 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1181 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1182 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1183 | } |
| 1184 | } |
| 1185 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1186 | } |
| 1187 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1188 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1189 | break; |
| 1190 | |
| 1191 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1192 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1193 | ManualNetworkSelectionArgument selArg = |
| 1194 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1195 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1196 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1197 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1198 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1199 | break; |
| 1200 | |
| 1201 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1202 | ar = (AsyncResult) msg.obj; |
| 1203 | request = (MainThreadRequest) ar.userObj; |
| 1204 | if (ar.exception == null) { |
| 1205 | request.result = true; |
| 1206 | } else { |
| 1207 | request.result = false; |
| 1208 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1209 | } |
| 1210 | notifyRequester(request); |
| 1211 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1212 | break; |
| 1213 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1214 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1215 | request = (MainThreadRequest) msg.obj; |
| 1216 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1217 | if (defaultPhone != null) { |
| 1218 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1219 | } else { |
| 1220 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1221 | Bundle bundle = new Bundle(); |
| 1222 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | e831598 | 2020-10-09 19:00:11 -0700 | [diff] [blame^] | 1223 | new ModemActivityInfo(0, 0, 0, |
| 1224 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1225 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1226 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1227 | break; |
| 1228 | |
| 1229 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 1230 | ar = (AsyncResult) msg.obj; |
| 1231 | request = (MainThreadRequest) ar.userObj; |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1232 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1233 | |
Hall Liu | e831598 | 2020-10-09 19:00:11 -0700 | [diff] [blame^] | 1234 | ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, |
| 1235 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1236 | if (ar.exception == null && ar.result != null) { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1237 | // Update the last modem activity info and the result of the request. |
| 1238 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1239 | if (isModemActivityInfoValid(info)) { |
Hall Liu | e831598 | 2020-10-09 19:00:11 -0700 | [diff] [blame^] | 1240 | int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()]; |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1241 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1242 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1243 | .getTransmitTimeMillis(); |
| 1244 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1245 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1246 | } |
Hall Liu | e831598 | 2020-10-09 19:00:11 -0700 | [diff] [blame^] | 1247 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1248 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1249 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1250 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1251 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1252 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1253 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1254 | info.getReceiveTimeMillis() |
| 1255 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1256 | } |
Hall Liu | e831598 | 2020-10-09 19:00:11 -0700 | [diff] [blame^] | 1257 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(), |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1258 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1259 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1260 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1261 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1262 | } else { |
| 1263 | if (ar.result == null) { |
| 1264 | loge("queryModemActivityInfo: Empty response"); |
| 1265 | } else if (ar.exception instanceof CommandException) { |
| 1266 | loge("queryModemActivityInfo: CommandException: " + |
| 1267 | ar.exception); |
| 1268 | } else { |
| 1269 | loge("queryModemActivityInfo: Unknown exception"); |
| 1270 | } |
| 1271 | } |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1272 | Bundle bundle = new Bundle(); |
| 1273 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1274 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1275 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1276 | break; |
| 1277 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1278 | case CMD_SET_ALLOWED_CARRIERS: |
| 1279 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1280 | CarrierRestrictionRules argument = |
| 1281 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1282 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1283 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1284 | break; |
| 1285 | |
| 1286 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1287 | ar = (AsyncResult) msg.obj; |
| 1288 | request = (MainThreadRequest) ar.userObj; |
| 1289 | if (ar.exception == null && ar.result != null) { |
| 1290 | request.result = ar.result; |
| 1291 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1292 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1293 | if (ar.exception instanceof CommandException) { |
| 1294 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1295 | CommandException.Error error = |
| 1296 | ((CommandException) (ar.exception)).getCommandError(); |
| 1297 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1298 | request.result = |
| 1299 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1300 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1301 | } else { |
| 1302 | loge("setAllowedCarriers: Unknown exception"); |
| 1303 | } |
| 1304 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1305 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1306 | break; |
| 1307 | |
| 1308 | case CMD_GET_ALLOWED_CARRIERS: |
| 1309 | request = (MainThreadRequest) msg.obj; |
| 1310 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1311 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1312 | break; |
| 1313 | |
| 1314 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1315 | ar = (AsyncResult) msg.obj; |
| 1316 | request = (MainThreadRequest) ar.userObj; |
| 1317 | if (ar.exception == null && ar.result != null) { |
| 1318 | request.result = ar.result; |
| 1319 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1320 | request.result = new IllegalStateException( |
| 1321 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1322 | if (ar.result == null) { |
| 1323 | loge("getAllowedCarriers: Empty response"); |
| 1324 | } else if (ar.exception instanceof CommandException) { |
| 1325 | loge("getAllowedCarriers: CommandException: " + |
| 1326 | ar.exception); |
| 1327 | } else { |
| 1328 | loge("getAllowedCarriers: Unknown exception"); |
| 1329 | } |
| 1330 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1331 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1332 | break; |
| 1333 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1334 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1335 | ar = (AsyncResult) msg.obj; |
| 1336 | request = (MainThreadRequest) ar.userObj; |
| 1337 | if (ar.exception == null && ar.result != null) { |
| 1338 | request.result = ar.result; |
| 1339 | } else { |
| 1340 | request.result = new IllegalArgumentException( |
| 1341 | "Failed to retrieve Forbidden Plmns"); |
| 1342 | if (ar.result == null) { |
| 1343 | loge("getForbiddenPlmns: Empty response"); |
| 1344 | } else { |
| 1345 | loge("getForbiddenPlmns: Unknown exception"); |
| 1346 | } |
| 1347 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1348 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1349 | break; |
| 1350 | |
| 1351 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1352 | request = (MainThreadRequest) msg.obj; |
| 1353 | uiccCard = getUiccCardFromRequest(request); |
| 1354 | if (uiccCard == null) { |
| 1355 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1356 | request.result = new IllegalArgumentException( |
| 1357 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1358 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1359 | break; |
| 1360 | } |
| 1361 | Integer appType = (Integer) request.argument; |
| 1362 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1363 | if (uiccApp == null) { |
| 1364 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1365 | + appType); |
| 1366 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1367 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1368 | break; |
| 1369 | } else { |
| 1370 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1371 | + " specified type -- " + appType); |
| 1372 | } |
| 1373 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1374 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1375 | onCompleted); |
| 1376 | break; |
| 1377 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1378 | case CMD_SWITCH_SLOTS: |
| 1379 | request = (MainThreadRequest) msg.obj; |
| 1380 | int[] physicalSlots = (int[]) request.argument; |
| 1381 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1382 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1383 | break; |
| 1384 | |
| 1385 | case EVENT_SWITCH_SLOTS_DONE: |
| 1386 | ar = (AsyncResult) msg.obj; |
| 1387 | request = (MainThreadRequest) ar.userObj; |
| 1388 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1389 | notifyRequester(request); |
| 1390 | break; |
| 1391 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1392 | request = (MainThreadRequest) msg.obj; |
| 1393 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1394 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1395 | break; |
| 1396 | |
| 1397 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1398 | ar = (AsyncResult) msg.obj; |
| 1399 | request = (MainThreadRequest) ar.userObj; |
| 1400 | if (ar.exception != null) { |
| 1401 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1402 | } else { |
| 1403 | int mode = ((int[]) ar.result)[0]; |
| 1404 | if (mode == 0) { |
| 1405 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1406 | } else { |
| 1407 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1408 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1409 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1410 | notifyRequester(request); |
| 1411 | break; |
| 1412 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1413 | request = (MainThreadRequest) msg.obj; |
| 1414 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1415 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1416 | break; |
| 1417 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1418 | ar = (AsyncResult) msg.obj; |
| 1419 | request = (MainThreadRequest) ar.userObj; |
| 1420 | if (ar.exception != null) { |
| 1421 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1422 | } else { |
| 1423 | request.result = ((int[]) ar.result)[0]; |
| 1424 | } |
| 1425 | notifyRequester(request); |
| 1426 | break; |
| 1427 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1428 | request = (MainThreadRequest) msg.obj; |
| 1429 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1430 | int mode = (int) request.argument; |
| 1431 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1432 | break; |
| 1433 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1434 | ar = (AsyncResult) msg.obj; |
| 1435 | request = (MainThreadRequest) ar.userObj; |
| 1436 | request.result = ar.exception == null; |
| 1437 | notifyRequester(request); |
| 1438 | break; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1439 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1440 | request = (MainThreadRequest) msg.obj; |
| 1441 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1442 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1443 | break; |
| 1444 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1445 | ar = (AsyncResult) msg.obj; |
| 1446 | request = (MainThreadRequest) ar.userObj; |
| 1447 | if (ar.exception != null) { |
| 1448 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1449 | } else { |
| 1450 | request.result = ((int[]) ar.result)[0]; |
| 1451 | } |
| 1452 | notifyRequester(request); |
| 1453 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1454 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1455 | request = (MainThreadRequest) msg.obj; |
| 1456 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1457 | int subscriptionMode = (int) request.argument; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1458 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1459 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1460 | break; |
| 1461 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1462 | ar = (AsyncResult) msg.obj; |
| 1463 | request = (MainThreadRequest) ar.userObj; |
| 1464 | request.result = ar.exception == null; |
| 1465 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1466 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1467 | case CMD_GET_ALL_CELL_INFO: |
| 1468 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1469 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1470 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1471 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1472 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1473 | ar = (AsyncResult) msg.obj; |
| 1474 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1475 | // If a timeout occurs, the response will be null |
| 1476 | request.result = (ar.exception == null && ar.result != null) |
| 1477 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1478 | synchronized (request) { |
| 1479 | request.notifyAll(); |
| 1480 | } |
| 1481 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1482 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1483 | request = (MainThreadRequest) msg.obj; |
| 1484 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1485 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1486 | break; |
| 1487 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1488 | ar = (AsyncResult) msg.obj; |
| 1489 | request = (MainThreadRequest) ar.userObj; |
| 1490 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1491 | try { |
| 1492 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1493 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1494 | cb.onError( |
| 1495 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1496 | ar.exception.getClass().getName(), |
| 1497 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1498 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1499 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1500 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1501 | } else { |
| 1502 | // use the result as returned |
| 1503 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1504 | } |
| 1505 | } catch (RemoteException re) { |
| 1506 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1507 | } |
| 1508 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1509 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1510 | request = (MainThreadRequest) msg.obj; |
| 1511 | WorkSource ws = (WorkSource) request.argument; |
| 1512 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1513 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1514 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1515 | } |
| 1516 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1517 | ar = (AsyncResult) msg.obj; |
| 1518 | request = (MainThreadRequest) ar.userObj; |
| 1519 | if (ar.exception == null) { |
| 1520 | request.result = ar.result; |
| 1521 | } else { |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1522 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1523 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1524 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1525 | } |
| 1526 | |
| 1527 | synchronized (request) { |
| 1528 | request.notifyAll(); |
| 1529 | } |
| 1530 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1531 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1532 | case CMD_MODEM_REBOOT: |
| 1533 | request = (MainThreadRequest) msg.obj; |
| 1534 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1535 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1536 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1537 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1538 | handleNullReturnEvent(msg, "rebootModem"); |
| 1539 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1540 | case CMD_REQUEST_ENABLE_MODEM: |
| 1541 | request = (MainThreadRequest) msg.obj; |
| 1542 | boolean enable = (boolean) request.argument; |
| 1543 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1544 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1545 | PhoneConfigurationManager.getInstance() |
| 1546 | .enablePhone(request.phone, enable, onCompleted); |
| 1547 | break; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1548 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1549 | ar = (AsyncResult) msg.obj; |
| 1550 | request = (MainThreadRequest) ar.userObj; |
| 1551 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1552 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1553 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1554 | if ((boolean) request.result) { |
| 1555 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1556 | updateModemStateMetrics(); |
| 1557 | } else { |
| 1558 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1559 | + ar.exception); |
| 1560 | } |
| 1561 | notifyRequester(request); |
| 1562 | break; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1563 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1564 | case CMD_GET_MODEM_STATUS: |
| 1565 | request = (MainThreadRequest) msg.obj; |
| 1566 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1567 | PhoneConfigurationManager.getInstance() |
| 1568 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1569 | break; |
| 1570 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1571 | ar = (AsyncResult) msg.obj; |
| 1572 | request = (MainThreadRequest) ar.userObj; |
| 1573 | int id = request.phone.getPhoneId(); |
| 1574 | if (ar.exception == null && ar.result != null) { |
| 1575 | request.result = ar.result; |
| 1576 | //update the cache as modem status has changed |
| 1577 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1578 | (boolean) request.result); |
| 1579 | } else { |
| 1580 | // Return true if modem status cannot be retrieved. For most cases, |
| 1581 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1582 | // and disable modem are not supported. Modem is always on. |
| 1583 | // TODO: this should be fixed in R to support a third |
| 1584 | // status UNKNOWN b/131631629 |
| 1585 | request.result = true; |
| 1586 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1587 | + ar.exception); |
| 1588 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1589 | notifyRequester(request); |
| 1590 | break; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1591 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1592 | request = (MainThreadRequest) msg.obj; |
| 1593 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1594 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1595 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1596 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1597 | break; |
| 1598 | } |
| 1599 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1600 | ar = (AsyncResult) msg.obj; |
| 1601 | request = (MainThreadRequest) ar.userObj; |
| 1602 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1603 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1604 | args.second.accept(ar.exception == null); |
| 1605 | notifyRequester(request); |
| 1606 | break; |
| 1607 | } |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1608 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1609 | request = (MainThreadRequest) msg.obj; |
| 1610 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1611 | Phone phone = getPhoneFromRequest(request); |
| 1612 | if (phone != null) { |
| 1613 | phone.getSystemSelectionChannels(onCompleted); |
| 1614 | } else { |
| 1615 | loge("getSystemSelectionChannels: No phone object"); |
| 1616 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1617 | notifyRequester(request); |
| 1618 | } |
| 1619 | break; |
| 1620 | } |
| 1621 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1622 | ar = (AsyncResult) msg.obj; |
| 1623 | request = (MainThreadRequest) ar.userObj; |
| 1624 | if (ar.exception == null && ar.result != null) { |
| 1625 | request.result = ar.result; |
| 1626 | } else { |
Sarah Chin | 5869187 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1627 | request.result = new IllegalStateException( |
| 1628 | "Failed to retrieve system selecton channels"); |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1629 | if (ar.result == null) { |
| 1630 | loge("getSystemSelectionChannels: Empty response"); |
| 1631 | } else { |
| 1632 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1633 | } |
| 1634 | } |
| 1635 | notifyRequester(request); |
| 1636 | break; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1637 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1638 | ar = (AsyncResult) msg.obj; |
| 1639 | request = (MainThreadRequest) ar.userObj; |
| 1640 | if (ar.exception == null && ar.result != null) { |
| 1641 | request.result = ar.result; |
| 1642 | } else { |
| 1643 | request.result = -1; |
| 1644 | loge("Failed to set Forbidden Plmns"); |
| 1645 | if (ar.result == null) { |
| 1646 | loge("setForbidenPlmns: Empty response"); |
| 1647 | } else if (ar.exception != null) { |
| 1648 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1649 | request.result = -1; |
| 1650 | } else { |
| 1651 | loge("setForbiddenPlmns: Unknown exception"); |
| 1652 | } |
| 1653 | } |
| 1654 | notifyRequester(request); |
| 1655 | break; |
| 1656 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1657 | request = (MainThreadRequest) msg.obj; |
| 1658 | uiccCard = getUiccCardFromRequest(request); |
| 1659 | if (uiccCard == null) { |
| 1660 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1661 | request.result = -1; |
| 1662 | notifyRequester(request); |
| 1663 | break; |
| 1664 | } |
| 1665 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1666 | (Pair<Integer, List<String>>) request.argument; |
| 1667 | appType = setFplmnsArgs.first; |
| 1668 | List<String> fplmns = setFplmnsArgs.second; |
| 1669 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1670 | if (uiccApp == null) { |
| 1671 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1672 | request.result = -1; |
| 1673 | loge("Failed to get UICC App"); |
| 1674 | notifyRequester(request); |
| 1675 | } else { |
| 1676 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1677 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1678 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1679 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1680 | break; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1681 | case CMD_ERASE_MODEM_CONFIG: |
| 1682 | request = (MainThreadRequest) msg.obj; |
| 1683 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1684 | defaultPhone.eraseModemConfig(onCompleted); |
| 1685 | break; |
| 1686 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1687 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1688 | break; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1689 | |
| 1690 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1691 | request = (MainThreadRequest) msg.obj; |
| 1692 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1693 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1694 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1695 | changed.first, changed.second, onCompleted); |
| 1696 | break; |
| 1697 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1698 | ar = (AsyncResult) msg.obj; |
| 1699 | request = (MainThreadRequest) ar.userObj; |
| 1700 | if (ar.exception == null) { |
| 1701 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1702 | // If the operation is successful, update the PIN storage |
| 1703 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1704 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1705 | UiccController.getInstance().getPinStorage() |
| 1706 | .storePin(passwords.second, phoneId); |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1707 | } else { |
| 1708 | request.result = msg.arg1; |
| 1709 | } |
| 1710 | notifyRequester(request); |
| 1711 | break; |
| 1712 | |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1713 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1714 | request = (MainThreadRequest) msg.obj; |
| 1715 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1716 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1717 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1718 | enabled.first, enabled.second, onCompleted); |
| 1719 | break; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1720 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1721 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1722 | ar = (AsyncResult) msg.obj; |
| 1723 | request = (MainThreadRequest) ar.userObj; |
| 1724 | if (ar.exception == null) { |
| 1725 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1726 | // If the operation is successful, update the PIN storage |
| 1727 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1728 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1729 | if (enabled.first) { |
| 1730 | UiccController.getInstance().getPinStorage() |
| 1731 | .storePin(enabled.second, phoneId); |
| 1732 | } else { |
| 1733 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1734 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1735 | } else { |
| 1736 | request.result = msg.arg1; |
| 1737 | } |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1738 | |
| 1739 | |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1740 | notifyRequester(request); |
| 1741 | break; |
| 1742 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1743 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1744 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1745 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1746 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1747 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1748 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1749 | break; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 1750 | |
| 1751 | case CMD_SET_DATA_THROTTLING: { |
| 1752 | request = (MainThreadRequest) msg.obj; |
| 1753 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1754 | DataThrottlingRequest dataThrottlingRequest = |
| 1755 | (DataThrottlingRequest) request.argument; |
| 1756 | Phone phone = getPhoneFromRequest(request); |
| 1757 | if (phone != null) { |
| 1758 | phone.setDataThrottling(onCompleted, |
| 1759 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1760 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1761 | } else { |
| 1762 | loge("setDataThrottling: No phone object"); |
| 1763 | request.result = |
| 1764 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1765 | notifyRequester(request); |
| 1766 | } |
| 1767 | |
| 1768 | break; |
| 1769 | } |
| 1770 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1771 | ar = (AsyncResult) msg.obj; |
| 1772 | request = (MainThreadRequest) ar.userObj; |
| 1773 | |
| 1774 | if (ar.exception == null) { |
| 1775 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1776 | } else if (ar.exception instanceof CommandException) { |
| 1777 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1778 | CommandException.Error error = |
| 1779 | ((CommandException) (ar.exception)).getCommandError(); |
| 1780 | |
| 1781 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1782 | request.result = TelephonyManager |
| 1783 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1784 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1785 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 1786 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1787 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 1788 | } else { |
| 1789 | request.result = |
| 1790 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1791 | } |
| 1792 | } else { |
| 1793 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1794 | } |
| 1795 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1796 | notifyRequester(request); |
| 1797 | break; |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1798 | |
| 1799 | case CMD_SET_SIM_POWER: { |
| 1800 | request = (MainThreadRequest) msg.obj; |
| 1801 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1802 | request = (MainThreadRequest) msg.obj; |
| 1803 | int stateToSet = |
| 1804 | ((Pair<Integer, IIntegerConsumer>) |
| 1805 | request.argument).first; |
| 1806 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1807 | break; |
| 1808 | } |
| 1809 | case EVENT_SET_SIM_POWER_DONE: { |
| 1810 | ar = (AsyncResult) msg.obj; |
| 1811 | request = (MainThreadRequest) ar.userObj; |
| 1812 | IIntegerConsumer callback = |
| 1813 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1814 | if (ar.exception != null) { |
| 1815 | loge("setSimPower exception: " + ar.exception); |
| 1816 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1817 | .RESULT_ERROR_UNKNOWN; |
| 1818 | if (ar.exception instanceof CommandException) { |
| 1819 | CommandException.Error error = |
| 1820 | ((CommandException) (ar.exception)).getCommandError(); |
| 1821 | if (error == CommandException.Error.SIM_ERR) { |
| 1822 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1823 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1824 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1825 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1826 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1827 | } else { |
| 1828 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1829 | } |
| 1830 | } |
| 1831 | try { |
| 1832 | callback.accept(errorCode); |
| 1833 | } catch (RemoteException e) { |
| 1834 | // Ignore if the remote process is no longer available to call back. |
| 1835 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1836 | } |
| 1837 | } else { |
| 1838 | try { |
| 1839 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1840 | } catch (RemoteException e) { |
| 1841 | // Ignore if the remote process is no longer available to call back. |
| 1842 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1843 | } |
| 1844 | } |
| 1845 | break; |
| 1846 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1847 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1848 | request = (MainThreadRequest) msg.obj; |
| 1849 | |
| 1850 | final Phone phone = getPhoneFromRequest(request); |
| 1851 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1852 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1853 | notifyRequester(request); |
| 1854 | break; |
| 1855 | } |
| 1856 | |
| 1857 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1858 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1859 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1860 | request); |
| 1861 | phone.getServiceStateTracker().setSignalStrengthUpdateRequest( |
| 1862 | request.subId, pair.first /*callingUid*/, |
| 1863 | pair.second /*request*/, onCompleted); |
| 1864 | break; |
| 1865 | } |
| 1866 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1867 | ar = (AsyncResult) msg.obj; |
| 1868 | request = (MainThreadRequest) ar.userObj; |
| 1869 | // request.result will be the exception of ar if present, true otherwise. |
| 1870 | // Be cautious not to leave result null which will wait() forever |
| 1871 | request.result = ar.exception != null ? ar.exception : true; |
| 1872 | notifyRequester(request); |
| 1873 | break; |
| 1874 | } |
| 1875 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1876 | request = (MainThreadRequest) msg.obj; |
| 1877 | |
| 1878 | Phone phone = getPhoneFromRequest(request); |
| 1879 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1880 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1881 | notifyRequester(request); |
| 1882 | break; |
| 1883 | } |
| 1884 | |
| 1885 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1886 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1887 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1888 | request); |
| 1889 | phone.getServiceStateTracker().clearSignalStrengthUpdateRequest( |
| 1890 | request.subId, pair.first /*callingUid*/, |
| 1891 | pair.second /*request*/, onCompleted); |
| 1892 | break; |
| 1893 | } |
| 1894 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1895 | ar = (AsyncResult) msg.obj; |
| 1896 | request = (MainThreadRequest) ar.userObj; |
| 1897 | request.result = ar.exception != null ? ar.exception : true; |
| 1898 | notifyRequester(request); |
| 1899 | break; |
| 1900 | } |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1901 | |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1902 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 1903 | request = (MainThreadRequest) msg.obj; |
| 1904 | request.result = |
| 1905 | UiccController.getInstance().getPinStorage().prepareUnattendedReboot(); |
| 1906 | notifyRequester(request); |
| 1907 | break; |
| 1908 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1909 | default: |
| 1910 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1911 | break; |
| 1912 | } |
| 1913 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1914 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1915 | private void notifyRequester(MainThreadRequest request) { |
| 1916 | synchronized (request) { |
| 1917 | request.notifyAll(); |
| 1918 | } |
| 1919 | } |
| 1920 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1921 | private void handleNullReturnEvent(Message msg, String command) { |
| 1922 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1923 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1924 | if (ar.exception == null) { |
| 1925 | request.result = true; |
| 1926 | } else { |
| 1927 | request.result = false; |
| 1928 | if (ar.exception instanceof CommandException) { |
| 1929 | loge(command + ": CommandException: " + ar.exception); |
| 1930 | } else { |
| 1931 | loge(command + ": Unknown exception"); |
| 1932 | } |
| 1933 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1934 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1935 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1936 | } |
| 1937 | |
| 1938 | /** |
| 1939 | * Posts the specified command to be executed on the main thread, |
| 1940 | * waits for the request to complete, and returns the result. |
| 1941 | * @see #sendRequestAsync |
| 1942 | */ |
| 1943 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1944 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 1945 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | /** |
| 1949 | * Posts the specified command to be executed on the main thread, |
| 1950 | * waits for the request to complete, and returns the result. |
| 1951 | * @see #sendRequestAsync |
| 1952 | */ |
| 1953 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1954 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1955 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | /** |
| 1959 | * Posts the specified command to be executed on the main thread, |
| 1960 | * waits for the request to complete, and returns the result. |
| 1961 | * @see #sendRequestAsync |
| 1962 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1963 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1964 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 1965 | } |
| 1966 | |
| 1967 | /** |
| 1968 | * Posts the specified command to be executed on the main thread, |
| 1969 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 1970 | * if not timeout or null otherwise. |
| 1971 | * @see #sendRequestAsync |
| 1972 | */ |
| 1973 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 1974 | long timeoutInMs) { |
| 1975 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1976 | } |
| 1977 | |
| 1978 | /** |
| 1979 | * Posts the specified command to be executed on the main thread, |
| 1980 | * waits for the request to complete, and returns the result. |
| 1981 | * @see #sendRequestAsync |
| 1982 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1983 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1984 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1985 | } |
| 1986 | |
| 1987 | /** |
| 1988 | * Posts the specified command to be executed on the main thread, |
| 1989 | * waits for the request to complete, and returns the result. |
| 1990 | * @see #sendRequestAsync |
| 1991 | */ |
| 1992 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1993 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 1994 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1995 | } |
| 1996 | |
| 1997 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1998 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 1999 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2000 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2001 | * @see #sendRequestAsync |
| 2002 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2003 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2004 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2005 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2006 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2007 | } |
| 2008 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2009 | MainThreadRequest request = null; |
| 2010 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2011 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2012 | } else if (phone != null) { |
| 2013 | request = new MainThreadRequest(argument, phone, workSource); |
| 2014 | } else { |
| 2015 | request = new MainThreadRequest(argument, subId, workSource); |
| 2016 | } |
| 2017 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2018 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2019 | msg.sendToTarget(); |
| 2020 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2021 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2022 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2023 | if (timeoutInMs >= 0) { |
| 2024 | // Wait for at least timeoutInMs before returning null request result |
| 2025 | long now = SystemClock.elapsedRealtime(); |
| 2026 | long deadline = now + timeoutInMs; |
| 2027 | while (request == null && now < deadline) { |
| 2028 | try { |
| 2029 | request.wait(deadline - now); |
| 2030 | } catch (InterruptedException e) { |
| 2031 | // Do nothing, go back and check if request is completed or timeout |
| 2032 | } finally { |
| 2033 | now = SystemClock.elapsedRealtime(); |
| 2034 | } |
| 2035 | } |
| 2036 | } else { |
| 2037 | // Wait for the request to complete |
| 2038 | while (request.result == null) { |
| 2039 | try { |
| 2040 | request.wait(); |
| 2041 | } catch (InterruptedException e) { |
| 2042 | // Do nothing, go back and wait until the request is complete |
| 2043 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2044 | } |
| 2045 | } |
| 2046 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2047 | if (request.result == null) { |
| 2048 | Log.wtf(LOG_TAG, |
| 2049 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2050 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2051 | return request.result; |
| 2052 | } |
| 2053 | |
| 2054 | /** |
| 2055 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2056 | * Posts the specified command to be executed on the main thread, and |
| 2057 | * returns immediately. |
| 2058 | * @see #sendRequest |
| 2059 | */ |
| 2060 | private void sendRequestAsync(int command) { |
| 2061 | mMainThreadHandler.sendEmptyMessage(command); |
| 2062 | } |
| 2063 | |
| 2064 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2065 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2066 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2067 | */ |
| 2068 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2069 | sendRequestAsync(command, argument, null, null); |
| 2070 | } |
| 2071 | |
| 2072 | /** |
| 2073 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2074 | * @see {@link #sendRequest(int,Object)} |
| 2075 | */ |
| 2076 | private void sendRequestAsync( |
| 2077 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2078 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2079 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2080 | msg.sendToTarget(); |
| 2081 | } |
| 2082 | |
| 2083 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2084 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2085 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2086 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2087 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2088 | synchronized (PhoneInterfaceManager.class) { |
| 2089 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2090 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2091 | } else { |
| 2092 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2093 | } |
| 2094 | return sInstance; |
| 2095 | } |
| 2096 | } |
| 2097 | |
| 2098 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2099 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2100 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2101 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | c9c432e | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2102 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2103 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2104 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2105 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2106 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2107 | mTelephonySharedPreferences = |
| 2108 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2109 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2110 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | fe1e6ac | 2021-03-12 10:25:03 -0800 | [diff] [blame] | 2111 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2112 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2113 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2114 | publish(); |
| 2115 | } |
| 2116 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2117 | private Phone getDefaultPhone() { |
| 2118 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2119 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2120 | } |
| 2121 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2122 | private void publish() { |
| 2123 | if (DBG) log("publish: " + this); |
| 2124 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2125 | TelephonyFrameworkInitializer |
| 2126 | .getTelephonyServiceManager() |
| 2127 | .getTelephonyServiceRegisterer() |
| 2128 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2129 | } |
| 2130 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2131 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2132 | if (request.phone != null) { |
| 2133 | return request.phone; |
| 2134 | } else { |
| 2135 | return getPhoneFromSubId(request.subId); |
| 2136 | } |
| 2137 | } |
| 2138 | |
| 2139 | private Phone getPhoneFromSubId(int subId) { |
| 2140 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2141 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2142 | } |
| 2143 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2144 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 2145 | Phone phone = getPhoneFromRequest(request); |
| 2146 | return phone == null ? null : |
| 2147 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 2148 | } |
| 2149 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2150 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2151 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2152 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2153 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2154 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2155 | private void sendEraseModemConfig(Phone phone) { |
| 2156 | if (phone != null) { |
| 2157 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2158 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 2159 | final long identity = Binder.clearCallingIdentity(); |
| 2160 | try { |
| 2161 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2162 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2163 | } finally { |
| 2164 | Binder.restoreCallingIdentity(identity); |
| 2165 | } |
| 2166 | } |
| 2167 | } |
| 2168 | |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2169 | private boolean isImsAvailableOnDevice() { |
| 2170 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2171 | if (pm == null) { |
| 2172 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2173 | // so do not throw error and allow. |
| 2174 | return true; |
| 2175 | } |
| 2176 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2177 | } |
| 2178 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2179 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2180 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2181 | } |
| 2182 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2183 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2184 | if (DBG) log("dial: " + number); |
| 2185 | // No permission check needed here: This is just a wrapper around the |
| 2186 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2187 | // the UI before it does anything. |
| 2188 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2189 | final long identity = Binder.clearCallingIdentity(); |
| 2190 | try { |
| 2191 | String url = createTelUrl(number); |
| 2192 | if (url == null) { |
| 2193 | return; |
| 2194 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2195 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2196 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2197 | PhoneConstants.State state = mCM.getState(subId); |
| 2198 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2199 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2200 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2201 | mApp.startActivity(intent); |
| 2202 | } |
| 2203 | } finally { |
| 2204 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2205 | } |
| 2206 | } |
| 2207 | |
| 2208 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2209 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2210 | } |
| 2211 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2212 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2213 | if (DBG) log("call: " + number); |
| 2214 | |
| 2215 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2216 | // need to do a permission check since we're calling startActivity() |
| 2217 | // from the context of the phone app. |
| 2218 | enforceCallPermission(); |
| 2219 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2220 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2221 | != AppOpsManager.MODE_ALLOWED) { |
| 2222 | return; |
| 2223 | } |
| 2224 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2225 | final long identity = Binder.clearCallingIdentity(); |
| 2226 | try { |
| 2227 | String url = createTelUrl(number); |
| 2228 | if (url == null) { |
| 2229 | return; |
| 2230 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2231 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2232 | boolean isValid = false; |
| 2233 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2234 | if (slist != null) { |
| 2235 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2236 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2237 | isValid = true; |
| 2238 | break; |
| 2239 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2240 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2241 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2242 | if (!isValid) { |
| 2243 | return; |
| 2244 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2245 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2246 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2247 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2248 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2249 | mApp.startActivity(intent); |
| 2250 | } finally { |
| 2251 | Binder.restoreCallingIdentity(identity); |
| 2252 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2253 | } |
| 2254 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2255 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2256 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2257 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2258 | } |
| 2259 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2260 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2261 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2262 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2263 | } |
| 2264 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2265 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2266 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2267 | |
| 2268 | final long identity = Binder.clearCallingIdentity(); |
| 2269 | try { |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2270 | Phone phone = getPhone(subId); |
| 2271 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2272 | checkSimPin.start(); |
| 2273 | return checkSimPin.unlockSim(null, pin); |
| 2274 | } finally { |
| 2275 | Binder.restoreCallingIdentity(identity); |
| 2276 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2277 | } |
| 2278 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2279 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2280 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2281 | |
| 2282 | final long identity = Binder.clearCallingIdentity(); |
| 2283 | try { |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2284 | Phone phone = getPhone(subId); |
| 2285 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2286 | checkSimPuk.start(); |
| 2287 | return checkSimPuk.unlockSim(puk, pin); |
| 2288 | } finally { |
| 2289 | Binder.restoreCallingIdentity(identity); |
| 2290 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2291 | } |
| 2292 | |
| 2293 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2294 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2295 | * a synchronous one. |
| 2296 | */ |
| 2297 | private static class UnlockSim extends Thread { |
| 2298 | |
| 2299 | private final IccCard mSimCard; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2300 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2301 | |
| 2302 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2303 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2304 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2305 | |
| 2306 | // For replies from SimCard interface |
| 2307 | private Handler mHandler; |
| 2308 | |
| 2309 | // For async handler to identify request type |
| 2310 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2311 | |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2312 | UnlockSim(int phoneId, IccCard simCard) { |
| 2313 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2314 | mSimCard = simCard; |
| 2315 | } |
| 2316 | |
| 2317 | @Override |
| 2318 | public void run() { |
| 2319 | Looper.prepare(); |
| 2320 | synchronized (UnlockSim.this) { |
| 2321 | mHandler = new Handler() { |
| 2322 | @Override |
| 2323 | public void handleMessage(Message msg) { |
| 2324 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2325 | switch (msg.what) { |
| 2326 | case SUPPLY_PIN_COMPLETE: |
| 2327 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2328 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2329 | mRetryCount = msg.arg1; |
| 2330 | if (ar.exception != null) { |
| 2331 | if (ar.exception instanceof CommandException && |
| 2332 | ((CommandException)(ar.exception)).getCommandError() |
| 2333 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2334 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2335 | } //When UiccCardApp dispose,handle message and return exception |
| 2336 | else if (ar.exception instanceof CommandException && |
| 2337 | ((CommandException) (ar.exception)).getCommandError() |
| 2338 | == CommandException.Error.ABORTED) { |
| 2339 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2340 | } else { |
| 2341 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2342 | } |
| 2343 | } else { |
| 2344 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2345 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2346 | mDone = true; |
| 2347 | UnlockSim.this.notifyAll(); |
| 2348 | } |
| 2349 | break; |
| 2350 | } |
| 2351 | } |
| 2352 | }; |
| 2353 | UnlockSim.this.notifyAll(); |
| 2354 | } |
| 2355 | Looper.loop(); |
| 2356 | } |
| 2357 | |
| 2358 | /* |
| 2359 | * Use PIN or PUK to unlock SIM card |
| 2360 | * |
| 2361 | * If PUK is null, unlock SIM card with PIN |
| 2362 | * |
| 2363 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2364 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2365 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2366 | |
| 2367 | while (mHandler == null) { |
| 2368 | try { |
| 2369 | wait(); |
| 2370 | } catch (InterruptedException e) { |
| 2371 | Thread.currentThread().interrupt(); |
| 2372 | } |
| 2373 | } |
| 2374 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2375 | |
| 2376 | if (puk == null) { |
| 2377 | mSimCard.supplyPin(pin, callback); |
| 2378 | } else { |
| 2379 | mSimCard.supplyPuk(puk, pin, callback); |
| 2380 | } |
| 2381 | |
| 2382 | while (!mDone) { |
| 2383 | try { |
| 2384 | Log.d(LOG_TAG, "wait for done"); |
| 2385 | wait(); |
| 2386 | } catch (InterruptedException e) { |
| 2387 | // Restore the interrupted status |
| 2388 | Thread.currentThread().interrupt(); |
| 2389 | } |
| 2390 | } |
| 2391 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2392 | int[] resultArray = new int[2]; |
| 2393 | resultArray[0] = mResult; |
| 2394 | resultArray[1] = mRetryCount; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2395 | |
| 2396 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
| 2397 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
| 2398 | } |
| 2399 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2400 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2401 | } |
| 2402 | } |
| 2403 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2404 | /** |
| 2405 | * This method has been removed due to privacy and stability concerns. |
| 2406 | */ |
| 2407 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2408 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2409 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2410 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2411 | } |
| 2412 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2413 | @Override |
| 2414 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2415 | mApp.getSystemService(AppOpsManager.class) |
| 2416 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2417 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2418 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2419 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2420 | // Callers targeting S have no business invoking this method. |
| 2421 | return; |
| 2422 | } |
| 2423 | |
| 2424 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2425 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2426 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2427 | .setCallingPackage(callingPackage) |
| 2428 | .setCallingFeatureId(null) |
| 2429 | .setCallingPid(Binder.getCallingPid()) |
| 2430 | .setCallingUid(Binder.getCallingUid()) |
| 2431 | .setMethod("updateServiceLocation") |
| 2432 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2433 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2434 | .build()); |
| 2435 | // Apps that lack location permission have no business calling this method; |
| 2436 | // however, because no permission was declared in the public API, denials must |
| 2437 | // all be "soft". |
| 2438 | switch (locationResult) { |
| 2439 | case DENIED_HARD: /* fall through */ |
| 2440 | case DENIED_SOFT: |
| 2441 | return; |
| 2442 | } |
| 2443 | |
| 2444 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2445 | final long identity = Binder.clearCallingIdentity(); |
| 2446 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2447 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2448 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2449 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2450 | } |
| 2451 | } finally { |
| 2452 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2453 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2454 | } |
| 2455 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2456 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2457 | @Override |
| 2458 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2459 | return isRadioOnWithFeature(callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2460 | } |
| 2461 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2462 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2463 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2464 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2465 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2466 | callingFeatureId); |
| 2467 | } |
| 2468 | |
| 2469 | @Deprecated |
| 2470 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2471 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2472 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
| 2473 | } |
| 2474 | |
| 2475 | @Override |
| 2476 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2477 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2478 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2479 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2480 | return false; |
| 2481 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2482 | |
| 2483 | final long identity = Binder.clearCallingIdentity(); |
| 2484 | try { |
| 2485 | return isRadioOnForSubscriber(subId); |
| 2486 | } finally { |
| 2487 | Binder.restoreCallingIdentity(identity); |
| 2488 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2489 | } |
| 2490 | |
| 2491 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2492 | final long identity = Binder.clearCallingIdentity(); |
| 2493 | try { |
| 2494 | final Phone phone = getPhone(subId); |
| 2495 | if (phone != null) { |
| 2496 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2497 | } else { |
| 2498 | return false; |
| 2499 | } |
| 2500 | } finally { |
| 2501 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2502 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2503 | } |
| 2504 | |
| 2505 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2506 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2507 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2508 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2509 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2510 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2511 | |
| 2512 | final long identity = Binder.clearCallingIdentity(); |
| 2513 | try { |
| 2514 | final Phone phone = getPhone(subId); |
| 2515 | if (phone != null) { |
| 2516 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2517 | } |
| 2518 | } finally { |
| 2519 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2520 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2521 | } |
| 2522 | |
| 2523 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2524 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2525 | } |
| 2526 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2527 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2528 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2529 | |
| 2530 | final long identity = Binder.clearCallingIdentity(); |
| 2531 | try { |
| 2532 | final Phone phone = getPhone(subId); |
| 2533 | if (phone == null) { |
| 2534 | return false; |
| 2535 | } |
| 2536 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2537 | toggleRadioOnOffForSubscriber(subId); |
| 2538 | } |
| 2539 | return true; |
| 2540 | } finally { |
| 2541 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2542 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2543 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2544 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2545 | public boolean needMobileRadioShutdown() { |
Shuo Qian | afeaf7d | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2546 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2547 | /* |
| 2548 | * If any of the Radios are available, it will need to be |
| 2549 | * shutdown. So return true if any Radio is available. |
| 2550 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2551 | final long identity = Binder.clearCallingIdentity(); |
| 2552 | try { |
| 2553 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2554 | Phone phone = PhoneFactory.getPhone(i); |
| 2555 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2556 | } |
| 2557 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2558 | return false; |
| 2559 | } finally { |
| 2560 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2561 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2562 | } |
| 2563 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2564 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2565 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2566 | enforceModifyPermission(); |
| 2567 | |
| 2568 | final long identity = Binder.clearCallingIdentity(); |
| 2569 | try { |
| 2570 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2571 | logv("Shutting down Phone " + i); |
| 2572 | shutdownRadioUsingPhoneId(i); |
| 2573 | } |
| 2574 | } finally { |
| 2575 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2576 | } |
| 2577 | } |
| 2578 | |
| 2579 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2580 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2581 | if (phone != null && phone.isRadioAvailable()) { |
| 2582 | phone.shutdownRadio(); |
| 2583 | } |
| 2584 | } |
| 2585 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2586 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2587 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2588 | |
| 2589 | final long identity = Binder.clearCallingIdentity(); |
| 2590 | try { |
| 2591 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2592 | if (defaultPhone != null) { |
| 2593 | defaultPhone.setRadioPower(turnOn); |
| 2594 | return true; |
| 2595 | } else { |
| 2596 | loge("There's no default phone."); |
| 2597 | return false; |
| 2598 | } |
| 2599 | } finally { |
| 2600 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2601 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2602 | } |
| 2603 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2604 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2605 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2606 | |
| 2607 | final long identity = Binder.clearCallingIdentity(); |
| 2608 | try { |
| 2609 | final Phone phone = getPhone(subId); |
| 2610 | if (phone != null) { |
| 2611 | phone.setRadioPower(turnOn); |
| 2612 | return true; |
| 2613 | } else { |
| 2614 | return false; |
| 2615 | } |
| 2616 | } finally { |
| 2617 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2618 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2619 | } |
| 2620 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2621 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2622 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2623 | public boolean enableDataConnectivity() { |
| 2624 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2625 | |
| 2626 | final long identity = Binder.clearCallingIdentity(); |
| 2627 | try { |
| 2628 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2629 | final Phone phone = getPhone(subId); |
| 2630 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2631 | phone.getDataEnabledSettings().setDataEnabled( |
| 2632 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2633 | return true; |
| 2634 | } else { |
| 2635 | return false; |
| 2636 | } |
| 2637 | } finally { |
| 2638 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2639 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2640 | } |
| 2641 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2642 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2643 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2644 | public boolean disableDataConnectivity() { |
| 2645 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2646 | |
| 2647 | final long identity = Binder.clearCallingIdentity(); |
| 2648 | try { |
| 2649 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2650 | final Phone phone = getPhone(subId); |
| 2651 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2652 | phone.getDataEnabledSettings().setDataEnabled( |
| 2653 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2654 | return true; |
| 2655 | } else { |
| 2656 | return false; |
| 2657 | } |
| 2658 | } finally { |
| 2659 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2660 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2661 | } |
| 2662 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2663 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2664 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2665 | final long identity = Binder.clearCallingIdentity(); |
| 2666 | try { |
| 2667 | final Phone phone = getPhone(subId); |
| 2668 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2669 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2670 | } else { |
| 2671 | return false; |
| 2672 | } |
| 2673 | } finally { |
| 2674 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2675 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2676 | } |
| 2677 | |
| 2678 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2679 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2680 | } |
| 2681 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2682 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2683 | enforceCallPermission(); |
| 2684 | |
| 2685 | final long identity = Binder.clearCallingIdentity(); |
| 2686 | try { |
| 2687 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2688 | return; |
| 2689 | } |
| 2690 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2691 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2692 | } finally { |
| 2693 | Binder.restoreCallingIdentity(identity); |
| 2694 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2695 | }; |
| 2696 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2697 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2698 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2699 | |
| 2700 | final long identity = Binder.clearCallingIdentity(); |
| 2701 | try { |
| 2702 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2703 | return false; |
| 2704 | } |
| 2705 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2706 | } finally { |
| 2707 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2708 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2709 | } |
| 2710 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2711 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2712 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2713 | } |
| 2714 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2715 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2716 | final long identity = Binder.clearCallingIdentity(); |
| 2717 | try { |
| 2718 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2719 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2720 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2721 | } finally { |
| 2722 | Binder.restoreCallingIdentity(identity); |
| 2723 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2724 | } |
| 2725 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2726 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2727 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2728 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2729 | } |
| 2730 | |
| 2731 | @Override |
| 2732 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2733 | final long identity = Binder.clearCallingIdentity(); |
| 2734 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2735 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2736 | if (phone != null) { |
| 2737 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2738 | } else { |
| 2739 | return PhoneConstantConversions.convertDataState( |
| 2740 | PhoneConstants.DataState.DISCONNECTED); |
| 2741 | } |
| 2742 | } finally { |
| 2743 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2744 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2745 | } |
| 2746 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2747 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2748 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2749 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2750 | } |
| 2751 | |
| 2752 | @Override |
| 2753 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2754 | final long identity = Binder.clearCallingIdentity(); |
| 2755 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2756 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2757 | if (phone != null) { |
| 2758 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2759 | } else { |
| 2760 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2761 | } |
| 2762 | } finally { |
| 2763 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2764 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2765 | } |
| 2766 | |
| 2767 | @Override |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2768 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2769 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2770 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2771 | |
| 2772 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2773 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2774 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2775 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2776 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2777 | .setCallingPid(Binder.getCallingPid()) |
| 2778 | .setCallingUid(Binder.getCallingUid()) |
| 2779 | .setMethod("getCellLocation") |
Hall Liu | c3f8eb6 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2780 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2781 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2782 | .build()); |
| 2783 | switch (locationResult) { |
| 2784 | case DENIED_HARD: |
| 2785 | throw new SecurityException("Not allowed to access cell location"); |
| 2786 | case DENIED_SOFT: |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2787 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2788 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2789 | } |
| 2790 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2791 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2792 | final long identity = Binder.clearCallingIdentity(); |
| 2793 | try { |
| 2794 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2795 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2796 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2797 | } finally { |
| 2798 | Binder.restoreCallingIdentity(identity); |
| 2799 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2800 | } |
| 2801 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2802 | @Override |
Jack Yu | 0142503 | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2803 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2804 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2805 | // registered cell info, so return a NULL country instead. |
| 2806 | final long identity = Binder.clearCallingIdentity(); |
| 2807 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2808 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2809 | // Get default phone in this case. |
| 2810 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2811 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2812 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2813 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | cf38ed9 | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2814 | if (phone == null) return ""; |
| 2815 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2816 | if (sst == null) return ""; |
| 2817 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2818 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 2819 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2820 | } finally { |
| 2821 | Binder.restoreCallingIdentity(identity); |
| 2822 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2823 | } |
| 2824 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2825 | /** |
| 2826 | * This method was removed due to potential issues caused by performing partial |
| 2827 | * updates of service state, and lack of a credible use case. |
| 2828 | * |
| 2829 | * This has the ability to break the telephony implementation by disabling notification of |
| 2830 | * changes in device connectivity. DO NOT USE THIS! |
| 2831 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2832 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2833 | public void enableLocationUpdates() { |
| 2834 | mApp.enforceCallingOrSelfPermission( |
| 2835 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2836 | } |
| 2837 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2838 | /** |
| 2839 | * This method was removed due to potential issues caused by performing partial |
| 2840 | * updates of service state, and lack of a credible use case. |
| 2841 | * |
| 2842 | * This has the ability to break the telephony implementation by disabling notification of |
| 2843 | * changes in device connectivity. DO NOT USE THIS! |
| 2844 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2845 | @Override |
| 2846 | public void disableLocationUpdates() { |
| 2847 | mApp.enforceCallingOrSelfPermission( |
| 2848 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2849 | } |
| 2850 | |
| 2851 | @Override |
| 2852 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2853 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2854 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2855 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2856 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2857 | throw new SecurityException( |
| 2858 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2859 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2860 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2861 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2862 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2863 | return null; |
| 2864 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2865 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2866 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2867 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2868 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2869 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2870 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2871 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2872 | for (CellInfo ci : info) { |
| 2873 | if (ci instanceof CellInfoGsm) { |
| 2874 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2875 | } else if (ci instanceof CellInfoWcdma) { |
| 2876 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2877 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2878 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2879 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2880 | } |
| 2881 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2882 | private List<CellInfo> getCachedCellInfo() { |
| 2883 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2884 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2885 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2886 | if (info != null) cellInfos.addAll(info); |
| 2887 | } |
| 2888 | return cellInfos; |
| 2889 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2890 | |
| 2891 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2892 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2893 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2894 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2895 | |
| 2896 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2897 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2898 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2899 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2900 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2901 | .setCallingPid(Binder.getCallingPid()) |
| 2902 | .setCallingUid(Binder.getCallingUid()) |
| 2903 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2904 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2905 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2906 | .build()); |
| 2907 | switch (locationResult) { |
| 2908 | case DENIED_HARD: |
| 2909 | throw new SecurityException("Not allowed to access cell info"); |
| 2910 | case DENIED_SOFT: |
| 2911 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2912 | } |
| 2913 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2914 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2915 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2916 | return getCachedCellInfo(); |
| 2917 | } |
| 2918 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2919 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2920 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2921 | final long identity = Binder.clearCallingIdentity(); |
| 2922 | try { |
| 2923 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2924 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2925 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2926 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2927 | if (info != null) cellInfos.addAll(info); |
| 2928 | } |
| 2929 | return cellInfos; |
| 2930 | } finally { |
| 2931 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2932 | } |
| 2933 | } |
| 2934 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2935 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2936 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2937 | String callingFeatureId) { |
| 2938 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2939 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2940 | } |
| 2941 | |
| 2942 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2943 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2944 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2945 | enforceModifyPermission(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2946 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2947 | } |
| 2948 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2949 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2950 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2951 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2952 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2953 | |
| 2954 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2955 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2956 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2957 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2958 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2959 | .setCallingPid(Binder.getCallingPid()) |
| 2960 | .setCallingUid(Binder.getCallingUid()) |
| 2961 | .setMethod("requestCellInfoUpdate") |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2962 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2963 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2964 | .build()); |
| 2965 | switch (locationResult) { |
| 2966 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2967 | if (TelephonyPermissions |
| 2968 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2969 | // Safetynet logging for b/154934934 |
| 2970 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2971 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2972 | throw new SecurityException("Not allowed to access cell info"); |
| 2973 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2974 | if (TelephonyPermissions |
| 2975 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2976 | // Safetynet logging for b/154934934 |
| 2977 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2978 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2979 | try { |
| 2980 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2981 | } catch (RemoteException re) { |
| 2982 | // Drop without consequences |
| 2983 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2984 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2985 | } |
| 2986 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2987 | |
| 2988 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2989 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2990 | |
| 2991 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2992 | } |
| 2993 | |
| 2994 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2995 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2996 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2997 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2998 | |
| 2999 | final long identity = Binder.clearCallingIdentity(); |
| 3000 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3001 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3002 | } finally { |
| 3003 | Binder.restoreCallingIdentity(identity); |
| 3004 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3005 | } |
| 3006 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3007 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3008 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3009 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3010 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3011 | return null; |
| 3012 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3013 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3014 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3015 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3016 | return null; |
| 3017 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3018 | |
| 3019 | final long identity = Binder.clearCallingIdentity(); |
| 3020 | try { |
| 3021 | return phone.getImei(); |
| 3022 | } finally { |
| 3023 | Binder.restoreCallingIdentity(identity); |
| 3024 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3025 | } |
| 3026 | |
| 3027 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3028 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3029 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3030 | String tac = null; |
| 3031 | if (phone != null) { |
| 3032 | String imei = phone.getImei(); |
| 3033 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3034 | } |
| 3035 | return tac; |
| 3036 | } |
| 3037 | |
| 3038 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3039 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3040 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3041 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3042 | return null; |
| 3043 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3044 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3045 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3046 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3047 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3048 | return null; |
| 3049 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3050 | |
| 3051 | final long identity = Binder.clearCallingIdentity(); |
| 3052 | try { |
| 3053 | return phone.getMeid(); |
| 3054 | } finally { |
| 3055 | Binder.restoreCallingIdentity(identity); |
| 3056 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3057 | } |
| 3058 | |
| 3059 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3060 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3061 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3062 | String manufacturerCode = null; |
| 3063 | if (phone != null) { |
| 3064 | String meid = phone.getMeid(); |
| 3065 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3066 | } |
| 3067 | return manufacturerCode; |
| 3068 | } |
| 3069 | |
| 3070 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3071 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3072 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3073 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3074 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3075 | return null; |
| 3076 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3077 | int subId = phone.getSubId(); |
| 3078 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3079 | mApp, subId, callingPackage, callingFeatureId, |
| 3080 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3081 | return null; |
| 3082 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3083 | |
| 3084 | final long identity = Binder.clearCallingIdentity(); |
| 3085 | try { |
| 3086 | return phone.getDeviceSvn(); |
| 3087 | } finally { |
| 3088 | Binder.restoreCallingIdentity(identity); |
| 3089 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3090 | } |
| 3091 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3092 | @Override |
| 3093 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3094 | final long identity = Binder.clearCallingIdentity(); |
| 3095 | try { |
| 3096 | final Phone phone = getPhone(subId); |
| 3097 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3098 | } finally { |
| 3099 | Binder.restoreCallingIdentity(identity); |
| 3100 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3101 | } |
| 3102 | |
| 3103 | @Override |
| 3104 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3105 | final long identity = Binder.clearCallingIdentity(); |
| 3106 | try { |
| 3107 | final Phone phone = getPhone(subId); |
| 3108 | return phone == null ? null : phone.getCarrierName(); |
| 3109 | } finally { |
| 3110 | Binder.restoreCallingIdentity(identity); |
| 3111 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3112 | } |
| 3113 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3114 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3115 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3116 | final long identity = Binder.clearCallingIdentity(); |
| 3117 | try { |
| 3118 | final Phone phone = getPhone(subId); |
| 3119 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3120 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3121 | } finally { |
| 3122 | Binder.restoreCallingIdentity(identity); |
| 3123 | } |
| 3124 | } |
| 3125 | |
| 3126 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3127 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3128 | final long identity = Binder.clearCallingIdentity(); |
| 3129 | try { |
| 3130 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3131 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3132 | } finally { |
| 3133 | Binder.restoreCallingIdentity(identity); |
| 3134 | } |
| 3135 | } |
| 3136 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3137 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3138 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3139 | if (!isSubscriptionMccMnc) { |
| 3140 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3141 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3142 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3143 | if (phone == null) { |
| 3144 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3145 | } |
| 3146 | final long identity = Binder.clearCallingIdentity(); |
| 3147 | try { |
| 3148 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3149 | } finally { |
| 3150 | Binder.restoreCallingIdentity(identity); |
| 3151 | } |
| 3152 | } |
| 3153 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3154 | // |
| 3155 | // Internal helper methods. |
| 3156 | // |
| 3157 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3158 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3159 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3160 | * |
| 3161 | * @throws SecurityException if the caller does not have the required permission |
| 3162 | */ |
| 3163 | private void enforceModifyPermission() { |
| 3164 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3165 | } |
| 3166 | |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3167 | /** |
| 3168 | * Make sure the caller is system. |
| 3169 | * |
| 3170 | * @throws SecurityException if the caller is not system. |
| 3171 | */ |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 3172 | private static void enforceSystemCaller() { |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3173 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 3174 | throw new SecurityException("Caller must be system"); |
| 3175 | } |
| 3176 | } |
| 3177 | |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3178 | private void enforceActiveEmergencySessionPermission() { |
| 3179 | mApp.enforceCallingOrSelfPermission( |
| 3180 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3181 | } |
| 3182 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3183 | /** |
| 3184 | * Make sure the caller has the CALL_PHONE permission. |
| 3185 | * |
| 3186 | * @throws SecurityException if the caller does not have the required permission |
| 3187 | */ |
| 3188 | private void enforceCallPermission() { |
| 3189 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3190 | } |
| 3191 | |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3192 | private void enforceSettingsPermission() { |
| 3193 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3194 | } |
| 3195 | |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3196 | private void enforceRebootPermission() { |
| 3197 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3198 | } |
| 3199 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3200 | private String createTelUrl(String number) { |
| 3201 | if (TextUtils.isEmpty(number)) { |
| 3202 | return null; |
| 3203 | } |
| 3204 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3205 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3206 | } |
| 3207 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3208 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3209 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3210 | } |
| 3211 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3212 | private static void logv(String msg) { |
| 3213 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3214 | } |
| 3215 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3216 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3217 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3218 | } |
| 3219 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3220 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3221 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3222 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3223 | } |
| 3224 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3225 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3226 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3227 | final long identity = Binder.clearCallingIdentity(); |
| 3228 | try { |
| 3229 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3230 | if (phone == null) { |
| 3231 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3232 | } else { |
| 3233 | return phone.getPhoneType(); |
| 3234 | } |
| 3235 | } finally { |
| 3236 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3237 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3238 | } |
| 3239 | |
| 3240 | /** |
| 3241 | * Returns the CDMA ERI icon index to display |
| 3242 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3243 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3244 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3245 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3246 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3247 | } |
| 3248 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3249 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3250 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3251 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3252 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3253 | mApp, subId, callingPackage, callingFeatureId, |
| 3254 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3255 | return -1; |
| 3256 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3257 | |
| 3258 | final long identity = Binder.clearCallingIdentity(); |
| 3259 | try { |
| 3260 | final Phone phone = getPhone(subId); |
| 3261 | if (phone != null) { |
| 3262 | return phone.getCdmaEriIconIndex(); |
| 3263 | } else { |
| 3264 | return -1; |
| 3265 | } |
| 3266 | } finally { |
| 3267 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3268 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3269 | } |
| 3270 | |
| 3271 | /** |
| 3272 | * Returns the CDMA ERI icon mode, |
| 3273 | * 0 - ON |
| 3274 | * 1 - FLASHING |
| 3275 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3276 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3277 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3278 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3279 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3280 | } |
| 3281 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3282 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3283 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3284 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3285 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3286 | mApp, subId, callingPackage, callingFeatureId, |
| 3287 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3288 | return -1; |
| 3289 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3290 | |
| 3291 | final long identity = Binder.clearCallingIdentity(); |
| 3292 | try { |
| 3293 | final Phone phone = getPhone(subId); |
| 3294 | if (phone != null) { |
| 3295 | return phone.getCdmaEriIconMode(); |
| 3296 | } else { |
| 3297 | return -1; |
| 3298 | } |
| 3299 | } finally { |
| 3300 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3301 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3302 | } |
| 3303 | |
| 3304 | /** |
| 3305 | * Returns the CDMA ERI text, |
| 3306 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3307 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3308 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3309 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3310 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3311 | } |
| 3312 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3313 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3314 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3315 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3316 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3317 | mApp, subId, callingPackage, callingFeatureId, |
| 3318 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3319 | return null; |
| 3320 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3321 | |
| 3322 | final long identity = Binder.clearCallingIdentity(); |
| 3323 | try { |
| 3324 | final Phone phone = getPhone(subId); |
| 3325 | if (phone != null) { |
| 3326 | return phone.getCdmaEriText(); |
| 3327 | } else { |
| 3328 | return null; |
| 3329 | } |
| 3330 | } finally { |
| 3331 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3332 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3333 | } |
| 3334 | |
| 3335 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3336 | * Returns the CDMA MDN. |
| 3337 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3338 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3339 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3340 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3341 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3342 | |
| 3343 | final long identity = Binder.clearCallingIdentity(); |
| 3344 | try { |
| 3345 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3346 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3347 | return phone.getLine1Number(); |
| 3348 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3349 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3350 | return null; |
| 3351 | } |
| 3352 | } finally { |
| 3353 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3354 | } |
| 3355 | } |
| 3356 | |
| 3357 | /** |
| 3358 | * Returns the CDMA MIN. |
| 3359 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3360 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3361 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3362 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3363 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3364 | |
| 3365 | final long identity = Binder.clearCallingIdentity(); |
| 3366 | try { |
| 3367 | final Phone phone = getPhone(subId); |
| 3368 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3369 | return phone.getCdmaMin(); |
| 3370 | } else { |
| 3371 | return null; |
| 3372 | } |
| 3373 | } finally { |
| 3374 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3375 | } |
| 3376 | } |
| 3377 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3378 | @Override |
| 3379 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3380 | INumberVerificationCallback callback, String callingPackage) { |
| 3381 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3382 | != PERMISSION_GRANTED) { |
| 3383 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3384 | } |
| 3385 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3386 | |
| 3387 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3388 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3389 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3390 | + "calling package: " + callingPackage |
| 3391 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3392 | } |
| 3393 | |
| 3394 | if (range == null) { |
| 3395 | throw new NullPointerException("Range must be non-null"); |
| 3396 | } |
| 3397 | |
| 3398 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3399 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3400 | |
| 3401 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3402 | } |
| 3403 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3404 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3405 | * Returns true if CDMA provisioning needs to run. |
| 3406 | */ |
| 3407 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3408 | final long identity = Binder.clearCallingIdentity(); |
| 3409 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3410 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3411 | } finally { |
| 3412 | Binder.restoreCallingIdentity(identity); |
| 3413 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3414 | } |
| 3415 | |
| 3416 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3417 | * Sets the voice mail number of a given subId. |
| 3418 | */ |
| 3419 | @Override |
| 3420 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3421 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3422 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3423 | |
| 3424 | final long identity = Binder.clearCallingIdentity(); |
| 3425 | try { |
| 3426 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3427 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3428 | return success; |
| 3429 | } finally { |
| 3430 | Binder.restoreCallingIdentity(identity); |
| 3431 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3432 | } |
| 3433 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3434 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3435 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3436 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3437 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3438 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3439 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3440 | throw new SecurityException("caller must be system dialer"); |
| 3441 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3442 | |
| 3443 | final long identity = Binder.clearCallingIdentity(); |
| 3444 | try { |
| 3445 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3446 | if (phoneAccountHandle == null) { |
| 3447 | return null; |
| 3448 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3449 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3450 | } finally { |
| 3451 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3452 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3453 | } |
| 3454 | |
| 3455 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3456 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3457 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3458 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3459 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3460 | mApp, subId, callingPackage, callingFeatureId, |
| 3461 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3462 | return null; |
| 3463 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3464 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3465 | final long identity = Binder.clearCallingIdentity(); |
| 3466 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3467 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3468 | } finally { |
| 3469 | Binder.restoreCallingIdentity(identity); |
| 3470 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3471 | } |
| 3472 | |
| 3473 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3474 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3475 | VisualVoicemailSmsFilterSettings settings) { |
| 3476 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3477 | |
| 3478 | final long identity = Binder.clearCallingIdentity(); |
| 3479 | try { |
| 3480 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3481 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3482 | } finally { |
| 3483 | Binder.restoreCallingIdentity(identity); |
| 3484 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3485 | } |
| 3486 | |
| 3487 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3488 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3489 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3490 | |
| 3491 | final long identity = Binder.clearCallingIdentity(); |
| 3492 | try { |
| 3493 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3494 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3495 | } finally { |
| 3496 | Binder.restoreCallingIdentity(identity); |
| 3497 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3498 | } |
| 3499 | |
| 3500 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3501 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3502 | String callingPackage, int subId) { |
| 3503 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3504 | |
| 3505 | final long identity = Binder.clearCallingIdentity(); |
| 3506 | try { |
| 3507 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3508 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3509 | } finally { |
| 3510 | Binder.restoreCallingIdentity(identity); |
| 3511 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3512 | } |
| 3513 | |
| 3514 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3515 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3516 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3517 | |
| 3518 | final long identity = Binder.clearCallingIdentity(); |
| 3519 | try { |
| 3520 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3521 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3522 | } finally { |
| 3523 | Binder.restoreCallingIdentity(identity); |
| 3524 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3525 | } |
| 3526 | |
| 3527 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3528 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3529 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3530 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3531 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3532 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3533 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3534 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3535 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3536 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3537 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3538 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3539 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3540 | * Sets the voice activation state of a given subId. |
| 3541 | */ |
| 3542 | @Override |
| 3543 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3544 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3545 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3546 | |
| 3547 | final long identity = Binder.clearCallingIdentity(); |
| 3548 | try { |
| 3549 | final Phone phone = getPhone(subId); |
| 3550 | if (phone != null) { |
| 3551 | phone.setVoiceActivationState(activationState); |
| 3552 | } else { |
| 3553 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3554 | } |
| 3555 | } finally { |
| 3556 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3557 | } |
| 3558 | } |
| 3559 | |
| 3560 | /** |
| 3561 | * Sets the data activation state of a given subId. |
| 3562 | */ |
| 3563 | @Override |
| 3564 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3565 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3566 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3567 | |
| 3568 | final long identity = Binder.clearCallingIdentity(); |
| 3569 | try { |
| 3570 | final Phone phone = getPhone(subId); |
| 3571 | if (phone != null) { |
| 3572 | phone.setDataActivationState(activationState); |
| 3573 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3574 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3575 | } |
| 3576 | } finally { |
| 3577 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3578 | } |
| 3579 | } |
| 3580 | |
| 3581 | /** |
| 3582 | * Returns the voice activation state of a given subId. |
| 3583 | */ |
| 3584 | @Override |
| 3585 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3586 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3587 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3588 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3589 | final long identity = Binder.clearCallingIdentity(); |
| 3590 | try { |
| 3591 | if (phone != null) { |
| 3592 | return phone.getVoiceActivationState(); |
| 3593 | } else { |
| 3594 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3595 | } |
| 3596 | } finally { |
| 3597 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3598 | } |
| 3599 | } |
| 3600 | |
| 3601 | /** |
| 3602 | * Returns the data activation state of a given subId. |
| 3603 | */ |
| 3604 | @Override |
| 3605 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3606 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3607 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3608 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3609 | final long identity = Binder.clearCallingIdentity(); |
| 3610 | try { |
| 3611 | if (phone != null) { |
| 3612 | return phone.getDataActivationState(); |
| 3613 | } else { |
| 3614 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3615 | } |
| 3616 | } finally { |
| 3617 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3618 | } |
| 3619 | } |
| 3620 | |
| 3621 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3622 | * Returns the unread count of voicemails for a subId |
| 3623 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3624 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3625 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3626 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3627 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3628 | mApp, subId, callingPackage, callingFeatureId, |
| 3629 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3630 | return 0; |
| 3631 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3632 | final long identity = Binder.clearCallingIdentity(); |
| 3633 | try { |
| 3634 | final Phone phone = getPhone(subId); |
| 3635 | if (phone != null) { |
| 3636 | return phone.getVoiceMessageCount(); |
| 3637 | } else { |
| 3638 | return 0; |
| 3639 | } |
| 3640 | } finally { |
| 3641 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3642 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3643 | } |
| 3644 | |
| 3645 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3646 | * returns true, if the device is in a state where both voice and data |
| 3647 | * are supported simultaneously. This can change based on location or network condition. |
| 3648 | */ |
| 3649 | @Override |
| 3650 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3651 | final long identity = Binder.clearCallingIdentity(); |
| 3652 | try { |
| 3653 | final Phone phone = getPhone(subId); |
| 3654 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3655 | } finally { |
| 3656 | Binder.restoreCallingIdentity(identity); |
| 3657 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3658 | } |
| 3659 | |
| 3660 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3661 | * Send the dialer code if called from the current default dialer or the caller has |
| 3662 | * carrier privilege. |
| 3663 | * @param inputCode The dialer code to send |
| 3664 | */ |
| 3665 | @Override |
| 3666 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3667 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3668 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3669 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3670 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3671 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3672 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3673 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3674 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3675 | |
| 3676 | final long identity = Binder.clearCallingIdentity(); |
| 3677 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3678 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3679 | } finally { |
| 3680 | Binder.restoreCallingIdentity(identity); |
| 3681 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3682 | } |
| 3683 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3684 | @Override |
| 3685 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3686 | TelephonyPermissions |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3687 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3688 | mApp, subId, "getNetworkSelectionMode"); |
| 3689 | final long identity = Binder.clearCallingIdentity(); |
| 3690 | try { |
| 3691 | if (!isActiveSubscription(subId)) { |
| 3692 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3693 | } |
| 3694 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3695 | } finally { |
| 3696 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3697 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3698 | } |
| 3699 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3700 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3701 | public boolean isInEmergencySmsMode() { |
| 3702 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3703 | final long identity = Binder.clearCallingIdentity(); |
| 3704 | try { |
| 3705 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3706 | if (phone.isInEmergencySmsMode()) { |
| 3707 | return true; |
| 3708 | } |
| 3709 | } |
| 3710 | } finally { |
| 3711 | Binder.restoreCallingIdentity(identity); |
| 3712 | } |
| 3713 | return false; |
| 3714 | } |
| 3715 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3716 | /** |
| 3717 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3718 | * @param subId The subscription to use to check the configuration. |
| 3719 | * @param c The callback that will be used to send the result. |
| 3720 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3721 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3722 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3723 | throws RemoteException { |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3724 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3725 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3726 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3727 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3728 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3729 | "IMS not available on device."); |
| 3730 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3731 | final long token = Binder.clearCallingIdentity(); |
| 3732 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3733 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3734 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3735 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3736 | } catch (ImsException e) { |
| 3737 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3738 | } finally { |
| 3739 | Binder.restoreCallingIdentity(token); |
| 3740 | } |
| 3741 | } |
| 3742 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3743 | /** |
| 3744 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3745 | * @param subId The subscription to use to check the configuration. |
| 3746 | * @param c The callback that will be used to send the result. |
| 3747 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3748 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3749 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3750 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3751 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3752 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3753 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3754 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3755 | final long token = Binder.clearCallingIdentity(); |
| 3756 | try { |
| 3757 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3758 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3759 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3760 | } catch (ImsException e) { |
| 3761 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3762 | + "is inactive, ignoring unregister."); |
| 3763 | // If the subscription is no longer active, just return, since the callback |
| 3764 | // will already have been removed internally. |
| 3765 | } finally { |
| 3766 | Binder.restoreCallingIdentity(token); |
| 3767 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3768 | } |
| 3769 | |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3770 | /** |
| 3771 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3772 | */ |
| 3773 | @Override |
| 3774 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3775 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3776 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3777 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3778 | "IMS not available on device."); |
| 3779 | } |
| 3780 | final long token = Binder.clearCallingIdentity(); |
| 3781 | try { |
| 3782 | Phone phone = getPhone(subId); |
| 3783 | if (phone == null) { |
| 3784 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3785 | + subId + "'"); |
| 3786 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3787 | } |
| 3788 | phone.getImsRegistrationState(regState -> { |
| 3789 | try { |
| 3790 | consumer.accept((regState == null) |
| 3791 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3792 | } catch (RemoteException e) { |
| 3793 | // Ignore if the remote process is no longer available to call back. |
| 3794 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3795 | } |
| 3796 | }); |
| 3797 | } finally { |
| 3798 | Binder.restoreCallingIdentity(token); |
| 3799 | } |
| 3800 | } |
| 3801 | |
| 3802 | /** |
| 3803 | * Get the transport type for the IMS service registration state. |
| 3804 | */ |
| 3805 | @Override |
| 3806 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3807 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3808 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3809 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3810 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3811 | "IMS not available on device."); |
| 3812 | } |
| 3813 | final long token = Binder.clearCallingIdentity(); |
| 3814 | try { |
| 3815 | Phone phone = getPhone(subId); |
| 3816 | if (phone == null) { |
| 3817 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3818 | + subId + "'"); |
| 3819 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3820 | } |
| 3821 | phone.getImsRegistrationTech(regTech -> { |
| 3822 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3823 | int regTechConverted = (regTech == null) |
| 3824 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3825 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3826 | regTechConverted); |
| 3827 | try { |
| 3828 | consumer.accept(regTechConverted); |
| 3829 | } catch (RemoteException e) { |
| 3830 | // Ignore if the remote process is no longer available to call back. |
| 3831 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3832 | } |
| 3833 | }); |
| 3834 | } finally { |
| 3835 | Binder.restoreCallingIdentity(token); |
| 3836 | } |
| 3837 | } |
| 3838 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3839 | /** |
| 3840 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3841 | * @param subId The subscription to use to check the configuration. |
| 3842 | * @param c The callback that will be used to send the result. |
| 3843 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3844 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3845 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3846 | throws RemoteException { |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3847 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3848 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3849 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3850 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3851 | "IMS not available on device."); |
| 3852 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3853 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3854 | final long token = Binder.clearCallingIdentity(); |
| 3855 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3856 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3857 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3858 | } catch (ImsException e) { |
| 3859 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3860 | } finally { |
| 3861 | Binder.restoreCallingIdentity(token); |
| 3862 | } |
| 3863 | } |
| 3864 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3865 | /** |
| 3866 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3867 | * @param subId The subscription to use to check the configuration. |
| 3868 | * @param c The callback that will be used to send the result. |
| 3869 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3870 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3871 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3872 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3873 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3874 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3875 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3876 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3877 | |
| 3878 | final long token = Binder.clearCallingIdentity(); |
| 3879 | try { |
| 3880 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3881 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3882 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3883 | } catch (ImsException e) { |
| 3884 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3885 | + "is inactive, ignoring unregister."); |
| 3886 | // If the subscription is no longer active, just return, since the callback |
| 3887 | // will already have been removed internally. |
| 3888 | } finally { |
| 3889 | Binder.restoreCallingIdentity(token); |
| 3890 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3891 | } |
| 3892 | |
| 3893 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3894 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3895 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3896 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3897 | final long token = Binder.clearCallingIdentity(); |
| 3898 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3899 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3900 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3901 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3902 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3903 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3904 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3905 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3906 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3907 | } finally { |
| 3908 | Binder.restoreCallingIdentity(token); |
| 3909 | } |
| 3910 | } |
| 3911 | |
| 3912 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3913 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3914 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3915 | final long token = Binder.clearCallingIdentity(); |
| 3916 | try { |
| 3917 | Phone phone = getPhone(subId); |
| 3918 | if (phone == null) return false; |
| 3919 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 32706d9 | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3920 | } catch (com.android.ims.ImsException e) { |
| 3921 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3922 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3923 | } finally { |
| 3924 | Binder.restoreCallingIdentity(token); |
| 3925 | } |
| 3926 | } |
| 3927 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3928 | /** |
| 3929 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3930 | * subscription. |
| 3931 | * @param subId The subscription to use to check the configuration. |
| 3932 | * @param callback The callback that will be used to send the result. |
| 3933 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3934 | * @param transportType The transport type of the MmTelFeature capability. |
| 3935 | */ |
| 3936 | @Override |
| 3937 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3938 | int transportType) { |
| 3939 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3940 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3941 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3942 | "IMS not available on device."); |
| 3943 | } |
| 3944 | final long token = Binder.clearCallingIdentity(); |
| 3945 | try { |
| 3946 | int slotId = getSlotIndex(subId); |
| 3947 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3948 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3949 | + subId + "'"); |
| 3950 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3951 | } |
| 3952 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3953 | transportType, aBoolean -> { |
| 3954 | try { |
| 3955 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3956 | } catch (RemoteException e) { |
| 3957 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3958 | + "running. Ignore"); |
| 3959 | } |
| 3960 | }); |
| 3961 | } finally { |
| 3962 | Binder.restoreCallingIdentity(token); |
| 3963 | } |
| 3964 | } |
| 3965 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3966 | /** |
| 3967 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3968 | * @param subId The subscription to use to check the configuration. |
| 3969 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3970 | @Override |
| 3971 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3972 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3973 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3974 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3975 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3976 | final long token = Binder.clearCallingIdentity(); |
| 3977 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3978 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3979 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3980 | } catch (ImsException e) { |
| 3981 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3982 | } finally { |
| 3983 | Binder.restoreCallingIdentity(token); |
| 3984 | } |
| 3985 | } |
| 3986 | |
| 3987 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3988 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3989 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3990 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3991 | final long identity = Binder.clearCallingIdentity(); |
| 3992 | try { |
| 3993 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3994 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3995 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3996 | } catch (ImsException e) { |
| 3997 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3998 | } finally { |
| 3999 | Binder.restoreCallingIdentity(identity); |
| 4000 | } |
| 4001 | } |
| 4002 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4003 | /** |
| 4004 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4005 | * @param subId The subscription to use to check the configuration. |
| 4006 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4007 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4008 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4009 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4010 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4011 | final long identity = Binder.clearCallingIdentity(); |
| 4012 | try { |
| 4013 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4014 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 4015 | } catch (ImsException e) { |
| 4016 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4017 | } finally { |
| 4018 | Binder.restoreCallingIdentity(identity); |
| 4019 | } |
| 4020 | } |
| 4021 | |
| 4022 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4023 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4024 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4025 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4026 | final long identity = Binder.clearCallingIdentity(); |
| 4027 | try { |
| 4028 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4029 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4030 | } catch (ImsException e) { |
| 4031 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4032 | } finally { |
| 4033 | Binder.restoreCallingIdentity(identity); |
| 4034 | } |
| 4035 | } |
| 4036 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4037 | /** |
| 4038 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4039 | * @param subId The subscription to use to check the configuration. |
| 4040 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4041 | @Override |
| 4042 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4043 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4044 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4045 | final long identity = Binder.clearCallingIdentity(); |
| 4046 | try { |
| 4047 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4048 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4049 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4050 | } catch (ImsException e) { |
| 4051 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4052 | } finally { |
| 4053 | Binder.restoreCallingIdentity(identity); |
| 4054 | } |
| 4055 | } |
| 4056 | |
| 4057 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4058 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4059 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4060 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4061 | final long identity = Binder.clearCallingIdentity(); |
| 4062 | try { |
| 4063 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4064 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4065 | } catch (ImsException e) { |
| 4066 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4067 | } finally { |
| 4068 | Binder.restoreCallingIdentity(identity); |
| 4069 | } |
| 4070 | } |
| 4071 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4072 | /** |
| 4073 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4074 | * @param subId The subscription to use to check the configuration. |
| 4075 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4076 | @Override |
| 4077 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4078 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4079 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4080 | final long identity = Binder.clearCallingIdentity(); |
| 4081 | try { |
| 4082 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4083 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4084 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4085 | } catch (ImsException e) { |
| 4086 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4087 | } finally { |
| 4088 | Binder.restoreCallingIdentity(identity); |
| 4089 | } |
| 4090 | } |
| 4091 | |
| 4092 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4093 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4094 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4095 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4096 | final long identity = Binder.clearCallingIdentity(); |
| 4097 | try { |
| 4098 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4099 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4100 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4101 | } catch (ImsException e) { |
| 4102 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4103 | } finally { |
| 4104 | Binder.restoreCallingIdentity(identity); |
| 4105 | } |
| 4106 | } |
| 4107 | |
| 4108 | @Override |
| 4109 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4110 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4111 | "setVoWiFiNonPersistent"); |
| 4112 | final long identity = Binder.clearCallingIdentity(); |
| 4113 | try { |
| 4114 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4115 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 4116 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4117 | } catch (ImsException e) { |
| 4118 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4119 | } finally { |
| 4120 | Binder.restoreCallingIdentity(identity); |
| 4121 | } |
| 4122 | } |
| 4123 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4124 | /** |
| 4125 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4126 | * @param subId The subscription to use to check the configuration. |
| 4127 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4128 | @Override |
| 4129 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4130 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4131 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4132 | final long identity = Binder.clearCallingIdentity(); |
| 4133 | try { |
| 4134 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4135 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4136 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4137 | } catch (ImsException e) { |
| 4138 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4139 | } finally { |
| 4140 | Binder.restoreCallingIdentity(identity); |
| 4141 | } |
| 4142 | } |
| 4143 | |
| 4144 | @Override |
| 4145 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4146 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4147 | "setVoWiFiModeSetting"); |
| 4148 | final long identity = Binder.clearCallingIdentity(); |
| 4149 | try { |
| 4150 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4151 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4152 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4153 | } catch (ImsException e) { |
| 4154 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4155 | } finally { |
| 4156 | Binder.restoreCallingIdentity(identity); |
| 4157 | } |
| 4158 | } |
| 4159 | |
| 4160 | @Override |
| 4161 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4162 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4163 | final long identity = Binder.clearCallingIdentity(); |
| 4164 | try { |
| 4165 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4166 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4167 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4168 | } catch (ImsException e) { |
| 4169 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4170 | } finally { |
| 4171 | Binder.restoreCallingIdentity(identity); |
| 4172 | } |
| 4173 | } |
| 4174 | |
| 4175 | @Override |
| 4176 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4177 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4178 | "setVoWiFiRoamingModeSetting"); |
| 4179 | final long identity = Binder.clearCallingIdentity(); |
| 4180 | try { |
| 4181 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4182 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4183 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4184 | } catch (ImsException e) { |
| 4185 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4186 | } finally { |
| 4187 | Binder.restoreCallingIdentity(identity); |
| 4188 | } |
| 4189 | } |
| 4190 | |
| 4191 | @Override |
| 4192 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4193 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4194 | "setRttCapabilityEnabled"); |
| 4195 | final long identity = Binder.clearCallingIdentity(); |
| 4196 | try { |
| 4197 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4198 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 4199 | } catch (ImsException e) { |
| 4200 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4201 | } finally { |
| 4202 | Binder.restoreCallingIdentity(identity); |
| 4203 | } |
| 4204 | } |
| 4205 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4206 | /** |
| 4207 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4208 | * @param subId The subscription to use to check the configuration. |
| 4209 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4210 | @Override |
| 4211 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4212 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4213 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4214 | final long identity = Binder.clearCallingIdentity(); |
| 4215 | try { |
| 4216 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4217 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4218 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4219 | } catch (ImsException e) { |
| 4220 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4221 | } finally { |
| 4222 | Binder.restoreCallingIdentity(identity); |
| 4223 | } |
| 4224 | } |
| 4225 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4226 | @Override |
| 4227 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4228 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4229 | final long identity = Binder.clearCallingIdentity(); |
| 4230 | try { |
Brad Ebinger | 6cf0f65 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4231 | if (!isImsAvailableOnDevice()) { |
| 4232 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4233 | "IMS not available on device."); |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4234 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4235 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4236 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4237 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4238 | } catch (ImsException e) { |
| 4239 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4240 | } finally { |
| 4241 | Binder.restoreCallingIdentity(identity); |
| 4242 | } |
| 4243 | } |
| 4244 | |
| 4245 | @Override |
| 4246 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4247 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4248 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4249 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4250 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4251 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4252 | try { |
| 4253 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4254 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4255 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4256 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4257 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4258 | + "is inactive, ignoring unregister."); |
| 4259 | // If the subscription is no longer active, just return, since the callback will already |
| 4260 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4261 | } finally { |
| 4262 | Binder.restoreCallingIdentity(identity); |
| 4263 | } |
| 4264 | } |
| 4265 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4266 | |
| 4267 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4268 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4269 | message); |
| 4270 | } |
| 4271 | |
| 4272 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4273 | boolean isMmtelCapability) { |
| 4274 | Phone phone = getPhone(subId); |
| 4275 | if (phone == null) { |
| 4276 | loge("phone instance null for subid " + subId); |
| 4277 | return false; |
| 4278 | } |
| 4279 | if (isMmtelCapability) { |
| 4280 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4281 | return false; |
| 4282 | } |
| 4283 | } else { |
| 4284 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4285 | return false; |
| 4286 | } |
| 4287 | } |
| 4288 | return true; |
| 4289 | } |
| 4290 | |
| 4291 | @Override |
| 4292 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4293 | boolean isProvisioned) { |
| 4294 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4295 | |
| 4296 | final long identity = Binder.clearCallingIdentity(); |
| 4297 | try { |
| 4298 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4299 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4300 | return; |
| 4301 | } |
| 4302 | |
| 4303 | // this capability requires provisioning, route to the correct API. |
| 4304 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4305 | switch (capability) { |
| 4306 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4307 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4308 | ims.setEabProvisioned(isProvisioned); |
| 4309 | break; |
| 4310 | default: { |
| 4311 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4312 | + "rcs capability '" + capability + "', which does not require " |
| 4313 | + "provisioning."); |
| 4314 | } |
| 4315 | } |
| 4316 | } finally { |
| 4317 | Binder.restoreCallingIdentity(identity); |
| 4318 | } |
| 4319 | |
| 4320 | } |
| 4321 | |
| 4322 | |
| 4323 | @Override |
| 4324 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4325 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4326 | final long identity = Binder.clearCallingIdentity(); |
| 4327 | try { |
| 4328 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4329 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4330 | return true; |
| 4331 | } |
| 4332 | |
| 4333 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4334 | switch (capability) { |
| 4335 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4336 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4337 | return ims.isEabProvisionedOnDevice(); |
| 4338 | |
| 4339 | default: { |
| 4340 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4341 | + "capability '" + capability + "', which does not require " |
| 4342 | + "provisioning."); |
| 4343 | } |
| 4344 | } |
| 4345 | |
| 4346 | } finally { |
| 4347 | Binder.restoreCallingIdentity(identity); |
| 4348 | } |
| 4349 | } |
| 4350 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4351 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4352 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4353 | boolean isProvisioned) { |
Brad Ebinger | 2a6be5f | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4354 | if (tech < ImsRegistrationImplBase.REGISTRATION_TECH_LTE |
| 4355 | || tech > ImsRegistrationImplBase.REGISTRATION_TECH_NR) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4356 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4357 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4358 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4359 | final long identity = Binder.clearCallingIdentity(); |
| 4360 | try { |
| 4361 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4362 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4363 | return; |
| 4364 | } |
Brad Ebinger | 2a6be5f | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4365 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE |
| 4366 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4367 | loge("setImsProvisioningStatusForCapability: called for technology that does " |
| 4368 | + "not support provisioning - " + tech); |
| 4369 | return; |
| 4370 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4371 | |
| 4372 | // this capability requires provisioning, route to the correct API. |
| 4373 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4374 | switch (capability) { |
| 4375 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4376 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4377 | ims.setVolteProvisioned(isProvisioned); |
| 4378 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4379 | ims.setWfcProvisioned(isProvisioned); |
| 4380 | } |
| 4381 | break; |
| 4382 | } |
| 4383 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4384 | // There is currently no difference in VT provisioning type. |
| 4385 | ims.setVtProvisioned(isProvisioned); |
| 4386 | break; |
| 4387 | } |
| 4388 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4389 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4390 | // change the capability of the feature instead if needed. |
| 4391 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4392 | == isProvisioned) { |
| 4393 | // No change in provisioning. |
| 4394 | return; |
| 4395 | } |
| 4396 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4397 | try { |
Brad Ebinger | 2a6be5f | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4398 | ims.changeMmTelCapability(isProvisioned, capability, tech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4399 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4400 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4401 | + ", Exception" + e.getMessage()); |
| 4402 | } |
| 4403 | break; |
| 4404 | } |
| 4405 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4406 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4407 | + "MmTel capability '" + capability + "', which does not require " |
| 4408 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4409 | } |
| 4410 | } |
| 4411 | |
| 4412 | } finally { |
| 4413 | Binder.restoreCallingIdentity(identity); |
| 4414 | } |
| 4415 | } |
| 4416 | |
| 4417 | @Override |
| 4418 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
Brad Ebinger | 2a6be5f | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4419 | if (tech < ImsRegistrationImplBase.REGISTRATION_TECH_LTE |
| 4420 | || tech > ImsRegistrationImplBase.REGISTRATION_TECH_NR) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4421 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4422 | } |
| 4423 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4424 | final long identity = Binder.clearCallingIdentity(); |
| 4425 | try { |
| 4426 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4427 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4428 | return true; |
| 4429 | } |
| 4430 | |
Brad Ebinger | 2a6be5f | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4431 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE |
| 4432 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4433 | loge("getImsProvisioningStatusForCapability: called for technology that does " |
| 4434 | + "not support provisioning - " + tech); |
| 4435 | return true; |
| 4436 | } |
| 4437 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4438 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4439 | switch (capability) { |
| 4440 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4441 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4442 | return ims.isVolteProvisionedOnDevice(); |
| 4443 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4444 | return ims.isWfcProvisionedOnDevice(); |
| 4445 | } |
| 4446 | // This should never happen, since we are checking tech above to make sure it |
| 4447 | // is either LTE or IWLAN. |
| 4448 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4449 | + "capability."); |
| 4450 | } |
| 4451 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4452 | // There is currently no difference in VT provisioning type. |
| 4453 | return ims.isVtProvisionedOnDevice(); |
| 4454 | } |
| 4455 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4456 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4457 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4458 | } |
| 4459 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4460 | throw new IllegalArgumentException( |
| 4461 | "Tried to get provisioning for MmTel capability '" + capability |
| 4462 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4463 | } |
| 4464 | } |
| 4465 | |
| 4466 | } finally { |
| 4467 | Binder.restoreCallingIdentity(identity); |
| 4468 | } |
| 4469 | } |
| 4470 | |
| 4471 | @Override |
| 4472 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4473 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4474 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4475 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4476 | } |
| 4477 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4478 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4479 | return (provisionedBits & capability) > 0; |
| 4480 | } |
| 4481 | |
| 4482 | @Override |
| 4483 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4484 | boolean isProvisioned) { |
| 4485 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4486 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4487 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4488 | } |
| 4489 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4490 | "setProvisioningStatusForCapability"); |
| 4491 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4492 | // If the current provisioning status for capability already matches isProvisioned, |
| 4493 | // do nothing. |
| 4494 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4495 | return; |
| 4496 | } |
| 4497 | if (isProvisioned) { |
| 4498 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4499 | } else { |
| 4500 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4501 | } |
| 4502 | } |
| 4503 | |
| 4504 | /** |
| 4505 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4506 | * technology. The bitfield should mirror the bitfield defined by |
| 4507 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4508 | */ |
| 4509 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4510 | String key = getMmTelProvisioningKey(subId, tech); |
| 4511 | // Default is no capabilities are provisioned. |
| 4512 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4513 | } |
| 4514 | |
| 4515 | /** |
| 4516 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4517 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4518 | * technology specified. |
| 4519 | * |
| 4520 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4521 | */ |
| 4522 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4523 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4524 | String key = getMmTelProvisioningKey(subId, tech); |
| 4525 | editor.putInt(key, newField); |
| 4526 | editor.commit(); |
| 4527 | } |
| 4528 | |
| 4529 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4530 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4531 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4532 | } |
| 4533 | |
| 4534 | /** |
| 4535 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4536 | * carrier associated with the subscription id. |
| 4537 | */ |
| 4538 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4539 | int capability) { |
| 4540 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4541 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4542 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4543 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4544 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4545 | false); |
| 4546 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4547 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4548 | |
| 4549 | // First check to make sure that the capability requires provisioning. |
| 4550 | switch (capability) { |
| 4551 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4552 | // intentional fallthrough |
| 4553 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4554 | if (requireVoiceVtProvisioning) { |
| 4555 | // Voice and Video requires provisioning |
| 4556 | return true; |
| 4557 | } |
| 4558 | break; |
| 4559 | } |
| 4560 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4561 | if (requireUtProvisioning) { |
| 4562 | // UT requires provisioning |
| 4563 | return true; |
| 4564 | } |
| 4565 | break; |
| 4566 | } |
| 4567 | } |
| 4568 | return false; |
| 4569 | } |
| 4570 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4571 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4572 | int capability) { |
| 4573 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4574 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4575 | |
| 4576 | boolean requireRcsProvisioning = c.getBoolean( |
| 4577 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4578 | |
| 4579 | // First check to make sure that the capability requires provisioning. |
| 4580 | switch (capability) { |
| 4581 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4582 | // intentional fallthrough |
| 4583 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4584 | if (requireRcsProvisioning) { |
| 4585 | // OPTION or PRESENCE requires provisioning |
| 4586 | return true; |
| 4587 | } |
| 4588 | break; |
| 4589 | } |
| 4590 | } |
| 4591 | return false; |
| 4592 | } |
| 4593 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4594 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4595 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4596 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4597 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4598 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4599 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4600 | final long identity = Binder.clearCallingIdentity(); |
| 4601 | try { |
| 4602 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4603 | int slotId = getSlotIndex(subId); |
| 4604 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4605 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4606 | + subId + "' for key:" + key); |
| 4607 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4608 | } |
calvinpan | 9cfff47 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4609 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4610 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4611 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4612 | + subId + "' for key:" + key); |
| 4613 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4614 | } finally { |
| 4615 | Binder.restoreCallingIdentity(identity); |
| 4616 | } |
| 4617 | } |
| 4618 | |
| 4619 | @Override |
| 4620 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4621 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4622 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4623 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4624 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4625 | final long identity = Binder.clearCallingIdentity(); |
| 4626 | try { |
| 4627 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4628 | int slotId = getSlotIndex(subId); |
| 4629 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4630 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4631 | + subId + "' for key:" + key); |
| 4632 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4633 | } |
calvinpan | 9cfff47 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4634 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4635 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4636 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4637 | + subId + "' for key:" + key); |
| 4638 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4639 | } finally { |
| 4640 | Binder.restoreCallingIdentity(identity); |
| 4641 | } |
| 4642 | } |
| 4643 | |
| 4644 | @Override |
| 4645 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4646 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4647 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4648 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4649 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4650 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4651 | final long identity = Binder.clearCallingIdentity(); |
| 4652 | try { |
| 4653 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4654 | int slotId = getSlotIndex(subId); |
| 4655 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4656 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4657 | + subId + "' for key:" + key); |
| 4658 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4659 | } |
calvinpan | 9cfff47 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4660 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4661 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4662 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | 9cfff47 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4663 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4664 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4665 | } finally { |
| 4666 | Binder.restoreCallingIdentity(identity); |
| 4667 | } |
| 4668 | } |
| 4669 | |
| 4670 | @Override |
| 4671 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4672 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4673 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4674 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4675 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4676 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4677 | final long identity = Binder.clearCallingIdentity(); |
| 4678 | try { |
| 4679 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4680 | int slotId = getSlotIndex(subId); |
| 4681 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4682 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4683 | + subId + "' for key:" + key); |
| 4684 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4685 | } |
calvinpan | 9cfff47 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4686 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4687 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4688 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | 9cfff47 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4689 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4690 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4691 | } finally { |
| 4692 | Binder.restoreCallingIdentity(identity); |
| 4693 | } |
| 4694 | } |
| 4695 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4696 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4697 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4698 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4699 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4700 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4701 | } |
| 4702 | return slotId; |
| 4703 | } |
| 4704 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4705 | private int getSlotIndex(int subId) { |
| 4706 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4707 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4708 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4709 | } |
| 4710 | return slotId; |
| 4711 | } |
| 4712 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4713 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4714 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4715 | */ |
| 4716 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4717 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4718 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4719 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4720 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4721 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4722 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4723 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4724 | mApp, subId, callingPackage, callingFeatureId, |
| 4725 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4726 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4727 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4728 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4729 | final long identity = Binder.clearCallingIdentity(); |
| 4730 | try { |
| 4731 | final Phone phone = getPhone(subId); |
| 4732 | if (phone != null) { |
| 4733 | return phone.getServiceState().getDataNetworkType(); |
| 4734 | } else { |
| 4735 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4736 | } |
| 4737 | } finally { |
| 4738 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4739 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4740 | } |
| 4741 | |
| 4742 | /** |
| 4743 | * Returns the data network type |
| 4744 | */ |
| 4745 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4746 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 4747 | return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(), |
| 4748 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4749 | } |
| 4750 | |
| 4751 | /** |
| 4752 | * Returns the data network type for a subId |
| 4753 | */ |
| 4754 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4755 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4756 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4757 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4758 | mApp, subId, callingPackage, callingFeatureId, |
| 4759 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4760 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4761 | } |
| 4762 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4763 | final long identity = Binder.clearCallingIdentity(); |
| 4764 | try { |
| 4765 | final Phone phone = getPhone(subId); |
| 4766 | if (phone != null) { |
| 4767 | return phone.getServiceState().getDataNetworkType(); |
| 4768 | } else { |
| 4769 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4770 | } |
| 4771 | } finally { |
| 4772 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4773 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4774 | } |
| 4775 | |
| 4776 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4777 | * Returns the Voice network type for a subId |
| 4778 | */ |
| 4779 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4780 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4781 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4782 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4783 | mApp, subId, callingPackage, callingFeatureId, |
| 4784 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4785 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4786 | } |
| 4787 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4788 | final long identity = Binder.clearCallingIdentity(); |
| 4789 | try { |
| 4790 | final Phone phone = getPhone(subId); |
| 4791 | if (phone != null) { |
| 4792 | return phone.getServiceState().getVoiceNetworkType(); |
| 4793 | } else { |
| 4794 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4795 | } |
| 4796 | } finally { |
| 4797 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4798 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4799 | } |
| 4800 | |
| 4801 | /** |
| 4802 | * @return true if a ICC card is present |
| 4803 | */ |
| 4804 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4805 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4806 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4807 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4808 | } |
| 4809 | |
| 4810 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4811 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4812 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4813 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4814 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4815 | final long identity = Binder.clearCallingIdentity(); |
| 4816 | try { |
| 4817 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4818 | if (phone != null) { |
| 4819 | return phone.getIccCard().hasIccCard(); |
| 4820 | } else { |
| 4821 | return false; |
| 4822 | } |
| 4823 | } finally { |
| 4824 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4825 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4826 | } |
| 4827 | |
| 4828 | /** |
| 4829 | * Return if the current radio is LTE on CDMA. This |
| 4830 | * is a tri-state return value as for a period of time |
| 4831 | * the mode may be unknown. |
| 4832 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4833 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4834 | * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE} |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4835 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4836 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4837 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4838 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4839 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4840 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4841 | } |
| 4842 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4843 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4844 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4845 | String callingFeatureId) { |
Sarah Chin | f6656a6 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4846 | try { |
| 4847 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4848 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4849 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4850 | } |
| 4851 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4852 | final long identity = Binder.clearCallingIdentity(); |
| 4853 | try { |
| 4854 | final Phone phone = getPhone(subId); |
| 4855 | if (phone == null) { |
| 4856 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4857 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4858 | return TelephonyProperties.lte_on_cdma_device() |
| 4859 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4860 | } |
| 4861 | } finally { |
| 4862 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4863 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4864 | } |
| 4865 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4866 | /** |
| 4867 | * {@hide} |
| 4868 | * Returns Default subId, 0 in the case of single standby. |
| 4869 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4870 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4871 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4872 | } |
| 4873 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4874 | private int getSlotForDefaultSubscription() { |
| 4875 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4876 | } |
| 4877 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4878 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4879 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4880 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4881 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4882 | private boolean isActiveSubscription(int subId) { |
| 4883 | return mSubscriptionController.isActiveSubId(subId); |
| 4884 | } |
| 4885 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4886 | /** |
| 4887 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4888 | */ |
| 4889 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4890 | final long identity = Binder.clearCallingIdentity(); |
| 4891 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4892 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4893 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4894 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4895 | } finally { |
| 4896 | Binder.restoreCallingIdentity(identity); |
| 4897 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4898 | } |
| 4899 | |
| 4900 | /** |
| 4901 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4902 | */ |
| 4903 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4904 | final long identity = Binder.clearCallingIdentity(); |
| 4905 | try { |
| 4906 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4907 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4908 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4909 | } finally { |
| 4910 | Binder.restoreCallingIdentity(identity); |
| 4911 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4912 | } |
| 4913 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4914 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4915 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4916 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4917 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4918 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4919 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4920 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4921 | if (phoneId == -1) { |
| 4922 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4923 | + " does not correspond to an active phone"); |
| 4924 | } |
| 4925 | return PhoneFactory.getPhone(phoneId); |
| 4926 | } |
| 4927 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4928 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4929 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4930 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4931 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4932 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4933 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4934 | if (DBG) { |
| 4935 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4936 | } |
| 4937 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4938 | p2); |
| 4939 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4940 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4941 | |
| 4942 | @Override |
| 4943 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4944 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4945 | enforceModifyPermission(); |
| 4946 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4947 | if (DBG) { |
| 4948 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4949 | } |
| 4950 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4951 | callingPackage, aid, p2); |
| 4952 | } |
| 4953 | |
| 4954 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4955 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4956 | final long identity = Binder.clearCallingIdentity(); |
| 4957 | try { |
| 4958 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4959 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4960 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4961 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4962 | if (bestComponent == null |
| 4963 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4964 | loge("The calling package is not allowed to access ISD-R."); |
| 4965 | throw new SecurityException( |
| 4966 | "The calling package is not allowed to access ISD-R."); |
| 4967 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4968 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4969 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4970 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4971 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4972 | null /* workSource */); |
| 4973 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4974 | return response; |
| 4975 | } finally { |
| 4976 | Binder.restoreCallingIdentity(identity); |
| 4977 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4978 | } |
| 4979 | |
| 4980 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4981 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4982 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4983 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4984 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4985 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4986 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4987 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4988 | @Override |
| 4989 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4990 | enforceModifyPermission(); |
| 4991 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4992 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4993 | channel); |
| 4994 | } |
| 4995 | |
| 4996 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4997 | final long identity = Binder.clearCallingIdentity(); |
| 4998 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4999 | if (channel < 0) { |
| 5000 | return false; |
| 5001 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5002 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 5003 | null /* workSource */); |
| 5004 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5005 | return success; |
| 5006 | } finally { |
| 5007 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5008 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5009 | } |
| 5010 | |
| 5011 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5012 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5013 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5014 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5015 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5016 | if (DBG) { |
| 5017 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5018 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5019 | + p3 + " data=" + data); |
| 5020 | } |
| 5021 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5022 | command, p1, p2, p3, data); |
| 5023 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5024 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5025 | @Override |
| 5026 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 5027 | int command, int p1, int p2, int p3, String data) { |
| 5028 | enforceModifyPermission(); |
| 5029 | if (DBG) { |
| 5030 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 5031 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5032 | + p3 + " data=" + data); |
| 5033 | } |
| 5034 | return iccTransmitApduLogicalChannelWithPermission( |
| 5035 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 5036 | data); |
| 5037 | } |
| 5038 | |
| 5039 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5040 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5041 | final long identity = Binder.clearCallingIdentity(); |
| 5042 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5043 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5044 | return ""; |
| 5045 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5046 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5047 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5048 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5049 | null /* workSource */); |
| 5050 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5051 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5052 | // Append the returned status code to the end of the response payload. |
| 5053 | String s = Integer.toHexString( |
| 5054 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5055 | if (response.payload != null) { |
| 5056 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5057 | } |
| 5058 | return s; |
| 5059 | } finally { |
| 5060 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5061 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5062 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5063 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5064 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5065 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5066 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5067 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5068 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5069 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5070 | if (DBG) { |
| 5071 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5072 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5073 | } |
| 5074 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5075 | cla, command, p1, p2, p3, data); |
| 5076 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5077 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5078 | @Override |
| 5079 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 5080 | int command, int p1, int p2, int p3, String data) { |
| 5081 | enforceModifyPermission(); |
| 5082 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5083 | if (DBG) { |
| 5084 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 5085 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 5086 | + " data=" + data); |
| 5087 | } |
| 5088 | |
| 5089 | return iccTransmitApduBasicChannelWithPermission( |
| 5090 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 5091 | p2, p3, data); |
| 5092 | } |
| 5093 | |
| 5094 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5095 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5096 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5097 | final long identity = Binder.clearCallingIdentity(); |
| 5098 | try { |
| 5099 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5100 | && TextUtils.equals(ISDR_AID, data)) { |
| 5101 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5102 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5103 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5104 | if (bestComponent == null |
| 5105 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5106 | loge("The calling package is not allowed to select ISD-R."); |
| 5107 | throw new SecurityException( |
| 5108 | "The calling package is not allowed to select ISD-R."); |
| 5109 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5110 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5111 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5112 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5113 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5114 | null /* workSource */); |
| 5115 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5116 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5117 | // Append the returned status code to the end of the response payload. |
| 5118 | String s = Integer.toHexString( |
| 5119 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5120 | if (response.payload != null) { |
| 5121 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5122 | } |
| 5123 | return s; |
| 5124 | } finally { |
| 5125 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5126 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5127 | } |
| 5128 | |
| 5129 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5130 | public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3, |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5131 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5132 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5133 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5134 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5135 | final long identity = Binder.clearCallingIdentity(); |
| 5136 | try { |
| 5137 | if (DBG) { |
| 5138 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5139 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5140 | } |
| 5141 | |
| 5142 | IccIoResult response = |
| 5143 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5144 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5145 | subId); |
| 5146 | |
| 5147 | if (DBG) { |
| 5148 | log("Exchange SIM_IO [R]" + response); |
| 5149 | } |
| 5150 | |
| 5151 | byte[] result = null; |
| 5152 | int length = 2; |
| 5153 | if (response.payload != null) { |
| 5154 | length = 2 + response.payload.length; |
| 5155 | result = new byte[length]; |
| 5156 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5157 | } else { |
| 5158 | result = new byte[length]; |
| 5159 | } |
| 5160 | |
| 5161 | result[length - 1] = (byte) response.sw2; |
| 5162 | result[length - 2] = (byte) response.sw1; |
| 5163 | return result; |
| 5164 | } finally { |
| 5165 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5166 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5167 | } |
| 5168 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5169 | /** |
| 5170 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5171 | * on a particular subscription |
| 5172 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5173 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5174 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5175 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5176 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5177 | return null; |
| 5178 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5179 | |
| 5180 | final long identity = Binder.clearCallingIdentity(); |
| 5181 | try { |
| 5182 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5183 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5184 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5185 | return null; |
| 5186 | } |
| 5187 | Object response = sendRequest( |
| 5188 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5189 | if (response instanceof String[]) { |
| 5190 | return (String[]) response; |
| 5191 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5192 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5193 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5194 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5195 | } finally { |
| 5196 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5197 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5198 | } |
| 5199 | |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5200 | /** |
| 5201 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5202 | * subscription. |
| 5203 | * |
| 5204 | * @param subId the id of the subscription. |
| 5205 | * @param appType the uicc app type, must be USIM or SIM. |
| 5206 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5207 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5208 | * @param callingFeatureId the feature in the package. |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5209 | * @return number of fplmns that is successfully written to the SIM. |
| 5210 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5211 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5212 | String callingFeatureId) { |
| 5213 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 5214 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5215 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 5216 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 5217 | } |
| 5218 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5219 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5220 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5221 | } |
| 5222 | if (fplmns == null) { |
| 5223 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5224 | } |
| 5225 | for (String fplmn : fplmns) { |
| 5226 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5227 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5228 | } |
| 5229 | } |
| 5230 | final long identity = Binder.clearCallingIdentity(); |
| 5231 | try { |
| 5232 | Object response = sendRequest( |
| 5233 | CMD_SET_FORBIDDEN_PLMNS, |
| 5234 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5235 | subId); |
| 5236 | return (int) response; |
| 5237 | } finally { |
| 5238 | Binder.restoreCallingIdentity(identity); |
| 5239 | } |
| 5240 | } |
| 5241 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5242 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5243 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5244 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5245 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5246 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5247 | final long identity = Binder.clearCallingIdentity(); |
| 5248 | try { |
| 5249 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5250 | if (response.payload == null) { |
| 5251 | return ""; |
| 5252 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5253 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5254 | // Append the returned status code to the end of the response payload. |
| 5255 | String s = Integer.toHexString( |
| 5256 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5257 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5258 | return s; |
| 5259 | } finally { |
| 5260 | Binder.restoreCallingIdentity(identity); |
| 5261 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5262 | } |
| 5263 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5264 | /** |
| 5265 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5266 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5267 | * |
| 5268 | * @param itemID the ID of the item to read |
| 5269 | * @return the NV item as a String, or null on error. |
| 5270 | */ |
| 5271 | @Override |
| 5272 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5273 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5274 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5275 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5276 | |
| 5277 | final long identity = Binder.clearCallingIdentity(); |
| 5278 | try { |
| 5279 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5280 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5281 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5282 | return value; |
| 5283 | } finally { |
| 5284 | Binder.restoreCallingIdentity(identity); |
| 5285 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5286 | } |
| 5287 | |
| 5288 | /** |
| 5289 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5290 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5291 | * |
| 5292 | * @param itemID the ID of the item to read |
| 5293 | * @param itemValue the value to write, as a String |
| 5294 | * @return true on success; false on any failure |
| 5295 | */ |
| 5296 | @Override |
| 5297 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5298 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5299 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5300 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5301 | |
| 5302 | final long identity = Binder.clearCallingIdentity(); |
| 5303 | try { |
| 5304 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5305 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5306 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5307 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5308 | return success; |
| 5309 | } finally { |
| 5310 | Binder.restoreCallingIdentity(identity); |
| 5311 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5312 | } |
| 5313 | |
| 5314 | /** |
| 5315 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5316 | * Used for device configuration by some CDMA operators. |
| 5317 | * |
| 5318 | * @param preferredRoamingList byte array containing the new PRL |
| 5319 | * @return true on success; false on any failure |
| 5320 | */ |
| 5321 | @Override |
| 5322 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5323 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5324 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5325 | |
| 5326 | final long identity = Binder.clearCallingIdentity(); |
| 5327 | try { |
| 5328 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5329 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5330 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5331 | return success; |
| 5332 | } finally { |
| 5333 | Binder.restoreCallingIdentity(identity); |
| 5334 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5335 | } |
| 5336 | |
| 5337 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5338 | * Rollback modem configurations to factory default except some config which are in whitelist. |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5339 | * Used for device configuration by some CDMA operators. |
| 5340 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5341 | * @param slotIndex - device slot. |
| 5342 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5343 | * @return true on success; false on any failure |
| 5344 | */ |
| 5345 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5346 | public boolean resetModemConfig(int slotIndex) { |
| 5347 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5348 | if (phone != null) { |
| 5349 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5350 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5351 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5352 | final long identity = Binder.clearCallingIdentity(); |
| 5353 | try { |
| 5354 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5355 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5356 | return success; |
| 5357 | } finally { |
| 5358 | Binder.restoreCallingIdentity(identity); |
| 5359 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5360 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5361 | return false; |
| 5362 | } |
| 5363 | |
| 5364 | /** |
| 5365 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5366 | * |
| 5367 | * @param slotIndex - device slot. |
| 5368 | * |
| 5369 | * @return true on success; false on any failure |
| 5370 | */ |
| 5371 | @Override |
| 5372 | public boolean rebootModem(int slotIndex) { |
| 5373 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5374 | if (phone != null) { |
| 5375 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5376 | mApp, phone.getSubId(), "rebootModem"); |
| 5377 | |
| 5378 | final long identity = Binder.clearCallingIdentity(); |
| 5379 | try { |
| 5380 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5381 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5382 | return success; |
| 5383 | } finally { |
| 5384 | Binder.restoreCallingIdentity(identity); |
| 5385 | } |
| 5386 | } |
| 5387 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5388 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5389 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5390 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5391 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5392 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5393 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5394 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5395 | return new String[0]; |
| 5396 | } |
| 5397 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5398 | final long identity = Binder.clearCallingIdentity(); |
| 5399 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5400 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5401 | } finally { |
| 5402 | Binder.restoreCallingIdentity(identity); |
| 5403 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5404 | } |
| 5405 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5406 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5407 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5408 | * {@link #disableIms(int)}. |
| 5409 | * @param slotIndex device slot. |
| 5410 | */ |
| 5411 | public void resetIms(int slotIndex) { |
| 5412 | enforceModifyPermission(); |
| 5413 | |
| 5414 | final long identity = Binder.clearCallingIdentity(); |
| 5415 | try { |
| 5416 | if (mImsResolver == null) { |
| 5417 | // may happen if the does not support IMS. |
| 5418 | return; |
| 5419 | } |
| 5420 | mImsResolver.disableIms(slotIndex); |
| 5421 | mImsResolver.enableIms(slotIndex); |
| 5422 | } finally { |
| 5423 | Binder.restoreCallingIdentity(identity); |
| 5424 | } |
| 5425 | } |
| 5426 | |
| 5427 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5428 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5429 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5430 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5431 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5432 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5433 | |
| 5434 | final long identity = Binder.clearCallingIdentity(); |
| 5435 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5436 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5437 | // may happen if the device does not support IMS. |
| 5438 | return; |
| 5439 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5440 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5441 | } finally { |
| 5442 | Binder.restoreCallingIdentity(identity); |
| 5443 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5444 | } |
| 5445 | |
| 5446 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5447 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5448 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5449 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5450 | public void disableIms(int slotId) { |
| 5451 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5452 | |
| 5453 | final long identity = Binder.clearCallingIdentity(); |
| 5454 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5455 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5456 | // may happen if the device does not support IMS. |
| 5457 | return; |
| 5458 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5459 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5460 | } finally { |
| 5461 | Binder.restoreCallingIdentity(identity); |
| 5462 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5463 | } |
| 5464 | |
| 5465 | /** |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5466 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5467 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5468 | */ |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5469 | @Override |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5470 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5471 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5472 | |
| 5473 | final long identity = Binder.clearCallingIdentity(); |
| 5474 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5475 | if (mImsResolver == null) { |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5476 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5477 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5478 | } |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5479 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5480 | } finally { |
| 5481 | Binder.restoreCallingIdentity(identity); |
| 5482 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5483 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5484 | /** |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5485 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5486 | */ |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5487 | @Override |
| 5488 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5489 | enforceModifyPermission(); |
| 5490 | |
| 5491 | final long identity = Binder.clearCallingIdentity(); |
| 5492 | try { |
| 5493 | if (mImsResolver == null) return; |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5494 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5495 | } finally { |
| 5496 | Binder.restoreCallingIdentity(identity); |
| 5497 | } |
| 5498 | } |
| 5499 | |
| 5500 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5501 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5502 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5503 | */ |
| 5504 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5505 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5506 | |
| 5507 | final long identity = Binder.clearCallingIdentity(); |
| 5508 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5509 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5510 | // may happen if the device does not support IMS. |
| 5511 | return null; |
| 5512 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5513 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5514 | } finally { |
| 5515 | Binder.restoreCallingIdentity(identity); |
| 5516 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5517 | } |
| 5518 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5519 | /** |
| 5520 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5521 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5522 | */ |
| 5523 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5524 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5525 | |
| 5526 | final long identity = Binder.clearCallingIdentity(); |
| 5527 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5528 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5529 | // may happen if the device does not support IMS. |
| 5530 | return null; |
| 5531 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5532 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5533 | } finally { |
| 5534 | Binder.restoreCallingIdentity(identity); |
| 5535 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5536 | } |
| 5537 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5538 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5539 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5540 | * |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5541 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5542 | * @param isCarrierService true if the ImsService is the carrier override, false if the |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5543 | * ImsService is the device default ImsService. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5544 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5545 | * @param packageName The name of the package that the current configuration will be replaced |
| 5546 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5547 | * @return true if setting the ImsService to bind to succeeded, false if it did not. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5548 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5549 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5550 | int[] featureTypes, String packageName) { |
| 5551 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5552 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5553 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5554 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5555 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5556 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5557 | final long identity = Binder.clearCallingIdentity(); |
| 5558 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5559 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5560 | // may happen if the device does not support IMS. |
| 5561 | return false; |
| 5562 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5563 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5564 | for (int featureType : featureTypes) { |
| 5565 | featureConfig.put(featureType, packageName); |
| 5566 | } |
| 5567 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5568 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5569 | } finally { |
| 5570 | Binder.restoreCallingIdentity(identity); |
| 5571 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5572 | } |
| 5573 | |
| 5574 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5575 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5576 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5577 | * |
| 5578 | * This should only be used for testing. |
| 5579 | * |
| 5580 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5581 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5582 | */ |
| 5583 | @Override |
| 5584 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5585 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5586 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5587 | "clearCarrierImsServiceOverride"); |
| 5588 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5589 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5590 | "clearCarrierImsServiceOverride"); |
| 5591 | |
| 5592 | final long identity = Binder.clearCallingIdentity(); |
| 5593 | try { |
| 5594 | if (mImsResolver == null) { |
| 5595 | // may happen if the device does not support IMS. |
| 5596 | return false; |
| 5597 | } |
| 5598 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5599 | } finally { |
| 5600 | Binder.restoreCallingIdentity(identity); |
| 5601 | } |
| 5602 | } |
| 5603 | |
| 5604 | /** |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5605 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5606 | * |
| 5607 | * @param slotId The slot that the ImsService is associated with. |
| 5608 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5609 | * the device default. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5610 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5611 | * @return the package name of the ImsService configuration. |
| 5612 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5613 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5614 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5615 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5616 | TelephonyPermissions |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5617 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5618 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5619 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5620 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5621 | final long identity = Binder.clearCallingIdentity(); |
| 5622 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5623 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5624 | // may happen if the device does not support IMS. |
| 5625 | return ""; |
| 5626 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5627 | // TODO: change API to query RCS separately. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5628 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5629 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5630 | } finally { |
| 5631 | Binder.restoreCallingIdentity(identity); |
| 5632 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5633 | } |
| 5634 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5635 | /** |
| 5636 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5637 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5638 | * @param callback A callback with an integer containing the |
| 5639 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5640 | */ |
| 5641 | @Override |
| 5642 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5643 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5644 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5645 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5646 | "IMS not available on device."); |
| 5647 | } |
| 5648 | final long token = Binder.clearCallingIdentity(); |
| 5649 | try { |
| 5650 | int slotId = getSlotIndex(subId); |
| 5651 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5652 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5653 | + subId + "'"); |
| 5654 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5655 | } |
| 5656 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5657 | try { |
| 5658 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5659 | } catch (RemoteException e) { |
| 5660 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5661 | + "Ignore"); |
| 5662 | } |
| 5663 | }); |
| 5664 | } finally { |
| 5665 | Binder.restoreCallingIdentity(token); |
| 5666 | } |
| 5667 | } |
| 5668 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5669 | /** |
| 5670 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5671 | */ |
| 5672 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5673 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5674 | |
| 5675 | final long identity = Binder.clearCallingIdentity(); |
| 5676 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5677 | // NOTE: Before S, this method only set the default phone. |
| 5678 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5679 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5680 | phone.setImsRegistrationState(registered); |
| 5681 | } |
| 5682 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5683 | } finally { |
| 5684 | Binder.restoreCallingIdentity(identity); |
| 5685 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5686 | } |
| 5687 | |
| 5688 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5689 | * Set the network selection mode to automatic. |
| 5690 | * |
| 5691 | */ |
| 5692 | @Override |
| 5693 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5694 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5695 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5696 | |
| 5697 | final long identity = Binder.clearCallingIdentity(); |
| 5698 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5699 | if (!isActiveSubscription(subId)) { |
| 5700 | return; |
| 5701 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5702 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 5703 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 5704 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5705 | } finally { |
| 5706 | Binder.restoreCallingIdentity(identity); |
| 5707 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5708 | } |
| 5709 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5710 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5711 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5712 | * |
| 5713 | * @param subId the id of the subscription. |
| 5714 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5715 | * the operator to attach to. |
| 5716 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5717 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5718 | * normal network selection next time. |
| 5719 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5720 | */ |
| 5721 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5722 | public boolean setNetworkSelectionModeManual( |
| 5723 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5724 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5725 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5726 | |
| 5727 | if (!isActiveSubscription(subId)) { |
| 5728 | return false; |
| 5729 | } |
| 5730 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5731 | final long identity = Binder.clearCallingIdentity(); |
| 5732 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5733 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5734 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5735 | if (DBG) { |
| 5736 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5737 | + " operator: " + operatorInfo); |
| 5738 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5739 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5740 | } finally { |
| 5741 | Binder.restoreCallingIdentity(identity); |
| 5742 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5743 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5744 | /** |
| 5745 | * Get the manual network selection |
| 5746 | * |
| 5747 | * @param subId the id of the subscription. |
| 5748 | * |
| 5749 | * @return the previously saved user selected PLMN |
| 5750 | */ |
| 5751 | @Override |
| 5752 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5753 | TelephonyPermissions |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5754 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5755 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5756 | |
| 5757 | final long identity = Binder.clearCallingIdentity(); |
| 5758 | try { |
| 5759 | if (!isActiveSubscription(subId)) { |
| 5760 | return ""; |
| 5761 | } |
| 5762 | |
| 5763 | final Phone phone = getPhone(subId); |
| 5764 | if (phone == null) { |
| 5765 | return ""; |
| 5766 | } |
| 5767 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5768 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5769 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5770 | } finally { |
| 5771 | Binder.restoreCallingIdentity(identity); |
| 5772 | } |
| 5773 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5774 | |
| 5775 | /** |
| 5776 | * Scans for available networks. |
| 5777 | */ |
| 5778 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5779 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5780 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5781 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5782 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5783 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5784 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5785 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5786 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5787 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5788 | .setCallingPid(Binder.getCallingPid()) |
| 5789 | .setCallingUid(Binder.getCallingUid()) |
| 5790 | .setMethod("getCellNetworkScanResults") |
| 5791 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | 008b169 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 5792 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5793 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5794 | .build()); |
| 5795 | switch (locationResult) { |
| 5796 | case DENIED_HARD: |
| 5797 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5798 | case DENIED_SOFT: |
| 5799 | return null; |
| 5800 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5801 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5802 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5803 | try { |
| 5804 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5805 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5806 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5807 | } finally { |
| 5808 | Binder.restoreCallingIdentity(identity); |
| 5809 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5810 | } |
| 5811 | |
| 5812 | /** |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5813 | * Get the call forwarding info, given the call forwarding reason. |
| 5814 | */ |
| 5815 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5816 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5817 | ICallForwardingInfoCallback callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5818 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5819 | long identity = Binder.clearCallingIdentity(); |
| 5820 | try { |
| 5821 | if (DBG) { |
| 5822 | log("getCallForwarding: subId " + subId |
| 5823 | + " callForwardingReason" + callForwardingReason); |
| 5824 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5825 | |
| 5826 | Phone phone = getPhone(subId); |
| 5827 | if (phone == null) { |
| 5828 | try { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5829 | callback.onError( |
| 5830 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5831 | } catch (RemoteException e) { |
| 5832 | // ignore |
| 5833 | } |
| 5834 | return; |
| 5835 | } |
| 5836 | |
| 5837 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 5838 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 5839 | @Override |
| 5840 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 5841 | try { |
| 5842 | callback.onCallForwardingInfoAvailable(info); |
| 5843 | } catch (RemoteException e) { |
| 5844 | // ignore |
| 5845 | } |
| 5846 | } |
| 5847 | |
| 5848 | @Override |
| 5849 | public void onError(int error) { |
| 5850 | try { |
| 5851 | callback.onError(error); |
| 5852 | } catch (RemoteException e) { |
| 5853 | // ignore |
| 5854 | } |
| 5855 | } |
| 5856 | }); |
| 5857 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5858 | } finally { |
| 5859 | Binder.restoreCallingIdentity(identity); |
| 5860 | } |
| 5861 | } |
| 5862 | |
| 5863 | /** |
| 5864 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5865 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5866 | */ |
| 5867 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5868 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 5869 | IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5870 | enforceModifyPermission(); |
| 5871 | long identity = Binder.clearCallingIdentity(); |
| 5872 | try { |
| 5873 | if (DBG) { |
| 5874 | log("setCallForwarding: subId " + subId |
| 5875 | + " callForwardingInfo" + callForwardingInfo); |
| 5876 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5877 | |
| 5878 | Phone phone = getPhone(subId); |
| 5879 | if (phone == null) { |
| 5880 | try { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5881 | callback.accept( |
| 5882 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5883 | } catch (RemoteException e) { |
| 5884 | // ignore |
| 5885 | } |
| 5886 | return; |
| 5887 | } |
| 5888 | |
| 5889 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 5890 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5891 | |
| 5892 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5893 | } finally { |
| 5894 | Binder.restoreCallingIdentity(identity); |
| 5895 | } |
| 5896 | } |
| 5897 | |
| 5898 | /** |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5899 | * Get the call waiting status for a subId. |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5900 | */ |
| 5901 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5902 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | c63cf52 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 5903 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5904 | long identity = Binder.clearCallingIdentity(); |
| 5905 | try { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5906 | Phone phone = getPhone(subId); |
| 5907 | if (phone == null) { |
| 5908 | try { |
| 5909 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5910 | } catch (RemoteException e) { |
| 5911 | // ignore |
| 5912 | } |
| 5913 | return; |
| 5914 | } |
SongFerngWang | c63cf52 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 5915 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 5916 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 5917 | boolean requireUssd = c.getBoolean( |
| 5918 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5919 | |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5920 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | c63cf52 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 5921 | if (requireUssd) { |
| 5922 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 5923 | getSubscriptionCarrierId(subId)); |
| 5924 | String newUssdCommand = ""; |
| 5925 | try { |
| 5926 | newUssdCommand = carrierXmlParser.getFeature( |
| 5927 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 5928 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 5929 | } catch (NullPointerException e) { |
| 5930 | loge("Failed to generate USSD number" + e); |
| 5931 | } |
| 5932 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 5933 | mMainThreadHandler, callback, carrierXmlParser, |
| 5934 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 5935 | final String ussdCommand = newUssdCommand; |
| 5936 | Executors.newSingleThreadExecutor().execute(() -> { |
| 5937 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 5938 | }); |
| 5939 | } else { |
| 5940 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 5941 | callback::accept); |
| 5942 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 5943 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5944 | } finally { |
| 5945 | Binder.restoreCallingIdentity(identity); |
| 5946 | } |
| 5947 | } |
| 5948 | |
| 5949 | /** |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5950 | * Sets whether call waiting is enabled for a given subId. |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5951 | */ |
| 5952 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5953 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5954 | enforceModifyPermission(); |
| 5955 | long identity = Binder.clearCallingIdentity(); |
| 5956 | try { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5957 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 5958 | |
| 5959 | Phone phone = getPhone(subId); |
| 5960 | if (phone == null) { |
| 5961 | try { |
| 5962 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5963 | } catch (RemoteException e) { |
| 5964 | // ignore |
| 5965 | } |
| 5966 | return; |
| 5967 | } |
| 5968 | |
SongFerngWang | c63cf52 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 5969 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 5970 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 5971 | boolean requireUssd = c.getBoolean( |
| 5972 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5973 | |
SongFerngWang | c63cf52 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 5974 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 5975 | if (requireUssd) { |
| 5976 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 5977 | getSubscriptionCarrierId(subId)); |
| 5978 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 5979 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 5980 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 5981 | String newUssdCommand = ""; |
| 5982 | try { |
| 5983 | newUssdCommand = carrierXmlParser.getFeature( |
| 5984 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 5985 | .makeCommand(ssAction, null); |
| 5986 | } catch (NullPointerException e) { |
| 5987 | loge("Failed to generate USSD number" + e); |
| 5988 | } |
| 5989 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 5990 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 5991 | final String ussdCommand = newUssdCommand; |
| 5992 | Executors.newSingleThreadExecutor().execute(() -> { |
| 5993 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 5994 | }); |
| 5995 | } else { |
| 5996 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 5997 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5998 | |
| 5999 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6000 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 6001 | } finally { |
| 6002 | Binder.restoreCallingIdentity(identity); |
| 6003 | } |
| 6004 | } |
| 6005 | |
| 6006 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6007 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6008 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6009 | * @param subId id of the subscription |
| 6010 | * @param request contains the radio access networks with bands/channels to scan |
| 6011 | * @param messenger callback messenger for scan results or errors |
| 6012 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6013 | * @return the id of the requested scan which can be used to stop the scan. |
| 6014 | */ |
| 6015 | @Override |
| 6016 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6017 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6018 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6019 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6020 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6021 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6022 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6023 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6024 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6025 | .setCallingPid(Binder.getCallingPid()) |
| 6026 | .setCallingUid(Binder.getCallingUid()) |
| 6027 | .setMethod("requestNetworkScan") |
| 6028 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6029 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6030 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6031 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6032 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6033 | if (e != null) { |
| 6034 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6035 | throw e; |
| 6036 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6037 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6038 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6039 | } |
| 6040 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6041 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6042 | int callingUid = Binder.getCallingUid(); |
| 6043 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6044 | final long identity = Binder.clearCallingIdentity(); |
| 6045 | try { |
| 6046 | return mNetworkScanRequestTracker.startNetworkScan( |
| 6047 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6048 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6049 | } finally { |
| 6050 | Binder.restoreCallingIdentity(identity); |
| 6051 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6052 | } |
| 6053 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6054 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6055 | NetworkScanRequest request, int subId, String callingPackage) { |
| 6056 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6057 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6058 | boolean hasNetworkScanPermission = |
| 6059 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6060 | == PERMISSION_GRANTED; |
| 6061 | |
| 6062 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6063 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6064 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6065 | } |
| 6066 | |
| 6067 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6068 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6069 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6070 | return new SecurityException("Specific channels must not be" |
| 6071 | + " scanned without location access."); |
| 6072 | } |
| 6073 | } |
| 6074 | } |
| 6075 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6076 | return null; |
| 6077 | } |
| 6078 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6079 | /** |
| 6080 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6081 | * |
| 6082 | * @param subId id of the subscription |
| 6083 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6084 | */ |
| 6085 | @Override |
| 6086 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6087 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6088 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6089 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6090 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6091 | final long identity = Binder.clearCallingIdentity(); |
| 6092 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6093 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6094 | } finally { |
| 6095 | Binder.restoreCallingIdentity(identity); |
| 6096 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6097 | } |
| 6098 | |
| 6099 | /** |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6100 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6101 | * |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6102 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6103 | */ |
| 6104 | @Override |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6105 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6106 | TelephonyPermissions |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6107 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6108 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6109 | |
| 6110 | final long identity = Binder.clearCallingIdentity(); |
| 6111 | try { |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6112 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6113 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6114 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6115 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6116 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6117 | } finally { |
| 6118 | Binder.restoreCallingIdentity(identity); |
| 6119 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6120 | } |
| 6121 | |
| 6122 | /** |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6123 | * Get the allowed network types for certain reason. |
| 6124 | * |
| 6125 | * @param subId the id of the subscription. |
| 6126 | * @param reason the reason the allowed network type change is taking place |
| 6127 | * @return the allowed network types. |
| 6128 | */ |
| 6129 | @Override |
| 6130 | public long getAllowedNetworkTypesForReason(int subId, |
| 6131 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6132 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 522637d | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6133 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6134 | final long identity = Binder.clearCallingIdentity(); |
| 6135 | try { |
| 6136 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6137 | } finally { |
| 6138 | Binder.restoreCallingIdentity(identity); |
| 6139 | } |
| 6140 | } |
| 6141 | |
| 6142 | /** |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6143 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6144 | * @param subId subscription id of the sim card |
| 6145 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6146 | * This can be passed following states |
| 6147 | * <ol> |
| 6148 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6149 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6150 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6151 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6152 | * </ol> |
| 6153 | * @return operation result. |
| 6154 | */ |
| 6155 | @Override |
| 6156 | public int setNrDualConnectivityState(int subId, |
| 6157 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6158 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6159 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6160 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6161 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6162 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6163 | } |
| 6164 | |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6165 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6166 | final long identity = Binder.clearCallingIdentity(); |
| 6167 | try { |
| 6168 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6169 | nrDualConnectivityState, subId, |
| 6170 | workSource); |
| 6171 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6172 | return result; |
| 6173 | } finally { |
| 6174 | Binder.restoreCallingIdentity(identity); |
| 6175 | } |
| 6176 | } |
| 6177 | |
| 6178 | /** |
| 6179 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6180 | * @return true if dual connectivity is enabled else false |
| 6181 | */ |
| 6182 | @Override |
| 6183 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6184 | TelephonyPermissions |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6185 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6186 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6187 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6188 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6189 | return false; |
| 6190 | } |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6191 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6192 | final long identity = Binder.clearCallingIdentity(); |
| 6193 | try { |
| 6194 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6195 | null, subId, workSource); |
| 6196 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6197 | return isEnabled; |
| 6198 | } finally { |
| 6199 | Binder.restoreCallingIdentity(identity); |
| 6200 | } |
| 6201 | } |
| 6202 | |
| 6203 | /** |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6204 | * Set the allowed network types of the device and |
| 6205 | * provide the reason triggering the allowed network change. |
| 6206 | * |
| 6207 | * @param subId the id of the subscription. |
| 6208 | * @param reason the reason the allowed network type change is taking place |
| 6209 | * @param allowedNetworkTypes the allowed network types. |
| 6210 | * @return true on success; false on any failure. |
| 6211 | */ |
| 6212 | @Override |
| 6213 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6214 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6215 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6216 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6217 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6218 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
SongFerngWang | c2d3ccc | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6219 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
| 6220 | return false; |
| 6221 | } |
| 6222 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6223 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6224 | return false; |
| 6225 | } |
| 6226 | |
SongFerngWang | 522637d | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6227 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
| 6228 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6229 | |
| 6230 | |
| 6231 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
| 6232 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6233 | return true; |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6234 | } |
SongFerngWang | 522637d | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6235 | |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6236 | final long identity = Binder.clearCallingIdentity(); |
| 6237 | try { |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6238 | Boolean success = (Boolean) sendRequest( |
| 6239 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6240 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6241 | |
| 6242 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6243 | return success; |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6244 | } finally { |
| 6245 | Binder.restoreCallingIdentity(identity); |
| 6246 | } |
| 6247 | } |
| 6248 | |
| 6249 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6250 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6251 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6252 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6253 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6254 | * @hide |
| 6255 | */ |
| 6256 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6257 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6258 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6259 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6260 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6261 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6262 | if (phone != null) { |
| 6263 | return phone.hasMatchedTetherApnSetting(); |
| 6264 | } else { |
| 6265 | return false; |
| 6266 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6267 | } finally { |
| 6268 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6269 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6270 | } |
| 6271 | |
| 6272 | /** |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6273 | * Enable or disable always reporting signal strength changes from radio. |
| 6274 | * |
| 6275 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6276 | */ |
| 6277 | @Override |
| 6278 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6279 | enforceModifyPermission(); |
| 6280 | enforceSystemCaller(); |
| 6281 | |
| 6282 | final long identity = Binder.clearCallingIdentity(); |
| 6283 | final Phone phone = getPhone(subId); |
| 6284 | try { |
| 6285 | if (phone != null) { |
| 6286 | if (DBG) { |
| 6287 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6288 | + " isEnable=" + isEnable); |
| 6289 | } |
| 6290 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6291 | } else { |
| 6292 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6293 | + subId); |
| 6294 | } |
| 6295 | } finally { |
| 6296 | Binder.restoreCallingIdentity(identity); |
| 6297 | } |
| 6298 | } |
| 6299 | |
| 6300 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6301 | * Get the user enabled state of Mobile Data. |
| 6302 | * |
| 6303 | * TODO: remove and use isUserDataEnabled. |
| 6304 | * This can't be removed now because some vendor codes |
| 6305 | * calls through ITelephony directly while they should |
| 6306 | * use TelephonyManager. |
| 6307 | * |
| 6308 | * @return true on enabled |
| 6309 | */ |
| 6310 | @Override |
| 6311 | public boolean getDataEnabled(int subId) { |
| 6312 | return isUserDataEnabled(subId); |
| 6313 | } |
| 6314 | |
| 6315 | /** |
| 6316 | * Get whether mobile data is enabled per user setting. |
| 6317 | * |
| 6318 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6319 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6320 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6321 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6322 | * |
| 6323 | * @return {@code true} if data is enabled else {@code false} |
| 6324 | */ |
| 6325 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6326 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6327 | try { |
| 6328 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6329 | null); |
| 6330 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6331 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6332 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6333 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6334 | |
| 6335 | final long identity = Binder.clearCallingIdentity(); |
| 6336 | try { |
| 6337 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6338 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6339 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6340 | if (phone != null) { |
| 6341 | boolean retVal = phone.isUserDataEnabled(); |
| 6342 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6343 | return retVal; |
| 6344 | } else { |
| 6345 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6346 | return false; |
| 6347 | } |
| 6348 | } finally { |
| 6349 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6350 | } |
| 6351 | } |
| 6352 | |
| 6353 | /** |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6354 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6355 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6356 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6357 | * |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6358 | * @return {@code true} if the overall data connection is capable; {@code false} if not. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6359 | */ |
| 6360 | @Override |
| 6361 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6362 | try { |
| 6363 | try { |
| 6364 | mApp.enforceCallingOrSelfPermission( |
| 6365 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6366 | null); |
| 6367 | } catch (Exception e) { |
| 6368 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6369 | "isDataEnabled"); |
| 6370 | } |
| 6371 | } catch (Exception e) { |
| 6372 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6373 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6374 | |
| 6375 | final long identity = Binder.clearCallingIdentity(); |
| 6376 | try { |
| 6377 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6378 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6379 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6380 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6381 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6382 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6383 | return retVal; |
| 6384 | } else { |
| 6385 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6386 | return false; |
| 6387 | } |
| 6388 | } finally { |
| 6389 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6390 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6391 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6392 | |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6393 | /** |
| 6394 | * Check if data is enabled for a specific reason |
| 6395 | * @param subId Subscription index |
| 6396 | * @param reason the reason the data enable change is taking place |
| 6397 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6398 | */ |
| 6399 | @Override |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6400 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6401 | @TelephonyManager.DataEnabledReason int reason) { |
| 6402 | try { |
| 6403 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6404 | null); |
| 6405 | } catch (Exception e) { |
| 6406 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6407 | "isDataEnabledForReason"); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6408 | } |
| 6409 | |
| 6410 | |
| 6411 | final long identity = Binder.clearCallingIdentity(); |
| 6412 | try { |
| 6413 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6414 | if (DBG) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6415 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6416 | + " reason=" + reason); |
| 6417 | } |
| 6418 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6419 | if (phone != null) { |
| 6420 | boolean retVal; |
| 6421 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6422 | retVal = phone.isUserDataEnabled(); |
| 6423 | } else { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6424 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6425 | } |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6426 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6427 | return retVal; |
| 6428 | } else { |
| 6429 | if (DBG) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6430 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6431 | + subId + " retVal=false"); |
| 6432 | } |
| 6433 | return false; |
| 6434 | } |
| 6435 | } finally { |
| 6436 | Binder.restoreCallingIdentity(identity); |
| 6437 | } |
| 6438 | } |
| 6439 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6440 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6441 | Phone phone) { |
Sarah Chin | ca45c31 | 2021-04-09 10:37:15 -0700 | [diff] [blame] | 6442 | if (uid == Process.PHONE_UID) { |
| 6443 | // Skip the check if it's the phone UID (system UID removed in b/184713596) |
| 6444 | // TODO (b/184954344): Check for system/phone UID at call site instead of here |
Hall Liu | ce478d2 | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6445 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6446 | } |
| 6447 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6448 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6449 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6450 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6451 | || subController == null) return privilegeFromSim; |
| 6452 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6453 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6454 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6455 | |
| 6456 | final long identity = Binder.clearCallingIdentity(); |
| 6457 | try { |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6458 | int subId = phone.getSubId(); |
| 6459 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6460 | // A test override is in place for the privileges for this subId, so don't try to |
| 6461 | // read the subscription privileges. |
| 6462 | return privilegeFromSim; |
| 6463 | } |
| 6464 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6465 | SubscriptionManager subManager = (SubscriptionManager) |
| 6466 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6467 | for (String pkg : packages) { |
| 6468 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6469 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6470 | } |
| 6471 | } |
| 6472 | return privilegeFromSim; |
| 6473 | } finally { |
| 6474 | Binder.restoreCallingIdentity(identity); |
| 6475 | } |
| 6476 | } |
| 6477 | |
| 6478 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6479 | String pkgName) { |
| 6480 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6481 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6482 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6483 | || subController == null) return privilegeFromSim; |
| 6484 | |
| 6485 | final long identity = Binder.clearCallingIdentity(); |
| 6486 | try { |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6487 | int subId = phone.getSubId(); |
| 6488 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6489 | // A test override is in place for the privileges for this subId, so don't try to |
| 6490 | // read the subscription privileges. |
| 6491 | return privilegeFromSim; |
| 6492 | } |
| 6493 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6494 | SubscriptionManager subManager = (SubscriptionManager) |
| 6495 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6496 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6497 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6498 | } finally { |
| 6499 | Binder.restoreCallingIdentity(identity); |
| 6500 | } |
| 6501 | } |
| 6502 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6503 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6504 | public int getCarrierPrivilegeStatus(int subId) { |
| 6505 | final Phone phone = getPhone(subId); |
| 6506 | if (phone == null) { |
| 6507 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6508 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6509 | } |
| 6510 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6511 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6512 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6513 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6514 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6515 | |
| 6516 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6517 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6518 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6519 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6520 | |
| 6521 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6522 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6523 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6524 | final Phone phone = getPhone(subId); |
| 6525 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6526 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6527 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6528 | } |
| 6529 | UiccProfile profile = |
| 6530 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6531 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6532 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6533 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6534 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6535 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6536 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6537 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6538 | } |
| 6539 | |
| 6540 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6541 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6542 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6543 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6544 | } |
| 6545 | |
| 6546 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6547 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6548 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6549 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6550 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6551 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6552 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6553 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6554 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6555 | } |
| 6556 | |
| 6557 | @Override |
| 6558 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6559 | if (TextUtils.isEmpty(pkgName)) |
| 6560 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6561 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6562 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6563 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6564 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6565 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6566 | continue; |
| 6567 | } |
| 6568 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6569 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6570 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6571 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6572 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6573 | break; |
| 6574 | } |
| 6575 | } |
| 6576 | |
| 6577 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6578 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6579 | |
| 6580 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6581 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6582 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6583 | loge("phoneId " + phoneId + " is not valid."); |
| 6584 | return null; |
| 6585 | } |
| 6586 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6587 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6588 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6589 | return null ; |
| 6590 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6591 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6592 | } |
| 6593 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6594 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6595 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6596 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6597 | List<String> privilegedPackages = new ArrayList<>(); |
| 6598 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6599 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6600 | // has UICC in that slot. |
| 6601 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6602 | if (card.hasCarrierPrivilegeRules()) { |
| 6603 | if (packages == null) { |
| 6604 | // Only check packages in user 0 for now |
| 6605 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6606 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6607 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6608 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6609 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6610 | } |
| 6611 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6612 | PackageInfo pkgInfo = packages.get(p); |
| 6613 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6614 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6615 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6616 | privilegedPackages.add(pkgInfo.packageName); |
| 6617 | } |
| 6618 | } |
| 6619 | } |
| 6620 | } |
| 6621 | return privilegedPackages; |
| 6622 | } |
| 6623 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6624 | @Override |
| 6625 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6626 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6627 | |
| 6628 | final long identity = Binder.clearCallingIdentity(); |
| 6629 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6630 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6631 | try { |
| 6632 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6633 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6634 | } |
| 6635 | } finally { |
| 6636 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6637 | } |
| 6638 | return privilegedPackages; |
| 6639 | } |
| 6640 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6641 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6642 | final Phone phone = getPhone(subId); |
| 6643 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6644 | if (card == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6645 | return null; |
| 6646 | } |
| 6647 | String iccId = card.getIccId(); |
| 6648 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6649 | return null; |
| 6650 | } |
| 6651 | return iccId; |
| 6652 | } |
| 6653 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6654 | @Override |
Shuo Qian | 8aa1132 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6655 | public void setCallComposerStatus(int subId, int status) { |
| 6656 | enforceModifyPermission(); |
| 6657 | |
| 6658 | final long identity = Binder.clearCallingIdentity(); |
| 6659 | try { |
| 6660 | Phone phone = getPhone(subId); |
| 6661 | if (phone != null) { |
| 6662 | Phone defaultPhone = phone.getImsPhone(); |
| 6663 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6664 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6665 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | d878246 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6666 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6667 | .updateImsServiceConfig(); |
Shuo Qian | 8aa1132 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6668 | } |
| 6669 | } |
Shuo Qian | d878246 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6670 | } catch (ImsException e) { |
| 6671 | throw new ServiceSpecificException(e.getCode()); |
| 6672 | } finally { |
Shuo Qian | 8aa1132 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6673 | Binder.restoreCallingIdentity(identity); |
| 6674 | } |
| 6675 | } |
| 6676 | |
| 6677 | @Override |
| 6678 | public int getCallComposerStatus(int subId) { |
| 6679 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6680 | |
| 6681 | final long identity = Binder.clearCallingIdentity(); |
| 6682 | try { |
| 6683 | Phone phone = getPhone(subId); |
| 6684 | if (phone != null) { |
| 6685 | Phone defaultPhone = phone.getImsPhone(); |
| 6686 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6687 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6688 | return imsPhone.getCallComposerStatus(); |
| 6689 | } |
| 6690 | } |
| 6691 | } finally { |
| 6692 | Binder.restoreCallingIdentity(identity); |
| 6693 | } |
| 6694 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6695 | } |
| 6696 | |
| 6697 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6698 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6699 | String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6700 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6701 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6702 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6703 | final long identity = Binder.clearCallingIdentity(); |
| 6704 | try { |
| 6705 | final String iccId = getIccId(subId); |
| 6706 | final Phone phone = getPhone(subId); |
| 6707 | if (phone == null) { |
| 6708 | return false; |
| 6709 | } |
| 6710 | final String subscriberId = phone.getSubscriberId(); |
| 6711 | |
| 6712 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6713 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6714 | + subscriberId + " to " + number); |
| 6715 | } |
| 6716 | |
| 6717 | if (TextUtils.isEmpty(iccId)) { |
| 6718 | return false; |
| 6719 | } |
| 6720 | |
| 6721 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6722 | |
| 6723 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6724 | if (alphaTag == null) { |
| 6725 | editor.remove(alphaTagPrefKey); |
| 6726 | } else { |
| 6727 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6728 | } |
| 6729 | |
| 6730 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6731 | // track all merged IMSIs based on line number |
| 6732 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6733 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6734 | if (number == null) { |
| 6735 | editor.remove(numberPrefKey); |
| 6736 | editor.remove(subscriberPrefKey); |
| 6737 | } else { |
| 6738 | editor.putString(numberPrefKey, number); |
| 6739 | editor.putString(subscriberPrefKey, subscriberId); |
| 6740 | } |
| 6741 | |
| 6742 | editor.commit(); |
| 6743 | return true; |
| 6744 | } finally { |
| 6745 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6746 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6747 | } |
| 6748 | |
| 6749 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6750 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6751 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6752 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6753 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6754 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6755 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6756 | return null; |
| 6757 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6758 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6759 | final long identity = Binder.clearCallingIdentity(); |
| 6760 | try { |
| 6761 | String iccId = getIccId(subId); |
| 6762 | if (iccId != null) { |
| 6763 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6764 | if (DBG_MERGE) { |
| 6765 | log("getLine1NumberForDisplay returning " |
| 6766 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6767 | } |
| 6768 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6769 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6770 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6771 | return null; |
| 6772 | } finally { |
| 6773 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6774 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6775 | } |
| 6776 | |
| 6777 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6778 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6779 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6780 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6781 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6782 | return null; |
| 6783 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6784 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6785 | final long identity = Binder.clearCallingIdentity(); |
| 6786 | try { |
| 6787 | String iccId = getIccId(subId); |
| 6788 | if (iccId != null) { |
| 6789 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6790 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6791 | } |
| 6792 | return null; |
| 6793 | } finally { |
| 6794 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6795 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6796 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6797 | |
| 6798 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6799 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6800 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6801 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6802 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6803 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6804 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6805 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6806 | return null; |
| 6807 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6808 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6809 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6810 | // the process, where TelephonyManager was instantiated. |
| 6811 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6812 | final long identity = Binder.clearCallingIdentity(); |
| 6813 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6814 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6815 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6816 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6817 | |
| 6818 | // Figure out what subscribers are currently active |
| 6819 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6820 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6821 | // Only consider subs which match the current subId |
| 6822 | // This logic can be simplified. See b/131189269 for progress. |
| 6823 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6824 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6825 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6826 | |
| 6827 | // First pass, find a number override for an active subscriber |
| 6828 | String mergeNumber = null; |
| 6829 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6830 | for (String key : prefs.keySet()) { |
| 6831 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6832 | final String subscriberId = (String) prefs.get(key); |
| 6833 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6834 | final String iccId = key.substring( |
| 6835 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6836 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6837 | mergeNumber = (String) prefs.get(numberKey); |
| 6838 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6839 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6840 | + " for active subscriber " + subscriberId); |
| 6841 | } |
| 6842 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6843 | break; |
| 6844 | } |
| 6845 | } |
| 6846 | } |
| 6847 | } |
| 6848 | |
| 6849 | // Shortcut when no active merged subscribers |
| 6850 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6851 | return null; |
| 6852 | } |
| 6853 | |
| 6854 | // Second pass, find all subscribers under that line override |
| 6855 | final ArraySet<String> result = new ArraySet<>(); |
| 6856 | for (String key : prefs.keySet()) { |
| 6857 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6858 | final String number = (String) prefs.get(key); |
| 6859 | if (mergeNumber.equals(number)) { |
| 6860 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6861 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6862 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6863 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6864 | result.add(subscriberId); |
| 6865 | } |
| 6866 | } |
| 6867 | } |
| 6868 | } |
| 6869 | |
| 6870 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6871 | Arrays.sort(resultArray); |
| 6872 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6873 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6874 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6875 | } |
| 6876 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6877 | } finally { |
| 6878 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6879 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6880 | } |
| 6881 | |
| 6882 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6883 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6884 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6885 | |
| 6886 | final long identity = Binder.clearCallingIdentity(); |
| 6887 | try { |
| 6888 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6889 | TelephonyManager.class); |
| 6890 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6891 | if (subscriberId == null) { |
| 6892 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6893 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6894 | + subId); |
| 6895 | } |
| 6896 | return null; |
| 6897 | } |
| 6898 | |
| 6899 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6900 | .getSubscriptionInfo(subId); |
| 6901 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6902 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6903 | if (groupUuid == null) { |
| 6904 | return new String[]{subscriberId}; |
| 6905 | } |
| 6906 | |
| 6907 | // Get all subscriberIds from the group. |
| 6908 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6909 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6910 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6911 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6912 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6913 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6914 | if (subscriberId != null) { |
| 6915 | mergedSubscriberIds.add(subscriberId); |
| 6916 | } |
| 6917 | } |
| 6918 | |
| 6919 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6920 | } finally { |
| 6921 | Binder.restoreCallingIdentity(identity); |
| 6922 | |
| 6923 | } |
| 6924 | } |
| 6925 | |
| 6926 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6927 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6928 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6929 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6930 | |
| 6931 | final long identity = Binder.clearCallingIdentity(); |
| 6932 | try { |
| 6933 | final Phone phone = getPhone(subId); |
| 6934 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6935 | } finally { |
| 6936 | Binder.restoreCallingIdentity(identity); |
| 6937 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6938 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6939 | |
| 6940 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6941 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6942 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6943 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6944 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6945 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6946 | |
| 6947 | final long identity = Binder.clearCallingIdentity(); |
| 6948 | try { |
| 6949 | final Phone phone = getPhone(subId); |
| 6950 | if (phone == null) { |
| 6951 | return false; |
| 6952 | } |
| 6953 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6954 | cdmaNonRoamingList); |
| 6955 | } finally { |
| 6956 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6957 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6958 | } |
| 6959 | |
| 6960 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6961 | @Deprecated |
| 6962 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6963 | enforceModifyPermission(); |
| 6964 | |
| 6965 | int returnValue = 0; |
| 6966 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6967 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6968 | if(result.exception == null) { |
| 6969 | if (result.result != null) { |
| 6970 | byte[] responseData = (byte[])(result.result); |
| 6971 | if(responseData.length > oemResp.length) { |
| 6972 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6973 | responseData.length + "bytes. Buffer Size is " + |
| 6974 | oemResp.length + "bytes."); |
| 6975 | } |
| 6976 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6977 | returnValue = responseData.length; |
| 6978 | } |
| 6979 | } else { |
| 6980 | CommandException ex = (CommandException) result.exception; |
| 6981 | returnValue = ex.getCommandError().ordinal(); |
| 6982 | if(returnValue > 0) returnValue *= -1; |
| 6983 | } |
| 6984 | } catch (RuntimeException e) { |
| 6985 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6986 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6987 | if(returnValue > 0) returnValue *= -1; |
| 6988 | } |
| 6989 | |
| 6990 | return returnValue; |
| 6991 | } |
| 6992 | |
| 6993 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6994 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6995 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 6996 | try { |
| 6997 | TelephonyPermissions |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6998 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 6999 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7000 | } catch (SecurityException e) { |
| 7001 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7002 | throw e; |
| 7003 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7004 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7005 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7006 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7007 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7008 | final long identity = Binder.clearCallingIdentity(); |
| 7009 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7010 | TelephonyPermissions |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7011 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7012 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7013 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7014 | } finally { |
| 7015 | Binder.restoreCallingIdentity(identity); |
| 7016 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7017 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7018 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7019 | |
| 7020 | @Override |
| 7021 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7022 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7023 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7024 | |
| 7025 | final long identity = Binder.clearCallingIdentity(); |
| 7026 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7027 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7028 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7029 | } finally { |
| 7030 | Binder.restoreCallingIdentity(identity); |
| 7031 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7032 | } |
| 7033 | |
| 7034 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7035 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7036 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7037 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7038 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7039 | return false; |
| 7040 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7041 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7042 | final long identity = Binder.clearCallingIdentity(); |
| 7043 | try { |
| 7044 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7045 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7046 | // In the long run, we may instead need to check if there exists a connection service |
| 7047 | // which can support video calling. |
| 7048 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7049 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7050 | return imsManager.isVtEnabledByPlatform() |
| 7051 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7052 | && imsManager.isVtEnabledByUser(); |
| 7053 | } finally { |
| 7054 | Binder.restoreCallingIdentity(identity); |
| 7055 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7056 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7057 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7058 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7059 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7060 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7061 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7062 | mApp, subId, callingPackage, callingFeatureId, |
| 7063 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7064 | return false; |
| 7065 | } |
| 7066 | |
| 7067 | final long identity = Binder.clearCallingIdentity(); |
| 7068 | try { |
| 7069 | CarrierConfigManager configManager = |
| 7070 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7071 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7072 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7073 | } finally { |
| 7074 | Binder.restoreCallingIdentity(identity); |
| 7075 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7076 | } |
| 7077 | |
| 7078 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7079 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7080 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7081 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7082 | return false; |
| 7083 | } |
| 7084 | |
| 7085 | final long identity = Binder.clearCallingIdentity(); |
| 7086 | try { |
| 7087 | CarrierConfigManager configManager = |
| 7088 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7089 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7090 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7091 | } finally { |
| 7092 | Binder.restoreCallingIdentity(identity); |
| 7093 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7094 | } |
| 7095 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7096 | @Override |
| 7097 | public boolean isTtyModeSupported() { |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7098 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7099 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7100 | } |
| 7101 | |
| 7102 | @Override |
| 7103 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7104 | final long identity = Binder.clearCallingIdentity(); |
| 7105 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7106 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7107 | } finally { |
| 7108 | Binder.restoreCallingIdentity(identity); |
| 7109 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7110 | } |
| 7111 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7112 | /** |
| 7113 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7114 | * support for the feature and device firmware support. |
| 7115 | * |
| 7116 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7117 | */ |
| 7118 | @Override |
| 7119 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7120 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7121 | final Phone phone = getPhone(subscriptionId); |
| 7122 | if (phone == null) { |
| 7123 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7124 | return false; |
| 7125 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7126 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7127 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7128 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7129 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7130 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7131 | return isCarrierSupported && isDeviceSupported; |
| 7132 | } finally { |
| 7133 | Binder.restoreCallingIdentity(identity); |
| 7134 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7135 | } |
| 7136 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7137 | /** |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7138 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7139 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7140 | * Otherwise. only returns true if the device and carrier both also support RTT. |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7141 | */ |
| 7142 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7143 | final long identity = Binder.clearCallingIdentity(); |
| 7144 | try { |
Hall Liu | 63767ec | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7145 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7146 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7147 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7148 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7149 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7150 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7151 | } finally { |
| 7152 | Binder.restoreCallingIdentity(identity); |
| 7153 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7154 | } |
| 7155 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7156 | @Deprecated |
| 7157 | @Override |
| 7158 | public String getDeviceId(String callingPackage) { |
| 7159 | return getDeviceIdWithFeature(callingPackage, null); |
| 7160 | } |
| 7161 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7162 | /** |
| 7163 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7164 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7165 | * |
| 7166 | * <p>Requires Permission: |
| 7167 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7168 | */ |
| 7169 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7170 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7171 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7172 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7173 | return null; |
| 7174 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7175 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7176 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7177 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7178 | return null; |
| 7179 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7180 | |
| 7181 | final long identity = Binder.clearCallingIdentity(); |
| 7182 | try { |
| 7183 | return phone.getDeviceId(); |
| 7184 | } finally { |
| 7185 | Binder.restoreCallingIdentity(identity); |
| 7186 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7187 | } |
| 7188 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7189 | /** |
| 7190 | * {@hide} |
| 7191 | * Returns the IMS Registration Status on a particular subid |
| 7192 | * |
| 7193 | * @param subId |
| 7194 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7195 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7196 | Phone phone = getPhone(subId); |
| 7197 | if (phone != null) { |
| 7198 | return phone.isImsRegistered(); |
| 7199 | } else { |
| 7200 | return false; |
| 7201 | } |
| 7202 | } |
| 7203 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7204 | @Override |
| 7205 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7206 | final long identity = Binder.clearCallingIdentity(); |
| 7207 | try { |
| 7208 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 7209 | } finally { |
| 7210 | Binder.restoreCallingIdentity(identity); |
| 7211 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7212 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7213 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7214 | @Override |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7215 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7216 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7217 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7218 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7219 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7220 | } |
| 7221 | final long identity = Binder.clearCallingIdentity(); |
| 7222 | try { |
| 7223 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7224 | } finally { |
| 7225 | Binder.restoreCallingIdentity(identity); |
| 7226 | } |
| 7227 | } |
| 7228 | |
| 7229 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7230 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 7231 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 7232 | + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7233 | final long identity = Binder.clearCallingIdentity(); |
| 7234 | try { |
| 7235 | Phone phone = getPhone(subscriptionId); |
| 7236 | if (phone == null) { |
| 7237 | return null; |
| 7238 | } |
| 7239 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7240 | } finally { |
| 7241 | Binder.restoreCallingIdentity(identity); |
| 7242 | } |
| 7243 | } |
| 7244 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7245 | /** |
| 7246 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7247 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7248 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7249 | final long identity = Binder.clearCallingIdentity(); |
| 7250 | try { |
| 7251 | Phone phone = getPhone(subId); |
| 7252 | if (phone != null) { |
| 7253 | return phone.isWifiCallingEnabled(); |
| 7254 | } else { |
| 7255 | return false; |
| 7256 | } |
| 7257 | } finally { |
| 7258 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7259 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7260 | } |
| 7261 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7262 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7263 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7264 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7265 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7266 | final long identity = Binder.clearCallingIdentity(); |
| 7267 | try { |
| 7268 | Phone phone = getPhone(subId); |
| 7269 | if (phone != null) { |
| 7270 | return phone.isVideoEnabled(); |
| 7271 | } else { |
| 7272 | return false; |
| 7273 | } |
| 7274 | } finally { |
| 7275 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7276 | } |
| 7277 | } |
| 7278 | |
| 7279 | /** |
| 7280 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7281 | * defined in {@link ImsRegistrationImplBase}. |
| 7282 | */ |
| 7283 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7284 | final long identity = Binder.clearCallingIdentity(); |
| 7285 | try { |
| 7286 | Phone phone = getPhone(subId); |
| 7287 | if (phone != null) { |
| 7288 | return phone.getImsRegistrationTech(); |
| 7289 | } else { |
| 7290 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7291 | } |
| 7292 | } finally { |
| 7293 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7294 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7295 | } |
| 7296 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7297 | @Override |
| 7298 | public void factoryReset(int subId) { |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7299 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7300 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7301 | return; |
| 7302 | } |
| 7303 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7304 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7305 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7306 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7307 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7308 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7309 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7310 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7311 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 522637d | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7312 | Phone phone = getPhone(subId); |
SongFerngWang | 51ee2b1 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7313 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7314 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 7315 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7316 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7317 | // There has been issues when Sms raw table somehow stores orphan |
| 7318 | // fragments. They lead to garbled message when new fragments come |
| 7319 | // in and combined with those stale ones. In case this happens again, |
| 7320 | // user can reset all network settings which will clean up this table. |
| 7321 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7322 | // Clean up IMS settings as well here. |
| 7323 | int slotId = getSlotIndex(subId); |
| 7324 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7325 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7326 | } |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7327 | |
| 7328 | // Erase modem config if erase modem on network setting is enabled. |
| 7329 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7330 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7331 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 7332 | sendEraseModemConfig(getDefaultPhone()); |
| 7333 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7334 | } finally { |
| 7335 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7336 | } |
| 7337 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7338 | |
SongFerngWang | 51ee2b1 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7339 | @VisibleForTesting |
| 7340 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7341 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7342 | return; |
| 7343 | } |
| 7344 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7345 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7346 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7347 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7348 | "user=" + defaultNetworkType); |
| 7349 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7350 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7351 | defaultNetworkType, null); |
| 7352 | } |
| 7353 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7354 | private void cleanUpSmsRawTable(Context context) { |
| 7355 | ContentResolver resolver = context.getContentResolver(); |
| 7356 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7357 | resolver.delete(uri, null, null); |
| 7358 | } |
| 7359 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7360 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7361 | public String getSimLocaleForSubscriber(int subId) { |
| 7362 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7363 | final Phone phone = getPhone(subId); |
| 7364 | if (phone == null) { |
| 7365 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7366 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7367 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7368 | final long identity = Binder.clearCallingIdentity(); |
| 7369 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7370 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7371 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7372 | if (info == null) { |
| 7373 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7374 | return null; |
| 7375 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7376 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7377 | // preferences (EF-PL and EF-LI)... |
| 7378 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7379 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7380 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7381 | if (localeFromDefaultSim != null) { |
| 7382 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7383 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7384 | + localeFromDefaultSim); |
| 7385 | return localeFromDefaultSim.toLanguageTag(); |
| 7386 | } else { |
| 7387 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7388 | } |
| 7389 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7390 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7391 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7392 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7393 | // the SIM and carrier preferences does not include a country we add the country |
| 7394 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7395 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7396 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7397 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7398 | return mccLocale.toLanguageTag(); |
| 7399 | } |
| 7400 | |
| 7401 | if (DBG) log("No locale found - returning null"); |
| 7402 | return null; |
| 7403 | } finally { |
| 7404 | Binder.restoreCallingIdentity(identity); |
| 7405 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7406 | } |
| 7407 | |
| 7408 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7409 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7410 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7411 | } |
| 7412 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7413 | /** |
| 7414 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7415 | */ |
| 7416 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7417 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7418 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7419 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7420 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7421 | private final ModemActivityInfo mLastModemActivityInfo = |
Hall Liu | e831598 | 2020-10-09 19:00:11 -0700 | [diff] [blame^] | 7422 | new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7423 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7424 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7425 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7426 | * representing the state of the modem. |
| 7427 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7428 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7429 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7430 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7431 | */ |
| 7432 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7433 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7434 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7435 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7436 | |
| 7437 | final long identity = Binder.clearCallingIdentity(); |
| 7438 | try { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 7439 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7440 | } finally { |
| 7441 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7442 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7443 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7444 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7445 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7446 | // less than total activity duration. |
| 7447 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7448 | if (info == null) { |
| 7449 | return false; |
| 7450 | } |
| 7451 | int activityDurationMs = |
Hall Liu | e831598 | 2020-10-09 19:00:11 -0700 | [diff] [blame^] | 7452 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7453 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7454 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7455 | return (info.isValid() |
| 7456 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7457 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7458 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7459 | && (totalTxTimeMs <= activityDurationMs)); |
| 7460 | } |
| 7461 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7462 | /** |
| 7463 | * {@hide} |
| 7464 | * Returns the service state information on specified subscription. |
| 7465 | */ |
| 7466 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7467 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7468 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7469 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7470 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7471 | return null; |
| 7472 | } |
| 7473 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7474 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7475 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7476 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7477 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7478 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7479 | .setCallingPid(Binder.getCallingPid()) |
| 7480 | .setCallingUid(Binder.getCallingUid()) |
| 7481 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7482 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7483 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | 008b169 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7484 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7485 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7486 | .build()); |
| 7487 | |
| 7488 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7489 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7490 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7491 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7492 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7493 | .setCallingPid(Binder.getCallingPid()) |
| 7494 | .setCallingUid(Binder.getCallingUid()) |
| 7495 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7496 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7497 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
Hall Liu | 008b169 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7498 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7499 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7500 | .build()); |
| 7501 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7502 | boolean hasFinePermission = |
| 7503 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7504 | boolean hasCoarsePermission = |
| 7505 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7506 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7507 | final long identity = Binder.clearCallingIdentity(); |
| 7508 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7509 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7510 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7511 | Rlog.d(LOG_TAG, |
| 7512 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7513 | return null; |
| 7514 | } |
| 7515 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7516 | final Phone phone = getPhone(subId); |
| 7517 | if (phone == null) { |
| 7518 | return null; |
| 7519 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7520 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7521 | ServiceState ss = phone.getServiceState(); |
| 7522 | |
| 7523 | // Scrub out the location info in ServiceState depending on what level of access |
| 7524 | // the caller has. |
| 7525 | if (hasFinePermission) return ss; |
Malcolm Chen | db33797 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7526 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7527 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7528 | } finally { |
| 7529 | Binder.restoreCallingIdentity(identity); |
| 7530 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7531 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7532 | |
| 7533 | /** |
| 7534 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7535 | * |
| 7536 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7537 | * voicemail ringtone. |
| 7538 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7539 | * PhoneAccount. |
| 7540 | */ |
| 7541 | @Override |
| 7542 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7543 | final long identity = Binder.clearCallingIdentity(); |
| 7544 | try { |
| 7545 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7546 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7547 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7548 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7549 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7550 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7551 | } finally { |
| 7552 | Binder.restoreCallingIdentity(identity); |
| 7553 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7554 | } |
| 7555 | |
| 7556 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7557 | * Sets the per-account voicemail ringtone. |
| 7558 | * |
| 7559 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7560 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7561 | * |
| 7562 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7563 | * voicemail ringtone. |
| 7564 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7565 | * PhoneAccount. |
| 7566 | */ |
| 7567 | @Override |
| 7568 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7569 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7570 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7571 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7572 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7573 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7574 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7575 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7576 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7577 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7578 | |
| 7579 | final long identity = Binder.clearCallingIdentity(); |
| 7580 | try { |
| 7581 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7582 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7583 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7584 | } |
| 7585 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7586 | } finally { |
| 7587 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7588 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7589 | } |
| 7590 | |
| 7591 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7592 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7593 | * |
| 7594 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7595 | * voicemail vibration setting. |
| 7596 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7597 | */ |
| 7598 | @Override |
| 7599 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7600 | final long identity = Binder.clearCallingIdentity(); |
| 7601 | try { |
| 7602 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7603 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7604 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7605 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7606 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7607 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7608 | } finally { |
| 7609 | Binder.restoreCallingIdentity(identity); |
| 7610 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7611 | } |
| 7612 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7613 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7614 | * Sets the per-account voicemail vibration. |
| 7615 | * |
| 7616 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7617 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7618 | * |
| 7619 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7620 | * voicemail vibration setting. |
| 7621 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7622 | * specific PhoneAccount. |
| 7623 | */ |
| 7624 | @Override |
| 7625 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7626 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7627 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7628 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7629 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7630 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7631 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7632 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7633 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7634 | } |
| 7635 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7636 | final long identity = Binder.clearCallingIdentity(); |
| 7637 | try { |
| 7638 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7639 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7640 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7641 | } |
| 7642 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7643 | } finally { |
| 7644 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7645 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7646 | } |
| 7647 | |
| 7648 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7649 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7650 | * |
| 7651 | * @throws SecurityException if the caller does not have the required permission |
| 7652 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7653 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7654 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7655 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7656 | } |
| 7657 | |
| 7658 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7659 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7660 | * permission. |
| 7661 | * |
| 7662 | * @throws SecurityException if the caller does not have the required permission |
| 7663 | */ |
| 7664 | private void enforceSendSmsPermission() { |
| 7665 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7666 | } |
| 7667 | |
| 7668 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7669 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7670 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7671 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7672 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7673 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7674 | final long identity = Binder.clearCallingIdentity(); |
| 7675 | try { |
| 7676 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7677 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7678 | if (componentName == null) { |
| 7679 | throw new SecurityException( |
| 7680 | "Caller not current active visual voicemail package[null]"); |
| 7681 | } |
| 7682 | String vvmPackage = componentName.getPackageName(); |
| 7683 | if (!callingPackage.equals(vvmPackage)) { |
| 7684 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7685 | + vvmPackage + "]"); |
| 7686 | } |
| 7687 | } finally { |
| 7688 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7689 | } |
| 7690 | } |
| 7691 | |
| 7692 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7693 | * Return the application ID for the app type. |
| 7694 | * |
| 7695 | * @param subId the subscription ID that this request applies to. |
| 7696 | * @param appType the uicc app type. |
| 7697 | * @return Application ID for specificied app type, or null if no uicc. |
| 7698 | */ |
| 7699 | @Override |
| 7700 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7701 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7702 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7703 | |
| 7704 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7705 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7706 | if (phone == null) { |
| 7707 | return null; |
| 7708 | } |
| 7709 | String aid = null; |
| 7710 | try { |
| 7711 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7712 | .getApplicationByType(appType).getAid(); |
| 7713 | } catch (Exception e) { |
| 7714 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7715 | } |
| 7716 | return aid; |
| 7717 | } finally { |
| 7718 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7719 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7720 | } |
| 7721 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7722 | /** |
| 7723 | * Return the Electronic Serial Number. |
| 7724 | * |
| 7725 | * @param subId the subscription ID that this request applies to. |
| 7726 | * @return ESN or null if error. |
| 7727 | */ |
| 7728 | @Override |
| 7729 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7730 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7731 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7732 | |
| 7733 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7734 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7735 | if (phone == null) { |
| 7736 | return null; |
| 7737 | } |
| 7738 | String esn = null; |
| 7739 | try { |
| 7740 | esn = phone.getEsn(); |
| 7741 | } catch (Exception e) { |
| 7742 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7743 | } |
| 7744 | return esn; |
| 7745 | } finally { |
| 7746 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7747 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7748 | } |
| 7749 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7750 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7751 | * Return the Preferred Roaming List Version. |
| 7752 | * |
| 7753 | * @param subId the subscription ID that this request applies to. |
| 7754 | * @return PRLVersion or null if error. |
| 7755 | */ |
| 7756 | @Override |
| 7757 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7758 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7759 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7760 | |
| 7761 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7762 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7763 | if (phone == null) { |
| 7764 | return null; |
| 7765 | } |
| 7766 | String cdmaPrlVersion = null; |
| 7767 | try { |
| 7768 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7769 | } catch (Exception e) { |
| 7770 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7771 | } |
| 7772 | return cdmaPrlVersion; |
| 7773 | } finally { |
| 7774 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7775 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7776 | } |
| 7777 | |
| 7778 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7779 | * Get snapshot of Telephony histograms |
| 7780 | * @return List of Telephony histograms |
| 7781 | * @hide |
| 7782 | */ |
| 7783 | @Override |
| 7784 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7785 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7786 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7787 | |
| 7788 | final long identity = Binder.clearCallingIdentity(); |
| 7789 | try { |
| 7790 | return RIL.getTelephonyRILTimingHistograms(); |
| 7791 | } finally { |
| 7792 | Binder.restoreCallingIdentity(identity); |
| 7793 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7794 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7795 | |
| 7796 | /** |
| 7797 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7798 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7799 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7800 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7801 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7802 | * @return Integer with the result of the operation, as defined in {@link TelephonyManager}. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7803 | */ |
| 7804 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7805 | @TelephonyManager.SetCarrierRestrictionResult |
| 7806 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7807 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7808 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7809 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7810 | if (carrierRestrictionRules == null) { |
| 7811 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7812 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7813 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7814 | final long identity = Binder.clearCallingIdentity(); |
| 7815 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7816 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7817 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7818 | } finally { |
| 7819 | Binder.restoreCallingIdentity(identity); |
| 7820 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7821 | } |
| 7822 | |
| 7823 | /** |
| 7824 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7825 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7826 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7827 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7828 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7829 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7830 | */ |
| 7831 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7832 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7833 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7834 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7835 | |
| 7836 | final long identity = Binder.clearCallingIdentity(); |
| 7837 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7838 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7839 | if (response instanceof CarrierRestrictionRules) { |
| 7840 | return (CarrierRestrictionRules) response; |
| 7841 | } |
| 7842 | // Response is an Exception of some kind, |
| 7843 | // which is signalled to the user as a NULL retval |
| 7844 | return null; |
| 7845 | } catch (Exception e) { |
| 7846 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7847 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7848 | } finally { |
| 7849 | Binder.restoreCallingIdentity(identity); |
| 7850 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7851 | } |
| 7852 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7853 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7854 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7855 | * @param subId the subscription ID that this action applies to. |
| 7856 | * @param enabled control enable or disable radio. |
| 7857 | * {@hide} |
| 7858 | */ |
| 7859 | @Override |
| 7860 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7861 | enforceModifyPermission(); |
| 7862 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7863 | |
| 7864 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7865 | if (phone == null) { |
| 7866 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7867 | return; |
| 7868 | } |
| 7869 | try { |
| 7870 | phone.carrierActionSetRadioEnabled(enabled); |
| 7871 | } catch (Exception e) { |
| 7872 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7873 | } finally { |
| 7874 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7875 | } |
| 7876 | } |
| 7877 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7878 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7879 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7880 | * network status based on which carrier apps could apply actions accordingly, |
| 7881 | * enable/disable default url handler for example. |
| 7882 | * |
| 7883 | * @param subId the subscription ID that this action applies to. |
| 7884 | * @param report control start/stop reporting the default network status. |
| 7885 | * {@hide} |
| 7886 | */ |
| 7887 | @Override |
| 7888 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7889 | enforceModifyPermission(); |
| 7890 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7891 | |
| 7892 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7893 | if (phone == null) { |
| 7894 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7895 | return; |
| 7896 | } |
| 7897 | try { |
| 7898 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7899 | } catch (Exception e) { |
| 7900 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7901 | } finally { |
| 7902 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7903 | } |
| 7904 | } |
| 7905 | |
| 7906 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7907 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7908 | * @param subId the subscription ID that this action applies to. |
| 7909 | * {@hide} |
| 7910 | */ |
| 7911 | @Override |
| 7912 | public void carrierActionResetAll(int subId) { |
| 7913 | enforceModifyPermission(); |
| 7914 | final Phone phone = getPhone(subId); |
| 7915 | if (phone == null) { |
| 7916 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7917 | return; |
| 7918 | } |
| 7919 | try { |
| 7920 | phone.carrierActionResetAll(); |
| 7921 | } catch (Exception e) { |
| 7922 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7923 | } |
| 7924 | } |
| 7925 | |
| 7926 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7927 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7928 | * bug report is being generated. |
| 7929 | */ |
| 7930 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7931 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7932 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7933 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7934 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7935 | + Binder.getCallingPid() |
| 7936 | + ", uid=" + Binder.getCallingUid() |
| 7937 | + "without permission " |
| 7938 | + android.Manifest.permission.DUMP); |
| 7939 | return; |
| 7940 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7941 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7942 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7943 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7944 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7945 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7946 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7947 | @NonNull String[] args) { |
| 7948 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 7949 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 7950 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7951 | } |
| 7952 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7953 | /** |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7954 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7955 | * @param subId Subscription index |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7956 | * @param reason the reason the data enable change is taking place |
| 7957 | * @param enabled True if enabling the data, otherwise disabling. |
| 7958 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7959 | */ |
| 7960 | @Override |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7961 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7962 | boolean enabled) { |
| 7963 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 7964 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7965 | try { |
| 7966 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7967 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7968 | } catch (SecurityException se) { |
| 7969 | enforceModifyPermission(); |
| 7970 | } |
| 7971 | } else { |
| 7972 | enforceModifyPermission(); |
| 7973 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7974 | |
| 7975 | final long identity = Binder.clearCallingIdentity(); |
| 7976 | try { |
| 7977 | Phone phone = getPhone(subId); |
| 7978 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7979 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7980 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7981 | } else { |
| 7982 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 7983 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7984 | } |
| 7985 | } finally { |
| 7986 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7987 | } |
| 7988 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7989 | |
| 7990 | /** |
| 7991 | * Get Client request stats |
| 7992 | * @return List of Client Request Stats |
| 7993 | * @hide |
| 7994 | */ |
| 7995 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7996 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7997 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7998 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7999 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8000 | return null; |
| 8001 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8002 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8003 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8004 | final long identity = Binder.clearCallingIdentity(); |
| 8005 | try { |
| 8006 | if (phone != null) { |
| 8007 | return phone.getClientRequestStats(); |
| 8008 | } |
| 8009 | |
| 8010 | return null; |
| 8011 | } finally { |
| 8012 | Binder.restoreCallingIdentity(identity); |
| 8013 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8014 | } |
| 8015 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8016 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8017 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8018 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8019 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8020 | |
| 8021 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8022 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8023 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8024 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8025 | * @param state State of SIM (power down, power up, pass through) |
| 8026 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8027 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8028 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8029 | * |
| 8030 | **/ |
| 8031 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8032 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8033 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8034 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8035 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8036 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8037 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8038 | final long identity = Binder.clearCallingIdentity(); |
| 8039 | try { |
| 8040 | if (phone != null) { |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8041 | phone.setSimPowerState(state, null, workSource); |
| 8042 | } |
| 8043 | } finally { |
| 8044 | Binder.restoreCallingIdentity(identity); |
| 8045 | } |
| 8046 | } |
| 8047 | |
| 8048 | /** |
| 8049 | * Set SIM card power state. |
| 8050 | * |
| 8051 | * @param slotIndex SIM slot id. |
| 8052 | * @param state State of SIM (power down, power up, pass through) |
| 8053 | * @param callback callback to trigger after success or failure |
| 8054 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8055 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8056 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8057 | * |
| 8058 | **/ |
| 8059 | @Override |
| 8060 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8061 | IIntegerConsumer callback) { |
| 8062 | enforceModifyPermission(); |
| 8063 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8064 | |
| 8065 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8066 | |
| 8067 | final long identity = Binder.clearCallingIdentity(); |
| 8068 | try { |
| 8069 | if (phone != null) { |
| 8070 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8071 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8072 | } |
| 8073 | } finally { |
| 8074 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8075 | } |
| 8076 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8077 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8078 | private boolean isUssdApiAllowed(int subId) { |
| 8079 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8080 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8081 | if (configManager == null) { |
| 8082 | return false; |
| 8083 | } |
| 8084 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8085 | if (pb == null) { |
| 8086 | return false; |
| 8087 | } |
| 8088 | return pb.getBoolean( |
| 8089 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8090 | } |
| 8091 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8092 | /** |
| 8093 | * Check if phone is in emergency callback mode |
| 8094 | * @return true if phone is in emergency callback mode |
| 8095 | * @param subId sub id |
| 8096 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8097 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8098 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8099 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8100 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8101 | |
| 8102 | final long identity = Binder.clearCallingIdentity(); |
| 8103 | try { |
| 8104 | if (phone != null) { |
| 8105 | return phone.isInEcm(); |
| 8106 | } else { |
| 8107 | return false; |
| 8108 | } |
| 8109 | } finally { |
| 8110 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8111 | } |
| 8112 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8113 | |
| 8114 | /** |
| 8115 | * Get the current signal strength information for the given subscription. |
| 8116 | * Because this information is not updated when the device is in a low power state |
| 8117 | * it should not be relied-upon to be current. |
| 8118 | * @param subId Subscription index |
| 8119 | * @return the most recent cached signal strength info from the modem |
| 8120 | */ |
| 8121 | @Override |
| 8122 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8123 | final long identity = Binder.clearCallingIdentity(); |
| 8124 | try { |
| 8125 | Phone p = getPhone(subId); |
| 8126 | if (p == null) { |
| 8127 | return null; |
| 8128 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8129 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8130 | return p.getSignalStrength(); |
| 8131 | } finally { |
| 8132 | Binder.restoreCallingIdentity(identity); |
| 8133 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8134 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8135 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8136 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8137 | * Get the current modem radio state for the given slot. |
| 8138 | * @param slotIndex slot index. |
| 8139 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8140 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8141 | * @return the current radio power state from the modem |
| 8142 | */ |
| 8143 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8144 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8145 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8146 | if (phone != null) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8147 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8148 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8149 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8150 | } |
| 8151 | |
| 8152 | final long identity = Binder.clearCallingIdentity(); |
| 8153 | try { |
| 8154 | return phone.getRadioPowerState(); |
| 8155 | } finally { |
| 8156 | Binder.restoreCallingIdentity(identity); |
| 8157 | } |
| 8158 | } |
| 8159 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8160 | } |
| 8161 | |
| 8162 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8163 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8164 | * |
| 8165 | * <p>Requires one of the following permissions: |
| 8166 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 8167 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8168 | * privileges. |
| 8169 | * |
| 8170 | * @param subId subscription id |
| 8171 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8172 | * {@code false}. |
| 8173 | */ |
| 8174 | @Override |
| 8175 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 11263f3 | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8176 | try { |
| 8177 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8178 | null); |
| 8179 | } catch (Exception e) { |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8180 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | 11263f3 | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8181 | mApp, subId, "isDataRoamingEnabled"); |
| 8182 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8183 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8184 | boolean isEnabled = false; |
| 8185 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8186 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8187 | Phone phone = getPhone(subId); |
| 8188 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8189 | } finally { |
| 8190 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8191 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8192 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8193 | } |
| 8194 | |
| 8195 | |
| 8196 | /** |
| 8197 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8198 | * |
| 8199 | * <p> Requires permission: |
| 8200 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8201 | * privileges. |
| 8202 | * |
| 8203 | * @param subId subscription id |
| 8204 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8205 | */ |
| 8206 | @Override |
| 8207 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8208 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8209 | mApp, subId, "setDataRoamingEnabled"); |
| 8210 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8211 | final long identity = Binder.clearCallingIdentity(); |
| 8212 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8213 | Phone phone = getPhone(subId); |
| 8214 | if (phone != null) { |
| 8215 | phone.setDataRoamingEnabled(isEnabled); |
| 8216 | } |
| 8217 | } finally { |
| 8218 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8219 | } |
| 8220 | } |
| 8221 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8222 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8223 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8224 | TelephonyPermissions |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8225 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8226 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8227 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8228 | boolean isAllowed = true; |
| 8229 | final long identity = Binder.clearCallingIdentity(); |
| 8230 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8231 | Phone phone = getPhone(subId); |
| 8232 | if (phone != null) { |
| 8233 | isAllowed = phone.isCspPlmnEnabled(); |
| 8234 | } |
| 8235 | } finally { |
| 8236 | Binder.restoreCallingIdentity(identity); |
| 8237 | } |
| 8238 | return isAllowed; |
| 8239 | } |
| 8240 | |
| 8241 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8242 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | cfdfe3a | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8243 | // Verify that tha callingPackage belongs to the calling UID |
| 8244 | mApp.getSystemService(AppOpsManager.class) |
| 8245 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8246 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8247 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8248 | try { |
| 8249 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8250 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8251 | } catch (SecurityException e) { |
| 8252 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8253 | // has carrier privileges on an active UICC |
| 8254 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8255 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8256 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8257 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8258 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8259 | |
| 8260 | final long identity = Binder.clearCallingIdentity(); |
| 8261 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8262 | UiccController uiccController = UiccController.getInstance(); |
| 8263 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8264 | if (hasReadPermission) { |
| 8265 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8266 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8267 | |
| 8268 | // Remove private info if the caller doesn't have access |
| 8269 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8270 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8271 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8272 | // is available |
| 8273 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 8274 | if (card == null || card.getUiccProfile() == null) { |
| 8275 | // assume no access if the card or profile is unavailable |
| 8276 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8277 | continue; |
| 8278 | } |
| 8279 | UiccProfile profile = card.getUiccProfile(); |
| 8280 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8281 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8282 | filteredInfos.add(cardInfo); |
| 8283 | } else { |
| 8284 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8285 | } |
| 8286 | } |
| 8287 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8288 | } finally { |
| 8289 | Binder.restoreCallingIdentity(identity); |
| 8290 | } |
| 8291 | } |
| 8292 | |
| 8293 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8294 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8295 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8296 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8297 | final long identity = Binder.clearCallingIdentity(); |
| 8298 | try { |
| 8299 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8300 | if (slots == null) { |
| 8301 | Rlog.i(LOG_TAG, "slots is null."); |
| 8302 | return null; |
| 8303 | } |
| 8304 | |
| 8305 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8306 | for (int i = 0; i < slots.length; i++) { |
| 8307 | UiccSlot slot = slots[i]; |
| 8308 | if (slot == null) { |
| 8309 | continue; |
| 8310 | } |
| 8311 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8312 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8313 | UiccCard card = slot.getUiccCard(); |
| 8314 | if (card != null) { |
| 8315 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8316 | } else { |
Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8317 | cardId = slot.getEid(); |
| 8318 | if (TextUtils.isEmpty(cardId)) { |
| 8319 | cardId = slot.getIccId(); |
| 8320 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8321 | } |
| 8322 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8323 | if (cardId != null) { |
| 8324 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8325 | // if cardId is an EID, it's all digits so this is fine |
| 8326 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8327 | } |
| 8328 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8329 | int cardState = 0; |
| 8330 | switch (slot.getCardState()) { |
| 8331 | case CARDSTATE_ABSENT: |
| 8332 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8333 | break; |
| 8334 | case CARDSTATE_PRESENT: |
| 8335 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8336 | break; |
| 8337 | case CARDSTATE_ERROR: |
| 8338 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8339 | break; |
| 8340 | case CARDSTATE_RESTRICTED: |
| 8341 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8342 | break; |
| 8343 | default: |
| 8344 | break; |
| 8345 | |
| 8346 | } |
| 8347 | |
| 8348 | infos[i] = new UiccSlotInfo( |
| 8349 | slot.isActive(), |
| 8350 | slot.isEuicc(), |
| 8351 | cardId, |
| 8352 | cardState, |
| 8353 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8354 | slot.isExtendedApduSupported(), |
| 8355 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8356 | } |
| 8357 | return infos; |
| 8358 | } finally { |
| 8359 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8360 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8361 | } |
| 8362 | |
| 8363 | @Override |
| 8364 | public boolean switchSlots(int[] physicalSlots) { |
| 8365 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8366 | |
| 8367 | final long identity = Binder.clearCallingIdentity(); |
| 8368 | try { |
| 8369 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8370 | } finally { |
| 8371 | Binder.restoreCallingIdentity(identity); |
| 8372 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8373 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8374 | |
| 8375 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8376 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8377 | final long identity = Binder.clearCallingIdentity(); |
| 8378 | try { |
| 8379 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8380 | } finally { |
| 8381 | Binder.restoreCallingIdentity(identity); |
| 8382 | } |
| 8383 | } |
| 8384 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8385 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8386 | * A test API to reload the UICC profile. |
| 8387 | * |
| 8388 | * <p>Requires that the calling app has permission |
| 8389 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8390 | * @hide |
| 8391 | */ |
| 8392 | @Override |
| 8393 | public void refreshUiccProfile(int subId) { |
| 8394 | enforceModifyPermission(); |
| 8395 | |
| 8396 | final long identity = Binder.clearCallingIdentity(); |
| 8397 | try { |
| 8398 | Phone phone = getPhone(subId); |
| 8399 | if (phone == null) { |
| 8400 | return; |
| 8401 | } |
| 8402 | UiccCard uiccCard = phone.getUiccCard(); |
| 8403 | if (uiccCard == null) { |
| 8404 | return; |
| 8405 | } |
| 8406 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8407 | if (uiccProfile == null) { |
| 8408 | return; |
| 8409 | } |
| 8410 | uiccProfile.refresh(); |
| 8411 | } finally { |
| 8412 | Binder.restoreCallingIdentity(identity); |
| 8413 | } |
| 8414 | } |
| 8415 | |
| 8416 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8417 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8418 | */ |
| 8419 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8420 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8421 | } |
| 8422 | |
| 8423 | /** |
| 8424 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8425 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8426 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8427 | */ |
| 8428 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8429 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8430 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | faaa63d | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8431 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8432 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8433 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8434 | return isDataRoamingEnabled; |
| 8435 | } |
| 8436 | |
| 8437 | /** |
| 8438 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8439 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8440 | */ |
| 8441 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8442 | List<Integer> list = TelephonyProperties.default_network(); |
| 8443 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8444 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8445 | return list.get(phoneId); |
| 8446 | } |
| 8447 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8448 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8449 | |
| 8450 | @Override |
| 8451 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8452 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8453 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8454 | |
| 8455 | final long identity = Binder.clearCallingIdentity(); |
| 8456 | try { |
| 8457 | final Phone phone = getPhone(subId); |
| 8458 | if (phone == null) { |
| 8459 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8460 | return; |
| 8461 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8462 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8463 | carrierPrivilegeRules, apn); |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8464 | if (carrierPrivilegeRules == null) { |
| 8465 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8466 | } else { |
| 8467 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8468 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8469 | } finally { |
| 8470 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8471 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8472 | } |
| 8473 | |
| 8474 | @Override |
| 8475 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8476 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8477 | |
| 8478 | final long identity = Binder.clearCallingIdentity(); |
| 8479 | try { |
| 8480 | final Phone phone = getPhone(subId); |
| 8481 | if (phone == null) { |
| 8482 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8483 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8484 | } |
| 8485 | return phone.getCarrierIdListVersion(); |
| 8486 | } finally { |
| 8487 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8488 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8489 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8490 | |
| 8491 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8492 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8493 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8494 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8495 | mApp, subId, callingPackage, callingFeatureId, |
| 8496 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8497 | return -1; |
| 8498 | } |
| 8499 | |
| 8500 | final long identity = Binder.clearCallingIdentity(); |
| 8501 | try { |
| 8502 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8503 | } finally { |
| 8504 | Binder.restoreCallingIdentity(identity); |
| 8505 | } |
| 8506 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8507 | |
| 8508 | @Override |
| 8509 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 0723870 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8510 | TelephonyPermissions |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8511 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8512 | mApp, subId, "getCdmaRoamingMode"); |
| 8513 | |
| 8514 | final long identity = Binder.clearCallingIdentity(); |
| 8515 | try { |
| 8516 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8517 | } finally { |
| 8518 | Binder.restoreCallingIdentity(identity); |
| 8519 | } |
| 8520 | } |
| 8521 | |
| 8522 | @Override |
| 8523 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8524 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8525 | mApp, subId, "setCdmaRoamingMode"); |
| 8526 | |
| 8527 | final long identity = Binder.clearCallingIdentity(); |
| 8528 | try { |
| 8529 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8530 | } finally { |
| 8531 | Binder.restoreCallingIdentity(identity); |
| 8532 | } |
| 8533 | } |
| 8534 | |
| 8535 | @Override |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8536 | public int getCdmaSubscriptionMode(int subId) { |
| 8537 | TelephonyPermissions |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8538 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8539 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8540 | |
| 8541 | final long identity = Binder.clearCallingIdentity(); |
| 8542 | try { |
| 8543 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8544 | } finally { |
| 8545 | Binder.restoreCallingIdentity(identity); |
| 8546 | } |
| 8547 | } |
| 8548 | |
| 8549 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8550 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8551 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8552 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8553 | |
| 8554 | final long identity = Binder.clearCallingIdentity(); |
| 8555 | try { |
| 8556 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8557 | } finally { |
| 8558 | Binder.restoreCallingIdentity(identity); |
| 8559 | } |
| 8560 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8561 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8562 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8563 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8564 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8565 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8566 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8567 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8568 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8569 | } |
| 8570 | final long identity = Binder.clearCallingIdentity(); |
| 8571 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8572 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8573 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8574 | if (phone.getEmergencyNumberTracker() != null |
| 8575 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8576 | emergencyNumberListInternal.put( |
| 8577 | phone.getSubId(), |
| 8578 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8579 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8580 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8581 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8582 | } finally { |
| 8583 | Binder.restoreCallingIdentity(identity); |
| 8584 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8585 | } |
| 8586 | |
| 8587 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8588 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8589 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8590 | if (!exactMatch) { |
| 8591 | TelephonyPermissions |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8592 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8593 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8594 | } |
| 8595 | final long identity = Binder.clearCallingIdentity(); |
| 8596 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8597 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8598 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8599 | && phone.getEmergencyNumberTracker() |
| 8600 | .isEmergencyNumber(number, exactMatch)) { |
| 8601 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8602 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8603 | } |
| 8604 | return false; |
| 8605 | } finally { |
| 8606 | Binder.restoreCallingIdentity(identity); |
| 8607 | } |
| 8608 | } |
| 8609 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8610 | /** |
Shuo Qian | 479dd9e | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 8611 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 8612 | */ |
| 8613 | @Override |
| 8614 | public void startEmergencyCallbackMode() { |
| 8615 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8616 | "startEmergencyCallbackMode"); |
| 8617 | enforceModifyPermission(); |
| 8618 | final long identity = Binder.clearCallingIdentity(); |
| 8619 | try { |
| 8620 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8621 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 8622 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 8623 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 8624 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 8625 | gsmCdmaPhone.obtainMessage( |
| 8626 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 8627 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 8628 | } |
| 8629 | } |
| 8630 | } finally { |
| 8631 | Binder.restoreCallingIdentity(identity); |
| 8632 | } |
| 8633 | } |
| 8634 | |
| 8635 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8636 | * Update emergency number list for test mode. |
| 8637 | */ |
| 8638 | @Override |
| 8639 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8640 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8641 | "updateEmergencyNumberListTestMode"); |
| 8642 | |
| 8643 | final long identity = Binder.clearCallingIdentity(); |
| 8644 | try { |
| 8645 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8646 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8647 | if (tracker != null) { |
| 8648 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8649 | } |
| 8650 | } |
| 8651 | } finally { |
| 8652 | Binder.restoreCallingIdentity(identity); |
| 8653 | } |
| 8654 | } |
| 8655 | |
| 8656 | /** |
| 8657 | * Get the full emergency number list for test mode. |
| 8658 | */ |
| 8659 | @Override |
| 8660 | public List<String> getEmergencyNumberListTestMode() { |
| 8661 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8662 | "getEmergencyNumberListTestMode"); |
| 8663 | |
| 8664 | final long identity = Binder.clearCallingIdentity(); |
| 8665 | try { |
| 8666 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8667 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8668 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8669 | if (tracker != null) { |
| 8670 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8671 | emergencyNumbers.add(num.getNumber()); |
| 8672 | } |
| 8673 | } |
| 8674 | } |
| 8675 | return new ArrayList<>(emergencyNumbers); |
| 8676 | } finally { |
| 8677 | Binder.restoreCallingIdentity(identity); |
| 8678 | } |
| 8679 | } |
| 8680 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8681 | @Override |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8682 | public int getEmergencyNumberDbVersion(int subId) { |
| 8683 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8684 | |
| 8685 | final long identity = Binder.clearCallingIdentity(); |
| 8686 | try { |
| 8687 | final Phone phone = getPhone(subId); |
| 8688 | if (phone == null) { |
| 8689 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8690 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8691 | } |
| 8692 | return phone.getEmergencyNumberDbVersion(); |
| 8693 | } finally { |
| 8694 | Binder.restoreCallingIdentity(identity); |
| 8695 | } |
| 8696 | } |
| 8697 | |
| 8698 | @Override |
| 8699 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8700 | enforceModifyPermission(); |
| 8701 | |
| 8702 | final long identity = Binder.clearCallingIdentity(); |
| 8703 | try { |
| 8704 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8705 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8706 | if (tracker != null) { |
| 8707 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8708 | } |
| 8709 | } |
| 8710 | } finally { |
| 8711 | Binder.restoreCallingIdentity(identity); |
| 8712 | } |
| 8713 | } |
| 8714 | |
| 8715 | @Override |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8716 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8717 | enforceActiveEmergencySessionPermission(); |
| 8718 | |
| 8719 | final long identity = Binder.clearCallingIdentity(); |
| 8720 | try { |
| 8721 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8722 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8723 | if (tracker != null) { |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8724 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8725 | } |
| 8726 | } |
| 8727 | } finally { |
| 8728 | Binder.restoreCallingIdentity(identity); |
| 8729 | } |
| 8730 | } |
| 8731 | |
| 8732 | @Override |
| 8733 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8734 | enforceActiveEmergencySessionPermission(); |
| 8735 | |
| 8736 | final long identity = Binder.clearCallingIdentity(); |
| 8737 | try { |
| 8738 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8739 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8740 | if (tracker != null) { |
| 8741 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8742 | } |
| 8743 | } |
| 8744 | } finally { |
| 8745 | Binder.restoreCallingIdentity(identity); |
| 8746 | } |
| 8747 | } |
| 8748 | |
| 8749 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8750 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8751 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8752 | Phone phone = getPhone(subId); |
| 8753 | if (phone == null) { |
| 8754 | return null; |
| 8755 | } |
| 8756 | final long identity = Binder.clearCallingIdentity(); |
| 8757 | try { |
| 8758 | UiccProfile profile = UiccController.getInstance() |
| 8759 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8760 | if (profile != null) { |
| 8761 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8762 | } |
| 8763 | } finally { |
| 8764 | Binder.restoreCallingIdentity(identity); |
| 8765 | } |
| 8766 | return null; |
| 8767 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8768 | |
| 8769 | /** |
| 8770 | * Enable or disable a modem stack. |
| 8771 | */ |
| 8772 | @Override |
| 8773 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8774 | enforceModifyPermission(); |
| 8775 | |
| 8776 | final long identity = Binder.clearCallingIdentity(); |
| 8777 | try { |
| 8778 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8779 | if (phone == null) { |
| 8780 | return false; |
| 8781 | } else { |
| 8782 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8783 | } |
| 8784 | } finally { |
| 8785 | Binder.restoreCallingIdentity(identity); |
| 8786 | } |
| 8787 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8788 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8789 | /** |
| 8790 | * Whether a modem stack is enabled or not. |
| 8791 | */ |
| 8792 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8793 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8794 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8795 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8796 | if (phone == null) return false; |
| 8797 | |
| 8798 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8799 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8800 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8801 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8802 | } |
| 8803 | |
| 8804 | final long identity = Binder.clearCallingIdentity(); |
| 8805 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8806 | try { |
| 8807 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8808 | } catch (NoSuchElementException ex) { |
| 8809 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8810 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8811 | } finally { |
| 8812 | Binder.restoreCallingIdentity(identity); |
| 8813 | } |
| 8814 | } |
| 8815 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8816 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8817 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8818 | enforceModifyPermission(); |
| 8819 | |
| 8820 | final long identity = Binder.clearCallingIdentity(); |
| 8821 | try { |
| 8822 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8823 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8824 | .commit(); |
| 8825 | } finally { |
| 8826 | Binder.restoreCallingIdentity(identity); |
| 8827 | } |
| 8828 | } |
| 8829 | |
| 8830 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8831 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8832 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8833 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8834 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8835 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8836 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8837 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8838 | |
| 8839 | final long identity = Binder.clearCallingIdentity(); |
| 8840 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8841 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8842 | } finally { |
| 8843 | Binder.restoreCallingIdentity(identity); |
| 8844 | } |
| 8845 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8846 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8847 | @TelephonyManager.IsMultiSimSupportedResult |
| 8848 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8849 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8850 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8851 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8852 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8853 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8854 | } |
| 8855 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8856 | // supported by the modem, indicate that it is restricted. |
| 8857 | PhoneCapability staticCapability = |
| 8858 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8859 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8860 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8861 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8862 | } |
SongFerngWang | 2c4309d | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 8863 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8864 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8865 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8866 | } |
| 8867 | // Check if support of multiple SIMs is restricted by carrier |
| 8868 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8869 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8870 | } |
| 8871 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8872 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8873 | } |
| 8874 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8875 | /** |
| 8876 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8877 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8878 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8879 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8880 | * @param numOfSims number of active sims we want to switch to |
| 8881 | */ |
| 8882 | @Override |
| 8883 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8884 | if (numOfSims == 1) { |
| 8885 | enforceModifyPermission(); |
| 8886 | } else { |
| 8887 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8888 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8889 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8890 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8891 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8892 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8893 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8894 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8895 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8896 | return; |
| 8897 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8898 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8899 | } finally { |
| 8900 | Binder.restoreCallingIdentity(identity); |
| 8901 | } |
| 8902 | } |
| 8903 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8904 | @Override |
| 8905 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8906 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8907 | Phone phone = getPhone(subId); |
| 8908 | if (phone == null) { |
| 8909 | return false; |
| 8910 | } |
| 8911 | final long identity = Binder.clearCallingIdentity(); |
| 8912 | try { |
| 8913 | UiccCard uiccCard = phone.getUiccCard(); |
| 8914 | if (uiccCard == null) { |
| 8915 | return false; |
| 8916 | } |
| 8917 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8918 | if (uiccProfile == null) { |
| 8919 | return false; |
| 8920 | } |
| 8921 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8922 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8923 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8924 | } |
| 8925 | return false; |
| 8926 | } finally { |
| 8927 | Binder.restoreCallingIdentity(identity); |
| 8928 | } |
| 8929 | } |
| 8930 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8931 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8932 | * Get whether making changes to modem configurations will trigger reboot. |
| 8933 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8934 | */ |
| 8935 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8936 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8937 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8938 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8939 | mApp, subId, callingPackage, callingFeatureId, |
| 8940 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8941 | return false; |
| 8942 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8943 | final long identity = Binder.clearCallingIdentity(); |
| 8944 | try { |
| 8945 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8946 | } finally { |
| 8947 | Binder.restoreCallingIdentity(identity); |
| 8948 | } |
| 8949 | } |
| 8950 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8951 | private void updateModemStateMetrics() { |
| 8952 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8953 | // TODO: check the state for each modem if the api is ready. |
| 8954 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8955 | } |
| 8956 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8957 | @Override |
| 8958 | public int[] getSlotsMapping() { |
| 8959 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8960 | |
| 8961 | final long identity = Binder.clearCallingIdentity(); |
| 8962 | try { |
| 8963 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8964 | // All logical slots should have a mapping to a physical slot. |
| 8965 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8966 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8967 | for (int i = 0; i < slotInfos.length; i++) { |
| 8968 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8969 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8970 | } |
| 8971 | } |
| 8972 | return logicalSlotsMapping; |
| 8973 | } finally { |
| 8974 | Binder.restoreCallingIdentity(identity); |
| 8975 | } |
| 8976 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8977 | |
| 8978 | /** |
| 8979 | * Get the IRadio HAL Version |
| 8980 | */ |
| 8981 | @Override |
| 8982 | public int getRadioHalVersion() { |
| 8983 | Phone phone = getDefaultPhone(); |
| 8984 | if (phone == null) return -1; |
| 8985 | HalVersion hv = phone.getHalVersion(); |
| 8986 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8987 | return hv.major * 100 + hv.minor; |
| 8988 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8989 | |
| 8990 | /** |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8991 | * Get the current calling package name. |
| 8992 | * @return the current calling package name |
| 8993 | */ |
| 8994 | @Override |
| 8995 | public String getCurrentPackageName() { |
| 8996 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8997 | } |
| 8998 | |
| 8999 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9000 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9001 | * corresponding network requests on a subId. |
| 9002 | * |
| 9003 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9004 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9005 | * 2) APN is un-metered for this subscription, or |
| 9006 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9007 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9008 | * |
| 9009 | * @return whether data is allowed for a apn type. |
| 9010 | * |
| 9011 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9012 | */ |
| 9013 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9014 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | f250974 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9015 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9016 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9017 | |
| 9018 | // Now that all security checks passes, perform the operation as ourselves. |
| 9019 | final long identity = Binder.clearCallingIdentity(); |
| 9020 | try { |
| 9021 | Phone phone = getPhone(subId); |
| 9022 | if (phone == null) return false; |
| 9023 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9024 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9025 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 9026 | } finally { |
| 9027 | Binder.restoreCallingIdentity(identity); |
| 9028 | } |
| 9029 | } |
| 9030 | |
| 9031 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9032 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9033 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9034 | |
| 9035 | // Now that all security checks passes, perform the operation as ourselves. |
| 9036 | final long identity = Binder.clearCallingIdentity(); |
| 9037 | try { |
| 9038 | Phone phone = getPhone(subId); |
| 9039 | if (phone == null) return true; // By default return true. |
| 9040 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9041 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9042 | } finally { |
| 9043 | Binder.restoreCallingIdentity(identity); |
| 9044 | } |
| 9045 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9046 | |
| 9047 | @Override |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9048 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9049 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9050 | enforceModifyPermission(); |
| 9051 | long token = Binder.clearCallingIdentity(); |
| 9052 | try { |
| 9053 | Phone phone = getPhone(subscriptionId); |
| 9054 | if (phone == null) { |
| 9055 | try { |
| 9056 | if (resultCallback != null) { |
| 9057 | resultCallback.accept(false); |
| 9058 | } |
| 9059 | } catch (RemoteException e) { |
| 9060 | // ignore |
| 9061 | } |
| 9062 | return; |
| 9063 | } |
| 9064 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9065 | Pair.create(specifiers, (x) -> { |
| 9066 | try { |
| 9067 | if (resultCallback != null) { |
| 9068 | resultCallback.accept(x); |
| 9069 | } |
| 9070 | } catch (RemoteException e) { |
| 9071 | // ignore |
| 9072 | } |
| 9073 | }); |
| 9074 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9075 | } finally { |
| 9076 | Binder.restoreCallingIdentity(token); |
| 9077 | } |
| 9078 | } |
| 9079 | |
| 9080 | @Override |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9081 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9082 | TelephonyPermissions |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9083 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9084 | mApp, subId, "getSystemSelectionChannels"); |
| 9085 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9086 | final long identity = Binder.clearCallingIdentity(); |
| 9087 | try { |
Sarah Chin | 5869187 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 9088 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 9089 | if (result instanceof IllegalStateException) { |
| 9090 | throw (IllegalStateException) result; |
| 9091 | } |
| 9092 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9093 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9094 | return specifiers; |
| 9095 | } finally { |
| 9096 | Binder.restoreCallingIdentity(identity); |
| 9097 | } |
| 9098 | } |
| 9099 | |
| 9100 | @Override |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9101 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9102 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9103 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9104 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9105 | if (iccRecords == null) { |
| 9106 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9107 | return false; |
| 9108 | } |
| 9109 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9110 | } |
| 9111 | |
| 9112 | @Override |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9113 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9114 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9115 | if (callingPackage == null) { |
| 9116 | callingPackage = getCurrentPackageName(); |
| 9117 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9118 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9119 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9120 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9121 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9122 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9123 | } |
| 9124 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9125 | Intent intent = new Intent(); |
| 9126 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9127 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9128 | // Bring up choose default SMS subscription dialog right now |
| 9129 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9130 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9131 | mApp.startActivity(intent); |
| 9132 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9133 | |
| 9134 | @Override |
| 9135 | public String getMmsUAProfUrl(int subId) { |
| 9136 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9137 | final long identity = Binder.clearCallingIdentity(); |
| 9138 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9139 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9140 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9141 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9142 | return carrierUAProfUrl; |
| 9143 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9144 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9145 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 9146 | } finally { |
| 9147 | Binder.restoreCallingIdentity(identity); |
| 9148 | } |
| 9149 | } |
| 9150 | |
| 9151 | @Override |
| 9152 | public String getMmsUserAgent(int subId) { |
| 9153 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9154 | final long identity = Binder.clearCallingIdentity(); |
| 9155 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9156 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9157 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9158 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9159 | return carrierUserAgent; |
| 9160 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9161 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9162 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 9163 | } finally { |
| 9164 | Binder.restoreCallingIdentity(identity); |
| 9165 | } |
| 9166 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9167 | |
| 9168 | @Override |
Hall Liu | c041a55 | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9169 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9170 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
| 9171 | |
| 9172 | final long identity = Binder.clearCallingIdentity(); |
| 9173 | try { |
| 9174 | Phone phone = getPhone(subscriptionId); |
| 9175 | if (phone == null) return false; |
| 9176 | |
| 9177 | switch (policy) { |
| 9178 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9179 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9180 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9181 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9182 | default: |
| 9183 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9184 | } |
| 9185 | } finally { |
| 9186 | Binder.restoreCallingIdentity(identity); |
| 9187 | } |
| 9188 | } |
| 9189 | |
| 9190 | @Override |
| 9191 | public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy, |
| 9192 | boolean enabled) { |
| 9193 | enforceModifyPermission(); |
| 9194 | |
| 9195 | final long identity = Binder.clearCallingIdentity(); |
| 9196 | try { |
| 9197 | Phone phone = getPhone(subscriptionId); |
| 9198 | if (phone == null) return; |
| 9199 | |
| 9200 | switch (policy) { |
| 9201 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9202 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9203 | break; |
| 9204 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9205 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9206 | break; |
| 9207 | default: |
| 9208 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9209 | } |
| 9210 | } finally { |
| 9211 | Binder.restoreCallingIdentity(identity); |
| 9212 | } |
| 9213 | } |
| 9214 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9215 | /** |
Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9216 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9217 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9218 | * otherwise. |
| 9219 | */ |
| 9220 | @Override |
| 9221 | public void setCepEnabled(boolean isCepEnabled) { |
| 9222 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9223 | |
| 9224 | final long identity = Binder.clearCallingIdentity(); |
| 9225 | try { |
| 9226 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9227 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9228 | Phone defaultPhone = phone.getImsPhone(); |
| 9229 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9230 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9231 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9232 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9233 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9234 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9235 | + imsPhone.getMsisdn()); |
| 9236 | } |
| 9237 | } |
| 9238 | } finally { |
| 9239 | Binder.restoreCallingIdentity(identity); |
| 9240 | } |
| 9241 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9242 | |
| 9243 | /** |
| 9244 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9245 | * |
| 9246 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9247 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9248 | * before being read. |
| 9249 | */ |
| 9250 | @Override |
| 9251 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9252 | isCompressed) { |
| 9253 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9254 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9255 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9256 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9257 | } |
| 9258 | if (!isImsAvailableOnDevice()) { |
| 9259 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9260 | "IMS not available on device."); |
| 9261 | } |
| 9262 | |
| 9263 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9264 | try { |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9265 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9266 | } finally { |
| 9267 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9268 | } |
| 9269 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9270 | |
| 9271 | @Override |
| 9272 | public boolean isIccLockEnabled(int subId) { |
| 9273 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9274 | |
| 9275 | // Now that all security checks passes, perform the operation as ourselves. |
| 9276 | final long identity = Binder.clearCallingIdentity(); |
| 9277 | try { |
| 9278 | Phone phone = getPhone(subId); |
| 9279 | if (phone != null && phone.getIccCard() != null) { |
| 9280 | return phone.getIccCard().getIccLockEnabled(); |
| 9281 | } else { |
| 9282 | return false; |
| 9283 | } |
| 9284 | } finally { |
| 9285 | Binder.restoreCallingIdentity(identity); |
| 9286 | } |
| 9287 | } |
| 9288 | |
| 9289 | /** |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9290 | * Set the ICC pin lock enabled or disabled. |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9291 | * |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9292 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9293 | * three cases: |
| 9294 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9295 | * successfully. |
| 9296 | * - Positive number and zero for remaining password attempts. |
| 9297 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9298 | * |
| 9299 | */ |
| 9300 | @Override |
| 9301 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9302 | enforceModifyPermission(); |
| 9303 | |
| 9304 | Phone phone = getPhone(subId); |
| 9305 | if (phone == null) { |
| 9306 | return 0; |
| 9307 | } |
| 9308 | // Now that all security checks passes, perform the operation as ourselves. |
| 9309 | final long identity = Binder.clearCallingIdentity(); |
| 9310 | try { |
| 9311 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9312 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9313 | return attemptsRemaining; |
| 9314 | |
| 9315 | } catch (Exception e) { |
| 9316 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9317 | } finally { |
| 9318 | Binder.restoreCallingIdentity(identity); |
| 9319 | } |
| 9320 | return 0; |
| 9321 | } |
| 9322 | |
| 9323 | /** |
| 9324 | * Change the ICC password used in ICC pin lock. |
| 9325 | * |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9326 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9327 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9328 | * - Positive number and zero for remaining password attempts. |
| 9329 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9330 | * |
| 9331 | */ |
| 9332 | @Override |
| 9333 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9334 | enforceModifyPermission(); |
| 9335 | |
| 9336 | Phone phone = getPhone(subId); |
| 9337 | if (phone == null) { |
| 9338 | return 0; |
| 9339 | } |
| 9340 | // Now that all security checks passes, perform the operation as ourselves. |
| 9341 | final long identity = Binder.clearCallingIdentity(); |
| 9342 | try { |
| 9343 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9344 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9345 | return attemptsRemaining; |
| 9346 | |
| 9347 | } catch (Exception e) { |
| 9348 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9349 | } finally { |
| 9350 | Binder.restoreCallingIdentity(identity); |
| 9351 | } |
| 9352 | return 0; |
| 9353 | } |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9354 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9355 | /** |
| 9356 | * Request for receiving user activity notification |
| 9357 | */ |
| 9358 | @Override |
| 9359 | public void requestUserActivityNotification() { |
| 9360 | if (!mNotifyUserActivity.get() |
| 9361 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9362 | mNotifyUserActivity.set(true); |
| 9363 | } |
| 9364 | } |
| 9365 | |
| 9366 | /** |
| 9367 | * Called when userActivity is signalled in the power manager. |
| 9368 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9369 | */ |
| 9370 | @Override |
| 9371 | public void userActivity() { |
| 9372 | // *************************************** |
| 9373 | // * Inherited from PhoneWindowManager * |
| 9374 | // *************************************** |
| 9375 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9376 | // WITH ITS LOCKS HELD. |
| 9377 | // |
| 9378 | // This code must be VERY careful about the locks |
| 9379 | // it acquires. |
| 9380 | // In fact, the current code acquires way too many, |
| 9381 | // and probably has lurking deadlocks. |
| 9382 | |
| 9383 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9384 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9385 | } |
| 9386 | |
| 9387 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9388 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9389 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9390 | } |
| 9391 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9392 | |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9393 | @Override |
| 9394 | public boolean canConnectTo5GInDsdsMode() { |
| 9395 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9396 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9397 | |
| 9398 | @Override |
| 9399 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9400 | String callingFeatureId) { |
| 9401 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9402 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9403 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9404 | } |
| 9405 | |
| 9406 | Phone phone = getPhone(subId); |
| 9407 | if (phone == null) { |
| 9408 | throw new RuntimeException("phone is not available"); |
| 9409 | } |
| 9410 | // Now that all security checks passes, perform the operation as ourselves. |
| 9411 | final long identity = Binder.clearCallingIdentity(); |
| 9412 | try { |
| 9413 | return phone.getEquivalentHomePlmns(); |
| 9414 | } finally { |
| 9415 | Binder.restoreCallingIdentity(identity); |
| 9416 | } |
| 9417 | } |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9418 | |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9419 | @Override |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9420 | public boolean isRadioInterfaceCapabilitySupported( |
| 9421 | @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
Daniel Bright | 0176b32 | 2021-02-24 21:03:28 +0000 | [diff] [blame] | 9422 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | fe1e6ac | 2021-03-12 10:25:03 -0800 | [diff] [blame] | 9423 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9424 | if (radioInterfaceCapabilities == null) { |
| 9425 | throw new RuntimeException("radio interface capabilities are not available"); |
| 9426 | } else { |
Daniel Bright | 0176b32 | 2021-02-24 21:03:28 +0000 | [diff] [blame] | 9427 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9428 | } |
| 9429 | } |
| 9430 | |
| 9431 | @Override |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9432 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 9433 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9434 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 9435 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9436 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 9437 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9438 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9439 | if (DBG) { |
| 9440 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 9441 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 9442 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 9443 | } |
| 9444 | |
| 9445 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 9446 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 9447 | || appType > TelephonyManager.APPTYPE_ISIM |
| 9448 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 9449 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 9450 | if (callback != null) { |
| 9451 | try { |
| 9452 | callback.onAuthenticationFailure( |
| 9453 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 9454 | } catch (RemoteException exception) { |
| 9455 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 9456 | } |
| 9457 | return; |
| 9458 | } |
| 9459 | } |
| 9460 | |
| 9461 | final long token = Binder.clearCallingIdentity(); |
| 9462 | try { |
| 9463 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 9464 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 9465 | forceBootStrapping, callback)); |
| 9466 | } finally { |
| 9467 | Binder.restoreCallingIdentity(token); |
| 9468 | } |
| 9469 | } |
| 9470 | |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9471 | /** |
Sooraj Sasindran | 730fcba | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 9472 | * Attempts to set the radio power state for all phones for thermal reason. |
| 9473 | * This does not guarantee that the |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9474 | * requested radio power state will actually be set. See {@link |
| 9475 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9476 | * |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9477 | * @param enable {@code true} if trying to turn radio on. |
| 9478 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9479 | * false}. |
| 9480 | */ |
Sooraj Sasindran | 730fcba | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 9481 | private boolean setRadioPowerForThermal(boolean enable) { |
| 9482 | boolean isPhoneAvailable = false; |
| 9483 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 9484 | Phone phone = PhoneFactory.getPhone(i); |
| 9485 | if (phone != null) { |
| 9486 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 9487 | isPhoneAvailable = true; |
| 9488 | } |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9489 | } |
Sooraj Sasindran | 730fcba | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 9490 | |
| 9491 | // return true if successfully informed the phone object about the thermal radio power |
| 9492 | // request. |
| 9493 | return isPhoneAvailable; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9494 | } |
| 9495 | |
| 9496 | private int handleDataThrottlingRequest(int subId, |
| 9497 | DataThrottlingRequest dataThrottlingRequest) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 9498 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 9499 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 9500 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 9501 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 9502 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 9503 | } |
| 9504 | |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9505 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 9506 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 730fcba | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 9507 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9508 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9509 | } |
| 9510 | |
| 9511 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 9512 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 9513 | if (isDataThrottlingSupported) { |
| 9514 | int thermalMitigationResult = |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9515 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 9516 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 9517 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 9518 | } else if (thermalMitigationResult |
| 9519 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 2035259 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 9520 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 9521 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 9522 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 9523 | } |
| 9524 | return thermalMitigationResult; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9525 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 9526 | |
| 9527 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9528 | } |
| 9529 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 9530 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 9531 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 9532 | for (String pckg : context.getResources() |
| 9533 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 9534 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 9535 | } |
| 9536 | } |
| 9537 | |
| 9538 | return sThermalMitigationAllowlistedPackages; |
| 9539 | } |
| 9540 | |
Jack Nudelman | e634f96 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 9541 | private boolean isAnyPhoneInEmergencyState() { |
| 9542 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 9543 | if (tm.isInEmergencyCall()) { |
| 9544 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 9545 | return true; |
| 9546 | } |
| 9547 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9548 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 9549 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
| 9550 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 9551 | + phone.isInEcm()); |
| 9552 | return true; |
| 9553 | } |
| 9554 | } |
| 9555 | |
| 9556 | return false; |
| 9557 | } |
| 9558 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 9559 | /** |
| 9560 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 9561 | * @param packageName name of package to be allowlisted |
| 9562 | * @param context |
| 9563 | */ |
| 9564 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 9565 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 9566 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 9567 | } |
| 9568 | |
| 9569 | /** |
| 9570 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 9571 | * @param packageName name of package to remove from allowlist |
| 9572 | * @param context |
| 9573 | */ |
| 9574 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 9575 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 9576 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 9577 | } |
| 9578 | |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9579 | /** |
| 9580 | * Thermal mitigation request to control functionalities at modem. |
| 9581 | * |
| 9582 | * @param subId the id of the subscription. |
| 9583 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 9584 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9585 | * |
| 9586 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 9587 | */ |
| 9588 | @Override |
| 9589 | @ThermalMitigationResult |
| 9590 | public int sendThermalMitigationRequest( |
| 9591 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 9592 | ThermalMitigationRequest thermalMitigationRequest, |
| 9593 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9594 | enforceModifyPermission(); |
| 9595 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 9596 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 9597 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 9598 | .contains(callingPackage)) { |
| 9599 | throw new SecurityException("Calling package must be configured in the device config. " |
| 9600 | + "calling package: " + callingPackage); |
| 9601 | } |
| 9602 | |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9603 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9604 | final long identity = Binder.clearCallingIdentity(); |
| 9605 | |
| 9606 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 9607 | try { |
| 9608 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 9609 | switch (thermalMitigationAction) { |
| 9610 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 9611 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9612 | handleDataThrottlingRequest(subId, |
| 9613 | thermalMitigationRequest.getDataThrottlingRequest()); |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9614 | break; |
| 9615 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 9616 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9617 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 9618 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 9619 | } |
| 9620 | |
| 9621 | // Ensure that radio is on. If not able to power on due to phone being |
| 9622 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 730fcba | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 9623 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9624 | thermalMitigationResult = |
| 9625 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9626 | break; |
| 9627 | } |
| 9628 | |
| 9629 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 9630 | false); |
| 9631 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9632 | break; |
| 9633 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 9634 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9635 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 9636 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 9637 | } |
| 9638 | |
| 9639 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 9640 | if (registry != null) { |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9641 | Phone phone = getPhone(subId); |
| 9642 | if (phone == null) { |
| 9643 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9644 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9645 | break; |
| 9646 | } |
| 9647 | |
Jack Nudelman | e634f96 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 9648 | TelephonyConnectionService service = |
| 9649 | registry.getTelephonyConnectionService(); |
Jack Nudelman | a80c001 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 9650 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e634f96 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 9651 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 9652 | thermalMitigationResult = |
| 9653 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 9654 | break; |
| 9655 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9656 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9657 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9658 | break; |
| 9659 | } |
| 9660 | } else { |
| 9661 | thermalMitigationResult = |
| 9662 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9663 | break; |
| 9664 | } |
| 9665 | |
| 9666 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 9667 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 730fcba | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 9668 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9669 | thermalMitigationResult = |
| 9670 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9671 | break; |
| 9672 | } |
| 9673 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9674 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9675 | break; |
| 9676 | default: |
| 9677 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 9678 | + "not exist. Requested action: " + thermalMitigationAction); |
| 9679 | } |
| 9680 | } catch (IllegalArgumentException e) { |
| 9681 | throw e; |
| 9682 | } catch (Exception e) { |
| 9683 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 9684 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 9685 | } finally { |
| 9686 | Binder.restoreCallingIdentity(identity); |
| 9687 | } |
| 9688 | |
| 9689 | if (DBG) { |
| 9690 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 9691 | + thermalMitigationResult); |
| 9692 | } |
| 9693 | |
| 9694 | return thermalMitigationResult; |
| 9695 | } |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9696 | |
| 9697 | /** |
| 9698 | * Set the GbaService Package Name that Telephony will bind to. |
| 9699 | * |
| 9700 | * @param subId The sim that the GbaService is associated with. |
| 9701 | * @param packageName The name of the package to be replaced with. |
| 9702 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9703 | */ |
| 9704 | @Override |
| 9705 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 9706 | enforceModifyPermission(); |
| 9707 | |
| 9708 | final long identity = Binder.clearCallingIdentity(); |
| 9709 | try { |
| 9710 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 9711 | } finally { |
| 9712 | Binder.restoreCallingIdentity(identity); |
| 9713 | } |
| 9714 | } |
| 9715 | |
| 9716 | /** |
| 9717 | * Return the package name of the currently bound GbaService. |
| 9718 | * |
| 9719 | * @param subId The sim that the GbaService is associated with. |
| 9720 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 9721 | */ |
| 9722 | @Override |
| 9723 | public String getBoundGbaService(int subId) { |
| 9724 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 9725 | |
| 9726 | final long identity = Binder.clearCallingIdentity(); |
| 9727 | try { |
| 9728 | return getGbaManager(subId).getServicePackage(); |
| 9729 | } finally { |
| 9730 | Binder.restoreCallingIdentity(identity); |
| 9731 | } |
| 9732 | } |
| 9733 | |
| 9734 | /** |
| 9735 | * Set the release time for telephony to unbind GbaService. |
| 9736 | * |
| 9737 | * @param subId The sim that the GbaService is associated with. |
| 9738 | * @param interval The release time to unbind GbaService by millisecond. |
| 9739 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9740 | */ |
| 9741 | @Override |
| 9742 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 9743 | enforceModifyPermission(); |
| 9744 | |
| 9745 | final long identity = Binder.clearCallingIdentity(); |
| 9746 | try { |
| 9747 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 9748 | } finally { |
| 9749 | Binder.restoreCallingIdentity(identity); |
| 9750 | } |
| 9751 | } |
| 9752 | |
| 9753 | /** |
| 9754 | * Return the release time for telephony to unbind GbaService. |
| 9755 | * |
| 9756 | * @param subId The sim that the GbaService is associated with. |
| 9757 | * @return The release time to unbind GbaService by millisecond. |
| 9758 | */ |
| 9759 | @Override |
| 9760 | public int getGbaReleaseTime(int subId) { |
| 9761 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 9762 | |
| 9763 | final long identity = Binder.clearCallingIdentity(); |
| 9764 | try { |
| 9765 | return getGbaManager(subId).getReleaseTime(); |
| 9766 | } finally { |
| 9767 | Binder.restoreCallingIdentity(identity); |
| 9768 | } |
| 9769 | } |
| 9770 | |
| 9771 | private GbaManager getGbaManager(int subId) { |
| 9772 | GbaManager instance = GbaManager.getInstance(subId); |
| 9773 | if (instance == null) { |
| 9774 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 9775 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 9776 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 9777 | } |
| 9778 | return instance; |
| 9779 | } |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9780 | |
| 9781 | /** |
| 9782 | * indicate whether the device and the carrier can support |
| 9783 | * RCS VoLTE single registration. |
| 9784 | */ |
| 9785 | @Override |
| 9786 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9787 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9788 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 9789 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9790 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9791 | |
| 9792 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9793 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9794 | } |
| 9795 | |
| 9796 | final long identity = Binder.clearCallingIdentity(); |
| 9797 | try { |
| 9798 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 9799 | if (rpm != null) { |
Hui Wang | 048c10a | 2021-06-21 18:05:57 +0000 | [diff] [blame] | 9800 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 9801 | if (isCapable != null) { |
| 9802 | return isCapable; |
| 9803 | } |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9804 | } |
Hui Wang | 048c10a | 2021-06-21 18:05:57 +0000 | [diff] [blame] | 9805 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 9806 | "service is temporarily unavailable."); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9807 | } finally { |
| 9808 | Binder.restoreCallingIdentity(identity); |
| 9809 | } |
| 9810 | } |
| 9811 | |
| 9812 | /** |
| 9813 | * Register RCS provisioning callback. |
| 9814 | */ |
| 9815 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9816 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9817 | IRcsConfigCallback callback) { |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9818 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9819 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9820 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9821 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9822 | |
| 9823 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9824 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9825 | } |
| 9826 | if (!isImsAvailableOnDevice()) { |
| 9827 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9828 | "IMS not available on device."); |
| 9829 | } |
| 9830 | |
| 9831 | final long identity = Binder.clearCallingIdentity(); |
| 9832 | try { |
Hui Wang | 713d45f | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9833 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9834 | .registerRcsProvisioningCallback(subId, callback)) { |
Hui Wang | 713d45f | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9835 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9836 | "Service not available for the subscription."); |
| 9837 | } |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9838 | } finally { |
| 9839 | Binder.restoreCallingIdentity(identity); |
| 9840 | } |
| 9841 | } |
| 9842 | |
| 9843 | /** |
| 9844 | * Unregister RCS provisioning callback. |
| 9845 | */ |
| 9846 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9847 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9848 | IRcsConfigCallback callback) { |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9849 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9850 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9851 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9852 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9853 | |
| 9854 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9855 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9856 | } |
| 9857 | if (!isImsAvailableOnDevice()) { |
| 9858 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9859 | "IMS not available on device."); |
| 9860 | } |
| 9861 | |
| 9862 | final long identity = Binder.clearCallingIdentity(); |
| 9863 | try { |
Hui Wang | 713d45f | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9864 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9865 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9866 | } finally { |
| 9867 | Binder.restoreCallingIdentity(identity); |
| 9868 | } |
| 9869 | } |
| 9870 | |
| 9871 | /** |
| 9872 | * trigger RCS reconfiguration. |
| 9873 | */ |
| 9874 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9875 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 9876 | "triggerRcsReconfiguration", |
| 9877 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9878 | |
| 9879 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9880 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9881 | } |
| 9882 | if (!isImsAvailableOnDevice()) { |
| 9883 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9884 | "IMS not available on device."); |
| 9885 | } |
| 9886 | |
| 9887 | final long identity = Binder.clearCallingIdentity(); |
| 9888 | try { |
| 9889 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 9890 | } finally { |
| 9891 | Binder.restoreCallingIdentity(identity); |
| 9892 | } |
| 9893 | } |
| 9894 | |
| 9895 | /** |
| 9896 | * Provide the client configuration parameters of the RCS application. |
| 9897 | */ |
| 9898 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9899 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 9900 | "setRcsClientConfiguration", |
| 9901 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9902 | |
| 9903 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9904 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9905 | } |
| 9906 | if (!isImsAvailableOnDevice()) { |
| 9907 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9908 | "IMS not available on device."); |
| 9909 | } |
| 9910 | |
| 9911 | final long identity = Binder.clearCallingIdentity(); |
| 9912 | |
| 9913 | try { |
| 9914 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 9915 | if (configBinder == null) { |
| 9916 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
| 9917 | } else { |
| 9918 | configBinder.setRcsClientConfiguration(rcc); |
| 9919 | } |
| 9920 | } catch (RemoteException e) { |
| 9921 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
| 9922 | } finally { |
| 9923 | Binder.restoreCallingIdentity(identity); |
| 9924 | } |
| 9925 | } |
| 9926 | |
| 9927 | /** |
Hui Wang | 19a2187 | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 9928 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 9929 | */ |
| 9930 | @Override |
| 9931 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 9932 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9933 | "setRcsSingleRegistrationTestModeEnabled"); |
| 9934 | |
| 9935 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 9936 | } |
| 9937 | |
| 9938 | /** |
| 9939 | * Gets the test mode for RCS VoLTE single registration. |
| 9940 | */ |
| 9941 | @Override |
| 9942 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 9943 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9944 | "getRcsSingleRegistrationTestModeEnabled"); |
| 9945 | |
| 9946 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 9947 | } |
| 9948 | |
| 9949 | /** |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9950 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 9951 | */ |
| 9952 | @Override |
| 9953 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 9954 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9955 | "setDeviceSingleRegistrationEnabledOverride"); |
| 9956 | enforceModifyPermission(); |
| 9957 | |
| 9958 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9959 | : Boolean.parseBoolean(enabledStr); |
| 9960 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 9961 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9962 | } |
| 9963 | |
| 9964 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 9965 | * Sends a device to device communication message. Only usable via shell. |
| 9966 | * @param message message to send. |
| 9967 | * @param value message value. |
| 9968 | */ |
| 9969 | @Override |
| 9970 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 9971 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9972 | "setCarrierSingleRegistrationEnabledOverride"); |
| 9973 | enforceModifyPermission(); |
| 9974 | |
| 9975 | final long identity = Binder.clearCallingIdentity(); |
| 9976 | try { |
| 9977 | TelephonyConnectionService service = |
| 9978 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 9979 | if (service == null) { |
| 9980 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 9981 | return; |
| 9982 | } |
| 9983 | service.sendTestDeviceToDeviceMessage(message, value); |
| 9984 | } finally { |
| 9985 | Binder.restoreCallingIdentity(identity); |
| 9986 | } |
| 9987 | } |
| 9988 | |
| 9989 | |
| 9990 | /** |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9991 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 9992 | */ |
| 9993 | @Override |
| 9994 | public boolean getDeviceSingleRegistrationEnabled() { |
| 9995 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 9996 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 9997 | } |
| 9998 | |
| 9999 | /** |
| 10000 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10001 | */ |
| 10002 | @Override |
| 10003 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10004 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10005 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10006 | enforceModifyPermission(); |
| 10007 | |
| 10008 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10009 | : Boolean.parseBoolean(enabledStr); |
| 10010 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10011 | subId, enabled); |
| 10012 | } |
| 10013 | |
| 10014 | /** |
| 10015 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10016 | */ |
| 10017 | @Override |
| 10018 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10019 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 10020 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 10021 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10022 | |
| 10023 | /** |
Hui Wang | eadb256 | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 10024 | * Overrides the ims feature validation result |
| 10025 | */ |
| 10026 | @Override |
| 10027 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 10028 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10029 | "setImsFeatureValidationOverride"); |
| 10030 | |
| 10031 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10032 | : Boolean.parseBoolean(enabledStr); |
| 10033 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 10034 | subId, enabled); |
| 10035 | } |
| 10036 | |
| 10037 | /** |
| 10038 | * Gets the ims feature validation override value |
| 10039 | */ |
| 10040 | @Override |
| 10041 | public boolean getImsFeatureValidationOverride(int subId) { |
| 10042 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10043 | "getImsFeatureValidationOverride"); |
| 10044 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 10045 | } |
| 10046 | |
| 10047 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10048 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 10049 | * their mobile plan. |
| 10050 | */ |
| 10051 | @Override |
| 10052 | public String getMobileProvisioningUrl() { |
| 10053 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 10054 | final long identity = Binder.clearCallingIdentity(); |
| 10055 | try { |
| 10056 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 10057 | } finally { |
| 10058 | Binder.restoreCallingIdentity(identity); |
| 10059 | } |
| 10060 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10061 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10062 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 10063 | * Get the EAB contact from the EAB database. |
| 10064 | */ |
| 10065 | @Override |
| 10066 | public String getContactFromEab(String contact) { |
| 10067 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 10068 | enforceModifyPermission(); |
| 10069 | final long identity = Binder.clearCallingIdentity(); |
| 10070 | try { |
| 10071 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 10072 | } finally { |
| 10073 | Binder.restoreCallingIdentity(identity); |
| 10074 | } |
| 10075 | } |
| 10076 | |
| 10077 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10078 | * Remove the EAB contacts from the EAB database. |
| 10079 | */ |
| 10080 | @Override |
| 10081 | public int removeContactFromEab(int subId, String contacts) { |
| 10082 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 10083 | enforceModifyPermission(); |
| 10084 | final long identity = Binder.clearCallingIdentity(); |
| 10085 | try { |
| 10086 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 10087 | } finally { |
| 10088 | Binder.restoreCallingIdentity(identity); |
| 10089 | } |
| 10090 | } |
| 10091 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10092 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10093 | public boolean getDeviceUceEnabled() { |
| 10094 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 10095 | final long identity = Binder.clearCallingIdentity(); |
| 10096 | try { |
| 10097 | return mApp.getDeviceUceEnabled(); |
| 10098 | } finally { |
| 10099 | Binder.restoreCallingIdentity(identity); |
| 10100 | } |
| 10101 | } |
| 10102 | |
| 10103 | @Override |
| 10104 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 10105 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 10106 | final long identity = Binder.clearCallingIdentity(); |
| 10107 | try { |
| 10108 | mApp.setDeviceUceEnabled(isEnabled); |
| 10109 | } finally { |
| 10110 | Binder.restoreCallingIdentity(identity); |
| 10111 | } |
| 10112 | } |
| 10113 | |
Brad Ebinger | d4c5bde | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10114 | /** |
| 10115 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10116 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10117 | */ |
| 10118 | // Used for SHELL command only right now. |
| 10119 | @Override |
| 10120 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 10121 | List<String> featureTags) { |
| 10122 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10123 | "addUceRegistrationOverrideShell"); |
| 10124 | final long identity = Binder.clearCallingIdentity(); |
| 10125 | try { |
| 10126 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 10127 | new ArraySet<>(featureTags)); |
| 10128 | } catch (ImsException e) { |
| 10129 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10130 | } finally { |
| 10131 | Binder.restoreCallingIdentity(identity); |
| 10132 | } |
| 10133 | } |
| 10134 | |
| 10135 | /** |
| 10136 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10137 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10138 | */ |
| 10139 | // Used for SHELL command only right now. |
| 10140 | @Override |
| 10141 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 10142 | List<String> featureTags) { |
| 10143 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10144 | "removeUceRegistrationOverrideShell"); |
| 10145 | final long identity = Binder.clearCallingIdentity(); |
| 10146 | try { |
| 10147 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 10148 | new ArraySet<>(featureTags)); |
| 10149 | } catch (ImsException e) { |
| 10150 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10151 | } finally { |
| 10152 | Binder.restoreCallingIdentity(identity); |
| 10153 | } |
| 10154 | } |
| 10155 | |
| 10156 | /** |
| 10157 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 10158 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10159 | */ |
| 10160 | // Used for SHELL command only right now. |
| 10161 | @Override |
| 10162 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 10163 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10164 | "clearUceRegistrationOverrideShell"); |
| 10165 | final long identity = Binder.clearCallingIdentity(); |
| 10166 | try { |
| 10167 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 10168 | } catch (ImsException e) { |
| 10169 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10170 | } finally { |
| 10171 | Binder.restoreCallingIdentity(identity); |
| 10172 | } |
| 10173 | } |
| 10174 | |
| 10175 | /** |
| 10176 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10177 | */ |
| 10178 | // Used for SHELL command only right now. |
| 10179 | @Override |
| 10180 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 10181 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10182 | "getLatestRcsContactUceCapabilityShell"); |
| 10183 | final long identity = Binder.clearCallingIdentity(); |
| 10184 | try { |
| 10185 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 10186 | } catch (ImsException e) { |
| 10187 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10188 | } finally { |
| 10189 | Binder.restoreCallingIdentity(identity); |
| 10190 | } |
| 10191 | } |
| 10192 | |
| 10193 | /** |
| 10194 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 10195 | * device does not have an active PUBLISH. |
| 10196 | */ |
| 10197 | // Used for SHELL command only right now. |
| 10198 | @Override |
| 10199 | public String getLastUcePidfXmlShell(int subId) { |
| 10200 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 10201 | final long identity = Binder.clearCallingIdentity(); |
| 10202 | try { |
| 10203 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 10204 | } catch (ImsException e) { |
| 10205 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10206 | } finally { |
| 10207 | Binder.restoreCallingIdentity(identity); |
| 10208 | } |
| 10209 | } |
| 10210 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 10211 | /** |
| 10212 | * Remove UCE requests cannot be sent to the network status. |
| 10213 | */ |
| 10214 | // Used for SHELL command only right now. |
| 10215 | @Override |
| 10216 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 10217 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 10218 | final long identity = Binder.clearCallingIdentity(); |
| 10219 | try { |
| 10220 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 10221 | } catch (ImsException e) { |
| 10222 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10223 | } finally { |
| 10224 | Binder.restoreCallingIdentity(identity); |
| 10225 | } |
| 10226 | } |
| 10227 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 10228 | /** |
| 10229 | * Remove UCE requests cannot be sent to the network status. |
| 10230 | */ |
| 10231 | // Used for SHELL command only. |
| 10232 | @Override |
| 10233 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 10234 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 10235 | final long identity = Binder.clearCallingIdentity(); |
| 10236 | try { |
| 10237 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 10238 | } catch (ImsException e) { |
| 10239 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10240 | } finally { |
| 10241 | Binder.restoreCallingIdentity(identity); |
| 10242 | } |
| 10243 | } |
Brad Ebinger | d4c5bde | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10244 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10245 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10246 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10247 | String callingPackage) { |
| 10248 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10249 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 10250 | |
| 10251 | final int callingUid = Binder.getCallingUid(); |
| 10252 | // Verify that tha callingPackage belongs to the calling UID |
| 10253 | mApp.getSystemService(AppOpsManager.class) |
| 10254 | .checkPackage(callingUid, callingPackage); |
| 10255 | |
| 10256 | validateSignalStrengthUpdateRequest(request, callingUid); |
| 10257 | |
| 10258 | final long identity = Binder.clearCallingIdentity(); |
| 10259 | try { |
| 10260 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10261 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10262 | |
| 10263 | if (result instanceof IllegalStateException) { |
| 10264 | throw (IllegalStateException) result; |
| 10265 | } |
| 10266 | } finally { |
| 10267 | Binder.restoreCallingIdentity(identity); |
| 10268 | } |
| 10269 | } |
| 10270 | |
| 10271 | @Override |
| 10272 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10273 | String callingPackage) { |
| 10274 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10275 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 10276 | |
| 10277 | final int callingUid = Binder.getCallingUid(); |
| 10278 | // Verify that tha callingPackage belongs to the calling UID |
| 10279 | mApp.getSystemService(AppOpsManager.class) |
| 10280 | .checkPackage(callingUid, callingPackage); |
| 10281 | |
| 10282 | final long identity = Binder.clearCallingIdentity(); |
| 10283 | try { |
| 10284 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10285 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10286 | |
| 10287 | if (result instanceof IllegalStateException) { |
| 10288 | throw (IllegalStateException) result; |
| 10289 | } |
| 10290 | } finally { |
| 10291 | Binder.restoreCallingIdentity(identity); |
| 10292 | } |
| 10293 | } |
| 10294 | |
| 10295 | private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request, |
| 10296 | int callingUid) { |
| 10297 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 10298 | // phone/system process do not have further restriction on request |
| 10299 | return; |
| 10300 | } |
| 10301 | |
| 10302 | // Applications has restrictions on how to use the request: |
| 10303 | // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle |
| 10304 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
| 10305 | // This is not system caller which has been checked above |
| 10306 | throw new IllegalArgumentException( |
| 10307 | "Only system can set isSystemThresholdReportingRequestedWhileIdle"); |
| 10308 | } |
| 10309 | |
| 10310 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 10311 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 10312 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 10313 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 10314 | || info.isEnabled()) { |
| 10315 | throw new IllegalArgumentException( |
| 10316 | "Only system can set hide fields in SignalThresholdInfo"); |
| 10317 | } |
| 10318 | |
| 10319 | // Thresholds length for each RAN need in range. This has been validated in |
| 10320 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 10321 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 10322 | final int[] thresholds = info.getThresholds(); |
| 10323 | Objects.requireNonNull(thresholds); |
| 10324 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 10325 | || thresholds.length |
| 10326 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 10327 | throw new IllegalArgumentException( |
| 10328 | "thresholds length is out of range: " + thresholds.length); |
| 10329 | } |
| 10330 | } |
| 10331 | } |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 10332 | |
| 10333 | /** |
| 10334 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 10335 | * required to be done shortly after the API is invoked. |
| 10336 | */ |
| 10337 | @Override |
| 10338 | @TelephonyManager.PrepareUnattendedRebootResult |
| 10339 | public int prepareForUnattendedReboot() { |
| 10340 | enforceRebootPermission(); |
| 10341 | |
| 10342 | final long identity = Binder.clearCallingIdentity(); |
| 10343 | try { |
| 10344 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null); |
| 10345 | } finally { |
| 10346 | Binder.restoreCallingIdentity(identity); |
| 10347 | } |
| 10348 | } |
SongFerngWang | 2c4309d | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10349 | |
| 10350 | /** |
| 10351 | * Gets the current phone capability. |
| 10352 | * |
| 10353 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 10354 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 10355 | * It's used to evaluate possible phone config change, for example from single |
| 10356 | * SIM device to multi-SIM device. |
| 10357 | */ |
| 10358 | @Override |
| 10359 | public PhoneCapability getPhoneCapability() { |
| 10360 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 10361 | final long identity = Binder.clearCallingIdentity(); |
| 10362 | try { |
| 10363 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 10364 | } finally { |
| 10365 | Binder.restoreCallingIdentity(identity); |
| 10366 | } |
| 10367 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 10368 | } |