Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
| 20 | |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA; |
| 22 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 23 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 24 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 25 | |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 26 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 27 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 28 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 29 | import android.annotation.Nullable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 30 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 31 | import android.app.PendingIntent; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 32 | import android.app.role.RoleManager; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 33 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 34 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 35 | import android.content.Context; |
| 36 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 37 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 38 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 39 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 40 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 41 | import android.net.Uri; |
| 42 | import android.os.AsyncResult; |
| 43 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 44 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.os.Bundle; |
| 46 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 47 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 48 | import android.os.Looper; |
| 49 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 50 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 51 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 52 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 53 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 54 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 55 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 56 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 57 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 58 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 59 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 60 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 61 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 62 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 63 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 64 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 65 | import android.provider.Telephony; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 66 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 67 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 68 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 69 | import android.telecom.TelecomManager; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 70 | import android.telephony.Annotation.ApnType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 71 | import android.telephony.Annotation.ThermalMitigationResult; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 72 | import android.telephony.CallForwardingInfo; |
Sooraj Sasindran | 4deb887 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 73 | import android.telephony.CarrierBandwidth; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 74 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 75 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 76 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 77 | import android.telephony.CellIdentityCdma; |
| 78 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 79 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 80 | import android.telephony.CellInfoGsm; |
| 81 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 82 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 83 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 84 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 85 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 86 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 87 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 88 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 89 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 90 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 91 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 92 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 93 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 94 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 95 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 96 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 97 | import android.telephony.SignalStrengthUpdateRequest; |
| 98 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 99 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 100 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 101 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 102 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 103 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 104 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 105 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 106 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 107 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 108 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 109 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 110 | import android.telephony.data.ApnSetting; |
| 111 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 112 | import android.telephony.gba.GbaAuthRequest; |
| 113 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 114 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 115 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 116 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 117 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 118 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 119 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 120 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 121 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 122 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 123 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 124 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 125 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 126 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 127 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 128 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 129 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 130 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 131 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 132 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 133 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 134 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 135 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 136 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 137 | import com.android.ims.rcs.uce.eab.EabUtil; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 138 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 142 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 145 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 148 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 149 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 150 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 153 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 155 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 161 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.RIL; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame^] | 166 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 170 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 171 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 172 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 174 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 175 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 176 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 178 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 179 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 181 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 182 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 183 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 184 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 185 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 186 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 187 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 188 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 189 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 190 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 191 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 192 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 193 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 194 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 195 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 196 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 197 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 198 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 199 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 200 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 201 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 202 | import com.android.services.telephony.TelecomAccountRegistry; |
| 203 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 204 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 205 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 206 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 207 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 208 | import java.io.IOException; |
| 209 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 210 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 211 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 212 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 213 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 214 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 215 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 216 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 217 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 218 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 219 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 220 | import java.util.Set; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 221 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 222 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 223 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 224 | |
| 225 | /** |
| 226 | * Implementation of the ITelephony interface. |
| 227 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 228 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 229 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 230 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 231 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 232 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 233 | |
| 234 | // Message codes used with mMainThreadHandler |
| 235 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 236 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 237 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 238 | private static final int CMD_OPEN_CHANNEL = 9; |
| 239 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 240 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 241 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 242 | private static final int CMD_NV_READ_ITEM = 13; |
| 243 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 244 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 245 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 246 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 247 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 248 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 249 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 250 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 251 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 252 | private static final int CMD_SEND_ENVELOPE = 25; |
| 253 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 254 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 255 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 256 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 257 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 258 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 259 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 260 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 261 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 262 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 263 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 264 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 265 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 266 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 267 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 268 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 269 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 270 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 271 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 272 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 273 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 274 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 275 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 276 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 277 | private static final int CMD_SWITCH_SLOTS = 50; |
| 278 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 279 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 280 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 281 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 282 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 283 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 284 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 285 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 286 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 287 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 288 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 289 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 290 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 291 | private static final int CMD_MODEM_REBOOT = 64; |
| 292 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 293 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 294 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 295 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 296 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 297 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 298 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 299 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 300 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 301 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 302 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 303 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 304 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 305 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 306 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 307 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 308 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 309 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 310 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 311 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 312 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 313 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 314 | private static final int CMD_GET_CALL_WAITING = 87; |
| 315 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 316 | private static final int CMD_SET_CALL_WAITING = 89; |
| 317 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 318 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 319 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 320 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 321 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 322 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 323 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 324 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 325 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 326 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 327 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 328 | private static final int CMD_SET_SIM_POWER = 101; |
| 329 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 330 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 331 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 332 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 333 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 334 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 335 | 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] | 336 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 337 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 338 | // Parameters of select command. |
| 339 | private static final int SELECT_COMMAND = 0xA4; |
| 340 | private static final int SELECT_P1 = 0x04; |
| 341 | private static final int SELECT_P2 = 0; |
| 342 | private static final int SELECT_P3 = 0x10; |
| 343 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 344 | /** The singleton instance. */ |
| 345 | private static PhoneInterfaceManager sInstance; |
| 346 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 347 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 348 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 349 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 350 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 351 | private AppOpsManager mAppOps; |
| 352 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 353 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 354 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 355 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame^] | 356 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 357 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 358 | /** User Activity */ |
| 359 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 360 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 361 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 362 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 363 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 364 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 365 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 366 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 367 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 368 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 369 | // String to store multi SIM allowed |
| 370 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 371 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 372 | // The AID of ISD-R. |
| 373 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 374 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 375 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 376 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 377 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 378 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 379 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 380 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
| 381 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 382 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 383 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 384 | */ |
| 385 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 386 | "reset_network_erase_modem_config_enabled"; |
| 387 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 388 | private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds |
| 389 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 390 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 391 | * A request object to use for transmitting data to an ICC. |
| 392 | */ |
| 393 | private static final class IccAPDUArgument { |
| 394 | public int channel, cla, command, p1, p2, p3; |
| 395 | public String data; |
| 396 | |
| 397 | public IccAPDUArgument(int channel, int cla, int command, |
| 398 | int p1, int p2, int p3, String data) { |
| 399 | this.channel = channel; |
| 400 | this.cla = cla; |
| 401 | this.command = command; |
| 402 | this.p1 = p1; |
| 403 | this.p2 = p2; |
| 404 | this.p3 = p3; |
| 405 | this.data = data; |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 410 | * A request object to use for transmitting data to an ICC. |
| 411 | */ |
| 412 | private static final class ManualNetworkSelectionArgument { |
| 413 | public OperatorInfo operatorInfo; |
| 414 | public boolean persistSelection; |
| 415 | |
| 416 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 417 | this.operatorInfo = operatorInfo; |
| 418 | this.persistSelection = persistSelection; |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 423 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 424 | * request after sending. The main thread will notify the request when it is complete. |
| 425 | */ |
| 426 | private static final class MainThreadRequest { |
| 427 | /** The argument to use for the request */ |
| 428 | public Object argument; |
| 429 | /** The result of the request that is run on the main thread */ |
| 430 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 431 | // The subscriber id that this request applies to. Defaults to |
| 432 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 433 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 434 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 435 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 436 | public Phone phone; |
| 437 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 438 | public WorkSource workSource; |
| 439 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 440 | public MainThreadRequest(Object argument) { |
| 441 | this.argument = argument; |
| 442 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 443 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 444 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 445 | this.argument = argument; |
| 446 | if (phone != null) { |
| 447 | this.phone = phone; |
| 448 | } |
| 449 | this.workSource = workSource; |
| 450 | } |
| 451 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 452 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 453 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 454 | if (subId != null) { |
| 455 | this.subId = subId; |
| 456 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 457 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 458 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 459 | } |
| 460 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 461 | private static final class IncomingThirdPartyCallArgs { |
| 462 | public final ComponentName component; |
| 463 | public final String callId; |
| 464 | public final String callerDisplayName; |
| 465 | |
| 466 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 467 | String callerDisplayName) { |
| 468 | this.component = component; |
| 469 | this.callId = callId; |
| 470 | this.callerDisplayName = callerDisplayName; |
| 471 | } |
| 472 | } |
| 473 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 474 | /** |
| 475 | * A handler that processes messages on the main thread in the phone process. Since many |
| 476 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 477 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 478 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 479 | * on, which will be notified when the operation completes and will contain the result of the |
| 480 | * request. |
| 481 | * |
| 482 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 483 | * note that request.result must be set to something non-null for the calling thread to |
| 484 | * unblock. |
| 485 | */ |
| 486 | private final class MainThreadHandler extends Handler { |
| 487 | @Override |
| 488 | public void handleMessage(Message msg) { |
| 489 | MainThreadRequest request; |
| 490 | Message onCompleted; |
| 491 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 492 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 493 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 494 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 495 | |
| 496 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 497 | case CMD_HANDLE_USSD_REQUEST: { |
| 498 | request = (MainThreadRequest) msg.obj; |
| 499 | final Phone phone = getPhoneFromRequest(request); |
| 500 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 501 | String ussdRequest = ussdObject.first; |
| 502 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 503 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 504 | if (!isUssdApiAllowed(request.subId)) { |
| 505 | // Carrier does not support use of this API, return failure. |
| 506 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 507 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 508 | Bundle returnData = new Bundle(); |
| 509 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 510 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 511 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 512 | request.result = true; |
| 513 | notifyRequester(request); |
| 514 | return; |
| 515 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 516 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 517 | try { |
| 518 | request.result = phone != null |
| 519 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 520 | } catch (CallStateException cse) { |
| 521 | request.result = false; |
| 522 | } |
| 523 | // Wake up the requesting thread |
| 524 | notifyRequester(request); |
| 525 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 526 | } |
| 527 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 528 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 529 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 530 | final Phone phone = getPhoneFromRequest(request); |
| 531 | request.result = phone != null ? |
| 532 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 533 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 534 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 535 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 536 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 537 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 538 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 539 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 540 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 541 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 542 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 543 | if (uiccCard == null) { |
| 544 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 545 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 546 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 547 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 548 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 549 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 550 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 551 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 552 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 553 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 554 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 555 | break; |
| 556 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 557 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 558 | ar = (AsyncResult) msg.obj; |
| 559 | request = (MainThreadRequest) ar.userObj; |
| 560 | if (ar.exception == null && ar.result != null) { |
| 561 | request.result = ar.result; |
| 562 | } else { |
| 563 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 564 | if (ar.result == null) { |
| 565 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 566 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 567 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 568 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 569 | } else { |
| 570 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 571 | } |
| 572 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 573 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 574 | break; |
| 575 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 576 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 577 | request = (MainThreadRequest) msg.obj; |
| 578 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 579 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 580 | if (uiccCard == null) { |
| 581 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 582 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 583 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 584 | } else { |
| 585 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 586 | request); |
| 587 | uiccCard.iccTransmitApduBasicChannel( |
| 588 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 589 | iccArgument.p3, iccArgument.data, onCompleted); |
| 590 | } |
| 591 | break; |
| 592 | |
| 593 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 594 | ar = (AsyncResult) msg.obj; |
| 595 | request = (MainThreadRequest) ar.userObj; |
| 596 | if (ar.exception == null && ar.result != null) { |
| 597 | request.result = ar.result; |
| 598 | } else { |
| 599 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 600 | if (ar.result == null) { |
| 601 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 602 | } else if (ar.exception instanceof CommandException) { |
| 603 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 604 | ar.exception); |
| 605 | } else { |
| 606 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 607 | } |
| 608 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 609 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 610 | break; |
| 611 | |
| 612 | case CMD_EXCHANGE_SIM_IO: |
| 613 | request = (MainThreadRequest) msg.obj; |
| 614 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 615 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 616 | if (uiccCard == null) { |
| 617 | loge("iccExchangeSimIO: No UICC"); |
| 618 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 619 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 620 | } else { |
| 621 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 622 | request); |
| 623 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 624 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 625 | iccArgument.data, onCompleted); |
| 626 | } |
| 627 | break; |
| 628 | |
| 629 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 630 | ar = (AsyncResult) msg.obj; |
| 631 | request = (MainThreadRequest) ar.userObj; |
| 632 | if (ar.exception == null && ar.result != null) { |
| 633 | request.result = ar.result; |
| 634 | } else { |
| 635 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 636 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 637 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 638 | break; |
| 639 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 640 | case CMD_SEND_ENVELOPE: |
| 641 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 642 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 643 | if (uiccCard == null) { |
| 644 | loge("sendEnvelopeWithStatus: No UICC"); |
| 645 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 646 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 647 | } else { |
| 648 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 649 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 650 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 651 | break; |
| 652 | |
| 653 | case EVENT_SEND_ENVELOPE_DONE: |
| 654 | ar = (AsyncResult) msg.obj; |
| 655 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 656 | if (ar.exception == null && ar.result != null) { |
| 657 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 658 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 659 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 660 | if (ar.result == null) { |
| 661 | loge("sendEnvelopeWithStatus: Empty response"); |
| 662 | } else if (ar.exception instanceof CommandException) { |
| 663 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 664 | ar.exception); |
| 665 | } else { |
| 666 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 667 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 668 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 669 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 670 | break; |
| 671 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 672 | case CMD_OPEN_CHANNEL: |
| 673 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 674 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 675 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 676 | if (uiccCard == null) { |
| 677 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 678 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 679 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 680 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 681 | } else { |
| 682 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 683 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 684 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 685 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 686 | break; |
| 687 | |
| 688 | case EVENT_OPEN_CHANNEL_DONE: |
| 689 | ar = (AsyncResult) msg.obj; |
| 690 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 691 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 692 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 693 | int[] result = (int[]) ar.result; |
| 694 | int channelId = result[0]; |
| 695 | byte[] selectResponse = null; |
| 696 | if (result.length > 1) { |
| 697 | selectResponse = new byte[result.length - 1]; |
| 698 | for (int i = 1; i < result.length; ++i) { |
| 699 | selectResponse[i - 1] = (byte) result[i]; |
| 700 | } |
| 701 | } |
| 702 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 703 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 704 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 705 | if (ar.result == null) { |
| 706 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 707 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 708 | if (ar.exception != null) { |
| 709 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 710 | } |
| 711 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 712 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 713 | if (ar.exception instanceof CommandException) { |
| 714 | CommandException.Error error = |
| 715 | ((CommandException) (ar.exception)).getCommandError(); |
| 716 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 717 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 718 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 719 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 720 | } |
| 721 | } |
| 722 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 723 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 724 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 725 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 726 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 727 | break; |
| 728 | |
| 729 | case CMD_CLOSE_CHANNEL: |
| 730 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 731 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 732 | if (uiccCard == null) { |
| 733 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 734 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 735 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 736 | } else { |
| 737 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 738 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 739 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 740 | break; |
| 741 | |
| 742 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 743 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 744 | break; |
| 745 | |
| 746 | case CMD_NV_READ_ITEM: |
| 747 | request = (MainThreadRequest) msg.obj; |
| 748 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 749 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 750 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 751 | break; |
| 752 | |
| 753 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 754 | ar = (AsyncResult) msg.obj; |
| 755 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 756 | if (ar.exception == null && ar.result != null) { |
| 757 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 758 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 759 | request.result = ""; |
| 760 | if (ar.result == null) { |
| 761 | loge("nvReadItem: Empty response"); |
| 762 | } else if (ar.exception instanceof CommandException) { |
| 763 | loge("nvReadItem: CommandException: " + |
| 764 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 765 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 766 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 767 | } |
| 768 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 769 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 770 | break; |
| 771 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 772 | case CMD_NV_WRITE_ITEM: |
| 773 | request = (MainThreadRequest) msg.obj; |
| 774 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 775 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 776 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 777 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 778 | break; |
| 779 | |
| 780 | case EVENT_NV_WRITE_ITEM_DONE: |
| 781 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 782 | break; |
| 783 | |
| 784 | case CMD_NV_WRITE_CDMA_PRL: |
| 785 | request = (MainThreadRequest) msg.obj; |
| 786 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 787 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 788 | break; |
| 789 | |
| 790 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 791 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 792 | break; |
| 793 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 794 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 795 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 796 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 797 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 798 | break; |
| 799 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 800 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 801 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 802 | break; |
| 803 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 804 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 805 | request = (MainThreadRequest) msg.obj; |
| 806 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 807 | request); |
| 808 | Phone phone = getPhoneFromRequest(request); |
| 809 | if (phone != null) { |
| 810 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 811 | } else { |
| 812 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 813 | request.result = false; |
| 814 | notifyRequester(request); |
| 815 | } |
| 816 | break; |
| 817 | } |
| 818 | |
| 819 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 820 | ar = (AsyncResult) msg.obj; |
| 821 | request = (MainThreadRequest) ar.userObj; |
| 822 | if (ar.exception == null && ar.result != null) { |
| 823 | request.result = ar.result; |
| 824 | } else { |
| 825 | // request.result must be set to something non-null |
| 826 | // for the calling thread to unblock |
| 827 | if (request.result != null) { |
| 828 | request.result = ar.result; |
| 829 | } else { |
| 830 | request.result = false; |
| 831 | } |
| 832 | if (ar.result == null) { |
| 833 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 834 | } else if (ar.exception instanceof CommandException) { |
| 835 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 836 | + ar.exception); |
| 837 | } else { |
| 838 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 839 | } |
| 840 | } |
| 841 | notifyRequester(request); |
| 842 | break; |
| 843 | |
| 844 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 845 | request = (MainThreadRequest) msg.obj; |
| 846 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 847 | Phone phone = getPhoneFromRequest(request); |
| 848 | if (phone != null) { |
| 849 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 850 | request.workSource); |
| 851 | } else { |
| 852 | loge("enableNrDualConnectivity: No phone object"); |
| 853 | request.result = |
| 854 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 855 | notifyRequester(request); |
| 856 | } |
| 857 | break; |
| 858 | } |
| 859 | |
| 860 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 861 | ar = (AsyncResult) msg.obj; |
| 862 | request = (MainThreadRequest) ar.userObj; |
| 863 | if (ar.exception == null) { |
| 864 | request.result = |
| 865 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 866 | } else { |
| 867 | request.result = |
| 868 | TelephonyManager |
| 869 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 870 | if (ar.exception instanceof CommandException) { |
| 871 | CommandException.Error error = |
| 872 | ((CommandException) (ar.exception)).getCommandError(); |
| 873 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 874 | request.result = |
| 875 | TelephonyManager |
| 876 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 877 | } |
| 878 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 879 | + ar.exception); |
| 880 | } else { |
| 881 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 882 | } |
| 883 | } |
| 884 | notifyRequester(request); |
| 885 | break; |
| 886 | } |
| 887 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 888 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 889 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 890 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 891 | request); |
| 892 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 893 | break; |
| 894 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 895 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 896 | ar = (AsyncResult) msg.obj; |
| 897 | request = (MainThreadRequest) ar.userObj; |
| 898 | if (ar.exception == null && ar.result != null) { |
| 899 | request.result = ar.result; // Integer |
| 900 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 901 | // request.result must be set to something non-null |
| 902 | // for the calling thread to unblock |
| 903 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 904 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 905 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 906 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 907 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 908 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 909 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 910 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 911 | } |
| 912 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 913 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 914 | break; |
| 915 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 916 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 917 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 918 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 919 | request); |
| 920 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 921 | (Pair<Integer, Long>) request.argument; |
| 922 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 923 | reasonWithNetworkTypes.first, |
| 924 | reasonWithNetworkTypes.second, |
| 925 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 926 | break; |
| 927 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 928 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 929 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 930 | break; |
| 931 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 932 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 933 | request = (MainThreadRequest)msg.obj; |
| 934 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 935 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 936 | break; |
| 937 | |
| 938 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 939 | ar = (AsyncResult)msg.obj; |
| 940 | request = (MainThreadRequest)ar.userObj; |
| 941 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 942 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 943 | break; |
| 944 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 945 | case CMD_SET_VOICEMAIL_NUMBER: |
| 946 | request = (MainThreadRequest) msg.obj; |
| 947 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 948 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 949 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 950 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 951 | break; |
| 952 | |
| 953 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 954 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 955 | break; |
| 956 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 957 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 958 | request = (MainThreadRequest) msg.obj; |
| 959 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 960 | request); |
| 961 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 962 | break; |
| 963 | |
| 964 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 965 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 966 | break; |
| 967 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 968 | case CMD_PERFORM_NETWORK_SCAN: |
| 969 | request = (MainThreadRequest) msg.obj; |
| 970 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 971 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 972 | break; |
| 973 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 974 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 975 | request = (MainThreadRequest) msg.obj; |
| 976 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 977 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 978 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 979 | request.argument; |
| 980 | int callForwardingReason = args.first; |
| 981 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 982 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 983 | } |
| 984 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 985 | ar = (AsyncResult) msg.obj; |
| 986 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 987 | TelephonyManager.CallForwardingInfoCallback callback = |
| 988 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 989 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 990 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 991 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 992 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 993 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 994 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 995 | // any service for voice call. |
| 996 | if ((callForwardInfo.serviceClass |
| 997 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 998 | callForwardingInfo = new CallForwardingInfo(true, |
| 999 | callForwardInfo.reason, |
| 1000 | callForwardInfo.number, |
| 1001 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1002 | break; |
| 1003 | } |
| 1004 | } |
| 1005 | // Didn't find a call forward info for voice call. |
| 1006 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1007 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1008 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1009 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1010 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1011 | } else { |
| 1012 | if (ar.result == null) { |
| 1013 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1014 | } |
| 1015 | if (ar.exception != null) { |
| 1016 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1017 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1018 | int errorCode = TelephonyManager |
| 1019 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1020 | if (ar.exception instanceof CommandException) { |
| 1021 | CommandException.Error error = |
| 1022 | ((CommandException) (ar.exception)).getCommandError(); |
| 1023 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1024 | errorCode = TelephonyManager |
| 1025 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1026 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1027 | errorCode = TelephonyManager |
| 1028 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1029 | } |
| 1030 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1031 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1032 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1033 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1034 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1035 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1036 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1037 | request = (MainThreadRequest) msg.obj; |
| 1038 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1039 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1040 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1041 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1042 | request.argument).first; |
| 1043 | request.phone.setCallForwardingOption( |
| 1044 | callForwardingInfoToSet.isEnabled() |
| 1045 | ? CommandsInterface.CF_ACTION_ENABLE |
| 1046 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1047 | callForwardingInfoToSet.getReason(), |
| 1048 | callForwardingInfoToSet.getNumber(), |
| 1049 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1050 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1051 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1052 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1053 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1054 | ar = (AsyncResult) msg.obj; |
| 1055 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1056 | Consumer<Integer> callback = |
| 1057 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1058 | request.argument).second; |
| 1059 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1060 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1061 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1062 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1063 | if (ar.exception instanceof CommandException) { |
| 1064 | CommandException.Error error = |
| 1065 | ((CommandException) (ar.exception)).getCommandError(); |
| 1066 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1067 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1068 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1069 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1070 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1071 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1072 | } |
| 1073 | } |
| 1074 | callback.accept(errorCode); |
| 1075 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1076 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1077 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1078 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1079 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1080 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1081 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1082 | request = (MainThreadRequest) msg.obj; |
| 1083 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1084 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1085 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1086 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1087 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1088 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1089 | ar = (AsyncResult) msg.obj; |
| 1090 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1091 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1092 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1093 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1094 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1095 | // Service Class is a bit mask per 3gpp 27.007. |
| 1096 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1097 | if (callForwardResults.length > 1 |
| 1098 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1099 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1100 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1101 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1102 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1103 | } else { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1104 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1105 | } |
| 1106 | } else { |
| 1107 | if (ar.result == null) { |
| 1108 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1109 | } |
| 1110 | if (ar.exception != null) { |
| 1111 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1112 | } |
| 1113 | if (ar.exception instanceof CommandException) { |
| 1114 | CommandException.Error error = |
| 1115 | ((CommandException) (ar.exception)).getCommandError(); |
| 1116 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1117 | callForwardingStatus = |
| 1118 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1119 | } |
| 1120 | } |
| 1121 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1122 | callback.accept(callForwardingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1123 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1124 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1125 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1126 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1127 | request = (MainThreadRequest) msg.obj; |
| 1128 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1129 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1130 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
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 EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1135 | ar = (AsyncResult) msg.obj; |
| 1136 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1137 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1138 | Consumer<Integer> callback = |
| 1139 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1140 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1141 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1142 | if (ar.exception instanceof CommandException) { |
| 1143 | CommandException.Error error = |
| 1144 | ((CommandException) (ar.exception)).getCommandError(); |
| 1145 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1146 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1147 | } else { |
| 1148 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1149 | } |
| 1150 | } else { |
| 1151 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1152 | } |
| 1153 | } else { |
| 1154 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1155 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1156 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1157 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1158 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1159 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1160 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1161 | ar = (AsyncResult) msg.obj; |
| 1162 | request = (MainThreadRequest) ar.userObj; |
| 1163 | CellNetworkScanResult cellScanResult; |
| 1164 | if (ar.exception == null && ar.result != null) { |
| 1165 | cellScanResult = new CellNetworkScanResult( |
| 1166 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1167 | (List<OperatorInfo>) ar.result); |
| 1168 | } else { |
| 1169 | if (ar.result == null) { |
| 1170 | loge("getCellNetworkScanResults: Empty response"); |
| 1171 | } |
| 1172 | if (ar.exception != null) { |
| 1173 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1174 | } |
| 1175 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1176 | if (ar.exception instanceof CommandException) { |
| 1177 | CommandException.Error error = |
| 1178 | ((CommandException) (ar.exception)).getCommandError(); |
| 1179 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1180 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1181 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1182 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1183 | } |
| 1184 | } |
| 1185 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1186 | } |
| 1187 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1188 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1189 | break; |
| 1190 | |
| 1191 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1192 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1193 | ManualNetworkSelectionArgument selArg = |
| 1194 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1195 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1196 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1197 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1198 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1199 | break; |
| 1200 | |
| 1201 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1202 | ar = (AsyncResult) msg.obj; |
| 1203 | request = (MainThreadRequest) ar.userObj; |
| 1204 | if (ar.exception == null) { |
| 1205 | request.result = true; |
| 1206 | } else { |
| 1207 | request.result = false; |
| 1208 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1209 | } |
| 1210 | notifyRequester(request); |
| 1211 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1212 | break; |
| 1213 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1214 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1215 | request = (MainThreadRequest) msg.obj; |
| 1216 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1217 | if (defaultPhone != null) { |
| 1218 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1219 | } else { |
| 1220 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1221 | Bundle bundle = new Bundle(); |
| 1222 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1223 | new ModemActivityInfo(0, 0, 0, |
| 1224 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1225 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1226 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1227 | break; |
| 1228 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1229 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1230 | ar = (AsyncResult) msg.obj; |
| 1231 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1232 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1233 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1234 | ModemActivityInfo ret = null; |
| 1235 | int error = 0; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1236 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1237 | // Update the last modem activity info and the result of the request. |
| 1238 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1239 | if (isModemActivityInfoValid(info)) { |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1240 | int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()]; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1241 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1242 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1243 | .getTransmitTimeMillis(); |
| 1244 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1245 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1246 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1247 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1248 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1249 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1250 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1251 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1252 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1253 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1254 | info.getReceiveTimeMillis() |
| 1255 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1256 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1257 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(), |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1258 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1259 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1260 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1261 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1262 | } else { |
| 1263 | if (ar.result == null) { |
| 1264 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1265 | error = TelephonyManager.ModemActivityInfoException |
| 1266 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1267 | } else if (ar.exception instanceof CommandException) { |
| 1268 | loge("queryModemActivityInfo: CommandException: " + |
| 1269 | ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1270 | error = TelephonyManager.ModemActivityInfoException |
| 1271 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1272 | } else { |
| 1273 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1274 | error = TelephonyManager.ModemActivityInfoException |
| 1275 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1276 | } |
| 1277 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1278 | Bundle bundle = new Bundle(); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1279 | if (ret != null) { |
| 1280 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1281 | } else { |
| 1282 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1283 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1284 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1285 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1286 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1287 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1288 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1289 | case CMD_SET_ALLOWED_CARRIERS: |
| 1290 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1291 | CarrierRestrictionRules argument = |
| 1292 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1293 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1294 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1295 | break; |
| 1296 | |
| 1297 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1298 | ar = (AsyncResult) msg.obj; |
| 1299 | request = (MainThreadRequest) ar.userObj; |
| 1300 | if (ar.exception == null && ar.result != null) { |
| 1301 | request.result = ar.result; |
| 1302 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1303 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1304 | if (ar.exception instanceof CommandException) { |
| 1305 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1306 | CommandException.Error error = |
| 1307 | ((CommandException) (ar.exception)).getCommandError(); |
| 1308 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1309 | request.result = |
| 1310 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1311 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1312 | } else { |
| 1313 | loge("setAllowedCarriers: Unknown exception"); |
| 1314 | } |
| 1315 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1316 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1317 | break; |
| 1318 | |
| 1319 | case CMD_GET_ALLOWED_CARRIERS: |
| 1320 | request = (MainThreadRequest) msg.obj; |
| 1321 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1322 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1323 | break; |
| 1324 | |
| 1325 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1326 | ar = (AsyncResult) msg.obj; |
| 1327 | request = (MainThreadRequest) ar.userObj; |
| 1328 | if (ar.exception == null && ar.result != null) { |
| 1329 | request.result = ar.result; |
| 1330 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1331 | request.result = new IllegalStateException( |
| 1332 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1333 | if (ar.result == null) { |
| 1334 | loge("getAllowedCarriers: Empty response"); |
| 1335 | } else if (ar.exception instanceof CommandException) { |
| 1336 | loge("getAllowedCarriers: CommandException: " + |
| 1337 | ar.exception); |
| 1338 | } else { |
| 1339 | loge("getAllowedCarriers: Unknown exception"); |
| 1340 | } |
| 1341 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1342 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1343 | break; |
| 1344 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1345 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1346 | ar = (AsyncResult) msg.obj; |
| 1347 | request = (MainThreadRequest) ar.userObj; |
| 1348 | if (ar.exception == null && ar.result != null) { |
| 1349 | request.result = ar.result; |
| 1350 | } else { |
| 1351 | request.result = new IllegalArgumentException( |
| 1352 | "Failed to retrieve Forbidden Plmns"); |
| 1353 | if (ar.result == null) { |
| 1354 | loge("getForbiddenPlmns: Empty response"); |
| 1355 | } else { |
| 1356 | loge("getForbiddenPlmns: Unknown exception"); |
| 1357 | } |
| 1358 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1359 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1360 | break; |
| 1361 | |
| 1362 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1363 | request = (MainThreadRequest) msg.obj; |
| 1364 | uiccCard = getUiccCardFromRequest(request); |
| 1365 | if (uiccCard == null) { |
| 1366 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1367 | request.result = new IllegalArgumentException( |
| 1368 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1369 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1370 | break; |
| 1371 | } |
| 1372 | Integer appType = (Integer) request.argument; |
| 1373 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1374 | if (uiccApp == null) { |
| 1375 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1376 | + appType); |
| 1377 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1378 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1379 | break; |
| 1380 | } else { |
| 1381 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1382 | + " specified type -- " + appType); |
| 1383 | } |
| 1384 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1385 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1386 | onCompleted); |
| 1387 | break; |
| 1388 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1389 | case CMD_SWITCH_SLOTS: |
| 1390 | request = (MainThreadRequest) msg.obj; |
| 1391 | int[] physicalSlots = (int[]) request.argument; |
| 1392 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1393 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1394 | break; |
| 1395 | |
| 1396 | case EVENT_SWITCH_SLOTS_DONE: |
| 1397 | ar = (AsyncResult) msg.obj; |
| 1398 | request = (MainThreadRequest) ar.userObj; |
| 1399 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1400 | notifyRequester(request); |
| 1401 | break; |
| 1402 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1403 | request = (MainThreadRequest) msg.obj; |
| 1404 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1405 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1406 | break; |
| 1407 | |
| 1408 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1409 | ar = (AsyncResult) msg.obj; |
| 1410 | request = (MainThreadRequest) ar.userObj; |
| 1411 | if (ar.exception != null) { |
| 1412 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1413 | } else { |
| 1414 | int mode = ((int[]) ar.result)[0]; |
| 1415 | if (mode == 0) { |
| 1416 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1417 | } else { |
| 1418 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1419 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1420 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1421 | notifyRequester(request); |
| 1422 | break; |
| 1423 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1424 | request = (MainThreadRequest) msg.obj; |
| 1425 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1426 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1427 | break; |
| 1428 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1429 | ar = (AsyncResult) msg.obj; |
| 1430 | request = (MainThreadRequest) ar.userObj; |
| 1431 | if (ar.exception != null) { |
| 1432 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1433 | } else { |
| 1434 | request.result = ((int[]) ar.result)[0]; |
| 1435 | } |
| 1436 | notifyRequester(request); |
| 1437 | break; |
| 1438 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1439 | request = (MainThreadRequest) msg.obj; |
| 1440 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1441 | int mode = (int) request.argument; |
| 1442 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1443 | break; |
| 1444 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1445 | ar = (AsyncResult) msg.obj; |
| 1446 | request = (MainThreadRequest) ar.userObj; |
| 1447 | request.result = ar.exception == null; |
| 1448 | notifyRequester(request); |
| 1449 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1450 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1451 | request = (MainThreadRequest) msg.obj; |
| 1452 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1453 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1454 | break; |
| 1455 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1456 | ar = (AsyncResult) msg.obj; |
| 1457 | request = (MainThreadRequest) ar.userObj; |
| 1458 | if (ar.exception != null) { |
| 1459 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1460 | } else { |
| 1461 | request.result = ((int[]) ar.result)[0]; |
| 1462 | } |
| 1463 | notifyRequester(request); |
| 1464 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1465 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1466 | request = (MainThreadRequest) msg.obj; |
| 1467 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1468 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1469 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1470 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1471 | break; |
| 1472 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1473 | ar = (AsyncResult) msg.obj; |
| 1474 | request = (MainThreadRequest) ar.userObj; |
| 1475 | request.result = ar.exception == null; |
| 1476 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1477 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1478 | case CMD_GET_ALL_CELL_INFO: |
| 1479 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1480 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1481 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1482 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1483 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1484 | ar = (AsyncResult) msg.obj; |
| 1485 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1486 | // If a timeout occurs, the response will be null |
| 1487 | request.result = (ar.exception == null && ar.result != null) |
| 1488 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1489 | synchronized (request) { |
| 1490 | request.notifyAll(); |
| 1491 | } |
| 1492 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1493 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1494 | request = (MainThreadRequest) msg.obj; |
| 1495 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1496 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1497 | break; |
| 1498 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1499 | ar = (AsyncResult) msg.obj; |
| 1500 | request = (MainThreadRequest) ar.userObj; |
| 1501 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1502 | try { |
| 1503 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1504 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1505 | cb.onError( |
| 1506 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1507 | ar.exception.getClass().getName(), |
| 1508 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1509 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1510 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1511 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1512 | } else { |
| 1513 | // use the result as returned |
| 1514 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1515 | } |
| 1516 | } catch (RemoteException re) { |
| 1517 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1518 | } |
| 1519 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1520 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1521 | request = (MainThreadRequest) msg.obj; |
| 1522 | WorkSource ws = (WorkSource) request.argument; |
| 1523 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1524 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1525 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1526 | } |
| 1527 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1528 | ar = (AsyncResult) msg.obj; |
| 1529 | request = (MainThreadRequest) ar.userObj; |
| 1530 | if (ar.exception == null) { |
| 1531 | request.result = ar.result; |
| 1532 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1533 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1534 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1535 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1536 | } |
| 1537 | |
| 1538 | synchronized (request) { |
| 1539 | request.notifyAll(); |
| 1540 | } |
| 1541 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1542 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1543 | case CMD_MODEM_REBOOT: |
| 1544 | request = (MainThreadRequest) msg.obj; |
| 1545 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1546 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1547 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1548 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1549 | handleNullReturnEvent(msg, "rebootModem"); |
| 1550 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1551 | case CMD_REQUEST_ENABLE_MODEM: |
| 1552 | request = (MainThreadRequest) msg.obj; |
| 1553 | boolean enable = (boolean) request.argument; |
| 1554 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1555 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1556 | PhoneConfigurationManager.getInstance() |
| 1557 | .enablePhone(request.phone, enable, onCompleted); |
| 1558 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1559 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1560 | ar = (AsyncResult) msg.obj; |
| 1561 | request = (MainThreadRequest) ar.userObj; |
| 1562 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1563 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1564 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1565 | if ((boolean) request.result) { |
| 1566 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1567 | updateModemStateMetrics(); |
| 1568 | } else { |
| 1569 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1570 | + ar.exception); |
| 1571 | } |
| 1572 | notifyRequester(request); |
| 1573 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1574 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1575 | case CMD_GET_MODEM_STATUS: |
| 1576 | request = (MainThreadRequest) msg.obj; |
| 1577 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1578 | PhoneConfigurationManager.getInstance() |
| 1579 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1580 | break; |
| 1581 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1582 | ar = (AsyncResult) msg.obj; |
| 1583 | request = (MainThreadRequest) ar.userObj; |
| 1584 | int id = request.phone.getPhoneId(); |
| 1585 | if (ar.exception == null && ar.result != null) { |
| 1586 | request.result = ar.result; |
| 1587 | //update the cache as modem status has changed |
| 1588 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1589 | (boolean) request.result); |
| 1590 | } else { |
| 1591 | // Return true if modem status cannot be retrieved. For most cases, |
| 1592 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1593 | // and disable modem are not supported. Modem is always on. |
| 1594 | // TODO: this should be fixed in R to support a third |
| 1595 | // status UNKNOWN b/131631629 |
| 1596 | request.result = true; |
| 1597 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1598 | + ar.exception); |
| 1599 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1600 | notifyRequester(request); |
| 1601 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1602 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1603 | request = (MainThreadRequest) msg.obj; |
| 1604 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1605 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1606 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1607 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1608 | break; |
| 1609 | } |
| 1610 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1611 | ar = (AsyncResult) msg.obj; |
| 1612 | request = (MainThreadRequest) ar.userObj; |
| 1613 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1614 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1615 | args.second.accept(ar.exception == null); |
| 1616 | notifyRequester(request); |
| 1617 | break; |
| 1618 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1619 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1620 | request = (MainThreadRequest) msg.obj; |
| 1621 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1622 | Phone phone = getPhoneFromRequest(request); |
| 1623 | if (phone != null) { |
| 1624 | phone.getSystemSelectionChannels(onCompleted); |
| 1625 | } else { |
| 1626 | loge("getSystemSelectionChannels: No phone object"); |
| 1627 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1628 | notifyRequester(request); |
| 1629 | } |
| 1630 | break; |
| 1631 | } |
| 1632 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1633 | ar = (AsyncResult) msg.obj; |
| 1634 | request = (MainThreadRequest) ar.userObj; |
| 1635 | if (ar.exception == null && ar.result != null) { |
| 1636 | request.result = ar.result; |
| 1637 | } else { |
| 1638 | request.result = new IllegalArgumentException( |
| 1639 | "Failed to retrieve system selection channels"); |
| 1640 | if (ar.result == null) { |
| 1641 | loge("getSystemSelectionChannels: Empty response"); |
| 1642 | } else { |
| 1643 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1644 | } |
| 1645 | } |
| 1646 | notifyRequester(request); |
| 1647 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1648 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1649 | ar = (AsyncResult) msg.obj; |
| 1650 | request = (MainThreadRequest) ar.userObj; |
| 1651 | if (ar.exception == null && ar.result != null) { |
| 1652 | request.result = ar.result; |
| 1653 | } else { |
| 1654 | request.result = -1; |
| 1655 | loge("Failed to set Forbidden Plmns"); |
| 1656 | if (ar.result == null) { |
| 1657 | loge("setForbidenPlmns: Empty response"); |
| 1658 | } else if (ar.exception != null) { |
| 1659 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1660 | request.result = -1; |
| 1661 | } else { |
| 1662 | loge("setForbiddenPlmns: Unknown exception"); |
| 1663 | } |
| 1664 | } |
| 1665 | notifyRequester(request); |
| 1666 | break; |
| 1667 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1668 | request = (MainThreadRequest) msg.obj; |
| 1669 | uiccCard = getUiccCardFromRequest(request); |
| 1670 | if (uiccCard == null) { |
| 1671 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1672 | request.result = -1; |
| 1673 | notifyRequester(request); |
| 1674 | break; |
| 1675 | } |
| 1676 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1677 | (Pair<Integer, List<String>>) request.argument; |
| 1678 | appType = setFplmnsArgs.first; |
| 1679 | List<String> fplmns = setFplmnsArgs.second; |
| 1680 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1681 | if (uiccApp == null) { |
| 1682 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1683 | request.result = -1; |
| 1684 | loge("Failed to get UICC App"); |
| 1685 | notifyRequester(request); |
| 1686 | } else { |
| 1687 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1688 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1689 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1690 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1691 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1692 | case CMD_ERASE_MODEM_CONFIG: |
| 1693 | request = (MainThreadRequest) msg.obj; |
| 1694 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1695 | defaultPhone.eraseModemConfig(onCompleted); |
| 1696 | break; |
| 1697 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1698 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1699 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1700 | |
| 1701 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1702 | request = (MainThreadRequest) msg.obj; |
| 1703 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1704 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1705 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1706 | changed.first, changed.second, onCompleted); |
| 1707 | break; |
| 1708 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1709 | ar = (AsyncResult) msg.obj; |
| 1710 | request = (MainThreadRequest) ar.userObj; |
| 1711 | if (ar.exception == null) { |
| 1712 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1713 | // If the operation is successful, update the PIN storage |
| 1714 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1715 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1716 | UiccController.getInstance().getPinStorage() |
| 1717 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1718 | } else { |
| 1719 | request.result = msg.arg1; |
| 1720 | } |
| 1721 | notifyRequester(request); |
| 1722 | break; |
| 1723 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1724 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1725 | request = (MainThreadRequest) msg.obj; |
| 1726 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1727 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1728 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1729 | enabled.first, enabled.second, onCompleted); |
| 1730 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1731 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1732 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1733 | ar = (AsyncResult) msg.obj; |
| 1734 | request = (MainThreadRequest) ar.userObj; |
| 1735 | if (ar.exception == null) { |
| 1736 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1737 | // If the operation is successful, update the PIN storage |
| 1738 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1739 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1740 | if (enabled.first) { |
| 1741 | UiccController.getInstance().getPinStorage() |
| 1742 | .storePin(enabled.second, phoneId); |
| 1743 | } else { |
| 1744 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1745 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1746 | } else { |
| 1747 | request.result = msg.arg1; |
| 1748 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1749 | |
| 1750 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1751 | notifyRequester(request); |
| 1752 | break; |
| 1753 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1754 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1755 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1756 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1757 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1758 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1759 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1760 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1761 | |
| 1762 | case CMD_SET_DATA_THROTTLING: { |
| 1763 | request = (MainThreadRequest) msg.obj; |
| 1764 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1765 | DataThrottlingRequest dataThrottlingRequest = |
| 1766 | (DataThrottlingRequest) request.argument; |
| 1767 | Phone phone = getPhoneFromRequest(request); |
| 1768 | if (phone != null) { |
| 1769 | phone.setDataThrottling(onCompleted, |
| 1770 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1771 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1772 | } else { |
| 1773 | loge("setDataThrottling: No phone object"); |
| 1774 | request.result = |
| 1775 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1776 | notifyRequester(request); |
| 1777 | } |
| 1778 | |
| 1779 | break; |
| 1780 | } |
| 1781 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1782 | ar = (AsyncResult) msg.obj; |
| 1783 | request = (MainThreadRequest) ar.userObj; |
| 1784 | |
| 1785 | if (ar.exception == null) { |
| 1786 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1787 | } else if (ar.exception instanceof CommandException) { |
| 1788 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1789 | CommandException.Error error = |
| 1790 | ((CommandException) (ar.exception)).getCommandError(); |
| 1791 | |
| 1792 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1793 | request.result = TelephonyManager |
| 1794 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1795 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1796 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
| 1797 | } else { |
| 1798 | request.result = |
| 1799 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1800 | } |
| 1801 | } else { |
| 1802 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1803 | } |
| 1804 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1805 | notifyRequester(request); |
| 1806 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1807 | |
| 1808 | case CMD_SET_SIM_POWER: { |
| 1809 | request = (MainThreadRequest) msg.obj; |
| 1810 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1811 | request = (MainThreadRequest) msg.obj; |
| 1812 | int stateToSet = |
| 1813 | ((Pair<Integer, IIntegerConsumer>) |
| 1814 | request.argument).first; |
| 1815 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1816 | break; |
| 1817 | } |
| 1818 | case EVENT_SET_SIM_POWER_DONE: { |
| 1819 | ar = (AsyncResult) msg.obj; |
| 1820 | request = (MainThreadRequest) ar.userObj; |
| 1821 | IIntegerConsumer callback = |
| 1822 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1823 | if (ar.exception != null) { |
| 1824 | loge("setSimPower exception: " + ar.exception); |
| 1825 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1826 | .RESULT_ERROR_UNKNOWN; |
| 1827 | if (ar.exception instanceof CommandException) { |
| 1828 | CommandException.Error error = |
| 1829 | ((CommandException) (ar.exception)).getCommandError(); |
| 1830 | if (error == CommandException.Error.SIM_ERR) { |
| 1831 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1832 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1833 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1834 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1835 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1836 | } else { |
| 1837 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1838 | } |
| 1839 | } |
| 1840 | try { |
| 1841 | callback.accept(errorCode); |
| 1842 | } catch (RemoteException e) { |
| 1843 | // Ignore if the remote process is no longer available to call back. |
| 1844 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1845 | } |
| 1846 | } else { |
| 1847 | try { |
| 1848 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1849 | } catch (RemoteException e) { |
| 1850 | // Ignore if the remote process is no longer available to call back. |
| 1851 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1852 | } |
| 1853 | } |
| 1854 | break; |
| 1855 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1856 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1857 | request = (MainThreadRequest) msg.obj; |
| 1858 | |
| 1859 | final Phone phone = getPhoneFromRequest(request); |
| 1860 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1861 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1862 | notifyRequester(request); |
| 1863 | break; |
| 1864 | } |
| 1865 | |
| 1866 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1867 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1868 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1869 | request); |
| 1870 | phone.getServiceStateTracker().setSignalStrengthUpdateRequest( |
| 1871 | request.subId, pair.first /*callingUid*/, |
| 1872 | pair.second /*request*/, onCompleted); |
| 1873 | break; |
| 1874 | } |
| 1875 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1876 | ar = (AsyncResult) msg.obj; |
| 1877 | request = (MainThreadRequest) ar.userObj; |
| 1878 | // request.result will be the exception of ar if present, true otherwise. |
| 1879 | // Be cautious not to leave result null which will wait() forever |
| 1880 | request.result = ar.exception != null ? ar.exception : true; |
| 1881 | notifyRequester(request); |
| 1882 | break; |
| 1883 | } |
| 1884 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1885 | request = (MainThreadRequest) msg.obj; |
| 1886 | |
| 1887 | Phone phone = getPhoneFromRequest(request); |
| 1888 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1889 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1890 | notifyRequester(request); |
| 1891 | break; |
| 1892 | } |
| 1893 | |
| 1894 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1895 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1896 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1897 | request); |
| 1898 | phone.getServiceStateTracker().clearSignalStrengthUpdateRequest( |
| 1899 | request.subId, pair.first /*callingUid*/, |
| 1900 | pair.second /*request*/, onCompleted); |
| 1901 | break; |
| 1902 | } |
| 1903 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1904 | ar = (AsyncResult) msg.obj; |
| 1905 | request = (MainThreadRequest) ar.userObj; |
| 1906 | request.result = ar.exception != null ? ar.exception : true; |
| 1907 | notifyRequester(request); |
| 1908 | break; |
| 1909 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1910 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1911 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 1912 | request = (MainThreadRequest) msg.obj; |
| 1913 | request.result = |
| 1914 | UiccController.getInstance().getPinStorage().prepareUnattendedReboot(); |
| 1915 | notifyRequester(request); |
| 1916 | break; |
| 1917 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1918 | default: |
| 1919 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1920 | break; |
| 1921 | } |
| 1922 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1923 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1924 | private void notifyRequester(MainThreadRequest request) { |
| 1925 | synchronized (request) { |
| 1926 | request.notifyAll(); |
| 1927 | } |
| 1928 | } |
| 1929 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1930 | private void handleNullReturnEvent(Message msg, String command) { |
| 1931 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1932 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1933 | if (ar.exception == null) { |
| 1934 | request.result = true; |
| 1935 | } else { |
| 1936 | request.result = false; |
| 1937 | if (ar.exception instanceof CommandException) { |
| 1938 | loge(command + ": CommandException: " + ar.exception); |
| 1939 | } else { |
| 1940 | loge(command + ": Unknown exception"); |
| 1941 | } |
| 1942 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1943 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1944 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1945 | } |
| 1946 | |
| 1947 | /** |
| 1948 | * Posts the specified command to be executed on the main thread, |
| 1949 | * waits for the request to complete, and returns the result. |
| 1950 | * @see #sendRequestAsync |
| 1951 | */ |
| 1952 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1953 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 1954 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1955 | } |
| 1956 | |
| 1957 | /** |
| 1958 | * Posts the specified command to be executed on the main thread, |
| 1959 | * waits for the request to complete, and returns the result. |
| 1960 | * @see #sendRequestAsync |
| 1961 | */ |
| 1962 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1963 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1964 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | /** |
| 1968 | * Posts the specified command to be executed on the main thread, |
| 1969 | * waits for the request to complete, and returns the result. |
| 1970 | * @see #sendRequestAsync |
| 1971 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1972 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1973 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 1974 | } |
| 1975 | |
| 1976 | /** |
| 1977 | * Posts the specified command to be executed on the main thread, |
| 1978 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 1979 | * if not timeout or null otherwise. |
| 1980 | * @see #sendRequestAsync |
| 1981 | */ |
| 1982 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 1983 | long timeoutInMs) { |
| 1984 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1985 | } |
| 1986 | |
| 1987 | /** |
| 1988 | * Posts the specified command to be executed on the main thread, |
| 1989 | * waits for the request to complete, and returns the result. |
| 1990 | * @see #sendRequestAsync |
| 1991 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1992 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1993 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1994 | } |
| 1995 | |
| 1996 | /** |
| 1997 | * Posts the specified command to be executed on the main thread, |
| 1998 | * waits for the request to complete, and returns the result. |
| 1999 | * @see #sendRequestAsync |
| 2000 | */ |
| 2001 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2002 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2003 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2004 | } |
| 2005 | |
| 2006 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2007 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2008 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2009 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2010 | * @see #sendRequestAsync |
| 2011 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2012 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2013 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2014 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2015 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2016 | } |
| 2017 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2018 | MainThreadRequest request = null; |
| 2019 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2020 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2021 | } else if (phone != null) { |
| 2022 | request = new MainThreadRequest(argument, phone, workSource); |
| 2023 | } else { |
| 2024 | request = new MainThreadRequest(argument, subId, workSource); |
| 2025 | } |
| 2026 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2027 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2028 | msg.sendToTarget(); |
| 2029 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2030 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2031 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2032 | if (timeoutInMs >= 0) { |
| 2033 | // Wait for at least timeoutInMs before returning null request result |
| 2034 | long now = SystemClock.elapsedRealtime(); |
| 2035 | long deadline = now + timeoutInMs; |
| 2036 | while (request == null && now < deadline) { |
| 2037 | try { |
| 2038 | request.wait(deadline - now); |
| 2039 | } catch (InterruptedException e) { |
| 2040 | // Do nothing, go back and check if request is completed or timeout |
| 2041 | } finally { |
| 2042 | now = SystemClock.elapsedRealtime(); |
| 2043 | } |
| 2044 | } |
| 2045 | } else { |
| 2046 | // Wait for the request to complete |
| 2047 | while (request.result == null) { |
| 2048 | try { |
| 2049 | request.wait(); |
| 2050 | } catch (InterruptedException e) { |
| 2051 | // Do nothing, go back and wait until the request is complete |
| 2052 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2053 | } |
| 2054 | } |
| 2055 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2056 | if (request.result == null) { |
| 2057 | Log.wtf(LOG_TAG, |
| 2058 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2059 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2060 | return request.result; |
| 2061 | } |
| 2062 | |
| 2063 | /** |
| 2064 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2065 | * Posts the specified command to be executed on the main thread, and |
| 2066 | * returns immediately. |
| 2067 | * @see #sendRequest |
| 2068 | */ |
| 2069 | private void sendRequestAsync(int command) { |
| 2070 | mMainThreadHandler.sendEmptyMessage(command); |
| 2071 | } |
| 2072 | |
| 2073 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2074 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2075 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2076 | */ |
| 2077 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2078 | sendRequestAsync(command, argument, null, null); |
| 2079 | } |
| 2080 | |
| 2081 | /** |
| 2082 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2083 | * @see {@link #sendRequest(int,Object)} |
| 2084 | */ |
| 2085 | private void sendRequestAsync( |
| 2086 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2087 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2088 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2089 | msg.sendToTarget(); |
| 2090 | } |
| 2091 | |
| 2092 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2093 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2094 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2095 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2096 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2097 | synchronized (PhoneInterfaceManager.class) { |
| 2098 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2099 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2100 | } else { |
| 2101 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2102 | } |
| 2103 | return sInstance; |
| 2104 | } |
| 2105 | } |
| 2106 | |
| 2107 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2108 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2109 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2110 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 2111 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2112 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2113 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2114 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2115 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2116 | mTelephonySharedPreferences = |
| 2117 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2118 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2119 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame^] | 2120 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2121 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2122 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2123 | publish(); |
| 2124 | } |
| 2125 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2126 | private Phone getDefaultPhone() { |
| 2127 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2128 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2129 | } |
| 2130 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2131 | private void publish() { |
| 2132 | if (DBG) log("publish: " + this); |
| 2133 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2134 | TelephonyFrameworkInitializer |
| 2135 | .getTelephonyServiceManager() |
| 2136 | .getTelephonyServiceRegisterer() |
| 2137 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2138 | } |
| 2139 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2140 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2141 | if (request.phone != null) { |
| 2142 | return request.phone; |
| 2143 | } else { |
| 2144 | return getPhoneFromSubId(request.subId); |
| 2145 | } |
| 2146 | } |
| 2147 | |
| 2148 | private Phone getPhoneFromSubId(int subId) { |
| 2149 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2150 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2151 | } |
| 2152 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2153 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 2154 | Phone phone = getPhoneFromRequest(request); |
| 2155 | return phone == null ? null : |
| 2156 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 2157 | } |
| 2158 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2159 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2160 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2161 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2162 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2163 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2164 | private void sendEraseModemConfig(Phone phone) { |
| 2165 | if (phone != null) { |
| 2166 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2167 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 2168 | final long identity = Binder.clearCallingIdentity(); |
| 2169 | try { |
| 2170 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2171 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2172 | } finally { |
| 2173 | Binder.restoreCallingIdentity(identity); |
| 2174 | } |
| 2175 | } |
| 2176 | } |
| 2177 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2178 | private boolean isImsAvailableOnDevice() { |
| 2179 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2180 | if (pm == null) { |
| 2181 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2182 | // so do not throw error and allow. |
| 2183 | return true; |
| 2184 | } |
| 2185 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2186 | } |
| 2187 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2188 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2189 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2190 | } |
| 2191 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2192 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2193 | if (DBG) log("dial: " + number); |
| 2194 | // No permission check needed here: This is just a wrapper around the |
| 2195 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2196 | // the UI before it does anything. |
| 2197 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2198 | final long identity = Binder.clearCallingIdentity(); |
| 2199 | try { |
| 2200 | String url = createTelUrl(number); |
| 2201 | if (url == null) { |
| 2202 | return; |
| 2203 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2204 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2205 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2206 | PhoneConstants.State state = mCM.getState(subId); |
| 2207 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2208 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2209 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2210 | mApp.startActivity(intent); |
| 2211 | } |
| 2212 | } finally { |
| 2213 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2214 | } |
| 2215 | } |
| 2216 | |
| 2217 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2218 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2219 | } |
| 2220 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2221 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2222 | if (DBG) log("call: " + number); |
| 2223 | |
| 2224 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2225 | // need to do a permission check since we're calling startActivity() |
| 2226 | // from the context of the phone app. |
| 2227 | enforceCallPermission(); |
| 2228 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2229 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2230 | != AppOpsManager.MODE_ALLOWED) { |
| 2231 | return; |
| 2232 | } |
| 2233 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2234 | final long identity = Binder.clearCallingIdentity(); |
| 2235 | try { |
| 2236 | String url = createTelUrl(number); |
| 2237 | if (url == null) { |
| 2238 | return; |
| 2239 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2240 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2241 | boolean isValid = false; |
| 2242 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2243 | if (slist != null) { |
| 2244 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2245 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2246 | isValid = true; |
| 2247 | break; |
| 2248 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2249 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2250 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2251 | if (!isValid) { |
| 2252 | return; |
| 2253 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2254 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2255 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2256 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2257 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2258 | mApp.startActivity(intent); |
| 2259 | } finally { |
| 2260 | Binder.restoreCallingIdentity(identity); |
| 2261 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2262 | } |
| 2263 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2264 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2265 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2266 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2267 | } |
| 2268 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2269 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2270 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2271 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2272 | } |
| 2273 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2274 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2275 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2276 | |
| 2277 | final long identity = Binder.clearCallingIdentity(); |
| 2278 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2279 | Phone phone = getPhone(subId); |
| 2280 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2281 | checkSimPin.start(); |
| 2282 | return checkSimPin.unlockSim(null, pin); |
| 2283 | } finally { |
| 2284 | Binder.restoreCallingIdentity(identity); |
| 2285 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2286 | } |
| 2287 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2288 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2289 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2290 | |
| 2291 | final long identity = Binder.clearCallingIdentity(); |
| 2292 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2293 | Phone phone = getPhone(subId); |
| 2294 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2295 | checkSimPuk.start(); |
| 2296 | return checkSimPuk.unlockSim(puk, pin); |
| 2297 | } finally { |
| 2298 | Binder.restoreCallingIdentity(identity); |
| 2299 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2300 | } |
| 2301 | |
| 2302 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2303 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2304 | * a synchronous one. |
| 2305 | */ |
| 2306 | private static class UnlockSim extends Thread { |
| 2307 | |
| 2308 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2309 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2310 | |
| 2311 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2312 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2313 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2314 | |
| 2315 | // For replies from SimCard interface |
| 2316 | private Handler mHandler; |
| 2317 | |
| 2318 | // For async handler to identify request type |
| 2319 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2320 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2321 | UnlockSim(int phoneId, IccCard simCard) { |
| 2322 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2323 | mSimCard = simCard; |
| 2324 | } |
| 2325 | |
| 2326 | @Override |
| 2327 | public void run() { |
| 2328 | Looper.prepare(); |
| 2329 | synchronized (UnlockSim.this) { |
| 2330 | mHandler = new Handler() { |
| 2331 | @Override |
| 2332 | public void handleMessage(Message msg) { |
| 2333 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2334 | switch (msg.what) { |
| 2335 | case SUPPLY_PIN_COMPLETE: |
| 2336 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2337 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2338 | mRetryCount = msg.arg1; |
| 2339 | if (ar.exception != null) { |
| 2340 | if (ar.exception instanceof CommandException && |
| 2341 | ((CommandException)(ar.exception)).getCommandError() |
| 2342 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2343 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2344 | } //When UiccCardApp dispose,handle message and return exception |
| 2345 | else if (ar.exception instanceof CommandException && |
| 2346 | ((CommandException) (ar.exception)).getCommandError() |
| 2347 | == CommandException.Error.ABORTED) { |
| 2348 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2349 | } else { |
| 2350 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2351 | } |
| 2352 | } else { |
| 2353 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2354 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2355 | mDone = true; |
| 2356 | UnlockSim.this.notifyAll(); |
| 2357 | } |
| 2358 | break; |
| 2359 | } |
| 2360 | } |
| 2361 | }; |
| 2362 | UnlockSim.this.notifyAll(); |
| 2363 | } |
| 2364 | Looper.loop(); |
| 2365 | } |
| 2366 | |
| 2367 | /* |
| 2368 | * Use PIN or PUK to unlock SIM card |
| 2369 | * |
| 2370 | * If PUK is null, unlock SIM card with PIN |
| 2371 | * |
| 2372 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2373 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2374 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2375 | |
| 2376 | while (mHandler == null) { |
| 2377 | try { |
| 2378 | wait(); |
| 2379 | } catch (InterruptedException e) { |
| 2380 | Thread.currentThread().interrupt(); |
| 2381 | } |
| 2382 | } |
| 2383 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2384 | |
| 2385 | if (puk == null) { |
| 2386 | mSimCard.supplyPin(pin, callback); |
| 2387 | } else { |
| 2388 | mSimCard.supplyPuk(puk, pin, callback); |
| 2389 | } |
| 2390 | |
| 2391 | while (!mDone) { |
| 2392 | try { |
| 2393 | Log.d(LOG_TAG, "wait for done"); |
| 2394 | wait(); |
| 2395 | } catch (InterruptedException e) { |
| 2396 | // Restore the interrupted status |
| 2397 | Thread.currentThread().interrupt(); |
| 2398 | } |
| 2399 | } |
| 2400 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2401 | int[] resultArray = new int[2]; |
| 2402 | resultArray[0] = mResult; |
| 2403 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2404 | |
| 2405 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
| 2406 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
| 2407 | } |
| 2408 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2409 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2410 | } |
| 2411 | } |
| 2412 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2413 | /** |
| 2414 | * This method has been removed due to privacy and stability concerns. |
| 2415 | */ |
| 2416 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2417 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2418 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2419 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2420 | } |
| 2421 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2422 | @Override |
| 2423 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2424 | mApp.getSystemService(AppOpsManager.class) |
| 2425 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2426 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2427 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2428 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2429 | // Callers targeting S have no business invoking this method. |
| 2430 | return; |
| 2431 | } |
| 2432 | |
| 2433 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2434 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2435 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2436 | .setCallingPackage(callingPackage) |
| 2437 | .setCallingFeatureId(null) |
| 2438 | .setCallingPid(Binder.getCallingPid()) |
| 2439 | .setCallingUid(Binder.getCallingUid()) |
| 2440 | .setMethod("updateServiceLocation") |
| 2441 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2442 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2443 | .build()); |
| 2444 | // Apps that lack location permission have no business calling this method; |
| 2445 | // however, because no permission was declared in the public API, denials must |
| 2446 | // all be "soft". |
| 2447 | switch (locationResult) { |
| 2448 | case DENIED_HARD: /* fall through */ |
| 2449 | case DENIED_SOFT: |
| 2450 | return; |
| 2451 | } |
| 2452 | |
| 2453 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2454 | final long identity = Binder.clearCallingIdentity(); |
| 2455 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2456 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2457 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2458 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2459 | } |
| 2460 | } finally { |
| 2461 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2462 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2463 | } |
| 2464 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2465 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2466 | @Override |
| 2467 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2468 | return isRadioOnWithFeature(callingPackage, null); |
| 2469 | } |
| 2470 | |
| 2471 | |
| 2472 | @Override |
| 2473 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2474 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2475 | callingFeatureId); |
| 2476 | } |
| 2477 | |
| 2478 | @Deprecated |
| 2479 | @Override |
| 2480 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2481 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2482 | } |
| 2483 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2484 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2485 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2486 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2487 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2488 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2489 | return false; |
| 2490 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2491 | |
| 2492 | final long identity = Binder.clearCallingIdentity(); |
| 2493 | try { |
| 2494 | return isRadioOnForSubscriber(subId); |
| 2495 | } finally { |
| 2496 | Binder.restoreCallingIdentity(identity); |
| 2497 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2498 | } |
| 2499 | |
| 2500 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2501 | final long identity = Binder.clearCallingIdentity(); |
| 2502 | try { |
| 2503 | final Phone phone = getPhone(subId); |
| 2504 | if (phone != null) { |
| 2505 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2506 | } else { |
| 2507 | return false; |
| 2508 | } |
| 2509 | } finally { |
| 2510 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2511 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2512 | } |
| 2513 | |
| 2514 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2515 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2516 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2517 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2518 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2519 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2520 | |
| 2521 | final long identity = Binder.clearCallingIdentity(); |
| 2522 | try { |
| 2523 | final Phone phone = getPhone(subId); |
| 2524 | if (phone != null) { |
| 2525 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2526 | } |
| 2527 | } finally { |
| 2528 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2529 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2530 | } |
| 2531 | |
| 2532 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2533 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2534 | } |
| 2535 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2536 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2537 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2538 | |
| 2539 | final long identity = Binder.clearCallingIdentity(); |
| 2540 | try { |
| 2541 | final Phone phone = getPhone(subId); |
| 2542 | if (phone == null) { |
| 2543 | return false; |
| 2544 | } |
| 2545 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2546 | toggleRadioOnOffForSubscriber(subId); |
| 2547 | } |
| 2548 | return true; |
| 2549 | } finally { |
| 2550 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2551 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2552 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2553 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2554 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2555 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2556 | /* |
| 2557 | * If any of the Radios are available, it will need to be |
| 2558 | * shutdown. So return true if any Radio is available. |
| 2559 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2560 | final long identity = Binder.clearCallingIdentity(); |
| 2561 | try { |
| 2562 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2563 | Phone phone = PhoneFactory.getPhone(i); |
| 2564 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2565 | } |
| 2566 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2567 | return false; |
| 2568 | } finally { |
| 2569 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2570 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2571 | } |
| 2572 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2573 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2574 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2575 | enforceModifyPermission(); |
| 2576 | |
| 2577 | final long identity = Binder.clearCallingIdentity(); |
| 2578 | try { |
| 2579 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2580 | logv("Shutting down Phone " + i); |
| 2581 | shutdownRadioUsingPhoneId(i); |
| 2582 | } |
| 2583 | } finally { |
| 2584 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2585 | } |
| 2586 | } |
| 2587 | |
| 2588 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2589 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2590 | if (phone != null && phone.isRadioAvailable()) { |
| 2591 | phone.shutdownRadio(); |
| 2592 | } |
| 2593 | } |
| 2594 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2595 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2596 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2597 | |
| 2598 | final long identity = Binder.clearCallingIdentity(); |
| 2599 | try { |
| 2600 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2601 | if (defaultPhone != null) { |
| 2602 | defaultPhone.setRadioPower(turnOn); |
| 2603 | return true; |
| 2604 | } else { |
| 2605 | loge("There's no default phone."); |
| 2606 | return false; |
| 2607 | } |
| 2608 | } finally { |
| 2609 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2610 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2611 | } |
| 2612 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2613 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2614 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2615 | |
| 2616 | final long identity = Binder.clearCallingIdentity(); |
| 2617 | try { |
| 2618 | final Phone phone = getPhone(subId); |
| 2619 | if (phone != null) { |
| 2620 | phone.setRadioPower(turnOn); |
| 2621 | return true; |
| 2622 | } else { |
| 2623 | return false; |
| 2624 | } |
| 2625 | } finally { |
| 2626 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2627 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2628 | } |
| 2629 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2630 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2631 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2632 | public boolean enableDataConnectivity() { |
| 2633 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2634 | |
| 2635 | final long identity = Binder.clearCallingIdentity(); |
| 2636 | try { |
| 2637 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2638 | final Phone phone = getPhone(subId); |
| 2639 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2640 | phone.getDataEnabledSettings().setDataEnabled( |
| 2641 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2642 | return true; |
| 2643 | } else { |
| 2644 | return false; |
| 2645 | } |
| 2646 | } finally { |
| 2647 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2648 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2649 | } |
| 2650 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2651 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2652 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2653 | public boolean disableDataConnectivity() { |
| 2654 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2655 | |
| 2656 | final long identity = Binder.clearCallingIdentity(); |
| 2657 | try { |
| 2658 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2659 | final Phone phone = getPhone(subId); |
| 2660 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2661 | phone.getDataEnabledSettings().setDataEnabled( |
| 2662 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2663 | return true; |
| 2664 | } else { |
| 2665 | return false; |
| 2666 | } |
| 2667 | } finally { |
| 2668 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2669 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2670 | } |
| 2671 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2672 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2673 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2674 | final long identity = Binder.clearCallingIdentity(); |
| 2675 | try { |
| 2676 | final Phone phone = getPhone(subId); |
| 2677 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2678 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2679 | } else { |
| 2680 | return false; |
| 2681 | } |
| 2682 | } finally { |
| 2683 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2684 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2685 | } |
| 2686 | |
| 2687 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2688 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2689 | } |
| 2690 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2691 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2692 | enforceCallPermission(); |
| 2693 | |
| 2694 | final long identity = Binder.clearCallingIdentity(); |
| 2695 | try { |
| 2696 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2697 | return; |
| 2698 | } |
| 2699 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2700 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2701 | } finally { |
| 2702 | Binder.restoreCallingIdentity(identity); |
| 2703 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2704 | }; |
| 2705 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2706 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2707 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2708 | |
| 2709 | final long identity = Binder.clearCallingIdentity(); |
| 2710 | try { |
| 2711 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2712 | return false; |
| 2713 | } |
| 2714 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2715 | } finally { |
| 2716 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2717 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2718 | } |
| 2719 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2720 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2721 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2722 | } |
| 2723 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2724 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2725 | final long identity = Binder.clearCallingIdentity(); |
| 2726 | try { |
| 2727 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2728 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2729 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2730 | } finally { |
| 2731 | Binder.restoreCallingIdentity(identity); |
| 2732 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2733 | } |
| 2734 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2735 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2736 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2737 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2738 | } |
| 2739 | |
| 2740 | @Override |
| 2741 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2742 | final long identity = Binder.clearCallingIdentity(); |
| 2743 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2744 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2745 | if (phone != null) { |
| 2746 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2747 | } else { |
| 2748 | return PhoneConstantConversions.convertDataState( |
| 2749 | PhoneConstants.DataState.DISCONNECTED); |
| 2750 | } |
| 2751 | } finally { |
| 2752 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2753 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2754 | } |
| 2755 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2756 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2757 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2758 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2759 | } |
| 2760 | |
| 2761 | @Override |
| 2762 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2763 | final long identity = Binder.clearCallingIdentity(); |
| 2764 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2765 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2766 | if (phone != null) { |
| 2767 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2768 | } else { |
| 2769 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2770 | } |
| 2771 | } finally { |
| 2772 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2773 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2774 | } |
| 2775 | |
| 2776 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2777 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2778 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2779 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2780 | |
| 2781 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2782 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2783 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2784 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2785 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2786 | .setCallingPid(Binder.getCallingPid()) |
| 2787 | .setCallingUid(Binder.getCallingUid()) |
| 2788 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2789 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2790 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2791 | .build()); |
| 2792 | switch (locationResult) { |
| 2793 | case DENIED_HARD: |
| 2794 | throw new SecurityException("Not allowed to access cell location"); |
| 2795 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2796 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2797 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2798 | } |
| 2799 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2800 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2801 | final long identity = Binder.clearCallingIdentity(); |
| 2802 | try { |
| 2803 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2804 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2805 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2806 | } finally { |
| 2807 | Binder.restoreCallingIdentity(identity); |
| 2808 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2809 | } |
| 2810 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2811 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2812 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2813 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2814 | // registered cell info, so return a NULL country instead. |
| 2815 | final long identity = Binder.clearCallingIdentity(); |
| 2816 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2817 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2818 | // Get default phone in this case. |
| 2819 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2820 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2821 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2822 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2823 | if (phone == null) return ""; |
| 2824 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2825 | if (sst == null) return ""; |
| 2826 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2827 | if (lt == null) return ""; |
| 2828 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2829 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2830 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2831 | } finally { |
| 2832 | Binder.restoreCallingIdentity(identity); |
| 2833 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2834 | } |
| 2835 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2836 | /** |
| 2837 | * This method was removed due to potential issues caused by performing partial |
| 2838 | * updates of service state, and lack of a credible use case. |
| 2839 | * |
| 2840 | * This has the ability to break the telephony implementation by disabling notification of |
| 2841 | * changes in device connectivity. DO NOT USE THIS! |
| 2842 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2843 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2844 | public void enableLocationUpdates() { |
| 2845 | mApp.enforceCallingOrSelfPermission( |
| 2846 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2847 | } |
| 2848 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2849 | /** |
| 2850 | * This method was removed due to potential issues caused by performing partial |
| 2851 | * updates of service state, and lack of a credible use case. |
| 2852 | * |
| 2853 | * This has the ability to break the telephony implementation by disabling notification of |
| 2854 | * changes in device connectivity. DO NOT USE THIS! |
| 2855 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2856 | @Override |
| 2857 | public void disableLocationUpdates() { |
| 2858 | mApp.enforceCallingOrSelfPermission( |
| 2859 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2860 | } |
| 2861 | |
| 2862 | @Override |
| 2863 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2864 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2865 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2866 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2867 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2868 | throw new SecurityException( |
| 2869 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2870 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2871 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2872 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2873 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2874 | return null; |
| 2875 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2876 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2877 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2878 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2879 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2880 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2881 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2882 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2883 | for (CellInfo ci : info) { |
| 2884 | if (ci instanceof CellInfoGsm) { |
| 2885 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2886 | } else if (ci instanceof CellInfoWcdma) { |
| 2887 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2888 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2889 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2890 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2891 | } |
| 2892 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2893 | private List<CellInfo> getCachedCellInfo() { |
| 2894 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2895 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2896 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2897 | if (info != null) cellInfos.addAll(info); |
| 2898 | } |
| 2899 | return cellInfos; |
| 2900 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2901 | |
| 2902 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2903 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2904 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2905 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2906 | |
| 2907 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2908 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2909 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2910 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2911 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2912 | .setCallingPid(Binder.getCallingPid()) |
| 2913 | .setCallingUid(Binder.getCallingUid()) |
| 2914 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2915 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2916 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2917 | .build()); |
| 2918 | switch (locationResult) { |
| 2919 | case DENIED_HARD: |
| 2920 | throw new SecurityException("Not allowed to access cell info"); |
| 2921 | case DENIED_SOFT: |
| 2922 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2923 | } |
| 2924 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2925 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2926 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2927 | return getCachedCellInfo(); |
| 2928 | } |
| 2929 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2930 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2931 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2932 | final long identity = Binder.clearCallingIdentity(); |
| 2933 | try { |
| 2934 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2935 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2936 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2937 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2938 | if (info != null) cellInfos.addAll(info); |
| 2939 | } |
| 2940 | return cellInfos; |
| 2941 | } finally { |
| 2942 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2943 | } |
| 2944 | } |
| 2945 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2946 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2947 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2948 | String callingFeatureId) { |
| 2949 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2950 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2951 | } |
| 2952 | |
| 2953 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2954 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2955 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2956 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2957 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2958 | } |
| 2959 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2960 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2961 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2962 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2963 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2964 | |
| 2965 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2966 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2967 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2968 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2969 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2970 | .setCallingPid(Binder.getCallingPid()) |
| 2971 | .setCallingUid(Binder.getCallingUid()) |
| 2972 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2973 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2974 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2975 | .build()); |
| 2976 | switch (locationResult) { |
| 2977 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2978 | if (TelephonyPermissions |
| 2979 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2980 | // Safetynet logging for b/154934934 |
| 2981 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2982 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2983 | throw new SecurityException("Not allowed to access cell info"); |
| 2984 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2985 | if (TelephonyPermissions |
| 2986 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2987 | // Safetynet logging for b/154934934 |
| 2988 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2989 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2990 | try { |
| 2991 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2992 | } catch (RemoteException re) { |
| 2993 | // Drop without consequences |
| 2994 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2995 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2996 | } |
| 2997 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2998 | |
| 2999 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3000 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3001 | |
| 3002 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3003 | } |
| 3004 | |
| 3005 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3006 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3007 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3008 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3009 | |
| 3010 | final long identity = Binder.clearCallingIdentity(); |
| 3011 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3012 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3013 | } finally { |
| 3014 | Binder.restoreCallingIdentity(identity); |
| 3015 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3016 | } |
| 3017 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3018 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3019 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3020 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3021 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3022 | return null; |
| 3023 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3024 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3025 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3026 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3027 | return null; |
| 3028 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3029 | |
| 3030 | final long identity = Binder.clearCallingIdentity(); |
| 3031 | try { |
| 3032 | return phone.getImei(); |
| 3033 | } finally { |
| 3034 | Binder.restoreCallingIdentity(identity); |
| 3035 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3036 | } |
| 3037 | |
| 3038 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3039 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3040 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3041 | String tac = null; |
| 3042 | if (phone != null) { |
| 3043 | String imei = phone.getImei(); |
| 3044 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3045 | } |
| 3046 | return tac; |
| 3047 | } |
| 3048 | |
| 3049 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3050 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3051 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3052 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3053 | return null; |
| 3054 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3055 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3056 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3057 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3058 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3059 | return null; |
| 3060 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3061 | |
| 3062 | final long identity = Binder.clearCallingIdentity(); |
| 3063 | try { |
| 3064 | return phone.getMeid(); |
| 3065 | } finally { |
| 3066 | Binder.restoreCallingIdentity(identity); |
| 3067 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3068 | } |
| 3069 | |
| 3070 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3071 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3072 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3073 | String manufacturerCode = null; |
| 3074 | if (phone != null) { |
| 3075 | String meid = phone.getMeid(); |
| 3076 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3077 | } |
| 3078 | return manufacturerCode; |
| 3079 | } |
| 3080 | |
| 3081 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3082 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3083 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3084 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3085 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3086 | return null; |
| 3087 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3088 | int subId = phone.getSubId(); |
| 3089 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3090 | mApp, subId, callingPackage, callingFeatureId, |
| 3091 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3092 | return null; |
| 3093 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3094 | |
| 3095 | final long identity = Binder.clearCallingIdentity(); |
| 3096 | try { |
| 3097 | return phone.getDeviceSvn(); |
| 3098 | } finally { |
| 3099 | Binder.restoreCallingIdentity(identity); |
| 3100 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3101 | } |
| 3102 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3103 | @Override |
| 3104 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3105 | final long identity = Binder.clearCallingIdentity(); |
| 3106 | try { |
| 3107 | final Phone phone = getPhone(subId); |
| 3108 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3109 | } finally { |
| 3110 | Binder.restoreCallingIdentity(identity); |
| 3111 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3112 | } |
| 3113 | |
| 3114 | @Override |
| 3115 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3116 | final long identity = Binder.clearCallingIdentity(); |
| 3117 | try { |
| 3118 | final Phone phone = getPhone(subId); |
| 3119 | return phone == null ? null : phone.getCarrierName(); |
| 3120 | } finally { |
| 3121 | Binder.restoreCallingIdentity(identity); |
| 3122 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3123 | } |
| 3124 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3125 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3126 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3127 | final long identity = Binder.clearCallingIdentity(); |
| 3128 | try { |
| 3129 | final Phone phone = getPhone(subId); |
| 3130 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3131 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3132 | } finally { |
| 3133 | Binder.restoreCallingIdentity(identity); |
| 3134 | } |
| 3135 | } |
| 3136 | |
| 3137 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3138 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3139 | final long identity = Binder.clearCallingIdentity(); |
| 3140 | try { |
| 3141 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3142 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3143 | } finally { |
| 3144 | Binder.restoreCallingIdentity(identity); |
| 3145 | } |
| 3146 | } |
| 3147 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3148 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3149 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3150 | if (!isSubscriptionMccMnc) { |
| 3151 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3152 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3153 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3154 | if (phone == null) { |
| 3155 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3156 | } |
| 3157 | final long identity = Binder.clearCallingIdentity(); |
| 3158 | try { |
| 3159 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3160 | } finally { |
| 3161 | Binder.restoreCallingIdentity(identity); |
| 3162 | } |
| 3163 | } |
| 3164 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3165 | // |
| 3166 | // Internal helper methods. |
| 3167 | // |
| 3168 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3169 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3170 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3171 | * |
| 3172 | * @throws SecurityException if the caller does not have the required permission |
| 3173 | */ |
| 3174 | private void enforceModifyPermission() { |
| 3175 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3176 | } |
| 3177 | |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3178 | /** |
| 3179 | * Make sure the caller is system. |
| 3180 | * |
| 3181 | * @throws SecurityException if the caller is not system. |
| 3182 | */ |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 3183 | private static void enforceSystemCaller() { |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3184 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 3185 | throw new SecurityException("Caller must be system"); |
| 3186 | } |
| 3187 | } |
| 3188 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3189 | private void enforceActiveEmergencySessionPermission() { |
| 3190 | mApp.enforceCallingOrSelfPermission( |
| 3191 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3192 | } |
| 3193 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3194 | /** |
| 3195 | * Make sure the caller has the CALL_PHONE permission. |
| 3196 | * |
| 3197 | * @throws SecurityException if the caller does not have the required permission |
| 3198 | */ |
| 3199 | private void enforceCallPermission() { |
| 3200 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3201 | } |
| 3202 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3203 | private void enforceSettingsPermission() { |
| 3204 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3205 | } |
| 3206 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3207 | private void enforceRebootPermission() { |
| 3208 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3209 | } |
| 3210 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3211 | private String createTelUrl(String number) { |
| 3212 | if (TextUtils.isEmpty(number)) { |
| 3213 | return null; |
| 3214 | } |
| 3215 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3216 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3217 | } |
| 3218 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3219 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3220 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3221 | } |
| 3222 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3223 | private static void logv(String msg) { |
| 3224 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3225 | } |
| 3226 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3227 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3228 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3229 | } |
| 3230 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3231 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3232 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3233 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3234 | } |
| 3235 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3236 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3237 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3238 | final long identity = Binder.clearCallingIdentity(); |
| 3239 | try { |
| 3240 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3241 | if (phone == null) { |
| 3242 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3243 | } else { |
| 3244 | return phone.getPhoneType(); |
| 3245 | } |
| 3246 | } finally { |
| 3247 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3248 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3249 | } |
| 3250 | |
| 3251 | /** |
| 3252 | * Returns the CDMA ERI icon index to display |
| 3253 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3254 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3255 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3256 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3257 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3258 | } |
| 3259 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3260 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3261 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3262 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3263 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3264 | mApp, subId, callingPackage, callingFeatureId, |
| 3265 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3266 | return -1; |
| 3267 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3268 | |
| 3269 | final long identity = Binder.clearCallingIdentity(); |
| 3270 | try { |
| 3271 | final Phone phone = getPhone(subId); |
| 3272 | if (phone != null) { |
| 3273 | return phone.getCdmaEriIconIndex(); |
| 3274 | } else { |
| 3275 | return -1; |
| 3276 | } |
| 3277 | } finally { |
| 3278 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3279 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3280 | } |
| 3281 | |
| 3282 | /** |
| 3283 | * Returns the CDMA ERI icon mode, |
| 3284 | * 0 - ON |
| 3285 | * 1 - FLASHING |
| 3286 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3287 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3288 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3289 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3290 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3291 | } |
| 3292 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3293 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3294 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3295 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3296 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3297 | mApp, subId, callingPackage, callingFeatureId, |
| 3298 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3299 | return -1; |
| 3300 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3301 | |
| 3302 | final long identity = Binder.clearCallingIdentity(); |
| 3303 | try { |
| 3304 | final Phone phone = getPhone(subId); |
| 3305 | if (phone != null) { |
| 3306 | return phone.getCdmaEriIconMode(); |
| 3307 | } else { |
| 3308 | return -1; |
| 3309 | } |
| 3310 | } finally { |
| 3311 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3312 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3313 | } |
| 3314 | |
| 3315 | /** |
| 3316 | * Returns the CDMA ERI text, |
| 3317 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3318 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3319 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3320 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3321 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3322 | } |
| 3323 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3324 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3325 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3326 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3327 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3328 | mApp, subId, callingPackage, callingFeatureId, |
| 3329 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3330 | return null; |
| 3331 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3332 | |
| 3333 | final long identity = Binder.clearCallingIdentity(); |
| 3334 | try { |
| 3335 | final Phone phone = getPhone(subId); |
| 3336 | if (phone != null) { |
| 3337 | return phone.getCdmaEriText(); |
| 3338 | } else { |
| 3339 | return null; |
| 3340 | } |
| 3341 | } finally { |
| 3342 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3343 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3344 | } |
| 3345 | |
| 3346 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3347 | * Returns the CDMA MDN. |
| 3348 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3349 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3350 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3351 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3352 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3353 | |
| 3354 | final long identity = Binder.clearCallingIdentity(); |
| 3355 | try { |
| 3356 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3357 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3358 | return phone.getLine1Number(); |
| 3359 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3360 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3361 | return null; |
| 3362 | } |
| 3363 | } finally { |
| 3364 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3365 | } |
| 3366 | } |
| 3367 | |
| 3368 | /** |
| 3369 | * Returns the CDMA MIN. |
| 3370 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3371 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3372 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3373 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3374 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3375 | |
| 3376 | final long identity = Binder.clearCallingIdentity(); |
| 3377 | try { |
| 3378 | final Phone phone = getPhone(subId); |
| 3379 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3380 | return phone.getCdmaMin(); |
| 3381 | } else { |
| 3382 | return null; |
| 3383 | } |
| 3384 | } finally { |
| 3385 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3386 | } |
| 3387 | } |
| 3388 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3389 | @Override |
| 3390 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3391 | INumberVerificationCallback callback, String callingPackage) { |
| 3392 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3393 | != PERMISSION_GRANTED) { |
| 3394 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3395 | } |
| 3396 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3397 | |
| 3398 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3399 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3400 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3401 | + "calling package: " + callingPackage |
| 3402 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3403 | } |
| 3404 | |
| 3405 | if (range == null) { |
| 3406 | throw new NullPointerException("Range must be non-null"); |
| 3407 | } |
| 3408 | |
| 3409 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3410 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3411 | |
| 3412 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3413 | } |
| 3414 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3415 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3416 | * Returns true if CDMA provisioning needs to run. |
| 3417 | */ |
| 3418 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3419 | final long identity = Binder.clearCallingIdentity(); |
| 3420 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3421 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3422 | } finally { |
| 3423 | Binder.restoreCallingIdentity(identity); |
| 3424 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3425 | } |
| 3426 | |
| 3427 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3428 | * Sets the voice mail number of a given subId. |
| 3429 | */ |
| 3430 | @Override |
| 3431 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3432 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3433 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3434 | |
| 3435 | final long identity = Binder.clearCallingIdentity(); |
| 3436 | try { |
| 3437 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3438 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3439 | return success; |
| 3440 | } finally { |
| 3441 | Binder.restoreCallingIdentity(identity); |
| 3442 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3443 | } |
| 3444 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3445 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3446 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3447 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3448 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3449 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3450 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3451 | throw new SecurityException("caller must be system dialer"); |
| 3452 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3453 | |
| 3454 | final long identity = Binder.clearCallingIdentity(); |
| 3455 | try { |
| 3456 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3457 | if (phoneAccountHandle == null) { |
| 3458 | return null; |
| 3459 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3460 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3461 | } finally { |
| 3462 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3463 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3464 | } |
| 3465 | |
| 3466 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3467 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3468 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3469 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3470 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3471 | mApp, subId, callingPackage, callingFeatureId, |
| 3472 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3473 | return null; |
| 3474 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3475 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3476 | final long identity = Binder.clearCallingIdentity(); |
| 3477 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3478 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3479 | } finally { |
| 3480 | Binder.restoreCallingIdentity(identity); |
| 3481 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3482 | } |
| 3483 | |
| 3484 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3485 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3486 | VisualVoicemailSmsFilterSettings settings) { |
| 3487 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3488 | |
| 3489 | final long identity = Binder.clearCallingIdentity(); |
| 3490 | try { |
| 3491 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3492 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3493 | } finally { |
| 3494 | Binder.restoreCallingIdentity(identity); |
| 3495 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3496 | } |
| 3497 | |
| 3498 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3499 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3500 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3501 | |
| 3502 | final long identity = Binder.clearCallingIdentity(); |
| 3503 | try { |
| 3504 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3505 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3506 | } finally { |
| 3507 | Binder.restoreCallingIdentity(identity); |
| 3508 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3509 | } |
| 3510 | |
| 3511 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3512 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3513 | String callingPackage, int subId) { |
| 3514 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3515 | |
| 3516 | final long identity = Binder.clearCallingIdentity(); |
| 3517 | try { |
| 3518 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3519 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3520 | } finally { |
| 3521 | Binder.restoreCallingIdentity(identity); |
| 3522 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3523 | } |
| 3524 | |
| 3525 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3526 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3527 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3528 | |
| 3529 | final long identity = Binder.clearCallingIdentity(); |
| 3530 | try { |
| 3531 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3532 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3533 | } finally { |
| 3534 | Binder.restoreCallingIdentity(identity); |
| 3535 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3536 | } |
| 3537 | |
| 3538 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3539 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3540 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3541 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3542 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3543 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3544 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3545 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3546 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3547 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3548 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3549 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3550 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3551 | * Sets the voice activation state of a given subId. |
| 3552 | */ |
| 3553 | @Override |
| 3554 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3555 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3556 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3557 | |
| 3558 | final long identity = Binder.clearCallingIdentity(); |
| 3559 | try { |
| 3560 | final Phone phone = getPhone(subId); |
| 3561 | if (phone != null) { |
| 3562 | phone.setVoiceActivationState(activationState); |
| 3563 | } else { |
| 3564 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3565 | } |
| 3566 | } finally { |
| 3567 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3568 | } |
| 3569 | } |
| 3570 | |
| 3571 | /** |
| 3572 | * Sets the data activation state of a given subId. |
| 3573 | */ |
| 3574 | @Override |
| 3575 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3576 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3577 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3578 | |
| 3579 | final long identity = Binder.clearCallingIdentity(); |
| 3580 | try { |
| 3581 | final Phone phone = getPhone(subId); |
| 3582 | if (phone != null) { |
| 3583 | phone.setDataActivationState(activationState); |
| 3584 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3585 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3586 | } |
| 3587 | } finally { |
| 3588 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3589 | } |
| 3590 | } |
| 3591 | |
| 3592 | /** |
| 3593 | * Returns the voice activation state of a given subId. |
| 3594 | */ |
| 3595 | @Override |
| 3596 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3597 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3598 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3599 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3600 | final long identity = Binder.clearCallingIdentity(); |
| 3601 | try { |
| 3602 | if (phone != null) { |
| 3603 | return phone.getVoiceActivationState(); |
| 3604 | } else { |
| 3605 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3606 | } |
| 3607 | } finally { |
| 3608 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3609 | } |
| 3610 | } |
| 3611 | |
| 3612 | /** |
| 3613 | * Returns the data activation state of a given subId. |
| 3614 | */ |
| 3615 | @Override |
| 3616 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3617 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3618 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3619 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3620 | final long identity = Binder.clearCallingIdentity(); |
| 3621 | try { |
| 3622 | if (phone != null) { |
| 3623 | return phone.getDataActivationState(); |
| 3624 | } else { |
| 3625 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3626 | } |
| 3627 | } finally { |
| 3628 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3629 | } |
| 3630 | } |
| 3631 | |
| 3632 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3633 | * Returns the unread count of voicemails for a subId |
| 3634 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3635 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3636 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3637 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3638 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3639 | mApp, subId, callingPackage, callingFeatureId, |
| 3640 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3641 | return 0; |
| 3642 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3643 | final long identity = Binder.clearCallingIdentity(); |
| 3644 | try { |
| 3645 | final Phone phone = getPhone(subId); |
| 3646 | if (phone != null) { |
| 3647 | return phone.getVoiceMessageCount(); |
| 3648 | } else { |
| 3649 | return 0; |
| 3650 | } |
| 3651 | } finally { |
| 3652 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3653 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3654 | } |
| 3655 | |
| 3656 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3657 | * returns true, if the device is in a state where both voice and data |
| 3658 | * are supported simultaneously. This can change based on location or network condition. |
| 3659 | */ |
| 3660 | @Override |
| 3661 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3662 | final long identity = Binder.clearCallingIdentity(); |
| 3663 | try { |
| 3664 | final Phone phone = getPhone(subId); |
| 3665 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3666 | } finally { |
| 3667 | Binder.restoreCallingIdentity(identity); |
| 3668 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3669 | } |
| 3670 | |
| 3671 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3672 | * Send the dialer code if called from the current default dialer or the caller has |
| 3673 | * carrier privilege. |
| 3674 | * @param inputCode The dialer code to send |
| 3675 | */ |
| 3676 | @Override |
| 3677 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3678 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3679 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3680 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3681 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3682 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3683 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3684 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3685 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3686 | |
| 3687 | final long identity = Binder.clearCallingIdentity(); |
| 3688 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3689 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3690 | } finally { |
| 3691 | Binder.restoreCallingIdentity(identity); |
| 3692 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3693 | } |
| 3694 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3695 | @Override |
| 3696 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3697 | TelephonyPermissions |
| 3698 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3699 | mApp, subId, "getNetworkSelectionMode"); |
| 3700 | final long identity = Binder.clearCallingIdentity(); |
| 3701 | try { |
| 3702 | if (!isActiveSubscription(subId)) { |
| 3703 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3704 | } |
| 3705 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3706 | } finally { |
| 3707 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3708 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3709 | } |
| 3710 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3711 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3712 | public boolean isInEmergencySmsMode() { |
| 3713 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3714 | final long identity = Binder.clearCallingIdentity(); |
| 3715 | try { |
| 3716 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3717 | if (phone.isInEmergencySmsMode()) { |
| 3718 | return true; |
| 3719 | } |
| 3720 | } |
| 3721 | } finally { |
| 3722 | Binder.restoreCallingIdentity(identity); |
| 3723 | } |
| 3724 | return false; |
| 3725 | } |
| 3726 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3727 | /** |
| 3728 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3729 | * @param subId The subscription to use to check the configuration. |
| 3730 | * @param c The callback that will be used to send the result. |
| 3731 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3732 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3733 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3734 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3735 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3736 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3737 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3738 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3739 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3740 | "IMS not available on device."); |
| 3741 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3742 | final long token = Binder.clearCallingIdentity(); |
| 3743 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3744 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3745 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3746 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3747 | } catch (ImsException e) { |
| 3748 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3749 | } finally { |
| 3750 | Binder.restoreCallingIdentity(token); |
| 3751 | } |
| 3752 | } |
| 3753 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3754 | /** |
| 3755 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3756 | * @param subId The subscription to use to check the configuration. |
| 3757 | * @param c The callback that will be used to send the result. |
| 3758 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3759 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3760 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3761 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3762 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3763 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3764 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3765 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3766 | final long token = Binder.clearCallingIdentity(); |
| 3767 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3768 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3769 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3770 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3771 | } catch (ImsException e) { |
| 3772 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3773 | + "is inactive, ignoring unregister."); |
| 3774 | // If the subscription is no longer active, just return, since the callback |
| 3775 | // will already have been removed internally. |
| 3776 | } finally { |
| 3777 | Binder.restoreCallingIdentity(token); |
| 3778 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3779 | } |
| 3780 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3781 | /** |
| 3782 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3783 | */ |
| 3784 | @Override |
| 3785 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3786 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3787 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3788 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3789 | "IMS not available on device."); |
| 3790 | } |
| 3791 | final long token = Binder.clearCallingIdentity(); |
| 3792 | try { |
| 3793 | Phone phone = getPhone(subId); |
| 3794 | if (phone == null) { |
| 3795 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3796 | + subId + "'"); |
| 3797 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3798 | } |
| 3799 | phone.getImsRegistrationState(regState -> { |
| 3800 | try { |
| 3801 | consumer.accept((regState == null) |
| 3802 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3803 | } catch (RemoteException e) { |
| 3804 | // Ignore if the remote process is no longer available to call back. |
| 3805 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3806 | } |
| 3807 | }); |
| 3808 | } finally { |
| 3809 | Binder.restoreCallingIdentity(token); |
| 3810 | } |
| 3811 | } |
| 3812 | |
| 3813 | /** |
| 3814 | * Get the transport type for the IMS service registration state. |
| 3815 | */ |
| 3816 | @Override |
| 3817 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3818 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3819 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3820 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3821 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3822 | "IMS not available on device."); |
| 3823 | } |
| 3824 | final long token = Binder.clearCallingIdentity(); |
| 3825 | try { |
| 3826 | Phone phone = getPhone(subId); |
| 3827 | if (phone == null) { |
| 3828 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3829 | + subId + "'"); |
| 3830 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3831 | } |
| 3832 | phone.getImsRegistrationTech(regTech -> { |
| 3833 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3834 | int regTechConverted = (regTech == null) |
| 3835 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3836 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3837 | regTechConverted); |
| 3838 | try { |
| 3839 | consumer.accept(regTechConverted); |
| 3840 | } catch (RemoteException e) { |
| 3841 | // Ignore if the remote process is no longer available to call back. |
| 3842 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3843 | } |
| 3844 | }); |
| 3845 | } finally { |
| 3846 | Binder.restoreCallingIdentity(token); |
| 3847 | } |
| 3848 | } |
| 3849 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3850 | /** |
| 3851 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3852 | * @param subId The subscription to use to check the configuration. |
| 3853 | * @param c The callback that will be used to send the result. |
| 3854 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3855 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3856 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3857 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3858 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3859 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3860 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3861 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3862 | "IMS not available on device."); |
| 3863 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3864 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3865 | final long token = Binder.clearCallingIdentity(); |
| 3866 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3867 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3868 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3869 | } catch (ImsException e) { |
| 3870 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3871 | } finally { |
| 3872 | Binder.restoreCallingIdentity(token); |
| 3873 | } |
| 3874 | } |
| 3875 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3876 | /** |
| 3877 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3878 | * @param subId The subscription to use to check the configuration. |
| 3879 | * @param c The callback that will be used to send the result. |
| 3880 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3881 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3882 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3883 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3884 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3885 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3886 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3887 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3888 | |
| 3889 | final long token = Binder.clearCallingIdentity(); |
| 3890 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3891 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3892 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3893 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3894 | } catch (ImsException e) { |
| 3895 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3896 | + "is inactive, ignoring unregister."); |
| 3897 | // If the subscription is no longer active, just return, since the callback |
| 3898 | // will already have been removed internally. |
| 3899 | } finally { |
| 3900 | Binder.restoreCallingIdentity(token); |
| 3901 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3902 | } |
| 3903 | |
| 3904 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3905 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3906 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3907 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3908 | final long token = Binder.clearCallingIdentity(); |
| 3909 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3910 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3911 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3912 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3913 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3914 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3915 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3916 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3917 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3918 | } finally { |
| 3919 | Binder.restoreCallingIdentity(token); |
| 3920 | } |
| 3921 | } |
| 3922 | |
| 3923 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3924 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3925 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3926 | final long token = Binder.clearCallingIdentity(); |
| 3927 | try { |
| 3928 | Phone phone = getPhone(subId); |
| 3929 | if (phone == null) return false; |
| 3930 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3931 | } catch (com.android.ims.ImsException e) { |
| 3932 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3933 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3934 | } finally { |
| 3935 | Binder.restoreCallingIdentity(token); |
| 3936 | } |
| 3937 | } |
| 3938 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3939 | /** |
| 3940 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3941 | * subscription. |
| 3942 | * @param subId The subscription to use to check the configuration. |
| 3943 | * @param callback The callback that will be used to send the result. |
| 3944 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3945 | * @param transportType The transport type of the MmTelFeature capability. |
| 3946 | */ |
| 3947 | @Override |
| 3948 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3949 | int transportType) { |
| 3950 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3951 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3952 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3953 | "IMS not available on device."); |
| 3954 | } |
| 3955 | final long token = Binder.clearCallingIdentity(); |
| 3956 | try { |
| 3957 | int slotId = getSlotIndex(subId); |
| 3958 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3959 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3960 | + subId + "'"); |
| 3961 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3962 | } |
| 3963 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3964 | transportType, aBoolean -> { |
| 3965 | try { |
| 3966 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3967 | } catch (RemoteException e) { |
| 3968 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3969 | + "running. Ignore"); |
| 3970 | } |
| 3971 | }); |
| 3972 | } finally { |
| 3973 | Binder.restoreCallingIdentity(token); |
| 3974 | } |
| 3975 | } |
| 3976 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3977 | /** |
| 3978 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3979 | * @param subId The subscription to use to check the configuration. |
| 3980 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3981 | @Override |
| 3982 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3983 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3984 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3985 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3986 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3987 | final long token = Binder.clearCallingIdentity(); |
| 3988 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3989 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3990 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3991 | } catch (ImsException e) { |
| 3992 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3993 | } finally { |
| 3994 | Binder.restoreCallingIdentity(token); |
| 3995 | } |
| 3996 | } |
| 3997 | |
| 3998 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3999 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4000 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4001 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4002 | final long identity = Binder.clearCallingIdentity(); |
| 4003 | try { |
| 4004 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4005 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4006 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4007 | } catch (ImsException e) { |
| 4008 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4009 | } finally { |
| 4010 | Binder.restoreCallingIdentity(identity); |
| 4011 | } |
| 4012 | } |
| 4013 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4014 | /** |
| 4015 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4016 | * @param subId The subscription to use to check the configuration. |
| 4017 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4018 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4019 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4020 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4021 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4022 | final long identity = Binder.clearCallingIdentity(); |
| 4023 | try { |
| 4024 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4025 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 4026 | } catch (ImsException e) { |
| 4027 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4028 | } finally { |
| 4029 | Binder.restoreCallingIdentity(identity); |
| 4030 | } |
| 4031 | } |
| 4032 | |
| 4033 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4034 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4035 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4036 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4037 | final long identity = Binder.clearCallingIdentity(); |
| 4038 | try { |
| 4039 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4040 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4041 | } catch (ImsException e) { |
| 4042 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4043 | } finally { |
| 4044 | Binder.restoreCallingIdentity(identity); |
| 4045 | } |
| 4046 | } |
| 4047 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4048 | /** |
| 4049 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4050 | * @param subId The subscription to use to check the configuration. |
| 4051 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4052 | @Override |
| 4053 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4054 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4055 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4056 | final long identity = Binder.clearCallingIdentity(); |
| 4057 | try { |
| 4058 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4059 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4060 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4061 | } catch (ImsException e) { |
| 4062 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4063 | } finally { |
| 4064 | Binder.restoreCallingIdentity(identity); |
| 4065 | } |
| 4066 | } |
| 4067 | |
| 4068 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4069 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4070 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4071 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4072 | final long identity = Binder.clearCallingIdentity(); |
| 4073 | try { |
| 4074 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4075 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4076 | } catch (ImsException e) { |
| 4077 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4078 | } finally { |
| 4079 | Binder.restoreCallingIdentity(identity); |
| 4080 | } |
| 4081 | } |
| 4082 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4083 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4084 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4085 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4086 | * @param subId The subscription to use to check the configuration. |
| 4087 | */ |
| 4088 | @Override |
| 4089 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
| 4090 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4091 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4092 | final long identity = Binder.clearCallingIdentity(); |
| 4093 | try { |
| 4094 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4095 | return ImsManager.getInstance(mApp, |
| 4096 | getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser(); |
| 4097 | } catch (ImsException e) { |
| 4098 | throw new ServiceSpecificException(e.getCode()); |
| 4099 | } finally { |
| 4100 | Binder.restoreCallingIdentity(identity); |
| 4101 | } |
| 4102 | } |
| 4103 | |
| 4104 | /** |
| 4105 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4106 | * Requires MODIFY_PHONE_STATE permission. |
| 4107 | * @param subId The subscription to use to check the configuration. |
| 4108 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4109 | * false otherwise |
| 4110 | */ |
| 4111 | @Override |
| 4112 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4113 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4114 | "setCrossSimCallingEnabled"); |
| 4115 | final long identity = Binder.clearCallingIdentity(); |
| 4116 | try { |
| 4117 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4118 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 4119 | .setCrossSimCallingEnabled(isEnabled); |
| 4120 | } catch (ImsException e) { |
| 4121 | throw new ServiceSpecificException(e.getCode()); |
| 4122 | } finally { |
| 4123 | Binder.restoreCallingIdentity(identity); |
| 4124 | } |
| 4125 | } |
| 4126 | |
| 4127 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4128 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4129 | * @param subId The subscription to use to check the configuration. |
| 4130 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4131 | @Override |
| 4132 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4133 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4134 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4135 | final long identity = Binder.clearCallingIdentity(); |
| 4136 | try { |
| 4137 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4138 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4139 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4140 | } catch (ImsException e) { |
| 4141 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4142 | } finally { |
| 4143 | Binder.restoreCallingIdentity(identity); |
| 4144 | } |
| 4145 | } |
| 4146 | |
| 4147 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4148 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4149 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4150 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4151 | final long identity = Binder.clearCallingIdentity(); |
| 4152 | try { |
| 4153 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4154 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4155 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4156 | } catch (ImsException e) { |
| 4157 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4158 | } finally { |
| 4159 | Binder.restoreCallingIdentity(identity); |
| 4160 | } |
| 4161 | } |
| 4162 | |
| 4163 | @Override |
| 4164 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4165 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4166 | "setVoWiFiNonPersistent"); |
| 4167 | final long identity = Binder.clearCallingIdentity(); |
| 4168 | try { |
| 4169 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4170 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 4171 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4172 | } catch (ImsException e) { |
| 4173 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4174 | } finally { |
| 4175 | Binder.restoreCallingIdentity(identity); |
| 4176 | } |
| 4177 | } |
| 4178 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4179 | /** |
| 4180 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4181 | * @param subId The subscription to use to check the configuration. |
| 4182 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4183 | @Override |
| 4184 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4185 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4186 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4187 | final long identity = Binder.clearCallingIdentity(); |
| 4188 | try { |
| 4189 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4190 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4191 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4192 | } catch (ImsException e) { |
| 4193 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4194 | } finally { |
| 4195 | Binder.restoreCallingIdentity(identity); |
| 4196 | } |
| 4197 | } |
| 4198 | |
| 4199 | @Override |
| 4200 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4201 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4202 | "setVoWiFiModeSetting"); |
| 4203 | final long identity = Binder.clearCallingIdentity(); |
| 4204 | try { |
| 4205 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4206 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4207 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4208 | } catch (ImsException e) { |
| 4209 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4210 | } finally { |
| 4211 | Binder.restoreCallingIdentity(identity); |
| 4212 | } |
| 4213 | } |
| 4214 | |
| 4215 | @Override |
| 4216 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4217 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4218 | final long identity = Binder.clearCallingIdentity(); |
| 4219 | try { |
| 4220 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4221 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4222 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4223 | } catch (ImsException e) { |
| 4224 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4225 | } finally { |
| 4226 | Binder.restoreCallingIdentity(identity); |
| 4227 | } |
| 4228 | } |
| 4229 | |
| 4230 | @Override |
| 4231 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4232 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4233 | "setVoWiFiRoamingModeSetting"); |
| 4234 | final long identity = Binder.clearCallingIdentity(); |
| 4235 | try { |
| 4236 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4237 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4238 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4239 | } catch (ImsException e) { |
| 4240 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4241 | } finally { |
| 4242 | Binder.restoreCallingIdentity(identity); |
| 4243 | } |
| 4244 | } |
| 4245 | |
| 4246 | @Override |
| 4247 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4248 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4249 | "setRttCapabilityEnabled"); |
| 4250 | final long identity = Binder.clearCallingIdentity(); |
| 4251 | try { |
| 4252 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4253 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 4254 | } catch (ImsException e) { |
| 4255 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4256 | } finally { |
| 4257 | Binder.restoreCallingIdentity(identity); |
| 4258 | } |
| 4259 | } |
| 4260 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4261 | /** |
| 4262 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4263 | * @param subId The subscription to use to check the configuration. |
| 4264 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4265 | @Override |
| 4266 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4267 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4268 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4269 | final long identity = Binder.clearCallingIdentity(); |
| 4270 | try { |
| 4271 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4272 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4273 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4274 | } catch (ImsException e) { |
| 4275 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4276 | } finally { |
| 4277 | Binder.restoreCallingIdentity(identity); |
| 4278 | } |
| 4279 | } |
| 4280 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4281 | @Override |
| 4282 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4283 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4284 | final long identity = Binder.clearCallingIdentity(); |
| 4285 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4286 | if (!isImsAvailableOnDevice()) { |
| 4287 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4288 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4289 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4290 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4291 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4292 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4293 | } catch (ImsException e) { |
| 4294 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4295 | } finally { |
| 4296 | Binder.restoreCallingIdentity(identity); |
| 4297 | } |
| 4298 | } |
| 4299 | |
| 4300 | @Override |
| 4301 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4302 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4303 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4304 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4305 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4306 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4307 | try { |
| 4308 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4309 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4310 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4311 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4312 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4313 | + "is inactive, ignoring unregister."); |
| 4314 | // If the subscription is no longer active, just return, since the callback will already |
| 4315 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4316 | } finally { |
| 4317 | Binder.restoreCallingIdentity(identity); |
| 4318 | } |
| 4319 | } |
| 4320 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4321 | |
| 4322 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4323 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4324 | message); |
| 4325 | } |
| 4326 | |
| 4327 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4328 | boolean isMmtelCapability) { |
| 4329 | Phone phone = getPhone(subId); |
| 4330 | if (phone == null) { |
| 4331 | loge("phone instance null for subid " + subId); |
| 4332 | return false; |
| 4333 | } |
| 4334 | if (isMmtelCapability) { |
| 4335 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4336 | return false; |
| 4337 | } |
| 4338 | } else { |
| 4339 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4340 | return false; |
| 4341 | } |
| 4342 | } |
| 4343 | return true; |
| 4344 | } |
| 4345 | |
| 4346 | @Override |
| 4347 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4348 | boolean isProvisioned) { |
| 4349 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4350 | |
| 4351 | final long identity = Binder.clearCallingIdentity(); |
| 4352 | try { |
| 4353 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4354 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4355 | return; |
| 4356 | } |
| 4357 | |
| 4358 | // this capability requires provisioning, route to the correct API. |
| 4359 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4360 | switch (capability) { |
| 4361 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4362 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4363 | ims.setEabProvisioned(isProvisioned); |
| 4364 | break; |
| 4365 | default: { |
| 4366 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4367 | + "rcs capability '" + capability + "', which does not require " |
| 4368 | + "provisioning."); |
| 4369 | } |
| 4370 | } |
| 4371 | } finally { |
| 4372 | Binder.restoreCallingIdentity(identity); |
| 4373 | } |
| 4374 | |
| 4375 | } |
| 4376 | |
| 4377 | |
| 4378 | @Override |
| 4379 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4380 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4381 | final long identity = Binder.clearCallingIdentity(); |
| 4382 | try { |
| 4383 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4384 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4385 | return true; |
| 4386 | } |
| 4387 | |
| 4388 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4389 | switch (capability) { |
| 4390 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4391 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4392 | return ims.isEabProvisionedOnDevice(); |
| 4393 | |
| 4394 | default: { |
| 4395 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4396 | + "capability '" + capability + "', which does not require " |
| 4397 | + "provisioning."); |
| 4398 | } |
| 4399 | } |
| 4400 | |
| 4401 | } finally { |
| 4402 | Binder.restoreCallingIdentity(identity); |
| 4403 | } |
| 4404 | } |
| 4405 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4406 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4407 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4408 | boolean isProvisioned) { |
| 4409 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4410 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4411 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4412 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4413 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4414 | final long identity = Binder.clearCallingIdentity(); |
| 4415 | try { |
| 4416 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4417 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4418 | return; |
| 4419 | } |
| 4420 | |
| 4421 | // this capability requires provisioning, route to the correct API. |
| 4422 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4423 | switch (capability) { |
| 4424 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4425 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4426 | ims.setVolteProvisioned(isProvisioned); |
| 4427 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4428 | ims.setWfcProvisioned(isProvisioned); |
| 4429 | } |
| 4430 | break; |
| 4431 | } |
| 4432 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4433 | // There is currently no difference in VT provisioning type. |
| 4434 | ims.setVtProvisioned(isProvisioned); |
| 4435 | break; |
| 4436 | } |
| 4437 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4438 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4439 | // change the capability of the feature instead if needed. |
| 4440 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4441 | == isProvisioned) { |
| 4442 | // No change in provisioning. |
| 4443 | return; |
| 4444 | } |
| 4445 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4446 | try { |
| 4447 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4448 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4449 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4450 | + ", Exception" + e.getMessage()); |
| 4451 | } |
| 4452 | break; |
| 4453 | } |
| 4454 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4455 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4456 | + "MmTel capability '" + capability + "', which does not require " |
| 4457 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4458 | } |
| 4459 | } |
| 4460 | |
| 4461 | } finally { |
| 4462 | Binder.restoreCallingIdentity(identity); |
| 4463 | } |
| 4464 | } |
| 4465 | |
| 4466 | @Override |
| 4467 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4468 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4469 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4470 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4471 | } |
| 4472 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4473 | final long identity = Binder.clearCallingIdentity(); |
| 4474 | try { |
| 4475 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4476 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4477 | return true; |
| 4478 | } |
| 4479 | |
| 4480 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4481 | switch (capability) { |
| 4482 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4483 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4484 | return ims.isVolteProvisionedOnDevice(); |
| 4485 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4486 | return ims.isWfcProvisionedOnDevice(); |
| 4487 | } |
| 4488 | // This should never happen, since we are checking tech above to make sure it |
| 4489 | // is either LTE or IWLAN. |
| 4490 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4491 | + "capability."); |
| 4492 | } |
| 4493 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4494 | // There is currently no difference in VT provisioning type. |
| 4495 | return ims.isVtProvisionedOnDevice(); |
| 4496 | } |
| 4497 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4498 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4499 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4500 | } |
| 4501 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4502 | throw new IllegalArgumentException( |
| 4503 | "Tried to get provisioning for MmTel capability '" + capability |
| 4504 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4505 | } |
| 4506 | } |
| 4507 | |
| 4508 | } finally { |
| 4509 | Binder.restoreCallingIdentity(identity); |
| 4510 | } |
| 4511 | } |
| 4512 | |
| 4513 | @Override |
| 4514 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4515 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4516 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4517 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4518 | } |
| 4519 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4520 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4521 | return (provisionedBits & capability) > 0; |
| 4522 | } |
| 4523 | |
| 4524 | @Override |
| 4525 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4526 | boolean isProvisioned) { |
| 4527 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4528 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4529 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4530 | } |
| 4531 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4532 | "setProvisioningStatusForCapability"); |
| 4533 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4534 | // If the current provisioning status for capability already matches isProvisioned, |
| 4535 | // do nothing. |
| 4536 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4537 | return; |
| 4538 | } |
| 4539 | if (isProvisioned) { |
| 4540 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4541 | } else { |
| 4542 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4543 | } |
| 4544 | } |
| 4545 | |
| 4546 | /** |
| 4547 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4548 | * technology. The bitfield should mirror the bitfield defined by |
| 4549 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4550 | */ |
| 4551 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4552 | String key = getMmTelProvisioningKey(subId, tech); |
| 4553 | // Default is no capabilities are provisioned. |
| 4554 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4555 | } |
| 4556 | |
| 4557 | /** |
| 4558 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4559 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4560 | * technology specified. |
| 4561 | * |
| 4562 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4563 | */ |
| 4564 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4565 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4566 | String key = getMmTelProvisioningKey(subId, tech); |
| 4567 | editor.putInt(key, newField); |
| 4568 | editor.commit(); |
| 4569 | } |
| 4570 | |
| 4571 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4572 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4573 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4574 | } |
| 4575 | |
| 4576 | /** |
| 4577 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4578 | * carrier associated with the subscription id. |
| 4579 | */ |
| 4580 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4581 | int capability) { |
| 4582 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4583 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4584 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4585 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4586 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4587 | false); |
| 4588 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4589 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4590 | |
| 4591 | // First check to make sure that the capability requires provisioning. |
| 4592 | switch (capability) { |
| 4593 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4594 | // intentional fallthrough |
| 4595 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4596 | if (requireVoiceVtProvisioning) { |
| 4597 | // Voice and Video requires provisioning |
| 4598 | return true; |
| 4599 | } |
| 4600 | break; |
| 4601 | } |
| 4602 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4603 | if (requireUtProvisioning) { |
| 4604 | // UT requires provisioning |
| 4605 | return true; |
| 4606 | } |
| 4607 | break; |
| 4608 | } |
| 4609 | } |
| 4610 | return false; |
| 4611 | } |
| 4612 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4613 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4614 | int capability) { |
| 4615 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4616 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4617 | |
| 4618 | boolean requireRcsProvisioning = c.getBoolean( |
| 4619 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4620 | |
| 4621 | // First check to make sure that the capability requires provisioning. |
| 4622 | switch (capability) { |
| 4623 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4624 | // intentional fallthrough |
| 4625 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4626 | if (requireRcsProvisioning) { |
| 4627 | // OPTION or PRESENCE requires provisioning |
| 4628 | return true; |
| 4629 | } |
| 4630 | break; |
| 4631 | } |
| 4632 | } |
| 4633 | return false; |
| 4634 | } |
| 4635 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4636 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4637 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4638 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4639 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4640 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4641 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4642 | final long identity = Binder.clearCallingIdentity(); |
| 4643 | try { |
| 4644 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4645 | int slotId = getSlotIndex(subId); |
| 4646 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4647 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4648 | + subId + "' for key:" + key); |
| 4649 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4650 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4651 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4652 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4653 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4654 | + subId + "' for key:" + key); |
| 4655 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4656 | } finally { |
| 4657 | Binder.restoreCallingIdentity(identity); |
| 4658 | } |
| 4659 | } |
| 4660 | |
| 4661 | @Override |
| 4662 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4663 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4664 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4665 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4666 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4667 | final long identity = Binder.clearCallingIdentity(); |
| 4668 | try { |
| 4669 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4670 | int slotId = getSlotIndex(subId); |
| 4671 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4672 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4673 | + subId + "' for key:" + key); |
| 4674 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4675 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4676 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4677 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4678 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4679 | + subId + "' for key:" + key); |
| 4680 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4681 | } finally { |
| 4682 | Binder.restoreCallingIdentity(identity); |
| 4683 | } |
| 4684 | } |
| 4685 | |
| 4686 | @Override |
| 4687 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4688 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4689 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4690 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4691 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4692 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4693 | final long identity = Binder.clearCallingIdentity(); |
| 4694 | try { |
| 4695 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4696 | int slotId = getSlotIndex(subId); |
| 4697 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4698 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4699 | + subId + "' for key:" + key); |
| 4700 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4701 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4702 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4703 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4704 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4705 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4706 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4707 | } finally { |
| 4708 | Binder.restoreCallingIdentity(identity); |
| 4709 | } |
| 4710 | } |
| 4711 | |
| 4712 | @Override |
| 4713 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4714 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4715 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4716 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4717 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4718 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4719 | final long identity = Binder.clearCallingIdentity(); |
| 4720 | try { |
| 4721 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4722 | int slotId = getSlotIndex(subId); |
| 4723 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4724 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4725 | + subId + "' for key:" + key); |
| 4726 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4727 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4728 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4729 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4730 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4731 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4732 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4733 | } finally { |
| 4734 | Binder.restoreCallingIdentity(identity); |
| 4735 | } |
| 4736 | } |
| 4737 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4738 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4739 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4740 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4741 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4742 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4743 | } |
| 4744 | return slotId; |
| 4745 | } |
| 4746 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4747 | private int getSlotIndex(int subId) { |
| 4748 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4749 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4750 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4751 | } |
| 4752 | return slotId; |
| 4753 | } |
| 4754 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4755 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4756 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4757 | */ |
| 4758 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4759 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4760 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4761 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4762 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4763 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4764 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4765 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4766 | mApp, subId, callingPackage, callingFeatureId, |
| 4767 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4768 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4769 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4770 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4771 | final long identity = Binder.clearCallingIdentity(); |
| 4772 | try { |
| 4773 | final Phone phone = getPhone(subId); |
| 4774 | if (phone != null) { |
| 4775 | return phone.getServiceState().getDataNetworkType(); |
| 4776 | } else { |
| 4777 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4778 | } |
| 4779 | } finally { |
| 4780 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4781 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4782 | } |
| 4783 | |
| 4784 | /** |
| 4785 | * Returns the data network type |
| 4786 | */ |
| 4787 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4788 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4789 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4790 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4791 | } |
| 4792 | |
| 4793 | /** |
| 4794 | * Returns the data network type for a subId |
| 4795 | */ |
| 4796 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4797 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4798 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4799 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4800 | mApp, subId, callingPackage, callingFeatureId, |
| 4801 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4802 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4803 | } |
| 4804 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4805 | final long identity = Binder.clearCallingIdentity(); |
| 4806 | try { |
| 4807 | final Phone phone = getPhone(subId); |
| 4808 | if (phone != null) { |
| 4809 | return phone.getServiceState().getDataNetworkType(); |
| 4810 | } else { |
| 4811 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4812 | } |
| 4813 | } finally { |
| 4814 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4815 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4816 | } |
| 4817 | |
| 4818 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4819 | * Returns the Voice network type for a subId |
| 4820 | */ |
| 4821 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4822 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4823 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4824 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4825 | mApp, subId, callingPackage, callingFeatureId, |
| 4826 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4827 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4828 | } |
| 4829 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4830 | final long identity = Binder.clearCallingIdentity(); |
| 4831 | try { |
| 4832 | final Phone phone = getPhone(subId); |
| 4833 | if (phone != null) { |
| 4834 | return phone.getServiceState().getVoiceNetworkType(); |
| 4835 | } else { |
| 4836 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4837 | } |
| 4838 | } finally { |
| 4839 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4840 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4841 | } |
| 4842 | |
| 4843 | /** |
| 4844 | * @return true if a ICC card is present |
| 4845 | */ |
| 4846 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4847 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4848 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4849 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4850 | } |
| 4851 | |
| 4852 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4853 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4854 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4855 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4856 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4857 | final long identity = Binder.clearCallingIdentity(); |
| 4858 | try { |
| 4859 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4860 | if (phone != null) { |
| 4861 | return phone.getIccCard().hasIccCard(); |
| 4862 | } else { |
| 4863 | return false; |
| 4864 | } |
| 4865 | } finally { |
| 4866 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4867 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4868 | } |
| 4869 | |
| 4870 | /** |
| 4871 | * Return if the current radio is LTE on CDMA. This |
| 4872 | * is a tri-state return value as for a period of time |
| 4873 | * the mode may be unknown. |
| 4874 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4875 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4876 | * @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] | 4877 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4878 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4879 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4880 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4881 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4882 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4883 | } |
| 4884 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4885 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4886 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4887 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4888 | try { |
| 4889 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4890 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4891 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4892 | } |
| 4893 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4894 | final long identity = Binder.clearCallingIdentity(); |
| 4895 | try { |
| 4896 | final Phone phone = getPhone(subId); |
| 4897 | if (phone == null) { |
| 4898 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4899 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4900 | return TelephonyProperties.lte_on_cdma_device() |
| 4901 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4902 | } |
| 4903 | } finally { |
| 4904 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4905 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4906 | } |
| 4907 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4908 | /** |
| 4909 | * {@hide} |
| 4910 | * Returns Default subId, 0 in the case of single standby. |
| 4911 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4912 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4913 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4914 | } |
| 4915 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4916 | private int getSlotForDefaultSubscription() { |
| 4917 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4918 | } |
| 4919 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4920 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4921 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4922 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4923 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4924 | private boolean isActiveSubscription(int subId) { |
| 4925 | return mSubscriptionController.isActiveSubId(subId); |
| 4926 | } |
| 4927 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4928 | /** |
| 4929 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4930 | */ |
| 4931 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4932 | final long identity = Binder.clearCallingIdentity(); |
| 4933 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4934 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4935 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4936 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4937 | } finally { |
| 4938 | Binder.restoreCallingIdentity(identity); |
| 4939 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4940 | } |
| 4941 | |
| 4942 | /** |
| 4943 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4944 | */ |
| 4945 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4946 | final long identity = Binder.clearCallingIdentity(); |
| 4947 | try { |
| 4948 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4949 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4950 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4951 | } finally { |
| 4952 | Binder.restoreCallingIdentity(identity); |
| 4953 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4954 | } |
| 4955 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4956 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4957 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4958 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4959 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4960 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4961 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4962 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4963 | if (phoneId == -1) { |
| 4964 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4965 | + " does not correspond to an active phone"); |
| 4966 | } |
| 4967 | return PhoneFactory.getPhone(phoneId); |
| 4968 | } |
| 4969 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4970 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4971 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4972 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4973 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4974 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4975 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4976 | if (DBG) { |
| 4977 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4978 | } |
| 4979 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4980 | p2); |
| 4981 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4982 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4983 | |
| 4984 | @Override |
| 4985 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4986 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4987 | enforceModifyPermission(); |
| 4988 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4989 | if (DBG) { |
| 4990 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4991 | } |
| 4992 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4993 | callingPackage, aid, p2); |
| 4994 | } |
| 4995 | |
| 4996 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4997 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4998 | final long identity = Binder.clearCallingIdentity(); |
| 4999 | try { |
| 5000 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 5001 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5002 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5003 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5004 | if (bestComponent == null |
| 5005 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5006 | loge("The calling package is not allowed to access ISD-R."); |
| 5007 | throw new SecurityException( |
| 5008 | "The calling package is not allowed to access ISD-R."); |
| 5009 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5010 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5011 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5012 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5013 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 5014 | null /* workSource */); |
| 5015 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5016 | return response; |
| 5017 | } finally { |
| 5018 | Binder.restoreCallingIdentity(identity); |
| 5019 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5020 | } |
| 5021 | |
| 5022 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5023 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5024 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5025 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5026 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 5027 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 5028 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5029 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5030 | @Override |
| 5031 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 5032 | enforceModifyPermission(); |
| 5033 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 5034 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 5035 | channel); |
| 5036 | } |
| 5037 | |
| 5038 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5039 | final long identity = Binder.clearCallingIdentity(); |
| 5040 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5041 | if (channel < 0) { |
| 5042 | return false; |
| 5043 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5044 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 5045 | null /* workSource */); |
| 5046 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5047 | return success; |
| 5048 | } finally { |
| 5049 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5050 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5051 | } |
| 5052 | |
| 5053 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5054 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5055 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5056 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5057 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5058 | if (DBG) { |
| 5059 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5060 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5061 | + p3 + " data=" + data); |
| 5062 | } |
| 5063 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5064 | command, p1, p2, p3, data); |
| 5065 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5066 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5067 | @Override |
| 5068 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 5069 | int command, int p1, int p2, int p3, String data) { |
| 5070 | enforceModifyPermission(); |
| 5071 | if (DBG) { |
| 5072 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 5073 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5074 | + p3 + " data=" + data); |
| 5075 | } |
| 5076 | return iccTransmitApduLogicalChannelWithPermission( |
| 5077 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 5078 | data); |
| 5079 | } |
| 5080 | |
| 5081 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5082 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5083 | final long identity = Binder.clearCallingIdentity(); |
| 5084 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5085 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5086 | return ""; |
| 5087 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5088 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5089 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5090 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5091 | null /* workSource */); |
| 5092 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5093 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5094 | // Append the returned status code to the end of the response payload. |
| 5095 | String s = Integer.toHexString( |
| 5096 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5097 | if (response.payload != null) { |
| 5098 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5099 | } |
| 5100 | return s; |
| 5101 | } finally { |
| 5102 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5103 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5104 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5105 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5106 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5107 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5108 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5109 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5110 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5111 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5112 | if (DBG) { |
| 5113 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5114 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5115 | } |
| 5116 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5117 | cla, command, p1, p2, p3, data); |
| 5118 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5119 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5120 | @Override |
| 5121 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 5122 | int command, int p1, int p2, int p3, String data) { |
| 5123 | enforceModifyPermission(); |
| 5124 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5125 | if (DBG) { |
| 5126 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 5127 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 5128 | + " data=" + data); |
| 5129 | } |
| 5130 | |
| 5131 | return iccTransmitApduBasicChannelWithPermission( |
| 5132 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 5133 | p2, p3, data); |
| 5134 | } |
| 5135 | |
| 5136 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5137 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5138 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5139 | final long identity = Binder.clearCallingIdentity(); |
| 5140 | try { |
| 5141 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5142 | && TextUtils.equals(ISDR_AID, data)) { |
| 5143 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5144 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5145 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5146 | if (bestComponent == null |
| 5147 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5148 | loge("The calling package is not allowed to select ISD-R."); |
| 5149 | throw new SecurityException( |
| 5150 | "The calling package is not allowed to select ISD-R."); |
| 5151 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5152 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5153 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5154 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5155 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5156 | null /* workSource */); |
| 5157 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5158 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5159 | // Append the returned status code to the end of the response payload. |
| 5160 | String s = Integer.toHexString( |
| 5161 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5162 | if (response.payload != null) { |
| 5163 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5164 | } |
| 5165 | return s; |
| 5166 | } finally { |
| 5167 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5168 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5169 | } |
| 5170 | |
| 5171 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5172 | 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] | 5173 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5174 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5175 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5176 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5177 | final long identity = Binder.clearCallingIdentity(); |
| 5178 | try { |
| 5179 | if (DBG) { |
| 5180 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5181 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5182 | } |
| 5183 | |
| 5184 | IccIoResult response = |
| 5185 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5186 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5187 | subId); |
| 5188 | |
| 5189 | if (DBG) { |
| 5190 | log("Exchange SIM_IO [R]" + response); |
| 5191 | } |
| 5192 | |
| 5193 | byte[] result = null; |
| 5194 | int length = 2; |
| 5195 | if (response.payload != null) { |
| 5196 | length = 2 + response.payload.length; |
| 5197 | result = new byte[length]; |
| 5198 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5199 | } else { |
| 5200 | result = new byte[length]; |
| 5201 | } |
| 5202 | |
| 5203 | result[length - 1] = (byte) response.sw2; |
| 5204 | result[length - 2] = (byte) response.sw1; |
| 5205 | return result; |
| 5206 | } finally { |
| 5207 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5208 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5209 | } |
| 5210 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5211 | /** |
| 5212 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5213 | * on a particular subscription |
| 5214 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5215 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5216 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5217 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5218 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5219 | return null; |
| 5220 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5221 | |
| 5222 | final long identity = Binder.clearCallingIdentity(); |
| 5223 | try { |
| 5224 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5225 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5226 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5227 | return null; |
| 5228 | } |
| 5229 | Object response = sendRequest( |
| 5230 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5231 | if (response instanceof String[]) { |
| 5232 | return (String[]) response; |
| 5233 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5234 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5235 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5236 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5237 | } finally { |
| 5238 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5239 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5240 | } |
| 5241 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5242 | /** |
| 5243 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5244 | * subscription. |
| 5245 | * |
| 5246 | * @param subId the id of the subscription. |
| 5247 | * @param appType the uicc app type, must be USIM or SIM. |
| 5248 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5249 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5250 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5251 | * @return number of fplmns that is successfully written to the SIM. |
| 5252 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5253 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5254 | String callingFeatureId) { |
| 5255 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 5256 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5257 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 5258 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 5259 | } |
| 5260 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5261 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5262 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5263 | } |
| 5264 | if (fplmns == null) { |
| 5265 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5266 | } |
| 5267 | for (String fplmn : fplmns) { |
| 5268 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5269 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5270 | } |
| 5271 | } |
| 5272 | final long identity = Binder.clearCallingIdentity(); |
| 5273 | try { |
| 5274 | Object response = sendRequest( |
| 5275 | CMD_SET_FORBIDDEN_PLMNS, |
| 5276 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5277 | subId); |
| 5278 | return (int) response; |
| 5279 | } finally { |
| 5280 | Binder.restoreCallingIdentity(identity); |
| 5281 | } |
| 5282 | } |
| 5283 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5284 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5285 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5286 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5287 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5288 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5289 | final long identity = Binder.clearCallingIdentity(); |
| 5290 | try { |
| 5291 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5292 | if (response.payload == null) { |
| 5293 | return ""; |
| 5294 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5295 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5296 | // Append the returned status code to the end of the response payload. |
| 5297 | String s = Integer.toHexString( |
| 5298 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5299 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5300 | return s; |
| 5301 | } finally { |
| 5302 | Binder.restoreCallingIdentity(identity); |
| 5303 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5304 | } |
| 5305 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5306 | /** |
| 5307 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5308 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5309 | * |
| 5310 | * @param itemID the ID of the item to read |
| 5311 | * @return the NV item as a String, or null on error. |
| 5312 | */ |
| 5313 | @Override |
| 5314 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5315 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5316 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5317 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5318 | |
| 5319 | final long identity = Binder.clearCallingIdentity(); |
| 5320 | try { |
| 5321 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5322 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5323 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5324 | return value; |
| 5325 | } finally { |
| 5326 | Binder.restoreCallingIdentity(identity); |
| 5327 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5328 | } |
| 5329 | |
| 5330 | /** |
| 5331 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5332 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5333 | * |
| 5334 | * @param itemID the ID of the item to read |
| 5335 | * @param itemValue the value to write, as a String |
| 5336 | * @return true on success; false on any failure |
| 5337 | */ |
| 5338 | @Override |
| 5339 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5340 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5341 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5342 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5343 | |
| 5344 | final long identity = Binder.clearCallingIdentity(); |
| 5345 | try { |
| 5346 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5347 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5348 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5349 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5350 | return success; |
| 5351 | } finally { |
| 5352 | Binder.restoreCallingIdentity(identity); |
| 5353 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5354 | } |
| 5355 | |
| 5356 | /** |
| 5357 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5358 | * Used for device configuration by some CDMA operators. |
| 5359 | * |
| 5360 | * @param preferredRoamingList byte array containing the new PRL |
| 5361 | * @return true on success; false on any failure |
| 5362 | */ |
| 5363 | @Override |
| 5364 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5365 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5366 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5367 | |
| 5368 | final long identity = Binder.clearCallingIdentity(); |
| 5369 | try { |
| 5370 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5371 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5372 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5373 | return success; |
| 5374 | } finally { |
| 5375 | Binder.restoreCallingIdentity(identity); |
| 5376 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5377 | } |
| 5378 | |
| 5379 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5380 | * 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] | 5381 | * Used for device configuration by some CDMA operators. |
| 5382 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5383 | * @param slotIndex - device slot. |
| 5384 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5385 | * @return true on success; false on any failure |
| 5386 | */ |
| 5387 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5388 | public boolean resetModemConfig(int slotIndex) { |
| 5389 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5390 | if (phone != null) { |
| 5391 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5392 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5393 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5394 | final long identity = Binder.clearCallingIdentity(); |
| 5395 | try { |
| 5396 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5397 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5398 | return success; |
| 5399 | } finally { |
| 5400 | Binder.restoreCallingIdentity(identity); |
| 5401 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5402 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5403 | return false; |
| 5404 | } |
| 5405 | |
| 5406 | /** |
| 5407 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5408 | * |
| 5409 | * @param slotIndex - device slot. |
| 5410 | * |
| 5411 | * @return true on success; false on any failure |
| 5412 | */ |
| 5413 | @Override |
| 5414 | public boolean rebootModem(int slotIndex) { |
| 5415 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5416 | if (phone != null) { |
| 5417 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5418 | mApp, phone.getSubId(), "rebootModem"); |
| 5419 | |
| 5420 | final long identity = Binder.clearCallingIdentity(); |
| 5421 | try { |
| 5422 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5423 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5424 | return success; |
| 5425 | } finally { |
| 5426 | Binder.restoreCallingIdentity(identity); |
| 5427 | } |
| 5428 | } |
| 5429 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5430 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5431 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5432 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5433 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5434 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5435 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5436 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5437 | return new String[0]; |
| 5438 | } |
| 5439 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5440 | final long identity = Binder.clearCallingIdentity(); |
| 5441 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5442 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5443 | } finally { |
| 5444 | Binder.restoreCallingIdentity(identity); |
| 5445 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5446 | } |
| 5447 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5448 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5449 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5450 | * {@link #disableIms(int)}. |
| 5451 | * @param slotIndex device slot. |
| 5452 | */ |
| 5453 | public void resetIms(int slotIndex) { |
| 5454 | enforceModifyPermission(); |
| 5455 | |
| 5456 | final long identity = Binder.clearCallingIdentity(); |
| 5457 | try { |
| 5458 | if (mImsResolver == null) { |
| 5459 | // may happen if the does not support IMS. |
| 5460 | return; |
| 5461 | } |
| 5462 | mImsResolver.disableIms(slotIndex); |
| 5463 | mImsResolver.enableIms(slotIndex); |
| 5464 | } finally { |
| 5465 | Binder.restoreCallingIdentity(identity); |
| 5466 | } |
| 5467 | } |
| 5468 | |
| 5469 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5470 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5471 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5472 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5473 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5474 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5475 | |
| 5476 | final long identity = Binder.clearCallingIdentity(); |
| 5477 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5478 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5479 | // may happen if the device does not support IMS. |
| 5480 | return; |
| 5481 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5482 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5483 | } finally { |
| 5484 | Binder.restoreCallingIdentity(identity); |
| 5485 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5486 | } |
| 5487 | |
| 5488 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5489 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5490 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5491 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5492 | public void disableIms(int slotId) { |
| 5493 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5494 | |
| 5495 | final long identity = Binder.clearCallingIdentity(); |
| 5496 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5497 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5498 | // may happen if the device does not support IMS. |
| 5499 | return; |
| 5500 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5501 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5502 | } finally { |
| 5503 | Binder.restoreCallingIdentity(identity); |
| 5504 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5505 | } |
| 5506 | |
| 5507 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5508 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5509 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5510 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5511 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5512 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5513 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5514 | |
| 5515 | final long identity = Binder.clearCallingIdentity(); |
| 5516 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5517 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5518 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5519 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5520 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5521 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5522 | } finally { |
| 5523 | Binder.restoreCallingIdentity(identity); |
| 5524 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5525 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5526 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5527 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5528 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5529 | @Override |
| 5530 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5531 | enforceModifyPermission(); |
| 5532 | |
| 5533 | final long identity = Binder.clearCallingIdentity(); |
| 5534 | try { |
| 5535 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5536 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5537 | } finally { |
| 5538 | Binder.restoreCallingIdentity(identity); |
| 5539 | } |
| 5540 | } |
| 5541 | |
| 5542 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5543 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5544 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5545 | */ |
| 5546 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5547 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5548 | |
| 5549 | final long identity = Binder.clearCallingIdentity(); |
| 5550 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5551 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5552 | // may happen if the device does not support IMS. |
| 5553 | return null; |
| 5554 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5555 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5556 | } finally { |
| 5557 | Binder.restoreCallingIdentity(identity); |
| 5558 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5559 | } |
| 5560 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5561 | /** |
| 5562 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5563 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5564 | */ |
| 5565 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5566 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5567 | |
| 5568 | final long identity = Binder.clearCallingIdentity(); |
| 5569 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5570 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5571 | // may happen if the device does not support IMS. |
| 5572 | return null; |
| 5573 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5574 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5575 | } finally { |
| 5576 | Binder.restoreCallingIdentity(identity); |
| 5577 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5578 | } |
| 5579 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5580 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5581 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5582 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5583 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5584 | * @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] | 5585 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5586 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5587 | * @param packageName The name of the package that the current configuration will be replaced |
| 5588 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5589 | * @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] | 5590 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5591 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5592 | int[] featureTypes, String packageName) { |
| 5593 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5594 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5595 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5596 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5597 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5598 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5599 | final long identity = Binder.clearCallingIdentity(); |
| 5600 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5601 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5602 | // may happen if the device does not support IMS. |
| 5603 | return false; |
| 5604 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5605 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5606 | for (int featureType : featureTypes) { |
| 5607 | featureConfig.put(featureType, packageName); |
| 5608 | } |
| 5609 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5610 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5611 | } finally { |
| 5612 | Binder.restoreCallingIdentity(identity); |
| 5613 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5614 | } |
| 5615 | |
| 5616 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5617 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5618 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5619 | * |
| 5620 | * This should only be used for testing. |
| 5621 | * |
| 5622 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5623 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5624 | */ |
| 5625 | @Override |
| 5626 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5627 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5628 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5629 | "clearCarrierImsServiceOverride"); |
| 5630 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5631 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5632 | "clearCarrierImsServiceOverride"); |
| 5633 | |
| 5634 | final long identity = Binder.clearCallingIdentity(); |
| 5635 | try { |
| 5636 | if (mImsResolver == null) { |
| 5637 | // may happen if the device does not support IMS. |
| 5638 | return false; |
| 5639 | } |
| 5640 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5641 | } finally { |
| 5642 | Binder.restoreCallingIdentity(identity); |
| 5643 | } |
| 5644 | } |
| 5645 | |
| 5646 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5647 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5648 | * |
| 5649 | * @param slotId The slot that the ImsService is associated with. |
| 5650 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5651 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5652 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5653 | * @return the package name of the ImsService configuration. |
| 5654 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5655 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5656 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5657 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5658 | TelephonyPermissions |
| 5659 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5660 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5661 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5662 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5663 | final long identity = Binder.clearCallingIdentity(); |
| 5664 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5665 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5666 | // may happen if the device does not support IMS. |
| 5667 | return ""; |
| 5668 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5669 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5670 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5671 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5672 | } finally { |
| 5673 | Binder.restoreCallingIdentity(identity); |
| 5674 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5675 | } |
| 5676 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5677 | /** |
| 5678 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5679 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5680 | * @param callback A callback with an integer containing the |
| 5681 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5682 | */ |
| 5683 | @Override |
| 5684 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5685 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5686 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5687 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5688 | "IMS not available on device."); |
| 5689 | } |
| 5690 | final long token = Binder.clearCallingIdentity(); |
| 5691 | try { |
| 5692 | int slotId = getSlotIndex(subId); |
| 5693 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5694 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5695 | + subId + "'"); |
| 5696 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5697 | } |
| 5698 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5699 | try { |
| 5700 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5701 | } catch (RemoteException e) { |
| 5702 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5703 | + "Ignore"); |
| 5704 | } |
| 5705 | }); |
| 5706 | } finally { |
| 5707 | Binder.restoreCallingIdentity(token); |
| 5708 | } |
| 5709 | } |
| 5710 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5711 | /** |
| 5712 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5713 | */ |
| 5714 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5715 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5716 | |
| 5717 | final long identity = Binder.clearCallingIdentity(); |
| 5718 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5719 | // NOTE: Before S, this method only set the default phone. |
| 5720 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5721 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5722 | phone.setImsRegistrationState(registered); |
| 5723 | } |
| 5724 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5725 | } finally { |
| 5726 | Binder.restoreCallingIdentity(identity); |
| 5727 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5728 | } |
| 5729 | |
| 5730 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5731 | * Set the network selection mode to automatic. |
| 5732 | * |
| 5733 | */ |
| 5734 | @Override |
| 5735 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5736 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5737 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5738 | |
| 5739 | final long identity = Binder.clearCallingIdentity(); |
| 5740 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5741 | if (!isActiveSubscription(subId)) { |
| 5742 | return; |
| 5743 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5744 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 5745 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 5746 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5747 | } finally { |
| 5748 | Binder.restoreCallingIdentity(identity); |
| 5749 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5750 | } |
| 5751 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5752 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5753 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5754 | * |
| 5755 | * @param subId the id of the subscription. |
| 5756 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5757 | * the operator to attach to. |
| 5758 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5759 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5760 | * normal network selection next time. |
| 5761 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5762 | */ |
| 5763 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5764 | public boolean setNetworkSelectionModeManual( |
| 5765 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5766 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5767 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5768 | |
| 5769 | if (!isActiveSubscription(subId)) { |
| 5770 | return false; |
| 5771 | } |
| 5772 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5773 | final long identity = Binder.clearCallingIdentity(); |
| 5774 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5775 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5776 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5777 | if (DBG) { |
| 5778 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5779 | + " operator: " + operatorInfo); |
| 5780 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5781 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5782 | } finally { |
| 5783 | Binder.restoreCallingIdentity(identity); |
| 5784 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5785 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5786 | /** |
| 5787 | * Get the manual network selection |
| 5788 | * |
| 5789 | * @param subId the id of the subscription. |
| 5790 | * |
| 5791 | * @return the previously saved user selected PLMN |
| 5792 | */ |
| 5793 | @Override |
| 5794 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5795 | TelephonyPermissions |
| 5796 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5797 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5798 | |
| 5799 | final long identity = Binder.clearCallingIdentity(); |
| 5800 | try { |
| 5801 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5802 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5803 | } |
| 5804 | |
| 5805 | final Phone phone = getPhone(subId); |
| 5806 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5807 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5808 | } |
| 5809 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5810 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5811 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5812 | } finally { |
| 5813 | Binder.restoreCallingIdentity(identity); |
| 5814 | } |
| 5815 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5816 | |
| 5817 | /** |
| 5818 | * Scans for available networks. |
| 5819 | */ |
| 5820 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5821 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5822 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5823 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5824 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5825 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5826 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5827 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5828 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5829 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5830 | .setCallingPid(Binder.getCallingPid()) |
| 5831 | .setCallingUid(Binder.getCallingUid()) |
| 5832 | .setMethod("getCellNetworkScanResults") |
| 5833 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 5834 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5835 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5836 | .build()); |
| 5837 | switch (locationResult) { |
| 5838 | case DENIED_HARD: |
| 5839 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5840 | case DENIED_SOFT: |
| 5841 | return null; |
| 5842 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5843 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5844 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5845 | try { |
| 5846 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5847 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5848 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5849 | } finally { |
| 5850 | Binder.restoreCallingIdentity(identity); |
| 5851 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5852 | } |
| 5853 | |
| 5854 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5855 | * Get the call forwarding info, given the call forwarding reason. |
| 5856 | */ |
| 5857 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5858 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5859 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5860 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5861 | long identity = Binder.clearCallingIdentity(); |
| 5862 | try { |
| 5863 | if (DBG) { |
| 5864 | log("getCallForwarding: subId " + subId |
| 5865 | + " callForwardingReason" + callForwardingReason); |
| 5866 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5867 | |
| 5868 | Phone phone = getPhone(subId); |
| 5869 | if (phone == null) { |
| 5870 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5871 | callback.onError( |
| 5872 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5873 | } catch (RemoteException e) { |
| 5874 | // ignore |
| 5875 | } |
| 5876 | return; |
| 5877 | } |
| 5878 | |
| 5879 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 5880 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 5881 | @Override |
| 5882 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 5883 | try { |
| 5884 | callback.onCallForwardingInfoAvailable(info); |
| 5885 | } catch (RemoteException e) { |
| 5886 | // ignore |
| 5887 | } |
| 5888 | } |
| 5889 | |
| 5890 | @Override |
| 5891 | public void onError(int error) { |
| 5892 | try { |
| 5893 | callback.onError(error); |
| 5894 | } catch (RemoteException e) { |
| 5895 | // ignore |
| 5896 | } |
| 5897 | } |
| 5898 | }); |
| 5899 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5900 | } finally { |
| 5901 | Binder.restoreCallingIdentity(identity); |
| 5902 | } |
| 5903 | } |
| 5904 | |
| 5905 | /** |
| 5906 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5907 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5908 | */ |
| 5909 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5910 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 5911 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5912 | enforceModifyPermission(); |
| 5913 | long identity = Binder.clearCallingIdentity(); |
| 5914 | try { |
| 5915 | if (DBG) { |
| 5916 | log("setCallForwarding: subId " + subId |
| 5917 | + " callForwardingInfo" + callForwardingInfo); |
| 5918 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5919 | |
| 5920 | Phone phone = getPhone(subId); |
| 5921 | if (phone == null) { |
| 5922 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5923 | callback.accept( |
| 5924 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5925 | } catch (RemoteException e) { |
| 5926 | // ignore |
| 5927 | } |
| 5928 | return; |
| 5929 | } |
| 5930 | |
| 5931 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 5932 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5933 | |
| 5934 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5935 | } finally { |
| 5936 | Binder.restoreCallingIdentity(identity); |
| 5937 | } |
| 5938 | } |
| 5939 | |
| 5940 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5941 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5942 | */ |
| 5943 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5944 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5945 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5946 | long identity = Binder.clearCallingIdentity(); |
| 5947 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5948 | |
| 5949 | Phone phone = getPhone(subId); |
| 5950 | if (phone == null) { |
| 5951 | try { |
| 5952 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5953 | } catch (RemoteException e) { |
| 5954 | // ignore |
| 5955 | } |
| 5956 | return; |
| 5957 | } |
| 5958 | |
| 5959 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 5960 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5961 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5962 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5963 | } finally { |
| 5964 | Binder.restoreCallingIdentity(identity); |
| 5965 | } |
| 5966 | } |
| 5967 | |
| 5968 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5969 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5970 | */ |
| 5971 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5972 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5973 | enforceModifyPermission(); |
| 5974 | long identity = Binder.clearCallingIdentity(); |
| 5975 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5976 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 5977 | |
| 5978 | Phone phone = getPhone(subId); |
| 5979 | if (phone == null) { |
| 5980 | try { |
| 5981 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5982 | } catch (RemoteException e) { |
| 5983 | // ignore |
| 5984 | } |
| 5985 | return; |
| 5986 | } |
| 5987 | |
| 5988 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 5989 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5990 | |
| 5991 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5992 | } finally { |
| 5993 | Binder.restoreCallingIdentity(identity); |
| 5994 | } |
| 5995 | } |
| 5996 | |
| 5997 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5998 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5999 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6000 | * @param subId id of the subscription |
| 6001 | * @param request contains the radio access networks with bands/channels to scan |
| 6002 | * @param messenger callback messenger for scan results or errors |
| 6003 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6004 | * @return the id of the requested scan which can be used to stop the scan. |
| 6005 | */ |
| 6006 | @Override |
| 6007 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6008 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6009 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6010 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6011 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6012 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6013 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6014 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6015 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6016 | .setCallingPid(Binder.getCallingPid()) |
| 6017 | .setCallingUid(Binder.getCallingUid()) |
| 6018 | .setMethod("requestNetworkScan") |
| 6019 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
James.cf Lin | 1d4d739 | 2020-07-03 18:22:53 +0800 | [diff] [blame] | 6020 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6021 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6022 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6023 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6024 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6025 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6026 | if (e != null) { |
| 6027 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6028 | throw e; |
| 6029 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6030 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6031 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6032 | } |
| 6033 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6034 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6035 | int callingUid = Binder.getCallingUid(); |
| 6036 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6037 | final long identity = Binder.clearCallingIdentity(); |
| 6038 | try { |
| 6039 | return mNetworkScanRequestTracker.startNetworkScan( |
| 6040 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6041 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6042 | } finally { |
| 6043 | Binder.restoreCallingIdentity(identity); |
| 6044 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6045 | } |
| 6046 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6047 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6048 | NetworkScanRequest request, int subId, String callingPackage) { |
| 6049 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6050 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6051 | boolean hasNetworkScanPermission = |
| 6052 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6053 | == PERMISSION_GRANTED; |
| 6054 | |
| 6055 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6056 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6057 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6058 | } |
| 6059 | |
| 6060 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6061 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6062 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6063 | return new SecurityException("Specific channels must not be" |
| 6064 | + " scanned without location access."); |
| 6065 | } |
| 6066 | } |
| 6067 | } |
| 6068 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6069 | return null; |
| 6070 | } |
| 6071 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6072 | /** |
| 6073 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6074 | * |
| 6075 | * @param subId id of the subscription |
| 6076 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6077 | */ |
| 6078 | @Override |
| 6079 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6080 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6081 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6082 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6083 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6084 | final long identity = Binder.clearCallingIdentity(); |
| 6085 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6086 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6087 | } finally { |
| 6088 | Binder.restoreCallingIdentity(identity); |
| 6089 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6090 | } |
| 6091 | |
| 6092 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6093 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6094 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6095 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6096 | */ |
| 6097 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6098 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6099 | TelephonyPermissions |
| 6100 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6101 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6102 | |
| 6103 | final long identity = Binder.clearCallingIdentity(); |
| 6104 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6105 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6106 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6107 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6108 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6109 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6110 | } finally { |
| 6111 | Binder.restoreCallingIdentity(identity); |
| 6112 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6113 | } |
| 6114 | |
| 6115 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6116 | * Get the allowed network types for certain reason. |
| 6117 | * |
| 6118 | * @param subId the id of the subscription. |
| 6119 | * @param reason the reason the allowed network type change is taking place |
| 6120 | * @return the allowed network types. |
| 6121 | */ |
| 6122 | @Override |
| 6123 | public long getAllowedNetworkTypesForReason(int subId, |
| 6124 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
| 6125 | TelephonyPermissions |
| 6126 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6127 | mApp, subId, "getAllowedNetworkTypesForReason"); |
| 6128 | final long identity = Binder.clearCallingIdentity(); |
| 6129 | try { |
| 6130 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6131 | } finally { |
| 6132 | Binder.restoreCallingIdentity(identity); |
| 6133 | } |
| 6134 | } |
| 6135 | |
| 6136 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6137 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6138 | * @param subId subscription id of the sim card |
| 6139 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6140 | * This can be passed following states |
| 6141 | * <ol> |
| 6142 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6143 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6144 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6145 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6146 | * </ol> |
| 6147 | * @return operation result. |
| 6148 | */ |
| 6149 | @Override |
| 6150 | public int setNrDualConnectivityState(int subId, |
| 6151 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6152 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6153 | mApp, subId, "enableNRDualConnectivity"); |
| 6154 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6155 | final long identity = Binder.clearCallingIdentity(); |
| 6156 | try { |
| 6157 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6158 | nrDualConnectivityState, subId, |
| 6159 | workSource); |
| 6160 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6161 | return result; |
| 6162 | } finally { |
| 6163 | Binder.restoreCallingIdentity(identity); |
| 6164 | } |
| 6165 | } |
| 6166 | |
| 6167 | /** |
| 6168 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6169 | * @return true if dual connectivity is enabled else false |
| 6170 | */ |
| 6171 | @Override |
| 6172 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6173 | TelephonyPermissions |
| 6174 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6175 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6176 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6177 | final long identity = Binder.clearCallingIdentity(); |
| 6178 | try { |
| 6179 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6180 | null, subId, workSource); |
| 6181 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6182 | return isEnabled; |
| 6183 | } finally { |
| 6184 | Binder.restoreCallingIdentity(identity); |
| 6185 | } |
| 6186 | } |
| 6187 | |
| 6188 | /** |
Sooraj Sasindran | 4deb887 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 6189 | * get carrier bandwidth per primary and secondary carrier |
| 6190 | * @param subId subscription id of the sim card |
| 6191 | * @return CarrierBandwidth with bandwidth of both primary and secondary carrier.. |
| 6192 | */ |
| 6193 | @Override |
| 6194 | public CarrierBandwidth getCarrierBandwidth(int subId) { |
| 6195 | TelephonyPermissions |
| 6196 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6197 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6198 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6199 | final long identity = Binder.clearCallingIdentity(); |
| 6200 | try { |
| 6201 | CarrierBandwidth carrierBandwidth = |
| 6202 | getPhoneFromSubId(subId).getCarrierBandwidth(); |
| 6203 | if (DBG) log("getCarrierBandwidth: " + carrierBandwidth); |
| 6204 | return carrierBandwidth; |
| 6205 | } finally { |
| 6206 | Binder.restoreCallingIdentity(identity); |
| 6207 | } |
| 6208 | } |
| 6209 | |
| 6210 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6211 | * Set the allowed network types of the device and |
| 6212 | * provide the reason triggering the allowed network change. |
| 6213 | * |
| 6214 | * @param subId the id of the subscription. |
| 6215 | * @param reason the reason the allowed network type change is taking place |
| 6216 | * @param allowedNetworkTypes the allowed network types. |
| 6217 | * @return true on success; false on any failure. |
| 6218 | */ |
| 6219 | @Override |
| 6220 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6221 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6222 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6223 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6224 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6225 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
| 6226 | Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason); |
| 6227 | return false; |
| 6228 | } |
| 6229 | |
| 6230 | if (DBG) { |
| 6231 | log("setAllowedNetworkTypesForReason: " + reason |
| 6232 | + " value: " + allowedNetworkTypes); |
| 6233 | } |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6234 | final long identity = Binder.clearCallingIdentity(); |
| 6235 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6236 | Boolean success = (Boolean) sendRequest( |
| 6237 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6238 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6239 | |
| 6240 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6241 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6242 | } finally { |
| 6243 | Binder.restoreCallingIdentity(identity); |
| 6244 | } |
| 6245 | } |
| 6246 | |
| 6247 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6248 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6249 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6250 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6251 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6252 | * @hide |
| 6253 | */ |
| 6254 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6255 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6256 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6257 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6258 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6259 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6260 | if (phone != null) { |
| 6261 | return phone.hasMatchedTetherApnSetting(); |
| 6262 | } else { |
| 6263 | return false; |
| 6264 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6265 | } finally { |
| 6266 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6267 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6268 | } |
| 6269 | |
| 6270 | /** |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6271 | * Enable or disable always reporting signal strength changes from radio. |
| 6272 | * |
| 6273 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6274 | */ |
| 6275 | @Override |
| 6276 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6277 | enforceModifyPermission(); |
| 6278 | enforceSystemCaller(); |
| 6279 | |
| 6280 | final long identity = Binder.clearCallingIdentity(); |
| 6281 | final Phone phone = getPhone(subId); |
| 6282 | try { |
| 6283 | if (phone != null) { |
| 6284 | if (DBG) { |
| 6285 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6286 | + " isEnable=" + isEnable); |
| 6287 | } |
| 6288 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6289 | } else { |
| 6290 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6291 | + subId); |
| 6292 | } |
| 6293 | } finally { |
| 6294 | Binder.restoreCallingIdentity(identity); |
| 6295 | } |
| 6296 | } |
| 6297 | |
| 6298 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6299 | * Get the user enabled state of Mobile Data. |
| 6300 | * |
| 6301 | * TODO: remove and use isUserDataEnabled. |
| 6302 | * This can't be removed now because some vendor codes |
| 6303 | * calls through ITelephony directly while they should |
| 6304 | * use TelephonyManager. |
| 6305 | * |
| 6306 | * @return true on enabled |
| 6307 | */ |
| 6308 | @Override |
| 6309 | public boolean getDataEnabled(int subId) { |
| 6310 | return isUserDataEnabled(subId); |
| 6311 | } |
| 6312 | |
| 6313 | /** |
| 6314 | * Get whether mobile data is enabled per user setting. |
| 6315 | * |
| 6316 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6317 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6318 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6319 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6320 | * |
| 6321 | * @return {@code true} if data is enabled else {@code false} |
| 6322 | */ |
| 6323 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6324 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6325 | try { |
| 6326 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6327 | null); |
| 6328 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6329 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6330 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6331 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6332 | |
| 6333 | final long identity = Binder.clearCallingIdentity(); |
| 6334 | try { |
| 6335 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6336 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6337 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6338 | if (phone != null) { |
| 6339 | boolean retVal = phone.isUserDataEnabled(); |
| 6340 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6341 | return retVal; |
| 6342 | } else { |
| 6343 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6344 | return false; |
| 6345 | } |
| 6346 | } finally { |
| 6347 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6348 | } |
| 6349 | } |
| 6350 | |
| 6351 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6352 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6353 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6354 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6355 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6356 | * @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] | 6357 | */ |
| 6358 | @Override |
| 6359 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6360 | try { |
| 6361 | try { |
| 6362 | mApp.enforceCallingOrSelfPermission( |
| 6363 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6364 | null); |
| 6365 | } catch (Exception e) { |
| 6366 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6367 | "isDataEnabled"); |
| 6368 | } |
| 6369 | } catch (Exception e) { |
| 6370 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6371 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6372 | |
| 6373 | final long identity = Binder.clearCallingIdentity(); |
| 6374 | try { |
| 6375 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6376 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6377 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6378 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6379 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6380 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6381 | return retVal; |
| 6382 | } else { |
| 6383 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6384 | return false; |
| 6385 | } |
| 6386 | } finally { |
| 6387 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6388 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6389 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6390 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6391 | /** |
| 6392 | * Check if data is enabled for a specific reason |
| 6393 | * @param subId Subscription index |
| 6394 | * @param reason the reason the data enable change is taking place |
| 6395 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6396 | */ |
| 6397 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6398 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6399 | @TelephonyManager.DataEnabledReason int reason) { |
| 6400 | try { |
| 6401 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6402 | null); |
| 6403 | } catch (Exception e) { |
| 6404 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6405 | "isDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6406 | } |
| 6407 | |
| 6408 | |
| 6409 | final long identity = Binder.clearCallingIdentity(); |
| 6410 | try { |
| 6411 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6412 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6413 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6414 | + " reason=" + reason); |
| 6415 | } |
| 6416 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6417 | if (phone != null) { |
| 6418 | boolean retVal; |
| 6419 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6420 | retVal = phone.isUserDataEnabled(); |
| 6421 | } else { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6422 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6423 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6424 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6425 | return retVal; |
| 6426 | } else { |
| 6427 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6428 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6429 | + subId + " retVal=false"); |
| 6430 | } |
| 6431 | return false; |
| 6432 | } |
| 6433 | } finally { |
| 6434 | Binder.restoreCallingIdentity(identity); |
| 6435 | } |
| 6436 | } |
| 6437 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6438 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6439 | Phone phone) { |
Hall Liu | 54a2a0c | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6440 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 6441 | // Skip the check if it's one of these special uids |
| 6442 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6443 | } |
| 6444 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6445 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6446 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6447 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6448 | || subController == null) return privilegeFromSim; |
| 6449 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6450 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6451 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6452 | |
| 6453 | final long identity = Binder.clearCallingIdentity(); |
| 6454 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6455 | int subId = phone.getSubId(); |
| 6456 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6457 | // A test override is in place for the privileges for this subId, so don't try to |
| 6458 | // read the subscription privileges. |
| 6459 | return privilegeFromSim; |
| 6460 | } |
| 6461 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6462 | SubscriptionManager subManager = (SubscriptionManager) |
| 6463 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6464 | for (String pkg : packages) { |
| 6465 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6466 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6467 | } |
| 6468 | } |
| 6469 | return privilegeFromSim; |
| 6470 | } finally { |
| 6471 | Binder.restoreCallingIdentity(identity); |
| 6472 | } |
| 6473 | } |
| 6474 | |
| 6475 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6476 | String pkgName) { |
| 6477 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6478 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6479 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6480 | || subController == null) return privilegeFromSim; |
| 6481 | |
| 6482 | final long identity = Binder.clearCallingIdentity(); |
| 6483 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6484 | int subId = phone.getSubId(); |
| 6485 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6486 | // A test override is in place for the privileges for this subId, so don't try to |
| 6487 | // read the subscription privileges. |
| 6488 | return privilegeFromSim; |
| 6489 | } |
| 6490 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6491 | SubscriptionManager subManager = (SubscriptionManager) |
| 6492 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6493 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6494 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6495 | } finally { |
| 6496 | Binder.restoreCallingIdentity(identity); |
| 6497 | } |
| 6498 | } |
| 6499 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6500 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6501 | public int getCarrierPrivilegeStatus(int subId) { |
| 6502 | final Phone phone = getPhone(subId); |
| 6503 | if (phone == null) { |
| 6504 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6505 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6506 | } |
| 6507 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6508 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6509 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6510 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6511 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6512 | |
| 6513 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6514 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6515 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6516 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6517 | |
| 6518 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6519 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6520 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6521 | final Phone phone = getPhone(subId); |
| 6522 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6523 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6524 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6525 | } |
| 6526 | UiccProfile profile = |
| 6527 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6528 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6529 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6530 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6531 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6532 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6533 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6534 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6535 | } |
| 6536 | |
| 6537 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6538 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6539 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6540 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6541 | } |
| 6542 | |
| 6543 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6544 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6545 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6546 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6547 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6548 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6549 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6550 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6551 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6552 | } |
| 6553 | |
| 6554 | @Override |
| 6555 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6556 | if (TextUtils.isEmpty(pkgName)) |
| 6557 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6558 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6559 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6560 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6561 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6562 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6563 | continue; |
| 6564 | } |
| 6565 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6566 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6567 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6568 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6569 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6570 | break; |
| 6571 | } |
| 6572 | } |
| 6573 | |
| 6574 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6575 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6576 | |
| 6577 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6578 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6579 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6580 | loge("phoneId " + phoneId + " is not valid."); |
| 6581 | return null; |
| 6582 | } |
| 6583 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6584 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6585 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6586 | return null ; |
| 6587 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6588 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6589 | } |
| 6590 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6591 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6592 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6593 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6594 | List<String> privilegedPackages = new ArrayList<>(); |
| 6595 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6596 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6597 | // has UICC in that slot. |
| 6598 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6599 | if (card.hasCarrierPrivilegeRules()) { |
| 6600 | if (packages == null) { |
| 6601 | // Only check packages in user 0 for now |
| 6602 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6603 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6604 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6605 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6606 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6607 | } |
| 6608 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6609 | PackageInfo pkgInfo = packages.get(p); |
| 6610 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6611 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6612 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6613 | privilegedPackages.add(pkgInfo.packageName); |
| 6614 | } |
| 6615 | } |
| 6616 | } |
| 6617 | } |
| 6618 | return privilegedPackages; |
| 6619 | } |
| 6620 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6621 | @Override |
| 6622 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6623 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6624 | |
| 6625 | final long identity = Binder.clearCallingIdentity(); |
| 6626 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6627 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6628 | try { |
| 6629 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6630 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6631 | } |
| 6632 | } finally { |
| 6633 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6634 | } |
| 6635 | return privilegedPackages; |
| 6636 | } |
| 6637 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6638 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6639 | final Phone phone = getPhone(subId); |
| 6640 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6641 | if (card == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6642 | return null; |
| 6643 | } |
| 6644 | String iccId = card.getIccId(); |
| 6645 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6646 | return null; |
| 6647 | } |
| 6648 | return iccId; |
| 6649 | } |
| 6650 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6651 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6652 | public void setCallComposerStatus(int subId, int status) { |
| 6653 | enforceModifyPermission(); |
| 6654 | |
| 6655 | final long identity = Binder.clearCallingIdentity(); |
| 6656 | try { |
| 6657 | Phone phone = getPhone(subId); |
| 6658 | if (phone != null) { |
| 6659 | Phone defaultPhone = phone.getImsPhone(); |
| 6660 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6661 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6662 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6663 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6664 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6665 | } |
| 6666 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6667 | } catch (ImsException e) { |
| 6668 | throw new ServiceSpecificException(e.getCode()); |
| 6669 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6670 | Binder.restoreCallingIdentity(identity); |
| 6671 | } |
| 6672 | } |
| 6673 | |
| 6674 | @Override |
| 6675 | public int getCallComposerStatus(int subId) { |
| 6676 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6677 | |
| 6678 | final long identity = Binder.clearCallingIdentity(); |
| 6679 | try { |
| 6680 | Phone phone = getPhone(subId); |
| 6681 | if (phone != null) { |
| 6682 | Phone defaultPhone = phone.getImsPhone(); |
| 6683 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6684 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6685 | return imsPhone.getCallComposerStatus(); |
| 6686 | } |
| 6687 | } |
| 6688 | } finally { |
| 6689 | Binder.restoreCallingIdentity(identity); |
| 6690 | } |
| 6691 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6692 | } |
| 6693 | |
| 6694 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6695 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6696 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6697 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6698 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6699 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6700 | final long identity = Binder.clearCallingIdentity(); |
| 6701 | try { |
| 6702 | final String iccId = getIccId(subId); |
| 6703 | final Phone phone = getPhone(subId); |
| 6704 | if (phone == null) { |
| 6705 | return false; |
| 6706 | } |
| 6707 | final String subscriberId = phone.getSubscriberId(); |
| 6708 | |
| 6709 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6710 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6711 | + subscriberId + " to " + number); |
| 6712 | } |
| 6713 | |
| 6714 | if (TextUtils.isEmpty(iccId)) { |
| 6715 | return false; |
| 6716 | } |
| 6717 | |
| 6718 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6719 | |
| 6720 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6721 | if (alphaTag == null) { |
| 6722 | editor.remove(alphaTagPrefKey); |
| 6723 | } else { |
| 6724 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6725 | } |
| 6726 | |
| 6727 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6728 | // track all merged IMSIs based on line number |
| 6729 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6730 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6731 | if (number == null) { |
| 6732 | editor.remove(numberPrefKey); |
| 6733 | editor.remove(subscriberPrefKey); |
| 6734 | } else { |
| 6735 | editor.putString(numberPrefKey, number); |
| 6736 | editor.putString(subscriberPrefKey, subscriberId); |
| 6737 | } |
| 6738 | |
| 6739 | editor.commit(); |
| 6740 | return true; |
| 6741 | } finally { |
| 6742 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6743 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6744 | } |
| 6745 | |
| 6746 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6747 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6748 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6749 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6750 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6751 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6752 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6753 | return null; |
| 6754 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6755 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6756 | final long identity = Binder.clearCallingIdentity(); |
| 6757 | try { |
| 6758 | String iccId = getIccId(subId); |
| 6759 | if (iccId != null) { |
| 6760 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6761 | if (DBG_MERGE) { |
| 6762 | log("getLine1NumberForDisplay returning " |
| 6763 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6764 | } |
| 6765 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6766 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6767 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6768 | return null; |
| 6769 | } finally { |
| 6770 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6771 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6772 | } |
| 6773 | |
| 6774 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6775 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6776 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6777 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6778 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6779 | return null; |
| 6780 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6781 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6782 | final long identity = Binder.clearCallingIdentity(); |
| 6783 | try { |
| 6784 | String iccId = getIccId(subId); |
| 6785 | if (iccId != null) { |
| 6786 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6787 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6788 | } |
| 6789 | return null; |
| 6790 | } finally { |
| 6791 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6792 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6793 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6794 | |
| 6795 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6796 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6797 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6798 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6799 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6800 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6801 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6802 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6803 | return null; |
| 6804 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6805 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6806 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6807 | // the process, where TelephonyManager was instantiated. |
| 6808 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6809 | final long identity = Binder.clearCallingIdentity(); |
| 6810 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6811 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6812 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6813 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6814 | |
| 6815 | // Figure out what subscribers are currently active |
| 6816 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6817 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6818 | // Only consider subs which match the current subId |
| 6819 | // This logic can be simplified. See b/131189269 for progress. |
| 6820 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6821 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6822 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6823 | |
| 6824 | // First pass, find a number override for an active subscriber |
| 6825 | String mergeNumber = null; |
| 6826 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6827 | for (String key : prefs.keySet()) { |
| 6828 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6829 | final String subscriberId = (String) prefs.get(key); |
| 6830 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6831 | final String iccId = key.substring( |
| 6832 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6833 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6834 | mergeNumber = (String) prefs.get(numberKey); |
| 6835 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6836 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6837 | + " for active subscriber " + subscriberId); |
| 6838 | } |
| 6839 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6840 | break; |
| 6841 | } |
| 6842 | } |
| 6843 | } |
| 6844 | } |
| 6845 | |
| 6846 | // Shortcut when no active merged subscribers |
| 6847 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6848 | return null; |
| 6849 | } |
| 6850 | |
| 6851 | // Second pass, find all subscribers under that line override |
| 6852 | final ArraySet<String> result = new ArraySet<>(); |
| 6853 | for (String key : prefs.keySet()) { |
| 6854 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6855 | final String number = (String) prefs.get(key); |
| 6856 | if (mergeNumber.equals(number)) { |
| 6857 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6858 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6859 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6860 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6861 | result.add(subscriberId); |
| 6862 | } |
| 6863 | } |
| 6864 | } |
| 6865 | } |
| 6866 | |
| 6867 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6868 | Arrays.sort(resultArray); |
| 6869 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6870 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6871 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6872 | } |
| 6873 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6874 | } finally { |
| 6875 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6876 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6877 | } |
| 6878 | |
| 6879 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6880 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6881 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6882 | |
| 6883 | final long identity = Binder.clearCallingIdentity(); |
| 6884 | try { |
| 6885 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6886 | TelephonyManager.class); |
| 6887 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6888 | if (subscriberId == null) { |
| 6889 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6890 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6891 | + subId); |
| 6892 | } |
| 6893 | return null; |
| 6894 | } |
| 6895 | |
| 6896 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6897 | .getSubscriptionInfo(subId); |
| 6898 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6899 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6900 | if (groupUuid == null) { |
| 6901 | return new String[]{subscriberId}; |
| 6902 | } |
| 6903 | |
| 6904 | // Get all subscriberIds from the group. |
| 6905 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6906 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6907 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6908 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6909 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6910 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6911 | if (subscriberId != null) { |
| 6912 | mergedSubscriberIds.add(subscriberId); |
| 6913 | } |
| 6914 | } |
| 6915 | |
| 6916 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6917 | } finally { |
| 6918 | Binder.restoreCallingIdentity(identity); |
| 6919 | |
| 6920 | } |
| 6921 | } |
| 6922 | |
| 6923 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6924 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6925 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6926 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6927 | |
| 6928 | final long identity = Binder.clearCallingIdentity(); |
| 6929 | try { |
| 6930 | final Phone phone = getPhone(subId); |
| 6931 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6932 | } finally { |
| 6933 | Binder.restoreCallingIdentity(identity); |
| 6934 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6935 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6936 | |
| 6937 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6938 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6939 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6940 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6941 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6942 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6943 | |
| 6944 | final long identity = Binder.clearCallingIdentity(); |
| 6945 | try { |
| 6946 | final Phone phone = getPhone(subId); |
| 6947 | if (phone == null) { |
| 6948 | return false; |
| 6949 | } |
| 6950 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6951 | cdmaNonRoamingList); |
| 6952 | } finally { |
| 6953 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6954 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6955 | } |
| 6956 | |
| 6957 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6958 | @Deprecated |
| 6959 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6960 | enforceModifyPermission(); |
| 6961 | |
| 6962 | int returnValue = 0; |
| 6963 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6964 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6965 | if(result.exception == null) { |
| 6966 | if (result.result != null) { |
| 6967 | byte[] responseData = (byte[])(result.result); |
| 6968 | if(responseData.length > oemResp.length) { |
| 6969 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6970 | responseData.length + "bytes. Buffer Size is " + |
| 6971 | oemResp.length + "bytes."); |
| 6972 | } |
| 6973 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6974 | returnValue = responseData.length; |
| 6975 | } |
| 6976 | } else { |
| 6977 | CommandException ex = (CommandException) result.exception; |
| 6978 | returnValue = ex.getCommandError().ordinal(); |
| 6979 | if(returnValue > 0) returnValue *= -1; |
| 6980 | } |
| 6981 | } catch (RuntimeException e) { |
| 6982 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6983 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6984 | if(returnValue > 0) returnValue *= -1; |
| 6985 | } |
| 6986 | |
| 6987 | return returnValue; |
| 6988 | } |
| 6989 | |
| 6990 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6991 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6992 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 6993 | try { |
| 6994 | TelephonyPermissions |
| 6995 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6996 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6997 | } catch (SecurityException e) { |
| 6998 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 6999 | throw e; |
| 7000 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7001 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7002 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7003 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7004 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7005 | final long identity = Binder.clearCallingIdentity(); |
| 7006 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7007 | TelephonyPermissions |
| 7008 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 7009 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7010 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7011 | } finally { |
| 7012 | Binder.restoreCallingIdentity(identity); |
| 7013 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7014 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7015 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7016 | |
| 7017 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7018 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7019 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7020 | try { |
| 7021 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7022 | Binder.getCallingUid())) { |
| 7023 | throw new SecurityException("Package uid and package name do not match: " |
| 7024 | + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage); |
| 7025 | } |
| 7026 | } catch (PackageManager.NameNotFoundException e) { |
| 7027 | throw new SecurityException("Package name invalid:" + callingPackage); |
| 7028 | } |
| 7029 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7030 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7031 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7032 | throw new SecurityException("App must be the dialer role holder to" |
| 7033 | + " upload a call composer pic"); |
| 7034 | } |
| 7035 | |
| 7036 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7037 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7038 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7039 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7040 | boolean readUntilEnd = false; |
| 7041 | int totalBytesRead = 0; |
| 7042 | byte[] buffer = new byte[16 * 1024]; |
| 7043 | while (true) { |
| 7044 | int numRead; |
| 7045 | try { |
| 7046 | numRead = input.read(buffer); |
| 7047 | } catch (IOException e) { |
| 7048 | try { |
| 7049 | fd.checkError(); |
| 7050 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7051 | null); |
| 7052 | } catch (IOException e1) { |
| 7053 | // This means that the other side closed explicitly with an error. If this |
| 7054 | // happens, log and ignore. |
| 7055 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7056 | } |
| 7057 | break; |
| 7058 | } |
| 7059 | if (numRead == -1) { |
| 7060 | readUntilEnd = true; |
| 7061 | break; |
| 7062 | } |
| 7063 | totalBytesRead += numRead; |
| 7064 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7065 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7066 | try { |
| 7067 | input.close(); |
| 7068 | } catch (IOException e) { |
| 7069 | // ignore |
| 7070 | } |
| 7071 | break; |
| 7072 | } |
| 7073 | output.write(buffer, 0, numRead); |
| 7074 | } |
| 7075 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7076 | // close is above, where the picture size is too big. |
| 7077 | |
| 7078 | try { |
| 7079 | fd.checkError(); |
| 7080 | } catch (IOException e) { |
| 7081 | loge("Remote end for call composer closed with an error: " + e); |
| 7082 | return; |
| 7083 | } |
| 7084 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7085 | if (!readUntilEnd) { |
| 7086 | loge("Did not finish reading entire image; aborting"); |
| 7087 | return; |
| 7088 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7089 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7090 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7091 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7092 | new CallComposerPictureTransfer.Factory() {}, |
| 7093 | imageData, |
| 7094 | (result) -> { |
| 7095 | if (result.first != null) { |
| 7096 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7097 | Bundle outputResult = new Bundle(); |
| 7098 | outputResult.putParcelable( |
| 7099 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7100 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7101 | outputResult); |
| 7102 | } else { |
| 7103 | callback.send(result.second, null); |
| 7104 | } |
| 7105 | } |
| 7106 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7107 | }); |
| 7108 | } |
| 7109 | |
| 7110 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7111 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7112 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7113 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7114 | |
| 7115 | final long identity = Binder.clearCallingIdentity(); |
| 7116 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7117 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7118 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7119 | } finally { |
| 7120 | Binder.restoreCallingIdentity(identity); |
| 7121 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7122 | } |
| 7123 | |
| 7124 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7125 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7126 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7127 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7128 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7129 | return false; |
| 7130 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7131 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7132 | final long identity = Binder.clearCallingIdentity(); |
| 7133 | try { |
| 7134 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7135 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7136 | // In the long run, we may instead need to check if there exists a connection service |
| 7137 | // which can support video calling. |
| 7138 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7139 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7140 | return imsManager.isVtEnabledByPlatform() |
| 7141 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7142 | && imsManager.isVtEnabledByUser(); |
| 7143 | } finally { |
| 7144 | Binder.restoreCallingIdentity(identity); |
| 7145 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7146 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7147 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7148 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7149 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7150 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7151 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7152 | mApp, subId, callingPackage, callingFeatureId, |
| 7153 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7154 | return false; |
| 7155 | } |
| 7156 | |
| 7157 | final long identity = Binder.clearCallingIdentity(); |
| 7158 | try { |
| 7159 | CarrierConfigManager configManager = |
| 7160 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7161 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7162 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7163 | } finally { |
| 7164 | Binder.restoreCallingIdentity(identity); |
| 7165 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7166 | } |
| 7167 | |
| 7168 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7169 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7170 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7171 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7172 | return false; |
| 7173 | } |
| 7174 | |
| 7175 | final long identity = Binder.clearCallingIdentity(); |
| 7176 | try { |
| 7177 | CarrierConfigManager configManager = |
| 7178 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7179 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7180 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7181 | } finally { |
| 7182 | Binder.restoreCallingIdentity(identity); |
| 7183 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7184 | } |
| 7185 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7186 | @Override |
| 7187 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7188 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7189 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7190 | } |
| 7191 | |
| 7192 | @Override |
| 7193 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7194 | final long identity = Binder.clearCallingIdentity(); |
| 7195 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7196 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7197 | } finally { |
| 7198 | Binder.restoreCallingIdentity(identity); |
| 7199 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7200 | } |
| 7201 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7202 | /** |
| 7203 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7204 | * support for the feature and device firmware support. |
| 7205 | * |
| 7206 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7207 | */ |
| 7208 | @Override |
| 7209 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7210 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7211 | final Phone phone = getPhone(subscriptionId); |
| 7212 | if (phone == null) { |
| 7213 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7214 | return false; |
| 7215 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7216 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7217 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7218 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7219 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7220 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7221 | return isCarrierSupported && isDeviceSupported; |
| 7222 | } finally { |
| 7223 | Binder.restoreCallingIdentity(identity); |
| 7224 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7225 | } |
| 7226 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7227 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7228 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7229 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7230 | * 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] | 7231 | */ |
| 7232 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7233 | final long identity = Binder.clearCallingIdentity(); |
| 7234 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7235 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7236 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7237 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7238 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7239 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7240 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7241 | } finally { |
| 7242 | Binder.restoreCallingIdentity(identity); |
| 7243 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7244 | } |
| 7245 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7246 | @Deprecated |
| 7247 | @Override |
| 7248 | public String getDeviceId(String callingPackage) { |
| 7249 | return getDeviceIdWithFeature(callingPackage, null); |
| 7250 | } |
| 7251 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7252 | /** |
| 7253 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7254 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7255 | * |
| 7256 | * <p>Requires Permission: |
| 7257 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7258 | */ |
| 7259 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7260 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7261 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7262 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7263 | return null; |
| 7264 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7265 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7266 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7267 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7268 | return null; |
| 7269 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7270 | |
| 7271 | final long identity = Binder.clearCallingIdentity(); |
| 7272 | try { |
| 7273 | return phone.getDeviceId(); |
| 7274 | } finally { |
| 7275 | Binder.restoreCallingIdentity(identity); |
| 7276 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7277 | } |
| 7278 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7279 | /** |
| 7280 | * {@hide} |
| 7281 | * Returns the IMS Registration Status on a particular subid |
| 7282 | * |
| 7283 | * @param subId |
| 7284 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7285 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7286 | Phone phone = getPhone(subId); |
| 7287 | if (phone != null) { |
| 7288 | return phone.isImsRegistered(); |
| 7289 | } else { |
| 7290 | return false; |
| 7291 | } |
| 7292 | } |
| 7293 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7294 | @Override |
| 7295 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7296 | final long identity = Binder.clearCallingIdentity(); |
| 7297 | try { |
| 7298 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 7299 | } finally { |
| 7300 | Binder.restoreCallingIdentity(identity); |
| 7301 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7302 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7303 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7304 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7305 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7306 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7307 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7308 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7309 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7310 | } |
| 7311 | final long identity = Binder.clearCallingIdentity(); |
| 7312 | try { |
| 7313 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7314 | } finally { |
| 7315 | Binder.restoreCallingIdentity(identity); |
| 7316 | } |
| 7317 | } |
| 7318 | |
| 7319 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7320 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 7321 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 7322 | + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7323 | final long identity = Binder.clearCallingIdentity(); |
| 7324 | try { |
| 7325 | Phone phone = getPhone(subscriptionId); |
| 7326 | if (phone == null) { |
| 7327 | return null; |
| 7328 | } |
| 7329 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7330 | } finally { |
| 7331 | Binder.restoreCallingIdentity(identity); |
| 7332 | } |
| 7333 | } |
| 7334 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7335 | /** |
| 7336 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7337 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7338 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7339 | final long identity = Binder.clearCallingIdentity(); |
| 7340 | try { |
| 7341 | Phone phone = getPhone(subId); |
| 7342 | if (phone != null) { |
| 7343 | return phone.isWifiCallingEnabled(); |
| 7344 | } else { |
| 7345 | return false; |
| 7346 | } |
| 7347 | } finally { |
| 7348 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7349 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7350 | } |
| 7351 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7352 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7353 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7354 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7355 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7356 | final long identity = Binder.clearCallingIdentity(); |
| 7357 | try { |
| 7358 | Phone phone = getPhone(subId); |
| 7359 | if (phone != null) { |
| 7360 | return phone.isVideoEnabled(); |
| 7361 | } else { |
| 7362 | return false; |
| 7363 | } |
| 7364 | } finally { |
| 7365 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7366 | } |
| 7367 | } |
| 7368 | |
| 7369 | /** |
| 7370 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7371 | * defined in {@link ImsRegistrationImplBase}. |
| 7372 | */ |
| 7373 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7374 | final long identity = Binder.clearCallingIdentity(); |
| 7375 | try { |
| 7376 | Phone phone = getPhone(subId); |
| 7377 | if (phone != null) { |
| 7378 | return phone.getImsRegistrationTech(); |
| 7379 | } else { |
| 7380 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7381 | } |
| 7382 | } finally { |
| 7383 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7384 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7385 | } |
| 7386 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7387 | @Override |
| 7388 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7389 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7390 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7391 | return; |
| 7392 | } |
| 7393 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7394 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7395 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7396 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7397 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7398 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7399 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7400 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7401 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7402 | setAllowedNetworkTypesForReason(subId, |
| 7403 | TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7404 | RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId))); |
| 7405 | setAllowedNetworkTypesForReason(subId, |
| 7406 | TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER, |
| 7407 | RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId))); |
| 7408 | setAllowedNetworkTypesForReason(subId, |
| 7409 | TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER, |
| 7410 | RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId))); |
Yomna Nasser | 3f777b6 | 2021-02-17 03:38:52 +0000 | [diff] [blame] | 7411 | setAllowedNetworkTypesForReason(subId, |
| 7412 | TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G, |
| 7413 | RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId))); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7414 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 7415 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7416 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7417 | // There has been issues when Sms raw table somehow stores orphan |
| 7418 | // fragments. They lead to garbled message when new fragments come |
| 7419 | // in and combined with those stale ones. In case this happens again, |
| 7420 | // user can reset all network settings which will clean up this table. |
| 7421 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7422 | // Clean up IMS settings as well here. |
| 7423 | int slotId = getSlotIndex(subId); |
| 7424 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7425 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7426 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7427 | |
| 7428 | // Erase modem config if erase modem on network setting is enabled. |
| 7429 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7430 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7431 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 7432 | sendEraseModemConfig(getDefaultPhone()); |
| 7433 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7434 | } finally { |
| 7435 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7436 | } |
| 7437 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7438 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7439 | private void cleanUpSmsRawTable(Context context) { |
| 7440 | ContentResolver resolver = context.getContentResolver(); |
| 7441 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7442 | resolver.delete(uri, null, null); |
| 7443 | } |
| 7444 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7445 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7446 | public String getSimLocaleForSubscriber(int subId) { |
| 7447 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7448 | final Phone phone = getPhone(subId); |
| 7449 | if (phone == null) { |
| 7450 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7451 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7452 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7453 | final long identity = Binder.clearCallingIdentity(); |
| 7454 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7455 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7456 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7457 | if (info == null) { |
| 7458 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7459 | return null; |
| 7460 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7461 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7462 | // preferences (EF-PL and EF-LI)... |
| 7463 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7464 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7465 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7466 | if (localeFromDefaultSim != null) { |
| 7467 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7468 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7469 | + localeFromDefaultSim); |
| 7470 | return localeFromDefaultSim.toLanguageTag(); |
| 7471 | } else { |
| 7472 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7473 | } |
| 7474 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7475 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7476 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7477 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7478 | // the SIM and carrier preferences does not include a country we add the country |
| 7479 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7480 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7481 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7482 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7483 | return mccLocale.toLanguageTag(); |
| 7484 | } |
| 7485 | |
| 7486 | if (DBG) log("No locale found - returning null"); |
| 7487 | return null; |
| 7488 | } finally { |
| 7489 | Binder.restoreCallingIdentity(identity); |
| 7490 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7491 | } |
| 7492 | |
| 7493 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7494 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7495 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7496 | } |
| 7497 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7498 | /** |
| 7499 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7500 | */ |
| 7501 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7502 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7503 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7504 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7505 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7506 | private final ModemActivityInfo mLastModemActivityInfo = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7507 | new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7508 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7509 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7510 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7511 | * representing the state of the modem. |
| 7512 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7513 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7514 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7515 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7516 | */ |
| 7517 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7518 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7519 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7520 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7521 | |
| 7522 | final long identity = Binder.clearCallingIdentity(); |
| 7523 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7524 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7525 | } finally { |
| 7526 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7527 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7528 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7529 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7530 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7531 | // less than total activity duration. |
| 7532 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7533 | if (info == null) { |
| 7534 | return false; |
| 7535 | } |
| 7536 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7537 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7538 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7539 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7540 | return (info.isValid() |
| 7541 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7542 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7543 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7544 | && (totalTxTimeMs <= activityDurationMs)); |
| 7545 | } |
| 7546 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7547 | /** |
| 7548 | * {@hide} |
| 7549 | * Returns the service state information on specified subscription. |
| 7550 | */ |
| 7551 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7552 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7553 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7554 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7555 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7556 | return null; |
| 7557 | } |
| 7558 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7559 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7560 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7561 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7562 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7563 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7564 | .setCallingPid(Binder.getCallingPid()) |
| 7565 | .setCallingUid(Binder.getCallingUid()) |
| 7566 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7567 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7568 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7569 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7570 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7571 | .build()); |
| 7572 | |
| 7573 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7574 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7575 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7576 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7577 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7578 | .setCallingPid(Binder.getCallingPid()) |
| 7579 | .setCallingUid(Binder.getCallingUid()) |
| 7580 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7581 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7582 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7583 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7584 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7585 | .build()); |
| 7586 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7587 | boolean hasFinePermission = |
| 7588 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7589 | boolean hasCoarsePermission = |
| 7590 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7591 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7592 | final Phone phone = getPhone(subId); |
| 7593 | if (phone == null) { |
| 7594 | return null; |
| 7595 | } |
| 7596 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 7597 | final long identity = Binder.clearCallingIdentity(); |
| 7598 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7599 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7600 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7601 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7602 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7603 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7604 | Rlog.d(LOG_TAG, |
| 7605 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7606 | return null; |
| 7607 | } |
| 7608 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7609 | ServiceState ss = phone.getServiceState(); |
| 7610 | |
| 7611 | // Scrub out the location info in ServiceState depending on what level of access |
| 7612 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7613 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7614 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7615 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7616 | } finally { |
| 7617 | Binder.restoreCallingIdentity(identity); |
| 7618 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7619 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7620 | |
| 7621 | /** |
| 7622 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7623 | * |
| 7624 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7625 | * voicemail ringtone. |
| 7626 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7627 | * PhoneAccount. |
| 7628 | */ |
| 7629 | @Override |
| 7630 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7631 | final long identity = Binder.clearCallingIdentity(); |
| 7632 | try { |
| 7633 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7634 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7635 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7636 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7637 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7638 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7639 | } finally { |
| 7640 | Binder.restoreCallingIdentity(identity); |
| 7641 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7642 | } |
| 7643 | |
| 7644 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7645 | * Sets the per-account voicemail ringtone. |
| 7646 | * |
| 7647 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7648 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7649 | * |
| 7650 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7651 | * voicemail ringtone. |
| 7652 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7653 | * PhoneAccount. |
| 7654 | */ |
| 7655 | @Override |
| 7656 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7657 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7658 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7659 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7660 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7661 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7662 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7663 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7664 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7665 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7666 | |
| 7667 | final long identity = Binder.clearCallingIdentity(); |
| 7668 | try { |
| 7669 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7670 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7671 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7672 | } |
| 7673 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7674 | } finally { |
| 7675 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7676 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7677 | } |
| 7678 | |
| 7679 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7680 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7681 | * |
| 7682 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7683 | * voicemail vibration setting. |
| 7684 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7685 | */ |
| 7686 | @Override |
| 7687 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7688 | final long identity = Binder.clearCallingIdentity(); |
| 7689 | try { |
| 7690 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7691 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7692 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7693 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7694 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7695 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7696 | } finally { |
| 7697 | Binder.restoreCallingIdentity(identity); |
| 7698 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7699 | } |
| 7700 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7701 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7702 | * Sets the per-account voicemail vibration. |
| 7703 | * |
| 7704 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7705 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7706 | * |
| 7707 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7708 | * voicemail vibration setting. |
| 7709 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7710 | * specific PhoneAccount. |
| 7711 | */ |
| 7712 | @Override |
| 7713 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7714 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7715 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7716 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7717 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7718 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7719 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7720 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7721 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7722 | } |
| 7723 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7724 | final long identity = Binder.clearCallingIdentity(); |
| 7725 | try { |
| 7726 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7727 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7728 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7729 | } |
| 7730 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7731 | } finally { |
| 7732 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7733 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7734 | } |
| 7735 | |
| 7736 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7737 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7738 | * |
| 7739 | * @throws SecurityException if the caller does not have the required permission |
| 7740 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7741 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7742 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7743 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7744 | } |
| 7745 | |
| 7746 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7747 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7748 | * permission. |
| 7749 | * |
| 7750 | * @throws SecurityException if the caller does not have the required permission |
| 7751 | */ |
| 7752 | private void enforceSendSmsPermission() { |
| 7753 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7754 | } |
| 7755 | |
| 7756 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7757 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7758 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7759 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7760 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7761 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7762 | final long identity = Binder.clearCallingIdentity(); |
| 7763 | try { |
| 7764 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7765 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7766 | if (componentName == null) { |
| 7767 | throw new SecurityException( |
| 7768 | "Caller not current active visual voicemail package[null]"); |
| 7769 | } |
| 7770 | String vvmPackage = componentName.getPackageName(); |
| 7771 | if (!callingPackage.equals(vvmPackage)) { |
| 7772 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7773 | + vvmPackage + "]"); |
| 7774 | } |
| 7775 | } finally { |
| 7776 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7777 | } |
| 7778 | } |
| 7779 | |
| 7780 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7781 | * Return the application ID for the app type. |
| 7782 | * |
| 7783 | * @param subId the subscription ID that this request applies to. |
| 7784 | * @param appType the uicc app type. |
| 7785 | * @return Application ID for specificied app type, or null if no uicc. |
| 7786 | */ |
| 7787 | @Override |
| 7788 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7789 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7790 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7791 | |
| 7792 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7793 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7794 | if (phone == null) { |
| 7795 | return null; |
| 7796 | } |
| 7797 | String aid = null; |
| 7798 | try { |
| 7799 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7800 | .getApplicationByType(appType).getAid(); |
| 7801 | } catch (Exception e) { |
| 7802 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7803 | } |
| 7804 | return aid; |
| 7805 | } finally { |
| 7806 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7807 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7808 | } |
| 7809 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7810 | /** |
| 7811 | * Return the Electronic Serial Number. |
| 7812 | * |
| 7813 | * @param subId the subscription ID that this request applies to. |
| 7814 | * @return ESN or null if error. |
| 7815 | */ |
| 7816 | @Override |
| 7817 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7818 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -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 | 4001d25 | 2016-05-11 10:29:41 -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 esn = null; |
| 7827 | try { |
| 7828 | esn = phone.getEsn(); |
| 7829 | } catch (Exception e) { |
| 7830 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7831 | } |
| 7832 | return esn; |
| 7833 | } finally { |
| 7834 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7835 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7836 | } |
| 7837 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7838 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7839 | * Return the Preferred Roaming List Version. |
| 7840 | * |
| 7841 | * @param subId the subscription ID that this request applies to. |
| 7842 | * @return PRLVersion or null if error. |
| 7843 | */ |
| 7844 | @Override |
| 7845 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7846 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7847 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7848 | |
| 7849 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7850 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7851 | if (phone == null) { |
| 7852 | return null; |
| 7853 | } |
| 7854 | String cdmaPrlVersion = null; |
| 7855 | try { |
| 7856 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7857 | } catch (Exception e) { |
| 7858 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7859 | } |
| 7860 | return cdmaPrlVersion; |
| 7861 | } finally { |
| 7862 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7863 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7864 | } |
| 7865 | |
| 7866 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7867 | * Get snapshot of Telephony histograms |
| 7868 | * @return List of Telephony histograms |
| 7869 | * @hide |
| 7870 | */ |
| 7871 | @Override |
| 7872 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7873 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7874 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7875 | |
| 7876 | final long identity = Binder.clearCallingIdentity(); |
| 7877 | try { |
| 7878 | return RIL.getTelephonyRILTimingHistograms(); |
| 7879 | } finally { |
| 7880 | Binder.restoreCallingIdentity(identity); |
| 7881 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7882 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7883 | |
| 7884 | /** |
| 7885 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7886 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7887 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7888 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7889 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7890 | * @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] | 7891 | */ |
| 7892 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7893 | @TelephonyManager.SetCarrierRestrictionResult |
| 7894 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7895 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7896 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7897 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7898 | if (carrierRestrictionRules == null) { |
| 7899 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7900 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7901 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7902 | final long identity = Binder.clearCallingIdentity(); |
| 7903 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7904 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7905 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7906 | } finally { |
| 7907 | Binder.restoreCallingIdentity(identity); |
| 7908 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7909 | } |
| 7910 | |
| 7911 | /** |
| 7912 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7913 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7914 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7915 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7916 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7917 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7918 | */ |
| 7919 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7920 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7921 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7922 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7923 | |
| 7924 | final long identity = Binder.clearCallingIdentity(); |
| 7925 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7926 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7927 | if (response instanceof CarrierRestrictionRules) { |
| 7928 | return (CarrierRestrictionRules) response; |
| 7929 | } |
| 7930 | // Response is an Exception of some kind, |
| 7931 | // which is signalled to the user as a NULL retval |
| 7932 | return null; |
| 7933 | } catch (Exception e) { |
| 7934 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7935 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7936 | } finally { |
| 7937 | Binder.restoreCallingIdentity(identity); |
| 7938 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7939 | } |
| 7940 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7941 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7942 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7943 | * @param subId the subscription ID that this action applies to. |
| 7944 | * @param enabled control enable or disable radio. |
| 7945 | * {@hide} |
| 7946 | */ |
| 7947 | @Override |
| 7948 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7949 | enforceModifyPermission(); |
| 7950 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7951 | |
| 7952 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7953 | if (phone == null) { |
| 7954 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7955 | return; |
| 7956 | } |
| 7957 | try { |
| 7958 | phone.carrierActionSetRadioEnabled(enabled); |
| 7959 | } catch (Exception e) { |
| 7960 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7961 | } finally { |
| 7962 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7963 | } |
| 7964 | } |
| 7965 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7966 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7967 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7968 | * network status based on which carrier apps could apply actions accordingly, |
| 7969 | * enable/disable default url handler for example. |
| 7970 | * |
| 7971 | * @param subId the subscription ID that this action applies to. |
| 7972 | * @param report control start/stop reporting the default network status. |
| 7973 | * {@hide} |
| 7974 | */ |
| 7975 | @Override |
| 7976 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7977 | enforceModifyPermission(); |
| 7978 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7979 | |
| 7980 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7981 | if (phone == null) { |
| 7982 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7983 | return; |
| 7984 | } |
| 7985 | try { |
| 7986 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7987 | } catch (Exception e) { |
| 7988 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7989 | } finally { |
| 7990 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7991 | } |
| 7992 | } |
| 7993 | |
| 7994 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7995 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7996 | * @param subId the subscription ID that this action applies to. |
| 7997 | * {@hide} |
| 7998 | */ |
| 7999 | @Override |
| 8000 | public void carrierActionResetAll(int subId) { |
| 8001 | enforceModifyPermission(); |
| 8002 | final Phone phone = getPhone(subId); |
| 8003 | if (phone == null) { |
| 8004 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8005 | return; |
| 8006 | } |
| 8007 | try { |
| 8008 | phone.carrierActionResetAll(); |
| 8009 | } catch (Exception e) { |
| 8010 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8011 | } |
| 8012 | } |
| 8013 | |
| 8014 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8015 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8016 | * bug report is being generated. |
| 8017 | */ |
| 8018 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8019 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8020 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8021 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8022 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8023 | + Binder.getCallingPid() |
| 8024 | + ", uid=" + Binder.getCallingUid() |
| 8025 | + "without permission " |
| 8026 | + android.Manifest.permission.DUMP); |
| 8027 | return; |
| 8028 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8029 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8030 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8031 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8032 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8033 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8034 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8035 | @NonNull String[] args) { |
| 8036 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8037 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8038 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8039 | } |
| 8040 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8041 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8042 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8043 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8044 | * @param reason the reason the data enable change is taking place |
| 8045 | * @param enabled True if enabling the data, otherwise disabling. |
| 8046 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8047 | */ |
| 8048 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8049 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8050 | boolean enabled) { |
| 8051 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8052 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8053 | try { |
| 8054 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8055 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8056 | } catch (SecurityException se) { |
| 8057 | enforceModifyPermission(); |
| 8058 | } |
| 8059 | } else { |
| 8060 | enforceModifyPermission(); |
| 8061 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8062 | |
| 8063 | final long identity = Binder.clearCallingIdentity(); |
| 8064 | try { |
| 8065 | Phone phone = getPhone(subId); |
| 8066 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8067 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8068 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8069 | } else { |
| 8070 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 8071 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8072 | } |
| 8073 | } finally { |
| 8074 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8075 | } |
| 8076 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8077 | |
| 8078 | /** |
| 8079 | * Get Client request stats |
| 8080 | * @return List of Client Request Stats |
| 8081 | * @hide |
| 8082 | */ |
| 8083 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8084 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8085 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8086 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8087 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8088 | return null; |
| 8089 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8090 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8091 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8092 | final long identity = Binder.clearCallingIdentity(); |
| 8093 | try { |
| 8094 | if (phone != null) { |
| 8095 | return phone.getClientRequestStats(); |
| 8096 | } |
| 8097 | |
| 8098 | return null; |
| 8099 | } finally { |
| 8100 | Binder.restoreCallingIdentity(identity); |
| 8101 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8102 | } |
| 8103 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8104 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8105 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8106 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8107 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8108 | |
| 8109 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8110 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8111 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8112 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8113 | * @param state State of SIM (power down, power up, pass through) |
| 8114 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8115 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8116 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8117 | * |
| 8118 | **/ |
| 8119 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8120 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8121 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8122 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8123 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8124 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8125 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8126 | final long identity = Binder.clearCallingIdentity(); |
| 8127 | try { |
| 8128 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8129 | phone.setSimPowerState(state, null, workSource); |
| 8130 | } |
| 8131 | } finally { |
| 8132 | Binder.restoreCallingIdentity(identity); |
| 8133 | } |
| 8134 | } |
| 8135 | |
| 8136 | /** |
| 8137 | * Set SIM card power state. |
| 8138 | * |
| 8139 | * @param slotIndex SIM slot id. |
| 8140 | * @param state State of SIM (power down, power up, pass through) |
| 8141 | * @param callback callback to trigger after success or failure |
| 8142 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8143 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8144 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8145 | * |
| 8146 | **/ |
| 8147 | @Override |
| 8148 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8149 | IIntegerConsumer callback) { |
| 8150 | enforceModifyPermission(); |
| 8151 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8152 | |
| 8153 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8154 | |
| 8155 | final long identity = Binder.clearCallingIdentity(); |
| 8156 | try { |
| 8157 | if (phone != null) { |
| 8158 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8159 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8160 | } |
| 8161 | } finally { |
| 8162 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8163 | } |
| 8164 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8165 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8166 | private boolean isUssdApiAllowed(int subId) { |
| 8167 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8168 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8169 | if (configManager == null) { |
| 8170 | return false; |
| 8171 | } |
| 8172 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8173 | if (pb == null) { |
| 8174 | return false; |
| 8175 | } |
| 8176 | return pb.getBoolean( |
| 8177 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8178 | } |
| 8179 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8180 | /** |
| 8181 | * Check if phone is in emergency callback mode |
| 8182 | * @return true if phone is in emergency callback mode |
| 8183 | * @param subId sub id |
| 8184 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8185 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8186 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8187 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8188 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8189 | |
| 8190 | final long identity = Binder.clearCallingIdentity(); |
| 8191 | try { |
| 8192 | if (phone != null) { |
| 8193 | return phone.isInEcm(); |
| 8194 | } else { |
| 8195 | return false; |
| 8196 | } |
| 8197 | } finally { |
| 8198 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8199 | } |
| 8200 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8201 | |
| 8202 | /** |
| 8203 | * Get the current signal strength information for the given subscription. |
| 8204 | * Because this information is not updated when the device is in a low power state |
| 8205 | * it should not be relied-upon to be current. |
| 8206 | * @param subId Subscription index |
| 8207 | * @return the most recent cached signal strength info from the modem |
| 8208 | */ |
| 8209 | @Override |
| 8210 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8211 | final long identity = Binder.clearCallingIdentity(); |
| 8212 | try { |
| 8213 | Phone p = getPhone(subId); |
| 8214 | if (p == null) { |
| 8215 | return null; |
| 8216 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8217 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8218 | return p.getSignalStrength(); |
| 8219 | } finally { |
| 8220 | Binder.restoreCallingIdentity(identity); |
| 8221 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8222 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8223 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8224 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8225 | * Get the current modem radio state for the given slot. |
| 8226 | * @param slotIndex slot index. |
| 8227 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8228 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8229 | * @return the current radio power state from the modem |
| 8230 | */ |
| 8231 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8232 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8233 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8234 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8235 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8236 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8237 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8238 | } |
| 8239 | |
| 8240 | final long identity = Binder.clearCallingIdentity(); |
| 8241 | try { |
| 8242 | return phone.getRadioPowerState(); |
| 8243 | } finally { |
| 8244 | Binder.restoreCallingIdentity(identity); |
| 8245 | } |
| 8246 | } |
| 8247 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8248 | } |
| 8249 | |
| 8250 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8251 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8252 | * |
| 8253 | * <p>Requires one of the following permissions: |
| 8254 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 8255 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8256 | * privileges. |
| 8257 | * |
| 8258 | * @param subId subscription id |
| 8259 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8260 | * {@code false}. |
| 8261 | */ |
| 8262 | @Override |
| 8263 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8264 | try { |
| 8265 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8266 | null); |
| 8267 | } catch (Exception e) { |
| 8268 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 8269 | mApp, subId, "isDataRoamingEnabled"); |
| 8270 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8271 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8272 | boolean isEnabled = false; |
| 8273 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8274 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8275 | Phone phone = getPhone(subId); |
| 8276 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8277 | } finally { |
| 8278 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8279 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8280 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8281 | } |
| 8282 | |
| 8283 | |
| 8284 | /** |
| 8285 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8286 | * |
| 8287 | * <p> Requires permission: |
| 8288 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8289 | * privileges. |
| 8290 | * |
| 8291 | * @param subId subscription id |
| 8292 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8293 | */ |
| 8294 | @Override |
| 8295 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8296 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8297 | mApp, subId, "setDataRoamingEnabled"); |
| 8298 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8299 | final long identity = Binder.clearCallingIdentity(); |
| 8300 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8301 | Phone phone = getPhone(subId); |
| 8302 | if (phone != null) { |
| 8303 | phone.setDataRoamingEnabled(isEnabled); |
| 8304 | } |
| 8305 | } finally { |
| 8306 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8307 | } |
| 8308 | } |
| 8309 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8310 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8311 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8312 | TelephonyPermissions |
| 8313 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8314 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8315 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8316 | boolean isAllowed = true; |
| 8317 | final long identity = Binder.clearCallingIdentity(); |
| 8318 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8319 | Phone phone = getPhone(subId); |
| 8320 | if (phone != null) { |
| 8321 | isAllowed = phone.isCspPlmnEnabled(); |
| 8322 | } |
| 8323 | } finally { |
| 8324 | Binder.restoreCallingIdentity(identity); |
| 8325 | } |
| 8326 | return isAllowed; |
| 8327 | } |
| 8328 | |
| 8329 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8330 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8331 | // Verify that tha callingPackage belongs to the calling UID |
| 8332 | mApp.getSystemService(AppOpsManager.class) |
| 8333 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8334 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8335 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8336 | try { |
| 8337 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8338 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8339 | } catch (SecurityException e) { |
| 8340 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8341 | // has carrier privileges on an active UICC |
| 8342 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8343 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8344 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8345 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8346 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8347 | |
| 8348 | final long identity = Binder.clearCallingIdentity(); |
| 8349 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8350 | UiccController uiccController = UiccController.getInstance(); |
| 8351 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8352 | if (hasReadPermission) { |
| 8353 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8354 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8355 | |
| 8356 | // Remove private info if the caller doesn't have access |
| 8357 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8358 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8359 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8360 | // is available |
| 8361 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 8362 | if (card == null || card.getUiccProfile() == null) { |
| 8363 | // assume no access if the card or profile is unavailable |
| 8364 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8365 | continue; |
| 8366 | } |
| 8367 | UiccProfile profile = card.getUiccProfile(); |
| 8368 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8369 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8370 | filteredInfos.add(cardInfo); |
| 8371 | } else { |
| 8372 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8373 | } |
| 8374 | } |
| 8375 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8376 | } finally { |
| 8377 | Binder.restoreCallingIdentity(identity); |
| 8378 | } |
| 8379 | } |
| 8380 | |
| 8381 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8382 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8383 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8384 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8385 | final long identity = Binder.clearCallingIdentity(); |
| 8386 | try { |
| 8387 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8388 | if (slots == null) { |
| 8389 | Rlog.i(LOG_TAG, "slots is null."); |
| 8390 | return null; |
| 8391 | } |
| 8392 | |
| 8393 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8394 | for (int i = 0; i < slots.length; i++) { |
| 8395 | UiccSlot slot = slots[i]; |
| 8396 | if (slot == null) { |
| 8397 | continue; |
| 8398 | } |
| 8399 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8400 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8401 | UiccCard card = slot.getUiccCard(); |
| 8402 | if (card != null) { |
| 8403 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8404 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8405 | cardId = slot.getEid(); |
| 8406 | if (TextUtils.isEmpty(cardId)) { |
| 8407 | cardId = slot.getIccId(); |
| 8408 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8409 | } |
| 8410 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8411 | if (cardId != null) { |
| 8412 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8413 | // if cardId is an EID, it's all digits so this is fine |
| 8414 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8415 | } |
| 8416 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8417 | int cardState = 0; |
| 8418 | switch (slot.getCardState()) { |
| 8419 | case CARDSTATE_ABSENT: |
| 8420 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8421 | break; |
| 8422 | case CARDSTATE_PRESENT: |
| 8423 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8424 | break; |
| 8425 | case CARDSTATE_ERROR: |
| 8426 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8427 | break; |
| 8428 | case CARDSTATE_RESTRICTED: |
| 8429 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8430 | break; |
| 8431 | default: |
| 8432 | break; |
| 8433 | |
| 8434 | } |
| 8435 | |
| 8436 | infos[i] = new UiccSlotInfo( |
| 8437 | slot.isActive(), |
| 8438 | slot.isEuicc(), |
| 8439 | cardId, |
| 8440 | cardState, |
| 8441 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8442 | slot.isExtendedApduSupported(), |
| 8443 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8444 | } |
| 8445 | return infos; |
| 8446 | } finally { |
| 8447 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8448 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8449 | } |
| 8450 | |
| 8451 | @Override |
| 8452 | public boolean switchSlots(int[] physicalSlots) { |
| 8453 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8454 | |
| 8455 | final long identity = Binder.clearCallingIdentity(); |
| 8456 | try { |
| 8457 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8458 | } finally { |
| 8459 | Binder.restoreCallingIdentity(identity); |
| 8460 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8461 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8462 | |
| 8463 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8464 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8465 | final long identity = Binder.clearCallingIdentity(); |
| 8466 | try { |
| 8467 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8468 | } finally { |
| 8469 | Binder.restoreCallingIdentity(identity); |
| 8470 | } |
| 8471 | } |
| 8472 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8473 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8474 | * A test API to reload the UICC profile. |
| 8475 | * |
| 8476 | * <p>Requires that the calling app has permission |
| 8477 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8478 | * @hide |
| 8479 | */ |
| 8480 | @Override |
| 8481 | public void refreshUiccProfile(int subId) { |
| 8482 | enforceModifyPermission(); |
| 8483 | |
| 8484 | final long identity = Binder.clearCallingIdentity(); |
| 8485 | try { |
| 8486 | Phone phone = getPhone(subId); |
| 8487 | if (phone == null) { |
| 8488 | return; |
| 8489 | } |
| 8490 | UiccCard uiccCard = phone.getUiccCard(); |
| 8491 | if (uiccCard == null) { |
| 8492 | return; |
| 8493 | } |
| 8494 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8495 | if (uiccProfile == null) { |
| 8496 | return; |
| 8497 | } |
| 8498 | uiccProfile.refresh(); |
| 8499 | } finally { |
| 8500 | Binder.restoreCallingIdentity(identity); |
| 8501 | } |
| 8502 | } |
| 8503 | |
| 8504 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8505 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8506 | */ |
| 8507 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8508 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8509 | } |
| 8510 | |
| 8511 | /** |
| 8512 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8513 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8514 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8515 | */ |
| 8516 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8517 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8518 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8519 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8520 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8521 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8522 | return isDataRoamingEnabled; |
| 8523 | } |
| 8524 | |
| 8525 | /** |
| 8526 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8527 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8528 | */ |
| 8529 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8530 | List<Integer> list = TelephonyProperties.default_network(); |
| 8531 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8532 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8533 | return list.get(phoneId); |
| 8534 | } |
| 8535 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8536 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8537 | |
| 8538 | @Override |
| 8539 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8540 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8541 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8542 | |
| 8543 | final long identity = Binder.clearCallingIdentity(); |
| 8544 | try { |
| 8545 | final Phone phone = getPhone(subId); |
| 8546 | if (phone == null) { |
| 8547 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8548 | return; |
| 8549 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8550 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8551 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8552 | if (carrierPrivilegeRules == null) { |
| 8553 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8554 | } else { |
| 8555 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8556 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8557 | } finally { |
| 8558 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8559 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8560 | } |
| 8561 | |
| 8562 | @Override |
| 8563 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8564 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8565 | |
| 8566 | final long identity = Binder.clearCallingIdentity(); |
| 8567 | try { |
| 8568 | final Phone phone = getPhone(subId); |
| 8569 | if (phone == null) { |
| 8570 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8571 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8572 | } |
| 8573 | return phone.getCarrierIdListVersion(); |
| 8574 | } finally { |
| 8575 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8576 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8577 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8578 | |
| 8579 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8580 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8581 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8582 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8583 | mApp, subId, callingPackage, callingFeatureId, |
| 8584 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8585 | return -1; |
| 8586 | } |
| 8587 | |
| 8588 | final long identity = Binder.clearCallingIdentity(); |
| 8589 | try { |
| 8590 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8591 | } finally { |
| 8592 | Binder.restoreCallingIdentity(identity); |
| 8593 | } |
| 8594 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8595 | |
| 8596 | @Override |
| 8597 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8598 | TelephonyPermissions |
| 8599 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8600 | mApp, subId, "getCdmaRoamingMode"); |
| 8601 | |
| 8602 | final long identity = Binder.clearCallingIdentity(); |
| 8603 | try { |
| 8604 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8605 | } finally { |
| 8606 | Binder.restoreCallingIdentity(identity); |
| 8607 | } |
| 8608 | } |
| 8609 | |
| 8610 | @Override |
| 8611 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8612 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8613 | mApp, subId, "setCdmaRoamingMode"); |
| 8614 | |
| 8615 | final long identity = Binder.clearCallingIdentity(); |
| 8616 | try { |
| 8617 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8618 | } finally { |
| 8619 | Binder.restoreCallingIdentity(identity); |
| 8620 | } |
| 8621 | } |
| 8622 | |
| 8623 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8624 | public int getCdmaSubscriptionMode(int subId) { |
| 8625 | TelephonyPermissions |
| 8626 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8627 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8628 | |
| 8629 | final long identity = Binder.clearCallingIdentity(); |
| 8630 | try { |
| 8631 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8632 | } finally { |
| 8633 | Binder.restoreCallingIdentity(identity); |
| 8634 | } |
| 8635 | } |
| 8636 | |
| 8637 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8638 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8639 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8640 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8641 | |
| 8642 | final long identity = Binder.clearCallingIdentity(); |
| 8643 | try { |
| 8644 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8645 | } finally { |
| 8646 | Binder.restoreCallingIdentity(identity); |
| 8647 | } |
| 8648 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8649 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8650 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8651 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8652 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8653 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8654 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8655 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8656 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8657 | } |
| 8658 | final long identity = Binder.clearCallingIdentity(); |
| 8659 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8660 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8661 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8662 | if (phone.getEmergencyNumberTracker() != null |
| 8663 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8664 | emergencyNumberListInternal.put( |
| 8665 | phone.getSubId(), |
| 8666 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8667 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8668 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8669 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8670 | } finally { |
| 8671 | Binder.restoreCallingIdentity(identity); |
| 8672 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8673 | } |
| 8674 | |
| 8675 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8676 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8677 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8678 | if (!exactMatch) { |
| 8679 | TelephonyPermissions |
| 8680 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8681 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8682 | } |
| 8683 | final long identity = Binder.clearCallingIdentity(); |
| 8684 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8685 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8686 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8687 | && phone.getEmergencyNumberTracker() |
| 8688 | .isEmergencyNumber(number, exactMatch)) { |
| 8689 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8690 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8691 | } |
| 8692 | return false; |
| 8693 | } finally { |
| 8694 | Binder.restoreCallingIdentity(identity); |
| 8695 | } |
| 8696 | } |
| 8697 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8698 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 8699 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 8700 | */ |
| 8701 | @Override |
| 8702 | public void startEmergencyCallbackMode() { |
| 8703 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8704 | "startEmergencyCallbackMode"); |
| 8705 | enforceModifyPermission(); |
| 8706 | final long identity = Binder.clearCallingIdentity(); |
| 8707 | try { |
| 8708 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8709 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 8710 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 8711 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 8712 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 8713 | gsmCdmaPhone.obtainMessage( |
| 8714 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 8715 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 8716 | } |
| 8717 | } |
| 8718 | } finally { |
| 8719 | Binder.restoreCallingIdentity(identity); |
| 8720 | } |
| 8721 | } |
| 8722 | |
| 8723 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8724 | * Update emergency number list for test mode. |
| 8725 | */ |
| 8726 | @Override |
| 8727 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8728 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8729 | "updateEmergencyNumberListTestMode"); |
| 8730 | |
| 8731 | final long identity = Binder.clearCallingIdentity(); |
| 8732 | try { |
| 8733 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8734 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8735 | if (tracker != null) { |
| 8736 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8737 | } |
| 8738 | } |
| 8739 | } finally { |
| 8740 | Binder.restoreCallingIdentity(identity); |
| 8741 | } |
| 8742 | } |
| 8743 | |
| 8744 | /** |
| 8745 | * Get the full emergency number list for test mode. |
| 8746 | */ |
| 8747 | @Override |
| 8748 | public List<String> getEmergencyNumberListTestMode() { |
| 8749 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8750 | "getEmergencyNumberListTestMode"); |
| 8751 | |
| 8752 | final long identity = Binder.clearCallingIdentity(); |
| 8753 | try { |
| 8754 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8755 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8756 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8757 | if (tracker != null) { |
| 8758 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8759 | emergencyNumbers.add(num.getNumber()); |
| 8760 | } |
| 8761 | } |
| 8762 | } |
| 8763 | return new ArrayList<>(emergencyNumbers); |
| 8764 | } finally { |
| 8765 | Binder.restoreCallingIdentity(identity); |
| 8766 | } |
| 8767 | } |
| 8768 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8769 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8770 | public int getEmergencyNumberDbVersion(int subId) { |
| 8771 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8772 | |
| 8773 | final long identity = Binder.clearCallingIdentity(); |
| 8774 | try { |
| 8775 | final Phone phone = getPhone(subId); |
| 8776 | if (phone == null) { |
| 8777 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8778 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8779 | } |
| 8780 | return phone.getEmergencyNumberDbVersion(); |
| 8781 | } finally { |
| 8782 | Binder.restoreCallingIdentity(identity); |
| 8783 | } |
| 8784 | } |
| 8785 | |
| 8786 | @Override |
| 8787 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8788 | enforceModifyPermission(); |
| 8789 | |
| 8790 | final long identity = Binder.clearCallingIdentity(); |
| 8791 | try { |
| 8792 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8793 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8794 | if (tracker != null) { |
| 8795 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8796 | } |
| 8797 | } |
| 8798 | } finally { |
| 8799 | Binder.restoreCallingIdentity(identity); |
| 8800 | } |
| 8801 | } |
| 8802 | |
| 8803 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8804 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8805 | enforceActiveEmergencySessionPermission(); |
| 8806 | |
| 8807 | final long identity = Binder.clearCallingIdentity(); |
| 8808 | try { |
| 8809 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8810 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8811 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8812 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8813 | } |
| 8814 | } |
| 8815 | } finally { |
| 8816 | Binder.restoreCallingIdentity(identity); |
| 8817 | } |
| 8818 | } |
| 8819 | |
| 8820 | @Override |
| 8821 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8822 | enforceActiveEmergencySessionPermission(); |
| 8823 | |
| 8824 | final long identity = Binder.clearCallingIdentity(); |
| 8825 | try { |
| 8826 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8827 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8828 | if (tracker != null) { |
| 8829 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8830 | } |
| 8831 | } |
| 8832 | } finally { |
| 8833 | Binder.restoreCallingIdentity(identity); |
| 8834 | } |
| 8835 | } |
| 8836 | |
| 8837 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8838 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8839 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8840 | Phone phone = getPhone(subId); |
| 8841 | if (phone == null) { |
| 8842 | return null; |
| 8843 | } |
| 8844 | final long identity = Binder.clearCallingIdentity(); |
| 8845 | try { |
| 8846 | UiccProfile profile = UiccController.getInstance() |
| 8847 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8848 | if (profile != null) { |
| 8849 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8850 | } |
| 8851 | } finally { |
| 8852 | Binder.restoreCallingIdentity(identity); |
| 8853 | } |
| 8854 | return null; |
| 8855 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8856 | |
| 8857 | /** |
| 8858 | * Enable or disable a modem stack. |
| 8859 | */ |
| 8860 | @Override |
| 8861 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8862 | enforceModifyPermission(); |
| 8863 | |
| 8864 | final long identity = Binder.clearCallingIdentity(); |
| 8865 | try { |
| 8866 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8867 | if (phone == null) { |
| 8868 | return false; |
| 8869 | } else { |
| 8870 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8871 | } |
| 8872 | } finally { |
| 8873 | Binder.restoreCallingIdentity(identity); |
| 8874 | } |
| 8875 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8876 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8877 | /** |
| 8878 | * Whether a modem stack is enabled or not. |
| 8879 | */ |
| 8880 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8881 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8882 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8883 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8884 | if (phone == null) return false; |
| 8885 | |
| 8886 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8887 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8888 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8889 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8890 | } |
| 8891 | |
| 8892 | final long identity = Binder.clearCallingIdentity(); |
| 8893 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8894 | try { |
| 8895 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8896 | } catch (NoSuchElementException ex) { |
| 8897 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8898 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8899 | } finally { |
| 8900 | Binder.restoreCallingIdentity(identity); |
| 8901 | } |
| 8902 | } |
| 8903 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8904 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8905 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8906 | enforceModifyPermission(); |
| 8907 | |
| 8908 | final long identity = Binder.clearCallingIdentity(); |
| 8909 | try { |
| 8910 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8911 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8912 | .commit(); |
| 8913 | } finally { |
| 8914 | Binder.restoreCallingIdentity(identity); |
| 8915 | } |
| 8916 | } |
| 8917 | |
| 8918 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8919 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8920 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8921 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8922 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8923 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8924 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8925 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8926 | |
| 8927 | final long identity = Binder.clearCallingIdentity(); |
| 8928 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8929 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8930 | } finally { |
| 8931 | Binder.restoreCallingIdentity(identity); |
| 8932 | } |
| 8933 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8934 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8935 | @TelephonyManager.IsMultiSimSupportedResult |
| 8936 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8937 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8938 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8939 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8940 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8941 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8942 | } |
| 8943 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8944 | // supported by the modem, indicate that it is restricted. |
| 8945 | PhoneCapability staticCapability = |
| 8946 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8947 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8948 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8949 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8950 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 8951 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8952 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8953 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8954 | } |
| 8955 | // Check if support of multiple SIMs is restricted by carrier |
| 8956 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8957 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8958 | } |
| 8959 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8960 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8961 | } |
| 8962 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8963 | /** |
| 8964 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8965 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8966 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8967 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8968 | * @param numOfSims number of active sims we want to switch to |
| 8969 | */ |
| 8970 | @Override |
| 8971 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8972 | if (numOfSims == 1) { |
| 8973 | enforceModifyPermission(); |
| 8974 | } else { |
| 8975 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8976 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8977 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8978 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8979 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8980 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8981 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8982 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8983 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8984 | return; |
| 8985 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8986 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8987 | } finally { |
| 8988 | Binder.restoreCallingIdentity(identity); |
| 8989 | } |
| 8990 | } |
| 8991 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8992 | @Override |
| 8993 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8994 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8995 | Phone phone = getPhone(subId); |
| 8996 | if (phone == null) { |
| 8997 | return false; |
| 8998 | } |
| 8999 | final long identity = Binder.clearCallingIdentity(); |
| 9000 | try { |
| 9001 | UiccCard uiccCard = phone.getUiccCard(); |
| 9002 | if (uiccCard == null) { |
| 9003 | return false; |
| 9004 | } |
| 9005 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 9006 | if (uiccProfile == null) { |
| 9007 | return false; |
| 9008 | } |
| 9009 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9010 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9011 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9012 | } |
| 9013 | return false; |
| 9014 | } finally { |
| 9015 | Binder.restoreCallingIdentity(identity); |
| 9016 | } |
| 9017 | } |
| 9018 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9019 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9020 | * Get whether making changes to modem configurations will trigger reboot. |
| 9021 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9022 | */ |
| 9023 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9024 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9025 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9026 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9027 | mApp, subId, callingPackage, callingFeatureId, |
| 9028 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9029 | return false; |
| 9030 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9031 | final long identity = Binder.clearCallingIdentity(); |
| 9032 | try { |
| 9033 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9034 | } finally { |
| 9035 | Binder.restoreCallingIdentity(identity); |
| 9036 | } |
| 9037 | } |
| 9038 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9039 | private void updateModemStateMetrics() { |
| 9040 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9041 | // TODO: check the state for each modem if the api is ready. |
| 9042 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9043 | } |
| 9044 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9045 | @Override |
| 9046 | public int[] getSlotsMapping() { |
| 9047 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 9048 | |
| 9049 | final long identity = Binder.clearCallingIdentity(); |
| 9050 | try { |
| 9051 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 9052 | // All logical slots should have a mapping to a physical slot. |
| 9053 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 9054 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 9055 | for (int i = 0; i < slotInfos.length; i++) { |
| 9056 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 9057 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 9058 | } |
| 9059 | } |
| 9060 | return logicalSlotsMapping; |
| 9061 | } finally { |
| 9062 | Binder.restoreCallingIdentity(identity); |
| 9063 | } |
| 9064 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9065 | |
| 9066 | /** |
| 9067 | * Get the IRadio HAL Version |
| 9068 | */ |
| 9069 | @Override |
| 9070 | public int getRadioHalVersion() { |
| 9071 | Phone phone = getDefaultPhone(); |
| 9072 | if (phone == null) return -1; |
| 9073 | HalVersion hv = phone.getHalVersion(); |
| 9074 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9075 | return hv.major * 100 + hv.minor; |
| 9076 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9077 | |
| 9078 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9079 | * Get the current calling package name. |
| 9080 | * @return the current calling package name |
| 9081 | */ |
| 9082 | @Override |
| 9083 | public String getCurrentPackageName() { |
| 9084 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9085 | } |
| 9086 | |
| 9087 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9088 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9089 | * corresponding network requests on a subId. |
| 9090 | * |
| 9091 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9092 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9093 | * 2) APN is un-metered for this subscription, or |
| 9094 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9095 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9096 | * |
| 9097 | * @return whether data is allowed for a apn type. |
| 9098 | * |
| 9099 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9100 | */ |
| 9101 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9102 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9103 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9104 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9105 | |
| 9106 | // Now that all security checks passes, perform the operation as ourselves. |
| 9107 | final long identity = Binder.clearCallingIdentity(); |
| 9108 | try { |
| 9109 | Phone phone = getPhone(subId); |
| 9110 | if (phone == null) return false; |
| 9111 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9112 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9113 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 9114 | } finally { |
| 9115 | Binder.restoreCallingIdentity(identity); |
| 9116 | } |
| 9117 | } |
| 9118 | |
| 9119 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9120 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9121 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9122 | |
| 9123 | // Now that all security checks passes, perform the operation as ourselves. |
| 9124 | final long identity = Binder.clearCallingIdentity(); |
| 9125 | try { |
| 9126 | Phone phone = getPhone(subId); |
| 9127 | if (phone == null) return true; // By default return true. |
| 9128 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9129 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9130 | } finally { |
| 9131 | Binder.restoreCallingIdentity(identity); |
| 9132 | } |
| 9133 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9134 | |
| 9135 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9136 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9137 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9138 | enforceModifyPermission(); |
| 9139 | long token = Binder.clearCallingIdentity(); |
| 9140 | try { |
| 9141 | Phone phone = getPhone(subscriptionId); |
| 9142 | if (phone == null) { |
| 9143 | try { |
| 9144 | if (resultCallback != null) { |
| 9145 | resultCallback.accept(false); |
| 9146 | } |
| 9147 | } catch (RemoteException e) { |
| 9148 | // ignore |
| 9149 | } |
| 9150 | return; |
| 9151 | } |
| 9152 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9153 | Pair.create(specifiers, (x) -> { |
| 9154 | try { |
| 9155 | if (resultCallback != null) { |
| 9156 | resultCallback.accept(x); |
| 9157 | } |
| 9158 | } catch (RemoteException e) { |
| 9159 | // ignore |
| 9160 | } |
| 9161 | }); |
| 9162 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9163 | } finally { |
| 9164 | Binder.restoreCallingIdentity(token); |
| 9165 | } |
| 9166 | } |
| 9167 | |
| 9168 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9169 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9170 | TelephonyPermissions |
| 9171 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 9172 | mApp, subId, "getSystemSelectionChannels"); |
| 9173 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9174 | final long identity = Binder.clearCallingIdentity(); |
| 9175 | try { |
| 9176 | List<RadioAccessSpecifier> specifiers = |
| 9177 | (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, |
| 9178 | null, subId, workSource); |
| 9179 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9180 | return specifiers; |
| 9181 | } finally { |
| 9182 | Binder.restoreCallingIdentity(identity); |
| 9183 | } |
| 9184 | } |
| 9185 | |
| 9186 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9187 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9188 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9189 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9190 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9191 | if (iccRecords == null) { |
| 9192 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9193 | return false; |
| 9194 | } |
| 9195 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9196 | } |
| 9197 | |
| 9198 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9199 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9200 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9201 | if (callingPackage == null) { |
| 9202 | callingPackage = getCurrentPackageName(); |
| 9203 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9204 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9205 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9206 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9207 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9208 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9209 | } |
| 9210 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9211 | Intent intent = new Intent(); |
| 9212 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9213 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9214 | // Bring up choose default SMS subscription dialog right now |
| 9215 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9216 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9217 | mApp.startActivity(intent); |
| 9218 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9219 | |
| 9220 | @Override |
| 9221 | public String getMmsUAProfUrl(int subId) { |
| 9222 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9223 | final long identity = Binder.clearCallingIdentity(); |
| 9224 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9225 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9226 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9227 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9228 | return carrierUAProfUrl; |
| 9229 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9230 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9231 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9232 | } finally { |
| 9233 | Binder.restoreCallingIdentity(identity); |
| 9234 | } |
| 9235 | } |
| 9236 | |
| 9237 | @Override |
| 9238 | public String getMmsUserAgent(int subId) { |
| 9239 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9240 | final long identity = Binder.clearCallingIdentity(); |
| 9241 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9242 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9243 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9244 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9245 | return carrierUserAgent; |
| 9246 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9247 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9248 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9249 | } finally { |
| 9250 | Binder.restoreCallingIdentity(identity); |
| 9251 | } |
| 9252 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9253 | |
| 9254 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9255 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9256 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9257 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9258 | final long identity = Binder.clearCallingIdentity(); |
| 9259 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9260 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9261 | if (phone == null) return false; |
| 9262 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9263 | switch (policy) { |
| 9264 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9265 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9266 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9267 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9268 | default: |
| 9269 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9270 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9271 | } finally { |
| 9272 | Binder.restoreCallingIdentity(identity); |
| 9273 | } |
| 9274 | } |
| 9275 | |
| 9276 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 9277 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9278 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9279 | enforceModifyPermission(); |
| 9280 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9281 | final long identity = Binder.clearCallingIdentity(); |
| 9282 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9283 | Phone phone = getPhone(subscriptionId); |
| 9284 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9285 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9286 | switch (policy) { |
| 9287 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9288 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9289 | break; |
| 9290 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9291 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9292 | break; |
| 9293 | default: |
| 9294 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9295 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9296 | } finally { |
| 9297 | Binder.restoreCallingIdentity(identity); |
| 9298 | } |
| 9299 | } |
| 9300 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9301 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9302 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9303 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9304 | * otherwise. |
| 9305 | */ |
| 9306 | @Override |
| 9307 | public void setCepEnabled(boolean isCepEnabled) { |
| 9308 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9309 | |
| 9310 | final long identity = Binder.clearCallingIdentity(); |
| 9311 | try { |
| 9312 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9313 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9314 | Phone defaultPhone = phone.getImsPhone(); |
| 9315 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9316 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9317 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9318 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9319 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9320 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9321 | + imsPhone.getMsisdn()); |
| 9322 | } |
| 9323 | } |
| 9324 | } finally { |
| 9325 | Binder.restoreCallingIdentity(identity); |
| 9326 | } |
| 9327 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9328 | |
| 9329 | /** |
| 9330 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9331 | * |
| 9332 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9333 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9334 | * before being read. |
| 9335 | */ |
| 9336 | @Override |
| 9337 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9338 | isCompressed) { |
| 9339 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9340 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9341 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9342 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9343 | } |
| 9344 | if (!isImsAvailableOnDevice()) { |
| 9345 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9346 | "IMS not available on device."); |
| 9347 | } |
| 9348 | |
| 9349 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9350 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9351 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9352 | } finally { |
| 9353 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9354 | } |
| 9355 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9356 | |
| 9357 | @Override |
| 9358 | public boolean isIccLockEnabled(int subId) { |
| 9359 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9360 | |
| 9361 | // Now that all security checks passes, perform the operation as ourselves. |
| 9362 | final long identity = Binder.clearCallingIdentity(); |
| 9363 | try { |
| 9364 | Phone phone = getPhone(subId); |
| 9365 | if (phone != null && phone.getIccCard() != null) { |
| 9366 | return phone.getIccCard().getIccLockEnabled(); |
| 9367 | } else { |
| 9368 | return false; |
| 9369 | } |
| 9370 | } finally { |
| 9371 | Binder.restoreCallingIdentity(identity); |
| 9372 | } |
| 9373 | } |
| 9374 | |
| 9375 | /** |
| 9376 | * Set the ICC pin lock enabled or disabled. |
| 9377 | * |
| 9378 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9379 | * three cases: |
| 9380 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9381 | * successfully. |
| 9382 | * - Positive number and zero for remaining password attempts. |
| 9383 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9384 | * |
| 9385 | */ |
| 9386 | @Override |
| 9387 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9388 | enforceModifyPermission(); |
| 9389 | |
| 9390 | Phone phone = getPhone(subId); |
| 9391 | if (phone == null) { |
| 9392 | return 0; |
| 9393 | } |
| 9394 | // Now that all security checks passes, perform the operation as ourselves. |
| 9395 | final long identity = Binder.clearCallingIdentity(); |
| 9396 | try { |
| 9397 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9398 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9399 | return attemptsRemaining; |
| 9400 | |
| 9401 | } catch (Exception e) { |
| 9402 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9403 | } finally { |
| 9404 | Binder.restoreCallingIdentity(identity); |
| 9405 | } |
| 9406 | return 0; |
| 9407 | } |
| 9408 | |
| 9409 | /** |
| 9410 | * Change the ICC password used in ICC pin lock. |
| 9411 | * |
| 9412 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9413 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9414 | * - Positive number and zero for remaining password attempts. |
| 9415 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9416 | * |
| 9417 | */ |
| 9418 | @Override |
| 9419 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9420 | enforceModifyPermission(); |
| 9421 | |
| 9422 | Phone phone = getPhone(subId); |
| 9423 | if (phone == null) { |
| 9424 | return 0; |
| 9425 | } |
| 9426 | // Now that all security checks passes, perform the operation as ourselves. |
| 9427 | final long identity = Binder.clearCallingIdentity(); |
| 9428 | try { |
| 9429 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9430 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9431 | return attemptsRemaining; |
| 9432 | |
| 9433 | } catch (Exception e) { |
| 9434 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9435 | } finally { |
| 9436 | Binder.restoreCallingIdentity(identity); |
| 9437 | } |
| 9438 | return 0; |
| 9439 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9440 | |
| 9441 | /** |
| 9442 | * Request for receiving user activity notification |
| 9443 | */ |
| 9444 | @Override |
| 9445 | public void requestUserActivityNotification() { |
| 9446 | if (!mNotifyUserActivity.get() |
| 9447 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9448 | mNotifyUserActivity.set(true); |
| 9449 | } |
| 9450 | } |
| 9451 | |
| 9452 | /** |
| 9453 | * Called when userActivity is signalled in the power manager. |
| 9454 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9455 | */ |
| 9456 | @Override |
| 9457 | public void userActivity() { |
| 9458 | // *************************************** |
| 9459 | // * Inherited from PhoneWindowManager * |
| 9460 | // *************************************** |
| 9461 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9462 | // WITH ITS LOCKS HELD. |
| 9463 | // |
| 9464 | // This code must be VERY careful about the locks |
| 9465 | // it acquires. |
| 9466 | // In fact, the current code acquires way too many, |
| 9467 | // and probably has lurking deadlocks. |
| 9468 | |
| 9469 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9470 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9471 | } |
| 9472 | |
| 9473 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9474 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9475 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9476 | } |
| 9477 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9478 | |
| 9479 | @Override |
| 9480 | public boolean canConnectTo5GInDsdsMode() { |
| 9481 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9482 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9483 | |
| 9484 | @Override |
| 9485 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9486 | String callingFeatureId) { |
| 9487 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9488 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9489 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9490 | } |
| 9491 | |
| 9492 | Phone phone = getPhone(subId); |
| 9493 | if (phone == null) { |
| 9494 | throw new RuntimeException("phone is not available"); |
| 9495 | } |
| 9496 | // Now that all security checks passes, perform the operation as ourselves. |
| 9497 | final long identity = Binder.clearCallingIdentity(); |
| 9498 | try { |
| 9499 | return phone.getEquivalentHomePlmns(); |
| 9500 | } finally { |
| 9501 | Binder.restoreCallingIdentity(identity); |
| 9502 | } |
| 9503 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9504 | |
| 9505 | @Override |
| 9506 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 9507 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 9508 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame^] | 9509 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9510 | if (radioInterfaceCapabilities == null) { |
| 9511 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9512 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 9513 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9514 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9515 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9516 | @Override |
| 9517 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 9518 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9519 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 9520 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9521 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 9522 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9523 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9524 | if (DBG) { |
| 9525 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 9526 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 9527 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 9528 | } |
| 9529 | |
| 9530 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 9531 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 9532 | || appType > TelephonyManager.APPTYPE_ISIM |
| 9533 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 9534 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 9535 | if (callback != null) { |
| 9536 | try { |
| 9537 | callback.onAuthenticationFailure( |
| 9538 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 9539 | } catch (RemoteException exception) { |
| 9540 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 9541 | } |
| 9542 | return; |
| 9543 | } |
| 9544 | } |
| 9545 | |
| 9546 | final long token = Binder.clearCallingIdentity(); |
| 9547 | try { |
| 9548 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 9549 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 9550 | forceBootStrapping, callback)); |
| 9551 | } finally { |
| 9552 | Binder.restoreCallingIdentity(token); |
| 9553 | } |
| 9554 | } |
| 9555 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9556 | /** |
| 9557 | * Attempts to set the radio power state for thermal reason. This does not guarantee that the |
| 9558 | * requested radio power state will actually be set. See {@link |
| 9559 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9560 | * |
| 9561 | * @param subId the subscription ID of the phone requesting to set the radio power state. |
| 9562 | * @param enable {@code true} if trying to turn radio on. |
| 9563 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9564 | * false}. |
| 9565 | */ |
| 9566 | private boolean setRadioPowerForThermal(int subId, boolean enable) { |
| 9567 | Phone phone = getPhone(subId); |
| 9568 | if (phone != null) { |
| 9569 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 9570 | return true; |
| 9571 | } |
| 9572 | return false; |
| 9573 | } |
| 9574 | |
| 9575 | private int handleDataThrottlingRequest(int subId, |
| 9576 | DataThrottlingRequest dataThrottlingRequest) { |
| 9577 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 9578 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9579 | if (!setRadioPowerForThermal(subId, true)) { |
| 9580 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9581 | } |
| 9582 | |
| 9583 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 9584 | |
| 9585 | int thermalMitigationResult = |
| 9586 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
| 9587 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 9588 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 9589 | } |
| 9590 | return thermalMitigationResult; |
| 9591 | } |
| 9592 | |
| 9593 | /** |
| 9594 | * Thermal mitigation request to control functionalities at modem. |
| 9595 | * |
| 9596 | * @param subId the id of the subscription. |
| 9597 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
| 9598 | * |
| 9599 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 9600 | */ |
| 9601 | @Override |
| 9602 | @ThermalMitigationResult |
| 9603 | public int sendThermalMitigationRequest( |
| 9604 | int subId, |
| 9605 | ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException { |
| 9606 | enforceModifyPermission(); |
| 9607 | |
| 9608 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9609 | final long identity = Binder.clearCallingIdentity(); |
| 9610 | |
| 9611 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 9612 | try { |
| 9613 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 9614 | switch (thermalMitigationAction) { |
| 9615 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 9616 | thermalMitigationResult = |
| 9617 | handleDataThrottlingRequest(subId, |
| 9618 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 9619 | break; |
| 9620 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 9621 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9622 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 9623 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 9624 | } |
| 9625 | |
| 9626 | // Ensure that radio is on. If not able to power on due to phone being |
| 9627 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9628 | if (!setRadioPowerForThermal(subId, true)) { |
| 9629 | thermalMitigationResult = |
| 9630 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9631 | break; |
| 9632 | } |
| 9633 | |
| 9634 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 9635 | false); |
| 9636 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9637 | break; |
| 9638 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 9639 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9640 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 9641 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 9642 | } |
| 9643 | |
| 9644 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 9645 | if (registry != null) { |
| 9646 | TelephonyConnectionService service = |
| 9647 | registry.getTelephonyConnectionService(); |
| 9648 | Phone phone = getPhone(subId); |
| 9649 | if (phone == null) { |
| 9650 | thermalMitigationResult = |
| 9651 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9652 | break; |
| 9653 | } |
| 9654 | |
| 9655 | if (PhoneConstantConversions.convertCallState(phone.getState()) |
| 9656 | != TelephonyManager.CALL_STATE_IDLE |
| 9657 | || phone.isInEmergencySmsMode() || phone.isInEcm() |
| 9658 | || (service != null && service.isEmergencyCallPending())) { |
| 9659 | String errorMessage = "Phone state is not valid. call state = " |
| 9660 | + PhoneConstantConversions.convertCallState(phone.getState()) |
| 9661 | + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode() |
| 9662 | + " isInEmergencyCallbackMode = " + phone.isInEcm(); |
| 9663 | errorMessage += service == null |
| 9664 | ? " TelephonyConnectionService is null" |
| 9665 | : " isEmergencyCallPending = " |
| 9666 | + service.isEmergencyCallPending(); |
| 9667 | Log.e(LOG_TAG, errorMessage); |
| 9668 | thermalMitigationResult = |
| 9669 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 9670 | break; |
| 9671 | } |
| 9672 | } else { |
| 9673 | thermalMitigationResult = |
| 9674 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9675 | break; |
| 9676 | } |
| 9677 | |
| 9678 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 9679 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9680 | if (!setRadioPowerForThermal(subId, false)) { |
| 9681 | thermalMitigationResult = |
| 9682 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9683 | break; |
| 9684 | } |
| 9685 | thermalMitigationResult = |
| 9686 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9687 | break; |
| 9688 | default: |
| 9689 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 9690 | + "not exist. Requested action: " + thermalMitigationAction); |
| 9691 | } |
| 9692 | } catch (IllegalArgumentException e) { |
| 9693 | throw e; |
| 9694 | } catch (Exception e) { |
| 9695 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 9696 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 9697 | } finally { |
| 9698 | Binder.restoreCallingIdentity(identity); |
| 9699 | } |
| 9700 | |
| 9701 | if (DBG) { |
| 9702 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 9703 | + thermalMitigationResult); |
| 9704 | } |
| 9705 | |
| 9706 | return thermalMitigationResult; |
| 9707 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9708 | |
| 9709 | /** |
| 9710 | * Set the GbaService Package Name that Telephony will bind to. |
| 9711 | * |
| 9712 | * @param subId The sim that the GbaService is associated with. |
| 9713 | * @param packageName The name of the package to be replaced with. |
| 9714 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9715 | */ |
| 9716 | @Override |
| 9717 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 9718 | enforceModifyPermission(); |
| 9719 | |
| 9720 | final long identity = Binder.clearCallingIdentity(); |
| 9721 | try { |
| 9722 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 9723 | } finally { |
| 9724 | Binder.restoreCallingIdentity(identity); |
| 9725 | } |
| 9726 | } |
| 9727 | |
| 9728 | /** |
| 9729 | * Return the package name of the currently bound GbaService. |
| 9730 | * |
| 9731 | * @param subId The sim that the GbaService is associated with. |
| 9732 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 9733 | */ |
| 9734 | @Override |
| 9735 | public String getBoundGbaService(int subId) { |
| 9736 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 9737 | |
| 9738 | final long identity = Binder.clearCallingIdentity(); |
| 9739 | try { |
| 9740 | return getGbaManager(subId).getServicePackage(); |
| 9741 | } finally { |
| 9742 | Binder.restoreCallingIdentity(identity); |
| 9743 | } |
| 9744 | } |
| 9745 | |
| 9746 | /** |
| 9747 | * Set the release time for telephony to unbind GbaService. |
| 9748 | * |
| 9749 | * @param subId The sim that the GbaService is associated with. |
| 9750 | * @param interval The release time to unbind GbaService by millisecond. |
| 9751 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9752 | */ |
| 9753 | @Override |
| 9754 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 9755 | enforceModifyPermission(); |
| 9756 | |
| 9757 | final long identity = Binder.clearCallingIdentity(); |
| 9758 | try { |
| 9759 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 9760 | } finally { |
| 9761 | Binder.restoreCallingIdentity(identity); |
| 9762 | } |
| 9763 | } |
| 9764 | |
| 9765 | /** |
| 9766 | * Return the release time for telephony to unbind GbaService. |
| 9767 | * |
| 9768 | * @param subId The sim that the GbaService is associated with. |
| 9769 | * @return The release time to unbind GbaService by millisecond. |
| 9770 | */ |
| 9771 | @Override |
| 9772 | public int getGbaReleaseTime(int subId) { |
| 9773 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 9774 | |
| 9775 | final long identity = Binder.clearCallingIdentity(); |
| 9776 | try { |
| 9777 | return getGbaManager(subId).getReleaseTime(); |
| 9778 | } finally { |
| 9779 | Binder.restoreCallingIdentity(identity); |
| 9780 | } |
| 9781 | } |
| 9782 | |
| 9783 | private GbaManager getGbaManager(int subId) { |
| 9784 | GbaManager instance = GbaManager.getInstance(subId); |
| 9785 | if (instance == null) { |
| 9786 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 9787 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 9788 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 9789 | } |
| 9790 | return instance; |
| 9791 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9792 | |
| 9793 | /** |
| 9794 | * indicate whether the device and the carrier can support |
| 9795 | * RCS VoLTE single registration. |
| 9796 | */ |
| 9797 | @Override |
| 9798 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9799 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9800 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 9801 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9802 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9803 | |
| 9804 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9805 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9806 | } |
| 9807 | |
| 9808 | final long identity = Binder.clearCallingIdentity(); |
| 9809 | try { |
| 9810 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 9811 | if (rpm != null) { |
| 9812 | return rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 9813 | } |
| 9814 | return false; |
| 9815 | } finally { |
| 9816 | Binder.restoreCallingIdentity(identity); |
| 9817 | } |
| 9818 | } |
| 9819 | |
| 9820 | /** |
| 9821 | * Register RCS provisioning callback. |
| 9822 | */ |
| 9823 | @Override |
| 9824 | public void registerRcsProvisioningChangedCallback(int subId, |
| 9825 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9826 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9827 | Binder.getCallingUid(), "registerRcsProvisioningChangedCallback", |
| 9828 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9829 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9830 | |
| 9831 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9832 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9833 | } |
| 9834 | if (!isImsAvailableOnDevice()) { |
| 9835 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9836 | "IMS not available on device."); |
| 9837 | } |
| 9838 | |
| 9839 | final long identity = Binder.clearCallingIdentity(); |
| 9840 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9841 | if (!RcsProvisioningMonitor.getInstance() |
| 9842 | .registerRcsProvisioningChangedCallback(subId, callback)) { |
| 9843 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9844 | "Service not available for the subscription."); |
| 9845 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9846 | } finally { |
| 9847 | Binder.restoreCallingIdentity(identity); |
| 9848 | } |
| 9849 | } |
| 9850 | |
| 9851 | /** |
| 9852 | * Unregister RCS provisioning callback. |
| 9853 | */ |
| 9854 | @Override |
| 9855 | public void unregisterRcsProvisioningChangedCallback(int subId, |
| 9856 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9857 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9858 | Binder.getCallingUid(), "unregisterRcsProvisioningChangedCallback", |
| 9859 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9860 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9861 | |
| 9862 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9863 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9864 | } |
| 9865 | if (!isImsAvailableOnDevice()) { |
| 9866 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9867 | "IMS not available on device."); |
| 9868 | } |
| 9869 | |
| 9870 | final long identity = Binder.clearCallingIdentity(); |
| 9871 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9872 | RcsProvisioningMonitor.getInstance() |
| 9873 | .unregisterRcsProvisioningChangedCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9874 | } finally { |
| 9875 | Binder.restoreCallingIdentity(identity); |
| 9876 | } |
| 9877 | } |
| 9878 | |
| 9879 | /** |
| 9880 | * trigger RCS reconfiguration. |
| 9881 | */ |
| 9882 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9883 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 9884 | "triggerRcsReconfiguration", |
| 9885 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9886 | |
| 9887 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9888 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9889 | } |
| 9890 | if (!isImsAvailableOnDevice()) { |
| 9891 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9892 | "IMS not available on device."); |
| 9893 | } |
| 9894 | |
| 9895 | final long identity = Binder.clearCallingIdentity(); |
| 9896 | try { |
| 9897 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 9898 | } finally { |
| 9899 | Binder.restoreCallingIdentity(identity); |
| 9900 | } |
| 9901 | } |
| 9902 | |
| 9903 | /** |
| 9904 | * Provide the client configuration parameters of the RCS application. |
| 9905 | */ |
| 9906 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9907 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 9908 | "setRcsClientConfiguration", |
| 9909 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9910 | |
| 9911 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9912 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9913 | } |
| 9914 | if (!isImsAvailableOnDevice()) { |
| 9915 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9916 | "IMS not available on device."); |
| 9917 | } |
| 9918 | |
| 9919 | final long identity = Binder.clearCallingIdentity(); |
| 9920 | |
| 9921 | try { |
| 9922 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 9923 | if (configBinder == null) { |
| 9924 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
| 9925 | } else { |
| 9926 | configBinder.setRcsClientConfiguration(rcc); |
| 9927 | } |
| 9928 | } catch (RemoteException e) { |
| 9929 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
| 9930 | } finally { |
| 9931 | Binder.restoreCallingIdentity(identity); |
| 9932 | } |
| 9933 | } |
| 9934 | |
| 9935 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 9936 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 9937 | */ |
| 9938 | @Override |
| 9939 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 9940 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9941 | "setRcsSingleRegistrationTestModeEnabled"); |
| 9942 | |
| 9943 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 9944 | } |
| 9945 | |
| 9946 | /** |
| 9947 | * Gets the test mode for RCS VoLTE single registration. |
| 9948 | */ |
| 9949 | @Override |
| 9950 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 9951 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9952 | "getRcsSingleRegistrationTestModeEnabled"); |
| 9953 | |
| 9954 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 9955 | } |
| 9956 | |
| 9957 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9958 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 9959 | */ |
| 9960 | @Override |
| 9961 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 9962 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9963 | "setDeviceSingleRegistrationEnabledOverride"); |
| 9964 | enforceModifyPermission(); |
| 9965 | |
| 9966 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9967 | : Boolean.parseBoolean(enabledStr); |
| 9968 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 9969 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9970 | } |
| 9971 | |
| 9972 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 9973 | * Sends a device to device communication message. Only usable via shell. |
| 9974 | * @param message message to send. |
| 9975 | * @param value message value. |
| 9976 | */ |
| 9977 | @Override |
| 9978 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 9979 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 9980 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 9981 | enforceModifyPermission(); |
| 9982 | |
| 9983 | final long identity = Binder.clearCallingIdentity(); |
| 9984 | try { |
| 9985 | TelephonyConnectionService service = |
| 9986 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 9987 | if (service == null) { |
| 9988 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 9989 | return; |
| 9990 | } |
| 9991 | service.sendTestDeviceToDeviceMessage(message, value); |
| 9992 | } finally { |
| 9993 | Binder.restoreCallingIdentity(identity); |
| 9994 | } |
| 9995 | } |
| 9996 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 9997 | /** |
| 9998 | * Sets the specified device to device transport active. |
| 9999 | * @param transport The transport to set active. |
| 10000 | */ |
| 10001 | @Override |
| 10002 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10003 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10004 | "setActiveDeviceToDeviceTransport"); |
| 10005 | enforceModifyPermission(); |
| 10006 | |
| 10007 | final long identity = Binder.clearCallingIdentity(); |
| 10008 | try { |
| 10009 | TelephonyConnectionService service = |
| 10010 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10011 | if (service == null) { |
| 10012 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10013 | return; |
| 10014 | } |
| 10015 | service.setActiveDeviceToDeviceTransport(transport); |
| 10016 | } finally { |
| 10017 | Binder.restoreCallingIdentity(identity); |
| 10018 | } |
| 10019 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10020 | |
| 10021 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10022 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10023 | */ |
| 10024 | @Override |
| 10025 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10026 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10027 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10028 | } |
| 10029 | |
| 10030 | /** |
| 10031 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10032 | */ |
| 10033 | @Override |
| 10034 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10035 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10036 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10037 | enforceModifyPermission(); |
| 10038 | |
| 10039 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10040 | : Boolean.parseBoolean(enabledStr); |
| 10041 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10042 | subId, enabled); |
| 10043 | } |
| 10044 | |
| 10045 | /** |
| 10046 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10047 | */ |
| 10048 | @Override |
| 10049 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10050 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 10051 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 10052 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10053 | |
| 10054 | /** |
| 10055 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 10056 | * their mobile plan. |
| 10057 | */ |
| 10058 | @Override |
| 10059 | public String getMobileProvisioningUrl() { |
| 10060 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 10061 | final long identity = Binder.clearCallingIdentity(); |
| 10062 | try { |
| 10063 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 10064 | } finally { |
| 10065 | Binder.restoreCallingIdentity(identity); |
| 10066 | } |
| 10067 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10068 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10069 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 10070 | * Get the EAB contact from the EAB database. |
| 10071 | */ |
| 10072 | @Override |
| 10073 | public String getContactFromEab(String contact) { |
| 10074 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 10075 | enforceModifyPermission(); |
| 10076 | final long identity = Binder.clearCallingIdentity(); |
| 10077 | try { |
| 10078 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 10079 | } finally { |
| 10080 | Binder.restoreCallingIdentity(identity); |
| 10081 | } |
| 10082 | } |
| 10083 | |
| 10084 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10085 | * Remove the EAB contacts from the EAB database. |
| 10086 | */ |
| 10087 | @Override |
| 10088 | public int removeContactFromEab(int subId, String contacts) { |
| 10089 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 10090 | enforceModifyPermission(); |
| 10091 | final long identity = Binder.clearCallingIdentity(); |
| 10092 | try { |
| 10093 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 10094 | } finally { |
| 10095 | Binder.restoreCallingIdentity(identity); |
| 10096 | } |
| 10097 | } |
| 10098 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10099 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10100 | public boolean getDeviceUceEnabled() { |
| 10101 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 10102 | final long identity = Binder.clearCallingIdentity(); |
| 10103 | try { |
| 10104 | return mApp.getDeviceUceEnabled(); |
| 10105 | } finally { |
| 10106 | Binder.restoreCallingIdentity(identity); |
| 10107 | } |
| 10108 | } |
| 10109 | |
| 10110 | @Override |
| 10111 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 10112 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 10113 | final long identity = Binder.clearCallingIdentity(); |
| 10114 | try { |
| 10115 | mApp.setDeviceUceEnabled(isEnabled); |
| 10116 | } finally { |
| 10117 | Binder.restoreCallingIdentity(identity); |
| 10118 | } |
| 10119 | } |
| 10120 | |
| 10121 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10122 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10123 | String callingPackage) { |
| 10124 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10125 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 10126 | |
| 10127 | final int callingUid = Binder.getCallingUid(); |
| 10128 | // Verify that tha callingPackage belongs to the calling UID |
| 10129 | mApp.getSystemService(AppOpsManager.class) |
| 10130 | .checkPackage(callingUid, callingPackage); |
| 10131 | |
| 10132 | validateSignalStrengthUpdateRequest(request, callingUid); |
| 10133 | |
| 10134 | final long identity = Binder.clearCallingIdentity(); |
| 10135 | try { |
| 10136 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10137 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10138 | |
| 10139 | if (result instanceof IllegalStateException) { |
| 10140 | throw (IllegalStateException) result; |
| 10141 | } |
| 10142 | } finally { |
| 10143 | Binder.restoreCallingIdentity(identity); |
| 10144 | } |
| 10145 | } |
| 10146 | |
| 10147 | @Override |
| 10148 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10149 | String callingPackage) { |
| 10150 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10151 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 10152 | |
| 10153 | final int callingUid = Binder.getCallingUid(); |
| 10154 | // Verify that tha callingPackage belongs to the calling UID |
| 10155 | mApp.getSystemService(AppOpsManager.class) |
| 10156 | .checkPackage(callingUid, callingPackage); |
| 10157 | |
| 10158 | final long identity = Binder.clearCallingIdentity(); |
| 10159 | try { |
| 10160 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10161 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10162 | |
| 10163 | if (result instanceof IllegalStateException) { |
| 10164 | throw (IllegalStateException) result; |
| 10165 | } |
| 10166 | } finally { |
| 10167 | Binder.restoreCallingIdentity(identity); |
| 10168 | } |
| 10169 | } |
| 10170 | |
| 10171 | private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request, |
| 10172 | int callingUid) { |
| 10173 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 10174 | // phone/system process do not have further restriction on request |
| 10175 | return; |
| 10176 | } |
| 10177 | |
| 10178 | // Applications has restrictions on how to use the request: |
| 10179 | // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle |
| 10180 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
| 10181 | // This is not system caller which has been checked above |
| 10182 | throw new IllegalArgumentException( |
| 10183 | "Only system can set isSystemThresholdReportingRequestedWhileIdle"); |
| 10184 | } |
| 10185 | |
| 10186 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 10187 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 10188 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 10189 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 10190 | || info.isEnabled()) { |
| 10191 | throw new IllegalArgumentException( |
| 10192 | "Only system can set hide fields in SignalThresholdInfo"); |
| 10193 | } |
| 10194 | |
| 10195 | // Thresholds length for each RAN need in range. This has been validated in |
| 10196 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 10197 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 10198 | final int[] thresholds = info.getThresholds(); |
| 10199 | Objects.requireNonNull(thresholds); |
| 10200 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 10201 | || thresholds.length |
| 10202 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 10203 | throw new IllegalArgumentException( |
| 10204 | "thresholds length is out of range: " + thresholds.length); |
| 10205 | } |
| 10206 | } |
| 10207 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10208 | |
| 10209 | /** |
| 10210 | * Gets the current phone capability. |
| 10211 | * |
| 10212 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 10213 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 10214 | * It's used to evaluate possible phone config change, for example from single |
| 10215 | * SIM device to multi-SIM device. |
| 10216 | */ |
| 10217 | @Override |
| 10218 | public PhoneCapability getPhoneCapability() { |
| 10219 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 10220 | final long identity = Binder.clearCallingIdentity(); |
| 10221 | try { |
| 10222 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 10223 | } finally { |
| 10224 | Binder.restoreCallingIdentity(identity); |
| 10225 | } |
| 10226 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 10227 | |
| 10228 | /** |
| 10229 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 10230 | * required to be done shortly after the API is invoked. |
| 10231 | */ |
| 10232 | @Override |
| 10233 | @TelephonyManager.PrepareUnattendedRebootResult |
| 10234 | public int prepareForUnattendedReboot() { |
| 10235 | enforceRebootPermission(); |
| 10236 | |
| 10237 | final long identity = Binder.clearCallingIdentity(); |
| 10238 | try { |
| 10239 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null); |
| 10240 | } finally { |
| 10241 | Binder.restoreCallingIdentity(identity); |
| 10242 | } |
| 10243 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 10244 | } |