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; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 73 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 74 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 75 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 76 | import android.telephony.CellIdentityCdma; |
| 77 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 78 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 79 | import android.telephony.CellInfoGsm; |
| 80 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 81 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 82 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 83 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 84 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 85 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 86 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 87 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 88 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 89 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 90 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 91 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 92 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 93 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 94 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 95 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 96 | import android.telephony.SignalStrengthUpdateRequest; |
| 97 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 98 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 99 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 100 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 101 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 102 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 103 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 104 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 105 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 106 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 107 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 108 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 109 | import android.telephony.data.ApnSetting; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame^] | 110 | import android.telephony.data.SlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 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; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame^] | 339 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 340 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 341 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 342 | // Parameters of select command. |
| 343 | private static final int SELECT_COMMAND = 0xA4; |
| 344 | private static final int SELECT_P1 = 0x04; |
| 345 | private static final int SELECT_P2 = 0; |
| 346 | private static final int SELECT_P3 = 0x10; |
| 347 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 348 | /** The singleton instance. */ |
| 349 | private static PhoneInterfaceManager sInstance; |
| 350 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 351 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 352 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 353 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 354 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 355 | private AppOpsManager mAppOps; |
| 356 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 357 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 358 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 359 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 360 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 361 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 362 | /** User Activity */ |
| 363 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 364 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 365 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 366 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 367 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 368 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 369 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 370 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 371 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 372 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 373 | // String to store multi SIM allowed |
| 374 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 375 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 376 | // The AID of ISD-R. |
| 377 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 378 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 379 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 380 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 381 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 382 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 383 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 384 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
| 385 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 386 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 387 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 388 | */ |
| 389 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 390 | "reset_network_erase_modem_config_enabled"; |
| 391 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 392 | private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds |
| 393 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 394 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 395 | * A request object to use for transmitting data to an ICC. |
| 396 | */ |
| 397 | private static final class IccAPDUArgument { |
| 398 | public int channel, cla, command, p1, p2, p3; |
| 399 | public String data; |
| 400 | |
| 401 | public IccAPDUArgument(int channel, int cla, int command, |
| 402 | int p1, int p2, int p3, String data) { |
| 403 | this.channel = channel; |
| 404 | this.cla = cla; |
| 405 | this.command = command; |
| 406 | this.p1 = p1; |
| 407 | this.p2 = p2; |
| 408 | this.p3 = p3; |
| 409 | this.data = data; |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 414 | * A request object to use for transmitting data to an ICC. |
| 415 | */ |
| 416 | private static final class ManualNetworkSelectionArgument { |
| 417 | public OperatorInfo operatorInfo; |
| 418 | public boolean persistSelection; |
| 419 | |
| 420 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 421 | this.operatorInfo = operatorInfo; |
| 422 | this.persistSelection = persistSelection; |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 427 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 428 | * request after sending. The main thread will notify the request when it is complete. |
| 429 | */ |
| 430 | private static final class MainThreadRequest { |
| 431 | /** The argument to use for the request */ |
| 432 | public Object argument; |
| 433 | /** The result of the request that is run on the main thread */ |
| 434 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 435 | // The subscriber id that this request applies to. Defaults to |
| 436 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 437 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 438 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 439 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 440 | public Phone phone; |
| 441 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 442 | public WorkSource workSource; |
| 443 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 444 | public MainThreadRequest(Object argument) { |
| 445 | this.argument = argument; |
| 446 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 447 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 448 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 449 | this.argument = argument; |
| 450 | if (phone != null) { |
| 451 | this.phone = phone; |
| 452 | } |
| 453 | this.workSource = workSource; |
| 454 | } |
| 455 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 456 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 457 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 458 | if (subId != null) { |
| 459 | this.subId = subId; |
| 460 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 461 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 462 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 463 | } |
| 464 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 465 | private static final class IncomingThirdPartyCallArgs { |
| 466 | public final ComponentName component; |
| 467 | public final String callId; |
| 468 | public final String callerDisplayName; |
| 469 | |
| 470 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 471 | String callerDisplayName) { |
| 472 | this.component = component; |
| 473 | this.callId = callId; |
| 474 | this.callerDisplayName = callerDisplayName; |
| 475 | } |
| 476 | } |
| 477 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 478 | /** |
| 479 | * A handler that processes messages on the main thread in the phone process. Since many |
| 480 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 481 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 482 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 483 | * on, which will be notified when the operation completes and will contain the result of the |
| 484 | * request. |
| 485 | * |
| 486 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 487 | * note that request.result must be set to something non-null for the calling thread to |
| 488 | * unblock. |
| 489 | */ |
| 490 | private final class MainThreadHandler extends Handler { |
| 491 | @Override |
| 492 | public void handleMessage(Message msg) { |
| 493 | MainThreadRequest request; |
| 494 | Message onCompleted; |
| 495 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 496 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 497 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 498 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 499 | |
| 500 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 501 | case CMD_HANDLE_USSD_REQUEST: { |
| 502 | request = (MainThreadRequest) msg.obj; |
| 503 | final Phone phone = getPhoneFromRequest(request); |
| 504 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 505 | String ussdRequest = ussdObject.first; |
| 506 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 507 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 508 | if (!isUssdApiAllowed(request.subId)) { |
| 509 | // Carrier does not support use of this API, return failure. |
| 510 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 511 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 512 | Bundle returnData = new Bundle(); |
| 513 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 514 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 515 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 516 | request.result = true; |
| 517 | notifyRequester(request); |
| 518 | return; |
| 519 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 520 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 521 | try { |
| 522 | request.result = phone != null |
| 523 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 524 | } catch (CallStateException cse) { |
| 525 | request.result = false; |
| 526 | } |
| 527 | // Wake up the requesting thread |
| 528 | notifyRequester(request); |
| 529 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 532 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 533 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 534 | final Phone phone = getPhoneFromRequest(request); |
| 535 | request.result = phone != null ? |
| 536 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 537 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 538 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 539 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 540 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 541 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 542 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 543 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 544 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 545 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 546 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 547 | if (uiccCard == null) { |
| 548 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 549 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 550 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 551 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 552 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 553 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 554 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 555 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 556 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 557 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 558 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 559 | break; |
| 560 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 561 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 562 | ar = (AsyncResult) msg.obj; |
| 563 | request = (MainThreadRequest) ar.userObj; |
| 564 | if (ar.exception == null && ar.result != null) { |
| 565 | request.result = ar.result; |
| 566 | } else { |
| 567 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 568 | if (ar.result == null) { |
| 569 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 570 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 571 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 572 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 573 | } else { |
| 574 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 575 | } |
| 576 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 577 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 578 | break; |
| 579 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 580 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 581 | request = (MainThreadRequest) msg.obj; |
| 582 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 583 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 584 | if (uiccCard == null) { |
| 585 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 586 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 587 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 588 | } else { |
| 589 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 590 | request); |
| 591 | uiccCard.iccTransmitApduBasicChannel( |
| 592 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 593 | iccArgument.p3, iccArgument.data, onCompleted); |
| 594 | } |
| 595 | break; |
| 596 | |
| 597 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 598 | ar = (AsyncResult) msg.obj; |
| 599 | request = (MainThreadRequest) ar.userObj; |
| 600 | if (ar.exception == null && ar.result != null) { |
| 601 | request.result = ar.result; |
| 602 | } else { |
| 603 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 604 | if (ar.result == null) { |
| 605 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 606 | } else if (ar.exception instanceof CommandException) { |
| 607 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 608 | ar.exception); |
| 609 | } else { |
| 610 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 611 | } |
| 612 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 613 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 614 | break; |
| 615 | |
| 616 | case CMD_EXCHANGE_SIM_IO: |
| 617 | request = (MainThreadRequest) msg.obj; |
| 618 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 619 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 620 | if (uiccCard == null) { |
| 621 | loge("iccExchangeSimIO: No UICC"); |
| 622 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 623 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 624 | } else { |
| 625 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 626 | request); |
| 627 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 628 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 629 | iccArgument.data, onCompleted); |
| 630 | } |
| 631 | break; |
| 632 | |
| 633 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 634 | ar = (AsyncResult) msg.obj; |
| 635 | request = (MainThreadRequest) ar.userObj; |
| 636 | if (ar.exception == null && ar.result != null) { |
| 637 | request.result = ar.result; |
| 638 | } else { |
| 639 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 640 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 641 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 642 | break; |
| 643 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 644 | case CMD_SEND_ENVELOPE: |
| 645 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 646 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 647 | if (uiccCard == null) { |
| 648 | loge("sendEnvelopeWithStatus: No UICC"); |
| 649 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 650 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 651 | } else { |
| 652 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 653 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 654 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 655 | break; |
| 656 | |
| 657 | case EVENT_SEND_ENVELOPE_DONE: |
| 658 | ar = (AsyncResult) msg.obj; |
| 659 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 660 | if (ar.exception == null && ar.result != null) { |
| 661 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 662 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 663 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 664 | if (ar.result == null) { |
| 665 | loge("sendEnvelopeWithStatus: Empty response"); |
| 666 | } else if (ar.exception instanceof CommandException) { |
| 667 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 668 | ar.exception); |
| 669 | } else { |
| 670 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 671 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 672 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 673 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 674 | break; |
| 675 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 676 | case CMD_OPEN_CHANNEL: |
| 677 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 678 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 679 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 680 | if (uiccCard == null) { |
| 681 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 682 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 683 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 684 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 685 | } else { |
| 686 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 687 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 688 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 689 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 690 | break; |
| 691 | |
| 692 | case EVENT_OPEN_CHANNEL_DONE: |
| 693 | ar = (AsyncResult) msg.obj; |
| 694 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 695 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 696 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 697 | int[] result = (int[]) ar.result; |
| 698 | int channelId = result[0]; |
| 699 | byte[] selectResponse = null; |
| 700 | if (result.length > 1) { |
| 701 | selectResponse = new byte[result.length - 1]; |
| 702 | for (int i = 1; i < result.length; ++i) { |
| 703 | selectResponse[i - 1] = (byte) result[i]; |
| 704 | } |
| 705 | } |
| 706 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 707 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 708 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 709 | if (ar.result == null) { |
| 710 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 711 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 712 | if (ar.exception != null) { |
| 713 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 714 | } |
| 715 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 716 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 717 | if (ar.exception instanceof CommandException) { |
| 718 | CommandException.Error error = |
| 719 | ((CommandException) (ar.exception)).getCommandError(); |
| 720 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 721 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 722 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 723 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 724 | } |
| 725 | } |
| 726 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 727 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 728 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 729 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 730 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 731 | break; |
| 732 | |
| 733 | case CMD_CLOSE_CHANNEL: |
| 734 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 735 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 736 | if (uiccCard == null) { |
| 737 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 738 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 739 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 740 | } else { |
| 741 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 742 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 743 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 744 | break; |
| 745 | |
| 746 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 747 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 748 | break; |
| 749 | |
| 750 | case CMD_NV_READ_ITEM: |
| 751 | request = (MainThreadRequest) msg.obj; |
| 752 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 753 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 754 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 755 | break; |
| 756 | |
| 757 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 758 | ar = (AsyncResult) msg.obj; |
| 759 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 760 | if (ar.exception == null && ar.result != null) { |
| 761 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 762 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 763 | request.result = ""; |
| 764 | if (ar.result == null) { |
| 765 | loge("nvReadItem: Empty response"); |
| 766 | } else if (ar.exception instanceof CommandException) { |
| 767 | loge("nvReadItem: CommandException: " + |
| 768 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 769 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 770 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 771 | } |
| 772 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 773 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 774 | break; |
| 775 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 776 | case CMD_NV_WRITE_ITEM: |
| 777 | request = (MainThreadRequest) msg.obj; |
| 778 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 779 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 780 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 781 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 782 | break; |
| 783 | |
| 784 | case EVENT_NV_WRITE_ITEM_DONE: |
| 785 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 786 | break; |
| 787 | |
| 788 | case CMD_NV_WRITE_CDMA_PRL: |
| 789 | request = (MainThreadRequest) msg.obj; |
| 790 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 791 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 792 | break; |
| 793 | |
| 794 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 795 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 796 | break; |
| 797 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 798 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 799 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 800 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 801 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 802 | break; |
| 803 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 804 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 805 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 806 | break; |
| 807 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 808 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 809 | request = (MainThreadRequest) msg.obj; |
| 810 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 811 | request); |
| 812 | Phone phone = getPhoneFromRequest(request); |
| 813 | if (phone != null) { |
| 814 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 815 | } else { |
| 816 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 817 | request.result = false; |
| 818 | notifyRequester(request); |
| 819 | } |
| 820 | break; |
| 821 | } |
| 822 | |
| 823 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 824 | ar = (AsyncResult) msg.obj; |
| 825 | request = (MainThreadRequest) ar.userObj; |
| 826 | if (ar.exception == null && ar.result != null) { |
| 827 | request.result = ar.result; |
| 828 | } else { |
| 829 | // request.result must be set to something non-null |
| 830 | // for the calling thread to unblock |
| 831 | if (request.result != null) { |
| 832 | request.result = ar.result; |
| 833 | } else { |
| 834 | request.result = false; |
| 835 | } |
| 836 | if (ar.result == null) { |
| 837 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 838 | } else if (ar.exception instanceof CommandException) { |
| 839 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 840 | + ar.exception); |
| 841 | } else { |
| 842 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 843 | } |
| 844 | } |
| 845 | notifyRequester(request); |
| 846 | break; |
| 847 | |
| 848 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 849 | request = (MainThreadRequest) msg.obj; |
| 850 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 851 | Phone phone = getPhoneFromRequest(request); |
| 852 | if (phone != null) { |
| 853 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 854 | request.workSource); |
| 855 | } else { |
| 856 | loge("enableNrDualConnectivity: No phone object"); |
| 857 | request.result = |
| 858 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 859 | notifyRequester(request); |
| 860 | } |
| 861 | break; |
| 862 | } |
| 863 | |
| 864 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 865 | ar = (AsyncResult) msg.obj; |
| 866 | request = (MainThreadRequest) ar.userObj; |
| 867 | if (ar.exception == null) { |
| 868 | request.result = |
| 869 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 870 | } else { |
| 871 | request.result = |
| 872 | TelephonyManager |
| 873 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 874 | if (ar.exception instanceof CommandException) { |
| 875 | CommandException.Error error = |
| 876 | ((CommandException) (ar.exception)).getCommandError(); |
| 877 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 878 | request.result = |
| 879 | TelephonyManager |
| 880 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 881 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 882 | request.result = |
| 883 | TelephonyManager |
| 884 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 885 | } |
| 886 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 887 | + ar.exception); |
| 888 | } else { |
| 889 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 890 | } |
| 891 | } |
| 892 | notifyRequester(request); |
| 893 | break; |
| 894 | } |
| 895 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 896 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 897 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 898 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 899 | request); |
| 900 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 901 | break; |
| 902 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 903 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 904 | ar = (AsyncResult) msg.obj; |
| 905 | request = (MainThreadRequest) ar.userObj; |
| 906 | if (ar.exception == null && ar.result != null) { |
| 907 | request.result = ar.result; // Integer |
| 908 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 909 | // request.result must be set to something non-null |
| 910 | // for the calling thread to unblock |
| 911 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 912 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 913 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 914 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 915 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 916 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 917 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 918 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 919 | } |
| 920 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 921 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 922 | break; |
| 923 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 924 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 925 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 926 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 927 | request); |
| 928 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 929 | (Pair<Integer, Long>) request.argument; |
| 930 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 931 | reasonWithNetworkTypes.first, |
| 932 | reasonWithNetworkTypes.second, |
| 933 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 934 | break; |
| 935 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 936 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 937 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 938 | break; |
| 939 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 940 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 941 | request = (MainThreadRequest)msg.obj; |
| 942 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 943 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 944 | break; |
| 945 | |
| 946 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 947 | ar = (AsyncResult)msg.obj; |
| 948 | request = (MainThreadRequest)ar.userObj; |
| 949 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 950 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 951 | break; |
| 952 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 953 | case CMD_SET_VOICEMAIL_NUMBER: |
| 954 | request = (MainThreadRequest) msg.obj; |
| 955 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 956 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 957 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 958 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 959 | break; |
| 960 | |
| 961 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 962 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 963 | break; |
| 964 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 965 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 966 | request = (MainThreadRequest) msg.obj; |
| 967 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 968 | request); |
| 969 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 970 | break; |
| 971 | |
| 972 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 973 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 974 | break; |
| 975 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 976 | case CMD_PERFORM_NETWORK_SCAN: |
| 977 | request = (MainThreadRequest) msg.obj; |
| 978 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 979 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 980 | break; |
| 981 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 982 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 983 | request = (MainThreadRequest) msg.obj; |
| 984 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 985 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 986 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 987 | request.argument; |
| 988 | int callForwardingReason = args.first; |
| 989 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 990 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 991 | } |
| 992 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 993 | ar = (AsyncResult) msg.obj; |
| 994 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 995 | TelephonyManager.CallForwardingInfoCallback callback = |
| 996 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 997 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 998 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 999 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1000 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1001 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1002 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1003 | // any service for voice call. |
| 1004 | if ((callForwardInfo.serviceClass |
| 1005 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1006 | callForwardingInfo = new CallForwardingInfo(true, |
| 1007 | callForwardInfo.reason, |
| 1008 | callForwardInfo.number, |
| 1009 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1010 | break; |
| 1011 | } |
| 1012 | } |
| 1013 | // Didn't find a call forward info for voice call. |
| 1014 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1015 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1016 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1017 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1018 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1019 | } else { |
| 1020 | if (ar.result == null) { |
| 1021 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1022 | } |
| 1023 | if (ar.exception != null) { |
| 1024 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1025 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1026 | int errorCode = TelephonyManager |
| 1027 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1028 | if (ar.exception instanceof CommandException) { |
| 1029 | CommandException.Error error = |
| 1030 | ((CommandException) (ar.exception)).getCommandError(); |
| 1031 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1032 | errorCode = TelephonyManager |
| 1033 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1034 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1035 | errorCode = TelephonyManager |
| 1036 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1037 | } |
| 1038 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1039 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1040 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1041 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1042 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1043 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1044 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1045 | request = (MainThreadRequest) msg.obj; |
| 1046 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1047 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1048 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1049 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1050 | request.argument).first; |
| 1051 | request.phone.setCallForwardingOption( |
| 1052 | callForwardingInfoToSet.isEnabled() |
| 1053 | ? CommandsInterface.CF_ACTION_ENABLE |
| 1054 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1055 | callForwardingInfoToSet.getReason(), |
| 1056 | callForwardingInfoToSet.getNumber(), |
| 1057 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1058 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1059 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1060 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1061 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1062 | ar = (AsyncResult) msg.obj; |
| 1063 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1064 | Consumer<Integer> callback = |
| 1065 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1066 | request.argument).second; |
| 1067 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1068 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1069 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1070 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1071 | if (ar.exception instanceof CommandException) { |
| 1072 | CommandException.Error error = |
| 1073 | ((CommandException) (ar.exception)).getCommandError(); |
| 1074 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1075 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1076 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1077 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1078 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1079 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1080 | } |
| 1081 | } |
| 1082 | callback.accept(errorCode); |
| 1083 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1084 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1085 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1086 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1087 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1088 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1089 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1090 | request = (MainThreadRequest) msg.obj; |
| 1091 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1092 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1093 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1094 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1095 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1096 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1097 | ar = (AsyncResult) msg.obj; |
| 1098 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1099 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1100 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1101 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1102 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1103 | // Service Class is a bit mask per 3gpp 27.007. |
| 1104 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1105 | if (callForwardResults.length > 1 |
| 1106 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1107 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1108 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1109 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1110 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1111 | } else { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1112 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1113 | } |
| 1114 | } else { |
| 1115 | if (ar.result == null) { |
| 1116 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1117 | } |
| 1118 | if (ar.exception != null) { |
| 1119 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1120 | } |
| 1121 | if (ar.exception instanceof CommandException) { |
| 1122 | CommandException.Error error = |
| 1123 | ((CommandException) (ar.exception)).getCommandError(); |
| 1124 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1125 | callForwardingStatus = |
| 1126 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1127 | } |
| 1128 | } |
| 1129 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1130 | callback.accept(callForwardingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1131 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1132 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1133 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1134 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1135 | request = (MainThreadRequest) msg.obj; |
| 1136 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1137 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1138 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1139 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1140 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1141 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1142 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1143 | ar = (AsyncResult) msg.obj; |
| 1144 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1145 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1146 | Consumer<Integer> callback = |
| 1147 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1148 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1149 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1150 | if (ar.exception instanceof CommandException) { |
| 1151 | CommandException.Error error = |
| 1152 | ((CommandException) (ar.exception)).getCommandError(); |
| 1153 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1154 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1155 | } else { |
| 1156 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1157 | } |
| 1158 | } else { |
| 1159 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1160 | } |
| 1161 | } else { |
| 1162 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1163 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1164 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1165 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1166 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1167 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1168 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1169 | ar = (AsyncResult) msg.obj; |
| 1170 | request = (MainThreadRequest) ar.userObj; |
| 1171 | CellNetworkScanResult cellScanResult; |
| 1172 | if (ar.exception == null && ar.result != null) { |
| 1173 | cellScanResult = new CellNetworkScanResult( |
| 1174 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1175 | (List<OperatorInfo>) ar.result); |
| 1176 | } else { |
| 1177 | if (ar.result == null) { |
| 1178 | loge("getCellNetworkScanResults: Empty response"); |
| 1179 | } |
| 1180 | if (ar.exception != null) { |
| 1181 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1182 | } |
| 1183 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1184 | if (ar.exception instanceof CommandException) { |
| 1185 | CommandException.Error error = |
| 1186 | ((CommandException) (ar.exception)).getCommandError(); |
| 1187 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1188 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1189 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1190 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1191 | } |
| 1192 | } |
| 1193 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1194 | } |
| 1195 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1196 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1197 | break; |
| 1198 | |
| 1199 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1200 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1201 | ManualNetworkSelectionArgument selArg = |
| 1202 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1203 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1204 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1205 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1206 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1207 | break; |
| 1208 | |
| 1209 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1210 | ar = (AsyncResult) msg.obj; |
| 1211 | request = (MainThreadRequest) ar.userObj; |
| 1212 | if (ar.exception == null) { |
| 1213 | request.result = true; |
| 1214 | } else { |
| 1215 | request.result = false; |
| 1216 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1217 | } |
| 1218 | notifyRequester(request); |
| 1219 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1220 | break; |
| 1221 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1222 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1223 | request = (MainThreadRequest) msg.obj; |
| 1224 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1225 | if (defaultPhone != null) { |
| 1226 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1227 | } else { |
| 1228 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1229 | Bundle bundle = new Bundle(); |
| 1230 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1231 | new ModemActivityInfo(0, 0, 0, |
| 1232 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1233 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1234 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1235 | break; |
| 1236 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1237 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1238 | ar = (AsyncResult) msg.obj; |
| 1239 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1240 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1241 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1242 | ModemActivityInfo ret = null; |
| 1243 | int error = 0; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1244 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1245 | // Update the last modem activity info and the result of the request. |
| 1246 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1247 | if (isModemActivityInfoValid(info)) { |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1248 | int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()]; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1249 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1250 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1251 | .getTransmitTimeMillis(); |
| 1252 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1253 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1254 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1255 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1256 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1257 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1258 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1259 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1260 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1261 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1262 | info.getReceiveTimeMillis() |
| 1263 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1264 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1265 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(), |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1266 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1267 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1268 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1269 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1270 | } else { |
| 1271 | if (ar.result == null) { |
| 1272 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1273 | error = TelephonyManager.ModemActivityInfoException |
| 1274 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1275 | } else if (ar.exception instanceof CommandException) { |
| 1276 | loge("queryModemActivityInfo: CommandException: " + |
| 1277 | ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1278 | error = TelephonyManager.ModemActivityInfoException |
| 1279 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1280 | } else { |
| 1281 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1282 | error = TelephonyManager.ModemActivityInfoException |
| 1283 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1284 | } |
| 1285 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1286 | Bundle bundle = new Bundle(); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1287 | if (ret != null) { |
| 1288 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1289 | } else { |
| 1290 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1291 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1292 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1293 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1294 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1295 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1296 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1297 | case CMD_SET_ALLOWED_CARRIERS: |
| 1298 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1299 | CarrierRestrictionRules argument = |
| 1300 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1301 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1302 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1303 | break; |
| 1304 | |
| 1305 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1306 | ar = (AsyncResult) msg.obj; |
| 1307 | request = (MainThreadRequest) ar.userObj; |
| 1308 | if (ar.exception == null && ar.result != null) { |
| 1309 | request.result = ar.result; |
| 1310 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1311 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1312 | if (ar.exception instanceof CommandException) { |
| 1313 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1314 | CommandException.Error error = |
| 1315 | ((CommandException) (ar.exception)).getCommandError(); |
| 1316 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1317 | request.result = |
| 1318 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1319 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1320 | } else { |
| 1321 | loge("setAllowedCarriers: Unknown exception"); |
| 1322 | } |
| 1323 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1324 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1325 | break; |
| 1326 | |
| 1327 | case CMD_GET_ALLOWED_CARRIERS: |
| 1328 | request = (MainThreadRequest) msg.obj; |
| 1329 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1330 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1331 | break; |
| 1332 | |
| 1333 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1334 | ar = (AsyncResult) msg.obj; |
| 1335 | request = (MainThreadRequest) ar.userObj; |
| 1336 | if (ar.exception == null && ar.result != null) { |
| 1337 | request.result = ar.result; |
| 1338 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1339 | request.result = new IllegalStateException( |
| 1340 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1341 | if (ar.result == null) { |
| 1342 | loge("getAllowedCarriers: Empty response"); |
| 1343 | } else if (ar.exception instanceof CommandException) { |
| 1344 | loge("getAllowedCarriers: CommandException: " + |
| 1345 | ar.exception); |
| 1346 | } else { |
| 1347 | loge("getAllowedCarriers: Unknown exception"); |
| 1348 | } |
| 1349 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1350 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1351 | break; |
| 1352 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1353 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1354 | ar = (AsyncResult) msg.obj; |
| 1355 | request = (MainThreadRequest) ar.userObj; |
| 1356 | if (ar.exception == null && ar.result != null) { |
| 1357 | request.result = ar.result; |
| 1358 | } else { |
| 1359 | request.result = new IllegalArgumentException( |
| 1360 | "Failed to retrieve Forbidden Plmns"); |
| 1361 | if (ar.result == null) { |
| 1362 | loge("getForbiddenPlmns: Empty response"); |
| 1363 | } else { |
| 1364 | loge("getForbiddenPlmns: Unknown exception"); |
| 1365 | } |
| 1366 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1367 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1368 | break; |
| 1369 | |
| 1370 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1371 | request = (MainThreadRequest) msg.obj; |
| 1372 | uiccCard = getUiccCardFromRequest(request); |
| 1373 | if (uiccCard == null) { |
| 1374 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1375 | request.result = new IllegalArgumentException( |
| 1376 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1377 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1378 | break; |
| 1379 | } |
| 1380 | Integer appType = (Integer) request.argument; |
| 1381 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1382 | if (uiccApp == null) { |
| 1383 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1384 | + appType); |
| 1385 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1386 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1387 | break; |
| 1388 | } else { |
| 1389 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1390 | + " specified type -- " + appType); |
| 1391 | } |
| 1392 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1393 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1394 | onCompleted); |
| 1395 | break; |
| 1396 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1397 | case CMD_SWITCH_SLOTS: |
| 1398 | request = (MainThreadRequest) msg.obj; |
| 1399 | int[] physicalSlots = (int[]) request.argument; |
| 1400 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1401 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1402 | break; |
| 1403 | |
| 1404 | case EVENT_SWITCH_SLOTS_DONE: |
| 1405 | ar = (AsyncResult) msg.obj; |
| 1406 | request = (MainThreadRequest) ar.userObj; |
| 1407 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1408 | notifyRequester(request); |
| 1409 | break; |
| 1410 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1411 | request = (MainThreadRequest) msg.obj; |
| 1412 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1413 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1414 | break; |
| 1415 | |
| 1416 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1417 | ar = (AsyncResult) msg.obj; |
| 1418 | request = (MainThreadRequest) ar.userObj; |
| 1419 | if (ar.exception != null) { |
| 1420 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1421 | } else { |
| 1422 | int mode = ((int[]) ar.result)[0]; |
| 1423 | if (mode == 0) { |
| 1424 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1425 | } else { |
| 1426 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1427 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1428 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1429 | notifyRequester(request); |
| 1430 | break; |
| 1431 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1432 | request = (MainThreadRequest) msg.obj; |
| 1433 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1434 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1435 | break; |
| 1436 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1437 | ar = (AsyncResult) msg.obj; |
| 1438 | request = (MainThreadRequest) ar.userObj; |
| 1439 | if (ar.exception != null) { |
| 1440 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1441 | } else { |
| 1442 | request.result = ((int[]) ar.result)[0]; |
| 1443 | } |
| 1444 | notifyRequester(request); |
| 1445 | break; |
| 1446 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1447 | request = (MainThreadRequest) msg.obj; |
| 1448 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1449 | int mode = (int) request.argument; |
| 1450 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1451 | break; |
| 1452 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1453 | ar = (AsyncResult) msg.obj; |
| 1454 | request = (MainThreadRequest) ar.userObj; |
| 1455 | request.result = ar.exception == null; |
| 1456 | notifyRequester(request); |
| 1457 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1458 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1459 | request = (MainThreadRequest) msg.obj; |
| 1460 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1461 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1462 | break; |
| 1463 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1464 | ar = (AsyncResult) msg.obj; |
| 1465 | request = (MainThreadRequest) ar.userObj; |
| 1466 | if (ar.exception != null) { |
| 1467 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1468 | } else { |
| 1469 | request.result = ((int[]) ar.result)[0]; |
| 1470 | } |
| 1471 | notifyRequester(request); |
| 1472 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1473 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1474 | request = (MainThreadRequest) msg.obj; |
| 1475 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1476 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1477 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1478 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1479 | break; |
| 1480 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1481 | ar = (AsyncResult) msg.obj; |
| 1482 | request = (MainThreadRequest) ar.userObj; |
| 1483 | request.result = ar.exception == null; |
| 1484 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1485 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1486 | case CMD_GET_ALL_CELL_INFO: |
| 1487 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1488 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1489 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1490 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1491 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1492 | ar = (AsyncResult) msg.obj; |
| 1493 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1494 | // If a timeout occurs, the response will be null |
| 1495 | request.result = (ar.exception == null && ar.result != null) |
| 1496 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1497 | synchronized (request) { |
| 1498 | request.notifyAll(); |
| 1499 | } |
| 1500 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1501 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1502 | request = (MainThreadRequest) msg.obj; |
| 1503 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1504 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1505 | break; |
| 1506 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1507 | ar = (AsyncResult) msg.obj; |
| 1508 | request = (MainThreadRequest) ar.userObj; |
| 1509 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1510 | try { |
| 1511 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1512 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1513 | cb.onError( |
| 1514 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1515 | ar.exception.getClass().getName(), |
| 1516 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1517 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1518 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1519 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1520 | } else { |
| 1521 | // use the result as returned |
| 1522 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1523 | } |
| 1524 | } catch (RemoteException re) { |
| 1525 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1526 | } |
| 1527 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1528 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1529 | request = (MainThreadRequest) msg.obj; |
| 1530 | WorkSource ws = (WorkSource) request.argument; |
| 1531 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1532 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1533 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1534 | } |
| 1535 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1536 | ar = (AsyncResult) msg.obj; |
| 1537 | request = (MainThreadRequest) ar.userObj; |
| 1538 | if (ar.exception == null) { |
| 1539 | request.result = ar.result; |
| 1540 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1541 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1542 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1543 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1544 | } |
| 1545 | |
| 1546 | synchronized (request) { |
| 1547 | request.notifyAll(); |
| 1548 | } |
| 1549 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1550 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1551 | case CMD_MODEM_REBOOT: |
| 1552 | request = (MainThreadRequest) msg.obj; |
| 1553 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1554 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1555 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1556 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1557 | handleNullReturnEvent(msg, "rebootModem"); |
| 1558 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1559 | case CMD_REQUEST_ENABLE_MODEM: |
| 1560 | request = (MainThreadRequest) msg.obj; |
| 1561 | boolean enable = (boolean) request.argument; |
| 1562 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1563 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1564 | PhoneConfigurationManager.getInstance() |
| 1565 | .enablePhone(request.phone, enable, onCompleted); |
| 1566 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1567 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1568 | ar = (AsyncResult) msg.obj; |
| 1569 | request = (MainThreadRequest) ar.userObj; |
| 1570 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1571 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1572 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1573 | if ((boolean) request.result) { |
| 1574 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1575 | updateModemStateMetrics(); |
| 1576 | } else { |
| 1577 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1578 | + ar.exception); |
| 1579 | } |
| 1580 | notifyRequester(request); |
| 1581 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1582 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1583 | case CMD_GET_MODEM_STATUS: |
| 1584 | request = (MainThreadRequest) msg.obj; |
| 1585 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1586 | PhoneConfigurationManager.getInstance() |
| 1587 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1588 | break; |
| 1589 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1590 | ar = (AsyncResult) msg.obj; |
| 1591 | request = (MainThreadRequest) ar.userObj; |
| 1592 | int id = request.phone.getPhoneId(); |
| 1593 | if (ar.exception == null && ar.result != null) { |
| 1594 | request.result = ar.result; |
| 1595 | //update the cache as modem status has changed |
| 1596 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1597 | (boolean) request.result); |
| 1598 | } else { |
| 1599 | // Return true if modem status cannot be retrieved. For most cases, |
| 1600 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1601 | // and disable modem are not supported. Modem is always on. |
| 1602 | // TODO: this should be fixed in R to support a third |
| 1603 | // status UNKNOWN b/131631629 |
| 1604 | request.result = true; |
| 1605 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1606 | + ar.exception); |
| 1607 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1608 | notifyRequester(request); |
| 1609 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1610 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1611 | request = (MainThreadRequest) msg.obj; |
| 1612 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1613 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1614 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1615 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1616 | break; |
| 1617 | } |
| 1618 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1619 | ar = (AsyncResult) msg.obj; |
| 1620 | request = (MainThreadRequest) ar.userObj; |
| 1621 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1622 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1623 | args.second.accept(ar.exception == null); |
| 1624 | notifyRequester(request); |
| 1625 | break; |
| 1626 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1627 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1628 | request = (MainThreadRequest) msg.obj; |
| 1629 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1630 | Phone phone = getPhoneFromRequest(request); |
| 1631 | if (phone != null) { |
| 1632 | phone.getSystemSelectionChannels(onCompleted); |
| 1633 | } else { |
| 1634 | loge("getSystemSelectionChannels: No phone object"); |
| 1635 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1636 | notifyRequester(request); |
| 1637 | } |
| 1638 | break; |
| 1639 | } |
| 1640 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1641 | ar = (AsyncResult) msg.obj; |
| 1642 | request = (MainThreadRequest) ar.userObj; |
| 1643 | if (ar.exception == null && ar.result != null) { |
| 1644 | request.result = ar.result; |
| 1645 | } else { |
| 1646 | request.result = new IllegalArgumentException( |
| 1647 | "Failed to retrieve system selection channels"); |
| 1648 | if (ar.result == null) { |
| 1649 | loge("getSystemSelectionChannels: Empty response"); |
| 1650 | } else { |
| 1651 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1652 | } |
| 1653 | } |
| 1654 | notifyRequester(request); |
| 1655 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1656 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1657 | ar = (AsyncResult) msg.obj; |
| 1658 | request = (MainThreadRequest) ar.userObj; |
| 1659 | if (ar.exception == null && ar.result != null) { |
| 1660 | request.result = ar.result; |
| 1661 | } else { |
| 1662 | request.result = -1; |
| 1663 | loge("Failed to set Forbidden Plmns"); |
| 1664 | if (ar.result == null) { |
| 1665 | loge("setForbidenPlmns: Empty response"); |
| 1666 | } else if (ar.exception != null) { |
| 1667 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1668 | request.result = -1; |
| 1669 | } else { |
| 1670 | loge("setForbiddenPlmns: Unknown exception"); |
| 1671 | } |
| 1672 | } |
| 1673 | notifyRequester(request); |
| 1674 | break; |
| 1675 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1676 | request = (MainThreadRequest) msg.obj; |
| 1677 | uiccCard = getUiccCardFromRequest(request); |
| 1678 | if (uiccCard == null) { |
| 1679 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1680 | request.result = -1; |
| 1681 | notifyRequester(request); |
| 1682 | break; |
| 1683 | } |
| 1684 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1685 | (Pair<Integer, List<String>>) request.argument; |
| 1686 | appType = setFplmnsArgs.first; |
| 1687 | List<String> fplmns = setFplmnsArgs.second; |
| 1688 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1689 | if (uiccApp == null) { |
| 1690 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1691 | request.result = -1; |
| 1692 | loge("Failed to get UICC App"); |
| 1693 | notifyRequester(request); |
| 1694 | } else { |
| 1695 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1696 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1697 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1698 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1699 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1700 | case CMD_ERASE_MODEM_CONFIG: |
| 1701 | request = (MainThreadRequest) msg.obj; |
| 1702 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1703 | defaultPhone.eraseModemConfig(onCompleted); |
| 1704 | break; |
| 1705 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1706 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1707 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1708 | |
| 1709 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1710 | request = (MainThreadRequest) msg.obj; |
| 1711 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1712 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1713 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1714 | changed.first, changed.second, onCompleted); |
| 1715 | break; |
| 1716 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1717 | ar = (AsyncResult) msg.obj; |
| 1718 | request = (MainThreadRequest) ar.userObj; |
| 1719 | if (ar.exception == null) { |
| 1720 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1721 | // If the operation is successful, update the PIN storage |
| 1722 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1723 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1724 | UiccController.getInstance().getPinStorage() |
| 1725 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1726 | } else { |
| 1727 | request.result = msg.arg1; |
| 1728 | } |
| 1729 | notifyRequester(request); |
| 1730 | break; |
| 1731 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1732 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1733 | request = (MainThreadRequest) msg.obj; |
| 1734 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1735 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1736 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1737 | enabled.first, enabled.second, onCompleted); |
| 1738 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1739 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1740 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1741 | ar = (AsyncResult) msg.obj; |
| 1742 | request = (MainThreadRequest) ar.userObj; |
| 1743 | if (ar.exception == null) { |
| 1744 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1745 | // If the operation is successful, update the PIN storage |
| 1746 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1747 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1748 | if (enabled.first) { |
| 1749 | UiccController.getInstance().getPinStorage() |
| 1750 | .storePin(enabled.second, phoneId); |
| 1751 | } else { |
| 1752 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1753 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1754 | } else { |
| 1755 | request.result = msg.arg1; |
| 1756 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1757 | |
| 1758 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1759 | notifyRequester(request); |
| 1760 | break; |
| 1761 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1762 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1763 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1764 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1765 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1766 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1767 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1768 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1769 | |
| 1770 | case CMD_SET_DATA_THROTTLING: { |
| 1771 | request = (MainThreadRequest) msg.obj; |
| 1772 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1773 | DataThrottlingRequest dataThrottlingRequest = |
| 1774 | (DataThrottlingRequest) request.argument; |
| 1775 | Phone phone = getPhoneFromRequest(request); |
| 1776 | if (phone != null) { |
| 1777 | phone.setDataThrottling(onCompleted, |
| 1778 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1779 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1780 | } else { |
| 1781 | loge("setDataThrottling: No phone object"); |
| 1782 | request.result = |
| 1783 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1784 | notifyRequester(request); |
| 1785 | } |
| 1786 | |
| 1787 | break; |
| 1788 | } |
| 1789 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1790 | ar = (AsyncResult) msg.obj; |
| 1791 | request = (MainThreadRequest) ar.userObj; |
| 1792 | |
| 1793 | if (ar.exception == null) { |
| 1794 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1795 | } else if (ar.exception instanceof CommandException) { |
| 1796 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1797 | CommandException.Error error = |
| 1798 | ((CommandException) (ar.exception)).getCommandError(); |
| 1799 | |
| 1800 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1801 | request.result = TelephonyManager |
| 1802 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1803 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1804 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
| 1805 | } else { |
| 1806 | request.result = |
| 1807 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1808 | } |
| 1809 | } else { |
| 1810 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1811 | } |
| 1812 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1813 | notifyRequester(request); |
| 1814 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1815 | |
| 1816 | case CMD_SET_SIM_POWER: { |
| 1817 | request = (MainThreadRequest) msg.obj; |
| 1818 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1819 | request = (MainThreadRequest) msg.obj; |
| 1820 | int stateToSet = |
| 1821 | ((Pair<Integer, IIntegerConsumer>) |
| 1822 | request.argument).first; |
| 1823 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1824 | break; |
| 1825 | } |
| 1826 | case EVENT_SET_SIM_POWER_DONE: { |
| 1827 | ar = (AsyncResult) msg.obj; |
| 1828 | request = (MainThreadRequest) ar.userObj; |
| 1829 | IIntegerConsumer callback = |
| 1830 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1831 | if (ar.exception != null) { |
| 1832 | loge("setSimPower exception: " + ar.exception); |
| 1833 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1834 | .RESULT_ERROR_UNKNOWN; |
| 1835 | if (ar.exception instanceof CommandException) { |
| 1836 | CommandException.Error error = |
| 1837 | ((CommandException) (ar.exception)).getCommandError(); |
| 1838 | if (error == CommandException.Error.SIM_ERR) { |
| 1839 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1840 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1841 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1842 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1843 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1844 | } else { |
| 1845 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1846 | } |
| 1847 | } |
| 1848 | try { |
| 1849 | callback.accept(errorCode); |
| 1850 | } catch (RemoteException e) { |
| 1851 | // Ignore if the remote process is no longer available to call back. |
| 1852 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1853 | } |
| 1854 | } else { |
| 1855 | try { |
| 1856 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1857 | } catch (RemoteException e) { |
| 1858 | // Ignore if the remote process is no longer available to call back. |
| 1859 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1860 | } |
| 1861 | } |
| 1862 | break; |
| 1863 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1864 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1865 | request = (MainThreadRequest) msg.obj; |
| 1866 | |
| 1867 | final Phone phone = getPhoneFromRequest(request); |
| 1868 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1869 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1870 | notifyRequester(request); |
| 1871 | break; |
| 1872 | } |
| 1873 | |
| 1874 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1875 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1876 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1877 | request); |
| 1878 | phone.getServiceStateTracker().setSignalStrengthUpdateRequest( |
| 1879 | request.subId, pair.first /*callingUid*/, |
| 1880 | pair.second /*request*/, onCompleted); |
| 1881 | break; |
| 1882 | } |
| 1883 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1884 | ar = (AsyncResult) msg.obj; |
| 1885 | request = (MainThreadRequest) ar.userObj; |
| 1886 | // request.result will be the exception of ar if present, true otherwise. |
| 1887 | // Be cautious not to leave result null which will wait() forever |
| 1888 | request.result = ar.exception != null ? ar.exception : true; |
| 1889 | notifyRequester(request); |
| 1890 | break; |
| 1891 | } |
| 1892 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1893 | request = (MainThreadRequest) msg.obj; |
| 1894 | |
| 1895 | Phone phone = getPhoneFromRequest(request); |
| 1896 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1897 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1898 | notifyRequester(request); |
| 1899 | break; |
| 1900 | } |
| 1901 | |
| 1902 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1903 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1904 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1905 | request); |
| 1906 | phone.getServiceStateTracker().clearSignalStrengthUpdateRequest( |
| 1907 | request.subId, pair.first /*callingUid*/, |
| 1908 | pair.second /*request*/, onCompleted); |
| 1909 | break; |
| 1910 | } |
| 1911 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1912 | ar = (AsyncResult) msg.obj; |
| 1913 | request = (MainThreadRequest) ar.userObj; |
| 1914 | request.result = ar.exception != null ? ar.exception : true; |
| 1915 | notifyRequester(request); |
| 1916 | break; |
| 1917 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1918 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame^] | 1919 | case CMD_GET_SLICING_CONFIG: { |
| 1920 | request = (MainThreadRequest) msg.obj; |
| 1921 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 1922 | request.phone.getSlicingConfig(onCompleted); |
| 1923 | break; |
| 1924 | } |
| 1925 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 1926 | ar = (AsyncResult) msg.obj; |
| 1927 | request = (MainThreadRequest) ar.userObj; |
| 1928 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1929 | |
| 1930 | SlicingConfig slicingConfig = null; |
| 1931 | Bundle bundle = new Bundle(); |
| 1932 | int resultCode = 0; |
| 1933 | if (ar.exception != null) { |
| 1934 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 1935 | + ar.exception); |
| 1936 | resultCode = TelephonyManager.SlicingException.ERROR_MODEM_ERROR; |
| 1937 | } else if (ar.result == null) { |
| 1938 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
| 1939 | resultCode = TelephonyManager.SlicingException.ERROR_TIMEOUT; |
| 1940 | } else { |
| 1941 | // use the result as returned |
| 1942 | resultCode = TelephonyManager.SlicingException.SUCCESS; |
| 1943 | slicingConfig = (SlicingConfig) ar.result; |
| 1944 | } |
| 1945 | |
| 1946 | if (slicingConfig == null) { |
| 1947 | slicingConfig = new SlicingConfig(); |
| 1948 | } |
| 1949 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 1950 | result.send(resultCode, bundle); |
| 1951 | notifyRequester(request); |
| 1952 | break; |
| 1953 | } |
| 1954 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1955 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 1956 | request = (MainThreadRequest) msg.obj; |
| 1957 | request.result = |
| 1958 | UiccController.getInstance().getPinStorage().prepareUnattendedReboot(); |
| 1959 | notifyRequester(request); |
| 1960 | break; |
| 1961 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1962 | default: |
| 1963 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1964 | break; |
| 1965 | } |
| 1966 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1967 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1968 | private void notifyRequester(MainThreadRequest request) { |
| 1969 | synchronized (request) { |
| 1970 | request.notifyAll(); |
| 1971 | } |
| 1972 | } |
| 1973 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1974 | private void handleNullReturnEvent(Message msg, String command) { |
| 1975 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1976 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1977 | if (ar.exception == null) { |
| 1978 | request.result = true; |
| 1979 | } else { |
| 1980 | request.result = false; |
| 1981 | if (ar.exception instanceof CommandException) { |
| 1982 | loge(command + ": CommandException: " + ar.exception); |
| 1983 | } else { |
| 1984 | loge(command + ": Unknown exception"); |
| 1985 | } |
| 1986 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1987 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1988 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1989 | } |
| 1990 | |
| 1991 | /** |
| 1992 | * Posts the specified command to be executed on the main thread, |
| 1993 | * waits for the request to complete, and returns the result. |
| 1994 | * @see #sendRequestAsync |
| 1995 | */ |
| 1996 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1997 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 1998 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | /** |
| 2002 | * Posts the specified command to be executed on the main thread, |
| 2003 | * waits for the request to complete, and returns the result. |
| 2004 | * @see #sendRequestAsync |
| 2005 | */ |
| 2006 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2007 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2008 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2009 | } |
| 2010 | |
| 2011 | /** |
| 2012 | * Posts the specified command to be executed on the main thread, |
| 2013 | * waits for the request to complete, and returns the result. |
| 2014 | * @see #sendRequestAsync |
| 2015 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2016 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2017 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2018 | } |
| 2019 | |
| 2020 | /** |
| 2021 | * Posts the specified command to be executed on the main thread, |
| 2022 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2023 | * if not timeout or null otherwise. |
| 2024 | * @see #sendRequestAsync |
| 2025 | */ |
| 2026 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2027 | long timeoutInMs) { |
| 2028 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2029 | } |
| 2030 | |
| 2031 | /** |
| 2032 | * Posts the specified command to be executed on the main thread, |
| 2033 | * waits for the request to complete, and returns the result. |
| 2034 | * @see #sendRequestAsync |
| 2035 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2036 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2037 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2038 | } |
| 2039 | |
| 2040 | /** |
| 2041 | * Posts the specified command to be executed on the main thread, |
| 2042 | * waits for the request to complete, and returns the result. |
| 2043 | * @see #sendRequestAsync |
| 2044 | */ |
| 2045 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2046 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2047 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2048 | } |
| 2049 | |
| 2050 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2051 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2052 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2053 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2054 | * @see #sendRequestAsync |
| 2055 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2056 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2057 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2058 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2059 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2060 | } |
| 2061 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2062 | MainThreadRequest request = null; |
| 2063 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2064 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2065 | } else if (phone != null) { |
| 2066 | request = new MainThreadRequest(argument, phone, workSource); |
| 2067 | } else { |
| 2068 | request = new MainThreadRequest(argument, subId, workSource); |
| 2069 | } |
| 2070 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2071 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2072 | msg.sendToTarget(); |
| 2073 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2074 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2075 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2076 | if (timeoutInMs >= 0) { |
| 2077 | // Wait for at least timeoutInMs before returning null request result |
| 2078 | long now = SystemClock.elapsedRealtime(); |
| 2079 | long deadline = now + timeoutInMs; |
| 2080 | while (request == null && now < deadline) { |
| 2081 | try { |
| 2082 | request.wait(deadline - now); |
| 2083 | } catch (InterruptedException e) { |
| 2084 | // Do nothing, go back and check if request is completed or timeout |
| 2085 | } finally { |
| 2086 | now = SystemClock.elapsedRealtime(); |
| 2087 | } |
| 2088 | } |
| 2089 | } else { |
| 2090 | // Wait for the request to complete |
| 2091 | while (request.result == null) { |
| 2092 | try { |
| 2093 | request.wait(); |
| 2094 | } catch (InterruptedException e) { |
| 2095 | // Do nothing, go back and wait until the request is complete |
| 2096 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2097 | } |
| 2098 | } |
| 2099 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2100 | if (request.result == null) { |
| 2101 | Log.wtf(LOG_TAG, |
| 2102 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2103 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2104 | return request.result; |
| 2105 | } |
| 2106 | |
| 2107 | /** |
| 2108 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2109 | * Posts the specified command to be executed on the main thread, and |
| 2110 | * returns immediately. |
| 2111 | * @see #sendRequest |
| 2112 | */ |
| 2113 | private void sendRequestAsync(int command) { |
| 2114 | mMainThreadHandler.sendEmptyMessage(command); |
| 2115 | } |
| 2116 | |
| 2117 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2118 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2119 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2120 | */ |
| 2121 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2122 | sendRequestAsync(command, argument, null, null); |
| 2123 | } |
| 2124 | |
| 2125 | /** |
| 2126 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2127 | * @see {@link #sendRequest(int,Object)} |
| 2128 | */ |
| 2129 | private void sendRequestAsync( |
| 2130 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2131 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2132 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2133 | msg.sendToTarget(); |
| 2134 | } |
| 2135 | |
| 2136 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2137 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2138 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2139 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2140 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2141 | synchronized (PhoneInterfaceManager.class) { |
| 2142 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2143 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2144 | } else { |
| 2145 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2146 | } |
| 2147 | return sInstance; |
| 2148 | } |
| 2149 | } |
| 2150 | |
| 2151 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2152 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2153 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2154 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 2155 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2156 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2157 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2158 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2159 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2160 | mTelephonySharedPreferences = |
| 2161 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2162 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2163 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2164 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2165 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2166 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2167 | publish(); |
| 2168 | } |
| 2169 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2170 | private Phone getDefaultPhone() { |
| 2171 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2172 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2173 | } |
| 2174 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2175 | private void publish() { |
| 2176 | if (DBG) log("publish: " + this); |
| 2177 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2178 | TelephonyFrameworkInitializer |
| 2179 | .getTelephonyServiceManager() |
| 2180 | .getTelephonyServiceRegisterer() |
| 2181 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2182 | } |
| 2183 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2184 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2185 | if (request.phone != null) { |
| 2186 | return request.phone; |
| 2187 | } else { |
| 2188 | return getPhoneFromSubId(request.subId); |
| 2189 | } |
| 2190 | } |
| 2191 | |
| 2192 | private Phone getPhoneFromSubId(int subId) { |
| 2193 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2194 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2195 | } |
| 2196 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2197 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 2198 | Phone phone = getPhoneFromRequest(request); |
| 2199 | return phone == null ? null : |
| 2200 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 2201 | } |
| 2202 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2203 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2204 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2205 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2206 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2207 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2208 | private void sendEraseModemConfig(Phone phone) { |
| 2209 | if (phone != null) { |
| 2210 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2211 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 2212 | final long identity = Binder.clearCallingIdentity(); |
| 2213 | try { |
| 2214 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2215 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2216 | } finally { |
| 2217 | Binder.restoreCallingIdentity(identity); |
| 2218 | } |
| 2219 | } |
| 2220 | } |
| 2221 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2222 | private boolean isImsAvailableOnDevice() { |
| 2223 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2224 | if (pm == null) { |
| 2225 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2226 | // so do not throw error and allow. |
| 2227 | return true; |
| 2228 | } |
| 2229 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2230 | } |
| 2231 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2232 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2233 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2234 | } |
| 2235 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2236 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2237 | if (DBG) log("dial: " + number); |
| 2238 | // No permission check needed here: This is just a wrapper around the |
| 2239 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2240 | // the UI before it does anything. |
| 2241 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2242 | final long identity = Binder.clearCallingIdentity(); |
| 2243 | try { |
| 2244 | String url = createTelUrl(number); |
| 2245 | if (url == null) { |
| 2246 | return; |
| 2247 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2248 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2249 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2250 | PhoneConstants.State state = mCM.getState(subId); |
| 2251 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2252 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2253 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2254 | mApp.startActivity(intent); |
| 2255 | } |
| 2256 | } finally { |
| 2257 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2258 | } |
| 2259 | } |
| 2260 | |
| 2261 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2262 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2263 | } |
| 2264 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2265 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2266 | if (DBG) log("call: " + number); |
| 2267 | |
| 2268 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2269 | // need to do a permission check since we're calling startActivity() |
| 2270 | // from the context of the phone app. |
| 2271 | enforceCallPermission(); |
| 2272 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2273 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2274 | != AppOpsManager.MODE_ALLOWED) { |
| 2275 | return; |
| 2276 | } |
| 2277 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2278 | final long identity = Binder.clearCallingIdentity(); |
| 2279 | try { |
| 2280 | String url = createTelUrl(number); |
| 2281 | if (url == null) { |
| 2282 | return; |
| 2283 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2284 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2285 | boolean isValid = false; |
| 2286 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2287 | if (slist != null) { |
| 2288 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2289 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2290 | isValid = true; |
| 2291 | break; |
| 2292 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2293 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2294 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2295 | if (!isValid) { |
| 2296 | return; |
| 2297 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2298 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2299 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2300 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2301 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2302 | mApp.startActivity(intent); |
| 2303 | } finally { |
| 2304 | Binder.restoreCallingIdentity(identity); |
| 2305 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2306 | } |
| 2307 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2308 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2309 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2310 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2311 | } |
| 2312 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2313 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2314 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2315 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2316 | } |
| 2317 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2318 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2319 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2320 | |
| 2321 | final long identity = Binder.clearCallingIdentity(); |
| 2322 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2323 | Phone phone = getPhone(subId); |
| 2324 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2325 | checkSimPin.start(); |
| 2326 | return checkSimPin.unlockSim(null, pin); |
| 2327 | } finally { |
| 2328 | Binder.restoreCallingIdentity(identity); |
| 2329 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2330 | } |
| 2331 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2332 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2333 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2334 | |
| 2335 | final long identity = Binder.clearCallingIdentity(); |
| 2336 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2337 | Phone phone = getPhone(subId); |
| 2338 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2339 | checkSimPuk.start(); |
| 2340 | return checkSimPuk.unlockSim(puk, pin); |
| 2341 | } finally { |
| 2342 | Binder.restoreCallingIdentity(identity); |
| 2343 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2344 | } |
| 2345 | |
| 2346 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2347 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2348 | * a synchronous one. |
| 2349 | */ |
| 2350 | private static class UnlockSim extends Thread { |
| 2351 | |
| 2352 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2353 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2354 | |
| 2355 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2356 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2357 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2358 | |
| 2359 | // For replies from SimCard interface |
| 2360 | private Handler mHandler; |
| 2361 | |
| 2362 | // For async handler to identify request type |
| 2363 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2364 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2365 | UnlockSim(int phoneId, IccCard simCard) { |
| 2366 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2367 | mSimCard = simCard; |
| 2368 | } |
| 2369 | |
| 2370 | @Override |
| 2371 | public void run() { |
| 2372 | Looper.prepare(); |
| 2373 | synchronized (UnlockSim.this) { |
| 2374 | mHandler = new Handler() { |
| 2375 | @Override |
| 2376 | public void handleMessage(Message msg) { |
| 2377 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2378 | switch (msg.what) { |
| 2379 | case SUPPLY_PIN_COMPLETE: |
| 2380 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2381 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2382 | mRetryCount = msg.arg1; |
| 2383 | if (ar.exception != null) { |
| 2384 | if (ar.exception instanceof CommandException && |
| 2385 | ((CommandException)(ar.exception)).getCommandError() |
| 2386 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2387 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2388 | } //When UiccCardApp dispose,handle message and return exception |
| 2389 | else if (ar.exception instanceof CommandException && |
| 2390 | ((CommandException) (ar.exception)).getCommandError() |
| 2391 | == CommandException.Error.ABORTED) { |
| 2392 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2393 | } else { |
| 2394 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2395 | } |
| 2396 | } else { |
| 2397 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2398 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2399 | mDone = true; |
| 2400 | UnlockSim.this.notifyAll(); |
| 2401 | } |
| 2402 | break; |
| 2403 | } |
| 2404 | } |
| 2405 | }; |
| 2406 | UnlockSim.this.notifyAll(); |
| 2407 | } |
| 2408 | Looper.loop(); |
| 2409 | } |
| 2410 | |
| 2411 | /* |
| 2412 | * Use PIN or PUK to unlock SIM card |
| 2413 | * |
| 2414 | * If PUK is null, unlock SIM card with PIN |
| 2415 | * |
| 2416 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2417 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2418 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2419 | |
| 2420 | while (mHandler == null) { |
| 2421 | try { |
| 2422 | wait(); |
| 2423 | } catch (InterruptedException e) { |
| 2424 | Thread.currentThread().interrupt(); |
| 2425 | } |
| 2426 | } |
| 2427 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2428 | |
| 2429 | if (puk == null) { |
| 2430 | mSimCard.supplyPin(pin, callback); |
| 2431 | } else { |
| 2432 | mSimCard.supplyPuk(puk, pin, callback); |
| 2433 | } |
| 2434 | |
| 2435 | while (!mDone) { |
| 2436 | try { |
| 2437 | Log.d(LOG_TAG, "wait for done"); |
| 2438 | wait(); |
| 2439 | } catch (InterruptedException e) { |
| 2440 | // Restore the interrupted status |
| 2441 | Thread.currentThread().interrupt(); |
| 2442 | } |
| 2443 | } |
| 2444 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2445 | int[] resultArray = new int[2]; |
| 2446 | resultArray[0] = mResult; |
| 2447 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2448 | |
| 2449 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
| 2450 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
| 2451 | } |
| 2452 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2453 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2454 | } |
| 2455 | } |
| 2456 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2457 | /** |
| 2458 | * This method has been removed due to privacy and stability concerns. |
| 2459 | */ |
| 2460 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2461 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2462 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2463 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2464 | } |
| 2465 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2466 | @Override |
| 2467 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2468 | mApp.getSystemService(AppOpsManager.class) |
| 2469 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2470 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2471 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2472 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2473 | // Callers targeting S have no business invoking this method. |
| 2474 | return; |
| 2475 | } |
| 2476 | |
| 2477 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2478 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2479 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2480 | .setCallingPackage(callingPackage) |
| 2481 | .setCallingFeatureId(null) |
| 2482 | .setCallingPid(Binder.getCallingPid()) |
| 2483 | .setCallingUid(Binder.getCallingUid()) |
| 2484 | .setMethod("updateServiceLocation") |
| 2485 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2486 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2487 | .build()); |
| 2488 | // Apps that lack location permission have no business calling this method; |
| 2489 | // however, because no permission was declared in the public API, denials must |
| 2490 | // all be "soft". |
| 2491 | switch (locationResult) { |
| 2492 | case DENIED_HARD: /* fall through */ |
| 2493 | case DENIED_SOFT: |
| 2494 | return; |
| 2495 | } |
| 2496 | |
| 2497 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2498 | final long identity = Binder.clearCallingIdentity(); |
| 2499 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2500 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2501 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2502 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2503 | } |
| 2504 | } finally { |
| 2505 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2506 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2507 | } |
| 2508 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2509 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2510 | @Override |
| 2511 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2512 | return isRadioOnWithFeature(callingPackage, null); |
| 2513 | } |
| 2514 | |
| 2515 | |
| 2516 | @Override |
| 2517 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2518 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2519 | callingFeatureId); |
| 2520 | } |
| 2521 | |
| 2522 | @Deprecated |
| 2523 | @Override |
| 2524 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2525 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2526 | } |
| 2527 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2528 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2529 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2530 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2531 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2532 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2533 | return false; |
| 2534 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2535 | |
| 2536 | final long identity = Binder.clearCallingIdentity(); |
| 2537 | try { |
| 2538 | return isRadioOnForSubscriber(subId); |
| 2539 | } finally { |
| 2540 | Binder.restoreCallingIdentity(identity); |
| 2541 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2542 | } |
| 2543 | |
| 2544 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2545 | final long identity = Binder.clearCallingIdentity(); |
| 2546 | try { |
| 2547 | final Phone phone = getPhone(subId); |
| 2548 | if (phone != null) { |
| 2549 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2550 | } else { |
| 2551 | return false; |
| 2552 | } |
| 2553 | } finally { |
| 2554 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2555 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2556 | } |
| 2557 | |
| 2558 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2559 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2560 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2561 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2562 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2563 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2564 | |
| 2565 | final long identity = Binder.clearCallingIdentity(); |
| 2566 | try { |
| 2567 | final Phone phone = getPhone(subId); |
| 2568 | if (phone != null) { |
| 2569 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2570 | } |
| 2571 | } finally { |
| 2572 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2573 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2574 | } |
| 2575 | |
| 2576 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2577 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2578 | } |
| 2579 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2580 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2581 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2582 | |
| 2583 | final long identity = Binder.clearCallingIdentity(); |
| 2584 | try { |
| 2585 | final Phone phone = getPhone(subId); |
| 2586 | if (phone == null) { |
| 2587 | return false; |
| 2588 | } |
| 2589 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2590 | toggleRadioOnOffForSubscriber(subId); |
| 2591 | } |
| 2592 | return true; |
| 2593 | } finally { |
| 2594 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2595 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2596 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2597 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2598 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2599 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2600 | /* |
| 2601 | * If any of the Radios are available, it will need to be |
| 2602 | * shutdown. So return true if any Radio is available. |
| 2603 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2604 | final long identity = Binder.clearCallingIdentity(); |
| 2605 | try { |
| 2606 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2607 | Phone phone = PhoneFactory.getPhone(i); |
| 2608 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2609 | } |
| 2610 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2611 | return false; |
| 2612 | } finally { |
| 2613 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2614 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2615 | } |
| 2616 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2617 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2618 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2619 | enforceModifyPermission(); |
| 2620 | |
| 2621 | final long identity = Binder.clearCallingIdentity(); |
| 2622 | try { |
| 2623 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2624 | logv("Shutting down Phone " + i); |
| 2625 | shutdownRadioUsingPhoneId(i); |
| 2626 | } |
| 2627 | } finally { |
| 2628 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2629 | } |
| 2630 | } |
| 2631 | |
| 2632 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2633 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2634 | if (phone != null && phone.isRadioAvailable()) { |
| 2635 | phone.shutdownRadio(); |
| 2636 | } |
| 2637 | } |
| 2638 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2639 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2640 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2641 | |
| 2642 | final long identity = Binder.clearCallingIdentity(); |
| 2643 | try { |
| 2644 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2645 | if (defaultPhone != null) { |
| 2646 | defaultPhone.setRadioPower(turnOn); |
| 2647 | return true; |
| 2648 | } else { |
| 2649 | loge("There's no default phone."); |
| 2650 | return false; |
| 2651 | } |
| 2652 | } finally { |
| 2653 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2654 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2655 | } |
| 2656 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2657 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2658 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2659 | |
| 2660 | final long identity = Binder.clearCallingIdentity(); |
| 2661 | try { |
| 2662 | final Phone phone = getPhone(subId); |
| 2663 | if (phone != null) { |
| 2664 | phone.setRadioPower(turnOn); |
| 2665 | return true; |
| 2666 | } else { |
| 2667 | return false; |
| 2668 | } |
| 2669 | } finally { |
| 2670 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2671 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2672 | } |
| 2673 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2674 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2675 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2676 | public boolean enableDataConnectivity() { |
| 2677 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2678 | |
| 2679 | final long identity = Binder.clearCallingIdentity(); |
| 2680 | try { |
| 2681 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2682 | final Phone phone = getPhone(subId); |
| 2683 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2684 | phone.getDataEnabledSettings().setDataEnabled( |
| 2685 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2686 | return true; |
| 2687 | } else { |
| 2688 | return false; |
| 2689 | } |
| 2690 | } finally { |
| 2691 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2692 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2693 | } |
| 2694 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2695 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2696 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2697 | public boolean disableDataConnectivity() { |
| 2698 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2699 | |
| 2700 | final long identity = Binder.clearCallingIdentity(); |
| 2701 | try { |
| 2702 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2703 | final Phone phone = getPhone(subId); |
| 2704 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2705 | phone.getDataEnabledSettings().setDataEnabled( |
| 2706 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2707 | return true; |
| 2708 | } else { |
| 2709 | return false; |
| 2710 | } |
| 2711 | } finally { |
| 2712 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2713 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2714 | } |
| 2715 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2716 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2717 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2718 | final long identity = Binder.clearCallingIdentity(); |
| 2719 | try { |
| 2720 | final Phone phone = getPhone(subId); |
| 2721 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2722 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2723 | } else { |
| 2724 | return false; |
| 2725 | } |
| 2726 | } finally { |
| 2727 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2728 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2729 | } |
| 2730 | |
| 2731 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2732 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2733 | } |
| 2734 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2735 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2736 | enforceCallPermission(); |
| 2737 | |
| 2738 | final long identity = Binder.clearCallingIdentity(); |
| 2739 | try { |
| 2740 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2741 | return; |
| 2742 | } |
| 2743 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2744 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2745 | } finally { |
| 2746 | Binder.restoreCallingIdentity(identity); |
| 2747 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2748 | }; |
| 2749 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2750 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2751 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2752 | |
| 2753 | final long identity = Binder.clearCallingIdentity(); |
| 2754 | try { |
| 2755 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2756 | return false; |
| 2757 | } |
| 2758 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2759 | } finally { |
| 2760 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2761 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2762 | } |
| 2763 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2764 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2765 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2766 | } |
| 2767 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2768 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2769 | final long identity = Binder.clearCallingIdentity(); |
| 2770 | try { |
| 2771 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2772 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2773 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2774 | } finally { |
| 2775 | Binder.restoreCallingIdentity(identity); |
| 2776 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2777 | } |
| 2778 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2779 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2780 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2781 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2782 | } |
| 2783 | |
| 2784 | @Override |
| 2785 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2786 | final long identity = Binder.clearCallingIdentity(); |
| 2787 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2788 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2789 | if (phone != null) { |
| 2790 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2791 | } else { |
| 2792 | return PhoneConstantConversions.convertDataState( |
| 2793 | PhoneConstants.DataState.DISCONNECTED); |
| 2794 | } |
| 2795 | } finally { |
| 2796 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2797 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2798 | } |
| 2799 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2800 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2801 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2802 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2803 | } |
| 2804 | |
| 2805 | @Override |
| 2806 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2807 | final long identity = Binder.clearCallingIdentity(); |
| 2808 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2809 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2810 | if (phone != null) { |
| 2811 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2812 | } else { |
| 2813 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2814 | } |
| 2815 | } finally { |
| 2816 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2817 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2818 | } |
| 2819 | |
| 2820 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2821 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2822 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2823 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2824 | |
| 2825 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2826 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2827 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2828 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2829 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2830 | .setCallingPid(Binder.getCallingPid()) |
| 2831 | .setCallingUid(Binder.getCallingUid()) |
| 2832 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2833 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2834 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2835 | .build()); |
| 2836 | switch (locationResult) { |
| 2837 | case DENIED_HARD: |
| 2838 | throw new SecurityException("Not allowed to access cell location"); |
| 2839 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2840 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2841 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2842 | } |
| 2843 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2844 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2845 | final long identity = Binder.clearCallingIdentity(); |
| 2846 | try { |
| 2847 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2848 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2849 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2850 | } finally { |
| 2851 | Binder.restoreCallingIdentity(identity); |
| 2852 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2853 | } |
| 2854 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2855 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2856 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2857 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2858 | // registered cell info, so return a NULL country instead. |
| 2859 | final long identity = Binder.clearCallingIdentity(); |
| 2860 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2861 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2862 | // Get default phone in this case. |
| 2863 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2864 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2865 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2866 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2867 | if (phone == null) return ""; |
| 2868 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2869 | if (sst == null) return ""; |
| 2870 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2871 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 2872 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2873 | } finally { |
| 2874 | Binder.restoreCallingIdentity(identity); |
| 2875 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2876 | } |
| 2877 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2878 | /** |
| 2879 | * This method was removed due to potential issues caused by performing partial |
| 2880 | * updates of service state, and lack of a credible use case. |
| 2881 | * |
| 2882 | * This has the ability to break the telephony implementation by disabling notification of |
| 2883 | * changes in device connectivity. DO NOT USE THIS! |
| 2884 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2885 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2886 | public void enableLocationUpdates() { |
| 2887 | mApp.enforceCallingOrSelfPermission( |
| 2888 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2889 | } |
| 2890 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2891 | /** |
| 2892 | * This method was removed due to potential issues caused by performing partial |
| 2893 | * updates of service state, and lack of a credible use case. |
| 2894 | * |
| 2895 | * This has the ability to break the telephony implementation by disabling notification of |
| 2896 | * changes in device connectivity. DO NOT USE THIS! |
| 2897 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2898 | @Override |
| 2899 | public void disableLocationUpdates() { |
| 2900 | mApp.enforceCallingOrSelfPermission( |
| 2901 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2902 | } |
| 2903 | |
| 2904 | @Override |
| 2905 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2906 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2907 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2908 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2909 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2910 | throw new SecurityException( |
| 2911 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2912 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2913 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2914 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2915 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2916 | return null; |
| 2917 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2918 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2919 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2920 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2921 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2922 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2923 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2924 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2925 | for (CellInfo ci : info) { |
| 2926 | if (ci instanceof CellInfoGsm) { |
| 2927 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2928 | } else if (ci instanceof CellInfoWcdma) { |
| 2929 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2930 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2931 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2932 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2933 | } |
| 2934 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2935 | private List<CellInfo> getCachedCellInfo() { |
| 2936 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2937 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2938 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2939 | if (info != null) cellInfos.addAll(info); |
| 2940 | } |
| 2941 | return cellInfos; |
| 2942 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2943 | |
| 2944 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2945 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2946 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2947 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2948 | |
| 2949 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2950 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2951 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2952 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2953 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2954 | .setCallingPid(Binder.getCallingPid()) |
| 2955 | .setCallingUid(Binder.getCallingUid()) |
| 2956 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2957 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2958 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2959 | .build()); |
| 2960 | switch (locationResult) { |
| 2961 | case DENIED_HARD: |
| 2962 | throw new SecurityException("Not allowed to access cell info"); |
| 2963 | case DENIED_SOFT: |
| 2964 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2965 | } |
| 2966 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2967 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2968 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2969 | return getCachedCellInfo(); |
| 2970 | } |
| 2971 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2972 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2973 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2974 | final long identity = Binder.clearCallingIdentity(); |
| 2975 | try { |
| 2976 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2977 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2978 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2979 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2980 | if (info != null) cellInfos.addAll(info); |
| 2981 | } |
| 2982 | return cellInfos; |
| 2983 | } finally { |
| 2984 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2985 | } |
| 2986 | } |
| 2987 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2988 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2989 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2990 | String callingFeatureId) { |
| 2991 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2992 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2993 | } |
| 2994 | |
| 2995 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2996 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2997 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2998 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2999 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3000 | } |
| 3001 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3002 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3003 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3004 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3005 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3006 | |
| 3007 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3008 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3009 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3010 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3011 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3012 | .setCallingPid(Binder.getCallingPid()) |
| 3013 | .setCallingUid(Binder.getCallingUid()) |
| 3014 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3015 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3016 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3017 | .build()); |
| 3018 | switch (locationResult) { |
| 3019 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3020 | if (TelephonyPermissions |
| 3021 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3022 | // Safetynet logging for b/154934934 |
| 3023 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3024 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3025 | throw new SecurityException("Not allowed to access cell info"); |
| 3026 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3027 | if (TelephonyPermissions |
| 3028 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3029 | // Safetynet logging for b/154934934 |
| 3030 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3031 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3032 | try { |
| 3033 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3034 | } catch (RemoteException re) { |
| 3035 | // Drop without consequences |
| 3036 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3037 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3038 | } |
| 3039 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3040 | |
| 3041 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3042 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3043 | |
| 3044 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3045 | } |
| 3046 | |
| 3047 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3048 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3049 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3050 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3051 | |
| 3052 | final long identity = Binder.clearCallingIdentity(); |
| 3053 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3054 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3055 | } finally { |
| 3056 | Binder.restoreCallingIdentity(identity); |
| 3057 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3058 | } |
| 3059 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3060 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3061 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3062 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3063 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3064 | return null; |
| 3065 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3066 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3067 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3068 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3069 | return null; |
| 3070 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3071 | |
| 3072 | final long identity = Binder.clearCallingIdentity(); |
| 3073 | try { |
| 3074 | return phone.getImei(); |
| 3075 | } finally { |
| 3076 | Binder.restoreCallingIdentity(identity); |
| 3077 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3078 | } |
| 3079 | |
| 3080 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3081 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3082 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3083 | String tac = null; |
| 3084 | if (phone != null) { |
| 3085 | String imei = phone.getImei(); |
| 3086 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3087 | } |
| 3088 | return tac; |
| 3089 | } |
| 3090 | |
| 3091 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3092 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3093 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3094 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3095 | return null; |
| 3096 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3097 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3098 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3099 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3100 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3101 | return null; |
| 3102 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3103 | |
| 3104 | final long identity = Binder.clearCallingIdentity(); |
| 3105 | try { |
| 3106 | return phone.getMeid(); |
| 3107 | } finally { |
| 3108 | Binder.restoreCallingIdentity(identity); |
| 3109 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3110 | } |
| 3111 | |
| 3112 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3113 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3114 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3115 | String manufacturerCode = null; |
| 3116 | if (phone != null) { |
| 3117 | String meid = phone.getMeid(); |
| 3118 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3119 | } |
| 3120 | return manufacturerCode; |
| 3121 | } |
| 3122 | |
| 3123 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3124 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3125 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3126 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3127 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3128 | return null; |
| 3129 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3130 | int subId = phone.getSubId(); |
| 3131 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3132 | mApp, subId, callingPackage, callingFeatureId, |
| 3133 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3134 | return null; |
| 3135 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3136 | |
| 3137 | final long identity = Binder.clearCallingIdentity(); |
| 3138 | try { |
| 3139 | return phone.getDeviceSvn(); |
| 3140 | } finally { |
| 3141 | Binder.restoreCallingIdentity(identity); |
| 3142 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3143 | } |
| 3144 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3145 | @Override |
| 3146 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3147 | final long identity = Binder.clearCallingIdentity(); |
| 3148 | try { |
| 3149 | final Phone phone = getPhone(subId); |
| 3150 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3151 | } finally { |
| 3152 | Binder.restoreCallingIdentity(identity); |
| 3153 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3154 | } |
| 3155 | |
| 3156 | @Override |
| 3157 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3158 | final long identity = Binder.clearCallingIdentity(); |
| 3159 | try { |
| 3160 | final Phone phone = getPhone(subId); |
| 3161 | return phone == null ? null : phone.getCarrierName(); |
| 3162 | } finally { |
| 3163 | Binder.restoreCallingIdentity(identity); |
| 3164 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3165 | } |
| 3166 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3167 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3168 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3169 | final long identity = Binder.clearCallingIdentity(); |
| 3170 | try { |
| 3171 | final Phone phone = getPhone(subId); |
| 3172 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3173 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3174 | } finally { |
| 3175 | Binder.restoreCallingIdentity(identity); |
| 3176 | } |
| 3177 | } |
| 3178 | |
| 3179 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3180 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3181 | final long identity = Binder.clearCallingIdentity(); |
| 3182 | try { |
| 3183 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3184 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3185 | } finally { |
| 3186 | Binder.restoreCallingIdentity(identity); |
| 3187 | } |
| 3188 | } |
| 3189 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3190 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3191 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3192 | if (!isSubscriptionMccMnc) { |
| 3193 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3194 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3195 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3196 | if (phone == null) { |
| 3197 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3198 | } |
| 3199 | final long identity = Binder.clearCallingIdentity(); |
| 3200 | try { |
| 3201 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3202 | } finally { |
| 3203 | Binder.restoreCallingIdentity(identity); |
| 3204 | } |
| 3205 | } |
| 3206 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3207 | // |
| 3208 | // Internal helper methods. |
| 3209 | // |
| 3210 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3211 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3212 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3213 | * |
| 3214 | * @throws SecurityException if the caller does not have the required permission |
| 3215 | */ |
| 3216 | private void enforceModifyPermission() { |
| 3217 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3218 | } |
| 3219 | |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3220 | /** |
| 3221 | * Make sure the caller is system. |
| 3222 | * |
| 3223 | * @throws SecurityException if the caller is not system. |
| 3224 | */ |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 3225 | private static void enforceSystemCaller() { |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3226 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 3227 | throw new SecurityException("Caller must be system"); |
| 3228 | } |
| 3229 | } |
| 3230 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3231 | private void enforceActiveEmergencySessionPermission() { |
| 3232 | mApp.enforceCallingOrSelfPermission( |
| 3233 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3234 | } |
| 3235 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3236 | /** |
| 3237 | * Make sure the caller has the CALL_PHONE permission. |
| 3238 | * |
| 3239 | * @throws SecurityException if the caller does not have the required permission |
| 3240 | */ |
| 3241 | private void enforceCallPermission() { |
| 3242 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3243 | } |
| 3244 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3245 | private void enforceSettingsPermission() { |
| 3246 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3247 | } |
| 3248 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3249 | private void enforceRebootPermission() { |
| 3250 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3251 | } |
| 3252 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3253 | private String createTelUrl(String number) { |
| 3254 | if (TextUtils.isEmpty(number)) { |
| 3255 | return null; |
| 3256 | } |
| 3257 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3258 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3259 | } |
| 3260 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3261 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3262 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3263 | } |
| 3264 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3265 | private static void logv(String msg) { |
| 3266 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3267 | } |
| 3268 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3269 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3270 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3271 | } |
| 3272 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3273 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3274 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3275 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3276 | } |
| 3277 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3278 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3279 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3280 | final long identity = Binder.clearCallingIdentity(); |
| 3281 | try { |
| 3282 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3283 | if (phone == null) { |
| 3284 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3285 | } else { |
| 3286 | return phone.getPhoneType(); |
| 3287 | } |
| 3288 | } finally { |
| 3289 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3290 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3291 | } |
| 3292 | |
| 3293 | /** |
| 3294 | * Returns the CDMA ERI icon index to display |
| 3295 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3296 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3297 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3298 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3299 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3300 | } |
| 3301 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3302 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3303 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3304 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3305 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3306 | mApp, subId, callingPackage, callingFeatureId, |
| 3307 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3308 | return -1; |
| 3309 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3310 | |
| 3311 | final long identity = Binder.clearCallingIdentity(); |
| 3312 | try { |
| 3313 | final Phone phone = getPhone(subId); |
| 3314 | if (phone != null) { |
| 3315 | return phone.getCdmaEriIconIndex(); |
| 3316 | } else { |
| 3317 | return -1; |
| 3318 | } |
| 3319 | } finally { |
| 3320 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3321 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3322 | } |
| 3323 | |
| 3324 | /** |
| 3325 | * Returns the CDMA ERI icon mode, |
| 3326 | * 0 - ON |
| 3327 | * 1 - FLASHING |
| 3328 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3329 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3330 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3331 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3332 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3333 | } |
| 3334 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3335 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3336 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3337 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3338 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3339 | mApp, subId, callingPackage, callingFeatureId, |
| 3340 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3341 | return -1; |
| 3342 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3343 | |
| 3344 | final long identity = Binder.clearCallingIdentity(); |
| 3345 | try { |
| 3346 | final Phone phone = getPhone(subId); |
| 3347 | if (phone != null) { |
| 3348 | return phone.getCdmaEriIconMode(); |
| 3349 | } else { |
| 3350 | return -1; |
| 3351 | } |
| 3352 | } finally { |
| 3353 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3354 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3355 | } |
| 3356 | |
| 3357 | /** |
| 3358 | * Returns the CDMA ERI text, |
| 3359 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3360 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3361 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3362 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3363 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3364 | } |
| 3365 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3366 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3367 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3368 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3369 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3370 | mApp, subId, callingPackage, callingFeatureId, |
| 3371 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3372 | return null; |
| 3373 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3374 | |
| 3375 | final long identity = Binder.clearCallingIdentity(); |
| 3376 | try { |
| 3377 | final Phone phone = getPhone(subId); |
| 3378 | if (phone != null) { |
| 3379 | return phone.getCdmaEriText(); |
| 3380 | } else { |
| 3381 | return null; |
| 3382 | } |
| 3383 | } finally { |
| 3384 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3385 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3386 | } |
| 3387 | |
| 3388 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3389 | * Returns the CDMA MDN. |
| 3390 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3391 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3392 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3393 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3394 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3395 | |
| 3396 | final long identity = Binder.clearCallingIdentity(); |
| 3397 | try { |
| 3398 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3399 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3400 | return phone.getLine1Number(); |
| 3401 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3402 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3403 | return null; |
| 3404 | } |
| 3405 | } finally { |
| 3406 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3407 | } |
| 3408 | } |
| 3409 | |
| 3410 | /** |
| 3411 | * Returns the CDMA MIN. |
| 3412 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3413 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3414 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3415 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3416 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3417 | |
| 3418 | final long identity = Binder.clearCallingIdentity(); |
| 3419 | try { |
| 3420 | final Phone phone = getPhone(subId); |
| 3421 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3422 | return phone.getCdmaMin(); |
| 3423 | } else { |
| 3424 | return null; |
| 3425 | } |
| 3426 | } finally { |
| 3427 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3428 | } |
| 3429 | } |
| 3430 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3431 | @Override |
| 3432 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3433 | INumberVerificationCallback callback, String callingPackage) { |
| 3434 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3435 | != PERMISSION_GRANTED) { |
| 3436 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3437 | } |
| 3438 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3439 | |
| 3440 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3441 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3442 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3443 | + "calling package: " + callingPackage |
| 3444 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3445 | } |
| 3446 | |
| 3447 | if (range == null) { |
| 3448 | throw new NullPointerException("Range must be non-null"); |
| 3449 | } |
| 3450 | |
| 3451 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3452 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3453 | |
| 3454 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3455 | } |
| 3456 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3457 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3458 | * Returns true if CDMA provisioning needs to run. |
| 3459 | */ |
| 3460 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3461 | final long identity = Binder.clearCallingIdentity(); |
| 3462 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3463 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3464 | } finally { |
| 3465 | Binder.restoreCallingIdentity(identity); |
| 3466 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3467 | } |
| 3468 | |
| 3469 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3470 | * Sets the voice mail number of a given subId. |
| 3471 | */ |
| 3472 | @Override |
| 3473 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3474 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3475 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3476 | |
| 3477 | final long identity = Binder.clearCallingIdentity(); |
| 3478 | try { |
| 3479 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3480 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3481 | return success; |
| 3482 | } finally { |
| 3483 | Binder.restoreCallingIdentity(identity); |
| 3484 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3485 | } |
| 3486 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3487 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3488 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3489 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3490 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3491 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3492 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3493 | throw new SecurityException("caller must be system dialer"); |
| 3494 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3495 | |
| 3496 | final long identity = Binder.clearCallingIdentity(); |
| 3497 | try { |
| 3498 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3499 | if (phoneAccountHandle == null) { |
| 3500 | return null; |
| 3501 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3502 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3503 | } finally { |
| 3504 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3505 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3506 | } |
| 3507 | |
| 3508 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3509 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3510 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3511 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3512 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3513 | mApp, subId, callingPackage, callingFeatureId, |
| 3514 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3515 | return null; |
| 3516 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3517 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3518 | final long identity = Binder.clearCallingIdentity(); |
| 3519 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3520 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3521 | } finally { |
| 3522 | Binder.restoreCallingIdentity(identity); |
| 3523 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3524 | } |
| 3525 | |
| 3526 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3527 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3528 | VisualVoicemailSmsFilterSettings settings) { |
| 3529 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3530 | |
| 3531 | final long identity = Binder.clearCallingIdentity(); |
| 3532 | try { |
| 3533 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3534 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3535 | } finally { |
| 3536 | Binder.restoreCallingIdentity(identity); |
| 3537 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3538 | } |
| 3539 | |
| 3540 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3541 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3542 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3543 | |
| 3544 | final long identity = Binder.clearCallingIdentity(); |
| 3545 | try { |
| 3546 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3547 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3548 | } finally { |
| 3549 | Binder.restoreCallingIdentity(identity); |
| 3550 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3551 | } |
| 3552 | |
| 3553 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3554 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3555 | String callingPackage, int subId) { |
| 3556 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3557 | |
| 3558 | final long identity = Binder.clearCallingIdentity(); |
| 3559 | try { |
| 3560 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3561 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3562 | } finally { |
| 3563 | Binder.restoreCallingIdentity(identity); |
| 3564 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3565 | } |
| 3566 | |
| 3567 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3568 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3569 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3570 | |
| 3571 | final long identity = Binder.clearCallingIdentity(); |
| 3572 | try { |
| 3573 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3574 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3575 | } finally { |
| 3576 | Binder.restoreCallingIdentity(identity); |
| 3577 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3578 | } |
| 3579 | |
| 3580 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3581 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3582 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3583 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3584 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3585 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3586 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3587 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3588 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3589 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3590 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3591 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3592 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3593 | * Sets the voice activation state of a given subId. |
| 3594 | */ |
| 3595 | @Override |
| 3596 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3597 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3598 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3599 | |
| 3600 | final long identity = Binder.clearCallingIdentity(); |
| 3601 | try { |
| 3602 | final Phone phone = getPhone(subId); |
| 3603 | if (phone != null) { |
| 3604 | phone.setVoiceActivationState(activationState); |
| 3605 | } else { |
| 3606 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3607 | } |
| 3608 | } finally { |
| 3609 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3610 | } |
| 3611 | } |
| 3612 | |
| 3613 | /** |
| 3614 | * Sets the data activation state of a given subId. |
| 3615 | */ |
| 3616 | @Override |
| 3617 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3618 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3619 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3620 | |
| 3621 | final long identity = Binder.clearCallingIdentity(); |
| 3622 | try { |
| 3623 | final Phone phone = getPhone(subId); |
| 3624 | if (phone != null) { |
| 3625 | phone.setDataActivationState(activationState); |
| 3626 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3627 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3628 | } |
| 3629 | } finally { |
| 3630 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3631 | } |
| 3632 | } |
| 3633 | |
| 3634 | /** |
| 3635 | * Returns the voice activation state of a given subId. |
| 3636 | */ |
| 3637 | @Override |
| 3638 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3639 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3640 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3641 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3642 | final long identity = Binder.clearCallingIdentity(); |
| 3643 | try { |
| 3644 | if (phone != null) { |
| 3645 | return phone.getVoiceActivationState(); |
| 3646 | } else { |
| 3647 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3648 | } |
| 3649 | } finally { |
| 3650 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3651 | } |
| 3652 | } |
| 3653 | |
| 3654 | /** |
| 3655 | * Returns the data activation state of a given subId. |
| 3656 | */ |
| 3657 | @Override |
| 3658 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3659 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3660 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3661 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3662 | final long identity = Binder.clearCallingIdentity(); |
| 3663 | try { |
| 3664 | if (phone != null) { |
| 3665 | return phone.getDataActivationState(); |
| 3666 | } else { |
| 3667 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3668 | } |
| 3669 | } finally { |
| 3670 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3671 | } |
| 3672 | } |
| 3673 | |
| 3674 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3675 | * Returns the unread count of voicemails for a subId |
| 3676 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3677 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3678 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3679 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3680 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3681 | mApp, subId, callingPackage, callingFeatureId, |
| 3682 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3683 | return 0; |
| 3684 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3685 | final long identity = Binder.clearCallingIdentity(); |
| 3686 | try { |
| 3687 | final Phone phone = getPhone(subId); |
| 3688 | if (phone != null) { |
| 3689 | return phone.getVoiceMessageCount(); |
| 3690 | } else { |
| 3691 | return 0; |
| 3692 | } |
| 3693 | } finally { |
| 3694 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3695 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3696 | } |
| 3697 | |
| 3698 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3699 | * returns true, if the device is in a state where both voice and data |
| 3700 | * are supported simultaneously. This can change based on location or network condition. |
| 3701 | */ |
| 3702 | @Override |
| 3703 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3704 | final long identity = Binder.clearCallingIdentity(); |
| 3705 | try { |
| 3706 | final Phone phone = getPhone(subId); |
| 3707 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3708 | } finally { |
| 3709 | Binder.restoreCallingIdentity(identity); |
| 3710 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3711 | } |
| 3712 | |
| 3713 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3714 | * Send the dialer code if called from the current default dialer or the caller has |
| 3715 | * carrier privilege. |
| 3716 | * @param inputCode The dialer code to send |
| 3717 | */ |
| 3718 | @Override |
| 3719 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3720 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3721 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3722 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3723 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3724 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3725 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3726 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3727 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3728 | |
| 3729 | final long identity = Binder.clearCallingIdentity(); |
| 3730 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3731 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3732 | } finally { |
| 3733 | Binder.restoreCallingIdentity(identity); |
| 3734 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3735 | } |
| 3736 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3737 | @Override |
| 3738 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3739 | TelephonyPermissions |
| 3740 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3741 | mApp, subId, "getNetworkSelectionMode"); |
| 3742 | final long identity = Binder.clearCallingIdentity(); |
| 3743 | try { |
| 3744 | if (!isActiveSubscription(subId)) { |
| 3745 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3746 | } |
| 3747 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3748 | } finally { |
| 3749 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3750 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3751 | } |
| 3752 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3753 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3754 | public boolean isInEmergencySmsMode() { |
| 3755 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3756 | final long identity = Binder.clearCallingIdentity(); |
| 3757 | try { |
| 3758 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3759 | if (phone.isInEmergencySmsMode()) { |
| 3760 | return true; |
| 3761 | } |
| 3762 | } |
| 3763 | } finally { |
| 3764 | Binder.restoreCallingIdentity(identity); |
| 3765 | } |
| 3766 | return false; |
| 3767 | } |
| 3768 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3769 | /** |
| 3770 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3771 | * @param subId The subscription to use to check the configuration. |
| 3772 | * @param c The callback that will be used to send the result. |
| 3773 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3774 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3775 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3776 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3777 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3778 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3779 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3780 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3781 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3782 | "IMS not available on device."); |
| 3783 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3784 | final long token = Binder.clearCallingIdentity(); |
| 3785 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3786 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3787 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3788 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3789 | } catch (ImsException e) { |
| 3790 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3791 | } finally { |
| 3792 | Binder.restoreCallingIdentity(token); |
| 3793 | } |
| 3794 | } |
| 3795 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3796 | /** |
| 3797 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3798 | * @param subId The subscription to use to check the configuration. |
| 3799 | * @param c The callback that will be used to send the result. |
| 3800 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3801 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3802 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3803 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3804 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3805 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3806 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3807 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3808 | final long token = Binder.clearCallingIdentity(); |
| 3809 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3810 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3811 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3812 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3813 | } catch (ImsException e) { |
| 3814 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3815 | + "is inactive, ignoring unregister."); |
| 3816 | // If the subscription is no longer active, just return, since the callback |
| 3817 | // will already have been removed internally. |
| 3818 | } finally { |
| 3819 | Binder.restoreCallingIdentity(token); |
| 3820 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3821 | } |
| 3822 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3823 | /** |
| 3824 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3825 | */ |
| 3826 | @Override |
| 3827 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3828 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3829 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3830 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3831 | "IMS not available on device."); |
| 3832 | } |
| 3833 | final long token = Binder.clearCallingIdentity(); |
| 3834 | try { |
| 3835 | Phone phone = getPhone(subId); |
| 3836 | if (phone == null) { |
| 3837 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3838 | + subId + "'"); |
| 3839 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3840 | } |
| 3841 | phone.getImsRegistrationState(regState -> { |
| 3842 | try { |
| 3843 | consumer.accept((regState == null) |
| 3844 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3845 | } catch (RemoteException e) { |
| 3846 | // Ignore if the remote process is no longer available to call back. |
| 3847 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3848 | } |
| 3849 | }); |
| 3850 | } finally { |
| 3851 | Binder.restoreCallingIdentity(token); |
| 3852 | } |
| 3853 | } |
| 3854 | |
| 3855 | /** |
| 3856 | * Get the transport type for the IMS service registration state. |
| 3857 | */ |
| 3858 | @Override |
| 3859 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3860 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3861 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3862 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3863 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3864 | "IMS not available on device."); |
| 3865 | } |
| 3866 | final long token = Binder.clearCallingIdentity(); |
| 3867 | try { |
| 3868 | Phone phone = getPhone(subId); |
| 3869 | if (phone == null) { |
| 3870 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3871 | + subId + "'"); |
| 3872 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3873 | } |
| 3874 | phone.getImsRegistrationTech(regTech -> { |
| 3875 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3876 | int regTechConverted = (regTech == null) |
| 3877 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3878 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3879 | regTechConverted); |
| 3880 | try { |
| 3881 | consumer.accept(regTechConverted); |
| 3882 | } catch (RemoteException e) { |
| 3883 | // Ignore if the remote process is no longer available to call back. |
| 3884 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3885 | } |
| 3886 | }); |
| 3887 | } finally { |
| 3888 | Binder.restoreCallingIdentity(token); |
| 3889 | } |
| 3890 | } |
| 3891 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3892 | /** |
| 3893 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3894 | * @param subId The subscription to use to check the configuration. |
| 3895 | * @param c The callback that will be used to send the result. |
| 3896 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3897 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3898 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3899 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3900 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3901 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3902 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3903 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3904 | "IMS not available on device."); |
| 3905 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3906 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3907 | final long token = Binder.clearCallingIdentity(); |
| 3908 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3909 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3910 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3911 | } catch (ImsException e) { |
| 3912 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3913 | } finally { |
| 3914 | Binder.restoreCallingIdentity(token); |
| 3915 | } |
| 3916 | } |
| 3917 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3918 | /** |
| 3919 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3920 | * @param subId The subscription to use to check the configuration. |
| 3921 | * @param c The callback that will be used to send the result. |
| 3922 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3923 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3924 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3925 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3926 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3927 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3928 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3929 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3930 | |
| 3931 | final long token = Binder.clearCallingIdentity(); |
| 3932 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3933 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3934 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3935 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3936 | } catch (ImsException e) { |
| 3937 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3938 | + "is inactive, ignoring unregister."); |
| 3939 | // If the subscription is no longer active, just return, since the callback |
| 3940 | // will already have been removed internally. |
| 3941 | } finally { |
| 3942 | Binder.restoreCallingIdentity(token); |
| 3943 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3944 | } |
| 3945 | |
| 3946 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3947 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3948 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3949 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3950 | final long token = Binder.clearCallingIdentity(); |
| 3951 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3952 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3953 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3954 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3955 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3956 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3957 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3958 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3959 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3960 | } finally { |
| 3961 | Binder.restoreCallingIdentity(token); |
| 3962 | } |
| 3963 | } |
| 3964 | |
| 3965 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3966 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3967 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3968 | final long token = Binder.clearCallingIdentity(); |
| 3969 | try { |
| 3970 | Phone phone = getPhone(subId); |
| 3971 | if (phone == null) return false; |
| 3972 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3973 | } catch (com.android.ims.ImsException e) { |
| 3974 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3975 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3976 | } finally { |
| 3977 | Binder.restoreCallingIdentity(token); |
| 3978 | } |
| 3979 | } |
| 3980 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3981 | /** |
| 3982 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3983 | * subscription. |
| 3984 | * @param subId The subscription to use to check the configuration. |
| 3985 | * @param callback The callback that will be used to send the result. |
| 3986 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3987 | * @param transportType The transport type of the MmTelFeature capability. |
| 3988 | */ |
| 3989 | @Override |
| 3990 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3991 | int transportType) { |
| 3992 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3993 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3994 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3995 | "IMS not available on device."); |
| 3996 | } |
| 3997 | final long token = Binder.clearCallingIdentity(); |
| 3998 | try { |
| 3999 | int slotId = getSlotIndex(subId); |
| 4000 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4001 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4002 | + subId + "'"); |
| 4003 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4004 | } |
| 4005 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4006 | transportType, aBoolean -> { |
| 4007 | try { |
| 4008 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4009 | } catch (RemoteException e) { |
| 4010 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4011 | + "running. Ignore"); |
| 4012 | } |
| 4013 | }); |
| 4014 | } finally { |
| 4015 | Binder.restoreCallingIdentity(token); |
| 4016 | } |
| 4017 | } |
| 4018 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4019 | /** |
| 4020 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4021 | * @param subId The subscription to use to check the configuration. |
| 4022 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4023 | @Override |
| 4024 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4025 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4026 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4027 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4028 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4029 | final long token = Binder.clearCallingIdentity(); |
| 4030 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4031 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4032 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4033 | } catch (ImsException e) { |
| 4034 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4035 | } finally { |
| 4036 | Binder.restoreCallingIdentity(token); |
| 4037 | } |
| 4038 | } |
| 4039 | |
| 4040 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4041 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4042 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4043 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4044 | final long identity = Binder.clearCallingIdentity(); |
| 4045 | try { |
| 4046 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4047 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4048 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4049 | } catch (ImsException e) { |
| 4050 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4051 | } finally { |
| 4052 | Binder.restoreCallingIdentity(identity); |
| 4053 | } |
| 4054 | } |
| 4055 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4056 | /** |
| 4057 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4058 | * @param subId The subscription to use to check the configuration. |
| 4059 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4060 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4061 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4062 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4063 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4064 | final long identity = Binder.clearCallingIdentity(); |
| 4065 | try { |
| 4066 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4067 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 4068 | } catch (ImsException e) { |
| 4069 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4070 | } finally { |
| 4071 | Binder.restoreCallingIdentity(identity); |
| 4072 | } |
| 4073 | } |
| 4074 | |
| 4075 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4076 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4077 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4078 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4079 | final long identity = Binder.clearCallingIdentity(); |
| 4080 | try { |
| 4081 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4082 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4083 | } catch (ImsException e) { |
| 4084 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4085 | } finally { |
| 4086 | Binder.restoreCallingIdentity(identity); |
| 4087 | } |
| 4088 | } |
| 4089 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4090 | /** |
| 4091 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4092 | * @param subId The subscription to use to check the configuration. |
| 4093 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4094 | @Override |
| 4095 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4096 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4097 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4098 | final long identity = Binder.clearCallingIdentity(); |
| 4099 | try { |
| 4100 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4101 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4102 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4103 | } catch (ImsException e) { |
| 4104 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4105 | } finally { |
| 4106 | Binder.restoreCallingIdentity(identity); |
| 4107 | } |
| 4108 | } |
| 4109 | |
| 4110 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4111 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4112 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4113 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4114 | final long identity = Binder.clearCallingIdentity(); |
| 4115 | try { |
| 4116 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4117 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4118 | } catch (ImsException e) { |
| 4119 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4120 | } finally { |
| 4121 | Binder.restoreCallingIdentity(identity); |
| 4122 | } |
| 4123 | } |
| 4124 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4125 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4126 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4127 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4128 | * @param subId The subscription to use to check the configuration. |
| 4129 | */ |
| 4130 | @Override |
| 4131 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
| 4132 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4133 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4134 | final long identity = Binder.clearCallingIdentity(); |
| 4135 | try { |
| 4136 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4137 | return ImsManager.getInstance(mApp, |
| 4138 | getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser(); |
| 4139 | } catch (ImsException e) { |
| 4140 | throw new ServiceSpecificException(e.getCode()); |
| 4141 | } finally { |
| 4142 | Binder.restoreCallingIdentity(identity); |
| 4143 | } |
| 4144 | } |
| 4145 | |
| 4146 | /** |
| 4147 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4148 | * Requires MODIFY_PHONE_STATE permission. |
| 4149 | * @param subId The subscription to use to check the configuration. |
| 4150 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4151 | * false otherwise |
| 4152 | */ |
| 4153 | @Override |
| 4154 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4155 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4156 | "setCrossSimCallingEnabled"); |
| 4157 | final long identity = Binder.clearCallingIdentity(); |
| 4158 | try { |
| 4159 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4160 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 4161 | .setCrossSimCallingEnabled(isEnabled); |
| 4162 | } catch (ImsException e) { |
| 4163 | throw new ServiceSpecificException(e.getCode()); |
| 4164 | } finally { |
| 4165 | Binder.restoreCallingIdentity(identity); |
| 4166 | } |
| 4167 | } |
| 4168 | |
| 4169 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4170 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4171 | * @param subId The subscription to use to check the configuration. |
| 4172 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4173 | @Override |
| 4174 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4175 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4176 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4177 | final long identity = Binder.clearCallingIdentity(); |
| 4178 | try { |
| 4179 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4180 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4181 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4182 | } catch (ImsException e) { |
| 4183 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4184 | } finally { |
| 4185 | Binder.restoreCallingIdentity(identity); |
| 4186 | } |
| 4187 | } |
| 4188 | |
| 4189 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4190 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4191 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4192 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4193 | final long identity = Binder.clearCallingIdentity(); |
| 4194 | try { |
| 4195 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4196 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4197 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4198 | } catch (ImsException e) { |
| 4199 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4200 | } finally { |
| 4201 | Binder.restoreCallingIdentity(identity); |
| 4202 | } |
| 4203 | } |
| 4204 | |
| 4205 | @Override |
| 4206 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4207 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4208 | "setVoWiFiNonPersistent"); |
| 4209 | final long identity = Binder.clearCallingIdentity(); |
| 4210 | try { |
| 4211 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4212 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 4213 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4214 | } catch (ImsException e) { |
| 4215 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4216 | } finally { |
| 4217 | Binder.restoreCallingIdentity(identity); |
| 4218 | } |
| 4219 | } |
| 4220 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4221 | /** |
| 4222 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4223 | * @param subId The subscription to use to check the configuration. |
| 4224 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4225 | @Override |
| 4226 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4227 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4228 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4229 | final long identity = Binder.clearCallingIdentity(); |
| 4230 | try { |
| 4231 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4232 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4233 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4234 | } catch (ImsException e) { |
| 4235 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4236 | } finally { |
| 4237 | Binder.restoreCallingIdentity(identity); |
| 4238 | } |
| 4239 | } |
| 4240 | |
| 4241 | @Override |
| 4242 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4243 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4244 | "setVoWiFiModeSetting"); |
| 4245 | final long identity = Binder.clearCallingIdentity(); |
| 4246 | try { |
| 4247 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4248 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4249 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4250 | } catch (ImsException e) { |
| 4251 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4252 | } finally { |
| 4253 | Binder.restoreCallingIdentity(identity); |
| 4254 | } |
| 4255 | } |
| 4256 | |
| 4257 | @Override |
| 4258 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4259 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4260 | final long identity = Binder.clearCallingIdentity(); |
| 4261 | try { |
| 4262 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4263 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4264 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4265 | } catch (ImsException e) { |
| 4266 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4267 | } finally { |
| 4268 | Binder.restoreCallingIdentity(identity); |
| 4269 | } |
| 4270 | } |
| 4271 | |
| 4272 | @Override |
| 4273 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4274 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4275 | "setVoWiFiRoamingModeSetting"); |
| 4276 | final long identity = Binder.clearCallingIdentity(); |
| 4277 | try { |
| 4278 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4279 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4280 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4281 | } catch (ImsException e) { |
| 4282 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4283 | } finally { |
| 4284 | Binder.restoreCallingIdentity(identity); |
| 4285 | } |
| 4286 | } |
| 4287 | |
| 4288 | @Override |
| 4289 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4290 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4291 | "setRttCapabilityEnabled"); |
| 4292 | final long identity = Binder.clearCallingIdentity(); |
| 4293 | try { |
| 4294 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4295 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 4296 | } catch (ImsException e) { |
| 4297 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4298 | } finally { |
| 4299 | Binder.restoreCallingIdentity(identity); |
| 4300 | } |
| 4301 | } |
| 4302 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4303 | /** |
| 4304 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4305 | * @param subId The subscription to use to check the configuration. |
| 4306 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4307 | @Override |
| 4308 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4309 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4310 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4311 | final long identity = Binder.clearCallingIdentity(); |
| 4312 | try { |
| 4313 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4314 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4315 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4316 | } catch (ImsException e) { |
| 4317 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4318 | } finally { |
| 4319 | Binder.restoreCallingIdentity(identity); |
| 4320 | } |
| 4321 | } |
| 4322 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4323 | @Override |
| 4324 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4325 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4326 | final long identity = Binder.clearCallingIdentity(); |
| 4327 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4328 | if (!isImsAvailableOnDevice()) { |
| 4329 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4330 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4331 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4332 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4333 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4334 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4335 | } catch (ImsException e) { |
| 4336 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4337 | } finally { |
| 4338 | Binder.restoreCallingIdentity(identity); |
| 4339 | } |
| 4340 | } |
| 4341 | |
| 4342 | @Override |
| 4343 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4344 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4345 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4346 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4347 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4348 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4349 | try { |
| 4350 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4351 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4352 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4353 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4354 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4355 | + "is inactive, ignoring unregister."); |
| 4356 | // If the subscription is no longer active, just return, since the callback will already |
| 4357 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4358 | } finally { |
| 4359 | Binder.restoreCallingIdentity(identity); |
| 4360 | } |
| 4361 | } |
| 4362 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4363 | |
| 4364 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4365 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4366 | message); |
| 4367 | } |
| 4368 | |
| 4369 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4370 | boolean isMmtelCapability) { |
| 4371 | Phone phone = getPhone(subId); |
| 4372 | if (phone == null) { |
| 4373 | loge("phone instance null for subid " + subId); |
| 4374 | return false; |
| 4375 | } |
| 4376 | if (isMmtelCapability) { |
| 4377 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4378 | return false; |
| 4379 | } |
| 4380 | } else { |
| 4381 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4382 | return false; |
| 4383 | } |
| 4384 | } |
| 4385 | return true; |
| 4386 | } |
| 4387 | |
| 4388 | @Override |
| 4389 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4390 | boolean isProvisioned) { |
| 4391 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4392 | |
| 4393 | final long identity = Binder.clearCallingIdentity(); |
| 4394 | try { |
| 4395 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4396 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4397 | return; |
| 4398 | } |
| 4399 | |
| 4400 | // this capability requires provisioning, route to the correct API. |
| 4401 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4402 | switch (capability) { |
| 4403 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4404 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4405 | ims.setEabProvisioned(isProvisioned); |
| 4406 | break; |
| 4407 | default: { |
| 4408 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4409 | + "rcs capability '" + capability + "', which does not require " |
| 4410 | + "provisioning."); |
| 4411 | } |
| 4412 | } |
| 4413 | } finally { |
| 4414 | Binder.restoreCallingIdentity(identity); |
| 4415 | } |
| 4416 | |
| 4417 | } |
| 4418 | |
| 4419 | |
| 4420 | @Override |
| 4421 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4422 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4423 | final long identity = Binder.clearCallingIdentity(); |
| 4424 | try { |
| 4425 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4426 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4427 | return true; |
| 4428 | } |
| 4429 | |
| 4430 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4431 | switch (capability) { |
| 4432 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4433 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4434 | return ims.isEabProvisionedOnDevice(); |
| 4435 | |
| 4436 | default: { |
| 4437 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4438 | + "capability '" + capability + "', which does not require " |
| 4439 | + "provisioning."); |
| 4440 | } |
| 4441 | } |
| 4442 | |
| 4443 | } finally { |
| 4444 | Binder.restoreCallingIdentity(identity); |
| 4445 | } |
| 4446 | } |
| 4447 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4448 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4449 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4450 | boolean isProvisioned) { |
| 4451 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4452 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4453 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4454 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4455 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4456 | final long identity = Binder.clearCallingIdentity(); |
| 4457 | try { |
| 4458 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4459 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4460 | return; |
| 4461 | } |
| 4462 | |
| 4463 | // this capability requires provisioning, route to the correct API. |
| 4464 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4465 | switch (capability) { |
| 4466 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4467 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4468 | ims.setVolteProvisioned(isProvisioned); |
| 4469 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4470 | ims.setWfcProvisioned(isProvisioned); |
| 4471 | } |
| 4472 | break; |
| 4473 | } |
| 4474 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4475 | // There is currently no difference in VT provisioning type. |
| 4476 | ims.setVtProvisioned(isProvisioned); |
| 4477 | break; |
| 4478 | } |
| 4479 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4480 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4481 | // change the capability of the feature instead if needed. |
| 4482 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4483 | == isProvisioned) { |
| 4484 | // No change in provisioning. |
| 4485 | return; |
| 4486 | } |
| 4487 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4488 | try { |
| 4489 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4490 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4491 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4492 | + ", Exception" + e.getMessage()); |
| 4493 | } |
| 4494 | break; |
| 4495 | } |
| 4496 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4497 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4498 | + "MmTel capability '" + capability + "', which does not require " |
| 4499 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4500 | } |
| 4501 | } |
| 4502 | |
| 4503 | } finally { |
| 4504 | Binder.restoreCallingIdentity(identity); |
| 4505 | } |
| 4506 | } |
| 4507 | |
| 4508 | @Override |
| 4509 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4510 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4511 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4512 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4513 | } |
| 4514 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4515 | final long identity = Binder.clearCallingIdentity(); |
| 4516 | try { |
| 4517 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4518 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4519 | return true; |
| 4520 | } |
| 4521 | |
| 4522 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4523 | switch (capability) { |
| 4524 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4525 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4526 | return ims.isVolteProvisionedOnDevice(); |
| 4527 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4528 | return ims.isWfcProvisionedOnDevice(); |
| 4529 | } |
| 4530 | // This should never happen, since we are checking tech above to make sure it |
| 4531 | // is either LTE or IWLAN. |
| 4532 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4533 | + "capability."); |
| 4534 | } |
| 4535 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4536 | // There is currently no difference in VT provisioning type. |
| 4537 | return ims.isVtProvisionedOnDevice(); |
| 4538 | } |
| 4539 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4540 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4541 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4542 | } |
| 4543 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4544 | throw new IllegalArgumentException( |
| 4545 | "Tried to get provisioning for MmTel capability '" + capability |
| 4546 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4547 | } |
| 4548 | } |
| 4549 | |
| 4550 | } finally { |
| 4551 | Binder.restoreCallingIdentity(identity); |
| 4552 | } |
| 4553 | } |
| 4554 | |
| 4555 | @Override |
| 4556 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4557 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4558 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4559 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4560 | } |
| 4561 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4562 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4563 | return (provisionedBits & capability) > 0; |
| 4564 | } |
| 4565 | |
| 4566 | @Override |
| 4567 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4568 | boolean isProvisioned) { |
| 4569 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4570 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4571 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4572 | } |
| 4573 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4574 | "setProvisioningStatusForCapability"); |
| 4575 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4576 | // If the current provisioning status for capability already matches isProvisioned, |
| 4577 | // do nothing. |
| 4578 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4579 | return; |
| 4580 | } |
| 4581 | if (isProvisioned) { |
| 4582 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4583 | } else { |
| 4584 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4585 | } |
| 4586 | } |
| 4587 | |
| 4588 | /** |
| 4589 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4590 | * technology. The bitfield should mirror the bitfield defined by |
| 4591 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4592 | */ |
| 4593 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4594 | String key = getMmTelProvisioningKey(subId, tech); |
| 4595 | // Default is no capabilities are provisioned. |
| 4596 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4597 | } |
| 4598 | |
| 4599 | /** |
| 4600 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4601 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4602 | * technology specified. |
| 4603 | * |
| 4604 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4605 | */ |
| 4606 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4607 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4608 | String key = getMmTelProvisioningKey(subId, tech); |
| 4609 | editor.putInt(key, newField); |
| 4610 | editor.commit(); |
| 4611 | } |
| 4612 | |
| 4613 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4614 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4615 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4616 | } |
| 4617 | |
| 4618 | /** |
| 4619 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4620 | * carrier associated with the subscription id. |
| 4621 | */ |
| 4622 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4623 | int capability) { |
| 4624 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4625 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4626 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4627 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4628 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4629 | false); |
| 4630 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4631 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4632 | |
| 4633 | // First check to make sure that the capability requires provisioning. |
| 4634 | switch (capability) { |
| 4635 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4636 | // intentional fallthrough |
| 4637 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4638 | if (requireVoiceVtProvisioning) { |
| 4639 | // Voice and Video requires provisioning |
| 4640 | return true; |
| 4641 | } |
| 4642 | break; |
| 4643 | } |
| 4644 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4645 | if (requireUtProvisioning) { |
| 4646 | // UT requires provisioning |
| 4647 | return true; |
| 4648 | } |
| 4649 | break; |
| 4650 | } |
| 4651 | } |
| 4652 | return false; |
| 4653 | } |
| 4654 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4655 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4656 | int capability) { |
| 4657 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4658 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4659 | |
| 4660 | boolean requireRcsProvisioning = c.getBoolean( |
| 4661 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4662 | |
| 4663 | // First check to make sure that the capability requires provisioning. |
| 4664 | switch (capability) { |
| 4665 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4666 | // intentional fallthrough |
| 4667 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4668 | if (requireRcsProvisioning) { |
| 4669 | // OPTION or PRESENCE requires provisioning |
| 4670 | return true; |
| 4671 | } |
| 4672 | break; |
| 4673 | } |
| 4674 | } |
| 4675 | return false; |
| 4676 | } |
| 4677 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4678 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4679 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4680 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4681 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4682 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4683 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4684 | final long identity = Binder.clearCallingIdentity(); |
| 4685 | try { |
| 4686 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4687 | int slotId = getSlotIndex(subId); |
| 4688 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4689 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4690 | + subId + "' for key:" + key); |
| 4691 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4692 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4693 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4694 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4695 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4696 | + subId + "' for key:" + key); |
| 4697 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4698 | } finally { |
| 4699 | Binder.restoreCallingIdentity(identity); |
| 4700 | } |
| 4701 | } |
| 4702 | |
| 4703 | @Override |
| 4704 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4705 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4706 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4707 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4708 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4709 | final long identity = Binder.clearCallingIdentity(); |
| 4710 | try { |
| 4711 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4712 | int slotId = getSlotIndex(subId); |
| 4713 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4714 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4715 | + subId + "' for key:" + key); |
| 4716 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4717 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4718 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4719 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4720 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4721 | + subId + "' for key:" + key); |
| 4722 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4723 | } finally { |
| 4724 | Binder.restoreCallingIdentity(identity); |
| 4725 | } |
| 4726 | } |
| 4727 | |
| 4728 | @Override |
| 4729 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4730 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4731 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4732 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4733 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4734 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4735 | final long identity = Binder.clearCallingIdentity(); |
| 4736 | try { |
| 4737 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4738 | int slotId = getSlotIndex(subId); |
| 4739 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4740 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4741 | + subId + "' for key:" + key); |
| 4742 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4743 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4744 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4745 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4746 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4747 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4748 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4749 | } finally { |
| 4750 | Binder.restoreCallingIdentity(identity); |
| 4751 | } |
| 4752 | } |
| 4753 | |
| 4754 | @Override |
| 4755 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4756 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4757 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4758 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4759 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4760 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4761 | final long identity = Binder.clearCallingIdentity(); |
| 4762 | try { |
| 4763 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4764 | int slotId = getSlotIndex(subId); |
| 4765 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4766 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4767 | + subId + "' for key:" + key); |
| 4768 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4769 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4770 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4771 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4772 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4773 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4774 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4775 | } finally { |
| 4776 | Binder.restoreCallingIdentity(identity); |
| 4777 | } |
| 4778 | } |
| 4779 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4780 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4781 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4782 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4783 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4784 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4785 | } |
| 4786 | return slotId; |
| 4787 | } |
| 4788 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4789 | private int getSlotIndex(int subId) { |
| 4790 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4791 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4792 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4793 | } |
| 4794 | return slotId; |
| 4795 | } |
| 4796 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4797 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4798 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4799 | */ |
| 4800 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4801 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4802 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4803 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4804 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4805 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4806 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4807 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4808 | mApp, subId, callingPackage, callingFeatureId, |
| 4809 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4810 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4811 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4812 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4813 | final long identity = Binder.clearCallingIdentity(); |
| 4814 | try { |
| 4815 | final Phone phone = getPhone(subId); |
| 4816 | if (phone != null) { |
| 4817 | return phone.getServiceState().getDataNetworkType(); |
| 4818 | } else { |
| 4819 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4820 | } |
| 4821 | } finally { |
| 4822 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4823 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4824 | } |
| 4825 | |
| 4826 | /** |
| 4827 | * Returns the data network type |
| 4828 | */ |
| 4829 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4830 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4831 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4832 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4833 | } |
| 4834 | |
| 4835 | /** |
| 4836 | * Returns the data network type for a subId |
| 4837 | */ |
| 4838 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4839 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4840 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4841 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4842 | mApp, subId, callingPackage, callingFeatureId, |
| 4843 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4844 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4845 | } |
| 4846 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4847 | final long identity = Binder.clearCallingIdentity(); |
| 4848 | try { |
| 4849 | final Phone phone = getPhone(subId); |
| 4850 | if (phone != null) { |
| 4851 | return phone.getServiceState().getDataNetworkType(); |
| 4852 | } else { |
| 4853 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4854 | } |
| 4855 | } finally { |
| 4856 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4857 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4858 | } |
| 4859 | |
| 4860 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4861 | * Returns the Voice network type for a subId |
| 4862 | */ |
| 4863 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4864 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4865 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4866 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4867 | mApp, subId, callingPackage, callingFeatureId, |
| 4868 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4869 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4870 | } |
| 4871 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4872 | final long identity = Binder.clearCallingIdentity(); |
| 4873 | try { |
| 4874 | final Phone phone = getPhone(subId); |
| 4875 | if (phone != null) { |
| 4876 | return phone.getServiceState().getVoiceNetworkType(); |
| 4877 | } else { |
| 4878 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4879 | } |
| 4880 | } finally { |
| 4881 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4882 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4883 | } |
| 4884 | |
| 4885 | /** |
| 4886 | * @return true if a ICC card is present |
| 4887 | */ |
| 4888 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4889 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4890 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4891 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4892 | } |
| 4893 | |
| 4894 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4895 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4896 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4897 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4898 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4899 | final long identity = Binder.clearCallingIdentity(); |
| 4900 | try { |
| 4901 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4902 | if (phone != null) { |
| 4903 | return phone.getIccCard().hasIccCard(); |
| 4904 | } else { |
| 4905 | return false; |
| 4906 | } |
| 4907 | } finally { |
| 4908 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4909 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4910 | } |
| 4911 | |
| 4912 | /** |
| 4913 | * Return if the current radio is LTE on CDMA. This |
| 4914 | * is a tri-state return value as for a period of time |
| 4915 | * the mode may be unknown. |
| 4916 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4917 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4918 | * @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] | 4919 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4920 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4921 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4922 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4923 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4924 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4925 | } |
| 4926 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4927 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4928 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4929 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4930 | try { |
| 4931 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4932 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4933 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4934 | } |
| 4935 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4936 | final long identity = Binder.clearCallingIdentity(); |
| 4937 | try { |
| 4938 | final Phone phone = getPhone(subId); |
| 4939 | if (phone == null) { |
| 4940 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4941 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4942 | return TelephonyProperties.lte_on_cdma_device() |
| 4943 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4944 | } |
| 4945 | } finally { |
| 4946 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4947 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4948 | } |
| 4949 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4950 | /** |
| 4951 | * {@hide} |
| 4952 | * Returns Default subId, 0 in the case of single standby. |
| 4953 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4954 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4955 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4956 | } |
| 4957 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4958 | private int getSlotForDefaultSubscription() { |
| 4959 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4960 | } |
| 4961 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4962 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4963 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4964 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4965 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4966 | private boolean isActiveSubscription(int subId) { |
| 4967 | return mSubscriptionController.isActiveSubId(subId); |
| 4968 | } |
| 4969 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4970 | /** |
| 4971 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4972 | */ |
| 4973 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4974 | final long identity = Binder.clearCallingIdentity(); |
| 4975 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4976 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4977 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4978 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4979 | } finally { |
| 4980 | Binder.restoreCallingIdentity(identity); |
| 4981 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4982 | } |
| 4983 | |
| 4984 | /** |
| 4985 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4986 | */ |
| 4987 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4988 | final long identity = Binder.clearCallingIdentity(); |
| 4989 | try { |
| 4990 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4991 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4992 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4993 | } finally { |
| 4994 | Binder.restoreCallingIdentity(identity); |
| 4995 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4996 | } |
| 4997 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4998 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4999 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5000 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5001 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5002 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5003 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 5004 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 5005 | if (phoneId == -1) { |
| 5006 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 5007 | + " does not correspond to an active phone"); |
| 5008 | } |
| 5009 | return PhoneFactory.getPhone(phoneId); |
| 5010 | } |
| 5011 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5012 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5013 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 5014 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5015 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5016 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5017 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5018 | if (DBG) { |
| 5019 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 5020 | } |
| 5021 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 5022 | p2); |
| 5023 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5024 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5025 | |
| 5026 | @Override |
| 5027 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 5028 | int slotIndex, String callingPackage, String aid, int p2) { |
| 5029 | enforceModifyPermission(); |
| 5030 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5031 | if (DBG) { |
| 5032 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 5033 | } |
| 5034 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 5035 | callingPackage, aid, p2); |
| 5036 | } |
| 5037 | |
| 5038 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 5039 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5040 | final long identity = Binder.clearCallingIdentity(); |
| 5041 | try { |
| 5042 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 5043 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5044 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5045 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5046 | if (bestComponent == null |
| 5047 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5048 | loge("The calling package is not allowed to access ISD-R."); |
| 5049 | throw new SecurityException( |
| 5050 | "The calling package is not allowed to access ISD-R."); |
| 5051 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5052 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5053 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5054 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5055 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 5056 | null /* workSource */); |
| 5057 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5058 | return response; |
| 5059 | } finally { |
| 5060 | Binder.restoreCallingIdentity(identity); |
| 5061 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5062 | } |
| 5063 | |
| 5064 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5065 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5066 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5067 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5068 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 5069 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 5070 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5071 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5072 | @Override |
| 5073 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 5074 | enforceModifyPermission(); |
| 5075 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 5076 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 5077 | channel); |
| 5078 | } |
| 5079 | |
| 5080 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5081 | final long identity = Binder.clearCallingIdentity(); |
| 5082 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5083 | if (channel < 0) { |
| 5084 | return false; |
| 5085 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5086 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 5087 | null /* workSource */); |
| 5088 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5089 | return success; |
| 5090 | } finally { |
| 5091 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5092 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5093 | } |
| 5094 | |
| 5095 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5096 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5097 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5098 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5099 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5100 | if (DBG) { |
| 5101 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5102 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5103 | + p3 + " data=" + data); |
| 5104 | } |
| 5105 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5106 | command, p1, p2, p3, data); |
| 5107 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5108 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5109 | @Override |
| 5110 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 5111 | int command, int p1, int p2, int p3, String data) { |
| 5112 | enforceModifyPermission(); |
| 5113 | if (DBG) { |
| 5114 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 5115 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5116 | + p3 + " data=" + data); |
| 5117 | } |
| 5118 | return iccTransmitApduLogicalChannelWithPermission( |
| 5119 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 5120 | data); |
| 5121 | } |
| 5122 | |
| 5123 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5124 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5125 | final long identity = Binder.clearCallingIdentity(); |
| 5126 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5127 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5128 | return ""; |
| 5129 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5130 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5131 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5132 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5133 | null /* workSource */); |
| 5134 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5135 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5136 | // Append the returned status code to the end of the response payload. |
| 5137 | String s = Integer.toHexString( |
| 5138 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5139 | if (response.payload != null) { |
| 5140 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5141 | } |
| 5142 | return s; |
| 5143 | } finally { |
| 5144 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5145 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5146 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5147 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5148 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5149 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5150 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5151 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5152 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5153 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5154 | if (DBG) { |
| 5155 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5156 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5157 | } |
| 5158 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5159 | cla, command, p1, p2, p3, data); |
| 5160 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5161 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5162 | @Override |
| 5163 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 5164 | int command, int p1, int p2, int p3, String data) { |
| 5165 | enforceModifyPermission(); |
| 5166 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5167 | if (DBG) { |
| 5168 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 5169 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 5170 | + " data=" + data); |
| 5171 | } |
| 5172 | |
| 5173 | return iccTransmitApduBasicChannelWithPermission( |
| 5174 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 5175 | p2, p3, data); |
| 5176 | } |
| 5177 | |
| 5178 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5179 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5180 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5181 | final long identity = Binder.clearCallingIdentity(); |
| 5182 | try { |
| 5183 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5184 | && TextUtils.equals(ISDR_AID, data)) { |
| 5185 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5186 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5187 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5188 | if (bestComponent == null |
| 5189 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5190 | loge("The calling package is not allowed to select ISD-R."); |
| 5191 | throw new SecurityException( |
| 5192 | "The calling package is not allowed to select ISD-R."); |
| 5193 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5194 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5195 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5196 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5197 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5198 | null /* workSource */); |
| 5199 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5200 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5201 | // Append the returned status code to the end of the response payload. |
| 5202 | String s = Integer.toHexString( |
| 5203 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5204 | if (response.payload != null) { |
| 5205 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5206 | } |
| 5207 | return s; |
| 5208 | } finally { |
| 5209 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5210 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5211 | } |
| 5212 | |
| 5213 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5214 | 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] | 5215 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5216 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5217 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5218 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5219 | final long identity = Binder.clearCallingIdentity(); |
| 5220 | try { |
| 5221 | if (DBG) { |
| 5222 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5223 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5224 | } |
| 5225 | |
| 5226 | IccIoResult response = |
| 5227 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5228 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5229 | subId); |
| 5230 | |
| 5231 | if (DBG) { |
| 5232 | log("Exchange SIM_IO [R]" + response); |
| 5233 | } |
| 5234 | |
| 5235 | byte[] result = null; |
| 5236 | int length = 2; |
| 5237 | if (response.payload != null) { |
| 5238 | length = 2 + response.payload.length; |
| 5239 | result = new byte[length]; |
| 5240 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5241 | } else { |
| 5242 | result = new byte[length]; |
| 5243 | } |
| 5244 | |
| 5245 | result[length - 1] = (byte) response.sw2; |
| 5246 | result[length - 2] = (byte) response.sw1; |
| 5247 | return result; |
| 5248 | } finally { |
| 5249 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5250 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5251 | } |
| 5252 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5253 | /** |
| 5254 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5255 | * on a particular subscription |
| 5256 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5257 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5258 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5259 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5260 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5261 | return null; |
| 5262 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5263 | |
| 5264 | final long identity = Binder.clearCallingIdentity(); |
| 5265 | try { |
| 5266 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5267 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5268 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5269 | return null; |
| 5270 | } |
| 5271 | Object response = sendRequest( |
| 5272 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5273 | if (response instanceof String[]) { |
| 5274 | return (String[]) response; |
| 5275 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5276 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5277 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5278 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5279 | } finally { |
| 5280 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5281 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5282 | } |
| 5283 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5284 | /** |
| 5285 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5286 | * subscription. |
| 5287 | * |
| 5288 | * @param subId the id of the subscription. |
| 5289 | * @param appType the uicc app type, must be USIM or SIM. |
| 5290 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5291 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5292 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5293 | * @return number of fplmns that is successfully written to the SIM. |
| 5294 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5295 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5296 | String callingFeatureId) { |
| 5297 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 5298 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5299 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 5300 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 5301 | } |
| 5302 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5303 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5304 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5305 | } |
| 5306 | if (fplmns == null) { |
| 5307 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5308 | } |
| 5309 | for (String fplmn : fplmns) { |
| 5310 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5311 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5312 | } |
| 5313 | } |
| 5314 | final long identity = Binder.clearCallingIdentity(); |
| 5315 | try { |
| 5316 | Object response = sendRequest( |
| 5317 | CMD_SET_FORBIDDEN_PLMNS, |
| 5318 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5319 | subId); |
| 5320 | return (int) response; |
| 5321 | } finally { |
| 5322 | Binder.restoreCallingIdentity(identity); |
| 5323 | } |
| 5324 | } |
| 5325 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5326 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5327 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5328 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5329 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5330 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5331 | final long identity = Binder.clearCallingIdentity(); |
| 5332 | try { |
| 5333 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5334 | if (response.payload == null) { |
| 5335 | return ""; |
| 5336 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5337 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5338 | // Append the returned status code to the end of the response payload. |
| 5339 | String s = Integer.toHexString( |
| 5340 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5341 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5342 | return s; |
| 5343 | } finally { |
| 5344 | Binder.restoreCallingIdentity(identity); |
| 5345 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5346 | } |
| 5347 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5348 | /** |
| 5349 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5350 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5351 | * |
| 5352 | * @param itemID the ID of the item to read |
| 5353 | * @return the NV item as a String, or null on error. |
| 5354 | */ |
| 5355 | @Override |
| 5356 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5357 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5358 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5359 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5360 | |
| 5361 | final long identity = Binder.clearCallingIdentity(); |
| 5362 | try { |
| 5363 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5364 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5365 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5366 | return value; |
| 5367 | } finally { |
| 5368 | Binder.restoreCallingIdentity(identity); |
| 5369 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5370 | } |
| 5371 | |
| 5372 | /** |
| 5373 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5374 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5375 | * |
| 5376 | * @param itemID the ID of the item to read |
| 5377 | * @param itemValue the value to write, as a String |
| 5378 | * @return true on success; false on any failure |
| 5379 | */ |
| 5380 | @Override |
| 5381 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5382 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5383 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5384 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5385 | |
| 5386 | final long identity = Binder.clearCallingIdentity(); |
| 5387 | try { |
| 5388 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5389 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5390 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5391 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5392 | return success; |
| 5393 | } finally { |
| 5394 | Binder.restoreCallingIdentity(identity); |
| 5395 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5396 | } |
| 5397 | |
| 5398 | /** |
| 5399 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5400 | * Used for device configuration by some CDMA operators. |
| 5401 | * |
| 5402 | * @param preferredRoamingList byte array containing the new PRL |
| 5403 | * @return true on success; false on any failure |
| 5404 | */ |
| 5405 | @Override |
| 5406 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5407 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5408 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5409 | |
| 5410 | final long identity = Binder.clearCallingIdentity(); |
| 5411 | try { |
| 5412 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5413 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5414 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5415 | return success; |
| 5416 | } finally { |
| 5417 | Binder.restoreCallingIdentity(identity); |
| 5418 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5419 | } |
| 5420 | |
| 5421 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5422 | * 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] | 5423 | * Used for device configuration by some CDMA operators. |
| 5424 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5425 | * @param slotIndex - device slot. |
| 5426 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5427 | * @return true on success; false on any failure |
| 5428 | */ |
| 5429 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5430 | public boolean resetModemConfig(int slotIndex) { |
| 5431 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5432 | if (phone != null) { |
| 5433 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5434 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5435 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5436 | final long identity = Binder.clearCallingIdentity(); |
| 5437 | try { |
| 5438 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5439 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5440 | return success; |
| 5441 | } finally { |
| 5442 | Binder.restoreCallingIdentity(identity); |
| 5443 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5444 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5445 | return false; |
| 5446 | } |
| 5447 | |
| 5448 | /** |
| 5449 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5450 | * |
| 5451 | * @param slotIndex - device slot. |
| 5452 | * |
| 5453 | * @return true on success; false on any failure |
| 5454 | */ |
| 5455 | @Override |
| 5456 | public boolean rebootModem(int slotIndex) { |
| 5457 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5458 | if (phone != null) { |
| 5459 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5460 | mApp, phone.getSubId(), "rebootModem"); |
| 5461 | |
| 5462 | final long identity = Binder.clearCallingIdentity(); |
| 5463 | try { |
| 5464 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5465 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5466 | return success; |
| 5467 | } finally { |
| 5468 | Binder.restoreCallingIdentity(identity); |
| 5469 | } |
| 5470 | } |
| 5471 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5472 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5473 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5474 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5475 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5476 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5477 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5478 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5479 | return new String[0]; |
| 5480 | } |
| 5481 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5482 | final long identity = Binder.clearCallingIdentity(); |
| 5483 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5484 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5485 | } finally { |
| 5486 | Binder.restoreCallingIdentity(identity); |
| 5487 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5488 | } |
| 5489 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5490 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5491 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5492 | * {@link #disableIms(int)}. |
| 5493 | * @param slotIndex device slot. |
| 5494 | */ |
| 5495 | public void resetIms(int slotIndex) { |
| 5496 | enforceModifyPermission(); |
| 5497 | |
| 5498 | final long identity = Binder.clearCallingIdentity(); |
| 5499 | try { |
| 5500 | if (mImsResolver == null) { |
| 5501 | // may happen if the does not support IMS. |
| 5502 | return; |
| 5503 | } |
| 5504 | mImsResolver.disableIms(slotIndex); |
| 5505 | mImsResolver.enableIms(slotIndex); |
| 5506 | } finally { |
| 5507 | Binder.restoreCallingIdentity(identity); |
| 5508 | } |
| 5509 | } |
| 5510 | |
| 5511 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5512 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5513 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5514 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5515 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5516 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5517 | |
| 5518 | final long identity = Binder.clearCallingIdentity(); |
| 5519 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5520 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5521 | // may happen if the device does not support IMS. |
| 5522 | return; |
| 5523 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5524 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5525 | } finally { |
| 5526 | Binder.restoreCallingIdentity(identity); |
| 5527 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5528 | } |
| 5529 | |
| 5530 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5531 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5532 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5533 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5534 | public void disableIms(int slotId) { |
| 5535 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5536 | |
| 5537 | final long identity = Binder.clearCallingIdentity(); |
| 5538 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5539 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5540 | // may happen if the device does not support IMS. |
| 5541 | return; |
| 5542 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5543 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5544 | } finally { |
| 5545 | Binder.restoreCallingIdentity(identity); |
| 5546 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5547 | } |
| 5548 | |
| 5549 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5550 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5551 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5552 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5553 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5554 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5555 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5556 | |
| 5557 | final long identity = Binder.clearCallingIdentity(); |
| 5558 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5559 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5560 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5561 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5562 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5563 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5564 | } finally { |
| 5565 | Binder.restoreCallingIdentity(identity); |
| 5566 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5567 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5568 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5569 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5570 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5571 | @Override |
| 5572 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5573 | enforceModifyPermission(); |
| 5574 | |
| 5575 | final long identity = Binder.clearCallingIdentity(); |
| 5576 | try { |
| 5577 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5578 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5579 | } finally { |
| 5580 | Binder.restoreCallingIdentity(identity); |
| 5581 | } |
| 5582 | } |
| 5583 | |
| 5584 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5585 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5586 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5587 | */ |
| 5588 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5589 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5590 | |
| 5591 | final long identity = Binder.clearCallingIdentity(); |
| 5592 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5593 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5594 | // may happen if the device does not support IMS. |
| 5595 | return null; |
| 5596 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5597 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5598 | } finally { |
| 5599 | Binder.restoreCallingIdentity(identity); |
| 5600 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5601 | } |
| 5602 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5603 | /** |
| 5604 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5605 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5606 | */ |
| 5607 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5608 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5609 | |
| 5610 | final long identity = Binder.clearCallingIdentity(); |
| 5611 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5612 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5613 | // may happen if the device does not support IMS. |
| 5614 | return null; |
| 5615 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5616 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5617 | } finally { |
| 5618 | Binder.restoreCallingIdentity(identity); |
| 5619 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5620 | } |
| 5621 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5622 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5623 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5624 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5625 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5626 | * @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] | 5627 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5628 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5629 | * @param packageName The name of the package that the current configuration will be replaced |
| 5630 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5631 | * @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] | 5632 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5633 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5634 | int[] featureTypes, String packageName) { |
| 5635 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5636 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5637 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5638 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5639 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5640 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5641 | final long identity = Binder.clearCallingIdentity(); |
| 5642 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5643 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5644 | // may happen if the device does not support IMS. |
| 5645 | return false; |
| 5646 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5647 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5648 | for (int featureType : featureTypes) { |
| 5649 | featureConfig.put(featureType, packageName); |
| 5650 | } |
| 5651 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5652 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5653 | } finally { |
| 5654 | Binder.restoreCallingIdentity(identity); |
| 5655 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5656 | } |
| 5657 | |
| 5658 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5659 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5660 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5661 | * |
| 5662 | * This should only be used for testing. |
| 5663 | * |
| 5664 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5665 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5666 | */ |
| 5667 | @Override |
| 5668 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5669 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5670 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5671 | "clearCarrierImsServiceOverride"); |
| 5672 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5673 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5674 | "clearCarrierImsServiceOverride"); |
| 5675 | |
| 5676 | final long identity = Binder.clearCallingIdentity(); |
| 5677 | try { |
| 5678 | if (mImsResolver == null) { |
| 5679 | // may happen if the device does not support IMS. |
| 5680 | return false; |
| 5681 | } |
| 5682 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5683 | } finally { |
| 5684 | Binder.restoreCallingIdentity(identity); |
| 5685 | } |
| 5686 | } |
| 5687 | |
| 5688 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5689 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5690 | * |
| 5691 | * @param slotId The slot that the ImsService is associated with. |
| 5692 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5693 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5694 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5695 | * @return the package name of the ImsService configuration. |
| 5696 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5697 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5698 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5699 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5700 | TelephonyPermissions |
| 5701 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5702 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5703 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5704 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5705 | final long identity = Binder.clearCallingIdentity(); |
| 5706 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5707 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5708 | // may happen if the device does not support IMS. |
| 5709 | return ""; |
| 5710 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5711 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5712 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5713 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5714 | } finally { |
| 5715 | Binder.restoreCallingIdentity(identity); |
| 5716 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5717 | } |
| 5718 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5719 | /** |
| 5720 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5721 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5722 | * @param callback A callback with an integer containing the |
| 5723 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5724 | */ |
| 5725 | @Override |
| 5726 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5727 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5728 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5729 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5730 | "IMS not available on device."); |
| 5731 | } |
| 5732 | final long token = Binder.clearCallingIdentity(); |
| 5733 | try { |
| 5734 | int slotId = getSlotIndex(subId); |
| 5735 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5736 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5737 | + subId + "'"); |
| 5738 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5739 | } |
| 5740 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5741 | try { |
| 5742 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5743 | } catch (RemoteException e) { |
| 5744 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5745 | + "Ignore"); |
| 5746 | } |
| 5747 | }); |
| 5748 | } finally { |
| 5749 | Binder.restoreCallingIdentity(token); |
| 5750 | } |
| 5751 | } |
| 5752 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5753 | /** |
| 5754 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5755 | */ |
| 5756 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5757 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5758 | |
| 5759 | final long identity = Binder.clearCallingIdentity(); |
| 5760 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5761 | // NOTE: Before S, this method only set the default phone. |
| 5762 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5763 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5764 | phone.setImsRegistrationState(registered); |
| 5765 | } |
| 5766 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5767 | } finally { |
| 5768 | Binder.restoreCallingIdentity(identity); |
| 5769 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5770 | } |
| 5771 | |
| 5772 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5773 | * Set the network selection mode to automatic. |
| 5774 | * |
| 5775 | */ |
| 5776 | @Override |
| 5777 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5778 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5779 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5780 | |
| 5781 | final long identity = Binder.clearCallingIdentity(); |
| 5782 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5783 | if (!isActiveSubscription(subId)) { |
| 5784 | return; |
| 5785 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5786 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 5787 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 5788 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5789 | } finally { |
| 5790 | Binder.restoreCallingIdentity(identity); |
| 5791 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5792 | } |
| 5793 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5794 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5795 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5796 | * |
| 5797 | * @param subId the id of the subscription. |
| 5798 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5799 | * the operator to attach to. |
| 5800 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5801 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5802 | * normal network selection next time. |
| 5803 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5804 | */ |
| 5805 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5806 | public boolean setNetworkSelectionModeManual( |
| 5807 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5808 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5809 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5810 | |
| 5811 | if (!isActiveSubscription(subId)) { |
| 5812 | return false; |
| 5813 | } |
| 5814 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5815 | final long identity = Binder.clearCallingIdentity(); |
| 5816 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5817 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5818 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5819 | if (DBG) { |
| 5820 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5821 | + " operator: " + operatorInfo); |
| 5822 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5823 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5824 | } finally { |
| 5825 | Binder.restoreCallingIdentity(identity); |
| 5826 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5827 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5828 | /** |
| 5829 | * Get the manual network selection |
| 5830 | * |
| 5831 | * @param subId the id of the subscription. |
| 5832 | * |
| 5833 | * @return the previously saved user selected PLMN |
| 5834 | */ |
| 5835 | @Override |
| 5836 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5837 | TelephonyPermissions |
| 5838 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5839 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5840 | |
| 5841 | final long identity = Binder.clearCallingIdentity(); |
| 5842 | try { |
| 5843 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5844 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5845 | } |
| 5846 | |
| 5847 | final Phone phone = getPhone(subId); |
| 5848 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5849 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5850 | } |
| 5851 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5852 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5853 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5854 | } finally { |
| 5855 | Binder.restoreCallingIdentity(identity); |
| 5856 | } |
| 5857 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5858 | |
| 5859 | /** |
| 5860 | * Scans for available networks. |
| 5861 | */ |
| 5862 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5863 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5864 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5865 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5866 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5867 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5868 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5869 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5870 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5871 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5872 | .setCallingPid(Binder.getCallingPid()) |
| 5873 | .setCallingUid(Binder.getCallingUid()) |
| 5874 | .setMethod("getCellNetworkScanResults") |
| 5875 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 5876 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5877 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5878 | .build()); |
| 5879 | switch (locationResult) { |
| 5880 | case DENIED_HARD: |
| 5881 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5882 | case DENIED_SOFT: |
| 5883 | return null; |
| 5884 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5885 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5886 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5887 | try { |
| 5888 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5889 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5890 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5891 | } finally { |
| 5892 | Binder.restoreCallingIdentity(identity); |
| 5893 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5894 | } |
| 5895 | |
| 5896 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5897 | * Get the call forwarding info, given the call forwarding reason. |
| 5898 | */ |
| 5899 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5900 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5901 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5902 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5903 | long identity = Binder.clearCallingIdentity(); |
| 5904 | try { |
| 5905 | if (DBG) { |
| 5906 | log("getCallForwarding: subId " + subId |
| 5907 | + " callForwardingReason" + callForwardingReason); |
| 5908 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5909 | |
| 5910 | Phone phone = getPhone(subId); |
| 5911 | if (phone == null) { |
| 5912 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5913 | callback.onError( |
| 5914 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5915 | } catch (RemoteException e) { |
| 5916 | // ignore |
| 5917 | } |
| 5918 | return; |
| 5919 | } |
| 5920 | |
| 5921 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 5922 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 5923 | @Override |
| 5924 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 5925 | try { |
| 5926 | callback.onCallForwardingInfoAvailable(info); |
| 5927 | } catch (RemoteException e) { |
| 5928 | // ignore |
| 5929 | } |
| 5930 | } |
| 5931 | |
| 5932 | @Override |
| 5933 | public void onError(int error) { |
| 5934 | try { |
| 5935 | callback.onError(error); |
| 5936 | } catch (RemoteException e) { |
| 5937 | // ignore |
| 5938 | } |
| 5939 | } |
| 5940 | }); |
| 5941 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5942 | } finally { |
| 5943 | Binder.restoreCallingIdentity(identity); |
| 5944 | } |
| 5945 | } |
| 5946 | |
| 5947 | /** |
| 5948 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5949 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5950 | */ |
| 5951 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5952 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 5953 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5954 | enforceModifyPermission(); |
| 5955 | long identity = Binder.clearCallingIdentity(); |
| 5956 | try { |
| 5957 | if (DBG) { |
| 5958 | log("setCallForwarding: subId " + subId |
| 5959 | + " callForwardingInfo" + callForwardingInfo); |
| 5960 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5961 | |
| 5962 | Phone phone = getPhone(subId); |
| 5963 | if (phone == null) { |
| 5964 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5965 | callback.accept( |
| 5966 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5967 | } catch (RemoteException e) { |
| 5968 | // ignore |
| 5969 | } |
| 5970 | return; |
| 5971 | } |
| 5972 | |
| 5973 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 5974 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5975 | |
| 5976 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5977 | } finally { |
| 5978 | Binder.restoreCallingIdentity(identity); |
| 5979 | } |
| 5980 | } |
| 5981 | |
| 5982 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5983 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5984 | */ |
| 5985 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5986 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5987 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5988 | long identity = Binder.clearCallingIdentity(); |
| 5989 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5990 | |
| 5991 | Phone phone = getPhone(subId); |
| 5992 | if (phone == null) { |
| 5993 | try { |
| 5994 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5995 | } catch (RemoteException e) { |
| 5996 | // ignore |
| 5997 | } |
| 5998 | return; |
| 5999 | } |
| 6000 | |
| 6001 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 6002 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6003 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6004 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6005 | } finally { |
| 6006 | Binder.restoreCallingIdentity(identity); |
| 6007 | } |
| 6008 | } |
| 6009 | |
| 6010 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6011 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6012 | */ |
| 6013 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6014 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6015 | enforceModifyPermission(); |
| 6016 | long identity = Binder.clearCallingIdentity(); |
| 6017 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6018 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6019 | |
| 6020 | Phone phone = getPhone(subId); |
| 6021 | if (phone == null) { |
| 6022 | try { |
| 6023 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6024 | } catch (RemoteException e) { |
| 6025 | // ignore |
| 6026 | } |
| 6027 | return; |
| 6028 | } |
| 6029 | |
| 6030 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6031 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6032 | |
| 6033 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6034 | } finally { |
| 6035 | Binder.restoreCallingIdentity(identity); |
| 6036 | } |
| 6037 | } |
| 6038 | |
| 6039 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6040 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6041 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6042 | * @param subId id of the subscription |
| 6043 | * @param request contains the radio access networks with bands/channels to scan |
| 6044 | * @param messenger callback messenger for scan results or errors |
| 6045 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6046 | * @return the id of the requested scan which can be used to stop the scan. |
| 6047 | */ |
| 6048 | @Override |
| 6049 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6050 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6051 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6052 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6053 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6054 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6055 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6056 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6057 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6058 | .setCallingPid(Binder.getCallingPid()) |
| 6059 | .setCallingUid(Binder.getCallingUid()) |
| 6060 | .setMethod("requestNetworkScan") |
| 6061 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
James.cf Lin | 1d4d739 | 2020-07-03 18:22:53 +0800 | [diff] [blame] | 6062 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6063 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6064 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6065 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6066 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6067 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6068 | if (e != null) { |
| 6069 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6070 | throw e; |
| 6071 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6072 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6073 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6074 | } |
| 6075 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6076 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6077 | int callingUid = Binder.getCallingUid(); |
| 6078 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6079 | final long identity = Binder.clearCallingIdentity(); |
| 6080 | try { |
| 6081 | return mNetworkScanRequestTracker.startNetworkScan( |
| 6082 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6083 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6084 | } finally { |
| 6085 | Binder.restoreCallingIdentity(identity); |
| 6086 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6087 | } |
| 6088 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6089 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6090 | NetworkScanRequest request, int subId, String callingPackage) { |
| 6091 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6092 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6093 | boolean hasNetworkScanPermission = |
| 6094 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6095 | == PERMISSION_GRANTED; |
| 6096 | |
| 6097 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6098 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6099 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6100 | } |
| 6101 | |
| 6102 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6103 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6104 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6105 | return new SecurityException("Specific channels must not be" |
| 6106 | + " scanned without location access."); |
| 6107 | } |
| 6108 | } |
| 6109 | } |
| 6110 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6111 | return null; |
| 6112 | } |
| 6113 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6114 | /** |
| 6115 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6116 | * |
| 6117 | * @param subId id of the subscription |
| 6118 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6119 | */ |
| 6120 | @Override |
| 6121 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6122 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6123 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6124 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6125 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6126 | final long identity = Binder.clearCallingIdentity(); |
| 6127 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6128 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6129 | } finally { |
| 6130 | Binder.restoreCallingIdentity(identity); |
| 6131 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6132 | } |
| 6133 | |
| 6134 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6135 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6136 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6137 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6138 | */ |
| 6139 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6140 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6141 | TelephonyPermissions |
| 6142 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6143 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6144 | |
| 6145 | final long identity = Binder.clearCallingIdentity(); |
| 6146 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6147 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6148 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6149 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6150 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6151 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6152 | } finally { |
| 6153 | Binder.restoreCallingIdentity(identity); |
| 6154 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6155 | } |
| 6156 | |
| 6157 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6158 | * Get the allowed network types for certain reason. |
| 6159 | * |
| 6160 | * @param subId the id of the subscription. |
| 6161 | * @param reason the reason the allowed network type change is taking place |
| 6162 | * @return the allowed network types. |
| 6163 | */ |
| 6164 | @Override |
| 6165 | public long getAllowedNetworkTypesForReason(int subId, |
| 6166 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6167 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 6168 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6169 | final long identity = Binder.clearCallingIdentity(); |
| 6170 | try { |
| 6171 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6172 | } finally { |
| 6173 | Binder.restoreCallingIdentity(identity); |
| 6174 | } |
| 6175 | } |
| 6176 | |
| 6177 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6178 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6179 | * @param subId subscription id of the sim card |
| 6180 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6181 | * This can be passed following states |
| 6182 | * <ol> |
| 6183 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6184 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6185 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6186 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6187 | * </ol> |
| 6188 | * @return operation result. |
| 6189 | */ |
| 6190 | @Override |
| 6191 | public int setNrDualConnectivityState(int subId, |
| 6192 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6193 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6194 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6195 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6196 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6197 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6198 | } |
| 6199 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6200 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6201 | final long identity = Binder.clearCallingIdentity(); |
| 6202 | try { |
| 6203 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6204 | nrDualConnectivityState, subId, |
| 6205 | workSource); |
| 6206 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6207 | return result; |
| 6208 | } finally { |
| 6209 | Binder.restoreCallingIdentity(identity); |
| 6210 | } |
| 6211 | } |
| 6212 | |
| 6213 | /** |
| 6214 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6215 | * @return true if dual connectivity is enabled else false |
| 6216 | */ |
| 6217 | @Override |
| 6218 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6219 | TelephonyPermissions |
| 6220 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6221 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6222 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6223 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6224 | return false; |
| 6225 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6226 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6227 | final long identity = Binder.clearCallingIdentity(); |
| 6228 | try { |
| 6229 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6230 | null, subId, workSource); |
| 6231 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6232 | return isEnabled; |
| 6233 | } finally { |
| 6234 | Binder.restoreCallingIdentity(identity); |
| 6235 | } |
| 6236 | } |
| 6237 | |
| 6238 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6239 | * Set the allowed network types of the device and |
| 6240 | * provide the reason triggering the allowed network change. |
| 6241 | * |
| 6242 | * @param subId the id of the subscription. |
| 6243 | * @param reason the reason the allowed network type change is taking place |
| 6244 | * @param allowedNetworkTypes the allowed network types. |
| 6245 | * @return true on success; false on any failure. |
| 6246 | */ |
| 6247 | @Override |
| 6248 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6249 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6250 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6251 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6252 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6253 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
| 6254 | Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason); |
| 6255 | return false; |
| 6256 | } |
| 6257 | |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6258 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
| 6259 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6260 | |
| 6261 | |
| 6262 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
| 6263 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6264 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6265 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6266 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6267 | final long identity = Binder.clearCallingIdentity(); |
| 6268 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6269 | Boolean success = (Boolean) sendRequest( |
| 6270 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6271 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6272 | |
| 6273 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6274 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6275 | } finally { |
| 6276 | Binder.restoreCallingIdentity(identity); |
| 6277 | } |
| 6278 | } |
| 6279 | |
| 6280 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6281 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6282 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6283 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6284 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6285 | * @hide |
| 6286 | */ |
| 6287 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6288 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6289 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6290 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6291 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6292 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6293 | if (phone != null) { |
| 6294 | return phone.hasMatchedTetherApnSetting(); |
| 6295 | } else { |
| 6296 | return false; |
| 6297 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6298 | } finally { |
| 6299 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6300 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6301 | } |
| 6302 | |
| 6303 | /** |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6304 | * Enable or disable always reporting signal strength changes from radio. |
| 6305 | * |
| 6306 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6307 | */ |
| 6308 | @Override |
| 6309 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6310 | enforceModifyPermission(); |
| 6311 | enforceSystemCaller(); |
| 6312 | |
| 6313 | final long identity = Binder.clearCallingIdentity(); |
| 6314 | final Phone phone = getPhone(subId); |
| 6315 | try { |
| 6316 | if (phone != null) { |
| 6317 | if (DBG) { |
| 6318 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6319 | + " isEnable=" + isEnable); |
| 6320 | } |
| 6321 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6322 | } else { |
| 6323 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6324 | + subId); |
| 6325 | } |
| 6326 | } finally { |
| 6327 | Binder.restoreCallingIdentity(identity); |
| 6328 | } |
| 6329 | } |
| 6330 | |
| 6331 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6332 | * Get the user enabled state of Mobile Data. |
| 6333 | * |
| 6334 | * TODO: remove and use isUserDataEnabled. |
| 6335 | * This can't be removed now because some vendor codes |
| 6336 | * calls through ITelephony directly while they should |
| 6337 | * use TelephonyManager. |
| 6338 | * |
| 6339 | * @return true on enabled |
| 6340 | */ |
| 6341 | @Override |
| 6342 | public boolean getDataEnabled(int subId) { |
| 6343 | return isUserDataEnabled(subId); |
| 6344 | } |
| 6345 | |
| 6346 | /** |
| 6347 | * Get whether mobile data is enabled per user setting. |
| 6348 | * |
| 6349 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6350 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6351 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6352 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6353 | * |
| 6354 | * @return {@code true} if data is enabled else {@code false} |
| 6355 | */ |
| 6356 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6357 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6358 | try { |
| 6359 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6360 | null); |
| 6361 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6362 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6363 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6364 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6365 | |
| 6366 | final long identity = Binder.clearCallingIdentity(); |
| 6367 | try { |
| 6368 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6369 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6370 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6371 | if (phone != null) { |
| 6372 | boolean retVal = phone.isUserDataEnabled(); |
| 6373 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6374 | return retVal; |
| 6375 | } else { |
| 6376 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6377 | return false; |
| 6378 | } |
| 6379 | } finally { |
| 6380 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6381 | } |
| 6382 | } |
| 6383 | |
| 6384 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6385 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6386 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6387 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6388 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6389 | * @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] | 6390 | */ |
| 6391 | @Override |
| 6392 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6393 | try { |
| 6394 | try { |
| 6395 | mApp.enforceCallingOrSelfPermission( |
| 6396 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6397 | null); |
| 6398 | } catch (Exception e) { |
| 6399 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6400 | "isDataEnabled"); |
| 6401 | } |
| 6402 | } catch (Exception e) { |
| 6403 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6404 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6405 | |
| 6406 | final long identity = Binder.clearCallingIdentity(); |
| 6407 | try { |
| 6408 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6409 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6410 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6411 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6412 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6413 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6414 | return retVal; |
| 6415 | } else { |
| 6416 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6417 | return false; |
| 6418 | } |
| 6419 | } finally { |
| 6420 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6421 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6422 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6423 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6424 | /** |
| 6425 | * Check if data is enabled for a specific reason |
| 6426 | * @param subId Subscription index |
| 6427 | * @param reason the reason the data enable change is taking place |
| 6428 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6429 | */ |
| 6430 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6431 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6432 | @TelephonyManager.DataEnabledReason int reason) { |
| 6433 | try { |
| 6434 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6435 | null); |
| 6436 | } catch (Exception e) { |
| 6437 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6438 | "isDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6439 | } |
| 6440 | |
| 6441 | |
| 6442 | final long identity = Binder.clearCallingIdentity(); |
| 6443 | try { |
| 6444 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6445 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6446 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6447 | + " reason=" + reason); |
| 6448 | } |
| 6449 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6450 | if (phone != null) { |
| 6451 | boolean retVal; |
| 6452 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6453 | retVal = phone.isUserDataEnabled(); |
| 6454 | } else { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6455 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6456 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6457 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6458 | return retVal; |
| 6459 | } else { |
| 6460 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6461 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6462 | + subId + " retVal=false"); |
| 6463 | } |
| 6464 | return false; |
| 6465 | } |
| 6466 | } finally { |
| 6467 | Binder.restoreCallingIdentity(identity); |
| 6468 | } |
| 6469 | } |
| 6470 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6471 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6472 | Phone phone) { |
Hall Liu | 54a2a0c | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6473 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 6474 | // Skip the check if it's one of these special uids |
| 6475 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6476 | } |
| 6477 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6478 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6479 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6480 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6481 | || subController == null) return privilegeFromSim; |
| 6482 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6483 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6484 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6485 | |
| 6486 | final long identity = Binder.clearCallingIdentity(); |
| 6487 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6488 | int subId = phone.getSubId(); |
| 6489 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6490 | // A test override is in place for the privileges for this subId, so don't try to |
| 6491 | // read the subscription privileges. |
| 6492 | return privilegeFromSim; |
| 6493 | } |
| 6494 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6495 | SubscriptionManager subManager = (SubscriptionManager) |
| 6496 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6497 | for (String pkg : packages) { |
| 6498 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6499 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6500 | } |
| 6501 | } |
| 6502 | return privilegeFromSim; |
| 6503 | } finally { |
| 6504 | Binder.restoreCallingIdentity(identity); |
| 6505 | } |
| 6506 | } |
| 6507 | |
| 6508 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6509 | String pkgName) { |
| 6510 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6511 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6512 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6513 | || subController == null) return privilegeFromSim; |
| 6514 | |
| 6515 | final long identity = Binder.clearCallingIdentity(); |
| 6516 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6517 | int subId = phone.getSubId(); |
| 6518 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6519 | // A test override is in place for the privileges for this subId, so don't try to |
| 6520 | // read the subscription privileges. |
| 6521 | return privilegeFromSim; |
| 6522 | } |
| 6523 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6524 | SubscriptionManager subManager = (SubscriptionManager) |
| 6525 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6526 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6527 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6528 | } finally { |
| 6529 | Binder.restoreCallingIdentity(identity); |
| 6530 | } |
| 6531 | } |
| 6532 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6533 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6534 | public int getCarrierPrivilegeStatus(int subId) { |
| 6535 | final Phone phone = getPhone(subId); |
| 6536 | if (phone == null) { |
| 6537 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6538 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6539 | } |
| 6540 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6541 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6542 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6543 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6544 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6545 | |
| 6546 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6547 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6548 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6549 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6550 | |
| 6551 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6552 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6553 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6554 | final Phone phone = getPhone(subId); |
| 6555 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6556 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6557 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6558 | } |
| 6559 | UiccProfile profile = |
| 6560 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6561 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6562 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6563 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6564 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6565 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6566 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6567 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6568 | } |
| 6569 | |
| 6570 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6571 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6572 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6573 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6574 | } |
| 6575 | |
| 6576 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6577 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6578 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6579 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6580 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6581 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6582 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6583 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6584 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6585 | } |
| 6586 | |
| 6587 | @Override |
| 6588 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6589 | if (TextUtils.isEmpty(pkgName)) |
| 6590 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6591 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6592 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6593 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6594 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6595 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6596 | continue; |
| 6597 | } |
| 6598 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6599 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6600 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6601 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6602 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6603 | break; |
| 6604 | } |
| 6605 | } |
| 6606 | |
| 6607 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6608 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6609 | |
| 6610 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6611 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6612 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6613 | loge("phoneId " + phoneId + " is not valid."); |
| 6614 | return null; |
| 6615 | } |
| 6616 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6617 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6618 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6619 | return null ; |
| 6620 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6621 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6622 | } |
| 6623 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6624 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6625 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6626 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6627 | List<String> privilegedPackages = new ArrayList<>(); |
| 6628 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6629 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6630 | // has UICC in that slot. |
| 6631 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6632 | if (card.hasCarrierPrivilegeRules()) { |
| 6633 | if (packages == null) { |
| 6634 | // Only check packages in user 0 for now |
| 6635 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6636 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6637 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6638 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6639 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6640 | } |
| 6641 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6642 | PackageInfo pkgInfo = packages.get(p); |
| 6643 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6644 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6645 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6646 | privilegedPackages.add(pkgInfo.packageName); |
| 6647 | } |
| 6648 | } |
| 6649 | } |
| 6650 | } |
| 6651 | return privilegedPackages; |
| 6652 | } |
| 6653 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6654 | @Override |
| 6655 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6656 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6657 | |
| 6658 | final long identity = Binder.clearCallingIdentity(); |
| 6659 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6660 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6661 | try { |
| 6662 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6663 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6664 | } |
| 6665 | } finally { |
| 6666 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6667 | } |
| 6668 | return privilegedPackages; |
| 6669 | } |
| 6670 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6671 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6672 | final Phone phone = getPhone(subId); |
| 6673 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6674 | if (card == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6675 | return null; |
| 6676 | } |
| 6677 | String iccId = card.getIccId(); |
| 6678 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6679 | return null; |
| 6680 | } |
| 6681 | return iccId; |
| 6682 | } |
| 6683 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6684 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6685 | public void setCallComposerStatus(int subId, int status) { |
| 6686 | enforceModifyPermission(); |
| 6687 | |
| 6688 | final long identity = Binder.clearCallingIdentity(); |
| 6689 | try { |
| 6690 | Phone phone = getPhone(subId); |
| 6691 | if (phone != null) { |
| 6692 | Phone defaultPhone = phone.getImsPhone(); |
| 6693 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6694 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6695 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6696 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6697 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6698 | } |
| 6699 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6700 | } catch (ImsException e) { |
| 6701 | throw new ServiceSpecificException(e.getCode()); |
| 6702 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6703 | Binder.restoreCallingIdentity(identity); |
| 6704 | } |
| 6705 | } |
| 6706 | |
| 6707 | @Override |
| 6708 | public int getCallComposerStatus(int subId) { |
| 6709 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6710 | |
| 6711 | final long identity = Binder.clearCallingIdentity(); |
| 6712 | try { |
| 6713 | Phone phone = getPhone(subId); |
| 6714 | if (phone != null) { |
| 6715 | Phone defaultPhone = phone.getImsPhone(); |
| 6716 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6717 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6718 | return imsPhone.getCallComposerStatus(); |
| 6719 | } |
| 6720 | } |
| 6721 | } finally { |
| 6722 | Binder.restoreCallingIdentity(identity); |
| 6723 | } |
| 6724 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6725 | } |
| 6726 | |
| 6727 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6728 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6729 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6730 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6731 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6732 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6733 | final long identity = Binder.clearCallingIdentity(); |
| 6734 | try { |
| 6735 | final String iccId = getIccId(subId); |
| 6736 | final Phone phone = getPhone(subId); |
| 6737 | if (phone == null) { |
| 6738 | return false; |
| 6739 | } |
| 6740 | final String subscriberId = phone.getSubscriberId(); |
| 6741 | |
| 6742 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6743 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6744 | + subscriberId + " to " + number); |
| 6745 | } |
| 6746 | |
| 6747 | if (TextUtils.isEmpty(iccId)) { |
| 6748 | return false; |
| 6749 | } |
| 6750 | |
| 6751 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6752 | |
| 6753 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6754 | if (alphaTag == null) { |
| 6755 | editor.remove(alphaTagPrefKey); |
| 6756 | } else { |
| 6757 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6758 | } |
| 6759 | |
| 6760 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6761 | // track all merged IMSIs based on line number |
| 6762 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6763 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6764 | if (number == null) { |
| 6765 | editor.remove(numberPrefKey); |
| 6766 | editor.remove(subscriberPrefKey); |
| 6767 | } else { |
| 6768 | editor.putString(numberPrefKey, number); |
| 6769 | editor.putString(subscriberPrefKey, subscriberId); |
| 6770 | } |
| 6771 | |
| 6772 | editor.commit(); |
| 6773 | return true; |
| 6774 | } finally { |
| 6775 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6776 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6777 | } |
| 6778 | |
| 6779 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6780 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6781 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6782 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6783 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6784 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6785 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6786 | return null; |
| 6787 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6788 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6789 | final long identity = Binder.clearCallingIdentity(); |
| 6790 | try { |
| 6791 | String iccId = getIccId(subId); |
| 6792 | if (iccId != null) { |
| 6793 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6794 | if (DBG_MERGE) { |
| 6795 | log("getLine1NumberForDisplay returning " |
| 6796 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6797 | } |
| 6798 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6799 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6800 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6801 | return null; |
| 6802 | } finally { |
| 6803 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6804 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6805 | } |
| 6806 | |
| 6807 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6808 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6809 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6810 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6811 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6812 | return null; |
| 6813 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6814 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6815 | final long identity = Binder.clearCallingIdentity(); |
| 6816 | try { |
| 6817 | String iccId = getIccId(subId); |
| 6818 | if (iccId != null) { |
| 6819 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6820 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6821 | } |
| 6822 | return null; |
| 6823 | } finally { |
| 6824 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6825 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6826 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6827 | |
| 6828 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6829 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6830 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6831 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6832 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6833 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6834 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6835 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6836 | return null; |
| 6837 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6838 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6839 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6840 | // the process, where TelephonyManager was instantiated. |
| 6841 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6842 | final long identity = Binder.clearCallingIdentity(); |
| 6843 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6844 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6845 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6846 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6847 | |
| 6848 | // Figure out what subscribers are currently active |
| 6849 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6850 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6851 | // Only consider subs which match the current subId |
| 6852 | // This logic can be simplified. See b/131189269 for progress. |
| 6853 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6854 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6855 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6856 | |
| 6857 | // First pass, find a number override for an active subscriber |
| 6858 | String mergeNumber = null; |
| 6859 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6860 | for (String key : prefs.keySet()) { |
| 6861 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6862 | final String subscriberId = (String) prefs.get(key); |
| 6863 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6864 | final String iccId = key.substring( |
| 6865 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6866 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6867 | mergeNumber = (String) prefs.get(numberKey); |
| 6868 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6869 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6870 | + " for active subscriber " + subscriberId); |
| 6871 | } |
| 6872 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6873 | break; |
| 6874 | } |
| 6875 | } |
| 6876 | } |
| 6877 | } |
| 6878 | |
| 6879 | // Shortcut when no active merged subscribers |
| 6880 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6881 | return null; |
| 6882 | } |
| 6883 | |
| 6884 | // Second pass, find all subscribers under that line override |
| 6885 | final ArraySet<String> result = new ArraySet<>(); |
| 6886 | for (String key : prefs.keySet()) { |
| 6887 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6888 | final String number = (String) prefs.get(key); |
| 6889 | if (mergeNumber.equals(number)) { |
| 6890 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6891 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6892 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6893 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6894 | result.add(subscriberId); |
| 6895 | } |
| 6896 | } |
| 6897 | } |
| 6898 | } |
| 6899 | |
| 6900 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6901 | Arrays.sort(resultArray); |
| 6902 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6903 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6904 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6905 | } |
| 6906 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6907 | } finally { |
| 6908 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6909 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6910 | } |
| 6911 | |
| 6912 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6913 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6914 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6915 | |
| 6916 | final long identity = Binder.clearCallingIdentity(); |
| 6917 | try { |
| 6918 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6919 | TelephonyManager.class); |
| 6920 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6921 | if (subscriberId == null) { |
| 6922 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6923 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6924 | + subId); |
| 6925 | } |
| 6926 | return null; |
| 6927 | } |
| 6928 | |
| 6929 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6930 | .getSubscriptionInfo(subId); |
| 6931 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6932 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6933 | if (groupUuid == null) { |
| 6934 | return new String[]{subscriberId}; |
| 6935 | } |
| 6936 | |
| 6937 | // Get all subscriberIds from the group. |
| 6938 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6939 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6940 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6941 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6942 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6943 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6944 | if (subscriberId != null) { |
| 6945 | mergedSubscriberIds.add(subscriberId); |
| 6946 | } |
| 6947 | } |
| 6948 | |
| 6949 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6950 | } finally { |
| 6951 | Binder.restoreCallingIdentity(identity); |
| 6952 | |
| 6953 | } |
| 6954 | } |
| 6955 | |
| 6956 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6957 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6958 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6959 | subId, "setOperatorBrandOverride"); |
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 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6965 | } finally { |
| 6966 | Binder.restoreCallingIdentity(identity); |
| 6967 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6968 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6969 | |
| 6970 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6971 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6972 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6973 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6974 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6975 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6976 | |
| 6977 | final long identity = Binder.clearCallingIdentity(); |
| 6978 | try { |
| 6979 | final Phone phone = getPhone(subId); |
| 6980 | if (phone == null) { |
| 6981 | return false; |
| 6982 | } |
| 6983 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6984 | cdmaNonRoamingList); |
| 6985 | } finally { |
| 6986 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6987 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6988 | } |
| 6989 | |
| 6990 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6991 | @Deprecated |
| 6992 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6993 | enforceModifyPermission(); |
| 6994 | |
| 6995 | int returnValue = 0; |
| 6996 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6997 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6998 | if(result.exception == null) { |
| 6999 | if (result.result != null) { |
| 7000 | byte[] responseData = (byte[])(result.result); |
| 7001 | if(responseData.length > oemResp.length) { |
| 7002 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7003 | responseData.length + "bytes. Buffer Size is " + |
| 7004 | oemResp.length + "bytes."); |
| 7005 | } |
| 7006 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7007 | returnValue = responseData.length; |
| 7008 | } |
| 7009 | } else { |
| 7010 | CommandException ex = (CommandException) result.exception; |
| 7011 | returnValue = ex.getCommandError().ordinal(); |
| 7012 | if(returnValue > 0) returnValue *= -1; |
| 7013 | } |
| 7014 | } catch (RuntimeException e) { |
| 7015 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7016 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7017 | if(returnValue > 0) returnValue *= -1; |
| 7018 | } |
| 7019 | |
| 7020 | return returnValue; |
| 7021 | } |
| 7022 | |
| 7023 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7024 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7025 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7026 | try { |
| 7027 | TelephonyPermissions |
| 7028 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 7029 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7030 | } catch (SecurityException e) { |
| 7031 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7032 | throw e; |
| 7033 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7034 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7035 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7036 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7037 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7038 | final long identity = Binder.clearCallingIdentity(); |
| 7039 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7040 | TelephonyPermissions |
| 7041 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 7042 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7043 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7044 | } finally { |
| 7045 | Binder.restoreCallingIdentity(identity); |
| 7046 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7047 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7048 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7049 | |
| 7050 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7051 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7052 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7053 | try { |
| 7054 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7055 | Binder.getCallingUid())) { |
| 7056 | throw new SecurityException("Package uid and package name do not match: " |
| 7057 | + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage); |
| 7058 | } |
| 7059 | } catch (PackageManager.NameNotFoundException e) { |
| 7060 | throw new SecurityException("Package name invalid:" + callingPackage); |
| 7061 | } |
| 7062 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7063 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7064 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7065 | throw new SecurityException("App must be the dialer role holder to" |
| 7066 | + " upload a call composer pic"); |
| 7067 | } |
| 7068 | |
| 7069 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7070 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7071 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7072 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7073 | boolean readUntilEnd = false; |
| 7074 | int totalBytesRead = 0; |
| 7075 | byte[] buffer = new byte[16 * 1024]; |
| 7076 | while (true) { |
| 7077 | int numRead; |
| 7078 | try { |
| 7079 | numRead = input.read(buffer); |
| 7080 | } catch (IOException e) { |
| 7081 | try { |
| 7082 | fd.checkError(); |
| 7083 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7084 | null); |
| 7085 | } catch (IOException e1) { |
| 7086 | // This means that the other side closed explicitly with an error. If this |
| 7087 | // happens, log and ignore. |
| 7088 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7089 | } |
| 7090 | break; |
| 7091 | } |
| 7092 | if (numRead == -1) { |
| 7093 | readUntilEnd = true; |
| 7094 | break; |
| 7095 | } |
| 7096 | totalBytesRead += numRead; |
| 7097 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7098 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7099 | try { |
| 7100 | input.close(); |
| 7101 | } catch (IOException e) { |
| 7102 | // ignore |
| 7103 | } |
| 7104 | break; |
| 7105 | } |
| 7106 | output.write(buffer, 0, numRead); |
| 7107 | } |
| 7108 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7109 | // close is above, where the picture size is too big. |
| 7110 | |
| 7111 | try { |
| 7112 | fd.checkError(); |
| 7113 | } catch (IOException e) { |
| 7114 | loge("Remote end for call composer closed with an error: " + e); |
| 7115 | return; |
| 7116 | } |
| 7117 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7118 | if (!readUntilEnd) { |
| 7119 | loge("Did not finish reading entire image; aborting"); |
| 7120 | return; |
| 7121 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7122 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7123 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7124 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7125 | new CallComposerPictureTransfer.Factory() {}, |
| 7126 | imageData, |
| 7127 | (result) -> { |
| 7128 | if (result.first != null) { |
| 7129 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7130 | Bundle outputResult = new Bundle(); |
| 7131 | outputResult.putParcelable( |
| 7132 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7133 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7134 | outputResult); |
| 7135 | } else { |
| 7136 | callback.send(result.second, null); |
| 7137 | } |
| 7138 | } |
| 7139 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7140 | }); |
| 7141 | } |
| 7142 | |
| 7143 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7144 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7145 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7146 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7147 | |
| 7148 | final long identity = Binder.clearCallingIdentity(); |
| 7149 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7150 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7151 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7152 | } finally { |
| 7153 | Binder.restoreCallingIdentity(identity); |
| 7154 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7155 | } |
| 7156 | |
| 7157 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7158 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7159 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7160 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7161 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7162 | return false; |
| 7163 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7164 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7165 | final long identity = Binder.clearCallingIdentity(); |
| 7166 | try { |
| 7167 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7168 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7169 | // In the long run, we may instead need to check if there exists a connection service |
| 7170 | // which can support video calling. |
| 7171 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7172 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7173 | return imsManager.isVtEnabledByPlatform() |
| 7174 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7175 | && imsManager.isVtEnabledByUser(); |
| 7176 | } finally { |
| 7177 | Binder.restoreCallingIdentity(identity); |
| 7178 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7179 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7180 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7181 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7182 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7183 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7184 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7185 | mApp, subId, callingPackage, callingFeatureId, |
| 7186 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7187 | return false; |
| 7188 | } |
| 7189 | |
| 7190 | final long identity = Binder.clearCallingIdentity(); |
| 7191 | try { |
| 7192 | CarrierConfigManager configManager = |
| 7193 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7194 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7195 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7196 | } finally { |
| 7197 | Binder.restoreCallingIdentity(identity); |
| 7198 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7199 | } |
| 7200 | |
| 7201 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7202 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7203 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7204 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7205 | return false; |
| 7206 | } |
| 7207 | |
| 7208 | final long identity = Binder.clearCallingIdentity(); |
| 7209 | try { |
| 7210 | CarrierConfigManager configManager = |
| 7211 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7212 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7213 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7214 | } finally { |
| 7215 | Binder.restoreCallingIdentity(identity); |
| 7216 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7217 | } |
| 7218 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7219 | @Override |
| 7220 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7221 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7222 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7223 | } |
| 7224 | |
| 7225 | @Override |
| 7226 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7227 | final long identity = Binder.clearCallingIdentity(); |
| 7228 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7229 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7230 | } finally { |
| 7231 | Binder.restoreCallingIdentity(identity); |
| 7232 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7233 | } |
| 7234 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7235 | /** |
| 7236 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7237 | * support for the feature and device firmware support. |
| 7238 | * |
| 7239 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7240 | */ |
| 7241 | @Override |
| 7242 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7243 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7244 | final Phone phone = getPhone(subscriptionId); |
| 7245 | if (phone == null) { |
| 7246 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7247 | return false; |
| 7248 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7249 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7250 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7251 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7252 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7253 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7254 | return isCarrierSupported && isDeviceSupported; |
| 7255 | } finally { |
| 7256 | Binder.restoreCallingIdentity(identity); |
| 7257 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7258 | } |
| 7259 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7260 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7261 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7262 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7263 | * 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] | 7264 | */ |
| 7265 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7266 | final long identity = Binder.clearCallingIdentity(); |
| 7267 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7268 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7269 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7270 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7271 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7272 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7273 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7274 | } finally { |
| 7275 | Binder.restoreCallingIdentity(identity); |
| 7276 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7277 | } |
| 7278 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7279 | @Deprecated |
| 7280 | @Override |
| 7281 | public String getDeviceId(String callingPackage) { |
| 7282 | return getDeviceIdWithFeature(callingPackage, null); |
| 7283 | } |
| 7284 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7285 | /** |
| 7286 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7287 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7288 | * |
| 7289 | * <p>Requires Permission: |
| 7290 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7291 | */ |
| 7292 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7293 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7294 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7295 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7296 | return null; |
| 7297 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7298 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7299 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7300 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7301 | return null; |
| 7302 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7303 | |
| 7304 | final long identity = Binder.clearCallingIdentity(); |
| 7305 | try { |
| 7306 | return phone.getDeviceId(); |
| 7307 | } finally { |
| 7308 | Binder.restoreCallingIdentity(identity); |
| 7309 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7310 | } |
| 7311 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7312 | /** |
| 7313 | * {@hide} |
| 7314 | * Returns the IMS Registration Status on a particular subid |
| 7315 | * |
| 7316 | * @param subId |
| 7317 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7318 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7319 | Phone phone = getPhone(subId); |
| 7320 | if (phone != null) { |
| 7321 | return phone.isImsRegistered(); |
| 7322 | } else { |
| 7323 | return false; |
| 7324 | } |
| 7325 | } |
| 7326 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7327 | @Override |
| 7328 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7329 | final long identity = Binder.clearCallingIdentity(); |
| 7330 | try { |
| 7331 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 7332 | } finally { |
| 7333 | Binder.restoreCallingIdentity(identity); |
| 7334 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7335 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7336 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7337 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7338 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7339 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7340 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7341 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7342 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7343 | } |
| 7344 | final long identity = Binder.clearCallingIdentity(); |
| 7345 | try { |
| 7346 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7347 | } finally { |
| 7348 | Binder.restoreCallingIdentity(identity); |
| 7349 | } |
| 7350 | } |
| 7351 | |
| 7352 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7353 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 7354 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 7355 | + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7356 | final long identity = Binder.clearCallingIdentity(); |
| 7357 | try { |
| 7358 | Phone phone = getPhone(subscriptionId); |
| 7359 | if (phone == null) { |
| 7360 | return null; |
| 7361 | } |
| 7362 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7363 | } finally { |
| 7364 | Binder.restoreCallingIdentity(identity); |
| 7365 | } |
| 7366 | } |
| 7367 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7368 | /** |
| 7369 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7370 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7371 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7372 | final long identity = Binder.clearCallingIdentity(); |
| 7373 | try { |
| 7374 | Phone phone = getPhone(subId); |
| 7375 | if (phone != null) { |
| 7376 | return phone.isWifiCallingEnabled(); |
| 7377 | } else { |
| 7378 | return false; |
| 7379 | } |
| 7380 | } finally { |
| 7381 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7382 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7383 | } |
| 7384 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7385 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7386 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7387 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7388 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7389 | final long identity = Binder.clearCallingIdentity(); |
| 7390 | try { |
| 7391 | Phone phone = getPhone(subId); |
| 7392 | if (phone != null) { |
| 7393 | return phone.isVideoEnabled(); |
| 7394 | } else { |
| 7395 | return false; |
| 7396 | } |
| 7397 | } finally { |
| 7398 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7399 | } |
| 7400 | } |
| 7401 | |
| 7402 | /** |
| 7403 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7404 | * defined in {@link ImsRegistrationImplBase}. |
| 7405 | */ |
| 7406 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7407 | final long identity = Binder.clearCallingIdentity(); |
| 7408 | try { |
| 7409 | Phone phone = getPhone(subId); |
| 7410 | if (phone != null) { |
| 7411 | return phone.getImsRegistrationTech(); |
| 7412 | } else { |
| 7413 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7414 | } |
| 7415 | } finally { |
| 7416 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7417 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7418 | } |
| 7419 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7420 | @Override |
| 7421 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7422 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7423 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7424 | return; |
| 7425 | } |
| 7426 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7427 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7428 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7429 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7430 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7431 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7432 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7433 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7434 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7435 | Phone phone = getPhone(subId); |
| 7436 | if (phone != null) { |
| 7437 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7438 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7439 | "user=" + RadioAccessFamily.getRafFromNetworkType( |
| 7440 | RILConstants.PREFERRED_NETWORK_MODE)); |
| 7441 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7442 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7443 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 7444 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7445 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7446 | // There has been issues when Sms raw table somehow stores orphan |
| 7447 | // fragments. They lead to garbled message when new fragments come |
| 7448 | // in and combined with those stale ones. In case this happens again, |
| 7449 | // user can reset all network settings which will clean up this table. |
| 7450 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7451 | // Clean up IMS settings as well here. |
| 7452 | int slotId = getSlotIndex(subId); |
| 7453 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7454 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7455 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7456 | |
| 7457 | // Erase modem config if erase modem on network setting is enabled. |
| 7458 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7459 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7460 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 7461 | sendEraseModemConfig(getDefaultPhone()); |
| 7462 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7463 | } finally { |
| 7464 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7465 | } |
| 7466 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7467 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7468 | private void cleanUpSmsRawTable(Context context) { |
| 7469 | ContentResolver resolver = context.getContentResolver(); |
| 7470 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7471 | resolver.delete(uri, null, null); |
| 7472 | } |
| 7473 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7474 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7475 | public String getSimLocaleForSubscriber(int subId) { |
| 7476 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7477 | final Phone phone = getPhone(subId); |
| 7478 | if (phone == null) { |
| 7479 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7480 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7481 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7482 | final long identity = Binder.clearCallingIdentity(); |
| 7483 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7484 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7485 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7486 | if (info == null) { |
| 7487 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7488 | return null; |
| 7489 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7490 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7491 | // preferences (EF-PL and EF-LI)... |
| 7492 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7493 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7494 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7495 | if (localeFromDefaultSim != null) { |
| 7496 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7497 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7498 | + localeFromDefaultSim); |
| 7499 | return localeFromDefaultSim.toLanguageTag(); |
| 7500 | } else { |
| 7501 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7502 | } |
| 7503 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7504 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7505 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7506 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7507 | // the SIM and carrier preferences does not include a country we add the country |
| 7508 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7509 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7510 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7511 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7512 | return mccLocale.toLanguageTag(); |
| 7513 | } |
| 7514 | |
| 7515 | if (DBG) log("No locale found - returning null"); |
| 7516 | return null; |
| 7517 | } finally { |
| 7518 | Binder.restoreCallingIdentity(identity); |
| 7519 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7520 | } |
| 7521 | |
| 7522 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7523 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7524 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7525 | } |
| 7526 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7527 | /** |
| 7528 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7529 | */ |
| 7530 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7531 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7532 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7533 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7534 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7535 | private final ModemActivityInfo mLastModemActivityInfo = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7536 | new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7537 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7538 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7539 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7540 | * representing the state of the modem. |
| 7541 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7542 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7543 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7544 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7545 | */ |
| 7546 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7547 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7548 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7549 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7550 | |
| 7551 | final long identity = Binder.clearCallingIdentity(); |
| 7552 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7553 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7554 | } finally { |
| 7555 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7556 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7557 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7558 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7559 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7560 | // less than total activity duration. |
| 7561 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7562 | if (info == null) { |
| 7563 | return false; |
| 7564 | } |
| 7565 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7566 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7567 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7568 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7569 | return (info.isValid() |
| 7570 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7571 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7572 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7573 | && (totalTxTimeMs <= activityDurationMs)); |
| 7574 | } |
| 7575 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7576 | /** |
| 7577 | * {@hide} |
| 7578 | * Returns the service state information on specified subscription. |
| 7579 | */ |
| 7580 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7581 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7582 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7583 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7584 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7585 | return null; |
| 7586 | } |
| 7587 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7588 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7589 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7590 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7591 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7592 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7593 | .setCallingPid(Binder.getCallingPid()) |
| 7594 | .setCallingUid(Binder.getCallingUid()) |
| 7595 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7596 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7597 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7598 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7599 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7600 | .build()); |
| 7601 | |
| 7602 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7603 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7604 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7605 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7606 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7607 | .setCallingPid(Binder.getCallingPid()) |
| 7608 | .setCallingUid(Binder.getCallingUid()) |
| 7609 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7610 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7611 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7612 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7613 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7614 | .build()); |
| 7615 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7616 | boolean hasFinePermission = |
| 7617 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7618 | boolean hasCoarsePermission = |
| 7619 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7620 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7621 | final Phone phone = getPhone(subId); |
| 7622 | if (phone == null) { |
| 7623 | return null; |
| 7624 | } |
| 7625 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 7626 | final long identity = Binder.clearCallingIdentity(); |
| 7627 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7628 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7629 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7630 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7631 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7632 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7633 | Rlog.d(LOG_TAG, |
| 7634 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7635 | return null; |
| 7636 | } |
| 7637 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7638 | ServiceState ss = phone.getServiceState(); |
| 7639 | |
| 7640 | // Scrub out the location info in ServiceState depending on what level of access |
| 7641 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7642 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7643 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7644 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7645 | } finally { |
| 7646 | Binder.restoreCallingIdentity(identity); |
| 7647 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7648 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7649 | |
| 7650 | /** |
| 7651 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7652 | * |
| 7653 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7654 | * voicemail ringtone. |
| 7655 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7656 | * PhoneAccount. |
| 7657 | */ |
| 7658 | @Override |
| 7659 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7660 | final long identity = Binder.clearCallingIdentity(); |
| 7661 | try { |
| 7662 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7663 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7664 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7665 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7666 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7667 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7668 | } finally { |
| 7669 | Binder.restoreCallingIdentity(identity); |
| 7670 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7671 | } |
| 7672 | |
| 7673 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7674 | * Sets the per-account voicemail ringtone. |
| 7675 | * |
| 7676 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7677 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7678 | * |
| 7679 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7680 | * voicemail ringtone. |
| 7681 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7682 | * PhoneAccount. |
| 7683 | */ |
| 7684 | @Override |
| 7685 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7686 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7687 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7688 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7689 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7690 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7691 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7692 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7693 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7694 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7695 | |
| 7696 | final long identity = Binder.clearCallingIdentity(); |
| 7697 | try { |
| 7698 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7699 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7700 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7701 | } |
| 7702 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7703 | } finally { |
| 7704 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7705 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7706 | } |
| 7707 | |
| 7708 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7709 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7710 | * |
| 7711 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7712 | * voicemail vibration setting. |
| 7713 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7714 | */ |
| 7715 | @Override |
| 7716 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7717 | final long identity = Binder.clearCallingIdentity(); |
| 7718 | try { |
| 7719 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7720 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7721 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7722 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7723 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7724 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7725 | } finally { |
| 7726 | Binder.restoreCallingIdentity(identity); |
| 7727 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7728 | } |
| 7729 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7730 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7731 | * Sets the per-account voicemail vibration. |
| 7732 | * |
| 7733 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7734 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7735 | * |
| 7736 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7737 | * voicemail vibration setting. |
| 7738 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7739 | * specific PhoneAccount. |
| 7740 | */ |
| 7741 | @Override |
| 7742 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7743 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7744 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7745 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7746 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7747 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7748 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7749 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7750 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7751 | } |
| 7752 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7753 | final long identity = Binder.clearCallingIdentity(); |
| 7754 | try { |
| 7755 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7756 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7757 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7758 | } |
| 7759 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7760 | } finally { |
| 7761 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7762 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7763 | } |
| 7764 | |
| 7765 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7766 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7767 | * |
| 7768 | * @throws SecurityException if the caller does not have the required permission |
| 7769 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7770 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7771 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7772 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7773 | } |
| 7774 | |
| 7775 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7776 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7777 | * permission. |
| 7778 | * |
| 7779 | * @throws SecurityException if the caller does not have the required permission |
| 7780 | */ |
| 7781 | private void enforceSendSmsPermission() { |
| 7782 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7783 | } |
| 7784 | |
| 7785 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7786 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7787 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7788 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7789 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7790 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7791 | final long identity = Binder.clearCallingIdentity(); |
| 7792 | try { |
| 7793 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7794 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7795 | if (componentName == null) { |
| 7796 | throw new SecurityException( |
| 7797 | "Caller not current active visual voicemail package[null]"); |
| 7798 | } |
| 7799 | String vvmPackage = componentName.getPackageName(); |
| 7800 | if (!callingPackage.equals(vvmPackage)) { |
| 7801 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7802 | + vvmPackage + "]"); |
| 7803 | } |
| 7804 | } finally { |
| 7805 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7806 | } |
| 7807 | } |
| 7808 | |
| 7809 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7810 | * Return the application ID for the app type. |
| 7811 | * |
| 7812 | * @param subId the subscription ID that this request applies to. |
| 7813 | * @param appType the uicc app type. |
| 7814 | * @return Application ID for specificied app type, or null if no uicc. |
| 7815 | */ |
| 7816 | @Override |
| 7817 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7818 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7819 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7820 | |
| 7821 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7822 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7823 | if (phone == null) { |
| 7824 | return null; |
| 7825 | } |
| 7826 | String aid = null; |
| 7827 | try { |
| 7828 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7829 | .getApplicationByType(appType).getAid(); |
| 7830 | } catch (Exception e) { |
| 7831 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7832 | } |
| 7833 | return aid; |
| 7834 | } finally { |
| 7835 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7836 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7837 | } |
| 7838 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7839 | /** |
| 7840 | * Return the Electronic Serial Number. |
| 7841 | * |
| 7842 | * @param subId the subscription ID that this request applies to. |
| 7843 | * @return ESN or null if error. |
| 7844 | */ |
| 7845 | @Override |
| 7846 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7847 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7848 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7849 | |
| 7850 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7851 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7852 | if (phone == null) { |
| 7853 | return null; |
| 7854 | } |
| 7855 | String esn = null; |
| 7856 | try { |
| 7857 | esn = phone.getEsn(); |
| 7858 | } catch (Exception e) { |
| 7859 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7860 | } |
| 7861 | return esn; |
| 7862 | } finally { |
| 7863 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7864 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7865 | } |
| 7866 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7867 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7868 | * Return the Preferred Roaming List Version. |
| 7869 | * |
| 7870 | * @param subId the subscription ID that this request applies to. |
| 7871 | * @return PRLVersion or null if error. |
| 7872 | */ |
| 7873 | @Override |
| 7874 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7875 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7876 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7877 | |
| 7878 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7879 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7880 | if (phone == null) { |
| 7881 | return null; |
| 7882 | } |
| 7883 | String cdmaPrlVersion = null; |
| 7884 | try { |
| 7885 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7886 | } catch (Exception e) { |
| 7887 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7888 | } |
| 7889 | return cdmaPrlVersion; |
| 7890 | } finally { |
| 7891 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7892 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7893 | } |
| 7894 | |
| 7895 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7896 | * Get snapshot of Telephony histograms |
| 7897 | * @return List of Telephony histograms |
| 7898 | * @hide |
| 7899 | */ |
| 7900 | @Override |
| 7901 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7902 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7903 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7904 | |
| 7905 | final long identity = Binder.clearCallingIdentity(); |
| 7906 | try { |
| 7907 | return RIL.getTelephonyRILTimingHistograms(); |
| 7908 | } finally { |
| 7909 | Binder.restoreCallingIdentity(identity); |
| 7910 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7911 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7912 | |
| 7913 | /** |
| 7914 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7915 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7916 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7917 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7918 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7919 | * @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] | 7920 | */ |
| 7921 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7922 | @TelephonyManager.SetCarrierRestrictionResult |
| 7923 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7924 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7925 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7926 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7927 | if (carrierRestrictionRules == null) { |
| 7928 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7929 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7930 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7931 | final long identity = Binder.clearCallingIdentity(); |
| 7932 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7933 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7934 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7935 | } finally { |
| 7936 | Binder.restoreCallingIdentity(identity); |
| 7937 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7938 | } |
| 7939 | |
| 7940 | /** |
| 7941 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7942 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7943 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7944 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7945 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7946 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7947 | */ |
| 7948 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7949 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7950 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7951 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7952 | |
| 7953 | final long identity = Binder.clearCallingIdentity(); |
| 7954 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7955 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7956 | if (response instanceof CarrierRestrictionRules) { |
| 7957 | return (CarrierRestrictionRules) response; |
| 7958 | } |
| 7959 | // Response is an Exception of some kind, |
| 7960 | // which is signalled to the user as a NULL retval |
| 7961 | return null; |
| 7962 | } catch (Exception e) { |
| 7963 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7964 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7965 | } finally { |
| 7966 | Binder.restoreCallingIdentity(identity); |
| 7967 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7968 | } |
| 7969 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7970 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7971 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7972 | * @param subId the subscription ID that this action applies to. |
| 7973 | * @param enabled control enable or disable radio. |
| 7974 | * {@hide} |
| 7975 | */ |
| 7976 | @Override |
| 7977 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7978 | enforceModifyPermission(); |
| 7979 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7980 | |
| 7981 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7982 | if (phone == null) { |
| 7983 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7984 | return; |
| 7985 | } |
| 7986 | try { |
| 7987 | phone.carrierActionSetRadioEnabled(enabled); |
| 7988 | } catch (Exception e) { |
| 7989 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7990 | } finally { |
| 7991 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7992 | } |
| 7993 | } |
| 7994 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7995 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7996 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7997 | * network status based on which carrier apps could apply actions accordingly, |
| 7998 | * enable/disable default url handler for example. |
| 7999 | * |
| 8000 | * @param subId the subscription ID that this action applies to. |
| 8001 | * @param report control start/stop reporting the default network status. |
| 8002 | * {@hide} |
| 8003 | */ |
| 8004 | @Override |
| 8005 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8006 | enforceModifyPermission(); |
| 8007 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8008 | |
| 8009 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8010 | if (phone == null) { |
| 8011 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8012 | return; |
| 8013 | } |
| 8014 | try { |
| 8015 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8016 | } catch (Exception e) { |
| 8017 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8018 | } finally { |
| 8019 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8020 | } |
| 8021 | } |
| 8022 | |
| 8023 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8024 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8025 | * @param subId the subscription ID that this action applies to. |
| 8026 | * {@hide} |
| 8027 | */ |
| 8028 | @Override |
| 8029 | public void carrierActionResetAll(int subId) { |
| 8030 | enforceModifyPermission(); |
| 8031 | final Phone phone = getPhone(subId); |
| 8032 | if (phone == null) { |
| 8033 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8034 | return; |
| 8035 | } |
| 8036 | try { |
| 8037 | phone.carrierActionResetAll(); |
| 8038 | } catch (Exception e) { |
| 8039 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8040 | } |
| 8041 | } |
| 8042 | |
| 8043 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8044 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8045 | * bug report is being generated. |
| 8046 | */ |
| 8047 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8048 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8049 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8050 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8051 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8052 | + Binder.getCallingPid() |
| 8053 | + ", uid=" + Binder.getCallingUid() |
| 8054 | + "without permission " |
| 8055 | + android.Manifest.permission.DUMP); |
| 8056 | return; |
| 8057 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8058 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8059 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8060 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8061 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8062 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8063 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8064 | @NonNull String[] args) { |
| 8065 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8066 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8067 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8068 | } |
| 8069 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8070 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8071 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8072 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8073 | * @param reason the reason the data enable change is taking place |
| 8074 | * @param enabled True if enabling the data, otherwise disabling. |
| 8075 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8076 | */ |
| 8077 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8078 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8079 | boolean enabled) { |
| 8080 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8081 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8082 | try { |
| 8083 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8084 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8085 | } catch (SecurityException se) { |
| 8086 | enforceModifyPermission(); |
| 8087 | } |
| 8088 | } else { |
| 8089 | enforceModifyPermission(); |
| 8090 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8091 | |
| 8092 | final long identity = Binder.clearCallingIdentity(); |
| 8093 | try { |
| 8094 | Phone phone = getPhone(subId); |
| 8095 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8096 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8097 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8098 | } else { |
| 8099 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 8100 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8101 | } |
| 8102 | } finally { |
| 8103 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8104 | } |
| 8105 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8106 | |
| 8107 | /** |
| 8108 | * Get Client request stats |
| 8109 | * @return List of Client Request Stats |
| 8110 | * @hide |
| 8111 | */ |
| 8112 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8113 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8114 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8115 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8116 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8117 | return null; |
| 8118 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8119 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8120 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8121 | final long identity = Binder.clearCallingIdentity(); |
| 8122 | try { |
| 8123 | if (phone != null) { |
| 8124 | return phone.getClientRequestStats(); |
| 8125 | } |
| 8126 | |
| 8127 | return null; |
| 8128 | } finally { |
| 8129 | Binder.restoreCallingIdentity(identity); |
| 8130 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8131 | } |
| 8132 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8133 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8134 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8135 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8136 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8137 | |
| 8138 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8139 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8140 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8141 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8142 | * @param state State of SIM (power down, power up, pass through) |
| 8143 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8144 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8145 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8146 | * |
| 8147 | **/ |
| 8148 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8149 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8150 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8151 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8152 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8153 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8154 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8155 | final long identity = Binder.clearCallingIdentity(); |
| 8156 | try { |
| 8157 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8158 | phone.setSimPowerState(state, null, workSource); |
| 8159 | } |
| 8160 | } finally { |
| 8161 | Binder.restoreCallingIdentity(identity); |
| 8162 | } |
| 8163 | } |
| 8164 | |
| 8165 | /** |
| 8166 | * Set SIM card power state. |
| 8167 | * |
| 8168 | * @param slotIndex SIM slot id. |
| 8169 | * @param state State of SIM (power down, power up, pass through) |
| 8170 | * @param callback callback to trigger after success or failure |
| 8171 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8172 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8173 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8174 | * |
| 8175 | **/ |
| 8176 | @Override |
| 8177 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8178 | IIntegerConsumer callback) { |
| 8179 | enforceModifyPermission(); |
| 8180 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8181 | |
| 8182 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8183 | |
| 8184 | final long identity = Binder.clearCallingIdentity(); |
| 8185 | try { |
| 8186 | if (phone != null) { |
| 8187 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8188 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8189 | } |
| 8190 | } finally { |
| 8191 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8192 | } |
| 8193 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8194 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8195 | private boolean isUssdApiAllowed(int subId) { |
| 8196 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8197 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8198 | if (configManager == null) { |
| 8199 | return false; |
| 8200 | } |
| 8201 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8202 | if (pb == null) { |
| 8203 | return false; |
| 8204 | } |
| 8205 | return pb.getBoolean( |
| 8206 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8207 | } |
| 8208 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8209 | /** |
| 8210 | * Check if phone is in emergency callback mode |
| 8211 | * @return true if phone is in emergency callback mode |
| 8212 | * @param subId sub id |
| 8213 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8214 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8215 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8216 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8217 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8218 | |
| 8219 | final long identity = Binder.clearCallingIdentity(); |
| 8220 | try { |
| 8221 | if (phone != null) { |
| 8222 | return phone.isInEcm(); |
| 8223 | } else { |
| 8224 | return false; |
| 8225 | } |
| 8226 | } finally { |
| 8227 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8228 | } |
| 8229 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8230 | |
| 8231 | /** |
| 8232 | * Get the current signal strength information for the given subscription. |
| 8233 | * Because this information is not updated when the device is in a low power state |
| 8234 | * it should not be relied-upon to be current. |
| 8235 | * @param subId Subscription index |
| 8236 | * @return the most recent cached signal strength info from the modem |
| 8237 | */ |
| 8238 | @Override |
| 8239 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8240 | final long identity = Binder.clearCallingIdentity(); |
| 8241 | try { |
| 8242 | Phone p = getPhone(subId); |
| 8243 | if (p == null) { |
| 8244 | return null; |
| 8245 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8246 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8247 | return p.getSignalStrength(); |
| 8248 | } finally { |
| 8249 | Binder.restoreCallingIdentity(identity); |
| 8250 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8251 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8252 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8253 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8254 | * Get the current modem radio state for the given slot. |
| 8255 | * @param slotIndex slot index. |
| 8256 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8257 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8258 | * @return the current radio power state from the modem |
| 8259 | */ |
| 8260 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8261 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8262 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8263 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8264 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8265 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8266 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8267 | } |
| 8268 | |
| 8269 | final long identity = Binder.clearCallingIdentity(); |
| 8270 | try { |
| 8271 | return phone.getRadioPowerState(); |
| 8272 | } finally { |
| 8273 | Binder.restoreCallingIdentity(identity); |
| 8274 | } |
| 8275 | } |
| 8276 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8277 | } |
| 8278 | |
| 8279 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8280 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8281 | * |
| 8282 | * <p>Requires one of the following permissions: |
| 8283 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 8284 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8285 | * privileges. |
| 8286 | * |
| 8287 | * @param subId subscription id |
| 8288 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8289 | * {@code false}. |
| 8290 | */ |
| 8291 | @Override |
| 8292 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8293 | try { |
| 8294 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8295 | null); |
| 8296 | } catch (Exception e) { |
| 8297 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 8298 | mApp, subId, "isDataRoamingEnabled"); |
| 8299 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8300 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8301 | boolean isEnabled = false; |
| 8302 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8303 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8304 | Phone phone = getPhone(subId); |
| 8305 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8306 | } finally { |
| 8307 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8308 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8309 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8310 | } |
| 8311 | |
| 8312 | |
| 8313 | /** |
| 8314 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8315 | * |
| 8316 | * <p> Requires permission: |
| 8317 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8318 | * privileges. |
| 8319 | * |
| 8320 | * @param subId subscription id |
| 8321 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8322 | */ |
| 8323 | @Override |
| 8324 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8325 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8326 | mApp, subId, "setDataRoamingEnabled"); |
| 8327 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8328 | final long identity = Binder.clearCallingIdentity(); |
| 8329 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8330 | Phone phone = getPhone(subId); |
| 8331 | if (phone != null) { |
| 8332 | phone.setDataRoamingEnabled(isEnabled); |
| 8333 | } |
| 8334 | } finally { |
| 8335 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8336 | } |
| 8337 | } |
| 8338 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8339 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8340 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8341 | TelephonyPermissions |
| 8342 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8343 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8344 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8345 | boolean isAllowed = true; |
| 8346 | final long identity = Binder.clearCallingIdentity(); |
| 8347 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8348 | Phone phone = getPhone(subId); |
| 8349 | if (phone != null) { |
| 8350 | isAllowed = phone.isCspPlmnEnabled(); |
| 8351 | } |
| 8352 | } finally { |
| 8353 | Binder.restoreCallingIdentity(identity); |
| 8354 | } |
| 8355 | return isAllowed; |
| 8356 | } |
| 8357 | |
| 8358 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8359 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8360 | // Verify that tha callingPackage belongs to the calling UID |
| 8361 | mApp.getSystemService(AppOpsManager.class) |
| 8362 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8363 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8364 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8365 | try { |
| 8366 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8367 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8368 | } catch (SecurityException e) { |
| 8369 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8370 | // has carrier privileges on an active UICC |
| 8371 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8372 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8373 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8374 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8375 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8376 | |
| 8377 | final long identity = Binder.clearCallingIdentity(); |
| 8378 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8379 | UiccController uiccController = UiccController.getInstance(); |
| 8380 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8381 | if (hasReadPermission) { |
| 8382 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8383 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8384 | |
| 8385 | // Remove private info if the caller doesn't have access |
| 8386 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8387 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8388 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8389 | // is available |
| 8390 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 8391 | if (card == null || card.getUiccProfile() == null) { |
| 8392 | // assume no access if the card or profile is unavailable |
| 8393 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8394 | continue; |
| 8395 | } |
| 8396 | UiccProfile profile = card.getUiccProfile(); |
| 8397 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8398 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8399 | filteredInfos.add(cardInfo); |
| 8400 | } else { |
| 8401 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8402 | } |
| 8403 | } |
| 8404 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8405 | } finally { |
| 8406 | Binder.restoreCallingIdentity(identity); |
| 8407 | } |
| 8408 | } |
| 8409 | |
| 8410 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8411 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8412 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8413 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8414 | final long identity = Binder.clearCallingIdentity(); |
| 8415 | try { |
| 8416 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8417 | if (slots == null) { |
| 8418 | Rlog.i(LOG_TAG, "slots is null."); |
| 8419 | return null; |
| 8420 | } |
| 8421 | |
| 8422 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8423 | for (int i = 0; i < slots.length; i++) { |
| 8424 | UiccSlot slot = slots[i]; |
| 8425 | if (slot == null) { |
| 8426 | continue; |
| 8427 | } |
| 8428 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8429 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8430 | UiccCard card = slot.getUiccCard(); |
| 8431 | if (card != null) { |
| 8432 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8433 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8434 | cardId = slot.getEid(); |
| 8435 | if (TextUtils.isEmpty(cardId)) { |
| 8436 | cardId = slot.getIccId(); |
| 8437 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8438 | } |
| 8439 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8440 | if (cardId != null) { |
| 8441 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8442 | // if cardId is an EID, it's all digits so this is fine |
| 8443 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8444 | } |
| 8445 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8446 | int cardState = 0; |
| 8447 | switch (slot.getCardState()) { |
| 8448 | case CARDSTATE_ABSENT: |
| 8449 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8450 | break; |
| 8451 | case CARDSTATE_PRESENT: |
| 8452 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8453 | break; |
| 8454 | case CARDSTATE_ERROR: |
| 8455 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8456 | break; |
| 8457 | case CARDSTATE_RESTRICTED: |
| 8458 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8459 | break; |
| 8460 | default: |
| 8461 | break; |
| 8462 | |
| 8463 | } |
| 8464 | |
| 8465 | infos[i] = new UiccSlotInfo( |
| 8466 | slot.isActive(), |
| 8467 | slot.isEuicc(), |
| 8468 | cardId, |
| 8469 | cardState, |
| 8470 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8471 | slot.isExtendedApduSupported(), |
| 8472 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8473 | } |
| 8474 | return infos; |
| 8475 | } finally { |
| 8476 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8477 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8478 | } |
| 8479 | |
| 8480 | @Override |
| 8481 | public boolean switchSlots(int[] physicalSlots) { |
| 8482 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8483 | |
| 8484 | final long identity = Binder.clearCallingIdentity(); |
| 8485 | try { |
| 8486 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8487 | } finally { |
| 8488 | Binder.restoreCallingIdentity(identity); |
| 8489 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8490 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8491 | |
| 8492 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8493 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8494 | final long identity = Binder.clearCallingIdentity(); |
| 8495 | try { |
| 8496 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8497 | } finally { |
| 8498 | Binder.restoreCallingIdentity(identity); |
| 8499 | } |
| 8500 | } |
| 8501 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8502 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8503 | * A test API to reload the UICC profile. |
| 8504 | * |
| 8505 | * <p>Requires that the calling app has permission |
| 8506 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8507 | * @hide |
| 8508 | */ |
| 8509 | @Override |
| 8510 | public void refreshUiccProfile(int subId) { |
| 8511 | enforceModifyPermission(); |
| 8512 | |
| 8513 | final long identity = Binder.clearCallingIdentity(); |
| 8514 | try { |
| 8515 | Phone phone = getPhone(subId); |
| 8516 | if (phone == null) { |
| 8517 | return; |
| 8518 | } |
| 8519 | UiccCard uiccCard = phone.getUiccCard(); |
| 8520 | if (uiccCard == null) { |
| 8521 | return; |
| 8522 | } |
| 8523 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8524 | if (uiccProfile == null) { |
| 8525 | return; |
| 8526 | } |
| 8527 | uiccProfile.refresh(); |
| 8528 | } finally { |
| 8529 | Binder.restoreCallingIdentity(identity); |
| 8530 | } |
| 8531 | } |
| 8532 | |
| 8533 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8534 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8535 | */ |
| 8536 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8537 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8538 | } |
| 8539 | |
| 8540 | /** |
| 8541 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8542 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8543 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8544 | */ |
| 8545 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8546 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8547 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8548 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8549 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8550 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8551 | return isDataRoamingEnabled; |
| 8552 | } |
| 8553 | |
| 8554 | /** |
| 8555 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8556 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8557 | */ |
| 8558 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8559 | List<Integer> list = TelephonyProperties.default_network(); |
| 8560 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8561 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8562 | return list.get(phoneId); |
| 8563 | } |
| 8564 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8565 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8566 | |
| 8567 | @Override |
| 8568 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8569 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8570 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8571 | |
| 8572 | final long identity = Binder.clearCallingIdentity(); |
| 8573 | try { |
| 8574 | final Phone phone = getPhone(subId); |
| 8575 | if (phone == null) { |
| 8576 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8577 | return; |
| 8578 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8579 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8580 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8581 | if (carrierPrivilegeRules == null) { |
| 8582 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8583 | } else { |
| 8584 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8585 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8586 | } finally { |
| 8587 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8588 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8589 | } |
| 8590 | |
| 8591 | @Override |
| 8592 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8593 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8594 | |
| 8595 | final long identity = Binder.clearCallingIdentity(); |
| 8596 | try { |
| 8597 | final Phone phone = getPhone(subId); |
| 8598 | if (phone == null) { |
| 8599 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8600 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8601 | } |
| 8602 | return phone.getCarrierIdListVersion(); |
| 8603 | } finally { |
| 8604 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8605 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8606 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8607 | |
| 8608 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8609 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8610 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8611 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8612 | mApp, subId, callingPackage, callingFeatureId, |
| 8613 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8614 | return -1; |
| 8615 | } |
| 8616 | |
| 8617 | final long identity = Binder.clearCallingIdentity(); |
| 8618 | try { |
| 8619 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8620 | } finally { |
| 8621 | Binder.restoreCallingIdentity(identity); |
| 8622 | } |
| 8623 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8624 | |
| 8625 | @Override |
| 8626 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8627 | TelephonyPermissions |
| 8628 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8629 | mApp, subId, "getCdmaRoamingMode"); |
| 8630 | |
| 8631 | final long identity = Binder.clearCallingIdentity(); |
| 8632 | try { |
| 8633 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8634 | } finally { |
| 8635 | Binder.restoreCallingIdentity(identity); |
| 8636 | } |
| 8637 | } |
| 8638 | |
| 8639 | @Override |
| 8640 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8641 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8642 | mApp, subId, "setCdmaRoamingMode"); |
| 8643 | |
| 8644 | final long identity = Binder.clearCallingIdentity(); |
| 8645 | try { |
| 8646 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8647 | } finally { |
| 8648 | Binder.restoreCallingIdentity(identity); |
| 8649 | } |
| 8650 | } |
| 8651 | |
| 8652 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8653 | public int getCdmaSubscriptionMode(int subId) { |
| 8654 | TelephonyPermissions |
| 8655 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8656 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8657 | |
| 8658 | final long identity = Binder.clearCallingIdentity(); |
| 8659 | try { |
| 8660 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8661 | } finally { |
| 8662 | Binder.restoreCallingIdentity(identity); |
| 8663 | } |
| 8664 | } |
| 8665 | |
| 8666 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8667 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8668 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8669 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8670 | |
| 8671 | final long identity = Binder.clearCallingIdentity(); |
| 8672 | try { |
| 8673 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8674 | } finally { |
| 8675 | Binder.restoreCallingIdentity(identity); |
| 8676 | } |
| 8677 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8678 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8679 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8680 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8681 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8682 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8683 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8684 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8685 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8686 | } |
| 8687 | final long identity = Binder.clearCallingIdentity(); |
| 8688 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8689 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8690 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8691 | if (phone.getEmergencyNumberTracker() != null |
| 8692 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8693 | emergencyNumberListInternal.put( |
| 8694 | phone.getSubId(), |
| 8695 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8696 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8697 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8698 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8699 | } finally { |
| 8700 | Binder.restoreCallingIdentity(identity); |
| 8701 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8702 | } |
| 8703 | |
| 8704 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8705 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8706 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8707 | if (!exactMatch) { |
| 8708 | TelephonyPermissions |
| 8709 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8710 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8711 | } |
| 8712 | final long identity = Binder.clearCallingIdentity(); |
| 8713 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8714 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8715 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8716 | && phone.getEmergencyNumberTracker() |
| 8717 | .isEmergencyNumber(number, exactMatch)) { |
| 8718 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8719 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8720 | } |
| 8721 | return false; |
| 8722 | } finally { |
| 8723 | Binder.restoreCallingIdentity(identity); |
| 8724 | } |
| 8725 | } |
| 8726 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8727 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 8728 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 8729 | */ |
| 8730 | @Override |
| 8731 | public void startEmergencyCallbackMode() { |
| 8732 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8733 | "startEmergencyCallbackMode"); |
| 8734 | enforceModifyPermission(); |
| 8735 | final long identity = Binder.clearCallingIdentity(); |
| 8736 | try { |
| 8737 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8738 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 8739 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 8740 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 8741 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 8742 | gsmCdmaPhone.obtainMessage( |
| 8743 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 8744 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 8745 | } |
| 8746 | } |
| 8747 | } finally { |
| 8748 | Binder.restoreCallingIdentity(identity); |
| 8749 | } |
| 8750 | } |
| 8751 | |
| 8752 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8753 | * Update emergency number list for test mode. |
| 8754 | */ |
| 8755 | @Override |
| 8756 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8757 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8758 | "updateEmergencyNumberListTestMode"); |
| 8759 | |
| 8760 | final long identity = Binder.clearCallingIdentity(); |
| 8761 | try { |
| 8762 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8763 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8764 | if (tracker != null) { |
| 8765 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8766 | } |
| 8767 | } |
| 8768 | } finally { |
| 8769 | Binder.restoreCallingIdentity(identity); |
| 8770 | } |
| 8771 | } |
| 8772 | |
| 8773 | /** |
| 8774 | * Get the full emergency number list for test mode. |
| 8775 | */ |
| 8776 | @Override |
| 8777 | public List<String> getEmergencyNumberListTestMode() { |
| 8778 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8779 | "getEmergencyNumberListTestMode"); |
| 8780 | |
| 8781 | final long identity = Binder.clearCallingIdentity(); |
| 8782 | try { |
| 8783 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8784 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8785 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8786 | if (tracker != null) { |
| 8787 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8788 | emergencyNumbers.add(num.getNumber()); |
| 8789 | } |
| 8790 | } |
| 8791 | } |
| 8792 | return new ArrayList<>(emergencyNumbers); |
| 8793 | } finally { |
| 8794 | Binder.restoreCallingIdentity(identity); |
| 8795 | } |
| 8796 | } |
| 8797 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8798 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8799 | public int getEmergencyNumberDbVersion(int subId) { |
| 8800 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8801 | |
| 8802 | final long identity = Binder.clearCallingIdentity(); |
| 8803 | try { |
| 8804 | final Phone phone = getPhone(subId); |
| 8805 | if (phone == null) { |
| 8806 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8807 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8808 | } |
| 8809 | return phone.getEmergencyNumberDbVersion(); |
| 8810 | } finally { |
| 8811 | Binder.restoreCallingIdentity(identity); |
| 8812 | } |
| 8813 | } |
| 8814 | |
| 8815 | @Override |
| 8816 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8817 | enforceModifyPermission(); |
| 8818 | |
| 8819 | final long identity = Binder.clearCallingIdentity(); |
| 8820 | try { |
| 8821 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8822 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8823 | if (tracker != null) { |
| 8824 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8825 | } |
| 8826 | } |
| 8827 | } finally { |
| 8828 | Binder.restoreCallingIdentity(identity); |
| 8829 | } |
| 8830 | } |
| 8831 | |
| 8832 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8833 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8834 | enforceActiveEmergencySessionPermission(); |
| 8835 | |
| 8836 | final long identity = Binder.clearCallingIdentity(); |
| 8837 | try { |
| 8838 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8839 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8840 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8841 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8842 | } |
| 8843 | } |
| 8844 | } finally { |
| 8845 | Binder.restoreCallingIdentity(identity); |
| 8846 | } |
| 8847 | } |
| 8848 | |
| 8849 | @Override |
| 8850 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8851 | enforceActiveEmergencySessionPermission(); |
| 8852 | |
| 8853 | final long identity = Binder.clearCallingIdentity(); |
| 8854 | try { |
| 8855 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8856 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8857 | if (tracker != null) { |
| 8858 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8859 | } |
| 8860 | } |
| 8861 | } finally { |
| 8862 | Binder.restoreCallingIdentity(identity); |
| 8863 | } |
| 8864 | } |
| 8865 | |
| 8866 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8867 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8868 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8869 | Phone phone = getPhone(subId); |
| 8870 | if (phone == null) { |
| 8871 | return null; |
| 8872 | } |
| 8873 | final long identity = Binder.clearCallingIdentity(); |
| 8874 | try { |
| 8875 | UiccProfile profile = UiccController.getInstance() |
| 8876 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8877 | if (profile != null) { |
| 8878 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8879 | } |
| 8880 | } finally { |
| 8881 | Binder.restoreCallingIdentity(identity); |
| 8882 | } |
| 8883 | return null; |
| 8884 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8885 | |
| 8886 | /** |
| 8887 | * Enable or disable a modem stack. |
| 8888 | */ |
| 8889 | @Override |
| 8890 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8891 | enforceModifyPermission(); |
| 8892 | |
| 8893 | final long identity = Binder.clearCallingIdentity(); |
| 8894 | try { |
| 8895 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8896 | if (phone == null) { |
| 8897 | return false; |
| 8898 | } else { |
| 8899 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8900 | } |
| 8901 | } finally { |
| 8902 | Binder.restoreCallingIdentity(identity); |
| 8903 | } |
| 8904 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8905 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8906 | /** |
| 8907 | * Whether a modem stack is enabled or not. |
| 8908 | */ |
| 8909 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8910 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8911 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8912 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8913 | if (phone == null) return false; |
| 8914 | |
| 8915 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8916 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8917 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8918 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8919 | } |
| 8920 | |
| 8921 | final long identity = Binder.clearCallingIdentity(); |
| 8922 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8923 | try { |
| 8924 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8925 | } catch (NoSuchElementException ex) { |
| 8926 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8927 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8928 | } finally { |
| 8929 | Binder.restoreCallingIdentity(identity); |
| 8930 | } |
| 8931 | } |
| 8932 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8933 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8934 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8935 | enforceModifyPermission(); |
| 8936 | |
| 8937 | final long identity = Binder.clearCallingIdentity(); |
| 8938 | try { |
| 8939 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8940 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8941 | .commit(); |
| 8942 | } finally { |
| 8943 | Binder.restoreCallingIdentity(identity); |
| 8944 | } |
| 8945 | } |
| 8946 | |
| 8947 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8948 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8949 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8950 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8951 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8952 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8953 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8954 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8955 | |
| 8956 | final long identity = Binder.clearCallingIdentity(); |
| 8957 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8958 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8959 | } finally { |
| 8960 | Binder.restoreCallingIdentity(identity); |
| 8961 | } |
| 8962 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8963 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8964 | @TelephonyManager.IsMultiSimSupportedResult |
| 8965 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8966 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8967 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8968 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8969 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8970 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8971 | } |
| 8972 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8973 | // supported by the modem, indicate that it is restricted. |
| 8974 | PhoneCapability staticCapability = |
| 8975 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8976 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8977 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8978 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8979 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 8980 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8981 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8982 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8983 | } |
| 8984 | // Check if support of multiple SIMs is restricted by carrier |
| 8985 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8986 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8987 | } |
| 8988 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8989 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8990 | } |
| 8991 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8992 | /** |
| 8993 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8994 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8995 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8996 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8997 | * @param numOfSims number of active sims we want to switch to |
| 8998 | */ |
| 8999 | @Override |
| 9000 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9001 | if (numOfSims == 1) { |
| 9002 | enforceModifyPermission(); |
| 9003 | } else { |
| 9004 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9005 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9006 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9007 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9008 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9009 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9010 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9011 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9012 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9013 | return; |
| 9014 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9015 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9016 | } finally { |
| 9017 | Binder.restoreCallingIdentity(identity); |
| 9018 | } |
| 9019 | } |
| 9020 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9021 | @Override |
| 9022 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9023 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9024 | Phone phone = getPhone(subId); |
| 9025 | if (phone == null) { |
| 9026 | return false; |
| 9027 | } |
| 9028 | final long identity = Binder.clearCallingIdentity(); |
| 9029 | try { |
| 9030 | UiccCard uiccCard = phone.getUiccCard(); |
| 9031 | if (uiccCard == null) { |
| 9032 | return false; |
| 9033 | } |
| 9034 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 9035 | if (uiccProfile == null) { |
| 9036 | return false; |
| 9037 | } |
| 9038 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9039 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9040 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9041 | } |
| 9042 | return false; |
| 9043 | } finally { |
| 9044 | Binder.restoreCallingIdentity(identity); |
| 9045 | } |
| 9046 | } |
| 9047 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9048 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9049 | * Get whether making changes to modem configurations will trigger reboot. |
| 9050 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9051 | */ |
| 9052 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9053 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9054 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9055 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9056 | mApp, subId, callingPackage, callingFeatureId, |
| 9057 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9058 | return false; |
| 9059 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9060 | final long identity = Binder.clearCallingIdentity(); |
| 9061 | try { |
| 9062 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9063 | } finally { |
| 9064 | Binder.restoreCallingIdentity(identity); |
| 9065 | } |
| 9066 | } |
| 9067 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9068 | private void updateModemStateMetrics() { |
| 9069 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9070 | // TODO: check the state for each modem if the api is ready. |
| 9071 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9072 | } |
| 9073 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9074 | @Override |
| 9075 | public int[] getSlotsMapping() { |
| 9076 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 9077 | |
| 9078 | final long identity = Binder.clearCallingIdentity(); |
| 9079 | try { |
| 9080 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 9081 | // All logical slots should have a mapping to a physical slot. |
| 9082 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 9083 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 9084 | for (int i = 0; i < slotInfos.length; i++) { |
| 9085 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 9086 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 9087 | } |
| 9088 | } |
| 9089 | return logicalSlotsMapping; |
| 9090 | } finally { |
| 9091 | Binder.restoreCallingIdentity(identity); |
| 9092 | } |
| 9093 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9094 | |
| 9095 | /** |
| 9096 | * Get the IRadio HAL Version |
| 9097 | */ |
| 9098 | @Override |
| 9099 | public int getRadioHalVersion() { |
| 9100 | Phone phone = getDefaultPhone(); |
| 9101 | if (phone == null) return -1; |
| 9102 | HalVersion hv = phone.getHalVersion(); |
| 9103 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9104 | return hv.major * 100 + hv.minor; |
| 9105 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9106 | |
| 9107 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9108 | * Get the current calling package name. |
| 9109 | * @return the current calling package name |
| 9110 | */ |
| 9111 | @Override |
| 9112 | public String getCurrentPackageName() { |
| 9113 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9114 | } |
| 9115 | |
| 9116 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9117 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9118 | * corresponding network requests on a subId. |
| 9119 | * |
| 9120 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9121 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9122 | * 2) APN is un-metered for this subscription, or |
| 9123 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9124 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9125 | * |
| 9126 | * @return whether data is allowed for a apn type. |
| 9127 | * |
| 9128 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9129 | */ |
| 9130 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9131 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9132 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9133 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9134 | |
| 9135 | // Now that all security checks passes, perform the operation as ourselves. |
| 9136 | final long identity = Binder.clearCallingIdentity(); |
| 9137 | try { |
| 9138 | Phone phone = getPhone(subId); |
| 9139 | if (phone == null) return false; |
| 9140 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9141 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9142 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 9143 | } finally { |
| 9144 | Binder.restoreCallingIdentity(identity); |
| 9145 | } |
| 9146 | } |
| 9147 | |
| 9148 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9149 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9150 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9151 | |
| 9152 | // Now that all security checks passes, perform the operation as ourselves. |
| 9153 | final long identity = Binder.clearCallingIdentity(); |
| 9154 | try { |
| 9155 | Phone phone = getPhone(subId); |
| 9156 | if (phone == null) return true; // By default return true. |
| 9157 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9158 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9159 | } finally { |
| 9160 | Binder.restoreCallingIdentity(identity); |
| 9161 | } |
| 9162 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9163 | |
| 9164 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9165 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9166 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9167 | enforceModifyPermission(); |
| 9168 | long token = Binder.clearCallingIdentity(); |
| 9169 | try { |
| 9170 | Phone phone = getPhone(subscriptionId); |
| 9171 | if (phone == null) { |
| 9172 | try { |
| 9173 | if (resultCallback != null) { |
| 9174 | resultCallback.accept(false); |
| 9175 | } |
| 9176 | } catch (RemoteException e) { |
| 9177 | // ignore |
| 9178 | } |
| 9179 | return; |
| 9180 | } |
| 9181 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9182 | Pair.create(specifiers, (x) -> { |
| 9183 | try { |
| 9184 | if (resultCallback != null) { |
| 9185 | resultCallback.accept(x); |
| 9186 | } |
| 9187 | } catch (RemoteException e) { |
| 9188 | // ignore |
| 9189 | } |
| 9190 | }); |
| 9191 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9192 | } finally { |
| 9193 | Binder.restoreCallingIdentity(token); |
| 9194 | } |
| 9195 | } |
| 9196 | |
| 9197 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9198 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9199 | TelephonyPermissions |
| 9200 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 9201 | mApp, subId, "getSystemSelectionChannels"); |
| 9202 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9203 | final long identity = Binder.clearCallingIdentity(); |
| 9204 | try { |
| 9205 | List<RadioAccessSpecifier> specifiers = |
| 9206 | (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, |
| 9207 | null, subId, workSource); |
| 9208 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9209 | return specifiers; |
| 9210 | } finally { |
| 9211 | Binder.restoreCallingIdentity(identity); |
| 9212 | } |
| 9213 | } |
| 9214 | |
| 9215 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9216 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9217 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9218 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9219 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9220 | if (iccRecords == null) { |
| 9221 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9222 | return false; |
| 9223 | } |
| 9224 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9225 | } |
| 9226 | |
| 9227 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9228 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9229 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9230 | if (callingPackage == null) { |
| 9231 | callingPackage = getCurrentPackageName(); |
| 9232 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9233 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9234 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9235 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9236 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9237 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9238 | } |
| 9239 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9240 | Intent intent = new Intent(); |
| 9241 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9242 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9243 | // Bring up choose default SMS subscription dialog right now |
| 9244 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9245 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9246 | mApp.startActivity(intent); |
| 9247 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9248 | |
| 9249 | @Override |
| 9250 | public String getMmsUAProfUrl(int subId) { |
| 9251 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9252 | final long identity = Binder.clearCallingIdentity(); |
| 9253 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9254 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9255 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9256 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9257 | return carrierUAProfUrl; |
| 9258 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9259 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9260 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9261 | } finally { |
| 9262 | Binder.restoreCallingIdentity(identity); |
| 9263 | } |
| 9264 | } |
| 9265 | |
| 9266 | @Override |
| 9267 | public String getMmsUserAgent(int subId) { |
| 9268 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9269 | final long identity = Binder.clearCallingIdentity(); |
| 9270 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9271 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9272 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9273 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9274 | return carrierUserAgent; |
| 9275 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9276 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9277 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9278 | } finally { |
| 9279 | Binder.restoreCallingIdentity(identity); |
| 9280 | } |
| 9281 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9282 | |
| 9283 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9284 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9285 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9286 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9287 | final long identity = Binder.clearCallingIdentity(); |
| 9288 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9289 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9290 | if (phone == null) return false; |
| 9291 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9292 | switch (policy) { |
| 9293 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9294 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9295 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9296 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9297 | default: |
| 9298 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9299 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9300 | } finally { |
| 9301 | Binder.restoreCallingIdentity(identity); |
| 9302 | } |
| 9303 | } |
| 9304 | |
| 9305 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 9306 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9307 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9308 | enforceModifyPermission(); |
| 9309 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9310 | final long identity = Binder.clearCallingIdentity(); |
| 9311 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9312 | Phone phone = getPhone(subscriptionId); |
| 9313 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9314 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9315 | switch (policy) { |
| 9316 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9317 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9318 | break; |
| 9319 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9320 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9321 | break; |
| 9322 | default: |
| 9323 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9324 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9325 | } finally { |
| 9326 | Binder.restoreCallingIdentity(identity); |
| 9327 | } |
| 9328 | } |
| 9329 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9330 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9331 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9332 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9333 | * otherwise. |
| 9334 | */ |
| 9335 | @Override |
| 9336 | public void setCepEnabled(boolean isCepEnabled) { |
| 9337 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9338 | |
| 9339 | final long identity = Binder.clearCallingIdentity(); |
| 9340 | try { |
| 9341 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9342 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9343 | Phone defaultPhone = phone.getImsPhone(); |
| 9344 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9345 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9346 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9347 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9348 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9349 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9350 | + imsPhone.getMsisdn()); |
| 9351 | } |
| 9352 | } |
| 9353 | } finally { |
| 9354 | Binder.restoreCallingIdentity(identity); |
| 9355 | } |
| 9356 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9357 | |
| 9358 | /** |
| 9359 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9360 | * |
| 9361 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9362 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9363 | * before being read. |
| 9364 | */ |
| 9365 | @Override |
| 9366 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9367 | isCompressed) { |
| 9368 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9369 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9370 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9371 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9372 | } |
| 9373 | if (!isImsAvailableOnDevice()) { |
| 9374 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9375 | "IMS not available on device."); |
| 9376 | } |
| 9377 | |
| 9378 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9379 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9380 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9381 | } finally { |
| 9382 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9383 | } |
| 9384 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9385 | |
| 9386 | @Override |
| 9387 | public boolean isIccLockEnabled(int subId) { |
| 9388 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9389 | |
| 9390 | // Now that all security checks passes, perform the operation as ourselves. |
| 9391 | final long identity = Binder.clearCallingIdentity(); |
| 9392 | try { |
| 9393 | Phone phone = getPhone(subId); |
| 9394 | if (phone != null && phone.getIccCard() != null) { |
| 9395 | return phone.getIccCard().getIccLockEnabled(); |
| 9396 | } else { |
| 9397 | return false; |
| 9398 | } |
| 9399 | } finally { |
| 9400 | Binder.restoreCallingIdentity(identity); |
| 9401 | } |
| 9402 | } |
| 9403 | |
| 9404 | /** |
| 9405 | * Set the ICC pin lock enabled or disabled. |
| 9406 | * |
| 9407 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9408 | * three cases: |
| 9409 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9410 | * successfully. |
| 9411 | * - Positive number and zero for remaining password attempts. |
| 9412 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9413 | * |
| 9414 | */ |
| 9415 | @Override |
| 9416 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9417 | enforceModifyPermission(); |
| 9418 | |
| 9419 | Phone phone = getPhone(subId); |
| 9420 | if (phone == null) { |
| 9421 | return 0; |
| 9422 | } |
| 9423 | // Now that all security checks passes, perform the operation as ourselves. |
| 9424 | final long identity = Binder.clearCallingIdentity(); |
| 9425 | try { |
| 9426 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9427 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9428 | return attemptsRemaining; |
| 9429 | |
| 9430 | } catch (Exception e) { |
| 9431 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9432 | } finally { |
| 9433 | Binder.restoreCallingIdentity(identity); |
| 9434 | } |
| 9435 | return 0; |
| 9436 | } |
| 9437 | |
| 9438 | /** |
| 9439 | * Change the ICC password used in ICC pin lock. |
| 9440 | * |
| 9441 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9442 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9443 | * - Positive number and zero for remaining password attempts. |
| 9444 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9445 | * |
| 9446 | */ |
| 9447 | @Override |
| 9448 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9449 | enforceModifyPermission(); |
| 9450 | |
| 9451 | Phone phone = getPhone(subId); |
| 9452 | if (phone == null) { |
| 9453 | return 0; |
| 9454 | } |
| 9455 | // Now that all security checks passes, perform the operation as ourselves. |
| 9456 | final long identity = Binder.clearCallingIdentity(); |
| 9457 | try { |
| 9458 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9459 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9460 | return attemptsRemaining; |
| 9461 | |
| 9462 | } catch (Exception e) { |
| 9463 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9464 | } finally { |
| 9465 | Binder.restoreCallingIdentity(identity); |
| 9466 | } |
| 9467 | return 0; |
| 9468 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9469 | |
| 9470 | /** |
| 9471 | * Request for receiving user activity notification |
| 9472 | */ |
| 9473 | @Override |
| 9474 | public void requestUserActivityNotification() { |
| 9475 | if (!mNotifyUserActivity.get() |
| 9476 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9477 | mNotifyUserActivity.set(true); |
| 9478 | } |
| 9479 | } |
| 9480 | |
| 9481 | /** |
| 9482 | * Called when userActivity is signalled in the power manager. |
| 9483 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9484 | */ |
| 9485 | @Override |
| 9486 | public void userActivity() { |
| 9487 | // *************************************** |
| 9488 | // * Inherited from PhoneWindowManager * |
| 9489 | // *************************************** |
| 9490 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9491 | // WITH ITS LOCKS HELD. |
| 9492 | // |
| 9493 | // This code must be VERY careful about the locks |
| 9494 | // it acquires. |
| 9495 | // In fact, the current code acquires way too many, |
| 9496 | // and probably has lurking deadlocks. |
| 9497 | |
| 9498 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9499 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9500 | } |
| 9501 | |
| 9502 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9503 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9504 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9505 | } |
| 9506 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9507 | |
| 9508 | @Override |
| 9509 | public boolean canConnectTo5GInDsdsMode() { |
| 9510 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9511 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9512 | |
| 9513 | @Override |
| 9514 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9515 | String callingFeatureId) { |
| 9516 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9517 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9518 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9519 | } |
| 9520 | |
| 9521 | Phone phone = getPhone(subId); |
| 9522 | if (phone == null) { |
| 9523 | throw new RuntimeException("phone is not available"); |
| 9524 | } |
| 9525 | // Now that all security checks passes, perform the operation as ourselves. |
| 9526 | final long identity = Binder.clearCallingIdentity(); |
| 9527 | try { |
| 9528 | return phone.getEquivalentHomePlmns(); |
| 9529 | } finally { |
| 9530 | Binder.restoreCallingIdentity(identity); |
| 9531 | } |
| 9532 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9533 | |
| 9534 | @Override |
| 9535 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 9536 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 9537 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 9538 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9539 | if (radioInterfaceCapabilities == null) { |
| 9540 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9541 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 9542 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9543 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9544 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9545 | @Override |
| 9546 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 9547 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9548 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 9549 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9550 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 9551 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9552 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9553 | if (DBG) { |
| 9554 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 9555 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 9556 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 9557 | } |
| 9558 | |
| 9559 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 9560 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 9561 | || appType > TelephonyManager.APPTYPE_ISIM |
| 9562 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 9563 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 9564 | if (callback != null) { |
| 9565 | try { |
| 9566 | callback.onAuthenticationFailure( |
| 9567 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 9568 | } catch (RemoteException exception) { |
| 9569 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 9570 | } |
| 9571 | return; |
| 9572 | } |
| 9573 | } |
| 9574 | |
| 9575 | final long token = Binder.clearCallingIdentity(); |
| 9576 | try { |
| 9577 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 9578 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 9579 | forceBootStrapping, callback)); |
| 9580 | } finally { |
| 9581 | Binder.restoreCallingIdentity(token); |
| 9582 | } |
| 9583 | } |
| 9584 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9585 | /** |
| 9586 | * Attempts to set the radio power state for thermal reason. This does not guarantee that the |
| 9587 | * requested radio power state will actually be set. See {@link |
| 9588 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9589 | * |
| 9590 | * @param subId the subscription ID of the phone requesting to set the radio power state. |
| 9591 | * @param enable {@code true} if trying to turn radio on. |
| 9592 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9593 | * false}. |
| 9594 | */ |
| 9595 | private boolean setRadioPowerForThermal(int subId, boolean enable) { |
| 9596 | Phone phone = getPhone(subId); |
| 9597 | if (phone != null) { |
| 9598 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 9599 | return true; |
| 9600 | } |
| 9601 | return false; |
| 9602 | } |
| 9603 | |
| 9604 | private int handleDataThrottlingRequest(int subId, |
| 9605 | DataThrottlingRequest dataThrottlingRequest) { |
| 9606 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 9607 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9608 | if (!setRadioPowerForThermal(subId, true)) { |
| 9609 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9610 | } |
| 9611 | |
| 9612 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 9613 | |
| 9614 | int thermalMitigationResult = |
| 9615 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
| 9616 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 9617 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 9618 | } |
| 9619 | return thermalMitigationResult; |
| 9620 | } |
| 9621 | |
| 9622 | /** |
| 9623 | * Thermal mitigation request to control functionalities at modem. |
| 9624 | * |
| 9625 | * @param subId the id of the subscription. |
| 9626 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
| 9627 | * |
| 9628 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 9629 | */ |
| 9630 | @Override |
| 9631 | @ThermalMitigationResult |
| 9632 | public int sendThermalMitigationRequest( |
| 9633 | int subId, |
| 9634 | ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException { |
| 9635 | enforceModifyPermission(); |
| 9636 | |
| 9637 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9638 | final long identity = Binder.clearCallingIdentity(); |
| 9639 | |
| 9640 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 9641 | try { |
| 9642 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 9643 | switch (thermalMitigationAction) { |
| 9644 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 9645 | thermalMitigationResult = |
| 9646 | handleDataThrottlingRequest(subId, |
| 9647 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 9648 | break; |
| 9649 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 9650 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9651 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 9652 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 9653 | } |
| 9654 | |
| 9655 | // Ensure that radio is on. If not able to power on due to phone being |
| 9656 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9657 | if (!setRadioPowerForThermal(subId, true)) { |
| 9658 | thermalMitigationResult = |
| 9659 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9660 | break; |
| 9661 | } |
| 9662 | |
| 9663 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 9664 | false); |
| 9665 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9666 | break; |
| 9667 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 9668 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9669 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 9670 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 9671 | } |
| 9672 | |
| 9673 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 9674 | if (registry != null) { |
| 9675 | TelephonyConnectionService service = |
| 9676 | registry.getTelephonyConnectionService(); |
| 9677 | Phone phone = getPhone(subId); |
| 9678 | if (phone == null) { |
| 9679 | thermalMitigationResult = |
| 9680 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9681 | break; |
| 9682 | } |
| 9683 | |
| 9684 | if (PhoneConstantConversions.convertCallState(phone.getState()) |
| 9685 | != TelephonyManager.CALL_STATE_IDLE |
| 9686 | || phone.isInEmergencySmsMode() || phone.isInEcm() |
| 9687 | || (service != null && service.isEmergencyCallPending())) { |
| 9688 | String errorMessage = "Phone state is not valid. call state = " |
| 9689 | + PhoneConstantConversions.convertCallState(phone.getState()) |
| 9690 | + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode() |
| 9691 | + " isInEmergencyCallbackMode = " + phone.isInEcm(); |
| 9692 | errorMessage += service == null |
| 9693 | ? " TelephonyConnectionService is null" |
| 9694 | : " isEmergencyCallPending = " |
| 9695 | + service.isEmergencyCallPending(); |
| 9696 | Log.e(LOG_TAG, errorMessage); |
| 9697 | thermalMitigationResult = |
| 9698 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 9699 | break; |
| 9700 | } |
| 9701 | } else { |
| 9702 | thermalMitigationResult = |
| 9703 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9704 | break; |
| 9705 | } |
| 9706 | |
| 9707 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 9708 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9709 | if (!setRadioPowerForThermal(subId, false)) { |
| 9710 | thermalMitigationResult = |
| 9711 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9712 | break; |
| 9713 | } |
| 9714 | thermalMitigationResult = |
| 9715 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9716 | break; |
| 9717 | default: |
| 9718 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 9719 | + "not exist. Requested action: " + thermalMitigationAction); |
| 9720 | } |
| 9721 | } catch (IllegalArgumentException e) { |
| 9722 | throw e; |
| 9723 | } catch (Exception e) { |
| 9724 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 9725 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 9726 | } finally { |
| 9727 | Binder.restoreCallingIdentity(identity); |
| 9728 | } |
| 9729 | |
| 9730 | if (DBG) { |
| 9731 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 9732 | + thermalMitigationResult); |
| 9733 | } |
| 9734 | |
| 9735 | return thermalMitigationResult; |
| 9736 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9737 | |
| 9738 | /** |
| 9739 | * Set the GbaService Package Name that Telephony will bind to. |
| 9740 | * |
| 9741 | * @param subId The sim that the GbaService is associated with. |
| 9742 | * @param packageName The name of the package to be replaced with. |
| 9743 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9744 | */ |
| 9745 | @Override |
| 9746 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 9747 | enforceModifyPermission(); |
| 9748 | |
| 9749 | final long identity = Binder.clearCallingIdentity(); |
| 9750 | try { |
| 9751 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 9752 | } finally { |
| 9753 | Binder.restoreCallingIdentity(identity); |
| 9754 | } |
| 9755 | } |
| 9756 | |
| 9757 | /** |
| 9758 | * Return the package name of the currently bound GbaService. |
| 9759 | * |
| 9760 | * @param subId The sim that the GbaService is associated with. |
| 9761 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 9762 | */ |
| 9763 | @Override |
| 9764 | public String getBoundGbaService(int subId) { |
| 9765 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 9766 | |
| 9767 | final long identity = Binder.clearCallingIdentity(); |
| 9768 | try { |
| 9769 | return getGbaManager(subId).getServicePackage(); |
| 9770 | } finally { |
| 9771 | Binder.restoreCallingIdentity(identity); |
| 9772 | } |
| 9773 | } |
| 9774 | |
| 9775 | /** |
| 9776 | * Set the release time for telephony to unbind GbaService. |
| 9777 | * |
| 9778 | * @param subId The sim that the GbaService is associated with. |
| 9779 | * @param interval The release time to unbind GbaService by millisecond. |
| 9780 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9781 | */ |
| 9782 | @Override |
| 9783 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 9784 | enforceModifyPermission(); |
| 9785 | |
| 9786 | final long identity = Binder.clearCallingIdentity(); |
| 9787 | try { |
| 9788 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 9789 | } finally { |
| 9790 | Binder.restoreCallingIdentity(identity); |
| 9791 | } |
| 9792 | } |
| 9793 | |
| 9794 | /** |
| 9795 | * Return the release time for telephony to unbind GbaService. |
| 9796 | * |
| 9797 | * @param subId The sim that the GbaService is associated with. |
| 9798 | * @return The release time to unbind GbaService by millisecond. |
| 9799 | */ |
| 9800 | @Override |
| 9801 | public int getGbaReleaseTime(int subId) { |
| 9802 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 9803 | |
| 9804 | final long identity = Binder.clearCallingIdentity(); |
| 9805 | try { |
| 9806 | return getGbaManager(subId).getReleaseTime(); |
| 9807 | } finally { |
| 9808 | Binder.restoreCallingIdentity(identity); |
| 9809 | } |
| 9810 | } |
| 9811 | |
| 9812 | private GbaManager getGbaManager(int subId) { |
| 9813 | GbaManager instance = GbaManager.getInstance(subId); |
| 9814 | if (instance == null) { |
| 9815 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 9816 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 9817 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 9818 | } |
| 9819 | return instance; |
| 9820 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9821 | |
| 9822 | /** |
| 9823 | * indicate whether the device and the carrier can support |
| 9824 | * RCS VoLTE single registration. |
| 9825 | */ |
| 9826 | @Override |
| 9827 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9828 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9829 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 9830 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9831 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9832 | |
| 9833 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9834 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9835 | } |
| 9836 | |
| 9837 | final long identity = Binder.clearCallingIdentity(); |
| 9838 | try { |
| 9839 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 9840 | if (rpm != null) { |
| 9841 | return rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 9842 | } |
| 9843 | return false; |
| 9844 | } finally { |
| 9845 | Binder.restoreCallingIdentity(identity); |
| 9846 | } |
| 9847 | } |
| 9848 | |
| 9849 | /** |
| 9850 | * Register RCS provisioning callback. |
| 9851 | */ |
| 9852 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9853 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9854 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9855 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9856 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9857 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9858 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9859 | |
| 9860 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9861 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9862 | } |
| 9863 | if (!isImsAvailableOnDevice()) { |
| 9864 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9865 | "IMS not available on device."); |
| 9866 | } |
| 9867 | |
| 9868 | final long identity = Binder.clearCallingIdentity(); |
| 9869 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9870 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9871 | .registerRcsProvisioningCallback(subId, callback)) { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9872 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9873 | "Service not available for the subscription."); |
| 9874 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9875 | } finally { |
| 9876 | Binder.restoreCallingIdentity(identity); |
| 9877 | } |
| 9878 | } |
| 9879 | |
| 9880 | /** |
| 9881 | * Unregister RCS provisioning callback. |
| 9882 | */ |
| 9883 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9884 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9885 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9886 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9887 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9888 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9889 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9890 | |
| 9891 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9892 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9893 | } |
| 9894 | if (!isImsAvailableOnDevice()) { |
| 9895 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9896 | "IMS not available on device."); |
| 9897 | } |
| 9898 | |
| 9899 | final long identity = Binder.clearCallingIdentity(); |
| 9900 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9901 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9902 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9903 | } finally { |
| 9904 | Binder.restoreCallingIdentity(identity); |
| 9905 | } |
| 9906 | } |
| 9907 | |
| 9908 | /** |
| 9909 | * trigger RCS reconfiguration. |
| 9910 | */ |
| 9911 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9912 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 9913 | "triggerRcsReconfiguration", |
| 9914 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9915 | |
| 9916 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9917 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9918 | } |
| 9919 | if (!isImsAvailableOnDevice()) { |
| 9920 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9921 | "IMS not available on device."); |
| 9922 | } |
| 9923 | |
| 9924 | final long identity = Binder.clearCallingIdentity(); |
| 9925 | try { |
| 9926 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 9927 | } finally { |
| 9928 | Binder.restoreCallingIdentity(identity); |
| 9929 | } |
| 9930 | } |
| 9931 | |
| 9932 | /** |
| 9933 | * Provide the client configuration parameters of the RCS application. |
| 9934 | */ |
| 9935 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9936 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 9937 | "setRcsClientConfiguration", |
| 9938 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9939 | |
| 9940 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9941 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9942 | } |
| 9943 | if (!isImsAvailableOnDevice()) { |
| 9944 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9945 | "IMS not available on device."); |
| 9946 | } |
| 9947 | |
| 9948 | final long identity = Binder.clearCallingIdentity(); |
| 9949 | |
| 9950 | try { |
| 9951 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 9952 | if (configBinder == null) { |
| 9953 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
| 9954 | } else { |
| 9955 | configBinder.setRcsClientConfiguration(rcc); |
| 9956 | } |
| 9957 | } catch (RemoteException e) { |
| 9958 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
| 9959 | } finally { |
| 9960 | Binder.restoreCallingIdentity(identity); |
| 9961 | } |
| 9962 | } |
| 9963 | |
| 9964 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 9965 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 9966 | */ |
| 9967 | @Override |
| 9968 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 9969 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9970 | "setRcsSingleRegistrationTestModeEnabled"); |
| 9971 | |
| 9972 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 9973 | } |
| 9974 | |
| 9975 | /** |
| 9976 | * Gets the test mode for RCS VoLTE single registration. |
| 9977 | */ |
| 9978 | @Override |
| 9979 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 9980 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9981 | "getRcsSingleRegistrationTestModeEnabled"); |
| 9982 | |
| 9983 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 9984 | } |
| 9985 | |
| 9986 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9987 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 9988 | */ |
| 9989 | @Override |
| 9990 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 9991 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9992 | "setDeviceSingleRegistrationEnabledOverride"); |
| 9993 | enforceModifyPermission(); |
| 9994 | |
| 9995 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9996 | : Boolean.parseBoolean(enabledStr); |
| 9997 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 9998 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9999 | } |
| 10000 | |
| 10001 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10002 | * Sends a device to device communication message. Only usable via shell. |
| 10003 | * @param message message to send. |
| 10004 | * @param value message value. |
| 10005 | */ |
| 10006 | @Override |
| 10007 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 10008 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10009 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10010 | enforceModifyPermission(); |
| 10011 | |
| 10012 | final long identity = Binder.clearCallingIdentity(); |
| 10013 | try { |
| 10014 | TelephonyConnectionService service = |
| 10015 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10016 | if (service == null) { |
| 10017 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10018 | return; |
| 10019 | } |
| 10020 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10021 | } finally { |
| 10022 | Binder.restoreCallingIdentity(identity); |
| 10023 | } |
| 10024 | } |
| 10025 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10026 | /** |
| 10027 | * Sets the specified device to device transport active. |
| 10028 | * @param transport The transport to set active. |
| 10029 | */ |
| 10030 | @Override |
| 10031 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10032 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10033 | "setActiveDeviceToDeviceTransport"); |
| 10034 | enforceModifyPermission(); |
| 10035 | |
| 10036 | final long identity = Binder.clearCallingIdentity(); |
| 10037 | try { |
| 10038 | TelephonyConnectionService service = |
| 10039 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10040 | if (service == null) { |
| 10041 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10042 | return; |
| 10043 | } |
| 10044 | service.setActiveDeviceToDeviceTransport(transport); |
| 10045 | } finally { |
| 10046 | Binder.restoreCallingIdentity(identity); |
| 10047 | } |
| 10048 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10049 | |
| 10050 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10051 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10052 | */ |
| 10053 | @Override |
| 10054 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10055 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10056 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10057 | } |
| 10058 | |
| 10059 | /** |
| 10060 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10061 | */ |
| 10062 | @Override |
| 10063 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10064 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10065 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10066 | enforceModifyPermission(); |
| 10067 | |
| 10068 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10069 | : Boolean.parseBoolean(enabledStr); |
| 10070 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10071 | subId, enabled); |
| 10072 | } |
| 10073 | |
| 10074 | /** |
| 10075 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10076 | */ |
| 10077 | @Override |
| 10078 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10079 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 10080 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 10081 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10082 | |
| 10083 | /** |
| 10084 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 10085 | * their mobile plan. |
| 10086 | */ |
| 10087 | @Override |
| 10088 | public String getMobileProvisioningUrl() { |
| 10089 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 10090 | final long identity = Binder.clearCallingIdentity(); |
| 10091 | try { |
| 10092 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 10093 | } finally { |
| 10094 | Binder.restoreCallingIdentity(identity); |
| 10095 | } |
| 10096 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10097 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10098 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 10099 | * Get the EAB contact from the EAB database. |
| 10100 | */ |
| 10101 | @Override |
| 10102 | public String getContactFromEab(String contact) { |
| 10103 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 10104 | enforceModifyPermission(); |
| 10105 | final long identity = Binder.clearCallingIdentity(); |
| 10106 | try { |
| 10107 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 10108 | } finally { |
| 10109 | Binder.restoreCallingIdentity(identity); |
| 10110 | } |
| 10111 | } |
| 10112 | |
| 10113 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10114 | * Remove the EAB contacts from the EAB database. |
| 10115 | */ |
| 10116 | @Override |
| 10117 | public int removeContactFromEab(int subId, String contacts) { |
| 10118 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 10119 | enforceModifyPermission(); |
| 10120 | final long identity = Binder.clearCallingIdentity(); |
| 10121 | try { |
| 10122 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 10123 | } finally { |
| 10124 | Binder.restoreCallingIdentity(identity); |
| 10125 | } |
| 10126 | } |
| 10127 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10128 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10129 | public boolean getDeviceUceEnabled() { |
| 10130 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 10131 | final long identity = Binder.clearCallingIdentity(); |
| 10132 | try { |
| 10133 | return mApp.getDeviceUceEnabled(); |
| 10134 | } finally { |
| 10135 | Binder.restoreCallingIdentity(identity); |
| 10136 | } |
| 10137 | } |
| 10138 | |
| 10139 | @Override |
| 10140 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 10141 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 10142 | final long identity = Binder.clearCallingIdentity(); |
| 10143 | try { |
| 10144 | mApp.setDeviceUceEnabled(isEnabled); |
| 10145 | } finally { |
| 10146 | Binder.restoreCallingIdentity(identity); |
| 10147 | } |
| 10148 | } |
| 10149 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10150 | /** |
| 10151 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10152 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10153 | */ |
| 10154 | // Used for SHELL command only right now. |
| 10155 | @Override |
| 10156 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 10157 | List<String> featureTags) { |
| 10158 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10159 | "addUceRegistrationOverrideShell"); |
| 10160 | final long identity = Binder.clearCallingIdentity(); |
| 10161 | try { |
| 10162 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 10163 | new ArraySet<>(featureTags)); |
| 10164 | } catch (ImsException e) { |
| 10165 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10166 | } finally { |
| 10167 | Binder.restoreCallingIdentity(identity); |
| 10168 | } |
| 10169 | } |
| 10170 | |
| 10171 | /** |
| 10172 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10173 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10174 | */ |
| 10175 | // Used for SHELL command only right now. |
| 10176 | @Override |
| 10177 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 10178 | List<String> featureTags) { |
| 10179 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10180 | "removeUceRegistrationOverrideShell"); |
| 10181 | final long identity = Binder.clearCallingIdentity(); |
| 10182 | try { |
| 10183 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 10184 | new ArraySet<>(featureTags)); |
| 10185 | } catch (ImsException e) { |
| 10186 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10187 | } finally { |
| 10188 | Binder.restoreCallingIdentity(identity); |
| 10189 | } |
| 10190 | } |
| 10191 | |
| 10192 | /** |
| 10193 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 10194 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10195 | */ |
| 10196 | // Used for SHELL command only right now. |
| 10197 | @Override |
| 10198 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 10199 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10200 | "clearUceRegistrationOverrideShell"); |
| 10201 | final long identity = Binder.clearCallingIdentity(); |
| 10202 | try { |
| 10203 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 10204 | } catch (ImsException e) { |
| 10205 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10206 | } finally { |
| 10207 | Binder.restoreCallingIdentity(identity); |
| 10208 | } |
| 10209 | } |
| 10210 | |
| 10211 | /** |
| 10212 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10213 | */ |
| 10214 | // Used for SHELL command only right now. |
| 10215 | @Override |
| 10216 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 10217 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10218 | "getLatestRcsContactUceCapabilityShell"); |
| 10219 | final long identity = Binder.clearCallingIdentity(); |
| 10220 | try { |
| 10221 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 10222 | } catch (ImsException e) { |
| 10223 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10224 | } finally { |
| 10225 | Binder.restoreCallingIdentity(identity); |
| 10226 | } |
| 10227 | } |
| 10228 | |
| 10229 | /** |
| 10230 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 10231 | * device does not have an active PUBLISH. |
| 10232 | */ |
| 10233 | // Used for SHELL command only right now. |
| 10234 | @Override |
| 10235 | public String getLastUcePidfXmlShell(int subId) { |
| 10236 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 10237 | final long identity = Binder.clearCallingIdentity(); |
| 10238 | try { |
| 10239 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 10240 | } catch (ImsException e) { |
| 10241 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10242 | } finally { |
| 10243 | Binder.restoreCallingIdentity(identity); |
| 10244 | } |
| 10245 | } |
| 10246 | |
| 10247 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10248 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10249 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10250 | String callingPackage) { |
| 10251 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10252 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 10253 | |
| 10254 | final int callingUid = Binder.getCallingUid(); |
| 10255 | // Verify that tha callingPackage belongs to the calling UID |
| 10256 | mApp.getSystemService(AppOpsManager.class) |
| 10257 | .checkPackage(callingUid, callingPackage); |
| 10258 | |
| 10259 | validateSignalStrengthUpdateRequest(request, callingUid); |
| 10260 | |
| 10261 | final long identity = Binder.clearCallingIdentity(); |
| 10262 | try { |
| 10263 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10264 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10265 | |
| 10266 | if (result instanceof IllegalStateException) { |
| 10267 | throw (IllegalStateException) result; |
| 10268 | } |
| 10269 | } finally { |
| 10270 | Binder.restoreCallingIdentity(identity); |
| 10271 | } |
| 10272 | } |
| 10273 | |
| 10274 | @Override |
| 10275 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10276 | String callingPackage) { |
| 10277 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10278 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 10279 | |
| 10280 | final int callingUid = Binder.getCallingUid(); |
| 10281 | // Verify that tha callingPackage belongs to the calling UID |
| 10282 | mApp.getSystemService(AppOpsManager.class) |
| 10283 | .checkPackage(callingUid, callingPackage); |
| 10284 | |
| 10285 | final long identity = Binder.clearCallingIdentity(); |
| 10286 | try { |
| 10287 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10288 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10289 | |
| 10290 | if (result instanceof IllegalStateException) { |
| 10291 | throw (IllegalStateException) result; |
| 10292 | } |
| 10293 | } finally { |
| 10294 | Binder.restoreCallingIdentity(identity); |
| 10295 | } |
| 10296 | } |
| 10297 | |
| 10298 | private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request, |
| 10299 | int callingUid) { |
| 10300 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 10301 | // phone/system process do not have further restriction on request |
| 10302 | return; |
| 10303 | } |
| 10304 | |
| 10305 | // Applications has restrictions on how to use the request: |
| 10306 | // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle |
| 10307 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
| 10308 | // This is not system caller which has been checked above |
| 10309 | throw new IllegalArgumentException( |
| 10310 | "Only system can set isSystemThresholdReportingRequestedWhileIdle"); |
| 10311 | } |
| 10312 | |
| 10313 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 10314 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 10315 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 10316 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 10317 | || info.isEnabled()) { |
| 10318 | throw new IllegalArgumentException( |
| 10319 | "Only system can set hide fields in SignalThresholdInfo"); |
| 10320 | } |
| 10321 | |
| 10322 | // Thresholds length for each RAN need in range. This has been validated in |
| 10323 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 10324 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 10325 | final int[] thresholds = info.getThresholds(); |
| 10326 | Objects.requireNonNull(thresholds); |
| 10327 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 10328 | || thresholds.length |
| 10329 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 10330 | throw new IllegalArgumentException( |
| 10331 | "thresholds length is out of range: " + thresholds.length); |
| 10332 | } |
| 10333 | } |
| 10334 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10335 | |
| 10336 | /** |
| 10337 | * Gets the current phone capability. |
| 10338 | * |
| 10339 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 10340 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 10341 | * It's used to evaluate possible phone config change, for example from single |
| 10342 | * SIM device to multi-SIM device. |
| 10343 | */ |
| 10344 | @Override |
| 10345 | public PhoneCapability getPhoneCapability() { |
| 10346 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 10347 | final long identity = Binder.clearCallingIdentity(); |
| 10348 | try { |
| 10349 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 10350 | } finally { |
| 10351 | Binder.restoreCallingIdentity(identity); |
| 10352 | } |
| 10353 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 10354 | |
| 10355 | /** |
| 10356 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 10357 | * required to be done shortly after the API is invoked. |
| 10358 | */ |
| 10359 | @Override |
| 10360 | @TelephonyManager.PrepareUnattendedRebootResult |
| 10361 | public int prepareForUnattendedReboot() { |
| 10362 | enforceRebootPermission(); |
| 10363 | |
| 10364 | final long identity = Binder.clearCallingIdentity(); |
| 10365 | try { |
| 10366 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null); |
| 10367 | } finally { |
| 10368 | Binder.restoreCallingIdentity(identity); |
| 10369 | } |
| 10370 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame^] | 10371 | |
| 10372 | /** |
| 10373 | * Request to get the current slicing configuration including URSP rules and |
| 10374 | * NSSAIs (configured, allowed and rejected). |
| 10375 | * |
| 10376 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 10377 | */ |
| 10378 | @Override |
| 10379 | public void getSlicingConfig(ResultReceiver callback) { |
| 10380 | enforceReadPrivilegedPermission("getSlicingConfig"); |
| 10381 | |
| 10382 | final long identity = Binder.clearCallingIdentity(); |
| 10383 | try { |
| 10384 | Phone phone = getDefaultPhone(); |
| 10385 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 10386 | } finally { |
| 10387 | Binder.restoreCallingIdentity(identity); |
| 10388 | } |
| 10389 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 10390 | } |