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 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 22 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 23 | |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 24 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 25 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 26 | import android.annotation.Nullable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 27 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 28 | import android.app.PendingIntent; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 29 | import android.app.role.RoleManager; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 30 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 31 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 32 | import android.content.Context; |
| 33 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 34 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 35 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 36 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 37 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 38 | import android.net.Uri; |
| 39 | import android.os.AsyncResult; |
| 40 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 41 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.os.Bundle; |
| 43 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 44 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.os.Looper; |
| 46 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 47 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 48 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 49 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 50 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 51 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 52 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 53 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 54 | import android.os.ServiceSpecificException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 55 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 56 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 57 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 58 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 59 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 60 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 61 | import android.provider.Telephony; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 62 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 63 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 64 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 65 | import android.telecom.TelecomManager; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 66 | import android.telephony.Annotation.ApnType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 67 | import android.telephony.Annotation.ThermalMitigationResult; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 68 | import android.telephony.CallForwardingInfo; |
Sooraj Sasindran | 4deb887 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 69 | import android.telephony.CarrierBandwidth; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 70 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 71 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 72 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 73 | import android.telephony.CellIdentityCdma; |
| 74 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 75 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 76 | import android.telephony.CellInfoGsm; |
| 77 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 78 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 79 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 80 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 81 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 82 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 83 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 84 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 85 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 86 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 87 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 88 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 89 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 90 | import android.telephony.RadioAccessSpecifier; |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 91 | import android.telephony.RadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 92 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 93 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 94 | import android.telephony.SignalStrengthUpdateRequest; |
| 95 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 96 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 97 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 98 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 99 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 100 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 101 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 102 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 103 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 104 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 105 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 106 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 107 | import android.telephony.data.ApnSetting; |
| 108 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 109 | import android.telephony.gba.GbaAuthRequest; |
| 110 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 111 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 112 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 113 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 114 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 115 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 116 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 117 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 118 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 119 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 120 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 121 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 122 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 123 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 124 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 125 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 126 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 127 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 128 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 129 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 130 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 131 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 132 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 133 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 134 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 138 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 141 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.GbaManager; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 144 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 145 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 148 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 150 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 156 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.RIL; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 164 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 165 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 168 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 170 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 172 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 173 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 175 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 176 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 178 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 179 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 180 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 181 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 182 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 183 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 184 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 185 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 186 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 187 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame^] | 188 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 189 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 190 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 191 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 192 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 193 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 194 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 195 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 196 | import com.android.services.telephony.TelecomAccountRegistry; |
| 197 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 198 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 199 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 200 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 201 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 202 | import java.io.IOException; |
| 203 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 204 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 205 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 206 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 207 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 208 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 209 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 210 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 211 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 212 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 213 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 214 | import java.util.Set; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 215 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 216 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 217 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 218 | |
| 219 | /** |
| 220 | * Implementation of the ITelephony interface. |
| 221 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 222 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 223 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 224 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 225 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 226 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 227 | |
| 228 | // Message codes used with mMainThreadHandler |
| 229 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 230 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 231 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 232 | private static final int CMD_OPEN_CHANNEL = 9; |
| 233 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 234 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 235 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 236 | private static final int CMD_NV_READ_ITEM = 13; |
| 237 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 238 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 239 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 240 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 241 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 242 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 243 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 244 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 245 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 246 | private static final int CMD_SEND_ENVELOPE = 25; |
| 247 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 248 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 249 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 250 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 251 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 252 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 253 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 254 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 255 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 256 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 257 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 258 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 259 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 260 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 261 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 262 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 263 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 264 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 265 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 266 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 267 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 268 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 269 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 270 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 271 | private static final int CMD_SWITCH_SLOTS = 50; |
| 272 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 273 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 274 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 275 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 276 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 277 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 278 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 279 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 280 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 281 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 282 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 283 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 284 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 285 | private static final int CMD_MODEM_REBOOT = 64; |
| 286 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 287 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 288 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 289 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 290 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 291 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 292 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 293 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 294 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 295 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 296 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 297 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 298 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 299 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 300 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 301 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 302 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 303 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 304 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 305 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 306 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 307 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 308 | private static final int CMD_GET_CALL_WAITING = 87; |
| 309 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 310 | private static final int CMD_SET_CALL_WAITING = 89; |
| 311 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 312 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 313 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 314 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 315 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 316 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 317 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 318 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 319 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 320 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 321 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 322 | private static final int CMD_SET_SIM_POWER = 101; |
| 323 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 324 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 325 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 326 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 327 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 328 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 329 | private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 330 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 331 | // Parameters of select command. |
| 332 | private static final int SELECT_COMMAND = 0xA4; |
| 333 | private static final int SELECT_P1 = 0x04; |
| 334 | private static final int SELECT_P2 = 0; |
| 335 | private static final int SELECT_P3 = 0x10; |
| 336 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 337 | /** The singleton instance. */ |
| 338 | private static PhoneInterfaceManager sInstance; |
| 339 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 340 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 341 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 342 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 343 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 344 | private AppOpsManager mAppOps; |
| 345 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 346 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 347 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 348 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 349 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 350 | /** User Activity */ |
| 351 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 352 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 353 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 354 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 355 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 356 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 357 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 358 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 359 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 360 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 361 | // String to store multi SIM allowed |
| 362 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 363 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 364 | // The AID of ISD-R. |
| 365 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 366 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 367 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 368 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 369 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 370 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 371 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 372 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
| 373 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 374 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 375 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 376 | */ |
| 377 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 378 | "reset_network_erase_modem_config_enabled"; |
| 379 | |
| 380 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 381 | * A request object to use for transmitting data to an ICC. |
| 382 | */ |
| 383 | private static final class IccAPDUArgument { |
| 384 | public int channel, cla, command, p1, p2, p3; |
| 385 | public String data; |
| 386 | |
| 387 | public IccAPDUArgument(int channel, int cla, int command, |
| 388 | int p1, int p2, int p3, String data) { |
| 389 | this.channel = channel; |
| 390 | this.cla = cla; |
| 391 | this.command = command; |
| 392 | this.p1 = p1; |
| 393 | this.p2 = p2; |
| 394 | this.p3 = p3; |
| 395 | this.data = data; |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 400 | * A request object to use for transmitting data to an ICC. |
| 401 | */ |
| 402 | private static final class ManualNetworkSelectionArgument { |
| 403 | public OperatorInfo operatorInfo; |
| 404 | public boolean persistSelection; |
| 405 | |
| 406 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 407 | this.operatorInfo = operatorInfo; |
| 408 | this.persistSelection = persistSelection; |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 413 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 414 | * request after sending. The main thread will notify the request when it is complete. |
| 415 | */ |
| 416 | private static final class MainThreadRequest { |
| 417 | /** The argument to use for the request */ |
| 418 | public Object argument; |
| 419 | /** The result of the request that is run on the main thread */ |
| 420 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 421 | // The subscriber id that this request applies to. Defaults to |
| 422 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 423 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 424 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 425 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 426 | public Phone phone; |
| 427 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 428 | public WorkSource workSource; |
| 429 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 430 | public MainThreadRequest(Object argument) { |
| 431 | this.argument = argument; |
| 432 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 433 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 434 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 435 | this.argument = argument; |
| 436 | if (phone != null) { |
| 437 | this.phone = phone; |
| 438 | } |
| 439 | this.workSource = workSource; |
| 440 | } |
| 441 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 442 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 443 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 444 | if (subId != null) { |
| 445 | this.subId = subId; |
| 446 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 447 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 448 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 449 | } |
| 450 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 451 | private static final class IncomingThirdPartyCallArgs { |
| 452 | public final ComponentName component; |
| 453 | public final String callId; |
| 454 | public final String callerDisplayName; |
| 455 | |
| 456 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 457 | String callerDisplayName) { |
| 458 | this.component = component; |
| 459 | this.callId = callId; |
| 460 | this.callerDisplayName = callerDisplayName; |
| 461 | } |
| 462 | } |
| 463 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 464 | /** |
| 465 | * A handler that processes messages on the main thread in the phone process. Since many |
| 466 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 467 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 468 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 469 | * on, which will be notified when the operation completes and will contain the result of the |
| 470 | * request. |
| 471 | * |
| 472 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 473 | * note that request.result must be set to something non-null for the calling thread to |
| 474 | * unblock. |
| 475 | */ |
| 476 | private final class MainThreadHandler extends Handler { |
| 477 | @Override |
| 478 | public void handleMessage(Message msg) { |
| 479 | MainThreadRequest request; |
| 480 | Message onCompleted; |
| 481 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 482 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 483 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 484 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 485 | |
| 486 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 487 | case CMD_HANDLE_USSD_REQUEST: { |
| 488 | request = (MainThreadRequest) msg.obj; |
| 489 | final Phone phone = getPhoneFromRequest(request); |
| 490 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 491 | String ussdRequest = ussdObject.first; |
| 492 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 493 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 494 | if (!isUssdApiAllowed(request.subId)) { |
| 495 | // Carrier does not support use of this API, return failure. |
| 496 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 497 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 498 | Bundle returnData = new Bundle(); |
| 499 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 500 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
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 | request.result = true; |
| 503 | notifyRequester(request); |
| 504 | return; |
| 505 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 506 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 507 | try { |
| 508 | request.result = phone != null |
| 509 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 510 | } catch (CallStateException cse) { |
| 511 | request.result = false; |
| 512 | } |
| 513 | // Wake up the requesting thread |
| 514 | notifyRequester(request); |
| 515 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 516 | } |
| 517 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 518 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 519 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 520 | final Phone phone = getPhoneFromRequest(request); |
| 521 | request.result = phone != null ? |
| 522 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 523 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 524 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 525 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 526 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 527 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 528 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 529 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 530 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 531 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 532 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 533 | if (uiccCard == null) { |
| 534 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 535 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 536 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 537 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 538 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 539 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 540 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 541 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 542 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 543 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 544 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 545 | break; |
| 546 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 547 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 548 | ar = (AsyncResult) msg.obj; |
| 549 | request = (MainThreadRequest) ar.userObj; |
| 550 | if (ar.exception == null && ar.result != null) { |
| 551 | request.result = ar.result; |
| 552 | } else { |
| 553 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 554 | if (ar.result == null) { |
| 555 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 556 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 557 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 558 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 559 | } else { |
| 560 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 561 | } |
| 562 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 563 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 564 | break; |
| 565 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 566 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 567 | request = (MainThreadRequest) msg.obj; |
| 568 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 569 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 570 | if (uiccCard == null) { |
| 571 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 572 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 573 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 574 | } else { |
| 575 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 576 | request); |
| 577 | uiccCard.iccTransmitApduBasicChannel( |
| 578 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 579 | iccArgument.p3, iccArgument.data, onCompleted); |
| 580 | } |
| 581 | break; |
| 582 | |
| 583 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 584 | ar = (AsyncResult) msg.obj; |
| 585 | request = (MainThreadRequest) ar.userObj; |
| 586 | if (ar.exception == null && ar.result != null) { |
| 587 | request.result = ar.result; |
| 588 | } else { |
| 589 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 590 | if (ar.result == null) { |
| 591 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 592 | } else if (ar.exception instanceof CommandException) { |
| 593 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 594 | ar.exception); |
| 595 | } else { |
| 596 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 597 | } |
| 598 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 599 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 600 | break; |
| 601 | |
| 602 | case CMD_EXCHANGE_SIM_IO: |
| 603 | request = (MainThreadRequest) msg.obj; |
| 604 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 605 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 606 | if (uiccCard == null) { |
| 607 | loge("iccExchangeSimIO: No UICC"); |
| 608 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 609 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 610 | } else { |
| 611 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 612 | request); |
| 613 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 614 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 615 | iccArgument.data, onCompleted); |
| 616 | } |
| 617 | break; |
| 618 | |
| 619 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 620 | ar = (AsyncResult) msg.obj; |
| 621 | request = (MainThreadRequest) ar.userObj; |
| 622 | if (ar.exception == null && ar.result != null) { |
| 623 | request.result = ar.result; |
| 624 | } else { |
| 625 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 626 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 627 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 628 | break; |
| 629 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 630 | case CMD_SEND_ENVELOPE: |
| 631 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 632 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 633 | if (uiccCard == null) { |
| 634 | loge("sendEnvelopeWithStatus: No UICC"); |
| 635 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 636 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 637 | } else { |
| 638 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 639 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 640 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 641 | break; |
| 642 | |
| 643 | case EVENT_SEND_ENVELOPE_DONE: |
| 644 | ar = (AsyncResult) msg.obj; |
| 645 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 646 | if (ar.exception == null && ar.result != null) { |
| 647 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 648 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 649 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 650 | if (ar.result == null) { |
| 651 | loge("sendEnvelopeWithStatus: Empty response"); |
| 652 | } else if (ar.exception instanceof CommandException) { |
| 653 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 654 | ar.exception); |
| 655 | } else { |
| 656 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 657 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 658 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 659 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 660 | break; |
| 661 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 662 | case CMD_OPEN_CHANNEL: |
| 663 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 664 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 665 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 666 | if (uiccCard == null) { |
| 667 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 668 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 669 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 670 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 671 | } else { |
| 672 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 673 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 674 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 675 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 676 | break; |
| 677 | |
| 678 | case EVENT_OPEN_CHANNEL_DONE: |
| 679 | ar = (AsyncResult) msg.obj; |
| 680 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 681 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 682 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 683 | int[] result = (int[]) ar.result; |
| 684 | int channelId = result[0]; |
| 685 | byte[] selectResponse = null; |
| 686 | if (result.length > 1) { |
| 687 | selectResponse = new byte[result.length - 1]; |
| 688 | for (int i = 1; i < result.length; ++i) { |
| 689 | selectResponse[i - 1] = (byte) result[i]; |
| 690 | } |
| 691 | } |
| 692 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 693 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 694 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 695 | if (ar.result == null) { |
| 696 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 697 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 698 | if (ar.exception != null) { |
| 699 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 700 | } |
| 701 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 702 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 703 | if (ar.exception instanceof CommandException) { |
| 704 | CommandException.Error error = |
| 705 | ((CommandException) (ar.exception)).getCommandError(); |
| 706 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 707 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 708 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 709 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 710 | } |
| 711 | } |
| 712 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 713 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 714 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 715 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 716 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 717 | break; |
| 718 | |
| 719 | case CMD_CLOSE_CHANNEL: |
| 720 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 721 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 722 | if (uiccCard == null) { |
| 723 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 724 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 725 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 726 | } else { |
| 727 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 728 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 729 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 730 | break; |
| 731 | |
| 732 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 733 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 734 | break; |
| 735 | |
| 736 | case CMD_NV_READ_ITEM: |
| 737 | request = (MainThreadRequest) msg.obj; |
| 738 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 739 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 740 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 741 | break; |
| 742 | |
| 743 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 744 | ar = (AsyncResult) msg.obj; |
| 745 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 746 | if (ar.exception == null && ar.result != null) { |
| 747 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 748 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 749 | request.result = ""; |
| 750 | if (ar.result == null) { |
| 751 | loge("nvReadItem: Empty response"); |
| 752 | } else if (ar.exception instanceof CommandException) { |
| 753 | loge("nvReadItem: CommandException: " + |
| 754 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 755 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 756 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 757 | } |
| 758 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 759 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 760 | break; |
| 761 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 762 | case CMD_NV_WRITE_ITEM: |
| 763 | request = (MainThreadRequest) msg.obj; |
| 764 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 765 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 766 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 767 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 768 | break; |
| 769 | |
| 770 | case EVENT_NV_WRITE_ITEM_DONE: |
| 771 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 772 | break; |
| 773 | |
| 774 | case CMD_NV_WRITE_CDMA_PRL: |
| 775 | request = (MainThreadRequest) msg.obj; |
| 776 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 777 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 778 | break; |
| 779 | |
| 780 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 781 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 782 | break; |
| 783 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 784 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 785 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 786 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 787 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 788 | break; |
| 789 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 790 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 791 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 792 | break; |
| 793 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 794 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 795 | request = (MainThreadRequest) msg.obj; |
| 796 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 797 | request); |
| 798 | Phone phone = getPhoneFromRequest(request); |
| 799 | if (phone != null) { |
| 800 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 801 | } else { |
| 802 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 803 | request.result = false; |
| 804 | notifyRequester(request); |
| 805 | } |
| 806 | break; |
| 807 | } |
| 808 | |
| 809 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 810 | ar = (AsyncResult) msg.obj; |
| 811 | request = (MainThreadRequest) ar.userObj; |
| 812 | if (ar.exception == null && ar.result != null) { |
| 813 | request.result = ar.result; |
| 814 | } else { |
| 815 | // request.result must be set to something non-null |
| 816 | // for the calling thread to unblock |
| 817 | if (request.result != null) { |
| 818 | request.result = ar.result; |
| 819 | } else { |
| 820 | request.result = false; |
| 821 | } |
| 822 | if (ar.result == null) { |
| 823 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 824 | } else if (ar.exception instanceof CommandException) { |
| 825 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 826 | + ar.exception); |
| 827 | } else { |
| 828 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 829 | } |
| 830 | } |
| 831 | notifyRequester(request); |
| 832 | break; |
| 833 | |
| 834 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 835 | request = (MainThreadRequest) msg.obj; |
| 836 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 837 | Phone phone = getPhoneFromRequest(request); |
| 838 | if (phone != null) { |
| 839 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 840 | request.workSource); |
| 841 | } else { |
| 842 | loge("enableNrDualConnectivity: No phone object"); |
| 843 | request.result = |
| 844 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 845 | notifyRequester(request); |
| 846 | } |
| 847 | break; |
| 848 | } |
| 849 | |
| 850 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 851 | ar = (AsyncResult) msg.obj; |
| 852 | request = (MainThreadRequest) ar.userObj; |
| 853 | if (ar.exception == null) { |
| 854 | request.result = |
| 855 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 856 | } else { |
| 857 | request.result = |
| 858 | TelephonyManager |
| 859 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 860 | if (ar.exception instanceof CommandException) { |
| 861 | CommandException.Error error = |
| 862 | ((CommandException) (ar.exception)).getCommandError(); |
| 863 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 864 | request.result = |
| 865 | TelephonyManager |
| 866 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 867 | } |
| 868 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 869 | + ar.exception); |
| 870 | } else { |
| 871 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 872 | } |
| 873 | } |
| 874 | notifyRequester(request); |
| 875 | break; |
| 876 | } |
| 877 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 878 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 879 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 880 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 881 | request); |
| 882 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 883 | break; |
| 884 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 885 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 886 | ar = (AsyncResult) msg.obj; |
| 887 | request = (MainThreadRequest) ar.userObj; |
| 888 | if (ar.exception == null && ar.result != null) { |
| 889 | request.result = ar.result; // Integer |
| 890 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 891 | // request.result must be set to something non-null |
| 892 | // for the calling thread to unblock |
| 893 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 894 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 895 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 896 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 897 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 898 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 899 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 900 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 901 | } |
| 902 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 903 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 904 | break; |
| 905 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 906 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 907 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 908 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 909 | request); |
| 910 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 911 | (Pair<Integer, Long>) request.argument; |
| 912 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 913 | reasonWithNetworkTypes.first, |
| 914 | reasonWithNetworkTypes.second, |
| 915 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 916 | break; |
| 917 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 918 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 919 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 920 | break; |
| 921 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 922 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 923 | request = (MainThreadRequest)msg.obj; |
| 924 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 925 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 926 | break; |
| 927 | |
| 928 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 929 | ar = (AsyncResult)msg.obj; |
| 930 | request = (MainThreadRequest)ar.userObj; |
| 931 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 932 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 933 | break; |
| 934 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 935 | case CMD_SET_VOICEMAIL_NUMBER: |
| 936 | request = (MainThreadRequest) msg.obj; |
| 937 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 938 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 939 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 940 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 941 | break; |
| 942 | |
| 943 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 944 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 945 | break; |
| 946 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 947 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 948 | request = (MainThreadRequest) msg.obj; |
| 949 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 950 | request); |
| 951 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 952 | break; |
| 953 | |
| 954 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 955 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 956 | break; |
| 957 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 958 | case CMD_PERFORM_NETWORK_SCAN: |
| 959 | request = (MainThreadRequest) msg.obj; |
| 960 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 961 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 962 | break; |
| 963 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 964 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 965 | request = (MainThreadRequest) msg.obj; |
| 966 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 967 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 968 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 969 | request.argument; |
| 970 | int callForwardingReason = args.first; |
| 971 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 972 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 973 | } |
| 974 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 975 | ar = (AsyncResult) msg.obj; |
| 976 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 977 | TelephonyManager.CallForwardingInfoCallback callback = |
| 978 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 979 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 980 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 981 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 982 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 983 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 984 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 985 | // any service for voice call. |
| 986 | if ((callForwardInfo.serviceClass |
| 987 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 988 | callForwardingInfo = new CallForwardingInfo(true, |
| 989 | callForwardInfo.reason, |
| 990 | callForwardInfo.number, |
| 991 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 992 | break; |
| 993 | } |
| 994 | } |
| 995 | // Didn't find a call forward info for voice call. |
| 996 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 997 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 998 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 999 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1000 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1001 | } else { |
| 1002 | if (ar.result == null) { |
| 1003 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1004 | } |
| 1005 | if (ar.exception != null) { |
| 1006 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1007 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1008 | int errorCode = TelephonyManager |
| 1009 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1010 | if (ar.exception instanceof CommandException) { |
| 1011 | CommandException.Error error = |
| 1012 | ((CommandException) (ar.exception)).getCommandError(); |
| 1013 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1014 | errorCode = TelephonyManager |
| 1015 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1016 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1017 | errorCode = TelephonyManager |
| 1018 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1019 | } |
| 1020 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1021 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1022 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1023 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1024 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1025 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1026 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1027 | request = (MainThreadRequest) msg.obj; |
| 1028 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1029 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1030 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1031 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1032 | request.argument).first; |
| 1033 | request.phone.setCallForwardingOption( |
| 1034 | callForwardingInfoToSet.isEnabled() |
| 1035 | ? CommandsInterface.CF_ACTION_ENABLE |
| 1036 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1037 | callForwardingInfoToSet.getReason(), |
| 1038 | callForwardingInfoToSet.getNumber(), |
| 1039 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1040 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1041 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1042 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1043 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1044 | ar = (AsyncResult) msg.obj; |
| 1045 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1046 | Consumer<Integer> callback = |
| 1047 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1048 | request.argument).second; |
| 1049 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1050 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1051 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1052 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1053 | if (ar.exception instanceof CommandException) { |
| 1054 | CommandException.Error error = |
| 1055 | ((CommandException) (ar.exception)).getCommandError(); |
| 1056 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1057 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1058 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1059 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1060 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1061 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1062 | } |
| 1063 | } |
| 1064 | callback.accept(errorCode); |
| 1065 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1066 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1067 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1068 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1069 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1070 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1071 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1072 | request = (MainThreadRequest) msg.obj; |
| 1073 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1074 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1075 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1076 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1077 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1078 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1079 | ar = (AsyncResult) msg.obj; |
| 1080 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1081 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1082 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1083 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1084 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1085 | // Service Class is a bit mask per 3gpp 27.007. |
| 1086 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1087 | if (callForwardResults.length > 1 |
| 1088 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1089 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1090 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1091 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1092 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1093 | } else { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1094 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1095 | } |
| 1096 | } else { |
| 1097 | if (ar.result == null) { |
| 1098 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1099 | } |
| 1100 | if (ar.exception != null) { |
| 1101 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1102 | } |
| 1103 | if (ar.exception instanceof CommandException) { |
| 1104 | CommandException.Error error = |
| 1105 | ((CommandException) (ar.exception)).getCommandError(); |
| 1106 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1107 | callForwardingStatus = |
| 1108 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1109 | } |
| 1110 | } |
| 1111 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1112 | callback.accept(callForwardingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1113 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1114 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1115 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1116 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1117 | request = (MainThreadRequest) msg.obj; |
| 1118 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1119 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1120 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
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 EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1125 | ar = (AsyncResult) msg.obj; |
| 1126 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1127 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1128 | Consumer<Integer> callback = |
| 1129 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1130 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1131 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1132 | if (ar.exception instanceof CommandException) { |
| 1133 | CommandException.Error error = |
| 1134 | ((CommandException) (ar.exception)).getCommandError(); |
| 1135 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1136 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1137 | } else { |
| 1138 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1139 | } |
| 1140 | } else { |
| 1141 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1142 | } |
| 1143 | } else { |
| 1144 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1145 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1146 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1147 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1148 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1149 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1150 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1151 | ar = (AsyncResult) msg.obj; |
| 1152 | request = (MainThreadRequest) ar.userObj; |
| 1153 | CellNetworkScanResult cellScanResult; |
| 1154 | if (ar.exception == null && ar.result != null) { |
| 1155 | cellScanResult = new CellNetworkScanResult( |
| 1156 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1157 | (List<OperatorInfo>) ar.result); |
| 1158 | } else { |
| 1159 | if (ar.result == null) { |
| 1160 | loge("getCellNetworkScanResults: Empty response"); |
| 1161 | } |
| 1162 | if (ar.exception != null) { |
| 1163 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1164 | } |
| 1165 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1166 | if (ar.exception instanceof CommandException) { |
| 1167 | CommandException.Error error = |
| 1168 | ((CommandException) (ar.exception)).getCommandError(); |
| 1169 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1170 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1171 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1172 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1173 | } |
| 1174 | } |
| 1175 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1176 | } |
| 1177 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1178 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1179 | break; |
| 1180 | |
| 1181 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1182 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1183 | ManualNetworkSelectionArgument selArg = |
| 1184 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1185 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1186 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1187 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1188 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1189 | break; |
| 1190 | |
| 1191 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1192 | ar = (AsyncResult) msg.obj; |
| 1193 | request = (MainThreadRequest) ar.userObj; |
| 1194 | if (ar.exception == null) { |
| 1195 | request.result = true; |
| 1196 | } else { |
| 1197 | request.result = false; |
| 1198 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1199 | } |
| 1200 | notifyRequester(request); |
| 1201 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1202 | break; |
| 1203 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1204 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1205 | request = (MainThreadRequest) msg.obj; |
| 1206 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1207 | if (defaultPhone != null) { |
| 1208 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1209 | } else { |
| 1210 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1211 | Bundle bundle = new Bundle(); |
| 1212 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1213 | new ModemActivityInfo(0, 0, 0, |
| 1214 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1215 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1216 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1217 | break; |
| 1218 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1219 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1220 | ar = (AsyncResult) msg.obj; |
| 1221 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1222 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1223 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1224 | ModemActivityInfo ret = null; |
| 1225 | int error = 0; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1226 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1227 | // Update the last modem activity info and the result of the request. |
| 1228 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1229 | if (isModemActivityInfoValid(info)) { |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1230 | int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()]; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1231 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1232 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1233 | .getTransmitTimeMillis(); |
| 1234 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1235 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1236 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1237 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1238 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1239 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1240 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1241 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1242 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1243 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1244 | info.getReceiveTimeMillis() |
| 1245 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1246 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1247 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(), |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1248 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1249 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1250 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1251 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1252 | } else { |
| 1253 | if (ar.result == null) { |
| 1254 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1255 | error = TelephonyManager.ModemActivityInfoException |
| 1256 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1257 | } else if (ar.exception instanceof CommandException) { |
| 1258 | loge("queryModemActivityInfo: CommandException: " + |
| 1259 | ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1260 | error = TelephonyManager.ModemActivityInfoException |
| 1261 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1262 | } else { |
| 1263 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1264 | error = TelephonyManager.ModemActivityInfoException |
| 1265 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1266 | } |
| 1267 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1268 | Bundle bundle = new Bundle(); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1269 | if (ret != null) { |
| 1270 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1271 | } else { |
| 1272 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1273 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1274 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1275 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1276 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1277 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1278 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1279 | case CMD_SET_ALLOWED_CARRIERS: |
| 1280 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1281 | CarrierRestrictionRules argument = |
| 1282 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1283 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1284 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1285 | break; |
| 1286 | |
| 1287 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1288 | ar = (AsyncResult) msg.obj; |
| 1289 | request = (MainThreadRequest) ar.userObj; |
| 1290 | if (ar.exception == null && ar.result != null) { |
| 1291 | request.result = ar.result; |
| 1292 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1293 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1294 | if (ar.exception instanceof CommandException) { |
| 1295 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1296 | CommandException.Error error = |
| 1297 | ((CommandException) (ar.exception)).getCommandError(); |
| 1298 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1299 | request.result = |
| 1300 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1301 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1302 | } else { |
| 1303 | loge("setAllowedCarriers: Unknown exception"); |
| 1304 | } |
| 1305 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1306 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1307 | break; |
| 1308 | |
| 1309 | case CMD_GET_ALLOWED_CARRIERS: |
| 1310 | request = (MainThreadRequest) msg.obj; |
| 1311 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1312 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1313 | break; |
| 1314 | |
| 1315 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1316 | ar = (AsyncResult) msg.obj; |
| 1317 | request = (MainThreadRequest) ar.userObj; |
| 1318 | if (ar.exception == null && ar.result != null) { |
| 1319 | request.result = ar.result; |
| 1320 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1321 | request.result = new IllegalStateException( |
| 1322 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1323 | if (ar.result == null) { |
| 1324 | loge("getAllowedCarriers: Empty response"); |
| 1325 | } else if (ar.exception instanceof CommandException) { |
| 1326 | loge("getAllowedCarriers: CommandException: " + |
| 1327 | ar.exception); |
| 1328 | } else { |
| 1329 | loge("getAllowedCarriers: Unknown exception"); |
| 1330 | } |
| 1331 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1332 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1333 | break; |
| 1334 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1335 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1336 | ar = (AsyncResult) msg.obj; |
| 1337 | request = (MainThreadRequest) ar.userObj; |
| 1338 | if (ar.exception == null && ar.result != null) { |
| 1339 | request.result = ar.result; |
| 1340 | } else { |
| 1341 | request.result = new IllegalArgumentException( |
| 1342 | "Failed to retrieve Forbidden Plmns"); |
| 1343 | if (ar.result == null) { |
| 1344 | loge("getForbiddenPlmns: Empty response"); |
| 1345 | } else { |
| 1346 | loge("getForbiddenPlmns: Unknown exception"); |
| 1347 | } |
| 1348 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1349 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1350 | break; |
| 1351 | |
| 1352 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1353 | request = (MainThreadRequest) msg.obj; |
| 1354 | uiccCard = getUiccCardFromRequest(request); |
| 1355 | if (uiccCard == null) { |
| 1356 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1357 | request.result = new IllegalArgumentException( |
| 1358 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1359 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1360 | break; |
| 1361 | } |
| 1362 | Integer appType = (Integer) request.argument; |
| 1363 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1364 | if (uiccApp == null) { |
| 1365 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1366 | + appType); |
| 1367 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1368 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1369 | break; |
| 1370 | } else { |
| 1371 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1372 | + " specified type -- " + appType); |
| 1373 | } |
| 1374 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1375 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1376 | onCompleted); |
| 1377 | break; |
| 1378 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1379 | case CMD_SWITCH_SLOTS: |
| 1380 | request = (MainThreadRequest) msg.obj; |
| 1381 | int[] physicalSlots = (int[]) request.argument; |
| 1382 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1383 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1384 | break; |
| 1385 | |
| 1386 | case EVENT_SWITCH_SLOTS_DONE: |
| 1387 | ar = (AsyncResult) msg.obj; |
| 1388 | request = (MainThreadRequest) ar.userObj; |
| 1389 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1390 | notifyRequester(request); |
| 1391 | break; |
| 1392 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1393 | request = (MainThreadRequest) msg.obj; |
| 1394 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1395 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1396 | break; |
| 1397 | |
| 1398 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1399 | ar = (AsyncResult) msg.obj; |
| 1400 | request = (MainThreadRequest) ar.userObj; |
| 1401 | if (ar.exception != null) { |
| 1402 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1403 | } else { |
| 1404 | int mode = ((int[]) ar.result)[0]; |
| 1405 | if (mode == 0) { |
| 1406 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1407 | } else { |
| 1408 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1409 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1410 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1411 | notifyRequester(request); |
| 1412 | break; |
| 1413 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1414 | request = (MainThreadRequest) msg.obj; |
| 1415 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1416 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1417 | break; |
| 1418 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1419 | ar = (AsyncResult) msg.obj; |
| 1420 | request = (MainThreadRequest) ar.userObj; |
| 1421 | if (ar.exception != null) { |
| 1422 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1423 | } else { |
| 1424 | request.result = ((int[]) ar.result)[0]; |
| 1425 | } |
| 1426 | notifyRequester(request); |
| 1427 | break; |
| 1428 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1429 | request = (MainThreadRequest) msg.obj; |
| 1430 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1431 | int mode = (int) request.argument; |
| 1432 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1433 | break; |
| 1434 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1435 | ar = (AsyncResult) msg.obj; |
| 1436 | request = (MainThreadRequest) ar.userObj; |
| 1437 | request.result = ar.exception == null; |
| 1438 | notifyRequester(request); |
| 1439 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1440 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1441 | request = (MainThreadRequest) msg.obj; |
| 1442 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1443 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1444 | break; |
| 1445 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1446 | ar = (AsyncResult) msg.obj; |
| 1447 | request = (MainThreadRequest) ar.userObj; |
| 1448 | if (ar.exception != null) { |
| 1449 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1450 | } else { |
| 1451 | request.result = ((int[]) ar.result)[0]; |
| 1452 | } |
| 1453 | notifyRequester(request); |
| 1454 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1455 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1456 | request = (MainThreadRequest) msg.obj; |
| 1457 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1458 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1459 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1460 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1461 | break; |
| 1462 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1463 | ar = (AsyncResult) msg.obj; |
| 1464 | request = (MainThreadRequest) ar.userObj; |
| 1465 | request.result = ar.exception == null; |
| 1466 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1467 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1468 | case CMD_GET_ALL_CELL_INFO: |
| 1469 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1470 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1471 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1472 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1473 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1474 | ar = (AsyncResult) msg.obj; |
| 1475 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1476 | // If a timeout occurs, the response will be null |
| 1477 | request.result = (ar.exception == null && ar.result != null) |
| 1478 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1479 | synchronized (request) { |
| 1480 | request.notifyAll(); |
| 1481 | } |
| 1482 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1483 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1484 | request = (MainThreadRequest) msg.obj; |
| 1485 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1486 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1487 | break; |
| 1488 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1489 | ar = (AsyncResult) msg.obj; |
| 1490 | request = (MainThreadRequest) ar.userObj; |
| 1491 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1492 | try { |
| 1493 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1494 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1495 | cb.onError( |
| 1496 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1497 | ar.exception.getClass().getName(), |
| 1498 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1499 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1500 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1501 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1502 | } else { |
| 1503 | // use the result as returned |
| 1504 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1505 | } |
| 1506 | } catch (RemoteException re) { |
| 1507 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1508 | } |
| 1509 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1510 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1511 | request = (MainThreadRequest) msg.obj; |
| 1512 | WorkSource ws = (WorkSource) request.argument; |
| 1513 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1514 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1515 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1516 | } |
| 1517 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1518 | ar = (AsyncResult) msg.obj; |
| 1519 | request = (MainThreadRequest) ar.userObj; |
| 1520 | if (ar.exception == null) { |
| 1521 | request.result = ar.result; |
| 1522 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1523 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1524 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1525 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1526 | } |
| 1527 | |
| 1528 | synchronized (request) { |
| 1529 | request.notifyAll(); |
| 1530 | } |
| 1531 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1532 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1533 | case CMD_MODEM_REBOOT: |
| 1534 | request = (MainThreadRequest) msg.obj; |
| 1535 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1536 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1537 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1538 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1539 | handleNullReturnEvent(msg, "rebootModem"); |
| 1540 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1541 | case CMD_REQUEST_ENABLE_MODEM: |
| 1542 | request = (MainThreadRequest) msg.obj; |
| 1543 | boolean enable = (boolean) request.argument; |
| 1544 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1545 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1546 | PhoneConfigurationManager.getInstance() |
| 1547 | .enablePhone(request.phone, enable, onCompleted); |
| 1548 | break; |
| 1549 | case EVENT_ENABLE_MODEM_DONE: |
| 1550 | ar = (AsyncResult) msg.obj; |
| 1551 | request = (MainThreadRequest) ar.userObj; |
| 1552 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1553 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1554 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1555 | if ((boolean) request.result) { |
| 1556 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1557 | updateModemStateMetrics(); |
| 1558 | } else { |
| 1559 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1560 | + ar.exception); |
| 1561 | } |
| 1562 | notifyRequester(request); |
| 1563 | break; |
| 1564 | case CMD_GET_MODEM_STATUS: |
| 1565 | request = (MainThreadRequest) msg.obj; |
| 1566 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1567 | PhoneConfigurationManager.getInstance() |
| 1568 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1569 | break; |
| 1570 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1571 | ar = (AsyncResult) msg.obj; |
| 1572 | request = (MainThreadRequest) ar.userObj; |
| 1573 | int id = request.phone.getPhoneId(); |
| 1574 | if (ar.exception == null && ar.result != null) { |
| 1575 | request.result = ar.result; |
| 1576 | //update the cache as modem status has changed |
| 1577 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1578 | (boolean) request.result); |
| 1579 | } else { |
| 1580 | // Return true if modem status cannot be retrieved. For most cases, |
| 1581 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1582 | // and disable modem are not supported. Modem is always on. |
| 1583 | // TODO: this should be fixed in R to support a third |
| 1584 | // status UNKNOWN b/131631629 |
| 1585 | request.result = true; |
| 1586 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1587 | + ar.exception); |
| 1588 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1589 | notifyRequester(request); |
| 1590 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1591 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1592 | request = (MainThreadRequest) msg.obj; |
| 1593 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1594 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1595 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1596 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1597 | break; |
| 1598 | } |
| 1599 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1600 | ar = (AsyncResult) msg.obj; |
| 1601 | request = (MainThreadRequest) ar.userObj; |
| 1602 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1603 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1604 | args.second.accept(ar.exception == null); |
| 1605 | notifyRequester(request); |
| 1606 | break; |
| 1607 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1608 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1609 | request = (MainThreadRequest) msg.obj; |
| 1610 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1611 | Phone phone = getPhoneFromRequest(request); |
| 1612 | if (phone != null) { |
| 1613 | phone.getSystemSelectionChannels(onCompleted); |
| 1614 | } else { |
| 1615 | loge("getSystemSelectionChannels: No phone object"); |
| 1616 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1617 | notifyRequester(request); |
| 1618 | } |
| 1619 | break; |
| 1620 | } |
| 1621 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1622 | ar = (AsyncResult) msg.obj; |
| 1623 | request = (MainThreadRequest) ar.userObj; |
| 1624 | if (ar.exception == null && ar.result != null) { |
| 1625 | request.result = ar.result; |
| 1626 | } else { |
| 1627 | request.result = new IllegalArgumentException( |
| 1628 | "Failed to retrieve system selection channels"); |
| 1629 | if (ar.result == null) { |
| 1630 | loge("getSystemSelectionChannels: Empty response"); |
| 1631 | } else { |
| 1632 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1633 | } |
| 1634 | } |
| 1635 | notifyRequester(request); |
| 1636 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1637 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1638 | ar = (AsyncResult) msg.obj; |
| 1639 | request = (MainThreadRequest) ar.userObj; |
| 1640 | if (ar.exception == null && ar.result != null) { |
| 1641 | request.result = ar.result; |
| 1642 | } else { |
| 1643 | request.result = -1; |
| 1644 | loge("Failed to set Forbidden Plmns"); |
| 1645 | if (ar.result == null) { |
| 1646 | loge("setForbidenPlmns: Empty response"); |
| 1647 | } else if (ar.exception != null) { |
| 1648 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1649 | request.result = -1; |
| 1650 | } else { |
| 1651 | loge("setForbiddenPlmns: Unknown exception"); |
| 1652 | } |
| 1653 | } |
| 1654 | notifyRequester(request); |
| 1655 | break; |
| 1656 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1657 | request = (MainThreadRequest) msg.obj; |
| 1658 | uiccCard = getUiccCardFromRequest(request); |
| 1659 | if (uiccCard == null) { |
| 1660 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1661 | request.result = -1; |
| 1662 | notifyRequester(request); |
| 1663 | break; |
| 1664 | } |
| 1665 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1666 | (Pair<Integer, List<String>>) request.argument; |
| 1667 | appType = setFplmnsArgs.first; |
| 1668 | List<String> fplmns = setFplmnsArgs.second; |
| 1669 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1670 | if (uiccApp == null) { |
| 1671 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1672 | request.result = -1; |
| 1673 | loge("Failed to get UICC App"); |
| 1674 | notifyRequester(request); |
| 1675 | } else { |
| 1676 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1677 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1678 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1679 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1680 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1681 | case CMD_ERASE_MODEM_CONFIG: |
| 1682 | request = (MainThreadRequest) msg.obj; |
| 1683 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1684 | defaultPhone.eraseModemConfig(onCompleted); |
| 1685 | break; |
| 1686 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1687 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1688 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1689 | |
| 1690 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1691 | request = (MainThreadRequest) msg.obj; |
| 1692 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1693 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1694 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1695 | changed.first, changed.second, onCompleted); |
| 1696 | break; |
| 1697 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1698 | ar = (AsyncResult) msg.obj; |
| 1699 | request = (MainThreadRequest) ar.userObj; |
| 1700 | if (ar.exception == null) { |
| 1701 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1702 | } else { |
| 1703 | request.result = msg.arg1; |
| 1704 | } |
| 1705 | notifyRequester(request); |
| 1706 | break; |
| 1707 | |
| 1708 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1709 | request = (MainThreadRequest) msg.obj; |
| 1710 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1711 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1712 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1713 | enabled.first, enabled.second, onCompleted); |
| 1714 | break; |
| 1715 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1716 | ar = (AsyncResult) msg.obj; |
| 1717 | request = (MainThreadRequest) ar.userObj; |
| 1718 | if (ar.exception == null) { |
| 1719 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1720 | } else { |
| 1721 | request.result = msg.arg1; |
| 1722 | } |
| 1723 | notifyRequester(request); |
| 1724 | break; |
| 1725 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1726 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1727 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1728 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1729 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1730 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1731 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1732 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1733 | |
| 1734 | case CMD_SET_DATA_THROTTLING: { |
| 1735 | request = (MainThreadRequest) msg.obj; |
| 1736 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1737 | DataThrottlingRequest dataThrottlingRequest = |
| 1738 | (DataThrottlingRequest) request.argument; |
| 1739 | Phone phone = getPhoneFromRequest(request); |
| 1740 | if (phone != null) { |
| 1741 | phone.setDataThrottling(onCompleted, |
| 1742 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1743 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1744 | } else { |
| 1745 | loge("setDataThrottling: No phone object"); |
| 1746 | request.result = |
| 1747 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1748 | notifyRequester(request); |
| 1749 | } |
| 1750 | |
| 1751 | break; |
| 1752 | } |
| 1753 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1754 | ar = (AsyncResult) msg.obj; |
| 1755 | request = (MainThreadRequest) ar.userObj; |
| 1756 | |
| 1757 | if (ar.exception == null) { |
| 1758 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1759 | } else if (ar.exception instanceof CommandException) { |
| 1760 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1761 | CommandException.Error error = |
| 1762 | ((CommandException) (ar.exception)).getCommandError(); |
| 1763 | |
| 1764 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1765 | request.result = TelephonyManager |
| 1766 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1767 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1768 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
| 1769 | } else { |
| 1770 | request.result = |
| 1771 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1772 | } |
| 1773 | } else { |
| 1774 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1775 | } |
| 1776 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1777 | notifyRequester(request); |
| 1778 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1779 | |
| 1780 | case CMD_SET_SIM_POWER: { |
| 1781 | request = (MainThreadRequest) msg.obj; |
| 1782 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1783 | request = (MainThreadRequest) msg.obj; |
| 1784 | int stateToSet = |
| 1785 | ((Pair<Integer, IIntegerConsumer>) |
| 1786 | request.argument).first; |
| 1787 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1788 | break; |
| 1789 | } |
| 1790 | case EVENT_SET_SIM_POWER_DONE: { |
| 1791 | ar = (AsyncResult) msg.obj; |
| 1792 | request = (MainThreadRequest) ar.userObj; |
| 1793 | IIntegerConsumer callback = |
| 1794 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1795 | if (ar.exception != null) { |
| 1796 | loge("setSimPower exception: " + ar.exception); |
| 1797 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1798 | .RESULT_ERROR_UNKNOWN; |
| 1799 | if (ar.exception instanceof CommandException) { |
| 1800 | CommandException.Error error = |
| 1801 | ((CommandException) (ar.exception)).getCommandError(); |
| 1802 | if (error == CommandException.Error.SIM_ERR) { |
| 1803 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1804 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1805 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1806 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1807 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1808 | } else { |
| 1809 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1810 | } |
| 1811 | } |
| 1812 | try { |
| 1813 | callback.accept(errorCode); |
| 1814 | } catch (RemoteException e) { |
| 1815 | // Ignore if the remote process is no longer available to call back. |
| 1816 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1817 | } |
| 1818 | } else { |
| 1819 | try { |
| 1820 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1821 | } catch (RemoteException e) { |
| 1822 | // Ignore if the remote process is no longer available to call back. |
| 1823 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1824 | } |
| 1825 | } |
| 1826 | break; |
| 1827 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1828 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1829 | request = (MainThreadRequest) msg.obj; |
| 1830 | |
| 1831 | final Phone phone = getPhoneFromRequest(request); |
| 1832 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1833 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1834 | notifyRequester(request); |
| 1835 | break; |
| 1836 | } |
| 1837 | |
| 1838 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1839 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1840 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1841 | request); |
| 1842 | phone.getServiceStateTracker().setSignalStrengthUpdateRequest( |
| 1843 | request.subId, pair.first /*callingUid*/, |
| 1844 | pair.second /*request*/, onCompleted); |
| 1845 | break; |
| 1846 | } |
| 1847 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1848 | ar = (AsyncResult) msg.obj; |
| 1849 | request = (MainThreadRequest) ar.userObj; |
| 1850 | // request.result will be the exception of ar if present, true otherwise. |
| 1851 | // Be cautious not to leave result null which will wait() forever |
| 1852 | request.result = ar.exception != null ? ar.exception : true; |
| 1853 | notifyRequester(request); |
| 1854 | break; |
| 1855 | } |
| 1856 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1857 | request = (MainThreadRequest) msg.obj; |
| 1858 | |
| 1859 | Phone phone = getPhoneFromRequest(request); |
| 1860 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1861 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1862 | notifyRequester(request); |
| 1863 | break; |
| 1864 | } |
| 1865 | |
| 1866 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1867 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1868 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1869 | request); |
| 1870 | phone.getServiceStateTracker().clearSignalStrengthUpdateRequest( |
| 1871 | request.subId, pair.first /*callingUid*/, |
| 1872 | pair.second /*request*/, onCompleted); |
| 1873 | break; |
| 1874 | } |
| 1875 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1876 | ar = (AsyncResult) msg.obj; |
| 1877 | request = (MainThreadRequest) ar.userObj; |
| 1878 | request.result = ar.exception != null ? ar.exception : true; |
| 1879 | notifyRequester(request); |
| 1880 | break; |
| 1881 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1882 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1883 | default: |
| 1884 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1885 | break; |
| 1886 | } |
| 1887 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1888 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1889 | private void notifyRequester(MainThreadRequest request) { |
| 1890 | synchronized (request) { |
| 1891 | request.notifyAll(); |
| 1892 | } |
| 1893 | } |
| 1894 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1895 | private void handleNullReturnEvent(Message msg, String command) { |
| 1896 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1897 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1898 | if (ar.exception == null) { |
| 1899 | request.result = true; |
| 1900 | } else { |
| 1901 | request.result = false; |
| 1902 | if (ar.exception instanceof CommandException) { |
| 1903 | loge(command + ": CommandException: " + ar.exception); |
| 1904 | } else { |
| 1905 | loge(command + ": Unknown exception"); |
| 1906 | } |
| 1907 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1908 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1909 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1910 | } |
| 1911 | |
| 1912 | /** |
| 1913 | * Posts the specified command to be executed on the main thread, |
| 1914 | * waits for the request to complete, and returns the result. |
| 1915 | * @see #sendRequestAsync |
| 1916 | */ |
| 1917 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1918 | return sendRequest( |
| 1919 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1920 | } |
| 1921 | |
| 1922 | /** |
| 1923 | * Posts the specified command to be executed on the main thread, |
| 1924 | * waits for the request to complete, and returns the result. |
| 1925 | * @see #sendRequestAsync |
| 1926 | */ |
| 1927 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1928 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1929 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1930 | } |
| 1931 | |
| 1932 | /** |
| 1933 | * Posts the specified command to be executed on the main thread, |
| 1934 | * waits for the request to complete, and returns the result. |
| 1935 | * @see #sendRequestAsync |
| 1936 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1937 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1938 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | /** |
| 1942 | * Posts the specified command to be executed on the main thread, |
| 1943 | * waits for the request to complete, and returns the result. |
| 1944 | * @see #sendRequestAsync |
| 1945 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1946 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1947 | return sendRequest(command, argument, subId, null, workSource); |
| 1948 | } |
| 1949 | |
| 1950 | /** |
| 1951 | * Posts the specified command to be executed on the main thread, |
| 1952 | * waits for the request to complete, and returns the result. |
| 1953 | * @see #sendRequestAsync |
| 1954 | */ |
| 1955 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1956 | return sendRequest( |
| 1957 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1958 | } |
| 1959 | |
| 1960 | /** |
| 1961 | * Posts the specified command to be executed on the main thread, |
| 1962 | * waits for the request to complete, and returns the result. |
| 1963 | * @see #sendRequestAsync |
| 1964 | */ |
| 1965 | private Object sendRequest( |
| 1966 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1967 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1968 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1969 | } |
| 1970 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1971 | MainThreadRequest request = null; |
| 1972 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1973 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1974 | } else if (phone != null) { |
| 1975 | request = new MainThreadRequest(argument, phone, workSource); |
| 1976 | } else { |
| 1977 | request = new MainThreadRequest(argument, subId, workSource); |
| 1978 | } |
| 1979 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1980 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1981 | msg.sendToTarget(); |
| 1982 | |
| 1983 | // Wait for the request to complete |
| 1984 | synchronized (request) { |
| 1985 | while (request.result == null) { |
| 1986 | try { |
| 1987 | request.wait(); |
| 1988 | } catch (InterruptedException e) { |
| 1989 | // Do nothing, go back and wait until the request is complete |
| 1990 | } |
| 1991 | } |
| 1992 | } |
| 1993 | return request.result; |
| 1994 | } |
| 1995 | |
| 1996 | /** |
| 1997 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1998 | * Posts the specified command to be executed on the main thread, and |
| 1999 | * returns immediately. |
| 2000 | * @see #sendRequest |
| 2001 | */ |
| 2002 | private void sendRequestAsync(int command) { |
| 2003 | mMainThreadHandler.sendEmptyMessage(command); |
| 2004 | } |
| 2005 | |
| 2006 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2007 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2008 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2009 | */ |
| 2010 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2011 | sendRequestAsync(command, argument, null, null); |
| 2012 | } |
| 2013 | |
| 2014 | /** |
| 2015 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2016 | * @see {@link #sendRequest(int,Object)} |
| 2017 | */ |
| 2018 | private void sendRequestAsync( |
| 2019 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2020 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2021 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2022 | msg.sendToTarget(); |
| 2023 | } |
| 2024 | |
| 2025 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2026 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2027 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2028 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2029 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2030 | synchronized (PhoneInterfaceManager.class) { |
| 2031 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2032 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2033 | } else { |
| 2034 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2035 | } |
| 2036 | return sInstance; |
| 2037 | } |
| 2038 | } |
| 2039 | |
| 2040 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2041 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2042 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2043 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 2044 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2045 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2046 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2047 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2048 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2049 | mTelephonySharedPreferences = |
| 2050 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2051 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2052 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2053 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2054 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2055 | publish(); |
| 2056 | } |
| 2057 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2058 | private Phone getDefaultPhone() { |
| 2059 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2060 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2061 | } |
| 2062 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2063 | private void publish() { |
| 2064 | if (DBG) log("publish: " + this); |
| 2065 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2066 | TelephonyFrameworkInitializer |
| 2067 | .getTelephonyServiceManager() |
| 2068 | .getTelephonyServiceRegisterer() |
| 2069 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2070 | } |
| 2071 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2072 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2073 | if (request.phone != null) { |
| 2074 | return request.phone; |
| 2075 | } else { |
| 2076 | return getPhoneFromSubId(request.subId); |
| 2077 | } |
| 2078 | } |
| 2079 | |
| 2080 | private Phone getPhoneFromSubId(int subId) { |
| 2081 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2082 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2083 | } |
| 2084 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2085 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 2086 | Phone phone = getPhoneFromRequest(request); |
| 2087 | return phone == null ? null : |
| 2088 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 2089 | } |
| 2090 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2091 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2092 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2093 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2094 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2095 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2096 | private void sendEraseModemConfig(Phone phone) { |
| 2097 | if (phone != null) { |
| 2098 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2099 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 2100 | final long identity = Binder.clearCallingIdentity(); |
| 2101 | try { |
| 2102 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2103 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2104 | } finally { |
| 2105 | Binder.restoreCallingIdentity(identity); |
| 2106 | } |
| 2107 | } |
| 2108 | } |
| 2109 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2110 | private boolean isImsAvailableOnDevice() { |
| 2111 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2112 | if (pm == null) { |
| 2113 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2114 | // so do not throw error and allow. |
| 2115 | return true; |
| 2116 | } |
| 2117 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2118 | } |
| 2119 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2120 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2121 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2122 | } |
| 2123 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2124 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2125 | if (DBG) log("dial: " + number); |
| 2126 | // No permission check needed here: This is just a wrapper around the |
| 2127 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2128 | // the UI before it does anything. |
| 2129 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2130 | final long identity = Binder.clearCallingIdentity(); |
| 2131 | try { |
| 2132 | String url = createTelUrl(number); |
| 2133 | if (url == null) { |
| 2134 | return; |
| 2135 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2136 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2137 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2138 | PhoneConstants.State state = mCM.getState(subId); |
| 2139 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2140 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2141 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2142 | mApp.startActivity(intent); |
| 2143 | } |
| 2144 | } finally { |
| 2145 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2146 | } |
| 2147 | } |
| 2148 | |
| 2149 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2150 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2151 | } |
| 2152 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2153 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2154 | if (DBG) log("call: " + number); |
| 2155 | |
| 2156 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2157 | // need to do a permission check since we're calling startActivity() |
| 2158 | // from the context of the phone app. |
| 2159 | enforceCallPermission(); |
| 2160 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2161 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2162 | != AppOpsManager.MODE_ALLOWED) { |
| 2163 | return; |
| 2164 | } |
| 2165 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2166 | final long identity = Binder.clearCallingIdentity(); |
| 2167 | try { |
| 2168 | String url = createTelUrl(number); |
| 2169 | if (url == null) { |
| 2170 | return; |
| 2171 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2172 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2173 | boolean isValid = false; |
| 2174 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2175 | if (slist != null) { |
| 2176 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2177 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2178 | isValid = true; |
| 2179 | break; |
| 2180 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2181 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2182 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2183 | if (!isValid) { |
| 2184 | return; |
| 2185 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2186 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2187 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2188 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2189 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2190 | mApp.startActivity(intent); |
| 2191 | } finally { |
| 2192 | Binder.restoreCallingIdentity(identity); |
| 2193 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2194 | } |
| 2195 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2196 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2197 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2198 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2199 | } |
| 2200 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2201 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2202 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2203 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2204 | } |
| 2205 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2206 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2207 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2208 | |
| 2209 | final long identity = Binder.clearCallingIdentity(); |
| 2210 | try { |
| 2211 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 2212 | checkSimPin.start(); |
| 2213 | return checkSimPin.unlockSim(null, pin); |
| 2214 | } finally { |
| 2215 | Binder.restoreCallingIdentity(identity); |
| 2216 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2217 | } |
| 2218 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2219 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2220 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2221 | |
| 2222 | final long identity = Binder.clearCallingIdentity(); |
| 2223 | try { |
| 2224 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 2225 | checkSimPuk.start(); |
| 2226 | return checkSimPuk.unlockSim(puk, pin); |
| 2227 | } finally { |
| 2228 | Binder.restoreCallingIdentity(identity); |
| 2229 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2230 | } |
| 2231 | |
| 2232 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2233 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2234 | * a synchronous one. |
| 2235 | */ |
| 2236 | private static class UnlockSim extends Thread { |
| 2237 | |
| 2238 | private final IccCard mSimCard; |
| 2239 | |
| 2240 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2241 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2242 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2243 | |
| 2244 | // For replies from SimCard interface |
| 2245 | private Handler mHandler; |
| 2246 | |
| 2247 | // For async handler to identify request type |
| 2248 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2249 | |
| 2250 | public UnlockSim(IccCard simCard) { |
| 2251 | mSimCard = simCard; |
| 2252 | } |
| 2253 | |
| 2254 | @Override |
| 2255 | public void run() { |
| 2256 | Looper.prepare(); |
| 2257 | synchronized (UnlockSim.this) { |
| 2258 | mHandler = new Handler() { |
| 2259 | @Override |
| 2260 | public void handleMessage(Message msg) { |
| 2261 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2262 | switch (msg.what) { |
| 2263 | case SUPPLY_PIN_COMPLETE: |
| 2264 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2265 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2266 | mRetryCount = msg.arg1; |
| 2267 | if (ar.exception != null) { |
| 2268 | if (ar.exception instanceof CommandException && |
| 2269 | ((CommandException)(ar.exception)).getCommandError() |
| 2270 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2271 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2272 | } //When UiccCardApp dispose,handle message and return exception |
| 2273 | else if (ar.exception instanceof CommandException && |
| 2274 | ((CommandException) (ar.exception)).getCommandError() |
| 2275 | == CommandException.Error.ABORTED) { |
| 2276 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2277 | } else { |
| 2278 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2279 | } |
| 2280 | } else { |
| 2281 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2282 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2283 | mDone = true; |
| 2284 | UnlockSim.this.notifyAll(); |
| 2285 | } |
| 2286 | break; |
| 2287 | } |
| 2288 | } |
| 2289 | }; |
| 2290 | UnlockSim.this.notifyAll(); |
| 2291 | } |
| 2292 | Looper.loop(); |
| 2293 | } |
| 2294 | |
| 2295 | /* |
| 2296 | * Use PIN or PUK to unlock SIM card |
| 2297 | * |
| 2298 | * If PUK is null, unlock SIM card with PIN |
| 2299 | * |
| 2300 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2301 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2302 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2303 | |
| 2304 | while (mHandler == null) { |
| 2305 | try { |
| 2306 | wait(); |
| 2307 | } catch (InterruptedException e) { |
| 2308 | Thread.currentThread().interrupt(); |
| 2309 | } |
| 2310 | } |
| 2311 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2312 | |
| 2313 | if (puk == null) { |
| 2314 | mSimCard.supplyPin(pin, callback); |
| 2315 | } else { |
| 2316 | mSimCard.supplyPuk(puk, pin, callback); |
| 2317 | } |
| 2318 | |
| 2319 | while (!mDone) { |
| 2320 | try { |
| 2321 | Log.d(LOG_TAG, "wait for done"); |
| 2322 | wait(); |
| 2323 | } catch (InterruptedException e) { |
| 2324 | // Restore the interrupted status |
| 2325 | Thread.currentThread().interrupt(); |
| 2326 | } |
| 2327 | } |
| 2328 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2329 | int[] resultArray = new int[2]; |
| 2330 | resultArray[0] = mResult; |
| 2331 | resultArray[1] = mRetryCount; |
| 2332 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2333 | } |
| 2334 | } |
| 2335 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2336 | /** |
| 2337 | * This method has been removed due to privacy and stability concerns. |
| 2338 | */ |
| 2339 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2340 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2341 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2342 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2343 | } |
| 2344 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2345 | @Override |
| 2346 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2347 | mApp.getSystemService(AppOpsManager.class) |
| 2348 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2349 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2350 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2351 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2352 | // Callers targeting S have no business invoking this method. |
| 2353 | return; |
| 2354 | } |
| 2355 | |
| 2356 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2357 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2358 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2359 | .setCallingPackage(callingPackage) |
| 2360 | .setCallingFeatureId(null) |
| 2361 | .setCallingPid(Binder.getCallingPid()) |
| 2362 | .setCallingUid(Binder.getCallingUid()) |
| 2363 | .setMethod("updateServiceLocation") |
| 2364 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2365 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2366 | .build()); |
| 2367 | // Apps that lack location permission have no business calling this method; |
| 2368 | // however, because no permission was declared in the public API, denials must |
| 2369 | // all be "soft". |
| 2370 | switch (locationResult) { |
| 2371 | case DENIED_HARD: /* fall through */ |
| 2372 | case DENIED_SOFT: |
| 2373 | return; |
| 2374 | } |
| 2375 | |
| 2376 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2377 | final long identity = Binder.clearCallingIdentity(); |
| 2378 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2379 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2380 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2381 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2382 | } |
| 2383 | } finally { |
| 2384 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2385 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2386 | } |
| 2387 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2388 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2389 | @Override |
| 2390 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2391 | return isRadioOnWithFeature(callingPackage, null); |
| 2392 | } |
| 2393 | |
| 2394 | |
| 2395 | @Override |
| 2396 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2397 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2398 | callingFeatureId); |
| 2399 | } |
| 2400 | |
| 2401 | @Deprecated |
| 2402 | @Override |
| 2403 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2404 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2405 | } |
| 2406 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2407 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2408 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2409 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2410 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2411 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2412 | return false; |
| 2413 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2414 | |
| 2415 | final long identity = Binder.clearCallingIdentity(); |
| 2416 | try { |
| 2417 | return isRadioOnForSubscriber(subId); |
| 2418 | } finally { |
| 2419 | Binder.restoreCallingIdentity(identity); |
| 2420 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2421 | } |
| 2422 | |
| 2423 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2424 | final long identity = Binder.clearCallingIdentity(); |
| 2425 | try { |
| 2426 | final Phone phone = getPhone(subId); |
| 2427 | if (phone != null) { |
| 2428 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2429 | } else { |
| 2430 | return false; |
| 2431 | } |
| 2432 | } finally { |
| 2433 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2434 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2435 | } |
| 2436 | |
| 2437 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2438 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2439 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2440 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2441 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2442 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2443 | |
| 2444 | final long identity = Binder.clearCallingIdentity(); |
| 2445 | try { |
| 2446 | final Phone phone = getPhone(subId); |
| 2447 | if (phone != null) { |
| 2448 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2449 | } |
| 2450 | } finally { |
| 2451 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2452 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2453 | } |
| 2454 | |
| 2455 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2456 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2457 | } |
| 2458 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2459 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2460 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2461 | |
| 2462 | final long identity = Binder.clearCallingIdentity(); |
| 2463 | try { |
| 2464 | final Phone phone = getPhone(subId); |
| 2465 | if (phone == null) { |
| 2466 | return false; |
| 2467 | } |
| 2468 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2469 | toggleRadioOnOffForSubscriber(subId); |
| 2470 | } |
| 2471 | return true; |
| 2472 | } finally { |
| 2473 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2474 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2475 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2476 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2477 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2478 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2479 | /* |
| 2480 | * If any of the Radios are available, it will need to be |
| 2481 | * shutdown. So return true if any Radio is available. |
| 2482 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2483 | final long identity = Binder.clearCallingIdentity(); |
| 2484 | try { |
| 2485 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2486 | Phone phone = PhoneFactory.getPhone(i); |
| 2487 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2488 | } |
| 2489 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2490 | return false; |
| 2491 | } finally { |
| 2492 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2493 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2494 | } |
| 2495 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2496 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2497 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2498 | enforceModifyPermission(); |
| 2499 | |
| 2500 | final long identity = Binder.clearCallingIdentity(); |
| 2501 | try { |
| 2502 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2503 | logv("Shutting down Phone " + i); |
| 2504 | shutdownRadioUsingPhoneId(i); |
| 2505 | } |
| 2506 | } finally { |
| 2507 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2508 | } |
| 2509 | } |
| 2510 | |
| 2511 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2512 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2513 | if (phone != null && phone.isRadioAvailable()) { |
| 2514 | phone.shutdownRadio(); |
| 2515 | } |
| 2516 | } |
| 2517 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2518 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2519 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2520 | |
| 2521 | final long identity = Binder.clearCallingIdentity(); |
| 2522 | try { |
| 2523 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2524 | if (defaultPhone != null) { |
| 2525 | defaultPhone.setRadioPower(turnOn); |
| 2526 | return true; |
| 2527 | } else { |
| 2528 | loge("There's no default phone."); |
| 2529 | return false; |
| 2530 | } |
| 2531 | } finally { |
| 2532 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2533 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2534 | } |
| 2535 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2536 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2537 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2538 | |
| 2539 | final long identity = Binder.clearCallingIdentity(); |
| 2540 | try { |
| 2541 | final Phone phone = getPhone(subId); |
| 2542 | if (phone != null) { |
| 2543 | phone.setRadioPower(turnOn); |
| 2544 | return true; |
| 2545 | } else { |
| 2546 | return false; |
| 2547 | } |
| 2548 | } finally { |
| 2549 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2550 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2551 | } |
| 2552 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2553 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2554 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2555 | public boolean enableDataConnectivity() { |
| 2556 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2557 | |
| 2558 | final long identity = Binder.clearCallingIdentity(); |
| 2559 | try { |
| 2560 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2561 | final Phone phone = getPhone(subId); |
| 2562 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2563 | phone.getDataEnabledSettings().setDataEnabled( |
| 2564 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2565 | return true; |
| 2566 | } else { |
| 2567 | return false; |
| 2568 | } |
| 2569 | } finally { |
| 2570 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2571 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2572 | } |
| 2573 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2574 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2575 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2576 | public boolean disableDataConnectivity() { |
| 2577 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2578 | |
| 2579 | final long identity = Binder.clearCallingIdentity(); |
| 2580 | try { |
| 2581 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2582 | final Phone phone = getPhone(subId); |
| 2583 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2584 | phone.getDataEnabledSettings().setDataEnabled( |
| 2585 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2586 | return true; |
| 2587 | } else { |
| 2588 | return false; |
| 2589 | } |
| 2590 | } finally { |
| 2591 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2592 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2593 | } |
| 2594 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2595 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2596 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2597 | final long identity = Binder.clearCallingIdentity(); |
| 2598 | try { |
| 2599 | final Phone phone = getPhone(subId); |
| 2600 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2601 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2602 | } else { |
| 2603 | return false; |
| 2604 | } |
| 2605 | } finally { |
| 2606 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2607 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2608 | } |
| 2609 | |
| 2610 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2611 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2612 | } |
| 2613 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2614 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2615 | enforceCallPermission(); |
| 2616 | |
| 2617 | final long identity = Binder.clearCallingIdentity(); |
| 2618 | try { |
| 2619 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2620 | return; |
| 2621 | } |
| 2622 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2623 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2624 | } finally { |
| 2625 | Binder.restoreCallingIdentity(identity); |
| 2626 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2627 | }; |
| 2628 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2629 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2630 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2631 | |
| 2632 | final long identity = Binder.clearCallingIdentity(); |
| 2633 | try { |
| 2634 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2635 | return false; |
| 2636 | } |
| 2637 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2638 | } finally { |
| 2639 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2640 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2641 | } |
| 2642 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2643 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2644 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2645 | } |
| 2646 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2647 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2648 | final long identity = Binder.clearCallingIdentity(); |
| 2649 | try { |
| 2650 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2651 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2652 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2653 | } finally { |
| 2654 | Binder.restoreCallingIdentity(identity); |
| 2655 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2656 | } |
| 2657 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2658 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2659 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2660 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2661 | } |
| 2662 | |
| 2663 | @Override |
| 2664 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2665 | final long identity = Binder.clearCallingIdentity(); |
| 2666 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2667 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2668 | if (phone != null) { |
| 2669 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2670 | } else { |
| 2671 | return PhoneConstantConversions.convertDataState( |
| 2672 | PhoneConstants.DataState.DISCONNECTED); |
| 2673 | } |
| 2674 | } finally { |
| 2675 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2676 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2677 | } |
| 2678 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2679 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2680 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2681 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2682 | } |
| 2683 | |
| 2684 | @Override |
| 2685 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2686 | final long identity = Binder.clearCallingIdentity(); |
| 2687 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2688 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2689 | if (phone != null) { |
| 2690 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2691 | } else { |
| 2692 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2693 | } |
| 2694 | } finally { |
| 2695 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2696 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2697 | } |
| 2698 | |
| 2699 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2700 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2701 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2702 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2703 | |
| 2704 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2705 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2706 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2707 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2708 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2709 | .setCallingPid(Binder.getCallingPid()) |
| 2710 | .setCallingUid(Binder.getCallingUid()) |
| 2711 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2712 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2713 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2714 | .build()); |
| 2715 | switch (locationResult) { |
| 2716 | case DENIED_HARD: |
| 2717 | throw new SecurityException("Not allowed to access cell location"); |
| 2718 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2719 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2720 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2721 | } |
| 2722 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2723 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2724 | final long identity = Binder.clearCallingIdentity(); |
| 2725 | try { |
| 2726 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2727 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2728 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2729 | } finally { |
| 2730 | Binder.restoreCallingIdentity(identity); |
| 2731 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2732 | } |
| 2733 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2734 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2735 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2736 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2737 | // registered cell info, so return a NULL country instead. |
| 2738 | final long identity = Binder.clearCallingIdentity(); |
| 2739 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2740 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2741 | // Get default phone in this case. |
| 2742 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2743 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2744 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2745 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2746 | if (phone == null) return ""; |
| 2747 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2748 | if (sst == null) return ""; |
| 2749 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2750 | if (lt == null) return ""; |
| 2751 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2752 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2753 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2754 | } finally { |
| 2755 | Binder.restoreCallingIdentity(identity); |
| 2756 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2757 | } |
| 2758 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2759 | /** |
| 2760 | * This method was removed due to potential issues caused by performing partial |
| 2761 | * updates of service state, and lack of a credible use case. |
| 2762 | * |
| 2763 | * This has the ability to break the telephony implementation by disabling notification of |
| 2764 | * changes in device connectivity. DO NOT USE THIS! |
| 2765 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2766 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2767 | public void enableLocationUpdates() { |
| 2768 | mApp.enforceCallingOrSelfPermission( |
| 2769 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2770 | } |
| 2771 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2772 | /** |
| 2773 | * This method was removed due to potential issues caused by performing partial |
| 2774 | * updates of service state, and lack of a credible use case. |
| 2775 | * |
| 2776 | * This has the ability to break the telephony implementation by disabling notification of |
| 2777 | * changes in device connectivity. DO NOT USE THIS! |
| 2778 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2779 | @Override |
| 2780 | public void disableLocationUpdates() { |
| 2781 | mApp.enforceCallingOrSelfPermission( |
| 2782 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2783 | } |
| 2784 | |
| 2785 | @Override |
| 2786 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2787 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2788 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2789 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2790 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2791 | throw new SecurityException( |
| 2792 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2793 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2794 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2795 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2796 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2797 | return null; |
| 2798 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2799 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2800 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2801 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2802 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2803 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2804 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2805 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2806 | for (CellInfo ci : info) { |
| 2807 | if (ci instanceof CellInfoGsm) { |
| 2808 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2809 | } else if (ci instanceof CellInfoWcdma) { |
| 2810 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2811 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2812 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2813 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2814 | } |
| 2815 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2816 | private List<CellInfo> getCachedCellInfo() { |
| 2817 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2818 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2819 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2820 | if (info != null) cellInfos.addAll(info); |
| 2821 | } |
| 2822 | return cellInfos; |
| 2823 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2824 | |
| 2825 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2826 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2827 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2828 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2829 | |
| 2830 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2831 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2832 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2833 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2834 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2835 | .setCallingPid(Binder.getCallingPid()) |
| 2836 | .setCallingUid(Binder.getCallingUid()) |
| 2837 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2838 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2839 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2840 | .build()); |
| 2841 | switch (locationResult) { |
| 2842 | case DENIED_HARD: |
| 2843 | throw new SecurityException("Not allowed to access cell info"); |
| 2844 | case DENIED_SOFT: |
| 2845 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2846 | } |
| 2847 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2848 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2849 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2850 | return getCachedCellInfo(); |
| 2851 | } |
| 2852 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2853 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2854 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2855 | final long identity = Binder.clearCallingIdentity(); |
| 2856 | try { |
| 2857 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2858 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2859 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2860 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2861 | if (info != null) cellInfos.addAll(info); |
| 2862 | } |
| 2863 | return cellInfos; |
| 2864 | } finally { |
| 2865 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2866 | } |
| 2867 | } |
| 2868 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2869 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2870 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2871 | String callingFeatureId) { |
| 2872 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2873 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2874 | } |
| 2875 | |
| 2876 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2877 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2878 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2879 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2880 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2881 | } |
| 2882 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2883 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2884 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2885 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2886 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2887 | |
| 2888 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2889 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2890 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2891 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2892 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2893 | .setCallingPid(Binder.getCallingPid()) |
| 2894 | .setCallingUid(Binder.getCallingUid()) |
| 2895 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2896 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2897 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2898 | .build()); |
| 2899 | switch (locationResult) { |
| 2900 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2901 | if (TelephonyPermissions |
| 2902 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2903 | // Safetynet logging for b/154934934 |
| 2904 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2905 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2906 | throw new SecurityException("Not allowed to access cell info"); |
| 2907 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2908 | if (TelephonyPermissions |
| 2909 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2910 | // Safetynet logging for b/154934934 |
| 2911 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2912 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2913 | try { |
| 2914 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2915 | } catch (RemoteException re) { |
| 2916 | // Drop without consequences |
| 2917 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2918 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2919 | } |
| 2920 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2921 | |
| 2922 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2923 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2924 | |
| 2925 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2926 | } |
| 2927 | |
| 2928 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2929 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2930 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2931 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2932 | |
| 2933 | final long identity = Binder.clearCallingIdentity(); |
| 2934 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2935 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2936 | } finally { |
| 2937 | Binder.restoreCallingIdentity(identity); |
| 2938 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2939 | } |
| 2940 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2941 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2942 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2943 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2944 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2945 | return null; |
| 2946 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2947 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2948 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2949 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2950 | return null; |
| 2951 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2952 | |
| 2953 | final long identity = Binder.clearCallingIdentity(); |
| 2954 | try { |
| 2955 | return phone.getImei(); |
| 2956 | } finally { |
| 2957 | Binder.restoreCallingIdentity(identity); |
| 2958 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2959 | } |
| 2960 | |
| 2961 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2962 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2963 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2964 | String tac = null; |
| 2965 | if (phone != null) { |
| 2966 | String imei = phone.getImei(); |
| 2967 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2968 | } |
| 2969 | return tac; |
| 2970 | } |
| 2971 | |
| 2972 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2973 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2974 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2975 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2976 | return null; |
| 2977 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2978 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2979 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2980 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2981 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2982 | return null; |
| 2983 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2984 | |
| 2985 | final long identity = Binder.clearCallingIdentity(); |
| 2986 | try { |
| 2987 | return phone.getMeid(); |
| 2988 | } finally { |
| 2989 | Binder.restoreCallingIdentity(identity); |
| 2990 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2991 | } |
| 2992 | |
| 2993 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2994 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2995 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2996 | String manufacturerCode = null; |
| 2997 | if (phone != null) { |
| 2998 | String meid = phone.getMeid(); |
| 2999 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3000 | } |
| 3001 | return manufacturerCode; |
| 3002 | } |
| 3003 | |
| 3004 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3005 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3006 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3007 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3008 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3009 | return null; |
| 3010 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3011 | int subId = phone.getSubId(); |
| 3012 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3013 | mApp, subId, callingPackage, callingFeatureId, |
| 3014 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3015 | return null; |
| 3016 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3017 | |
| 3018 | final long identity = Binder.clearCallingIdentity(); |
| 3019 | try { |
| 3020 | return phone.getDeviceSvn(); |
| 3021 | } finally { |
| 3022 | Binder.restoreCallingIdentity(identity); |
| 3023 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3024 | } |
| 3025 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3026 | @Override |
| 3027 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3028 | final long identity = Binder.clearCallingIdentity(); |
| 3029 | try { |
| 3030 | final Phone phone = getPhone(subId); |
| 3031 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3032 | } finally { |
| 3033 | Binder.restoreCallingIdentity(identity); |
| 3034 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3035 | } |
| 3036 | |
| 3037 | @Override |
| 3038 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3039 | final long identity = Binder.clearCallingIdentity(); |
| 3040 | try { |
| 3041 | final Phone phone = getPhone(subId); |
| 3042 | return phone == null ? null : phone.getCarrierName(); |
| 3043 | } finally { |
| 3044 | Binder.restoreCallingIdentity(identity); |
| 3045 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3046 | } |
| 3047 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3048 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3049 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3050 | final long identity = Binder.clearCallingIdentity(); |
| 3051 | try { |
| 3052 | final Phone phone = getPhone(subId); |
| 3053 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3054 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3055 | } finally { |
| 3056 | Binder.restoreCallingIdentity(identity); |
| 3057 | } |
| 3058 | } |
| 3059 | |
| 3060 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3061 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3062 | final long identity = Binder.clearCallingIdentity(); |
| 3063 | try { |
| 3064 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3065 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3066 | } finally { |
| 3067 | Binder.restoreCallingIdentity(identity); |
| 3068 | } |
| 3069 | } |
| 3070 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3071 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3072 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3073 | if (!isSubscriptionMccMnc) { |
| 3074 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3075 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3076 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3077 | if (phone == null) { |
| 3078 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3079 | } |
| 3080 | final long identity = Binder.clearCallingIdentity(); |
| 3081 | try { |
| 3082 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3083 | } finally { |
| 3084 | Binder.restoreCallingIdentity(identity); |
| 3085 | } |
| 3086 | } |
| 3087 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3088 | // |
| 3089 | // Internal helper methods. |
| 3090 | // |
| 3091 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3092 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3093 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3094 | * |
| 3095 | * @throws SecurityException if the caller does not have the required permission |
| 3096 | */ |
| 3097 | private void enforceModifyPermission() { |
| 3098 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3099 | } |
| 3100 | |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3101 | /** |
| 3102 | * Make sure the caller is system. |
| 3103 | * |
| 3104 | * @throws SecurityException if the caller is not system. |
| 3105 | */ |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 3106 | private static void enforceSystemCaller() { |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3107 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 3108 | throw new SecurityException("Caller must be system"); |
| 3109 | } |
| 3110 | } |
| 3111 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3112 | private void enforceActiveEmergencySessionPermission() { |
| 3113 | mApp.enforceCallingOrSelfPermission( |
| 3114 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3115 | } |
| 3116 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3117 | /** |
| 3118 | * Make sure the caller has the CALL_PHONE permission. |
| 3119 | * |
| 3120 | * @throws SecurityException if the caller does not have the required permission |
| 3121 | */ |
| 3122 | private void enforceCallPermission() { |
| 3123 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3124 | } |
| 3125 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3126 | private void enforceSettingsPermission() { |
| 3127 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3128 | } |
| 3129 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3130 | private String createTelUrl(String number) { |
| 3131 | if (TextUtils.isEmpty(number)) { |
| 3132 | return null; |
| 3133 | } |
| 3134 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3135 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3136 | } |
| 3137 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3138 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3139 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3140 | } |
| 3141 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3142 | private static void logv(String msg) { |
| 3143 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3144 | } |
| 3145 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3146 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3147 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3148 | } |
| 3149 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3150 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3151 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3152 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3153 | } |
| 3154 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3155 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3156 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3157 | final long identity = Binder.clearCallingIdentity(); |
| 3158 | try { |
| 3159 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3160 | if (phone == null) { |
| 3161 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3162 | } else { |
| 3163 | return phone.getPhoneType(); |
| 3164 | } |
| 3165 | } finally { |
| 3166 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3167 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3168 | } |
| 3169 | |
| 3170 | /** |
| 3171 | * Returns the CDMA ERI icon index to display |
| 3172 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3173 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3174 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3175 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3176 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3177 | } |
| 3178 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3179 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3180 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3181 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3182 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3183 | mApp, subId, callingPackage, callingFeatureId, |
| 3184 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3185 | return -1; |
| 3186 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3187 | |
| 3188 | final long identity = Binder.clearCallingIdentity(); |
| 3189 | try { |
| 3190 | final Phone phone = getPhone(subId); |
| 3191 | if (phone != null) { |
| 3192 | return phone.getCdmaEriIconIndex(); |
| 3193 | } else { |
| 3194 | return -1; |
| 3195 | } |
| 3196 | } finally { |
| 3197 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3198 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3199 | } |
| 3200 | |
| 3201 | /** |
| 3202 | * Returns the CDMA ERI icon mode, |
| 3203 | * 0 - ON |
| 3204 | * 1 - FLASHING |
| 3205 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3206 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3207 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3208 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3209 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3210 | } |
| 3211 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3212 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3213 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3214 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3215 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3216 | mApp, subId, callingPackage, callingFeatureId, |
| 3217 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3218 | return -1; |
| 3219 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3220 | |
| 3221 | final long identity = Binder.clearCallingIdentity(); |
| 3222 | try { |
| 3223 | final Phone phone = getPhone(subId); |
| 3224 | if (phone != null) { |
| 3225 | return phone.getCdmaEriIconMode(); |
| 3226 | } else { |
| 3227 | return -1; |
| 3228 | } |
| 3229 | } finally { |
| 3230 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3231 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3232 | } |
| 3233 | |
| 3234 | /** |
| 3235 | * Returns the CDMA ERI text, |
| 3236 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3237 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3238 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3239 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3240 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3241 | } |
| 3242 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3243 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3244 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3245 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3246 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3247 | mApp, subId, callingPackage, callingFeatureId, |
| 3248 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3249 | return null; |
| 3250 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3251 | |
| 3252 | final long identity = Binder.clearCallingIdentity(); |
| 3253 | try { |
| 3254 | final Phone phone = getPhone(subId); |
| 3255 | if (phone != null) { |
| 3256 | return phone.getCdmaEriText(); |
| 3257 | } else { |
| 3258 | return null; |
| 3259 | } |
| 3260 | } finally { |
| 3261 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3262 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3263 | } |
| 3264 | |
| 3265 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3266 | * Returns the CDMA MDN. |
| 3267 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3268 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3269 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3270 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3271 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3272 | |
| 3273 | final long identity = Binder.clearCallingIdentity(); |
| 3274 | try { |
| 3275 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3276 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3277 | return phone.getLine1Number(); |
| 3278 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3279 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3280 | return null; |
| 3281 | } |
| 3282 | } finally { |
| 3283 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3284 | } |
| 3285 | } |
| 3286 | |
| 3287 | /** |
| 3288 | * Returns the CDMA MIN. |
| 3289 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3290 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3291 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3292 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3293 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3294 | |
| 3295 | final long identity = Binder.clearCallingIdentity(); |
| 3296 | try { |
| 3297 | final Phone phone = getPhone(subId); |
| 3298 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3299 | return phone.getCdmaMin(); |
| 3300 | } else { |
| 3301 | return null; |
| 3302 | } |
| 3303 | } finally { |
| 3304 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3305 | } |
| 3306 | } |
| 3307 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3308 | @Override |
| 3309 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3310 | INumberVerificationCallback callback, String callingPackage) { |
| 3311 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3312 | != PERMISSION_GRANTED) { |
| 3313 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3314 | } |
| 3315 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3316 | |
| 3317 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3318 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3319 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3320 | + "calling package: " + callingPackage |
| 3321 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3322 | } |
| 3323 | |
| 3324 | if (range == null) { |
| 3325 | throw new NullPointerException("Range must be non-null"); |
| 3326 | } |
| 3327 | |
| 3328 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3329 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3330 | |
| 3331 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3332 | } |
| 3333 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3334 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3335 | * Returns true if CDMA provisioning needs to run. |
| 3336 | */ |
| 3337 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3338 | final long identity = Binder.clearCallingIdentity(); |
| 3339 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3340 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3341 | } finally { |
| 3342 | Binder.restoreCallingIdentity(identity); |
| 3343 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3344 | } |
| 3345 | |
| 3346 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3347 | * Sets the voice mail number of a given subId. |
| 3348 | */ |
| 3349 | @Override |
| 3350 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3351 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3352 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3353 | |
| 3354 | final long identity = Binder.clearCallingIdentity(); |
| 3355 | try { |
| 3356 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3357 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3358 | return success; |
| 3359 | } finally { |
| 3360 | Binder.restoreCallingIdentity(identity); |
| 3361 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3362 | } |
| 3363 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3364 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3365 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3366 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3367 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3368 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3369 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3370 | throw new SecurityException("caller must be system dialer"); |
| 3371 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3372 | |
| 3373 | final long identity = Binder.clearCallingIdentity(); |
| 3374 | try { |
| 3375 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3376 | if (phoneAccountHandle == null) { |
| 3377 | return null; |
| 3378 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3379 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3380 | } finally { |
| 3381 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3382 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3383 | } |
| 3384 | |
| 3385 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3386 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3387 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3388 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3389 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3390 | mApp, subId, callingPackage, callingFeatureId, |
| 3391 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3392 | return null; |
| 3393 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3394 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3395 | final long identity = Binder.clearCallingIdentity(); |
| 3396 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3397 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3398 | } finally { |
| 3399 | Binder.restoreCallingIdentity(identity); |
| 3400 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3401 | } |
| 3402 | |
| 3403 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3404 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3405 | VisualVoicemailSmsFilterSettings settings) { |
| 3406 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3407 | |
| 3408 | final long identity = Binder.clearCallingIdentity(); |
| 3409 | try { |
| 3410 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3411 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3412 | } finally { |
| 3413 | Binder.restoreCallingIdentity(identity); |
| 3414 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3415 | } |
| 3416 | |
| 3417 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3418 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3419 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3420 | |
| 3421 | final long identity = Binder.clearCallingIdentity(); |
| 3422 | try { |
| 3423 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3424 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3425 | } finally { |
| 3426 | Binder.restoreCallingIdentity(identity); |
| 3427 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3428 | } |
| 3429 | |
| 3430 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3431 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3432 | String callingPackage, int subId) { |
| 3433 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3434 | |
| 3435 | final long identity = Binder.clearCallingIdentity(); |
| 3436 | try { |
| 3437 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3438 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3439 | } finally { |
| 3440 | Binder.restoreCallingIdentity(identity); |
| 3441 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3442 | } |
| 3443 | |
| 3444 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3445 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3446 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3447 | |
| 3448 | final long identity = Binder.clearCallingIdentity(); |
| 3449 | try { |
| 3450 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3451 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3452 | } finally { |
| 3453 | Binder.restoreCallingIdentity(identity); |
| 3454 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3455 | } |
| 3456 | |
| 3457 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3458 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3459 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3460 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3461 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3462 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3463 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3464 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3465 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3466 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3467 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3468 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3469 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3470 | * Sets the voice activation state of a given subId. |
| 3471 | */ |
| 3472 | @Override |
| 3473 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3474 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3475 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3476 | |
| 3477 | final long identity = Binder.clearCallingIdentity(); |
| 3478 | try { |
| 3479 | final Phone phone = getPhone(subId); |
| 3480 | if (phone != null) { |
| 3481 | phone.setVoiceActivationState(activationState); |
| 3482 | } else { |
| 3483 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3484 | } |
| 3485 | } finally { |
| 3486 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3487 | } |
| 3488 | } |
| 3489 | |
| 3490 | /** |
| 3491 | * Sets the data activation state of a given subId. |
| 3492 | */ |
| 3493 | @Override |
| 3494 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3495 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3496 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3497 | |
| 3498 | final long identity = Binder.clearCallingIdentity(); |
| 3499 | try { |
| 3500 | final Phone phone = getPhone(subId); |
| 3501 | if (phone != null) { |
| 3502 | phone.setDataActivationState(activationState); |
| 3503 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3504 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3505 | } |
| 3506 | } finally { |
| 3507 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3508 | } |
| 3509 | } |
| 3510 | |
| 3511 | /** |
| 3512 | * Returns the voice activation state of a given subId. |
| 3513 | */ |
| 3514 | @Override |
| 3515 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3516 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3517 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3518 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3519 | final long identity = Binder.clearCallingIdentity(); |
| 3520 | try { |
| 3521 | if (phone != null) { |
| 3522 | return phone.getVoiceActivationState(); |
| 3523 | } else { |
| 3524 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3525 | } |
| 3526 | } finally { |
| 3527 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3528 | } |
| 3529 | } |
| 3530 | |
| 3531 | /** |
| 3532 | * Returns the data activation state of a given subId. |
| 3533 | */ |
| 3534 | @Override |
| 3535 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3536 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3537 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3538 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3539 | final long identity = Binder.clearCallingIdentity(); |
| 3540 | try { |
| 3541 | if (phone != null) { |
| 3542 | return phone.getDataActivationState(); |
| 3543 | } else { |
| 3544 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3545 | } |
| 3546 | } finally { |
| 3547 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3548 | } |
| 3549 | } |
| 3550 | |
| 3551 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3552 | * Returns the unread count of voicemails for a subId |
| 3553 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3554 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3555 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3556 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3557 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3558 | mApp, subId, callingPackage, callingFeatureId, |
| 3559 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3560 | return 0; |
| 3561 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3562 | final long identity = Binder.clearCallingIdentity(); |
| 3563 | try { |
| 3564 | final Phone phone = getPhone(subId); |
| 3565 | if (phone != null) { |
| 3566 | return phone.getVoiceMessageCount(); |
| 3567 | } else { |
| 3568 | return 0; |
| 3569 | } |
| 3570 | } finally { |
| 3571 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3572 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3573 | } |
| 3574 | |
| 3575 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3576 | * returns true, if the device is in a state where both voice and data |
| 3577 | * are supported simultaneously. This can change based on location or network condition. |
| 3578 | */ |
| 3579 | @Override |
| 3580 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3581 | final long identity = Binder.clearCallingIdentity(); |
| 3582 | try { |
| 3583 | final Phone phone = getPhone(subId); |
| 3584 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3585 | } finally { |
| 3586 | Binder.restoreCallingIdentity(identity); |
| 3587 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3588 | } |
| 3589 | |
| 3590 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3591 | * Send the dialer code if called from the current default dialer or the caller has |
| 3592 | * carrier privilege. |
| 3593 | * @param inputCode The dialer code to send |
| 3594 | */ |
| 3595 | @Override |
| 3596 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3597 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3598 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3599 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3600 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3601 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3602 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3603 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3604 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3605 | |
| 3606 | final long identity = Binder.clearCallingIdentity(); |
| 3607 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3608 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3609 | } finally { |
| 3610 | Binder.restoreCallingIdentity(identity); |
| 3611 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3612 | } |
| 3613 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3614 | @Override |
| 3615 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3616 | TelephonyPermissions |
| 3617 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3618 | mApp, subId, "getNetworkSelectionMode"); |
| 3619 | final long identity = Binder.clearCallingIdentity(); |
| 3620 | try { |
| 3621 | if (!isActiveSubscription(subId)) { |
| 3622 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3623 | } |
| 3624 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3625 | } finally { |
| 3626 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3627 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3628 | } |
| 3629 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3630 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3631 | public boolean isInEmergencySmsMode() { |
| 3632 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3633 | final long identity = Binder.clearCallingIdentity(); |
| 3634 | try { |
| 3635 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3636 | if (phone.isInEmergencySmsMode()) { |
| 3637 | return true; |
| 3638 | } |
| 3639 | } |
| 3640 | } finally { |
| 3641 | Binder.restoreCallingIdentity(identity); |
| 3642 | } |
| 3643 | return false; |
| 3644 | } |
| 3645 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3646 | /** |
| 3647 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3648 | * @param subId The subscription to use to check the configuration. |
| 3649 | * @param c The callback that will be used to send the result. |
| 3650 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3651 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3652 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3653 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3654 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3655 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3656 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3657 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3658 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3659 | "IMS not available on device."); |
| 3660 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3661 | final long token = Binder.clearCallingIdentity(); |
| 3662 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3663 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3664 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3665 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3666 | } catch (ImsException e) { |
| 3667 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3668 | } finally { |
| 3669 | Binder.restoreCallingIdentity(token); |
| 3670 | } |
| 3671 | } |
| 3672 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3673 | /** |
| 3674 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3675 | * @param subId The subscription to use to check the configuration. |
| 3676 | * @param c The callback that will be used to send the result. |
| 3677 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3678 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3679 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3680 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3681 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3682 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3683 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3684 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3685 | final long token = Binder.clearCallingIdentity(); |
| 3686 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3687 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3688 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3689 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3690 | } catch (ImsException e) { |
| 3691 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3692 | + "is inactive, ignoring unregister."); |
| 3693 | // If the subscription is no longer active, just return, since the callback |
| 3694 | // will already have been removed internally. |
| 3695 | } finally { |
| 3696 | Binder.restoreCallingIdentity(token); |
| 3697 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3698 | } |
| 3699 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3700 | /** |
| 3701 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3702 | */ |
| 3703 | @Override |
| 3704 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3705 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3706 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3707 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3708 | "IMS not available on device."); |
| 3709 | } |
| 3710 | final long token = Binder.clearCallingIdentity(); |
| 3711 | try { |
| 3712 | Phone phone = getPhone(subId); |
| 3713 | if (phone == null) { |
| 3714 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3715 | + subId + "'"); |
| 3716 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3717 | } |
| 3718 | phone.getImsRegistrationState(regState -> { |
| 3719 | try { |
| 3720 | consumer.accept((regState == null) |
| 3721 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3722 | } catch (RemoteException e) { |
| 3723 | // Ignore if the remote process is no longer available to call back. |
| 3724 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3725 | } |
| 3726 | }); |
| 3727 | } finally { |
| 3728 | Binder.restoreCallingIdentity(token); |
| 3729 | } |
| 3730 | } |
| 3731 | |
| 3732 | /** |
| 3733 | * Get the transport type for the IMS service registration state. |
| 3734 | */ |
| 3735 | @Override |
| 3736 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3737 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3738 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3739 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3740 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3741 | "IMS not available on device."); |
| 3742 | } |
| 3743 | final long token = Binder.clearCallingIdentity(); |
| 3744 | try { |
| 3745 | Phone phone = getPhone(subId); |
| 3746 | if (phone == null) { |
| 3747 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3748 | + subId + "'"); |
| 3749 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3750 | } |
| 3751 | phone.getImsRegistrationTech(regTech -> { |
| 3752 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3753 | int regTechConverted = (regTech == null) |
| 3754 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3755 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3756 | regTechConverted); |
| 3757 | try { |
| 3758 | consumer.accept(regTechConverted); |
| 3759 | } catch (RemoteException e) { |
| 3760 | // Ignore if the remote process is no longer available to call back. |
| 3761 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3762 | } |
| 3763 | }); |
| 3764 | } finally { |
| 3765 | Binder.restoreCallingIdentity(token); |
| 3766 | } |
| 3767 | } |
| 3768 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3769 | /** |
| 3770 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3771 | * @param subId The subscription to use to check the configuration. |
| 3772 | * @param c The callback that will be used to send the result. |
| 3773 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3774 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3775 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3776 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3777 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3778 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3779 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3780 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3781 | "IMS not available on device."); |
| 3782 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3783 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3784 | final long token = Binder.clearCallingIdentity(); |
| 3785 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3786 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3787 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3788 | } catch (ImsException e) { |
| 3789 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3790 | } finally { |
| 3791 | Binder.restoreCallingIdentity(token); |
| 3792 | } |
| 3793 | } |
| 3794 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3795 | /** |
| 3796 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3797 | * @param subId The subscription to use to check the configuration. |
| 3798 | * @param c The callback that will be used to send the result. |
| 3799 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3800 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3801 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3802 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3803 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3804 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3805 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3806 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3807 | |
| 3808 | final long token = Binder.clearCallingIdentity(); |
| 3809 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3810 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3811 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3812 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3813 | } catch (ImsException e) { |
| 3814 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3815 | + "is inactive, ignoring unregister."); |
| 3816 | // If the subscription is no longer active, just return, since the callback |
| 3817 | // will already have been removed internally. |
| 3818 | } finally { |
| 3819 | Binder.restoreCallingIdentity(token); |
| 3820 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3821 | } |
| 3822 | |
| 3823 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3824 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3825 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3826 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3827 | final long token = Binder.clearCallingIdentity(); |
| 3828 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3829 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3830 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3831 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3832 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3833 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3834 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3835 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3836 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3837 | } finally { |
| 3838 | Binder.restoreCallingIdentity(token); |
| 3839 | } |
| 3840 | } |
| 3841 | |
| 3842 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3843 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3844 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3845 | final long token = Binder.clearCallingIdentity(); |
| 3846 | try { |
| 3847 | Phone phone = getPhone(subId); |
| 3848 | if (phone == null) return false; |
| 3849 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3850 | } catch (com.android.ims.ImsException e) { |
| 3851 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3852 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3853 | } finally { |
| 3854 | Binder.restoreCallingIdentity(token); |
| 3855 | } |
| 3856 | } |
| 3857 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3858 | /** |
| 3859 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3860 | * subscription. |
| 3861 | * @param subId The subscription to use to check the configuration. |
| 3862 | * @param callback The callback that will be used to send the result. |
| 3863 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3864 | * @param transportType The transport type of the MmTelFeature capability. |
| 3865 | */ |
| 3866 | @Override |
| 3867 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3868 | int transportType) { |
| 3869 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3870 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3871 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3872 | "IMS not available on device."); |
| 3873 | } |
| 3874 | final long token = Binder.clearCallingIdentity(); |
| 3875 | try { |
| 3876 | int slotId = getSlotIndex(subId); |
| 3877 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3878 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3879 | + subId + "'"); |
| 3880 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3881 | } |
| 3882 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3883 | transportType, aBoolean -> { |
| 3884 | try { |
| 3885 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3886 | } catch (RemoteException e) { |
| 3887 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3888 | + "running. Ignore"); |
| 3889 | } |
| 3890 | }); |
| 3891 | } finally { |
| 3892 | Binder.restoreCallingIdentity(token); |
| 3893 | } |
| 3894 | } |
| 3895 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3896 | /** |
| 3897 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3898 | * @param subId The subscription to use to check the configuration. |
| 3899 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3900 | @Override |
| 3901 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3902 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3903 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3904 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3905 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3906 | final long token = Binder.clearCallingIdentity(); |
| 3907 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3908 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3909 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3910 | } catch (ImsException e) { |
| 3911 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3912 | } finally { |
| 3913 | Binder.restoreCallingIdentity(token); |
| 3914 | } |
| 3915 | } |
| 3916 | |
| 3917 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3918 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3919 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3920 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3921 | final long identity = Binder.clearCallingIdentity(); |
| 3922 | try { |
| 3923 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3924 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3925 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3926 | } catch (ImsException e) { |
| 3927 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3928 | } finally { |
| 3929 | Binder.restoreCallingIdentity(identity); |
| 3930 | } |
| 3931 | } |
| 3932 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3933 | /** |
| 3934 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3935 | * @param subId The subscription to use to check the configuration. |
| 3936 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3937 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3938 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3939 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3940 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3941 | final long identity = Binder.clearCallingIdentity(); |
| 3942 | try { |
| 3943 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3944 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3945 | } catch (ImsException e) { |
| 3946 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3947 | } finally { |
| 3948 | Binder.restoreCallingIdentity(identity); |
| 3949 | } |
| 3950 | } |
| 3951 | |
| 3952 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3953 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3954 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3955 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3956 | final long identity = Binder.clearCallingIdentity(); |
| 3957 | try { |
| 3958 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3959 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3960 | } catch (ImsException e) { |
| 3961 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3962 | } finally { |
| 3963 | Binder.restoreCallingIdentity(identity); |
| 3964 | } |
| 3965 | } |
| 3966 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3967 | /** |
| 3968 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3969 | * @param subId The subscription to use to check the configuration. |
| 3970 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3971 | @Override |
| 3972 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3973 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3974 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3975 | final long identity = Binder.clearCallingIdentity(); |
| 3976 | try { |
| 3977 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3978 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3979 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3980 | } catch (ImsException e) { |
| 3981 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3982 | } finally { |
| 3983 | Binder.restoreCallingIdentity(identity); |
| 3984 | } |
| 3985 | } |
| 3986 | |
| 3987 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3988 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3989 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3990 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3991 | final long identity = Binder.clearCallingIdentity(); |
| 3992 | try { |
| 3993 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3994 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3995 | } catch (ImsException e) { |
| 3996 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3997 | } finally { |
| 3998 | Binder.restoreCallingIdentity(identity); |
| 3999 | } |
| 4000 | } |
| 4001 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4002 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4003 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4004 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4005 | * @param subId The subscription to use to check the configuration. |
| 4006 | */ |
| 4007 | @Override |
| 4008 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
| 4009 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4010 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4011 | final long identity = Binder.clearCallingIdentity(); |
| 4012 | try { |
| 4013 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4014 | return ImsManager.getInstance(mApp, |
| 4015 | getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser(); |
| 4016 | } catch (ImsException e) { |
| 4017 | throw new ServiceSpecificException(e.getCode()); |
| 4018 | } finally { |
| 4019 | Binder.restoreCallingIdentity(identity); |
| 4020 | } |
| 4021 | } |
| 4022 | |
| 4023 | /** |
| 4024 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4025 | * Requires MODIFY_PHONE_STATE permission. |
| 4026 | * @param subId The subscription to use to check the configuration. |
| 4027 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4028 | * false otherwise |
| 4029 | */ |
| 4030 | @Override |
| 4031 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4032 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4033 | "setCrossSimCallingEnabled"); |
| 4034 | final long identity = Binder.clearCallingIdentity(); |
| 4035 | try { |
| 4036 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4037 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 4038 | .setCrossSimCallingEnabled(isEnabled); |
| 4039 | } catch (ImsException e) { |
| 4040 | throw new ServiceSpecificException(e.getCode()); |
| 4041 | } finally { |
| 4042 | Binder.restoreCallingIdentity(identity); |
| 4043 | } |
| 4044 | } |
| 4045 | |
| 4046 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4047 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4048 | * @param subId The subscription to use to check the configuration. |
| 4049 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4050 | @Override |
| 4051 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4052 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4053 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4054 | final long identity = Binder.clearCallingIdentity(); |
| 4055 | try { |
| 4056 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4057 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4058 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4059 | } catch (ImsException e) { |
| 4060 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4061 | } finally { |
| 4062 | Binder.restoreCallingIdentity(identity); |
| 4063 | } |
| 4064 | } |
| 4065 | |
| 4066 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4067 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4068 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4069 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4070 | final long identity = Binder.clearCallingIdentity(); |
| 4071 | try { |
| 4072 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4073 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4074 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4075 | } catch (ImsException e) { |
| 4076 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4077 | } finally { |
| 4078 | Binder.restoreCallingIdentity(identity); |
| 4079 | } |
| 4080 | } |
| 4081 | |
| 4082 | @Override |
| 4083 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4084 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4085 | "setVoWiFiNonPersistent"); |
| 4086 | final long identity = Binder.clearCallingIdentity(); |
| 4087 | try { |
| 4088 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4089 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 4090 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4091 | } catch (ImsException e) { |
| 4092 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4093 | } finally { |
| 4094 | Binder.restoreCallingIdentity(identity); |
| 4095 | } |
| 4096 | } |
| 4097 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4098 | /** |
| 4099 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4100 | * @param subId The subscription to use to check the configuration. |
| 4101 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4102 | @Override |
| 4103 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4104 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4105 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4106 | final long identity = Binder.clearCallingIdentity(); |
| 4107 | try { |
| 4108 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4109 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4110 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4111 | } catch (ImsException e) { |
| 4112 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4113 | } finally { |
| 4114 | Binder.restoreCallingIdentity(identity); |
| 4115 | } |
| 4116 | } |
| 4117 | |
| 4118 | @Override |
| 4119 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4120 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4121 | "setVoWiFiModeSetting"); |
| 4122 | final long identity = Binder.clearCallingIdentity(); |
| 4123 | try { |
| 4124 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4125 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4126 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4127 | } catch (ImsException e) { |
| 4128 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4129 | } finally { |
| 4130 | Binder.restoreCallingIdentity(identity); |
| 4131 | } |
| 4132 | } |
| 4133 | |
| 4134 | @Override |
| 4135 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4136 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4137 | final long identity = Binder.clearCallingIdentity(); |
| 4138 | try { |
| 4139 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4140 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4141 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4142 | } catch (ImsException e) { |
| 4143 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4144 | } finally { |
| 4145 | Binder.restoreCallingIdentity(identity); |
| 4146 | } |
| 4147 | } |
| 4148 | |
| 4149 | @Override |
| 4150 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4151 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4152 | "setVoWiFiRoamingModeSetting"); |
| 4153 | final long identity = Binder.clearCallingIdentity(); |
| 4154 | try { |
| 4155 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4156 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4157 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4158 | } catch (ImsException e) { |
| 4159 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4160 | } finally { |
| 4161 | Binder.restoreCallingIdentity(identity); |
| 4162 | } |
| 4163 | } |
| 4164 | |
| 4165 | @Override |
| 4166 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4167 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4168 | "setRttCapabilityEnabled"); |
| 4169 | final long identity = Binder.clearCallingIdentity(); |
| 4170 | try { |
| 4171 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4172 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 4173 | } catch (ImsException e) { |
| 4174 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4175 | } finally { |
| 4176 | Binder.restoreCallingIdentity(identity); |
| 4177 | } |
| 4178 | } |
| 4179 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4180 | /** |
| 4181 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4182 | * @param subId The subscription to use to check the configuration. |
| 4183 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4184 | @Override |
| 4185 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4186 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4187 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4188 | final long identity = Binder.clearCallingIdentity(); |
| 4189 | try { |
| 4190 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4191 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4192 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4193 | } catch (ImsException e) { |
| 4194 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4195 | } finally { |
| 4196 | Binder.restoreCallingIdentity(identity); |
| 4197 | } |
| 4198 | } |
| 4199 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4200 | @Override |
| 4201 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4202 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4203 | final long identity = Binder.clearCallingIdentity(); |
| 4204 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4205 | if (!isImsAvailableOnDevice()) { |
| 4206 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4207 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4208 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4209 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4210 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4211 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4212 | } catch (ImsException e) { |
| 4213 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4214 | } finally { |
| 4215 | Binder.restoreCallingIdentity(identity); |
| 4216 | } |
| 4217 | } |
| 4218 | |
| 4219 | @Override |
| 4220 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4221 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4222 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4223 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4224 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4225 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4226 | try { |
| 4227 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4228 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4229 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4230 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4231 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4232 | + "is inactive, ignoring unregister."); |
| 4233 | // If the subscription is no longer active, just return, since the callback will already |
| 4234 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4235 | } finally { |
| 4236 | Binder.restoreCallingIdentity(identity); |
| 4237 | } |
| 4238 | } |
| 4239 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4240 | |
| 4241 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4242 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4243 | message); |
| 4244 | } |
| 4245 | |
| 4246 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4247 | boolean isMmtelCapability) { |
| 4248 | Phone phone = getPhone(subId); |
| 4249 | if (phone == null) { |
| 4250 | loge("phone instance null for subid " + subId); |
| 4251 | return false; |
| 4252 | } |
| 4253 | if (isMmtelCapability) { |
| 4254 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4255 | return false; |
| 4256 | } |
| 4257 | } else { |
| 4258 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4259 | return false; |
| 4260 | } |
| 4261 | } |
| 4262 | return true; |
| 4263 | } |
| 4264 | |
| 4265 | @Override |
| 4266 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4267 | boolean isProvisioned) { |
| 4268 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4269 | |
| 4270 | final long identity = Binder.clearCallingIdentity(); |
| 4271 | try { |
| 4272 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4273 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4274 | return; |
| 4275 | } |
| 4276 | |
| 4277 | // this capability requires provisioning, route to the correct API. |
| 4278 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4279 | switch (capability) { |
| 4280 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4281 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4282 | ims.setEabProvisioned(isProvisioned); |
| 4283 | break; |
| 4284 | default: { |
| 4285 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4286 | + "rcs capability '" + capability + "', which does not require " |
| 4287 | + "provisioning."); |
| 4288 | } |
| 4289 | } |
| 4290 | } finally { |
| 4291 | Binder.restoreCallingIdentity(identity); |
| 4292 | } |
| 4293 | |
| 4294 | } |
| 4295 | |
| 4296 | |
| 4297 | @Override |
| 4298 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4299 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4300 | final long identity = Binder.clearCallingIdentity(); |
| 4301 | try { |
| 4302 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4303 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4304 | return true; |
| 4305 | } |
| 4306 | |
| 4307 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4308 | switch (capability) { |
| 4309 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4310 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4311 | return ims.isEabProvisionedOnDevice(); |
| 4312 | |
| 4313 | default: { |
| 4314 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4315 | + "capability '" + capability + "', which does not require " |
| 4316 | + "provisioning."); |
| 4317 | } |
| 4318 | } |
| 4319 | |
| 4320 | } finally { |
| 4321 | Binder.restoreCallingIdentity(identity); |
| 4322 | } |
| 4323 | } |
| 4324 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4325 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4326 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4327 | boolean isProvisioned) { |
| 4328 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4329 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4330 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4331 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4332 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4333 | final long identity = Binder.clearCallingIdentity(); |
| 4334 | try { |
| 4335 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4336 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4337 | return; |
| 4338 | } |
| 4339 | |
| 4340 | // this capability requires provisioning, route to the correct API. |
| 4341 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4342 | switch (capability) { |
| 4343 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4344 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4345 | ims.setVolteProvisioned(isProvisioned); |
| 4346 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4347 | ims.setWfcProvisioned(isProvisioned); |
| 4348 | } |
| 4349 | break; |
| 4350 | } |
| 4351 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4352 | // There is currently no difference in VT provisioning type. |
| 4353 | ims.setVtProvisioned(isProvisioned); |
| 4354 | break; |
| 4355 | } |
| 4356 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4357 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4358 | // change the capability of the feature instead if needed. |
| 4359 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4360 | == isProvisioned) { |
| 4361 | // No change in provisioning. |
| 4362 | return; |
| 4363 | } |
| 4364 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4365 | try { |
| 4366 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4367 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4368 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4369 | + ", Exception" + e.getMessage()); |
| 4370 | } |
| 4371 | break; |
| 4372 | } |
| 4373 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4374 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4375 | + "MmTel capability '" + capability + "', which does not require " |
| 4376 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4377 | } |
| 4378 | } |
| 4379 | |
| 4380 | } finally { |
| 4381 | Binder.restoreCallingIdentity(identity); |
| 4382 | } |
| 4383 | } |
| 4384 | |
| 4385 | @Override |
| 4386 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4387 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4388 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4389 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4390 | } |
| 4391 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4392 | final long identity = Binder.clearCallingIdentity(); |
| 4393 | try { |
| 4394 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4395 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4396 | return true; |
| 4397 | } |
| 4398 | |
| 4399 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4400 | switch (capability) { |
| 4401 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4402 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4403 | return ims.isVolteProvisionedOnDevice(); |
| 4404 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4405 | return ims.isWfcProvisionedOnDevice(); |
| 4406 | } |
| 4407 | // This should never happen, since we are checking tech above to make sure it |
| 4408 | // is either LTE or IWLAN. |
| 4409 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4410 | + "capability."); |
| 4411 | } |
| 4412 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4413 | // There is currently no difference in VT provisioning type. |
| 4414 | return ims.isVtProvisionedOnDevice(); |
| 4415 | } |
| 4416 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4417 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4418 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4419 | } |
| 4420 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4421 | throw new IllegalArgumentException( |
| 4422 | "Tried to get provisioning for MmTel capability '" + capability |
| 4423 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4424 | } |
| 4425 | } |
| 4426 | |
| 4427 | } finally { |
| 4428 | Binder.restoreCallingIdentity(identity); |
| 4429 | } |
| 4430 | } |
| 4431 | |
| 4432 | @Override |
| 4433 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4434 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4435 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4436 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4437 | } |
| 4438 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4439 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4440 | return (provisionedBits & capability) > 0; |
| 4441 | } |
| 4442 | |
| 4443 | @Override |
| 4444 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4445 | boolean isProvisioned) { |
| 4446 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4447 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4448 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4449 | } |
| 4450 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4451 | "setProvisioningStatusForCapability"); |
| 4452 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4453 | // If the current provisioning status for capability already matches isProvisioned, |
| 4454 | // do nothing. |
| 4455 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4456 | return; |
| 4457 | } |
| 4458 | if (isProvisioned) { |
| 4459 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4460 | } else { |
| 4461 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4462 | } |
| 4463 | } |
| 4464 | |
| 4465 | /** |
| 4466 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4467 | * technology. The bitfield should mirror the bitfield defined by |
| 4468 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4469 | */ |
| 4470 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4471 | String key = getMmTelProvisioningKey(subId, tech); |
| 4472 | // Default is no capabilities are provisioned. |
| 4473 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4474 | } |
| 4475 | |
| 4476 | /** |
| 4477 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4478 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4479 | * technology specified. |
| 4480 | * |
| 4481 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4482 | */ |
| 4483 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4484 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4485 | String key = getMmTelProvisioningKey(subId, tech); |
| 4486 | editor.putInt(key, newField); |
| 4487 | editor.commit(); |
| 4488 | } |
| 4489 | |
| 4490 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4491 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4492 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4493 | } |
| 4494 | |
| 4495 | /** |
| 4496 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4497 | * carrier associated with the subscription id. |
| 4498 | */ |
| 4499 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4500 | int capability) { |
| 4501 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4502 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4503 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4504 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4505 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4506 | false); |
| 4507 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4508 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4509 | |
| 4510 | // First check to make sure that the capability requires provisioning. |
| 4511 | switch (capability) { |
| 4512 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4513 | // intentional fallthrough |
| 4514 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4515 | if (requireVoiceVtProvisioning) { |
| 4516 | // Voice and Video requires provisioning |
| 4517 | return true; |
| 4518 | } |
| 4519 | break; |
| 4520 | } |
| 4521 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4522 | if (requireUtProvisioning) { |
| 4523 | // UT requires provisioning |
| 4524 | return true; |
| 4525 | } |
| 4526 | break; |
| 4527 | } |
| 4528 | } |
| 4529 | return false; |
| 4530 | } |
| 4531 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4532 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4533 | int capability) { |
| 4534 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4535 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4536 | |
| 4537 | boolean requireRcsProvisioning = c.getBoolean( |
| 4538 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4539 | |
| 4540 | // First check to make sure that the capability requires provisioning. |
| 4541 | switch (capability) { |
| 4542 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4543 | // intentional fallthrough |
| 4544 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4545 | if (requireRcsProvisioning) { |
| 4546 | // OPTION or PRESENCE requires provisioning |
| 4547 | return true; |
| 4548 | } |
| 4549 | break; |
| 4550 | } |
| 4551 | } |
| 4552 | return false; |
| 4553 | } |
| 4554 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4555 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4556 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4557 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4558 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4559 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4560 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4561 | final long identity = Binder.clearCallingIdentity(); |
| 4562 | try { |
| 4563 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4564 | int slotId = getSlotIndex(subId); |
| 4565 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4566 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4567 | + subId + "' for key:" + key); |
| 4568 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4569 | } |
| 4570 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4571 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4572 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4573 | + subId + "' for key:" + key); |
| 4574 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4575 | } finally { |
| 4576 | Binder.restoreCallingIdentity(identity); |
| 4577 | } |
| 4578 | } |
| 4579 | |
| 4580 | @Override |
| 4581 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4582 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4583 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4584 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4585 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4586 | final long identity = Binder.clearCallingIdentity(); |
| 4587 | try { |
| 4588 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4589 | int slotId = getSlotIndex(subId); |
| 4590 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4591 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4592 | + subId + "' for key:" + key); |
| 4593 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4594 | } |
| 4595 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4596 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4597 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4598 | + subId + "' for key:" + key); |
| 4599 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4600 | } finally { |
| 4601 | Binder.restoreCallingIdentity(identity); |
| 4602 | } |
| 4603 | } |
| 4604 | |
| 4605 | @Override |
| 4606 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4607 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4608 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4609 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4610 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4611 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4612 | final long identity = Binder.clearCallingIdentity(); |
| 4613 | try { |
| 4614 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4615 | int slotId = getSlotIndex(subId); |
| 4616 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4617 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4618 | + subId + "' for key:" + key); |
| 4619 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4620 | } |
| 4621 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4622 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4623 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4624 | + "' for key:" + key); |
| 4625 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4626 | } finally { |
| 4627 | Binder.restoreCallingIdentity(identity); |
| 4628 | } |
| 4629 | } |
| 4630 | |
| 4631 | @Override |
| 4632 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4633 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4634 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4635 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4636 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4637 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4638 | final long identity = Binder.clearCallingIdentity(); |
| 4639 | try { |
| 4640 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4641 | int slotId = getSlotIndex(subId); |
| 4642 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4643 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4644 | + subId + "' for key:" + key); |
| 4645 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4646 | } |
| 4647 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4648 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4649 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4650 | + "' for key:" + key); |
| 4651 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4652 | } finally { |
| 4653 | Binder.restoreCallingIdentity(identity); |
| 4654 | } |
| 4655 | } |
| 4656 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4657 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4658 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4659 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4660 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4661 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4662 | } |
| 4663 | return slotId; |
| 4664 | } |
| 4665 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4666 | private int getSlotIndex(int subId) { |
| 4667 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4668 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4669 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4670 | } |
| 4671 | return slotId; |
| 4672 | } |
| 4673 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4674 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4675 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4676 | */ |
| 4677 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4678 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4679 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4680 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4681 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4682 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4683 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4684 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4685 | mApp, subId, callingPackage, callingFeatureId, |
| 4686 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4687 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4688 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4689 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4690 | final long identity = Binder.clearCallingIdentity(); |
| 4691 | try { |
| 4692 | final Phone phone = getPhone(subId); |
| 4693 | if (phone != null) { |
| 4694 | return phone.getServiceState().getDataNetworkType(); |
| 4695 | } else { |
| 4696 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4697 | } |
| 4698 | } finally { |
| 4699 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4700 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4701 | } |
| 4702 | |
| 4703 | /** |
| 4704 | * Returns the data network type |
| 4705 | */ |
| 4706 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4707 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4708 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4709 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4710 | } |
| 4711 | |
| 4712 | /** |
| 4713 | * Returns the data network type for a subId |
| 4714 | */ |
| 4715 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4716 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4717 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4718 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4719 | mApp, subId, callingPackage, callingFeatureId, |
| 4720 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4721 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4722 | } |
| 4723 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4724 | final long identity = Binder.clearCallingIdentity(); |
| 4725 | try { |
| 4726 | final Phone phone = getPhone(subId); |
| 4727 | if (phone != null) { |
| 4728 | return phone.getServiceState().getDataNetworkType(); |
| 4729 | } else { |
| 4730 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4731 | } |
| 4732 | } finally { |
| 4733 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4734 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4735 | } |
| 4736 | |
| 4737 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4738 | * Returns the Voice network type for a subId |
| 4739 | */ |
| 4740 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4741 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4742 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4743 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4744 | mApp, subId, callingPackage, callingFeatureId, |
| 4745 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4746 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4747 | } |
| 4748 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4749 | final long identity = Binder.clearCallingIdentity(); |
| 4750 | try { |
| 4751 | final Phone phone = getPhone(subId); |
| 4752 | if (phone != null) { |
| 4753 | return phone.getServiceState().getVoiceNetworkType(); |
| 4754 | } else { |
| 4755 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4756 | } |
| 4757 | } finally { |
| 4758 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4759 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4760 | } |
| 4761 | |
| 4762 | /** |
| 4763 | * @return true if a ICC card is present |
| 4764 | */ |
| 4765 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4766 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4767 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4768 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4769 | } |
| 4770 | |
| 4771 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4772 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4773 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4774 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4775 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4776 | final long identity = Binder.clearCallingIdentity(); |
| 4777 | try { |
| 4778 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4779 | if (phone != null) { |
| 4780 | return phone.getIccCard().hasIccCard(); |
| 4781 | } else { |
| 4782 | return false; |
| 4783 | } |
| 4784 | } finally { |
| 4785 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4786 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4787 | } |
| 4788 | |
| 4789 | /** |
| 4790 | * Return if the current radio is LTE on CDMA. This |
| 4791 | * is a tri-state return value as for a period of time |
| 4792 | * the mode may be unknown. |
| 4793 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4794 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4795 | * @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] | 4796 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4797 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4798 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4799 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4800 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4801 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4802 | } |
| 4803 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4804 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4805 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4806 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4807 | try { |
| 4808 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4809 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4810 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4811 | } |
| 4812 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4813 | final long identity = Binder.clearCallingIdentity(); |
| 4814 | try { |
| 4815 | final Phone phone = getPhone(subId); |
| 4816 | if (phone == null) { |
| 4817 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4818 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4819 | return TelephonyProperties.lte_on_cdma_device() |
| 4820 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4821 | } |
| 4822 | } finally { |
| 4823 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4824 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4825 | } |
| 4826 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4827 | /** |
| 4828 | * {@hide} |
| 4829 | * Returns Default subId, 0 in the case of single standby. |
| 4830 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4831 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4832 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4833 | } |
| 4834 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4835 | private int getSlotForDefaultSubscription() { |
| 4836 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4837 | } |
| 4838 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4839 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4840 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4841 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4842 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4843 | private boolean isActiveSubscription(int subId) { |
| 4844 | return mSubscriptionController.isActiveSubId(subId); |
| 4845 | } |
| 4846 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4847 | /** |
| 4848 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4849 | */ |
| 4850 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4851 | final long identity = Binder.clearCallingIdentity(); |
| 4852 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4853 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4854 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4855 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4856 | } finally { |
| 4857 | Binder.restoreCallingIdentity(identity); |
| 4858 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4859 | } |
| 4860 | |
| 4861 | /** |
| 4862 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4863 | */ |
| 4864 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4865 | final long identity = Binder.clearCallingIdentity(); |
| 4866 | try { |
| 4867 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4868 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4869 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4870 | } finally { |
| 4871 | Binder.restoreCallingIdentity(identity); |
| 4872 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4873 | } |
| 4874 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4875 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4876 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4877 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4878 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4879 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4880 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4881 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4882 | if (phoneId == -1) { |
| 4883 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4884 | + " does not correspond to an active phone"); |
| 4885 | } |
| 4886 | return PhoneFactory.getPhone(phoneId); |
| 4887 | } |
| 4888 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4889 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4890 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4891 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4892 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4893 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4894 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4895 | if (DBG) { |
| 4896 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4897 | } |
| 4898 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4899 | p2); |
| 4900 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4901 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4902 | |
| 4903 | @Override |
| 4904 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4905 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4906 | enforceModifyPermission(); |
| 4907 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4908 | if (DBG) { |
| 4909 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4910 | } |
| 4911 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4912 | callingPackage, aid, p2); |
| 4913 | } |
| 4914 | |
| 4915 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4916 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4917 | final long identity = Binder.clearCallingIdentity(); |
| 4918 | try { |
| 4919 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4920 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4921 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4922 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4923 | if (bestComponent == null |
| 4924 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4925 | loge("The calling package is not allowed to access ISD-R."); |
| 4926 | throw new SecurityException( |
| 4927 | "The calling package is not allowed to access ISD-R."); |
| 4928 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4929 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4930 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4931 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4932 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4933 | null /* workSource */); |
| 4934 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4935 | return response; |
| 4936 | } finally { |
| 4937 | Binder.restoreCallingIdentity(identity); |
| 4938 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4939 | } |
| 4940 | |
| 4941 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4942 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4943 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4944 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4945 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4946 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4947 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4948 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4949 | @Override |
| 4950 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4951 | enforceModifyPermission(); |
| 4952 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4953 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4954 | channel); |
| 4955 | } |
| 4956 | |
| 4957 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4958 | final long identity = Binder.clearCallingIdentity(); |
| 4959 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4960 | if (channel < 0) { |
| 4961 | return false; |
| 4962 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4963 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4964 | null /* workSource */); |
| 4965 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4966 | return success; |
| 4967 | } finally { |
| 4968 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4969 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4970 | } |
| 4971 | |
| 4972 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4973 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4974 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4975 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4976 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4977 | if (DBG) { |
| 4978 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4979 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4980 | + p3 + " data=" + data); |
| 4981 | } |
| 4982 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4983 | command, p1, p2, p3, data); |
| 4984 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4985 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4986 | @Override |
| 4987 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4988 | int command, int p1, int p2, int p3, String data) { |
| 4989 | enforceModifyPermission(); |
| 4990 | if (DBG) { |
| 4991 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4992 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4993 | + p3 + " data=" + data); |
| 4994 | } |
| 4995 | return iccTransmitApduLogicalChannelWithPermission( |
| 4996 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4997 | data); |
| 4998 | } |
| 4999 | |
| 5000 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5001 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5002 | final long identity = Binder.clearCallingIdentity(); |
| 5003 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5004 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5005 | return ""; |
| 5006 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5007 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5008 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5009 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5010 | null /* workSource */); |
| 5011 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5012 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5013 | // Append the returned status code to the end of the response payload. |
| 5014 | String s = Integer.toHexString( |
| 5015 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5016 | if (response.payload != null) { |
| 5017 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5018 | } |
| 5019 | return s; |
| 5020 | } finally { |
| 5021 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5022 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5023 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5024 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5025 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5026 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5027 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5028 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5029 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5030 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5031 | if (DBG) { |
| 5032 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5033 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5034 | } |
| 5035 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5036 | cla, command, p1, p2, p3, data); |
| 5037 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5038 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5039 | @Override |
| 5040 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 5041 | int command, int p1, int p2, int p3, String data) { |
| 5042 | enforceModifyPermission(); |
| 5043 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5044 | if (DBG) { |
| 5045 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 5046 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 5047 | + " data=" + data); |
| 5048 | } |
| 5049 | |
| 5050 | return iccTransmitApduBasicChannelWithPermission( |
| 5051 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 5052 | p2, p3, data); |
| 5053 | } |
| 5054 | |
| 5055 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5056 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5057 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5058 | final long identity = Binder.clearCallingIdentity(); |
| 5059 | try { |
| 5060 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5061 | && TextUtils.equals(ISDR_AID, data)) { |
| 5062 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5063 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5064 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5065 | if (bestComponent == null |
| 5066 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5067 | loge("The calling package is not allowed to select ISD-R."); |
| 5068 | throw new SecurityException( |
| 5069 | "The calling package is not allowed to select ISD-R."); |
| 5070 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5071 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5072 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5073 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5074 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5075 | null /* workSource */); |
| 5076 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5077 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5078 | // Append the returned status code to the end of the response payload. |
| 5079 | String s = Integer.toHexString( |
| 5080 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5081 | if (response.payload != null) { |
| 5082 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5083 | } |
| 5084 | return s; |
| 5085 | } finally { |
| 5086 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5087 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5088 | } |
| 5089 | |
| 5090 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5091 | 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] | 5092 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5093 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5094 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5095 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5096 | final long identity = Binder.clearCallingIdentity(); |
| 5097 | try { |
| 5098 | if (DBG) { |
| 5099 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5100 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5101 | } |
| 5102 | |
| 5103 | IccIoResult response = |
| 5104 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5105 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5106 | subId); |
| 5107 | |
| 5108 | if (DBG) { |
| 5109 | log("Exchange SIM_IO [R]" + response); |
| 5110 | } |
| 5111 | |
| 5112 | byte[] result = null; |
| 5113 | int length = 2; |
| 5114 | if (response.payload != null) { |
| 5115 | length = 2 + response.payload.length; |
| 5116 | result = new byte[length]; |
| 5117 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5118 | } else { |
| 5119 | result = new byte[length]; |
| 5120 | } |
| 5121 | |
| 5122 | result[length - 1] = (byte) response.sw2; |
| 5123 | result[length - 2] = (byte) response.sw1; |
| 5124 | return result; |
| 5125 | } finally { |
| 5126 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5127 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5128 | } |
| 5129 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5130 | /** |
| 5131 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5132 | * on a particular subscription |
| 5133 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5134 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5135 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5136 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5137 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5138 | return null; |
| 5139 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5140 | |
| 5141 | final long identity = Binder.clearCallingIdentity(); |
| 5142 | try { |
| 5143 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5144 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5145 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5146 | return null; |
| 5147 | } |
| 5148 | Object response = sendRequest( |
| 5149 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5150 | if (response instanceof String[]) { |
| 5151 | return (String[]) response; |
| 5152 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5153 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5154 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5155 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5156 | } finally { |
| 5157 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5158 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5159 | } |
| 5160 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5161 | /** |
| 5162 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5163 | * subscription. |
| 5164 | * |
| 5165 | * @param subId the id of the subscription. |
| 5166 | * @param appType the uicc app type, must be USIM or SIM. |
| 5167 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5168 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5169 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5170 | * @return number of fplmns that is successfully written to the SIM. |
| 5171 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5172 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5173 | String callingFeatureId) { |
| 5174 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 5175 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5176 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 5177 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 5178 | } |
| 5179 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5180 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5181 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5182 | } |
| 5183 | if (fplmns == null) { |
| 5184 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5185 | } |
| 5186 | for (String fplmn : fplmns) { |
| 5187 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5188 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5189 | } |
| 5190 | } |
| 5191 | final long identity = Binder.clearCallingIdentity(); |
| 5192 | try { |
| 5193 | Object response = sendRequest( |
| 5194 | CMD_SET_FORBIDDEN_PLMNS, |
| 5195 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5196 | subId); |
| 5197 | return (int) response; |
| 5198 | } finally { |
| 5199 | Binder.restoreCallingIdentity(identity); |
| 5200 | } |
| 5201 | } |
| 5202 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5203 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5204 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5205 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5206 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5207 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5208 | final long identity = Binder.clearCallingIdentity(); |
| 5209 | try { |
| 5210 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5211 | if (response.payload == null) { |
| 5212 | return ""; |
| 5213 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5214 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5215 | // Append the returned status code to the end of the response payload. |
| 5216 | String s = Integer.toHexString( |
| 5217 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5218 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5219 | return s; |
| 5220 | } finally { |
| 5221 | Binder.restoreCallingIdentity(identity); |
| 5222 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5223 | } |
| 5224 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5225 | /** |
| 5226 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5227 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5228 | * |
| 5229 | * @param itemID the ID of the item to read |
| 5230 | * @return the NV item as a String, or null on error. |
| 5231 | */ |
| 5232 | @Override |
| 5233 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5234 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5235 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5236 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5237 | |
| 5238 | final long identity = Binder.clearCallingIdentity(); |
| 5239 | try { |
| 5240 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5241 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5242 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5243 | return value; |
| 5244 | } finally { |
| 5245 | Binder.restoreCallingIdentity(identity); |
| 5246 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5247 | } |
| 5248 | |
| 5249 | /** |
| 5250 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5251 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5252 | * |
| 5253 | * @param itemID the ID of the item to read |
| 5254 | * @param itemValue the value to write, as a String |
| 5255 | * @return true on success; false on any failure |
| 5256 | */ |
| 5257 | @Override |
| 5258 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5259 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5260 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5261 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5262 | |
| 5263 | final long identity = Binder.clearCallingIdentity(); |
| 5264 | try { |
| 5265 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5266 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5267 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5268 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5269 | return success; |
| 5270 | } finally { |
| 5271 | Binder.restoreCallingIdentity(identity); |
| 5272 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5273 | } |
| 5274 | |
| 5275 | /** |
| 5276 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5277 | * Used for device configuration by some CDMA operators. |
| 5278 | * |
| 5279 | * @param preferredRoamingList byte array containing the new PRL |
| 5280 | * @return true on success; false on any failure |
| 5281 | */ |
| 5282 | @Override |
| 5283 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5284 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5285 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5286 | |
| 5287 | final long identity = Binder.clearCallingIdentity(); |
| 5288 | try { |
| 5289 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5290 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5291 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5292 | return success; |
| 5293 | } finally { |
| 5294 | Binder.restoreCallingIdentity(identity); |
| 5295 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5296 | } |
| 5297 | |
| 5298 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5299 | * 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] | 5300 | * Used for device configuration by some CDMA operators. |
| 5301 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5302 | * @param slotIndex - device slot. |
| 5303 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5304 | * @return true on success; false on any failure |
| 5305 | */ |
| 5306 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5307 | public boolean resetModemConfig(int slotIndex) { |
| 5308 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5309 | if (phone != null) { |
| 5310 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5311 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5312 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5313 | final long identity = Binder.clearCallingIdentity(); |
| 5314 | try { |
| 5315 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5316 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5317 | return success; |
| 5318 | } finally { |
| 5319 | Binder.restoreCallingIdentity(identity); |
| 5320 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5321 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5322 | return false; |
| 5323 | } |
| 5324 | |
| 5325 | /** |
| 5326 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5327 | * |
| 5328 | * @param slotIndex - device slot. |
| 5329 | * |
| 5330 | * @return true on success; false on any failure |
| 5331 | */ |
| 5332 | @Override |
| 5333 | public boolean rebootModem(int slotIndex) { |
| 5334 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5335 | if (phone != null) { |
| 5336 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5337 | mApp, phone.getSubId(), "rebootModem"); |
| 5338 | |
| 5339 | final long identity = Binder.clearCallingIdentity(); |
| 5340 | try { |
| 5341 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5342 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5343 | return success; |
| 5344 | } finally { |
| 5345 | Binder.restoreCallingIdentity(identity); |
| 5346 | } |
| 5347 | } |
| 5348 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5349 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5350 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5351 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5352 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5353 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5354 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5355 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5356 | return new String[0]; |
| 5357 | } |
| 5358 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5359 | final long identity = Binder.clearCallingIdentity(); |
| 5360 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5361 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5362 | } finally { |
| 5363 | Binder.restoreCallingIdentity(identity); |
| 5364 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5365 | } |
| 5366 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5367 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5368 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5369 | * {@link #disableIms(int)}. |
| 5370 | * @param slotIndex device slot. |
| 5371 | */ |
| 5372 | public void resetIms(int slotIndex) { |
| 5373 | enforceModifyPermission(); |
| 5374 | |
| 5375 | final long identity = Binder.clearCallingIdentity(); |
| 5376 | try { |
| 5377 | if (mImsResolver == null) { |
| 5378 | // may happen if the does not support IMS. |
| 5379 | return; |
| 5380 | } |
| 5381 | mImsResolver.disableIms(slotIndex); |
| 5382 | mImsResolver.enableIms(slotIndex); |
| 5383 | } finally { |
| 5384 | Binder.restoreCallingIdentity(identity); |
| 5385 | } |
| 5386 | } |
| 5387 | |
| 5388 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5389 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5390 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5391 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5392 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5393 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5394 | |
| 5395 | final long identity = Binder.clearCallingIdentity(); |
| 5396 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5397 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5398 | // may happen if the device does not support IMS. |
| 5399 | return; |
| 5400 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5401 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5402 | } finally { |
| 5403 | Binder.restoreCallingIdentity(identity); |
| 5404 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5405 | } |
| 5406 | |
| 5407 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5408 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5409 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5410 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5411 | public void disableIms(int slotId) { |
| 5412 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5413 | |
| 5414 | final long identity = Binder.clearCallingIdentity(); |
| 5415 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5416 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5417 | // may happen if the device does not support IMS. |
| 5418 | return; |
| 5419 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5420 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5421 | } finally { |
| 5422 | Binder.restoreCallingIdentity(identity); |
| 5423 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5424 | } |
| 5425 | |
| 5426 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5427 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5428 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5429 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5430 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5431 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5432 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5433 | |
| 5434 | final long identity = Binder.clearCallingIdentity(); |
| 5435 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5436 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5437 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5438 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5439 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5440 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5441 | } finally { |
| 5442 | Binder.restoreCallingIdentity(identity); |
| 5443 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5444 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5445 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5446 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5447 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5448 | @Override |
| 5449 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5450 | enforceModifyPermission(); |
| 5451 | |
| 5452 | final long identity = Binder.clearCallingIdentity(); |
| 5453 | try { |
| 5454 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5455 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5456 | } finally { |
| 5457 | Binder.restoreCallingIdentity(identity); |
| 5458 | } |
| 5459 | } |
| 5460 | |
| 5461 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5462 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5463 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5464 | */ |
| 5465 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5466 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5467 | |
| 5468 | final long identity = Binder.clearCallingIdentity(); |
| 5469 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5470 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5471 | // may happen if the device does not support IMS. |
| 5472 | return null; |
| 5473 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5474 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5475 | } finally { |
| 5476 | Binder.restoreCallingIdentity(identity); |
| 5477 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5478 | } |
| 5479 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5480 | /** |
| 5481 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5482 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5483 | */ |
| 5484 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5485 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5486 | |
| 5487 | final long identity = Binder.clearCallingIdentity(); |
| 5488 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5489 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5490 | // may happen if the device does not support IMS. |
| 5491 | return null; |
| 5492 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5493 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5494 | } finally { |
| 5495 | Binder.restoreCallingIdentity(identity); |
| 5496 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5497 | } |
| 5498 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5499 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5500 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5501 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5502 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5503 | * @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] | 5504 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5505 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5506 | * @param packageName The name of the package that the current configuration will be replaced |
| 5507 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5508 | * @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] | 5509 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5510 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5511 | int[] featureTypes, String packageName) { |
| 5512 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5513 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5514 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5515 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5516 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5517 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5518 | final long identity = Binder.clearCallingIdentity(); |
| 5519 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5520 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5521 | // may happen if the device does not support IMS. |
| 5522 | return false; |
| 5523 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5524 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5525 | for (int featureType : featureTypes) { |
| 5526 | featureConfig.put(featureType, packageName); |
| 5527 | } |
| 5528 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5529 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5530 | } finally { |
| 5531 | Binder.restoreCallingIdentity(identity); |
| 5532 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5533 | } |
| 5534 | |
| 5535 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5536 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5537 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5538 | * |
| 5539 | * This should only be used for testing. |
| 5540 | * |
| 5541 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5542 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5543 | */ |
| 5544 | @Override |
| 5545 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5546 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5547 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5548 | "clearCarrierImsServiceOverride"); |
| 5549 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5550 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5551 | "clearCarrierImsServiceOverride"); |
| 5552 | |
| 5553 | final long identity = Binder.clearCallingIdentity(); |
| 5554 | try { |
| 5555 | if (mImsResolver == null) { |
| 5556 | // may happen if the device does not support IMS. |
| 5557 | return false; |
| 5558 | } |
| 5559 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5560 | } finally { |
| 5561 | Binder.restoreCallingIdentity(identity); |
| 5562 | } |
| 5563 | } |
| 5564 | |
| 5565 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5566 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5567 | * |
| 5568 | * @param slotId The slot that the ImsService is associated with. |
| 5569 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5570 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5571 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5572 | * @return the package name of the ImsService configuration. |
| 5573 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5574 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5575 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5576 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5577 | TelephonyPermissions |
| 5578 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5579 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5580 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5581 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5582 | final long identity = Binder.clearCallingIdentity(); |
| 5583 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5584 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5585 | // may happen if the device does not support IMS. |
| 5586 | return ""; |
| 5587 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5588 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5589 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5590 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5591 | } finally { |
| 5592 | Binder.restoreCallingIdentity(identity); |
| 5593 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5594 | } |
| 5595 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5596 | /** |
| 5597 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5598 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5599 | * @param callback A callback with an integer containing the |
| 5600 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5601 | */ |
| 5602 | @Override |
| 5603 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5604 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5605 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5606 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5607 | "IMS not available on device."); |
| 5608 | } |
| 5609 | final long token = Binder.clearCallingIdentity(); |
| 5610 | try { |
| 5611 | int slotId = getSlotIndex(subId); |
| 5612 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5613 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5614 | + subId + "'"); |
| 5615 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5616 | } |
| 5617 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5618 | try { |
| 5619 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5620 | } catch (RemoteException e) { |
| 5621 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5622 | + "Ignore"); |
| 5623 | } |
| 5624 | }); |
| 5625 | } finally { |
| 5626 | Binder.restoreCallingIdentity(token); |
| 5627 | } |
| 5628 | } |
| 5629 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5630 | /** |
| 5631 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5632 | */ |
| 5633 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5634 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5635 | |
| 5636 | final long identity = Binder.clearCallingIdentity(); |
| 5637 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5638 | // NOTE: Before S, this method only set the default phone. |
| 5639 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5640 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5641 | phone.setImsRegistrationState(registered); |
| 5642 | } |
| 5643 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5644 | } finally { |
| 5645 | Binder.restoreCallingIdentity(identity); |
| 5646 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5647 | } |
| 5648 | |
| 5649 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5650 | * Set the network selection mode to automatic. |
| 5651 | * |
| 5652 | */ |
| 5653 | @Override |
| 5654 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5655 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5656 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5657 | |
| 5658 | final long identity = Binder.clearCallingIdentity(); |
| 5659 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5660 | if (!isActiveSubscription(subId)) { |
| 5661 | return; |
| 5662 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5663 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5664 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5665 | } finally { |
| 5666 | Binder.restoreCallingIdentity(identity); |
| 5667 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5668 | } |
| 5669 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5670 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5671 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5672 | * |
| 5673 | * @param subId the id of the subscription. |
| 5674 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5675 | * the operator to attach to. |
| 5676 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5677 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5678 | * normal network selection next time. |
| 5679 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5680 | */ |
| 5681 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5682 | public boolean setNetworkSelectionModeManual( |
| 5683 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5684 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5685 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5686 | |
| 5687 | if (!isActiveSubscription(subId)) { |
| 5688 | return false; |
| 5689 | } |
| 5690 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5691 | final long identity = Binder.clearCallingIdentity(); |
| 5692 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5693 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5694 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5695 | if (DBG) { |
| 5696 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5697 | + " operator: " + operatorInfo); |
| 5698 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5699 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5700 | } finally { |
| 5701 | Binder.restoreCallingIdentity(identity); |
| 5702 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5703 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5704 | /** |
| 5705 | * Get the manual network selection |
| 5706 | * |
| 5707 | * @param subId the id of the subscription. |
| 5708 | * |
| 5709 | * @return the previously saved user selected PLMN |
| 5710 | */ |
| 5711 | @Override |
| 5712 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5713 | TelephonyPermissions |
| 5714 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5715 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5716 | |
| 5717 | final long identity = Binder.clearCallingIdentity(); |
| 5718 | try { |
| 5719 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5720 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5721 | } |
| 5722 | |
| 5723 | final Phone phone = getPhone(subId); |
| 5724 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5725 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5726 | } |
| 5727 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5728 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5729 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5730 | } finally { |
| 5731 | Binder.restoreCallingIdentity(identity); |
| 5732 | } |
| 5733 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5734 | |
| 5735 | /** |
| 5736 | * Scans for available networks. |
| 5737 | */ |
| 5738 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5739 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5740 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5741 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5742 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5743 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5744 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5745 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5746 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5747 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5748 | .setCallingPid(Binder.getCallingPid()) |
| 5749 | .setCallingUid(Binder.getCallingUid()) |
| 5750 | .setMethod("getCellNetworkScanResults") |
| 5751 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 5752 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5753 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5754 | .build()); |
| 5755 | switch (locationResult) { |
| 5756 | case DENIED_HARD: |
| 5757 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5758 | case DENIED_SOFT: |
| 5759 | return null; |
| 5760 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5761 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5762 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5763 | try { |
| 5764 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5765 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5766 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5767 | } finally { |
| 5768 | Binder.restoreCallingIdentity(identity); |
| 5769 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5770 | } |
| 5771 | |
| 5772 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5773 | * Get the call forwarding info, given the call forwarding reason. |
| 5774 | */ |
| 5775 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5776 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5777 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5778 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5779 | long identity = Binder.clearCallingIdentity(); |
| 5780 | try { |
| 5781 | if (DBG) { |
| 5782 | log("getCallForwarding: subId " + subId |
| 5783 | + " callForwardingReason" + callForwardingReason); |
| 5784 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5785 | |
| 5786 | Phone phone = getPhone(subId); |
| 5787 | if (phone == null) { |
| 5788 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5789 | callback.onError( |
| 5790 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5791 | } catch (RemoteException e) { |
| 5792 | // ignore |
| 5793 | } |
| 5794 | return; |
| 5795 | } |
| 5796 | |
| 5797 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 5798 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 5799 | @Override |
| 5800 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 5801 | try { |
| 5802 | callback.onCallForwardingInfoAvailable(info); |
| 5803 | } catch (RemoteException e) { |
| 5804 | // ignore |
| 5805 | } |
| 5806 | } |
| 5807 | |
| 5808 | @Override |
| 5809 | public void onError(int error) { |
| 5810 | try { |
| 5811 | callback.onError(error); |
| 5812 | } catch (RemoteException e) { |
| 5813 | // ignore |
| 5814 | } |
| 5815 | } |
| 5816 | }); |
| 5817 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5818 | } finally { |
| 5819 | Binder.restoreCallingIdentity(identity); |
| 5820 | } |
| 5821 | } |
| 5822 | |
| 5823 | /** |
| 5824 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5825 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5826 | */ |
| 5827 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5828 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 5829 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5830 | enforceModifyPermission(); |
| 5831 | long identity = Binder.clearCallingIdentity(); |
| 5832 | try { |
| 5833 | if (DBG) { |
| 5834 | log("setCallForwarding: subId " + subId |
| 5835 | + " callForwardingInfo" + callForwardingInfo); |
| 5836 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5837 | |
| 5838 | Phone phone = getPhone(subId); |
| 5839 | if (phone == null) { |
| 5840 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5841 | callback.accept( |
| 5842 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5843 | } catch (RemoteException e) { |
| 5844 | // ignore |
| 5845 | } |
| 5846 | return; |
| 5847 | } |
| 5848 | |
| 5849 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 5850 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5851 | |
| 5852 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5853 | } finally { |
| 5854 | Binder.restoreCallingIdentity(identity); |
| 5855 | } |
| 5856 | } |
| 5857 | |
| 5858 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5859 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5860 | */ |
| 5861 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5862 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5863 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5864 | long identity = Binder.clearCallingIdentity(); |
| 5865 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5866 | |
| 5867 | Phone phone = getPhone(subId); |
| 5868 | if (phone == null) { |
| 5869 | try { |
| 5870 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5871 | } catch (RemoteException e) { |
| 5872 | // ignore |
| 5873 | } |
| 5874 | return; |
| 5875 | } |
| 5876 | |
| 5877 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 5878 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5879 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5880 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5881 | } finally { |
| 5882 | Binder.restoreCallingIdentity(identity); |
| 5883 | } |
| 5884 | } |
| 5885 | |
| 5886 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5887 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5888 | */ |
| 5889 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5890 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5891 | enforceModifyPermission(); |
| 5892 | long identity = Binder.clearCallingIdentity(); |
| 5893 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5894 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 5895 | |
| 5896 | Phone phone = getPhone(subId); |
| 5897 | if (phone == null) { |
| 5898 | try { |
| 5899 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5900 | } catch (RemoteException e) { |
| 5901 | // ignore |
| 5902 | } |
| 5903 | return; |
| 5904 | } |
| 5905 | |
| 5906 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 5907 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5908 | |
| 5909 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5910 | } finally { |
| 5911 | Binder.restoreCallingIdentity(identity); |
| 5912 | } |
| 5913 | } |
| 5914 | |
| 5915 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5916 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5917 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5918 | * @param subId id of the subscription |
| 5919 | * @param request contains the radio access networks with bands/channels to scan |
| 5920 | * @param messenger callback messenger for scan results or errors |
| 5921 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5922 | * @return the id of the requested scan which can be used to stop the scan. |
| 5923 | */ |
| 5924 | @Override |
| 5925 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5926 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5927 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5928 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5929 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5930 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5931 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5932 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5933 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5934 | .setCallingPid(Binder.getCallingPid()) |
| 5935 | .setCallingUid(Binder.getCallingUid()) |
| 5936 | .setMethod("requestNetworkScan") |
| 5937 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
James.cf Lin | 1d4d739 | 2020-07-03 18:22:53 +0800 | [diff] [blame] | 5938 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5939 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5940 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5941 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5942 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 5943 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5944 | if (e != null) { |
| 5945 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5946 | throw e; |
| 5947 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5948 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5949 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5950 | } |
| 5951 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5952 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5953 | int callingUid = Binder.getCallingUid(); |
| 5954 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5955 | final long identity = Binder.clearCallingIdentity(); |
| 5956 | try { |
| 5957 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5958 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5959 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5960 | } finally { |
| 5961 | Binder.restoreCallingIdentity(identity); |
| 5962 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5963 | } |
| 5964 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5965 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5966 | NetworkScanRequest request, int subId, String callingPackage) { |
| 5967 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5968 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5969 | boolean hasNetworkScanPermission = |
| 5970 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5971 | == PERMISSION_GRANTED; |
| 5972 | |
| 5973 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5974 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5975 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5976 | } |
| 5977 | |
| 5978 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5979 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5980 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5981 | return new SecurityException("Specific channels must not be" |
| 5982 | + " scanned without location access."); |
| 5983 | } |
| 5984 | } |
| 5985 | } |
| 5986 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5987 | return null; |
| 5988 | } |
| 5989 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5990 | /** |
| 5991 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5992 | * |
| 5993 | * @param subId id of the subscription |
| 5994 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5995 | */ |
| 5996 | @Override |
| 5997 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5998 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5999 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6000 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6001 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6002 | final long identity = Binder.clearCallingIdentity(); |
| 6003 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6004 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6005 | } finally { |
| 6006 | Binder.restoreCallingIdentity(identity); |
| 6007 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6008 | } |
| 6009 | |
| 6010 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6011 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6012 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6013 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6014 | */ |
| 6015 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6016 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6017 | TelephonyPermissions |
| 6018 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6019 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6020 | |
| 6021 | final long identity = Binder.clearCallingIdentity(); |
| 6022 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6023 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6024 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6025 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6026 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6027 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6028 | } finally { |
| 6029 | Binder.restoreCallingIdentity(identity); |
| 6030 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6031 | } |
| 6032 | |
| 6033 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6034 | * Get the allowed network types for certain reason. |
| 6035 | * |
| 6036 | * @param subId the id of the subscription. |
| 6037 | * @param reason the reason the allowed network type change is taking place |
| 6038 | * @return the allowed network types. |
| 6039 | */ |
| 6040 | @Override |
| 6041 | public long getAllowedNetworkTypesForReason(int subId, |
| 6042 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
| 6043 | TelephonyPermissions |
| 6044 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6045 | mApp, subId, "getAllowedNetworkTypesForReason"); |
| 6046 | final long identity = Binder.clearCallingIdentity(); |
| 6047 | try { |
| 6048 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6049 | } finally { |
| 6050 | Binder.restoreCallingIdentity(identity); |
| 6051 | } |
| 6052 | } |
| 6053 | |
| 6054 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6055 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6056 | * @param subId subscription id of the sim card |
| 6057 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6058 | * This can be passed following states |
| 6059 | * <ol> |
| 6060 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6061 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6062 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6063 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6064 | * </ol> |
| 6065 | * @return operation result. |
| 6066 | */ |
| 6067 | @Override |
| 6068 | public int setNrDualConnectivityState(int subId, |
| 6069 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6070 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6071 | mApp, subId, "enableNRDualConnectivity"); |
| 6072 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6073 | final long identity = Binder.clearCallingIdentity(); |
| 6074 | try { |
| 6075 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6076 | nrDualConnectivityState, subId, |
| 6077 | workSource); |
| 6078 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6079 | return result; |
| 6080 | } finally { |
| 6081 | Binder.restoreCallingIdentity(identity); |
| 6082 | } |
| 6083 | } |
| 6084 | |
| 6085 | /** |
| 6086 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6087 | * @return true if dual connectivity is enabled else false |
| 6088 | */ |
| 6089 | @Override |
| 6090 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6091 | TelephonyPermissions |
| 6092 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6093 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6094 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6095 | final long identity = Binder.clearCallingIdentity(); |
| 6096 | try { |
| 6097 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6098 | null, subId, workSource); |
| 6099 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6100 | return isEnabled; |
| 6101 | } finally { |
| 6102 | Binder.restoreCallingIdentity(identity); |
| 6103 | } |
| 6104 | } |
| 6105 | |
| 6106 | /** |
Sooraj Sasindran | 4deb887 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 6107 | * get carrier bandwidth per primary and secondary carrier |
| 6108 | * @param subId subscription id of the sim card |
| 6109 | * @return CarrierBandwidth with bandwidth of both primary and secondary carrier.. |
| 6110 | */ |
| 6111 | @Override |
| 6112 | public CarrierBandwidth getCarrierBandwidth(int subId) { |
| 6113 | TelephonyPermissions |
| 6114 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6115 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6116 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6117 | final long identity = Binder.clearCallingIdentity(); |
| 6118 | try { |
| 6119 | CarrierBandwidth carrierBandwidth = |
| 6120 | getPhoneFromSubId(subId).getCarrierBandwidth(); |
| 6121 | if (DBG) log("getCarrierBandwidth: " + carrierBandwidth); |
| 6122 | return carrierBandwidth; |
| 6123 | } finally { |
| 6124 | Binder.restoreCallingIdentity(identity); |
| 6125 | } |
| 6126 | } |
| 6127 | |
| 6128 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6129 | * Set the allowed network types of the device and |
| 6130 | * provide the reason triggering the allowed network change. |
| 6131 | * |
| 6132 | * @param subId the id of the subscription. |
| 6133 | * @param reason the reason the allowed network type change is taking place |
| 6134 | * @param allowedNetworkTypes the allowed network types. |
| 6135 | * @return true on success; false on any failure. |
| 6136 | */ |
| 6137 | @Override |
| 6138 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6139 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6140 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6141 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6142 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6143 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
| 6144 | Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason); |
| 6145 | return false; |
| 6146 | } |
| 6147 | |
| 6148 | if (DBG) { |
| 6149 | log("setAllowedNetworkTypesForReason: " + reason |
| 6150 | + " value: " + allowedNetworkTypes); |
| 6151 | } |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6152 | final long identity = Binder.clearCallingIdentity(); |
| 6153 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6154 | Boolean success = (Boolean) sendRequest( |
| 6155 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6156 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6157 | |
| 6158 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6159 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6160 | } finally { |
| 6161 | Binder.restoreCallingIdentity(identity); |
| 6162 | } |
| 6163 | } |
| 6164 | |
| 6165 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6166 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6167 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6168 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6169 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6170 | * @hide |
| 6171 | */ |
| 6172 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6173 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6174 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6175 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6176 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6177 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6178 | if (phone != null) { |
| 6179 | return phone.hasMatchedTetherApnSetting(); |
| 6180 | } else { |
| 6181 | return false; |
| 6182 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6183 | } finally { |
| 6184 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6185 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6186 | } |
| 6187 | |
| 6188 | /** |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6189 | * Enable or disable always reporting signal strength changes from radio. |
| 6190 | * |
| 6191 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6192 | */ |
| 6193 | @Override |
| 6194 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6195 | enforceModifyPermission(); |
| 6196 | enforceSystemCaller(); |
| 6197 | |
| 6198 | final long identity = Binder.clearCallingIdentity(); |
| 6199 | final Phone phone = getPhone(subId); |
| 6200 | try { |
| 6201 | if (phone != null) { |
| 6202 | if (DBG) { |
| 6203 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6204 | + " isEnable=" + isEnable); |
| 6205 | } |
| 6206 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6207 | } else { |
| 6208 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6209 | + subId); |
| 6210 | } |
| 6211 | } finally { |
| 6212 | Binder.restoreCallingIdentity(identity); |
| 6213 | } |
| 6214 | } |
| 6215 | |
| 6216 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6217 | * Get the user enabled state of Mobile Data. |
| 6218 | * |
| 6219 | * TODO: remove and use isUserDataEnabled. |
| 6220 | * This can't be removed now because some vendor codes |
| 6221 | * calls through ITelephony directly while they should |
| 6222 | * use TelephonyManager. |
| 6223 | * |
| 6224 | * @return true on enabled |
| 6225 | */ |
| 6226 | @Override |
| 6227 | public boolean getDataEnabled(int subId) { |
| 6228 | return isUserDataEnabled(subId); |
| 6229 | } |
| 6230 | |
| 6231 | /** |
| 6232 | * Get whether mobile data is enabled per user setting. |
| 6233 | * |
| 6234 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6235 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6236 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6237 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6238 | * |
| 6239 | * @return {@code true} if data is enabled else {@code false} |
| 6240 | */ |
| 6241 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6242 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6243 | try { |
| 6244 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6245 | null); |
| 6246 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6247 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6248 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6249 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6250 | |
| 6251 | final long identity = Binder.clearCallingIdentity(); |
| 6252 | try { |
| 6253 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6254 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6255 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6256 | if (phone != null) { |
| 6257 | boolean retVal = phone.isUserDataEnabled(); |
| 6258 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6259 | return retVal; |
| 6260 | } else { |
| 6261 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6262 | return false; |
| 6263 | } |
| 6264 | } finally { |
| 6265 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6266 | } |
| 6267 | } |
| 6268 | |
| 6269 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6270 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6271 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6272 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6273 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6274 | * @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] | 6275 | */ |
| 6276 | @Override |
| 6277 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6278 | try { |
| 6279 | try { |
| 6280 | mApp.enforceCallingOrSelfPermission( |
| 6281 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6282 | null); |
| 6283 | } catch (Exception e) { |
| 6284 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6285 | "isDataEnabled"); |
| 6286 | } |
| 6287 | } catch (Exception e) { |
| 6288 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6289 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6290 | |
| 6291 | final long identity = Binder.clearCallingIdentity(); |
| 6292 | try { |
| 6293 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6294 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6295 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6296 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6297 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6298 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6299 | return retVal; |
| 6300 | } else { |
| 6301 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6302 | return false; |
| 6303 | } |
| 6304 | } finally { |
| 6305 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6306 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6307 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6308 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6309 | /** |
| 6310 | * Check if data is enabled for a specific reason |
| 6311 | * @param subId Subscription index |
| 6312 | * @param reason the reason the data enable change is taking place |
| 6313 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6314 | */ |
| 6315 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6316 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6317 | @TelephonyManager.DataEnabledReason int reason) { |
| 6318 | try { |
| 6319 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6320 | null); |
| 6321 | } catch (Exception e) { |
| 6322 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6323 | "isDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6324 | } |
| 6325 | |
| 6326 | |
| 6327 | final long identity = Binder.clearCallingIdentity(); |
| 6328 | try { |
| 6329 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6330 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6331 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6332 | + " reason=" + reason); |
| 6333 | } |
| 6334 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6335 | if (phone != null) { |
| 6336 | boolean retVal; |
| 6337 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6338 | retVal = phone.isUserDataEnabled(); |
| 6339 | } else { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6340 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6341 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6342 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6343 | return retVal; |
| 6344 | } else { |
| 6345 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6346 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6347 | + subId + " retVal=false"); |
| 6348 | } |
| 6349 | return false; |
| 6350 | } |
| 6351 | } finally { |
| 6352 | Binder.restoreCallingIdentity(identity); |
| 6353 | } |
| 6354 | } |
| 6355 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6356 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6357 | Phone phone) { |
Hall Liu | 54a2a0c | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6358 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 6359 | // Skip the check if it's one of these special uids |
| 6360 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6361 | } |
| 6362 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6363 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6364 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6365 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6366 | || subController == null) return privilegeFromSim; |
| 6367 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6368 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6369 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6370 | |
| 6371 | final long identity = Binder.clearCallingIdentity(); |
| 6372 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6373 | int subId = phone.getSubId(); |
| 6374 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6375 | // A test override is in place for the privileges for this subId, so don't try to |
| 6376 | // read the subscription privileges. |
| 6377 | return privilegeFromSim; |
| 6378 | } |
| 6379 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6380 | SubscriptionManager subManager = (SubscriptionManager) |
| 6381 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6382 | for (String pkg : packages) { |
| 6383 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6384 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6385 | } |
| 6386 | } |
| 6387 | return privilegeFromSim; |
| 6388 | } finally { |
| 6389 | Binder.restoreCallingIdentity(identity); |
| 6390 | } |
| 6391 | } |
| 6392 | |
| 6393 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6394 | String pkgName) { |
| 6395 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6396 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6397 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6398 | || subController == null) return privilegeFromSim; |
| 6399 | |
| 6400 | final long identity = Binder.clearCallingIdentity(); |
| 6401 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6402 | int subId = phone.getSubId(); |
| 6403 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6404 | // A test override is in place for the privileges for this subId, so don't try to |
| 6405 | // read the subscription privileges. |
| 6406 | return privilegeFromSim; |
| 6407 | } |
| 6408 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6409 | SubscriptionManager subManager = (SubscriptionManager) |
| 6410 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6411 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6412 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6413 | } finally { |
| 6414 | Binder.restoreCallingIdentity(identity); |
| 6415 | } |
| 6416 | } |
| 6417 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6418 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6419 | public int getCarrierPrivilegeStatus(int subId) { |
| 6420 | final Phone phone = getPhone(subId); |
| 6421 | if (phone == null) { |
| 6422 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6423 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6424 | } |
| 6425 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6426 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6427 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6428 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6429 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6430 | |
| 6431 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6432 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6433 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6434 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6435 | |
| 6436 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6437 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6438 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6439 | final Phone phone = getPhone(subId); |
| 6440 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6441 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6442 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6443 | } |
| 6444 | UiccProfile profile = |
| 6445 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6446 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6447 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6448 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6449 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6450 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6451 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6452 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6453 | } |
| 6454 | |
| 6455 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6456 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6457 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6458 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6459 | } |
| 6460 | |
| 6461 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6462 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6463 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6464 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6465 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6466 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6467 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6468 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6469 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6470 | } |
| 6471 | |
| 6472 | @Override |
| 6473 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6474 | if (TextUtils.isEmpty(pkgName)) |
| 6475 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6476 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6477 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6478 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6479 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6480 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6481 | continue; |
| 6482 | } |
| 6483 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6484 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6485 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6486 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6487 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6488 | break; |
| 6489 | } |
| 6490 | } |
| 6491 | |
| 6492 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6493 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6494 | |
| 6495 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6496 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6497 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6498 | loge("phoneId " + phoneId + " is not valid."); |
| 6499 | return null; |
| 6500 | } |
| 6501 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6502 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6503 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6504 | return null ; |
| 6505 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6506 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6507 | } |
| 6508 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6509 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6510 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6511 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6512 | List<String> privilegedPackages = new ArrayList<>(); |
| 6513 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6514 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6515 | // has UICC in that slot. |
| 6516 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6517 | if (card.hasCarrierPrivilegeRules()) { |
| 6518 | if (packages == null) { |
| 6519 | // Only check packages in user 0 for now |
| 6520 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6521 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6522 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6523 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6524 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6525 | } |
| 6526 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6527 | PackageInfo pkgInfo = packages.get(p); |
| 6528 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6529 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6530 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6531 | privilegedPackages.add(pkgInfo.packageName); |
| 6532 | } |
| 6533 | } |
| 6534 | } |
| 6535 | } |
| 6536 | return privilegedPackages; |
| 6537 | } |
| 6538 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6539 | @Override |
| 6540 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6541 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6542 | |
| 6543 | final long identity = Binder.clearCallingIdentity(); |
| 6544 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6545 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6546 | try { |
| 6547 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6548 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6549 | } |
| 6550 | } finally { |
| 6551 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6552 | } |
| 6553 | return privilegedPackages; |
| 6554 | } |
| 6555 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6556 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6557 | final Phone phone = getPhone(subId); |
| 6558 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6559 | if (card == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6560 | return null; |
| 6561 | } |
| 6562 | String iccId = card.getIccId(); |
| 6563 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6564 | return null; |
| 6565 | } |
| 6566 | return iccId; |
| 6567 | } |
| 6568 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6569 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6570 | public void setCallComposerStatus(int subId, int status) { |
| 6571 | enforceModifyPermission(); |
| 6572 | |
| 6573 | final long identity = Binder.clearCallingIdentity(); |
| 6574 | try { |
| 6575 | Phone phone = getPhone(subId); |
| 6576 | if (phone != null) { |
| 6577 | Phone defaultPhone = phone.getImsPhone(); |
| 6578 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6579 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6580 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6581 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6582 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6583 | } |
| 6584 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6585 | } catch (ImsException e) { |
| 6586 | throw new ServiceSpecificException(e.getCode()); |
| 6587 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6588 | Binder.restoreCallingIdentity(identity); |
| 6589 | } |
| 6590 | } |
| 6591 | |
| 6592 | @Override |
| 6593 | public int getCallComposerStatus(int subId) { |
| 6594 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6595 | |
| 6596 | final long identity = Binder.clearCallingIdentity(); |
| 6597 | try { |
| 6598 | Phone phone = getPhone(subId); |
| 6599 | if (phone != null) { |
| 6600 | Phone defaultPhone = phone.getImsPhone(); |
| 6601 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6602 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6603 | return imsPhone.getCallComposerStatus(); |
| 6604 | } |
| 6605 | } |
| 6606 | } finally { |
| 6607 | Binder.restoreCallingIdentity(identity); |
| 6608 | } |
| 6609 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6610 | } |
| 6611 | |
| 6612 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6613 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6614 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6615 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6616 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6617 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6618 | final long identity = Binder.clearCallingIdentity(); |
| 6619 | try { |
| 6620 | final String iccId = getIccId(subId); |
| 6621 | final Phone phone = getPhone(subId); |
| 6622 | if (phone == null) { |
| 6623 | return false; |
| 6624 | } |
| 6625 | final String subscriberId = phone.getSubscriberId(); |
| 6626 | |
| 6627 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6628 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6629 | + subscriberId + " to " + number); |
| 6630 | } |
| 6631 | |
| 6632 | if (TextUtils.isEmpty(iccId)) { |
| 6633 | return false; |
| 6634 | } |
| 6635 | |
| 6636 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6637 | |
| 6638 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6639 | if (alphaTag == null) { |
| 6640 | editor.remove(alphaTagPrefKey); |
| 6641 | } else { |
| 6642 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6643 | } |
| 6644 | |
| 6645 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6646 | // track all merged IMSIs based on line number |
| 6647 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6648 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6649 | if (number == null) { |
| 6650 | editor.remove(numberPrefKey); |
| 6651 | editor.remove(subscriberPrefKey); |
| 6652 | } else { |
| 6653 | editor.putString(numberPrefKey, number); |
| 6654 | editor.putString(subscriberPrefKey, subscriberId); |
| 6655 | } |
| 6656 | |
| 6657 | editor.commit(); |
| 6658 | return true; |
| 6659 | } finally { |
| 6660 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6661 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6662 | } |
| 6663 | |
| 6664 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6665 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6666 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6667 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6668 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6669 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6670 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6671 | return null; |
| 6672 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6673 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6674 | final long identity = Binder.clearCallingIdentity(); |
| 6675 | try { |
| 6676 | String iccId = getIccId(subId); |
| 6677 | if (iccId != null) { |
| 6678 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6679 | if (DBG_MERGE) { |
| 6680 | log("getLine1NumberForDisplay returning " |
| 6681 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6682 | } |
| 6683 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6684 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6685 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6686 | return null; |
| 6687 | } finally { |
| 6688 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6689 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6690 | } |
| 6691 | |
| 6692 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6693 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6694 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6695 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6696 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6697 | return null; |
| 6698 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6699 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6700 | final long identity = Binder.clearCallingIdentity(); |
| 6701 | try { |
| 6702 | String iccId = getIccId(subId); |
| 6703 | if (iccId != null) { |
| 6704 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6705 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6706 | } |
| 6707 | return null; |
| 6708 | } finally { |
| 6709 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6710 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6711 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6712 | |
| 6713 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6714 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6715 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6716 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6717 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6718 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6719 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6720 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6721 | return null; |
| 6722 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6723 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6724 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6725 | // the process, where TelephonyManager was instantiated. |
| 6726 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6727 | final long identity = Binder.clearCallingIdentity(); |
| 6728 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6729 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6730 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6731 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6732 | |
| 6733 | // Figure out what subscribers are currently active |
| 6734 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6735 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6736 | // Only consider subs which match the current subId |
| 6737 | // This logic can be simplified. See b/131189269 for progress. |
| 6738 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6739 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6740 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6741 | |
| 6742 | // First pass, find a number override for an active subscriber |
| 6743 | String mergeNumber = null; |
| 6744 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6745 | for (String key : prefs.keySet()) { |
| 6746 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6747 | final String subscriberId = (String) prefs.get(key); |
| 6748 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6749 | final String iccId = key.substring( |
| 6750 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6751 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6752 | mergeNumber = (String) prefs.get(numberKey); |
| 6753 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6754 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6755 | + " for active subscriber " + subscriberId); |
| 6756 | } |
| 6757 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6758 | break; |
| 6759 | } |
| 6760 | } |
| 6761 | } |
| 6762 | } |
| 6763 | |
| 6764 | // Shortcut when no active merged subscribers |
| 6765 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6766 | return null; |
| 6767 | } |
| 6768 | |
| 6769 | // Second pass, find all subscribers under that line override |
| 6770 | final ArraySet<String> result = new ArraySet<>(); |
| 6771 | for (String key : prefs.keySet()) { |
| 6772 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6773 | final String number = (String) prefs.get(key); |
| 6774 | if (mergeNumber.equals(number)) { |
| 6775 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6776 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6777 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6778 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6779 | result.add(subscriberId); |
| 6780 | } |
| 6781 | } |
| 6782 | } |
| 6783 | } |
| 6784 | |
| 6785 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6786 | Arrays.sort(resultArray); |
| 6787 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6788 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6789 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6790 | } |
| 6791 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6792 | } finally { |
| 6793 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6794 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6795 | } |
| 6796 | |
| 6797 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6798 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6799 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6800 | |
| 6801 | final long identity = Binder.clearCallingIdentity(); |
| 6802 | try { |
| 6803 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6804 | TelephonyManager.class); |
| 6805 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6806 | if (subscriberId == null) { |
| 6807 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6808 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6809 | + subId); |
| 6810 | } |
| 6811 | return null; |
| 6812 | } |
| 6813 | |
| 6814 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6815 | .getSubscriptionInfo(subId); |
| 6816 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6817 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6818 | if (groupUuid == null) { |
| 6819 | return new String[]{subscriberId}; |
| 6820 | } |
| 6821 | |
| 6822 | // Get all subscriberIds from the group. |
| 6823 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6824 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6825 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6826 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6827 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6828 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6829 | if (subscriberId != null) { |
| 6830 | mergedSubscriberIds.add(subscriberId); |
| 6831 | } |
| 6832 | } |
| 6833 | |
| 6834 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6835 | } finally { |
| 6836 | Binder.restoreCallingIdentity(identity); |
| 6837 | |
| 6838 | } |
| 6839 | } |
| 6840 | |
| 6841 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6842 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6843 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6844 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6845 | |
| 6846 | final long identity = Binder.clearCallingIdentity(); |
| 6847 | try { |
| 6848 | final Phone phone = getPhone(subId); |
| 6849 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6850 | } finally { |
| 6851 | Binder.restoreCallingIdentity(identity); |
| 6852 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6853 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6854 | |
| 6855 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6856 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6857 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6858 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6859 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6860 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6861 | |
| 6862 | final long identity = Binder.clearCallingIdentity(); |
| 6863 | try { |
| 6864 | final Phone phone = getPhone(subId); |
| 6865 | if (phone == null) { |
| 6866 | return false; |
| 6867 | } |
| 6868 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6869 | cdmaNonRoamingList); |
| 6870 | } finally { |
| 6871 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6872 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6873 | } |
| 6874 | |
| 6875 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6876 | @Deprecated |
| 6877 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6878 | enforceModifyPermission(); |
| 6879 | |
| 6880 | int returnValue = 0; |
| 6881 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6882 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6883 | if(result.exception == null) { |
| 6884 | if (result.result != null) { |
| 6885 | byte[] responseData = (byte[])(result.result); |
| 6886 | if(responseData.length > oemResp.length) { |
| 6887 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6888 | responseData.length + "bytes. Buffer Size is " + |
| 6889 | oemResp.length + "bytes."); |
| 6890 | } |
| 6891 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6892 | returnValue = responseData.length; |
| 6893 | } |
| 6894 | } else { |
| 6895 | CommandException ex = (CommandException) result.exception; |
| 6896 | returnValue = ex.getCommandError().ordinal(); |
| 6897 | if(returnValue > 0) returnValue *= -1; |
| 6898 | } |
| 6899 | } catch (RuntimeException e) { |
| 6900 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6901 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6902 | if(returnValue > 0) returnValue *= -1; |
| 6903 | } |
| 6904 | |
| 6905 | return returnValue; |
| 6906 | } |
| 6907 | |
| 6908 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6909 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6910 | try { |
| 6911 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6912 | } catch (RuntimeException e) { |
| 6913 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6914 | } |
| 6915 | } |
| 6916 | |
| 6917 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6918 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6919 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 6920 | try { |
| 6921 | TelephonyPermissions |
| 6922 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6923 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6924 | } catch (SecurityException e) { |
| 6925 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 6926 | throw e; |
| 6927 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6928 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6929 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6930 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6931 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6932 | final long identity = Binder.clearCallingIdentity(); |
| 6933 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6934 | TelephonyPermissions |
| 6935 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6936 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6937 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6938 | } finally { |
| 6939 | Binder.restoreCallingIdentity(identity); |
| 6940 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6941 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6942 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6943 | |
| 6944 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 6945 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 6946 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 6947 | try { |
| 6948 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 6949 | Binder.getCallingUid())) { |
| 6950 | throw new SecurityException("Package uid and package name do not match: " |
| 6951 | + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage); |
| 6952 | } |
| 6953 | } catch (PackageManager.NameNotFoundException e) { |
| 6954 | throw new SecurityException("Package name invalid:" + callingPackage); |
| 6955 | } |
| 6956 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 6957 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 6958 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 6959 | throw new SecurityException("App must be the dialer role holder to" |
| 6960 | + " upload a call composer pic"); |
| 6961 | } |
| 6962 | |
| 6963 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6964 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 6965 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 6966 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 6967 | boolean readUntilEnd = false; |
| 6968 | int totalBytesRead = 0; |
| 6969 | byte[] buffer = new byte[16 * 1024]; |
| 6970 | while (true) { |
| 6971 | int numRead; |
| 6972 | try { |
| 6973 | numRead = input.read(buffer); |
| 6974 | } catch (IOException e) { |
| 6975 | try { |
| 6976 | fd.checkError(); |
| 6977 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 6978 | null); |
| 6979 | } catch (IOException e1) { |
| 6980 | // This means that the other side closed explicitly with an error. If this |
| 6981 | // happens, log and ignore. |
| 6982 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 6983 | } |
| 6984 | break; |
| 6985 | } |
| 6986 | if (numRead == -1) { |
| 6987 | readUntilEnd = true; |
| 6988 | break; |
| 6989 | } |
| 6990 | totalBytesRead += numRead; |
| 6991 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 6992 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 6993 | try { |
| 6994 | input.close(); |
| 6995 | } catch (IOException e) { |
| 6996 | // ignore |
| 6997 | } |
| 6998 | break; |
| 6999 | } |
| 7000 | output.write(buffer, 0, numRead); |
| 7001 | } |
| 7002 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7003 | // close is above, where the picture size is too big. |
| 7004 | |
| 7005 | try { |
| 7006 | fd.checkError(); |
| 7007 | } catch (IOException e) { |
| 7008 | loge("Remote end for call composer closed with an error: " + e); |
| 7009 | return; |
| 7010 | } |
| 7011 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame^] | 7012 | if (!readUntilEnd) { |
| 7013 | loge("Did not finish reading entire image; aborting"); |
| 7014 | return; |
| 7015 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7016 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame^] | 7017 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7018 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7019 | new CallComposerPictureTransfer.Factory() {}, |
| 7020 | imageData, |
| 7021 | (result) -> { |
| 7022 | if (result.first != null) { |
| 7023 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7024 | Bundle outputResult = new Bundle(); |
| 7025 | outputResult.putParcelable( |
| 7026 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7027 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7028 | outputResult); |
| 7029 | } else { |
| 7030 | callback.send(result.second, null); |
| 7031 | } |
| 7032 | } |
| 7033 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7034 | }); |
| 7035 | } |
| 7036 | |
| 7037 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7038 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7039 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7040 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7041 | |
| 7042 | final long identity = Binder.clearCallingIdentity(); |
| 7043 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7044 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7045 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7046 | } finally { |
| 7047 | Binder.restoreCallingIdentity(identity); |
| 7048 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7049 | } |
| 7050 | |
| 7051 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7052 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7053 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7054 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7055 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7056 | return false; |
| 7057 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7058 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7059 | final long identity = Binder.clearCallingIdentity(); |
| 7060 | try { |
| 7061 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7062 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7063 | // In the long run, we may instead need to check if there exists a connection service |
| 7064 | // which can support video calling. |
| 7065 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7066 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7067 | return imsManager.isVtEnabledByPlatform() |
| 7068 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7069 | && imsManager.isVtEnabledByUser(); |
| 7070 | } finally { |
| 7071 | Binder.restoreCallingIdentity(identity); |
| 7072 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7073 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7074 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7075 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7076 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7077 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7078 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7079 | mApp, subId, callingPackage, callingFeatureId, |
| 7080 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7081 | return false; |
| 7082 | } |
| 7083 | |
| 7084 | final long identity = Binder.clearCallingIdentity(); |
| 7085 | try { |
| 7086 | CarrierConfigManager configManager = |
| 7087 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7088 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7089 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7090 | } finally { |
| 7091 | Binder.restoreCallingIdentity(identity); |
| 7092 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7093 | } |
| 7094 | |
| 7095 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7096 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7097 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7098 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7099 | return false; |
| 7100 | } |
| 7101 | |
| 7102 | final long identity = Binder.clearCallingIdentity(); |
| 7103 | try { |
| 7104 | CarrierConfigManager configManager = |
| 7105 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7106 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7107 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7108 | } finally { |
| 7109 | Binder.restoreCallingIdentity(identity); |
| 7110 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7111 | } |
| 7112 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7113 | @Override |
| 7114 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7115 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7116 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7117 | } |
| 7118 | |
| 7119 | @Override |
| 7120 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7121 | final long identity = Binder.clearCallingIdentity(); |
| 7122 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7123 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7124 | } finally { |
| 7125 | Binder.restoreCallingIdentity(identity); |
| 7126 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7127 | } |
| 7128 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7129 | /** |
| 7130 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7131 | * support for the feature and device firmware support. |
| 7132 | * |
| 7133 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7134 | */ |
| 7135 | @Override |
| 7136 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7137 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7138 | final Phone phone = getPhone(subscriptionId); |
| 7139 | if (phone == null) { |
| 7140 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7141 | return false; |
| 7142 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7143 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7144 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7145 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7146 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7147 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7148 | return isCarrierSupported && isDeviceSupported; |
| 7149 | } finally { |
| 7150 | Binder.restoreCallingIdentity(identity); |
| 7151 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7152 | } |
| 7153 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7154 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7155 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7156 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7157 | * 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] | 7158 | */ |
| 7159 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7160 | final long identity = Binder.clearCallingIdentity(); |
| 7161 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7162 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7163 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7164 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7165 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7166 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7167 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7168 | } finally { |
| 7169 | Binder.restoreCallingIdentity(identity); |
| 7170 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7171 | } |
| 7172 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7173 | @Deprecated |
| 7174 | @Override |
| 7175 | public String getDeviceId(String callingPackage) { |
| 7176 | return getDeviceIdWithFeature(callingPackage, null); |
| 7177 | } |
| 7178 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7179 | /** |
| 7180 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7181 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7182 | * |
| 7183 | * <p>Requires Permission: |
| 7184 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7185 | */ |
| 7186 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7187 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7188 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7189 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7190 | return null; |
| 7191 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7192 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7193 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7194 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7195 | return null; |
| 7196 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7197 | |
| 7198 | final long identity = Binder.clearCallingIdentity(); |
| 7199 | try { |
| 7200 | return phone.getDeviceId(); |
| 7201 | } finally { |
| 7202 | Binder.restoreCallingIdentity(identity); |
| 7203 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7204 | } |
| 7205 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7206 | /** |
| 7207 | * {@hide} |
| 7208 | * Returns the IMS Registration Status on a particular subid |
| 7209 | * |
| 7210 | * @param subId |
| 7211 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7212 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7213 | Phone phone = getPhone(subId); |
| 7214 | if (phone != null) { |
| 7215 | return phone.isImsRegistered(); |
| 7216 | } else { |
| 7217 | return false; |
| 7218 | } |
| 7219 | } |
| 7220 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7221 | @Override |
| 7222 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7223 | final long identity = Binder.clearCallingIdentity(); |
| 7224 | try { |
| 7225 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 7226 | } finally { |
| 7227 | Binder.restoreCallingIdentity(identity); |
| 7228 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7229 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7230 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7231 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7232 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7233 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7234 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7235 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7236 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7237 | } |
| 7238 | final long identity = Binder.clearCallingIdentity(); |
| 7239 | try { |
| 7240 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7241 | } finally { |
| 7242 | Binder.restoreCallingIdentity(identity); |
| 7243 | } |
| 7244 | } |
| 7245 | |
| 7246 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7247 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 7248 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 7249 | + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7250 | final long identity = Binder.clearCallingIdentity(); |
| 7251 | try { |
| 7252 | Phone phone = getPhone(subscriptionId); |
| 7253 | if (phone == null) { |
| 7254 | return null; |
| 7255 | } |
| 7256 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7257 | } finally { |
| 7258 | Binder.restoreCallingIdentity(identity); |
| 7259 | } |
| 7260 | } |
| 7261 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7262 | /** |
| 7263 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7264 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7265 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7266 | final long identity = Binder.clearCallingIdentity(); |
| 7267 | try { |
| 7268 | Phone phone = getPhone(subId); |
| 7269 | if (phone != null) { |
| 7270 | return phone.isWifiCallingEnabled(); |
| 7271 | } else { |
| 7272 | return false; |
| 7273 | } |
| 7274 | } finally { |
| 7275 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7276 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7277 | } |
| 7278 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7279 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7280 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7281 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7282 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7283 | final long identity = Binder.clearCallingIdentity(); |
| 7284 | try { |
| 7285 | Phone phone = getPhone(subId); |
| 7286 | if (phone != null) { |
| 7287 | return phone.isVideoEnabled(); |
| 7288 | } else { |
| 7289 | return false; |
| 7290 | } |
| 7291 | } finally { |
| 7292 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7293 | } |
| 7294 | } |
| 7295 | |
| 7296 | /** |
| 7297 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7298 | * defined in {@link ImsRegistrationImplBase}. |
| 7299 | */ |
| 7300 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7301 | final long identity = Binder.clearCallingIdentity(); |
| 7302 | try { |
| 7303 | Phone phone = getPhone(subId); |
| 7304 | if (phone != null) { |
| 7305 | return phone.getImsRegistrationTech(); |
| 7306 | } else { |
| 7307 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7308 | } |
| 7309 | } finally { |
| 7310 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7311 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7312 | } |
| 7313 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7314 | @Override |
| 7315 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7316 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7317 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7318 | return; |
| 7319 | } |
| 7320 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7321 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7322 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7323 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7324 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7325 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7326 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7327 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7328 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7329 | setAllowedNetworkTypesForReason(subId, |
| 7330 | TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7331 | RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId))); |
| 7332 | setAllowedNetworkTypesForReason(subId, |
| 7333 | TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER, |
| 7334 | RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId))); |
| 7335 | setAllowedNetworkTypesForReason(subId, |
| 7336 | TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER, |
| 7337 | RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId))); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7338 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 7339 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7340 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7341 | // There has been issues when Sms raw table somehow stores orphan |
| 7342 | // fragments. They lead to garbled message when new fragments come |
| 7343 | // in and combined with those stale ones. In case this happens again, |
| 7344 | // user can reset all network settings which will clean up this table. |
| 7345 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7346 | // Clean up IMS settings as well here. |
| 7347 | int slotId = getSlotIndex(subId); |
| 7348 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7349 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7350 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7351 | |
| 7352 | // Erase modem config if erase modem on network setting is enabled. |
| 7353 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7354 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7355 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 7356 | sendEraseModemConfig(getDefaultPhone()); |
| 7357 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7358 | } finally { |
| 7359 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7360 | } |
| 7361 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7362 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7363 | private void cleanUpSmsRawTable(Context context) { |
| 7364 | ContentResolver resolver = context.getContentResolver(); |
| 7365 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7366 | resolver.delete(uri, null, null); |
| 7367 | } |
| 7368 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7369 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7370 | public String getSimLocaleForSubscriber(int subId) { |
| 7371 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7372 | final Phone phone = getPhone(subId); |
| 7373 | if (phone == null) { |
| 7374 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7375 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7376 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7377 | final long identity = Binder.clearCallingIdentity(); |
| 7378 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7379 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7380 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7381 | if (info == null) { |
| 7382 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7383 | return null; |
| 7384 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7385 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7386 | // preferences (EF-PL and EF-LI)... |
| 7387 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7388 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7389 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7390 | if (localeFromDefaultSim != null) { |
| 7391 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7392 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7393 | + localeFromDefaultSim); |
| 7394 | return localeFromDefaultSim.toLanguageTag(); |
| 7395 | } else { |
| 7396 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7397 | } |
| 7398 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7399 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7400 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7401 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7402 | // the SIM and carrier preferences does not include a country we add the country |
| 7403 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7404 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7405 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7406 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7407 | return mccLocale.toLanguageTag(); |
| 7408 | } |
| 7409 | |
| 7410 | if (DBG) log("No locale found - returning null"); |
| 7411 | return null; |
| 7412 | } finally { |
| 7413 | Binder.restoreCallingIdentity(identity); |
| 7414 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7415 | } |
| 7416 | |
| 7417 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7418 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7419 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7420 | } |
| 7421 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7422 | /** |
| 7423 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7424 | */ |
| 7425 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7426 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7427 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7428 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7429 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7430 | private final ModemActivityInfo mLastModemActivityInfo = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7431 | new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7432 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7433 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7434 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7435 | * representing the state of the modem. |
| 7436 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7437 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7438 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7439 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7440 | */ |
| 7441 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7442 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7443 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7444 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7445 | |
| 7446 | final long identity = Binder.clearCallingIdentity(); |
| 7447 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7448 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7449 | } finally { |
| 7450 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7451 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7452 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7453 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7454 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7455 | // less than total activity duration. |
| 7456 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7457 | if (info == null) { |
| 7458 | return false; |
| 7459 | } |
| 7460 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7461 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7462 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7463 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7464 | return (info.isValid() |
| 7465 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7466 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7467 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7468 | && (totalTxTimeMs <= activityDurationMs)); |
| 7469 | } |
| 7470 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7471 | /** |
| 7472 | * {@hide} |
| 7473 | * Returns the service state information on specified subscription. |
| 7474 | */ |
| 7475 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7476 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7477 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7478 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7479 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7480 | return null; |
| 7481 | } |
| 7482 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7483 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7484 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7485 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7486 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7487 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7488 | .setCallingPid(Binder.getCallingPid()) |
| 7489 | .setCallingUid(Binder.getCallingUid()) |
| 7490 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7491 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7492 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7493 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7494 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7495 | .build()); |
| 7496 | |
| 7497 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7498 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7499 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7500 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7501 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7502 | .setCallingPid(Binder.getCallingPid()) |
| 7503 | .setCallingUid(Binder.getCallingUid()) |
| 7504 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7505 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7506 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7507 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7508 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7509 | .build()); |
| 7510 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7511 | boolean hasFinePermission = |
| 7512 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7513 | boolean hasCoarsePermission = |
| 7514 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7515 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7516 | final Phone phone = getPhone(subId); |
| 7517 | if (phone == null) { |
| 7518 | return null; |
| 7519 | } |
| 7520 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 7521 | final long identity = Binder.clearCallingIdentity(); |
| 7522 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7523 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7524 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7525 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7526 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7527 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7528 | Rlog.d(LOG_TAG, |
| 7529 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7530 | return null; |
| 7531 | } |
| 7532 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7533 | ServiceState ss = phone.getServiceState(); |
| 7534 | |
| 7535 | // Scrub out the location info in ServiceState depending on what level of access |
| 7536 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7537 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7538 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7539 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7540 | } finally { |
| 7541 | Binder.restoreCallingIdentity(identity); |
| 7542 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7543 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7544 | |
| 7545 | /** |
| 7546 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7547 | * |
| 7548 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7549 | * voicemail ringtone. |
| 7550 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7551 | * PhoneAccount. |
| 7552 | */ |
| 7553 | @Override |
| 7554 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7555 | final long identity = Binder.clearCallingIdentity(); |
| 7556 | try { |
| 7557 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7558 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7559 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7560 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7561 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7562 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7563 | } finally { |
| 7564 | Binder.restoreCallingIdentity(identity); |
| 7565 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7566 | } |
| 7567 | |
| 7568 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7569 | * Sets the per-account voicemail ringtone. |
| 7570 | * |
| 7571 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7572 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7573 | * |
| 7574 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7575 | * voicemail ringtone. |
| 7576 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7577 | * PhoneAccount. |
| 7578 | */ |
| 7579 | @Override |
| 7580 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7581 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7582 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7583 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7584 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7585 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7586 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7587 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7588 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7589 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7590 | |
| 7591 | final long identity = Binder.clearCallingIdentity(); |
| 7592 | try { |
| 7593 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7594 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7595 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7596 | } |
| 7597 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7598 | } finally { |
| 7599 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7600 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7601 | } |
| 7602 | |
| 7603 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7604 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7605 | * |
| 7606 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7607 | * voicemail vibration setting. |
| 7608 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7609 | */ |
| 7610 | @Override |
| 7611 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7612 | final long identity = Binder.clearCallingIdentity(); |
| 7613 | try { |
| 7614 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7615 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7616 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7617 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7618 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7619 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7620 | } finally { |
| 7621 | Binder.restoreCallingIdentity(identity); |
| 7622 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7623 | } |
| 7624 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7625 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7626 | * Sets the per-account voicemail vibration. |
| 7627 | * |
| 7628 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7629 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7630 | * |
| 7631 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7632 | * voicemail vibration setting. |
| 7633 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7634 | * specific PhoneAccount. |
| 7635 | */ |
| 7636 | @Override |
| 7637 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7638 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7639 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7640 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7641 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7642 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7643 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7644 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7645 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7646 | } |
| 7647 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7648 | final long identity = Binder.clearCallingIdentity(); |
| 7649 | try { |
| 7650 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7651 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7652 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7653 | } |
| 7654 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7655 | } finally { |
| 7656 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7657 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7658 | } |
| 7659 | |
| 7660 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7661 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7662 | * |
| 7663 | * @throws SecurityException if the caller does not have the required permission |
| 7664 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7665 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7666 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7667 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7668 | } |
| 7669 | |
| 7670 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7671 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7672 | * permission. |
| 7673 | * |
| 7674 | * @throws SecurityException if the caller does not have the required permission |
| 7675 | */ |
| 7676 | private void enforceSendSmsPermission() { |
| 7677 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7678 | } |
| 7679 | |
| 7680 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7681 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7682 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7683 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7684 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7685 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7686 | final long identity = Binder.clearCallingIdentity(); |
| 7687 | try { |
| 7688 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7689 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7690 | if (componentName == null) { |
| 7691 | throw new SecurityException( |
| 7692 | "Caller not current active visual voicemail package[null]"); |
| 7693 | } |
| 7694 | String vvmPackage = componentName.getPackageName(); |
| 7695 | if (!callingPackage.equals(vvmPackage)) { |
| 7696 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7697 | + vvmPackage + "]"); |
| 7698 | } |
| 7699 | } finally { |
| 7700 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7701 | } |
| 7702 | } |
| 7703 | |
| 7704 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7705 | * Return the application ID for the app type. |
| 7706 | * |
| 7707 | * @param subId the subscription ID that this request applies to. |
| 7708 | * @param appType the uicc app type. |
| 7709 | * @return Application ID for specificied app type, or null if no uicc. |
| 7710 | */ |
| 7711 | @Override |
| 7712 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7713 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7714 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7715 | |
| 7716 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7717 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7718 | if (phone == null) { |
| 7719 | return null; |
| 7720 | } |
| 7721 | String aid = null; |
| 7722 | try { |
| 7723 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7724 | .getApplicationByType(appType).getAid(); |
| 7725 | } catch (Exception e) { |
| 7726 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7727 | } |
| 7728 | return aid; |
| 7729 | } finally { |
| 7730 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7731 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7732 | } |
| 7733 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7734 | /** |
| 7735 | * Return the Electronic Serial Number. |
| 7736 | * |
| 7737 | * @param subId the subscription ID that this request applies to. |
| 7738 | * @return ESN or null if error. |
| 7739 | */ |
| 7740 | @Override |
| 7741 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7742 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7743 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7744 | |
| 7745 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7746 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7747 | if (phone == null) { |
| 7748 | return null; |
| 7749 | } |
| 7750 | String esn = null; |
| 7751 | try { |
| 7752 | esn = phone.getEsn(); |
| 7753 | } catch (Exception e) { |
| 7754 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7755 | } |
| 7756 | return esn; |
| 7757 | } finally { |
| 7758 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7759 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7760 | } |
| 7761 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7762 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7763 | * Return the Preferred Roaming List Version. |
| 7764 | * |
| 7765 | * @param subId the subscription ID that this request applies to. |
| 7766 | * @return PRLVersion or null if error. |
| 7767 | */ |
| 7768 | @Override |
| 7769 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7770 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7771 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7772 | |
| 7773 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7774 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7775 | if (phone == null) { |
| 7776 | return null; |
| 7777 | } |
| 7778 | String cdmaPrlVersion = null; |
| 7779 | try { |
| 7780 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7781 | } catch (Exception e) { |
| 7782 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7783 | } |
| 7784 | return cdmaPrlVersion; |
| 7785 | } finally { |
| 7786 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7787 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7788 | } |
| 7789 | |
| 7790 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7791 | * Get snapshot of Telephony histograms |
| 7792 | * @return List of Telephony histograms |
| 7793 | * @hide |
| 7794 | */ |
| 7795 | @Override |
| 7796 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7797 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7798 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7799 | |
| 7800 | final long identity = Binder.clearCallingIdentity(); |
| 7801 | try { |
| 7802 | return RIL.getTelephonyRILTimingHistograms(); |
| 7803 | } finally { |
| 7804 | Binder.restoreCallingIdentity(identity); |
| 7805 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7806 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7807 | |
| 7808 | /** |
| 7809 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7810 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7811 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7812 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7813 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7814 | * @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] | 7815 | */ |
| 7816 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7817 | @TelephonyManager.SetCarrierRestrictionResult |
| 7818 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7819 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7820 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7821 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7822 | if (carrierRestrictionRules == null) { |
| 7823 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7824 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7825 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7826 | final long identity = Binder.clearCallingIdentity(); |
| 7827 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7828 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7829 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7830 | } finally { |
| 7831 | Binder.restoreCallingIdentity(identity); |
| 7832 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7833 | } |
| 7834 | |
| 7835 | /** |
| 7836 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7837 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7838 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7839 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7840 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7841 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7842 | */ |
| 7843 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7844 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7845 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7846 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7847 | |
| 7848 | final long identity = Binder.clearCallingIdentity(); |
| 7849 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7850 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7851 | if (response instanceof CarrierRestrictionRules) { |
| 7852 | return (CarrierRestrictionRules) response; |
| 7853 | } |
| 7854 | // Response is an Exception of some kind, |
| 7855 | // which is signalled to the user as a NULL retval |
| 7856 | return null; |
| 7857 | } catch (Exception e) { |
| 7858 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7859 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7860 | } finally { |
| 7861 | Binder.restoreCallingIdentity(identity); |
| 7862 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7863 | } |
| 7864 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7865 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7866 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7867 | * @param subId the subscription ID that this action applies to. |
| 7868 | * @param enabled control enable or disable radio. |
| 7869 | * {@hide} |
| 7870 | */ |
| 7871 | @Override |
| 7872 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7873 | enforceModifyPermission(); |
| 7874 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7875 | |
| 7876 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7877 | if (phone == null) { |
| 7878 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7879 | return; |
| 7880 | } |
| 7881 | try { |
| 7882 | phone.carrierActionSetRadioEnabled(enabled); |
| 7883 | } catch (Exception e) { |
| 7884 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7885 | } finally { |
| 7886 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7887 | } |
| 7888 | } |
| 7889 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7890 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7891 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7892 | * network status based on which carrier apps could apply actions accordingly, |
| 7893 | * enable/disable default url handler for example. |
| 7894 | * |
| 7895 | * @param subId the subscription ID that this action applies to. |
| 7896 | * @param report control start/stop reporting the default network status. |
| 7897 | * {@hide} |
| 7898 | */ |
| 7899 | @Override |
| 7900 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7901 | enforceModifyPermission(); |
| 7902 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7903 | |
| 7904 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7905 | if (phone == null) { |
| 7906 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7907 | return; |
| 7908 | } |
| 7909 | try { |
| 7910 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7911 | } catch (Exception e) { |
| 7912 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7913 | } finally { |
| 7914 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7915 | } |
| 7916 | } |
| 7917 | |
| 7918 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7919 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7920 | * @param subId the subscription ID that this action applies to. |
| 7921 | * {@hide} |
| 7922 | */ |
| 7923 | @Override |
| 7924 | public void carrierActionResetAll(int subId) { |
| 7925 | enforceModifyPermission(); |
| 7926 | final Phone phone = getPhone(subId); |
| 7927 | if (phone == null) { |
| 7928 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7929 | return; |
| 7930 | } |
| 7931 | try { |
| 7932 | phone.carrierActionResetAll(); |
| 7933 | } catch (Exception e) { |
| 7934 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7935 | } |
| 7936 | } |
| 7937 | |
| 7938 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7939 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7940 | * bug report is being generated. |
| 7941 | */ |
| 7942 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7943 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7944 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7945 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7946 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7947 | + Binder.getCallingPid() |
| 7948 | + ", uid=" + Binder.getCallingUid() |
| 7949 | + "without permission " |
| 7950 | + android.Manifest.permission.DUMP); |
| 7951 | return; |
| 7952 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7953 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7954 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7955 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7956 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7957 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7958 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7959 | @NonNull String[] args) { |
| 7960 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 7961 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 7962 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7963 | } |
| 7964 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7965 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7966 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 7967 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7968 | * @param reason the reason the data enable change is taking place |
| 7969 | * @param enabled True if enabling the data, otherwise disabling. |
| 7970 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7971 | */ |
| 7972 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7973 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7974 | boolean enabled) { |
| 7975 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 7976 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7977 | try { |
| 7978 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7979 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7980 | } catch (SecurityException se) { |
| 7981 | enforceModifyPermission(); |
| 7982 | } |
| 7983 | } else { |
| 7984 | enforceModifyPermission(); |
| 7985 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7986 | |
| 7987 | final long identity = Binder.clearCallingIdentity(); |
| 7988 | try { |
| 7989 | Phone phone = getPhone(subId); |
| 7990 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7991 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7992 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7993 | } else { |
| 7994 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 7995 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7996 | } |
| 7997 | } finally { |
| 7998 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7999 | } |
| 8000 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8001 | |
| 8002 | /** |
| 8003 | * Get Client request stats |
| 8004 | * @return List of Client Request Stats |
| 8005 | * @hide |
| 8006 | */ |
| 8007 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8008 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8009 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8010 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8011 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8012 | return null; |
| 8013 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8014 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8015 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8016 | final long identity = Binder.clearCallingIdentity(); |
| 8017 | try { |
| 8018 | if (phone != null) { |
| 8019 | return phone.getClientRequestStats(); |
| 8020 | } |
| 8021 | |
| 8022 | return null; |
| 8023 | } finally { |
| 8024 | Binder.restoreCallingIdentity(identity); |
| 8025 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8026 | } |
| 8027 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8028 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8029 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8030 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8031 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8032 | |
| 8033 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8034 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8035 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8036 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8037 | * @param state State of SIM (power down, power up, pass through) |
| 8038 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8039 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8040 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8041 | * |
| 8042 | **/ |
| 8043 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8044 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8045 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8046 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8047 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8048 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8049 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8050 | final long identity = Binder.clearCallingIdentity(); |
| 8051 | try { |
| 8052 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8053 | phone.setSimPowerState(state, null, workSource); |
| 8054 | } |
| 8055 | } finally { |
| 8056 | Binder.restoreCallingIdentity(identity); |
| 8057 | } |
| 8058 | } |
| 8059 | |
| 8060 | /** |
| 8061 | * Set SIM card power state. |
| 8062 | * |
| 8063 | * @param slotIndex SIM slot id. |
| 8064 | * @param state State of SIM (power down, power up, pass through) |
| 8065 | * @param callback callback to trigger after success or failure |
| 8066 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8067 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8068 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8069 | * |
| 8070 | **/ |
| 8071 | @Override |
| 8072 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8073 | IIntegerConsumer callback) { |
| 8074 | enforceModifyPermission(); |
| 8075 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8076 | |
| 8077 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8078 | |
| 8079 | final long identity = Binder.clearCallingIdentity(); |
| 8080 | try { |
| 8081 | if (phone != null) { |
| 8082 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8083 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8084 | } |
| 8085 | } finally { |
| 8086 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8087 | } |
| 8088 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8089 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8090 | private boolean isUssdApiAllowed(int subId) { |
| 8091 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8092 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8093 | if (configManager == null) { |
| 8094 | return false; |
| 8095 | } |
| 8096 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8097 | if (pb == null) { |
| 8098 | return false; |
| 8099 | } |
| 8100 | return pb.getBoolean( |
| 8101 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8102 | } |
| 8103 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8104 | /** |
| 8105 | * Check if phone is in emergency callback mode |
| 8106 | * @return true if phone is in emergency callback mode |
| 8107 | * @param subId sub id |
| 8108 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8109 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8110 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8111 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8112 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8113 | |
| 8114 | final long identity = Binder.clearCallingIdentity(); |
| 8115 | try { |
| 8116 | if (phone != null) { |
| 8117 | return phone.isInEcm(); |
| 8118 | } else { |
| 8119 | return false; |
| 8120 | } |
| 8121 | } finally { |
| 8122 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8123 | } |
| 8124 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8125 | |
| 8126 | /** |
| 8127 | * Get the current signal strength information for the given subscription. |
| 8128 | * Because this information is not updated when the device is in a low power state |
| 8129 | * it should not be relied-upon to be current. |
| 8130 | * @param subId Subscription index |
| 8131 | * @return the most recent cached signal strength info from the modem |
| 8132 | */ |
| 8133 | @Override |
| 8134 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8135 | final long identity = Binder.clearCallingIdentity(); |
| 8136 | try { |
| 8137 | Phone p = getPhone(subId); |
| 8138 | if (p == null) { |
| 8139 | return null; |
| 8140 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8141 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8142 | return p.getSignalStrength(); |
| 8143 | } finally { |
| 8144 | Binder.restoreCallingIdentity(identity); |
| 8145 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8146 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8147 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8148 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8149 | * Get the current modem radio state for the given slot. |
| 8150 | * @param slotIndex slot index. |
| 8151 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8152 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8153 | * @return the current radio power state from the modem |
| 8154 | */ |
| 8155 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8156 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8157 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8158 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8159 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8160 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8161 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8162 | } |
| 8163 | |
| 8164 | final long identity = Binder.clearCallingIdentity(); |
| 8165 | try { |
| 8166 | return phone.getRadioPowerState(); |
| 8167 | } finally { |
| 8168 | Binder.restoreCallingIdentity(identity); |
| 8169 | } |
| 8170 | } |
| 8171 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8172 | } |
| 8173 | |
| 8174 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8175 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8176 | * |
| 8177 | * <p>Requires one of the following permissions: |
| 8178 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 8179 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8180 | * privileges. |
| 8181 | * |
| 8182 | * @param subId subscription id |
| 8183 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8184 | * {@code false}. |
| 8185 | */ |
| 8186 | @Override |
| 8187 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8188 | try { |
| 8189 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8190 | null); |
| 8191 | } catch (Exception e) { |
| 8192 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 8193 | mApp, subId, "isDataRoamingEnabled"); |
| 8194 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8195 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8196 | boolean isEnabled = false; |
| 8197 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8198 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8199 | Phone phone = getPhone(subId); |
| 8200 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8201 | } finally { |
| 8202 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8203 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8204 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8205 | } |
| 8206 | |
| 8207 | |
| 8208 | /** |
| 8209 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8210 | * |
| 8211 | * <p> Requires permission: |
| 8212 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8213 | * privileges. |
| 8214 | * |
| 8215 | * @param subId subscription id |
| 8216 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8217 | */ |
| 8218 | @Override |
| 8219 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8220 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8221 | mApp, subId, "setDataRoamingEnabled"); |
| 8222 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8223 | final long identity = Binder.clearCallingIdentity(); |
| 8224 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8225 | Phone phone = getPhone(subId); |
| 8226 | if (phone != null) { |
| 8227 | phone.setDataRoamingEnabled(isEnabled); |
| 8228 | } |
| 8229 | } finally { |
| 8230 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8231 | } |
| 8232 | } |
| 8233 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8234 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8235 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8236 | TelephonyPermissions |
| 8237 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8238 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8239 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8240 | boolean isAllowed = true; |
| 8241 | final long identity = Binder.clearCallingIdentity(); |
| 8242 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8243 | Phone phone = getPhone(subId); |
| 8244 | if (phone != null) { |
| 8245 | isAllowed = phone.isCspPlmnEnabled(); |
| 8246 | } |
| 8247 | } finally { |
| 8248 | Binder.restoreCallingIdentity(identity); |
| 8249 | } |
| 8250 | return isAllowed; |
| 8251 | } |
| 8252 | |
| 8253 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8254 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8255 | // Verify that tha callingPackage belongs to the calling UID |
| 8256 | mApp.getSystemService(AppOpsManager.class) |
| 8257 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8258 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8259 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8260 | try { |
| 8261 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8262 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8263 | } catch (SecurityException e) { |
| 8264 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8265 | // has carrier privileges on an active UICC |
| 8266 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8267 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8268 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8269 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8270 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8271 | |
| 8272 | final long identity = Binder.clearCallingIdentity(); |
| 8273 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8274 | UiccController uiccController = UiccController.getInstance(); |
| 8275 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8276 | if (hasReadPermission) { |
| 8277 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8278 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8279 | |
| 8280 | // Remove private info if the caller doesn't have access |
| 8281 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8282 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8283 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8284 | // is available |
| 8285 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 8286 | if (card == null || card.getUiccProfile() == null) { |
| 8287 | // assume no access if the card or profile is unavailable |
| 8288 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8289 | continue; |
| 8290 | } |
| 8291 | UiccProfile profile = card.getUiccProfile(); |
| 8292 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8293 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8294 | filteredInfos.add(cardInfo); |
| 8295 | } else { |
| 8296 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8297 | } |
| 8298 | } |
| 8299 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8300 | } finally { |
| 8301 | Binder.restoreCallingIdentity(identity); |
| 8302 | } |
| 8303 | } |
| 8304 | |
| 8305 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8306 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8307 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8308 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8309 | final long identity = Binder.clearCallingIdentity(); |
| 8310 | try { |
| 8311 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8312 | if (slots == null) { |
| 8313 | Rlog.i(LOG_TAG, "slots is null."); |
| 8314 | return null; |
| 8315 | } |
| 8316 | |
| 8317 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8318 | for (int i = 0; i < slots.length; i++) { |
| 8319 | UiccSlot slot = slots[i]; |
| 8320 | if (slot == null) { |
| 8321 | continue; |
| 8322 | } |
| 8323 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8324 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8325 | UiccCard card = slot.getUiccCard(); |
| 8326 | if (card != null) { |
| 8327 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8328 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8329 | cardId = slot.getEid(); |
| 8330 | if (TextUtils.isEmpty(cardId)) { |
| 8331 | cardId = slot.getIccId(); |
| 8332 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8333 | } |
| 8334 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8335 | if (cardId != null) { |
| 8336 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8337 | // if cardId is an EID, it's all digits so this is fine |
| 8338 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8339 | } |
| 8340 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8341 | int cardState = 0; |
| 8342 | switch (slot.getCardState()) { |
| 8343 | case CARDSTATE_ABSENT: |
| 8344 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8345 | break; |
| 8346 | case CARDSTATE_PRESENT: |
| 8347 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8348 | break; |
| 8349 | case CARDSTATE_ERROR: |
| 8350 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8351 | break; |
| 8352 | case CARDSTATE_RESTRICTED: |
| 8353 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8354 | break; |
| 8355 | default: |
| 8356 | break; |
| 8357 | |
| 8358 | } |
| 8359 | |
| 8360 | infos[i] = new UiccSlotInfo( |
| 8361 | slot.isActive(), |
| 8362 | slot.isEuicc(), |
| 8363 | cardId, |
| 8364 | cardState, |
| 8365 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8366 | slot.isExtendedApduSupported(), |
| 8367 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8368 | } |
| 8369 | return infos; |
| 8370 | } finally { |
| 8371 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8372 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8373 | } |
| 8374 | |
| 8375 | @Override |
| 8376 | public boolean switchSlots(int[] physicalSlots) { |
| 8377 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8378 | |
| 8379 | final long identity = Binder.clearCallingIdentity(); |
| 8380 | try { |
| 8381 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8382 | } finally { |
| 8383 | Binder.restoreCallingIdentity(identity); |
| 8384 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8385 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8386 | |
| 8387 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8388 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8389 | final long identity = Binder.clearCallingIdentity(); |
| 8390 | try { |
| 8391 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8392 | } finally { |
| 8393 | Binder.restoreCallingIdentity(identity); |
| 8394 | } |
| 8395 | } |
| 8396 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8397 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8398 | * A test API to reload the UICC profile. |
| 8399 | * |
| 8400 | * <p>Requires that the calling app has permission |
| 8401 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8402 | * @hide |
| 8403 | */ |
| 8404 | @Override |
| 8405 | public void refreshUiccProfile(int subId) { |
| 8406 | enforceModifyPermission(); |
| 8407 | |
| 8408 | final long identity = Binder.clearCallingIdentity(); |
| 8409 | try { |
| 8410 | Phone phone = getPhone(subId); |
| 8411 | if (phone == null) { |
| 8412 | return; |
| 8413 | } |
| 8414 | UiccCard uiccCard = phone.getUiccCard(); |
| 8415 | if (uiccCard == null) { |
| 8416 | return; |
| 8417 | } |
| 8418 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8419 | if (uiccProfile == null) { |
| 8420 | return; |
| 8421 | } |
| 8422 | uiccProfile.refresh(); |
| 8423 | } finally { |
| 8424 | Binder.restoreCallingIdentity(identity); |
| 8425 | } |
| 8426 | } |
| 8427 | |
| 8428 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8429 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8430 | */ |
| 8431 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8432 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8433 | } |
| 8434 | |
| 8435 | /** |
| 8436 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8437 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8438 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8439 | */ |
| 8440 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8441 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8442 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8443 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8444 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8445 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8446 | return isDataRoamingEnabled; |
| 8447 | } |
| 8448 | |
| 8449 | /** |
| 8450 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8451 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8452 | */ |
| 8453 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8454 | List<Integer> list = TelephonyProperties.default_network(); |
| 8455 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8456 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8457 | return list.get(phoneId); |
| 8458 | } |
| 8459 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8460 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8461 | |
| 8462 | @Override |
| 8463 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8464 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8465 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8466 | |
| 8467 | final long identity = Binder.clearCallingIdentity(); |
| 8468 | try { |
| 8469 | final Phone phone = getPhone(subId); |
| 8470 | if (phone == null) { |
| 8471 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8472 | return; |
| 8473 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8474 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8475 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8476 | if (carrierPrivilegeRules == null) { |
| 8477 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8478 | } else { |
| 8479 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8480 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8481 | } finally { |
| 8482 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8483 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8484 | } |
| 8485 | |
| 8486 | @Override |
| 8487 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8488 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8489 | |
| 8490 | final long identity = Binder.clearCallingIdentity(); |
| 8491 | try { |
| 8492 | final Phone phone = getPhone(subId); |
| 8493 | if (phone == null) { |
| 8494 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8495 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8496 | } |
| 8497 | return phone.getCarrierIdListVersion(); |
| 8498 | } finally { |
| 8499 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8500 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8501 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8502 | |
| 8503 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8504 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8505 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8506 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8507 | mApp, subId, callingPackage, callingFeatureId, |
| 8508 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8509 | return -1; |
| 8510 | } |
| 8511 | |
| 8512 | final long identity = Binder.clearCallingIdentity(); |
| 8513 | try { |
| 8514 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8515 | } finally { |
| 8516 | Binder.restoreCallingIdentity(identity); |
| 8517 | } |
| 8518 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8519 | |
| 8520 | @Override |
| 8521 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8522 | TelephonyPermissions |
| 8523 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8524 | mApp, subId, "getCdmaRoamingMode"); |
| 8525 | |
| 8526 | final long identity = Binder.clearCallingIdentity(); |
| 8527 | try { |
| 8528 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8529 | } finally { |
| 8530 | Binder.restoreCallingIdentity(identity); |
| 8531 | } |
| 8532 | } |
| 8533 | |
| 8534 | @Override |
| 8535 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8536 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8537 | mApp, subId, "setCdmaRoamingMode"); |
| 8538 | |
| 8539 | final long identity = Binder.clearCallingIdentity(); |
| 8540 | try { |
| 8541 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8542 | } finally { |
| 8543 | Binder.restoreCallingIdentity(identity); |
| 8544 | } |
| 8545 | } |
| 8546 | |
| 8547 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8548 | public int getCdmaSubscriptionMode(int subId) { |
| 8549 | TelephonyPermissions |
| 8550 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8551 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8552 | |
| 8553 | final long identity = Binder.clearCallingIdentity(); |
| 8554 | try { |
| 8555 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8556 | } finally { |
| 8557 | Binder.restoreCallingIdentity(identity); |
| 8558 | } |
| 8559 | } |
| 8560 | |
| 8561 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8562 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8563 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8564 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8565 | |
| 8566 | final long identity = Binder.clearCallingIdentity(); |
| 8567 | try { |
| 8568 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8569 | } finally { |
| 8570 | Binder.restoreCallingIdentity(identity); |
| 8571 | } |
| 8572 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8573 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8574 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8575 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8576 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8577 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8578 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8579 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8580 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8581 | } |
| 8582 | final long identity = Binder.clearCallingIdentity(); |
| 8583 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8584 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8585 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8586 | if (phone.getEmergencyNumberTracker() != null |
| 8587 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8588 | emergencyNumberListInternal.put( |
| 8589 | phone.getSubId(), |
| 8590 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8591 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8592 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8593 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8594 | } finally { |
| 8595 | Binder.restoreCallingIdentity(identity); |
| 8596 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8597 | } |
| 8598 | |
| 8599 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8600 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8601 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8602 | if (!exactMatch) { |
| 8603 | TelephonyPermissions |
| 8604 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8605 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8606 | } |
| 8607 | final long identity = Binder.clearCallingIdentity(); |
| 8608 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8609 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8610 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8611 | && phone.getEmergencyNumberTracker() |
| 8612 | .isEmergencyNumber(number, exactMatch)) { |
| 8613 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8614 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8615 | } |
| 8616 | return false; |
| 8617 | } finally { |
| 8618 | Binder.restoreCallingIdentity(identity); |
| 8619 | } |
| 8620 | } |
| 8621 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8622 | /** |
| 8623 | * Update emergency number list for test mode. |
| 8624 | */ |
| 8625 | @Override |
| 8626 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8627 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8628 | "updateEmergencyNumberListTestMode"); |
| 8629 | |
| 8630 | final long identity = Binder.clearCallingIdentity(); |
| 8631 | try { |
| 8632 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8633 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8634 | if (tracker != null) { |
| 8635 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8636 | } |
| 8637 | } |
| 8638 | } finally { |
| 8639 | Binder.restoreCallingIdentity(identity); |
| 8640 | } |
| 8641 | } |
| 8642 | |
| 8643 | /** |
| 8644 | * Get the full emergency number list for test mode. |
| 8645 | */ |
| 8646 | @Override |
| 8647 | public List<String> getEmergencyNumberListTestMode() { |
| 8648 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8649 | "getEmergencyNumberListTestMode"); |
| 8650 | |
| 8651 | final long identity = Binder.clearCallingIdentity(); |
| 8652 | try { |
| 8653 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8654 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8655 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8656 | if (tracker != null) { |
| 8657 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8658 | emergencyNumbers.add(num.getNumber()); |
| 8659 | } |
| 8660 | } |
| 8661 | } |
| 8662 | return new ArrayList<>(emergencyNumbers); |
| 8663 | } finally { |
| 8664 | Binder.restoreCallingIdentity(identity); |
| 8665 | } |
| 8666 | } |
| 8667 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8668 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8669 | public int getEmergencyNumberDbVersion(int subId) { |
| 8670 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8671 | |
| 8672 | final long identity = Binder.clearCallingIdentity(); |
| 8673 | try { |
| 8674 | final Phone phone = getPhone(subId); |
| 8675 | if (phone == null) { |
| 8676 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8677 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8678 | } |
| 8679 | return phone.getEmergencyNumberDbVersion(); |
| 8680 | } finally { |
| 8681 | Binder.restoreCallingIdentity(identity); |
| 8682 | } |
| 8683 | } |
| 8684 | |
| 8685 | @Override |
| 8686 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8687 | enforceModifyPermission(); |
| 8688 | |
| 8689 | final long identity = Binder.clearCallingIdentity(); |
| 8690 | try { |
| 8691 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8692 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8693 | if (tracker != null) { |
| 8694 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8695 | } |
| 8696 | } |
| 8697 | } finally { |
| 8698 | Binder.restoreCallingIdentity(identity); |
| 8699 | } |
| 8700 | } |
| 8701 | |
| 8702 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8703 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8704 | enforceActiveEmergencySessionPermission(); |
| 8705 | |
| 8706 | final long identity = Binder.clearCallingIdentity(); |
| 8707 | try { |
| 8708 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8709 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8710 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8711 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8712 | } |
| 8713 | } |
| 8714 | } finally { |
| 8715 | Binder.restoreCallingIdentity(identity); |
| 8716 | } |
| 8717 | } |
| 8718 | |
| 8719 | @Override |
| 8720 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8721 | enforceActiveEmergencySessionPermission(); |
| 8722 | |
| 8723 | final long identity = Binder.clearCallingIdentity(); |
| 8724 | try { |
| 8725 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8726 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8727 | if (tracker != null) { |
| 8728 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8729 | } |
| 8730 | } |
| 8731 | } finally { |
| 8732 | Binder.restoreCallingIdentity(identity); |
| 8733 | } |
| 8734 | } |
| 8735 | |
| 8736 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8737 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8738 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8739 | Phone phone = getPhone(subId); |
| 8740 | if (phone == null) { |
| 8741 | return null; |
| 8742 | } |
| 8743 | final long identity = Binder.clearCallingIdentity(); |
| 8744 | try { |
| 8745 | UiccProfile profile = UiccController.getInstance() |
| 8746 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8747 | if (profile != null) { |
| 8748 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8749 | } |
| 8750 | } finally { |
| 8751 | Binder.restoreCallingIdentity(identity); |
| 8752 | } |
| 8753 | return null; |
| 8754 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8755 | |
| 8756 | /** |
| 8757 | * Enable or disable a modem stack. |
| 8758 | */ |
| 8759 | @Override |
| 8760 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8761 | enforceModifyPermission(); |
| 8762 | |
| 8763 | final long identity = Binder.clearCallingIdentity(); |
| 8764 | try { |
| 8765 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8766 | if (phone == null) { |
| 8767 | return false; |
| 8768 | } else { |
| 8769 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8770 | } |
| 8771 | } finally { |
| 8772 | Binder.restoreCallingIdentity(identity); |
| 8773 | } |
| 8774 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8775 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8776 | /** |
| 8777 | * Whether a modem stack is enabled or not. |
| 8778 | */ |
| 8779 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8780 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8781 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8782 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8783 | if (phone == null) return false; |
| 8784 | |
| 8785 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8786 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8787 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8788 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8789 | } |
| 8790 | |
| 8791 | final long identity = Binder.clearCallingIdentity(); |
| 8792 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8793 | try { |
| 8794 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8795 | } catch (NoSuchElementException ex) { |
| 8796 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8797 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8798 | } finally { |
| 8799 | Binder.restoreCallingIdentity(identity); |
| 8800 | } |
| 8801 | } |
| 8802 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8803 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8804 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8805 | enforceModifyPermission(); |
| 8806 | |
| 8807 | final long identity = Binder.clearCallingIdentity(); |
| 8808 | try { |
| 8809 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8810 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8811 | .commit(); |
| 8812 | } finally { |
| 8813 | Binder.restoreCallingIdentity(identity); |
| 8814 | } |
| 8815 | } |
| 8816 | |
| 8817 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8818 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8819 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8820 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8821 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8822 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8823 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8824 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8825 | |
| 8826 | final long identity = Binder.clearCallingIdentity(); |
| 8827 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8828 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8829 | } finally { |
| 8830 | Binder.restoreCallingIdentity(identity); |
| 8831 | } |
| 8832 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8833 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8834 | @TelephonyManager.IsMultiSimSupportedResult |
| 8835 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8836 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8837 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8838 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8839 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8840 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8841 | } |
| 8842 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8843 | // supported by the modem, indicate that it is restricted. |
| 8844 | PhoneCapability staticCapability = |
| 8845 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8846 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8847 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8848 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8849 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 8850 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8851 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8852 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8853 | } |
| 8854 | // Check if support of multiple SIMs is restricted by carrier |
| 8855 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8856 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8857 | } |
| 8858 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8859 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8860 | } |
| 8861 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8862 | /** |
| 8863 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8864 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8865 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8866 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8867 | * @param numOfSims number of active sims we want to switch to |
| 8868 | */ |
| 8869 | @Override |
| 8870 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8871 | if (numOfSims == 1) { |
| 8872 | enforceModifyPermission(); |
| 8873 | } else { |
| 8874 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8875 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8876 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8877 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8878 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8879 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8880 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8881 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8882 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8883 | return; |
| 8884 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8885 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8886 | } finally { |
| 8887 | Binder.restoreCallingIdentity(identity); |
| 8888 | } |
| 8889 | } |
| 8890 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8891 | @Override |
| 8892 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8893 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8894 | Phone phone = getPhone(subId); |
| 8895 | if (phone == null) { |
| 8896 | return false; |
| 8897 | } |
| 8898 | final long identity = Binder.clearCallingIdentity(); |
| 8899 | try { |
| 8900 | UiccCard uiccCard = phone.getUiccCard(); |
| 8901 | if (uiccCard == null) { |
| 8902 | return false; |
| 8903 | } |
| 8904 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8905 | if (uiccProfile == null) { |
| 8906 | return false; |
| 8907 | } |
| 8908 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8909 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8910 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8911 | } |
| 8912 | return false; |
| 8913 | } finally { |
| 8914 | Binder.restoreCallingIdentity(identity); |
| 8915 | } |
| 8916 | } |
| 8917 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8918 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8919 | * Get whether making changes to modem configurations will trigger reboot. |
| 8920 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8921 | */ |
| 8922 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8923 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8924 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8925 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8926 | mApp, subId, callingPackage, callingFeatureId, |
| 8927 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8928 | return false; |
| 8929 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8930 | final long identity = Binder.clearCallingIdentity(); |
| 8931 | try { |
| 8932 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8933 | } finally { |
| 8934 | Binder.restoreCallingIdentity(identity); |
| 8935 | } |
| 8936 | } |
| 8937 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8938 | private void updateModemStateMetrics() { |
| 8939 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8940 | // TODO: check the state for each modem if the api is ready. |
| 8941 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8942 | } |
| 8943 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8944 | @Override |
| 8945 | public int[] getSlotsMapping() { |
| 8946 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8947 | |
| 8948 | final long identity = Binder.clearCallingIdentity(); |
| 8949 | try { |
| 8950 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8951 | // All logical slots should have a mapping to a physical slot. |
| 8952 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8953 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8954 | for (int i = 0; i < slotInfos.length; i++) { |
| 8955 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8956 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8957 | } |
| 8958 | } |
| 8959 | return logicalSlotsMapping; |
| 8960 | } finally { |
| 8961 | Binder.restoreCallingIdentity(identity); |
| 8962 | } |
| 8963 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8964 | |
| 8965 | /** |
| 8966 | * Get the IRadio HAL Version |
| 8967 | */ |
| 8968 | @Override |
| 8969 | public int getRadioHalVersion() { |
| 8970 | Phone phone = getDefaultPhone(); |
| 8971 | if (phone == null) return -1; |
| 8972 | HalVersion hv = phone.getHalVersion(); |
| 8973 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8974 | return hv.major * 100 + hv.minor; |
| 8975 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8976 | |
| 8977 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8978 | * Get the current calling package name. |
| 8979 | * @return the current calling package name |
| 8980 | */ |
| 8981 | @Override |
| 8982 | public String getCurrentPackageName() { |
| 8983 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8984 | } |
| 8985 | |
| 8986 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8987 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8988 | * corresponding network requests on a subId. |
| 8989 | * |
| 8990 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8991 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8992 | * 2) APN is un-metered for this subscription, or |
| 8993 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8994 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8995 | * |
| 8996 | * @return whether data is allowed for a apn type. |
| 8997 | * |
| 8998 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8999 | */ |
| 9000 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9001 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9002 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9003 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9004 | |
| 9005 | // Now that all security checks passes, perform the operation as ourselves. |
| 9006 | final long identity = Binder.clearCallingIdentity(); |
| 9007 | try { |
| 9008 | Phone phone = getPhone(subId); |
| 9009 | if (phone == null) return false; |
| 9010 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9011 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9012 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 9013 | } finally { |
| 9014 | Binder.restoreCallingIdentity(identity); |
| 9015 | } |
| 9016 | } |
| 9017 | |
| 9018 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9019 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9020 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9021 | |
| 9022 | // Now that all security checks passes, perform the operation as ourselves. |
| 9023 | final long identity = Binder.clearCallingIdentity(); |
| 9024 | try { |
| 9025 | Phone phone = getPhone(subId); |
| 9026 | if (phone == null) return true; // By default return true. |
| 9027 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9028 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9029 | } finally { |
| 9030 | Binder.restoreCallingIdentity(identity); |
| 9031 | } |
| 9032 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9033 | |
| 9034 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9035 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9036 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9037 | enforceModifyPermission(); |
| 9038 | long token = Binder.clearCallingIdentity(); |
| 9039 | try { |
| 9040 | Phone phone = getPhone(subscriptionId); |
| 9041 | if (phone == null) { |
| 9042 | try { |
| 9043 | if (resultCallback != null) { |
| 9044 | resultCallback.accept(false); |
| 9045 | } |
| 9046 | } catch (RemoteException e) { |
| 9047 | // ignore |
| 9048 | } |
| 9049 | return; |
| 9050 | } |
| 9051 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9052 | Pair.create(specifiers, (x) -> { |
| 9053 | try { |
| 9054 | if (resultCallback != null) { |
| 9055 | resultCallback.accept(x); |
| 9056 | } |
| 9057 | } catch (RemoteException e) { |
| 9058 | // ignore |
| 9059 | } |
| 9060 | }); |
| 9061 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9062 | } finally { |
| 9063 | Binder.restoreCallingIdentity(token); |
| 9064 | } |
| 9065 | } |
| 9066 | |
| 9067 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9068 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9069 | TelephonyPermissions |
| 9070 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 9071 | mApp, subId, "getSystemSelectionChannels"); |
| 9072 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9073 | final long identity = Binder.clearCallingIdentity(); |
| 9074 | try { |
| 9075 | List<RadioAccessSpecifier> specifiers = |
| 9076 | (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, |
| 9077 | null, subId, workSource); |
| 9078 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9079 | return specifiers; |
| 9080 | } finally { |
| 9081 | Binder.restoreCallingIdentity(identity); |
| 9082 | } |
| 9083 | } |
| 9084 | |
| 9085 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9086 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9087 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9088 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9089 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9090 | if (iccRecords == null) { |
| 9091 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9092 | return false; |
| 9093 | } |
| 9094 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9095 | } |
| 9096 | |
| 9097 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9098 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9099 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9100 | if (callingPackage == null) { |
| 9101 | callingPackage = getCurrentPackageName(); |
| 9102 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9103 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9104 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9105 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9106 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9107 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9108 | } |
| 9109 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9110 | Intent intent = new Intent(); |
| 9111 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9112 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9113 | // Bring up choose default SMS subscription dialog right now |
| 9114 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9115 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9116 | mApp.startActivity(intent); |
| 9117 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9118 | |
| 9119 | @Override |
| 9120 | public String getMmsUAProfUrl(int subId) { |
| 9121 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9122 | final long identity = Binder.clearCallingIdentity(); |
| 9123 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9124 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9125 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9126 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9127 | return carrierUAProfUrl; |
| 9128 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9129 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9130 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9131 | } finally { |
| 9132 | Binder.restoreCallingIdentity(identity); |
| 9133 | } |
| 9134 | } |
| 9135 | |
| 9136 | @Override |
| 9137 | public String getMmsUserAgent(int subId) { |
| 9138 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9139 | final long identity = Binder.clearCallingIdentity(); |
| 9140 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9141 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9142 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9143 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9144 | return carrierUserAgent; |
| 9145 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9146 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9147 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9148 | } finally { |
| 9149 | Binder.restoreCallingIdentity(identity); |
| 9150 | } |
| 9151 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9152 | |
| 9153 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9154 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9155 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9156 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9157 | final long identity = Binder.clearCallingIdentity(); |
| 9158 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9159 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9160 | if (phone == null) return false; |
| 9161 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9162 | switch (policy) { |
| 9163 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9164 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9165 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9166 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9167 | default: |
| 9168 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9169 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9170 | } finally { |
| 9171 | Binder.restoreCallingIdentity(identity); |
| 9172 | } |
| 9173 | } |
| 9174 | |
| 9175 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9176 | public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy, |
| 9177 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9178 | enforceModifyPermission(); |
| 9179 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9180 | final long identity = Binder.clearCallingIdentity(); |
| 9181 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9182 | Phone phone = getPhone(subscriptionId); |
| 9183 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9184 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9185 | switch (policy) { |
| 9186 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9187 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9188 | break; |
| 9189 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9190 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9191 | break; |
| 9192 | default: |
| 9193 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9194 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9195 | } finally { |
| 9196 | Binder.restoreCallingIdentity(identity); |
| 9197 | } |
| 9198 | } |
| 9199 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9200 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9201 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9202 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9203 | * otherwise. |
| 9204 | */ |
| 9205 | @Override |
| 9206 | public void setCepEnabled(boolean isCepEnabled) { |
| 9207 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9208 | |
| 9209 | final long identity = Binder.clearCallingIdentity(); |
| 9210 | try { |
| 9211 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9212 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9213 | Phone defaultPhone = phone.getImsPhone(); |
| 9214 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9215 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9216 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9217 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9218 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9219 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9220 | + imsPhone.getMsisdn()); |
| 9221 | } |
| 9222 | } |
| 9223 | } finally { |
| 9224 | Binder.restoreCallingIdentity(identity); |
| 9225 | } |
| 9226 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9227 | |
| 9228 | /** |
| 9229 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9230 | * |
| 9231 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9232 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9233 | * before being read. |
| 9234 | */ |
| 9235 | @Override |
| 9236 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9237 | isCompressed) { |
| 9238 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9239 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9240 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9241 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9242 | } |
| 9243 | if (!isImsAvailableOnDevice()) { |
| 9244 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9245 | "IMS not available on device."); |
| 9246 | } |
| 9247 | |
| 9248 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9249 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9250 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9251 | } finally { |
| 9252 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9253 | } |
| 9254 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9255 | |
| 9256 | @Override |
| 9257 | public boolean isIccLockEnabled(int subId) { |
| 9258 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9259 | |
| 9260 | // Now that all security checks passes, perform the operation as ourselves. |
| 9261 | final long identity = Binder.clearCallingIdentity(); |
| 9262 | try { |
| 9263 | Phone phone = getPhone(subId); |
| 9264 | if (phone != null && phone.getIccCard() != null) { |
| 9265 | return phone.getIccCard().getIccLockEnabled(); |
| 9266 | } else { |
| 9267 | return false; |
| 9268 | } |
| 9269 | } finally { |
| 9270 | Binder.restoreCallingIdentity(identity); |
| 9271 | } |
| 9272 | } |
| 9273 | |
| 9274 | /** |
| 9275 | * Set the ICC pin lock enabled or disabled. |
| 9276 | * |
| 9277 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9278 | * three cases: |
| 9279 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9280 | * successfully. |
| 9281 | * - Positive number and zero for remaining password attempts. |
| 9282 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9283 | * |
| 9284 | */ |
| 9285 | @Override |
| 9286 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9287 | enforceModifyPermission(); |
| 9288 | |
| 9289 | Phone phone = getPhone(subId); |
| 9290 | if (phone == null) { |
| 9291 | return 0; |
| 9292 | } |
| 9293 | // Now that all security checks passes, perform the operation as ourselves. |
| 9294 | final long identity = Binder.clearCallingIdentity(); |
| 9295 | try { |
| 9296 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9297 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9298 | return attemptsRemaining; |
| 9299 | |
| 9300 | } catch (Exception e) { |
| 9301 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9302 | } finally { |
| 9303 | Binder.restoreCallingIdentity(identity); |
| 9304 | } |
| 9305 | return 0; |
| 9306 | } |
| 9307 | |
| 9308 | /** |
| 9309 | * Change the ICC password used in ICC pin lock. |
| 9310 | * |
| 9311 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9312 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9313 | * - Positive number and zero for remaining password attempts. |
| 9314 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9315 | * |
| 9316 | */ |
| 9317 | @Override |
| 9318 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9319 | enforceModifyPermission(); |
| 9320 | |
| 9321 | Phone phone = getPhone(subId); |
| 9322 | if (phone == null) { |
| 9323 | return 0; |
| 9324 | } |
| 9325 | // Now that all security checks passes, perform the operation as ourselves. |
| 9326 | final long identity = Binder.clearCallingIdentity(); |
| 9327 | try { |
| 9328 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9329 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9330 | return attemptsRemaining; |
| 9331 | |
| 9332 | } catch (Exception e) { |
| 9333 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9334 | } finally { |
| 9335 | Binder.restoreCallingIdentity(identity); |
| 9336 | } |
| 9337 | return 0; |
| 9338 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9339 | |
| 9340 | /** |
| 9341 | * Request for receiving user activity notification |
| 9342 | */ |
| 9343 | @Override |
| 9344 | public void requestUserActivityNotification() { |
| 9345 | if (!mNotifyUserActivity.get() |
| 9346 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9347 | mNotifyUserActivity.set(true); |
| 9348 | } |
| 9349 | } |
| 9350 | |
| 9351 | /** |
| 9352 | * Called when userActivity is signalled in the power manager. |
| 9353 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9354 | */ |
| 9355 | @Override |
| 9356 | public void userActivity() { |
| 9357 | // *************************************** |
| 9358 | // * Inherited from PhoneWindowManager * |
| 9359 | // *************************************** |
| 9360 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9361 | // WITH ITS LOCKS HELD. |
| 9362 | // |
| 9363 | // This code must be VERY careful about the locks |
| 9364 | // it acquires. |
| 9365 | // In fact, the current code acquires way too many, |
| 9366 | // and probably has lurking deadlocks. |
| 9367 | |
| 9368 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9369 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9370 | } |
| 9371 | |
| 9372 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9373 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9374 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9375 | } |
| 9376 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9377 | |
| 9378 | @Override |
| 9379 | public boolean canConnectTo5GInDsdsMode() { |
| 9380 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9381 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9382 | |
| 9383 | @Override |
| 9384 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9385 | String callingFeatureId) { |
| 9386 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9387 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9388 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9389 | } |
| 9390 | |
| 9391 | Phone phone = getPhone(subId); |
| 9392 | if (phone == null) { |
| 9393 | throw new RuntimeException("phone is not available"); |
| 9394 | } |
| 9395 | // Now that all security checks passes, perform the operation as ourselves. |
| 9396 | final long identity = Binder.clearCallingIdentity(); |
| 9397 | try { |
| 9398 | return phone.getEquivalentHomePlmns(); |
| 9399 | } finally { |
| 9400 | Binder.restoreCallingIdentity(identity); |
| 9401 | } |
| 9402 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9403 | |
| 9404 | @Override |
| 9405 | public boolean isRadioInterfaceCapabilitySupported( |
| 9406 | @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 9407 | RadioInterfaceCapabilities radioInterfaceCapabilities = |
| 9408 | mPhoneConfigurationManager.getRadioInterfaceCapabilities(); |
| 9409 | if (radioInterfaceCapabilities == null) { |
| 9410 | throw new RuntimeException("radio interface capabilities are not available"); |
| 9411 | } else { |
| 9412 | return radioInterfaceCapabilities.isSupported(capability); |
| 9413 | } |
| 9414 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9415 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9416 | @Override |
| 9417 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 9418 | UaSecurityProtocolIdentifier securityProtocol, |
| 9419 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) |
| 9420 | throws RemoteException { |
| 9421 | enforceModifyPermission(); |
| 9422 | if (DBG) { |
| 9423 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 9424 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 9425 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 9426 | } |
| 9427 | |
| 9428 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 9429 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 9430 | || appType > TelephonyManager.APPTYPE_ISIM |
| 9431 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 9432 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 9433 | if (callback != null) { |
| 9434 | try { |
| 9435 | callback.onAuthenticationFailure( |
| 9436 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 9437 | } catch (RemoteException exception) { |
| 9438 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 9439 | } |
| 9440 | return; |
| 9441 | } |
| 9442 | } |
| 9443 | |
| 9444 | final long token = Binder.clearCallingIdentity(); |
| 9445 | try { |
| 9446 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 9447 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 9448 | forceBootStrapping, callback)); |
| 9449 | } finally { |
| 9450 | Binder.restoreCallingIdentity(token); |
| 9451 | } |
| 9452 | } |
| 9453 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9454 | /** |
| 9455 | * Attempts to set the radio power state for thermal reason. This does not guarantee that the |
| 9456 | * requested radio power state will actually be set. See {@link |
| 9457 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9458 | * |
| 9459 | * @param subId the subscription ID of the phone requesting to set the radio power state. |
| 9460 | * @param enable {@code true} if trying to turn radio on. |
| 9461 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9462 | * false}. |
| 9463 | */ |
| 9464 | private boolean setRadioPowerForThermal(int subId, boolean enable) { |
| 9465 | Phone phone = getPhone(subId); |
| 9466 | if (phone != null) { |
| 9467 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 9468 | return true; |
| 9469 | } |
| 9470 | return false; |
| 9471 | } |
| 9472 | |
| 9473 | private int handleDataThrottlingRequest(int subId, |
| 9474 | DataThrottlingRequest dataThrottlingRequest) { |
| 9475 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 9476 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9477 | if (!setRadioPowerForThermal(subId, true)) { |
| 9478 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9479 | } |
| 9480 | |
| 9481 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 9482 | |
| 9483 | int thermalMitigationResult = |
| 9484 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
| 9485 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 9486 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 9487 | } |
| 9488 | return thermalMitigationResult; |
| 9489 | } |
| 9490 | |
| 9491 | /** |
| 9492 | * Thermal mitigation request to control functionalities at modem. |
| 9493 | * |
| 9494 | * @param subId the id of the subscription. |
| 9495 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
| 9496 | * |
| 9497 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 9498 | */ |
| 9499 | @Override |
| 9500 | @ThermalMitigationResult |
| 9501 | public int sendThermalMitigationRequest( |
| 9502 | int subId, |
| 9503 | ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException { |
| 9504 | enforceModifyPermission(); |
| 9505 | |
| 9506 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9507 | final long identity = Binder.clearCallingIdentity(); |
| 9508 | |
| 9509 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 9510 | try { |
| 9511 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 9512 | switch (thermalMitigationAction) { |
| 9513 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 9514 | thermalMitigationResult = |
| 9515 | handleDataThrottlingRequest(subId, |
| 9516 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 9517 | break; |
| 9518 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 9519 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9520 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 9521 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 9522 | } |
| 9523 | |
| 9524 | // Ensure that radio is on. If not able to power on due to phone being |
| 9525 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9526 | if (!setRadioPowerForThermal(subId, true)) { |
| 9527 | thermalMitigationResult = |
| 9528 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9529 | break; |
| 9530 | } |
| 9531 | |
| 9532 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 9533 | false); |
| 9534 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9535 | break; |
| 9536 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 9537 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9538 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 9539 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 9540 | } |
| 9541 | |
| 9542 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 9543 | if (registry != null) { |
| 9544 | TelephonyConnectionService service = |
| 9545 | registry.getTelephonyConnectionService(); |
| 9546 | Phone phone = getPhone(subId); |
| 9547 | if (phone == null) { |
| 9548 | thermalMitigationResult = |
| 9549 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9550 | break; |
| 9551 | } |
| 9552 | |
| 9553 | if (PhoneConstantConversions.convertCallState(phone.getState()) |
| 9554 | != TelephonyManager.CALL_STATE_IDLE |
| 9555 | || phone.isInEmergencySmsMode() || phone.isInEcm() |
| 9556 | || (service != null && service.isEmergencyCallPending())) { |
| 9557 | String errorMessage = "Phone state is not valid. call state = " |
| 9558 | + PhoneConstantConversions.convertCallState(phone.getState()) |
| 9559 | + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode() |
| 9560 | + " isInEmergencyCallbackMode = " + phone.isInEcm(); |
| 9561 | errorMessage += service == null |
| 9562 | ? " TelephonyConnectionService is null" |
| 9563 | : " isEmergencyCallPending = " |
| 9564 | + service.isEmergencyCallPending(); |
| 9565 | Log.e(LOG_TAG, errorMessage); |
| 9566 | thermalMitigationResult = |
| 9567 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 9568 | break; |
| 9569 | } |
| 9570 | } else { |
| 9571 | thermalMitigationResult = |
| 9572 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9573 | break; |
| 9574 | } |
| 9575 | |
| 9576 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 9577 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9578 | if (!setRadioPowerForThermal(subId, false)) { |
| 9579 | thermalMitigationResult = |
| 9580 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9581 | break; |
| 9582 | } |
| 9583 | thermalMitigationResult = |
| 9584 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9585 | break; |
| 9586 | default: |
| 9587 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 9588 | + "not exist. Requested action: " + thermalMitigationAction); |
| 9589 | } |
| 9590 | } catch (IllegalArgumentException e) { |
| 9591 | throw e; |
| 9592 | } catch (Exception e) { |
| 9593 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 9594 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 9595 | } finally { |
| 9596 | Binder.restoreCallingIdentity(identity); |
| 9597 | } |
| 9598 | |
| 9599 | if (DBG) { |
| 9600 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 9601 | + thermalMitigationResult); |
| 9602 | } |
| 9603 | |
| 9604 | return thermalMitigationResult; |
| 9605 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9606 | |
| 9607 | /** |
| 9608 | * Set the GbaService Package Name that Telephony will bind to. |
| 9609 | * |
| 9610 | * @param subId The sim that the GbaService is associated with. |
| 9611 | * @param packageName The name of the package to be replaced with. |
| 9612 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9613 | */ |
| 9614 | @Override |
| 9615 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 9616 | enforceModifyPermission(); |
| 9617 | |
| 9618 | final long identity = Binder.clearCallingIdentity(); |
| 9619 | try { |
| 9620 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 9621 | } finally { |
| 9622 | Binder.restoreCallingIdentity(identity); |
| 9623 | } |
| 9624 | } |
| 9625 | |
| 9626 | /** |
| 9627 | * Return the package name of the currently bound GbaService. |
| 9628 | * |
| 9629 | * @param subId The sim that the GbaService is associated with. |
| 9630 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 9631 | */ |
| 9632 | @Override |
| 9633 | public String getBoundGbaService(int subId) { |
| 9634 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 9635 | |
| 9636 | final long identity = Binder.clearCallingIdentity(); |
| 9637 | try { |
| 9638 | return getGbaManager(subId).getServicePackage(); |
| 9639 | } finally { |
| 9640 | Binder.restoreCallingIdentity(identity); |
| 9641 | } |
| 9642 | } |
| 9643 | |
| 9644 | /** |
| 9645 | * Set the release time for telephony to unbind GbaService. |
| 9646 | * |
| 9647 | * @param subId The sim that the GbaService is associated with. |
| 9648 | * @param interval The release time to unbind GbaService by millisecond. |
| 9649 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9650 | */ |
| 9651 | @Override |
| 9652 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 9653 | enforceModifyPermission(); |
| 9654 | |
| 9655 | final long identity = Binder.clearCallingIdentity(); |
| 9656 | try { |
| 9657 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 9658 | } finally { |
| 9659 | Binder.restoreCallingIdentity(identity); |
| 9660 | } |
| 9661 | } |
| 9662 | |
| 9663 | /** |
| 9664 | * Return the release time for telephony to unbind GbaService. |
| 9665 | * |
| 9666 | * @param subId The sim that the GbaService is associated with. |
| 9667 | * @return The release time to unbind GbaService by millisecond. |
| 9668 | */ |
| 9669 | @Override |
| 9670 | public int getGbaReleaseTime(int subId) { |
| 9671 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 9672 | |
| 9673 | final long identity = Binder.clearCallingIdentity(); |
| 9674 | try { |
| 9675 | return getGbaManager(subId).getReleaseTime(); |
| 9676 | } finally { |
| 9677 | Binder.restoreCallingIdentity(identity); |
| 9678 | } |
| 9679 | } |
| 9680 | |
| 9681 | private GbaManager getGbaManager(int subId) { |
| 9682 | GbaManager instance = GbaManager.getInstance(subId); |
| 9683 | if (instance == null) { |
| 9684 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 9685 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 9686 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 9687 | } |
| 9688 | return instance; |
| 9689 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9690 | |
| 9691 | /** |
| 9692 | * indicate whether the device and the carrier can support |
| 9693 | * RCS VoLTE single registration. |
| 9694 | */ |
| 9695 | @Override |
| 9696 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
| 9697 | enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable"); |
| 9698 | |
| 9699 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9700 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9701 | } |
| 9702 | |
| 9703 | final long identity = Binder.clearCallingIdentity(); |
| 9704 | try { |
| 9705 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 9706 | if (rpm != null) { |
| 9707 | return rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 9708 | } |
| 9709 | return false; |
| 9710 | } finally { |
| 9711 | Binder.restoreCallingIdentity(identity); |
| 9712 | } |
| 9713 | } |
| 9714 | |
| 9715 | /** |
| 9716 | * Register RCS provisioning callback. |
| 9717 | */ |
| 9718 | @Override |
| 9719 | public void registerRcsProvisioningChangedCallback(int subId, |
| 9720 | IRcsConfigCallback callback) { |
| 9721 | enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback"); |
| 9722 | |
| 9723 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9724 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9725 | } |
| 9726 | if (!isImsAvailableOnDevice()) { |
| 9727 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9728 | "IMS not available on device."); |
| 9729 | } |
| 9730 | |
| 9731 | final long identity = Binder.clearCallingIdentity(); |
| 9732 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9733 | if (!RcsProvisioningMonitor.getInstance() |
| 9734 | .registerRcsProvisioningChangedCallback(subId, callback)) { |
| 9735 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9736 | "Service not available for the subscription."); |
| 9737 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9738 | } finally { |
| 9739 | Binder.restoreCallingIdentity(identity); |
| 9740 | } |
| 9741 | } |
| 9742 | |
| 9743 | /** |
| 9744 | * Unregister RCS provisioning callback. |
| 9745 | */ |
| 9746 | @Override |
| 9747 | public void unregisterRcsProvisioningChangedCallback(int subId, |
| 9748 | IRcsConfigCallback callback) { |
| 9749 | enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback"); |
| 9750 | |
| 9751 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9752 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9753 | } |
| 9754 | if (!isImsAvailableOnDevice()) { |
| 9755 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9756 | "IMS not available on device."); |
| 9757 | } |
| 9758 | |
| 9759 | final long identity = Binder.clearCallingIdentity(); |
| 9760 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9761 | RcsProvisioningMonitor.getInstance() |
| 9762 | .unregisterRcsProvisioningChangedCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9763 | } finally { |
| 9764 | Binder.restoreCallingIdentity(identity); |
| 9765 | } |
| 9766 | } |
| 9767 | |
| 9768 | /** |
| 9769 | * trigger RCS reconfiguration. |
| 9770 | */ |
| 9771 | public void triggerRcsReconfiguration(int subId) { |
| 9772 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9773 | mApp, subId, "triggerRcsReconfiguration"); |
| 9774 | |
| 9775 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9776 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9777 | } |
| 9778 | if (!isImsAvailableOnDevice()) { |
| 9779 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9780 | "IMS not available on device."); |
| 9781 | } |
| 9782 | |
| 9783 | final long identity = Binder.clearCallingIdentity(); |
| 9784 | try { |
| 9785 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 9786 | } finally { |
| 9787 | Binder.restoreCallingIdentity(identity); |
| 9788 | } |
| 9789 | } |
| 9790 | |
| 9791 | /** |
| 9792 | * Provide the client configuration parameters of the RCS application. |
| 9793 | */ |
| 9794 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
| 9795 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9796 | mApp, subId, "setRcsClientConfiguration"); |
| 9797 | |
| 9798 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9799 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9800 | } |
| 9801 | if (!isImsAvailableOnDevice()) { |
| 9802 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9803 | "IMS not available on device."); |
| 9804 | } |
| 9805 | |
| 9806 | final long identity = Binder.clearCallingIdentity(); |
| 9807 | |
| 9808 | try { |
| 9809 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 9810 | if (configBinder == null) { |
| 9811 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
| 9812 | } else { |
| 9813 | configBinder.setRcsClientConfiguration(rcc); |
| 9814 | } |
| 9815 | } catch (RemoteException e) { |
| 9816 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
| 9817 | } finally { |
| 9818 | Binder.restoreCallingIdentity(identity); |
| 9819 | } |
| 9820 | } |
| 9821 | |
| 9822 | /** |
| 9823 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 9824 | */ |
| 9825 | @Override |
| 9826 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 9827 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9828 | "setDeviceSingleRegistrationEnabledOverride"); |
| 9829 | enforceModifyPermission(); |
| 9830 | |
| 9831 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9832 | : Boolean.parseBoolean(enabledStr); |
| 9833 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
| 9834 | } |
| 9835 | |
| 9836 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 9837 | * Sends a device to device communication message. Only usable via shell. |
| 9838 | * @param message message to send. |
| 9839 | * @param value message value. |
| 9840 | */ |
| 9841 | @Override |
| 9842 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 9843 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9844 | "setCarrierSingleRegistrationEnabledOverride"); |
| 9845 | enforceModifyPermission(); |
| 9846 | |
| 9847 | final long identity = Binder.clearCallingIdentity(); |
| 9848 | try { |
| 9849 | TelephonyConnectionService service = |
| 9850 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 9851 | if (service == null) { |
| 9852 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 9853 | return; |
| 9854 | } |
| 9855 | service.sendTestDeviceToDeviceMessage(message, value); |
| 9856 | } finally { |
| 9857 | Binder.restoreCallingIdentity(identity); |
| 9858 | } |
| 9859 | } |
| 9860 | |
| 9861 | |
| 9862 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9863 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 9864 | */ |
| 9865 | @Override |
| 9866 | public boolean getDeviceSingleRegistrationEnabled() { |
| 9867 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 9868 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 9869 | } |
| 9870 | |
| 9871 | /** |
| 9872 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9873 | */ |
| 9874 | @Override |
| 9875 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 9876 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9877 | "setCarrierSingleRegistrationEnabledOverride"); |
| 9878 | enforceModifyPermission(); |
| 9879 | |
| 9880 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9881 | : Boolean.parseBoolean(enabledStr); |
| 9882 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 9883 | subId, enabled); |
| 9884 | } |
| 9885 | |
| 9886 | /** |
| 9887 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9888 | */ |
| 9889 | @Override |
| 9890 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 9891 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 9892 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 9893 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 9894 | |
| 9895 | /** |
| 9896 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 9897 | * their mobile plan. |
| 9898 | */ |
| 9899 | @Override |
| 9900 | public String getMobileProvisioningUrl() { |
| 9901 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 9902 | final long identity = Binder.clearCallingIdentity(); |
| 9903 | try { |
| 9904 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 9905 | } finally { |
| 9906 | Binder.restoreCallingIdentity(identity); |
| 9907 | } |
| 9908 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 9909 | |
| 9910 | @Override |
| 9911 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 9912 | String callingPackage) { |
| 9913 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9914 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 9915 | |
| 9916 | final int callingUid = Binder.getCallingUid(); |
| 9917 | // Verify that tha callingPackage belongs to the calling UID |
| 9918 | mApp.getSystemService(AppOpsManager.class) |
| 9919 | .checkPackage(callingUid, callingPackage); |
| 9920 | |
| 9921 | validateSignalStrengthUpdateRequest(request, callingUid); |
| 9922 | |
| 9923 | final long identity = Binder.clearCallingIdentity(); |
| 9924 | try { |
| 9925 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 9926 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 9927 | |
| 9928 | if (result instanceof IllegalStateException) { |
| 9929 | throw (IllegalStateException) result; |
| 9930 | } |
| 9931 | } finally { |
| 9932 | Binder.restoreCallingIdentity(identity); |
| 9933 | } |
| 9934 | } |
| 9935 | |
| 9936 | @Override |
| 9937 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 9938 | String callingPackage) { |
| 9939 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9940 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 9941 | |
| 9942 | final int callingUid = Binder.getCallingUid(); |
| 9943 | // Verify that tha callingPackage belongs to the calling UID |
| 9944 | mApp.getSystemService(AppOpsManager.class) |
| 9945 | .checkPackage(callingUid, callingPackage); |
| 9946 | |
| 9947 | final long identity = Binder.clearCallingIdentity(); |
| 9948 | try { |
| 9949 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 9950 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 9951 | |
| 9952 | if (result instanceof IllegalStateException) { |
| 9953 | throw (IllegalStateException) result; |
| 9954 | } |
| 9955 | } finally { |
| 9956 | Binder.restoreCallingIdentity(identity); |
| 9957 | } |
| 9958 | } |
| 9959 | |
| 9960 | private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request, |
| 9961 | int callingUid) { |
| 9962 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 9963 | // phone/system process do not have further restriction on request |
| 9964 | return; |
| 9965 | } |
| 9966 | |
| 9967 | // Applications has restrictions on how to use the request: |
| 9968 | // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle |
| 9969 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
| 9970 | // This is not system caller which has been checked above |
| 9971 | throw new IllegalArgumentException( |
| 9972 | "Only system can set isSystemThresholdReportingRequestedWhileIdle"); |
| 9973 | } |
| 9974 | |
| 9975 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 9976 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 9977 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 9978 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 9979 | || info.isEnabled()) { |
| 9980 | throw new IllegalArgumentException( |
| 9981 | "Only system can set hide fields in SignalThresholdInfo"); |
| 9982 | } |
| 9983 | |
| 9984 | // Thresholds length for each RAN need in range. This has been validated in |
| 9985 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 9986 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 9987 | final int[] thresholds = info.getThresholds(); |
| 9988 | Objects.requireNonNull(thresholds); |
| 9989 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 9990 | || thresholds.length |
| 9991 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 9992 | throw new IllegalArgumentException( |
| 9993 | "thresholds length is out of range: " + thresholds.length); |
| 9994 | } |
| 9995 | } |
| 9996 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9997 | |
| 9998 | /** |
| 9999 | * Gets the current phone capability. |
| 10000 | * |
| 10001 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 10002 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 10003 | * It's used to evaluate possible phone config change, for example from single |
| 10004 | * SIM device to multi-SIM device. |
| 10005 | */ |
| 10006 | @Override |
| 10007 | public PhoneCapability getPhoneCapability() { |
| 10008 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 10009 | final long identity = Binder.clearCallingIdentity(); |
| 10010 | try { |
| 10011 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 10012 | } finally { |
| 10013 | Binder.restoreCallingIdentity(identity); |
| 10014 | } |
| 10015 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 10016 | } |