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 | ccbaf74 | 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 | 34c09a5 | 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; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -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; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 32 | import android.app.role.RoleManager; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 33 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 34 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 35 | import android.content.Context; |
| 36 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 37 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 38 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 39 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 40 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 41 | import android.net.Uri; |
| 42 | import android.os.AsyncResult; |
| 43 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 44 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.os.Bundle; |
| 46 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 47 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 48 | import android.os.Looper; |
| 49 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 50 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 51 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 52 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 53 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 54 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 55 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 56 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 57 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 58 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 59 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 60 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 61 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 62 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 63 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 64 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 65 | import android.provider.Telephony; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 66 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 67 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 68 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 69 | import android.telecom.TelecomManager; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 70 | import android.telephony.Annotation.ApnType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 71 | import android.telephony.Annotation.ThermalMitigationResult; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 72 | import android.telephony.CallForwardingInfo; |
Sooraj Sasindran | 4deb887 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 73 | import android.telephony.CarrierBandwidth; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 74 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 75 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 76 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 77 | import android.telephony.CellIdentityCdma; |
| 78 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 79 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 80 | import android.telephony.CellInfoGsm; |
| 81 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 82 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 83 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 84 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 85 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 86 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 87 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 88 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 89 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 90 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 91 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 92 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 93 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 94 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 95 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 96 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 97 | import android.telephony.SignalStrengthUpdateRequest; |
| 98 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 99 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 100 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 101 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 102 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 103 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 104 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 105 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 106 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 107 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 108 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 109 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 110 | import android.telephony.data.ApnSetting; |
| 111 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 112 | import android.telephony.gba.GbaAuthRequest; |
| 113 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 114 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 115 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 116 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame^] | 117 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 118 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 119 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 120 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 121 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 122 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 123 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 124 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 125 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 126 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 127 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 128 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 129 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 130 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 131 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 132 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 133 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 134 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 135 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 136 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 137 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 138 | import com.android.ims.rcs.uce.eab.EabUtil; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 139 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 143 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 146 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 149 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 150 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 151 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 156 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 162 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 166 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 167 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 168 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 172 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 173 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 174 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 175 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 176 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 178 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 179 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 180 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 181 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 183 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 184 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 185 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 186 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 187 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 188 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 189 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 190 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 191 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 192 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 193 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 194 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 195 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 196 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 197 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 198 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 199 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 200 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 201 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 202 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 203 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 204 | import com.android.services.telephony.TelecomAccountRegistry; |
| 205 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 206 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 207 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 208 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 209 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 210 | import java.io.IOException; |
| 211 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 212 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 213 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 214 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 215 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 216 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 217 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 218 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 219 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 220 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 221 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 222 | import java.util.Set; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 223 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 224 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 225 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 226 | |
| 227 | /** |
| 228 | * Implementation of the ITelephony interface. |
| 229 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 230 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 231 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 232 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 233 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 234 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 235 | |
| 236 | // Message codes used with mMainThreadHandler |
| 237 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 238 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 239 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 240 | private static final int CMD_OPEN_CHANNEL = 9; |
| 241 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 242 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 243 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 244 | private static final int CMD_NV_READ_ITEM = 13; |
| 245 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 246 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 247 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 248 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 249 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 250 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 251 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 252 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 253 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 254 | private static final int CMD_SEND_ENVELOPE = 25; |
| 255 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 256 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 257 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 258 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 259 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 260 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 261 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 262 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 263 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 264 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 265 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 266 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 267 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 268 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 269 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 270 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 271 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 272 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 273 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 274 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 275 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 276 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 277 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 278 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 279 | private static final int CMD_SWITCH_SLOTS = 50; |
| 280 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 281 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 282 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 283 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 284 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 285 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 286 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 287 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 288 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 289 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 290 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 291 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 292 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 293 | private static final int CMD_MODEM_REBOOT = 64; |
| 294 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 295 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 296 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 297 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 298 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 299 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 300 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 301 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 302 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 303 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 304 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 305 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 306 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 307 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 308 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 309 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 310 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 311 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 312 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 313 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 314 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 315 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 316 | private static final int CMD_GET_CALL_WAITING = 87; |
| 317 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 318 | private static final int CMD_SET_CALL_WAITING = 89; |
| 319 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 320 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 321 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 322 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 323 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 324 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 325 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 326 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 327 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 328 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 329 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 330 | private static final int CMD_SET_SIM_POWER = 101; |
| 331 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 332 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 333 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 334 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 335 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 336 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 337 | private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 338 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 339 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 340 | // Parameters of select command. |
| 341 | private static final int SELECT_COMMAND = 0xA4; |
| 342 | private static final int SELECT_P1 = 0x04; |
| 343 | private static final int SELECT_P2 = 0; |
| 344 | private static final int SELECT_P3 = 0x10; |
| 345 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 346 | /** The singleton instance. */ |
| 347 | private static PhoneInterfaceManager sInstance; |
| 348 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 349 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 350 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 351 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 352 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 353 | private AppOpsManager mAppOps; |
| 354 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 355 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 356 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 357 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 358 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 359 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 360 | /** User Activity */ |
| 361 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 362 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 363 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 364 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 365 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 366 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 367 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 368 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 369 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 370 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 371 | // String to store multi SIM allowed |
| 372 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 373 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 374 | // The AID of ISD-R. |
| 375 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 376 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 377 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 378 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 379 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 380 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 381 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 382 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
| 383 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 384 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 385 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 386 | */ |
| 387 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 388 | "reset_network_erase_modem_config_enabled"; |
| 389 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 390 | private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds |
| 391 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 392 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 393 | * A request object to use for transmitting data to an ICC. |
| 394 | */ |
| 395 | private static final class IccAPDUArgument { |
| 396 | public int channel, cla, command, p1, p2, p3; |
| 397 | public String data; |
| 398 | |
| 399 | public IccAPDUArgument(int channel, int cla, int command, |
| 400 | int p1, int p2, int p3, String data) { |
| 401 | this.channel = channel; |
| 402 | this.cla = cla; |
| 403 | this.command = command; |
| 404 | this.p1 = p1; |
| 405 | this.p2 = p2; |
| 406 | this.p3 = p3; |
| 407 | this.data = data; |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 412 | * A request object to use for transmitting data to an ICC. |
| 413 | */ |
| 414 | private static final class ManualNetworkSelectionArgument { |
| 415 | public OperatorInfo operatorInfo; |
| 416 | public boolean persistSelection; |
| 417 | |
| 418 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 419 | this.operatorInfo = operatorInfo; |
| 420 | this.persistSelection = persistSelection; |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 425 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 426 | * request after sending. The main thread will notify the request when it is complete. |
| 427 | */ |
| 428 | private static final class MainThreadRequest { |
| 429 | /** The argument to use for the request */ |
| 430 | public Object argument; |
| 431 | /** The result of the request that is run on the main thread */ |
| 432 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 433 | // The subscriber id that this request applies to. Defaults to |
| 434 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 435 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 436 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 437 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 438 | public Phone phone; |
| 439 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 440 | public WorkSource workSource; |
| 441 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 442 | public MainThreadRequest(Object argument) { |
| 443 | this.argument = argument; |
| 444 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 445 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 446 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 447 | this.argument = argument; |
| 448 | if (phone != null) { |
| 449 | this.phone = phone; |
| 450 | } |
| 451 | this.workSource = workSource; |
| 452 | } |
| 453 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 454 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 455 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 456 | if (subId != null) { |
| 457 | this.subId = subId; |
| 458 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 459 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 460 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 461 | } |
| 462 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 463 | private static final class IncomingThirdPartyCallArgs { |
| 464 | public final ComponentName component; |
| 465 | public final String callId; |
| 466 | public final String callerDisplayName; |
| 467 | |
| 468 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 469 | String callerDisplayName) { |
| 470 | this.component = component; |
| 471 | this.callId = callId; |
| 472 | this.callerDisplayName = callerDisplayName; |
| 473 | } |
| 474 | } |
| 475 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 476 | /** |
| 477 | * A handler that processes messages on the main thread in the phone process. Since many |
| 478 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 479 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 480 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 481 | * on, which will be notified when the operation completes and will contain the result of the |
| 482 | * request. |
| 483 | * |
| 484 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 485 | * note that request.result must be set to something non-null for the calling thread to |
| 486 | * unblock. |
| 487 | */ |
| 488 | private final class MainThreadHandler extends Handler { |
| 489 | @Override |
| 490 | public void handleMessage(Message msg) { |
| 491 | MainThreadRequest request; |
| 492 | Message onCompleted; |
| 493 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 494 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 495 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 496 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 497 | |
| 498 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 499 | case CMD_HANDLE_USSD_REQUEST: { |
| 500 | request = (MainThreadRequest) msg.obj; |
| 501 | final Phone phone = getPhoneFromRequest(request); |
| 502 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 503 | String ussdRequest = ussdObject.first; |
| 504 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 505 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 506 | if (!isUssdApiAllowed(request.subId)) { |
| 507 | // Carrier does not support use of this API, return failure. |
| 508 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 509 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 510 | Bundle returnData = new Bundle(); |
| 511 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 512 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
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 | request.result = true; |
| 515 | notifyRequester(request); |
| 516 | return; |
| 517 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 518 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 519 | try { |
| 520 | request.result = phone != null |
| 521 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 522 | } catch (CallStateException cse) { |
| 523 | request.result = false; |
| 524 | } |
| 525 | // Wake up the requesting thread |
| 526 | notifyRequester(request); |
| 527 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 528 | } |
| 529 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 530 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 531 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 532 | final Phone phone = getPhoneFromRequest(request); |
| 533 | request.result = phone != null ? |
| 534 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 535 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 536 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 537 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 538 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 539 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 540 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 541 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 542 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 543 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 544 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 545 | if (uiccCard == null) { |
| 546 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 547 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 548 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 549 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 550 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 551 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 552 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 553 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 554 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 555 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 556 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 557 | break; |
| 558 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 559 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 560 | ar = (AsyncResult) msg.obj; |
| 561 | request = (MainThreadRequest) ar.userObj; |
| 562 | if (ar.exception == null && ar.result != null) { |
| 563 | request.result = ar.result; |
| 564 | } else { |
| 565 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 566 | if (ar.result == null) { |
| 567 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 568 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 569 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 570 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 571 | } else { |
| 572 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 573 | } |
| 574 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 575 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 576 | break; |
| 577 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 578 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 579 | request = (MainThreadRequest) msg.obj; |
| 580 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 581 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 582 | if (uiccCard == null) { |
| 583 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 584 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 585 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 586 | } else { |
| 587 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 588 | request); |
| 589 | uiccCard.iccTransmitApduBasicChannel( |
| 590 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 591 | iccArgument.p3, iccArgument.data, onCompleted); |
| 592 | } |
| 593 | break; |
| 594 | |
| 595 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 596 | ar = (AsyncResult) msg.obj; |
| 597 | request = (MainThreadRequest) ar.userObj; |
| 598 | if (ar.exception == null && ar.result != null) { |
| 599 | request.result = ar.result; |
| 600 | } else { |
| 601 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 602 | if (ar.result == null) { |
| 603 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 604 | } else if (ar.exception instanceof CommandException) { |
| 605 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 606 | ar.exception); |
| 607 | } else { |
| 608 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 609 | } |
| 610 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 611 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 612 | break; |
| 613 | |
| 614 | case CMD_EXCHANGE_SIM_IO: |
| 615 | request = (MainThreadRequest) msg.obj; |
| 616 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 617 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 618 | if (uiccCard == null) { |
| 619 | loge("iccExchangeSimIO: No UICC"); |
| 620 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 621 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 622 | } else { |
| 623 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 624 | request); |
| 625 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 626 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 627 | iccArgument.data, onCompleted); |
| 628 | } |
| 629 | break; |
| 630 | |
| 631 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 632 | ar = (AsyncResult) msg.obj; |
| 633 | request = (MainThreadRequest) ar.userObj; |
| 634 | if (ar.exception == null && ar.result != null) { |
| 635 | request.result = ar.result; |
| 636 | } else { |
| 637 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 638 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 639 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 640 | break; |
| 641 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 642 | case CMD_SEND_ENVELOPE: |
| 643 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 644 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 645 | if (uiccCard == null) { |
| 646 | loge("sendEnvelopeWithStatus: No UICC"); |
| 647 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 648 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 649 | } else { |
| 650 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 651 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 652 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 653 | break; |
| 654 | |
| 655 | case EVENT_SEND_ENVELOPE_DONE: |
| 656 | ar = (AsyncResult) msg.obj; |
| 657 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 658 | if (ar.exception == null && ar.result != null) { |
| 659 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 660 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 661 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 662 | if (ar.result == null) { |
| 663 | loge("sendEnvelopeWithStatus: Empty response"); |
| 664 | } else if (ar.exception instanceof CommandException) { |
| 665 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 666 | ar.exception); |
| 667 | } else { |
| 668 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 669 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 670 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 671 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 672 | break; |
| 673 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 674 | case CMD_OPEN_CHANNEL: |
| 675 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 676 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 677 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 678 | if (uiccCard == null) { |
| 679 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 680 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 681 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 682 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 683 | } else { |
| 684 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 685 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 686 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 687 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 688 | break; |
| 689 | |
| 690 | case EVENT_OPEN_CHANNEL_DONE: |
| 691 | ar = (AsyncResult) msg.obj; |
| 692 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 693 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 694 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 695 | int[] result = (int[]) ar.result; |
| 696 | int channelId = result[0]; |
| 697 | byte[] selectResponse = null; |
| 698 | if (result.length > 1) { |
| 699 | selectResponse = new byte[result.length - 1]; |
| 700 | for (int i = 1; i < result.length; ++i) { |
| 701 | selectResponse[i - 1] = (byte) result[i]; |
| 702 | } |
| 703 | } |
| 704 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 705 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 706 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 707 | if (ar.result == null) { |
| 708 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 709 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 710 | if (ar.exception != null) { |
| 711 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 712 | } |
| 713 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 714 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 715 | if (ar.exception instanceof CommandException) { |
| 716 | CommandException.Error error = |
| 717 | ((CommandException) (ar.exception)).getCommandError(); |
| 718 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 719 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 720 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 721 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 722 | } |
| 723 | } |
| 724 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 725 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 726 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 727 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 728 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 729 | break; |
| 730 | |
| 731 | case CMD_CLOSE_CHANNEL: |
| 732 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 733 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 734 | if (uiccCard == null) { |
| 735 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 736 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 737 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 738 | } else { |
| 739 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 740 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 741 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 742 | break; |
| 743 | |
| 744 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 745 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 746 | break; |
| 747 | |
| 748 | case CMD_NV_READ_ITEM: |
| 749 | request = (MainThreadRequest) msg.obj; |
| 750 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 751 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 752 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 753 | break; |
| 754 | |
| 755 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 756 | ar = (AsyncResult) msg.obj; |
| 757 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 758 | if (ar.exception == null && ar.result != null) { |
| 759 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 760 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 761 | request.result = ""; |
| 762 | if (ar.result == null) { |
| 763 | loge("nvReadItem: Empty response"); |
| 764 | } else if (ar.exception instanceof CommandException) { |
| 765 | loge("nvReadItem: CommandException: " + |
| 766 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 767 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 768 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 769 | } |
| 770 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 771 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 772 | break; |
| 773 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 774 | case CMD_NV_WRITE_ITEM: |
| 775 | request = (MainThreadRequest) msg.obj; |
| 776 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 777 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 778 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 779 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 780 | break; |
| 781 | |
| 782 | case EVENT_NV_WRITE_ITEM_DONE: |
| 783 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 784 | break; |
| 785 | |
| 786 | case CMD_NV_WRITE_CDMA_PRL: |
| 787 | request = (MainThreadRequest) msg.obj; |
| 788 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 789 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 790 | break; |
| 791 | |
| 792 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 793 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 794 | break; |
| 795 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 796 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 797 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 798 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 799 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 800 | break; |
| 801 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 802 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 803 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 804 | break; |
| 805 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 806 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 807 | request = (MainThreadRequest) msg.obj; |
| 808 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 809 | request); |
| 810 | Phone phone = getPhoneFromRequest(request); |
| 811 | if (phone != null) { |
| 812 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 813 | } else { |
| 814 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 815 | request.result = false; |
| 816 | notifyRequester(request); |
| 817 | } |
| 818 | break; |
| 819 | } |
| 820 | |
| 821 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 822 | ar = (AsyncResult) msg.obj; |
| 823 | request = (MainThreadRequest) ar.userObj; |
| 824 | if (ar.exception == null && ar.result != null) { |
| 825 | request.result = ar.result; |
| 826 | } else { |
| 827 | // request.result must be set to something non-null |
| 828 | // for the calling thread to unblock |
| 829 | if (request.result != null) { |
| 830 | request.result = ar.result; |
| 831 | } else { |
| 832 | request.result = false; |
| 833 | } |
| 834 | if (ar.result == null) { |
| 835 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 836 | } else if (ar.exception instanceof CommandException) { |
| 837 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 838 | + ar.exception); |
| 839 | } else { |
| 840 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 841 | } |
| 842 | } |
| 843 | notifyRequester(request); |
| 844 | break; |
| 845 | |
| 846 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 847 | request = (MainThreadRequest) msg.obj; |
| 848 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 849 | Phone phone = getPhoneFromRequest(request); |
| 850 | if (phone != null) { |
| 851 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 852 | request.workSource); |
| 853 | } else { |
| 854 | loge("enableNrDualConnectivity: No phone object"); |
| 855 | request.result = |
| 856 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 857 | notifyRequester(request); |
| 858 | } |
| 859 | break; |
| 860 | } |
| 861 | |
| 862 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 863 | ar = (AsyncResult) msg.obj; |
| 864 | request = (MainThreadRequest) ar.userObj; |
| 865 | if (ar.exception == null) { |
| 866 | request.result = |
| 867 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 868 | } else { |
| 869 | request.result = |
| 870 | TelephonyManager |
| 871 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 872 | if (ar.exception instanceof CommandException) { |
| 873 | CommandException.Error error = |
| 874 | ((CommandException) (ar.exception)).getCommandError(); |
| 875 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 876 | request.result = |
| 877 | TelephonyManager |
| 878 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 879 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 880 | request.result = |
| 881 | TelephonyManager |
| 882 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 883 | } |
| 884 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 885 | + ar.exception); |
| 886 | } else { |
| 887 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 888 | } |
| 889 | } |
| 890 | notifyRequester(request); |
| 891 | break; |
| 892 | } |
| 893 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 894 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 895 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 896 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 897 | request); |
| 898 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 899 | break; |
| 900 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 901 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 902 | ar = (AsyncResult) msg.obj; |
| 903 | request = (MainThreadRequest) ar.userObj; |
| 904 | if (ar.exception == null && ar.result != null) { |
| 905 | request.result = ar.result; // Integer |
| 906 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 907 | // request.result must be set to something non-null |
| 908 | // for the calling thread to unblock |
| 909 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 910 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 911 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 912 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 913 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 914 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 915 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 916 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 917 | } |
| 918 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 919 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 920 | break; |
| 921 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 922 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 923 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 924 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 925 | request); |
| 926 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 927 | (Pair<Integer, Long>) request.argument; |
| 928 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 929 | reasonWithNetworkTypes.first, |
| 930 | reasonWithNetworkTypes.second, |
| 931 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 932 | break; |
| 933 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 934 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 935 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 936 | break; |
| 937 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 938 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 939 | request = (MainThreadRequest)msg.obj; |
| 940 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 941 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 942 | break; |
| 943 | |
| 944 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 945 | ar = (AsyncResult)msg.obj; |
| 946 | request = (MainThreadRequest)ar.userObj; |
| 947 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 948 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 949 | break; |
| 950 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 951 | case CMD_SET_VOICEMAIL_NUMBER: |
| 952 | request = (MainThreadRequest) msg.obj; |
| 953 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 954 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 955 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 956 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 957 | break; |
| 958 | |
| 959 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 960 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 961 | break; |
| 962 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 963 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 964 | request = (MainThreadRequest) msg.obj; |
| 965 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 966 | request); |
| 967 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 968 | break; |
| 969 | |
| 970 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 971 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 972 | break; |
| 973 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 974 | case CMD_PERFORM_NETWORK_SCAN: |
| 975 | request = (MainThreadRequest) msg.obj; |
| 976 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 977 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 978 | break; |
| 979 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 980 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 981 | request = (MainThreadRequest) msg.obj; |
| 982 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 983 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 984 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 985 | request.argument; |
| 986 | int callForwardingReason = args.first; |
| 987 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 988 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 989 | } |
| 990 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 991 | ar = (AsyncResult) msg.obj; |
| 992 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 993 | TelephonyManager.CallForwardingInfoCallback callback = |
| 994 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 995 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 996 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 997 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 998 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 999 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1000 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1001 | // any service for voice call. |
| 1002 | if ((callForwardInfo.serviceClass |
| 1003 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1004 | callForwardingInfo = new CallForwardingInfo(true, |
| 1005 | callForwardInfo.reason, |
| 1006 | callForwardInfo.number, |
| 1007 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1008 | break; |
| 1009 | } |
| 1010 | } |
| 1011 | // Didn't find a call forward info for voice call. |
| 1012 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1013 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1014 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1015 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1016 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1017 | } else { |
| 1018 | if (ar.result == null) { |
| 1019 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1020 | } |
| 1021 | if (ar.exception != null) { |
| 1022 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1023 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1024 | int errorCode = TelephonyManager |
| 1025 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1026 | if (ar.exception instanceof CommandException) { |
| 1027 | CommandException.Error error = |
| 1028 | ((CommandException) (ar.exception)).getCommandError(); |
| 1029 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1030 | errorCode = TelephonyManager |
| 1031 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1032 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1033 | errorCode = TelephonyManager |
| 1034 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1035 | } |
| 1036 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1037 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1038 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1039 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1040 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1041 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1042 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1043 | request = (MainThreadRequest) msg.obj; |
| 1044 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1045 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1046 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1047 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1048 | request.argument).first; |
| 1049 | request.phone.setCallForwardingOption( |
| 1050 | callForwardingInfoToSet.isEnabled() |
| 1051 | ? CommandsInterface.CF_ACTION_ENABLE |
| 1052 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1053 | callForwardingInfoToSet.getReason(), |
| 1054 | callForwardingInfoToSet.getNumber(), |
| 1055 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1056 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1057 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1058 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1059 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1060 | ar = (AsyncResult) msg.obj; |
| 1061 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1062 | Consumer<Integer> callback = |
| 1063 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1064 | request.argument).second; |
| 1065 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1066 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1067 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1068 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1069 | if (ar.exception instanceof CommandException) { |
| 1070 | CommandException.Error error = |
| 1071 | ((CommandException) (ar.exception)).getCommandError(); |
| 1072 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1073 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1074 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1075 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1076 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1077 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1078 | } |
| 1079 | } |
| 1080 | callback.accept(errorCode); |
| 1081 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1082 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1083 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1084 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1085 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1086 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1087 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1088 | request = (MainThreadRequest) msg.obj; |
| 1089 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1090 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1091 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1092 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1093 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1094 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1095 | ar = (AsyncResult) msg.obj; |
| 1096 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1097 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1098 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1099 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1100 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1101 | // Service Class is a bit mask per 3gpp 27.007. |
| 1102 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1103 | if (callForwardResults.length > 1 |
| 1104 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1105 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1106 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1107 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1108 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1109 | } else { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1110 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1111 | } |
| 1112 | } else { |
| 1113 | if (ar.result == null) { |
| 1114 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1115 | } |
| 1116 | if (ar.exception != null) { |
| 1117 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1118 | } |
| 1119 | if (ar.exception instanceof CommandException) { |
| 1120 | CommandException.Error error = |
| 1121 | ((CommandException) (ar.exception)).getCommandError(); |
| 1122 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1123 | callForwardingStatus = |
| 1124 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1125 | } |
| 1126 | } |
| 1127 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1128 | callback.accept(callForwardingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1129 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1130 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1131 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1132 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1133 | request = (MainThreadRequest) msg.obj; |
| 1134 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1135 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1136 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1137 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1138 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1139 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1140 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1141 | ar = (AsyncResult) msg.obj; |
| 1142 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1143 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1144 | Consumer<Integer> callback = |
| 1145 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1146 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1147 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1148 | if (ar.exception instanceof CommandException) { |
| 1149 | CommandException.Error error = |
| 1150 | ((CommandException) (ar.exception)).getCommandError(); |
| 1151 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1152 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1153 | } else { |
| 1154 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1155 | } |
| 1156 | } else { |
| 1157 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1158 | } |
| 1159 | } else { |
| 1160 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1161 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1162 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1163 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1164 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1165 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1166 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1167 | ar = (AsyncResult) msg.obj; |
| 1168 | request = (MainThreadRequest) ar.userObj; |
| 1169 | CellNetworkScanResult cellScanResult; |
| 1170 | if (ar.exception == null && ar.result != null) { |
| 1171 | cellScanResult = new CellNetworkScanResult( |
| 1172 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1173 | (List<OperatorInfo>) ar.result); |
| 1174 | } else { |
| 1175 | if (ar.result == null) { |
| 1176 | loge("getCellNetworkScanResults: Empty response"); |
| 1177 | } |
| 1178 | if (ar.exception != null) { |
| 1179 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1180 | } |
| 1181 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1182 | if (ar.exception instanceof CommandException) { |
| 1183 | CommandException.Error error = |
| 1184 | ((CommandException) (ar.exception)).getCommandError(); |
| 1185 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1186 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1187 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1188 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1189 | } |
| 1190 | } |
| 1191 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1192 | } |
| 1193 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1194 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1195 | break; |
| 1196 | |
| 1197 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1198 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1199 | ManualNetworkSelectionArgument selArg = |
| 1200 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1201 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1202 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1203 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1204 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1205 | break; |
| 1206 | |
| 1207 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1208 | ar = (AsyncResult) msg.obj; |
| 1209 | request = (MainThreadRequest) ar.userObj; |
| 1210 | if (ar.exception == null) { |
| 1211 | request.result = true; |
| 1212 | } else { |
| 1213 | request.result = false; |
| 1214 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1215 | } |
| 1216 | notifyRequester(request); |
| 1217 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1218 | break; |
| 1219 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1220 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1221 | request = (MainThreadRequest) msg.obj; |
| 1222 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1223 | if (defaultPhone != null) { |
| 1224 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1225 | } else { |
| 1226 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1227 | Bundle bundle = new Bundle(); |
| 1228 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1229 | new ModemActivityInfo(0, 0, 0, |
| 1230 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1231 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1232 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1233 | break; |
| 1234 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1235 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1236 | ar = (AsyncResult) msg.obj; |
| 1237 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1238 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1239 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1240 | ModemActivityInfo ret = null; |
| 1241 | int error = 0; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1242 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1243 | // Update the last modem activity info and the result of the request. |
| 1244 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1245 | if (isModemActivityInfoValid(info)) { |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1246 | int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()]; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1247 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1248 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1249 | .getTransmitTimeMillis(); |
| 1250 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1251 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1252 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1253 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1254 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1255 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1256 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1257 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1258 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1259 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1260 | info.getReceiveTimeMillis() |
| 1261 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1262 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1263 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(), |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1264 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1265 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1266 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1267 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1268 | } else { |
| 1269 | if (ar.result == null) { |
| 1270 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1271 | error = TelephonyManager.ModemActivityInfoException |
| 1272 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1273 | } else if (ar.exception instanceof CommandException) { |
| 1274 | loge("queryModemActivityInfo: CommandException: " + |
| 1275 | ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1276 | error = TelephonyManager.ModemActivityInfoException |
| 1277 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1278 | } else { |
| 1279 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1280 | error = TelephonyManager.ModemActivityInfoException |
| 1281 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1282 | } |
| 1283 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1284 | Bundle bundle = new Bundle(); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1285 | if (ret != null) { |
| 1286 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1287 | } else { |
| 1288 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1289 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1290 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1291 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1292 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1293 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1294 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1295 | case CMD_SET_ALLOWED_CARRIERS: |
| 1296 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1297 | CarrierRestrictionRules argument = |
| 1298 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1299 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1300 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1301 | break; |
| 1302 | |
| 1303 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1304 | ar = (AsyncResult) msg.obj; |
| 1305 | request = (MainThreadRequest) ar.userObj; |
| 1306 | if (ar.exception == null && ar.result != null) { |
| 1307 | request.result = ar.result; |
| 1308 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1309 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1310 | if (ar.exception instanceof CommandException) { |
| 1311 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1312 | CommandException.Error error = |
| 1313 | ((CommandException) (ar.exception)).getCommandError(); |
| 1314 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1315 | request.result = |
| 1316 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1317 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1318 | } else { |
| 1319 | loge("setAllowedCarriers: Unknown exception"); |
| 1320 | } |
| 1321 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1322 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1323 | break; |
| 1324 | |
| 1325 | case CMD_GET_ALLOWED_CARRIERS: |
| 1326 | request = (MainThreadRequest) msg.obj; |
| 1327 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1328 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1329 | break; |
| 1330 | |
| 1331 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1332 | ar = (AsyncResult) msg.obj; |
| 1333 | request = (MainThreadRequest) ar.userObj; |
| 1334 | if (ar.exception == null && ar.result != null) { |
| 1335 | request.result = ar.result; |
| 1336 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1337 | request.result = new IllegalStateException( |
| 1338 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1339 | if (ar.result == null) { |
| 1340 | loge("getAllowedCarriers: Empty response"); |
| 1341 | } else if (ar.exception instanceof CommandException) { |
| 1342 | loge("getAllowedCarriers: CommandException: " + |
| 1343 | ar.exception); |
| 1344 | } else { |
| 1345 | loge("getAllowedCarriers: Unknown exception"); |
| 1346 | } |
| 1347 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1348 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1349 | break; |
| 1350 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1351 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1352 | ar = (AsyncResult) msg.obj; |
| 1353 | request = (MainThreadRequest) ar.userObj; |
| 1354 | if (ar.exception == null && ar.result != null) { |
| 1355 | request.result = ar.result; |
| 1356 | } else { |
| 1357 | request.result = new IllegalArgumentException( |
| 1358 | "Failed to retrieve Forbidden Plmns"); |
| 1359 | if (ar.result == null) { |
| 1360 | loge("getForbiddenPlmns: Empty response"); |
| 1361 | } else { |
| 1362 | loge("getForbiddenPlmns: Unknown exception"); |
| 1363 | } |
| 1364 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1365 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1366 | break; |
| 1367 | |
| 1368 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1369 | request = (MainThreadRequest) msg.obj; |
| 1370 | uiccCard = getUiccCardFromRequest(request); |
| 1371 | if (uiccCard == null) { |
| 1372 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1373 | request.result = new IllegalArgumentException( |
| 1374 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1375 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1376 | break; |
| 1377 | } |
| 1378 | Integer appType = (Integer) request.argument; |
| 1379 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1380 | if (uiccApp == null) { |
| 1381 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1382 | + appType); |
| 1383 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1384 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1385 | break; |
| 1386 | } else { |
| 1387 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1388 | + " specified type -- " + appType); |
| 1389 | } |
| 1390 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1391 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1392 | onCompleted); |
| 1393 | break; |
| 1394 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1395 | case CMD_SWITCH_SLOTS: |
| 1396 | request = (MainThreadRequest) msg.obj; |
| 1397 | int[] physicalSlots = (int[]) request.argument; |
| 1398 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1399 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1400 | break; |
| 1401 | |
| 1402 | case EVENT_SWITCH_SLOTS_DONE: |
| 1403 | ar = (AsyncResult) msg.obj; |
| 1404 | request = (MainThreadRequest) ar.userObj; |
| 1405 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1406 | notifyRequester(request); |
| 1407 | break; |
| 1408 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1409 | request = (MainThreadRequest) msg.obj; |
| 1410 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1411 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1412 | break; |
| 1413 | |
| 1414 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1415 | ar = (AsyncResult) msg.obj; |
| 1416 | request = (MainThreadRequest) ar.userObj; |
| 1417 | if (ar.exception != null) { |
| 1418 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1419 | } else { |
| 1420 | int mode = ((int[]) ar.result)[0]; |
| 1421 | if (mode == 0) { |
| 1422 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1423 | } else { |
| 1424 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1425 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1426 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1427 | notifyRequester(request); |
| 1428 | break; |
| 1429 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1430 | request = (MainThreadRequest) msg.obj; |
| 1431 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1432 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1433 | break; |
| 1434 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1435 | ar = (AsyncResult) msg.obj; |
| 1436 | request = (MainThreadRequest) ar.userObj; |
| 1437 | if (ar.exception != null) { |
| 1438 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1439 | } else { |
| 1440 | request.result = ((int[]) ar.result)[0]; |
| 1441 | } |
| 1442 | notifyRequester(request); |
| 1443 | break; |
| 1444 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1445 | request = (MainThreadRequest) msg.obj; |
| 1446 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1447 | int mode = (int) request.argument; |
| 1448 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1449 | break; |
| 1450 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1451 | ar = (AsyncResult) msg.obj; |
| 1452 | request = (MainThreadRequest) ar.userObj; |
| 1453 | request.result = ar.exception == null; |
| 1454 | notifyRequester(request); |
| 1455 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1456 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1457 | request = (MainThreadRequest) msg.obj; |
| 1458 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1459 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1460 | break; |
| 1461 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1462 | ar = (AsyncResult) msg.obj; |
| 1463 | request = (MainThreadRequest) ar.userObj; |
| 1464 | if (ar.exception != null) { |
| 1465 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1466 | } else { |
| 1467 | request.result = ((int[]) ar.result)[0]; |
| 1468 | } |
| 1469 | notifyRequester(request); |
| 1470 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1471 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1472 | request = (MainThreadRequest) msg.obj; |
| 1473 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1474 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1475 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1476 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1477 | break; |
| 1478 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1479 | ar = (AsyncResult) msg.obj; |
| 1480 | request = (MainThreadRequest) ar.userObj; |
| 1481 | request.result = ar.exception == null; |
| 1482 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1483 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1484 | case CMD_GET_ALL_CELL_INFO: |
| 1485 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1486 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1487 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1488 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1489 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1490 | ar = (AsyncResult) msg.obj; |
| 1491 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1492 | // If a timeout occurs, the response will be null |
| 1493 | request.result = (ar.exception == null && ar.result != null) |
| 1494 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1495 | synchronized (request) { |
| 1496 | request.notifyAll(); |
| 1497 | } |
| 1498 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1499 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1500 | request = (MainThreadRequest) msg.obj; |
| 1501 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1502 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1503 | break; |
| 1504 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1505 | ar = (AsyncResult) msg.obj; |
| 1506 | request = (MainThreadRequest) ar.userObj; |
| 1507 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1508 | try { |
| 1509 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1510 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1511 | cb.onError( |
| 1512 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1513 | ar.exception.getClass().getName(), |
| 1514 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1515 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1516 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1517 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1518 | } else { |
| 1519 | // use the result as returned |
| 1520 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1521 | } |
| 1522 | } catch (RemoteException re) { |
| 1523 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1524 | } |
| 1525 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1526 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1527 | request = (MainThreadRequest) msg.obj; |
| 1528 | WorkSource ws = (WorkSource) request.argument; |
| 1529 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1530 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1531 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1532 | } |
| 1533 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1534 | ar = (AsyncResult) msg.obj; |
| 1535 | request = (MainThreadRequest) ar.userObj; |
| 1536 | if (ar.exception == null) { |
| 1537 | request.result = ar.result; |
| 1538 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1539 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1540 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1541 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1542 | } |
| 1543 | |
| 1544 | synchronized (request) { |
| 1545 | request.notifyAll(); |
| 1546 | } |
| 1547 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1548 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1549 | case CMD_MODEM_REBOOT: |
| 1550 | request = (MainThreadRequest) msg.obj; |
| 1551 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1552 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1553 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1554 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1555 | handleNullReturnEvent(msg, "rebootModem"); |
| 1556 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1557 | case CMD_REQUEST_ENABLE_MODEM: |
| 1558 | request = (MainThreadRequest) msg.obj; |
| 1559 | boolean enable = (boolean) request.argument; |
| 1560 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1561 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1562 | PhoneConfigurationManager.getInstance() |
| 1563 | .enablePhone(request.phone, enable, onCompleted); |
| 1564 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1565 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1566 | ar = (AsyncResult) msg.obj; |
| 1567 | request = (MainThreadRequest) ar.userObj; |
| 1568 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1569 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1570 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1571 | if ((boolean) request.result) { |
| 1572 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1573 | updateModemStateMetrics(); |
| 1574 | } else { |
| 1575 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1576 | + ar.exception); |
| 1577 | } |
| 1578 | notifyRequester(request); |
| 1579 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1580 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1581 | case CMD_GET_MODEM_STATUS: |
| 1582 | request = (MainThreadRequest) msg.obj; |
| 1583 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1584 | PhoneConfigurationManager.getInstance() |
| 1585 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1586 | break; |
| 1587 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1588 | ar = (AsyncResult) msg.obj; |
| 1589 | request = (MainThreadRequest) ar.userObj; |
| 1590 | int id = request.phone.getPhoneId(); |
| 1591 | if (ar.exception == null && ar.result != null) { |
| 1592 | request.result = ar.result; |
| 1593 | //update the cache as modem status has changed |
| 1594 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1595 | (boolean) request.result); |
| 1596 | } else { |
| 1597 | // Return true if modem status cannot be retrieved. For most cases, |
| 1598 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1599 | // and disable modem are not supported. Modem is always on. |
| 1600 | // TODO: this should be fixed in R to support a third |
| 1601 | // status UNKNOWN b/131631629 |
| 1602 | request.result = true; |
| 1603 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1604 | + ar.exception); |
| 1605 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1606 | notifyRequester(request); |
| 1607 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1608 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1609 | request = (MainThreadRequest) msg.obj; |
| 1610 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1611 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1612 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1613 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1614 | break; |
| 1615 | } |
| 1616 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1617 | ar = (AsyncResult) msg.obj; |
| 1618 | request = (MainThreadRequest) ar.userObj; |
| 1619 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1620 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1621 | args.second.accept(ar.exception == null); |
| 1622 | notifyRequester(request); |
| 1623 | break; |
| 1624 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1625 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1626 | request = (MainThreadRequest) msg.obj; |
| 1627 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1628 | Phone phone = getPhoneFromRequest(request); |
| 1629 | if (phone != null) { |
| 1630 | phone.getSystemSelectionChannels(onCompleted); |
| 1631 | } else { |
| 1632 | loge("getSystemSelectionChannels: No phone object"); |
| 1633 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1634 | notifyRequester(request); |
| 1635 | } |
| 1636 | break; |
| 1637 | } |
| 1638 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1639 | ar = (AsyncResult) msg.obj; |
| 1640 | request = (MainThreadRequest) ar.userObj; |
| 1641 | if (ar.exception == null && ar.result != null) { |
| 1642 | request.result = ar.result; |
| 1643 | } else { |
| 1644 | request.result = new IllegalArgumentException( |
| 1645 | "Failed to retrieve system selection channels"); |
| 1646 | if (ar.result == null) { |
| 1647 | loge("getSystemSelectionChannels: Empty response"); |
| 1648 | } else { |
| 1649 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1650 | } |
| 1651 | } |
| 1652 | notifyRequester(request); |
| 1653 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1654 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1655 | ar = (AsyncResult) msg.obj; |
| 1656 | request = (MainThreadRequest) ar.userObj; |
| 1657 | if (ar.exception == null && ar.result != null) { |
| 1658 | request.result = ar.result; |
| 1659 | } else { |
| 1660 | request.result = -1; |
| 1661 | loge("Failed to set Forbidden Plmns"); |
| 1662 | if (ar.result == null) { |
| 1663 | loge("setForbidenPlmns: Empty response"); |
| 1664 | } else if (ar.exception != null) { |
| 1665 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1666 | request.result = -1; |
| 1667 | } else { |
| 1668 | loge("setForbiddenPlmns: Unknown exception"); |
| 1669 | } |
| 1670 | } |
| 1671 | notifyRequester(request); |
| 1672 | break; |
| 1673 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1674 | request = (MainThreadRequest) msg.obj; |
| 1675 | uiccCard = getUiccCardFromRequest(request); |
| 1676 | if (uiccCard == null) { |
| 1677 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1678 | request.result = -1; |
| 1679 | notifyRequester(request); |
| 1680 | break; |
| 1681 | } |
| 1682 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1683 | (Pair<Integer, List<String>>) request.argument; |
| 1684 | appType = setFplmnsArgs.first; |
| 1685 | List<String> fplmns = setFplmnsArgs.second; |
| 1686 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1687 | if (uiccApp == null) { |
| 1688 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1689 | request.result = -1; |
| 1690 | loge("Failed to get UICC App"); |
| 1691 | notifyRequester(request); |
| 1692 | } else { |
| 1693 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1694 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1695 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1696 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1697 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1698 | case CMD_ERASE_MODEM_CONFIG: |
| 1699 | request = (MainThreadRequest) msg.obj; |
| 1700 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1701 | defaultPhone.eraseModemConfig(onCompleted); |
| 1702 | break; |
| 1703 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1704 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1705 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1706 | |
| 1707 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1708 | request = (MainThreadRequest) msg.obj; |
| 1709 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1710 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1711 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1712 | changed.first, changed.second, onCompleted); |
| 1713 | break; |
| 1714 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1715 | ar = (AsyncResult) msg.obj; |
| 1716 | request = (MainThreadRequest) ar.userObj; |
| 1717 | if (ar.exception == null) { |
| 1718 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1719 | // If the operation is successful, update the PIN storage |
| 1720 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1721 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1722 | UiccController.getInstance().getPinStorage() |
| 1723 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1724 | } else { |
| 1725 | request.result = msg.arg1; |
| 1726 | } |
| 1727 | notifyRequester(request); |
| 1728 | break; |
| 1729 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1730 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1731 | request = (MainThreadRequest) msg.obj; |
| 1732 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1733 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1734 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1735 | enabled.first, enabled.second, onCompleted); |
| 1736 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1737 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1738 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1739 | ar = (AsyncResult) msg.obj; |
| 1740 | request = (MainThreadRequest) ar.userObj; |
| 1741 | if (ar.exception == null) { |
| 1742 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1743 | // If the operation is successful, update the PIN storage |
| 1744 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1745 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1746 | if (enabled.first) { |
| 1747 | UiccController.getInstance().getPinStorage() |
| 1748 | .storePin(enabled.second, phoneId); |
| 1749 | } else { |
| 1750 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1751 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1752 | } else { |
| 1753 | request.result = msg.arg1; |
| 1754 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1755 | |
| 1756 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1757 | notifyRequester(request); |
| 1758 | break; |
| 1759 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1760 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1761 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1762 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1763 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1764 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1765 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1766 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1767 | |
| 1768 | case CMD_SET_DATA_THROTTLING: { |
| 1769 | request = (MainThreadRequest) msg.obj; |
| 1770 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1771 | DataThrottlingRequest dataThrottlingRequest = |
| 1772 | (DataThrottlingRequest) request.argument; |
| 1773 | Phone phone = getPhoneFromRequest(request); |
| 1774 | if (phone != null) { |
| 1775 | phone.setDataThrottling(onCompleted, |
| 1776 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1777 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1778 | } else { |
| 1779 | loge("setDataThrottling: No phone object"); |
| 1780 | request.result = |
| 1781 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1782 | notifyRequester(request); |
| 1783 | } |
| 1784 | |
| 1785 | break; |
| 1786 | } |
| 1787 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1788 | ar = (AsyncResult) msg.obj; |
| 1789 | request = (MainThreadRequest) ar.userObj; |
| 1790 | |
| 1791 | if (ar.exception == null) { |
| 1792 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1793 | } else if (ar.exception instanceof CommandException) { |
| 1794 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1795 | CommandException.Error error = |
| 1796 | ((CommandException) (ar.exception)).getCommandError(); |
| 1797 | |
| 1798 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1799 | request.result = TelephonyManager |
| 1800 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1801 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1802 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
| 1803 | } else { |
| 1804 | request.result = |
| 1805 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1806 | } |
| 1807 | } else { |
| 1808 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1809 | } |
| 1810 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1811 | notifyRequester(request); |
| 1812 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1813 | |
| 1814 | case CMD_SET_SIM_POWER: { |
| 1815 | request = (MainThreadRequest) msg.obj; |
| 1816 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1817 | request = (MainThreadRequest) msg.obj; |
| 1818 | int stateToSet = |
| 1819 | ((Pair<Integer, IIntegerConsumer>) |
| 1820 | request.argument).first; |
| 1821 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1822 | break; |
| 1823 | } |
| 1824 | case EVENT_SET_SIM_POWER_DONE: { |
| 1825 | ar = (AsyncResult) msg.obj; |
| 1826 | request = (MainThreadRequest) ar.userObj; |
| 1827 | IIntegerConsumer callback = |
| 1828 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1829 | if (ar.exception != null) { |
| 1830 | loge("setSimPower exception: " + ar.exception); |
| 1831 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1832 | .RESULT_ERROR_UNKNOWN; |
| 1833 | if (ar.exception instanceof CommandException) { |
| 1834 | CommandException.Error error = |
| 1835 | ((CommandException) (ar.exception)).getCommandError(); |
| 1836 | if (error == CommandException.Error.SIM_ERR) { |
| 1837 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1838 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1839 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1840 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1841 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1842 | } else { |
| 1843 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1844 | } |
| 1845 | } |
| 1846 | try { |
| 1847 | callback.accept(errorCode); |
| 1848 | } catch (RemoteException e) { |
| 1849 | // Ignore if the remote process is no longer available to call back. |
| 1850 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1851 | } |
| 1852 | } else { |
| 1853 | try { |
| 1854 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1855 | } catch (RemoteException e) { |
| 1856 | // Ignore if the remote process is no longer available to call back. |
| 1857 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1858 | } |
| 1859 | } |
| 1860 | break; |
| 1861 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1862 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1863 | request = (MainThreadRequest) msg.obj; |
| 1864 | |
| 1865 | final Phone phone = getPhoneFromRequest(request); |
| 1866 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1867 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1868 | notifyRequester(request); |
| 1869 | break; |
| 1870 | } |
| 1871 | |
| 1872 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1873 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1874 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1875 | request); |
| 1876 | phone.getServiceStateTracker().setSignalStrengthUpdateRequest( |
| 1877 | request.subId, pair.first /*callingUid*/, |
| 1878 | pair.second /*request*/, onCompleted); |
| 1879 | break; |
| 1880 | } |
| 1881 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1882 | ar = (AsyncResult) msg.obj; |
| 1883 | request = (MainThreadRequest) ar.userObj; |
| 1884 | // request.result will be the exception of ar if present, true otherwise. |
| 1885 | // Be cautious not to leave result null which will wait() forever |
| 1886 | request.result = ar.exception != null ? ar.exception : true; |
| 1887 | notifyRequester(request); |
| 1888 | break; |
| 1889 | } |
| 1890 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1891 | request = (MainThreadRequest) msg.obj; |
| 1892 | |
| 1893 | Phone phone = getPhoneFromRequest(request); |
| 1894 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1895 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1896 | notifyRequester(request); |
| 1897 | break; |
| 1898 | } |
| 1899 | |
| 1900 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1901 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1902 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1903 | request); |
| 1904 | phone.getServiceStateTracker().clearSignalStrengthUpdateRequest( |
| 1905 | request.subId, pair.first /*callingUid*/, |
| 1906 | pair.second /*request*/, onCompleted); |
| 1907 | break; |
| 1908 | } |
| 1909 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1910 | ar = (AsyncResult) msg.obj; |
| 1911 | request = (MainThreadRequest) ar.userObj; |
| 1912 | request.result = ar.exception != null ? ar.exception : true; |
| 1913 | notifyRequester(request); |
| 1914 | break; |
| 1915 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1916 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1917 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 1918 | request = (MainThreadRequest) msg.obj; |
| 1919 | request.result = |
| 1920 | UiccController.getInstance().getPinStorage().prepareUnattendedReboot(); |
| 1921 | notifyRequester(request); |
| 1922 | break; |
| 1923 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1924 | default: |
| 1925 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1926 | break; |
| 1927 | } |
| 1928 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1929 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1930 | private void notifyRequester(MainThreadRequest request) { |
| 1931 | synchronized (request) { |
| 1932 | request.notifyAll(); |
| 1933 | } |
| 1934 | } |
| 1935 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1936 | private void handleNullReturnEvent(Message msg, String command) { |
| 1937 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1938 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1939 | if (ar.exception == null) { |
| 1940 | request.result = true; |
| 1941 | } else { |
| 1942 | request.result = false; |
| 1943 | if (ar.exception instanceof CommandException) { |
| 1944 | loge(command + ": CommandException: " + ar.exception); |
| 1945 | } else { |
| 1946 | loge(command + ": Unknown exception"); |
| 1947 | } |
| 1948 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1949 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1950 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1951 | } |
| 1952 | |
| 1953 | /** |
| 1954 | * Posts the specified command to be executed on the main thread, |
| 1955 | * waits for the request to complete, and returns the result. |
| 1956 | * @see #sendRequestAsync |
| 1957 | */ |
| 1958 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1959 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 1960 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1961 | } |
| 1962 | |
| 1963 | /** |
| 1964 | * Posts the specified command to be executed on the main thread, |
| 1965 | * waits for the request to complete, and returns the result. |
| 1966 | * @see #sendRequestAsync |
| 1967 | */ |
| 1968 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1969 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1970 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1971 | } |
| 1972 | |
| 1973 | /** |
| 1974 | * Posts the specified command to be executed on the main thread, |
| 1975 | * waits for the request to complete, and returns the result. |
| 1976 | * @see #sendRequestAsync |
| 1977 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1978 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1979 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 1980 | } |
| 1981 | |
| 1982 | /** |
| 1983 | * Posts the specified command to be executed on the main thread, |
| 1984 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 1985 | * if not timeout or null otherwise. |
| 1986 | * @see #sendRequestAsync |
| 1987 | */ |
| 1988 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 1989 | long timeoutInMs) { |
| 1990 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1991 | } |
| 1992 | |
| 1993 | /** |
| 1994 | * Posts the specified command to be executed on the main thread, |
| 1995 | * waits for the request to complete, and returns the result. |
| 1996 | * @see #sendRequestAsync |
| 1997 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1998 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1999 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2000 | } |
| 2001 | |
| 2002 | /** |
| 2003 | * Posts the specified command to be executed on the main thread, |
| 2004 | * waits for the request to complete, and returns the result. |
| 2005 | * @see #sendRequestAsync |
| 2006 | */ |
| 2007 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2008 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2009 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2010 | } |
| 2011 | |
| 2012 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2013 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2014 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2015 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2016 | * @see #sendRequestAsync |
| 2017 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2018 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2019 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2020 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2021 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2022 | } |
| 2023 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2024 | MainThreadRequest request = null; |
| 2025 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2026 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2027 | } else if (phone != null) { |
| 2028 | request = new MainThreadRequest(argument, phone, workSource); |
| 2029 | } else { |
| 2030 | request = new MainThreadRequest(argument, subId, workSource); |
| 2031 | } |
| 2032 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2033 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2034 | msg.sendToTarget(); |
| 2035 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2036 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2037 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2038 | if (timeoutInMs >= 0) { |
| 2039 | // Wait for at least timeoutInMs before returning null request result |
| 2040 | long now = SystemClock.elapsedRealtime(); |
| 2041 | long deadline = now + timeoutInMs; |
| 2042 | while (request == null && now < deadline) { |
| 2043 | try { |
| 2044 | request.wait(deadline - now); |
| 2045 | } catch (InterruptedException e) { |
| 2046 | // Do nothing, go back and check if request is completed or timeout |
| 2047 | } finally { |
| 2048 | now = SystemClock.elapsedRealtime(); |
| 2049 | } |
| 2050 | } |
| 2051 | } else { |
| 2052 | // Wait for the request to complete |
| 2053 | while (request.result == null) { |
| 2054 | try { |
| 2055 | request.wait(); |
| 2056 | } catch (InterruptedException e) { |
| 2057 | // Do nothing, go back and wait until the request is complete |
| 2058 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2059 | } |
| 2060 | } |
| 2061 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2062 | if (request.result == null) { |
| 2063 | Log.wtf(LOG_TAG, |
| 2064 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2065 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2066 | return request.result; |
| 2067 | } |
| 2068 | |
| 2069 | /** |
| 2070 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2071 | * Posts the specified command to be executed on the main thread, and |
| 2072 | * returns immediately. |
| 2073 | * @see #sendRequest |
| 2074 | */ |
| 2075 | private void sendRequestAsync(int command) { |
| 2076 | mMainThreadHandler.sendEmptyMessage(command); |
| 2077 | } |
| 2078 | |
| 2079 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2080 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2081 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2082 | */ |
| 2083 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2084 | sendRequestAsync(command, argument, null, null); |
| 2085 | } |
| 2086 | |
| 2087 | /** |
| 2088 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2089 | * @see {@link #sendRequest(int,Object)} |
| 2090 | */ |
| 2091 | private void sendRequestAsync( |
| 2092 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2093 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2094 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2095 | msg.sendToTarget(); |
| 2096 | } |
| 2097 | |
| 2098 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2099 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2100 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2101 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2102 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2103 | synchronized (PhoneInterfaceManager.class) { |
| 2104 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2105 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2106 | } else { |
| 2107 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2108 | } |
| 2109 | return sInstance; |
| 2110 | } |
| 2111 | } |
| 2112 | |
| 2113 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2114 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2115 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2116 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 2117 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2118 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2119 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2120 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2121 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2122 | mTelephonySharedPreferences = |
| 2123 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2124 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2125 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2126 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2127 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2128 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2129 | publish(); |
| 2130 | } |
| 2131 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2132 | private Phone getDefaultPhone() { |
| 2133 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2134 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2135 | } |
| 2136 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2137 | private void publish() { |
| 2138 | if (DBG) log("publish: " + this); |
| 2139 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2140 | TelephonyFrameworkInitializer |
| 2141 | .getTelephonyServiceManager() |
| 2142 | .getTelephonyServiceRegisterer() |
| 2143 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2144 | } |
| 2145 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2146 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2147 | if (request.phone != null) { |
| 2148 | return request.phone; |
| 2149 | } else { |
| 2150 | return getPhoneFromSubId(request.subId); |
| 2151 | } |
| 2152 | } |
| 2153 | |
| 2154 | private Phone getPhoneFromSubId(int subId) { |
| 2155 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2156 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2157 | } |
| 2158 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2159 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 2160 | Phone phone = getPhoneFromRequest(request); |
| 2161 | return phone == null ? null : |
| 2162 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 2163 | } |
| 2164 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2165 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2166 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2167 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2168 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2169 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2170 | private void sendEraseModemConfig(Phone phone) { |
| 2171 | if (phone != null) { |
| 2172 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2173 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 2174 | final long identity = Binder.clearCallingIdentity(); |
| 2175 | try { |
| 2176 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2177 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2178 | } finally { |
| 2179 | Binder.restoreCallingIdentity(identity); |
| 2180 | } |
| 2181 | } |
| 2182 | } |
| 2183 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2184 | private boolean isImsAvailableOnDevice() { |
| 2185 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2186 | if (pm == null) { |
| 2187 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2188 | // so do not throw error and allow. |
| 2189 | return true; |
| 2190 | } |
| 2191 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2192 | } |
| 2193 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2194 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2195 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2196 | } |
| 2197 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2198 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2199 | if (DBG) log("dial: " + number); |
| 2200 | // No permission check needed here: This is just a wrapper around the |
| 2201 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2202 | // the UI before it does anything. |
| 2203 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2204 | final long identity = Binder.clearCallingIdentity(); |
| 2205 | try { |
| 2206 | String url = createTelUrl(number); |
| 2207 | if (url == null) { |
| 2208 | return; |
| 2209 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2210 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2211 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2212 | PhoneConstants.State state = mCM.getState(subId); |
| 2213 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2214 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2215 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2216 | mApp.startActivity(intent); |
| 2217 | } |
| 2218 | } finally { |
| 2219 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2220 | } |
| 2221 | } |
| 2222 | |
| 2223 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2224 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2225 | } |
| 2226 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2227 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2228 | if (DBG) log("call: " + number); |
| 2229 | |
| 2230 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2231 | // need to do a permission check since we're calling startActivity() |
| 2232 | // from the context of the phone app. |
| 2233 | enforceCallPermission(); |
| 2234 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2235 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2236 | != AppOpsManager.MODE_ALLOWED) { |
| 2237 | return; |
| 2238 | } |
| 2239 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2240 | final long identity = Binder.clearCallingIdentity(); |
| 2241 | try { |
| 2242 | String url = createTelUrl(number); |
| 2243 | if (url == null) { |
| 2244 | return; |
| 2245 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2246 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2247 | boolean isValid = false; |
| 2248 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2249 | if (slist != null) { |
| 2250 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2251 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2252 | isValid = true; |
| 2253 | break; |
| 2254 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2255 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2256 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2257 | if (!isValid) { |
| 2258 | return; |
| 2259 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2260 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2261 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2262 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2263 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2264 | mApp.startActivity(intent); |
| 2265 | } finally { |
| 2266 | Binder.restoreCallingIdentity(identity); |
| 2267 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2268 | } |
| 2269 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2270 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2271 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2272 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2273 | } |
| 2274 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2275 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2276 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2277 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2278 | } |
| 2279 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2280 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2281 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2282 | |
| 2283 | final long identity = Binder.clearCallingIdentity(); |
| 2284 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2285 | Phone phone = getPhone(subId); |
| 2286 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2287 | checkSimPin.start(); |
| 2288 | return checkSimPin.unlockSim(null, pin); |
| 2289 | } finally { |
| 2290 | Binder.restoreCallingIdentity(identity); |
| 2291 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2292 | } |
| 2293 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2294 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2295 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2296 | |
| 2297 | final long identity = Binder.clearCallingIdentity(); |
| 2298 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2299 | Phone phone = getPhone(subId); |
| 2300 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2301 | checkSimPuk.start(); |
| 2302 | return checkSimPuk.unlockSim(puk, pin); |
| 2303 | } finally { |
| 2304 | Binder.restoreCallingIdentity(identity); |
| 2305 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2306 | } |
| 2307 | |
| 2308 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2309 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2310 | * a synchronous one. |
| 2311 | */ |
| 2312 | private static class UnlockSim extends Thread { |
| 2313 | |
| 2314 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2315 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2316 | |
| 2317 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2318 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2319 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2320 | |
| 2321 | // For replies from SimCard interface |
| 2322 | private Handler mHandler; |
| 2323 | |
| 2324 | // For async handler to identify request type |
| 2325 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2326 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2327 | UnlockSim(int phoneId, IccCard simCard) { |
| 2328 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2329 | mSimCard = simCard; |
| 2330 | } |
| 2331 | |
| 2332 | @Override |
| 2333 | public void run() { |
| 2334 | Looper.prepare(); |
| 2335 | synchronized (UnlockSim.this) { |
| 2336 | mHandler = new Handler() { |
| 2337 | @Override |
| 2338 | public void handleMessage(Message msg) { |
| 2339 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2340 | switch (msg.what) { |
| 2341 | case SUPPLY_PIN_COMPLETE: |
| 2342 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2343 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2344 | mRetryCount = msg.arg1; |
| 2345 | if (ar.exception != null) { |
| 2346 | if (ar.exception instanceof CommandException && |
| 2347 | ((CommandException)(ar.exception)).getCommandError() |
| 2348 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2349 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2350 | } //When UiccCardApp dispose,handle message and return exception |
| 2351 | else if (ar.exception instanceof CommandException && |
| 2352 | ((CommandException) (ar.exception)).getCommandError() |
| 2353 | == CommandException.Error.ABORTED) { |
| 2354 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2355 | } else { |
| 2356 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2357 | } |
| 2358 | } else { |
| 2359 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2360 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2361 | mDone = true; |
| 2362 | UnlockSim.this.notifyAll(); |
| 2363 | } |
| 2364 | break; |
| 2365 | } |
| 2366 | } |
| 2367 | }; |
| 2368 | UnlockSim.this.notifyAll(); |
| 2369 | } |
| 2370 | Looper.loop(); |
| 2371 | } |
| 2372 | |
| 2373 | /* |
| 2374 | * Use PIN or PUK to unlock SIM card |
| 2375 | * |
| 2376 | * If PUK is null, unlock SIM card with PIN |
| 2377 | * |
| 2378 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2379 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2380 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2381 | |
| 2382 | while (mHandler == null) { |
| 2383 | try { |
| 2384 | wait(); |
| 2385 | } catch (InterruptedException e) { |
| 2386 | Thread.currentThread().interrupt(); |
| 2387 | } |
| 2388 | } |
| 2389 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2390 | |
| 2391 | if (puk == null) { |
| 2392 | mSimCard.supplyPin(pin, callback); |
| 2393 | } else { |
| 2394 | mSimCard.supplyPuk(puk, pin, callback); |
| 2395 | } |
| 2396 | |
| 2397 | while (!mDone) { |
| 2398 | try { |
| 2399 | Log.d(LOG_TAG, "wait for done"); |
| 2400 | wait(); |
| 2401 | } catch (InterruptedException e) { |
| 2402 | // Restore the interrupted status |
| 2403 | Thread.currentThread().interrupt(); |
| 2404 | } |
| 2405 | } |
| 2406 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2407 | int[] resultArray = new int[2]; |
| 2408 | resultArray[0] = mResult; |
| 2409 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2410 | |
| 2411 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
| 2412 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
| 2413 | } |
| 2414 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2415 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2416 | } |
| 2417 | } |
| 2418 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2419 | /** |
| 2420 | * This method has been removed due to privacy and stability concerns. |
| 2421 | */ |
| 2422 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2423 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2424 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2425 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2426 | } |
| 2427 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2428 | @Override |
| 2429 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2430 | mApp.getSystemService(AppOpsManager.class) |
| 2431 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2432 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2433 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2434 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2435 | // Callers targeting S have no business invoking this method. |
| 2436 | return; |
| 2437 | } |
| 2438 | |
| 2439 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2440 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2441 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2442 | .setCallingPackage(callingPackage) |
| 2443 | .setCallingFeatureId(null) |
| 2444 | .setCallingPid(Binder.getCallingPid()) |
| 2445 | .setCallingUid(Binder.getCallingUid()) |
| 2446 | .setMethod("updateServiceLocation") |
| 2447 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2448 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2449 | .build()); |
| 2450 | // Apps that lack location permission have no business calling this method; |
| 2451 | // however, because no permission was declared in the public API, denials must |
| 2452 | // all be "soft". |
| 2453 | switch (locationResult) { |
| 2454 | case DENIED_HARD: /* fall through */ |
| 2455 | case DENIED_SOFT: |
| 2456 | return; |
| 2457 | } |
| 2458 | |
| 2459 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2460 | final long identity = Binder.clearCallingIdentity(); |
| 2461 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2462 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2463 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2464 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2465 | } |
| 2466 | } finally { |
| 2467 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2468 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2469 | } |
| 2470 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2471 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2472 | @Override |
| 2473 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2474 | return isRadioOnWithFeature(callingPackage, null); |
| 2475 | } |
| 2476 | |
| 2477 | |
| 2478 | @Override |
| 2479 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2480 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2481 | callingFeatureId); |
| 2482 | } |
| 2483 | |
| 2484 | @Deprecated |
| 2485 | @Override |
| 2486 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2487 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2488 | } |
| 2489 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2490 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2491 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2492 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2493 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2494 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2495 | return false; |
| 2496 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2497 | |
| 2498 | final long identity = Binder.clearCallingIdentity(); |
| 2499 | try { |
| 2500 | return isRadioOnForSubscriber(subId); |
| 2501 | } finally { |
| 2502 | Binder.restoreCallingIdentity(identity); |
| 2503 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2504 | } |
| 2505 | |
| 2506 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2507 | final long identity = Binder.clearCallingIdentity(); |
| 2508 | try { |
| 2509 | final Phone phone = getPhone(subId); |
| 2510 | if (phone != null) { |
| 2511 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2512 | } else { |
| 2513 | return false; |
| 2514 | } |
| 2515 | } finally { |
| 2516 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2517 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2518 | } |
| 2519 | |
| 2520 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2521 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2522 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2523 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2524 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2525 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2526 | |
| 2527 | final long identity = Binder.clearCallingIdentity(); |
| 2528 | try { |
| 2529 | final Phone phone = getPhone(subId); |
| 2530 | if (phone != null) { |
| 2531 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2532 | } |
| 2533 | } finally { |
| 2534 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2535 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2536 | } |
| 2537 | |
| 2538 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2539 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2540 | } |
| 2541 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2542 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2543 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2544 | |
| 2545 | final long identity = Binder.clearCallingIdentity(); |
| 2546 | try { |
| 2547 | final Phone phone = getPhone(subId); |
| 2548 | if (phone == null) { |
| 2549 | return false; |
| 2550 | } |
| 2551 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2552 | toggleRadioOnOffForSubscriber(subId); |
| 2553 | } |
| 2554 | return true; |
| 2555 | } finally { |
| 2556 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2557 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2558 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2559 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2560 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2561 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2562 | /* |
| 2563 | * If any of the Radios are available, it will need to be |
| 2564 | * shutdown. So return true if any Radio is available. |
| 2565 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2566 | final long identity = Binder.clearCallingIdentity(); |
| 2567 | try { |
| 2568 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2569 | Phone phone = PhoneFactory.getPhone(i); |
| 2570 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2571 | } |
| 2572 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2573 | return false; |
| 2574 | } finally { |
| 2575 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2576 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2577 | } |
| 2578 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2579 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2580 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2581 | enforceModifyPermission(); |
| 2582 | |
| 2583 | final long identity = Binder.clearCallingIdentity(); |
| 2584 | try { |
| 2585 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2586 | logv("Shutting down Phone " + i); |
| 2587 | shutdownRadioUsingPhoneId(i); |
| 2588 | } |
| 2589 | } finally { |
| 2590 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2591 | } |
| 2592 | } |
| 2593 | |
| 2594 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2595 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2596 | if (phone != null && phone.isRadioAvailable()) { |
| 2597 | phone.shutdownRadio(); |
| 2598 | } |
| 2599 | } |
| 2600 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2601 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2602 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2603 | |
| 2604 | final long identity = Binder.clearCallingIdentity(); |
| 2605 | try { |
| 2606 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2607 | if (defaultPhone != null) { |
| 2608 | defaultPhone.setRadioPower(turnOn); |
| 2609 | return true; |
| 2610 | } else { |
| 2611 | loge("There's no default phone."); |
| 2612 | return false; |
| 2613 | } |
| 2614 | } finally { |
| 2615 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2616 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2617 | } |
| 2618 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2619 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2620 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2621 | |
| 2622 | final long identity = Binder.clearCallingIdentity(); |
| 2623 | try { |
| 2624 | final Phone phone = getPhone(subId); |
| 2625 | if (phone != null) { |
| 2626 | phone.setRadioPower(turnOn); |
| 2627 | return true; |
| 2628 | } else { |
| 2629 | return false; |
| 2630 | } |
| 2631 | } finally { |
| 2632 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2633 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2634 | } |
| 2635 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2636 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2637 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2638 | public boolean enableDataConnectivity() { |
| 2639 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2640 | |
| 2641 | final long identity = Binder.clearCallingIdentity(); |
| 2642 | try { |
| 2643 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2644 | final Phone phone = getPhone(subId); |
| 2645 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2646 | phone.getDataEnabledSettings().setDataEnabled( |
| 2647 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2648 | return true; |
| 2649 | } else { |
| 2650 | return false; |
| 2651 | } |
| 2652 | } finally { |
| 2653 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2654 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2655 | } |
| 2656 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2657 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2658 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2659 | public boolean disableDataConnectivity() { |
| 2660 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2661 | |
| 2662 | final long identity = Binder.clearCallingIdentity(); |
| 2663 | try { |
| 2664 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2665 | final Phone phone = getPhone(subId); |
| 2666 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2667 | phone.getDataEnabledSettings().setDataEnabled( |
| 2668 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2669 | return true; |
| 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 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2678 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2679 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2680 | final long identity = Binder.clearCallingIdentity(); |
| 2681 | try { |
| 2682 | final Phone phone = getPhone(subId); |
| 2683 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2684 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2685 | } else { |
| 2686 | return false; |
| 2687 | } |
| 2688 | } finally { |
| 2689 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2690 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2691 | } |
| 2692 | |
| 2693 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2694 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2695 | } |
| 2696 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2697 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2698 | enforceCallPermission(); |
| 2699 | |
| 2700 | final long identity = Binder.clearCallingIdentity(); |
| 2701 | try { |
| 2702 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2703 | return; |
| 2704 | } |
| 2705 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2706 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2707 | } finally { |
| 2708 | Binder.restoreCallingIdentity(identity); |
| 2709 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2710 | }; |
| 2711 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2712 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2713 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2714 | |
| 2715 | final long identity = Binder.clearCallingIdentity(); |
| 2716 | try { |
| 2717 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2718 | return false; |
| 2719 | } |
| 2720 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2721 | } finally { |
| 2722 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2723 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2724 | } |
| 2725 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2726 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2727 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2728 | } |
| 2729 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2730 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2731 | final long identity = Binder.clearCallingIdentity(); |
| 2732 | try { |
| 2733 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2734 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2735 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2736 | } finally { |
| 2737 | Binder.restoreCallingIdentity(identity); |
| 2738 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2739 | } |
| 2740 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2741 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2742 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2743 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2744 | } |
| 2745 | |
| 2746 | @Override |
| 2747 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2748 | final long identity = Binder.clearCallingIdentity(); |
| 2749 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2750 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2751 | if (phone != null) { |
| 2752 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2753 | } else { |
| 2754 | return PhoneConstantConversions.convertDataState( |
| 2755 | PhoneConstants.DataState.DISCONNECTED); |
| 2756 | } |
| 2757 | } finally { |
| 2758 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2759 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2760 | } |
| 2761 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2762 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2763 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2764 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2765 | } |
| 2766 | |
| 2767 | @Override |
| 2768 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2769 | final long identity = Binder.clearCallingIdentity(); |
| 2770 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2771 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2772 | if (phone != null) { |
| 2773 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2774 | } else { |
| 2775 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2776 | } |
| 2777 | } finally { |
| 2778 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2779 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2780 | } |
| 2781 | |
| 2782 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2783 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2784 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2785 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2786 | |
| 2787 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2788 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2789 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2790 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2791 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2792 | .setCallingPid(Binder.getCallingPid()) |
| 2793 | .setCallingUid(Binder.getCallingUid()) |
| 2794 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2795 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2796 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2797 | .build()); |
| 2798 | switch (locationResult) { |
| 2799 | case DENIED_HARD: |
| 2800 | throw new SecurityException("Not allowed to access cell location"); |
| 2801 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2802 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2803 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2804 | } |
| 2805 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2806 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2807 | final long identity = Binder.clearCallingIdentity(); |
| 2808 | try { |
| 2809 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2810 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2811 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2812 | } finally { |
| 2813 | Binder.restoreCallingIdentity(identity); |
| 2814 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2815 | } |
| 2816 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2817 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2818 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2819 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2820 | // registered cell info, so return a NULL country instead. |
| 2821 | final long identity = Binder.clearCallingIdentity(); |
| 2822 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2823 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2824 | // Get default phone in this case. |
| 2825 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2826 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2827 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2828 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2829 | if (phone == null) return ""; |
| 2830 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2831 | if (sst == null) return ""; |
| 2832 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2833 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 2834 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2835 | } finally { |
| 2836 | Binder.restoreCallingIdentity(identity); |
| 2837 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2838 | } |
| 2839 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2840 | /** |
| 2841 | * This method was removed due to potential issues caused by performing partial |
| 2842 | * updates of service state, and lack of a credible use case. |
| 2843 | * |
| 2844 | * This has the ability to break the telephony implementation by disabling notification of |
| 2845 | * changes in device connectivity. DO NOT USE THIS! |
| 2846 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2847 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2848 | public void enableLocationUpdates() { |
| 2849 | mApp.enforceCallingOrSelfPermission( |
| 2850 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2851 | } |
| 2852 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2853 | /** |
| 2854 | * This method was removed due to potential issues caused by performing partial |
| 2855 | * updates of service state, and lack of a credible use case. |
| 2856 | * |
| 2857 | * This has the ability to break the telephony implementation by disabling notification of |
| 2858 | * changes in device connectivity. DO NOT USE THIS! |
| 2859 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2860 | @Override |
| 2861 | public void disableLocationUpdates() { |
| 2862 | mApp.enforceCallingOrSelfPermission( |
| 2863 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2864 | } |
| 2865 | |
| 2866 | @Override |
| 2867 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2868 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2869 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2870 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2871 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2872 | throw new SecurityException( |
| 2873 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2874 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2875 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2876 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2877 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2878 | return null; |
| 2879 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2880 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2881 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2882 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2883 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2884 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2885 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2886 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2887 | for (CellInfo ci : info) { |
| 2888 | if (ci instanceof CellInfoGsm) { |
| 2889 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2890 | } else if (ci instanceof CellInfoWcdma) { |
| 2891 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2892 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2893 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2894 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2895 | } |
| 2896 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2897 | private List<CellInfo> getCachedCellInfo() { |
| 2898 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2899 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2900 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2901 | if (info != null) cellInfos.addAll(info); |
| 2902 | } |
| 2903 | return cellInfos; |
| 2904 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2905 | |
| 2906 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2907 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2908 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2909 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2910 | |
| 2911 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2912 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2913 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2914 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2915 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2916 | .setCallingPid(Binder.getCallingPid()) |
| 2917 | .setCallingUid(Binder.getCallingUid()) |
| 2918 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2919 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2920 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2921 | .build()); |
| 2922 | switch (locationResult) { |
| 2923 | case DENIED_HARD: |
| 2924 | throw new SecurityException("Not allowed to access cell info"); |
| 2925 | case DENIED_SOFT: |
| 2926 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2927 | } |
| 2928 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2929 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2930 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2931 | return getCachedCellInfo(); |
| 2932 | } |
| 2933 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2934 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2935 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2936 | final long identity = Binder.clearCallingIdentity(); |
| 2937 | try { |
| 2938 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2939 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2940 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2941 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2942 | if (info != null) cellInfos.addAll(info); |
| 2943 | } |
| 2944 | return cellInfos; |
| 2945 | } finally { |
| 2946 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2947 | } |
| 2948 | } |
| 2949 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2950 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2951 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2952 | String callingFeatureId) { |
| 2953 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2954 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2955 | } |
| 2956 | |
| 2957 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2958 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2959 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2960 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2961 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2962 | } |
| 2963 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2964 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2965 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2966 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2967 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2968 | |
| 2969 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2970 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2971 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2972 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2973 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2974 | .setCallingPid(Binder.getCallingPid()) |
| 2975 | .setCallingUid(Binder.getCallingUid()) |
| 2976 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2977 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2978 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2979 | .build()); |
| 2980 | switch (locationResult) { |
| 2981 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2982 | if (TelephonyPermissions |
| 2983 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2984 | // Safetynet logging for b/154934934 |
| 2985 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2986 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2987 | throw new SecurityException("Not allowed to access cell info"); |
| 2988 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2989 | if (TelephonyPermissions |
| 2990 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2991 | // Safetynet logging for b/154934934 |
| 2992 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2993 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2994 | try { |
| 2995 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2996 | } catch (RemoteException re) { |
| 2997 | // Drop without consequences |
| 2998 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2999 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3000 | } |
| 3001 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3002 | |
| 3003 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3004 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3005 | |
| 3006 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3007 | } |
| 3008 | |
| 3009 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3010 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3011 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3012 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3013 | |
| 3014 | final long identity = Binder.clearCallingIdentity(); |
| 3015 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3016 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3017 | } finally { |
| 3018 | Binder.restoreCallingIdentity(identity); |
| 3019 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3020 | } |
| 3021 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3022 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3023 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3024 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3025 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3026 | return null; |
| 3027 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3028 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3029 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3030 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3031 | return null; |
| 3032 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3033 | |
| 3034 | final long identity = Binder.clearCallingIdentity(); |
| 3035 | try { |
| 3036 | return phone.getImei(); |
| 3037 | } finally { |
| 3038 | Binder.restoreCallingIdentity(identity); |
| 3039 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3040 | } |
| 3041 | |
| 3042 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3043 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3044 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3045 | String tac = null; |
| 3046 | if (phone != null) { |
| 3047 | String imei = phone.getImei(); |
| 3048 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3049 | } |
| 3050 | return tac; |
| 3051 | } |
| 3052 | |
| 3053 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3054 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3055 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3056 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3057 | return null; |
| 3058 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3059 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3060 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3061 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3062 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3063 | return null; |
| 3064 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3065 | |
| 3066 | final long identity = Binder.clearCallingIdentity(); |
| 3067 | try { |
| 3068 | return phone.getMeid(); |
| 3069 | } finally { |
| 3070 | Binder.restoreCallingIdentity(identity); |
| 3071 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3072 | } |
| 3073 | |
| 3074 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3075 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3076 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3077 | String manufacturerCode = null; |
| 3078 | if (phone != null) { |
| 3079 | String meid = phone.getMeid(); |
| 3080 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3081 | } |
| 3082 | return manufacturerCode; |
| 3083 | } |
| 3084 | |
| 3085 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3086 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3087 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3088 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3089 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3090 | return null; |
| 3091 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3092 | int subId = phone.getSubId(); |
| 3093 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3094 | mApp, subId, callingPackage, callingFeatureId, |
| 3095 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3096 | return null; |
| 3097 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3098 | |
| 3099 | final long identity = Binder.clearCallingIdentity(); |
| 3100 | try { |
| 3101 | return phone.getDeviceSvn(); |
| 3102 | } finally { |
| 3103 | Binder.restoreCallingIdentity(identity); |
| 3104 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3105 | } |
| 3106 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3107 | @Override |
| 3108 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3109 | final long identity = Binder.clearCallingIdentity(); |
| 3110 | try { |
| 3111 | final Phone phone = getPhone(subId); |
| 3112 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3113 | } finally { |
| 3114 | Binder.restoreCallingIdentity(identity); |
| 3115 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3116 | } |
| 3117 | |
| 3118 | @Override |
| 3119 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3120 | final long identity = Binder.clearCallingIdentity(); |
| 3121 | try { |
| 3122 | final Phone phone = getPhone(subId); |
| 3123 | return phone == null ? null : phone.getCarrierName(); |
| 3124 | } finally { |
| 3125 | Binder.restoreCallingIdentity(identity); |
| 3126 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3127 | } |
| 3128 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3129 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3130 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3131 | final long identity = Binder.clearCallingIdentity(); |
| 3132 | try { |
| 3133 | final Phone phone = getPhone(subId); |
| 3134 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3135 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3136 | } finally { |
| 3137 | Binder.restoreCallingIdentity(identity); |
| 3138 | } |
| 3139 | } |
| 3140 | |
| 3141 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3142 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3143 | final long identity = Binder.clearCallingIdentity(); |
| 3144 | try { |
| 3145 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3146 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3147 | } finally { |
| 3148 | Binder.restoreCallingIdentity(identity); |
| 3149 | } |
| 3150 | } |
| 3151 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3152 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3153 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3154 | if (!isSubscriptionMccMnc) { |
| 3155 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3156 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3157 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3158 | if (phone == null) { |
| 3159 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3160 | } |
| 3161 | final long identity = Binder.clearCallingIdentity(); |
| 3162 | try { |
| 3163 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3164 | } finally { |
| 3165 | Binder.restoreCallingIdentity(identity); |
| 3166 | } |
| 3167 | } |
| 3168 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3169 | // |
| 3170 | // Internal helper methods. |
| 3171 | // |
| 3172 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3173 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3174 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3175 | * |
| 3176 | * @throws SecurityException if the caller does not have the required permission |
| 3177 | */ |
| 3178 | private void enforceModifyPermission() { |
| 3179 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3180 | } |
| 3181 | |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3182 | /** |
| 3183 | * Make sure the caller is system. |
| 3184 | * |
| 3185 | * @throws SecurityException if the caller is not system. |
| 3186 | */ |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 3187 | private static void enforceSystemCaller() { |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3188 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 3189 | throw new SecurityException("Caller must be system"); |
| 3190 | } |
| 3191 | } |
| 3192 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3193 | private void enforceActiveEmergencySessionPermission() { |
| 3194 | mApp.enforceCallingOrSelfPermission( |
| 3195 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3196 | } |
| 3197 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3198 | /** |
| 3199 | * Make sure the caller has the CALL_PHONE permission. |
| 3200 | * |
| 3201 | * @throws SecurityException if the caller does not have the required permission |
| 3202 | */ |
| 3203 | private void enforceCallPermission() { |
| 3204 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3205 | } |
| 3206 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3207 | private void enforceSettingsPermission() { |
| 3208 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3209 | } |
| 3210 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3211 | private void enforceRebootPermission() { |
| 3212 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3213 | } |
| 3214 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3215 | private String createTelUrl(String number) { |
| 3216 | if (TextUtils.isEmpty(number)) { |
| 3217 | return null; |
| 3218 | } |
| 3219 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3220 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3221 | } |
| 3222 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3223 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3224 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3225 | } |
| 3226 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3227 | private static void logv(String msg) { |
| 3228 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3229 | } |
| 3230 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3231 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3232 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3233 | } |
| 3234 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3235 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3236 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3237 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3238 | } |
| 3239 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3240 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3241 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3242 | final long identity = Binder.clearCallingIdentity(); |
| 3243 | try { |
| 3244 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3245 | if (phone == null) { |
| 3246 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3247 | } else { |
| 3248 | return phone.getPhoneType(); |
| 3249 | } |
| 3250 | } finally { |
| 3251 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3252 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3253 | } |
| 3254 | |
| 3255 | /** |
| 3256 | * Returns the CDMA ERI icon index to display |
| 3257 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3258 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3259 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3260 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3261 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3262 | } |
| 3263 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3264 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3265 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3266 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3267 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3268 | mApp, subId, callingPackage, callingFeatureId, |
| 3269 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3270 | return -1; |
| 3271 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3272 | |
| 3273 | final long identity = Binder.clearCallingIdentity(); |
| 3274 | try { |
| 3275 | final Phone phone = getPhone(subId); |
| 3276 | if (phone != null) { |
| 3277 | return phone.getCdmaEriIconIndex(); |
| 3278 | } else { |
| 3279 | return -1; |
| 3280 | } |
| 3281 | } finally { |
| 3282 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3283 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3284 | } |
| 3285 | |
| 3286 | /** |
| 3287 | * Returns the CDMA ERI icon mode, |
| 3288 | * 0 - ON |
| 3289 | * 1 - FLASHING |
| 3290 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3291 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3292 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3293 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3294 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3295 | } |
| 3296 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3297 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3298 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3299 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3300 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3301 | mApp, subId, callingPackage, callingFeatureId, |
| 3302 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3303 | return -1; |
| 3304 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3305 | |
| 3306 | final long identity = Binder.clearCallingIdentity(); |
| 3307 | try { |
| 3308 | final Phone phone = getPhone(subId); |
| 3309 | if (phone != null) { |
| 3310 | return phone.getCdmaEriIconMode(); |
| 3311 | } else { |
| 3312 | return -1; |
| 3313 | } |
| 3314 | } finally { |
| 3315 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3316 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3317 | } |
| 3318 | |
| 3319 | /** |
| 3320 | * Returns the CDMA ERI text, |
| 3321 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3322 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3323 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3324 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3325 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3326 | } |
| 3327 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3328 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3329 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3330 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3331 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3332 | mApp, subId, callingPackage, callingFeatureId, |
| 3333 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3334 | return null; |
| 3335 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3336 | |
| 3337 | final long identity = Binder.clearCallingIdentity(); |
| 3338 | try { |
| 3339 | final Phone phone = getPhone(subId); |
| 3340 | if (phone != null) { |
| 3341 | return phone.getCdmaEriText(); |
| 3342 | } else { |
| 3343 | return null; |
| 3344 | } |
| 3345 | } finally { |
| 3346 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3347 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3348 | } |
| 3349 | |
| 3350 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3351 | * Returns the CDMA MDN. |
| 3352 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3353 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3354 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3355 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3356 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3357 | |
| 3358 | final long identity = Binder.clearCallingIdentity(); |
| 3359 | try { |
| 3360 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3361 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3362 | return phone.getLine1Number(); |
| 3363 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3364 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3365 | return null; |
| 3366 | } |
| 3367 | } finally { |
| 3368 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3369 | } |
| 3370 | } |
| 3371 | |
| 3372 | /** |
| 3373 | * Returns the CDMA MIN. |
| 3374 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3375 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3376 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3377 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3378 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3379 | |
| 3380 | final long identity = Binder.clearCallingIdentity(); |
| 3381 | try { |
| 3382 | final Phone phone = getPhone(subId); |
| 3383 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3384 | return phone.getCdmaMin(); |
| 3385 | } else { |
| 3386 | return null; |
| 3387 | } |
| 3388 | } finally { |
| 3389 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3390 | } |
| 3391 | } |
| 3392 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3393 | @Override |
| 3394 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3395 | INumberVerificationCallback callback, String callingPackage) { |
| 3396 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3397 | != PERMISSION_GRANTED) { |
| 3398 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3399 | } |
| 3400 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3401 | |
| 3402 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3403 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3404 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3405 | + "calling package: " + callingPackage |
| 3406 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3407 | } |
| 3408 | |
| 3409 | if (range == null) { |
| 3410 | throw new NullPointerException("Range must be non-null"); |
| 3411 | } |
| 3412 | |
| 3413 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3414 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3415 | |
| 3416 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3417 | } |
| 3418 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3419 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3420 | * Returns true if CDMA provisioning needs to run. |
| 3421 | */ |
| 3422 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3423 | final long identity = Binder.clearCallingIdentity(); |
| 3424 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3425 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3426 | } finally { |
| 3427 | Binder.restoreCallingIdentity(identity); |
| 3428 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3429 | } |
| 3430 | |
| 3431 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3432 | * Sets the voice mail number of a given subId. |
| 3433 | */ |
| 3434 | @Override |
| 3435 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3436 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3437 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3438 | |
| 3439 | final long identity = Binder.clearCallingIdentity(); |
| 3440 | try { |
| 3441 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3442 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3443 | return success; |
| 3444 | } finally { |
| 3445 | Binder.restoreCallingIdentity(identity); |
| 3446 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3447 | } |
| 3448 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3449 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3450 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3451 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3452 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3453 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3454 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3455 | throw new SecurityException("caller must be system dialer"); |
| 3456 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3457 | |
| 3458 | final long identity = Binder.clearCallingIdentity(); |
| 3459 | try { |
| 3460 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3461 | if (phoneAccountHandle == null) { |
| 3462 | return null; |
| 3463 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3464 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3465 | } finally { |
| 3466 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3467 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3468 | } |
| 3469 | |
| 3470 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3471 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3472 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3473 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3474 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3475 | mApp, subId, callingPackage, callingFeatureId, |
| 3476 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3477 | return null; |
| 3478 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3479 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3480 | final long identity = Binder.clearCallingIdentity(); |
| 3481 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3482 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3483 | } finally { |
| 3484 | Binder.restoreCallingIdentity(identity); |
| 3485 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3486 | } |
| 3487 | |
| 3488 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3489 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3490 | VisualVoicemailSmsFilterSettings settings) { |
| 3491 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3492 | |
| 3493 | final long identity = Binder.clearCallingIdentity(); |
| 3494 | try { |
| 3495 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3496 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3497 | } finally { |
| 3498 | Binder.restoreCallingIdentity(identity); |
| 3499 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3500 | } |
| 3501 | |
| 3502 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3503 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3504 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3505 | |
| 3506 | final long identity = Binder.clearCallingIdentity(); |
| 3507 | try { |
| 3508 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3509 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3510 | } finally { |
| 3511 | Binder.restoreCallingIdentity(identity); |
| 3512 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3513 | } |
| 3514 | |
| 3515 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3516 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3517 | String callingPackage, int subId) { |
| 3518 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3519 | |
| 3520 | final long identity = Binder.clearCallingIdentity(); |
| 3521 | try { |
| 3522 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3523 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3524 | } finally { |
| 3525 | Binder.restoreCallingIdentity(identity); |
| 3526 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3527 | } |
| 3528 | |
| 3529 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3530 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3531 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3532 | |
| 3533 | final long identity = Binder.clearCallingIdentity(); |
| 3534 | try { |
| 3535 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3536 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3537 | } finally { |
| 3538 | Binder.restoreCallingIdentity(identity); |
| 3539 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3540 | } |
| 3541 | |
| 3542 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3543 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3544 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3545 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3546 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3547 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3548 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3549 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3550 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3551 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3552 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3553 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3554 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3555 | * Sets the voice activation state of a given subId. |
| 3556 | */ |
| 3557 | @Override |
| 3558 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3559 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3560 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3561 | |
| 3562 | final long identity = Binder.clearCallingIdentity(); |
| 3563 | try { |
| 3564 | final Phone phone = getPhone(subId); |
| 3565 | if (phone != null) { |
| 3566 | phone.setVoiceActivationState(activationState); |
| 3567 | } else { |
| 3568 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3569 | } |
| 3570 | } finally { |
| 3571 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3572 | } |
| 3573 | } |
| 3574 | |
| 3575 | /** |
| 3576 | * Sets the data activation state of a given subId. |
| 3577 | */ |
| 3578 | @Override |
| 3579 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3580 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3581 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3582 | |
| 3583 | final long identity = Binder.clearCallingIdentity(); |
| 3584 | try { |
| 3585 | final Phone phone = getPhone(subId); |
| 3586 | if (phone != null) { |
| 3587 | phone.setDataActivationState(activationState); |
| 3588 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3589 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3590 | } |
| 3591 | } finally { |
| 3592 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3593 | } |
| 3594 | } |
| 3595 | |
| 3596 | /** |
| 3597 | * Returns the voice activation state of a given subId. |
| 3598 | */ |
| 3599 | @Override |
| 3600 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3601 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3602 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3603 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3604 | final long identity = Binder.clearCallingIdentity(); |
| 3605 | try { |
| 3606 | if (phone != null) { |
| 3607 | return phone.getVoiceActivationState(); |
| 3608 | } else { |
| 3609 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3610 | } |
| 3611 | } finally { |
| 3612 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3613 | } |
| 3614 | } |
| 3615 | |
| 3616 | /** |
| 3617 | * Returns the data activation state of a given subId. |
| 3618 | */ |
| 3619 | @Override |
| 3620 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3621 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3622 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3623 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3624 | final long identity = Binder.clearCallingIdentity(); |
| 3625 | try { |
| 3626 | if (phone != null) { |
| 3627 | return phone.getDataActivationState(); |
| 3628 | } else { |
| 3629 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3630 | } |
| 3631 | } finally { |
| 3632 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3633 | } |
| 3634 | } |
| 3635 | |
| 3636 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3637 | * Returns the unread count of voicemails for a subId |
| 3638 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3639 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3640 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3641 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3642 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3643 | mApp, subId, callingPackage, callingFeatureId, |
| 3644 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3645 | return 0; |
| 3646 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3647 | final long identity = Binder.clearCallingIdentity(); |
| 3648 | try { |
| 3649 | final Phone phone = getPhone(subId); |
| 3650 | if (phone != null) { |
| 3651 | return phone.getVoiceMessageCount(); |
| 3652 | } else { |
| 3653 | return 0; |
| 3654 | } |
| 3655 | } finally { |
| 3656 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3657 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3658 | } |
| 3659 | |
| 3660 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3661 | * returns true, if the device is in a state where both voice and data |
| 3662 | * are supported simultaneously. This can change based on location or network condition. |
| 3663 | */ |
| 3664 | @Override |
| 3665 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3666 | final long identity = Binder.clearCallingIdentity(); |
| 3667 | try { |
| 3668 | final Phone phone = getPhone(subId); |
| 3669 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3670 | } finally { |
| 3671 | Binder.restoreCallingIdentity(identity); |
| 3672 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3673 | } |
| 3674 | |
| 3675 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3676 | * Send the dialer code if called from the current default dialer or the caller has |
| 3677 | * carrier privilege. |
| 3678 | * @param inputCode The dialer code to send |
| 3679 | */ |
| 3680 | @Override |
| 3681 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3682 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3683 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3684 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3685 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3686 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3687 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3688 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3689 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3690 | |
| 3691 | final long identity = Binder.clearCallingIdentity(); |
| 3692 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3693 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3694 | } finally { |
| 3695 | Binder.restoreCallingIdentity(identity); |
| 3696 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3697 | } |
| 3698 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3699 | @Override |
| 3700 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3701 | TelephonyPermissions |
| 3702 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3703 | mApp, subId, "getNetworkSelectionMode"); |
| 3704 | final long identity = Binder.clearCallingIdentity(); |
| 3705 | try { |
| 3706 | if (!isActiveSubscription(subId)) { |
| 3707 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3708 | } |
| 3709 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3710 | } finally { |
| 3711 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3712 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3713 | } |
| 3714 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3715 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3716 | public boolean isInEmergencySmsMode() { |
| 3717 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3718 | final long identity = Binder.clearCallingIdentity(); |
| 3719 | try { |
| 3720 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3721 | if (phone.isInEmergencySmsMode()) { |
| 3722 | return true; |
| 3723 | } |
| 3724 | } |
| 3725 | } finally { |
| 3726 | Binder.restoreCallingIdentity(identity); |
| 3727 | } |
| 3728 | return false; |
| 3729 | } |
| 3730 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3731 | /** |
| 3732 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3733 | * @param subId The subscription to use to check the configuration. |
| 3734 | * @param c The callback that will be used to send the result. |
| 3735 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3736 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3737 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3738 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3739 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3740 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3741 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3742 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3743 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3744 | "IMS not available on device."); |
| 3745 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3746 | final long token = Binder.clearCallingIdentity(); |
| 3747 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3748 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3749 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3750 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3751 | } catch (ImsException e) { |
| 3752 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3753 | } finally { |
| 3754 | Binder.restoreCallingIdentity(token); |
| 3755 | } |
| 3756 | } |
| 3757 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3758 | /** |
| 3759 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3760 | * @param subId The subscription to use to check the configuration. |
| 3761 | * @param c The callback that will be used to send the result. |
| 3762 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3763 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3764 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3765 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3766 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3767 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3768 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3769 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3770 | final long token = Binder.clearCallingIdentity(); |
| 3771 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3772 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3773 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3774 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3775 | } catch (ImsException e) { |
| 3776 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3777 | + "is inactive, ignoring unregister."); |
| 3778 | // If the subscription is no longer active, just return, since the callback |
| 3779 | // will already have been removed internally. |
| 3780 | } finally { |
| 3781 | Binder.restoreCallingIdentity(token); |
| 3782 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3783 | } |
| 3784 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3785 | /** |
| 3786 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3787 | */ |
| 3788 | @Override |
| 3789 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3790 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3791 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3792 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3793 | "IMS not available on device."); |
| 3794 | } |
| 3795 | final long token = Binder.clearCallingIdentity(); |
| 3796 | try { |
| 3797 | Phone phone = getPhone(subId); |
| 3798 | if (phone == null) { |
| 3799 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3800 | + subId + "'"); |
| 3801 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3802 | } |
| 3803 | phone.getImsRegistrationState(regState -> { |
| 3804 | try { |
| 3805 | consumer.accept((regState == null) |
| 3806 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3807 | } catch (RemoteException e) { |
| 3808 | // Ignore if the remote process is no longer available to call back. |
| 3809 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3810 | } |
| 3811 | }); |
| 3812 | } finally { |
| 3813 | Binder.restoreCallingIdentity(token); |
| 3814 | } |
| 3815 | } |
| 3816 | |
| 3817 | /** |
| 3818 | * Get the transport type for the IMS service registration state. |
| 3819 | */ |
| 3820 | @Override |
| 3821 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3822 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3823 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3824 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3825 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3826 | "IMS not available on device."); |
| 3827 | } |
| 3828 | final long token = Binder.clearCallingIdentity(); |
| 3829 | try { |
| 3830 | Phone phone = getPhone(subId); |
| 3831 | if (phone == null) { |
| 3832 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3833 | + subId + "'"); |
| 3834 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3835 | } |
| 3836 | phone.getImsRegistrationTech(regTech -> { |
| 3837 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3838 | int regTechConverted = (regTech == null) |
| 3839 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3840 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3841 | regTechConverted); |
| 3842 | try { |
| 3843 | consumer.accept(regTechConverted); |
| 3844 | } catch (RemoteException e) { |
| 3845 | // Ignore if the remote process is no longer available to call back. |
| 3846 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3847 | } |
| 3848 | }); |
| 3849 | } finally { |
| 3850 | Binder.restoreCallingIdentity(token); |
| 3851 | } |
| 3852 | } |
| 3853 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3854 | /** |
| 3855 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3856 | * @param subId The subscription to use to check the configuration. |
| 3857 | * @param c The callback that will be used to send the result. |
| 3858 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3859 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3860 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3861 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3862 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3863 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3864 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3865 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3866 | "IMS not available on device."); |
| 3867 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3868 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3869 | final long token = Binder.clearCallingIdentity(); |
| 3870 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3871 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3872 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3873 | } catch (ImsException e) { |
| 3874 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3875 | } finally { |
| 3876 | Binder.restoreCallingIdentity(token); |
| 3877 | } |
| 3878 | } |
| 3879 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3880 | /** |
| 3881 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3882 | * @param subId The subscription to use to check the configuration. |
| 3883 | * @param c The callback that will be used to send the result. |
| 3884 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3885 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3886 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3887 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3888 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3889 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3890 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3891 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3892 | |
| 3893 | final long token = Binder.clearCallingIdentity(); |
| 3894 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3895 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3896 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3897 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3898 | } catch (ImsException e) { |
| 3899 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3900 | + "is inactive, ignoring unregister."); |
| 3901 | // If the subscription is no longer active, just return, since the callback |
| 3902 | // will already have been removed internally. |
| 3903 | } finally { |
| 3904 | Binder.restoreCallingIdentity(token); |
| 3905 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3906 | } |
| 3907 | |
| 3908 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3909 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3910 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3911 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3912 | final long token = Binder.clearCallingIdentity(); |
| 3913 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3914 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3915 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3916 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3917 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3918 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3919 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3920 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3921 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3922 | } finally { |
| 3923 | Binder.restoreCallingIdentity(token); |
| 3924 | } |
| 3925 | } |
| 3926 | |
| 3927 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3928 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3929 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3930 | final long token = Binder.clearCallingIdentity(); |
| 3931 | try { |
| 3932 | Phone phone = getPhone(subId); |
| 3933 | if (phone == null) return false; |
| 3934 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3935 | } catch (com.android.ims.ImsException e) { |
| 3936 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3937 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3938 | } finally { |
| 3939 | Binder.restoreCallingIdentity(token); |
| 3940 | } |
| 3941 | } |
| 3942 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3943 | /** |
| 3944 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3945 | * subscription. |
| 3946 | * @param subId The subscription to use to check the configuration. |
| 3947 | * @param callback The callback that will be used to send the result. |
| 3948 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3949 | * @param transportType The transport type of the MmTelFeature capability. |
| 3950 | */ |
| 3951 | @Override |
| 3952 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3953 | int transportType) { |
| 3954 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3955 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3956 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3957 | "IMS not available on device."); |
| 3958 | } |
| 3959 | final long token = Binder.clearCallingIdentity(); |
| 3960 | try { |
| 3961 | int slotId = getSlotIndex(subId); |
| 3962 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3963 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3964 | + subId + "'"); |
| 3965 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3966 | } |
| 3967 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3968 | transportType, aBoolean -> { |
| 3969 | try { |
| 3970 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3971 | } catch (RemoteException e) { |
| 3972 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3973 | + "running. Ignore"); |
| 3974 | } |
| 3975 | }); |
| 3976 | } finally { |
| 3977 | Binder.restoreCallingIdentity(token); |
| 3978 | } |
| 3979 | } |
| 3980 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3981 | /** |
| 3982 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3983 | * @param subId The subscription to use to check the configuration. |
| 3984 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3985 | @Override |
| 3986 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3987 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3988 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3989 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3990 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3991 | final long token = Binder.clearCallingIdentity(); |
| 3992 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3993 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3994 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3995 | } catch (ImsException e) { |
| 3996 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3997 | } finally { |
| 3998 | Binder.restoreCallingIdentity(token); |
| 3999 | } |
| 4000 | } |
| 4001 | |
| 4002 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4003 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4004 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4005 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4006 | final long identity = Binder.clearCallingIdentity(); |
| 4007 | try { |
| 4008 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4009 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4010 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4011 | } catch (ImsException e) { |
| 4012 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4013 | } finally { |
| 4014 | Binder.restoreCallingIdentity(identity); |
| 4015 | } |
| 4016 | } |
| 4017 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4018 | /** |
| 4019 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4020 | * @param subId The subscription to use to check the configuration. |
| 4021 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4022 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4023 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4024 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4025 | mApp, subId, "isVtSettingEnabled"); |
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. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4029 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 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 | |
| 4037 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4038 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4039 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4040 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4041 | final long identity = Binder.clearCallingIdentity(); |
| 4042 | try { |
| 4043 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4044 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4045 | } catch (ImsException e) { |
| 4046 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4047 | } finally { |
| 4048 | Binder.restoreCallingIdentity(identity); |
| 4049 | } |
| 4050 | } |
| 4051 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4052 | /** |
| 4053 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4054 | * @param subId The subscription to use to check the configuration. |
| 4055 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4056 | @Override |
| 4057 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4058 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4059 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4060 | final long identity = Binder.clearCallingIdentity(); |
| 4061 | try { |
| 4062 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4063 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4064 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
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 | |
| 4072 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4073 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4074 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4075 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4076 | final long identity = Binder.clearCallingIdentity(); |
| 4077 | try { |
| 4078 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4079 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4080 | } catch (ImsException e) { |
| 4081 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4082 | } finally { |
| 4083 | Binder.restoreCallingIdentity(identity); |
| 4084 | } |
| 4085 | } |
| 4086 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4087 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4088 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4089 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4090 | * @param subId The subscription to use to check the configuration. |
| 4091 | */ |
| 4092 | @Override |
| 4093 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
| 4094 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4095 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4096 | final long identity = Binder.clearCallingIdentity(); |
| 4097 | try { |
| 4098 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4099 | return ImsManager.getInstance(mApp, |
| 4100 | getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser(); |
| 4101 | } catch (ImsException e) { |
| 4102 | throw new ServiceSpecificException(e.getCode()); |
| 4103 | } finally { |
| 4104 | Binder.restoreCallingIdentity(identity); |
| 4105 | } |
| 4106 | } |
| 4107 | |
| 4108 | /** |
| 4109 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4110 | * Requires MODIFY_PHONE_STATE permission. |
| 4111 | * @param subId The subscription to use to check the configuration. |
| 4112 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4113 | * false otherwise |
| 4114 | */ |
| 4115 | @Override |
| 4116 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4117 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4118 | "setCrossSimCallingEnabled"); |
| 4119 | final long identity = Binder.clearCallingIdentity(); |
| 4120 | try { |
| 4121 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4122 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 4123 | .setCrossSimCallingEnabled(isEnabled); |
| 4124 | } catch (ImsException e) { |
| 4125 | throw new ServiceSpecificException(e.getCode()); |
| 4126 | } finally { |
| 4127 | Binder.restoreCallingIdentity(identity); |
| 4128 | } |
| 4129 | } |
| 4130 | |
| 4131 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4132 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4133 | * @param subId The subscription to use to check the configuration. |
| 4134 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4135 | @Override |
| 4136 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4137 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4138 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4139 | final long identity = Binder.clearCallingIdentity(); |
| 4140 | try { |
| 4141 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4142 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4143 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4144 | } catch (ImsException e) { |
| 4145 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4146 | } finally { |
| 4147 | Binder.restoreCallingIdentity(identity); |
| 4148 | } |
| 4149 | } |
| 4150 | |
| 4151 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4152 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4153 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4154 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4155 | final long identity = Binder.clearCallingIdentity(); |
| 4156 | try { |
| 4157 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4158 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4159 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4160 | } catch (ImsException e) { |
| 4161 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4162 | } finally { |
| 4163 | Binder.restoreCallingIdentity(identity); |
| 4164 | } |
| 4165 | } |
| 4166 | |
| 4167 | @Override |
| 4168 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4169 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4170 | "setVoWiFiNonPersistent"); |
| 4171 | final long identity = Binder.clearCallingIdentity(); |
| 4172 | try { |
| 4173 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4174 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 4175 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4176 | } catch (ImsException e) { |
| 4177 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4178 | } finally { |
| 4179 | Binder.restoreCallingIdentity(identity); |
| 4180 | } |
| 4181 | } |
| 4182 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4183 | /** |
| 4184 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4185 | * @param subId The subscription to use to check the configuration. |
| 4186 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4187 | @Override |
| 4188 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4189 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4190 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4191 | final long identity = Binder.clearCallingIdentity(); |
| 4192 | try { |
| 4193 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4194 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4195 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4196 | } catch (ImsException e) { |
| 4197 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4198 | } finally { |
| 4199 | Binder.restoreCallingIdentity(identity); |
| 4200 | } |
| 4201 | } |
| 4202 | |
| 4203 | @Override |
| 4204 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4205 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4206 | "setVoWiFiModeSetting"); |
| 4207 | final long identity = Binder.clearCallingIdentity(); |
| 4208 | try { |
| 4209 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4210 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4211 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4212 | } catch (ImsException e) { |
| 4213 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4214 | } finally { |
| 4215 | Binder.restoreCallingIdentity(identity); |
| 4216 | } |
| 4217 | } |
| 4218 | |
| 4219 | @Override |
| 4220 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4221 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4222 | final long identity = Binder.clearCallingIdentity(); |
| 4223 | try { |
| 4224 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4225 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4226 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4227 | } catch (ImsException e) { |
| 4228 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4229 | } finally { |
| 4230 | Binder.restoreCallingIdentity(identity); |
| 4231 | } |
| 4232 | } |
| 4233 | |
| 4234 | @Override |
| 4235 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4236 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4237 | "setVoWiFiRoamingModeSetting"); |
| 4238 | final long identity = Binder.clearCallingIdentity(); |
| 4239 | try { |
| 4240 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4241 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4242 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4243 | } catch (ImsException e) { |
| 4244 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4245 | } finally { |
| 4246 | Binder.restoreCallingIdentity(identity); |
| 4247 | } |
| 4248 | } |
| 4249 | |
| 4250 | @Override |
| 4251 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4252 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4253 | "setRttCapabilityEnabled"); |
| 4254 | final long identity = Binder.clearCallingIdentity(); |
| 4255 | try { |
| 4256 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4257 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 4258 | } catch (ImsException e) { |
| 4259 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4260 | } finally { |
| 4261 | Binder.restoreCallingIdentity(identity); |
| 4262 | } |
| 4263 | } |
| 4264 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4265 | /** |
| 4266 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4267 | * @param subId The subscription to use to check the configuration. |
| 4268 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4269 | @Override |
| 4270 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4271 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4272 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4273 | final long identity = Binder.clearCallingIdentity(); |
| 4274 | try { |
| 4275 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4276 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4277 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4278 | } catch (ImsException e) { |
| 4279 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4280 | } finally { |
| 4281 | Binder.restoreCallingIdentity(identity); |
| 4282 | } |
| 4283 | } |
| 4284 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4285 | @Override |
| 4286 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4287 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4288 | final long identity = Binder.clearCallingIdentity(); |
| 4289 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4290 | if (!isImsAvailableOnDevice()) { |
| 4291 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4292 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4293 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4294 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4295 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4296 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4297 | } catch (ImsException e) { |
| 4298 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4299 | } finally { |
| 4300 | Binder.restoreCallingIdentity(identity); |
| 4301 | } |
| 4302 | } |
| 4303 | |
| 4304 | @Override |
| 4305 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4306 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4307 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4308 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4309 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4310 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4311 | try { |
| 4312 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4313 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4314 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4315 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4316 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4317 | + "is inactive, ignoring unregister."); |
| 4318 | // If the subscription is no longer active, just return, since the callback will already |
| 4319 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4320 | } finally { |
| 4321 | Binder.restoreCallingIdentity(identity); |
| 4322 | } |
| 4323 | } |
| 4324 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4325 | |
| 4326 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4327 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4328 | message); |
| 4329 | } |
| 4330 | |
| 4331 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4332 | boolean isMmtelCapability) { |
| 4333 | Phone phone = getPhone(subId); |
| 4334 | if (phone == null) { |
| 4335 | loge("phone instance null for subid " + subId); |
| 4336 | return false; |
| 4337 | } |
| 4338 | if (isMmtelCapability) { |
| 4339 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4340 | return false; |
| 4341 | } |
| 4342 | } else { |
| 4343 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4344 | return false; |
| 4345 | } |
| 4346 | } |
| 4347 | return true; |
| 4348 | } |
| 4349 | |
| 4350 | @Override |
| 4351 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4352 | boolean isProvisioned) { |
| 4353 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4354 | |
| 4355 | final long identity = Binder.clearCallingIdentity(); |
| 4356 | try { |
| 4357 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4358 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4359 | return; |
| 4360 | } |
| 4361 | |
| 4362 | // this capability requires provisioning, route to the correct API. |
| 4363 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4364 | switch (capability) { |
| 4365 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4366 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4367 | ims.setEabProvisioned(isProvisioned); |
| 4368 | break; |
| 4369 | default: { |
| 4370 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4371 | + "rcs capability '" + capability + "', which does not require " |
| 4372 | + "provisioning."); |
| 4373 | } |
| 4374 | } |
| 4375 | } finally { |
| 4376 | Binder.restoreCallingIdentity(identity); |
| 4377 | } |
| 4378 | |
| 4379 | } |
| 4380 | |
| 4381 | |
| 4382 | @Override |
| 4383 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4384 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4385 | final long identity = Binder.clearCallingIdentity(); |
| 4386 | try { |
| 4387 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4388 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4389 | return true; |
| 4390 | } |
| 4391 | |
| 4392 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4393 | switch (capability) { |
| 4394 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4395 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4396 | return ims.isEabProvisionedOnDevice(); |
| 4397 | |
| 4398 | default: { |
| 4399 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4400 | + "capability '" + capability + "', which does not require " |
| 4401 | + "provisioning."); |
| 4402 | } |
| 4403 | } |
| 4404 | |
| 4405 | } finally { |
| 4406 | Binder.restoreCallingIdentity(identity); |
| 4407 | } |
| 4408 | } |
| 4409 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4410 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4411 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4412 | boolean isProvisioned) { |
| 4413 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4414 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4415 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4416 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4417 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4418 | final long identity = Binder.clearCallingIdentity(); |
| 4419 | try { |
| 4420 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4421 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4422 | return; |
| 4423 | } |
| 4424 | |
| 4425 | // this capability requires provisioning, route to the correct API. |
| 4426 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4427 | switch (capability) { |
| 4428 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4429 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4430 | ims.setVolteProvisioned(isProvisioned); |
| 4431 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4432 | ims.setWfcProvisioned(isProvisioned); |
| 4433 | } |
| 4434 | break; |
| 4435 | } |
| 4436 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4437 | // There is currently no difference in VT provisioning type. |
| 4438 | ims.setVtProvisioned(isProvisioned); |
| 4439 | break; |
| 4440 | } |
| 4441 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4442 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4443 | // change the capability of the feature instead if needed. |
| 4444 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4445 | == isProvisioned) { |
| 4446 | // No change in provisioning. |
| 4447 | return; |
| 4448 | } |
| 4449 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4450 | try { |
| 4451 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4452 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4453 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4454 | + ", Exception" + e.getMessage()); |
| 4455 | } |
| 4456 | break; |
| 4457 | } |
| 4458 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4459 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4460 | + "MmTel capability '" + capability + "', which does not require " |
| 4461 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4462 | } |
| 4463 | } |
| 4464 | |
| 4465 | } finally { |
| 4466 | Binder.restoreCallingIdentity(identity); |
| 4467 | } |
| 4468 | } |
| 4469 | |
| 4470 | @Override |
| 4471 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4472 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4473 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4474 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4475 | } |
| 4476 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4477 | final long identity = Binder.clearCallingIdentity(); |
| 4478 | try { |
| 4479 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4480 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4481 | return true; |
| 4482 | } |
| 4483 | |
| 4484 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4485 | switch (capability) { |
| 4486 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4487 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4488 | return ims.isVolteProvisionedOnDevice(); |
| 4489 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4490 | return ims.isWfcProvisionedOnDevice(); |
| 4491 | } |
| 4492 | // This should never happen, since we are checking tech above to make sure it |
| 4493 | // is either LTE or IWLAN. |
| 4494 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4495 | + "capability."); |
| 4496 | } |
| 4497 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4498 | // There is currently no difference in VT provisioning type. |
| 4499 | return ims.isVtProvisionedOnDevice(); |
| 4500 | } |
| 4501 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4502 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4503 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4504 | } |
| 4505 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4506 | throw new IllegalArgumentException( |
| 4507 | "Tried to get provisioning for MmTel capability '" + capability |
| 4508 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4509 | } |
| 4510 | } |
| 4511 | |
| 4512 | } finally { |
| 4513 | Binder.restoreCallingIdentity(identity); |
| 4514 | } |
| 4515 | } |
| 4516 | |
| 4517 | @Override |
| 4518 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4519 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4520 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4521 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4522 | } |
| 4523 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4524 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4525 | return (provisionedBits & capability) > 0; |
| 4526 | } |
| 4527 | |
| 4528 | @Override |
| 4529 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4530 | boolean isProvisioned) { |
| 4531 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4532 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4533 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4534 | } |
| 4535 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4536 | "setProvisioningStatusForCapability"); |
| 4537 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4538 | // If the current provisioning status for capability already matches isProvisioned, |
| 4539 | // do nothing. |
| 4540 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4541 | return; |
| 4542 | } |
| 4543 | if (isProvisioned) { |
| 4544 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4545 | } else { |
| 4546 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4547 | } |
| 4548 | } |
| 4549 | |
| 4550 | /** |
| 4551 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4552 | * technology. The bitfield should mirror the bitfield defined by |
| 4553 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4554 | */ |
| 4555 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4556 | String key = getMmTelProvisioningKey(subId, tech); |
| 4557 | // Default is no capabilities are provisioned. |
| 4558 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4559 | } |
| 4560 | |
| 4561 | /** |
| 4562 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4563 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4564 | * technology specified. |
| 4565 | * |
| 4566 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4567 | */ |
| 4568 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4569 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4570 | String key = getMmTelProvisioningKey(subId, tech); |
| 4571 | editor.putInt(key, newField); |
| 4572 | editor.commit(); |
| 4573 | } |
| 4574 | |
| 4575 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4576 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4577 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4578 | } |
| 4579 | |
| 4580 | /** |
| 4581 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4582 | * carrier associated with the subscription id. |
| 4583 | */ |
| 4584 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4585 | int capability) { |
| 4586 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4587 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4588 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4589 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4590 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4591 | false); |
| 4592 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4593 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4594 | |
| 4595 | // First check to make sure that the capability requires provisioning. |
| 4596 | switch (capability) { |
| 4597 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4598 | // intentional fallthrough |
| 4599 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4600 | if (requireVoiceVtProvisioning) { |
| 4601 | // Voice and Video requires provisioning |
| 4602 | return true; |
| 4603 | } |
| 4604 | break; |
| 4605 | } |
| 4606 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4607 | if (requireUtProvisioning) { |
| 4608 | // UT requires provisioning |
| 4609 | return true; |
| 4610 | } |
| 4611 | break; |
| 4612 | } |
| 4613 | } |
| 4614 | return false; |
| 4615 | } |
| 4616 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4617 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4618 | int capability) { |
| 4619 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4620 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4621 | |
| 4622 | boolean requireRcsProvisioning = c.getBoolean( |
| 4623 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4624 | |
| 4625 | // First check to make sure that the capability requires provisioning. |
| 4626 | switch (capability) { |
| 4627 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4628 | // intentional fallthrough |
| 4629 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4630 | if (requireRcsProvisioning) { |
| 4631 | // OPTION or PRESENCE requires provisioning |
| 4632 | return true; |
| 4633 | } |
| 4634 | break; |
| 4635 | } |
| 4636 | } |
| 4637 | return false; |
| 4638 | } |
| 4639 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4640 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4641 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4642 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4643 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4644 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4645 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4646 | final long identity = Binder.clearCallingIdentity(); |
| 4647 | try { |
| 4648 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4649 | int slotId = getSlotIndex(subId); |
| 4650 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4651 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4652 | + subId + "' for key:" + key); |
| 4653 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4654 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4655 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4656 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4657 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4658 | + subId + "' for key:" + key); |
| 4659 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4660 | } finally { |
| 4661 | Binder.restoreCallingIdentity(identity); |
| 4662 | } |
| 4663 | } |
| 4664 | |
| 4665 | @Override |
| 4666 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4667 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4668 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4669 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4670 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4671 | final long identity = Binder.clearCallingIdentity(); |
| 4672 | try { |
| 4673 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4674 | int slotId = getSlotIndex(subId); |
| 4675 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4676 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4677 | + subId + "' for key:" + key); |
| 4678 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4679 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4680 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4681 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4682 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4683 | + subId + "' for key:" + key); |
| 4684 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4685 | } finally { |
| 4686 | Binder.restoreCallingIdentity(identity); |
| 4687 | } |
| 4688 | } |
| 4689 | |
| 4690 | @Override |
| 4691 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4692 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4693 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4694 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4695 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4696 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4697 | final long identity = Binder.clearCallingIdentity(); |
| 4698 | try { |
| 4699 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4700 | int slotId = getSlotIndex(subId); |
| 4701 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4702 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4703 | + subId + "' for key:" + key); |
| 4704 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4705 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4706 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4707 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4708 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4709 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4710 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4711 | } finally { |
| 4712 | Binder.restoreCallingIdentity(identity); |
| 4713 | } |
| 4714 | } |
| 4715 | |
| 4716 | @Override |
| 4717 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4718 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4719 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4720 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4721 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4722 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4723 | final long identity = Binder.clearCallingIdentity(); |
| 4724 | try { |
| 4725 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4726 | int slotId = getSlotIndex(subId); |
| 4727 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4728 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4729 | + subId + "' for key:" + key); |
| 4730 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4731 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4732 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4733 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4734 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4735 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4736 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4737 | } finally { |
| 4738 | Binder.restoreCallingIdentity(identity); |
| 4739 | } |
| 4740 | } |
| 4741 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4742 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4743 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4744 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4745 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4746 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4747 | } |
| 4748 | return slotId; |
| 4749 | } |
| 4750 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4751 | private int getSlotIndex(int subId) { |
| 4752 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4753 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4754 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4755 | } |
| 4756 | return slotId; |
| 4757 | } |
| 4758 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4759 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4760 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4761 | */ |
| 4762 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4763 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4764 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4765 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4766 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4767 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4768 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4769 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4770 | mApp, subId, callingPackage, callingFeatureId, |
| 4771 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4772 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4773 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4774 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4775 | final long identity = Binder.clearCallingIdentity(); |
| 4776 | try { |
| 4777 | final Phone phone = getPhone(subId); |
| 4778 | if (phone != null) { |
| 4779 | return phone.getServiceState().getDataNetworkType(); |
| 4780 | } else { |
| 4781 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4782 | } |
| 4783 | } finally { |
| 4784 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4785 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4786 | } |
| 4787 | |
| 4788 | /** |
| 4789 | * Returns the data network type |
| 4790 | */ |
| 4791 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4792 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4793 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4794 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4795 | } |
| 4796 | |
| 4797 | /** |
| 4798 | * Returns the data network type for a subId |
| 4799 | */ |
| 4800 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4801 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4802 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4803 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4804 | mApp, subId, callingPackage, callingFeatureId, |
| 4805 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4806 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4807 | } |
| 4808 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4809 | final long identity = Binder.clearCallingIdentity(); |
| 4810 | try { |
| 4811 | final Phone phone = getPhone(subId); |
| 4812 | if (phone != null) { |
| 4813 | return phone.getServiceState().getDataNetworkType(); |
| 4814 | } else { |
| 4815 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4816 | } |
| 4817 | } finally { |
| 4818 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4819 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4820 | } |
| 4821 | |
| 4822 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4823 | * Returns the Voice network type for a subId |
| 4824 | */ |
| 4825 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4826 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4827 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4828 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4829 | mApp, subId, callingPackage, callingFeatureId, |
| 4830 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4831 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4832 | } |
| 4833 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4834 | final long identity = Binder.clearCallingIdentity(); |
| 4835 | try { |
| 4836 | final Phone phone = getPhone(subId); |
| 4837 | if (phone != null) { |
| 4838 | return phone.getServiceState().getVoiceNetworkType(); |
| 4839 | } else { |
| 4840 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4841 | } |
| 4842 | } finally { |
| 4843 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4844 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4845 | } |
| 4846 | |
| 4847 | /** |
| 4848 | * @return true if a ICC card is present |
| 4849 | */ |
| 4850 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4851 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4852 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4853 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4854 | } |
| 4855 | |
| 4856 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4857 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4858 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4859 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4860 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4861 | final long identity = Binder.clearCallingIdentity(); |
| 4862 | try { |
| 4863 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4864 | if (phone != null) { |
| 4865 | return phone.getIccCard().hasIccCard(); |
| 4866 | } else { |
| 4867 | return false; |
| 4868 | } |
| 4869 | } finally { |
| 4870 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4871 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4872 | } |
| 4873 | |
| 4874 | /** |
| 4875 | * Return if the current radio is LTE on CDMA. This |
| 4876 | * is a tri-state return value as for a period of time |
| 4877 | * the mode may be unknown. |
| 4878 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4879 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4880 | * @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] | 4881 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4882 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4883 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4884 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4885 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4886 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4887 | } |
| 4888 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4889 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4890 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4891 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4892 | try { |
| 4893 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4894 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4895 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4896 | } |
| 4897 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4898 | final long identity = Binder.clearCallingIdentity(); |
| 4899 | try { |
| 4900 | final Phone phone = getPhone(subId); |
| 4901 | if (phone == null) { |
| 4902 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4903 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4904 | return TelephonyProperties.lte_on_cdma_device() |
| 4905 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4906 | } |
| 4907 | } finally { |
| 4908 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4909 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4910 | } |
| 4911 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4912 | /** |
| 4913 | * {@hide} |
| 4914 | * Returns Default subId, 0 in the case of single standby. |
| 4915 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4916 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4917 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4918 | } |
| 4919 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4920 | private int getSlotForDefaultSubscription() { |
| 4921 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4922 | } |
| 4923 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4924 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4925 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4926 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4927 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4928 | private boolean isActiveSubscription(int subId) { |
| 4929 | return mSubscriptionController.isActiveSubId(subId); |
| 4930 | } |
| 4931 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4932 | /** |
| 4933 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4934 | */ |
| 4935 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4936 | final long identity = Binder.clearCallingIdentity(); |
| 4937 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4938 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4939 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4940 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4941 | } finally { |
| 4942 | Binder.restoreCallingIdentity(identity); |
| 4943 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4944 | } |
| 4945 | |
| 4946 | /** |
| 4947 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4948 | */ |
| 4949 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4950 | final long identity = Binder.clearCallingIdentity(); |
| 4951 | try { |
| 4952 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4953 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4954 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4955 | } finally { |
| 4956 | Binder.restoreCallingIdentity(identity); |
| 4957 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4958 | } |
| 4959 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4960 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4961 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4962 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4963 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4964 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4965 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4966 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4967 | if (phoneId == -1) { |
| 4968 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4969 | + " does not correspond to an active phone"); |
| 4970 | } |
| 4971 | return PhoneFactory.getPhone(phoneId); |
| 4972 | } |
| 4973 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4974 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4975 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4976 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4977 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4978 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4979 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4980 | if (DBG) { |
| 4981 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4982 | } |
| 4983 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4984 | p2); |
| 4985 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4986 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4987 | |
| 4988 | @Override |
| 4989 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4990 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4991 | enforceModifyPermission(); |
| 4992 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4993 | if (DBG) { |
| 4994 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4995 | } |
| 4996 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4997 | callingPackage, aid, p2); |
| 4998 | } |
| 4999 | |
| 5000 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 5001 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5002 | final long identity = Binder.clearCallingIdentity(); |
| 5003 | try { |
| 5004 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 5005 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5006 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5007 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5008 | if (bestComponent == null |
| 5009 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5010 | loge("The calling package is not allowed to access ISD-R."); |
| 5011 | throw new SecurityException( |
| 5012 | "The calling package is not allowed to access ISD-R."); |
| 5013 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5014 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5015 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5016 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5017 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 5018 | null /* workSource */); |
| 5019 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5020 | return response; |
| 5021 | } finally { |
| 5022 | Binder.restoreCallingIdentity(identity); |
| 5023 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5024 | } |
| 5025 | |
| 5026 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5027 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5028 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5029 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5030 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 5031 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 5032 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5033 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5034 | @Override |
| 5035 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 5036 | enforceModifyPermission(); |
| 5037 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 5038 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 5039 | channel); |
| 5040 | } |
| 5041 | |
| 5042 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5043 | final long identity = Binder.clearCallingIdentity(); |
| 5044 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5045 | if (channel < 0) { |
| 5046 | return false; |
| 5047 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5048 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 5049 | null /* workSource */); |
| 5050 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5051 | return success; |
| 5052 | } finally { |
| 5053 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5054 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5055 | } |
| 5056 | |
| 5057 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5058 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5059 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5060 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5061 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5062 | if (DBG) { |
| 5063 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5064 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5065 | + p3 + " data=" + data); |
| 5066 | } |
| 5067 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5068 | command, p1, p2, p3, data); |
| 5069 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5070 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5071 | @Override |
| 5072 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 5073 | int command, int p1, int p2, int p3, String data) { |
| 5074 | enforceModifyPermission(); |
| 5075 | if (DBG) { |
| 5076 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 5077 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5078 | + p3 + " data=" + data); |
| 5079 | } |
| 5080 | return iccTransmitApduLogicalChannelWithPermission( |
| 5081 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 5082 | data); |
| 5083 | } |
| 5084 | |
| 5085 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5086 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5087 | final long identity = Binder.clearCallingIdentity(); |
| 5088 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5089 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5090 | return ""; |
| 5091 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5092 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5093 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5094 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5095 | null /* workSource */); |
| 5096 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5097 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5098 | // Append the returned status code to the end of the response payload. |
| 5099 | String s = Integer.toHexString( |
| 5100 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5101 | if (response.payload != null) { |
| 5102 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5103 | } |
| 5104 | return s; |
| 5105 | } finally { |
| 5106 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5107 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5108 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5109 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5110 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5111 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5112 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5113 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5114 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5115 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5116 | if (DBG) { |
| 5117 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5118 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5119 | } |
| 5120 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5121 | cla, command, p1, p2, p3, data); |
| 5122 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5123 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5124 | @Override |
| 5125 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 5126 | int command, int p1, int p2, int p3, String data) { |
| 5127 | enforceModifyPermission(); |
| 5128 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5129 | if (DBG) { |
| 5130 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 5131 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 5132 | + " data=" + data); |
| 5133 | } |
| 5134 | |
| 5135 | return iccTransmitApduBasicChannelWithPermission( |
| 5136 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 5137 | p2, p3, data); |
| 5138 | } |
| 5139 | |
| 5140 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5141 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5142 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5143 | final long identity = Binder.clearCallingIdentity(); |
| 5144 | try { |
| 5145 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5146 | && TextUtils.equals(ISDR_AID, data)) { |
| 5147 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5148 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5149 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5150 | if (bestComponent == null |
| 5151 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5152 | loge("The calling package is not allowed to select ISD-R."); |
| 5153 | throw new SecurityException( |
| 5154 | "The calling package is not allowed to select ISD-R."); |
| 5155 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5156 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5157 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5158 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5159 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5160 | null /* workSource */); |
| 5161 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5162 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5163 | // Append the returned status code to the end of the response payload. |
| 5164 | String s = Integer.toHexString( |
| 5165 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5166 | if (response.payload != null) { |
| 5167 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5168 | } |
| 5169 | return s; |
| 5170 | } finally { |
| 5171 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5172 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5173 | } |
| 5174 | |
| 5175 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5176 | 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] | 5177 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5178 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5179 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5180 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5181 | final long identity = Binder.clearCallingIdentity(); |
| 5182 | try { |
| 5183 | if (DBG) { |
| 5184 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5185 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5186 | } |
| 5187 | |
| 5188 | IccIoResult response = |
| 5189 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5190 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5191 | subId); |
| 5192 | |
| 5193 | if (DBG) { |
| 5194 | log("Exchange SIM_IO [R]" + response); |
| 5195 | } |
| 5196 | |
| 5197 | byte[] result = null; |
| 5198 | int length = 2; |
| 5199 | if (response.payload != null) { |
| 5200 | length = 2 + response.payload.length; |
| 5201 | result = new byte[length]; |
| 5202 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5203 | } else { |
| 5204 | result = new byte[length]; |
| 5205 | } |
| 5206 | |
| 5207 | result[length - 1] = (byte) response.sw2; |
| 5208 | result[length - 2] = (byte) response.sw1; |
| 5209 | return result; |
| 5210 | } finally { |
| 5211 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5212 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5213 | } |
| 5214 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5215 | /** |
| 5216 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5217 | * on a particular subscription |
| 5218 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5219 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5220 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5221 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5222 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5223 | return null; |
| 5224 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5225 | |
| 5226 | final long identity = Binder.clearCallingIdentity(); |
| 5227 | try { |
| 5228 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5229 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5230 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5231 | return null; |
| 5232 | } |
| 5233 | Object response = sendRequest( |
| 5234 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5235 | if (response instanceof String[]) { |
| 5236 | return (String[]) response; |
| 5237 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5238 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5239 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5240 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5241 | } finally { |
| 5242 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5243 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5244 | } |
| 5245 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5246 | /** |
| 5247 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5248 | * subscription. |
| 5249 | * |
| 5250 | * @param subId the id of the subscription. |
| 5251 | * @param appType the uicc app type, must be USIM or SIM. |
| 5252 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5253 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5254 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5255 | * @return number of fplmns that is successfully written to the SIM. |
| 5256 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5257 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5258 | String callingFeatureId) { |
| 5259 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 5260 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5261 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 5262 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 5263 | } |
| 5264 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5265 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5266 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5267 | } |
| 5268 | if (fplmns == null) { |
| 5269 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5270 | } |
| 5271 | for (String fplmn : fplmns) { |
| 5272 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5273 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5274 | } |
| 5275 | } |
| 5276 | final long identity = Binder.clearCallingIdentity(); |
| 5277 | try { |
| 5278 | Object response = sendRequest( |
| 5279 | CMD_SET_FORBIDDEN_PLMNS, |
| 5280 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5281 | subId); |
| 5282 | return (int) response; |
| 5283 | } finally { |
| 5284 | Binder.restoreCallingIdentity(identity); |
| 5285 | } |
| 5286 | } |
| 5287 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5288 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5289 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5290 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5291 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5292 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5293 | final long identity = Binder.clearCallingIdentity(); |
| 5294 | try { |
| 5295 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5296 | if (response.payload == null) { |
| 5297 | return ""; |
| 5298 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5299 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5300 | // Append the returned status code to the end of the response payload. |
| 5301 | String s = Integer.toHexString( |
| 5302 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5303 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5304 | return s; |
| 5305 | } finally { |
| 5306 | Binder.restoreCallingIdentity(identity); |
| 5307 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5308 | } |
| 5309 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5310 | /** |
| 5311 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5312 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5313 | * |
| 5314 | * @param itemID the ID of the item to read |
| 5315 | * @return the NV item as a String, or null on error. |
| 5316 | */ |
| 5317 | @Override |
| 5318 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5319 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5320 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5321 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5322 | |
| 5323 | final long identity = Binder.clearCallingIdentity(); |
| 5324 | try { |
| 5325 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5326 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5327 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5328 | return value; |
| 5329 | } finally { |
| 5330 | Binder.restoreCallingIdentity(identity); |
| 5331 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5332 | } |
| 5333 | |
| 5334 | /** |
| 5335 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5336 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5337 | * |
| 5338 | * @param itemID the ID of the item to read |
| 5339 | * @param itemValue the value to write, as a String |
| 5340 | * @return true on success; false on any failure |
| 5341 | */ |
| 5342 | @Override |
| 5343 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5344 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5345 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5346 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5347 | |
| 5348 | final long identity = Binder.clearCallingIdentity(); |
| 5349 | try { |
| 5350 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5351 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5352 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5353 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5354 | return success; |
| 5355 | } finally { |
| 5356 | Binder.restoreCallingIdentity(identity); |
| 5357 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5358 | } |
| 5359 | |
| 5360 | /** |
| 5361 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5362 | * Used for device configuration by some CDMA operators. |
| 5363 | * |
| 5364 | * @param preferredRoamingList byte array containing the new PRL |
| 5365 | * @return true on success; false on any failure |
| 5366 | */ |
| 5367 | @Override |
| 5368 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5369 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5370 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5371 | |
| 5372 | final long identity = Binder.clearCallingIdentity(); |
| 5373 | try { |
| 5374 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5375 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5376 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5377 | return success; |
| 5378 | } finally { |
| 5379 | Binder.restoreCallingIdentity(identity); |
| 5380 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5381 | } |
| 5382 | |
| 5383 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5384 | * 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] | 5385 | * Used for device configuration by some CDMA operators. |
| 5386 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5387 | * @param slotIndex - device slot. |
| 5388 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5389 | * @return true on success; false on any failure |
| 5390 | */ |
| 5391 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5392 | public boolean resetModemConfig(int slotIndex) { |
| 5393 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5394 | if (phone != null) { |
| 5395 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5396 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5397 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5398 | final long identity = Binder.clearCallingIdentity(); |
| 5399 | try { |
| 5400 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5401 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5402 | return success; |
| 5403 | } finally { |
| 5404 | Binder.restoreCallingIdentity(identity); |
| 5405 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5406 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5407 | return false; |
| 5408 | } |
| 5409 | |
| 5410 | /** |
| 5411 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5412 | * |
| 5413 | * @param slotIndex - device slot. |
| 5414 | * |
| 5415 | * @return true on success; false on any failure |
| 5416 | */ |
| 5417 | @Override |
| 5418 | public boolean rebootModem(int slotIndex) { |
| 5419 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5420 | if (phone != null) { |
| 5421 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5422 | mApp, phone.getSubId(), "rebootModem"); |
| 5423 | |
| 5424 | final long identity = Binder.clearCallingIdentity(); |
| 5425 | try { |
| 5426 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5427 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5428 | return success; |
| 5429 | } finally { |
| 5430 | Binder.restoreCallingIdentity(identity); |
| 5431 | } |
| 5432 | } |
| 5433 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5434 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5435 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5436 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5437 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5438 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5439 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5440 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5441 | return new String[0]; |
| 5442 | } |
| 5443 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5444 | final long identity = Binder.clearCallingIdentity(); |
| 5445 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5446 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5447 | } finally { |
| 5448 | Binder.restoreCallingIdentity(identity); |
| 5449 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5450 | } |
| 5451 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5452 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5453 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5454 | * {@link #disableIms(int)}. |
| 5455 | * @param slotIndex device slot. |
| 5456 | */ |
| 5457 | public void resetIms(int slotIndex) { |
| 5458 | enforceModifyPermission(); |
| 5459 | |
| 5460 | final long identity = Binder.clearCallingIdentity(); |
| 5461 | try { |
| 5462 | if (mImsResolver == null) { |
| 5463 | // may happen if the does not support IMS. |
| 5464 | return; |
| 5465 | } |
| 5466 | mImsResolver.disableIms(slotIndex); |
| 5467 | mImsResolver.enableIms(slotIndex); |
| 5468 | } finally { |
| 5469 | Binder.restoreCallingIdentity(identity); |
| 5470 | } |
| 5471 | } |
| 5472 | |
| 5473 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5474 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5475 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5476 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5477 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5478 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5479 | |
| 5480 | final long identity = Binder.clearCallingIdentity(); |
| 5481 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5482 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5483 | // may happen if the device does not support IMS. |
| 5484 | return; |
| 5485 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5486 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5487 | } finally { |
| 5488 | Binder.restoreCallingIdentity(identity); |
| 5489 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5490 | } |
| 5491 | |
| 5492 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5493 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5494 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5495 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5496 | public void disableIms(int slotId) { |
| 5497 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5498 | |
| 5499 | final long identity = Binder.clearCallingIdentity(); |
| 5500 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5501 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5502 | // may happen if the device does not support IMS. |
| 5503 | return; |
| 5504 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5505 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5506 | } finally { |
| 5507 | Binder.restoreCallingIdentity(identity); |
| 5508 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5509 | } |
| 5510 | |
| 5511 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5512 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5513 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5514 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5515 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5516 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5517 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5518 | |
| 5519 | final long identity = Binder.clearCallingIdentity(); |
| 5520 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5521 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5522 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5523 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5524 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5525 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5526 | } finally { |
| 5527 | Binder.restoreCallingIdentity(identity); |
| 5528 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5529 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5530 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5531 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5532 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5533 | @Override |
| 5534 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5535 | enforceModifyPermission(); |
| 5536 | |
| 5537 | final long identity = Binder.clearCallingIdentity(); |
| 5538 | try { |
| 5539 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5540 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5541 | } finally { |
| 5542 | Binder.restoreCallingIdentity(identity); |
| 5543 | } |
| 5544 | } |
| 5545 | |
| 5546 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5547 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5548 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5549 | */ |
| 5550 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5551 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5552 | |
| 5553 | final long identity = Binder.clearCallingIdentity(); |
| 5554 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5555 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5556 | // may happen if the device does not support IMS. |
| 5557 | return null; |
| 5558 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5559 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5560 | } finally { |
| 5561 | Binder.restoreCallingIdentity(identity); |
| 5562 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5563 | } |
| 5564 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5565 | /** |
| 5566 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5567 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5568 | */ |
| 5569 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5570 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5571 | |
| 5572 | final long identity = Binder.clearCallingIdentity(); |
| 5573 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5574 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5575 | // may happen if the device does not support IMS. |
| 5576 | return null; |
| 5577 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5578 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5579 | } finally { |
| 5580 | Binder.restoreCallingIdentity(identity); |
| 5581 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5582 | } |
| 5583 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5584 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5585 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5586 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5587 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5588 | * @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] | 5589 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5590 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5591 | * @param packageName The name of the package that the current configuration will be replaced |
| 5592 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5593 | * @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] | 5594 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5595 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5596 | int[] featureTypes, String packageName) { |
| 5597 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5598 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5599 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5600 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5601 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5602 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5603 | final long identity = Binder.clearCallingIdentity(); |
| 5604 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5605 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5606 | // may happen if the device does not support IMS. |
| 5607 | return false; |
| 5608 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5609 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5610 | for (int featureType : featureTypes) { |
| 5611 | featureConfig.put(featureType, packageName); |
| 5612 | } |
| 5613 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5614 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5615 | } finally { |
| 5616 | Binder.restoreCallingIdentity(identity); |
| 5617 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5618 | } |
| 5619 | |
| 5620 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5621 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5622 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5623 | * |
| 5624 | * This should only be used for testing. |
| 5625 | * |
| 5626 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5627 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5628 | */ |
| 5629 | @Override |
| 5630 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5631 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5632 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5633 | "clearCarrierImsServiceOverride"); |
| 5634 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5635 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5636 | "clearCarrierImsServiceOverride"); |
| 5637 | |
| 5638 | final long identity = Binder.clearCallingIdentity(); |
| 5639 | try { |
| 5640 | if (mImsResolver == null) { |
| 5641 | // may happen if the device does not support IMS. |
| 5642 | return false; |
| 5643 | } |
| 5644 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5645 | } finally { |
| 5646 | Binder.restoreCallingIdentity(identity); |
| 5647 | } |
| 5648 | } |
| 5649 | |
| 5650 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5651 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5652 | * |
| 5653 | * @param slotId The slot that the ImsService is associated with. |
| 5654 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5655 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5656 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5657 | * @return the package name of the ImsService configuration. |
| 5658 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5659 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5660 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5661 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5662 | TelephonyPermissions |
| 5663 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5664 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5665 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5666 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5667 | final long identity = Binder.clearCallingIdentity(); |
| 5668 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5669 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5670 | // may happen if the device does not support IMS. |
| 5671 | return ""; |
| 5672 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5673 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5674 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5675 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5676 | } finally { |
| 5677 | Binder.restoreCallingIdentity(identity); |
| 5678 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5679 | } |
| 5680 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5681 | /** |
| 5682 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5683 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5684 | * @param callback A callback with an integer containing the |
| 5685 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5686 | */ |
| 5687 | @Override |
| 5688 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5689 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5690 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5691 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5692 | "IMS not available on device."); |
| 5693 | } |
| 5694 | final long token = Binder.clearCallingIdentity(); |
| 5695 | try { |
| 5696 | int slotId = getSlotIndex(subId); |
| 5697 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5698 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5699 | + subId + "'"); |
| 5700 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5701 | } |
| 5702 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5703 | try { |
| 5704 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5705 | } catch (RemoteException e) { |
| 5706 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5707 | + "Ignore"); |
| 5708 | } |
| 5709 | }); |
| 5710 | } finally { |
| 5711 | Binder.restoreCallingIdentity(token); |
| 5712 | } |
| 5713 | } |
| 5714 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5715 | /** |
| 5716 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5717 | */ |
| 5718 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5719 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5720 | |
| 5721 | final long identity = Binder.clearCallingIdentity(); |
| 5722 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5723 | // NOTE: Before S, this method only set the default phone. |
| 5724 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5725 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5726 | phone.setImsRegistrationState(registered); |
| 5727 | } |
| 5728 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5729 | } finally { |
| 5730 | Binder.restoreCallingIdentity(identity); |
| 5731 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5732 | } |
| 5733 | |
| 5734 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5735 | * Set the network selection mode to automatic. |
| 5736 | * |
| 5737 | */ |
| 5738 | @Override |
| 5739 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5740 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5741 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5742 | |
| 5743 | final long identity = Binder.clearCallingIdentity(); |
| 5744 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5745 | if (!isActiveSubscription(subId)) { |
| 5746 | return; |
| 5747 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5748 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 5749 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 5750 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5751 | } finally { |
| 5752 | Binder.restoreCallingIdentity(identity); |
| 5753 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5754 | } |
| 5755 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5756 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5757 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5758 | * |
| 5759 | * @param subId the id of the subscription. |
| 5760 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5761 | * the operator to attach to. |
| 5762 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5763 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5764 | * normal network selection next time. |
| 5765 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5766 | */ |
| 5767 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5768 | public boolean setNetworkSelectionModeManual( |
| 5769 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5770 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5771 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5772 | |
| 5773 | if (!isActiveSubscription(subId)) { |
| 5774 | return false; |
| 5775 | } |
| 5776 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5777 | final long identity = Binder.clearCallingIdentity(); |
| 5778 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5779 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5780 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5781 | if (DBG) { |
| 5782 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5783 | + " operator: " + operatorInfo); |
| 5784 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5785 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5786 | } finally { |
| 5787 | Binder.restoreCallingIdentity(identity); |
| 5788 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5789 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5790 | /** |
| 5791 | * Get the manual network selection |
| 5792 | * |
| 5793 | * @param subId the id of the subscription. |
| 5794 | * |
| 5795 | * @return the previously saved user selected PLMN |
| 5796 | */ |
| 5797 | @Override |
| 5798 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5799 | TelephonyPermissions |
| 5800 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5801 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5802 | |
| 5803 | final long identity = Binder.clearCallingIdentity(); |
| 5804 | try { |
| 5805 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5806 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5807 | } |
| 5808 | |
| 5809 | final Phone phone = getPhone(subId); |
| 5810 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5811 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5812 | } |
| 5813 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5814 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5815 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5816 | } finally { |
| 5817 | Binder.restoreCallingIdentity(identity); |
| 5818 | } |
| 5819 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5820 | |
| 5821 | /** |
| 5822 | * Scans for available networks. |
| 5823 | */ |
| 5824 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5825 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5826 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5827 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5828 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5829 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5830 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5831 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5832 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5833 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5834 | .setCallingPid(Binder.getCallingPid()) |
| 5835 | .setCallingUid(Binder.getCallingUid()) |
| 5836 | .setMethod("getCellNetworkScanResults") |
| 5837 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 5838 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5839 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5840 | .build()); |
| 5841 | switch (locationResult) { |
| 5842 | case DENIED_HARD: |
| 5843 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5844 | case DENIED_SOFT: |
| 5845 | return null; |
| 5846 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5847 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5848 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5849 | try { |
| 5850 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5851 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5852 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5853 | } finally { |
| 5854 | Binder.restoreCallingIdentity(identity); |
| 5855 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5856 | } |
| 5857 | |
| 5858 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5859 | * Get the call forwarding info, given the call forwarding reason. |
| 5860 | */ |
| 5861 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5862 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5863 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5864 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5865 | long identity = Binder.clearCallingIdentity(); |
| 5866 | try { |
| 5867 | if (DBG) { |
| 5868 | log("getCallForwarding: subId " + subId |
| 5869 | + " callForwardingReason" + callForwardingReason); |
| 5870 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5871 | |
| 5872 | Phone phone = getPhone(subId); |
| 5873 | if (phone == null) { |
| 5874 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5875 | callback.onError( |
| 5876 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5877 | } catch (RemoteException e) { |
| 5878 | // ignore |
| 5879 | } |
| 5880 | return; |
| 5881 | } |
| 5882 | |
| 5883 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 5884 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 5885 | @Override |
| 5886 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 5887 | try { |
| 5888 | callback.onCallForwardingInfoAvailable(info); |
| 5889 | } catch (RemoteException e) { |
| 5890 | // ignore |
| 5891 | } |
| 5892 | } |
| 5893 | |
| 5894 | @Override |
| 5895 | public void onError(int error) { |
| 5896 | try { |
| 5897 | callback.onError(error); |
| 5898 | } catch (RemoteException e) { |
| 5899 | // ignore |
| 5900 | } |
| 5901 | } |
| 5902 | }); |
| 5903 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5904 | } finally { |
| 5905 | Binder.restoreCallingIdentity(identity); |
| 5906 | } |
| 5907 | } |
| 5908 | |
| 5909 | /** |
| 5910 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5911 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5912 | */ |
| 5913 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5914 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 5915 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5916 | enforceModifyPermission(); |
| 5917 | long identity = Binder.clearCallingIdentity(); |
| 5918 | try { |
| 5919 | if (DBG) { |
| 5920 | log("setCallForwarding: subId " + subId |
| 5921 | + " callForwardingInfo" + callForwardingInfo); |
| 5922 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5923 | |
| 5924 | Phone phone = getPhone(subId); |
| 5925 | if (phone == null) { |
| 5926 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5927 | callback.accept( |
| 5928 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5929 | } catch (RemoteException e) { |
| 5930 | // ignore |
| 5931 | } |
| 5932 | return; |
| 5933 | } |
| 5934 | |
| 5935 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 5936 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5937 | |
| 5938 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5939 | } finally { |
| 5940 | Binder.restoreCallingIdentity(identity); |
| 5941 | } |
| 5942 | } |
| 5943 | |
| 5944 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5945 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5946 | */ |
| 5947 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5948 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5949 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5950 | long identity = Binder.clearCallingIdentity(); |
| 5951 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5952 | |
| 5953 | Phone phone = getPhone(subId); |
| 5954 | if (phone == null) { |
| 5955 | try { |
| 5956 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5957 | } catch (RemoteException e) { |
| 5958 | // ignore |
| 5959 | } |
| 5960 | return; |
| 5961 | } |
| 5962 | |
| 5963 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 5964 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5965 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5966 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5967 | } finally { |
| 5968 | Binder.restoreCallingIdentity(identity); |
| 5969 | } |
| 5970 | } |
| 5971 | |
| 5972 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5973 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5974 | */ |
| 5975 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5976 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5977 | enforceModifyPermission(); |
| 5978 | long identity = Binder.clearCallingIdentity(); |
| 5979 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5980 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 5981 | |
| 5982 | Phone phone = getPhone(subId); |
| 5983 | if (phone == null) { |
| 5984 | try { |
| 5985 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5986 | } catch (RemoteException e) { |
| 5987 | // ignore |
| 5988 | } |
| 5989 | return; |
| 5990 | } |
| 5991 | |
| 5992 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 5993 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5994 | |
| 5995 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5996 | } finally { |
| 5997 | Binder.restoreCallingIdentity(identity); |
| 5998 | } |
| 5999 | } |
| 6000 | |
| 6001 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6002 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6003 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6004 | * @param subId id of the subscription |
| 6005 | * @param request contains the radio access networks with bands/channels to scan |
| 6006 | * @param messenger callback messenger for scan results or errors |
| 6007 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6008 | * @return the id of the requested scan which can be used to stop the scan. |
| 6009 | */ |
| 6010 | @Override |
| 6011 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6012 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6013 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6014 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6015 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6016 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6017 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6018 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6019 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6020 | .setCallingPid(Binder.getCallingPid()) |
| 6021 | .setCallingUid(Binder.getCallingUid()) |
| 6022 | .setMethod("requestNetworkScan") |
| 6023 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
James.cf Lin | 1d4d739 | 2020-07-03 18:22:53 +0800 | [diff] [blame] | 6024 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6025 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6026 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6027 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6028 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6029 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6030 | if (e != null) { |
| 6031 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6032 | throw e; |
| 6033 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6034 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6035 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6036 | } |
| 6037 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6038 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6039 | int callingUid = Binder.getCallingUid(); |
| 6040 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6041 | final long identity = Binder.clearCallingIdentity(); |
| 6042 | try { |
| 6043 | return mNetworkScanRequestTracker.startNetworkScan( |
| 6044 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6045 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6046 | } finally { |
| 6047 | Binder.restoreCallingIdentity(identity); |
| 6048 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6049 | } |
| 6050 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6051 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6052 | NetworkScanRequest request, int subId, String callingPackage) { |
| 6053 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6054 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6055 | boolean hasNetworkScanPermission = |
| 6056 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6057 | == PERMISSION_GRANTED; |
| 6058 | |
| 6059 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6060 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6061 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6062 | } |
| 6063 | |
| 6064 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6065 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6066 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6067 | return new SecurityException("Specific channels must not be" |
| 6068 | + " scanned without location access."); |
| 6069 | } |
| 6070 | } |
| 6071 | } |
| 6072 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6073 | return null; |
| 6074 | } |
| 6075 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6076 | /** |
| 6077 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6078 | * |
| 6079 | * @param subId id of the subscription |
| 6080 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6081 | */ |
| 6082 | @Override |
| 6083 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6084 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6085 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6086 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6087 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6088 | final long identity = Binder.clearCallingIdentity(); |
| 6089 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6090 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6091 | } finally { |
| 6092 | Binder.restoreCallingIdentity(identity); |
| 6093 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6094 | } |
| 6095 | |
| 6096 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6097 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6098 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6099 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6100 | */ |
| 6101 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6102 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6103 | TelephonyPermissions |
| 6104 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6105 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6106 | |
| 6107 | final long identity = Binder.clearCallingIdentity(); |
| 6108 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6109 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6110 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6111 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6112 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6113 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6114 | } finally { |
| 6115 | Binder.restoreCallingIdentity(identity); |
| 6116 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6117 | } |
| 6118 | |
| 6119 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6120 | * Get the allowed network types for certain reason. |
| 6121 | * |
| 6122 | * @param subId the id of the subscription. |
| 6123 | * @param reason the reason the allowed network type change is taking place |
| 6124 | * @return the allowed network types. |
| 6125 | */ |
| 6126 | @Override |
| 6127 | public long getAllowedNetworkTypesForReason(int subId, |
| 6128 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6129 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 6130 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6131 | final long identity = Binder.clearCallingIdentity(); |
| 6132 | try { |
| 6133 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6134 | } finally { |
| 6135 | Binder.restoreCallingIdentity(identity); |
| 6136 | } |
| 6137 | } |
| 6138 | |
| 6139 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6140 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6141 | * @param subId subscription id of the sim card |
| 6142 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6143 | * This can be passed following states |
| 6144 | * <ol> |
| 6145 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6146 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6147 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6148 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6149 | * </ol> |
| 6150 | * @return operation result. |
| 6151 | */ |
| 6152 | @Override |
| 6153 | public int setNrDualConnectivityState(int subId, |
| 6154 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6155 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6156 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6157 | if (isRadioInterfaceCapabilitySupported( |
| 6158 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6159 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6160 | } |
| 6161 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6162 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6163 | final long identity = Binder.clearCallingIdentity(); |
| 6164 | try { |
| 6165 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6166 | nrDualConnectivityState, subId, |
| 6167 | workSource); |
| 6168 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6169 | return result; |
| 6170 | } finally { |
| 6171 | Binder.restoreCallingIdentity(identity); |
| 6172 | } |
| 6173 | } |
| 6174 | |
| 6175 | /** |
| 6176 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6177 | * @return true if dual connectivity is enabled else false |
| 6178 | */ |
| 6179 | @Override |
| 6180 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6181 | TelephonyPermissions |
| 6182 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6183 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6184 | if (isRadioInterfaceCapabilitySupported( |
| 6185 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6186 | return false; |
| 6187 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6188 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6189 | final long identity = Binder.clearCallingIdentity(); |
| 6190 | try { |
| 6191 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6192 | null, subId, workSource); |
| 6193 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6194 | return isEnabled; |
| 6195 | } finally { |
| 6196 | Binder.restoreCallingIdentity(identity); |
| 6197 | } |
| 6198 | } |
| 6199 | |
| 6200 | /** |
Sooraj Sasindran | 4deb887 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 6201 | * get carrier bandwidth per primary and secondary carrier |
| 6202 | * @param subId subscription id of the sim card |
| 6203 | * @return CarrierBandwidth with bandwidth of both primary and secondary carrier.. |
| 6204 | */ |
| 6205 | @Override |
| 6206 | public CarrierBandwidth getCarrierBandwidth(int subId) { |
| 6207 | TelephonyPermissions |
| 6208 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6209 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6210 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6211 | final long identity = Binder.clearCallingIdentity(); |
| 6212 | try { |
| 6213 | CarrierBandwidth carrierBandwidth = |
| 6214 | getPhoneFromSubId(subId).getCarrierBandwidth(); |
| 6215 | if (DBG) log("getCarrierBandwidth: " + carrierBandwidth); |
| 6216 | return carrierBandwidth; |
| 6217 | } finally { |
| 6218 | Binder.restoreCallingIdentity(identity); |
| 6219 | } |
| 6220 | } |
| 6221 | |
| 6222 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6223 | * Set the allowed network types of the device and |
| 6224 | * provide the reason triggering the allowed network change. |
| 6225 | * |
| 6226 | * @param subId the id of the subscription. |
| 6227 | * @param reason the reason the allowed network type change is taking place |
| 6228 | * @param allowedNetworkTypes the allowed network types. |
| 6229 | * @return true on success; false on any failure. |
| 6230 | */ |
| 6231 | @Override |
| 6232 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6233 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6234 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6235 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6236 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6237 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
| 6238 | Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason); |
| 6239 | return false; |
| 6240 | } |
| 6241 | |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6242 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
| 6243 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6244 | |
| 6245 | |
| 6246 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
| 6247 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6248 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6249 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6250 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6251 | final long identity = Binder.clearCallingIdentity(); |
| 6252 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6253 | Boolean success = (Boolean) sendRequest( |
| 6254 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6255 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6256 | |
| 6257 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6258 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6259 | } finally { |
| 6260 | Binder.restoreCallingIdentity(identity); |
| 6261 | } |
| 6262 | } |
| 6263 | |
| 6264 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6265 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6266 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6267 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6268 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6269 | * @hide |
| 6270 | */ |
| 6271 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6272 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6273 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6274 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6275 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6276 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6277 | if (phone != null) { |
| 6278 | return phone.hasMatchedTetherApnSetting(); |
| 6279 | } else { |
| 6280 | return false; |
| 6281 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6282 | } finally { |
| 6283 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6284 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6285 | } |
| 6286 | |
| 6287 | /** |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6288 | * Enable or disable always reporting signal strength changes from radio. |
| 6289 | * |
| 6290 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6291 | */ |
| 6292 | @Override |
| 6293 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6294 | enforceModifyPermission(); |
| 6295 | enforceSystemCaller(); |
| 6296 | |
| 6297 | final long identity = Binder.clearCallingIdentity(); |
| 6298 | final Phone phone = getPhone(subId); |
| 6299 | try { |
| 6300 | if (phone != null) { |
| 6301 | if (DBG) { |
| 6302 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6303 | + " isEnable=" + isEnable); |
| 6304 | } |
| 6305 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6306 | } else { |
| 6307 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6308 | + subId); |
| 6309 | } |
| 6310 | } finally { |
| 6311 | Binder.restoreCallingIdentity(identity); |
| 6312 | } |
| 6313 | } |
| 6314 | |
| 6315 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6316 | * Get the user enabled state of Mobile Data. |
| 6317 | * |
| 6318 | * TODO: remove and use isUserDataEnabled. |
| 6319 | * This can't be removed now because some vendor codes |
| 6320 | * calls through ITelephony directly while they should |
| 6321 | * use TelephonyManager. |
| 6322 | * |
| 6323 | * @return true on enabled |
| 6324 | */ |
| 6325 | @Override |
| 6326 | public boolean getDataEnabled(int subId) { |
| 6327 | return isUserDataEnabled(subId); |
| 6328 | } |
| 6329 | |
| 6330 | /** |
| 6331 | * Get whether mobile data is enabled per user setting. |
| 6332 | * |
| 6333 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6334 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6335 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6336 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6337 | * |
| 6338 | * @return {@code true} if data is enabled else {@code false} |
| 6339 | */ |
| 6340 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6341 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6342 | try { |
| 6343 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6344 | null); |
| 6345 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6346 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6347 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6348 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6349 | |
| 6350 | final long identity = Binder.clearCallingIdentity(); |
| 6351 | try { |
| 6352 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6353 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6354 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6355 | if (phone != null) { |
| 6356 | boolean retVal = phone.isUserDataEnabled(); |
| 6357 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6358 | return retVal; |
| 6359 | } else { |
| 6360 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6361 | return false; |
| 6362 | } |
| 6363 | } finally { |
| 6364 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6365 | } |
| 6366 | } |
| 6367 | |
| 6368 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6369 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6370 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6371 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6372 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6373 | * @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] | 6374 | */ |
| 6375 | @Override |
| 6376 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6377 | try { |
| 6378 | try { |
| 6379 | mApp.enforceCallingOrSelfPermission( |
| 6380 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6381 | null); |
| 6382 | } catch (Exception e) { |
| 6383 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6384 | "isDataEnabled"); |
| 6385 | } |
| 6386 | } catch (Exception e) { |
| 6387 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6388 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6389 | |
| 6390 | final long identity = Binder.clearCallingIdentity(); |
| 6391 | try { |
| 6392 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6393 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6394 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6395 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6396 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6397 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6398 | return retVal; |
| 6399 | } else { |
| 6400 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6401 | return false; |
| 6402 | } |
| 6403 | } finally { |
| 6404 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6405 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6406 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6407 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6408 | /** |
| 6409 | * Check if data is enabled for a specific reason |
| 6410 | * @param subId Subscription index |
| 6411 | * @param reason the reason the data enable change is taking place |
| 6412 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6413 | */ |
| 6414 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6415 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6416 | @TelephonyManager.DataEnabledReason int reason) { |
| 6417 | try { |
| 6418 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6419 | null); |
| 6420 | } catch (Exception e) { |
| 6421 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6422 | "isDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6423 | } |
| 6424 | |
| 6425 | |
| 6426 | final long identity = Binder.clearCallingIdentity(); |
| 6427 | try { |
| 6428 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6429 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6430 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6431 | + " reason=" + reason); |
| 6432 | } |
| 6433 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6434 | if (phone != null) { |
| 6435 | boolean retVal; |
| 6436 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6437 | retVal = phone.isUserDataEnabled(); |
| 6438 | } else { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6439 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6440 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6441 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6442 | return retVal; |
| 6443 | } else { |
| 6444 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6445 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6446 | + subId + " retVal=false"); |
| 6447 | } |
| 6448 | return false; |
| 6449 | } |
| 6450 | } finally { |
| 6451 | Binder.restoreCallingIdentity(identity); |
| 6452 | } |
| 6453 | } |
| 6454 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6455 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6456 | Phone phone) { |
Hall Liu | 54a2a0c | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6457 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 6458 | // Skip the check if it's one of these special uids |
| 6459 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6460 | } |
| 6461 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6462 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6463 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6464 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6465 | || subController == null) return privilegeFromSim; |
| 6466 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6467 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6468 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6469 | |
| 6470 | final long identity = Binder.clearCallingIdentity(); |
| 6471 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6472 | int subId = phone.getSubId(); |
| 6473 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6474 | // A test override is in place for the privileges for this subId, so don't try to |
| 6475 | // read the subscription privileges. |
| 6476 | return privilegeFromSim; |
| 6477 | } |
| 6478 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6479 | SubscriptionManager subManager = (SubscriptionManager) |
| 6480 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6481 | for (String pkg : packages) { |
| 6482 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6483 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6484 | } |
| 6485 | } |
| 6486 | return privilegeFromSim; |
| 6487 | } finally { |
| 6488 | Binder.restoreCallingIdentity(identity); |
| 6489 | } |
| 6490 | } |
| 6491 | |
| 6492 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6493 | String pkgName) { |
| 6494 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6495 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6496 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6497 | || subController == null) return privilegeFromSim; |
| 6498 | |
| 6499 | final long identity = Binder.clearCallingIdentity(); |
| 6500 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6501 | int subId = phone.getSubId(); |
| 6502 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6503 | // A test override is in place for the privileges for this subId, so don't try to |
| 6504 | // read the subscription privileges. |
| 6505 | return privilegeFromSim; |
| 6506 | } |
| 6507 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6508 | SubscriptionManager subManager = (SubscriptionManager) |
| 6509 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6510 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6511 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6512 | } finally { |
| 6513 | Binder.restoreCallingIdentity(identity); |
| 6514 | } |
| 6515 | } |
| 6516 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6517 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6518 | public int getCarrierPrivilegeStatus(int subId) { |
| 6519 | final Phone phone = getPhone(subId); |
| 6520 | if (phone == null) { |
| 6521 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6522 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6523 | } |
| 6524 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6525 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6526 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6527 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6528 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6529 | |
| 6530 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6531 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6532 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6533 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6534 | |
| 6535 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6536 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6537 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6538 | final Phone phone = getPhone(subId); |
| 6539 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6540 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6541 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6542 | } |
| 6543 | UiccProfile profile = |
| 6544 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6545 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6546 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6547 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6548 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6549 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6550 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6551 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6552 | } |
| 6553 | |
| 6554 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6555 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6556 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6557 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6558 | } |
| 6559 | |
| 6560 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6561 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6562 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6563 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6564 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6565 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6566 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6567 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6568 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6569 | } |
| 6570 | |
| 6571 | @Override |
| 6572 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6573 | if (TextUtils.isEmpty(pkgName)) |
| 6574 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6575 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6576 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6577 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6578 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6579 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6580 | continue; |
| 6581 | } |
| 6582 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6583 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6584 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6585 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6586 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6587 | break; |
| 6588 | } |
| 6589 | } |
| 6590 | |
| 6591 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6592 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6593 | |
| 6594 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6595 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6596 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6597 | loge("phoneId " + phoneId + " is not valid."); |
| 6598 | return null; |
| 6599 | } |
| 6600 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6601 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6602 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6603 | return null ; |
| 6604 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6605 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6606 | } |
| 6607 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6608 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6609 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6610 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6611 | List<String> privilegedPackages = new ArrayList<>(); |
| 6612 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6613 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6614 | // has UICC in that slot. |
| 6615 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6616 | if (card.hasCarrierPrivilegeRules()) { |
| 6617 | if (packages == null) { |
| 6618 | // Only check packages in user 0 for now |
| 6619 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6620 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6621 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6622 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6623 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6624 | } |
| 6625 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6626 | PackageInfo pkgInfo = packages.get(p); |
| 6627 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6628 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6629 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6630 | privilegedPackages.add(pkgInfo.packageName); |
| 6631 | } |
| 6632 | } |
| 6633 | } |
| 6634 | } |
| 6635 | return privilegedPackages; |
| 6636 | } |
| 6637 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6638 | @Override |
| 6639 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6640 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6641 | |
| 6642 | final long identity = Binder.clearCallingIdentity(); |
| 6643 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6644 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6645 | try { |
| 6646 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6647 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6648 | } |
| 6649 | } finally { |
| 6650 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6651 | } |
| 6652 | return privilegedPackages; |
| 6653 | } |
| 6654 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6655 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6656 | final Phone phone = getPhone(subId); |
| 6657 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6658 | if (card == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6659 | return null; |
| 6660 | } |
| 6661 | String iccId = card.getIccId(); |
| 6662 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6663 | return null; |
| 6664 | } |
| 6665 | return iccId; |
| 6666 | } |
| 6667 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6668 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6669 | public void setCallComposerStatus(int subId, int status) { |
| 6670 | enforceModifyPermission(); |
| 6671 | |
| 6672 | final long identity = Binder.clearCallingIdentity(); |
| 6673 | try { |
| 6674 | Phone phone = getPhone(subId); |
| 6675 | if (phone != null) { |
| 6676 | Phone defaultPhone = phone.getImsPhone(); |
| 6677 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6678 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6679 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6680 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6681 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6682 | } |
| 6683 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6684 | } catch (ImsException e) { |
| 6685 | throw new ServiceSpecificException(e.getCode()); |
| 6686 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6687 | Binder.restoreCallingIdentity(identity); |
| 6688 | } |
| 6689 | } |
| 6690 | |
| 6691 | @Override |
| 6692 | public int getCallComposerStatus(int subId) { |
| 6693 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6694 | |
| 6695 | final long identity = Binder.clearCallingIdentity(); |
| 6696 | try { |
| 6697 | Phone phone = getPhone(subId); |
| 6698 | if (phone != null) { |
| 6699 | Phone defaultPhone = phone.getImsPhone(); |
| 6700 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6701 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6702 | return imsPhone.getCallComposerStatus(); |
| 6703 | } |
| 6704 | } |
| 6705 | } finally { |
| 6706 | Binder.restoreCallingIdentity(identity); |
| 6707 | } |
| 6708 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6709 | } |
| 6710 | |
| 6711 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6712 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6713 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6714 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6715 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6716 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6717 | final long identity = Binder.clearCallingIdentity(); |
| 6718 | try { |
| 6719 | final String iccId = getIccId(subId); |
| 6720 | final Phone phone = getPhone(subId); |
| 6721 | if (phone == null) { |
| 6722 | return false; |
| 6723 | } |
| 6724 | final String subscriberId = phone.getSubscriberId(); |
| 6725 | |
| 6726 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6727 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6728 | + subscriberId + " to " + number); |
| 6729 | } |
| 6730 | |
| 6731 | if (TextUtils.isEmpty(iccId)) { |
| 6732 | return false; |
| 6733 | } |
| 6734 | |
| 6735 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6736 | |
| 6737 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6738 | if (alphaTag == null) { |
| 6739 | editor.remove(alphaTagPrefKey); |
| 6740 | } else { |
| 6741 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6742 | } |
| 6743 | |
| 6744 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6745 | // track all merged IMSIs based on line number |
| 6746 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6747 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6748 | if (number == null) { |
| 6749 | editor.remove(numberPrefKey); |
| 6750 | editor.remove(subscriberPrefKey); |
| 6751 | } else { |
| 6752 | editor.putString(numberPrefKey, number); |
| 6753 | editor.putString(subscriberPrefKey, subscriberId); |
| 6754 | } |
| 6755 | |
| 6756 | editor.commit(); |
| 6757 | return true; |
| 6758 | } finally { |
| 6759 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6760 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6761 | } |
| 6762 | |
| 6763 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6764 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6765 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6766 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6767 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6768 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6769 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6770 | return null; |
| 6771 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6772 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6773 | final long identity = Binder.clearCallingIdentity(); |
| 6774 | try { |
| 6775 | String iccId = getIccId(subId); |
| 6776 | if (iccId != null) { |
| 6777 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6778 | if (DBG_MERGE) { |
| 6779 | log("getLine1NumberForDisplay returning " |
| 6780 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6781 | } |
| 6782 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6783 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6784 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6785 | return null; |
| 6786 | } finally { |
| 6787 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6788 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6789 | } |
| 6790 | |
| 6791 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6792 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6793 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6794 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6795 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6796 | return null; |
| 6797 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6798 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6799 | final long identity = Binder.clearCallingIdentity(); |
| 6800 | try { |
| 6801 | String iccId = getIccId(subId); |
| 6802 | if (iccId != null) { |
| 6803 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6804 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6805 | } |
| 6806 | return null; |
| 6807 | } finally { |
| 6808 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6809 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6810 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6811 | |
| 6812 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6813 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6814 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6815 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6816 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6817 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6818 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6819 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6820 | return null; |
| 6821 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6822 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6823 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6824 | // the process, where TelephonyManager was instantiated. |
| 6825 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6826 | final long identity = Binder.clearCallingIdentity(); |
| 6827 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6828 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6829 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6830 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6831 | |
| 6832 | // Figure out what subscribers are currently active |
| 6833 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6834 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6835 | // Only consider subs which match the current subId |
| 6836 | // This logic can be simplified. See b/131189269 for progress. |
| 6837 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6838 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6839 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6840 | |
| 6841 | // First pass, find a number override for an active subscriber |
| 6842 | String mergeNumber = null; |
| 6843 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6844 | for (String key : prefs.keySet()) { |
| 6845 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6846 | final String subscriberId = (String) prefs.get(key); |
| 6847 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6848 | final String iccId = key.substring( |
| 6849 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6850 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6851 | mergeNumber = (String) prefs.get(numberKey); |
| 6852 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6853 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6854 | + " for active subscriber " + subscriberId); |
| 6855 | } |
| 6856 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6857 | break; |
| 6858 | } |
| 6859 | } |
| 6860 | } |
| 6861 | } |
| 6862 | |
| 6863 | // Shortcut when no active merged subscribers |
| 6864 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6865 | return null; |
| 6866 | } |
| 6867 | |
| 6868 | // Second pass, find all subscribers under that line override |
| 6869 | final ArraySet<String> result = new ArraySet<>(); |
| 6870 | for (String key : prefs.keySet()) { |
| 6871 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6872 | final String number = (String) prefs.get(key); |
| 6873 | if (mergeNumber.equals(number)) { |
| 6874 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6875 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6876 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6877 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6878 | result.add(subscriberId); |
| 6879 | } |
| 6880 | } |
| 6881 | } |
| 6882 | } |
| 6883 | |
| 6884 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6885 | Arrays.sort(resultArray); |
| 6886 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6887 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6888 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6889 | } |
| 6890 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6891 | } finally { |
| 6892 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6893 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6894 | } |
| 6895 | |
| 6896 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6897 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6898 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6899 | |
| 6900 | final long identity = Binder.clearCallingIdentity(); |
| 6901 | try { |
| 6902 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6903 | TelephonyManager.class); |
| 6904 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6905 | if (subscriberId == null) { |
| 6906 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6907 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6908 | + subId); |
| 6909 | } |
| 6910 | return null; |
| 6911 | } |
| 6912 | |
| 6913 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6914 | .getSubscriptionInfo(subId); |
| 6915 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6916 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6917 | if (groupUuid == null) { |
| 6918 | return new String[]{subscriberId}; |
| 6919 | } |
| 6920 | |
| 6921 | // Get all subscriberIds from the group. |
| 6922 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6923 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6924 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6925 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6926 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6927 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6928 | if (subscriberId != null) { |
| 6929 | mergedSubscriberIds.add(subscriberId); |
| 6930 | } |
| 6931 | } |
| 6932 | |
| 6933 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6934 | } finally { |
| 6935 | Binder.restoreCallingIdentity(identity); |
| 6936 | |
| 6937 | } |
| 6938 | } |
| 6939 | |
| 6940 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6941 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6942 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6943 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6944 | |
| 6945 | final long identity = Binder.clearCallingIdentity(); |
| 6946 | try { |
| 6947 | final Phone phone = getPhone(subId); |
| 6948 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6949 | } finally { |
| 6950 | Binder.restoreCallingIdentity(identity); |
| 6951 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6952 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6953 | |
| 6954 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6955 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6956 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6957 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6958 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6959 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6960 | |
| 6961 | final long identity = Binder.clearCallingIdentity(); |
| 6962 | try { |
| 6963 | final Phone phone = getPhone(subId); |
| 6964 | if (phone == null) { |
| 6965 | return false; |
| 6966 | } |
| 6967 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6968 | cdmaNonRoamingList); |
| 6969 | } finally { |
| 6970 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6971 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6972 | } |
| 6973 | |
| 6974 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6975 | @Deprecated |
| 6976 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6977 | enforceModifyPermission(); |
| 6978 | |
| 6979 | int returnValue = 0; |
| 6980 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6981 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6982 | if(result.exception == null) { |
| 6983 | if (result.result != null) { |
| 6984 | byte[] responseData = (byte[])(result.result); |
| 6985 | if(responseData.length > oemResp.length) { |
| 6986 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6987 | responseData.length + "bytes. Buffer Size is " + |
| 6988 | oemResp.length + "bytes."); |
| 6989 | } |
| 6990 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6991 | returnValue = responseData.length; |
| 6992 | } |
| 6993 | } else { |
| 6994 | CommandException ex = (CommandException) result.exception; |
| 6995 | returnValue = ex.getCommandError().ordinal(); |
| 6996 | if(returnValue > 0) returnValue *= -1; |
| 6997 | } |
| 6998 | } catch (RuntimeException e) { |
| 6999 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7000 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7001 | if(returnValue > 0) returnValue *= -1; |
| 7002 | } |
| 7003 | |
| 7004 | return returnValue; |
| 7005 | } |
| 7006 | |
| 7007 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7008 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7009 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7010 | try { |
| 7011 | TelephonyPermissions |
| 7012 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 7013 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7014 | } catch (SecurityException e) { |
| 7015 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7016 | throw e; |
| 7017 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7018 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7019 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7020 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7021 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7022 | final long identity = Binder.clearCallingIdentity(); |
| 7023 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7024 | TelephonyPermissions |
| 7025 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 7026 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7027 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7028 | } finally { |
| 7029 | Binder.restoreCallingIdentity(identity); |
| 7030 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7031 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7032 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7033 | |
| 7034 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7035 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7036 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7037 | try { |
| 7038 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7039 | Binder.getCallingUid())) { |
| 7040 | throw new SecurityException("Package uid and package name do not match: " |
| 7041 | + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage); |
| 7042 | } |
| 7043 | } catch (PackageManager.NameNotFoundException e) { |
| 7044 | throw new SecurityException("Package name invalid:" + callingPackage); |
| 7045 | } |
| 7046 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7047 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7048 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7049 | throw new SecurityException("App must be the dialer role holder to" |
| 7050 | + " upload a call composer pic"); |
| 7051 | } |
| 7052 | |
| 7053 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7054 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7055 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7056 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7057 | boolean readUntilEnd = false; |
| 7058 | int totalBytesRead = 0; |
| 7059 | byte[] buffer = new byte[16 * 1024]; |
| 7060 | while (true) { |
| 7061 | int numRead; |
| 7062 | try { |
| 7063 | numRead = input.read(buffer); |
| 7064 | } catch (IOException e) { |
| 7065 | try { |
| 7066 | fd.checkError(); |
| 7067 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7068 | null); |
| 7069 | } catch (IOException e1) { |
| 7070 | // This means that the other side closed explicitly with an error. If this |
| 7071 | // happens, log and ignore. |
| 7072 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7073 | } |
| 7074 | break; |
| 7075 | } |
| 7076 | if (numRead == -1) { |
| 7077 | readUntilEnd = true; |
| 7078 | break; |
| 7079 | } |
| 7080 | totalBytesRead += numRead; |
| 7081 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7082 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7083 | try { |
| 7084 | input.close(); |
| 7085 | } catch (IOException e) { |
| 7086 | // ignore |
| 7087 | } |
| 7088 | break; |
| 7089 | } |
| 7090 | output.write(buffer, 0, numRead); |
| 7091 | } |
| 7092 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7093 | // close is above, where the picture size is too big. |
| 7094 | |
| 7095 | try { |
| 7096 | fd.checkError(); |
| 7097 | } catch (IOException e) { |
| 7098 | loge("Remote end for call composer closed with an error: " + e); |
| 7099 | return; |
| 7100 | } |
| 7101 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7102 | if (!readUntilEnd) { |
| 7103 | loge("Did not finish reading entire image; aborting"); |
| 7104 | return; |
| 7105 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7106 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7107 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7108 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7109 | new CallComposerPictureTransfer.Factory() {}, |
| 7110 | imageData, |
| 7111 | (result) -> { |
| 7112 | if (result.first != null) { |
| 7113 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7114 | Bundle outputResult = new Bundle(); |
| 7115 | outputResult.putParcelable( |
| 7116 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7117 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7118 | outputResult); |
| 7119 | } else { |
| 7120 | callback.send(result.second, null); |
| 7121 | } |
| 7122 | } |
| 7123 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7124 | }); |
| 7125 | } |
| 7126 | |
| 7127 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7128 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7129 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7130 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7131 | |
| 7132 | final long identity = Binder.clearCallingIdentity(); |
| 7133 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7134 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7135 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7136 | } finally { |
| 7137 | Binder.restoreCallingIdentity(identity); |
| 7138 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7139 | } |
| 7140 | |
| 7141 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7142 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7143 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7144 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7145 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7146 | return false; |
| 7147 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7148 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7149 | final long identity = Binder.clearCallingIdentity(); |
| 7150 | try { |
| 7151 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7152 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7153 | // In the long run, we may instead need to check if there exists a connection service |
| 7154 | // which can support video calling. |
| 7155 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7156 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7157 | return imsManager.isVtEnabledByPlatform() |
| 7158 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7159 | && imsManager.isVtEnabledByUser(); |
| 7160 | } finally { |
| 7161 | Binder.restoreCallingIdentity(identity); |
| 7162 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7163 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7164 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7165 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7166 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7167 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7168 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7169 | mApp, subId, callingPackage, callingFeatureId, |
| 7170 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7171 | return false; |
| 7172 | } |
| 7173 | |
| 7174 | final long identity = Binder.clearCallingIdentity(); |
| 7175 | try { |
| 7176 | CarrierConfigManager configManager = |
| 7177 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7178 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7179 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7180 | } finally { |
| 7181 | Binder.restoreCallingIdentity(identity); |
| 7182 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7183 | } |
| 7184 | |
| 7185 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7186 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7187 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7188 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7189 | return false; |
| 7190 | } |
| 7191 | |
| 7192 | final long identity = Binder.clearCallingIdentity(); |
| 7193 | try { |
| 7194 | CarrierConfigManager configManager = |
| 7195 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7196 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7197 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7198 | } finally { |
| 7199 | Binder.restoreCallingIdentity(identity); |
| 7200 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7201 | } |
| 7202 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7203 | @Override |
| 7204 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7205 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7206 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7207 | } |
| 7208 | |
| 7209 | @Override |
| 7210 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7211 | final long identity = Binder.clearCallingIdentity(); |
| 7212 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7213 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7214 | } finally { |
| 7215 | Binder.restoreCallingIdentity(identity); |
| 7216 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7217 | } |
| 7218 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7219 | /** |
| 7220 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7221 | * support for the feature and device firmware support. |
| 7222 | * |
| 7223 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7224 | */ |
| 7225 | @Override |
| 7226 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7227 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7228 | final Phone phone = getPhone(subscriptionId); |
| 7229 | if (phone == null) { |
| 7230 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7231 | return false; |
| 7232 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7233 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7234 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7235 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7236 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7237 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7238 | return isCarrierSupported && isDeviceSupported; |
| 7239 | } finally { |
| 7240 | Binder.restoreCallingIdentity(identity); |
| 7241 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7242 | } |
| 7243 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7244 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7245 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7246 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7247 | * 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] | 7248 | */ |
| 7249 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7250 | final long identity = Binder.clearCallingIdentity(); |
| 7251 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7252 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7253 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7254 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7255 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7256 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7257 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7258 | } finally { |
| 7259 | Binder.restoreCallingIdentity(identity); |
| 7260 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7261 | } |
| 7262 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7263 | @Deprecated |
| 7264 | @Override |
| 7265 | public String getDeviceId(String callingPackage) { |
| 7266 | return getDeviceIdWithFeature(callingPackage, null); |
| 7267 | } |
| 7268 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7269 | /** |
| 7270 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7271 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7272 | * |
| 7273 | * <p>Requires Permission: |
| 7274 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7275 | */ |
| 7276 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7277 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7278 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7279 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7280 | return null; |
| 7281 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7282 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7283 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7284 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7285 | return null; |
| 7286 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7287 | |
| 7288 | final long identity = Binder.clearCallingIdentity(); |
| 7289 | try { |
| 7290 | return phone.getDeviceId(); |
| 7291 | } finally { |
| 7292 | Binder.restoreCallingIdentity(identity); |
| 7293 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7294 | } |
| 7295 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7296 | /** |
| 7297 | * {@hide} |
| 7298 | * Returns the IMS Registration Status on a particular subid |
| 7299 | * |
| 7300 | * @param subId |
| 7301 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7302 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7303 | Phone phone = getPhone(subId); |
| 7304 | if (phone != null) { |
| 7305 | return phone.isImsRegistered(); |
| 7306 | } else { |
| 7307 | return false; |
| 7308 | } |
| 7309 | } |
| 7310 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7311 | @Override |
| 7312 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7313 | final long identity = Binder.clearCallingIdentity(); |
| 7314 | try { |
| 7315 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 7316 | } finally { |
| 7317 | Binder.restoreCallingIdentity(identity); |
| 7318 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7319 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7320 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7321 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7322 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7323 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7324 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7325 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7326 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7327 | } |
| 7328 | final long identity = Binder.clearCallingIdentity(); |
| 7329 | try { |
| 7330 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7331 | } finally { |
| 7332 | Binder.restoreCallingIdentity(identity); |
| 7333 | } |
| 7334 | } |
| 7335 | |
| 7336 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7337 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 7338 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 7339 | + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7340 | final long identity = Binder.clearCallingIdentity(); |
| 7341 | try { |
| 7342 | Phone phone = getPhone(subscriptionId); |
| 7343 | if (phone == null) { |
| 7344 | return null; |
| 7345 | } |
| 7346 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7347 | } finally { |
| 7348 | Binder.restoreCallingIdentity(identity); |
| 7349 | } |
| 7350 | } |
| 7351 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7352 | /** |
| 7353 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7354 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7355 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7356 | final long identity = Binder.clearCallingIdentity(); |
| 7357 | try { |
| 7358 | Phone phone = getPhone(subId); |
| 7359 | if (phone != null) { |
| 7360 | return phone.isWifiCallingEnabled(); |
| 7361 | } else { |
| 7362 | return false; |
| 7363 | } |
| 7364 | } finally { |
| 7365 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7366 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7367 | } |
| 7368 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7369 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7370 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7371 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7372 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7373 | final long identity = Binder.clearCallingIdentity(); |
| 7374 | try { |
| 7375 | Phone phone = getPhone(subId); |
| 7376 | if (phone != null) { |
| 7377 | return phone.isVideoEnabled(); |
| 7378 | } else { |
| 7379 | return false; |
| 7380 | } |
| 7381 | } finally { |
| 7382 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7383 | } |
| 7384 | } |
| 7385 | |
| 7386 | /** |
| 7387 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7388 | * defined in {@link ImsRegistrationImplBase}. |
| 7389 | */ |
| 7390 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7391 | final long identity = Binder.clearCallingIdentity(); |
| 7392 | try { |
| 7393 | Phone phone = getPhone(subId); |
| 7394 | if (phone != null) { |
| 7395 | return phone.getImsRegistrationTech(); |
| 7396 | } else { |
| 7397 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7398 | } |
| 7399 | } finally { |
| 7400 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7401 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7402 | } |
| 7403 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7404 | @Override |
| 7405 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7406 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7407 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7408 | return; |
| 7409 | } |
| 7410 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7411 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7412 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7413 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7414 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7415 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7416 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7417 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7418 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7419 | Phone phone = getPhone(subId); |
| 7420 | if (phone != null) { |
| 7421 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7422 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7423 | "user=" + RadioAccessFamily.getRafFromNetworkType( |
| 7424 | RILConstants.PREFERRED_NETWORK_MODE)); |
| 7425 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7426 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7427 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 7428 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7429 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7430 | // There has been issues when Sms raw table somehow stores orphan |
| 7431 | // fragments. They lead to garbled message when new fragments come |
| 7432 | // in and combined with those stale ones. In case this happens again, |
| 7433 | // user can reset all network settings which will clean up this table. |
| 7434 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7435 | // Clean up IMS settings as well here. |
| 7436 | int slotId = getSlotIndex(subId); |
| 7437 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7438 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7439 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7440 | |
| 7441 | // Erase modem config if erase modem on network setting is enabled. |
| 7442 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7443 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7444 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 7445 | sendEraseModemConfig(getDefaultPhone()); |
| 7446 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7447 | } finally { |
| 7448 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7449 | } |
| 7450 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7451 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7452 | private void cleanUpSmsRawTable(Context context) { |
| 7453 | ContentResolver resolver = context.getContentResolver(); |
| 7454 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7455 | resolver.delete(uri, null, null); |
| 7456 | } |
| 7457 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7458 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7459 | public String getSimLocaleForSubscriber(int subId) { |
| 7460 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7461 | final Phone phone = getPhone(subId); |
| 7462 | if (phone == null) { |
| 7463 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7464 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7465 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7466 | final long identity = Binder.clearCallingIdentity(); |
| 7467 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7468 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7469 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7470 | if (info == null) { |
| 7471 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7472 | return null; |
| 7473 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7474 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7475 | // preferences (EF-PL and EF-LI)... |
| 7476 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7477 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7478 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7479 | if (localeFromDefaultSim != null) { |
| 7480 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7481 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7482 | + localeFromDefaultSim); |
| 7483 | return localeFromDefaultSim.toLanguageTag(); |
| 7484 | } else { |
| 7485 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7486 | } |
| 7487 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7488 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7489 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7490 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7491 | // the SIM and carrier preferences does not include a country we add the country |
| 7492 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7493 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7494 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7495 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7496 | return mccLocale.toLanguageTag(); |
| 7497 | } |
| 7498 | |
| 7499 | if (DBG) log("No locale found - returning null"); |
| 7500 | return null; |
| 7501 | } finally { |
| 7502 | Binder.restoreCallingIdentity(identity); |
| 7503 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7504 | } |
| 7505 | |
| 7506 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7507 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7508 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7509 | } |
| 7510 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7511 | /** |
| 7512 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7513 | */ |
| 7514 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7515 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7516 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7517 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7518 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7519 | private final ModemActivityInfo mLastModemActivityInfo = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7520 | new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7521 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7522 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7523 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7524 | * representing the state of the modem. |
| 7525 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7526 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7527 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7528 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7529 | */ |
| 7530 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7531 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7532 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7533 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7534 | |
| 7535 | final long identity = Binder.clearCallingIdentity(); |
| 7536 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7537 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7538 | } finally { |
| 7539 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7540 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7541 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7542 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7543 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7544 | // less than total activity duration. |
| 7545 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7546 | if (info == null) { |
| 7547 | return false; |
| 7548 | } |
| 7549 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7550 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7551 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7552 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7553 | return (info.isValid() |
| 7554 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7555 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7556 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7557 | && (totalTxTimeMs <= activityDurationMs)); |
| 7558 | } |
| 7559 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7560 | /** |
| 7561 | * {@hide} |
| 7562 | * Returns the service state information on specified subscription. |
| 7563 | */ |
| 7564 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7565 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7566 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7567 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7568 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7569 | return null; |
| 7570 | } |
| 7571 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7572 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7573 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7574 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7575 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7576 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7577 | .setCallingPid(Binder.getCallingPid()) |
| 7578 | .setCallingUid(Binder.getCallingUid()) |
| 7579 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7580 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7581 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7582 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7583 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7584 | .build()); |
| 7585 | |
| 7586 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7587 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7588 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7589 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7590 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7591 | .setCallingPid(Binder.getCallingPid()) |
| 7592 | .setCallingUid(Binder.getCallingUid()) |
| 7593 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7594 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7595 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7596 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7597 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7598 | .build()); |
| 7599 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7600 | boolean hasFinePermission = |
| 7601 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7602 | boolean hasCoarsePermission = |
| 7603 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7604 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7605 | final Phone phone = getPhone(subId); |
| 7606 | if (phone == null) { |
| 7607 | return null; |
| 7608 | } |
| 7609 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 7610 | final long identity = Binder.clearCallingIdentity(); |
| 7611 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7612 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7613 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7614 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7615 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7616 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7617 | Rlog.d(LOG_TAG, |
| 7618 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7619 | return null; |
| 7620 | } |
| 7621 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7622 | ServiceState ss = phone.getServiceState(); |
| 7623 | |
| 7624 | // Scrub out the location info in ServiceState depending on what level of access |
| 7625 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7626 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7627 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7628 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7629 | } finally { |
| 7630 | Binder.restoreCallingIdentity(identity); |
| 7631 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7632 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7633 | |
| 7634 | /** |
| 7635 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7636 | * |
| 7637 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7638 | * voicemail ringtone. |
| 7639 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7640 | * PhoneAccount. |
| 7641 | */ |
| 7642 | @Override |
| 7643 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7644 | final long identity = Binder.clearCallingIdentity(); |
| 7645 | try { |
| 7646 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7647 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7648 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7649 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7650 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7651 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7652 | } finally { |
| 7653 | Binder.restoreCallingIdentity(identity); |
| 7654 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7655 | } |
| 7656 | |
| 7657 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7658 | * Sets the per-account voicemail ringtone. |
| 7659 | * |
| 7660 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7661 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7662 | * |
| 7663 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7664 | * voicemail ringtone. |
| 7665 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7666 | * PhoneAccount. |
| 7667 | */ |
| 7668 | @Override |
| 7669 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7670 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7671 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7672 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7673 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7674 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7675 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7676 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7677 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7678 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7679 | |
| 7680 | final long identity = Binder.clearCallingIdentity(); |
| 7681 | try { |
| 7682 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7683 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7684 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7685 | } |
| 7686 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7687 | } finally { |
| 7688 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7689 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7690 | } |
| 7691 | |
| 7692 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7693 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7694 | * |
| 7695 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7696 | * voicemail vibration setting. |
| 7697 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7698 | */ |
| 7699 | @Override |
| 7700 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7701 | final long identity = Binder.clearCallingIdentity(); |
| 7702 | try { |
| 7703 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7704 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7705 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7706 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7707 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7708 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7709 | } finally { |
| 7710 | Binder.restoreCallingIdentity(identity); |
| 7711 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7712 | } |
| 7713 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7714 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7715 | * Sets the per-account voicemail vibration. |
| 7716 | * |
| 7717 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7718 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7719 | * |
| 7720 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7721 | * voicemail vibration setting. |
| 7722 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7723 | * specific PhoneAccount. |
| 7724 | */ |
| 7725 | @Override |
| 7726 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7727 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7728 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7729 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7730 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7731 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7732 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7733 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7734 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7735 | } |
| 7736 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7737 | final long identity = Binder.clearCallingIdentity(); |
| 7738 | try { |
| 7739 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7740 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7741 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7742 | } |
| 7743 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7744 | } finally { |
| 7745 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7746 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7747 | } |
| 7748 | |
| 7749 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7750 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7751 | * |
| 7752 | * @throws SecurityException if the caller does not have the required permission |
| 7753 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7754 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7755 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7756 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7757 | } |
| 7758 | |
| 7759 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7760 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7761 | * permission. |
| 7762 | * |
| 7763 | * @throws SecurityException if the caller does not have the required permission |
| 7764 | */ |
| 7765 | private void enforceSendSmsPermission() { |
| 7766 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7767 | } |
| 7768 | |
| 7769 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7770 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7771 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7772 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7773 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7774 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7775 | final long identity = Binder.clearCallingIdentity(); |
| 7776 | try { |
| 7777 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7778 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7779 | if (componentName == null) { |
| 7780 | throw new SecurityException( |
| 7781 | "Caller not current active visual voicemail package[null]"); |
| 7782 | } |
| 7783 | String vvmPackage = componentName.getPackageName(); |
| 7784 | if (!callingPackage.equals(vvmPackage)) { |
| 7785 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7786 | + vvmPackage + "]"); |
| 7787 | } |
| 7788 | } finally { |
| 7789 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7790 | } |
| 7791 | } |
| 7792 | |
| 7793 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7794 | * Return the application ID for the app type. |
| 7795 | * |
| 7796 | * @param subId the subscription ID that this request applies to. |
| 7797 | * @param appType the uicc app type. |
| 7798 | * @return Application ID for specificied app type, or null if no uicc. |
| 7799 | */ |
| 7800 | @Override |
| 7801 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7802 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7803 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7804 | |
| 7805 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7806 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7807 | if (phone == null) { |
| 7808 | return null; |
| 7809 | } |
| 7810 | String aid = null; |
| 7811 | try { |
| 7812 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7813 | .getApplicationByType(appType).getAid(); |
| 7814 | } catch (Exception e) { |
| 7815 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7816 | } |
| 7817 | return aid; |
| 7818 | } finally { |
| 7819 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7820 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7821 | } |
| 7822 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7823 | /** |
| 7824 | * Return the Electronic Serial Number. |
| 7825 | * |
| 7826 | * @param subId the subscription ID that this request applies to. |
| 7827 | * @return ESN or null if error. |
| 7828 | */ |
| 7829 | @Override |
| 7830 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7831 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7832 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7833 | |
| 7834 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7835 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7836 | if (phone == null) { |
| 7837 | return null; |
| 7838 | } |
| 7839 | String esn = null; |
| 7840 | try { |
| 7841 | esn = phone.getEsn(); |
| 7842 | } catch (Exception e) { |
| 7843 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7844 | } |
| 7845 | return esn; |
| 7846 | } finally { |
| 7847 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7848 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7849 | } |
| 7850 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7851 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7852 | * Return the Preferred Roaming List Version. |
| 7853 | * |
| 7854 | * @param subId the subscription ID that this request applies to. |
| 7855 | * @return PRLVersion or null if error. |
| 7856 | */ |
| 7857 | @Override |
| 7858 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7859 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7860 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7861 | |
| 7862 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7863 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7864 | if (phone == null) { |
| 7865 | return null; |
| 7866 | } |
| 7867 | String cdmaPrlVersion = null; |
| 7868 | try { |
| 7869 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7870 | } catch (Exception e) { |
| 7871 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7872 | } |
| 7873 | return cdmaPrlVersion; |
| 7874 | } finally { |
| 7875 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7876 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7877 | } |
| 7878 | |
| 7879 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7880 | * Get snapshot of Telephony histograms |
| 7881 | * @return List of Telephony histograms |
| 7882 | * @hide |
| 7883 | */ |
| 7884 | @Override |
| 7885 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7886 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7887 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7888 | |
| 7889 | final long identity = Binder.clearCallingIdentity(); |
| 7890 | try { |
| 7891 | return RIL.getTelephonyRILTimingHistograms(); |
| 7892 | } finally { |
| 7893 | Binder.restoreCallingIdentity(identity); |
| 7894 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7895 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7896 | |
| 7897 | /** |
| 7898 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7899 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7900 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7901 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7902 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7903 | * @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] | 7904 | */ |
| 7905 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7906 | @TelephonyManager.SetCarrierRestrictionResult |
| 7907 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7908 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7909 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7910 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7911 | if (carrierRestrictionRules == null) { |
| 7912 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7913 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7914 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7915 | final long identity = Binder.clearCallingIdentity(); |
| 7916 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7917 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7918 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7919 | } finally { |
| 7920 | Binder.restoreCallingIdentity(identity); |
| 7921 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7922 | } |
| 7923 | |
| 7924 | /** |
| 7925 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7926 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7927 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7928 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7929 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7930 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7931 | */ |
| 7932 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7933 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7934 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7935 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7936 | |
| 7937 | final long identity = Binder.clearCallingIdentity(); |
| 7938 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7939 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7940 | if (response instanceof CarrierRestrictionRules) { |
| 7941 | return (CarrierRestrictionRules) response; |
| 7942 | } |
| 7943 | // Response is an Exception of some kind, |
| 7944 | // which is signalled to the user as a NULL retval |
| 7945 | return null; |
| 7946 | } catch (Exception e) { |
| 7947 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7948 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7949 | } finally { |
| 7950 | Binder.restoreCallingIdentity(identity); |
| 7951 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7952 | } |
| 7953 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7954 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7955 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7956 | * @param subId the subscription ID that this action applies to. |
| 7957 | * @param enabled control enable or disable radio. |
| 7958 | * {@hide} |
| 7959 | */ |
| 7960 | @Override |
| 7961 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7962 | enforceModifyPermission(); |
| 7963 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7964 | |
| 7965 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7966 | if (phone == null) { |
| 7967 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7968 | return; |
| 7969 | } |
| 7970 | try { |
| 7971 | phone.carrierActionSetRadioEnabled(enabled); |
| 7972 | } catch (Exception e) { |
| 7973 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7974 | } finally { |
| 7975 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7976 | } |
| 7977 | } |
| 7978 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7979 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7980 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7981 | * network status based on which carrier apps could apply actions accordingly, |
| 7982 | * enable/disable default url handler for example. |
| 7983 | * |
| 7984 | * @param subId the subscription ID that this action applies to. |
| 7985 | * @param report control start/stop reporting the default network status. |
| 7986 | * {@hide} |
| 7987 | */ |
| 7988 | @Override |
| 7989 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7990 | enforceModifyPermission(); |
| 7991 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7992 | |
| 7993 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7994 | if (phone == null) { |
| 7995 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7996 | return; |
| 7997 | } |
| 7998 | try { |
| 7999 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8000 | } catch (Exception e) { |
| 8001 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8002 | } finally { |
| 8003 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8004 | } |
| 8005 | } |
| 8006 | |
| 8007 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8008 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8009 | * @param subId the subscription ID that this action applies to. |
| 8010 | * {@hide} |
| 8011 | */ |
| 8012 | @Override |
| 8013 | public void carrierActionResetAll(int subId) { |
| 8014 | enforceModifyPermission(); |
| 8015 | final Phone phone = getPhone(subId); |
| 8016 | if (phone == null) { |
| 8017 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8018 | return; |
| 8019 | } |
| 8020 | try { |
| 8021 | phone.carrierActionResetAll(); |
| 8022 | } catch (Exception e) { |
| 8023 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8024 | } |
| 8025 | } |
| 8026 | |
| 8027 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8028 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8029 | * bug report is being generated. |
| 8030 | */ |
| 8031 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8032 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8033 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8034 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8035 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8036 | + Binder.getCallingPid() |
| 8037 | + ", uid=" + Binder.getCallingUid() |
| 8038 | + "without permission " |
| 8039 | + android.Manifest.permission.DUMP); |
| 8040 | return; |
| 8041 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8042 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8043 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8044 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8045 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8046 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8047 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8048 | @NonNull String[] args) { |
| 8049 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8050 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8051 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8052 | } |
| 8053 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8054 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8055 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8056 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8057 | * @param reason the reason the data enable change is taking place |
| 8058 | * @param enabled True if enabling the data, otherwise disabling. |
| 8059 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8060 | */ |
| 8061 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8062 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8063 | boolean enabled) { |
| 8064 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8065 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8066 | try { |
| 8067 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8068 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8069 | } catch (SecurityException se) { |
| 8070 | enforceModifyPermission(); |
| 8071 | } |
| 8072 | } else { |
| 8073 | enforceModifyPermission(); |
| 8074 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8075 | |
| 8076 | final long identity = Binder.clearCallingIdentity(); |
| 8077 | try { |
| 8078 | Phone phone = getPhone(subId); |
| 8079 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8080 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8081 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8082 | } else { |
| 8083 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 8084 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8085 | } |
| 8086 | } finally { |
| 8087 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8088 | } |
| 8089 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8090 | |
| 8091 | /** |
| 8092 | * Get Client request stats |
| 8093 | * @return List of Client Request Stats |
| 8094 | * @hide |
| 8095 | */ |
| 8096 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8097 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8098 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8099 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8100 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8101 | return null; |
| 8102 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8103 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8104 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8105 | final long identity = Binder.clearCallingIdentity(); |
| 8106 | try { |
| 8107 | if (phone != null) { |
| 8108 | return phone.getClientRequestStats(); |
| 8109 | } |
| 8110 | |
| 8111 | return null; |
| 8112 | } finally { |
| 8113 | Binder.restoreCallingIdentity(identity); |
| 8114 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8115 | } |
| 8116 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8117 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8118 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8119 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8120 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8121 | |
| 8122 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8123 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8124 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8125 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8126 | * @param state State of SIM (power down, power up, pass through) |
| 8127 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8128 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8129 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8130 | * |
| 8131 | **/ |
| 8132 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8133 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8134 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8135 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8136 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8137 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8138 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8139 | final long identity = Binder.clearCallingIdentity(); |
| 8140 | try { |
| 8141 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8142 | phone.setSimPowerState(state, null, workSource); |
| 8143 | } |
| 8144 | } finally { |
| 8145 | Binder.restoreCallingIdentity(identity); |
| 8146 | } |
| 8147 | } |
| 8148 | |
| 8149 | /** |
| 8150 | * Set SIM card power state. |
| 8151 | * |
| 8152 | * @param slotIndex SIM slot id. |
| 8153 | * @param state State of SIM (power down, power up, pass through) |
| 8154 | * @param callback callback to trigger after success or failure |
| 8155 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8156 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8157 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8158 | * |
| 8159 | **/ |
| 8160 | @Override |
| 8161 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8162 | IIntegerConsumer callback) { |
| 8163 | enforceModifyPermission(); |
| 8164 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8165 | |
| 8166 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8167 | |
| 8168 | final long identity = Binder.clearCallingIdentity(); |
| 8169 | try { |
| 8170 | if (phone != null) { |
| 8171 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8172 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8173 | } |
| 8174 | } finally { |
| 8175 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8176 | } |
| 8177 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8178 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8179 | private boolean isUssdApiAllowed(int subId) { |
| 8180 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8181 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8182 | if (configManager == null) { |
| 8183 | return false; |
| 8184 | } |
| 8185 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8186 | if (pb == null) { |
| 8187 | return false; |
| 8188 | } |
| 8189 | return pb.getBoolean( |
| 8190 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8191 | } |
| 8192 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8193 | /** |
| 8194 | * Check if phone is in emergency callback mode |
| 8195 | * @return true if phone is in emergency callback mode |
| 8196 | * @param subId sub id |
| 8197 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8198 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8199 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8200 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8201 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8202 | |
| 8203 | final long identity = Binder.clearCallingIdentity(); |
| 8204 | try { |
| 8205 | if (phone != null) { |
| 8206 | return phone.isInEcm(); |
| 8207 | } else { |
| 8208 | return false; |
| 8209 | } |
| 8210 | } finally { |
| 8211 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8212 | } |
| 8213 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8214 | |
| 8215 | /** |
| 8216 | * Get the current signal strength information for the given subscription. |
| 8217 | * Because this information is not updated when the device is in a low power state |
| 8218 | * it should not be relied-upon to be current. |
| 8219 | * @param subId Subscription index |
| 8220 | * @return the most recent cached signal strength info from the modem |
| 8221 | */ |
| 8222 | @Override |
| 8223 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8224 | final long identity = Binder.clearCallingIdentity(); |
| 8225 | try { |
| 8226 | Phone p = getPhone(subId); |
| 8227 | if (p == null) { |
| 8228 | return null; |
| 8229 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8230 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8231 | return p.getSignalStrength(); |
| 8232 | } finally { |
| 8233 | Binder.restoreCallingIdentity(identity); |
| 8234 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8235 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8236 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8237 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8238 | * Get the current modem radio state for the given slot. |
| 8239 | * @param slotIndex slot index. |
| 8240 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8241 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8242 | * @return the current radio power state from the modem |
| 8243 | */ |
| 8244 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8245 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8246 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8247 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8248 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8249 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8250 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8251 | } |
| 8252 | |
| 8253 | final long identity = Binder.clearCallingIdentity(); |
| 8254 | try { |
| 8255 | return phone.getRadioPowerState(); |
| 8256 | } finally { |
| 8257 | Binder.restoreCallingIdentity(identity); |
| 8258 | } |
| 8259 | } |
| 8260 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8261 | } |
| 8262 | |
| 8263 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8264 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8265 | * |
| 8266 | * <p>Requires one of the following permissions: |
| 8267 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 8268 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8269 | * privileges. |
| 8270 | * |
| 8271 | * @param subId subscription id |
| 8272 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8273 | * {@code false}. |
| 8274 | */ |
| 8275 | @Override |
| 8276 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8277 | try { |
| 8278 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8279 | null); |
| 8280 | } catch (Exception e) { |
| 8281 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 8282 | mApp, subId, "isDataRoamingEnabled"); |
| 8283 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8284 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8285 | boolean isEnabled = false; |
| 8286 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8287 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8288 | Phone phone = getPhone(subId); |
| 8289 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8290 | } finally { |
| 8291 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8292 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8293 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8294 | } |
| 8295 | |
| 8296 | |
| 8297 | /** |
| 8298 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8299 | * |
| 8300 | * <p> Requires permission: |
| 8301 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8302 | * privileges. |
| 8303 | * |
| 8304 | * @param subId subscription id |
| 8305 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8306 | */ |
| 8307 | @Override |
| 8308 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8309 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8310 | mApp, subId, "setDataRoamingEnabled"); |
| 8311 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8312 | final long identity = Binder.clearCallingIdentity(); |
| 8313 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8314 | Phone phone = getPhone(subId); |
| 8315 | if (phone != null) { |
| 8316 | phone.setDataRoamingEnabled(isEnabled); |
| 8317 | } |
| 8318 | } finally { |
| 8319 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8320 | } |
| 8321 | } |
| 8322 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8323 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8324 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8325 | TelephonyPermissions |
| 8326 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8327 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8328 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8329 | boolean isAllowed = true; |
| 8330 | final long identity = Binder.clearCallingIdentity(); |
| 8331 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8332 | Phone phone = getPhone(subId); |
| 8333 | if (phone != null) { |
| 8334 | isAllowed = phone.isCspPlmnEnabled(); |
| 8335 | } |
| 8336 | } finally { |
| 8337 | Binder.restoreCallingIdentity(identity); |
| 8338 | } |
| 8339 | return isAllowed; |
| 8340 | } |
| 8341 | |
| 8342 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8343 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8344 | // Verify that tha callingPackage belongs to the calling UID |
| 8345 | mApp.getSystemService(AppOpsManager.class) |
| 8346 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8347 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8348 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8349 | try { |
| 8350 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8351 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8352 | } catch (SecurityException e) { |
| 8353 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8354 | // has carrier privileges on an active UICC |
| 8355 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8356 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8357 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8358 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8359 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8360 | |
| 8361 | final long identity = Binder.clearCallingIdentity(); |
| 8362 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8363 | UiccController uiccController = UiccController.getInstance(); |
| 8364 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8365 | if (hasReadPermission) { |
| 8366 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8367 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8368 | |
| 8369 | // Remove private info if the caller doesn't have access |
| 8370 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8371 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8372 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8373 | // is available |
| 8374 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 8375 | if (card == null || card.getUiccProfile() == null) { |
| 8376 | // assume no access if the card or profile is unavailable |
| 8377 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8378 | continue; |
| 8379 | } |
| 8380 | UiccProfile profile = card.getUiccProfile(); |
| 8381 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8382 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8383 | filteredInfos.add(cardInfo); |
| 8384 | } else { |
| 8385 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8386 | } |
| 8387 | } |
| 8388 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8389 | } finally { |
| 8390 | Binder.restoreCallingIdentity(identity); |
| 8391 | } |
| 8392 | } |
| 8393 | |
| 8394 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8395 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8396 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8397 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8398 | final long identity = Binder.clearCallingIdentity(); |
| 8399 | try { |
| 8400 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8401 | if (slots == null) { |
| 8402 | Rlog.i(LOG_TAG, "slots is null."); |
| 8403 | return null; |
| 8404 | } |
| 8405 | |
| 8406 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8407 | for (int i = 0; i < slots.length; i++) { |
| 8408 | UiccSlot slot = slots[i]; |
| 8409 | if (slot == null) { |
| 8410 | continue; |
| 8411 | } |
| 8412 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8413 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8414 | UiccCard card = slot.getUiccCard(); |
| 8415 | if (card != null) { |
| 8416 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8417 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8418 | cardId = slot.getEid(); |
| 8419 | if (TextUtils.isEmpty(cardId)) { |
| 8420 | cardId = slot.getIccId(); |
| 8421 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8422 | } |
| 8423 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8424 | if (cardId != null) { |
| 8425 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8426 | // if cardId is an EID, it's all digits so this is fine |
| 8427 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8428 | } |
| 8429 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8430 | int cardState = 0; |
| 8431 | switch (slot.getCardState()) { |
| 8432 | case CARDSTATE_ABSENT: |
| 8433 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8434 | break; |
| 8435 | case CARDSTATE_PRESENT: |
| 8436 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8437 | break; |
| 8438 | case CARDSTATE_ERROR: |
| 8439 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8440 | break; |
| 8441 | case CARDSTATE_RESTRICTED: |
| 8442 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8443 | break; |
| 8444 | default: |
| 8445 | break; |
| 8446 | |
| 8447 | } |
| 8448 | |
| 8449 | infos[i] = new UiccSlotInfo( |
| 8450 | slot.isActive(), |
| 8451 | slot.isEuicc(), |
| 8452 | cardId, |
| 8453 | cardState, |
| 8454 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8455 | slot.isExtendedApduSupported(), |
| 8456 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8457 | } |
| 8458 | return infos; |
| 8459 | } finally { |
| 8460 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8461 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8462 | } |
| 8463 | |
| 8464 | @Override |
| 8465 | public boolean switchSlots(int[] physicalSlots) { |
| 8466 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8467 | |
| 8468 | final long identity = Binder.clearCallingIdentity(); |
| 8469 | try { |
| 8470 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8471 | } finally { |
| 8472 | Binder.restoreCallingIdentity(identity); |
| 8473 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8474 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8475 | |
| 8476 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8477 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8478 | final long identity = Binder.clearCallingIdentity(); |
| 8479 | try { |
| 8480 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8481 | } finally { |
| 8482 | Binder.restoreCallingIdentity(identity); |
| 8483 | } |
| 8484 | } |
| 8485 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8486 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8487 | * A test API to reload the UICC profile. |
| 8488 | * |
| 8489 | * <p>Requires that the calling app has permission |
| 8490 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8491 | * @hide |
| 8492 | */ |
| 8493 | @Override |
| 8494 | public void refreshUiccProfile(int subId) { |
| 8495 | enforceModifyPermission(); |
| 8496 | |
| 8497 | final long identity = Binder.clearCallingIdentity(); |
| 8498 | try { |
| 8499 | Phone phone = getPhone(subId); |
| 8500 | if (phone == null) { |
| 8501 | return; |
| 8502 | } |
| 8503 | UiccCard uiccCard = phone.getUiccCard(); |
| 8504 | if (uiccCard == null) { |
| 8505 | return; |
| 8506 | } |
| 8507 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8508 | if (uiccProfile == null) { |
| 8509 | return; |
| 8510 | } |
| 8511 | uiccProfile.refresh(); |
| 8512 | } finally { |
| 8513 | Binder.restoreCallingIdentity(identity); |
| 8514 | } |
| 8515 | } |
| 8516 | |
| 8517 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8518 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8519 | */ |
| 8520 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8521 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8522 | } |
| 8523 | |
| 8524 | /** |
| 8525 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8526 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8527 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8528 | */ |
| 8529 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8530 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8531 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8532 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8533 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8534 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8535 | return isDataRoamingEnabled; |
| 8536 | } |
| 8537 | |
| 8538 | /** |
| 8539 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8540 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8541 | */ |
| 8542 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8543 | List<Integer> list = TelephonyProperties.default_network(); |
| 8544 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8545 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8546 | return list.get(phoneId); |
| 8547 | } |
| 8548 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8549 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8550 | |
| 8551 | @Override |
| 8552 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8553 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8554 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8555 | |
| 8556 | final long identity = Binder.clearCallingIdentity(); |
| 8557 | try { |
| 8558 | final Phone phone = getPhone(subId); |
| 8559 | if (phone == null) { |
| 8560 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8561 | return; |
| 8562 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8563 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8564 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8565 | if (carrierPrivilegeRules == null) { |
| 8566 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8567 | } else { |
| 8568 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8569 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8570 | } finally { |
| 8571 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8572 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8573 | } |
| 8574 | |
| 8575 | @Override |
| 8576 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8577 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8578 | |
| 8579 | final long identity = Binder.clearCallingIdentity(); |
| 8580 | try { |
| 8581 | final Phone phone = getPhone(subId); |
| 8582 | if (phone == null) { |
| 8583 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8584 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8585 | } |
| 8586 | return phone.getCarrierIdListVersion(); |
| 8587 | } finally { |
| 8588 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8589 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8590 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8591 | |
| 8592 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8593 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8594 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8595 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8596 | mApp, subId, callingPackage, callingFeatureId, |
| 8597 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8598 | return -1; |
| 8599 | } |
| 8600 | |
| 8601 | final long identity = Binder.clearCallingIdentity(); |
| 8602 | try { |
| 8603 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8604 | } finally { |
| 8605 | Binder.restoreCallingIdentity(identity); |
| 8606 | } |
| 8607 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8608 | |
| 8609 | @Override |
| 8610 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8611 | TelephonyPermissions |
| 8612 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8613 | mApp, subId, "getCdmaRoamingMode"); |
| 8614 | |
| 8615 | final long identity = Binder.clearCallingIdentity(); |
| 8616 | try { |
| 8617 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8618 | } finally { |
| 8619 | Binder.restoreCallingIdentity(identity); |
| 8620 | } |
| 8621 | } |
| 8622 | |
| 8623 | @Override |
| 8624 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8625 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8626 | mApp, subId, "setCdmaRoamingMode"); |
| 8627 | |
| 8628 | final long identity = Binder.clearCallingIdentity(); |
| 8629 | try { |
| 8630 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8631 | } finally { |
| 8632 | Binder.restoreCallingIdentity(identity); |
| 8633 | } |
| 8634 | } |
| 8635 | |
| 8636 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8637 | public int getCdmaSubscriptionMode(int subId) { |
| 8638 | TelephonyPermissions |
| 8639 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8640 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8641 | |
| 8642 | final long identity = Binder.clearCallingIdentity(); |
| 8643 | try { |
| 8644 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8645 | } finally { |
| 8646 | Binder.restoreCallingIdentity(identity); |
| 8647 | } |
| 8648 | } |
| 8649 | |
| 8650 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8651 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8652 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8653 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8654 | |
| 8655 | final long identity = Binder.clearCallingIdentity(); |
| 8656 | try { |
| 8657 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8658 | } finally { |
| 8659 | Binder.restoreCallingIdentity(identity); |
| 8660 | } |
| 8661 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8662 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8663 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8664 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8665 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8666 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8667 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8668 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8669 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8670 | } |
| 8671 | final long identity = Binder.clearCallingIdentity(); |
| 8672 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8673 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8674 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8675 | if (phone.getEmergencyNumberTracker() != null |
| 8676 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8677 | emergencyNumberListInternal.put( |
| 8678 | phone.getSubId(), |
| 8679 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8680 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8681 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8682 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8683 | } finally { |
| 8684 | Binder.restoreCallingIdentity(identity); |
| 8685 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8686 | } |
| 8687 | |
| 8688 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8689 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8690 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8691 | if (!exactMatch) { |
| 8692 | TelephonyPermissions |
| 8693 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8694 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8695 | } |
| 8696 | final long identity = Binder.clearCallingIdentity(); |
| 8697 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8698 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8699 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8700 | && phone.getEmergencyNumberTracker() |
| 8701 | .isEmergencyNumber(number, exactMatch)) { |
| 8702 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8703 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8704 | } |
| 8705 | return false; |
| 8706 | } finally { |
| 8707 | Binder.restoreCallingIdentity(identity); |
| 8708 | } |
| 8709 | } |
| 8710 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8711 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 8712 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 8713 | */ |
| 8714 | @Override |
| 8715 | public void startEmergencyCallbackMode() { |
| 8716 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8717 | "startEmergencyCallbackMode"); |
| 8718 | enforceModifyPermission(); |
| 8719 | final long identity = Binder.clearCallingIdentity(); |
| 8720 | try { |
| 8721 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8722 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 8723 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 8724 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 8725 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 8726 | gsmCdmaPhone.obtainMessage( |
| 8727 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 8728 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 8729 | } |
| 8730 | } |
| 8731 | } finally { |
| 8732 | Binder.restoreCallingIdentity(identity); |
| 8733 | } |
| 8734 | } |
| 8735 | |
| 8736 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8737 | * Update emergency number list for test mode. |
| 8738 | */ |
| 8739 | @Override |
| 8740 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8741 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8742 | "updateEmergencyNumberListTestMode"); |
| 8743 | |
| 8744 | final long identity = Binder.clearCallingIdentity(); |
| 8745 | try { |
| 8746 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8747 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8748 | if (tracker != null) { |
| 8749 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8750 | } |
| 8751 | } |
| 8752 | } finally { |
| 8753 | Binder.restoreCallingIdentity(identity); |
| 8754 | } |
| 8755 | } |
| 8756 | |
| 8757 | /** |
| 8758 | * Get the full emergency number list for test mode. |
| 8759 | */ |
| 8760 | @Override |
| 8761 | public List<String> getEmergencyNumberListTestMode() { |
| 8762 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8763 | "getEmergencyNumberListTestMode"); |
| 8764 | |
| 8765 | final long identity = Binder.clearCallingIdentity(); |
| 8766 | try { |
| 8767 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8768 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8769 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8770 | if (tracker != null) { |
| 8771 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8772 | emergencyNumbers.add(num.getNumber()); |
| 8773 | } |
| 8774 | } |
| 8775 | } |
| 8776 | return new ArrayList<>(emergencyNumbers); |
| 8777 | } finally { |
| 8778 | Binder.restoreCallingIdentity(identity); |
| 8779 | } |
| 8780 | } |
| 8781 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8782 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8783 | public int getEmergencyNumberDbVersion(int subId) { |
| 8784 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8785 | |
| 8786 | final long identity = Binder.clearCallingIdentity(); |
| 8787 | try { |
| 8788 | final Phone phone = getPhone(subId); |
| 8789 | if (phone == null) { |
| 8790 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8791 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8792 | } |
| 8793 | return phone.getEmergencyNumberDbVersion(); |
| 8794 | } finally { |
| 8795 | Binder.restoreCallingIdentity(identity); |
| 8796 | } |
| 8797 | } |
| 8798 | |
| 8799 | @Override |
| 8800 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8801 | enforceModifyPermission(); |
| 8802 | |
| 8803 | final long identity = Binder.clearCallingIdentity(); |
| 8804 | try { |
| 8805 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8806 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8807 | if (tracker != null) { |
| 8808 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8809 | } |
| 8810 | } |
| 8811 | } finally { |
| 8812 | Binder.restoreCallingIdentity(identity); |
| 8813 | } |
| 8814 | } |
| 8815 | |
| 8816 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8817 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8818 | enforceActiveEmergencySessionPermission(); |
| 8819 | |
| 8820 | final long identity = Binder.clearCallingIdentity(); |
| 8821 | try { |
| 8822 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8823 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8824 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8825 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8826 | } |
| 8827 | } |
| 8828 | } finally { |
| 8829 | Binder.restoreCallingIdentity(identity); |
| 8830 | } |
| 8831 | } |
| 8832 | |
| 8833 | @Override |
| 8834 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8835 | enforceActiveEmergencySessionPermission(); |
| 8836 | |
| 8837 | final long identity = Binder.clearCallingIdentity(); |
| 8838 | try { |
| 8839 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8840 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8841 | if (tracker != null) { |
| 8842 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8843 | } |
| 8844 | } |
| 8845 | } finally { |
| 8846 | Binder.restoreCallingIdentity(identity); |
| 8847 | } |
| 8848 | } |
| 8849 | |
| 8850 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8851 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8852 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8853 | Phone phone = getPhone(subId); |
| 8854 | if (phone == null) { |
| 8855 | return null; |
| 8856 | } |
| 8857 | final long identity = Binder.clearCallingIdentity(); |
| 8858 | try { |
| 8859 | UiccProfile profile = UiccController.getInstance() |
| 8860 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8861 | if (profile != null) { |
| 8862 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8863 | } |
| 8864 | } finally { |
| 8865 | Binder.restoreCallingIdentity(identity); |
| 8866 | } |
| 8867 | return null; |
| 8868 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8869 | |
| 8870 | /** |
| 8871 | * Enable or disable a modem stack. |
| 8872 | */ |
| 8873 | @Override |
| 8874 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8875 | enforceModifyPermission(); |
| 8876 | |
| 8877 | final long identity = Binder.clearCallingIdentity(); |
| 8878 | try { |
| 8879 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8880 | if (phone == null) { |
| 8881 | return false; |
| 8882 | } else { |
| 8883 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8884 | } |
| 8885 | } finally { |
| 8886 | Binder.restoreCallingIdentity(identity); |
| 8887 | } |
| 8888 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8889 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8890 | /** |
| 8891 | * Whether a modem stack is enabled or not. |
| 8892 | */ |
| 8893 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8894 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8895 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8896 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8897 | if (phone == null) return false; |
| 8898 | |
| 8899 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8900 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8901 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8902 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8903 | } |
| 8904 | |
| 8905 | final long identity = Binder.clearCallingIdentity(); |
| 8906 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8907 | try { |
| 8908 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8909 | } catch (NoSuchElementException ex) { |
| 8910 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8911 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8912 | } finally { |
| 8913 | Binder.restoreCallingIdentity(identity); |
| 8914 | } |
| 8915 | } |
| 8916 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8917 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8918 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8919 | enforceModifyPermission(); |
| 8920 | |
| 8921 | final long identity = Binder.clearCallingIdentity(); |
| 8922 | try { |
| 8923 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8924 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8925 | .commit(); |
| 8926 | } finally { |
| 8927 | Binder.restoreCallingIdentity(identity); |
| 8928 | } |
| 8929 | } |
| 8930 | |
| 8931 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8932 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8933 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8934 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8935 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8936 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8937 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8938 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8939 | |
| 8940 | final long identity = Binder.clearCallingIdentity(); |
| 8941 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8942 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8943 | } finally { |
| 8944 | Binder.restoreCallingIdentity(identity); |
| 8945 | } |
| 8946 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8947 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8948 | @TelephonyManager.IsMultiSimSupportedResult |
| 8949 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8950 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8951 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8952 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8953 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8954 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8955 | } |
| 8956 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8957 | // supported by the modem, indicate that it is restricted. |
| 8958 | PhoneCapability staticCapability = |
| 8959 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8960 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8961 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8962 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8963 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 8964 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8965 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8966 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8967 | } |
| 8968 | // Check if support of multiple SIMs is restricted by carrier |
| 8969 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8970 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8971 | } |
| 8972 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8973 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8974 | } |
| 8975 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8976 | /** |
| 8977 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8978 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8979 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8980 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8981 | * @param numOfSims number of active sims we want to switch to |
| 8982 | */ |
| 8983 | @Override |
| 8984 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8985 | if (numOfSims == 1) { |
| 8986 | enforceModifyPermission(); |
| 8987 | } else { |
| 8988 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8989 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8990 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8991 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8992 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8993 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8994 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8995 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8996 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8997 | return; |
| 8998 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8999 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9000 | } finally { |
| 9001 | Binder.restoreCallingIdentity(identity); |
| 9002 | } |
| 9003 | } |
| 9004 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9005 | @Override |
| 9006 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9007 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9008 | Phone phone = getPhone(subId); |
| 9009 | if (phone == null) { |
| 9010 | return false; |
| 9011 | } |
| 9012 | final long identity = Binder.clearCallingIdentity(); |
| 9013 | try { |
| 9014 | UiccCard uiccCard = phone.getUiccCard(); |
| 9015 | if (uiccCard == null) { |
| 9016 | return false; |
| 9017 | } |
| 9018 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 9019 | if (uiccProfile == null) { |
| 9020 | return false; |
| 9021 | } |
| 9022 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9023 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9024 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9025 | } |
| 9026 | return false; |
| 9027 | } finally { |
| 9028 | Binder.restoreCallingIdentity(identity); |
| 9029 | } |
| 9030 | } |
| 9031 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9032 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9033 | * Get whether making changes to modem configurations will trigger reboot. |
| 9034 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9035 | */ |
| 9036 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9037 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9038 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9039 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9040 | mApp, subId, callingPackage, callingFeatureId, |
| 9041 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9042 | return false; |
| 9043 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9044 | final long identity = Binder.clearCallingIdentity(); |
| 9045 | try { |
| 9046 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9047 | } finally { |
| 9048 | Binder.restoreCallingIdentity(identity); |
| 9049 | } |
| 9050 | } |
| 9051 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9052 | private void updateModemStateMetrics() { |
| 9053 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9054 | // TODO: check the state for each modem if the api is ready. |
| 9055 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9056 | } |
| 9057 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9058 | @Override |
| 9059 | public int[] getSlotsMapping() { |
| 9060 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 9061 | |
| 9062 | final long identity = Binder.clearCallingIdentity(); |
| 9063 | try { |
| 9064 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 9065 | // All logical slots should have a mapping to a physical slot. |
| 9066 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 9067 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 9068 | for (int i = 0; i < slotInfos.length; i++) { |
| 9069 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 9070 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 9071 | } |
| 9072 | } |
| 9073 | return logicalSlotsMapping; |
| 9074 | } finally { |
| 9075 | Binder.restoreCallingIdentity(identity); |
| 9076 | } |
| 9077 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9078 | |
| 9079 | /** |
| 9080 | * Get the IRadio HAL Version |
| 9081 | */ |
| 9082 | @Override |
| 9083 | public int getRadioHalVersion() { |
| 9084 | Phone phone = getDefaultPhone(); |
| 9085 | if (phone == null) return -1; |
| 9086 | HalVersion hv = phone.getHalVersion(); |
| 9087 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9088 | return hv.major * 100 + hv.minor; |
| 9089 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9090 | |
| 9091 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9092 | * Get the current calling package name. |
| 9093 | * @return the current calling package name |
| 9094 | */ |
| 9095 | @Override |
| 9096 | public String getCurrentPackageName() { |
| 9097 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9098 | } |
| 9099 | |
| 9100 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9101 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9102 | * corresponding network requests on a subId. |
| 9103 | * |
| 9104 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9105 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9106 | * 2) APN is un-metered for this subscription, or |
| 9107 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9108 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9109 | * |
| 9110 | * @return whether data is allowed for a apn type. |
| 9111 | * |
| 9112 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9113 | */ |
| 9114 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9115 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9116 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9117 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9118 | |
| 9119 | // Now that all security checks passes, perform the operation as ourselves. |
| 9120 | final long identity = Binder.clearCallingIdentity(); |
| 9121 | try { |
| 9122 | Phone phone = getPhone(subId); |
| 9123 | if (phone == null) return false; |
| 9124 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9125 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9126 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 9127 | } finally { |
| 9128 | Binder.restoreCallingIdentity(identity); |
| 9129 | } |
| 9130 | } |
| 9131 | |
| 9132 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9133 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9134 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9135 | |
| 9136 | // Now that all security checks passes, perform the operation as ourselves. |
| 9137 | final long identity = Binder.clearCallingIdentity(); |
| 9138 | try { |
| 9139 | Phone phone = getPhone(subId); |
| 9140 | if (phone == null) return true; // By default return true. |
| 9141 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9142 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9143 | } finally { |
| 9144 | Binder.restoreCallingIdentity(identity); |
| 9145 | } |
| 9146 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9147 | |
| 9148 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9149 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9150 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9151 | enforceModifyPermission(); |
| 9152 | long token = Binder.clearCallingIdentity(); |
| 9153 | try { |
| 9154 | Phone phone = getPhone(subscriptionId); |
| 9155 | if (phone == null) { |
| 9156 | try { |
| 9157 | if (resultCallback != null) { |
| 9158 | resultCallback.accept(false); |
| 9159 | } |
| 9160 | } catch (RemoteException e) { |
| 9161 | // ignore |
| 9162 | } |
| 9163 | return; |
| 9164 | } |
| 9165 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9166 | Pair.create(specifiers, (x) -> { |
| 9167 | try { |
| 9168 | if (resultCallback != null) { |
| 9169 | resultCallback.accept(x); |
| 9170 | } |
| 9171 | } catch (RemoteException e) { |
| 9172 | // ignore |
| 9173 | } |
| 9174 | }); |
| 9175 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9176 | } finally { |
| 9177 | Binder.restoreCallingIdentity(token); |
| 9178 | } |
| 9179 | } |
| 9180 | |
| 9181 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9182 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9183 | TelephonyPermissions |
| 9184 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 9185 | mApp, subId, "getSystemSelectionChannels"); |
| 9186 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9187 | final long identity = Binder.clearCallingIdentity(); |
| 9188 | try { |
| 9189 | List<RadioAccessSpecifier> specifiers = |
| 9190 | (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, |
| 9191 | null, subId, workSource); |
| 9192 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9193 | return specifiers; |
| 9194 | } finally { |
| 9195 | Binder.restoreCallingIdentity(identity); |
| 9196 | } |
| 9197 | } |
| 9198 | |
| 9199 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9200 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9201 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9202 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9203 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9204 | if (iccRecords == null) { |
| 9205 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9206 | return false; |
| 9207 | } |
| 9208 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9209 | } |
| 9210 | |
| 9211 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9212 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9213 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9214 | if (callingPackage == null) { |
| 9215 | callingPackage = getCurrentPackageName(); |
| 9216 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9217 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9218 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9219 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9220 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9221 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9222 | } |
| 9223 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9224 | Intent intent = new Intent(); |
| 9225 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9226 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9227 | // Bring up choose default SMS subscription dialog right now |
| 9228 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9229 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9230 | mApp.startActivity(intent); |
| 9231 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9232 | |
| 9233 | @Override |
| 9234 | public String getMmsUAProfUrl(int subId) { |
| 9235 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9236 | final long identity = Binder.clearCallingIdentity(); |
| 9237 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9238 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9239 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9240 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9241 | return carrierUAProfUrl; |
| 9242 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9243 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9244 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9245 | } finally { |
| 9246 | Binder.restoreCallingIdentity(identity); |
| 9247 | } |
| 9248 | } |
| 9249 | |
| 9250 | @Override |
| 9251 | public String getMmsUserAgent(int subId) { |
| 9252 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9253 | final long identity = Binder.clearCallingIdentity(); |
| 9254 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9255 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9256 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9257 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9258 | return carrierUserAgent; |
| 9259 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9260 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9261 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9262 | } finally { |
| 9263 | Binder.restoreCallingIdentity(identity); |
| 9264 | } |
| 9265 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9266 | |
| 9267 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9268 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9269 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9270 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9271 | final long identity = Binder.clearCallingIdentity(); |
| 9272 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9273 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9274 | if (phone == null) return false; |
| 9275 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9276 | switch (policy) { |
| 9277 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9278 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9279 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9280 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9281 | default: |
| 9282 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9283 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9284 | } finally { |
| 9285 | Binder.restoreCallingIdentity(identity); |
| 9286 | } |
| 9287 | } |
| 9288 | |
| 9289 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 9290 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9291 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9292 | enforceModifyPermission(); |
| 9293 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9294 | final long identity = Binder.clearCallingIdentity(); |
| 9295 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9296 | Phone phone = getPhone(subscriptionId); |
| 9297 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9298 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9299 | switch (policy) { |
| 9300 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9301 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9302 | break; |
| 9303 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9304 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9305 | break; |
| 9306 | default: |
| 9307 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9308 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9309 | } finally { |
| 9310 | Binder.restoreCallingIdentity(identity); |
| 9311 | } |
| 9312 | } |
| 9313 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9314 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9315 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9316 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9317 | * otherwise. |
| 9318 | */ |
| 9319 | @Override |
| 9320 | public void setCepEnabled(boolean isCepEnabled) { |
| 9321 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9322 | |
| 9323 | final long identity = Binder.clearCallingIdentity(); |
| 9324 | try { |
| 9325 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9326 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9327 | Phone defaultPhone = phone.getImsPhone(); |
| 9328 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9329 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9330 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9331 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9332 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9333 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9334 | + imsPhone.getMsisdn()); |
| 9335 | } |
| 9336 | } |
| 9337 | } finally { |
| 9338 | Binder.restoreCallingIdentity(identity); |
| 9339 | } |
| 9340 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9341 | |
| 9342 | /** |
| 9343 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9344 | * |
| 9345 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9346 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9347 | * before being read. |
| 9348 | */ |
| 9349 | @Override |
| 9350 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9351 | isCompressed) { |
| 9352 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9353 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9354 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9355 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9356 | } |
| 9357 | if (!isImsAvailableOnDevice()) { |
| 9358 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9359 | "IMS not available on device."); |
| 9360 | } |
| 9361 | |
| 9362 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9363 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9364 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9365 | } finally { |
| 9366 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9367 | } |
| 9368 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9369 | |
| 9370 | @Override |
| 9371 | public boolean isIccLockEnabled(int subId) { |
| 9372 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9373 | |
| 9374 | // Now that all security checks passes, perform the operation as ourselves. |
| 9375 | final long identity = Binder.clearCallingIdentity(); |
| 9376 | try { |
| 9377 | Phone phone = getPhone(subId); |
| 9378 | if (phone != null && phone.getIccCard() != null) { |
| 9379 | return phone.getIccCard().getIccLockEnabled(); |
| 9380 | } else { |
| 9381 | return false; |
| 9382 | } |
| 9383 | } finally { |
| 9384 | Binder.restoreCallingIdentity(identity); |
| 9385 | } |
| 9386 | } |
| 9387 | |
| 9388 | /** |
| 9389 | * Set the ICC pin lock enabled or disabled. |
| 9390 | * |
| 9391 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9392 | * three cases: |
| 9393 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9394 | * successfully. |
| 9395 | * - Positive number and zero for remaining password attempts. |
| 9396 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9397 | * |
| 9398 | */ |
| 9399 | @Override |
| 9400 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9401 | enforceModifyPermission(); |
| 9402 | |
| 9403 | Phone phone = getPhone(subId); |
| 9404 | if (phone == null) { |
| 9405 | return 0; |
| 9406 | } |
| 9407 | // Now that all security checks passes, perform the operation as ourselves. |
| 9408 | final long identity = Binder.clearCallingIdentity(); |
| 9409 | try { |
| 9410 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9411 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9412 | return attemptsRemaining; |
| 9413 | |
| 9414 | } catch (Exception e) { |
| 9415 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9416 | } finally { |
| 9417 | Binder.restoreCallingIdentity(identity); |
| 9418 | } |
| 9419 | return 0; |
| 9420 | } |
| 9421 | |
| 9422 | /** |
| 9423 | * Change the ICC password used in ICC pin lock. |
| 9424 | * |
| 9425 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9426 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9427 | * - Positive number and zero for remaining password attempts. |
| 9428 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9429 | * |
| 9430 | */ |
| 9431 | @Override |
| 9432 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9433 | enforceModifyPermission(); |
| 9434 | |
| 9435 | Phone phone = getPhone(subId); |
| 9436 | if (phone == null) { |
| 9437 | return 0; |
| 9438 | } |
| 9439 | // Now that all security checks passes, perform the operation as ourselves. |
| 9440 | final long identity = Binder.clearCallingIdentity(); |
| 9441 | try { |
| 9442 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9443 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9444 | return attemptsRemaining; |
| 9445 | |
| 9446 | } catch (Exception e) { |
| 9447 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9448 | } finally { |
| 9449 | Binder.restoreCallingIdentity(identity); |
| 9450 | } |
| 9451 | return 0; |
| 9452 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9453 | |
| 9454 | /** |
| 9455 | * Request for receiving user activity notification |
| 9456 | */ |
| 9457 | @Override |
| 9458 | public void requestUserActivityNotification() { |
| 9459 | if (!mNotifyUserActivity.get() |
| 9460 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9461 | mNotifyUserActivity.set(true); |
| 9462 | } |
| 9463 | } |
| 9464 | |
| 9465 | /** |
| 9466 | * Called when userActivity is signalled in the power manager. |
| 9467 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9468 | */ |
| 9469 | @Override |
| 9470 | public void userActivity() { |
| 9471 | // *************************************** |
| 9472 | // * Inherited from PhoneWindowManager * |
| 9473 | // *************************************** |
| 9474 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9475 | // WITH ITS LOCKS HELD. |
| 9476 | // |
| 9477 | // This code must be VERY careful about the locks |
| 9478 | // it acquires. |
| 9479 | // In fact, the current code acquires way too many, |
| 9480 | // and probably has lurking deadlocks. |
| 9481 | |
| 9482 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9483 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9484 | } |
| 9485 | |
| 9486 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9487 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9488 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9489 | } |
| 9490 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9491 | |
| 9492 | @Override |
| 9493 | public boolean canConnectTo5GInDsdsMode() { |
| 9494 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9495 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9496 | |
| 9497 | @Override |
| 9498 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9499 | String callingFeatureId) { |
| 9500 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9501 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9502 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9503 | } |
| 9504 | |
| 9505 | Phone phone = getPhone(subId); |
| 9506 | if (phone == null) { |
| 9507 | throw new RuntimeException("phone is not available"); |
| 9508 | } |
| 9509 | // Now that all security checks passes, perform the operation as ourselves. |
| 9510 | final long identity = Binder.clearCallingIdentity(); |
| 9511 | try { |
| 9512 | return phone.getEquivalentHomePlmns(); |
| 9513 | } finally { |
| 9514 | Binder.restoreCallingIdentity(identity); |
| 9515 | } |
| 9516 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9517 | |
| 9518 | @Override |
| 9519 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 9520 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 9521 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 9522 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9523 | if (radioInterfaceCapabilities == null) { |
| 9524 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9525 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 9526 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9527 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9528 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9529 | @Override |
| 9530 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 9531 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9532 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 9533 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9534 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 9535 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9536 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9537 | if (DBG) { |
| 9538 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 9539 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 9540 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 9541 | } |
| 9542 | |
| 9543 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 9544 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 9545 | || appType > TelephonyManager.APPTYPE_ISIM |
| 9546 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 9547 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 9548 | if (callback != null) { |
| 9549 | try { |
| 9550 | callback.onAuthenticationFailure( |
| 9551 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 9552 | } catch (RemoteException exception) { |
| 9553 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 9554 | } |
| 9555 | return; |
| 9556 | } |
| 9557 | } |
| 9558 | |
| 9559 | final long token = Binder.clearCallingIdentity(); |
| 9560 | try { |
| 9561 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 9562 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 9563 | forceBootStrapping, callback)); |
| 9564 | } finally { |
| 9565 | Binder.restoreCallingIdentity(token); |
| 9566 | } |
| 9567 | } |
| 9568 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9569 | /** |
| 9570 | * Attempts to set the radio power state for thermal reason. This does not guarantee that the |
| 9571 | * requested radio power state will actually be set. See {@link |
| 9572 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9573 | * |
| 9574 | * @param subId the subscription ID of the phone requesting to set the radio power state. |
| 9575 | * @param enable {@code true} if trying to turn radio on. |
| 9576 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9577 | * false}. |
| 9578 | */ |
| 9579 | private boolean setRadioPowerForThermal(int subId, boolean enable) { |
| 9580 | Phone phone = getPhone(subId); |
| 9581 | if (phone != null) { |
| 9582 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 9583 | return true; |
| 9584 | } |
| 9585 | return false; |
| 9586 | } |
| 9587 | |
| 9588 | private int handleDataThrottlingRequest(int subId, |
| 9589 | DataThrottlingRequest dataThrottlingRequest) { |
| 9590 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 9591 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9592 | if (!setRadioPowerForThermal(subId, true)) { |
| 9593 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9594 | } |
| 9595 | |
| 9596 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 9597 | |
| 9598 | int thermalMitigationResult = |
| 9599 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
| 9600 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 9601 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 9602 | } |
| 9603 | return thermalMitigationResult; |
| 9604 | } |
| 9605 | |
| 9606 | /** |
| 9607 | * Thermal mitigation request to control functionalities at modem. |
| 9608 | * |
| 9609 | * @param subId the id of the subscription. |
| 9610 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
| 9611 | * |
| 9612 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 9613 | */ |
| 9614 | @Override |
| 9615 | @ThermalMitigationResult |
| 9616 | public int sendThermalMitigationRequest( |
| 9617 | int subId, |
| 9618 | ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException { |
| 9619 | enforceModifyPermission(); |
| 9620 | |
| 9621 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9622 | final long identity = Binder.clearCallingIdentity(); |
| 9623 | |
| 9624 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 9625 | try { |
| 9626 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 9627 | switch (thermalMitigationAction) { |
| 9628 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 9629 | thermalMitigationResult = |
| 9630 | handleDataThrottlingRequest(subId, |
| 9631 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 9632 | break; |
| 9633 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 9634 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9635 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 9636 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 9637 | } |
| 9638 | |
| 9639 | // Ensure that radio is on. If not able to power on due to phone being |
| 9640 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9641 | if (!setRadioPowerForThermal(subId, true)) { |
| 9642 | thermalMitigationResult = |
| 9643 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9644 | break; |
| 9645 | } |
| 9646 | |
| 9647 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 9648 | false); |
| 9649 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9650 | break; |
| 9651 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 9652 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9653 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 9654 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 9655 | } |
| 9656 | |
| 9657 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 9658 | if (registry != null) { |
| 9659 | TelephonyConnectionService service = |
| 9660 | registry.getTelephonyConnectionService(); |
| 9661 | Phone phone = getPhone(subId); |
| 9662 | if (phone == null) { |
| 9663 | thermalMitigationResult = |
| 9664 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9665 | break; |
| 9666 | } |
| 9667 | |
| 9668 | if (PhoneConstantConversions.convertCallState(phone.getState()) |
| 9669 | != TelephonyManager.CALL_STATE_IDLE |
| 9670 | || phone.isInEmergencySmsMode() || phone.isInEcm() |
| 9671 | || (service != null && service.isEmergencyCallPending())) { |
| 9672 | String errorMessage = "Phone state is not valid. call state = " |
| 9673 | + PhoneConstantConversions.convertCallState(phone.getState()) |
| 9674 | + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode() |
| 9675 | + " isInEmergencyCallbackMode = " + phone.isInEcm(); |
| 9676 | errorMessage += service == null |
| 9677 | ? " TelephonyConnectionService is null" |
| 9678 | : " isEmergencyCallPending = " |
| 9679 | + service.isEmergencyCallPending(); |
| 9680 | Log.e(LOG_TAG, errorMessage); |
| 9681 | thermalMitigationResult = |
| 9682 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 9683 | break; |
| 9684 | } |
| 9685 | } else { |
| 9686 | thermalMitigationResult = |
| 9687 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9688 | break; |
| 9689 | } |
| 9690 | |
| 9691 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 9692 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9693 | if (!setRadioPowerForThermal(subId, false)) { |
| 9694 | thermalMitigationResult = |
| 9695 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9696 | break; |
| 9697 | } |
| 9698 | thermalMitigationResult = |
| 9699 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9700 | break; |
| 9701 | default: |
| 9702 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 9703 | + "not exist. Requested action: " + thermalMitigationAction); |
| 9704 | } |
| 9705 | } catch (IllegalArgumentException e) { |
| 9706 | throw e; |
| 9707 | } catch (Exception e) { |
| 9708 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 9709 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 9710 | } finally { |
| 9711 | Binder.restoreCallingIdentity(identity); |
| 9712 | } |
| 9713 | |
| 9714 | if (DBG) { |
| 9715 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 9716 | + thermalMitigationResult); |
| 9717 | } |
| 9718 | |
| 9719 | return thermalMitigationResult; |
| 9720 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9721 | |
| 9722 | /** |
| 9723 | * Set the GbaService Package Name that Telephony will bind to. |
| 9724 | * |
| 9725 | * @param subId The sim that the GbaService is associated with. |
| 9726 | * @param packageName The name of the package to be replaced with. |
| 9727 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9728 | */ |
| 9729 | @Override |
| 9730 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 9731 | enforceModifyPermission(); |
| 9732 | |
| 9733 | final long identity = Binder.clearCallingIdentity(); |
| 9734 | try { |
| 9735 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 9736 | } finally { |
| 9737 | Binder.restoreCallingIdentity(identity); |
| 9738 | } |
| 9739 | } |
| 9740 | |
| 9741 | /** |
| 9742 | * Return the package name of the currently bound GbaService. |
| 9743 | * |
| 9744 | * @param subId The sim that the GbaService is associated with. |
| 9745 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 9746 | */ |
| 9747 | @Override |
| 9748 | public String getBoundGbaService(int subId) { |
| 9749 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 9750 | |
| 9751 | final long identity = Binder.clearCallingIdentity(); |
| 9752 | try { |
| 9753 | return getGbaManager(subId).getServicePackage(); |
| 9754 | } finally { |
| 9755 | Binder.restoreCallingIdentity(identity); |
| 9756 | } |
| 9757 | } |
| 9758 | |
| 9759 | /** |
| 9760 | * Set the release time for telephony to unbind GbaService. |
| 9761 | * |
| 9762 | * @param subId The sim that the GbaService is associated with. |
| 9763 | * @param interval The release time to unbind GbaService by millisecond. |
| 9764 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9765 | */ |
| 9766 | @Override |
| 9767 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 9768 | enforceModifyPermission(); |
| 9769 | |
| 9770 | final long identity = Binder.clearCallingIdentity(); |
| 9771 | try { |
| 9772 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 9773 | } finally { |
| 9774 | Binder.restoreCallingIdentity(identity); |
| 9775 | } |
| 9776 | } |
| 9777 | |
| 9778 | /** |
| 9779 | * Return the release time for telephony to unbind GbaService. |
| 9780 | * |
| 9781 | * @param subId The sim that the GbaService is associated with. |
| 9782 | * @return The release time to unbind GbaService by millisecond. |
| 9783 | */ |
| 9784 | @Override |
| 9785 | public int getGbaReleaseTime(int subId) { |
| 9786 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 9787 | |
| 9788 | final long identity = Binder.clearCallingIdentity(); |
| 9789 | try { |
| 9790 | return getGbaManager(subId).getReleaseTime(); |
| 9791 | } finally { |
| 9792 | Binder.restoreCallingIdentity(identity); |
| 9793 | } |
| 9794 | } |
| 9795 | |
| 9796 | private GbaManager getGbaManager(int subId) { |
| 9797 | GbaManager instance = GbaManager.getInstance(subId); |
| 9798 | if (instance == null) { |
| 9799 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 9800 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 9801 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 9802 | } |
| 9803 | return instance; |
| 9804 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9805 | |
| 9806 | /** |
| 9807 | * indicate whether the device and the carrier can support |
| 9808 | * RCS VoLTE single registration. |
| 9809 | */ |
| 9810 | @Override |
| 9811 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9812 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9813 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 9814 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9815 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9816 | |
| 9817 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9818 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9819 | } |
| 9820 | |
| 9821 | final long identity = Binder.clearCallingIdentity(); |
| 9822 | try { |
| 9823 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 9824 | if (rpm != null) { |
| 9825 | return rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 9826 | } |
| 9827 | return false; |
| 9828 | } finally { |
| 9829 | Binder.restoreCallingIdentity(identity); |
| 9830 | } |
| 9831 | } |
| 9832 | |
| 9833 | /** |
| 9834 | * Register RCS provisioning callback. |
| 9835 | */ |
| 9836 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9837 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9838 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9839 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9840 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9841 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9842 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9843 | |
| 9844 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9845 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9846 | } |
| 9847 | if (!isImsAvailableOnDevice()) { |
| 9848 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9849 | "IMS not available on device."); |
| 9850 | } |
| 9851 | |
| 9852 | final long identity = Binder.clearCallingIdentity(); |
| 9853 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9854 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9855 | .registerRcsProvisioningCallback(subId, callback)) { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9856 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9857 | "Service not available for the subscription."); |
| 9858 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9859 | } finally { |
| 9860 | Binder.restoreCallingIdentity(identity); |
| 9861 | } |
| 9862 | } |
| 9863 | |
| 9864 | /** |
| 9865 | * Unregister RCS provisioning callback. |
| 9866 | */ |
| 9867 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9868 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9869 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9870 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9871 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9872 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9873 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9874 | |
| 9875 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9876 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9877 | } |
| 9878 | if (!isImsAvailableOnDevice()) { |
| 9879 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9880 | "IMS not available on device."); |
| 9881 | } |
| 9882 | |
| 9883 | final long identity = Binder.clearCallingIdentity(); |
| 9884 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9885 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9886 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9887 | } finally { |
| 9888 | Binder.restoreCallingIdentity(identity); |
| 9889 | } |
| 9890 | } |
| 9891 | |
| 9892 | /** |
| 9893 | * trigger RCS reconfiguration. |
| 9894 | */ |
| 9895 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9896 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 9897 | "triggerRcsReconfiguration", |
| 9898 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9899 | |
| 9900 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9901 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9902 | } |
| 9903 | if (!isImsAvailableOnDevice()) { |
| 9904 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9905 | "IMS not available on device."); |
| 9906 | } |
| 9907 | |
| 9908 | final long identity = Binder.clearCallingIdentity(); |
| 9909 | try { |
| 9910 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 9911 | } finally { |
| 9912 | Binder.restoreCallingIdentity(identity); |
| 9913 | } |
| 9914 | } |
| 9915 | |
| 9916 | /** |
| 9917 | * Provide the client configuration parameters of the RCS application. |
| 9918 | */ |
| 9919 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9920 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 9921 | "setRcsClientConfiguration", |
| 9922 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9923 | |
| 9924 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9925 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9926 | } |
| 9927 | if (!isImsAvailableOnDevice()) { |
| 9928 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9929 | "IMS not available on device."); |
| 9930 | } |
| 9931 | |
| 9932 | final long identity = Binder.clearCallingIdentity(); |
| 9933 | |
| 9934 | try { |
| 9935 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 9936 | if (configBinder == null) { |
| 9937 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
| 9938 | } else { |
| 9939 | configBinder.setRcsClientConfiguration(rcc); |
| 9940 | } |
| 9941 | } catch (RemoteException e) { |
| 9942 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
| 9943 | } finally { |
| 9944 | Binder.restoreCallingIdentity(identity); |
| 9945 | } |
| 9946 | } |
| 9947 | |
| 9948 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 9949 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 9950 | */ |
| 9951 | @Override |
| 9952 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 9953 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9954 | "setRcsSingleRegistrationTestModeEnabled"); |
| 9955 | |
| 9956 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 9957 | } |
| 9958 | |
| 9959 | /** |
| 9960 | * Gets the test mode for RCS VoLTE single registration. |
| 9961 | */ |
| 9962 | @Override |
| 9963 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 9964 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9965 | "getRcsSingleRegistrationTestModeEnabled"); |
| 9966 | |
| 9967 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 9968 | } |
| 9969 | |
| 9970 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9971 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 9972 | */ |
| 9973 | @Override |
| 9974 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 9975 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9976 | "setDeviceSingleRegistrationEnabledOverride"); |
| 9977 | enforceModifyPermission(); |
| 9978 | |
| 9979 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9980 | : Boolean.parseBoolean(enabledStr); |
| 9981 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 9982 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9983 | } |
| 9984 | |
| 9985 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 9986 | * Sends a device to device communication message. Only usable via shell. |
| 9987 | * @param message message to send. |
| 9988 | * @param value message value. |
| 9989 | */ |
| 9990 | @Override |
| 9991 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 9992 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 9993 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 9994 | enforceModifyPermission(); |
| 9995 | |
| 9996 | final long identity = Binder.clearCallingIdentity(); |
| 9997 | try { |
| 9998 | TelephonyConnectionService service = |
| 9999 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10000 | if (service == null) { |
| 10001 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10002 | return; |
| 10003 | } |
| 10004 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10005 | } finally { |
| 10006 | Binder.restoreCallingIdentity(identity); |
| 10007 | } |
| 10008 | } |
| 10009 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10010 | /** |
| 10011 | * Sets the specified device to device transport active. |
| 10012 | * @param transport The transport to set active. |
| 10013 | */ |
| 10014 | @Override |
| 10015 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10016 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10017 | "setActiveDeviceToDeviceTransport"); |
| 10018 | enforceModifyPermission(); |
| 10019 | |
| 10020 | final long identity = Binder.clearCallingIdentity(); |
| 10021 | try { |
| 10022 | TelephonyConnectionService service = |
| 10023 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10024 | if (service == null) { |
| 10025 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10026 | return; |
| 10027 | } |
| 10028 | service.setActiveDeviceToDeviceTransport(transport); |
| 10029 | } finally { |
| 10030 | Binder.restoreCallingIdentity(identity); |
| 10031 | } |
| 10032 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10033 | |
| 10034 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10035 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10036 | */ |
| 10037 | @Override |
| 10038 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10039 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10040 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10041 | } |
| 10042 | |
| 10043 | /** |
| 10044 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10045 | */ |
| 10046 | @Override |
| 10047 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10048 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10049 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10050 | enforceModifyPermission(); |
| 10051 | |
| 10052 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10053 | : Boolean.parseBoolean(enabledStr); |
| 10054 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10055 | subId, enabled); |
| 10056 | } |
| 10057 | |
| 10058 | /** |
| 10059 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10060 | */ |
| 10061 | @Override |
| 10062 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10063 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 10064 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 10065 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10066 | |
| 10067 | /** |
| 10068 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 10069 | * their mobile plan. |
| 10070 | */ |
| 10071 | @Override |
| 10072 | public String getMobileProvisioningUrl() { |
| 10073 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 10074 | final long identity = Binder.clearCallingIdentity(); |
| 10075 | try { |
| 10076 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 10077 | } finally { |
| 10078 | Binder.restoreCallingIdentity(identity); |
| 10079 | } |
| 10080 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10081 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10082 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 10083 | * Get the EAB contact from the EAB database. |
| 10084 | */ |
| 10085 | @Override |
| 10086 | public String getContactFromEab(String contact) { |
| 10087 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 10088 | enforceModifyPermission(); |
| 10089 | final long identity = Binder.clearCallingIdentity(); |
| 10090 | try { |
| 10091 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 10092 | } finally { |
| 10093 | Binder.restoreCallingIdentity(identity); |
| 10094 | } |
| 10095 | } |
| 10096 | |
| 10097 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10098 | * Remove the EAB contacts from the EAB database. |
| 10099 | */ |
| 10100 | @Override |
| 10101 | public int removeContactFromEab(int subId, String contacts) { |
| 10102 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 10103 | enforceModifyPermission(); |
| 10104 | final long identity = Binder.clearCallingIdentity(); |
| 10105 | try { |
| 10106 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 10107 | } finally { |
| 10108 | Binder.restoreCallingIdentity(identity); |
| 10109 | } |
| 10110 | } |
| 10111 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10112 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10113 | public boolean getDeviceUceEnabled() { |
| 10114 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 10115 | final long identity = Binder.clearCallingIdentity(); |
| 10116 | try { |
| 10117 | return mApp.getDeviceUceEnabled(); |
| 10118 | } finally { |
| 10119 | Binder.restoreCallingIdentity(identity); |
| 10120 | } |
| 10121 | } |
| 10122 | |
| 10123 | @Override |
| 10124 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 10125 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 10126 | final long identity = Binder.clearCallingIdentity(); |
| 10127 | try { |
| 10128 | mApp.setDeviceUceEnabled(isEnabled); |
| 10129 | } finally { |
| 10130 | Binder.restoreCallingIdentity(identity); |
| 10131 | } |
| 10132 | } |
| 10133 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame^] | 10134 | /** |
| 10135 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10136 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10137 | */ |
| 10138 | // Used for SHELL command only right now. |
| 10139 | @Override |
| 10140 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 10141 | List<String> featureTags) { |
| 10142 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10143 | "addUceRegistrationOverrideShell"); |
| 10144 | final long identity = Binder.clearCallingIdentity(); |
| 10145 | try { |
| 10146 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 10147 | new ArraySet<>(featureTags)); |
| 10148 | } catch (ImsException e) { |
| 10149 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10150 | } finally { |
| 10151 | Binder.restoreCallingIdentity(identity); |
| 10152 | } |
| 10153 | } |
| 10154 | |
| 10155 | /** |
| 10156 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10157 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10158 | */ |
| 10159 | // Used for SHELL command only right now. |
| 10160 | @Override |
| 10161 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 10162 | List<String> featureTags) { |
| 10163 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10164 | "removeUceRegistrationOverrideShell"); |
| 10165 | final long identity = Binder.clearCallingIdentity(); |
| 10166 | try { |
| 10167 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 10168 | new ArraySet<>(featureTags)); |
| 10169 | } catch (ImsException e) { |
| 10170 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10171 | } finally { |
| 10172 | Binder.restoreCallingIdentity(identity); |
| 10173 | } |
| 10174 | } |
| 10175 | |
| 10176 | /** |
| 10177 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 10178 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10179 | */ |
| 10180 | // Used for SHELL command only right now. |
| 10181 | @Override |
| 10182 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 10183 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10184 | "clearUceRegistrationOverrideShell"); |
| 10185 | final long identity = Binder.clearCallingIdentity(); |
| 10186 | try { |
| 10187 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 10188 | } catch (ImsException e) { |
| 10189 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10190 | } finally { |
| 10191 | Binder.restoreCallingIdentity(identity); |
| 10192 | } |
| 10193 | } |
| 10194 | |
| 10195 | /** |
| 10196 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10197 | */ |
| 10198 | // Used for SHELL command only right now. |
| 10199 | @Override |
| 10200 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 10201 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10202 | "getLatestRcsContactUceCapabilityShell"); |
| 10203 | final long identity = Binder.clearCallingIdentity(); |
| 10204 | try { |
| 10205 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 10206 | } catch (ImsException e) { |
| 10207 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10208 | } finally { |
| 10209 | Binder.restoreCallingIdentity(identity); |
| 10210 | } |
| 10211 | } |
| 10212 | |
| 10213 | /** |
| 10214 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 10215 | * device does not have an active PUBLISH. |
| 10216 | */ |
| 10217 | // Used for SHELL command only right now. |
| 10218 | @Override |
| 10219 | public String getLastUcePidfXmlShell(int subId) { |
| 10220 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 10221 | final long identity = Binder.clearCallingIdentity(); |
| 10222 | try { |
| 10223 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 10224 | } catch (ImsException e) { |
| 10225 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10226 | } finally { |
| 10227 | Binder.restoreCallingIdentity(identity); |
| 10228 | } |
| 10229 | } |
| 10230 | |
| 10231 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10232 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10233 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10234 | String callingPackage) { |
| 10235 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10236 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 10237 | |
| 10238 | final int callingUid = Binder.getCallingUid(); |
| 10239 | // Verify that tha callingPackage belongs to the calling UID |
| 10240 | mApp.getSystemService(AppOpsManager.class) |
| 10241 | .checkPackage(callingUid, callingPackage); |
| 10242 | |
| 10243 | validateSignalStrengthUpdateRequest(request, callingUid); |
| 10244 | |
| 10245 | final long identity = Binder.clearCallingIdentity(); |
| 10246 | try { |
| 10247 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10248 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10249 | |
| 10250 | if (result instanceof IllegalStateException) { |
| 10251 | throw (IllegalStateException) result; |
| 10252 | } |
| 10253 | } finally { |
| 10254 | Binder.restoreCallingIdentity(identity); |
| 10255 | } |
| 10256 | } |
| 10257 | |
| 10258 | @Override |
| 10259 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10260 | String callingPackage) { |
| 10261 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10262 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 10263 | |
| 10264 | final int callingUid = Binder.getCallingUid(); |
| 10265 | // Verify that tha callingPackage belongs to the calling UID |
| 10266 | mApp.getSystemService(AppOpsManager.class) |
| 10267 | .checkPackage(callingUid, callingPackage); |
| 10268 | |
| 10269 | final long identity = Binder.clearCallingIdentity(); |
| 10270 | try { |
| 10271 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10272 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10273 | |
| 10274 | if (result instanceof IllegalStateException) { |
| 10275 | throw (IllegalStateException) result; |
| 10276 | } |
| 10277 | } finally { |
| 10278 | Binder.restoreCallingIdentity(identity); |
| 10279 | } |
| 10280 | } |
| 10281 | |
| 10282 | private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request, |
| 10283 | int callingUid) { |
| 10284 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 10285 | // phone/system process do not have further restriction on request |
| 10286 | return; |
| 10287 | } |
| 10288 | |
| 10289 | // Applications has restrictions on how to use the request: |
| 10290 | // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle |
| 10291 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
| 10292 | // This is not system caller which has been checked above |
| 10293 | throw new IllegalArgumentException( |
| 10294 | "Only system can set isSystemThresholdReportingRequestedWhileIdle"); |
| 10295 | } |
| 10296 | |
| 10297 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 10298 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 10299 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 10300 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 10301 | || info.isEnabled()) { |
| 10302 | throw new IllegalArgumentException( |
| 10303 | "Only system can set hide fields in SignalThresholdInfo"); |
| 10304 | } |
| 10305 | |
| 10306 | // Thresholds length for each RAN need in range. This has been validated in |
| 10307 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 10308 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 10309 | final int[] thresholds = info.getThresholds(); |
| 10310 | Objects.requireNonNull(thresholds); |
| 10311 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 10312 | || thresholds.length |
| 10313 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 10314 | throw new IllegalArgumentException( |
| 10315 | "thresholds length is out of range: " + thresholds.length); |
| 10316 | } |
| 10317 | } |
| 10318 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10319 | |
| 10320 | /** |
| 10321 | * Gets the current phone capability. |
| 10322 | * |
| 10323 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 10324 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 10325 | * It's used to evaluate possible phone config change, for example from single |
| 10326 | * SIM device to multi-SIM device. |
| 10327 | */ |
| 10328 | @Override |
| 10329 | public PhoneCapability getPhoneCapability() { |
| 10330 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 10331 | final long identity = Binder.clearCallingIdentity(); |
| 10332 | try { |
| 10333 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 10334 | } finally { |
| 10335 | Binder.restoreCallingIdentity(identity); |
| 10336 | } |
| 10337 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 10338 | |
| 10339 | /** |
| 10340 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 10341 | * required to be done shortly after the API is invoked. |
| 10342 | */ |
| 10343 | @Override |
| 10344 | @TelephonyManager.PrepareUnattendedRebootResult |
| 10345 | public int prepareForUnattendedReboot() { |
| 10346 | enforceRebootPermission(); |
| 10347 | |
| 10348 | final long identity = Binder.clearCallingIdentity(); |
| 10349 | try { |
| 10350 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null); |
| 10351 | } finally { |
| 10352 | Binder.restoreCallingIdentity(identity); |
| 10353 | } |
| 10354 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 10355 | } |