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; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 166 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 169 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 170 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 171 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 173 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 175 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 177 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 178 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 179 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 181 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 183 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 184 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 185 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 186 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 187 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 188 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 189 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 190 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 191 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 192 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 193 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 194 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 195 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 196 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 197 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 198 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 199 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 200 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 201 | import com.android.services.telephony.TelecomAccountRegistry; |
| 202 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 203 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 204 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 205 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 206 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 207 | import java.io.IOException; |
| 208 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 209 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 210 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 211 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 212 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 213 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 214 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 215 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 216 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 217 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 218 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 219 | import java.util.Set; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 220 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 221 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 222 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 223 | |
| 224 | /** |
| 225 | * Implementation of the ITelephony interface. |
| 226 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 227 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 228 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 229 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 230 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 231 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 232 | |
| 233 | // Message codes used with mMainThreadHandler |
| 234 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 235 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 236 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 237 | private static final int CMD_OPEN_CHANNEL = 9; |
| 238 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 239 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 240 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 241 | private static final int CMD_NV_READ_ITEM = 13; |
| 242 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 243 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 244 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 245 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 246 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 247 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 248 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 249 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 250 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 251 | private static final int CMD_SEND_ENVELOPE = 25; |
| 252 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 253 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 254 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 255 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 256 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 257 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 258 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 259 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 260 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 261 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 262 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 263 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 264 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 265 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 266 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 267 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 268 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 269 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 270 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 271 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 272 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 273 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 274 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 275 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 276 | private static final int CMD_SWITCH_SLOTS = 50; |
| 277 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 278 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 279 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 280 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 281 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 282 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 283 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 284 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 285 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 286 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 287 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 288 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 289 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 290 | private static final int CMD_MODEM_REBOOT = 64; |
| 291 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 292 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 293 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 294 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 295 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 296 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 297 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 298 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 299 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 300 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 301 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 302 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 303 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 304 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 305 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 306 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 307 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 308 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 309 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 310 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 311 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 312 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 313 | private static final int CMD_GET_CALL_WAITING = 87; |
| 314 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 315 | private static final int CMD_SET_CALL_WAITING = 89; |
| 316 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 317 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 318 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 319 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 320 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 321 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 322 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 323 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 324 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 325 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 326 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 327 | private static final int CMD_SET_SIM_POWER = 101; |
| 328 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 329 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 330 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 331 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 332 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 333 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 334 | 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] | 335 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 336 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 337 | // Parameters of select command. |
| 338 | private static final int SELECT_COMMAND = 0xA4; |
| 339 | private static final int SELECT_P1 = 0x04; |
| 340 | private static final int SELECT_P2 = 0; |
| 341 | private static final int SELECT_P3 = 0x10; |
| 342 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 343 | /** The singleton instance. */ |
| 344 | private static PhoneInterfaceManager sInstance; |
| 345 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 346 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 347 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 348 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 349 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 350 | private AppOpsManager mAppOps; |
| 351 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 352 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 353 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 354 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 355 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 356 | /** User Activity */ |
| 357 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 358 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 359 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 360 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 361 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 362 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 363 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 364 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 365 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 366 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 367 | // String to store multi SIM allowed |
| 368 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 369 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 370 | // The AID of ISD-R. |
| 371 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 372 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 373 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 374 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 375 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 376 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 377 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 378 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
| 379 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 380 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 381 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 382 | */ |
| 383 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 384 | "reset_network_erase_modem_config_enabled"; |
| 385 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 386 | private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds |
| 387 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 388 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 389 | * A request object to use for transmitting data to an ICC. |
| 390 | */ |
| 391 | private static final class IccAPDUArgument { |
| 392 | public int channel, cla, command, p1, p2, p3; |
| 393 | public String data; |
| 394 | |
| 395 | public IccAPDUArgument(int channel, int cla, int command, |
| 396 | int p1, int p2, int p3, String data) { |
| 397 | this.channel = channel; |
| 398 | this.cla = cla; |
| 399 | this.command = command; |
| 400 | this.p1 = p1; |
| 401 | this.p2 = p2; |
| 402 | this.p3 = p3; |
| 403 | this.data = data; |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 408 | * A request object to use for transmitting data to an ICC. |
| 409 | */ |
| 410 | private static final class ManualNetworkSelectionArgument { |
| 411 | public OperatorInfo operatorInfo; |
| 412 | public boolean persistSelection; |
| 413 | |
| 414 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 415 | this.operatorInfo = operatorInfo; |
| 416 | this.persistSelection = persistSelection; |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 421 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 422 | * request after sending. The main thread will notify the request when it is complete. |
| 423 | */ |
| 424 | private static final class MainThreadRequest { |
| 425 | /** The argument to use for the request */ |
| 426 | public Object argument; |
| 427 | /** The result of the request that is run on the main thread */ |
| 428 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 429 | // The subscriber id that this request applies to. Defaults to |
| 430 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 431 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 432 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 433 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 434 | public Phone phone; |
| 435 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 436 | public WorkSource workSource; |
| 437 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 438 | public MainThreadRequest(Object argument) { |
| 439 | this.argument = argument; |
| 440 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 441 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 442 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 443 | this.argument = argument; |
| 444 | if (phone != null) { |
| 445 | this.phone = phone; |
| 446 | } |
| 447 | this.workSource = workSource; |
| 448 | } |
| 449 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 450 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 451 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 452 | if (subId != null) { |
| 453 | this.subId = subId; |
| 454 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 455 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 456 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 457 | } |
| 458 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 459 | private static final class IncomingThirdPartyCallArgs { |
| 460 | public final ComponentName component; |
| 461 | public final String callId; |
| 462 | public final String callerDisplayName; |
| 463 | |
| 464 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 465 | String callerDisplayName) { |
| 466 | this.component = component; |
| 467 | this.callId = callId; |
| 468 | this.callerDisplayName = callerDisplayName; |
| 469 | } |
| 470 | } |
| 471 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 472 | /** |
| 473 | * A handler that processes messages on the main thread in the phone process. Since many |
| 474 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 475 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 476 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 477 | * on, which will be notified when the operation completes and will contain the result of the |
| 478 | * request. |
| 479 | * |
| 480 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 481 | * note that request.result must be set to something non-null for the calling thread to |
| 482 | * unblock. |
| 483 | */ |
| 484 | private final class MainThreadHandler extends Handler { |
| 485 | @Override |
| 486 | public void handleMessage(Message msg) { |
| 487 | MainThreadRequest request; |
| 488 | Message onCompleted; |
| 489 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 490 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 491 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 492 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 493 | |
| 494 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 495 | case CMD_HANDLE_USSD_REQUEST: { |
| 496 | request = (MainThreadRequest) msg.obj; |
| 497 | final Phone phone = getPhoneFromRequest(request); |
| 498 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 499 | String ussdRequest = ussdObject.first; |
| 500 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 501 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 502 | if (!isUssdApiAllowed(request.subId)) { |
| 503 | // Carrier does not support use of this API, return failure. |
| 504 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 505 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 506 | Bundle returnData = new Bundle(); |
| 507 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 508 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 509 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 510 | request.result = true; |
| 511 | notifyRequester(request); |
| 512 | return; |
| 513 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 514 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 515 | try { |
| 516 | request.result = phone != null |
| 517 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 518 | } catch (CallStateException cse) { |
| 519 | request.result = false; |
| 520 | } |
| 521 | // Wake up the requesting thread |
| 522 | notifyRequester(request); |
| 523 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 524 | } |
| 525 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 526 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 527 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 528 | final Phone phone = getPhoneFromRequest(request); |
| 529 | request.result = phone != null ? |
| 530 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 531 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 532 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 533 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 534 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 535 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 536 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 537 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 538 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 539 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 540 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 541 | if (uiccCard == null) { |
| 542 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 543 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 544 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 545 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 546 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 547 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 548 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 549 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 550 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 551 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 552 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 553 | break; |
| 554 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 555 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 556 | ar = (AsyncResult) msg.obj; |
| 557 | request = (MainThreadRequest) ar.userObj; |
| 558 | if (ar.exception == null && ar.result != null) { |
| 559 | request.result = ar.result; |
| 560 | } else { |
| 561 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 562 | if (ar.result == null) { |
| 563 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 564 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 565 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 566 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 567 | } else { |
| 568 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 569 | } |
| 570 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 571 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 572 | break; |
| 573 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 574 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 575 | request = (MainThreadRequest) msg.obj; |
| 576 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 577 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 578 | if (uiccCard == null) { |
| 579 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 580 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 581 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 582 | } else { |
| 583 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 584 | request); |
| 585 | uiccCard.iccTransmitApduBasicChannel( |
| 586 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 587 | iccArgument.p3, iccArgument.data, onCompleted); |
| 588 | } |
| 589 | break; |
| 590 | |
| 591 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 592 | ar = (AsyncResult) msg.obj; |
| 593 | request = (MainThreadRequest) ar.userObj; |
| 594 | if (ar.exception == null && ar.result != null) { |
| 595 | request.result = ar.result; |
| 596 | } else { |
| 597 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 598 | if (ar.result == null) { |
| 599 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 600 | } else if (ar.exception instanceof CommandException) { |
| 601 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 602 | ar.exception); |
| 603 | } else { |
| 604 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 605 | } |
| 606 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 607 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 608 | break; |
| 609 | |
| 610 | case CMD_EXCHANGE_SIM_IO: |
| 611 | request = (MainThreadRequest) msg.obj; |
| 612 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 613 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 614 | if (uiccCard == null) { |
| 615 | loge("iccExchangeSimIO: No UICC"); |
| 616 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 617 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 618 | } else { |
| 619 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 620 | request); |
| 621 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 622 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 623 | iccArgument.data, onCompleted); |
| 624 | } |
| 625 | break; |
| 626 | |
| 627 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 628 | ar = (AsyncResult) msg.obj; |
| 629 | request = (MainThreadRequest) ar.userObj; |
| 630 | if (ar.exception == null && ar.result != null) { |
| 631 | request.result = ar.result; |
| 632 | } else { |
| 633 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 634 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 635 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 636 | break; |
| 637 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 638 | case CMD_SEND_ENVELOPE: |
| 639 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 640 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 641 | if (uiccCard == null) { |
| 642 | loge("sendEnvelopeWithStatus: No UICC"); |
| 643 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 644 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 645 | } else { |
| 646 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 647 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 648 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 649 | break; |
| 650 | |
| 651 | case EVENT_SEND_ENVELOPE_DONE: |
| 652 | ar = (AsyncResult) msg.obj; |
| 653 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 654 | if (ar.exception == null && ar.result != null) { |
| 655 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 656 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 657 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 658 | if (ar.result == null) { |
| 659 | loge("sendEnvelopeWithStatus: Empty response"); |
| 660 | } else if (ar.exception instanceof CommandException) { |
| 661 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 662 | ar.exception); |
| 663 | } else { |
| 664 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 665 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 666 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 667 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 668 | break; |
| 669 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 670 | case CMD_OPEN_CHANNEL: |
| 671 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 672 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 673 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 674 | if (uiccCard == null) { |
| 675 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 676 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 677 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 678 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 679 | } else { |
| 680 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 681 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 682 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 683 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 684 | break; |
| 685 | |
| 686 | case EVENT_OPEN_CHANNEL_DONE: |
| 687 | ar = (AsyncResult) msg.obj; |
| 688 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 689 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 690 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 691 | int[] result = (int[]) ar.result; |
| 692 | int channelId = result[0]; |
| 693 | byte[] selectResponse = null; |
| 694 | if (result.length > 1) { |
| 695 | selectResponse = new byte[result.length - 1]; |
| 696 | for (int i = 1; i < result.length; ++i) { |
| 697 | selectResponse[i - 1] = (byte) result[i]; |
| 698 | } |
| 699 | } |
| 700 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 701 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 702 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 703 | if (ar.result == null) { |
| 704 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 705 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 706 | if (ar.exception != null) { |
| 707 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 708 | } |
| 709 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 710 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 711 | if (ar.exception instanceof CommandException) { |
| 712 | CommandException.Error error = |
| 713 | ((CommandException) (ar.exception)).getCommandError(); |
| 714 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 715 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 716 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 717 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 718 | } |
| 719 | } |
| 720 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 721 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 722 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 723 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 724 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 725 | break; |
| 726 | |
| 727 | case CMD_CLOSE_CHANNEL: |
| 728 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 729 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 730 | if (uiccCard == null) { |
| 731 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 732 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 733 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 734 | } else { |
| 735 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 736 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 737 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 738 | break; |
| 739 | |
| 740 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 741 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 742 | break; |
| 743 | |
| 744 | case CMD_NV_READ_ITEM: |
| 745 | request = (MainThreadRequest) msg.obj; |
| 746 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 747 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 748 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 749 | break; |
| 750 | |
| 751 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 752 | ar = (AsyncResult) msg.obj; |
| 753 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 754 | if (ar.exception == null && ar.result != null) { |
| 755 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 756 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 757 | request.result = ""; |
| 758 | if (ar.result == null) { |
| 759 | loge("nvReadItem: Empty response"); |
| 760 | } else if (ar.exception instanceof CommandException) { |
| 761 | loge("nvReadItem: CommandException: " + |
| 762 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 763 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 764 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 765 | } |
| 766 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 767 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 768 | break; |
| 769 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 770 | case CMD_NV_WRITE_ITEM: |
| 771 | request = (MainThreadRequest) msg.obj; |
| 772 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 773 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 774 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 775 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 776 | break; |
| 777 | |
| 778 | case EVENT_NV_WRITE_ITEM_DONE: |
| 779 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 780 | break; |
| 781 | |
| 782 | case CMD_NV_WRITE_CDMA_PRL: |
| 783 | request = (MainThreadRequest) msg.obj; |
| 784 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 785 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 786 | break; |
| 787 | |
| 788 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 789 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 790 | break; |
| 791 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 792 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 793 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 794 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 795 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 796 | break; |
| 797 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 798 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 799 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 800 | break; |
| 801 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 802 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 803 | request = (MainThreadRequest) msg.obj; |
| 804 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 805 | request); |
| 806 | Phone phone = getPhoneFromRequest(request); |
| 807 | if (phone != null) { |
| 808 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 809 | } else { |
| 810 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 811 | request.result = false; |
| 812 | notifyRequester(request); |
| 813 | } |
| 814 | break; |
| 815 | } |
| 816 | |
| 817 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 818 | ar = (AsyncResult) msg.obj; |
| 819 | request = (MainThreadRequest) ar.userObj; |
| 820 | if (ar.exception == null && ar.result != null) { |
| 821 | request.result = ar.result; |
| 822 | } else { |
| 823 | // request.result must be set to something non-null |
| 824 | // for the calling thread to unblock |
| 825 | if (request.result != null) { |
| 826 | request.result = ar.result; |
| 827 | } else { |
| 828 | request.result = false; |
| 829 | } |
| 830 | if (ar.result == null) { |
| 831 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 832 | } else if (ar.exception instanceof CommandException) { |
| 833 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 834 | + ar.exception); |
| 835 | } else { |
| 836 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 837 | } |
| 838 | } |
| 839 | notifyRequester(request); |
| 840 | break; |
| 841 | |
| 842 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 843 | request = (MainThreadRequest) msg.obj; |
| 844 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 845 | Phone phone = getPhoneFromRequest(request); |
| 846 | if (phone != null) { |
| 847 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 848 | request.workSource); |
| 849 | } else { |
| 850 | loge("enableNrDualConnectivity: No phone object"); |
| 851 | request.result = |
| 852 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 853 | notifyRequester(request); |
| 854 | } |
| 855 | break; |
| 856 | } |
| 857 | |
| 858 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 859 | ar = (AsyncResult) msg.obj; |
| 860 | request = (MainThreadRequest) ar.userObj; |
| 861 | if (ar.exception == null) { |
| 862 | request.result = |
| 863 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 864 | } else { |
| 865 | request.result = |
| 866 | TelephonyManager |
| 867 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 868 | if (ar.exception instanceof CommandException) { |
| 869 | CommandException.Error error = |
| 870 | ((CommandException) (ar.exception)).getCommandError(); |
| 871 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 872 | request.result = |
| 873 | TelephonyManager |
| 874 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 875 | } |
| 876 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 877 | + ar.exception); |
| 878 | } else { |
| 879 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 880 | } |
| 881 | } |
| 882 | notifyRequester(request); |
| 883 | break; |
| 884 | } |
| 885 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 886 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 887 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 888 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 889 | request); |
| 890 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 891 | break; |
| 892 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 893 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 894 | ar = (AsyncResult) msg.obj; |
| 895 | request = (MainThreadRequest) ar.userObj; |
| 896 | if (ar.exception == null && ar.result != null) { |
| 897 | request.result = ar.result; // Integer |
| 898 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 899 | // request.result must be set to something non-null |
| 900 | // for the calling thread to unblock |
| 901 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 902 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 903 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 904 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 905 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 906 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 907 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 908 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 909 | } |
| 910 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 911 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 912 | break; |
| 913 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 914 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 915 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 916 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 917 | request); |
| 918 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 919 | (Pair<Integer, Long>) request.argument; |
| 920 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 921 | reasonWithNetworkTypes.first, |
| 922 | reasonWithNetworkTypes.second, |
| 923 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 924 | break; |
| 925 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 926 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 927 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 928 | break; |
| 929 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 930 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 931 | request = (MainThreadRequest)msg.obj; |
| 932 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 933 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 934 | break; |
| 935 | |
| 936 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 937 | ar = (AsyncResult)msg.obj; |
| 938 | request = (MainThreadRequest)ar.userObj; |
| 939 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 940 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 941 | break; |
| 942 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 943 | case CMD_SET_VOICEMAIL_NUMBER: |
| 944 | request = (MainThreadRequest) msg.obj; |
| 945 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 946 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 947 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 948 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 949 | break; |
| 950 | |
| 951 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 952 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 953 | break; |
| 954 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 955 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 956 | request = (MainThreadRequest) msg.obj; |
| 957 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 958 | request); |
| 959 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 960 | break; |
| 961 | |
| 962 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 963 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 964 | break; |
| 965 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 966 | case CMD_PERFORM_NETWORK_SCAN: |
| 967 | request = (MainThreadRequest) msg.obj; |
| 968 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 969 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 970 | break; |
| 971 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 972 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 973 | request = (MainThreadRequest) msg.obj; |
| 974 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 975 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 976 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 977 | request.argument; |
| 978 | int callForwardingReason = args.first; |
| 979 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 980 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 981 | } |
| 982 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 983 | ar = (AsyncResult) msg.obj; |
| 984 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 985 | TelephonyManager.CallForwardingInfoCallback callback = |
| 986 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 987 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 988 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 989 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 990 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 991 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 992 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 993 | // any service for voice call. |
| 994 | if ((callForwardInfo.serviceClass |
| 995 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 996 | callForwardingInfo = new CallForwardingInfo(true, |
| 997 | callForwardInfo.reason, |
| 998 | callForwardInfo.number, |
| 999 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1000 | break; |
| 1001 | } |
| 1002 | } |
| 1003 | // Didn't find a call forward info for voice call. |
| 1004 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1005 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1006 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1007 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1008 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1009 | } else { |
| 1010 | if (ar.result == null) { |
| 1011 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1012 | } |
| 1013 | if (ar.exception != null) { |
| 1014 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1015 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1016 | int errorCode = TelephonyManager |
| 1017 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1018 | if (ar.exception instanceof CommandException) { |
| 1019 | CommandException.Error error = |
| 1020 | ((CommandException) (ar.exception)).getCommandError(); |
| 1021 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1022 | errorCode = TelephonyManager |
| 1023 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1024 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1025 | errorCode = TelephonyManager |
| 1026 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1027 | } |
| 1028 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1029 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1030 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1031 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1032 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1033 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1034 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1035 | request = (MainThreadRequest) msg.obj; |
| 1036 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1037 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1038 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1039 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1040 | request.argument).first; |
| 1041 | request.phone.setCallForwardingOption( |
| 1042 | callForwardingInfoToSet.isEnabled() |
| 1043 | ? CommandsInterface.CF_ACTION_ENABLE |
| 1044 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1045 | callForwardingInfoToSet.getReason(), |
| 1046 | callForwardingInfoToSet.getNumber(), |
| 1047 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1048 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1049 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1050 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1051 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1052 | ar = (AsyncResult) msg.obj; |
| 1053 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1054 | Consumer<Integer> callback = |
| 1055 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1056 | request.argument).second; |
| 1057 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1058 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1059 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1060 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1061 | if (ar.exception instanceof CommandException) { |
| 1062 | CommandException.Error error = |
| 1063 | ((CommandException) (ar.exception)).getCommandError(); |
| 1064 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1065 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1066 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1067 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1068 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1069 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1070 | } |
| 1071 | } |
| 1072 | callback.accept(errorCode); |
| 1073 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1074 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1075 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1076 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1077 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1078 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1079 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1080 | request = (MainThreadRequest) msg.obj; |
| 1081 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1082 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1083 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1084 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1085 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1086 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1087 | ar = (AsyncResult) msg.obj; |
| 1088 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1089 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1090 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1091 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1092 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1093 | // Service Class is a bit mask per 3gpp 27.007. |
| 1094 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1095 | if (callForwardResults.length > 1 |
| 1096 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1097 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1098 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1099 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1100 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1101 | } else { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1102 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1103 | } |
| 1104 | } else { |
| 1105 | if (ar.result == null) { |
| 1106 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1107 | } |
| 1108 | if (ar.exception != null) { |
| 1109 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1110 | } |
| 1111 | if (ar.exception instanceof CommandException) { |
| 1112 | CommandException.Error error = |
| 1113 | ((CommandException) (ar.exception)).getCommandError(); |
| 1114 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1115 | callForwardingStatus = |
| 1116 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1117 | } |
| 1118 | } |
| 1119 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1120 | callback.accept(callForwardingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1121 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1122 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1123 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1124 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1125 | request = (MainThreadRequest) msg.obj; |
| 1126 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1127 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1128 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1129 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1130 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1131 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1132 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1133 | ar = (AsyncResult) msg.obj; |
| 1134 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1135 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1136 | Consumer<Integer> callback = |
| 1137 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1138 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1139 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1140 | if (ar.exception instanceof CommandException) { |
| 1141 | CommandException.Error error = |
| 1142 | ((CommandException) (ar.exception)).getCommandError(); |
| 1143 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1144 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1145 | } else { |
| 1146 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1147 | } |
| 1148 | } else { |
| 1149 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1150 | } |
| 1151 | } else { |
| 1152 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1153 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1154 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1155 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1156 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1157 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1158 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1159 | ar = (AsyncResult) msg.obj; |
| 1160 | request = (MainThreadRequest) ar.userObj; |
| 1161 | CellNetworkScanResult cellScanResult; |
| 1162 | if (ar.exception == null && ar.result != null) { |
| 1163 | cellScanResult = new CellNetworkScanResult( |
| 1164 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1165 | (List<OperatorInfo>) ar.result); |
| 1166 | } else { |
| 1167 | if (ar.result == null) { |
| 1168 | loge("getCellNetworkScanResults: Empty response"); |
| 1169 | } |
| 1170 | if (ar.exception != null) { |
| 1171 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1172 | } |
| 1173 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1174 | if (ar.exception instanceof CommandException) { |
| 1175 | CommandException.Error error = |
| 1176 | ((CommandException) (ar.exception)).getCommandError(); |
| 1177 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1178 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1179 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1180 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1181 | } |
| 1182 | } |
| 1183 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1184 | } |
| 1185 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1186 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1187 | break; |
| 1188 | |
| 1189 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1190 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1191 | ManualNetworkSelectionArgument selArg = |
| 1192 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1193 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1194 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1195 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1196 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1197 | break; |
| 1198 | |
| 1199 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1200 | ar = (AsyncResult) msg.obj; |
| 1201 | request = (MainThreadRequest) ar.userObj; |
| 1202 | if (ar.exception == null) { |
| 1203 | request.result = true; |
| 1204 | } else { |
| 1205 | request.result = false; |
| 1206 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1207 | } |
| 1208 | notifyRequester(request); |
| 1209 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1210 | break; |
| 1211 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1212 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1213 | request = (MainThreadRequest) msg.obj; |
| 1214 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1215 | if (defaultPhone != null) { |
| 1216 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1217 | } else { |
| 1218 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1219 | Bundle bundle = new Bundle(); |
| 1220 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1221 | new ModemActivityInfo(0, 0, 0, |
| 1222 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1223 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1224 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1225 | break; |
| 1226 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1227 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1228 | ar = (AsyncResult) msg.obj; |
| 1229 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1230 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1231 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1232 | ModemActivityInfo ret = null; |
| 1233 | int error = 0; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1234 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1235 | // Update the last modem activity info and the result of the request. |
| 1236 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1237 | if (isModemActivityInfoValid(info)) { |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1238 | int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()]; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1239 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1240 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1241 | .getTransmitTimeMillis(); |
| 1242 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1243 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1244 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1245 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1246 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1247 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1248 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1249 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1250 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1251 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1252 | info.getReceiveTimeMillis() |
| 1253 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1254 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1255 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(), |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1256 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1257 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1258 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1259 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1260 | } else { |
| 1261 | if (ar.result == null) { |
| 1262 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1263 | error = TelephonyManager.ModemActivityInfoException |
| 1264 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1265 | } else if (ar.exception instanceof CommandException) { |
| 1266 | loge("queryModemActivityInfo: CommandException: " + |
| 1267 | ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1268 | error = TelephonyManager.ModemActivityInfoException |
| 1269 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1270 | } else { |
| 1271 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1272 | error = TelephonyManager.ModemActivityInfoException |
| 1273 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1274 | } |
| 1275 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1276 | Bundle bundle = new Bundle(); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1277 | if (ret != null) { |
| 1278 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1279 | } else { |
| 1280 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1281 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1282 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1283 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1284 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1285 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1286 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1287 | case CMD_SET_ALLOWED_CARRIERS: |
| 1288 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1289 | CarrierRestrictionRules argument = |
| 1290 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1291 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1292 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1293 | break; |
| 1294 | |
| 1295 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1296 | ar = (AsyncResult) msg.obj; |
| 1297 | request = (MainThreadRequest) ar.userObj; |
| 1298 | if (ar.exception == null && ar.result != null) { |
| 1299 | request.result = ar.result; |
| 1300 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1301 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1302 | if (ar.exception instanceof CommandException) { |
| 1303 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1304 | CommandException.Error error = |
| 1305 | ((CommandException) (ar.exception)).getCommandError(); |
| 1306 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1307 | request.result = |
| 1308 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1309 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1310 | } else { |
| 1311 | loge("setAllowedCarriers: Unknown exception"); |
| 1312 | } |
| 1313 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1314 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1315 | break; |
| 1316 | |
| 1317 | case CMD_GET_ALLOWED_CARRIERS: |
| 1318 | request = (MainThreadRequest) msg.obj; |
| 1319 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1320 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1321 | break; |
| 1322 | |
| 1323 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1324 | ar = (AsyncResult) msg.obj; |
| 1325 | request = (MainThreadRequest) ar.userObj; |
| 1326 | if (ar.exception == null && ar.result != null) { |
| 1327 | request.result = ar.result; |
| 1328 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1329 | request.result = new IllegalStateException( |
| 1330 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1331 | if (ar.result == null) { |
| 1332 | loge("getAllowedCarriers: Empty response"); |
| 1333 | } else if (ar.exception instanceof CommandException) { |
| 1334 | loge("getAllowedCarriers: CommandException: " + |
| 1335 | ar.exception); |
| 1336 | } else { |
| 1337 | loge("getAllowedCarriers: Unknown exception"); |
| 1338 | } |
| 1339 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1340 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1341 | break; |
| 1342 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1343 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1344 | ar = (AsyncResult) msg.obj; |
| 1345 | request = (MainThreadRequest) ar.userObj; |
| 1346 | if (ar.exception == null && ar.result != null) { |
| 1347 | request.result = ar.result; |
| 1348 | } else { |
| 1349 | request.result = new IllegalArgumentException( |
| 1350 | "Failed to retrieve Forbidden Plmns"); |
| 1351 | if (ar.result == null) { |
| 1352 | loge("getForbiddenPlmns: Empty response"); |
| 1353 | } else { |
| 1354 | loge("getForbiddenPlmns: Unknown exception"); |
| 1355 | } |
| 1356 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1357 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1358 | break; |
| 1359 | |
| 1360 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1361 | request = (MainThreadRequest) msg.obj; |
| 1362 | uiccCard = getUiccCardFromRequest(request); |
| 1363 | if (uiccCard == null) { |
| 1364 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1365 | request.result = new IllegalArgumentException( |
| 1366 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1367 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1368 | break; |
| 1369 | } |
| 1370 | Integer appType = (Integer) request.argument; |
| 1371 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1372 | if (uiccApp == null) { |
| 1373 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1374 | + appType); |
| 1375 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1376 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1377 | break; |
| 1378 | } else { |
| 1379 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1380 | + " specified type -- " + appType); |
| 1381 | } |
| 1382 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1383 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1384 | onCompleted); |
| 1385 | break; |
| 1386 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1387 | case CMD_SWITCH_SLOTS: |
| 1388 | request = (MainThreadRequest) msg.obj; |
| 1389 | int[] physicalSlots = (int[]) request.argument; |
| 1390 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1391 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1392 | break; |
| 1393 | |
| 1394 | case EVENT_SWITCH_SLOTS_DONE: |
| 1395 | ar = (AsyncResult) msg.obj; |
| 1396 | request = (MainThreadRequest) ar.userObj; |
| 1397 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1398 | notifyRequester(request); |
| 1399 | break; |
| 1400 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1401 | request = (MainThreadRequest) msg.obj; |
| 1402 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1403 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1404 | break; |
| 1405 | |
| 1406 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1407 | ar = (AsyncResult) msg.obj; |
| 1408 | request = (MainThreadRequest) ar.userObj; |
| 1409 | if (ar.exception != null) { |
| 1410 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1411 | } else { |
| 1412 | int mode = ((int[]) ar.result)[0]; |
| 1413 | if (mode == 0) { |
| 1414 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1415 | } else { |
| 1416 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1417 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1418 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1419 | notifyRequester(request); |
| 1420 | break; |
| 1421 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1422 | request = (MainThreadRequest) msg.obj; |
| 1423 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1424 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1425 | break; |
| 1426 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1427 | ar = (AsyncResult) msg.obj; |
| 1428 | request = (MainThreadRequest) ar.userObj; |
| 1429 | if (ar.exception != null) { |
| 1430 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1431 | } else { |
| 1432 | request.result = ((int[]) ar.result)[0]; |
| 1433 | } |
| 1434 | notifyRequester(request); |
| 1435 | break; |
| 1436 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1437 | request = (MainThreadRequest) msg.obj; |
| 1438 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1439 | int mode = (int) request.argument; |
| 1440 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1441 | break; |
| 1442 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1443 | ar = (AsyncResult) msg.obj; |
| 1444 | request = (MainThreadRequest) ar.userObj; |
| 1445 | request.result = ar.exception == null; |
| 1446 | notifyRequester(request); |
| 1447 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1448 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1449 | request = (MainThreadRequest) msg.obj; |
| 1450 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1451 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1452 | break; |
| 1453 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1454 | ar = (AsyncResult) msg.obj; |
| 1455 | request = (MainThreadRequest) ar.userObj; |
| 1456 | if (ar.exception != null) { |
| 1457 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1458 | } else { |
| 1459 | request.result = ((int[]) ar.result)[0]; |
| 1460 | } |
| 1461 | notifyRequester(request); |
| 1462 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1463 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1464 | request = (MainThreadRequest) msg.obj; |
| 1465 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1466 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1467 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1468 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1469 | break; |
| 1470 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1471 | ar = (AsyncResult) msg.obj; |
| 1472 | request = (MainThreadRequest) ar.userObj; |
| 1473 | request.result = ar.exception == null; |
| 1474 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1475 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1476 | case CMD_GET_ALL_CELL_INFO: |
| 1477 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1478 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1479 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1480 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1481 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1482 | ar = (AsyncResult) msg.obj; |
| 1483 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1484 | // If a timeout occurs, the response will be null |
| 1485 | request.result = (ar.exception == null && ar.result != null) |
| 1486 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1487 | synchronized (request) { |
| 1488 | request.notifyAll(); |
| 1489 | } |
| 1490 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1491 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1492 | request = (MainThreadRequest) msg.obj; |
| 1493 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1494 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1495 | break; |
| 1496 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1497 | ar = (AsyncResult) msg.obj; |
| 1498 | request = (MainThreadRequest) ar.userObj; |
| 1499 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1500 | try { |
| 1501 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1502 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1503 | cb.onError( |
| 1504 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1505 | ar.exception.getClass().getName(), |
| 1506 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1507 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1508 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1509 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1510 | } else { |
| 1511 | // use the result as returned |
| 1512 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1513 | } |
| 1514 | } catch (RemoteException re) { |
| 1515 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1516 | } |
| 1517 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1518 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1519 | request = (MainThreadRequest) msg.obj; |
| 1520 | WorkSource ws = (WorkSource) request.argument; |
| 1521 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1522 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1523 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1524 | } |
| 1525 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1526 | ar = (AsyncResult) msg.obj; |
| 1527 | request = (MainThreadRequest) ar.userObj; |
| 1528 | if (ar.exception == null) { |
| 1529 | request.result = ar.result; |
| 1530 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1531 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1532 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1533 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1534 | } |
| 1535 | |
| 1536 | synchronized (request) { |
| 1537 | request.notifyAll(); |
| 1538 | } |
| 1539 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1540 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1541 | case CMD_MODEM_REBOOT: |
| 1542 | request = (MainThreadRequest) msg.obj; |
| 1543 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1544 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1545 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1546 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1547 | handleNullReturnEvent(msg, "rebootModem"); |
| 1548 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1549 | case CMD_REQUEST_ENABLE_MODEM: |
| 1550 | request = (MainThreadRequest) msg.obj; |
| 1551 | boolean enable = (boolean) request.argument; |
| 1552 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1553 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1554 | PhoneConfigurationManager.getInstance() |
| 1555 | .enablePhone(request.phone, enable, onCompleted); |
| 1556 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1557 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1558 | ar = (AsyncResult) msg.obj; |
| 1559 | request = (MainThreadRequest) ar.userObj; |
| 1560 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1561 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1562 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1563 | if ((boolean) request.result) { |
| 1564 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1565 | updateModemStateMetrics(); |
| 1566 | } else { |
| 1567 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1568 | + ar.exception); |
| 1569 | } |
| 1570 | notifyRequester(request); |
| 1571 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1572 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1573 | case CMD_GET_MODEM_STATUS: |
| 1574 | request = (MainThreadRequest) msg.obj; |
| 1575 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1576 | PhoneConfigurationManager.getInstance() |
| 1577 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1578 | break; |
| 1579 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1580 | ar = (AsyncResult) msg.obj; |
| 1581 | request = (MainThreadRequest) ar.userObj; |
| 1582 | int id = request.phone.getPhoneId(); |
| 1583 | if (ar.exception == null && ar.result != null) { |
| 1584 | request.result = ar.result; |
| 1585 | //update the cache as modem status has changed |
| 1586 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1587 | (boolean) request.result); |
| 1588 | } else { |
| 1589 | // Return true if modem status cannot be retrieved. For most cases, |
| 1590 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1591 | // and disable modem are not supported. Modem is always on. |
| 1592 | // TODO: this should be fixed in R to support a third |
| 1593 | // status UNKNOWN b/131631629 |
| 1594 | request.result = true; |
| 1595 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1596 | + ar.exception); |
| 1597 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1598 | notifyRequester(request); |
| 1599 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1600 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1601 | request = (MainThreadRequest) msg.obj; |
| 1602 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1603 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1604 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1605 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1606 | break; |
| 1607 | } |
| 1608 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1609 | ar = (AsyncResult) msg.obj; |
| 1610 | request = (MainThreadRequest) ar.userObj; |
| 1611 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1612 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1613 | args.second.accept(ar.exception == null); |
| 1614 | notifyRequester(request); |
| 1615 | break; |
| 1616 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1617 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1618 | request = (MainThreadRequest) msg.obj; |
| 1619 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1620 | Phone phone = getPhoneFromRequest(request); |
| 1621 | if (phone != null) { |
| 1622 | phone.getSystemSelectionChannels(onCompleted); |
| 1623 | } else { |
| 1624 | loge("getSystemSelectionChannels: No phone object"); |
| 1625 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1626 | notifyRequester(request); |
| 1627 | } |
| 1628 | break; |
| 1629 | } |
| 1630 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1631 | ar = (AsyncResult) msg.obj; |
| 1632 | request = (MainThreadRequest) ar.userObj; |
| 1633 | if (ar.exception == null && ar.result != null) { |
| 1634 | request.result = ar.result; |
| 1635 | } else { |
| 1636 | request.result = new IllegalArgumentException( |
| 1637 | "Failed to retrieve system selection channels"); |
| 1638 | if (ar.result == null) { |
| 1639 | loge("getSystemSelectionChannels: Empty response"); |
| 1640 | } else { |
| 1641 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1642 | } |
| 1643 | } |
| 1644 | notifyRequester(request); |
| 1645 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1646 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1647 | ar = (AsyncResult) msg.obj; |
| 1648 | request = (MainThreadRequest) ar.userObj; |
| 1649 | if (ar.exception == null && ar.result != null) { |
| 1650 | request.result = ar.result; |
| 1651 | } else { |
| 1652 | request.result = -1; |
| 1653 | loge("Failed to set Forbidden Plmns"); |
| 1654 | if (ar.result == null) { |
| 1655 | loge("setForbidenPlmns: Empty response"); |
| 1656 | } else if (ar.exception != null) { |
| 1657 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1658 | request.result = -1; |
| 1659 | } else { |
| 1660 | loge("setForbiddenPlmns: Unknown exception"); |
| 1661 | } |
| 1662 | } |
| 1663 | notifyRequester(request); |
| 1664 | break; |
| 1665 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1666 | request = (MainThreadRequest) msg.obj; |
| 1667 | uiccCard = getUiccCardFromRequest(request); |
| 1668 | if (uiccCard == null) { |
| 1669 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1670 | request.result = -1; |
| 1671 | notifyRequester(request); |
| 1672 | break; |
| 1673 | } |
| 1674 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1675 | (Pair<Integer, List<String>>) request.argument; |
| 1676 | appType = setFplmnsArgs.first; |
| 1677 | List<String> fplmns = setFplmnsArgs.second; |
| 1678 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1679 | if (uiccApp == null) { |
| 1680 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1681 | request.result = -1; |
| 1682 | loge("Failed to get UICC App"); |
| 1683 | notifyRequester(request); |
| 1684 | } else { |
| 1685 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1686 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1687 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1688 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1689 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1690 | case CMD_ERASE_MODEM_CONFIG: |
| 1691 | request = (MainThreadRequest) msg.obj; |
| 1692 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1693 | defaultPhone.eraseModemConfig(onCompleted); |
| 1694 | break; |
| 1695 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1696 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1697 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1698 | |
| 1699 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1700 | request = (MainThreadRequest) msg.obj; |
| 1701 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1702 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1703 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1704 | changed.first, changed.second, onCompleted); |
| 1705 | break; |
| 1706 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1707 | ar = (AsyncResult) msg.obj; |
| 1708 | request = (MainThreadRequest) ar.userObj; |
| 1709 | if (ar.exception == null) { |
| 1710 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1711 | // If the operation is successful, update the PIN storage |
| 1712 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1713 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1714 | UiccController.getInstance().getPinStorage() |
| 1715 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1716 | } else { |
| 1717 | request.result = msg.arg1; |
| 1718 | } |
| 1719 | notifyRequester(request); |
| 1720 | break; |
| 1721 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1722 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1723 | request = (MainThreadRequest) msg.obj; |
| 1724 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1725 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1726 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1727 | enabled.first, enabled.second, onCompleted); |
| 1728 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1729 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1730 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1731 | ar = (AsyncResult) msg.obj; |
| 1732 | request = (MainThreadRequest) ar.userObj; |
| 1733 | if (ar.exception == null) { |
| 1734 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1735 | // If the operation is successful, update the PIN storage |
| 1736 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1737 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1738 | if (enabled.first) { |
| 1739 | UiccController.getInstance().getPinStorage() |
| 1740 | .storePin(enabled.second, phoneId); |
| 1741 | } else { |
| 1742 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1743 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1744 | } else { |
| 1745 | request.result = msg.arg1; |
| 1746 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1747 | |
| 1748 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1749 | notifyRequester(request); |
| 1750 | break; |
| 1751 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1752 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1753 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1754 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1755 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1756 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1757 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1758 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1759 | |
| 1760 | case CMD_SET_DATA_THROTTLING: { |
| 1761 | request = (MainThreadRequest) msg.obj; |
| 1762 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1763 | DataThrottlingRequest dataThrottlingRequest = |
| 1764 | (DataThrottlingRequest) request.argument; |
| 1765 | Phone phone = getPhoneFromRequest(request); |
| 1766 | if (phone != null) { |
| 1767 | phone.setDataThrottling(onCompleted, |
| 1768 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1769 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1770 | } else { |
| 1771 | loge("setDataThrottling: No phone object"); |
| 1772 | request.result = |
| 1773 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1774 | notifyRequester(request); |
| 1775 | } |
| 1776 | |
| 1777 | break; |
| 1778 | } |
| 1779 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1780 | ar = (AsyncResult) msg.obj; |
| 1781 | request = (MainThreadRequest) ar.userObj; |
| 1782 | |
| 1783 | if (ar.exception == null) { |
| 1784 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1785 | } else if (ar.exception instanceof CommandException) { |
| 1786 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1787 | CommandException.Error error = |
| 1788 | ((CommandException) (ar.exception)).getCommandError(); |
| 1789 | |
| 1790 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1791 | request.result = TelephonyManager |
| 1792 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1793 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1794 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
| 1795 | } else { |
| 1796 | request.result = |
| 1797 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1798 | } |
| 1799 | } else { |
| 1800 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1801 | } |
| 1802 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1803 | notifyRequester(request); |
| 1804 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1805 | |
| 1806 | case CMD_SET_SIM_POWER: { |
| 1807 | request = (MainThreadRequest) msg.obj; |
| 1808 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1809 | request = (MainThreadRequest) msg.obj; |
| 1810 | int stateToSet = |
| 1811 | ((Pair<Integer, IIntegerConsumer>) |
| 1812 | request.argument).first; |
| 1813 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1814 | break; |
| 1815 | } |
| 1816 | case EVENT_SET_SIM_POWER_DONE: { |
| 1817 | ar = (AsyncResult) msg.obj; |
| 1818 | request = (MainThreadRequest) ar.userObj; |
| 1819 | IIntegerConsumer callback = |
| 1820 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1821 | if (ar.exception != null) { |
| 1822 | loge("setSimPower exception: " + ar.exception); |
| 1823 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1824 | .RESULT_ERROR_UNKNOWN; |
| 1825 | if (ar.exception instanceof CommandException) { |
| 1826 | CommandException.Error error = |
| 1827 | ((CommandException) (ar.exception)).getCommandError(); |
| 1828 | if (error == CommandException.Error.SIM_ERR) { |
| 1829 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1830 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1831 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1832 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1833 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1834 | } else { |
| 1835 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1836 | } |
| 1837 | } |
| 1838 | try { |
| 1839 | callback.accept(errorCode); |
| 1840 | } catch (RemoteException e) { |
| 1841 | // Ignore if the remote process is no longer available to call back. |
| 1842 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1843 | } |
| 1844 | } else { |
| 1845 | try { |
| 1846 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1847 | } catch (RemoteException e) { |
| 1848 | // Ignore if the remote process is no longer available to call back. |
| 1849 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1850 | } |
| 1851 | } |
| 1852 | break; |
| 1853 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1854 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1855 | request = (MainThreadRequest) msg.obj; |
| 1856 | |
| 1857 | final Phone phone = getPhoneFromRequest(request); |
| 1858 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1859 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1860 | notifyRequester(request); |
| 1861 | break; |
| 1862 | } |
| 1863 | |
| 1864 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1865 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1866 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1867 | request); |
| 1868 | phone.getServiceStateTracker().setSignalStrengthUpdateRequest( |
| 1869 | request.subId, pair.first /*callingUid*/, |
| 1870 | pair.second /*request*/, onCompleted); |
| 1871 | break; |
| 1872 | } |
| 1873 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1874 | ar = (AsyncResult) msg.obj; |
| 1875 | request = (MainThreadRequest) ar.userObj; |
| 1876 | // request.result will be the exception of ar if present, true otherwise. |
| 1877 | // Be cautious not to leave result null which will wait() forever |
| 1878 | request.result = ar.exception != null ? ar.exception : true; |
| 1879 | notifyRequester(request); |
| 1880 | break; |
| 1881 | } |
| 1882 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1883 | request = (MainThreadRequest) msg.obj; |
| 1884 | |
| 1885 | Phone phone = getPhoneFromRequest(request); |
| 1886 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1887 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1888 | notifyRequester(request); |
| 1889 | break; |
| 1890 | } |
| 1891 | |
| 1892 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1893 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1894 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1895 | request); |
| 1896 | phone.getServiceStateTracker().clearSignalStrengthUpdateRequest( |
| 1897 | request.subId, pair.first /*callingUid*/, |
| 1898 | pair.second /*request*/, onCompleted); |
| 1899 | break; |
| 1900 | } |
| 1901 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1902 | ar = (AsyncResult) msg.obj; |
| 1903 | request = (MainThreadRequest) ar.userObj; |
| 1904 | request.result = ar.exception != null ? ar.exception : true; |
| 1905 | notifyRequester(request); |
| 1906 | break; |
| 1907 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1908 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1909 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 1910 | request = (MainThreadRequest) msg.obj; |
| 1911 | request.result = |
| 1912 | UiccController.getInstance().getPinStorage().prepareUnattendedReboot(); |
| 1913 | notifyRequester(request); |
| 1914 | break; |
| 1915 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1916 | default: |
| 1917 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1918 | break; |
| 1919 | } |
| 1920 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1921 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1922 | private void notifyRequester(MainThreadRequest request) { |
| 1923 | synchronized (request) { |
| 1924 | request.notifyAll(); |
| 1925 | } |
| 1926 | } |
| 1927 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1928 | private void handleNullReturnEvent(Message msg, String command) { |
| 1929 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1930 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1931 | if (ar.exception == null) { |
| 1932 | request.result = true; |
| 1933 | } else { |
| 1934 | request.result = false; |
| 1935 | if (ar.exception instanceof CommandException) { |
| 1936 | loge(command + ": CommandException: " + ar.exception); |
| 1937 | } else { |
| 1938 | loge(command + ": Unknown exception"); |
| 1939 | } |
| 1940 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1941 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1942 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | /** |
| 1946 | * Posts the specified command to be executed on the main thread, |
| 1947 | * waits for the request to complete, and returns the result. |
| 1948 | * @see #sendRequestAsync |
| 1949 | */ |
| 1950 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1951 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 1952 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1953 | } |
| 1954 | |
| 1955 | /** |
| 1956 | * Posts the specified command to be executed on the main thread, |
| 1957 | * waits for the request to complete, and returns the result. |
| 1958 | * @see #sendRequestAsync |
| 1959 | */ |
| 1960 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1961 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1962 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | /** |
| 1966 | * Posts the specified command to be executed on the main thread, |
| 1967 | * waits for the request to complete, and returns the result. |
| 1968 | * @see #sendRequestAsync |
| 1969 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1970 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1971 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 1972 | } |
| 1973 | |
| 1974 | /** |
| 1975 | * Posts the specified command to be executed on the main thread, |
| 1976 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 1977 | * if not timeout or null otherwise. |
| 1978 | * @see #sendRequestAsync |
| 1979 | */ |
| 1980 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 1981 | long timeoutInMs) { |
| 1982 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1983 | } |
| 1984 | |
| 1985 | /** |
| 1986 | * Posts the specified command to be executed on the main thread, |
| 1987 | * waits for the request to complete, and returns the result. |
| 1988 | * @see #sendRequestAsync |
| 1989 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1990 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1991 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1992 | } |
| 1993 | |
| 1994 | /** |
| 1995 | * Posts the specified command to be executed on the main thread, |
| 1996 | * waits for the request to complete, and returns the result. |
| 1997 | * @see #sendRequestAsync |
| 1998 | */ |
| 1999 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2000 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2001 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2002 | } |
| 2003 | |
| 2004 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2005 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2006 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2007 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2008 | * @see #sendRequestAsync |
| 2009 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2010 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2011 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2012 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2013 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2014 | } |
| 2015 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2016 | MainThreadRequest request = null; |
| 2017 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2018 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2019 | } else if (phone != null) { |
| 2020 | request = new MainThreadRequest(argument, phone, workSource); |
| 2021 | } else { |
| 2022 | request = new MainThreadRequest(argument, subId, workSource); |
| 2023 | } |
| 2024 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2025 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2026 | msg.sendToTarget(); |
| 2027 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2028 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2029 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2030 | if (timeoutInMs >= 0) { |
| 2031 | // Wait for at least timeoutInMs before returning null request result |
| 2032 | long now = SystemClock.elapsedRealtime(); |
| 2033 | long deadline = now + timeoutInMs; |
| 2034 | while (request == null && now < deadline) { |
| 2035 | try { |
| 2036 | request.wait(deadline - now); |
| 2037 | } catch (InterruptedException e) { |
| 2038 | // Do nothing, go back and check if request is completed or timeout |
| 2039 | } finally { |
| 2040 | now = SystemClock.elapsedRealtime(); |
| 2041 | } |
| 2042 | } |
| 2043 | } else { |
| 2044 | // Wait for the request to complete |
| 2045 | while (request.result == null) { |
| 2046 | try { |
| 2047 | request.wait(); |
| 2048 | } catch (InterruptedException e) { |
| 2049 | // Do nothing, go back and wait until the request is complete |
| 2050 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2051 | } |
| 2052 | } |
| 2053 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2054 | if (request.result == null) { |
| 2055 | Log.wtf(LOG_TAG, |
| 2056 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2057 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2058 | return request.result; |
| 2059 | } |
| 2060 | |
| 2061 | /** |
| 2062 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2063 | * Posts the specified command to be executed on the main thread, and |
| 2064 | * returns immediately. |
| 2065 | * @see #sendRequest |
| 2066 | */ |
| 2067 | private void sendRequestAsync(int command) { |
| 2068 | mMainThreadHandler.sendEmptyMessage(command); |
| 2069 | } |
| 2070 | |
| 2071 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2072 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2073 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2074 | */ |
| 2075 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2076 | sendRequestAsync(command, argument, null, null); |
| 2077 | } |
| 2078 | |
| 2079 | /** |
| 2080 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2081 | * @see {@link #sendRequest(int,Object)} |
| 2082 | */ |
| 2083 | private void sendRequestAsync( |
| 2084 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2085 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2086 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2087 | msg.sendToTarget(); |
| 2088 | } |
| 2089 | |
| 2090 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2091 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2092 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2093 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2094 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2095 | synchronized (PhoneInterfaceManager.class) { |
| 2096 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2097 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2098 | } else { |
| 2099 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2100 | } |
| 2101 | return sInstance; |
| 2102 | } |
| 2103 | } |
| 2104 | |
| 2105 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2106 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2107 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2108 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 2109 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2110 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2111 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2112 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2113 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2114 | mTelephonySharedPreferences = |
| 2115 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2116 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2117 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2118 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2119 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2120 | publish(); |
| 2121 | } |
| 2122 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2123 | private Phone getDefaultPhone() { |
| 2124 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2125 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2126 | } |
| 2127 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2128 | private void publish() { |
| 2129 | if (DBG) log("publish: " + this); |
| 2130 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2131 | TelephonyFrameworkInitializer |
| 2132 | .getTelephonyServiceManager() |
| 2133 | .getTelephonyServiceRegisterer() |
| 2134 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2135 | } |
| 2136 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2137 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2138 | if (request.phone != null) { |
| 2139 | return request.phone; |
| 2140 | } else { |
| 2141 | return getPhoneFromSubId(request.subId); |
| 2142 | } |
| 2143 | } |
| 2144 | |
| 2145 | private Phone getPhoneFromSubId(int subId) { |
| 2146 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2147 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2148 | } |
| 2149 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2150 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 2151 | Phone phone = getPhoneFromRequest(request); |
| 2152 | return phone == null ? null : |
| 2153 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 2154 | } |
| 2155 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2156 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2157 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2158 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2159 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2160 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2161 | private void sendEraseModemConfig(Phone phone) { |
| 2162 | if (phone != null) { |
| 2163 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2164 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 2165 | final long identity = Binder.clearCallingIdentity(); |
| 2166 | try { |
| 2167 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2168 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2169 | } finally { |
| 2170 | Binder.restoreCallingIdentity(identity); |
| 2171 | } |
| 2172 | } |
| 2173 | } |
| 2174 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2175 | private boolean isImsAvailableOnDevice() { |
| 2176 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2177 | if (pm == null) { |
| 2178 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2179 | // so do not throw error and allow. |
| 2180 | return true; |
| 2181 | } |
| 2182 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2183 | } |
| 2184 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2185 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2186 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2187 | } |
| 2188 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2189 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2190 | if (DBG) log("dial: " + number); |
| 2191 | // No permission check needed here: This is just a wrapper around the |
| 2192 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2193 | // the UI before it does anything. |
| 2194 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2195 | final long identity = Binder.clearCallingIdentity(); |
| 2196 | try { |
| 2197 | String url = createTelUrl(number); |
| 2198 | if (url == null) { |
| 2199 | return; |
| 2200 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2201 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2202 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2203 | PhoneConstants.State state = mCM.getState(subId); |
| 2204 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2205 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2206 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2207 | mApp.startActivity(intent); |
| 2208 | } |
| 2209 | } finally { |
| 2210 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2211 | } |
| 2212 | } |
| 2213 | |
| 2214 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2215 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2216 | } |
| 2217 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2218 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2219 | if (DBG) log("call: " + number); |
| 2220 | |
| 2221 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2222 | // need to do a permission check since we're calling startActivity() |
| 2223 | // from the context of the phone app. |
| 2224 | enforceCallPermission(); |
| 2225 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2226 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2227 | != AppOpsManager.MODE_ALLOWED) { |
| 2228 | return; |
| 2229 | } |
| 2230 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2231 | final long identity = Binder.clearCallingIdentity(); |
| 2232 | try { |
| 2233 | String url = createTelUrl(number); |
| 2234 | if (url == null) { |
| 2235 | return; |
| 2236 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2237 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2238 | boolean isValid = false; |
| 2239 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2240 | if (slist != null) { |
| 2241 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2242 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2243 | isValid = true; |
| 2244 | break; |
| 2245 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2246 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2247 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2248 | if (!isValid) { |
| 2249 | return; |
| 2250 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2251 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2252 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2253 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2254 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2255 | mApp.startActivity(intent); |
| 2256 | } finally { |
| 2257 | Binder.restoreCallingIdentity(identity); |
| 2258 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2259 | } |
| 2260 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2261 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2262 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2263 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2264 | } |
| 2265 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2266 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2267 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2268 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2269 | } |
| 2270 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2271 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2272 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2273 | |
| 2274 | final long identity = Binder.clearCallingIdentity(); |
| 2275 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2276 | Phone phone = getPhone(subId); |
| 2277 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2278 | checkSimPin.start(); |
| 2279 | return checkSimPin.unlockSim(null, pin); |
| 2280 | } finally { |
| 2281 | Binder.restoreCallingIdentity(identity); |
| 2282 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2283 | } |
| 2284 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2285 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2286 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2287 | |
| 2288 | final long identity = Binder.clearCallingIdentity(); |
| 2289 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2290 | Phone phone = getPhone(subId); |
| 2291 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2292 | checkSimPuk.start(); |
| 2293 | return checkSimPuk.unlockSim(puk, pin); |
| 2294 | } finally { |
| 2295 | Binder.restoreCallingIdentity(identity); |
| 2296 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2297 | } |
| 2298 | |
| 2299 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2300 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2301 | * a synchronous one. |
| 2302 | */ |
| 2303 | private static class UnlockSim extends Thread { |
| 2304 | |
| 2305 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2306 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2307 | |
| 2308 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2309 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2310 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2311 | |
| 2312 | // For replies from SimCard interface |
| 2313 | private Handler mHandler; |
| 2314 | |
| 2315 | // For async handler to identify request type |
| 2316 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2317 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2318 | UnlockSim(int phoneId, IccCard simCard) { |
| 2319 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2320 | mSimCard = simCard; |
| 2321 | } |
| 2322 | |
| 2323 | @Override |
| 2324 | public void run() { |
| 2325 | Looper.prepare(); |
| 2326 | synchronized (UnlockSim.this) { |
| 2327 | mHandler = new Handler() { |
| 2328 | @Override |
| 2329 | public void handleMessage(Message msg) { |
| 2330 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2331 | switch (msg.what) { |
| 2332 | case SUPPLY_PIN_COMPLETE: |
| 2333 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2334 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2335 | mRetryCount = msg.arg1; |
| 2336 | if (ar.exception != null) { |
| 2337 | if (ar.exception instanceof CommandException && |
| 2338 | ((CommandException)(ar.exception)).getCommandError() |
| 2339 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2340 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2341 | } //When UiccCardApp dispose,handle message and return exception |
| 2342 | else if (ar.exception instanceof CommandException && |
| 2343 | ((CommandException) (ar.exception)).getCommandError() |
| 2344 | == CommandException.Error.ABORTED) { |
| 2345 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2346 | } else { |
| 2347 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2348 | } |
| 2349 | } else { |
| 2350 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2351 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2352 | mDone = true; |
| 2353 | UnlockSim.this.notifyAll(); |
| 2354 | } |
| 2355 | break; |
| 2356 | } |
| 2357 | } |
| 2358 | }; |
| 2359 | UnlockSim.this.notifyAll(); |
| 2360 | } |
| 2361 | Looper.loop(); |
| 2362 | } |
| 2363 | |
| 2364 | /* |
| 2365 | * Use PIN or PUK to unlock SIM card |
| 2366 | * |
| 2367 | * If PUK is null, unlock SIM card with PIN |
| 2368 | * |
| 2369 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2370 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2371 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2372 | |
| 2373 | while (mHandler == null) { |
| 2374 | try { |
| 2375 | wait(); |
| 2376 | } catch (InterruptedException e) { |
| 2377 | Thread.currentThread().interrupt(); |
| 2378 | } |
| 2379 | } |
| 2380 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2381 | |
| 2382 | if (puk == null) { |
| 2383 | mSimCard.supplyPin(pin, callback); |
| 2384 | } else { |
| 2385 | mSimCard.supplyPuk(puk, pin, callback); |
| 2386 | } |
| 2387 | |
| 2388 | while (!mDone) { |
| 2389 | try { |
| 2390 | Log.d(LOG_TAG, "wait for done"); |
| 2391 | wait(); |
| 2392 | } catch (InterruptedException e) { |
| 2393 | // Restore the interrupted status |
| 2394 | Thread.currentThread().interrupt(); |
| 2395 | } |
| 2396 | } |
| 2397 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2398 | int[] resultArray = new int[2]; |
| 2399 | resultArray[0] = mResult; |
| 2400 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2401 | |
| 2402 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
| 2403 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
| 2404 | } |
| 2405 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2406 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2407 | } |
| 2408 | } |
| 2409 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2410 | /** |
| 2411 | * This method has been removed due to privacy and stability concerns. |
| 2412 | */ |
| 2413 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2414 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2415 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2416 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2417 | } |
| 2418 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2419 | @Override |
| 2420 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2421 | mApp.getSystemService(AppOpsManager.class) |
| 2422 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2423 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2424 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2425 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2426 | // Callers targeting S have no business invoking this method. |
| 2427 | return; |
| 2428 | } |
| 2429 | |
| 2430 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2431 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2432 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2433 | .setCallingPackage(callingPackage) |
| 2434 | .setCallingFeatureId(null) |
| 2435 | .setCallingPid(Binder.getCallingPid()) |
| 2436 | .setCallingUid(Binder.getCallingUid()) |
| 2437 | .setMethod("updateServiceLocation") |
| 2438 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2439 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2440 | .build()); |
| 2441 | // Apps that lack location permission have no business calling this method; |
| 2442 | // however, because no permission was declared in the public API, denials must |
| 2443 | // all be "soft". |
| 2444 | switch (locationResult) { |
| 2445 | case DENIED_HARD: /* fall through */ |
| 2446 | case DENIED_SOFT: |
| 2447 | return; |
| 2448 | } |
| 2449 | |
| 2450 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2451 | final long identity = Binder.clearCallingIdentity(); |
| 2452 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2453 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2454 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2455 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2456 | } |
| 2457 | } finally { |
| 2458 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2459 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2460 | } |
| 2461 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2462 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2463 | @Override |
| 2464 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2465 | return isRadioOnWithFeature(callingPackage, null); |
| 2466 | } |
| 2467 | |
| 2468 | |
| 2469 | @Override |
| 2470 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2471 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2472 | callingFeatureId); |
| 2473 | } |
| 2474 | |
| 2475 | @Deprecated |
| 2476 | @Override |
| 2477 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2478 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2479 | } |
| 2480 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2481 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2482 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2483 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2484 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2485 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2486 | return false; |
| 2487 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2488 | |
| 2489 | final long identity = Binder.clearCallingIdentity(); |
| 2490 | try { |
| 2491 | return isRadioOnForSubscriber(subId); |
| 2492 | } finally { |
| 2493 | Binder.restoreCallingIdentity(identity); |
| 2494 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2495 | } |
| 2496 | |
| 2497 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2498 | final long identity = Binder.clearCallingIdentity(); |
| 2499 | try { |
| 2500 | final Phone phone = getPhone(subId); |
| 2501 | if (phone != null) { |
| 2502 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2503 | } else { |
| 2504 | return false; |
| 2505 | } |
| 2506 | } finally { |
| 2507 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2508 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2509 | } |
| 2510 | |
| 2511 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2512 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2513 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2514 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2515 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2516 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2517 | |
| 2518 | final long identity = Binder.clearCallingIdentity(); |
| 2519 | try { |
| 2520 | final Phone phone = getPhone(subId); |
| 2521 | if (phone != null) { |
| 2522 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2523 | } |
| 2524 | } finally { |
| 2525 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2526 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2527 | } |
| 2528 | |
| 2529 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2530 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2531 | } |
| 2532 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2533 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2534 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2535 | |
| 2536 | final long identity = Binder.clearCallingIdentity(); |
| 2537 | try { |
| 2538 | final Phone phone = getPhone(subId); |
| 2539 | if (phone == null) { |
| 2540 | return false; |
| 2541 | } |
| 2542 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2543 | toggleRadioOnOffForSubscriber(subId); |
| 2544 | } |
| 2545 | return true; |
| 2546 | } finally { |
| 2547 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2548 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2549 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2550 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2551 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2552 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2553 | /* |
| 2554 | * If any of the Radios are available, it will need to be |
| 2555 | * shutdown. So return true if any Radio is available. |
| 2556 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2557 | final long identity = Binder.clearCallingIdentity(); |
| 2558 | try { |
| 2559 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2560 | Phone phone = PhoneFactory.getPhone(i); |
| 2561 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2562 | } |
| 2563 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2564 | return false; |
| 2565 | } finally { |
| 2566 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2567 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2568 | } |
| 2569 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2570 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2571 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2572 | enforceModifyPermission(); |
| 2573 | |
| 2574 | final long identity = Binder.clearCallingIdentity(); |
| 2575 | try { |
| 2576 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2577 | logv("Shutting down Phone " + i); |
| 2578 | shutdownRadioUsingPhoneId(i); |
| 2579 | } |
| 2580 | } finally { |
| 2581 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2582 | } |
| 2583 | } |
| 2584 | |
| 2585 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2586 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2587 | if (phone != null && phone.isRadioAvailable()) { |
| 2588 | phone.shutdownRadio(); |
| 2589 | } |
| 2590 | } |
| 2591 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2592 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2593 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2594 | |
| 2595 | final long identity = Binder.clearCallingIdentity(); |
| 2596 | try { |
| 2597 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2598 | if (defaultPhone != null) { |
| 2599 | defaultPhone.setRadioPower(turnOn); |
| 2600 | return true; |
| 2601 | } else { |
| 2602 | loge("There's no default phone."); |
| 2603 | return false; |
| 2604 | } |
| 2605 | } finally { |
| 2606 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2607 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2608 | } |
| 2609 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2610 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2611 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2612 | |
| 2613 | final long identity = Binder.clearCallingIdentity(); |
| 2614 | try { |
| 2615 | final Phone phone = getPhone(subId); |
| 2616 | if (phone != null) { |
| 2617 | phone.setRadioPower(turnOn); |
| 2618 | return true; |
| 2619 | } else { |
| 2620 | return false; |
| 2621 | } |
| 2622 | } finally { |
| 2623 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2624 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2625 | } |
| 2626 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2627 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2628 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2629 | public boolean enableDataConnectivity() { |
| 2630 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2631 | |
| 2632 | final long identity = Binder.clearCallingIdentity(); |
| 2633 | try { |
| 2634 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2635 | final Phone phone = getPhone(subId); |
| 2636 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2637 | phone.getDataEnabledSettings().setDataEnabled( |
| 2638 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2639 | return true; |
| 2640 | } else { |
| 2641 | return false; |
| 2642 | } |
| 2643 | } finally { |
| 2644 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2645 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2646 | } |
| 2647 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2648 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2649 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2650 | public boolean disableDataConnectivity() { |
| 2651 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2652 | |
| 2653 | final long identity = Binder.clearCallingIdentity(); |
| 2654 | try { |
| 2655 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2656 | final Phone phone = getPhone(subId); |
| 2657 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2658 | phone.getDataEnabledSettings().setDataEnabled( |
| 2659 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2660 | return true; |
| 2661 | } else { |
| 2662 | return false; |
| 2663 | } |
| 2664 | } finally { |
| 2665 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2666 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2667 | } |
| 2668 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2669 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2670 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2671 | final long identity = Binder.clearCallingIdentity(); |
| 2672 | try { |
| 2673 | final Phone phone = getPhone(subId); |
| 2674 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2675 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2676 | } else { |
| 2677 | return false; |
| 2678 | } |
| 2679 | } finally { |
| 2680 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2681 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2682 | } |
| 2683 | |
| 2684 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2685 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2686 | } |
| 2687 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2688 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2689 | enforceCallPermission(); |
| 2690 | |
| 2691 | final long identity = Binder.clearCallingIdentity(); |
| 2692 | try { |
| 2693 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2694 | return; |
| 2695 | } |
| 2696 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2697 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2698 | } finally { |
| 2699 | Binder.restoreCallingIdentity(identity); |
| 2700 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2701 | }; |
| 2702 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2703 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2704 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2705 | |
| 2706 | final long identity = Binder.clearCallingIdentity(); |
| 2707 | try { |
| 2708 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2709 | return false; |
| 2710 | } |
| 2711 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2712 | } finally { |
| 2713 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2714 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2715 | } |
| 2716 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2717 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2718 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2719 | } |
| 2720 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2721 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2722 | final long identity = Binder.clearCallingIdentity(); |
| 2723 | try { |
| 2724 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2725 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2726 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2727 | } finally { |
| 2728 | Binder.restoreCallingIdentity(identity); |
| 2729 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2730 | } |
| 2731 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2732 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2733 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2734 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2735 | } |
| 2736 | |
| 2737 | @Override |
| 2738 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2739 | final long identity = Binder.clearCallingIdentity(); |
| 2740 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2741 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2742 | if (phone != null) { |
| 2743 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2744 | } else { |
| 2745 | return PhoneConstantConversions.convertDataState( |
| 2746 | PhoneConstants.DataState.DISCONNECTED); |
| 2747 | } |
| 2748 | } finally { |
| 2749 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2750 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2751 | } |
| 2752 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2753 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2754 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2755 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2756 | } |
| 2757 | |
| 2758 | @Override |
| 2759 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2760 | final long identity = Binder.clearCallingIdentity(); |
| 2761 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2762 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2763 | if (phone != null) { |
| 2764 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2765 | } else { |
| 2766 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2767 | } |
| 2768 | } finally { |
| 2769 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2770 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2771 | } |
| 2772 | |
| 2773 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2774 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2775 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2776 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2777 | |
| 2778 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2779 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2780 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2781 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2782 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2783 | .setCallingPid(Binder.getCallingPid()) |
| 2784 | .setCallingUid(Binder.getCallingUid()) |
| 2785 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2786 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2787 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2788 | .build()); |
| 2789 | switch (locationResult) { |
| 2790 | case DENIED_HARD: |
| 2791 | throw new SecurityException("Not allowed to access cell location"); |
| 2792 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2793 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2794 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2795 | } |
| 2796 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2797 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2798 | final long identity = Binder.clearCallingIdentity(); |
| 2799 | try { |
| 2800 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2801 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2802 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2803 | } finally { |
| 2804 | Binder.restoreCallingIdentity(identity); |
| 2805 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2806 | } |
| 2807 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2808 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2809 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2810 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2811 | // registered cell info, so return a NULL country instead. |
| 2812 | final long identity = Binder.clearCallingIdentity(); |
| 2813 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2814 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2815 | // Get default phone in this case. |
| 2816 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2817 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2818 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2819 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2820 | if (phone == null) return ""; |
| 2821 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2822 | if (sst == null) return ""; |
| 2823 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2824 | if (lt == null) return ""; |
| 2825 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2826 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2827 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2828 | } finally { |
| 2829 | Binder.restoreCallingIdentity(identity); |
| 2830 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2831 | } |
| 2832 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2833 | /** |
| 2834 | * This method was removed due to potential issues caused by performing partial |
| 2835 | * updates of service state, and lack of a credible use case. |
| 2836 | * |
| 2837 | * This has the ability to break the telephony implementation by disabling notification of |
| 2838 | * changes in device connectivity. DO NOT USE THIS! |
| 2839 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2840 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2841 | public void enableLocationUpdates() { |
| 2842 | mApp.enforceCallingOrSelfPermission( |
| 2843 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2844 | } |
| 2845 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2846 | /** |
| 2847 | * This method was removed due to potential issues caused by performing partial |
| 2848 | * updates of service state, and lack of a credible use case. |
| 2849 | * |
| 2850 | * This has the ability to break the telephony implementation by disabling notification of |
| 2851 | * changes in device connectivity. DO NOT USE THIS! |
| 2852 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2853 | @Override |
| 2854 | public void disableLocationUpdates() { |
| 2855 | mApp.enforceCallingOrSelfPermission( |
| 2856 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2857 | } |
| 2858 | |
| 2859 | @Override |
| 2860 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2861 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2862 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2863 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2864 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2865 | throw new SecurityException( |
| 2866 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2867 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2868 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2869 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2870 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2871 | return null; |
| 2872 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2873 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2874 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2875 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2876 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2877 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2878 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2879 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2880 | for (CellInfo ci : info) { |
| 2881 | if (ci instanceof CellInfoGsm) { |
| 2882 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2883 | } else if (ci instanceof CellInfoWcdma) { |
| 2884 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2885 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2886 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2887 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2888 | } |
| 2889 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2890 | private List<CellInfo> getCachedCellInfo() { |
| 2891 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2892 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2893 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2894 | if (info != null) cellInfos.addAll(info); |
| 2895 | } |
| 2896 | return cellInfos; |
| 2897 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2898 | |
| 2899 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2900 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2901 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2902 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2903 | |
| 2904 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2905 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2906 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2907 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2908 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2909 | .setCallingPid(Binder.getCallingPid()) |
| 2910 | .setCallingUid(Binder.getCallingUid()) |
| 2911 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2912 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2913 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2914 | .build()); |
| 2915 | switch (locationResult) { |
| 2916 | case DENIED_HARD: |
| 2917 | throw new SecurityException("Not allowed to access cell info"); |
| 2918 | case DENIED_SOFT: |
| 2919 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2920 | } |
| 2921 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2922 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2923 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2924 | return getCachedCellInfo(); |
| 2925 | } |
| 2926 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2927 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2928 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2929 | final long identity = Binder.clearCallingIdentity(); |
| 2930 | try { |
| 2931 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2932 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2933 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2934 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2935 | if (info != null) cellInfos.addAll(info); |
| 2936 | } |
| 2937 | return cellInfos; |
| 2938 | } finally { |
| 2939 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2940 | } |
| 2941 | } |
| 2942 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2943 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2944 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2945 | String callingFeatureId) { |
| 2946 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2947 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2948 | } |
| 2949 | |
| 2950 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2951 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2952 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2953 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2954 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2955 | } |
| 2956 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2957 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2958 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2959 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2960 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2961 | |
| 2962 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2963 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2964 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2965 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2966 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2967 | .setCallingPid(Binder.getCallingPid()) |
| 2968 | .setCallingUid(Binder.getCallingUid()) |
| 2969 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2970 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2971 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2972 | .build()); |
| 2973 | switch (locationResult) { |
| 2974 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2975 | if (TelephonyPermissions |
| 2976 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2977 | // Safetynet logging for b/154934934 |
| 2978 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2979 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2980 | throw new SecurityException("Not allowed to access cell info"); |
| 2981 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2982 | if (TelephonyPermissions |
| 2983 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2984 | // Safetynet logging for b/154934934 |
| 2985 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2986 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2987 | try { |
| 2988 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2989 | } catch (RemoteException re) { |
| 2990 | // Drop without consequences |
| 2991 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2992 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2993 | } |
| 2994 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2995 | |
| 2996 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2997 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2998 | |
| 2999 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3000 | } |
| 3001 | |
| 3002 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3003 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3004 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3005 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3006 | |
| 3007 | final long identity = Binder.clearCallingIdentity(); |
| 3008 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3009 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3010 | } finally { |
| 3011 | Binder.restoreCallingIdentity(identity); |
| 3012 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3013 | } |
| 3014 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3015 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3016 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3017 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3018 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3019 | return null; |
| 3020 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3021 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3022 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3023 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3024 | return null; |
| 3025 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3026 | |
| 3027 | final long identity = Binder.clearCallingIdentity(); |
| 3028 | try { |
| 3029 | return phone.getImei(); |
| 3030 | } finally { |
| 3031 | Binder.restoreCallingIdentity(identity); |
| 3032 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3033 | } |
| 3034 | |
| 3035 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3036 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3037 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3038 | String tac = null; |
| 3039 | if (phone != null) { |
| 3040 | String imei = phone.getImei(); |
| 3041 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3042 | } |
| 3043 | return tac; |
| 3044 | } |
| 3045 | |
| 3046 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3047 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3048 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3049 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3050 | return null; |
| 3051 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3052 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3053 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3054 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3055 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3056 | return null; |
| 3057 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3058 | |
| 3059 | final long identity = Binder.clearCallingIdentity(); |
| 3060 | try { |
| 3061 | return phone.getMeid(); |
| 3062 | } finally { |
| 3063 | Binder.restoreCallingIdentity(identity); |
| 3064 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3065 | } |
| 3066 | |
| 3067 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3068 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3069 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3070 | String manufacturerCode = null; |
| 3071 | if (phone != null) { |
| 3072 | String meid = phone.getMeid(); |
| 3073 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3074 | } |
| 3075 | return manufacturerCode; |
| 3076 | } |
| 3077 | |
| 3078 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3079 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3080 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3081 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3082 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3083 | return null; |
| 3084 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3085 | int subId = phone.getSubId(); |
| 3086 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3087 | mApp, subId, callingPackage, callingFeatureId, |
| 3088 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3089 | return null; |
| 3090 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3091 | |
| 3092 | final long identity = Binder.clearCallingIdentity(); |
| 3093 | try { |
| 3094 | return phone.getDeviceSvn(); |
| 3095 | } finally { |
| 3096 | Binder.restoreCallingIdentity(identity); |
| 3097 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3098 | } |
| 3099 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3100 | @Override |
| 3101 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3102 | final long identity = Binder.clearCallingIdentity(); |
| 3103 | try { |
| 3104 | final Phone phone = getPhone(subId); |
| 3105 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3106 | } finally { |
| 3107 | Binder.restoreCallingIdentity(identity); |
| 3108 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3109 | } |
| 3110 | |
| 3111 | @Override |
| 3112 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3113 | final long identity = Binder.clearCallingIdentity(); |
| 3114 | try { |
| 3115 | final Phone phone = getPhone(subId); |
| 3116 | return phone == null ? null : phone.getCarrierName(); |
| 3117 | } finally { |
| 3118 | Binder.restoreCallingIdentity(identity); |
| 3119 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3120 | } |
| 3121 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3122 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3123 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3124 | final long identity = Binder.clearCallingIdentity(); |
| 3125 | try { |
| 3126 | final Phone phone = getPhone(subId); |
| 3127 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3128 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3129 | } finally { |
| 3130 | Binder.restoreCallingIdentity(identity); |
| 3131 | } |
| 3132 | } |
| 3133 | |
| 3134 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3135 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3136 | final long identity = Binder.clearCallingIdentity(); |
| 3137 | try { |
| 3138 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3139 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3140 | } finally { |
| 3141 | Binder.restoreCallingIdentity(identity); |
| 3142 | } |
| 3143 | } |
| 3144 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3145 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3146 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3147 | if (!isSubscriptionMccMnc) { |
| 3148 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3149 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3150 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3151 | if (phone == null) { |
| 3152 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3153 | } |
| 3154 | final long identity = Binder.clearCallingIdentity(); |
| 3155 | try { |
| 3156 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3157 | } finally { |
| 3158 | Binder.restoreCallingIdentity(identity); |
| 3159 | } |
| 3160 | } |
| 3161 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3162 | // |
| 3163 | // Internal helper methods. |
| 3164 | // |
| 3165 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3166 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3167 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3168 | * |
| 3169 | * @throws SecurityException if the caller does not have the required permission |
| 3170 | */ |
| 3171 | private void enforceModifyPermission() { |
| 3172 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3173 | } |
| 3174 | |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3175 | /** |
| 3176 | * Make sure the caller is system. |
| 3177 | * |
| 3178 | * @throws SecurityException if the caller is not system. |
| 3179 | */ |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 3180 | private static void enforceSystemCaller() { |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3181 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 3182 | throw new SecurityException("Caller must be system"); |
| 3183 | } |
| 3184 | } |
| 3185 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3186 | private void enforceActiveEmergencySessionPermission() { |
| 3187 | mApp.enforceCallingOrSelfPermission( |
| 3188 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3189 | } |
| 3190 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3191 | /** |
| 3192 | * Make sure the caller has the CALL_PHONE permission. |
| 3193 | * |
| 3194 | * @throws SecurityException if the caller does not have the required permission |
| 3195 | */ |
| 3196 | private void enforceCallPermission() { |
| 3197 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3198 | } |
| 3199 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3200 | private void enforceSettingsPermission() { |
| 3201 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3202 | } |
| 3203 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3204 | private void enforceRebootPermission() { |
| 3205 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3206 | } |
| 3207 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3208 | private String createTelUrl(String number) { |
| 3209 | if (TextUtils.isEmpty(number)) { |
| 3210 | return null; |
| 3211 | } |
| 3212 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3213 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3214 | } |
| 3215 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3216 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3217 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3218 | } |
| 3219 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3220 | private static void logv(String msg) { |
| 3221 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3222 | } |
| 3223 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3224 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3225 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3226 | } |
| 3227 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3228 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3229 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3230 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3231 | } |
| 3232 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3233 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3234 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3235 | final long identity = Binder.clearCallingIdentity(); |
| 3236 | try { |
| 3237 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3238 | if (phone == null) { |
| 3239 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3240 | } else { |
| 3241 | return phone.getPhoneType(); |
| 3242 | } |
| 3243 | } finally { |
| 3244 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3245 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3246 | } |
| 3247 | |
| 3248 | /** |
| 3249 | * Returns the CDMA ERI icon index to display |
| 3250 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3251 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3252 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3253 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3254 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3255 | } |
| 3256 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3257 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3258 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3259 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3260 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3261 | mApp, subId, callingPackage, callingFeatureId, |
| 3262 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3263 | return -1; |
| 3264 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3265 | |
| 3266 | final long identity = Binder.clearCallingIdentity(); |
| 3267 | try { |
| 3268 | final Phone phone = getPhone(subId); |
| 3269 | if (phone != null) { |
| 3270 | return phone.getCdmaEriIconIndex(); |
| 3271 | } else { |
| 3272 | return -1; |
| 3273 | } |
| 3274 | } finally { |
| 3275 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3276 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3277 | } |
| 3278 | |
| 3279 | /** |
| 3280 | * Returns the CDMA ERI icon mode, |
| 3281 | * 0 - ON |
| 3282 | * 1 - FLASHING |
| 3283 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3284 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3285 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3286 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3287 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3288 | } |
| 3289 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3290 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3291 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3292 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3293 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3294 | mApp, subId, callingPackage, callingFeatureId, |
| 3295 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3296 | return -1; |
| 3297 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3298 | |
| 3299 | final long identity = Binder.clearCallingIdentity(); |
| 3300 | try { |
| 3301 | final Phone phone = getPhone(subId); |
| 3302 | if (phone != null) { |
| 3303 | return phone.getCdmaEriIconMode(); |
| 3304 | } else { |
| 3305 | return -1; |
| 3306 | } |
| 3307 | } finally { |
| 3308 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3309 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3310 | } |
| 3311 | |
| 3312 | /** |
| 3313 | * Returns the CDMA ERI text, |
| 3314 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3315 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3316 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3317 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3318 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3319 | } |
| 3320 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3321 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3322 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3323 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3324 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3325 | mApp, subId, callingPackage, callingFeatureId, |
| 3326 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3327 | return null; |
| 3328 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3329 | |
| 3330 | final long identity = Binder.clearCallingIdentity(); |
| 3331 | try { |
| 3332 | final Phone phone = getPhone(subId); |
| 3333 | if (phone != null) { |
| 3334 | return phone.getCdmaEriText(); |
| 3335 | } else { |
| 3336 | return null; |
| 3337 | } |
| 3338 | } finally { |
| 3339 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3340 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3341 | } |
| 3342 | |
| 3343 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3344 | * Returns the CDMA MDN. |
| 3345 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3346 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3347 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3348 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3349 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3350 | |
| 3351 | final long identity = Binder.clearCallingIdentity(); |
| 3352 | try { |
| 3353 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3354 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3355 | return phone.getLine1Number(); |
| 3356 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3357 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3358 | return null; |
| 3359 | } |
| 3360 | } finally { |
| 3361 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3362 | } |
| 3363 | } |
| 3364 | |
| 3365 | /** |
| 3366 | * Returns the CDMA MIN. |
| 3367 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3368 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3369 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3370 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3371 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3372 | |
| 3373 | final long identity = Binder.clearCallingIdentity(); |
| 3374 | try { |
| 3375 | final Phone phone = getPhone(subId); |
| 3376 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3377 | return phone.getCdmaMin(); |
| 3378 | } else { |
| 3379 | return null; |
| 3380 | } |
| 3381 | } finally { |
| 3382 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3383 | } |
| 3384 | } |
| 3385 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3386 | @Override |
| 3387 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3388 | INumberVerificationCallback callback, String callingPackage) { |
| 3389 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3390 | != PERMISSION_GRANTED) { |
| 3391 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3392 | } |
| 3393 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3394 | |
| 3395 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3396 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3397 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3398 | + "calling package: " + callingPackage |
| 3399 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3400 | } |
| 3401 | |
| 3402 | if (range == null) { |
| 3403 | throw new NullPointerException("Range must be non-null"); |
| 3404 | } |
| 3405 | |
| 3406 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3407 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3408 | |
| 3409 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3410 | } |
| 3411 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3412 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3413 | * Returns true if CDMA provisioning needs to run. |
| 3414 | */ |
| 3415 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3416 | final long identity = Binder.clearCallingIdentity(); |
| 3417 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3418 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3419 | } finally { |
| 3420 | Binder.restoreCallingIdentity(identity); |
| 3421 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3422 | } |
| 3423 | |
| 3424 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3425 | * Sets the voice mail number of a given subId. |
| 3426 | */ |
| 3427 | @Override |
| 3428 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3429 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3430 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3431 | |
| 3432 | final long identity = Binder.clearCallingIdentity(); |
| 3433 | try { |
| 3434 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3435 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3436 | return success; |
| 3437 | } finally { |
| 3438 | Binder.restoreCallingIdentity(identity); |
| 3439 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3440 | } |
| 3441 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3442 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3443 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3444 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3445 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3446 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3447 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3448 | throw new SecurityException("caller must be system dialer"); |
| 3449 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3450 | |
| 3451 | final long identity = Binder.clearCallingIdentity(); |
| 3452 | try { |
| 3453 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3454 | if (phoneAccountHandle == null) { |
| 3455 | return null; |
| 3456 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3457 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3458 | } finally { |
| 3459 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3460 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3461 | } |
| 3462 | |
| 3463 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3464 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3465 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3466 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3467 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3468 | mApp, subId, callingPackage, callingFeatureId, |
| 3469 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3470 | return null; |
| 3471 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3472 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3473 | final long identity = Binder.clearCallingIdentity(); |
| 3474 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3475 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3476 | } finally { |
| 3477 | Binder.restoreCallingIdentity(identity); |
| 3478 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3479 | } |
| 3480 | |
| 3481 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3482 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3483 | VisualVoicemailSmsFilterSettings settings) { |
| 3484 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3485 | |
| 3486 | final long identity = Binder.clearCallingIdentity(); |
| 3487 | try { |
| 3488 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3489 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3490 | } finally { |
| 3491 | Binder.restoreCallingIdentity(identity); |
| 3492 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3493 | } |
| 3494 | |
| 3495 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3496 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3497 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3498 | |
| 3499 | final long identity = Binder.clearCallingIdentity(); |
| 3500 | try { |
| 3501 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3502 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3503 | } finally { |
| 3504 | Binder.restoreCallingIdentity(identity); |
| 3505 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3506 | } |
| 3507 | |
| 3508 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3509 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3510 | String callingPackage, int subId) { |
| 3511 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3512 | |
| 3513 | final long identity = Binder.clearCallingIdentity(); |
| 3514 | try { |
| 3515 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3516 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3517 | } finally { |
| 3518 | Binder.restoreCallingIdentity(identity); |
| 3519 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3520 | } |
| 3521 | |
| 3522 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3523 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3524 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3525 | |
| 3526 | final long identity = Binder.clearCallingIdentity(); |
| 3527 | try { |
| 3528 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3529 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3530 | } finally { |
| 3531 | Binder.restoreCallingIdentity(identity); |
| 3532 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3533 | } |
| 3534 | |
| 3535 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3536 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3537 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3538 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3539 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3540 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3541 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3542 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3543 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3544 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3545 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3546 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3547 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3548 | * Sets the voice activation state of a given subId. |
| 3549 | */ |
| 3550 | @Override |
| 3551 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3552 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3553 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3554 | |
| 3555 | final long identity = Binder.clearCallingIdentity(); |
| 3556 | try { |
| 3557 | final Phone phone = getPhone(subId); |
| 3558 | if (phone != null) { |
| 3559 | phone.setVoiceActivationState(activationState); |
| 3560 | } else { |
| 3561 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3562 | } |
| 3563 | } finally { |
| 3564 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3565 | } |
| 3566 | } |
| 3567 | |
| 3568 | /** |
| 3569 | * Sets the data activation state of a given subId. |
| 3570 | */ |
| 3571 | @Override |
| 3572 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3573 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3574 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3575 | |
| 3576 | final long identity = Binder.clearCallingIdentity(); |
| 3577 | try { |
| 3578 | final Phone phone = getPhone(subId); |
| 3579 | if (phone != null) { |
| 3580 | phone.setDataActivationState(activationState); |
| 3581 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3582 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3583 | } |
| 3584 | } finally { |
| 3585 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3586 | } |
| 3587 | } |
| 3588 | |
| 3589 | /** |
| 3590 | * Returns the voice activation state of a given subId. |
| 3591 | */ |
| 3592 | @Override |
| 3593 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3594 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3595 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3596 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3597 | final long identity = Binder.clearCallingIdentity(); |
| 3598 | try { |
| 3599 | if (phone != null) { |
| 3600 | return phone.getVoiceActivationState(); |
| 3601 | } else { |
| 3602 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3603 | } |
| 3604 | } finally { |
| 3605 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3606 | } |
| 3607 | } |
| 3608 | |
| 3609 | /** |
| 3610 | * Returns the data activation state of a given subId. |
| 3611 | */ |
| 3612 | @Override |
| 3613 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3614 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3615 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3616 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3617 | final long identity = Binder.clearCallingIdentity(); |
| 3618 | try { |
| 3619 | if (phone != null) { |
| 3620 | return phone.getDataActivationState(); |
| 3621 | } else { |
| 3622 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3623 | } |
| 3624 | } finally { |
| 3625 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3626 | } |
| 3627 | } |
| 3628 | |
| 3629 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3630 | * Returns the unread count of voicemails for a subId |
| 3631 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3632 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3633 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3634 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3635 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3636 | mApp, subId, callingPackage, callingFeatureId, |
| 3637 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3638 | return 0; |
| 3639 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3640 | final long identity = Binder.clearCallingIdentity(); |
| 3641 | try { |
| 3642 | final Phone phone = getPhone(subId); |
| 3643 | if (phone != null) { |
| 3644 | return phone.getVoiceMessageCount(); |
| 3645 | } else { |
| 3646 | return 0; |
| 3647 | } |
| 3648 | } finally { |
| 3649 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3650 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3651 | } |
| 3652 | |
| 3653 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3654 | * returns true, if the device is in a state where both voice and data |
| 3655 | * are supported simultaneously. This can change based on location or network condition. |
| 3656 | */ |
| 3657 | @Override |
| 3658 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3659 | final long identity = Binder.clearCallingIdentity(); |
| 3660 | try { |
| 3661 | final Phone phone = getPhone(subId); |
| 3662 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3663 | } finally { |
| 3664 | Binder.restoreCallingIdentity(identity); |
| 3665 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3666 | } |
| 3667 | |
| 3668 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3669 | * Send the dialer code if called from the current default dialer or the caller has |
| 3670 | * carrier privilege. |
| 3671 | * @param inputCode The dialer code to send |
| 3672 | */ |
| 3673 | @Override |
| 3674 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3675 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3676 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3677 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3678 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3679 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3680 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3681 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3682 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3683 | |
| 3684 | final long identity = Binder.clearCallingIdentity(); |
| 3685 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3686 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3687 | } finally { |
| 3688 | Binder.restoreCallingIdentity(identity); |
| 3689 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3690 | } |
| 3691 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3692 | @Override |
| 3693 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3694 | TelephonyPermissions |
| 3695 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3696 | mApp, subId, "getNetworkSelectionMode"); |
| 3697 | final long identity = Binder.clearCallingIdentity(); |
| 3698 | try { |
| 3699 | if (!isActiveSubscription(subId)) { |
| 3700 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3701 | } |
| 3702 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3703 | } finally { |
| 3704 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3705 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3706 | } |
| 3707 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3708 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3709 | public boolean isInEmergencySmsMode() { |
| 3710 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3711 | final long identity = Binder.clearCallingIdentity(); |
| 3712 | try { |
| 3713 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3714 | if (phone.isInEmergencySmsMode()) { |
| 3715 | return true; |
| 3716 | } |
| 3717 | } |
| 3718 | } finally { |
| 3719 | Binder.restoreCallingIdentity(identity); |
| 3720 | } |
| 3721 | return false; |
| 3722 | } |
| 3723 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3724 | /** |
| 3725 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3726 | * @param subId The subscription to use to check the configuration. |
| 3727 | * @param c The callback that will be used to send the result. |
| 3728 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3729 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3730 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3731 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3732 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3733 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3734 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3735 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3736 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3737 | "IMS not available on device."); |
| 3738 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3739 | final long token = Binder.clearCallingIdentity(); |
| 3740 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3741 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3742 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3743 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3744 | } catch (ImsException e) { |
| 3745 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3746 | } finally { |
| 3747 | Binder.restoreCallingIdentity(token); |
| 3748 | } |
| 3749 | } |
| 3750 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3751 | /** |
| 3752 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3753 | * @param subId The subscription to use to check the configuration. |
| 3754 | * @param c The callback that will be used to send the result. |
| 3755 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3756 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3757 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3758 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3759 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3760 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3761 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3762 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3763 | final long token = Binder.clearCallingIdentity(); |
| 3764 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3765 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3766 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3767 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3768 | } catch (ImsException e) { |
| 3769 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3770 | + "is inactive, ignoring unregister."); |
| 3771 | // If the subscription is no longer active, just return, since the callback |
| 3772 | // will already have been removed internally. |
| 3773 | } finally { |
| 3774 | Binder.restoreCallingIdentity(token); |
| 3775 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3776 | } |
| 3777 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3778 | /** |
| 3779 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3780 | */ |
| 3781 | @Override |
| 3782 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3783 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3784 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3785 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3786 | "IMS not available on device."); |
| 3787 | } |
| 3788 | final long token = Binder.clearCallingIdentity(); |
| 3789 | try { |
| 3790 | Phone phone = getPhone(subId); |
| 3791 | if (phone == null) { |
| 3792 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3793 | + subId + "'"); |
| 3794 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3795 | } |
| 3796 | phone.getImsRegistrationState(regState -> { |
| 3797 | try { |
| 3798 | consumer.accept((regState == null) |
| 3799 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3800 | } catch (RemoteException e) { |
| 3801 | // Ignore if the remote process is no longer available to call back. |
| 3802 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3803 | } |
| 3804 | }); |
| 3805 | } finally { |
| 3806 | Binder.restoreCallingIdentity(token); |
| 3807 | } |
| 3808 | } |
| 3809 | |
| 3810 | /** |
| 3811 | * Get the transport type for the IMS service registration state. |
| 3812 | */ |
| 3813 | @Override |
| 3814 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3815 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3816 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3817 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3818 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3819 | "IMS not available on device."); |
| 3820 | } |
| 3821 | final long token = Binder.clearCallingIdentity(); |
| 3822 | try { |
| 3823 | Phone phone = getPhone(subId); |
| 3824 | if (phone == null) { |
| 3825 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3826 | + subId + "'"); |
| 3827 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3828 | } |
| 3829 | phone.getImsRegistrationTech(regTech -> { |
| 3830 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3831 | int regTechConverted = (regTech == null) |
| 3832 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3833 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3834 | regTechConverted); |
| 3835 | try { |
| 3836 | consumer.accept(regTechConverted); |
| 3837 | } catch (RemoteException e) { |
| 3838 | // Ignore if the remote process is no longer available to call back. |
| 3839 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3840 | } |
| 3841 | }); |
| 3842 | } finally { |
| 3843 | Binder.restoreCallingIdentity(token); |
| 3844 | } |
| 3845 | } |
| 3846 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3847 | /** |
| 3848 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3849 | * @param subId The subscription to use to check the configuration. |
| 3850 | * @param c The callback that will be used to send the result. |
| 3851 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3852 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3853 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3854 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3855 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3856 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3857 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3858 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3859 | "IMS not available on device."); |
| 3860 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3861 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3862 | final long token = Binder.clearCallingIdentity(); |
| 3863 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3864 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3865 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3866 | } catch (ImsException e) { |
| 3867 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3868 | } finally { |
| 3869 | Binder.restoreCallingIdentity(token); |
| 3870 | } |
| 3871 | } |
| 3872 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3873 | /** |
| 3874 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3875 | * @param subId The subscription to use to check the configuration. |
| 3876 | * @param c The callback that will be used to send the result. |
| 3877 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3878 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3879 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3880 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3881 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3882 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3883 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3884 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3885 | |
| 3886 | final long token = Binder.clearCallingIdentity(); |
| 3887 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3888 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3889 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3890 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3891 | } catch (ImsException e) { |
| 3892 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3893 | + "is inactive, ignoring unregister."); |
| 3894 | // If the subscription is no longer active, just return, since the callback |
| 3895 | // will already have been removed internally. |
| 3896 | } finally { |
| 3897 | Binder.restoreCallingIdentity(token); |
| 3898 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3899 | } |
| 3900 | |
| 3901 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3902 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3903 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3904 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3905 | final long token = Binder.clearCallingIdentity(); |
| 3906 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3907 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3908 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3909 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3910 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3911 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3912 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3913 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3914 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3915 | } finally { |
| 3916 | Binder.restoreCallingIdentity(token); |
| 3917 | } |
| 3918 | } |
| 3919 | |
| 3920 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3921 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3922 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3923 | final long token = Binder.clearCallingIdentity(); |
| 3924 | try { |
| 3925 | Phone phone = getPhone(subId); |
| 3926 | if (phone == null) return false; |
| 3927 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3928 | } catch (com.android.ims.ImsException e) { |
| 3929 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3930 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3931 | } finally { |
| 3932 | Binder.restoreCallingIdentity(token); |
| 3933 | } |
| 3934 | } |
| 3935 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3936 | /** |
| 3937 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3938 | * subscription. |
| 3939 | * @param subId The subscription to use to check the configuration. |
| 3940 | * @param callback The callback that will be used to send the result. |
| 3941 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3942 | * @param transportType The transport type of the MmTelFeature capability. |
| 3943 | */ |
| 3944 | @Override |
| 3945 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3946 | int transportType) { |
| 3947 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3948 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3949 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3950 | "IMS not available on device."); |
| 3951 | } |
| 3952 | final long token = Binder.clearCallingIdentity(); |
| 3953 | try { |
| 3954 | int slotId = getSlotIndex(subId); |
| 3955 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3956 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3957 | + subId + "'"); |
| 3958 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3959 | } |
| 3960 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3961 | transportType, aBoolean -> { |
| 3962 | try { |
| 3963 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3964 | } catch (RemoteException e) { |
| 3965 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3966 | + "running. Ignore"); |
| 3967 | } |
| 3968 | }); |
| 3969 | } finally { |
| 3970 | Binder.restoreCallingIdentity(token); |
| 3971 | } |
| 3972 | } |
| 3973 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3974 | /** |
| 3975 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3976 | * @param subId The subscription to use to check the configuration. |
| 3977 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3978 | @Override |
| 3979 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3980 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3981 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3982 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3983 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3984 | final long token = Binder.clearCallingIdentity(); |
| 3985 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3986 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3987 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3988 | } catch (ImsException e) { |
| 3989 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3990 | } finally { |
| 3991 | Binder.restoreCallingIdentity(token); |
| 3992 | } |
| 3993 | } |
| 3994 | |
| 3995 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3996 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3997 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3998 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3999 | final long identity = Binder.clearCallingIdentity(); |
| 4000 | try { |
| 4001 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4002 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4003 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4004 | } catch (ImsException e) { |
| 4005 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4006 | } finally { |
| 4007 | Binder.restoreCallingIdentity(identity); |
| 4008 | } |
| 4009 | } |
| 4010 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4011 | /** |
| 4012 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4013 | * @param subId The subscription to use to check the configuration. |
| 4014 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4015 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4016 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4017 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4018 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4019 | final long identity = Binder.clearCallingIdentity(); |
| 4020 | try { |
| 4021 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4022 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 4023 | } catch (ImsException e) { |
| 4024 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4025 | } finally { |
| 4026 | Binder.restoreCallingIdentity(identity); |
| 4027 | } |
| 4028 | } |
| 4029 | |
| 4030 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4031 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4032 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4033 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4034 | final long identity = Binder.clearCallingIdentity(); |
| 4035 | try { |
| 4036 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4037 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4038 | } catch (ImsException e) { |
| 4039 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4040 | } finally { |
| 4041 | Binder.restoreCallingIdentity(identity); |
| 4042 | } |
| 4043 | } |
| 4044 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4045 | /** |
| 4046 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4047 | * @param subId The subscription to use to check the configuration. |
| 4048 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4049 | @Override |
| 4050 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4051 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4052 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4053 | final long identity = Binder.clearCallingIdentity(); |
| 4054 | try { |
| 4055 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4056 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4057 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4058 | } catch (ImsException e) { |
| 4059 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4060 | } finally { |
| 4061 | Binder.restoreCallingIdentity(identity); |
| 4062 | } |
| 4063 | } |
| 4064 | |
| 4065 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4066 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4067 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4068 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4069 | final long identity = Binder.clearCallingIdentity(); |
| 4070 | try { |
| 4071 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4072 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4073 | } catch (ImsException e) { |
| 4074 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4075 | } finally { |
| 4076 | Binder.restoreCallingIdentity(identity); |
| 4077 | } |
| 4078 | } |
| 4079 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4080 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4081 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4082 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4083 | * @param subId The subscription to use to check the configuration. |
| 4084 | */ |
| 4085 | @Override |
| 4086 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
| 4087 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4088 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4089 | final long identity = Binder.clearCallingIdentity(); |
| 4090 | try { |
| 4091 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4092 | return ImsManager.getInstance(mApp, |
| 4093 | getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser(); |
| 4094 | } catch (ImsException e) { |
| 4095 | throw new ServiceSpecificException(e.getCode()); |
| 4096 | } finally { |
| 4097 | Binder.restoreCallingIdentity(identity); |
| 4098 | } |
| 4099 | } |
| 4100 | |
| 4101 | /** |
| 4102 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4103 | * Requires MODIFY_PHONE_STATE permission. |
| 4104 | * @param subId The subscription to use to check the configuration. |
| 4105 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4106 | * false otherwise |
| 4107 | */ |
| 4108 | @Override |
| 4109 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4110 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4111 | "setCrossSimCallingEnabled"); |
| 4112 | final long identity = Binder.clearCallingIdentity(); |
| 4113 | try { |
| 4114 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4115 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 4116 | .setCrossSimCallingEnabled(isEnabled); |
| 4117 | } catch (ImsException e) { |
| 4118 | throw new ServiceSpecificException(e.getCode()); |
| 4119 | } finally { |
| 4120 | Binder.restoreCallingIdentity(identity); |
| 4121 | } |
| 4122 | } |
| 4123 | |
| 4124 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4125 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4126 | * @param subId The subscription to use to check the configuration. |
| 4127 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4128 | @Override |
| 4129 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4130 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4131 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4132 | final long identity = Binder.clearCallingIdentity(); |
| 4133 | try { |
| 4134 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4135 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4136 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4137 | } catch (ImsException e) { |
| 4138 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4139 | } finally { |
| 4140 | Binder.restoreCallingIdentity(identity); |
| 4141 | } |
| 4142 | } |
| 4143 | |
| 4144 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4145 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4146 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4147 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4148 | final long identity = Binder.clearCallingIdentity(); |
| 4149 | try { |
| 4150 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4151 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4152 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4153 | } catch (ImsException e) { |
| 4154 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4155 | } finally { |
| 4156 | Binder.restoreCallingIdentity(identity); |
| 4157 | } |
| 4158 | } |
| 4159 | |
| 4160 | @Override |
| 4161 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4162 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4163 | "setVoWiFiNonPersistent"); |
| 4164 | final long identity = Binder.clearCallingIdentity(); |
| 4165 | try { |
| 4166 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4167 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 4168 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4169 | } catch (ImsException e) { |
| 4170 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4171 | } finally { |
| 4172 | Binder.restoreCallingIdentity(identity); |
| 4173 | } |
| 4174 | } |
| 4175 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4176 | /** |
| 4177 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4178 | * @param subId The subscription to use to check the configuration. |
| 4179 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4180 | @Override |
| 4181 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4182 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4183 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4184 | final long identity = Binder.clearCallingIdentity(); |
| 4185 | try { |
| 4186 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4187 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4188 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4189 | } catch (ImsException e) { |
| 4190 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4191 | } finally { |
| 4192 | Binder.restoreCallingIdentity(identity); |
| 4193 | } |
| 4194 | } |
| 4195 | |
| 4196 | @Override |
| 4197 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4198 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4199 | "setVoWiFiModeSetting"); |
| 4200 | final long identity = Binder.clearCallingIdentity(); |
| 4201 | try { |
| 4202 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4203 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4204 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4205 | } catch (ImsException e) { |
| 4206 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4207 | } finally { |
| 4208 | Binder.restoreCallingIdentity(identity); |
| 4209 | } |
| 4210 | } |
| 4211 | |
| 4212 | @Override |
| 4213 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4214 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4215 | final long identity = Binder.clearCallingIdentity(); |
| 4216 | try { |
| 4217 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4218 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4219 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4220 | } catch (ImsException e) { |
| 4221 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4222 | } finally { |
| 4223 | Binder.restoreCallingIdentity(identity); |
| 4224 | } |
| 4225 | } |
| 4226 | |
| 4227 | @Override |
| 4228 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4229 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4230 | "setVoWiFiRoamingModeSetting"); |
| 4231 | final long identity = Binder.clearCallingIdentity(); |
| 4232 | try { |
| 4233 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4234 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4235 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4236 | } catch (ImsException e) { |
| 4237 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4238 | } finally { |
| 4239 | Binder.restoreCallingIdentity(identity); |
| 4240 | } |
| 4241 | } |
| 4242 | |
| 4243 | @Override |
| 4244 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4245 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4246 | "setRttCapabilityEnabled"); |
| 4247 | final long identity = Binder.clearCallingIdentity(); |
| 4248 | try { |
| 4249 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4250 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 4251 | } catch (ImsException e) { |
| 4252 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4253 | } finally { |
| 4254 | Binder.restoreCallingIdentity(identity); |
| 4255 | } |
| 4256 | } |
| 4257 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4258 | /** |
| 4259 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4260 | * @param subId The subscription to use to check the configuration. |
| 4261 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4262 | @Override |
| 4263 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4264 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4265 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4266 | final long identity = Binder.clearCallingIdentity(); |
| 4267 | try { |
| 4268 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4269 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4270 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4271 | } catch (ImsException e) { |
| 4272 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4273 | } finally { |
| 4274 | Binder.restoreCallingIdentity(identity); |
| 4275 | } |
| 4276 | } |
| 4277 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4278 | @Override |
| 4279 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4280 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4281 | final long identity = Binder.clearCallingIdentity(); |
| 4282 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4283 | if (!isImsAvailableOnDevice()) { |
| 4284 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4285 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4286 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4287 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4288 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4289 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4290 | } catch (ImsException e) { |
| 4291 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4292 | } finally { |
| 4293 | Binder.restoreCallingIdentity(identity); |
| 4294 | } |
| 4295 | } |
| 4296 | |
| 4297 | @Override |
| 4298 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4299 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4300 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4301 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4302 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4303 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4304 | try { |
| 4305 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4306 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4307 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4308 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4309 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4310 | + "is inactive, ignoring unregister."); |
| 4311 | // If the subscription is no longer active, just return, since the callback will already |
| 4312 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4313 | } finally { |
| 4314 | Binder.restoreCallingIdentity(identity); |
| 4315 | } |
| 4316 | } |
| 4317 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4318 | |
| 4319 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4320 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4321 | message); |
| 4322 | } |
| 4323 | |
| 4324 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4325 | boolean isMmtelCapability) { |
| 4326 | Phone phone = getPhone(subId); |
| 4327 | if (phone == null) { |
| 4328 | loge("phone instance null for subid " + subId); |
| 4329 | return false; |
| 4330 | } |
| 4331 | if (isMmtelCapability) { |
| 4332 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4333 | return false; |
| 4334 | } |
| 4335 | } else { |
| 4336 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4337 | return false; |
| 4338 | } |
| 4339 | } |
| 4340 | return true; |
| 4341 | } |
| 4342 | |
| 4343 | @Override |
| 4344 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4345 | boolean isProvisioned) { |
| 4346 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4347 | |
| 4348 | final long identity = Binder.clearCallingIdentity(); |
| 4349 | try { |
| 4350 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4351 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4352 | return; |
| 4353 | } |
| 4354 | |
| 4355 | // this capability requires provisioning, route to the correct API. |
| 4356 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4357 | switch (capability) { |
| 4358 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4359 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4360 | ims.setEabProvisioned(isProvisioned); |
| 4361 | break; |
| 4362 | default: { |
| 4363 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4364 | + "rcs capability '" + capability + "', which does not require " |
| 4365 | + "provisioning."); |
| 4366 | } |
| 4367 | } |
| 4368 | } finally { |
| 4369 | Binder.restoreCallingIdentity(identity); |
| 4370 | } |
| 4371 | |
| 4372 | } |
| 4373 | |
| 4374 | |
| 4375 | @Override |
| 4376 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4377 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4378 | final long identity = Binder.clearCallingIdentity(); |
| 4379 | try { |
| 4380 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4381 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4382 | return true; |
| 4383 | } |
| 4384 | |
| 4385 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4386 | switch (capability) { |
| 4387 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4388 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4389 | return ims.isEabProvisionedOnDevice(); |
| 4390 | |
| 4391 | default: { |
| 4392 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4393 | + "capability '" + capability + "', which does not require " |
| 4394 | + "provisioning."); |
| 4395 | } |
| 4396 | } |
| 4397 | |
| 4398 | } finally { |
| 4399 | Binder.restoreCallingIdentity(identity); |
| 4400 | } |
| 4401 | } |
| 4402 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4403 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4404 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4405 | boolean isProvisioned) { |
| 4406 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4407 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4408 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4409 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4410 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4411 | final long identity = Binder.clearCallingIdentity(); |
| 4412 | try { |
| 4413 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4414 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4415 | return; |
| 4416 | } |
| 4417 | |
| 4418 | // this capability requires provisioning, route to the correct API. |
| 4419 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4420 | switch (capability) { |
| 4421 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4422 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4423 | ims.setVolteProvisioned(isProvisioned); |
| 4424 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4425 | ims.setWfcProvisioned(isProvisioned); |
| 4426 | } |
| 4427 | break; |
| 4428 | } |
| 4429 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4430 | // There is currently no difference in VT provisioning type. |
| 4431 | ims.setVtProvisioned(isProvisioned); |
| 4432 | break; |
| 4433 | } |
| 4434 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4435 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4436 | // change the capability of the feature instead if needed. |
| 4437 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4438 | == isProvisioned) { |
| 4439 | // No change in provisioning. |
| 4440 | return; |
| 4441 | } |
| 4442 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4443 | try { |
| 4444 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4445 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4446 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4447 | + ", Exception" + e.getMessage()); |
| 4448 | } |
| 4449 | break; |
| 4450 | } |
| 4451 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4452 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4453 | + "MmTel capability '" + capability + "', which does not require " |
| 4454 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4455 | } |
| 4456 | } |
| 4457 | |
| 4458 | } finally { |
| 4459 | Binder.restoreCallingIdentity(identity); |
| 4460 | } |
| 4461 | } |
| 4462 | |
| 4463 | @Override |
| 4464 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4465 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4466 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4467 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4468 | } |
| 4469 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4470 | final long identity = Binder.clearCallingIdentity(); |
| 4471 | try { |
| 4472 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4473 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4474 | return true; |
| 4475 | } |
| 4476 | |
| 4477 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4478 | switch (capability) { |
| 4479 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4480 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4481 | return ims.isVolteProvisionedOnDevice(); |
| 4482 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4483 | return ims.isWfcProvisionedOnDevice(); |
| 4484 | } |
| 4485 | // This should never happen, since we are checking tech above to make sure it |
| 4486 | // is either LTE or IWLAN. |
| 4487 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4488 | + "capability."); |
| 4489 | } |
| 4490 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4491 | // There is currently no difference in VT provisioning type. |
| 4492 | return ims.isVtProvisionedOnDevice(); |
| 4493 | } |
| 4494 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4495 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4496 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4497 | } |
| 4498 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4499 | throw new IllegalArgumentException( |
| 4500 | "Tried to get provisioning for MmTel capability '" + capability |
| 4501 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4502 | } |
| 4503 | } |
| 4504 | |
| 4505 | } finally { |
| 4506 | Binder.restoreCallingIdentity(identity); |
| 4507 | } |
| 4508 | } |
| 4509 | |
| 4510 | @Override |
| 4511 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4512 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4513 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4514 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4515 | } |
| 4516 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4517 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4518 | return (provisionedBits & capability) > 0; |
| 4519 | } |
| 4520 | |
| 4521 | @Override |
| 4522 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4523 | boolean isProvisioned) { |
| 4524 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4525 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4526 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4527 | } |
| 4528 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4529 | "setProvisioningStatusForCapability"); |
| 4530 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4531 | // If the current provisioning status for capability already matches isProvisioned, |
| 4532 | // do nothing. |
| 4533 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4534 | return; |
| 4535 | } |
| 4536 | if (isProvisioned) { |
| 4537 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4538 | } else { |
| 4539 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4540 | } |
| 4541 | } |
| 4542 | |
| 4543 | /** |
| 4544 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4545 | * technology. The bitfield should mirror the bitfield defined by |
| 4546 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4547 | */ |
| 4548 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4549 | String key = getMmTelProvisioningKey(subId, tech); |
| 4550 | // Default is no capabilities are provisioned. |
| 4551 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4552 | } |
| 4553 | |
| 4554 | /** |
| 4555 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4556 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4557 | * technology specified. |
| 4558 | * |
| 4559 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4560 | */ |
| 4561 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4562 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4563 | String key = getMmTelProvisioningKey(subId, tech); |
| 4564 | editor.putInt(key, newField); |
| 4565 | editor.commit(); |
| 4566 | } |
| 4567 | |
| 4568 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4569 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4570 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4571 | } |
| 4572 | |
| 4573 | /** |
| 4574 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4575 | * carrier associated with the subscription id. |
| 4576 | */ |
| 4577 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4578 | int capability) { |
| 4579 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4580 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4581 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4582 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4583 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4584 | false); |
| 4585 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4586 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4587 | |
| 4588 | // First check to make sure that the capability requires provisioning. |
| 4589 | switch (capability) { |
| 4590 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4591 | // intentional fallthrough |
| 4592 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4593 | if (requireVoiceVtProvisioning) { |
| 4594 | // Voice and Video requires provisioning |
| 4595 | return true; |
| 4596 | } |
| 4597 | break; |
| 4598 | } |
| 4599 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4600 | if (requireUtProvisioning) { |
| 4601 | // UT requires provisioning |
| 4602 | return true; |
| 4603 | } |
| 4604 | break; |
| 4605 | } |
| 4606 | } |
| 4607 | return false; |
| 4608 | } |
| 4609 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4610 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4611 | int capability) { |
| 4612 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4613 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4614 | |
| 4615 | boolean requireRcsProvisioning = c.getBoolean( |
| 4616 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4617 | |
| 4618 | // First check to make sure that the capability requires provisioning. |
| 4619 | switch (capability) { |
| 4620 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4621 | // intentional fallthrough |
| 4622 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4623 | if (requireRcsProvisioning) { |
| 4624 | // OPTION or PRESENCE requires provisioning |
| 4625 | return true; |
| 4626 | } |
| 4627 | break; |
| 4628 | } |
| 4629 | } |
| 4630 | return false; |
| 4631 | } |
| 4632 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4633 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4634 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4635 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4636 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4637 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4638 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4639 | final long identity = Binder.clearCallingIdentity(); |
| 4640 | try { |
| 4641 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4642 | int slotId = getSlotIndex(subId); |
| 4643 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4644 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4645 | + subId + "' for key:" + key); |
| 4646 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4647 | } |
| 4648 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4649 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4650 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4651 | + subId + "' for key:" + key); |
| 4652 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4653 | } finally { |
| 4654 | Binder.restoreCallingIdentity(identity); |
| 4655 | } |
| 4656 | } |
| 4657 | |
| 4658 | @Override |
| 4659 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4660 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4661 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4662 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4663 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4664 | final long identity = Binder.clearCallingIdentity(); |
| 4665 | try { |
| 4666 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4667 | int slotId = getSlotIndex(subId); |
| 4668 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4669 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4670 | + subId + "' for key:" + key); |
| 4671 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4672 | } |
| 4673 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4674 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4675 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4676 | + subId + "' for key:" + key); |
| 4677 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4678 | } finally { |
| 4679 | Binder.restoreCallingIdentity(identity); |
| 4680 | } |
| 4681 | } |
| 4682 | |
| 4683 | @Override |
| 4684 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4685 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4686 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4687 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4688 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4689 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4690 | final long identity = Binder.clearCallingIdentity(); |
| 4691 | try { |
| 4692 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4693 | int slotId = getSlotIndex(subId); |
| 4694 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4695 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4696 | + subId + "' for key:" + key); |
| 4697 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4698 | } |
| 4699 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4700 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4701 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4702 | + "' for key:" + key); |
| 4703 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4704 | } finally { |
| 4705 | Binder.restoreCallingIdentity(identity); |
| 4706 | } |
| 4707 | } |
| 4708 | |
| 4709 | @Override |
| 4710 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4711 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4712 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4713 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4714 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4715 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4716 | final long identity = Binder.clearCallingIdentity(); |
| 4717 | try { |
| 4718 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4719 | int slotId = getSlotIndex(subId); |
| 4720 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4721 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4722 | + subId + "' for key:" + key); |
| 4723 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4724 | } |
| 4725 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4726 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4727 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4728 | + "' for key:" + key); |
| 4729 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4730 | } finally { |
| 4731 | Binder.restoreCallingIdentity(identity); |
| 4732 | } |
| 4733 | } |
| 4734 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4735 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4736 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4737 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4738 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4739 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4740 | } |
| 4741 | return slotId; |
| 4742 | } |
| 4743 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4744 | private int getSlotIndex(int subId) { |
| 4745 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4746 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4747 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4748 | } |
| 4749 | return slotId; |
| 4750 | } |
| 4751 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4752 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4753 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4754 | */ |
| 4755 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4756 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4757 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4758 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4759 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4760 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4761 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4762 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4763 | mApp, subId, callingPackage, callingFeatureId, |
| 4764 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4765 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4766 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4767 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4768 | final long identity = Binder.clearCallingIdentity(); |
| 4769 | try { |
| 4770 | final Phone phone = getPhone(subId); |
| 4771 | if (phone != null) { |
| 4772 | return phone.getServiceState().getDataNetworkType(); |
| 4773 | } else { |
| 4774 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4775 | } |
| 4776 | } finally { |
| 4777 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4778 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4779 | } |
| 4780 | |
| 4781 | /** |
| 4782 | * Returns the data network type |
| 4783 | */ |
| 4784 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4785 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4786 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4787 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4788 | } |
| 4789 | |
| 4790 | /** |
| 4791 | * Returns the data network type for a subId |
| 4792 | */ |
| 4793 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4794 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4795 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4796 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4797 | mApp, subId, callingPackage, callingFeatureId, |
| 4798 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4799 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4800 | } |
| 4801 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4802 | final long identity = Binder.clearCallingIdentity(); |
| 4803 | try { |
| 4804 | final Phone phone = getPhone(subId); |
| 4805 | if (phone != null) { |
| 4806 | return phone.getServiceState().getDataNetworkType(); |
| 4807 | } else { |
| 4808 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4809 | } |
| 4810 | } finally { |
| 4811 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4812 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4813 | } |
| 4814 | |
| 4815 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4816 | * Returns the Voice network type for a subId |
| 4817 | */ |
| 4818 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4819 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4820 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4821 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4822 | mApp, subId, callingPackage, callingFeatureId, |
| 4823 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4824 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4825 | } |
| 4826 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4827 | final long identity = Binder.clearCallingIdentity(); |
| 4828 | try { |
| 4829 | final Phone phone = getPhone(subId); |
| 4830 | if (phone != null) { |
| 4831 | return phone.getServiceState().getVoiceNetworkType(); |
| 4832 | } else { |
| 4833 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4834 | } |
| 4835 | } finally { |
| 4836 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4837 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4838 | } |
| 4839 | |
| 4840 | /** |
| 4841 | * @return true if a ICC card is present |
| 4842 | */ |
| 4843 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4844 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4845 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4846 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4847 | } |
| 4848 | |
| 4849 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4850 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4851 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4852 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4853 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4854 | final long identity = Binder.clearCallingIdentity(); |
| 4855 | try { |
| 4856 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4857 | if (phone != null) { |
| 4858 | return phone.getIccCard().hasIccCard(); |
| 4859 | } else { |
| 4860 | return false; |
| 4861 | } |
| 4862 | } finally { |
| 4863 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4864 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4865 | } |
| 4866 | |
| 4867 | /** |
| 4868 | * Return if the current radio is LTE on CDMA. This |
| 4869 | * is a tri-state return value as for a period of time |
| 4870 | * the mode may be unknown. |
| 4871 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4872 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4873 | * @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] | 4874 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4875 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4876 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4877 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4878 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4879 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4880 | } |
| 4881 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4882 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4883 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4884 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4885 | try { |
| 4886 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4887 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4888 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4889 | } |
| 4890 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4891 | final long identity = Binder.clearCallingIdentity(); |
| 4892 | try { |
| 4893 | final Phone phone = getPhone(subId); |
| 4894 | if (phone == null) { |
| 4895 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4896 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4897 | return TelephonyProperties.lte_on_cdma_device() |
| 4898 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4899 | } |
| 4900 | } finally { |
| 4901 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4902 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4903 | } |
| 4904 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4905 | /** |
| 4906 | * {@hide} |
| 4907 | * Returns Default subId, 0 in the case of single standby. |
| 4908 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4909 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4910 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4911 | } |
| 4912 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4913 | private int getSlotForDefaultSubscription() { |
| 4914 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4915 | } |
| 4916 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4917 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4918 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4919 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4920 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4921 | private boolean isActiveSubscription(int subId) { |
| 4922 | return mSubscriptionController.isActiveSubId(subId); |
| 4923 | } |
| 4924 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4925 | /** |
| 4926 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4927 | */ |
| 4928 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4929 | final long identity = Binder.clearCallingIdentity(); |
| 4930 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4931 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4932 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4933 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4934 | } finally { |
| 4935 | Binder.restoreCallingIdentity(identity); |
| 4936 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4937 | } |
| 4938 | |
| 4939 | /** |
| 4940 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4941 | */ |
| 4942 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4943 | final long identity = Binder.clearCallingIdentity(); |
| 4944 | try { |
| 4945 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4946 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4947 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4948 | } finally { |
| 4949 | Binder.restoreCallingIdentity(identity); |
| 4950 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4951 | } |
| 4952 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4953 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4954 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4955 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4956 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4957 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4958 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4959 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4960 | if (phoneId == -1) { |
| 4961 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4962 | + " does not correspond to an active phone"); |
| 4963 | } |
| 4964 | return PhoneFactory.getPhone(phoneId); |
| 4965 | } |
| 4966 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4967 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4968 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4969 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4970 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4971 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4972 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4973 | if (DBG) { |
| 4974 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4975 | } |
| 4976 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4977 | p2); |
| 4978 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4979 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4980 | |
| 4981 | @Override |
| 4982 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4983 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4984 | enforceModifyPermission(); |
| 4985 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4986 | if (DBG) { |
| 4987 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4988 | } |
| 4989 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4990 | callingPackage, aid, p2); |
| 4991 | } |
| 4992 | |
| 4993 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4994 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4995 | final long identity = Binder.clearCallingIdentity(); |
| 4996 | try { |
| 4997 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4998 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4999 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5000 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5001 | if (bestComponent == null |
| 5002 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5003 | loge("The calling package is not allowed to access ISD-R."); |
| 5004 | throw new SecurityException( |
| 5005 | "The calling package is not allowed to access ISD-R."); |
| 5006 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5007 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5008 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5009 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5010 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 5011 | null /* workSource */); |
| 5012 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5013 | return response; |
| 5014 | } finally { |
| 5015 | Binder.restoreCallingIdentity(identity); |
| 5016 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5017 | } |
| 5018 | |
| 5019 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5020 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5021 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5022 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5023 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 5024 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 5025 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5026 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5027 | @Override |
| 5028 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 5029 | enforceModifyPermission(); |
| 5030 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 5031 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 5032 | channel); |
| 5033 | } |
| 5034 | |
| 5035 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5036 | final long identity = Binder.clearCallingIdentity(); |
| 5037 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5038 | if (channel < 0) { |
| 5039 | return false; |
| 5040 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5041 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 5042 | null /* workSource */); |
| 5043 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5044 | return success; |
| 5045 | } finally { |
| 5046 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5047 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5048 | } |
| 5049 | |
| 5050 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5051 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5052 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5053 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5054 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5055 | if (DBG) { |
| 5056 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5057 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5058 | + p3 + " data=" + data); |
| 5059 | } |
| 5060 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5061 | command, p1, p2, p3, data); |
| 5062 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5063 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5064 | @Override |
| 5065 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 5066 | int command, int p1, int p2, int p3, String data) { |
| 5067 | enforceModifyPermission(); |
| 5068 | if (DBG) { |
| 5069 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 5070 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5071 | + p3 + " data=" + data); |
| 5072 | } |
| 5073 | return iccTransmitApduLogicalChannelWithPermission( |
| 5074 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 5075 | data); |
| 5076 | } |
| 5077 | |
| 5078 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5079 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5080 | final long identity = Binder.clearCallingIdentity(); |
| 5081 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5082 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5083 | return ""; |
| 5084 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5085 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5086 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5087 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5088 | null /* workSource */); |
| 5089 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5090 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5091 | // Append the returned status code to the end of the response payload. |
| 5092 | String s = Integer.toHexString( |
| 5093 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5094 | if (response.payload != null) { |
| 5095 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5096 | } |
| 5097 | return s; |
| 5098 | } finally { |
| 5099 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5100 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5101 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5102 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5103 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5104 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5105 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5106 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5107 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5108 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5109 | if (DBG) { |
| 5110 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5111 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5112 | } |
| 5113 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5114 | cla, command, p1, p2, p3, data); |
| 5115 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5116 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5117 | @Override |
| 5118 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 5119 | int command, int p1, int p2, int p3, String data) { |
| 5120 | enforceModifyPermission(); |
| 5121 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5122 | if (DBG) { |
| 5123 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 5124 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 5125 | + " data=" + data); |
| 5126 | } |
| 5127 | |
| 5128 | return iccTransmitApduBasicChannelWithPermission( |
| 5129 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 5130 | p2, p3, data); |
| 5131 | } |
| 5132 | |
| 5133 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5134 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5135 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5136 | final long identity = Binder.clearCallingIdentity(); |
| 5137 | try { |
| 5138 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5139 | && TextUtils.equals(ISDR_AID, data)) { |
| 5140 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5141 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5142 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5143 | if (bestComponent == null |
| 5144 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5145 | loge("The calling package is not allowed to select ISD-R."); |
| 5146 | throw new SecurityException( |
| 5147 | "The calling package is not allowed to select ISD-R."); |
| 5148 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5149 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5150 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5151 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5152 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5153 | null /* workSource */); |
| 5154 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5155 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5156 | // Append the returned status code to the end of the response payload. |
| 5157 | String s = Integer.toHexString( |
| 5158 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5159 | if (response.payload != null) { |
| 5160 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5161 | } |
| 5162 | return s; |
| 5163 | } finally { |
| 5164 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5165 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5166 | } |
| 5167 | |
| 5168 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5169 | 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] | 5170 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5171 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5172 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5173 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5174 | final long identity = Binder.clearCallingIdentity(); |
| 5175 | try { |
| 5176 | if (DBG) { |
| 5177 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5178 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5179 | } |
| 5180 | |
| 5181 | IccIoResult response = |
| 5182 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5183 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5184 | subId); |
| 5185 | |
| 5186 | if (DBG) { |
| 5187 | log("Exchange SIM_IO [R]" + response); |
| 5188 | } |
| 5189 | |
| 5190 | byte[] result = null; |
| 5191 | int length = 2; |
| 5192 | if (response.payload != null) { |
| 5193 | length = 2 + response.payload.length; |
| 5194 | result = new byte[length]; |
| 5195 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5196 | } else { |
| 5197 | result = new byte[length]; |
| 5198 | } |
| 5199 | |
| 5200 | result[length - 1] = (byte) response.sw2; |
| 5201 | result[length - 2] = (byte) response.sw1; |
| 5202 | return result; |
| 5203 | } finally { |
| 5204 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5205 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5206 | } |
| 5207 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5208 | /** |
| 5209 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5210 | * on a particular subscription |
| 5211 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5212 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5213 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5214 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5215 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5216 | return null; |
| 5217 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5218 | |
| 5219 | final long identity = Binder.clearCallingIdentity(); |
| 5220 | try { |
| 5221 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5222 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5223 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5224 | return null; |
| 5225 | } |
| 5226 | Object response = sendRequest( |
| 5227 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5228 | if (response instanceof String[]) { |
| 5229 | return (String[]) response; |
| 5230 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5231 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5232 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5233 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5234 | } finally { |
| 5235 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5236 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5237 | } |
| 5238 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5239 | /** |
| 5240 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5241 | * subscription. |
| 5242 | * |
| 5243 | * @param subId the id of the subscription. |
| 5244 | * @param appType the uicc app type, must be USIM or SIM. |
| 5245 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5246 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5247 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5248 | * @return number of fplmns that is successfully written to the SIM. |
| 5249 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5250 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5251 | String callingFeatureId) { |
| 5252 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 5253 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5254 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 5255 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 5256 | } |
| 5257 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5258 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5259 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5260 | } |
| 5261 | if (fplmns == null) { |
| 5262 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5263 | } |
| 5264 | for (String fplmn : fplmns) { |
| 5265 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5266 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5267 | } |
| 5268 | } |
| 5269 | final long identity = Binder.clearCallingIdentity(); |
| 5270 | try { |
| 5271 | Object response = sendRequest( |
| 5272 | CMD_SET_FORBIDDEN_PLMNS, |
| 5273 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5274 | subId); |
| 5275 | return (int) response; |
| 5276 | } finally { |
| 5277 | Binder.restoreCallingIdentity(identity); |
| 5278 | } |
| 5279 | } |
| 5280 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5281 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5282 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5283 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5284 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5285 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5286 | final long identity = Binder.clearCallingIdentity(); |
| 5287 | try { |
| 5288 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5289 | if (response.payload == null) { |
| 5290 | return ""; |
| 5291 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5292 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5293 | // Append the returned status code to the end of the response payload. |
| 5294 | String s = Integer.toHexString( |
| 5295 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5296 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5297 | return s; |
| 5298 | } finally { |
| 5299 | Binder.restoreCallingIdentity(identity); |
| 5300 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5301 | } |
| 5302 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5303 | /** |
| 5304 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5305 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5306 | * |
| 5307 | * @param itemID the ID of the item to read |
| 5308 | * @return the NV item as a String, or null on error. |
| 5309 | */ |
| 5310 | @Override |
| 5311 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5312 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5313 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5314 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5315 | |
| 5316 | final long identity = Binder.clearCallingIdentity(); |
| 5317 | try { |
| 5318 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5319 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5320 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5321 | return value; |
| 5322 | } finally { |
| 5323 | Binder.restoreCallingIdentity(identity); |
| 5324 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5325 | } |
| 5326 | |
| 5327 | /** |
| 5328 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5329 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5330 | * |
| 5331 | * @param itemID the ID of the item to read |
| 5332 | * @param itemValue the value to write, as a String |
| 5333 | * @return true on success; false on any failure |
| 5334 | */ |
| 5335 | @Override |
| 5336 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5337 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5338 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5339 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5340 | |
| 5341 | final long identity = Binder.clearCallingIdentity(); |
| 5342 | try { |
| 5343 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5344 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5345 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5346 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5347 | return success; |
| 5348 | } finally { |
| 5349 | Binder.restoreCallingIdentity(identity); |
| 5350 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5351 | } |
| 5352 | |
| 5353 | /** |
| 5354 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5355 | * Used for device configuration by some CDMA operators. |
| 5356 | * |
| 5357 | * @param preferredRoamingList byte array containing the new PRL |
| 5358 | * @return true on success; false on any failure |
| 5359 | */ |
| 5360 | @Override |
| 5361 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5362 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5363 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5364 | |
| 5365 | final long identity = Binder.clearCallingIdentity(); |
| 5366 | try { |
| 5367 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5368 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5369 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5370 | return success; |
| 5371 | } finally { |
| 5372 | Binder.restoreCallingIdentity(identity); |
| 5373 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5374 | } |
| 5375 | |
| 5376 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5377 | * 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] | 5378 | * Used for device configuration by some CDMA operators. |
| 5379 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5380 | * @param slotIndex - device slot. |
| 5381 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5382 | * @return true on success; false on any failure |
| 5383 | */ |
| 5384 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5385 | public boolean resetModemConfig(int slotIndex) { |
| 5386 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5387 | if (phone != null) { |
| 5388 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5389 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5390 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5391 | final long identity = Binder.clearCallingIdentity(); |
| 5392 | try { |
| 5393 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5394 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5395 | return success; |
| 5396 | } finally { |
| 5397 | Binder.restoreCallingIdentity(identity); |
| 5398 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5399 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5400 | return false; |
| 5401 | } |
| 5402 | |
| 5403 | /** |
| 5404 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5405 | * |
| 5406 | * @param slotIndex - device slot. |
| 5407 | * |
| 5408 | * @return true on success; false on any failure |
| 5409 | */ |
| 5410 | @Override |
| 5411 | public boolean rebootModem(int slotIndex) { |
| 5412 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5413 | if (phone != null) { |
| 5414 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5415 | mApp, phone.getSubId(), "rebootModem"); |
| 5416 | |
| 5417 | final long identity = Binder.clearCallingIdentity(); |
| 5418 | try { |
| 5419 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5420 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5421 | return success; |
| 5422 | } finally { |
| 5423 | Binder.restoreCallingIdentity(identity); |
| 5424 | } |
| 5425 | } |
| 5426 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5427 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5428 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5429 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5430 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5431 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5432 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5433 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5434 | return new String[0]; |
| 5435 | } |
| 5436 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5437 | final long identity = Binder.clearCallingIdentity(); |
| 5438 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5439 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5440 | } finally { |
| 5441 | Binder.restoreCallingIdentity(identity); |
| 5442 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5443 | } |
| 5444 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5445 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5446 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5447 | * {@link #disableIms(int)}. |
| 5448 | * @param slotIndex device slot. |
| 5449 | */ |
| 5450 | public void resetIms(int slotIndex) { |
| 5451 | enforceModifyPermission(); |
| 5452 | |
| 5453 | final long identity = Binder.clearCallingIdentity(); |
| 5454 | try { |
| 5455 | if (mImsResolver == null) { |
| 5456 | // may happen if the does not support IMS. |
| 5457 | return; |
| 5458 | } |
| 5459 | mImsResolver.disableIms(slotIndex); |
| 5460 | mImsResolver.enableIms(slotIndex); |
| 5461 | } finally { |
| 5462 | Binder.restoreCallingIdentity(identity); |
| 5463 | } |
| 5464 | } |
| 5465 | |
| 5466 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5467 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5468 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5469 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5470 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5471 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5472 | |
| 5473 | final long identity = Binder.clearCallingIdentity(); |
| 5474 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5475 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5476 | // may happen if the device does not support IMS. |
| 5477 | return; |
| 5478 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5479 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5480 | } finally { |
| 5481 | Binder.restoreCallingIdentity(identity); |
| 5482 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5483 | } |
| 5484 | |
| 5485 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5486 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5487 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5488 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5489 | public void disableIms(int slotId) { |
| 5490 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5491 | |
| 5492 | final long identity = Binder.clearCallingIdentity(); |
| 5493 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5494 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5495 | // may happen if the device does not support IMS. |
| 5496 | return; |
| 5497 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5498 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5499 | } finally { |
| 5500 | Binder.restoreCallingIdentity(identity); |
| 5501 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5502 | } |
| 5503 | |
| 5504 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5505 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5506 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5507 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5508 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5509 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5510 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5511 | |
| 5512 | final long identity = Binder.clearCallingIdentity(); |
| 5513 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5514 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5515 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5516 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5517 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5518 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5519 | } finally { |
| 5520 | Binder.restoreCallingIdentity(identity); |
| 5521 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5522 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5523 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5524 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5525 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5526 | @Override |
| 5527 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5528 | enforceModifyPermission(); |
| 5529 | |
| 5530 | final long identity = Binder.clearCallingIdentity(); |
| 5531 | try { |
| 5532 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5533 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5534 | } finally { |
| 5535 | Binder.restoreCallingIdentity(identity); |
| 5536 | } |
| 5537 | } |
| 5538 | |
| 5539 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5540 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5541 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5542 | */ |
| 5543 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5544 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5545 | |
| 5546 | final long identity = Binder.clearCallingIdentity(); |
| 5547 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5548 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5549 | // may happen if the device does not support IMS. |
| 5550 | return null; |
| 5551 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5552 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5553 | } finally { |
| 5554 | Binder.restoreCallingIdentity(identity); |
| 5555 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5556 | } |
| 5557 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5558 | /** |
| 5559 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5560 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5561 | */ |
| 5562 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5563 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5564 | |
| 5565 | final long identity = Binder.clearCallingIdentity(); |
| 5566 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5567 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5568 | // may happen if the device does not support IMS. |
| 5569 | return null; |
| 5570 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5571 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5572 | } finally { |
| 5573 | Binder.restoreCallingIdentity(identity); |
| 5574 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5575 | } |
| 5576 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5577 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5578 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5579 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5580 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5581 | * @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] | 5582 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5583 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5584 | * @param packageName The name of the package that the current configuration will be replaced |
| 5585 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5586 | * @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] | 5587 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5588 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5589 | int[] featureTypes, String packageName) { |
| 5590 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5591 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5592 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5593 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5594 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5595 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5596 | final long identity = Binder.clearCallingIdentity(); |
| 5597 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5598 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5599 | // may happen if the device does not support IMS. |
| 5600 | return false; |
| 5601 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5602 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5603 | for (int featureType : featureTypes) { |
| 5604 | featureConfig.put(featureType, packageName); |
| 5605 | } |
| 5606 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5607 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5608 | } finally { |
| 5609 | Binder.restoreCallingIdentity(identity); |
| 5610 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5611 | } |
| 5612 | |
| 5613 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5614 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5615 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5616 | * |
| 5617 | * This should only be used for testing. |
| 5618 | * |
| 5619 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5620 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5621 | */ |
| 5622 | @Override |
| 5623 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5624 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5625 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5626 | "clearCarrierImsServiceOverride"); |
| 5627 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5628 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5629 | "clearCarrierImsServiceOverride"); |
| 5630 | |
| 5631 | final long identity = Binder.clearCallingIdentity(); |
| 5632 | try { |
| 5633 | if (mImsResolver == null) { |
| 5634 | // may happen if the device does not support IMS. |
| 5635 | return false; |
| 5636 | } |
| 5637 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5638 | } finally { |
| 5639 | Binder.restoreCallingIdentity(identity); |
| 5640 | } |
| 5641 | } |
| 5642 | |
| 5643 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5644 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5645 | * |
| 5646 | * @param slotId The slot that the ImsService is associated with. |
| 5647 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5648 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5649 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5650 | * @return the package name of the ImsService configuration. |
| 5651 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5652 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5653 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5654 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5655 | TelephonyPermissions |
| 5656 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5657 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5658 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5659 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5660 | final long identity = Binder.clearCallingIdentity(); |
| 5661 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5662 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5663 | // may happen if the device does not support IMS. |
| 5664 | return ""; |
| 5665 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5666 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5667 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5668 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5669 | } finally { |
| 5670 | Binder.restoreCallingIdentity(identity); |
| 5671 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5672 | } |
| 5673 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5674 | /** |
| 5675 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5676 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5677 | * @param callback A callback with an integer containing the |
| 5678 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5679 | */ |
| 5680 | @Override |
| 5681 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5682 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5683 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5684 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5685 | "IMS not available on device."); |
| 5686 | } |
| 5687 | final long token = Binder.clearCallingIdentity(); |
| 5688 | try { |
| 5689 | int slotId = getSlotIndex(subId); |
| 5690 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5691 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5692 | + subId + "'"); |
| 5693 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5694 | } |
| 5695 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5696 | try { |
| 5697 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5698 | } catch (RemoteException e) { |
| 5699 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5700 | + "Ignore"); |
| 5701 | } |
| 5702 | }); |
| 5703 | } finally { |
| 5704 | Binder.restoreCallingIdentity(token); |
| 5705 | } |
| 5706 | } |
| 5707 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5708 | /** |
| 5709 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5710 | */ |
| 5711 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5712 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5713 | |
| 5714 | final long identity = Binder.clearCallingIdentity(); |
| 5715 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5716 | // NOTE: Before S, this method only set the default phone. |
| 5717 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5718 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5719 | phone.setImsRegistrationState(registered); |
| 5720 | } |
| 5721 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5722 | } finally { |
| 5723 | Binder.restoreCallingIdentity(identity); |
| 5724 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5725 | } |
| 5726 | |
| 5727 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5728 | * Set the network selection mode to automatic. |
| 5729 | * |
| 5730 | */ |
| 5731 | @Override |
| 5732 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5733 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5734 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5735 | |
| 5736 | final long identity = Binder.clearCallingIdentity(); |
| 5737 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5738 | if (!isActiveSubscription(subId)) { |
| 5739 | return; |
| 5740 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5741 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 5742 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 5743 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5744 | } finally { |
| 5745 | Binder.restoreCallingIdentity(identity); |
| 5746 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5747 | } |
| 5748 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5749 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5750 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5751 | * |
| 5752 | * @param subId the id of the subscription. |
| 5753 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5754 | * the operator to attach to. |
| 5755 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5756 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5757 | * normal network selection next time. |
| 5758 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5759 | */ |
| 5760 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5761 | public boolean setNetworkSelectionModeManual( |
| 5762 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5763 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5764 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5765 | |
| 5766 | if (!isActiveSubscription(subId)) { |
| 5767 | return false; |
| 5768 | } |
| 5769 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5770 | final long identity = Binder.clearCallingIdentity(); |
| 5771 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5772 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5773 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5774 | if (DBG) { |
| 5775 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5776 | + " operator: " + operatorInfo); |
| 5777 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5778 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5779 | } finally { |
| 5780 | Binder.restoreCallingIdentity(identity); |
| 5781 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5782 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5783 | /** |
| 5784 | * Get the manual network selection |
| 5785 | * |
| 5786 | * @param subId the id of the subscription. |
| 5787 | * |
| 5788 | * @return the previously saved user selected PLMN |
| 5789 | */ |
| 5790 | @Override |
| 5791 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5792 | TelephonyPermissions |
| 5793 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5794 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5795 | |
| 5796 | final long identity = Binder.clearCallingIdentity(); |
| 5797 | try { |
| 5798 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5799 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5800 | } |
| 5801 | |
| 5802 | final Phone phone = getPhone(subId); |
| 5803 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5804 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5805 | } |
| 5806 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5807 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5808 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5809 | } finally { |
| 5810 | Binder.restoreCallingIdentity(identity); |
| 5811 | } |
| 5812 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5813 | |
| 5814 | /** |
| 5815 | * Scans for available networks. |
| 5816 | */ |
| 5817 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5818 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5819 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5820 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5821 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5822 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5823 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5824 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5825 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5826 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5827 | .setCallingPid(Binder.getCallingPid()) |
| 5828 | .setCallingUid(Binder.getCallingUid()) |
| 5829 | .setMethod("getCellNetworkScanResults") |
| 5830 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 5831 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5832 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5833 | .build()); |
| 5834 | switch (locationResult) { |
| 5835 | case DENIED_HARD: |
| 5836 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5837 | case DENIED_SOFT: |
| 5838 | return null; |
| 5839 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5840 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5841 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5842 | try { |
| 5843 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5844 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5845 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5846 | } finally { |
| 5847 | Binder.restoreCallingIdentity(identity); |
| 5848 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5849 | } |
| 5850 | |
| 5851 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5852 | * Get the call forwarding info, given the call forwarding reason. |
| 5853 | */ |
| 5854 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5855 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5856 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5857 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5858 | long identity = Binder.clearCallingIdentity(); |
| 5859 | try { |
| 5860 | if (DBG) { |
| 5861 | log("getCallForwarding: subId " + subId |
| 5862 | + " callForwardingReason" + callForwardingReason); |
| 5863 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5864 | |
| 5865 | Phone phone = getPhone(subId); |
| 5866 | if (phone == null) { |
| 5867 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5868 | callback.onError( |
| 5869 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5870 | } catch (RemoteException e) { |
| 5871 | // ignore |
| 5872 | } |
| 5873 | return; |
| 5874 | } |
| 5875 | |
| 5876 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 5877 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 5878 | @Override |
| 5879 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 5880 | try { |
| 5881 | callback.onCallForwardingInfoAvailable(info); |
| 5882 | } catch (RemoteException e) { |
| 5883 | // ignore |
| 5884 | } |
| 5885 | } |
| 5886 | |
| 5887 | @Override |
| 5888 | public void onError(int error) { |
| 5889 | try { |
| 5890 | callback.onError(error); |
| 5891 | } catch (RemoteException e) { |
| 5892 | // ignore |
| 5893 | } |
| 5894 | } |
| 5895 | }); |
| 5896 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5897 | } finally { |
| 5898 | Binder.restoreCallingIdentity(identity); |
| 5899 | } |
| 5900 | } |
| 5901 | |
| 5902 | /** |
| 5903 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5904 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5905 | */ |
| 5906 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5907 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 5908 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5909 | enforceModifyPermission(); |
| 5910 | long identity = Binder.clearCallingIdentity(); |
| 5911 | try { |
| 5912 | if (DBG) { |
| 5913 | log("setCallForwarding: subId " + subId |
| 5914 | + " callForwardingInfo" + callForwardingInfo); |
| 5915 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5916 | |
| 5917 | Phone phone = getPhone(subId); |
| 5918 | if (phone == null) { |
| 5919 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5920 | callback.accept( |
| 5921 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5922 | } catch (RemoteException e) { |
| 5923 | // ignore |
| 5924 | } |
| 5925 | return; |
| 5926 | } |
| 5927 | |
| 5928 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 5929 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5930 | |
| 5931 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5932 | } finally { |
| 5933 | Binder.restoreCallingIdentity(identity); |
| 5934 | } |
| 5935 | } |
| 5936 | |
| 5937 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5938 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5939 | */ |
| 5940 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5941 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5942 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5943 | long identity = Binder.clearCallingIdentity(); |
| 5944 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5945 | |
| 5946 | Phone phone = getPhone(subId); |
| 5947 | if (phone == null) { |
| 5948 | try { |
| 5949 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5950 | } catch (RemoteException e) { |
| 5951 | // ignore |
| 5952 | } |
| 5953 | return; |
| 5954 | } |
| 5955 | |
| 5956 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 5957 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5958 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5959 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5960 | } finally { |
| 5961 | Binder.restoreCallingIdentity(identity); |
| 5962 | } |
| 5963 | } |
| 5964 | |
| 5965 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5966 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5967 | */ |
| 5968 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5969 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5970 | enforceModifyPermission(); |
| 5971 | long identity = Binder.clearCallingIdentity(); |
| 5972 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5973 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 5974 | |
| 5975 | Phone phone = getPhone(subId); |
| 5976 | if (phone == null) { |
| 5977 | try { |
| 5978 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5979 | } catch (RemoteException e) { |
| 5980 | // ignore |
| 5981 | } |
| 5982 | return; |
| 5983 | } |
| 5984 | |
| 5985 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 5986 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5987 | |
| 5988 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5989 | } finally { |
| 5990 | Binder.restoreCallingIdentity(identity); |
| 5991 | } |
| 5992 | } |
| 5993 | |
| 5994 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5995 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5996 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5997 | * @param subId id of the subscription |
| 5998 | * @param request contains the radio access networks with bands/channels to scan |
| 5999 | * @param messenger callback messenger for scan results or errors |
| 6000 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6001 | * @return the id of the requested scan which can be used to stop the scan. |
| 6002 | */ |
| 6003 | @Override |
| 6004 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6005 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6006 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6007 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6008 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6009 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6010 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6011 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6012 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6013 | .setCallingPid(Binder.getCallingPid()) |
| 6014 | .setCallingUid(Binder.getCallingUid()) |
| 6015 | .setMethod("requestNetworkScan") |
| 6016 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
James.cf Lin | 1d4d739 | 2020-07-03 18:22:53 +0800 | [diff] [blame] | 6017 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6018 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6019 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6020 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6021 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6022 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6023 | if (e != null) { |
| 6024 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6025 | throw e; |
| 6026 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6027 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6028 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6029 | } |
| 6030 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6031 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6032 | int callingUid = Binder.getCallingUid(); |
| 6033 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6034 | final long identity = Binder.clearCallingIdentity(); |
| 6035 | try { |
| 6036 | return mNetworkScanRequestTracker.startNetworkScan( |
| 6037 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6038 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6039 | } finally { |
| 6040 | Binder.restoreCallingIdentity(identity); |
| 6041 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6042 | } |
| 6043 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6044 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6045 | NetworkScanRequest request, int subId, String callingPackage) { |
| 6046 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6047 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6048 | boolean hasNetworkScanPermission = |
| 6049 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6050 | == PERMISSION_GRANTED; |
| 6051 | |
| 6052 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6053 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6054 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6055 | } |
| 6056 | |
| 6057 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6058 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6059 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6060 | return new SecurityException("Specific channels must not be" |
| 6061 | + " scanned without location access."); |
| 6062 | } |
| 6063 | } |
| 6064 | } |
| 6065 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6066 | return null; |
| 6067 | } |
| 6068 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6069 | /** |
| 6070 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6071 | * |
| 6072 | * @param subId id of the subscription |
| 6073 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6074 | */ |
| 6075 | @Override |
| 6076 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6077 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6078 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6079 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6080 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6081 | final long identity = Binder.clearCallingIdentity(); |
| 6082 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6083 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6084 | } finally { |
| 6085 | Binder.restoreCallingIdentity(identity); |
| 6086 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6087 | } |
| 6088 | |
| 6089 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6090 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6091 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6092 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6093 | */ |
| 6094 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6095 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6096 | TelephonyPermissions |
| 6097 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6098 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6099 | |
| 6100 | final long identity = Binder.clearCallingIdentity(); |
| 6101 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6102 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6103 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6104 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6105 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6106 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6107 | } finally { |
| 6108 | Binder.restoreCallingIdentity(identity); |
| 6109 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6110 | } |
| 6111 | |
| 6112 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6113 | * Get the allowed network types for certain reason. |
| 6114 | * |
| 6115 | * @param subId the id of the subscription. |
| 6116 | * @param reason the reason the allowed network type change is taking place |
| 6117 | * @return the allowed network types. |
| 6118 | */ |
| 6119 | @Override |
| 6120 | public long getAllowedNetworkTypesForReason(int subId, |
| 6121 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
| 6122 | TelephonyPermissions |
| 6123 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6124 | mApp, subId, "getAllowedNetworkTypesForReason"); |
| 6125 | final long identity = Binder.clearCallingIdentity(); |
| 6126 | try { |
| 6127 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6128 | } finally { |
| 6129 | Binder.restoreCallingIdentity(identity); |
| 6130 | } |
| 6131 | } |
| 6132 | |
| 6133 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6134 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6135 | * @param subId subscription id of the sim card |
| 6136 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6137 | * This can be passed following states |
| 6138 | * <ol> |
| 6139 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6140 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6141 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6142 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6143 | * </ol> |
| 6144 | * @return operation result. |
| 6145 | */ |
| 6146 | @Override |
| 6147 | public int setNrDualConnectivityState(int subId, |
| 6148 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6149 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6150 | mApp, subId, "enableNRDualConnectivity"); |
| 6151 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6152 | final long identity = Binder.clearCallingIdentity(); |
| 6153 | try { |
| 6154 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6155 | nrDualConnectivityState, subId, |
| 6156 | workSource); |
| 6157 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6158 | return result; |
| 6159 | } finally { |
| 6160 | Binder.restoreCallingIdentity(identity); |
| 6161 | } |
| 6162 | } |
| 6163 | |
| 6164 | /** |
| 6165 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6166 | * @return true if dual connectivity is enabled else false |
| 6167 | */ |
| 6168 | @Override |
| 6169 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6170 | TelephonyPermissions |
| 6171 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6172 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6173 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6174 | final long identity = Binder.clearCallingIdentity(); |
| 6175 | try { |
| 6176 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6177 | null, subId, workSource); |
| 6178 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6179 | return isEnabled; |
| 6180 | } finally { |
| 6181 | Binder.restoreCallingIdentity(identity); |
| 6182 | } |
| 6183 | } |
| 6184 | |
| 6185 | /** |
Sooraj Sasindran | 4deb887 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 6186 | * get carrier bandwidth per primary and secondary carrier |
| 6187 | * @param subId subscription id of the sim card |
| 6188 | * @return CarrierBandwidth with bandwidth of both primary and secondary carrier.. |
| 6189 | */ |
| 6190 | @Override |
| 6191 | public CarrierBandwidth getCarrierBandwidth(int subId) { |
| 6192 | TelephonyPermissions |
| 6193 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6194 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6195 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6196 | final long identity = Binder.clearCallingIdentity(); |
| 6197 | try { |
| 6198 | CarrierBandwidth carrierBandwidth = |
| 6199 | getPhoneFromSubId(subId).getCarrierBandwidth(); |
| 6200 | if (DBG) log("getCarrierBandwidth: " + carrierBandwidth); |
| 6201 | return carrierBandwidth; |
| 6202 | } finally { |
| 6203 | Binder.restoreCallingIdentity(identity); |
| 6204 | } |
| 6205 | } |
| 6206 | |
| 6207 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6208 | * Set the allowed network types of the device and |
| 6209 | * provide the reason triggering the allowed network change. |
| 6210 | * |
| 6211 | * @param subId the id of the subscription. |
| 6212 | * @param reason the reason the allowed network type change is taking place |
| 6213 | * @param allowedNetworkTypes the allowed network types. |
| 6214 | * @return true on success; false on any failure. |
| 6215 | */ |
| 6216 | @Override |
| 6217 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6218 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6219 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6220 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6221 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6222 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
| 6223 | Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason); |
| 6224 | return false; |
| 6225 | } |
| 6226 | |
| 6227 | if (DBG) { |
| 6228 | log("setAllowedNetworkTypesForReason: " + reason |
| 6229 | + " value: " + allowedNetworkTypes); |
| 6230 | } |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6231 | final long identity = Binder.clearCallingIdentity(); |
| 6232 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6233 | Boolean success = (Boolean) sendRequest( |
| 6234 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6235 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6236 | |
| 6237 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6238 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6239 | } finally { |
| 6240 | Binder.restoreCallingIdentity(identity); |
| 6241 | } |
| 6242 | } |
| 6243 | |
| 6244 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6245 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6246 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6247 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6248 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6249 | * @hide |
| 6250 | */ |
| 6251 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6252 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6253 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6254 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6255 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6256 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6257 | if (phone != null) { |
| 6258 | return phone.hasMatchedTetherApnSetting(); |
| 6259 | } else { |
| 6260 | return false; |
| 6261 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6262 | } finally { |
| 6263 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6264 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6265 | } |
| 6266 | |
| 6267 | /** |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6268 | * Enable or disable always reporting signal strength changes from radio. |
| 6269 | * |
| 6270 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6271 | */ |
| 6272 | @Override |
| 6273 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6274 | enforceModifyPermission(); |
| 6275 | enforceSystemCaller(); |
| 6276 | |
| 6277 | final long identity = Binder.clearCallingIdentity(); |
| 6278 | final Phone phone = getPhone(subId); |
| 6279 | try { |
| 6280 | if (phone != null) { |
| 6281 | if (DBG) { |
| 6282 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6283 | + " isEnable=" + isEnable); |
| 6284 | } |
| 6285 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6286 | } else { |
| 6287 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6288 | + subId); |
| 6289 | } |
| 6290 | } finally { |
| 6291 | Binder.restoreCallingIdentity(identity); |
| 6292 | } |
| 6293 | } |
| 6294 | |
| 6295 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6296 | * Get the user enabled state of Mobile Data. |
| 6297 | * |
| 6298 | * TODO: remove and use isUserDataEnabled. |
| 6299 | * This can't be removed now because some vendor codes |
| 6300 | * calls through ITelephony directly while they should |
| 6301 | * use TelephonyManager. |
| 6302 | * |
| 6303 | * @return true on enabled |
| 6304 | */ |
| 6305 | @Override |
| 6306 | public boolean getDataEnabled(int subId) { |
| 6307 | return isUserDataEnabled(subId); |
| 6308 | } |
| 6309 | |
| 6310 | /** |
| 6311 | * Get whether mobile data is enabled per user setting. |
| 6312 | * |
| 6313 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6314 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6315 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6316 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6317 | * |
| 6318 | * @return {@code true} if data is enabled else {@code false} |
| 6319 | */ |
| 6320 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6321 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6322 | try { |
| 6323 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6324 | null); |
| 6325 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6326 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6327 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6328 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6329 | |
| 6330 | final long identity = Binder.clearCallingIdentity(); |
| 6331 | try { |
| 6332 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6333 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6334 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6335 | if (phone != null) { |
| 6336 | boolean retVal = phone.isUserDataEnabled(); |
| 6337 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6338 | return retVal; |
| 6339 | } else { |
| 6340 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6341 | return false; |
| 6342 | } |
| 6343 | } finally { |
| 6344 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6345 | } |
| 6346 | } |
| 6347 | |
| 6348 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6349 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6350 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6351 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6352 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6353 | * @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] | 6354 | */ |
| 6355 | @Override |
| 6356 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6357 | try { |
| 6358 | try { |
| 6359 | mApp.enforceCallingOrSelfPermission( |
| 6360 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6361 | null); |
| 6362 | } catch (Exception e) { |
| 6363 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6364 | "isDataEnabled"); |
| 6365 | } |
| 6366 | } catch (Exception e) { |
| 6367 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6368 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6369 | |
| 6370 | final long identity = Binder.clearCallingIdentity(); |
| 6371 | try { |
| 6372 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6373 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6374 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6375 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6376 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6377 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6378 | return retVal; |
| 6379 | } else { |
| 6380 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6381 | return false; |
| 6382 | } |
| 6383 | } finally { |
| 6384 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6385 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6386 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6387 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6388 | /** |
| 6389 | * Check if data is enabled for a specific reason |
| 6390 | * @param subId Subscription index |
| 6391 | * @param reason the reason the data enable change is taking place |
| 6392 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6393 | */ |
| 6394 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6395 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6396 | @TelephonyManager.DataEnabledReason int reason) { |
| 6397 | try { |
| 6398 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6399 | null); |
| 6400 | } catch (Exception e) { |
| 6401 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6402 | "isDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6403 | } |
| 6404 | |
| 6405 | |
| 6406 | final long identity = Binder.clearCallingIdentity(); |
| 6407 | try { |
| 6408 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6409 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6410 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6411 | + " reason=" + reason); |
| 6412 | } |
| 6413 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6414 | if (phone != null) { |
| 6415 | boolean retVal; |
| 6416 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6417 | retVal = phone.isUserDataEnabled(); |
| 6418 | } else { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6419 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6420 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6421 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6422 | return retVal; |
| 6423 | } else { |
| 6424 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6425 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6426 | + subId + " retVal=false"); |
| 6427 | } |
| 6428 | return false; |
| 6429 | } |
| 6430 | } finally { |
| 6431 | Binder.restoreCallingIdentity(identity); |
| 6432 | } |
| 6433 | } |
| 6434 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6435 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6436 | Phone phone) { |
Hall Liu | 54a2a0c | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6437 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 6438 | // Skip the check if it's one of these special uids |
| 6439 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6440 | } |
| 6441 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6442 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6443 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6444 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6445 | || subController == null) return privilegeFromSim; |
| 6446 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6447 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6448 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6449 | |
| 6450 | final long identity = Binder.clearCallingIdentity(); |
| 6451 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6452 | int subId = phone.getSubId(); |
| 6453 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6454 | // A test override is in place for the privileges for this subId, so don't try to |
| 6455 | // read the subscription privileges. |
| 6456 | return privilegeFromSim; |
| 6457 | } |
| 6458 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6459 | SubscriptionManager subManager = (SubscriptionManager) |
| 6460 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6461 | for (String pkg : packages) { |
| 6462 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6463 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6464 | } |
| 6465 | } |
| 6466 | return privilegeFromSim; |
| 6467 | } finally { |
| 6468 | Binder.restoreCallingIdentity(identity); |
| 6469 | } |
| 6470 | } |
| 6471 | |
| 6472 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6473 | String pkgName) { |
| 6474 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6475 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6476 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6477 | || subController == null) return privilegeFromSim; |
| 6478 | |
| 6479 | final long identity = Binder.clearCallingIdentity(); |
| 6480 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6481 | int subId = phone.getSubId(); |
| 6482 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6483 | // A test override is in place for the privileges for this subId, so don't try to |
| 6484 | // read the subscription privileges. |
| 6485 | return privilegeFromSim; |
| 6486 | } |
| 6487 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6488 | SubscriptionManager subManager = (SubscriptionManager) |
| 6489 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6490 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6491 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6492 | } finally { |
| 6493 | Binder.restoreCallingIdentity(identity); |
| 6494 | } |
| 6495 | } |
| 6496 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6497 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6498 | public int getCarrierPrivilegeStatus(int subId) { |
| 6499 | final Phone phone = getPhone(subId); |
| 6500 | if (phone == null) { |
| 6501 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6502 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6503 | } |
| 6504 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6505 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6506 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6507 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6508 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6509 | |
| 6510 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6511 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6512 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6513 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6514 | |
| 6515 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6516 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6517 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6518 | final Phone phone = getPhone(subId); |
| 6519 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6520 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6521 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6522 | } |
| 6523 | UiccProfile profile = |
| 6524 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6525 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6526 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6527 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6528 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6529 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6530 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6531 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6532 | } |
| 6533 | |
| 6534 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6535 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6536 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6537 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6538 | } |
| 6539 | |
| 6540 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6541 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6542 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6543 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6544 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6545 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6546 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6547 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6548 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6549 | } |
| 6550 | |
| 6551 | @Override |
| 6552 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6553 | if (TextUtils.isEmpty(pkgName)) |
| 6554 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6555 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6556 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6557 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6558 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6559 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6560 | continue; |
| 6561 | } |
| 6562 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6563 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6564 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6565 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6566 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6567 | break; |
| 6568 | } |
| 6569 | } |
| 6570 | |
| 6571 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6572 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6573 | |
| 6574 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6575 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6576 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6577 | loge("phoneId " + phoneId + " is not valid."); |
| 6578 | return null; |
| 6579 | } |
| 6580 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6581 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6582 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6583 | return null ; |
| 6584 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6585 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6586 | } |
| 6587 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6588 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6589 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6590 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6591 | List<String> privilegedPackages = new ArrayList<>(); |
| 6592 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6593 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6594 | // has UICC in that slot. |
| 6595 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6596 | if (card.hasCarrierPrivilegeRules()) { |
| 6597 | if (packages == null) { |
| 6598 | // Only check packages in user 0 for now |
| 6599 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6600 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6601 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6602 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6603 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6604 | } |
| 6605 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6606 | PackageInfo pkgInfo = packages.get(p); |
| 6607 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6608 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6609 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6610 | privilegedPackages.add(pkgInfo.packageName); |
| 6611 | } |
| 6612 | } |
| 6613 | } |
| 6614 | } |
| 6615 | return privilegedPackages; |
| 6616 | } |
| 6617 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6618 | @Override |
| 6619 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6620 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6621 | |
| 6622 | final long identity = Binder.clearCallingIdentity(); |
| 6623 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6624 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6625 | try { |
| 6626 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6627 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6628 | } |
| 6629 | } finally { |
| 6630 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6631 | } |
| 6632 | return privilegedPackages; |
| 6633 | } |
| 6634 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6635 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6636 | final Phone phone = getPhone(subId); |
| 6637 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6638 | if (card == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6639 | return null; |
| 6640 | } |
| 6641 | String iccId = card.getIccId(); |
| 6642 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6643 | return null; |
| 6644 | } |
| 6645 | return iccId; |
| 6646 | } |
| 6647 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6648 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6649 | public void setCallComposerStatus(int subId, int status) { |
| 6650 | enforceModifyPermission(); |
| 6651 | |
| 6652 | final long identity = Binder.clearCallingIdentity(); |
| 6653 | try { |
| 6654 | Phone phone = getPhone(subId); |
| 6655 | if (phone != null) { |
| 6656 | Phone defaultPhone = phone.getImsPhone(); |
| 6657 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6658 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6659 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6660 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6661 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6662 | } |
| 6663 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6664 | } catch (ImsException e) { |
| 6665 | throw new ServiceSpecificException(e.getCode()); |
| 6666 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6667 | Binder.restoreCallingIdentity(identity); |
| 6668 | } |
| 6669 | } |
| 6670 | |
| 6671 | @Override |
| 6672 | public int getCallComposerStatus(int subId) { |
| 6673 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6674 | |
| 6675 | final long identity = Binder.clearCallingIdentity(); |
| 6676 | try { |
| 6677 | Phone phone = getPhone(subId); |
| 6678 | if (phone != null) { |
| 6679 | Phone defaultPhone = phone.getImsPhone(); |
| 6680 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6681 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6682 | return imsPhone.getCallComposerStatus(); |
| 6683 | } |
| 6684 | } |
| 6685 | } finally { |
| 6686 | Binder.restoreCallingIdentity(identity); |
| 6687 | } |
| 6688 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6689 | } |
| 6690 | |
| 6691 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6692 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6693 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6694 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6695 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6696 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6697 | final long identity = Binder.clearCallingIdentity(); |
| 6698 | try { |
| 6699 | final String iccId = getIccId(subId); |
| 6700 | final Phone phone = getPhone(subId); |
| 6701 | if (phone == null) { |
| 6702 | return false; |
| 6703 | } |
| 6704 | final String subscriberId = phone.getSubscriberId(); |
| 6705 | |
| 6706 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6707 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6708 | + subscriberId + " to " + number); |
| 6709 | } |
| 6710 | |
| 6711 | if (TextUtils.isEmpty(iccId)) { |
| 6712 | return false; |
| 6713 | } |
| 6714 | |
| 6715 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6716 | |
| 6717 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6718 | if (alphaTag == null) { |
| 6719 | editor.remove(alphaTagPrefKey); |
| 6720 | } else { |
| 6721 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6722 | } |
| 6723 | |
| 6724 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6725 | // track all merged IMSIs based on line number |
| 6726 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6727 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6728 | if (number == null) { |
| 6729 | editor.remove(numberPrefKey); |
| 6730 | editor.remove(subscriberPrefKey); |
| 6731 | } else { |
| 6732 | editor.putString(numberPrefKey, number); |
| 6733 | editor.putString(subscriberPrefKey, subscriberId); |
| 6734 | } |
| 6735 | |
| 6736 | editor.commit(); |
| 6737 | return true; |
| 6738 | } finally { |
| 6739 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6740 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6741 | } |
| 6742 | |
| 6743 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6744 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6745 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6746 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6747 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6748 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6749 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6750 | return null; |
| 6751 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6752 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6753 | final long identity = Binder.clearCallingIdentity(); |
| 6754 | try { |
| 6755 | String iccId = getIccId(subId); |
| 6756 | if (iccId != null) { |
| 6757 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6758 | if (DBG_MERGE) { |
| 6759 | log("getLine1NumberForDisplay returning " |
| 6760 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6761 | } |
| 6762 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6763 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6764 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6765 | return null; |
| 6766 | } finally { |
| 6767 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6768 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6769 | } |
| 6770 | |
| 6771 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6772 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6773 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6774 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6775 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6776 | return null; |
| 6777 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6778 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6779 | final long identity = Binder.clearCallingIdentity(); |
| 6780 | try { |
| 6781 | String iccId = getIccId(subId); |
| 6782 | if (iccId != null) { |
| 6783 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6784 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6785 | } |
| 6786 | return null; |
| 6787 | } finally { |
| 6788 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6789 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6790 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6791 | |
| 6792 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6793 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6794 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6795 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6796 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6797 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6798 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6799 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6800 | return null; |
| 6801 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6802 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6803 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6804 | // the process, where TelephonyManager was instantiated. |
| 6805 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6806 | final long identity = Binder.clearCallingIdentity(); |
| 6807 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6808 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6809 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6810 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6811 | |
| 6812 | // Figure out what subscribers are currently active |
| 6813 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6814 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6815 | // Only consider subs which match the current subId |
| 6816 | // This logic can be simplified. See b/131189269 for progress. |
| 6817 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6818 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6819 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6820 | |
| 6821 | // First pass, find a number override for an active subscriber |
| 6822 | String mergeNumber = null; |
| 6823 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6824 | for (String key : prefs.keySet()) { |
| 6825 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6826 | final String subscriberId = (String) prefs.get(key); |
| 6827 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6828 | final String iccId = key.substring( |
| 6829 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6830 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6831 | mergeNumber = (String) prefs.get(numberKey); |
| 6832 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6833 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6834 | + " for active subscriber " + subscriberId); |
| 6835 | } |
| 6836 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6837 | break; |
| 6838 | } |
| 6839 | } |
| 6840 | } |
| 6841 | } |
| 6842 | |
| 6843 | // Shortcut when no active merged subscribers |
| 6844 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6845 | return null; |
| 6846 | } |
| 6847 | |
| 6848 | // Second pass, find all subscribers under that line override |
| 6849 | final ArraySet<String> result = new ArraySet<>(); |
| 6850 | for (String key : prefs.keySet()) { |
| 6851 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6852 | final String number = (String) prefs.get(key); |
| 6853 | if (mergeNumber.equals(number)) { |
| 6854 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6855 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6856 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6857 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6858 | result.add(subscriberId); |
| 6859 | } |
| 6860 | } |
| 6861 | } |
| 6862 | } |
| 6863 | |
| 6864 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6865 | Arrays.sort(resultArray); |
| 6866 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6867 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6868 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6869 | } |
| 6870 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6871 | } finally { |
| 6872 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6873 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6874 | } |
| 6875 | |
| 6876 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6877 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6878 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6879 | |
| 6880 | final long identity = Binder.clearCallingIdentity(); |
| 6881 | try { |
| 6882 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6883 | TelephonyManager.class); |
| 6884 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6885 | if (subscriberId == null) { |
| 6886 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6887 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6888 | + subId); |
| 6889 | } |
| 6890 | return null; |
| 6891 | } |
| 6892 | |
| 6893 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6894 | .getSubscriptionInfo(subId); |
| 6895 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6896 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6897 | if (groupUuid == null) { |
| 6898 | return new String[]{subscriberId}; |
| 6899 | } |
| 6900 | |
| 6901 | // Get all subscriberIds from the group. |
| 6902 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6903 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6904 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6905 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6906 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6907 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6908 | if (subscriberId != null) { |
| 6909 | mergedSubscriberIds.add(subscriberId); |
| 6910 | } |
| 6911 | } |
| 6912 | |
| 6913 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6914 | } finally { |
| 6915 | Binder.restoreCallingIdentity(identity); |
| 6916 | |
| 6917 | } |
| 6918 | } |
| 6919 | |
| 6920 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6921 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6922 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6923 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6924 | |
| 6925 | final long identity = Binder.clearCallingIdentity(); |
| 6926 | try { |
| 6927 | final Phone phone = getPhone(subId); |
| 6928 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6929 | } finally { |
| 6930 | Binder.restoreCallingIdentity(identity); |
| 6931 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6932 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6933 | |
| 6934 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6935 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6936 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6937 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6938 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6939 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6940 | |
| 6941 | final long identity = Binder.clearCallingIdentity(); |
| 6942 | try { |
| 6943 | final Phone phone = getPhone(subId); |
| 6944 | if (phone == null) { |
| 6945 | return false; |
| 6946 | } |
| 6947 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6948 | cdmaNonRoamingList); |
| 6949 | } finally { |
| 6950 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6951 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6952 | } |
| 6953 | |
| 6954 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6955 | @Deprecated |
| 6956 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6957 | enforceModifyPermission(); |
| 6958 | |
| 6959 | int returnValue = 0; |
| 6960 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6961 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6962 | if(result.exception == null) { |
| 6963 | if (result.result != null) { |
| 6964 | byte[] responseData = (byte[])(result.result); |
| 6965 | if(responseData.length > oemResp.length) { |
| 6966 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6967 | responseData.length + "bytes. Buffer Size is " + |
| 6968 | oemResp.length + "bytes."); |
| 6969 | } |
| 6970 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6971 | returnValue = responseData.length; |
| 6972 | } |
| 6973 | } else { |
| 6974 | CommandException ex = (CommandException) result.exception; |
| 6975 | returnValue = ex.getCommandError().ordinal(); |
| 6976 | if(returnValue > 0) returnValue *= -1; |
| 6977 | } |
| 6978 | } catch (RuntimeException e) { |
| 6979 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6980 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6981 | if(returnValue > 0) returnValue *= -1; |
| 6982 | } |
| 6983 | |
| 6984 | return returnValue; |
| 6985 | } |
| 6986 | |
| 6987 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6988 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6989 | try { |
| 6990 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6991 | } catch (RuntimeException e) { |
| 6992 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6993 | } |
| 6994 | } |
| 6995 | |
| 6996 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6997 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6998 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 6999 | try { |
| 7000 | TelephonyPermissions |
| 7001 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 7002 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7003 | } catch (SecurityException e) { |
| 7004 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7005 | throw e; |
| 7006 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7007 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7008 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7009 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7010 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7011 | final long identity = Binder.clearCallingIdentity(); |
| 7012 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7013 | TelephonyPermissions |
| 7014 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 7015 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7016 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7017 | } finally { |
| 7018 | Binder.restoreCallingIdentity(identity); |
| 7019 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7020 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7021 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7022 | |
| 7023 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7024 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7025 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7026 | try { |
| 7027 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7028 | Binder.getCallingUid())) { |
| 7029 | throw new SecurityException("Package uid and package name do not match: " |
| 7030 | + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage); |
| 7031 | } |
| 7032 | } catch (PackageManager.NameNotFoundException e) { |
| 7033 | throw new SecurityException("Package name invalid:" + callingPackage); |
| 7034 | } |
| 7035 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7036 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7037 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7038 | throw new SecurityException("App must be the dialer role holder to" |
| 7039 | + " upload a call composer pic"); |
| 7040 | } |
| 7041 | |
| 7042 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7043 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7044 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7045 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7046 | boolean readUntilEnd = false; |
| 7047 | int totalBytesRead = 0; |
| 7048 | byte[] buffer = new byte[16 * 1024]; |
| 7049 | while (true) { |
| 7050 | int numRead; |
| 7051 | try { |
| 7052 | numRead = input.read(buffer); |
| 7053 | } catch (IOException e) { |
| 7054 | try { |
| 7055 | fd.checkError(); |
| 7056 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7057 | null); |
| 7058 | } catch (IOException e1) { |
| 7059 | // This means that the other side closed explicitly with an error. If this |
| 7060 | // happens, log and ignore. |
| 7061 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7062 | } |
| 7063 | break; |
| 7064 | } |
| 7065 | if (numRead == -1) { |
| 7066 | readUntilEnd = true; |
| 7067 | break; |
| 7068 | } |
| 7069 | totalBytesRead += numRead; |
| 7070 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7071 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7072 | try { |
| 7073 | input.close(); |
| 7074 | } catch (IOException e) { |
| 7075 | // ignore |
| 7076 | } |
| 7077 | break; |
| 7078 | } |
| 7079 | output.write(buffer, 0, numRead); |
| 7080 | } |
| 7081 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7082 | // close is above, where the picture size is too big. |
| 7083 | |
| 7084 | try { |
| 7085 | fd.checkError(); |
| 7086 | } catch (IOException e) { |
| 7087 | loge("Remote end for call composer closed with an error: " + e); |
| 7088 | return; |
| 7089 | } |
| 7090 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7091 | if (!readUntilEnd) { |
| 7092 | loge("Did not finish reading entire image; aborting"); |
| 7093 | return; |
| 7094 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7095 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7096 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7097 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7098 | new CallComposerPictureTransfer.Factory() {}, |
| 7099 | imageData, |
| 7100 | (result) -> { |
| 7101 | if (result.first != null) { |
| 7102 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7103 | Bundle outputResult = new Bundle(); |
| 7104 | outputResult.putParcelable( |
| 7105 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7106 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7107 | outputResult); |
| 7108 | } else { |
| 7109 | callback.send(result.second, null); |
| 7110 | } |
| 7111 | } |
| 7112 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7113 | }); |
| 7114 | } |
| 7115 | |
| 7116 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7117 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7118 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7119 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7120 | |
| 7121 | final long identity = Binder.clearCallingIdentity(); |
| 7122 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7123 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7124 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7125 | } finally { |
| 7126 | Binder.restoreCallingIdentity(identity); |
| 7127 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7128 | } |
| 7129 | |
| 7130 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7131 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7132 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7133 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7134 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7135 | return false; |
| 7136 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7137 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7138 | final long identity = Binder.clearCallingIdentity(); |
| 7139 | try { |
| 7140 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7141 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7142 | // In the long run, we may instead need to check if there exists a connection service |
| 7143 | // which can support video calling. |
| 7144 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7145 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7146 | return imsManager.isVtEnabledByPlatform() |
| 7147 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7148 | && imsManager.isVtEnabledByUser(); |
| 7149 | } finally { |
| 7150 | Binder.restoreCallingIdentity(identity); |
| 7151 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7152 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7153 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7154 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7155 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7156 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7157 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7158 | mApp, subId, callingPackage, callingFeatureId, |
| 7159 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7160 | return false; |
| 7161 | } |
| 7162 | |
| 7163 | final long identity = Binder.clearCallingIdentity(); |
| 7164 | try { |
| 7165 | CarrierConfigManager configManager = |
| 7166 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7167 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7168 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7169 | } finally { |
| 7170 | Binder.restoreCallingIdentity(identity); |
| 7171 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7172 | } |
| 7173 | |
| 7174 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7175 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7176 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7177 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7178 | return false; |
| 7179 | } |
| 7180 | |
| 7181 | final long identity = Binder.clearCallingIdentity(); |
| 7182 | try { |
| 7183 | CarrierConfigManager configManager = |
| 7184 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7185 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7186 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7187 | } finally { |
| 7188 | Binder.restoreCallingIdentity(identity); |
| 7189 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7190 | } |
| 7191 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7192 | @Override |
| 7193 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7194 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7195 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7196 | } |
| 7197 | |
| 7198 | @Override |
| 7199 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7200 | final long identity = Binder.clearCallingIdentity(); |
| 7201 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7202 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7203 | } finally { |
| 7204 | Binder.restoreCallingIdentity(identity); |
| 7205 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7206 | } |
| 7207 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7208 | /** |
| 7209 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7210 | * support for the feature and device firmware support. |
| 7211 | * |
| 7212 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7213 | */ |
| 7214 | @Override |
| 7215 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7216 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7217 | final Phone phone = getPhone(subscriptionId); |
| 7218 | if (phone == null) { |
| 7219 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7220 | return false; |
| 7221 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7222 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7223 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7224 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7225 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7226 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7227 | return isCarrierSupported && isDeviceSupported; |
| 7228 | } finally { |
| 7229 | Binder.restoreCallingIdentity(identity); |
| 7230 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7231 | } |
| 7232 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7233 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7234 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7235 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7236 | * 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] | 7237 | */ |
| 7238 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7239 | final long identity = Binder.clearCallingIdentity(); |
| 7240 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7241 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7242 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7243 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7244 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7245 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7246 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7247 | } finally { |
| 7248 | Binder.restoreCallingIdentity(identity); |
| 7249 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7250 | } |
| 7251 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7252 | @Deprecated |
| 7253 | @Override |
| 7254 | public String getDeviceId(String callingPackage) { |
| 7255 | return getDeviceIdWithFeature(callingPackage, null); |
| 7256 | } |
| 7257 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7258 | /** |
| 7259 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7260 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7261 | * |
| 7262 | * <p>Requires Permission: |
| 7263 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7264 | */ |
| 7265 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7266 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7267 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7268 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7269 | return null; |
| 7270 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7271 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7272 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7273 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7274 | return null; |
| 7275 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7276 | |
| 7277 | final long identity = Binder.clearCallingIdentity(); |
| 7278 | try { |
| 7279 | return phone.getDeviceId(); |
| 7280 | } finally { |
| 7281 | Binder.restoreCallingIdentity(identity); |
| 7282 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7283 | } |
| 7284 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7285 | /** |
| 7286 | * {@hide} |
| 7287 | * Returns the IMS Registration Status on a particular subid |
| 7288 | * |
| 7289 | * @param subId |
| 7290 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7291 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7292 | Phone phone = getPhone(subId); |
| 7293 | if (phone != null) { |
| 7294 | return phone.isImsRegistered(); |
| 7295 | } else { |
| 7296 | return false; |
| 7297 | } |
| 7298 | } |
| 7299 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7300 | @Override |
| 7301 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7302 | final long identity = Binder.clearCallingIdentity(); |
| 7303 | try { |
| 7304 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 7305 | } finally { |
| 7306 | Binder.restoreCallingIdentity(identity); |
| 7307 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7308 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7309 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7310 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7311 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7312 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7313 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7314 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7315 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7316 | } |
| 7317 | final long identity = Binder.clearCallingIdentity(); |
| 7318 | try { |
| 7319 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7320 | } finally { |
| 7321 | Binder.restoreCallingIdentity(identity); |
| 7322 | } |
| 7323 | } |
| 7324 | |
| 7325 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7326 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 7327 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 7328 | + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7329 | final long identity = Binder.clearCallingIdentity(); |
| 7330 | try { |
| 7331 | Phone phone = getPhone(subscriptionId); |
| 7332 | if (phone == null) { |
| 7333 | return null; |
| 7334 | } |
| 7335 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7336 | } finally { |
| 7337 | Binder.restoreCallingIdentity(identity); |
| 7338 | } |
| 7339 | } |
| 7340 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7341 | /** |
| 7342 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7343 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7344 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7345 | final long identity = Binder.clearCallingIdentity(); |
| 7346 | try { |
| 7347 | Phone phone = getPhone(subId); |
| 7348 | if (phone != null) { |
| 7349 | return phone.isWifiCallingEnabled(); |
| 7350 | } else { |
| 7351 | return false; |
| 7352 | } |
| 7353 | } finally { |
| 7354 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7355 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7356 | } |
| 7357 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7358 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7359 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7360 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7361 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7362 | final long identity = Binder.clearCallingIdentity(); |
| 7363 | try { |
| 7364 | Phone phone = getPhone(subId); |
| 7365 | if (phone != null) { |
| 7366 | return phone.isVideoEnabled(); |
| 7367 | } else { |
| 7368 | return false; |
| 7369 | } |
| 7370 | } finally { |
| 7371 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7372 | } |
| 7373 | } |
| 7374 | |
| 7375 | /** |
| 7376 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7377 | * defined in {@link ImsRegistrationImplBase}. |
| 7378 | */ |
| 7379 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7380 | final long identity = Binder.clearCallingIdentity(); |
| 7381 | try { |
| 7382 | Phone phone = getPhone(subId); |
| 7383 | if (phone != null) { |
| 7384 | return phone.getImsRegistrationTech(); |
| 7385 | } else { |
| 7386 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7387 | } |
| 7388 | } finally { |
| 7389 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7390 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7391 | } |
| 7392 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7393 | @Override |
| 7394 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7395 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7396 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7397 | return; |
| 7398 | } |
| 7399 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7400 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7401 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7402 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7403 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7404 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7405 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7406 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7407 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7408 | setAllowedNetworkTypesForReason(subId, |
| 7409 | TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7410 | RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId))); |
| 7411 | setAllowedNetworkTypesForReason(subId, |
| 7412 | TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER, |
| 7413 | RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId))); |
| 7414 | setAllowedNetworkTypesForReason(subId, |
| 7415 | TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER, |
| 7416 | RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId))); |
Yomna Nasser | 3f777b6 | 2021-02-17 03:38:52 +0000 | [diff] [blame] | 7417 | setAllowedNetworkTypesForReason(subId, |
| 7418 | TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G, |
| 7419 | RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId))); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7420 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 7421 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7422 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7423 | // There has been issues when Sms raw table somehow stores orphan |
| 7424 | // fragments. They lead to garbled message when new fragments come |
| 7425 | // in and combined with those stale ones. In case this happens again, |
| 7426 | // user can reset all network settings which will clean up this table. |
| 7427 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7428 | // Clean up IMS settings as well here. |
| 7429 | int slotId = getSlotIndex(subId); |
| 7430 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7431 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7432 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7433 | |
| 7434 | // Erase modem config if erase modem on network setting is enabled. |
| 7435 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7436 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7437 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 7438 | sendEraseModemConfig(getDefaultPhone()); |
| 7439 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7440 | } finally { |
| 7441 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7442 | } |
| 7443 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7444 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7445 | private void cleanUpSmsRawTable(Context context) { |
| 7446 | ContentResolver resolver = context.getContentResolver(); |
| 7447 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7448 | resolver.delete(uri, null, null); |
| 7449 | } |
| 7450 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7451 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7452 | public String getSimLocaleForSubscriber(int subId) { |
| 7453 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7454 | final Phone phone = getPhone(subId); |
| 7455 | if (phone == null) { |
| 7456 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7457 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7458 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7459 | final long identity = Binder.clearCallingIdentity(); |
| 7460 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7461 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7462 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7463 | if (info == null) { |
| 7464 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7465 | return null; |
| 7466 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7467 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7468 | // preferences (EF-PL and EF-LI)... |
| 7469 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7470 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7471 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7472 | if (localeFromDefaultSim != null) { |
| 7473 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7474 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7475 | + localeFromDefaultSim); |
| 7476 | return localeFromDefaultSim.toLanguageTag(); |
| 7477 | } else { |
| 7478 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7479 | } |
| 7480 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7481 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7482 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7483 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7484 | // the SIM and carrier preferences does not include a country we add the country |
| 7485 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7486 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7487 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7488 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7489 | return mccLocale.toLanguageTag(); |
| 7490 | } |
| 7491 | |
| 7492 | if (DBG) log("No locale found - returning null"); |
| 7493 | return null; |
| 7494 | } finally { |
| 7495 | Binder.restoreCallingIdentity(identity); |
| 7496 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7497 | } |
| 7498 | |
| 7499 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7500 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7501 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7502 | } |
| 7503 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7504 | /** |
| 7505 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7506 | */ |
| 7507 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7508 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7509 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7510 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7511 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7512 | private final ModemActivityInfo mLastModemActivityInfo = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7513 | new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7514 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7515 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7516 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7517 | * representing the state of the modem. |
| 7518 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7519 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7520 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7521 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7522 | */ |
| 7523 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7524 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7525 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7526 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7527 | |
| 7528 | final long identity = Binder.clearCallingIdentity(); |
| 7529 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7530 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7531 | } finally { |
| 7532 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7533 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7534 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7535 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7536 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7537 | // less than total activity duration. |
| 7538 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7539 | if (info == null) { |
| 7540 | return false; |
| 7541 | } |
| 7542 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7543 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7544 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7545 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7546 | return (info.isValid() |
| 7547 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7548 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7549 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7550 | && (totalTxTimeMs <= activityDurationMs)); |
| 7551 | } |
| 7552 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7553 | /** |
| 7554 | * {@hide} |
| 7555 | * Returns the service state information on specified subscription. |
| 7556 | */ |
| 7557 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7558 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7559 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7560 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7561 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7562 | return null; |
| 7563 | } |
| 7564 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7565 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7566 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7567 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7568 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7569 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7570 | .setCallingPid(Binder.getCallingPid()) |
| 7571 | .setCallingUid(Binder.getCallingUid()) |
| 7572 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7573 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7574 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7575 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7576 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7577 | .build()); |
| 7578 | |
| 7579 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7580 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7581 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7582 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7583 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7584 | .setCallingPid(Binder.getCallingPid()) |
| 7585 | .setCallingUid(Binder.getCallingUid()) |
| 7586 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7587 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7588 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7589 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7590 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7591 | .build()); |
| 7592 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7593 | boolean hasFinePermission = |
| 7594 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7595 | boolean hasCoarsePermission = |
| 7596 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7597 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7598 | final Phone phone = getPhone(subId); |
| 7599 | if (phone == null) { |
| 7600 | return null; |
| 7601 | } |
| 7602 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 7603 | final long identity = Binder.clearCallingIdentity(); |
| 7604 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7605 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7606 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7607 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7608 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7609 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7610 | Rlog.d(LOG_TAG, |
| 7611 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7612 | return null; |
| 7613 | } |
| 7614 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7615 | ServiceState ss = phone.getServiceState(); |
| 7616 | |
| 7617 | // Scrub out the location info in ServiceState depending on what level of access |
| 7618 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7619 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7620 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7621 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7622 | } finally { |
| 7623 | Binder.restoreCallingIdentity(identity); |
| 7624 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7625 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7626 | |
| 7627 | /** |
| 7628 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7629 | * |
| 7630 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7631 | * voicemail ringtone. |
| 7632 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7633 | * PhoneAccount. |
| 7634 | */ |
| 7635 | @Override |
| 7636 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7637 | final long identity = Binder.clearCallingIdentity(); |
| 7638 | try { |
| 7639 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7640 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7641 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7642 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7643 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7644 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7645 | } finally { |
| 7646 | Binder.restoreCallingIdentity(identity); |
| 7647 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7648 | } |
| 7649 | |
| 7650 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7651 | * Sets the per-account voicemail ringtone. |
| 7652 | * |
| 7653 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7654 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7655 | * |
| 7656 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7657 | * voicemail ringtone. |
| 7658 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7659 | * PhoneAccount. |
| 7660 | */ |
| 7661 | @Override |
| 7662 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7663 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7664 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7665 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7666 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7667 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7668 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7669 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7670 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7671 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7672 | |
| 7673 | final long identity = Binder.clearCallingIdentity(); |
| 7674 | try { |
| 7675 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7676 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7677 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7678 | } |
| 7679 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7680 | } finally { |
| 7681 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7682 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7683 | } |
| 7684 | |
| 7685 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7686 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7687 | * |
| 7688 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7689 | * voicemail vibration setting. |
| 7690 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7691 | */ |
| 7692 | @Override |
| 7693 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7694 | final long identity = Binder.clearCallingIdentity(); |
| 7695 | try { |
| 7696 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7697 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7698 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7699 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7700 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7701 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7702 | } finally { |
| 7703 | Binder.restoreCallingIdentity(identity); |
| 7704 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7705 | } |
| 7706 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7707 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7708 | * Sets the per-account voicemail vibration. |
| 7709 | * |
| 7710 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7711 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7712 | * |
| 7713 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7714 | * voicemail vibration setting. |
| 7715 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7716 | * specific PhoneAccount. |
| 7717 | */ |
| 7718 | @Override |
| 7719 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7720 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7721 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7722 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7723 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7724 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7725 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7726 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7727 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7728 | } |
| 7729 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7730 | final long identity = Binder.clearCallingIdentity(); |
| 7731 | try { |
| 7732 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7733 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7734 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7735 | } |
| 7736 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7737 | } finally { |
| 7738 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7739 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7740 | } |
| 7741 | |
| 7742 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7743 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7744 | * |
| 7745 | * @throws SecurityException if the caller does not have the required permission |
| 7746 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7747 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7748 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7749 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7750 | } |
| 7751 | |
| 7752 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7753 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7754 | * permission. |
| 7755 | * |
| 7756 | * @throws SecurityException if the caller does not have the required permission |
| 7757 | */ |
| 7758 | private void enforceSendSmsPermission() { |
| 7759 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7760 | } |
| 7761 | |
| 7762 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7763 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7764 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7765 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7766 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7767 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7768 | final long identity = Binder.clearCallingIdentity(); |
| 7769 | try { |
| 7770 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7771 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7772 | if (componentName == null) { |
| 7773 | throw new SecurityException( |
| 7774 | "Caller not current active visual voicemail package[null]"); |
| 7775 | } |
| 7776 | String vvmPackage = componentName.getPackageName(); |
| 7777 | if (!callingPackage.equals(vvmPackage)) { |
| 7778 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7779 | + vvmPackage + "]"); |
| 7780 | } |
| 7781 | } finally { |
| 7782 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7783 | } |
| 7784 | } |
| 7785 | |
| 7786 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7787 | * Return the application ID for the app type. |
| 7788 | * |
| 7789 | * @param subId the subscription ID that this request applies to. |
| 7790 | * @param appType the uicc app type. |
| 7791 | * @return Application ID for specificied app type, or null if no uicc. |
| 7792 | */ |
| 7793 | @Override |
| 7794 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7795 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7796 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7797 | |
| 7798 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7799 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7800 | if (phone == null) { |
| 7801 | return null; |
| 7802 | } |
| 7803 | String aid = null; |
| 7804 | try { |
| 7805 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7806 | .getApplicationByType(appType).getAid(); |
| 7807 | } catch (Exception e) { |
| 7808 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7809 | } |
| 7810 | return aid; |
| 7811 | } finally { |
| 7812 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7813 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7814 | } |
| 7815 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7816 | /** |
| 7817 | * Return the Electronic Serial Number. |
| 7818 | * |
| 7819 | * @param subId the subscription ID that this request applies to. |
| 7820 | * @return ESN or null if error. |
| 7821 | */ |
| 7822 | @Override |
| 7823 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7824 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7825 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7826 | |
| 7827 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7828 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7829 | if (phone == null) { |
| 7830 | return null; |
| 7831 | } |
| 7832 | String esn = null; |
| 7833 | try { |
| 7834 | esn = phone.getEsn(); |
| 7835 | } catch (Exception e) { |
| 7836 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7837 | } |
| 7838 | return esn; |
| 7839 | } finally { |
| 7840 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7841 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7842 | } |
| 7843 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7844 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7845 | * Return the Preferred Roaming List Version. |
| 7846 | * |
| 7847 | * @param subId the subscription ID that this request applies to. |
| 7848 | * @return PRLVersion or null if error. |
| 7849 | */ |
| 7850 | @Override |
| 7851 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7852 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7853 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7854 | |
| 7855 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7856 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7857 | if (phone == null) { |
| 7858 | return null; |
| 7859 | } |
| 7860 | String cdmaPrlVersion = null; |
| 7861 | try { |
| 7862 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7863 | } catch (Exception e) { |
| 7864 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7865 | } |
| 7866 | return cdmaPrlVersion; |
| 7867 | } finally { |
| 7868 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7869 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7870 | } |
| 7871 | |
| 7872 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7873 | * Get snapshot of Telephony histograms |
| 7874 | * @return List of Telephony histograms |
| 7875 | * @hide |
| 7876 | */ |
| 7877 | @Override |
| 7878 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7879 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7880 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7881 | |
| 7882 | final long identity = Binder.clearCallingIdentity(); |
| 7883 | try { |
| 7884 | return RIL.getTelephonyRILTimingHistograms(); |
| 7885 | } finally { |
| 7886 | Binder.restoreCallingIdentity(identity); |
| 7887 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7888 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7889 | |
| 7890 | /** |
| 7891 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7892 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7893 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7894 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7895 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7896 | * @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] | 7897 | */ |
| 7898 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7899 | @TelephonyManager.SetCarrierRestrictionResult |
| 7900 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7901 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7902 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7903 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7904 | if (carrierRestrictionRules == null) { |
| 7905 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7906 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7907 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7908 | final long identity = Binder.clearCallingIdentity(); |
| 7909 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7910 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7911 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7912 | } finally { |
| 7913 | Binder.restoreCallingIdentity(identity); |
| 7914 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7915 | } |
| 7916 | |
| 7917 | /** |
| 7918 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7919 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7920 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7921 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7922 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7923 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7924 | */ |
| 7925 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7926 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7927 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7928 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7929 | |
| 7930 | final long identity = Binder.clearCallingIdentity(); |
| 7931 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7932 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7933 | if (response instanceof CarrierRestrictionRules) { |
| 7934 | return (CarrierRestrictionRules) response; |
| 7935 | } |
| 7936 | // Response is an Exception of some kind, |
| 7937 | // which is signalled to the user as a NULL retval |
| 7938 | return null; |
| 7939 | } catch (Exception e) { |
| 7940 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7941 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7942 | } finally { |
| 7943 | Binder.restoreCallingIdentity(identity); |
| 7944 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7945 | } |
| 7946 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7947 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7948 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7949 | * @param subId the subscription ID that this action applies to. |
| 7950 | * @param enabled control enable or disable radio. |
| 7951 | * {@hide} |
| 7952 | */ |
| 7953 | @Override |
| 7954 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7955 | enforceModifyPermission(); |
| 7956 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7957 | |
| 7958 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7959 | if (phone == null) { |
| 7960 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7961 | return; |
| 7962 | } |
| 7963 | try { |
| 7964 | phone.carrierActionSetRadioEnabled(enabled); |
| 7965 | } catch (Exception e) { |
| 7966 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7967 | } finally { |
| 7968 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7969 | } |
| 7970 | } |
| 7971 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7972 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7973 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7974 | * network status based on which carrier apps could apply actions accordingly, |
| 7975 | * enable/disable default url handler for example. |
| 7976 | * |
| 7977 | * @param subId the subscription ID that this action applies to. |
| 7978 | * @param report control start/stop reporting the default network status. |
| 7979 | * {@hide} |
| 7980 | */ |
| 7981 | @Override |
| 7982 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7983 | enforceModifyPermission(); |
| 7984 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7985 | |
| 7986 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7987 | if (phone == null) { |
| 7988 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7989 | return; |
| 7990 | } |
| 7991 | try { |
| 7992 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7993 | } catch (Exception e) { |
| 7994 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7995 | } finally { |
| 7996 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7997 | } |
| 7998 | } |
| 7999 | |
| 8000 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8001 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8002 | * @param subId the subscription ID that this action applies to. |
| 8003 | * {@hide} |
| 8004 | */ |
| 8005 | @Override |
| 8006 | public void carrierActionResetAll(int subId) { |
| 8007 | enforceModifyPermission(); |
| 8008 | final Phone phone = getPhone(subId); |
| 8009 | if (phone == null) { |
| 8010 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8011 | return; |
| 8012 | } |
| 8013 | try { |
| 8014 | phone.carrierActionResetAll(); |
| 8015 | } catch (Exception e) { |
| 8016 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8017 | } |
| 8018 | } |
| 8019 | |
| 8020 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8021 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8022 | * bug report is being generated. |
| 8023 | */ |
| 8024 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8025 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8026 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8027 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8028 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8029 | + Binder.getCallingPid() |
| 8030 | + ", uid=" + Binder.getCallingUid() |
| 8031 | + "without permission " |
| 8032 | + android.Manifest.permission.DUMP); |
| 8033 | return; |
| 8034 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8035 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8036 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8037 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8038 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8039 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8040 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8041 | @NonNull String[] args) { |
| 8042 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8043 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8044 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8045 | } |
| 8046 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8047 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8048 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8049 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8050 | * @param reason the reason the data enable change is taking place |
| 8051 | * @param enabled True if enabling the data, otherwise disabling. |
| 8052 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8053 | */ |
| 8054 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8055 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8056 | boolean enabled) { |
| 8057 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8058 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8059 | try { |
| 8060 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8061 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8062 | } catch (SecurityException se) { |
| 8063 | enforceModifyPermission(); |
| 8064 | } |
| 8065 | } else { |
| 8066 | enforceModifyPermission(); |
| 8067 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8068 | |
| 8069 | final long identity = Binder.clearCallingIdentity(); |
| 8070 | try { |
| 8071 | Phone phone = getPhone(subId); |
| 8072 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8073 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8074 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8075 | } else { |
| 8076 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 8077 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8078 | } |
| 8079 | } finally { |
| 8080 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8081 | } |
| 8082 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8083 | |
| 8084 | /** |
| 8085 | * Get Client request stats |
| 8086 | * @return List of Client Request Stats |
| 8087 | * @hide |
| 8088 | */ |
| 8089 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8090 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8091 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8092 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8093 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8094 | return null; |
| 8095 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8096 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8097 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8098 | final long identity = Binder.clearCallingIdentity(); |
| 8099 | try { |
| 8100 | if (phone != null) { |
| 8101 | return phone.getClientRequestStats(); |
| 8102 | } |
| 8103 | |
| 8104 | return null; |
| 8105 | } finally { |
| 8106 | Binder.restoreCallingIdentity(identity); |
| 8107 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8108 | } |
| 8109 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8110 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8111 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8112 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8113 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8114 | |
| 8115 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8116 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8117 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8118 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8119 | * @param state State of SIM (power down, power up, pass through) |
| 8120 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8121 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8122 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8123 | * |
| 8124 | **/ |
| 8125 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8126 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8127 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8128 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8129 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8130 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8131 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8132 | final long identity = Binder.clearCallingIdentity(); |
| 8133 | try { |
| 8134 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8135 | phone.setSimPowerState(state, null, workSource); |
| 8136 | } |
| 8137 | } finally { |
| 8138 | Binder.restoreCallingIdentity(identity); |
| 8139 | } |
| 8140 | } |
| 8141 | |
| 8142 | /** |
| 8143 | * Set SIM card power state. |
| 8144 | * |
| 8145 | * @param slotIndex SIM slot id. |
| 8146 | * @param state State of SIM (power down, power up, pass through) |
| 8147 | * @param callback callback to trigger after success or failure |
| 8148 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8149 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8150 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8151 | * |
| 8152 | **/ |
| 8153 | @Override |
| 8154 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8155 | IIntegerConsumer callback) { |
| 8156 | enforceModifyPermission(); |
| 8157 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8158 | |
| 8159 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8160 | |
| 8161 | final long identity = Binder.clearCallingIdentity(); |
| 8162 | try { |
| 8163 | if (phone != null) { |
| 8164 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8165 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8166 | } |
| 8167 | } finally { |
| 8168 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8169 | } |
| 8170 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8171 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8172 | private boolean isUssdApiAllowed(int subId) { |
| 8173 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8174 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8175 | if (configManager == null) { |
| 8176 | return false; |
| 8177 | } |
| 8178 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8179 | if (pb == null) { |
| 8180 | return false; |
| 8181 | } |
| 8182 | return pb.getBoolean( |
| 8183 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8184 | } |
| 8185 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8186 | /** |
| 8187 | * Check if phone is in emergency callback mode |
| 8188 | * @return true if phone is in emergency callback mode |
| 8189 | * @param subId sub id |
| 8190 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8191 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8192 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8193 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8194 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8195 | |
| 8196 | final long identity = Binder.clearCallingIdentity(); |
| 8197 | try { |
| 8198 | if (phone != null) { |
| 8199 | return phone.isInEcm(); |
| 8200 | } else { |
| 8201 | return false; |
| 8202 | } |
| 8203 | } finally { |
| 8204 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8205 | } |
| 8206 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8207 | |
| 8208 | /** |
| 8209 | * Get the current signal strength information for the given subscription. |
| 8210 | * Because this information is not updated when the device is in a low power state |
| 8211 | * it should not be relied-upon to be current. |
| 8212 | * @param subId Subscription index |
| 8213 | * @return the most recent cached signal strength info from the modem |
| 8214 | */ |
| 8215 | @Override |
| 8216 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8217 | final long identity = Binder.clearCallingIdentity(); |
| 8218 | try { |
| 8219 | Phone p = getPhone(subId); |
| 8220 | if (p == null) { |
| 8221 | return null; |
| 8222 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8223 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8224 | return p.getSignalStrength(); |
| 8225 | } finally { |
| 8226 | Binder.restoreCallingIdentity(identity); |
| 8227 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8228 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8229 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8230 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8231 | * Get the current modem radio state for the given slot. |
| 8232 | * @param slotIndex slot index. |
| 8233 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8234 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8235 | * @return the current radio power state from the modem |
| 8236 | */ |
| 8237 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8238 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8239 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8240 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8241 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8242 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8243 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8244 | } |
| 8245 | |
| 8246 | final long identity = Binder.clearCallingIdentity(); |
| 8247 | try { |
| 8248 | return phone.getRadioPowerState(); |
| 8249 | } finally { |
| 8250 | Binder.restoreCallingIdentity(identity); |
| 8251 | } |
| 8252 | } |
| 8253 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8254 | } |
| 8255 | |
| 8256 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8257 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8258 | * |
| 8259 | * <p>Requires one of the following permissions: |
| 8260 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 8261 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8262 | * privileges. |
| 8263 | * |
| 8264 | * @param subId subscription id |
| 8265 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8266 | * {@code false}. |
| 8267 | */ |
| 8268 | @Override |
| 8269 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8270 | try { |
| 8271 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8272 | null); |
| 8273 | } catch (Exception e) { |
| 8274 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 8275 | mApp, subId, "isDataRoamingEnabled"); |
| 8276 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8277 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8278 | boolean isEnabled = false; |
| 8279 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8280 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8281 | Phone phone = getPhone(subId); |
| 8282 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8283 | } finally { |
| 8284 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8285 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8286 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8287 | } |
| 8288 | |
| 8289 | |
| 8290 | /** |
| 8291 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8292 | * |
| 8293 | * <p> Requires permission: |
| 8294 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8295 | * privileges. |
| 8296 | * |
| 8297 | * @param subId subscription id |
| 8298 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8299 | */ |
| 8300 | @Override |
| 8301 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8302 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8303 | mApp, subId, "setDataRoamingEnabled"); |
| 8304 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8305 | final long identity = Binder.clearCallingIdentity(); |
| 8306 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8307 | Phone phone = getPhone(subId); |
| 8308 | if (phone != null) { |
| 8309 | phone.setDataRoamingEnabled(isEnabled); |
| 8310 | } |
| 8311 | } finally { |
| 8312 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8313 | } |
| 8314 | } |
| 8315 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8316 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8317 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8318 | TelephonyPermissions |
| 8319 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8320 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8321 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8322 | boolean isAllowed = true; |
| 8323 | final long identity = Binder.clearCallingIdentity(); |
| 8324 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8325 | Phone phone = getPhone(subId); |
| 8326 | if (phone != null) { |
| 8327 | isAllowed = phone.isCspPlmnEnabled(); |
| 8328 | } |
| 8329 | } finally { |
| 8330 | Binder.restoreCallingIdentity(identity); |
| 8331 | } |
| 8332 | return isAllowed; |
| 8333 | } |
| 8334 | |
| 8335 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8336 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8337 | // Verify that tha callingPackage belongs to the calling UID |
| 8338 | mApp.getSystemService(AppOpsManager.class) |
| 8339 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8340 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8341 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8342 | try { |
| 8343 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8344 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8345 | } catch (SecurityException e) { |
| 8346 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8347 | // has carrier privileges on an active UICC |
| 8348 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8349 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8350 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8351 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8352 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8353 | |
| 8354 | final long identity = Binder.clearCallingIdentity(); |
| 8355 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8356 | UiccController uiccController = UiccController.getInstance(); |
| 8357 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8358 | if (hasReadPermission) { |
| 8359 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8360 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8361 | |
| 8362 | // Remove private info if the caller doesn't have access |
| 8363 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8364 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8365 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8366 | // is available |
| 8367 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 8368 | if (card == null || card.getUiccProfile() == null) { |
| 8369 | // assume no access if the card or profile is unavailable |
| 8370 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8371 | continue; |
| 8372 | } |
| 8373 | UiccProfile profile = card.getUiccProfile(); |
| 8374 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8375 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8376 | filteredInfos.add(cardInfo); |
| 8377 | } else { |
| 8378 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8379 | } |
| 8380 | } |
| 8381 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8382 | } finally { |
| 8383 | Binder.restoreCallingIdentity(identity); |
| 8384 | } |
| 8385 | } |
| 8386 | |
| 8387 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8388 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8389 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8390 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8391 | final long identity = Binder.clearCallingIdentity(); |
| 8392 | try { |
| 8393 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8394 | if (slots == null) { |
| 8395 | Rlog.i(LOG_TAG, "slots is null."); |
| 8396 | return null; |
| 8397 | } |
| 8398 | |
| 8399 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8400 | for (int i = 0; i < slots.length; i++) { |
| 8401 | UiccSlot slot = slots[i]; |
| 8402 | if (slot == null) { |
| 8403 | continue; |
| 8404 | } |
| 8405 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8406 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8407 | UiccCard card = slot.getUiccCard(); |
| 8408 | if (card != null) { |
| 8409 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8410 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8411 | cardId = slot.getEid(); |
| 8412 | if (TextUtils.isEmpty(cardId)) { |
| 8413 | cardId = slot.getIccId(); |
| 8414 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8415 | } |
| 8416 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8417 | if (cardId != null) { |
| 8418 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8419 | // if cardId is an EID, it's all digits so this is fine |
| 8420 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8421 | } |
| 8422 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8423 | int cardState = 0; |
| 8424 | switch (slot.getCardState()) { |
| 8425 | case CARDSTATE_ABSENT: |
| 8426 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8427 | break; |
| 8428 | case CARDSTATE_PRESENT: |
| 8429 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8430 | break; |
| 8431 | case CARDSTATE_ERROR: |
| 8432 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8433 | break; |
| 8434 | case CARDSTATE_RESTRICTED: |
| 8435 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8436 | break; |
| 8437 | default: |
| 8438 | break; |
| 8439 | |
| 8440 | } |
| 8441 | |
| 8442 | infos[i] = new UiccSlotInfo( |
| 8443 | slot.isActive(), |
| 8444 | slot.isEuicc(), |
| 8445 | cardId, |
| 8446 | cardState, |
| 8447 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8448 | slot.isExtendedApduSupported(), |
| 8449 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8450 | } |
| 8451 | return infos; |
| 8452 | } finally { |
| 8453 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8454 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8455 | } |
| 8456 | |
| 8457 | @Override |
| 8458 | public boolean switchSlots(int[] physicalSlots) { |
| 8459 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8460 | |
| 8461 | final long identity = Binder.clearCallingIdentity(); |
| 8462 | try { |
| 8463 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8464 | } finally { |
| 8465 | Binder.restoreCallingIdentity(identity); |
| 8466 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8467 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8468 | |
| 8469 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8470 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8471 | final long identity = Binder.clearCallingIdentity(); |
| 8472 | try { |
| 8473 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8474 | } finally { |
| 8475 | Binder.restoreCallingIdentity(identity); |
| 8476 | } |
| 8477 | } |
| 8478 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8479 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8480 | * A test API to reload the UICC profile. |
| 8481 | * |
| 8482 | * <p>Requires that the calling app has permission |
| 8483 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8484 | * @hide |
| 8485 | */ |
| 8486 | @Override |
| 8487 | public void refreshUiccProfile(int subId) { |
| 8488 | enforceModifyPermission(); |
| 8489 | |
| 8490 | final long identity = Binder.clearCallingIdentity(); |
| 8491 | try { |
| 8492 | Phone phone = getPhone(subId); |
| 8493 | if (phone == null) { |
| 8494 | return; |
| 8495 | } |
| 8496 | UiccCard uiccCard = phone.getUiccCard(); |
| 8497 | if (uiccCard == null) { |
| 8498 | return; |
| 8499 | } |
| 8500 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8501 | if (uiccProfile == null) { |
| 8502 | return; |
| 8503 | } |
| 8504 | uiccProfile.refresh(); |
| 8505 | } finally { |
| 8506 | Binder.restoreCallingIdentity(identity); |
| 8507 | } |
| 8508 | } |
| 8509 | |
| 8510 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8511 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8512 | */ |
| 8513 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8514 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8515 | } |
| 8516 | |
| 8517 | /** |
| 8518 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8519 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8520 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8521 | */ |
| 8522 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8523 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8524 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8525 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8526 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8527 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8528 | return isDataRoamingEnabled; |
| 8529 | } |
| 8530 | |
| 8531 | /** |
| 8532 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8533 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8534 | */ |
| 8535 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8536 | List<Integer> list = TelephonyProperties.default_network(); |
| 8537 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8538 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8539 | return list.get(phoneId); |
| 8540 | } |
| 8541 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8542 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8543 | |
| 8544 | @Override |
| 8545 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8546 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8547 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8548 | |
| 8549 | final long identity = Binder.clearCallingIdentity(); |
| 8550 | try { |
| 8551 | final Phone phone = getPhone(subId); |
| 8552 | if (phone == null) { |
| 8553 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8554 | return; |
| 8555 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8556 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8557 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8558 | if (carrierPrivilegeRules == null) { |
| 8559 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8560 | } else { |
| 8561 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8562 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8563 | } finally { |
| 8564 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8565 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8566 | } |
| 8567 | |
| 8568 | @Override |
| 8569 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8570 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8571 | |
| 8572 | final long identity = Binder.clearCallingIdentity(); |
| 8573 | try { |
| 8574 | final Phone phone = getPhone(subId); |
| 8575 | if (phone == null) { |
| 8576 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8577 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8578 | } |
| 8579 | return phone.getCarrierIdListVersion(); |
| 8580 | } finally { |
| 8581 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8582 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8583 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8584 | |
| 8585 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8586 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8587 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8588 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8589 | mApp, subId, callingPackage, callingFeatureId, |
| 8590 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8591 | return -1; |
| 8592 | } |
| 8593 | |
| 8594 | final long identity = Binder.clearCallingIdentity(); |
| 8595 | try { |
| 8596 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8597 | } finally { |
| 8598 | Binder.restoreCallingIdentity(identity); |
| 8599 | } |
| 8600 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8601 | |
| 8602 | @Override |
| 8603 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8604 | TelephonyPermissions |
| 8605 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8606 | mApp, subId, "getCdmaRoamingMode"); |
| 8607 | |
| 8608 | final long identity = Binder.clearCallingIdentity(); |
| 8609 | try { |
| 8610 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8611 | } finally { |
| 8612 | Binder.restoreCallingIdentity(identity); |
| 8613 | } |
| 8614 | } |
| 8615 | |
| 8616 | @Override |
| 8617 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8618 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8619 | mApp, subId, "setCdmaRoamingMode"); |
| 8620 | |
| 8621 | final long identity = Binder.clearCallingIdentity(); |
| 8622 | try { |
| 8623 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8624 | } finally { |
| 8625 | Binder.restoreCallingIdentity(identity); |
| 8626 | } |
| 8627 | } |
| 8628 | |
| 8629 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8630 | public int getCdmaSubscriptionMode(int subId) { |
| 8631 | TelephonyPermissions |
| 8632 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8633 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8634 | |
| 8635 | final long identity = Binder.clearCallingIdentity(); |
| 8636 | try { |
| 8637 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8638 | } finally { |
| 8639 | Binder.restoreCallingIdentity(identity); |
| 8640 | } |
| 8641 | } |
| 8642 | |
| 8643 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8644 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8645 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8646 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8647 | |
| 8648 | final long identity = Binder.clearCallingIdentity(); |
| 8649 | try { |
| 8650 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8651 | } finally { |
| 8652 | Binder.restoreCallingIdentity(identity); |
| 8653 | } |
| 8654 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8655 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8656 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8657 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8658 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8659 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8660 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8661 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8662 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8663 | } |
| 8664 | final long identity = Binder.clearCallingIdentity(); |
| 8665 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8666 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8667 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8668 | if (phone.getEmergencyNumberTracker() != null |
| 8669 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8670 | emergencyNumberListInternal.put( |
| 8671 | phone.getSubId(), |
| 8672 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8673 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8674 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8675 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8676 | } finally { |
| 8677 | Binder.restoreCallingIdentity(identity); |
| 8678 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8679 | } |
| 8680 | |
| 8681 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8682 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8683 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8684 | if (!exactMatch) { |
| 8685 | TelephonyPermissions |
| 8686 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8687 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8688 | } |
| 8689 | final long identity = Binder.clearCallingIdentity(); |
| 8690 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8691 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8692 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8693 | && phone.getEmergencyNumberTracker() |
| 8694 | .isEmergencyNumber(number, exactMatch)) { |
| 8695 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8696 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8697 | } |
| 8698 | return false; |
| 8699 | } finally { |
| 8700 | Binder.restoreCallingIdentity(identity); |
| 8701 | } |
| 8702 | } |
| 8703 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8704 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame^] | 8705 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 8706 | */ |
| 8707 | @Override |
| 8708 | public void startEmergencyCallbackMode() { |
| 8709 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8710 | "startEmergencyCallbackMode"); |
| 8711 | enforceModifyPermission(); |
| 8712 | final long identity = Binder.clearCallingIdentity(); |
| 8713 | try { |
| 8714 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8715 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 8716 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 8717 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 8718 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 8719 | gsmCdmaPhone.obtainMessage( |
| 8720 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 8721 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 8722 | } |
| 8723 | } |
| 8724 | } finally { |
| 8725 | Binder.restoreCallingIdentity(identity); |
| 8726 | } |
| 8727 | } |
| 8728 | |
| 8729 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8730 | * Update emergency number list for test mode. |
| 8731 | */ |
| 8732 | @Override |
| 8733 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8734 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8735 | "updateEmergencyNumberListTestMode"); |
| 8736 | |
| 8737 | final long identity = Binder.clearCallingIdentity(); |
| 8738 | try { |
| 8739 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8740 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8741 | if (tracker != null) { |
| 8742 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8743 | } |
| 8744 | } |
| 8745 | } finally { |
| 8746 | Binder.restoreCallingIdentity(identity); |
| 8747 | } |
| 8748 | } |
| 8749 | |
| 8750 | /** |
| 8751 | * Get the full emergency number list for test mode. |
| 8752 | */ |
| 8753 | @Override |
| 8754 | public List<String> getEmergencyNumberListTestMode() { |
| 8755 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8756 | "getEmergencyNumberListTestMode"); |
| 8757 | |
| 8758 | final long identity = Binder.clearCallingIdentity(); |
| 8759 | try { |
| 8760 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8761 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8762 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8763 | if (tracker != null) { |
| 8764 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8765 | emergencyNumbers.add(num.getNumber()); |
| 8766 | } |
| 8767 | } |
| 8768 | } |
| 8769 | return new ArrayList<>(emergencyNumbers); |
| 8770 | } finally { |
| 8771 | Binder.restoreCallingIdentity(identity); |
| 8772 | } |
| 8773 | } |
| 8774 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8775 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8776 | public int getEmergencyNumberDbVersion(int subId) { |
| 8777 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8778 | |
| 8779 | final long identity = Binder.clearCallingIdentity(); |
| 8780 | try { |
| 8781 | final Phone phone = getPhone(subId); |
| 8782 | if (phone == null) { |
| 8783 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8784 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8785 | } |
| 8786 | return phone.getEmergencyNumberDbVersion(); |
| 8787 | } finally { |
| 8788 | Binder.restoreCallingIdentity(identity); |
| 8789 | } |
| 8790 | } |
| 8791 | |
| 8792 | @Override |
| 8793 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8794 | enforceModifyPermission(); |
| 8795 | |
| 8796 | final long identity = Binder.clearCallingIdentity(); |
| 8797 | try { |
| 8798 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8799 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8800 | if (tracker != null) { |
| 8801 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8802 | } |
| 8803 | } |
| 8804 | } finally { |
| 8805 | Binder.restoreCallingIdentity(identity); |
| 8806 | } |
| 8807 | } |
| 8808 | |
| 8809 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8810 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8811 | enforceActiveEmergencySessionPermission(); |
| 8812 | |
| 8813 | final long identity = Binder.clearCallingIdentity(); |
| 8814 | try { |
| 8815 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8816 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8817 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8818 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8819 | } |
| 8820 | } |
| 8821 | } finally { |
| 8822 | Binder.restoreCallingIdentity(identity); |
| 8823 | } |
| 8824 | } |
| 8825 | |
| 8826 | @Override |
| 8827 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8828 | enforceActiveEmergencySessionPermission(); |
| 8829 | |
| 8830 | final long identity = Binder.clearCallingIdentity(); |
| 8831 | try { |
| 8832 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8833 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8834 | if (tracker != null) { |
| 8835 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8836 | } |
| 8837 | } |
| 8838 | } finally { |
| 8839 | Binder.restoreCallingIdentity(identity); |
| 8840 | } |
| 8841 | } |
| 8842 | |
| 8843 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8844 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8845 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8846 | Phone phone = getPhone(subId); |
| 8847 | if (phone == null) { |
| 8848 | return null; |
| 8849 | } |
| 8850 | final long identity = Binder.clearCallingIdentity(); |
| 8851 | try { |
| 8852 | UiccProfile profile = UiccController.getInstance() |
| 8853 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8854 | if (profile != null) { |
| 8855 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8856 | } |
| 8857 | } finally { |
| 8858 | Binder.restoreCallingIdentity(identity); |
| 8859 | } |
| 8860 | return null; |
| 8861 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8862 | |
| 8863 | /** |
| 8864 | * Enable or disable a modem stack. |
| 8865 | */ |
| 8866 | @Override |
| 8867 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8868 | enforceModifyPermission(); |
| 8869 | |
| 8870 | final long identity = Binder.clearCallingIdentity(); |
| 8871 | try { |
| 8872 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8873 | if (phone == null) { |
| 8874 | return false; |
| 8875 | } else { |
| 8876 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8877 | } |
| 8878 | } finally { |
| 8879 | Binder.restoreCallingIdentity(identity); |
| 8880 | } |
| 8881 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8882 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8883 | /** |
| 8884 | * Whether a modem stack is enabled or not. |
| 8885 | */ |
| 8886 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8887 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8888 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8889 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8890 | if (phone == null) return false; |
| 8891 | |
| 8892 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8893 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8894 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8895 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8896 | } |
| 8897 | |
| 8898 | final long identity = Binder.clearCallingIdentity(); |
| 8899 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8900 | try { |
| 8901 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8902 | } catch (NoSuchElementException ex) { |
| 8903 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8904 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8905 | } finally { |
| 8906 | Binder.restoreCallingIdentity(identity); |
| 8907 | } |
| 8908 | } |
| 8909 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8910 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8911 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8912 | enforceModifyPermission(); |
| 8913 | |
| 8914 | final long identity = Binder.clearCallingIdentity(); |
| 8915 | try { |
| 8916 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8917 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8918 | .commit(); |
| 8919 | } finally { |
| 8920 | Binder.restoreCallingIdentity(identity); |
| 8921 | } |
| 8922 | } |
| 8923 | |
| 8924 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8925 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8926 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8927 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8928 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8929 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8930 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8931 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8932 | |
| 8933 | final long identity = Binder.clearCallingIdentity(); |
| 8934 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8935 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8936 | } finally { |
| 8937 | Binder.restoreCallingIdentity(identity); |
| 8938 | } |
| 8939 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8940 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8941 | @TelephonyManager.IsMultiSimSupportedResult |
| 8942 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8943 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8944 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8945 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8946 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8947 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8948 | } |
| 8949 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8950 | // supported by the modem, indicate that it is restricted. |
| 8951 | PhoneCapability staticCapability = |
| 8952 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8953 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8954 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8955 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8956 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 8957 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8958 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8959 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8960 | } |
| 8961 | // Check if support of multiple SIMs is restricted by carrier |
| 8962 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8963 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8964 | } |
| 8965 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8966 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8967 | } |
| 8968 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8969 | /** |
| 8970 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8971 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8972 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8973 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8974 | * @param numOfSims number of active sims we want to switch to |
| 8975 | */ |
| 8976 | @Override |
| 8977 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8978 | if (numOfSims == 1) { |
| 8979 | enforceModifyPermission(); |
| 8980 | } else { |
| 8981 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8982 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8983 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8984 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8985 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8986 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8987 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8988 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8989 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8990 | return; |
| 8991 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8992 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8993 | } finally { |
| 8994 | Binder.restoreCallingIdentity(identity); |
| 8995 | } |
| 8996 | } |
| 8997 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8998 | @Override |
| 8999 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9000 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9001 | Phone phone = getPhone(subId); |
| 9002 | if (phone == null) { |
| 9003 | return false; |
| 9004 | } |
| 9005 | final long identity = Binder.clearCallingIdentity(); |
| 9006 | try { |
| 9007 | UiccCard uiccCard = phone.getUiccCard(); |
| 9008 | if (uiccCard == null) { |
| 9009 | return false; |
| 9010 | } |
| 9011 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 9012 | if (uiccProfile == null) { |
| 9013 | return false; |
| 9014 | } |
| 9015 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9016 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9017 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9018 | } |
| 9019 | return false; |
| 9020 | } finally { |
| 9021 | Binder.restoreCallingIdentity(identity); |
| 9022 | } |
| 9023 | } |
| 9024 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9025 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9026 | * Get whether making changes to modem configurations will trigger reboot. |
| 9027 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9028 | */ |
| 9029 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9030 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9031 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9032 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9033 | mApp, subId, callingPackage, callingFeatureId, |
| 9034 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9035 | return false; |
| 9036 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9037 | final long identity = Binder.clearCallingIdentity(); |
| 9038 | try { |
| 9039 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9040 | } finally { |
| 9041 | Binder.restoreCallingIdentity(identity); |
| 9042 | } |
| 9043 | } |
| 9044 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9045 | private void updateModemStateMetrics() { |
| 9046 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9047 | // TODO: check the state for each modem if the api is ready. |
| 9048 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9049 | } |
| 9050 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9051 | @Override |
| 9052 | public int[] getSlotsMapping() { |
| 9053 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 9054 | |
| 9055 | final long identity = Binder.clearCallingIdentity(); |
| 9056 | try { |
| 9057 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 9058 | // All logical slots should have a mapping to a physical slot. |
| 9059 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 9060 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 9061 | for (int i = 0; i < slotInfos.length; i++) { |
| 9062 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 9063 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 9064 | } |
| 9065 | } |
| 9066 | return logicalSlotsMapping; |
| 9067 | } finally { |
| 9068 | Binder.restoreCallingIdentity(identity); |
| 9069 | } |
| 9070 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9071 | |
| 9072 | /** |
| 9073 | * Get the IRadio HAL Version |
| 9074 | */ |
| 9075 | @Override |
| 9076 | public int getRadioHalVersion() { |
| 9077 | Phone phone = getDefaultPhone(); |
| 9078 | if (phone == null) return -1; |
| 9079 | HalVersion hv = phone.getHalVersion(); |
| 9080 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9081 | return hv.major * 100 + hv.minor; |
| 9082 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9083 | |
| 9084 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9085 | * Get the current calling package name. |
| 9086 | * @return the current calling package name |
| 9087 | */ |
| 9088 | @Override |
| 9089 | public String getCurrentPackageName() { |
| 9090 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9091 | } |
| 9092 | |
| 9093 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9094 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9095 | * corresponding network requests on a subId. |
| 9096 | * |
| 9097 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9098 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9099 | * 2) APN is un-metered for this subscription, or |
| 9100 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9101 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9102 | * |
| 9103 | * @return whether data is allowed for a apn type. |
| 9104 | * |
| 9105 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9106 | */ |
| 9107 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9108 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9109 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9110 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9111 | |
| 9112 | // Now that all security checks passes, perform the operation as ourselves. |
| 9113 | final long identity = Binder.clearCallingIdentity(); |
| 9114 | try { |
| 9115 | Phone phone = getPhone(subId); |
| 9116 | if (phone == null) return false; |
| 9117 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9118 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9119 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 9120 | } finally { |
| 9121 | Binder.restoreCallingIdentity(identity); |
| 9122 | } |
| 9123 | } |
| 9124 | |
| 9125 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9126 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9127 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9128 | |
| 9129 | // Now that all security checks passes, perform the operation as ourselves. |
| 9130 | final long identity = Binder.clearCallingIdentity(); |
| 9131 | try { |
| 9132 | Phone phone = getPhone(subId); |
| 9133 | if (phone == null) return true; // By default return true. |
| 9134 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9135 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9136 | } finally { |
| 9137 | Binder.restoreCallingIdentity(identity); |
| 9138 | } |
| 9139 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9140 | |
| 9141 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9142 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9143 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9144 | enforceModifyPermission(); |
| 9145 | long token = Binder.clearCallingIdentity(); |
| 9146 | try { |
| 9147 | Phone phone = getPhone(subscriptionId); |
| 9148 | if (phone == null) { |
| 9149 | try { |
| 9150 | if (resultCallback != null) { |
| 9151 | resultCallback.accept(false); |
| 9152 | } |
| 9153 | } catch (RemoteException e) { |
| 9154 | // ignore |
| 9155 | } |
| 9156 | return; |
| 9157 | } |
| 9158 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9159 | Pair.create(specifiers, (x) -> { |
| 9160 | try { |
| 9161 | if (resultCallback != null) { |
| 9162 | resultCallback.accept(x); |
| 9163 | } |
| 9164 | } catch (RemoteException e) { |
| 9165 | // ignore |
| 9166 | } |
| 9167 | }); |
| 9168 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9169 | } finally { |
| 9170 | Binder.restoreCallingIdentity(token); |
| 9171 | } |
| 9172 | } |
| 9173 | |
| 9174 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9175 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9176 | TelephonyPermissions |
| 9177 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 9178 | mApp, subId, "getSystemSelectionChannels"); |
| 9179 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9180 | final long identity = Binder.clearCallingIdentity(); |
| 9181 | try { |
| 9182 | List<RadioAccessSpecifier> specifiers = |
| 9183 | (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, |
| 9184 | null, subId, workSource); |
| 9185 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9186 | return specifiers; |
| 9187 | } finally { |
| 9188 | Binder.restoreCallingIdentity(identity); |
| 9189 | } |
| 9190 | } |
| 9191 | |
| 9192 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9193 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9194 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9195 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9196 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9197 | if (iccRecords == null) { |
| 9198 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9199 | return false; |
| 9200 | } |
| 9201 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9202 | } |
| 9203 | |
| 9204 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9205 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9206 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9207 | if (callingPackage == null) { |
| 9208 | callingPackage = getCurrentPackageName(); |
| 9209 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9210 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9211 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9212 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9213 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9214 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9215 | } |
| 9216 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9217 | Intent intent = new Intent(); |
| 9218 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9219 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9220 | // Bring up choose default SMS subscription dialog right now |
| 9221 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9222 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9223 | mApp.startActivity(intent); |
| 9224 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9225 | |
| 9226 | @Override |
| 9227 | public String getMmsUAProfUrl(int subId) { |
| 9228 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9229 | final long identity = Binder.clearCallingIdentity(); |
| 9230 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9231 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9232 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9233 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9234 | return carrierUAProfUrl; |
| 9235 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9236 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9237 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9238 | } finally { |
| 9239 | Binder.restoreCallingIdentity(identity); |
| 9240 | } |
| 9241 | } |
| 9242 | |
| 9243 | @Override |
| 9244 | public String getMmsUserAgent(int subId) { |
| 9245 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9246 | final long identity = Binder.clearCallingIdentity(); |
| 9247 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9248 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9249 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9250 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9251 | return carrierUserAgent; |
| 9252 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9253 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9254 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9255 | } finally { |
| 9256 | Binder.restoreCallingIdentity(identity); |
| 9257 | } |
| 9258 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9259 | |
| 9260 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9261 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9262 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9263 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9264 | final long identity = Binder.clearCallingIdentity(); |
| 9265 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9266 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9267 | if (phone == null) return false; |
| 9268 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9269 | switch (policy) { |
| 9270 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9271 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9272 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9273 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9274 | default: |
| 9275 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9276 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9277 | } finally { |
| 9278 | Binder.restoreCallingIdentity(identity); |
| 9279 | } |
| 9280 | } |
| 9281 | |
| 9282 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 9283 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9284 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9285 | enforceModifyPermission(); |
| 9286 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9287 | final long identity = Binder.clearCallingIdentity(); |
| 9288 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9289 | Phone phone = getPhone(subscriptionId); |
| 9290 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9291 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9292 | switch (policy) { |
| 9293 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9294 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9295 | break; |
| 9296 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9297 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9298 | break; |
| 9299 | default: |
| 9300 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9301 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9302 | } finally { |
| 9303 | Binder.restoreCallingIdentity(identity); |
| 9304 | } |
| 9305 | } |
| 9306 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9307 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9308 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9309 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9310 | * otherwise. |
| 9311 | */ |
| 9312 | @Override |
| 9313 | public void setCepEnabled(boolean isCepEnabled) { |
| 9314 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9315 | |
| 9316 | final long identity = Binder.clearCallingIdentity(); |
| 9317 | try { |
| 9318 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9319 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9320 | Phone defaultPhone = phone.getImsPhone(); |
| 9321 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9322 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9323 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9324 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9325 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9326 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9327 | + imsPhone.getMsisdn()); |
| 9328 | } |
| 9329 | } |
| 9330 | } finally { |
| 9331 | Binder.restoreCallingIdentity(identity); |
| 9332 | } |
| 9333 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9334 | |
| 9335 | /** |
| 9336 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9337 | * |
| 9338 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9339 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9340 | * before being read. |
| 9341 | */ |
| 9342 | @Override |
| 9343 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9344 | isCompressed) { |
| 9345 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9346 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9347 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9348 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9349 | } |
| 9350 | if (!isImsAvailableOnDevice()) { |
| 9351 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9352 | "IMS not available on device."); |
| 9353 | } |
| 9354 | |
| 9355 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9356 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9357 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9358 | } finally { |
| 9359 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9360 | } |
| 9361 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9362 | |
| 9363 | @Override |
| 9364 | public boolean isIccLockEnabled(int subId) { |
| 9365 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9366 | |
| 9367 | // Now that all security checks passes, perform the operation as ourselves. |
| 9368 | final long identity = Binder.clearCallingIdentity(); |
| 9369 | try { |
| 9370 | Phone phone = getPhone(subId); |
| 9371 | if (phone != null && phone.getIccCard() != null) { |
| 9372 | return phone.getIccCard().getIccLockEnabled(); |
| 9373 | } else { |
| 9374 | return false; |
| 9375 | } |
| 9376 | } finally { |
| 9377 | Binder.restoreCallingIdentity(identity); |
| 9378 | } |
| 9379 | } |
| 9380 | |
| 9381 | /** |
| 9382 | * Set the ICC pin lock enabled or disabled. |
| 9383 | * |
| 9384 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9385 | * three cases: |
| 9386 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9387 | * successfully. |
| 9388 | * - Positive number and zero for remaining password attempts. |
| 9389 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9390 | * |
| 9391 | */ |
| 9392 | @Override |
| 9393 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9394 | enforceModifyPermission(); |
| 9395 | |
| 9396 | Phone phone = getPhone(subId); |
| 9397 | if (phone == null) { |
| 9398 | return 0; |
| 9399 | } |
| 9400 | // Now that all security checks passes, perform the operation as ourselves. |
| 9401 | final long identity = Binder.clearCallingIdentity(); |
| 9402 | try { |
| 9403 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9404 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9405 | return attemptsRemaining; |
| 9406 | |
| 9407 | } catch (Exception e) { |
| 9408 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9409 | } finally { |
| 9410 | Binder.restoreCallingIdentity(identity); |
| 9411 | } |
| 9412 | return 0; |
| 9413 | } |
| 9414 | |
| 9415 | /** |
| 9416 | * Change the ICC password used in ICC pin lock. |
| 9417 | * |
| 9418 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9419 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9420 | * - Positive number and zero for remaining password attempts. |
| 9421 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9422 | * |
| 9423 | */ |
| 9424 | @Override |
| 9425 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9426 | enforceModifyPermission(); |
| 9427 | |
| 9428 | Phone phone = getPhone(subId); |
| 9429 | if (phone == null) { |
| 9430 | return 0; |
| 9431 | } |
| 9432 | // Now that all security checks passes, perform the operation as ourselves. |
| 9433 | final long identity = Binder.clearCallingIdentity(); |
| 9434 | try { |
| 9435 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9436 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9437 | return attemptsRemaining; |
| 9438 | |
| 9439 | } catch (Exception e) { |
| 9440 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9441 | } finally { |
| 9442 | Binder.restoreCallingIdentity(identity); |
| 9443 | } |
| 9444 | return 0; |
| 9445 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9446 | |
| 9447 | /** |
| 9448 | * Request for receiving user activity notification |
| 9449 | */ |
| 9450 | @Override |
| 9451 | public void requestUserActivityNotification() { |
| 9452 | if (!mNotifyUserActivity.get() |
| 9453 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9454 | mNotifyUserActivity.set(true); |
| 9455 | } |
| 9456 | } |
| 9457 | |
| 9458 | /** |
| 9459 | * Called when userActivity is signalled in the power manager. |
| 9460 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9461 | */ |
| 9462 | @Override |
| 9463 | public void userActivity() { |
| 9464 | // *************************************** |
| 9465 | // * Inherited from PhoneWindowManager * |
| 9466 | // *************************************** |
| 9467 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9468 | // WITH ITS LOCKS HELD. |
| 9469 | // |
| 9470 | // This code must be VERY careful about the locks |
| 9471 | // it acquires. |
| 9472 | // In fact, the current code acquires way too many, |
| 9473 | // and probably has lurking deadlocks. |
| 9474 | |
| 9475 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9476 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9477 | } |
| 9478 | |
| 9479 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9480 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9481 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9482 | } |
| 9483 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9484 | |
| 9485 | @Override |
| 9486 | public boolean canConnectTo5GInDsdsMode() { |
| 9487 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9488 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9489 | |
| 9490 | @Override |
| 9491 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9492 | String callingFeatureId) { |
| 9493 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9494 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9495 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9496 | } |
| 9497 | |
| 9498 | Phone phone = getPhone(subId); |
| 9499 | if (phone == null) { |
| 9500 | throw new RuntimeException("phone is not available"); |
| 9501 | } |
| 9502 | // Now that all security checks passes, perform the operation as ourselves. |
| 9503 | final long identity = Binder.clearCallingIdentity(); |
| 9504 | try { |
| 9505 | return phone.getEquivalentHomePlmns(); |
| 9506 | } finally { |
| 9507 | Binder.restoreCallingIdentity(identity); |
| 9508 | } |
| 9509 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9510 | |
| 9511 | @Override |
| 9512 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 9513 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 9514 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9515 | mPhoneConfigurationManager.getRadioInterfaceCapabilities(); |
| 9516 | if (radioInterfaceCapabilities == null) { |
| 9517 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9518 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 9519 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9520 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9521 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9522 | @Override |
| 9523 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 9524 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9525 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 9526 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9527 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 9528 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9529 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9530 | if (DBG) { |
| 9531 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 9532 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 9533 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 9534 | } |
| 9535 | |
| 9536 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 9537 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 9538 | || appType > TelephonyManager.APPTYPE_ISIM |
| 9539 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 9540 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 9541 | if (callback != null) { |
| 9542 | try { |
| 9543 | callback.onAuthenticationFailure( |
| 9544 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 9545 | } catch (RemoteException exception) { |
| 9546 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 9547 | } |
| 9548 | return; |
| 9549 | } |
| 9550 | } |
| 9551 | |
| 9552 | final long token = Binder.clearCallingIdentity(); |
| 9553 | try { |
| 9554 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 9555 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 9556 | forceBootStrapping, callback)); |
| 9557 | } finally { |
| 9558 | Binder.restoreCallingIdentity(token); |
| 9559 | } |
| 9560 | } |
| 9561 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9562 | /** |
| 9563 | * Attempts to set the radio power state for thermal reason. This does not guarantee that the |
| 9564 | * requested radio power state will actually be set. See {@link |
| 9565 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9566 | * |
| 9567 | * @param subId the subscription ID of the phone requesting to set the radio power state. |
| 9568 | * @param enable {@code true} if trying to turn radio on. |
| 9569 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9570 | * false}. |
| 9571 | */ |
| 9572 | private boolean setRadioPowerForThermal(int subId, boolean enable) { |
| 9573 | Phone phone = getPhone(subId); |
| 9574 | if (phone != null) { |
| 9575 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 9576 | return true; |
| 9577 | } |
| 9578 | return false; |
| 9579 | } |
| 9580 | |
| 9581 | private int handleDataThrottlingRequest(int subId, |
| 9582 | DataThrottlingRequest dataThrottlingRequest) { |
| 9583 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 9584 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9585 | if (!setRadioPowerForThermal(subId, true)) { |
| 9586 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9587 | } |
| 9588 | |
| 9589 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 9590 | |
| 9591 | int thermalMitigationResult = |
| 9592 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
| 9593 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 9594 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 9595 | } |
| 9596 | return thermalMitigationResult; |
| 9597 | } |
| 9598 | |
| 9599 | /** |
| 9600 | * Thermal mitigation request to control functionalities at modem. |
| 9601 | * |
| 9602 | * @param subId the id of the subscription. |
| 9603 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
| 9604 | * |
| 9605 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 9606 | */ |
| 9607 | @Override |
| 9608 | @ThermalMitigationResult |
| 9609 | public int sendThermalMitigationRequest( |
| 9610 | int subId, |
| 9611 | ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException { |
| 9612 | enforceModifyPermission(); |
| 9613 | |
| 9614 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9615 | final long identity = Binder.clearCallingIdentity(); |
| 9616 | |
| 9617 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 9618 | try { |
| 9619 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 9620 | switch (thermalMitigationAction) { |
| 9621 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 9622 | thermalMitigationResult = |
| 9623 | handleDataThrottlingRequest(subId, |
| 9624 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 9625 | break; |
| 9626 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 9627 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9628 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 9629 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 9630 | } |
| 9631 | |
| 9632 | // Ensure that radio is on. If not able to power on due to phone being |
| 9633 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9634 | if (!setRadioPowerForThermal(subId, true)) { |
| 9635 | thermalMitigationResult = |
| 9636 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9637 | break; |
| 9638 | } |
| 9639 | |
| 9640 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 9641 | false); |
| 9642 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9643 | break; |
| 9644 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 9645 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9646 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 9647 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 9648 | } |
| 9649 | |
| 9650 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 9651 | if (registry != null) { |
| 9652 | TelephonyConnectionService service = |
| 9653 | registry.getTelephonyConnectionService(); |
| 9654 | Phone phone = getPhone(subId); |
| 9655 | if (phone == null) { |
| 9656 | thermalMitigationResult = |
| 9657 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9658 | break; |
| 9659 | } |
| 9660 | |
| 9661 | if (PhoneConstantConversions.convertCallState(phone.getState()) |
| 9662 | != TelephonyManager.CALL_STATE_IDLE |
| 9663 | || phone.isInEmergencySmsMode() || phone.isInEcm() |
| 9664 | || (service != null && service.isEmergencyCallPending())) { |
| 9665 | String errorMessage = "Phone state is not valid. call state = " |
| 9666 | + PhoneConstantConversions.convertCallState(phone.getState()) |
| 9667 | + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode() |
| 9668 | + " isInEmergencyCallbackMode = " + phone.isInEcm(); |
| 9669 | errorMessage += service == null |
| 9670 | ? " TelephonyConnectionService is null" |
| 9671 | : " isEmergencyCallPending = " |
| 9672 | + service.isEmergencyCallPending(); |
| 9673 | Log.e(LOG_TAG, errorMessage); |
| 9674 | thermalMitigationResult = |
| 9675 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 9676 | break; |
| 9677 | } |
| 9678 | } else { |
| 9679 | thermalMitigationResult = |
| 9680 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9681 | break; |
| 9682 | } |
| 9683 | |
| 9684 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 9685 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9686 | if (!setRadioPowerForThermal(subId, false)) { |
| 9687 | thermalMitigationResult = |
| 9688 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9689 | break; |
| 9690 | } |
| 9691 | thermalMitigationResult = |
| 9692 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9693 | break; |
| 9694 | default: |
| 9695 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 9696 | + "not exist. Requested action: " + thermalMitigationAction); |
| 9697 | } |
| 9698 | } catch (IllegalArgumentException e) { |
| 9699 | throw e; |
| 9700 | } catch (Exception e) { |
| 9701 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 9702 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 9703 | } finally { |
| 9704 | Binder.restoreCallingIdentity(identity); |
| 9705 | } |
| 9706 | |
| 9707 | if (DBG) { |
| 9708 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 9709 | + thermalMitigationResult); |
| 9710 | } |
| 9711 | |
| 9712 | return thermalMitigationResult; |
| 9713 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9714 | |
| 9715 | /** |
| 9716 | * Set the GbaService Package Name that Telephony will bind to. |
| 9717 | * |
| 9718 | * @param subId The sim that the GbaService is associated with. |
| 9719 | * @param packageName The name of the package to be replaced with. |
| 9720 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9721 | */ |
| 9722 | @Override |
| 9723 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 9724 | enforceModifyPermission(); |
| 9725 | |
| 9726 | final long identity = Binder.clearCallingIdentity(); |
| 9727 | try { |
| 9728 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 9729 | } finally { |
| 9730 | Binder.restoreCallingIdentity(identity); |
| 9731 | } |
| 9732 | } |
| 9733 | |
| 9734 | /** |
| 9735 | * Return the package name of the currently bound GbaService. |
| 9736 | * |
| 9737 | * @param subId The sim that the GbaService is associated with. |
| 9738 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 9739 | */ |
| 9740 | @Override |
| 9741 | public String getBoundGbaService(int subId) { |
| 9742 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 9743 | |
| 9744 | final long identity = Binder.clearCallingIdentity(); |
| 9745 | try { |
| 9746 | return getGbaManager(subId).getServicePackage(); |
| 9747 | } finally { |
| 9748 | Binder.restoreCallingIdentity(identity); |
| 9749 | } |
| 9750 | } |
| 9751 | |
| 9752 | /** |
| 9753 | * Set the release time for telephony to unbind GbaService. |
| 9754 | * |
| 9755 | * @param subId The sim that the GbaService is associated with. |
| 9756 | * @param interval The release time to unbind GbaService by millisecond. |
| 9757 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9758 | */ |
| 9759 | @Override |
| 9760 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 9761 | enforceModifyPermission(); |
| 9762 | |
| 9763 | final long identity = Binder.clearCallingIdentity(); |
| 9764 | try { |
| 9765 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 9766 | } finally { |
| 9767 | Binder.restoreCallingIdentity(identity); |
| 9768 | } |
| 9769 | } |
| 9770 | |
| 9771 | /** |
| 9772 | * Return the release time for telephony to unbind GbaService. |
| 9773 | * |
| 9774 | * @param subId The sim that the GbaService is associated with. |
| 9775 | * @return The release time to unbind GbaService by millisecond. |
| 9776 | */ |
| 9777 | @Override |
| 9778 | public int getGbaReleaseTime(int subId) { |
| 9779 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 9780 | |
| 9781 | final long identity = Binder.clearCallingIdentity(); |
| 9782 | try { |
| 9783 | return getGbaManager(subId).getReleaseTime(); |
| 9784 | } finally { |
| 9785 | Binder.restoreCallingIdentity(identity); |
| 9786 | } |
| 9787 | } |
| 9788 | |
| 9789 | private GbaManager getGbaManager(int subId) { |
| 9790 | GbaManager instance = GbaManager.getInstance(subId); |
| 9791 | if (instance == null) { |
| 9792 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 9793 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 9794 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 9795 | } |
| 9796 | return instance; |
| 9797 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9798 | |
| 9799 | /** |
| 9800 | * indicate whether the device and the carrier can support |
| 9801 | * RCS VoLTE single registration. |
| 9802 | */ |
| 9803 | @Override |
| 9804 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9805 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9806 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 9807 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9808 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9809 | |
| 9810 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9811 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9812 | } |
| 9813 | |
| 9814 | final long identity = Binder.clearCallingIdentity(); |
| 9815 | try { |
| 9816 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 9817 | if (rpm != null) { |
| 9818 | return rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 9819 | } |
| 9820 | return false; |
| 9821 | } finally { |
| 9822 | Binder.restoreCallingIdentity(identity); |
| 9823 | } |
| 9824 | } |
| 9825 | |
| 9826 | /** |
| 9827 | * Register RCS provisioning callback. |
| 9828 | */ |
| 9829 | @Override |
| 9830 | public void registerRcsProvisioningChangedCallback(int subId, |
| 9831 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9832 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9833 | Binder.getCallingUid(), "registerRcsProvisioningChangedCallback", |
| 9834 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9835 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9836 | |
| 9837 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9838 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9839 | } |
| 9840 | if (!isImsAvailableOnDevice()) { |
| 9841 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9842 | "IMS not available on device."); |
| 9843 | } |
| 9844 | |
| 9845 | final long identity = Binder.clearCallingIdentity(); |
| 9846 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9847 | if (!RcsProvisioningMonitor.getInstance() |
| 9848 | .registerRcsProvisioningChangedCallback(subId, callback)) { |
| 9849 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9850 | "Service not available for the subscription."); |
| 9851 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9852 | } finally { |
| 9853 | Binder.restoreCallingIdentity(identity); |
| 9854 | } |
| 9855 | } |
| 9856 | |
| 9857 | /** |
| 9858 | * Unregister RCS provisioning callback. |
| 9859 | */ |
| 9860 | @Override |
| 9861 | public void unregisterRcsProvisioningChangedCallback(int subId, |
| 9862 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9863 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9864 | Binder.getCallingUid(), "unregisterRcsProvisioningChangedCallback", |
| 9865 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9866 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9867 | |
| 9868 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9869 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9870 | } |
| 9871 | if (!isImsAvailableOnDevice()) { |
| 9872 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9873 | "IMS not available on device."); |
| 9874 | } |
| 9875 | |
| 9876 | final long identity = Binder.clearCallingIdentity(); |
| 9877 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9878 | RcsProvisioningMonitor.getInstance() |
| 9879 | .unregisterRcsProvisioningChangedCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9880 | } finally { |
| 9881 | Binder.restoreCallingIdentity(identity); |
| 9882 | } |
| 9883 | } |
| 9884 | |
| 9885 | /** |
| 9886 | * trigger RCS reconfiguration. |
| 9887 | */ |
| 9888 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9889 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 9890 | "triggerRcsReconfiguration", |
| 9891 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9892 | |
| 9893 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9894 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9895 | } |
| 9896 | if (!isImsAvailableOnDevice()) { |
| 9897 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9898 | "IMS not available on device."); |
| 9899 | } |
| 9900 | |
| 9901 | final long identity = Binder.clearCallingIdentity(); |
| 9902 | try { |
| 9903 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 9904 | } finally { |
| 9905 | Binder.restoreCallingIdentity(identity); |
| 9906 | } |
| 9907 | } |
| 9908 | |
| 9909 | /** |
| 9910 | * Provide the client configuration parameters of the RCS application. |
| 9911 | */ |
| 9912 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9913 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 9914 | "setRcsClientConfiguration", |
| 9915 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9916 | |
| 9917 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9918 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9919 | } |
| 9920 | if (!isImsAvailableOnDevice()) { |
| 9921 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9922 | "IMS not available on device."); |
| 9923 | } |
| 9924 | |
| 9925 | final long identity = Binder.clearCallingIdentity(); |
| 9926 | |
| 9927 | try { |
| 9928 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 9929 | if (configBinder == null) { |
| 9930 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
| 9931 | } else { |
| 9932 | configBinder.setRcsClientConfiguration(rcc); |
| 9933 | } |
| 9934 | } catch (RemoteException e) { |
| 9935 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
| 9936 | } finally { |
| 9937 | Binder.restoreCallingIdentity(identity); |
| 9938 | } |
| 9939 | } |
| 9940 | |
| 9941 | /** |
| 9942 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 9943 | */ |
| 9944 | @Override |
| 9945 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 9946 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9947 | "setDeviceSingleRegistrationEnabledOverride"); |
| 9948 | enforceModifyPermission(); |
| 9949 | |
| 9950 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9951 | : Boolean.parseBoolean(enabledStr); |
| 9952 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 9953 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9954 | } |
| 9955 | |
| 9956 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 9957 | * Sends a device to device communication message. Only usable via shell. |
| 9958 | * @param message message to send. |
| 9959 | * @param value message value. |
| 9960 | */ |
| 9961 | @Override |
| 9962 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 9963 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 9964 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 9965 | enforceModifyPermission(); |
| 9966 | |
| 9967 | final long identity = Binder.clearCallingIdentity(); |
| 9968 | try { |
| 9969 | TelephonyConnectionService service = |
| 9970 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 9971 | if (service == null) { |
| 9972 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 9973 | return; |
| 9974 | } |
| 9975 | service.sendTestDeviceToDeviceMessage(message, value); |
| 9976 | } finally { |
| 9977 | Binder.restoreCallingIdentity(identity); |
| 9978 | } |
| 9979 | } |
| 9980 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 9981 | /** |
| 9982 | * Sets the specified device to device transport active. |
| 9983 | * @param transport The transport to set active. |
| 9984 | */ |
| 9985 | @Override |
| 9986 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 9987 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9988 | "setActiveDeviceToDeviceTransport"); |
| 9989 | enforceModifyPermission(); |
| 9990 | |
| 9991 | final long identity = Binder.clearCallingIdentity(); |
| 9992 | try { |
| 9993 | TelephonyConnectionService service = |
| 9994 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 9995 | if (service == null) { |
| 9996 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 9997 | return; |
| 9998 | } |
| 9999 | service.setActiveDeviceToDeviceTransport(transport); |
| 10000 | } finally { |
| 10001 | Binder.restoreCallingIdentity(identity); |
| 10002 | } |
| 10003 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10004 | |
| 10005 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10006 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10007 | */ |
| 10008 | @Override |
| 10009 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10010 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10011 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10012 | } |
| 10013 | |
| 10014 | /** |
| 10015 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10016 | */ |
| 10017 | @Override |
| 10018 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10019 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10020 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10021 | enforceModifyPermission(); |
| 10022 | |
| 10023 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10024 | : Boolean.parseBoolean(enabledStr); |
| 10025 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10026 | subId, enabled); |
| 10027 | } |
| 10028 | |
| 10029 | /** |
| 10030 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10031 | */ |
| 10032 | @Override |
| 10033 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10034 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 10035 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 10036 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10037 | |
| 10038 | /** |
| 10039 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 10040 | * their mobile plan. |
| 10041 | */ |
| 10042 | @Override |
| 10043 | public String getMobileProvisioningUrl() { |
| 10044 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 10045 | final long identity = Binder.clearCallingIdentity(); |
| 10046 | try { |
| 10047 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 10048 | } finally { |
| 10049 | Binder.restoreCallingIdentity(identity); |
| 10050 | } |
| 10051 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10052 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10053 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 10054 | * Get the EAB contact from the EAB database. |
| 10055 | */ |
| 10056 | @Override |
| 10057 | public String getContactFromEab(String contact) { |
| 10058 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 10059 | enforceModifyPermission(); |
| 10060 | final long identity = Binder.clearCallingIdentity(); |
| 10061 | try { |
| 10062 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 10063 | } finally { |
| 10064 | Binder.restoreCallingIdentity(identity); |
| 10065 | } |
| 10066 | } |
| 10067 | |
| 10068 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10069 | * Remove the EAB contacts from the EAB database. |
| 10070 | */ |
| 10071 | @Override |
| 10072 | public int removeContactFromEab(int subId, String contacts) { |
| 10073 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 10074 | enforceModifyPermission(); |
| 10075 | final long identity = Binder.clearCallingIdentity(); |
| 10076 | try { |
| 10077 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 10078 | } finally { |
| 10079 | Binder.restoreCallingIdentity(identity); |
| 10080 | } |
| 10081 | } |
| 10082 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10083 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10084 | public boolean getDeviceUceEnabled() { |
| 10085 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 10086 | final long identity = Binder.clearCallingIdentity(); |
| 10087 | try { |
| 10088 | return mApp.getDeviceUceEnabled(); |
| 10089 | } finally { |
| 10090 | Binder.restoreCallingIdentity(identity); |
| 10091 | } |
| 10092 | } |
| 10093 | |
| 10094 | @Override |
| 10095 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 10096 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 10097 | final long identity = Binder.clearCallingIdentity(); |
| 10098 | try { |
| 10099 | mApp.setDeviceUceEnabled(isEnabled); |
| 10100 | } finally { |
| 10101 | Binder.restoreCallingIdentity(identity); |
| 10102 | } |
| 10103 | } |
| 10104 | |
| 10105 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10106 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10107 | String callingPackage) { |
| 10108 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10109 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 10110 | |
| 10111 | final int callingUid = Binder.getCallingUid(); |
| 10112 | // Verify that tha callingPackage belongs to the calling UID |
| 10113 | mApp.getSystemService(AppOpsManager.class) |
| 10114 | .checkPackage(callingUid, callingPackage); |
| 10115 | |
| 10116 | validateSignalStrengthUpdateRequest(request, callingUid); |
| 10117 | |
| 10118 | final long identity = Binder.clearCallingIdentity(); |
| 10119 | try { |
| 10120 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10121 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10122 | |
| 10123 | if (result instanceof IllegalStateException) { |
| 10124 | throw (IllegalStateException) result; |
| 10125 | } |
| 10126 | } finally { |
| 10127 | Binder.restoreCallingIdentity(identity); |
| 10128 | } |
| 10129 | } |
| 10130 | |
| 10131 | @Override |
| 10132 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10133 | String callingPackage) { |
| 10134 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10135 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 10136 | |
| 10137 | final int callingUid = Binder.getCallingUid(); |
| 10138 | // Verify that tha callingPackage belongs to the calling UID |
| 10139 | mApp.getSystemService(AppOpsManager.class) |
| 10140 | .checkPackage(callingUid, callingPackage); |
| 10141 | |
| 10142 | final long identity = Binder.clearCallingIdentity(); |
| 10143 | try { |
| 10144 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10145 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10146 | |
| 10147 | if (result instanceof IllegalStateException) { |
| 10148 | throw (IllegalStateException) result; |
| 10149 | } |
| 10150 | } finally { |
| 10151 | Binder.restoreCallingIdentity(identity); |
| 10152 | } |
| 10153 | } |
| 10154 | |
| 10155 | private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request, |
| 10156 | int callingUid) { |
| 10157 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 10158 | // phone/system process do not have further restriction on request |
| 10159 | return; |
| 10160 | } |
| 10161 | |
| 10162 | // Applications has restrictions on how to use the request: |
| 10163 | // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle |
| 10164 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
| 10165 | // This is not system caller which has been checked above |
| 10166 | throw new IllegalArgumentException( |
| 10167 | "Only system can set isSystemThresholdReportingRequestedWhileIdle"); |
| 10168 | } |
| 10169 | |
| 10170 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 10171 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 10172 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 10173 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 10174 | || info.isEnabled()) { |
| 10175 | throw new IllegalArgumentException( |
| 10176 | "Only system can set hide fields in SignalThresholdInfo"); |
| 10177 | } |
| 10178 | |
| 10179 | // Thresholds length for each RAN need in range. This has been validated in |
| 10180 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 10181 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 10182 | final int[] thresholds = info.getThresholds(); |
| 10183 | Objects.requireNonNull(thresholds); |
| 10184 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 10185 | || thresholds.length |
| 10186 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 10187 | throw new IllegalArgumentException( |
| 10188 | "thresholds length is out of range: " + thresholds.length); |
| 10189 | } |
| 10190 | } |
| 10191 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10192 | |
| 10193 | /** |
| 10194 | * Gets the current phone capability. |
| 10195 | * |
| 10196 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 10197 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 10198 | * It's used to evaluate possible phone config change, for example from single |
| 10199 | * SIM device to multi-SIM device. |
| 10200 | */ |
| 10201 | @Override |
| 10202 | public PhoneCapability getPhoneCapability() { |
| 10203 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 10204 | final long identity = Binder.clearCallingIdentity(); |
| 10205 | try { |
| 10206 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 10207 | } finally { |
| 10208 | Binder.restoreCallingIdentity(identity); |
| 10209 | } |
| 10210 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 10211 | |
| 10212 | /** |
| 10213 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 10214 | * required to be done shortly after the API is invoked. |
| 10215 | */ |
| 10216 | @Override |
| 10217 | @TelephonyManager.PrepareUnattendedRebootResult |
| 10218 | public int prepareForUnattendedReboot() { |
| 10219 | enforceRebootPermission(); |
| 10220 | |
| 10221 | final long identity = Binder.clearCallingIdentity(); |
| 10222 | try { |
| 10223 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null); |
| 10224 | } finally { |
| 10225 | Binder.restoreCallingIdentity(identity); |
| 10226 | } |
| 10227 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 10228 | } |