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; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 29 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 30 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 31 | import android.content.Context; |
| 32 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 33 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 34 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 35 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 36 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 37 | import android.net.Uri; |
| 38 | import android.os.AsyncResult; |
| 39 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 40 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 41 | import android.os.Bundle; |
| 42 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 43 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 44 | import android.os.Looper; |
| 45 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 46 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 47 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 48 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 49 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 50 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 51 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 52 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 53 | import android.os.ServiceSpecificException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 54 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 55 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 56 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 57 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 58 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 59 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 60 | import android.provider.Telephony; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 61 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 62 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 63 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 64 | import android.telecom.TelecomManager; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 65 | import android.telephony.Annotation.ApnType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 66 | import android.telephony.Annotation.ThermalMitigationResult; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 67 | import android.telephony.CallForwardingInfo; |
Sooraj Sasindran | 4deb887 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 68 | import android.telephony.CarrierBandwidth; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 69 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 70 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 71 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 72 | import android.telephony.CellIdentityCdma; |
| 73 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 74 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 75 | import android.telephony.CellInfoGsm; |
| 76 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 77 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 78 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 79 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 80 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 81 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 82 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 83 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 84 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 85 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 86 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 87 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 88 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 89 | import android.telephony.RadioAccessSpecifier; |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 90 | import android.telephony.RadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 91 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 92 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 93 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 94 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 95 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 96 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 97 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 98 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 99 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 100 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 101 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 102 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 103 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 104 | import android.telephony.data.ApnSetting; |
| 105 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 106 | import android.telephony.gba.GbaAuthRequest; |
| 107 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 108 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 109 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 110 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 111 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 112 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 113 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 114 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 115 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 116 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 117 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 118 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 119 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 120 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 121 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 122 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 123 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 124 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 125 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 126 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 127 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 128 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 129 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 130 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 131 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 132 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 135 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 138 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.GbaManager; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 141 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 142 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 145 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 147 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 153 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 162 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 163 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 164 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 168 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 170 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 171 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 174 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 175 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 176 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 178 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 179 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 180 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 181 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 182 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 183 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 184 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 185 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 186 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 187 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 188 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 189 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 190 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 191 | import com.android.services.telephony.TelecomAccountRegistry; |
| 192 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 193 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 194 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 195 | import java.io.FileDescriptor; |
| 196 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 197 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 198 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 199 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 200 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 201 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 202 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 203 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 204 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 205 | import java.util.Set; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 206 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 207 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 208 | |
| 209 | /** |
| 210 | * Implementation of the ITelephony interface. |
| 211 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 212 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 213 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 214 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 215 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 216 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 217 | |
| 218 | // Message codes used with mMainThreadHandler |
| 219 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 220 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 221 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 222 | private static final int CMD_OPEN_CHANNEL = 9; |
| 223 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 224 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 225 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 226 | private static final int CMD_NV_READ_ITEM = 13; |
| 227 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 228 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 229 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 230 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 231 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 232 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 233 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 234 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 235 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 236 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 237 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 238 | private static final int CMD_SEND_ENVELOPE = 25; |
| 239 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 240 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 241 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 242 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 243 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 244 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 245 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 246 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 247 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 248 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 249 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 250 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 251 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 252 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 253 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 254 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 255 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 256 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 257 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 258 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 259 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 260 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 261 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 262 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 263 | private static final int CMD_SWITCH_SLOTS = 50; |
| 264 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 265 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 266 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 267 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 268 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 269 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 270 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 271 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 272 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 273 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 274 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 275 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 276 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 277 | private static final int CMD_MODEM_REBOOT = 64; |
| 278 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 279 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 280 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 281 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 282 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 283 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 284 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 285 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 286 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 287 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 288 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 289 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 290 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 291 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 292 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 293 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 294 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 295 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 296 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 297 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 298 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 299 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 300 | private static final int CMD_GET_CALL_WAITING = 87; |
| 301 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 302 | private static final int CMD_SET_CALL_WAITING = 89; |
| 303 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 304 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 305 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 306 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 307 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 308 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 309 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 310 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 311 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 312 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 313 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 314 | private static final int CMD_SET_SIM_POWER = 101; |
| 315 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 316 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 317 | // Parameters of select command. |
| 318 | private static final int SELECT_COMMAND = 0xA4; |
| 319 | private static final int SELECT_P1 = 0x04; |
| 320 | private static final int SELECT_P2 = 0; |
| 321 | private static final int SELECT_P3 = 0x10; |
| 322 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 323 | /** The singleton instance. */ |
| 324 | private static PhoneInterfaceManager sInstance; |
| 325 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 326 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 327 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 328 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 329 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 330 | private AppOpsManager mAppOps; |
| 331 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 332 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 333 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 334 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 335 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 336 | /** User Activity */ |
| 337 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 338 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 339 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 340 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 341 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 342 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 343 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 344 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 345 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 346 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 347 | // String to store multi SIM allowed |
| 348 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 349 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 350 | // The AID of ISD-R. |
| 351 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 352 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 353 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 354 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 355 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 356 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 357 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 358 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
| 359 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 360 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 361 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 362 | */ |
| 363 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 364 | "reset_network_erase_modem_config_enabled"; |
| 365 | |
| 366 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 367 | * A request object to use for transmitting data to an ICC. |
| 368 | */ |
| 369 | private static final class IccAPDUArgument { |
| 370 | public int channel, cla, command, p1, p2, p3; |
| 371 | public String data; |
| 372 | |
| 373 | public IccAPDUArgument(int channel, int cla, int command, |
| 374 | int p1, int p2, int p3, String data) { |
| 375 | this.channel = channel; |
| 376 | this.cla = cla; |
| 377 | this.command = command; |
| 378 | this.p1 = p1; |
| 379 | this.p2 = p2; |
| 380 | this.p3 = p3; |
| 381 | this.data = data; |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 386 | * A request object to use for transmitting data to an ICC. |
| 387 | */ |
| 388 | private static final class ManualNetworkSelectionArgument { |
| 389 | public OperatorInfo operatorInfo; |
| 390 | public boolean persistSelection; |
| 391 | |
| 392 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 393 | this.operatorInfo = operatorInfo; |
| 394 | this.persistSelection = persistSelection; |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 399 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 400 | * request after sending. The main thread will notify the request when it is complete. |
| 401 | */ |
| 402 | private static final class MainThreadRequest { |
| 403 | /** The argument to use for the request */ |
| 404 | public Object argument; |
| 405 | /** The result of the request that is run on the main thread */ |
| 406 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 407 | // The subscriber id that this request applies to. Defaults to |
| 408 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 409 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 410 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 411 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 412 | public Phone phone; |
| 413 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 414 | public WorkSource workSource; |
| 415 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 416 | public MainThreadRequest(Object argument) { |
| 417 | this.argument = argument; |
| 418 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 419 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 420 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 421 | this.argument = argument; |
| 422 | if (phone != null) { |
| 423 | this.phone = phone; |
| 424 | } |
| 425 | this.workSource = workSource; |
| 426 | } |
| 427 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 428 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 429 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 430 | if (subId != null) { |
| 431 | this.subId = subId; |
| 432 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 433 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 434 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 435 | } |
| 436 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 437 | private static final class IncomingThirdPartyCallArgs { |
| 438 | public final ComponentName component; |
| 439 | public final String callId; |
| 440 | public final String callerDisplayName; |
| 441 | |
| 442 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 443 | String callerDisplayName) { |
| 444 | this.component = component; |
| 445 | this.callId = callId; |
| 446 | this.callerDisplayName = callerDisplayName; |
| 447 | } |
| 448 | } |
| 449 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 450 | /** |
| 451 | * A handler that processes messages on the main thread in the phone process. Since many |
| 452 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 453 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 454 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 455 | * on, which will be notified when the operation completes and will contain the result of the |
| 456 | * request. |
| 457 | * |
| 458 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 459 | * note that request.result must be set to something non-null for the calling thread to |
| 460 | * unblock. |
| 461 | */ |
| 462 | private final class MainThreadHandler extends Handler { |
| 463 | @Override |
| 464 | public void handleMessage(Message msg) { |
| 465 | MainThreadRequest request; |
| 466 | Message onCompleted; |
| 467 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 468 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 469 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 470 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 471 | |
| 472 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 473 | case CMD_HANDLE_USSD_REQUEST: { |
| 474 | request = (MainThreadRequest) msg.obj; |
| 475 | final Phone phone = getPhoneFromRequest(request); |
| 476 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 477 | String ussdRequest = ussdObject.first; |
| 478 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 479 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 480 | if (!isUssdApiAllowed(request.subId)) { |
| 481 | // Carrier does not support use of this API, return failure. |
| 482 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 483 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 484 | Bundle returnData = new Bundle(); |
| 485 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 486 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 487 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 488 | request.result = true; |
| 489 | notifyRequester(request); |
| 490 | return; |
| 491 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 492 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 493 | try { |
| 494 | request.result = phone != null |
| 495 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 496 | } catch (CallStateException cse) { |
| 497 | request.result = false; |
| 498 | } |
| 499 | // Wake up the requesting thread |
| 500 | notifyRequester(request); |
| 501 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 502 | } |
| 503 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 504 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 505 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 506 | final Phone phone = getPhoneFromRequest(request); |
| 507 | request.result = phone != null ? |
| 508 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 509 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 510 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 511 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 512 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 513 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 514 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 515 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 516 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 517 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 518 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 519 | if (uiccCard == null) { |
| 520 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 521 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 522 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 523 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 524 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 525 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 526 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 527 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 528 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 529 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 530 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 531 | break; |
| 532 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 533 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 534 | ar = (AsyncResult) msg.obj; |
| 535 | request = (MainThreadRequest) ar.userObj; |
| 536 | if (ar.exception == null && ar.result != null) { |
| 537 | request.result = ar.result; |
| 538 | } else { |
| 539 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 540 | if (ar.result == null) { |
| 541 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 542 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 543 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 544 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 545 | } else { |
| 546 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 547 | } |
| 548 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 549 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 550 | break; |
| 551 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 552 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 553 | request = (MainThreadRequest) msg.obj; |
| 554 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 555 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 556 | if (uiccCard == null) { |
| 557 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 558 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 559 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 560 | } else { |
| 561 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 562 | request); |
| 563 | uiccCard.iccTransmitApduBasicChannel( |
| 564 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 565 | iccArgument.p3, iccArgument.data, onCompleted); |
| 566 | } |
| 567 | break; |
| 568 | |
| 569 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 570 | ar = (AsyncResult) msg.obj; |
| 571 | request = (MainThreadRequest) ar.userObj; |
| 572 | if (ar.exception == null && ar.result != null) { |
| 573 | request.result = ar.result; |
| 574 | } else { |
| 575 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 576 | if (ar.result == null) { |
| 577 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 578 | } else if (ar.exception instanceof CommandException) { |
| 579 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 580 | ar.exception); |
| 581 | } else { |
| 582 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 583 | } |
| 584 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 585 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 586 | break; |
| 587 | |
| 588 | case CMD_EXCHANGE_SIM_IO: |
| 589 | request = (MainThreadRequest) msg.obj; |
| 590 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 591 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 592 | if (uiccCard == null) { |
| 593 | loge("iccExchangeSimIO: No UICC"); |
| 594 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 595 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 596 | } else { |
| 597 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 598 | request); |
| 599 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 600 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 601 | iccArgument.data, onCompleted); |
| 602 | } |
| 603 | break; |
| 604 | |
| 605 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 606 | ar = (AsyncResult) msg.obj; |
| 607 | request = (MainThreadRequest) ar.userObj; |
| 608 | if (ar.exception == null && ar.result != null) { |
| 609 | request.result = ar.result; |
| 610 | } else { |
| 611 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 612 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 613 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 614 | break; |
| 615 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 616 | case CMD_SEND_ENVELOPE: |
| 617 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 618 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 619 | if (uiccCard == null) { |
| 620 | loge("sendEnvelopeWithStatus: No UICC"); |
| 621 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 622 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 623 | } else { |
| 624 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 625 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 626 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 627 | break; |
| 628 | |
| 629 | case EVENT_SEND_ENVELOPE_DONE: |
| 630 | ar = (AsyncResult) msg.obj; |
| 631 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 632 | if (ar.exception == null && ar.result != null) { |
| 633 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 634 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 635 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 636 | if (ar.result == null) { |
| 637 | loge("sendEnvelopeWithStatus: Empty response"); |
| 638 | } else if (ar.exception instanceof CommandException) { |
| 639 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 640 | ar.exception); |
| 641 | } else { |
| 642 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 643 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 644 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 645 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 646 | break; |
| 647 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 648 | case CMD_OPEN_CHANNEL: |
| 649 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 650 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 651 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 652 | if (uiccCard == null) { |
| 653 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 654 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 655 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 656 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 657 | } else { |
| 658 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 659 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 660 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 661 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 662 | break; |
| 663 | |
| 664 | case EVENT_OPEN_CHANNEL_DONE: |
| 665 | ar = (AsyncResult) msg.obj; |
| 666 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 667 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 668 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 669 | int[] result = (int[]) ar.result; |
| 670 | int channelId = result[0]; |
| 671 | byte[] selectResponse = null; |
| 672 | if (result.length > 1) { |
| 673 | selectResponse = new byte[result.length - 1]; |
| 674 | for (int i = 1; i < result.length; ++i) { |
| 675 | selectResponse[i - 1] = (byte) result[i]; |
| 676 | } |
| 677 | } |
| 678 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 679 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 680 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 681 | if (ar.result == null) { |
| 682 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 683 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 684 | if (ar.exception != null) { |
| 685 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 686 | } |
| 687 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 688 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 689 | if (ar.exception instanceof CommandException) { |
| 690 | CommandException.Error error = |
| 691 | ((CommandException) (ar.exception)).getCommandError(); |
| 692 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 693 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 694 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 695 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 696 | } |
| 697 | } |
| 698 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 699 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 700 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 701 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 702 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 703 | break; |
| 704 | |
| 705 | case CMD_CLOSE_CHANNEL: |
| 706 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 707 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 708 | if (uiccCard == null) { |
| 709 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 710 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 711 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 712 | } else { |
| 713 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 714 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 715 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 716 | break; |
| 717 | |
| 718 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 719 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 720 | break; |
| 721 | |
| 722 | case CMD_NV_READ_ITEM: |
| 723 | request = (MainThreadRequest) msg.obj; |
| 724 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 725 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 726 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 727 | break; |
| 728 | |
| 729 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 730 | ar = (AsyncResult) msg.obj; |
| 731 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 732 | if (ar.exception == null && ar.result != null) { |
| 733 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 734 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 735 | request.result = ""; |
| 736 | if (ar.result == null) { |
| 737 | loge("nvReadItem: Empty response"); |
| 738 | } else if (ar.exception instanceof CommandException) { |
| 739 | loge("nvReadItem: CommandException: " + |
| 740 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 741 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 742 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 743 | } |
| 744 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 745 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 746 | break; |
| 747 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 748 | case CMD_NV_WRITE_ITEM: |
| 749 | request = (MainThreadRequest) msg.obj; |
| 750 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 751 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 752 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 753 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 754 | break; |
| 755 | |
| 756 | case EVENT_NV_WRITE_ITEM_DONE: |
| 757 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 758 | break; |
| 759 | |
| 760 | case CMD_NV_WRITE_CDMA_PRL: |
| 761 | request = (MainThreadRequest) msg.obj; |
| 762 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 763 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 764 | break; |
| 765 | |
| 766 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 767 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 768 | break; |
| 769 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 770 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 771 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 772 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 773 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 774 | break; |
| 775 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 776 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 777 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 778 | break; |
| 779 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 780 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 781 | request = (MainThreadRequest) msg.obj; |
| 782 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 783 | request); |
| 784 | Phone phone = getPhoneFromRequest(request); |
| 785 | if (phone != null) { |
| 786 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 787 | } else { |
| 788 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 789 | request.result = false; |
| 790 | notifyRequester(request); |
| 791 | } |
| 792 | break; |
| 793 | } |
| 794 | |
| 795 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 796 | ar = (AsyncResult) msg.obj; |
| 797 | request = (MainThreadRequest) ar.userObj; |
| 798 | if (ar.exception == null && ar.result != null) { |
| 799 | request.result = ar.result; |
| 800 | } else { |
| 801 | // request.result must be set to something non-null |
| 802 | // for the calling thread to unblock |
| 803 | if (request.result != null) { |
| 804 | request.result = ar.result; |
| 805 | } else { |
| 806 | request.result = false; |
| 807 | } |
| 808 | if (ar.result == null) { |
| 809 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 810 | } else if (ar.exception instanceof CommandException) { |
| 811 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 812 | + ar.exception); |
| 813 | } else { |
| 814 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 815 | } |
| 816 | } |
| 817 | notifyRequester(request); |
| 818 | break; |
| 819 | |
| 820 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 821 | request = (MainThreadRequest) msg.obj; |
| 822 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 823 | Phone phone = getPhoneFromRequest(request); |
| 824 | if (phone != null) { |
| 825 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 826 | request.workSource); |
| 827 | } else { |
| 828 | loge("enableNrDualConnectivity: No phone object"); |
| 829 | request.result = |
| 830 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 831 | notifyRequester(request); |
| 832 | } |
| 833 | break; |
| 834 | } |
| 835 | |
| 836 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 837 | ar = (AsyncResult) msg.obj; |
| 838 | request = (MainThreadRequest) ar.userObj; |
| 839 | if (ar.exception == null) { |
| 840 | request.result = |
| 841 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 842 | } else { |
| 843 | request.result = |
| 844 | TelephonyManager |
| 845 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 846 | if (ar.exception instanceof CommandException) { |
| 847 | CommandException.Error error = |
| 848 | ((CommandException) (ar.exception)).getCommandError(); |
| 849 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 850 | request.result = |
| 851 | TelephonyManager |
| 852 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 853 | } |
| 854 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 855 | + ar.exception); |
| 856 | } else { |
| 857 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 858 | } |
| 859 | } |
| 860 | notifyRequester(request); |
| 861 | break; |
| 862 | } |
| 863 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 864 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 865 | request = (MainThreadRequest) msg.obj; |
| 866 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 867 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 868 | break; |
| 869 | |
| 870 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 871 | ar = (AsyncResult) msg.obj; |
| 872 | request = (MainThreadRequest) ar.userObj; |
| 873 | if (ar.exception == null && ar.result != null) { |
| 874 | request.result = ar.result; // Integer |
| 875 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 876 | // request.result must be set to something non-null |
| 877 | // for the calling thread to unblock |
| 878 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 879 | if (ar.result == null) { |
| 880 | loge("getPreferredNetworkType: Empty response"); |
| 881 | } else if (ar.exception instanceof CommandException) { |
| 882 | loge("getPreferredNetworkType: CommandException: " + |
| 883 | ar.exception); |
| 884 | } else { |
| 885 | loge("getPreferredNetworkType: Unknown exception"); |
| 886 | } |
| 887 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 888 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 889 | break; |
| 890 | |
| 891 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 892 | request = (MainThreadRequest) msg.obj; |
| 893 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 894 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 895 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 896 | break; |
| 897 | |
| 898 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 899 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 900 | break; |
| 901 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 902 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 903 | request = (MainThreadRequest)msg.obj; |
| 904 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 905 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 906 | break; |
| 907 | |
| 908 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 909 | ar = (AsyncResult)msg.obj; |
| 910 | request = (MainThreadRequest)ar.userObj; |
| 911 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 912 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 913 | break; |
| 914 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 915 | case CMD_SET_VOICEMAIL_NUMBER: |
| 916 | request = (MainThreadRequest) msg.obj; |
| 917 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 918 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 919 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 920 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 921 | break; |
| 922 | |
| 923 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 924 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 925 | break; |
| 926 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 927 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 928 | request = (MainThreadRequest) msg.obj; |
| 929 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 930 | request); |
| 931 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 932 | break; |
| 933 | |
| 934 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 935 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 936 | break; |
| 937 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 938 | case CMD_PERFORM_NETWORK_SCAN: |
| 939 | request = (MainThreadRequest) msg.obj; |
| 940 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 941 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 942 | break; |
| 943 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 944 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 945 | request = (MainThreadRequest) msg.obj; |
| 946 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 947 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 948 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 949 | request.argument; |
| 950 | int callForwardingReason = args.first; |
| 951 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 952 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 953 | } |
| 954 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 955 | ar = (AsyncResult) msg.obj; |
| 956 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 957 | TelephonyManager.CallForwardingInfoCallback callback = |
| 958 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 959 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 960 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 961 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 962 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 963 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 964 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 965 | // any service for voice call. |
| 966 | if ((callForwardInfo.serviceClass |
| 967 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 968 | callForwardingInfo = new CallForwardingInfo(true, |
| 969 | callForwardInfo.reason, |
| 970 | callForwardInfo.number, |
| 971 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 972 | break; |
| 973 | } |
| 974 | } |
| 975 | // Didn't find a call forward info for voice call. |
| 976 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 977 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 978 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 979 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 980 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 981 | } else { |
| 982 | if (ar.result == null) { |
| 983 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 984 | } |
| 985 | if (ar.exception != null) { |
| 986 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 987 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 988 | int errorCode = TelephonyManager |
| 989 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 990 | if (ar.exception instanceof CommandException) { |
| 991 | CommandException.Error error = |
| 992 | ((CommandException) (ar.exception)).getCommandError(); |
| 993 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 994 | errorCode = TelephonyManager |
| 995 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 996 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 997 | errorCode = TelephonyManager |
| 998 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 999 | } |
| 1000 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1001 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1002 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1003 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1004 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1005 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1006 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1007 | request = (MainThreadRequest) msg.obj; |
| 1008 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1009 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1010 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1011 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1012 | request.argument).first; |
| 1013 | request.phone.setCallForwardingOption( |
| 1014 | callForwardingInfoToSet.isEnabled() |
| 1015 | ? CommandsInterface.CF_ACTION_ENABLE |
| 1016 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1017 | callForwardingInfoToSet.getReason(), |
| 1018 | callForwardingInfoToSet.getNumber(), |
| 1019 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1020 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1021 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1022 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1023 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1024 | ar = (AsyncResult) msg.obj; |
| 1025 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1026 | Consumer<Integer> callback = |
| 1027 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1028 | request.argument).second; |
| 1029 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1030 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1031 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1032 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1033 | if (ar.exception instanceof CommandException) { |
| 1034 | CommandException.Error error = |
| 1035 | ((CommandException) (ar.exception)).getCommandError(); |
| 1036 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1037 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1038 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1039 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1040 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1041 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1042 | } |
| 1043 | } |
| 1044 | callback.accept(errorCode); |
| 1045 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1046 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1047 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1048 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1049 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1050 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1051 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1052 | request = (MainThreadRequest) msg.obj; |
| 1053 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1054 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1055 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1056 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1057 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1058 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1059 | ar = (AsyncResult) msg.obj; |
| 1060 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1061 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1062 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1063 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1064 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1065 | // Service Class is a bit mask per 3gpp 27.007. |
| 1066 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1067 | if (callForwardResults.length > 1 |
| 1068 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1069 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1070 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1071 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1072 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1073 | } else { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1074 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1075 | } |
| 1076 | } else { |
| 1077 | if (ar.result == null) { |
| 1078 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1079 | } |
| 1080 | if (ar.exception != null) { |
| 1081 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1082 | } |
| 1083 | if (ar.exception instanceof CommandException) { |
| 1084 | CommandException.Error error = |
| 1085 | ((CommandException) (ar.exception)).getCommandError(); |
| 1086 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1087 | callForwardingStatus = |
| 1088 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1089 | } |
| 1090 | } |
| 1091 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1092 | callback.accept(callForwardingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1093 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1094 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1095 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1096 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1097 | request = (MainThreadRequest) msg.obj; |
| 1098 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1099 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1100 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1101 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1102 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1103 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1104 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1105 | ar = (AsyncResult) msg.obj; |
| 1106 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1107 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1108 | Consumer<Integer> callback = |
| 1109 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1110 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1111 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1112 | if (ar.exception instanceof CommandException) { |
| 1113 | CommandException.Error error = |
| 1114 | ((CommandException) (ar.exception)).getCommandError(); |
| 1115 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1116 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1117 | } else { |
| 1118 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1119 | } |
| 1120 | } else { |
| 1121 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1122 | } |
| 1123 | } else { |
| 1124 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1125 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1126 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1127 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1128 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1129 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1130 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1131 | ar = (AsyncResult) msg.obj; |
| 1132 | request = (MainThreadRequest) ar.userObj; |
| 1133 | CellNetworkScanResult cellScanResult; |
| 1134 | if (ar.exception == null && ar.result != null) { |
| 1135 | cellScanResult = new CellNetworkScanResult( |
| 1136 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1137 | (List<OperatorInfo>) ar.result); |
| 1138 | } else { |
| 1139 | if (ar.result == null) { |
| 1140 | loge("getCellNetworkScanResults: Empty response"); |
| 1141 | } |
| 1142 | if (ar.exception != null) { |
| 1143 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1144 | } |
| 1145 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1146 | if (ar.exception instanceof CommandException) { |
| 1147 | CommandException.Error error = |
| 1148 | ((CommandException) (ar.exception)).getCommandError(); |
| 1149 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1150 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1151 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1152 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1153 | } |
| 1154 | } |
| 1155 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1156 | } |
| 1157 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1158 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1159 | break; |
| 1160 | |
| 1161 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1162 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1163 | ManualNetworkSelectionArgument selArg = |
| 1164 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1165 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1166 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1167 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1168 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1169 | break; |
| 1170 | |
| 1171 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1172 | ar = (AsyncResult) msg.obj; |
| 1173 | request = (MainThreadRequest) ar.userObj; |
| 1174 | if (ar.exception == null) { |
| 1175 | request.result = true; |
| 1176 | } else { |
| 1177 | request.result = false; |
| 1178 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1179 | } |
| 1180 | notifyRequester(request); |
| 1181 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1182 | break; |
| 1183 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1184 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1185 | request = (MainThreadRequest) msg.obj; |
| 1186 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1187 | if (defaultPhone != null) { |
| 1188 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1189 | } else { |
| 1190 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1191 | Bundle bundle = new Bundle(); |
| 1192 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1193 | new ModemActivityInfo(0, 0, 0, |
| 1194 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1195 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1196 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1197 | break; |
| 1198 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1199 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1200 | ar = (AsyncResult) msg.obj; |
| 1201 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1202 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1203 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1204 | ModemActivityInfo ret = null; |
| 1205 | int error = 0; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1206 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1207 | // Update the last modem activity info and the result of the request. |
| 1208 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1209 | if (isModemActivityInfoValid(info)) { |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1210 | int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()]; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1211 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1212 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1213 | .getTransmitTimeMillis(); |
| 1214 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1215 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1216 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1217 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1218 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1219 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1220 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1221 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1222 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1223 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1224 | info.getReceiveTimeMillis() |
| 1225 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1226 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1227 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(), |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1228 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1229 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1230 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1231 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1232 | } else { |
| 1233 | if (ar.result == null) { |
| 1234 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1235 | error = TelephonyManager.ModemActivityInfoException |
| 1236 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1237 | } else if (ar.exception instanceof CommandException) { |
| 1238 | loge("queryModemActivityInfo: CommandException: " + |
| 1239 | ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1240 | error = TelephonyManager.ModemActivityInfoException |
| 1241 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1242 | } else { |
| 1243 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1244 | error = TelephonyManager.ModemActivityInfoException |
| 1245 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1246 | } |
| 1247 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1248 | Bundle bundle = new Bundle(); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1249 | if (ret != null) { |
| 1250 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1251 | } else { |
| 1252 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1253 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1254 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1255 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1256 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1257 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1258 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1259 | case CMD_SET_ALLOWED_CARRIERS: |
| 1260 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1261 | CarrierRestrictionRules argument = |
| 1262 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1263 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1264 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1265 | break; |
| 1266 | |
| 1267 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1268 | ar = (AsyncResult) msg.obj; |
| 1269 | request = (MainThreadRequest) ar.userObj; |
| 1270 | if (ar.exception == null && ar.result != null) { |
| 1271 | request.result = ar.result; |
| 1272 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1273 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1274 | if (ar.exception instanceof CommandException) { |
| 1275 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1276 | CommandException.Error error = |
| 1277 | ((CommandException) (ar.exception)).getCommandError(); |
| 1278 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1279 | request.result = |
| 1280 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1281 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1282 | } else { |
| 1283 | loge("setAllowedCarriers: Unknown exception"); |
| 1284 | } |
| 1285 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1286 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1287 | break; |
| 1288 | |
| 1289 | case CMD_GET_ALLOWED_CARRIERS: |
| 1290 | request = (MainThreadRequest) msg.obj; |
| 1291 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1292 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1293 | break; |
| 1294 | |
| 1295 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1296 | ar = (AsyncResult) msg.obj; |
| 1297 | request = (MainThreadRequest) ar.userObj; |
| 1298 | if (ar.exception == null && ar.result != null) { |
| 1299 | request.result = ar.result; |
| 1300 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1301 | request.result = new IllegalStateException( |
| 1302 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1303 | if (ar.result == null) { |
| 1304 | loge("getAllowedCarriers: Empty response"); |
| 1305 | } else if (ar.exception instanceof CommandException) { |
| 1306 | loge("getAllowedCarriers: CommandException: " + |
| 1307 | ar.exception); |
| 1308 | } else { |
| 1309 | loge("getAllowedCarriers: Unknown exception"); |
| 1310 | } |
| 1311 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1312 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1313 | break; |
| 1314 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1315 | case EVENT_GET_FORBIDDEN_PLMNS_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 { |
| 1321 | request.result = new IllegalArgumentException( |
| 1322 | "Failed to retrieve Forbidden Plmns"); |
| 1323 | if (ar.result == null) { |
| 1324 | loge("getForbiddenPlmns: Empty response"); |
| 1325 | } else { |
| 1326 | loge("getForbiddenPlmns: Unknown exception"); |
| 1327 | } |
| 1328 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1329 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1330 | break; |
| 1331 | |
| 1332 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1333 | request = (MainThreadRequest) msg.obj; |
| 1334 | uiccCard = getUiccCardFromRequest(request); |
| 1335 | if (uiccCard == null) { |
| 1336 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1337 | request.result = new IllegalArgumentException( |
| 1338 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1339 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1340 | break; |
| 1341 | } |
| 1342 | Integer appType = (Integer) request.argument; |
| 1343 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1344 | if (uiccApp == null) { |
| 1345 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1346 | + appType); |
| 1347 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1348 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1349 | break; |
| 1350 | } else { |
| 1351 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1352 | + " specified type -- " + appType); |
| 1353 | } |
| 1354 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1355 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1356 | onCompleted); |
| 1357 | break; |
| 1358 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1359 | case CMD_SWITCH_SLOTS: |
| 1360 | request = (MainThreadRequest) msg.obj; |
| 1361 | int[] physicalSlots = (int[]) request.argument; |
| 1362 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1363 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1364 | break; |
| 1365 | |
| 1366 | case EVENT_SWITCH_SLOTS_DONE: |
| 1367 | ar = (AsyncResult) msg.obj; |
| 1368 | request = (MainThreadRequest) ar.userObj; |
| 1369 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1370 | notifyRequester(request); |
| 1371 | break; |
| 1372 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1373 | request = (MainThreadRequest) msg.obj; |
| 1374 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1375 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1376 | break; |
| 1377 | |
| 1378 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1379 | ar = (AsyncResult) msg.obj; |
| 1380 | request = (MainThreadRequest) ar.userObj; |
| 1381 | if (ar.exception != null) { |
| 1382 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1383 | } else { |
| 1384 | int mode = ((int[]) ar.result)[0]; |
| 1385 | if (mode == 0) { |
| 1386 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1387 | } else { |
| 1388 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1389 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1390 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1391 | notifyRequester(request); |
| 1392 | break; |
| 1393 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1394 | request = (MainThreadRequest) msg.obj; |
| 1395 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1396 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1397 | break; |
| 1398 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1399 | ar = (AsyncResult) msg.obj; |
| 1400 | request = (MainThreadRequest) ar.userObj; |
| 1401 | if (ar.exception != null) { |
| 1402 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1403 | } else { |
| 1404 | request.result = ((int[]) ar.result)[0]; |
| 1405 | } |
| 1406 | notifyRequester(request); |
| 1407 | break; |
| 1408 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1409 | request = (MainThreadRequest) msg.obj; |
| 1410 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1411 | int mode = (int) request.argument; |
| 1412 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1413 | break; |
| 1414 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1415 | ar = (AsyncResult) msg.obj; |
| 1416 | request = (MainThreadRequest) ar.userObj; |
| 1417 | request.result = ar.exception == null; |
| 1418 | notifyRequester(request); |
| 1419 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1420 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1421 | request = (MainThreadRequest) msg.obj; |
| 1422 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1423 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1424 | break; |
| 1425 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1426 | ar = (AsyncResult) msg.obj; |
| 1427 | request = (MainThreadRequest) ar.userObj; |
| 1428 | if (ar.exception != null) { |
| 1429 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1430 | } else { |
| 1431 | request.result = ((int[]) ar.result)[0]; |
| 1432 | } |
| 1433 | notifyRequester(request); |
| 1434 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1435 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1436 | request = (MainThreadRequest) msg.obj; |
| 1437 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1438 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1439 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1440 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1441 | break; |
| 1442 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1443 | ar = (AsyncResult) msg.obj; |
| 1444 | request = (MainThreadRequest) ar.userObj; |
| 1445 | request.result = ar.exception == null; |
| 1446 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1447 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1448 | case CMD_GET_ALL_CELL_INFO: |
| 1449 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1450 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1451 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1452 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1453 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1454 | ar = (AsyncResult) msg.obj; |
| 1455 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1456 | // If a timeout occurs, the response will be null |
| 1457 | request.result = (ar.exception == null && ar.result != null) |
| 1458 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1459 | synchronized (request) { |
| 1460 | request.notifyAll(); |
| 1461 | } |
| 1462 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1463 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1464 | request = (MainThreadRequest) msg.obj; |
| 1465 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1466 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1467 | break; |
| 1468 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1469 | ar = (AsyncResult) msg.obj; |
| 1470 | request = (MainThreadRequest) ar.userObj; |
| 1471 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1472 | try { |
| 1473 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1474 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1475 | cb.onError( |
| 1476 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1477 | ar.exception.getClass().getName(), |
| 1478 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1479 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1480 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1481 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1482 | } else { |
| 1483 | // use the result as returned |
| 1484 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1485 | } |
| 1486 | } catch (RemoteException re) { |
| 1487 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1488 | } |
| 1489 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1490 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1491 | request = (MainThreadRequest) msg.obj; |
| 1492 | WorkSource ws = (WorkSource) request.argument; |
| 1493 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1494 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1495 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1496 | } |
| 1497 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1498 | ar = (AsyncResult) msg.obj; |
| 1499 | request = (MainThreadRequest) ar.userObj; |
| 1500 | if (ar.exception == null) { |
| 1501 | request.result = ar.result; |
| 1502 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1503 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1504 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1505 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1506 | } |
| 1507 | |
| 1508 | synchronized (request) { |
| 1509 | request.notifyAll(); |
| 1510 | } |
| 1511 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1512 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1513 | case CMD_MODEM_REBOOT: |
| 1514 | request = (MainThreadRequest) msg.obj; |
| 1515 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1516 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1517 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1518 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1519 | handleNullReturnEvent(msg, "rebootModem"); |
| 1520 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1521 | case CMD_REQUEST_ENABLE_MODEM: |
| 1522 | request = (MainThreadRequest) msg.obj; |
| 1523 | boolean enable = (boolean) request.argument; |
| 1524 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1525 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1526 | PhoneConfigurationManager.getInstance() |
| 1527 | .enablePhone(request.phone, enable, onCompleted); |
| 1528 | break; |
| 1529 | case EVENT_ENABLE_MODEM_DONE: |
| 1530 | ar = (AsyncResult) msg.obj; |
| 1531 | request = (MainThreadRequest) ar.userObj; |
| 1532 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1533 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1534 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1535 | if ((boolean) request.result) { |
| 1536 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1537 | updateModemStateMetrics(); |
| 1538 | } else { |
| 1539 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1540 | + ar.exception); |
| 1541 | } |
| 1542 | notifyRequester(request); |
| 1543 | break; |
| 1544 | case CMD_GET_MODEM_STATUS: |
| 1545 | request = (MainThreadRequest) msg.obj; |
| 1546 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1547 | PhoneConfigurationManager.getInstance() |
| 1548 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1549 | break; |
| 1550 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1551 | ar = (AsyncResult) msg.obj; |
| 1552 | request = (MainThreadRequest) ar.userObj; |
| 1553 | int id = request.phone.getPhoneId(); |
| 1554 | if (ar.exception == null && ar.result != null) { |
| 1555 | request.result = ar.result; |
| 1556 | //update the cache as modem status has changed |
| 1557 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1558 | (boolean) request.result); |
| 1559 | } else { |
| 1560 | // Return true if modem status cannot be retrieved. For most cases, |
| 1561 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1562 | // and disable modem are not supported. Modem is always on. |
| 1563 | // TODO: this should be fixed in R to support a third |
| 1564 | // status UNKNOWN b/131631629 |
| 1565 | request.result = true; |
| 1566 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1567 | + ar.exception); |
| 1568 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1569 | notifyRequester(request); |
| 1570 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1571 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1572 | request = (MainThreadRequest) msg.obj; |
| 1573 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1574 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1575 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1576 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1577 | break; |
| 1578 | } |
| 1579 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1580 | ar = (AsyncResult) msg.obj; |
| 1581 | request = (MainThreadRequest) ar.userObj; |
| 1582 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1583 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1584 | args.second.accept(ar.exception == null); |
| 1585 | notifyRequester(request); |
| 1586 | break; |
| 1587 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1588 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1589 | request = (MainThreadRequest) msg.obj; |
| 1590 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1591 | Phone phone = getPhoneFromRequest(request); |
| 1592 | if (phone != null) { |
| 1593 | phone.getSystemSelectionChannels(onCompleted); |
| 1594 | } else { |
| 1595 | loge("getSystemSelectionChannels: No phone object"); |
| 1596 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1597 | notifyRequester(request); |
| 1598 | } |
| 1599 | break; |
| 1600 | } |
| 1601 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1602 | ar = (AsyncResult) msg.obj; |
| 1603 | request = (MainThreadRequest) ar.userObj; |
| 1604 | if (ar.exception == null && ar.result != null) { |
| 1605 | request.result = ar.result; |
| 1606 | } else { |
| 1607 | request.result = new IllegalArgumentException( |
| 1608 | "Failed to retrieve system selection channels"); |
| 1609 | if (ar.result == null) { |
| 1610 | loge("getSystemSelectionChannels: Empty response"); |
| 1611 | } else { |
| 1612 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1613 | } |
| 1614 | } |
| 1615 | notifyRequester(request); |
| 1616 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1617 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1618 | ar = (AsyncResult) msg.obj; |
| 1619 | request = (MainThreadRequest) ar.userObj; |
| 1620 | if (ar.exception == null && ar.result != null) { |
| 1621 | request.result = ar.result; |
| 1622 | } else { |
| 1623 | request.result = -1; |
| 1624 | loge("Failed to set Forbidden Plmns"); |
| 1625 | if (ar.result == null) { |
| 1626 | loge("setForbidenPlmns: Empty response"); |
| 1627 | } else if (ar.exception != null) { |
| 1628 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1629 | request.result = -1; |
| 1630 | } else { |
| 1631 | loge("setForbiddenPlmns: Unknown exception"); |
| 1632 | } |
| 1633 | } |
| 1634 | notifyRequester(request); |
| 1635 | break; |
| 1636 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1637 | request = (MainThreadRequest) msg.obj; |
| 1638 | uiccCard = getUiccCardFromRequest(request); |
| 1639 | if (uiccCard == null) { |
| 1640 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1641 | request.result = -1; |
| 1642 | notifyRequester(request); |
| 1643 | break; |
| 1644 | } |
| 1645 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1646 | (Pair<Integer, List<String>>) request.argument; |
| 1647 | appType = setFplmnsArgs.first; |
| 1648 | List<String> fplmns = setFplmnsArgs.second; |
| 1649 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1650 | if (uiccApp == null) { |
| 1651 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1652 | request.result = -1; |
| 1653 | loge("Failed to get UICC App"); |
| 1654 | notifyRequester(request); |
| 1655 | } else { |
| 1656 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1657 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1658 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1659 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1660 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1661 | case CMD_ERASE_MODEM_CONFIG: |
| 1662 | request = (MainThreadRequest) msg.obj; |
| 1663 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1664 | defaultPhone.eraseModemConfig(onCompleted); |
| 1665 | break; |
| 1666 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1667 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1668 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1669 | |
| 1670 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1671 | request = (MainThreadRequest) msg.obj; |
| 1672 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1673 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1674 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1675 | changed.first, changed.second, onCompleted); |
| 1676 | break; |
| 1677 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1678 | ar = (AsyncResult) msg.obj; |
| 1679 | request = (MainThreadRequest) ar.userObj; |
| 1680 | if (ar.exception == null) { |
| 1681 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1682 | } else { |
| 1683 | request.result = msg.arg1; |
| 1684 | } |
| 1685 | notifyRequester(request); |
| 1686 | break; |
| 1687 | |
| 1688 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1689 | request = (MainThreadRequest) msg.obj; |
| 1690 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1691 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1692 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1693 | enabled.first, enabled.second, onCompleted); |
| 1694 | break; |
| 1695 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1696 | ar = (AsyncResult) msg.obj; |
| 1697 | request = (MainThreadRequest) ar.userObj; |
| 1698 | if (ar.exception == null) { |
| 1699 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1700 | } else { |
| 1701 | request.result = msg.arg1; |
| 1702 | } |
| 1703 | notifyRequester(request); |
| 1704 | break; |
| 1705 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1706 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1707 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1708 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1709 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1710 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1711 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1712 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1713 | |
| 1714 | case CMD_SET_DATA_THROTTLING: { |
| 1715 | request = (MainThreadRequest) msg.obj; |
| 1716 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1717 | DataThrottlingRequest dataThrottlingRequest = |
| 1718 | (DataThrottlingRequest) request.argument; |
| 1719 | Phone phone = getPhoneFromRequest(request); |
| 1720 | if (phone != null) { |
| 1721 | phone.setDataThrottling(onCompleted, |
| 1722 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1723 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1724 | } else { |
| 1725 | loge("setDataThrottling: No phone object"); |
| 1726 | request.result = |
| 1727 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1728 | notifyRequester(request); |
| 1729 | } |
| 1730 | |
| 1731 | break; |
| 1732 | } |
| 1733 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1734 | ar = (AsyncResult) msg.obj; |
| 1735 | request = (MainThreadRequest) ar.userObj; |
| 1736 | |
| 1737 | if (ar.exception == null) { |
| 1738 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1739 | } else if (ar.exception instanceof CommandException) { |
| 1740 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1741 | CommandException.Error error = |
| 1742 | ((CommandException) (ar.exception)).getCommandError(); |
| 1743 | |
| 1744 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1745 | request.result = TelephonyManager |
| 1746 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1747 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1748 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
| 1749 | } else { |
| 1750 | request.result = |
| 1751 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1752 | } |
| 1753 | } else { |
| 1754 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1755 | } |
| 1756 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1757 | notifyRequester(request); |
| 1758 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1759 | |
| 1760 | case CMD_SET_SIM_POWER: { |
| 1761 | request = (MainThreadRequest) msg.obj; |
| 1762 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1763 | request = (MainThreadRequest) msg.obj; |
| 1764 | int stateToSet = |
| 1765 | ((Pair<Integer, IIntegerConsumer>) |
| 1766 | request.argument).first; |
| 1767 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1768 | break; |
| 1769 | } |
| 1770 | case EVENT_SET_SIM_POWER_DONE: { |
| 1771 | ar = (AsyncResult) msg.obj; |
| 1772 | request = (MainThreadRequest) ar.userObj; |
| 1773 | IIntegerConsumer callback = |
| 1774 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1775 | if (ar.exception != null) { |
| 1776 | loge("setSimPower exception: " + ar.exception); |
| 1777 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1778 | .RESULT_ERROR_UNKNOWN; |
| 1779 | if (ar.exception instanceof CommandException) { |
| 1780 | CommandException.Error error = |
| 1781 | ((CommandException) (ar.exception)).getCommandError(); |
| 1782 | if (error == CommandException.Error.SIM_ERR) { |
| 1783 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1784 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1785 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1786 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1787 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1788 | } else { |
| 1789 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1790 | } |
| 1791 | } |
| 1792 | try { |
| 1793 | callback.accept(errorCode); |
| 1794 | } catch (RemoteException e) { |
| 1795 | // Ignore if the remote process is no longer available to call back. |
| 1796 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1797 | } |
| 1798 | } else { |
| 1799 | try { |
| 1800 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1801 | } catch (RemoteException e) { |
| 1802 | // Ignore if the remote process is no longer available to call back. |
| 1803 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1804 | } |
| 1805 | } |
| 1806 | break; |
| 1807 | } |
| 1808 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1809 | default: |
| 1810 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1811 | break; |
| 1812 | } |
| 1813 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1814 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1815 | private void notifyRequester(MainThreadRequest request) { |
| 1816 | synchronized (request) { |
| 1817 | request.notifyAll(); |
| 1818 | } |
| 1819 | } |
| 1820 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1821 | private void handleNullReturnEvent(Message msg, String command) { |
| 1822 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1823 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1824 | if (ar.exception == null) { |
| 1825 | request.result = true; |
| 1826 | } else { |
| 1827 | request.result = false; |
| 1828 | if (ar.exception instanceof CommandException) { |
| 1829 | loge(command + ": CommandException: " + ar.exception); |
| 1830 | } else { |
| 1831 | loge(command + ": Unknown exception"); |
| 1832 | } |
| 1833 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1834 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1835 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1836 | } |
| 1837 | |
| 1838 | /** |
| 1839 | * Posts the specified command to be executed on the main thread, |
| 1840 | * waits for the request to complete, and returns the result. |
| 1841 | * @see #sendRequestAsync |
| 1842 | */ |
| 1843 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1844 | return sendRequest( |
| 1845 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1846 | } |
| 1847 | |
| 1848 | /** |
| 1849 | * Posts the specified command to be executed on the main thread, |
| 1850 | * waits for the request to complete, and returns the result. |
| 1851 | * @see #sendRequestAsync |
| 1852 | */ |
| 1853 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1854 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1855 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1856 | } |
| 1857 | |
| 1858 | /** |
| 1859 | * Posts the specified command to be executed on the main thread, |
| 1860 | * waits for the request to complete, and returns the result. |
| 1861 | * @see #sendRequestAsync |
| 1862 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1863 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1864 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1865 | } |
| 1866 | |
| 1867 | /** |
| 1868 | * Posts the specified command to be executed on the main thread, |
| 1869 | * waits for the request to complete, and returns the result. |
| 1870 | * @see #sendRequestAsync |
| 1871 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1872 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1873 | return sendRequest(command, argument, subId, null, workSource); |
| 1874 | } |
| 1875 | |
| 1876 | /** |
| 1877 | * Posts the specified command to be executed on the main thread, |
| 1878 | * waits for the request to complete, and returns the result. |
| 1879 | * @see #sendRequestAsync |
| 1880 | */ |
| 1881 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1882 | return sendRequest( |
| 1883 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1884 | } |
| 1885 | |
| 1886 | /** |
| 1887 | * Posts the specified command to be executed on the main thread, |
| 1888 | * waits for the request to complete, and returns the result. |
| 1889 | * @see #sendRequestAsync |
| 1890 | */ |
| 1891 | private Object sendRequest( |
| 1892 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1893 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1894 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1895 | } |
| 1896 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1897 | MainThreadRequest request = null; |
| 1898 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1899 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1900 | } else if (phone != null) { |
| 1901 | request = new MainThreadRequest(argument, phone, workSource); |
| 1902 | } else { |
| 1903 | request = new MainThreadRequest(argument, subId, workSource); |
| 1904 | } |
| 1905 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1906 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1907 | msg.sendToTarget(); |
| 1908 | |
| 1909 | // Wait for the request to complete |
| 1910 | synchronized (request) { |
| 1911 | while (request.result == null) { |
| 1912 | try { |
| 1913 | request.wait(); |
| 1914 | } catch (InterruptedException e) { |
| 1915 | // Do nothing, go back and wait until the request is complete |
| 1916 | } |
| 1917 | } |
| 1918 | } |
| 1919 | return request.result; |
| 1920 | } |
| 1921 | |
| 1922 | /** |
| 1923 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1924 | * Posts the specified command to be executed on the main thread, and |
| 1925 | * returns immediately. |
| 1926 | * @see #sendRequest |
| 1927 | */ |
| 1928 | private void sendRequestAsync(int command) { |
| 1929 | mMainThreadHandler.sendEmptyMessage(command); |
| 1930 | } |
| 1931 | |
| 1932 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1933 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1934 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1935 | */ |
| 1936 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1937 | sendRequestAsync(command, argument, null, null); |
| 1938 | } |
| 1939 | |
| 1940 | /** |
| 1941 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1942 | * @see {@link #sendRequest(int,Object)} |
| 1943 | */ |
| 1944 | private void sendRequestAsync( |
| 1945 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1946 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1947 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1948 | msg.sendToTarget(); |
| 1949 | } |
| 1950 | |
| 1951 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1952 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1953 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1954 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1955 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1956 | synchronized (PhoneInterfaceManager.class) { |
| 1957 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1958 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1959 | } else { |
| 1960 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1961 | } |
| 1962 | return sInstance; |
| 1963 | } |
| 1964 | } |
| 1965 | |
| 1966 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 1967 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1968 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1969 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1970 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1971 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1972 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1973 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1974 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1975 | mTelephonySharedPreferences = |
| 1976 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1977 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1978 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 1979 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1980 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1981 | publish(); |
| 1982 | } |
| 1983 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1984 | private Phone getDefaultPhone() { |
| 1985 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1986 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1987 | } |
| 1988 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1989 | private void publish() { |
| 1990 | if (DBG) log("publish: " + this); |
| 1991 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 1992 | TelephonyFrameworkInitializer |
| 1993 | .getTelephonyServiceManager() |
| 1994 | .getTelephonyServiceRegisterer() |
| 1995 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1996 | } |
| 1997 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1998 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1999 | if (request.phone != null) { |
| 2000 | return request.phone; |
| 2001 | } else { |
| 2002 | return getPhoneFromSubId(request.subId); |
| 2003 | } |
| 2004 | } |
| 2005 | |
| 2006 | private Phone getPhoneFromSubId(int subId) { |
| 2007 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2008 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2009 | } |
| 2010 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2011 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 2012 | Phone phone = getPhoneFromRequest(request); |
| 2013 | return phone == null ? null : |
| 2014 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 2015 | } |
| 2016 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2017 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2018 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2019 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2020 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2021 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2022 | private void sendEraseModemConfig(Phone phone) { |
| 2023 | if (phone != null) { |
| 2024 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2025 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 2026 | final long identity = Binder.clearCallingIdentity(); |
| 2027 | try { |
| 2028 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2029 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2030 | } finally { |
| 2031 | Binder.restoreCallingIdentity(identity); |
| 2032 | } |
| 2033 | } |
| 2034 | } |
| 2035 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2036 | private boolean isImsAvailableOnDevice() { |
| 2037 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2038 | if (pm == null) { |
| 2039 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2040 | // so do not throw error and allow. |
| 2041 | return true; |
| 2042 | } |
| 2043 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2044 | } |
| 2045 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2046 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2047 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2048 | } |
| 2049 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2050 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2051 | if (DBG) log("dial: " + number); |
| 2052 | // No permission check needed here: This is just a wrapper around the |
| 2053 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2054 | // the UI before it does anything. |
| 2055 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2056 | final long identity = Binder.clearCallingIdentity(); |
| 2057 | try { |
| 2058 | String url = createTelUrl(number); |
| 2059 | if (url == null) { |
| 2060 | return; |
| 2061 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2062 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2063 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2064 | PhoneConstants.State state = mCM.getState(subId); |
| 2065 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2066 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2067 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2068 | mApp.startActivity(intent); |
| 2069 | } |
| 2070 | } finally { |
| 2071 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2072 | } |
| 2073 | } |
| 2074 | |
| 2075 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2076 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2077 | } |
| 2078 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2079 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2080 | if (DBG) log("call: " + number); |
| 2081 | |
| 2082 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2083 | // need to do a permission check since we're calling startActivity() |
| 2084 | // from the context of the phone app. |
| 2085 | enforceCallPermission(); |
| 2086 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2087 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2088 | != AppOpsManager.MODE_ALLOWED) { |
| 2089 | return; |
| 2090 | } |
| 2091 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2092 | final long identity = Binder.clearCallingIdentity(); |
| 2093 | try { |
| 2094 | String url = createTelUrl(number); |
| 2095 | if (url == null) { |
| 2096 | return; |
| 2097 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2098 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2099 | boolean isValid = false; |
| 2100 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2101 | if (slist != null) { |
| 2102 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2103 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2104 | isValid = true; |
| 2105 | break; |
| 2106 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2107 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2108 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2109 | if (!isValid) { |
| 2110 | return; |
| 2111 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2112 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2113 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2114 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2115 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2116 | mApp.startActivity(intent); |
| 2117 | } finally { |
| 2118 | Binder.restoreCallingIdentity(identity); |
| 2119 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2120 | } |
| 2121 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2122 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2123 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2124 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2125 | } |
| 2126 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2127 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2128 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2129 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2130 | } |
| 2131 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2132 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2133 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2134 | |
| 2135 | final long identity = Binder.clearCallingIdentity(); |
| 2136 | try { |
| 2137 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 2138 | checkSimPin.start(); |
| 2139 | return checkSimPin.unlockSim(null, pin); |
| 2140 | } finally { |
| 2141 | Binder.restoreCallingIdentity(identity); |
| 2142 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2143 | } |
| 2144 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2145 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2146 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2147 | |
| 2148 | final long identity = Binder.clearCallingIdentity(); |
| 2149 | try { |
| 2150 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 2151 | checkSimPuk.start(); |
| 2152 | return checkSimPuk.unlockSim(puk, pin); |
| 2153 | } finally { |
| 2154 | Binder.restoreCallingIdentity(identity); |
| 2155 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2156 | } |
| 2157 | |
| 2158 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2159 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2160 | * a synchronous one. |
| 2161 | */ |
| 2162 | private static class UnlockSim extends Thread { |
| 2163 | |
| 2164 | private final IccCard mSimCard; |
| 2165 | |
| 2166 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2167 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2168 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2169 | |
| 2170 | // For replies from SimCard interface |
| 2171 | private Handler mHandler; |
| 2172 | |
| 2173 | // For async handler to identify request type |
| 2174 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2175 | |
| 2176 | public UnlockSim(IccCard simCard) { |
| 2177 | mSimCard = simCard; |
| 2178 | } |
| 2179 | |
| 2180 | @Override |
| 2181 | public void run() { |
| 2182 | Looper.prepare(); |
| 2183 | synchronized (UnlockSim.this) { |
| 2184 | mHandler = new Handler() { |
| 2185 | @Override |
| 2186 | public void handleMessage(Message msg) { |
| 2187 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2188 | switch (msg.what) { |
| 2189 | case SUPPLY_PIN_COMPLETE: |
| 2190 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2191 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2192 | mRetryCount = msg.arg1; |
| 2193 | if (ar.exception != null) { |
| 2194 | if (ar.exception instanceof CommandException && |
| 2195 | ((CommandException)(ar.exception)).getCommandError() |
| 2196 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2197 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2198 | } //When UiccCardApp dispose,handle message and return exception |
| 2199 | else if (ar.exception instanceof CommandException && |
| 2200 | ((CommandException) (ar.exception)).getCommandError() |
| 2201 | == CommandException.Error.ABORTED) { |
| 2202 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2203 | } else { |
| 2204 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2205 | } |
| 2206 | } else { |
| 2207 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2208 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2209 | mDone = true; |
| 2210 | UnlockSim.this.notifyAll(); |
| 2211 | } |
| 2212 | break; |
| 2213 | } |
| 2214 | } |
| 2215 | }; |
| 2216 | UnlockSim.this.notifyAll(); |
| 2217 | } |
| 2218 | Looper.loop(); |
| 2219 | } |
| 2220 | |
| 2221 | /* |
| 2222 | * Use PIN or PUK to unlock SIM card |
| 2223 | * |
| 2224 | * If PUK is null, unlock SIM card with PIN |
| 2225 | * |
| 2226 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2227 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2228 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2229 | |
| 2230 | while (mHandler == null) { |
| 2231 | try { |
| 2232 | wait(); |
| 2233 | } catch (InterruptedException e) { |
| 2234 | Thread.currentThread().interrupt(); |
| 2235 | } |
| 2236 | } |
| 2237 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2238 | |
| 2239 | if (puk == null) { |
| 2240 | mSimCard.supplyPin(pin, callback); |
| 2241 | } else { |
| 2242 | mSimCard.supplyPuk(puk, pin, callback); |
| 2243 | } |
| 2244 | |
| 2245 | while (!mDone) { |
| 2246 | try { |
| 2247 | Log.d(LOG_TAG, "wait for done"); |
| 2248 | wait(); |
| 2249 | } catch (InterruptedException e) { |
| 2250 | // Restore the interrupted status |
| 2251 | Thread.currentThread().interrupt(); |
| 2252 | } |
| 2253 | } |
| 2254 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2255 | int[] resultArray = new int[2]; |
| 2256 | resultArray[0] = mResult; |
| 2257 | resultArray[1] = mRetryCount; |
| 2258 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2259 | } |
| 2260 | } |
| 2261 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2262 | /** |
| 2263 | * This method has been removed due to privacy and stability concerns. |
| 2264 | */ |
| 2265 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2266 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2267 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2268 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2269 | } |
| 2270 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2271 | @Override |
| 2272 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2273 | mApp.getSystemService(AppOpsManager.class) |
| 2274 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2275 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2276 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2277 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2278 | // Callers targeting S have no business invoking this method. |
| 2279 | return; |
| 2280 | } |
| 2281 | |
| 2282 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2283 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2284 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2285 | .setCallingPackage(callingPackage) |
| 2286 | .setCallingFeatureId(null) |
| 2287 | .setCallingPid(Binder.getCallingPid()) |
| 2288 | .setCallingUid(Binder.getCallingUid()) |
| 2289 | .setMethod("updateServiceLocation") |
| 2290 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2291 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2292 | .build()); |
| 2293 | // Apps that lack location permission have no business calling this method; |
| 2294 | // however, because no permission was declared in the public API, denials must |
| 2295 | // all be "soft". |
| 2296 | switch (locationResult) { |
| 2297 | case DENIED_HARD: /* fall through */ |
| 2298 | case DENIED_SOFT: |
| 2299 | return; |
| 2300 | } |
| 2301 | |
| 2302 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2303 | final long identity = Binder.clearCallingIdentity(); |
| 2304 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2305 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2306 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2307 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2308 | } |
| 2309 | } finally { |
| 2310 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2311 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2312 | } |
| 2313 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2314 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2315 | @Override |
| 2316 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2317 | return isRadioOnWithFeature(callingPackage, null); |
| 2318 | } |
| 2319 | |
| 2320 | |
| 2321 | @Override |
| 2322 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2323 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2324 | callingFeatureId); |
| 2325 | } |
| 2326 | |
| 2327 | @Deprecated |
| 2328 | @Override |
| 2329 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2330 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2331 | } |
| 2332 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2333 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2334 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2335 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2336 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2337 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2338 | return false; |
| 2339 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2340 | |
| 2341 | final long identity = Binder.clearCallingIdentity(); |
| 2342 | try { |
| 2343 | return isRadioOnForSubscriber(subId); |
| 2344 | } finally { |
| 2345 | Binder.restoreCallingIdentity(identity); |
| 2346 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2347 | } |
| 2348 | |
| 2349 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2350 | final long identity = Binder.clearCallingIdentity(); |
| 2351 | try { |
| 2352 | final Phone phone = getPhone(subId); |
| 2353 | if (phone != null) { |
| 2354 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2355 | } else { |
| 2356 | return false; |
| 2357 | } |
| 2358 | } finally { |
| 2359 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2360 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2361 | } |
| 2362 | |
| 2363 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2364 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2365 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2366 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2367 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2368 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2369 | |
| 2370 | final long identity = Binder.clearCallingIdentity(); |
| 2371 | try { |
| 2372 | final Phone phone = getPhone(subId); |
| 2373 | if (phone != null) { |
| 2374 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2375 | } |
| 2376 | } finally { |
| 2377 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2378 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2379 | } |
| 2380 | |
| 2381 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2382 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2383 | } |
| 2384 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2385 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2386 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2387 | |
| 2388 | final long identity = Binder.clearCallingIdentity(); |
| 2389 | try { |
| 2390 | final Phone phone = getPhone(subId); |
| 2391 | if (phone == null) { |
| 2392 | return false; |
| 2393 | } |
| 2394 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2395 | toggleRadioOnOffForSubscriber(subId); |
| 2396 | } |
| 2397 | return true; |
| 2398 | } finally { |
| 2399 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2400 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2401 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2402 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2403 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2404 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2405 | /* |
| 2406 | * If any of the Radios are available, it will need to be |
| 2407 | * shutdown. So return true if any Radio is available. |
| 2408 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2409 | final long identity = Binder.clearCallingIdentity(); |
| 2410 | try { |
| 2411 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2412 | Phone phone = PhoneFactory.getPhone(i); |
| 2413 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2414 | } |
| 2415 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2416 | return false; |
| 2417 | } finally { |
| 2418 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2419 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2420 | } |
| 2421 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2422 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2423 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2424 | enforceModifyPermission(); |
| 2425 | |
| 2426 | final long identity = Binder.clearCallingIdentity(); |
| 2427 | try { |
| 2428 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2429 | logv("Shutting down Phone " + i); |
| 2430 | shutdownRadioUsingPhoneId(i); |
| 2431 | } |
| 2432 | } finally { |
| 2433 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2434 | } |
| 2435 | } |
| 2436 | |
| 2437 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2438 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2439 | if (phone != null && phone.isRadioAvailable()) { |
| 2440 | phone.shutdownRadio(); |
| 2441 | } |
| 2442 | } |
| 2443 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2444 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2445 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2446 | |
| 2447 | final long identity = Binder.clearCallingIdentity(); |
| 2448 | try { |
| 2449 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2450 | if (defaultPhone != null) { |
| 2451 | defaultPhone.setRadioPower(turnOn); |
| 2452 | return true; |
| 2453 | } else { |
| 2454 | loge("There's no default phone."); |
| 2455 | return false; |
| 2456 | } |
| 2457 | } finally { |
| 2458 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2459 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2460 | } |
| 2461 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2462 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2463 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2464 | |
| 2465 | final long identity = Binder.clearCallingIdentity(); |
| 2466 | try { |
| 2467 | final Phone phone = getPhone(subId); |
| 2468 | if (phone != null) { |
| 2469 | phone.setRadioPower(turnOn); |
| 2470 | return true; |
| 2471 | } else { |
| 2472 | return false; |
| 2473 | } |
| 2474 | } finally { |
| 2475 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2476 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2477 | } |
| 2478 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2479 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2480 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2481 | public boolean enableDataConnectivity() { |
| 2482 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2483 | |
| 2484 | final long identity = Binder.clearCallingIdentity(); |
| 2485 | try { |
| 2486 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2487 | final Phone phone = getPhone(subId); |
| 2488 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2489 | phone.getDataEnabledSettings().setDataEnabled( |
| 2490 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2491 | return true; |
| 2492 | } else { |
| 2493 | return false; |
| 2494 | } |
| 2495 | } finally { |
| 2496 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2497 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2498 | } |
| 2499 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2500 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2501 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2502 | public boolean disableDataConnectivity() { |
| 2503 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2504 | |
| 2505 | final long identity = Binder.clearCallingIdentity(); |
| 2506 | try { |
| 2507 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2508 | final Phone phone = getPhone(subId); |
| 2509 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2510 | phone.getDataEnabledSettings().setDataEnabled( |
| 2511 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2512 | return true; |
| 2513 | } else { |
| 2514 | return false; |
| 2515 | } |
| 2516 | } finally { |
| 2517 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2518 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2519 | } |
| 2520 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2521 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2522 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2523 | final long identity = Binder.clearCallingIdentity(); |
| 2524 | try { |
| 2525 | final Phone phone = getPhone(subId); |
| 2526 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2527 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2528 | } else { |
| 2529 | return false; |
| 2530 | } |
| 2531 | } finally { |
| 2532 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2533 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2534 | } |
| 2535 | |
| 2536 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2537 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2538 | } |
| 2539 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2540 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2541 | enforceCallPermission(); |
| 2542 | |
| 2543 | final long identity = Binder.clearCallingIdentity(); |
| 2544 | try { |
| 2545 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2546 | return; |
| 2547 | } |
| 2548 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2549 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2550 | } finally { |
| 2551 | Binder.restoreCallingIdentity(identity); |
| 2552 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2553 | }; |
| 2554 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2555 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2556 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2557 | |
| 2558 | final long identity = Binder.clearCallingIdentity(); |
| 2559 | try { |
| 2560 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2561 | return false; |
| 2562 | } |
| 2563 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2564 | } finally { |
| 2565 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2566 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2567 | } |
| 2568 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2569 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2570 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2571 | } |
| 2572 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2573 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2574 | final long identity = Binder.clearCallingIdentity(); |
| 2575 | try { |
| 2576 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2577 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2578 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2579 | } finally { |
| 2580 | Binder.restoreCallingIdentity(identity); |
| 2581 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2582 | } |
| 2583 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2584 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2585 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2586 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2587 | } |
| 2588 | |
| 2589 | @Override |
| 2590 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2591 | final long identity = Binder.clearCallingIdentity(); |
| 2592 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2593 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2594 | if (phone != null) { |
| 2595 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2596 | } else { |
| 2597 | return PhoneConstantConversions.convertDataState( |
| 2598 | PhoneConstants.DataState.DISCONNECTED); |
| 2599 | } |
| 2600 | } finally { |
| 2601 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2602 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2603 | } |
| 2604 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2605 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2606 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2607 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2608 | } |
| 2609 | |
| 2610 | @Override |
| 2611 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2612 | final long identity = Binder.clearCallingIdentity(); |
| 2613 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2614 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2615 | if (phone != null) { |
| 2616 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2617 | } else { |
| 2618 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2619 | } |
| 2620 | } finally { |
| 2621 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2622 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2623 | } |
| 2624 | |
| 2625 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2626 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2627 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2628 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2629 | |
| 2630 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2631 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2632 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2633 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2634 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2635 | .setCallingPid(Binder.getCallingPid()) |
| 2636 | .setCallingUid(Binder.getCallingUid()) |
| 2637 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2638 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2639 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2640 | .build()); |
| 2641 | switch (locationResult) { |
| 2642 | case DENIED_HARD: |
| 2643 | throw new SecurityException("Not allowed to access cell location"); |
| 2644 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2645 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2646 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2647 | } |
| 2648 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2649 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2650 | final long identity = Binder.clearCallingIdentity(); |
| 2651 | try { |
| 2652 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2653 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2654 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2655 | } finally { |
| 2656 | Binder.restoreCallingIdentity(identity); |
| 2657 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2658 | } |
| 2659 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2660 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2661 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2662 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2663 | // registered cell info, so return a NULL country instead. |
| 2664 | final long identity = Binder.clearCallingIdentity(); |
| 2665 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2666 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2667 | // Get default phone in this case. |
| 2668 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2669 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2670 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2671 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2672 | if (phone == null) return ""; |
| 2673 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2674 | if (sst == null) return ""; |
| 2675 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2676 | if (lt == null) return ""; |
| 2677 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2678 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2679 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2680 | } finally { |
| 2681 | Binder.restoreCallingIdentity(identity); |
| 2682 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2683 | } |
| 2684 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2685 | /** |
| 2686 | * This method was removed due to potential issues caused by performing partial |
| 2687 | * updates of service state, and lack of a credible use case. |
| 2688 | * |
| 2689 | * This has the ability to break the telephony implementation by disabling notification of |
| 2690 | * changes in device connectivity. DO NOT USE THIS! |
| 2691 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2692 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2693 | public void enableLocationUpdates() { |
| 2694 | mApp.enforceCallingOrSelfPermission( |
| 2695 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2696 | } |
| 2697 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2698 | /** |
| 2699 | * This method was removed due to potential issues caused by performing partial |
| 2700 | * updates of service state, and lack of a credible use case. |
| 2701 | * |
| 2702 | * This has the ability to break the telephony implementation by disabling notification of |
| 2703 | * changes in device connectivity. DO NOT USE THIS! |
| 2704 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2705 | @Override |
| 2706 | public void disableLocationUpdates() { |
| 2707 | mApp.enforceCallingOrSelfPermission( |
| 2708 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2709 | } |
| 2710 | |
| 2711 | @Override |
| 2712 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2713 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2714 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2715 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2716 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2717 | throw new SecurityException( |
| 2718 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2719 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2720 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2721 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2722 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2723 | return null; |
| 2724 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2725 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2726 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2727 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2728 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2729 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2730 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2731 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2732 | for (CellInfo ci : info) { |
| 2733 | if (ci instanceof CellInfoGsm) { |
| 2734 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2735 | } else if (ci instanceof CellInfoWcdma) { |
| 2736 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2737 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2738 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2739 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2740 | } |
| 2741 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2742 | private List<CellInfo> getCachedCellInfo() { |
| 2743 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2744 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2745 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2746 | if (info != null) cellInfos.addAll(info); |
| 2747 | } |
| 2748 | return cellInfos; |
| 2749 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2750 | |
| 2751 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2752 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2753 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2754 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2755 | |
| 2756 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2757 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2758 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2759 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2760 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2761 | .setCallingPid(Binder.getCallingPid()) |
| 2762 | .setCallingUid(Binder.getCallingUid()) |
| 2763 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2764 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2765 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2766 | .build()); |
| 2767 | switch (locationResult) { |
| 2768 | case DENIED_HARD: |
| 2769 | throw new SecurityException("Not allowed to access cell info"); |
| 2770 | case DENIED_SOFT: |
| 2771 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2772 | } |
| 2773 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2774 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2775 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2776 | return getCachedCellInfo(); |
| 2777 | } |
| 2778 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2779 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2780 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2781 | final long identity = Binder.clearCallingIdentity(); |
| 2782 | try { |
| 2783 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2784 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2785 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2786 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2787 | if (info != null) cellInfos.addAll(info); |
| 2788 | } |
| 2789 | return cellInfos; |
| 2790 | } finally { |
| 2791 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2792 | } |
| 2793 | } |
| 2794 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2795 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2796 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2797 | String callingFeatureId) { |
| 2798 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2799 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2800 | } |
| 2801 | |
| 2802 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2803 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2804 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2805 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2806 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2807 | } |
| 2808 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2809 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2810 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2811 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2812 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2813 | |
| 2814 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2815 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2816 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2817 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2818 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2819 | .setCallingPid(Binder.getCallingPid()) |
| 2820 | .setCallingUid(Binder.getCallingUid()) |
| 2821 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2822 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2823 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2824 | .build()); |
| 2825 | switch (locationResult) { |
| 2826 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2827 | if (TelephonyPermissions |
| 2828 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2829 | // Safetynet logging for b/154934934 |
| 2830 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2831 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2832 | throw new SecurityException("Not allowed to access cell info"); |
| 2833 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2834 | if (TelephonyPermissions |
| 2835 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2836 | // Safetynet logging for b/154934934 |
| 2837 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2838 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2839 | try { |
| 2840 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2841 | } catch (RemoteException re) { |
| 2842 | // Drop without consequences |
| 2843 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2844 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2845 | } |
| 2846 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2847 | |
| 2848 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2849 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2850 | |
| 2851 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2852 | } |
| 2853 | |
| 2854 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2855 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2856 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2857 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2858 | |
| 2859 | final long identity = Binder.clearCallingIdentity(); |
| 2860 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2861 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2862 | } finally { |
| 2863 | Binder.restoreCallingIdentity(identity); |
| 2864 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2865 | } |
| 2866 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2867 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2868 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2869 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2870 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2871 | return null; |
| 2872 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2873 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2874 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2875 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2876 | return null; |
| 2877 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2878 | |
| 2879 | final long identity = Binder.clearCallingIdentity(); |
| 2880 | try { |
| 2881 | return phone.getImei(); |
| 2882 | } finally { |
| 2883 | Binder.restoreCallingIdentity(identity); |
| 2884 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2885 | } |
| 2886 | |
| 2887 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2888 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2889 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2890 | String tac = null; |
| 2891 | if (phone != null) { |
| 2892 | String imei = phone.getImei(); |
| 2893 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2894 | } |
| 2895 | return tac; |
| 2896 | } |
| 2897 | |
| 2898 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2899 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2900 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2901 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2902 | return null; |
| 2903 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2904 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2905 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2906 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2907 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2908 | return null; |
| 2909 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2910 | |
| 2911 | final long identity = Binder.clearCallingIdentity(); |
| 2912 | try { |
| 2913 | return phone.getMeid(); |
| 2914 | } finally { |
| 2915 | Binder.restoreCallingIdentity(identity); |
| 2916 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2917 | } |
| 2918 | |
| 2919 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2920 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2921 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2922 | String manufacturerCode = null; |
| 2923 | if (phone != null) { |
| 2924 | String meid = phone.getMeid(); |
| 2925 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2926 | } |
| 2927 | return manufacturerCode; |
| 2928 | } |
| 2929 | |
| 2930 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2931 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2932 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2933 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2934 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2935 | return null; |
| 2936 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2937 | int subId = phone.getSubId(); |
| 2938 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2939 | mApp, subId, callingPackage, callingFeatureId, |
| 2940 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2941 | return null; |
| 2942 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2943 | |
| 2944 | final long identity = Binder.clearCallingIdentity(); |
| 2945 | try { |
| 2946 | return phone.getDeviceSvn(); |
| 2947 | } finally { |
| 2948 | Binder.restoreCallingIdentity(identity); |
| 2949 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2950 | } |
| 2951 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2952 | @Override |
| 2953 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2954 | final long identity = Binder.clearCallingIdentity(); |
| 2955 | try { |
| 2956 | final Phone phone = getPhone(subId); |
| 2957 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2958 | } finally { |
| 2959 | Binder.restoreCallingIdentity(identity); |
| 2960 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2961 | } |
| 2962 | |
| 2963 | @Override |
| 2964 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2965 | final long identity = Binder.clearCallingIdentity(); |
| 2966 | try { |
| 2967 | final Phone phone = getPhone(subId); |
| 2968 | return phone == null ? null : phone.getCarrierName(); |
| 2969 | } finally { |
| 2970 | Binder.restoreCallingIdentity(identity); |
| 2971 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2972 | } |
| 2973 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2974 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2975 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2976 | final long identity = Binder.clearCallingIdentity(); |
| 2977 | try { |
| 2978 | final Phone phone = getPhone(subId); |
| 2979 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2980 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2981 | } finally { |
| 2982 | Binder.restoreCallingIdentity(identity); |
| 2983 | } |
| 2984 | } |
| 2985 | |
| 2986 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2987 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2988 | final long identity = Binder.clearCallingIdentity(); |
| 2989 | try { |
| 2990 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2991 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2992 | } finally { |
| 2993 | Binder.restoreCallingIdentity(identity); |
| 2994 | } |
| 2995 | } |
| 2996 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2997 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2998 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2999 | if (!isSubscriptionMccMnc) { |
| 3000 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3001 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3002 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3003 | if (phone == null) { |
| 3004 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3005 | } |
| 3006 | final long identity = Binder.clearCallingIdentity(); |
| 3007 | try { |
| 3008 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3009 | } finally { |
| 3010 | Binder.restoreCallingIdentity(identity); |
| 3011 | } |
| 3012 | } |
| 3013 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3014 | // |
| 3015 | // Internal helper methods. |
| 3016 | // |
| 3017 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3018 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3019 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3020 | * |
| 3021 | * @throws SecurityException if the caller does not have the required permission |
| 3022 | */ |
| 3023 | private void enforceModifyPermission() { |
| 3024 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3025 | } |
| 3026 | |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3027 | /** |
| 3028 | * Make sure the caller is system. |
| 3029 | * |
| 3030 | * @throws SecurityException if the caller is not system. |
| 3031 | */ |
| 3032 | private void enforceSystemCaller() { |
| 3033 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 3034 | throw new SecurityException("Caller must be system"); |
| 3035 | } |
| 3036 | } |
| 3037 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3038 | private void enforceActiveEmergencySessionPermission() { |
| 3039 | mApp.enforceCallingOrSelfPermission( |
| 3040 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3041 | } |
| 3042 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3043 | /** |
| 3044 | * Make sure the caller has the CALL_PHONE permission. |
| 3045 | * |
| 3046 | * @throws SecurityException if the caller does not have the required permission |
| 3047 | */ |
| 3048 | private void enforceCallPermission() { |
| 3049 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3050 | } |
| 3051 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3052 | private void enforceSettingsPermission() { |
| 3053 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3054 | } |
| 3055 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3056 | private String createTelUrl(String number) { |
| 3057 | if (TextUtils.isEmpty(number)) { |
| 3058 | return null; |
| 3059 | } |
| 3060 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3061 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3062 | } |
| 3063 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3064 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3065 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3066 | } |
| 3067 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3068 | private static void logv(String msg) { |
| 3069 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3070 | } |
| 3071 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3072 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3073 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3074 | } |
| 3075 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3076 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3077 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3078 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3079 | } |
| 3080 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3081 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3082 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3083 | final long identity = Binder.clearCallingIdentity(); |
| 3084 | try { |
| 3085 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3086 | if (phone == null) { |
| 3087 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3088 | } else { |
| 3089 | return phone.getPhoneType(); |
| 3090 | } |
| 3091 | } finally { |
| 3092 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3093 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3094 | } |
| 3095 | |
| 3096 | /** |
| 3097 | * Returns the CDMA ERI icon index to display |
| 3098 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3099 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3100 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3101 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3102 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3103 | } |
| 3104 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3105 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3106 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3107 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3108 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3109 | mApp, subId, callingPackage, callingFeatureId, |
| 3110 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3111 | return -1; |
| 3112 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3113 | |
| 3114 | final long identity = Binder.clearCallingIdentity(); |
| 3115 | try { |
| 3116 | final Phone phone = getPhone(subId); |
| 3117 | if (phone != null) { |
| 3118 | return phone.getCdmaEriIconIndex(); |
| 3119 | } else { |
| 3120 | return -1; |
| 3121 | } |
| 3122 | } finally { |
| 3123 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3124 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3125 | } |
| 3126 | |
| 3127 | /** |
| 3128 | * Returns the CDMA ERI icon mode, |
| 3129 | * 0 - ON |
| 3130 | * 1 - FLASHING |
| 3131 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3132 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3133 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3134 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3135 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3136 | } |
| 3137 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3138 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3139 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3140 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3141 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3142 | mApp, subId, callingPackage, callingFeatureId, |
| 3143 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3144 | return -1; |
| 3145 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3146 | |
| 3147 | final long identity = Binder.clearCallingIdentity(); |
| 3148 | try { |
| 3149 | final Phone phone = getPhone(subId); |
| 3150 | if (phone != null) { |
| 3151 | return phone.getCdmaEriIconMode(); |
| 3152 | } else { |
| 3153 | return -1; |
| 3154 | } |
| 3155 | } finally { |
| 3156 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3157 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3158 | } |
| 3159 | |
| 3160 | /** |
| 3161 | * Returns the CDMA ERI text, |
| 3162 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3163 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3164 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3165 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3166 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3167 | } |
| 3168 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3169 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3170 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3171 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3172 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3173 | mApp, subId, callingPackage, callingFeatureId, |
| 3174 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3175 | return null; |
| 3176 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3177 | |
| 3178 | final long identity = Binder.clearCallingIdentity(); |
| 3179 | try { |
| 3180 | final Phone phone = getPhone(subId); |
| 3181 | if (phone != null) { |
| 3182 | return phone.getCdmaEriText(); |
| 3183 | } else { |
| 3184 | return null; |
| 3185 | } |
| 3186 | } finally { |
| 3187 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3188 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3189 | } |
| 3190 | |
| 3191 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3192 | * Returns the CDMA MDN. |
| 3193 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3194 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3195 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3196 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3197 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3198 | |
| 3199 | final long identity = Binder.clearCallingIdentity(); |
| 3200 | try { |
| 3201 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3202 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3203 | return phone.getLine1Number(); |
| 3204 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3205 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3206 | return null; |
| 3207 | } |
| 3208 | } finally { |
| 3209 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3210 | } |
| 3211 | } |
| 3212 | |
| 3213 | /** |
| 3214 | * Returns the CDMA MIN. |
| 3215 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3216 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3217 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3218 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3219 | mApp, subId, "getCdmaMin"); |
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 && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3225 | return phone.getCdmaMin(); |
| 3226 | } else { |
| 3227 | return null; |
| 3228 | } |
| 3229 | } finally { |
| 3230 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3231 | } |
| 3232 | } |
| 3233 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3234 | @Override |
| 3235 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3236 | INumberVerificationCallback callback, String callingPackage) { |
| 3237 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3238 | != PERMISSION_GRANTED) { |
| 3239 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3240 | } |
| 3241 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3242 | |
| 3243 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3244 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 3245 | throw new SecurityException("Calling package must be configured in the device config"); |
| 3246 | } |
| 3247 | |
| 3248 | if (range == null) { |
| 3249 | throw new NullPointerException("Range must be non-null"); |
| 3250 | } |
| 3251 | |
| 3252 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3253 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3254 | |
| 3255 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3256 | } |
| 3257 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3258 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3259 | * Returns true if CDMA provisioning needs to run. |
| 3260 | */ |
| 3261 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3262 | final long identity = Binder.clearCallingIdentity(); |
| 3263 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3264 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3265 | } finally { |
| 3266 | Binder.restoreCallingIdentity(identity); |
| 3267 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3268 | } |
| 3269 | |
| 3270 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3271 | * Sets the voice mail number of a given subId. |
| 3272 | */ |
| 3273 | @Override |
| 3274 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3275 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3276 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3277 | |
| 3278 | final long identity = Binder.clearCallingIdentity(); |
| 3279 | try { |
| 3280 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3281 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3282 | return success; |
| 3283 | } finally { |
| 3284 | Binder.restoreCallingIdentity(identity); |
| 3285 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3286 | } |
| 3287 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3288 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3289 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3290 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3291 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3292 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3293 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3294 | throw new SecurityException("caller must be system dialer"); |
| 3295 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3296 | |
| 3297 | final long identity = Binder.clearCallingIdentity(); |
| 3298 | try { |
| 3299 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3300 | if (phoneAccountHandle == null) { |
| 3301 | return null; |
| 3302 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3303 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3304 | } finally { |
| 3305 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3306 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3307 | } |
| 3308 | |
| 3309 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3310 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3311 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3312 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3313 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3314 | mApp, subId, callingPackage, callingFeatureId, |
| 3315 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3316 | return null; |
| 3317 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3318 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3319 | final long identity = Binder.clearCallingIdentity(); |
| 3320 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3321 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3322 | } finally { |
| 3323 | Binder.restoreCallingIdentity(identity); |
| 3324 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3325 | } |
| 3326 | |
| 3327 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3328 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3329 | VisualVoicemailSmsFilterSettings settings) { |
| 3330 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3331 | |
| 3332 | final long identity = Binder.clearCallingIdentity(); |
| 3333 | try { |
| 3334 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3335 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3336 | } finally { |
| 3337 | Binder.restoreCallingIdentity(identity); |
| 3338 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3339 | } |
| 3340 | |
| 3341 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3342 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3343 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3344 | |
| 3345 | final long identity = Binder.clearCallingIdentity(); |
| 3346 | try { |
| 3347 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3348 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3349 | } finally { |
| 3350 | Binder.restoreCallingIdentity(identity); |
| 3351 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3352 | } |
| 3353 | |
| 3354 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3355 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3356 | String callingPackage, int subId) { |
| 3357 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3358 | |
| 3359 | final long identity = Binder.clearCallingIdentity(); |
| 3360 | try { |
| 3361 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3362 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3363 | } finally { |
| 3364 | Binder.restoreCallingIdentity(identity); |
| 3365 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3366 | } |
| 3367 | |
| 3368 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3369 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3370 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3371 | |
| 3372 | final long identity = Binder.clearCallingIdentity(); |
| 3373 | try { |
| 3374 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3375 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3376 | } finally { |
| 3377 | Binder.restoreCallingIdentity(identity); |
| 3378 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3379 | } |
| 3380 | |
| 3381 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3382 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3383 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3384 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3385 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3386 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3387 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3388 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3389 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3390 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3391 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3392 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3393 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3394 | * Sets the voice activation state of a given subId. |
| 3395 | */ |
| 3396 | @Override |
| 3397 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3398 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3399 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3400 | |
| 3401 | final long identity = Binder.clearCallingIdentity(); |
| 3402 | try { |
| 3403 | final Phone phone = getPhone(subId); |
| 3404 | if (phone != null) { |
| 3405 | phone.setVoiceActivationState(activationState); |
| 3406 | } else { |
| 3407 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3408 | } |
| 3409 | } finally { |
| 3410 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3411 | } |
| 3412 | } |
| 3413 | |
| 3414 | /** |
| 3415 | * Sets the data activation state of a given subId. |
| 3416 | */ |
| 3417 | @Override |
| 3418 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3419 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3420 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3421 | |
| 3422 | final long identity = Binder.clearCallingIdentity(); |
| 3423 | try { |
| 3424 | final Phone phone = getPhone(subId); |
| 3425 | if (phone != null) { |
| 3426 | phone.setDataActivationState(activationState); |
| 3427 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3428 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3429 | } |
| 3430 | } finally { |
| 3431 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3432 | } |
| 3433 | } |
| 3434 | |
| 3435 | /** |
| 3436 | * Returns the voice activation state of a given subId. |
| 3437 | */ |
| 3438 | @Override |
| 3439 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3440 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3441 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3442 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3443 | final long identity = Binder.clearCallingIdentity(); |
| 3444 | try { |
| 3445 | if (phone != null) { |
| 3446 | return phone.getVoiceActivationState(); |
| 3447 | } else { |
| 3448 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3449 | } |
| 3450 | } finally { |
| 3451 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3452 | } |
| 3453 | } |
| 3454 | |
| 3455 | /** |
| 3456 | * Returns the data activation state of a given subId. |
| 3457 | */ |
| 3458 | @Override |
| 3459 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3460 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3461 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3462 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3463 | final long identity = Binder.clearCallingIdentity(); |
| 3464 | try { |
| 3465 | if (phone != null) { |
| 3466 | return phone.getDataActivationState(); |
| 3467 | } else { |
| 3468 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3469 | } |
| 3470 | } finally { |
| 3471 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3472 | } |
| 3473 | } |
| 3474 | |
| 3475 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3476 | * Returns the unread count of voicemails for a subId |
| 3477 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3478 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3479 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3480 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3481 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3482 | mApp, subId, callingPackage, callingFeatureId, |
| 3483 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3484 | return 0; |
| 3485 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3486 | final long identity = Binder.clearCallingIdentity(); |
| 3487 | try { |
| 3488 | final Phone phone = getPhone(subId); |
| 3489 | if (phone != null) { |
| 3490 | return phone.getVoiceMessageCount(); |
| 3491 | } else { |
| 3492 | return 0; |
| 3493 | } |
| 3494 | } finally { |
| 3495 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3496 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3497 | } |
| 3498 | |
| 3499 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3500 | * returns true, if the device is in a state where both voice and data |
| 3501 | * are supported simultaneously. This can change based on location or network condition. |
| 3502 | */ |
| 3503 | @Override |
| 3504 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3505 | final long identity = Binder.clearCallingIdentity(); |
| 3506 | try { |
| 3507 | final Phone phone = getPhone(subId); |
| 3508 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3509 | } finally { |
| 3510 | Binder.restoreCallingIdentity(identity); |
| 3511 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3512 | } |
| 3513 | |
| 3514 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3515 | * Send the dialer code if called from the current default dialer or the caller has |
| 3516 | * carrier privilege. |
| 3517 | * @param inputCode The dialer code to send |
| 3518 | */ |
| 3519 | @Override |
| 3520 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3521 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3522 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3523 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3524 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3525 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3526 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3527 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3528 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3529 | |
| 3530 | final long identity = Binder.clearCallingIdentity(); |
| 3531 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3532 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3533 | } finally { |
| 3534 | Binder.restoreCallingIdentity(identity); |
| 3535 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3536 | } |
| 3537 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3538 | @Override |
| 3539 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3540 | TelephonyPermissions |
| 3541 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3542 | mApp, subId, "getNetworkSelectionMode"); |
| 3543 | final long identity = Binder.clearCallingIdentity(); |
| 3544 | try { |
| 3545 | if (!isActiveSubscription(subId)) { |
| 3546 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3547 | } |
| 3548 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3549 | } finally { |
| 3550 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3551 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3552 | } |
| 3553 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3554 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3555 | public boolean isInEmergencySmsMode() { |
| 3556 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3557 | final long identity = Binder.clearCallingIdentity(); |
| 3558 | try { |
| 3559 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3560 | if (phone.isInEmergencySmsMode()) { |
| 3561 | return true; |
| 3562 | } |
| 3563 | } |
| 3564 | } finally { |
| 3565 | Binder.restoreCallingIdentity(identity); |
| 3566 | } |
| 3567 | return false; |
| 3568 | } |
| 3569 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3570 | /** |
| 3571 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3572 | * @param subId The subscription to use to check the configuration. |
| 3573 | * @param c The callback that will be used to send the result. |
| 3574 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3575 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3576 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3577 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3578 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3579 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3580 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3581 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3582 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3583 | "IMS not available on device."); |
| 3584 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3585 | final long token = Binder.clearCallingIdentity(); |
| 3586 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3587 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3588 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3589 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3590 | } catch (ImsException e) { |
| 3591 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3592 | } finally { |
| 3593 | Binder.restoreCallingIdentity(token); |
| 3594 | } |
| 3595 | } |
| 3596 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3597 | /** |
| 3598 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3599 | * @param subId The subscription to use to check the configuration. |
| 3600 | * @param c The callback that will be used to send the result. |
| 3601 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3602 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3603 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3604 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3605 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3606 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3607 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3608 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3609 | final long token = Binder.clearCallingIdentity(); |
| 3610 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3611 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3612 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3613 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3614 | } catch (ImsException e) { |
| 3615 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3616 | + "is inactive, ignoring unregister."); |
| 3617 | // If the subscription is no longer active, just return, since the callback |
| 3618 | // will already have been removed internally. |
| 3619 | } finally { |
| 3620 | Binder.restoreCallingIdentity(token); |
| 3621 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3622 | } |
| 3623 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3624 | /** |
| 3625 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3626 | */ |
| 3627 | @Override |
| 3628 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3629 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3630 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3631 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3632 | "IMS not available on device."); |
| 3633 | } |
| 3634 | final long token = Binder.clearCallingIdentity(); |
| 3635 | try { |
| 3636 | Phone phone = getPhone(subId); |
| 3637 | if (phone == null) { |
| 3638 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3639 | + subId + "'"); |
| 3640 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3641 | } |
| 3642 | phone.getImsRegistrationState(regState -> { |
| 3643 | try { |
| 3644 | consumer.accept((regState == null) |
| 3645 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3646 | } catch (RemoteException e) { |
| 3647 | // Ignore if the remote process is no longer available to call back. |
| 3648 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3649 | } |
| 3650 | }); |
| 3651 | } finally { |
| 3652 | Binder.restoreCallingIdentity(token); |
| 3653 | } |
| 3654 | } |
| 3655 | |
| 3656 | /** |
| 3657 | * Get the transport type for the IMS service registration state. |
| 3658 | */ |
| 3659 | @Override |
| 3660 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3661 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3662 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3663 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3664 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3665 | "IMS not available on device."); |
| 3666 | } |
| 3667 | final long token = Binder.clearCallingIdentity(); |
| 3668 | try { |
| 3669 | Phone phone = getPhone(subId); |
| 3670 | if (phone == null) { |
| 3671 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3672 | + subId + "'"); |
| 3673 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3674 | } |
| 3675 | phone.getImsRegistrationTech(regTech -> { |
| 3676 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3677 | int regTechConverted = (regTech == null) |
| 3678 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3679 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3680 | regTechConverted); |
| 3681 | try { |
| 3682 | consumer.accept(regTechConverted); |
| 3683 | } catch (RemoteException e) { |
| 3684 | // Ignore if the remote process is no longer available to call back. |
| 3685 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3686 | } |
| 3687 | }); |
| 3688 | } finally { |
| 3689 | Binder.restoreCallingIdentity(token); |
| 3690 | } |
| 3691 | } |
| 3692 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3693 | /** |
| 3694 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3695 | * @param subId The subscription to use to check the configuration. |
| 3696 | * @param c The callback that will be used to send the result. |
| 3697 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3698 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3699 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3700 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3701 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3702 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3703 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3704 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3705 | "IMS not available on device."); |
| 3706 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3707 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3708 | final long token = Binder.clearCallingIdentity(); |
| 3709 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3710 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3711 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3712 | } catch (ImsException e) { |
| 3713 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3714 | } finally { |
| 3715 | Binder.restoreCallingIdentity(token); |
| 3716 | } |
| 3717 | } |
| 3718 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3719 | /** |
| 3720 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3721 | * @param subId The subscription to use to check the configuration. |
| 3722 | * @param c The callback that will be used to send the result. |
| 3723 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3724 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3725 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3726 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3727 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3728 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3729 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3730 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3731 | |
| 3732 | final long token = Binder.clearCallingIdentity(); |
| 3733 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3734 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3735 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3736 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3737 | } catch (ImsException e) { |
| 3738 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3739 | + "is inactive, ignoring unregister."); |
| 3740 | // If the subscription is no longer active, just return, since the callback |
| 3741 | // will already have been removed internally. |
| 3742 | } finally { |
| 3743 | Binder.restoreCallingIdentity(token); |
| 3744 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3745 | } |
| 3746 | |
| 3747 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3748 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3749 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3750 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3751 | final long token = Binder.clearCallingIdentity(); |
| 3752 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3753 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3754 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3755 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3756 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3757 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3758 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3759 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3760 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3761 | } finally { |
| 3762 | Binder.restoreCallingIdentity(token); |
| 3763 | } |
| 3764 | } |
| 3765 | |
| 3766 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3767 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3768 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3769 | final long token = Binder.clearCallingIdentity(); |
| 3770 | try { |
| 3771 | Phone phone = getPhone(subId); |
| 3772 | if (phone == null) return false; |
| 3773 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3774 | } catch (com.android.ims.ImsException e) { |
| 3775 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3776 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3777 | } finally { |
| 3778 | Binder.restoreCallingIdentity(token); |
| 3779 | } |
| 3780 | } |
| 3781 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3782 | /** |
| 3783 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3784 | * subscription. |
| 3785 | * @param subId The subscription to use to check the configuration. |
| 3786 | * @param callback The callback that will be used to send the result. |
| 3787 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3788 | * @param transportType The transport type of the MmTelFeature capability. |
| 3789 | */ |
| 3790 | @Override |
| 3791 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3792 | int transportType) { |
| 3793 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3794 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3795 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3796 | "IMS not available on device."); |
| 3797 | } |
| 3798 | final long token = Binder.clearCallingIdentity(); |
| 3799 | try { |
| 3800 | int slotId = getSlotIndex(subId); |
| 3801 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3802 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3803 | + subId + "'"); |
| 3804 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3805 | } |
| 3806 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3807 | transportType, aBoolean -> { |
| 3808 | try { |
| 3809 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3810 | } catch (RemoteException e) { |
| 3811 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3812 | + "running. Ignore"); |
| 3813 | } |
| 3814 | }); |
| 3815 | } finally { |
| 3816 | Binder.restoreCallingIdentity(token); |
| 3817 | } |
| 3818 | } |
| 3819 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3820 | /** |
| 3821 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3822 | * @param subId The subscription to use to check the configuration. |
| 3823 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3824 | @Override |
| 3825 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3826 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3827 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3828 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3829 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3830 | final long token = Binder.clearCallingIdentity(); |
| 3831 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3832 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3833 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3834 | } catch (ImsException e) { |
| 3835 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3836 | } finally { |
| 3837 | Binder.restoreCallingIdentity(token); |
| 3838 | } |
| 3839 | } |
| 3840 | |
| 3841 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3842 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3843 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3844 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3845 | final long identity = Binder.clearCallingIdentity(); |
| 3846 | try { |
| 3847 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3848 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3849 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3850 | } catch (ImsException e) { |
| 3851 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3852 | } finally { |
| 3853 | Binder.restoreCallingIdentity(identity); |
| 3854 | } |
| 3855 | } |
| 3856 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3857 | /** |
| 3858 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3859 | * @param subId The subscription to use to check the configuration. |
| 3860 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3861 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3862 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3863 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3864 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3865 | final long identity = Binder.clearCallingIdentity(); |
| 3866 | try { |
| 3867 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3868 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3869 | } catch (ImsException e) { |
| 3870 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3871 | } finally { |
| 3872 | Binder.restoreCallingIdentity(identity); |
| 3873 | } |
| 3874 | } |
| 3875 | |
| 3876 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3877 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3878 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3879 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3880 | final long identity = Binder.clearCallingIdentity(); |
| 3881 | try { |
| 3882 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3883 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3884 | } catch (ImsException e) { |
| 3885 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3886 | } finally { |
| 3887 | Binder.restoreCallingIdentity(identity); |
| 3888 | } |
| 3889 | } |
| 3890 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3891 | /** |
| 3892 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3893 | * @param subId The subscription to use to check the configuration. |
| 3894 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3895 | @Override |
| 3896 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3897 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3898 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3899 | final long identity = Binder.clearCallingIdentity(); |
| 3900 | try { |
| 3901 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3902 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3903 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3904 | } catch (ImsException e) { |
| 3905 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3906 | } finally { |
| 3907 | Binder.restoreCallingIdentity(identity); |
| 3908 | } |
| 3909 | } |
| 3910 | |
| 3911 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3912 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3913 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3914 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3915 | final long identity = Binder.clearCallingIdentity(); |
| 3916 | try { |
| 3917 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3918 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3919 | } catch (ImsException e) { |
| 3920 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3921 | } finally { |
| 3922 | Binder.restoreCallingIdentity(identity); |
| 3923 | } |
| 3924 | } |
| 3925 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3926 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame^] | 3927 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 3928 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3929 | * @param subId The subscription to use to check the configuration. |
| 3930 | */ |
| 3931 | @Override |
| 3932 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
| 3933 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3934 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 3935 | final long identity = Binder.clearCallingIdentity(); |
| 3936 | try { |
| 3937 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3938 | return ImsManager.getInstance(mApp, |
| 3939 | getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser(); |
| 3940 | } catch (ImsException e) { |
| 3941 | throw new ServiceSpecificException(e.getCode()); |
| 3942 | } finally { |
| 3943 | Binder.restoreCallingIdentity(identity); |
| 3944 | } |
| 3945 | } |
| 3946 | |
| 3947 | /** |
| 3948 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 3949 | * Requires MODIFY_PHONE_STATE permission. |
| 3950 | * @param subId The subscription to use to check the configuration. |
| 3951 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 3952 | * false otherwise |
| 3953 | */ |
| 3954 | @Override |
| 3955 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 3956 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3957 | "setCrossSimCallingEnabled"); |
| 3958 | final long identity = Binder.clearCallingIdentity(); |
| 3959 | try { |
| 3960 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3961 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3962 | .setCrossSimCallingEnabled(isEnabled); |
| 3963 | } catch (ImsException e) { |
| 3964 | throw new ServiceSpecificException(e.getCode()); |
| 3965 | } finally { |
| 3966 | Binder.restoreCallingIdentity(identity); |
| 3967 | } |
| 3968 | } |
| 3969 | |
| 3970 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3971 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3972 | * @param subId The subscription to use to check the configuration. |
| 3973 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3974 | @Override |
| 3975 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3976 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3977 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3978 | final long identity = Binder.clearCallingIdentity(); |
| 3979 | try { |
| 3980 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3981 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3982 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3983 | } catch (ImsException e) { |
| 3984 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3985 | } finally { |
| 3986 | Binder.restoreCallingIdentity(identity); |
| 3987 | } |
| 3988 | } |
| 3989 | |
| 3990 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3991 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3992 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3993 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3994 | final long identity = Binder.clearCallingIdentity(); |
| 3995 | try { |
| 3996 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3997 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3998 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3999 | } catch (ImsException e) { |
| 4000 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4001 | } finally { |
| 4002 | Binder.restoreCallingIdentity(identity); |
| 4003 | } |
| 4004 | } |
| 4005 | |
| 4006 | @Override |
| 4007 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4008 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4009 | "setVoWiFiNonPersistent"); |
| 4010 | final long identity = Binder.clearCallingIdentity(); |
| 4011 | try { |
| 4012 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4013 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 4014 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4015 | } catch (ImsException e) { |
| 4016 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4017 | } finally { |
| 4018 | Binder.restoreCallingIdentity(identity); |
| 4019 | } |
| 4020 | } |
| 4021 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4022 | /** |
| 4023 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4024 | * @param subId The subscription to use to check the configuration. |
| 4025 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4026 | @Override |
| 4027 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4028 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4029 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4030 | final long identity = Binder.clearCallingIdentity(); |
| 4031 | try { |
| 4032 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4033 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4034 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4035 | } catch (ImsException e) { |
| 4036 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4037 | } finally { |
| 4038 | Binder.restoreCallingIdentity(identity); |
| 4039 | } |
| 4040 | } |
| 4041 | |
| 4042 | @Override |
| 4043 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4044 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4045 | "setVoWiFiModeSetting"); |
| 4046 | final long identity = Binder.clearCallingIdentity(); |
| 4047 | try { |
| 4048 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4049 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4050 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4051 | } catch (ImsException e) { |
| 4052 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4053 | } finally { |
| 4054 | Binder.restoreCallingIdentity(identity); |
| 4055 | } |
| 4056 | } |
| 4057 | |
| 4058 | @Override |
| 4059 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4060 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4061 | final long identity = Binder.clearCallingIdentity(); |
| 4062 | try { |
| 4063 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4064 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4065 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4066 | } catch (ImsException e) { |
| 4067 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4068 | } finally { |
| 4069 | Binder.restoreCallingIdentity(identity); |
| 4070 | } |
| 4071 | } |
| 4072 | |
| 4073 | @Override |
| 4074 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4075 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4076 | "setVoWiFiRoamingModeSetting"); |
| 4077 | final long identity = Binder.clearCallingIdentity(); |
| 4078 | try { |
| 4079 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4080 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4081 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4082 | } catch (ImsException e) { |
| 4083 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4084 | } finally { |
| 4085 | Binder.restoreCallingIdentity(identity); |
| 4086 | } |
| 4087 | } |
| 4088 | |
| 4089 | @Override |
| 4090 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4091 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4092 | "setRttCapabilityEnabled"); |
| 4093 | final long identity = Binder.clearCallingIdentity(); |
| 4094 | try { |
| 4095 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4096 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 4097 | } catch (ImsException e) { |
| 4098 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4099 | } finally { |
| 4100 | Binder.restoreCallingIdentity(identity); |
| 4101 | } |
| 4102 | } |
| 4103 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4104 | /** |
| 4105 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4106 | * @param subId The subscription to use to check the configuration. |
| 4107 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4108 | @Override |
| 4109 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4110 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4111 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4112 | final long identity = Binder.clearCallingIdentity(); |
| 4113 | try { |
| 4114 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4115 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4116 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4117 | } catch (ImsException e) { |
| 4118 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4119 | } finally { |
| 4120 | Binder.restoreCallingIdentity(identity); |
| 4121 | } |
| 4122 | } |
| 4123 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4124 | @Override |
| 4125 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4126 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4127 | final long identity = Binder.clearCallingIdentity(); |
| 4128 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4129 | if (!isImsAvailableOnDevice()) { |
| 4130 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4131 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4132 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4133 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4134 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4135 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4136 | } catch (ImsException e) { |
| 4137 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4138 | } finally { |
| 4139 | Binder.restoreCallingIdentity(identity); |
| 4140 | } |
| 4141 | } |
| 4142 | |
| 4143 | @Override |
| 4144 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4145 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4146 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4147 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4148 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4149 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4150 | try { |
| 4151 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4152 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4153 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4154 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4155 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4156 | + "is inactive, ignoring unregister."); |
| 4157 | // If the subscription is no longer active, just return, since the callback will already |
| 4158 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4159 | } finally { |
| 4160 | Binder.restoreCallingIdentity(identity); |
| 4161 | } |
| 4162 | } |
| 4163 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4164 | |
| 4165 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4166 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4167 | message); |
| 4168 | } |
| 4169 | |
| 4170 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4171 | boolean isMmtelCapability) { |
| 4172 | Phone phone = getPhone(subId); |
| 4173 | if (phone == null) { |
| 4174 | loge("phone instance null for subid " + subId); |
| 4175 | return false; |
| 4176 | } |
| 4177 | if (isMmtelCapability) { |
| 4178 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4179 | return false; |
| 4180 | } |
| 4181 | } else { |
| 4182 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4183 | return false; |
| 4184 | } |
| 4185 | } |
| 4186 | return true; |
| 4187 | } |
| 4188 | |
| 4189 | @Override |
| 4190 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4191 | boolean isProvisioned) { |
| 4192 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4193 | |
| 4194 | final long identity = Binder.clearCallingIdentity(); |
| 4195 | try { |
| 4196 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4197 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4198 | return; |
| 4199 | } |
| 4200 | |
| 4201 | // this capability requires provisioning, route to the correct API. |
| 4202 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4203 | switch (capability) { |
| 4204 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4205 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4206 | ims.setEabProvisioned(isProvisioned); |
| 4207 | break; |
| 4208 | default: { |
| 4209 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4210 | + "rcs capability '" + capability + "', which does not require " |
| 4211 | + "provisioning."); |
| 4212 | } |
| 4213 | } |
| 4214 | } finally { |
| 4215 | Binder.restoreCallingIdentity(identity); |
| 4216 | } |
| 4217 | |
| 4218 | } |
| 4219 | |
| 4220 | |
| 4221 | @Override |
| 4222 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4223 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4224 | final long identity = Binder.clearCallingIdentity(); |
| 4225 | try { |
| 4226 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4227 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4228 | return true; |
| 4229 | } |
| 4230 | |
| 4231 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4232 | switch (capability) { |
| 4233 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4234 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4235 | return ims.isEabProvisionedOnDevice(); |
| 4236 | |
| 4237 | default: { |
| 4238 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4239 | + "capability '" + capability + "', which does not require " |
| 4240 | + "provisioning."); |
| 4241 | } |
| 4242 | } |
| 4243 | |
| 4244 | } finally { |
| 4245 | Binder.restoreCallingIdentity(identity); |
| 4246 | } |
| 4247 | } |
| 4248 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4249 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4250 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4251 | boolean isProvisioned) { |
| 4252 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4253 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4254 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4255 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4256 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4257 | final long identity = Binder.clearCallingIdentity(); |
| 4258 | try { |
| 4259 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4260 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4261 | return; |
| 4262 | } |
| 4263 | |
| 4264 | // this capability requires provisioning, route to the correct API. |
| 4265 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4266 | switch (capability) { |
| 4267 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4268 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4269 | ims.setVolteProvisioned(isProvisioned); |
| 4270 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4271 | ims.setWfcProvisioned(isProvisioned); |
| 4272 | } |
| 4273 | break; |
| 4274 | } |
| 4275 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4276 | // There is currently no difference in VT provisioning type. |
| 4277 | ims.setVtProvisioned(isProvisioned); |
| 4278 | break; |
| 4279 | } |
| 4280 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4281 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4282 | // change the capability of the feature instead if needed. |
| 4283 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4284 | == isProvisioned) { |
| 4285 | // No change in provisioning. |
| 4286 | return; |
| 4287 | } |
| 4288 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4289 | try { |
| 4290 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4291 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4292 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4293 | + ", Exception" + e.getMessage()); |
| 4294 | } |
| 4295 | break; |
| 4296 | } |
| 4297 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4298 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4299 | + "MmTel capability '" + capability + "', which does not require " |
| 4300 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4301 | } |
| 4302 | } |
| 4303 | |
| 4304 | } finally { |
| 4305 | Binder.restoreCallingIdentity(identity); |
| 4306 | } |
| 4307 | } |
| 4308 | |
| 4309 | @Override |
| 4310 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4311 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4312 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4313 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4314 | } |
| 4315 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4316 | final long identity = Binder.clearCallingIdentity(); |
| 4317 | try { |
| 4318 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4319 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4320 | return true; |
| 4321 | } |
| 4322 | |
| 4323 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4324 | switch (capability) { |
| 4325 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4326 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4327 | return ims.isVolteProvisionedOnDevice(); |
| 4328 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4329 | return ims.isWfcProvisionedOnDevice(); |
| 4330 | } |
| 4331 | // This should never happen, since we are checking tech above to make sure it |
| 4332 | // is either LTE or IWLAN. |
| 4333 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4334 | + "capability."); |
| 4335 | } |
| 4336 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4337 | // There is currently no difference in VT provisioning type. |
| 4338 | return ims.isVtProvisionedOnDevice(); |
| 4339 | } |
| 4340 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4341 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4342 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4343 | } |
| 4344 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4345 | throw new IllegalArgumentException( |
| 4346 | "Tried to get provisioning for MmTel capability '" + capability |
| 4347 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4348 | } |
| 4349 | } |
| 4350 | |
| 4351 | } finally { |
| 4352 | Binder.restoreCallingIdentity(identity); |
| 4353 | } |
| 4354 | } |
| 4355 | |
| 4356 | @Override |
| 4357 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4358 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4359 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4360 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4361 | } |
| 4362 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4363 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4364 | return (provisionedBits & capability) > 0; |
| 4365 | } |
| 4366 | |
| 4367 | @Override |
| 4368 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4369 | boolean isProvisioned) { |
| 4370 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4371 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4372 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4373 | } |
| 4374 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4375 | "setProvisioningStatusForCapability"); |
| 4376 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4377 | // If the current provisioning status for capability already matches isProvisioned, |
| 4378 | // do nothing. |
| 4379 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4380 | return; |
| 4381 | } |
| 4382 | if (isProvisioned) { |
| 4383 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4384 | } else { |
| 4385 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4386 | } |
| 4387 | } |
| 4388 | |
| 4389 | /** |
| 4390 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4391 | * technology. The bitfield should mirror the bitfield defined by |
| 4392 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4393 | */ |
| 4394 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4395 | String key = getMmTelProvisioningKey(subId, tech); |
| 4396 | // Default is no capabilities are provisioned. |
| 4397 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4398 | } |
| 4399 | |
| 4400 | /** |
| 4401 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4402 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4403 | * technology specified. |
| 4404 | * |
| 4405 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4406 | */ |
| 4407 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4408 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4409 | String key = getMmTelProvisioningKey(subId, tech); |
| 4410 | editor.putInt(key, newField); |
| 4411 | editor.commit(); |
| 4412 | } |
| 4413 | |
| 4414 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4415 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4416 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4417 | } |
| 4418 | |
| 4419 | /** |
| 4420 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4421 | * carrier associated with the subscription id. |
| 4422 | */ |
| 4423 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4424 | int capability) { |
| 4425 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4426 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4427 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4428 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4429 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4430 | false); |
| 4431 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4432 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4433 | |
| 4434 | // First check to make sure that the capability requires provisioning. |
| 4435 | switch (capability) { |
| 4436 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4437 | // intentional fallthrough |
| 4438 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4439 | if (requireVoiceVtProvisioning) { |
| 4440 | // Voice and Video requires provisioning |
| 4441 | return true; |
| 4442 | } |
| 4443 | break; |
| 4444 | } |
| 4445 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4446 | if (requireUtProvisioning) { |
| 4447 | // UT requires provisioning |
| 4448 | return true; |
| 4449 | } |
| 4450 | break; |
| 4451 | } |
| 4452 | } |
| 4453 | return false; |
| 4454 | } |
| 4455 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4456 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4457 | int capability) { |
| 4458 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4459 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4460 | |
| 4461 | boolean requireRcsProvisioning = c.getBoolean( |
| 4462 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4463 | |
| 4464 | // First check to make sure that the capability requires provisioning. |
| 4465 | switch (capability) { |
| 4466 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4467 | // intentional fallthrough |
| 4468 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4469 | if (requireRcsProvisioning) { |
| 4470 | // OPTION or PRESENCE requires provisioning |
| 4471 | return true; |
| 4472 | } |
| 4473 | break; |
| 4474 | } |
| 4475 | } |
| 4476 | return false; |
| 4477 | } |
| 4478 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4479 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4480 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4481 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4482 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4483 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4484 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4485 | final long identity = Binder.clearCallingIdentity(); |
| 4486 | try { |
| 4487 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4488 | int slotId = getSlotIndex(subId); |
| 4489 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4490 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4491 | + subId + "' for key:" + key); |
| 4492 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4493 | } |
| 4494 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4495 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4496 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4497 | + subId + "' for key:" + key); |
| 4498 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4499 | } finally { |
| 4500 | Binder.restoreCallingIdentity(identity); |
| 4501 | } |
| 4502 | } |
| 4503 | |
| 4504 | @Override |
| 4505 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4506 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4507 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4508 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4509 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4510 | final long identity = Binder.clearCallingIdentity(); |
| 4511 | try { |
| 4512 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4513 | int slotId = getSlotIndex(subId); |
| 4514 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4515 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4516 | + subId + "' for key:" + key); |
| 4517 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4518 | } |
| 4519 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4520 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4521 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4522 | + subId + "' for key:" + key); |
| 4523 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4524 | } finally { |
| 4525 | Binder.restoreCallingIdentity(identity); |
| 4526 | } |
| 4527 | } |
| 4528 | |
| 4529 | @Override |
| 4530 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4531 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4532 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4533 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4534 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4535 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4536 | final long identity = Binder.clearCallingIdentity(); |
| 4537 | try { |
| 4538 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4539 | int slotId = getSlotIndex(subId); |
| 4540 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4541 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4542 | + subId + "' for key:" + key); |
| 4543 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4544 | } |
| 4545 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4546 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4547 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4548 | + "' for key:" + key); |
| 4549 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4550 | } finally { |
| 4551 | Binder.restoreCallingIdentity(identity); |
| 4552 | } |
| 4553 | } |
| 4554 | |
| 4555 | @Override |
| 4556 | public int setImsProvisioningString(int subId, int key, String value) { |
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 | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4560 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4561 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4562 | final long identity = Binder.clearCallingIdentity(); |
| 4563 | try { |
| 4564 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4565 | int slotId = getSlotIndex(subId); |
| 4566 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4567 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4568 | + subId + "' for key:" + key); |
| 4569 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4570 | } |
| 4571 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4572 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4573 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4574 | + "' for key:" + key); |
| 4575 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4576 | } finally { |
| 4577 | Binder.restoreCallingIdentity(identity); |
| 4578 | } |
| 4579 | } |
| 4580 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4581 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4582 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4583 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4584 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4585 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4586 | } |
| 4587 | return slotId; |
| 4588 | } |
| 4589 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4590 | private int getSlotIndex(int subId) { |
| 4591 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4592 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4593 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4594 | } |
| 4595 | return slotId; |
| 4596 | } |
| 4597 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4598 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4599 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4600 | */ |
| 4601 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4602 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4603 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4604 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4605 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4606 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4607 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4608 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4609 | mApp, subId, callingPackage, callingFeatureId, |
| 4610 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4611 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4612 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4613 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4614 | final long identity = Binder.clearCallingIdentity(); |
| 4615 | try { |
| 4616 | final Phone phone = getPhone(subId); |
| 4617 | if (phone != null) { |
| 4618 | return phone.getServiceState().getDataNetworkType(); |
| 4619 | } else { |
| 4620 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4621 | } |
| 4622 | } finally { |
| 4623 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4624 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4625 | } |
| 4626 | |
| 4627 | /** |
| 4628 | * Returns the data network type |
| 4629 | */ |
| 4630 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4631 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4632 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4633 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4634 | } |
| 4635 | |
| 4636 | /** |
| 4637 | * Returns the data network type for a subId |
| 4638 | */ |
| 4639 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4640 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4641 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4642 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4643 | mApp, subId, callingPackage, callingFeatureId, |
| 4644 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4645 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4646 | } |
| 4647 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4648 | final long identity = Binder.clearCallingIdentity(); |
| 4649 | try { |
| 4650 | final Phone phone = getPhone(subId); |
| 4651 | if (phone != null) { |
| 4652 | return phone.getServiceState().getDataNetworkType(); |
| 4653 | } else { |
| 4654 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4655 | } |
| 4656 | } finally { |
| 4657 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4658 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4659 | } |
| 4660 | |
| 4661 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4662 | * Returns the Voice network type for a subId |
| 4663 | */ |
| 4664 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4665 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4666 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4667 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4668 | mApp, subId, callingPackage, callingFeatureId, |
| 4669 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4670 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4671 | } |
| 4672 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4673 | final long identity = Binder.clearCallingIdentity(); |
| 4674 | try { |
| 4675 | final Phone phone = getPhone(subId); |
| 4676 | if (phone != null) { |
| 4677 | return phone.getServiceState().getVoiceNetworkType(); |
| 4678 | } else { |
| 4679 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4680 | } |
| 4681 | } finally { |
| 4682 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4683 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4684 | } |
| 4685 | |
| 4686 | /** |
| 4687 | * @return true if a ICC card is present |
| 4688 | */ |
| 4689 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4690 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4691 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4692 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4693 | } |
| 4694 | |
| 4695 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4696 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4697 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4698 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4699 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4700 | final long identity = Binder.clearCallingIdentity(); |
| 4701 | try { |
| 4702 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4703 | if (phone != null) { |
| 4704 | return phone.getIccCard().hasIccCard(); |
| 4705 | } else { |
| 4706 | return false; |
| 4707 | } |
| 4708 | } finally { |
| 4709 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4710 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4711 | } |
| 4712 | |
| 4713 | /** |
| 4714 | * Return if the current radio is LTE on CDMA. This |
| 4715 | * is a tri-state return value as for a period of time |
| 4716 | * the mode may be unknown. |
| 4717 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4718 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4719 | * @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] | 4720 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4721 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4722 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4723 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4724 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4725 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4726 | } |
| 4727 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4728 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4729 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4730 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4731 | try { |
| 4732 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4733 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4734 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4735 | } |
| 4736 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4737 | final long identity = Binder.clearCallingIdentity(); |
| 4738 | try { |
| 4739 | final Phone phone = getPhone(subId); |
| 4740 | if (phone == null) { |
| 4741 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4742 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4743 | return TelephonyProperties.lte_on_cdma_device() |
| 4744 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4745 | } |
| 4746 | } finally { |
| 4747 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4748 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4749 | } |
| 4750 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4751 | /** |
| 4752 | * {@hide} |
| 4753 | * Returns Default subId, 0 in the case of single standby. |
| 4754 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4755 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4756 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4757 | } |
| 4758 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4759 | private int getSlotForDefaultSubscription() { |
| 4760 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4761 | } |
| 4762 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4763 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4764 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4765 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4766 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4767 | private boolean isActiveSubscription(int subId) { |
| 4768 | return mSubscriptionController.isActiveSubId(subId); |
| 4769 | } |
| 4770 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4771 | /** |
| 4772 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4773 | */ |
| 4774 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4775 | final long identity = Binder.clearCallingIdentity(); |
| 4776 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4777 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4778 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4779 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4780 | } finally { |
| 4781 | Binder.restoreCallingIdentity(identity); |
| 4782 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4783 | } |
| 4784 | |
| 4785 | /** |
| 4786 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4787 | */ |
| 4788 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4789 | final long identity = Binder.clearCallingIdentity(); |
| 4790 | try { |
| 4791 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4792 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4793 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4794 | } finally { |
| 4795 | Binder.restoreCallingIdentity(identity); |
| 4796 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4797 | } |
| 4798 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4799 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4800 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4801 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4802 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4803 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4804 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4805 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4806 | if (phoneId == -1) { |
| 4807 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4808 | + " does not correspond to an active phone"); |
| 4809 | } |
| 4810 | return PhoneFactory.getPhone(phoneId); |
| 4811 | } |
| 4812 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4813 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4814 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4815 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4816 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4817 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4818 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4819 | if (DBG) { |
| 4820 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4821 | } |
| 4822 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4823 | p2); |
| 4824 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4825 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4826 | |
| 4827 | @Override |
| 4828 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4829 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4830 | enforceModifyPermission(); |
| 4831 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4832 | if (DBG) { |
| 4833 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4834 | } |
| 4835 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4836 | callingPackage, aid, p2); |
| 4837 | } |
| 4838 | |
| 4839 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4840 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4841 | final long identity = Binder.clearCallingIdentity(); |
| 4842 | try { |
| 4843 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4844 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4845 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4846 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4847 | if (bestComponent == null |
| 4848 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4849 | loge("The calling package is not allowed to access ISD-R."); |
| 4850 | throw new SecurityException( |
| 4851 | "The calling package is not allowed to access ISD-R."); |
| 4852 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4853 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4854 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4855 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4856 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4857 | null /* workSource */); |
| 4858 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4859 | return response; |
| 4860 | } finally { |
| 4861 | Binder.restoreCallingIdentity(identity); |
| 4862 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4863 | } |
| 4864 | |
| 4865 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4866 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4867 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4868 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4869 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4870 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4871 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4872 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4873 | @Override |
| 4874 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4875 | enforceModifyPermission(); |
| 4876 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4877 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4878 | channel); |
| 4879 | } |
| 4880 | |
| 4881 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4882 | final long identity = Binder.clearCallingIdentity(); |
| 4883 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4884 | if (channel < 0) { |
| 4885 | return false; |
| 4886 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4887 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4888 | null /* workSource */); |
| 4889 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4890 | return success; |
| 4891 | } finally { |
| 4892 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4893 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4894 | } |
| 4895 | |
| 4896 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4897 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4898 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4899 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4900 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4901 | if (DBG) { |
| 4902 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4903 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4904 | + p3 + " data=" + data); |
| 4905 | } |
| 4906 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4907 | command, p1, p2, p3, data); |
| 4908 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4909 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4910 | @Override |
| 4911 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4912 | int command, int p1, int p2, int p3, String data) { |
| 4913 | enforceModifyPermission(); |
| 4914 | if (DBG) { |
| 4915 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4916 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4917 | + p3 + " data=" + data); |
| 4918 | } |
| 4919 | return iccTransmitApduLogicalChannelWithPermission( |
| 4920 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4921 | data); |
| 4922 | } |
| 4923 | |
| 4924 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4925 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4926 | final long identity = Binder.clearCallingIdentity(); |
| 4927 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4928 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4929 | return ""; |
| 4930 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4931 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4932 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4933 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4934 | null /* workSource */); |
| 4935 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4936 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4937 | // Append the returned status code to the end of the response payload. |
| 4938 | String s = Integer.toHexString( |
| 4939 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4940 | if (response.payload != null) { |
| 4941 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4942 | } |
| 4943 | return s; |
| 4944 | } finally { |
| 4945 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4946 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4947 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4948 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4949 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4950 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4951 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4952 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4953 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4954 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4955 | if (DBG) { |
| 4956 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4957 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4958 | } |
| 4959 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4960 | cla, command, p1, p2, p3, data); |
| 4961 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4962 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4963 | @Override |
| 4964 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4965 | int command, int p1, int p2, int p3, String data) { |
| 4966 | enforceModifyPermission(); |
| 4967 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4968 | if (DBG) { |
| 4969 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4970 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4971 | + " data=" + data); |
| 4972 | } |
| 4973 | |
| 4974 | return iccTransmitApduBasicChannelWithPermission( |
| 4975 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4976 | p2, p3, data); |
| 4977 | } |
| 4978 | |
| 4979 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4980 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4981 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4982 | final long identity = Binder.clearCallingIdentity(); |
| 4983 | try { |
| 4984 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4985 | && TextUtils.equals(ISDR_AID, data)) { |
| 4986 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4987 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4988 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4989 | if (bestComponent == null |
| 4990 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4991 | loge("The calling package is not allowed to select ISD-R."); |
| 4992 | throw new SecurityException( |
| 4993 | "The calling package is not allowed to select ISD-R."); |
| 4994 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4995 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4996 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4997 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4998 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4999 | null /* workSource */); |
| 5000 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5001 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5002 | // Append the returned status code to the end of the response payload. |
| 5003 | String s = Integer.toHexString( |
| 5004 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5005 | if (response.payload != null) { |
| 5006 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5007 | } |
| 5008 | return s; |
| 5009 | } finally { |
| 5010 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5011 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5012 | } |
| 5013 | |
| 5014 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5015 | 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] | 5016 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5017 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5018 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5019 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5020 | final long identity = Binder.clearCallingIdentity(); |
| 5021 | try { |
| 5022 | if (DBG) { |
| 5023 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5024 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5025 | } |
| 5026 | |
| 5027 | IccIoResult response = |
| 5028 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5029 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5030 | subId); |
| 5031 | |
| 5032 | if (DBG) { |
| 5033 | log("Exchange SIM_IO [R]" + response); |
| 5034 | } |
| 5035 | |
| 5036 | byte[] result = null; |
| 5037 | int length = 2; |
| 5038 | if (response.payload != null) { |
| 5039 | length = 2 + response.payload.length; |
| 5040 | result = new byte[length]; |
| 5041 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5042 | } else { |
| 5043 | result = new byte[length]; |
| 5044 | } |
| 5045 | |
| 5046 | result[length - 1] = (byte) response.sw2; |
| 5047 | result[length - 2] = (byte) response.sw1; |
| 5048 | return result; |
| 5049 | } finally { |
| 5050 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5051 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5052 | } |
| 5053 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5054 | /** |
| 5055 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5056 | * on a particular subscription |
| 5057 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5058 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5059 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5060 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5061 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5062 | return null; |
| 5063 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5064 | |
| 5065 | final long identity = Binder.clearCallingIdentity(); |
| 5066 | try { |
| 5067 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5068 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5069 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5070 | return null; |
| 5071 | } |
| 5072 | Object response = sendRequest( |
| 5073 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5074 | if (response instanceof String[]) { |
| 5075 | return (String[]) response; |
| 5076 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5077 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5078 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5079 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5080 | } finally { |
| 5081 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5082 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5083 | } |
| 5084 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5085 | /** |
| 5086 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5087 | * subscription. |
| 5088 | * |
| 5089 | * @param subId the id of the subscription. |
| 5090 | * @param appType the uicc app type, must be USIM or SIM. |
| 5091 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5092 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5093 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5094 | * @return number of fplmns that is successfully written to the SIM. |
| 5095 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5096 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5097 | String callingFeatureId) { |
| 5098 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 5099 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5100 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 5101 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 5102 | } |
| 5103 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5104 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5105 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5106 | } |
| 5107 | if (fplmns == null) { |
| 5108 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5109 | } |
| 5110 | for (String fplmn : fplmns) { |
| 5111 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5112 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5113 | } |
| 5114 | } |
| 5115 | final long identity = Binder.clearCallingIdentity(); |
| 5116 | try { |
| 5117 | Object response = sendRequest( |
| 5118 | CMD_SET_FORBIDDEN_PLMNS, |
| 5119 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5120 | subId); |
| 5121 | return (int) response; |
| 5122 | } finally { |
| 5123 | Binder.restoreCallingIdentity(identity); |
| 5124 | } |
| 5125 | } |
| 5126 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5127 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5128 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5129 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5130 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5131 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5132 | final long identity = Binder.clearCallingIdentity(); |
| 5133 | try { |
| 5134 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5135 | if (response.payload == null) { |
| 5136 | return ""; |
| 5137 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5138 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5139 | // Append the returned status code to the end of the response payload. |
| 5140 | String s = Integer.toHexString( |
| 5141 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5142 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5143 | return s; |
| 5144 | } finally { |
| 5145 | Binder.restoreCallingIdentity(identity); |
| 5146 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5147 | } |
| 5148 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5149 | /** |
| 5150 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5151 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5152 | * |
| 5153 | * @param itemID the ID of the item to read |
| 5154 | * @return the NV item as a String, or null on error. |
| 5155 | */ |
| 5156 | @Override |
| 5157 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5158 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5159 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5160 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5161 | |
| 5162 | final long identity = Binder.clearCallingIdentity(); |
| 5163 | try { |
| 5164 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5165 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5166 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5167 | return value; |
| 5168 | } finally { |
| 5169 | Binder.restoreCallingIdentity(identity); |
| 5170 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5171 | } |
| 5172 | |
| 5173 | /** |
| 5174 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5175 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5176 | * |
| 5177 | * @param itemID the ID of the item to read |
| 5178 | * @param itemValue the value to write, as a String |
| 5179 | * @return true on success; false on any failure |
| 5180 | */ |
| 5181 | @Override |
| 5182 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5183 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5184 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5185 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5186 | |
| 5187 | final long identity = Binder.clearCallingIdentity(); |
| 5188 | try { |
| 5189 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5190 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5191 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5192 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5193 | return success; |
| 5194 | } finally { |
| 5195 | Binder.restoreCallingIdentity(identity); |
| 5196 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5197 | } |
| 5198 | |
| 5199 | /** |
| 5200 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5201 | * Used for device configuration by some CDMA operators. |
| 5202 | * |
| 5203 | * @param preferredRoamingList byte array containing the new PRL |
| 5204 | * @return true on success; false on any failure |
| 5205 | */ |
| 5206 | @Override |
| 5207 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5208 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5209 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5210 | |
| 5211 | final long identity = Binder.clearCallingIdentity(); |
| 5212 | try { |
| 5213 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5214 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5215 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5216 | return success; |
| 5217 | } finally { |
| 5218 | Binder.restoreCallingIdentity(identity); |
| 5219 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5220 | } |
| 5221 | |
| 5222 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5223 | * 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] | 5224 | * Used for device configuration by some CDMA operators. |
| 5225 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5226 | * @param slotIndex - device slot. |
| 5227 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5228 | * @return true on success; false on any failure |
| 5229 | */ |
| 5230 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5231 | public boolean resetModemConfig(int slotIndex) { |
| 5232 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5233 | if (phone != null) { |
| 5234 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5235 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5236 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5237 | final long identity = Binder.clearCallingIdentity(); |
| 5238 | try { |
| 5239 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5240 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5241 | return success; |
| 5242 | } finally { |
| 5243 | Binder.restoreCallingIdentity(identity); |
| 5244 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5245 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5246 | return false; |
| 5247 | } |
| 5248 | |
| 5249 | /** |
| 5250 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5251 | * |
| 5252 | * @param slotIndex - device slot. |
| 5253 | * |
| 5254 | * @return true on success; false on any failure |
| 5255 | */ |
| 5256 | @Override |
| 5257 | public boolean rebootModem(int slotIndex) { |
| 5258 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5259 | if (phone != null) { |
| 5260 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5261 | mApp, phone.getSubId(), "rebootModem"); |
| 5262 | |
| 5263 | final long identity = Binder.clearCallingIdentity(); |
| 5264 | try { |
| 5265 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5266 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5267 | return success; |
| 5268 | } finally { |
| 5269 | Binder.restoreCallingIdentity(identity); |
| 5270 | } |
| 5271 | } |
| 5272 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5273 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5274 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5275 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5276 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5277 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5278 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5279 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5280 | return new String[0]; |
| 5281 | } |
| 5282 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5283 | final long identity = Binder.clearCallingIdentity(); |
| 5284 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5285 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5286 | } finally { |
| 5287 | Binder.restoreCallingIdentity(identity); |
| 5288 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5289 | } |
| 5290 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5291 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5292 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5293 | * {@link #disableIms(int)}. |
| 5294 | * @param slotIndex device slot. |
| 5295 | */ |
| 5296 | public void resetIms(int slotIndex) { |
| 5297 | enforceModifyPermission(); |
| 5298 | |
| 5299 | final long identity = Binder.clearCallingIdentity(); |
| 5300 | try { |
| 5301 | if (mImsResolver == null) { |
| 5302 | // may happen if the does not support IMS. |
| 5303 | return; |
| 5304 | } |
| 5305 | mImsResolver.disableIms(slotIndex); |
| 5306 | mImsResolver.enableIms(slotIndex); |
| 5307 | } finally { |
| 5308 | Binder.restoreCallingIdentity(identity); |
| 5309 | } |
| 5310 | } |
| 5311 | |
| 5312 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5313 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5314 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5315 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5316 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5317 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5318 | |
| 5319 | final long identity = Binder.clearCallingIdentity(); |
| 5320 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5321 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5322 | // may happen if the device does not support IMS. |
| 5323 | return; |
| 5324 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5325 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5326 | } finally { |
| 5327 | Binder.restoreCallingIdentity(identity); |
| 5328 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5329 | } |
| 5330 | |
| 5331 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5332 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5333 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5334 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5335 | public void disableIms(int slotId) { |
| 5336 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5337 | |
| 5338 | final long identity = Binder.clearCallingIdentity(); |
| 5339 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5340 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5341 | // may happen if the device does not support IMS. |
| 5342 | return; |
| 5343 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5344 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5345 | } finally { |
| 5346 | Binder.restoreCallingIdentity(identity); |
| 5347 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5348 | } |
| 5349 | |
| 5350 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5351 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5352 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5353 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5354 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5355 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5356 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5357 | |
| 5358 | final long identity = Binder.clearCallingIdentity(); |
| 5359 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5360 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5361 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5362 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5363 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5364 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5365 | } finally { |
| 5366 | Binder.restoreCallingIdentity(identity); |
| 5367 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5368 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5369 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5370 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5371 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5372 | @Override |
| 5373 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5374 | enforceModifyPermission(); |
| 5375 | |
| 5376 | final long identity = Binder.clearCallingIdentity(); |
| 5377 | try { |
| 5378 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5379 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5380 | } finally { |
| 5381 | Binder.restoreCallingIdentity(identity); |
| 5382 | } |
| 5383 | } |
| 5384 | |
| 5385 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5386 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5387 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5388 | */ |
| 5389 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5390 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5391 | |
| 5392 | final long identity = Binder.clearCallingIdentity(); |
| 5393 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5394 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5395 | // may happen if the device does not support IMS. |
| 5396 | return null; |
| 5397 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5398 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5399 | } finally { |
| 5400 | Binder.restoreCallingIdentity(identity); |
| 5401 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5402 | } |
| 5403 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5404 | /** |
| 5405 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5406 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5407 | */ |
| 5408 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5409 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5410 | |
| 5411 | final long identity = Binder.clearCallingIdentity(); |
| 5412 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5413 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5414 | // may happen if the device does not support IMS. |
| 5415 | return null; |
| 5416 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5417 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5418 | } finally { |
| 5419 | Binder.restoreCallingIdentity(identity); |
| 5420 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5421 | } |
| 5422 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5423 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5424 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5425 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5426 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5427 | * @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] | 5428 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5429 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5430 | * @param packageName The name of the package that the current configuration will be replaced |
| 5431 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5432 | * @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] | 5433 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5434 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5435 | int[] featureTypes, String packageName) { |
| 5436 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5437 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5438 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5439 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5440 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5441 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5442 | final long identity = Binder.clearCallingIdentity(); |
| 5443 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5444 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5445 | // may happen if the device does not support IMS. |
| 5446 | return false; |
| 5447 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5448 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5449 | for (int featureType : featureTypes) { |
| 5450 | featureConfig.put(featureType, packageName); |
| 5451 | } |
| 5452 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5453 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5454 | } finally { |
| 5455 | Binder.restoreCallingIdentity(identity); |
| 5456 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5457 | } |
| 5458 | |
| 5459 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5460 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5461 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5462 | * |
| 5463 | * This should only be used for testing. |
| 5464 | * |
| 5465 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5466 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5467 | */ |
| 5468 | @Override |
| 5469 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5470 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5471 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5472 | "clearCarrierImsServiceOverride"); |
| 5473 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5474 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5475 | "clearCarrierImsServiceOverride"); |
| 5476 | |
| 5477 | final long identity = Binder.clearCallingIdentity(); |
| 5478 | try { |
| 5479 | if (mImsResolver == null) { |
| 5480 | // may happen if the device does not support IMS. |
| 5481 | return false; |
| 5482 | } |
| 5483 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5484 | } finally { |
| 5485 | Binder.restoreCallingIdentity(identity); |
| 5486 | } |
| 5487 | } |
| 5488 | |
| 5489 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5490 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5491 | * |
| 5492 | * @param slotId The slot that the ImsService is associated with. |
| 5493 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5494 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5495 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5496 | * @return the package name of the ImsService configuration. |
| 5497 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5498 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5499 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5500 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5501 | TelephonyPermissions |
| 5502 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5503 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5504 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5505 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5506 | final long identity = Binder.clearCallingIdentity(); |
| 5507 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5508 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5509 | // may happen if the device does not support IMS. |
| 5510 | return ""; |
| 5511 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5512 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5513 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5514 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5515 | } finally { |
| 5516 | Binder.restoreCallingIdentity(identity); |
| 5517 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5518 | } |
| 5519 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5520 | /** |
| 5521 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5522 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5523 | * @param callback A callback with an integer containing the |
| 5524 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5525 | */ |
| 5526 | @Override |
| 5527 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5528 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5529 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5530 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5531 | "IMS not available on device."); |
| 5532 | } |
| 5533 | final long token = Binder.clearCallingIdentity(); |
| 5534 | try { |
| 5535 | int slotId = getSlotIndex(subId); |
| 5536 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5537 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5538 | + subId + "'"); |
| 5539 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5540 | } |
| 5541 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5542 | try { |
| 5543 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5544 | } catch (RemoteException e) { |
| 5545 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5546 | + "Ignore"); |
| 5547 | } |
| 5548 | }); |
| 5549 | } finally { |
| 5550 | Binder.restoreCallingIdentity(token); |
| 5551 | } |
| 5552 | } |
| 5553 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5554 | public void setImsRegistrationState(boolean registered) { |
| 5555 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5556 | |
| 5557 | final long identity = Binder.clearCallingIdentity(); |
| 5558 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5559 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5560 | } finally { |
| 5561 | Binder.restoreCallingIdentity(identity); |
| 5562 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5563 | } |
| 5564 | |
| 5565 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5566 | * Set the network selection mode to automatic. |
| 5567 | * |
| 5568 | */ |
| 5569 | @Override |
| 5570 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5571 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5572 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5573 | |
| 5574 | final long identity = Binder.clearCallingIdentity(); |
| 5575 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5576 | if (!isActiveSubscription(subId)) { |
| 5577 | return; |
| 5578 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5579 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5580 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5581 | } finally { |
| 5582 | Binder.restoreCallingIdentity(identity); |
| 5583 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5584 | } |
| 5585 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5586 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5587 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5588 | * |
| 5589 | * @param subId the id of the subscription. |
| 5590 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5591 | * the operator to attach to. |
| 5592 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5593 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5594 | * normal network selection next time. |
| 5595 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5596 | */ |
| 5597 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5598 | public boolean setNetworkSelectionModeManual( |
| 5599 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5600 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5601 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5602 | |
| 5603 | if (!isActiveSubscription(subId)) { |
| 5604 | return false; |
| 5605 | } |
| 5606 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5607 | final long identity = Binder.clearCallingIdentity(); |
| 5608 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5609 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5610 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5611 | if (DBG) { |
| 5612 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5613 | + " operator: " + operatorInfo); |
| 5614 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5615 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5616 | } finally { |
| 5617 | Binder.restoreCallingIdentity(identity); |
| 5618 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5619 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5620 | /** |
| 5621 | * Get the manual network selection |
| 5622 | * |
| 5623 | * @param subId the id of the subscription. |
| 5624 | * |
| 5625 | * @return the previously saved user selected PLMN |
| 5626 | */ |
| 5627 | @Override |
| 5628 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5629 | TelephonyPermissions |
| 5630 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5631 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5632 | |
| 5633 | final long identity = Binder.clearCallingIdentity(); |
| 5634 | try { |
| 5635 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5636 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5637 | } |
| 5638 | |
| 5639 | final Phone phone = getPhone(subId); |
| 5640 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5641 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5642 | } |
| 5643 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5644 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5645 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5646 | } finally { |
| 5647 | Binder.restoreCallingIdentity(identity); |
| 5648 | } |
| 5649 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5650 | |
| 5651 | /** |
| 5652 | * Scans for available networks. |
| 5653 | */ |
| 5654 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5655 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5656 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5657 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5658 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5659 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5660 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5661 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5662 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5663 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5664 | .setCallingPid(Binder.getCallingPid()) |
| 5665 | .setCallingUid(Binder.getCallingUid()) |
| 5666 | .setMethod("getCellNetworkScanResults") |
| 5667 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 5668 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5669 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5670 | .build()); |
| 5671 | switch (locationResult) { |
| 5672 | case DENIED_HARD: |
| 5673 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5674 | case DENIED_SOFT: |
| 5675 | return null; |
| 5676 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5677 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5678 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5679 | try { |
| 5680 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5681 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5682 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5683 | } finally { |
| 5684 | Binder.restoreCallingIdentity(identity); |
| 5685 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5686 | } |
| 5687 | |
| 5688 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5689 | * Get the call forwarding info, given the call forwarding reason. |
| 5690 | */ |
| 5691 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5692 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5693 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5694 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5695 | long identity = Binder.clearCallingIdentity(); |
| 5696 | try { |
| 5697 | if (DBG) { |
| 5698 | log("getCallForwarding: subId " + subId |
| 5699 | + " callForwardingReason" + callForwardingReason); |
| 5700 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5701 | |
| 5702 | Phone phone = getPhone(subId); |
| 5703 | if (phone == null) { |
| 5704 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5705 | callback.onError( |
| 5706 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5707 | } catch (RemoteException e) { |
| 5708 | // ignore |
| 5709 | } |
| 5710 | return; |
| 5711 | } |
| 5712 | |
| 5713 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 5714 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 5715 | @Override |
| 5716 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 5717 | try { |
| 5718 | callback.onCallForwardingInfoAvailable(info); |
| 5719 | } catch (RemoteException e) { |
| 5720 | // ignore |
| 5721 | } |
| 5722 | } |
| 5723 | |
| 5724 | @Override |
| 5725 | public void onError(int error) { |
| 5726 | try { |
| 5727 | callback.onError(error); |
| 5728 | } catch (RemoteException e) { |
| 5729 | // ignore |
| 5730 | } |
| 5731 | } |
| 5732 | }); |
| 5733 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5734 | } finally { |
| 5735 | Binder.restoreCallingIdentity(identity); |
| 5736 | } |
| 5737 | } |
| 5738 | |
| 5739 | /** |
| 5740 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5741 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5742 | */ |
| 5743 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5744 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 5745 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5746 | enforceModifyPermission(); |
| 5747 | long identity = Binder.clearCallingIdentity(); |
| 5748 | try { |
| 5749 | if (DBG) { |
| 5750 | log("setCallForwarding: subId " + subId |
| 5751 | + " callForwardingInfo" + callForwardingInfo); |
| 5752 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5753 | |
| 5754 | Phone phone = getPhone(subId); |
| 5755 | if (phone == null) { |
| 5756 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5757 | callback.accept( |
| 5758 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5759 | } catch (RemoteException e) { |
| 5760 | // ignore |
| 5761 | } |
| 5762 | return; |
| 5763 | } |
| 5764 | |
| 5765 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 5766 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5767 | |
| 5768 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5769 | } finally { |
| 5770 | Binder.restoreCallingIdentity(identity); |
| 5771 | } |
| 5772 | } |
| 5773 | |
| 5774 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5775 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5776 | */ |
| 5777 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5778 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5779 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5780 | long identity = Binder.clearCallingIdentity(); |
| 5781 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5782 | |
| 5783 | Phone phone = getPhone(subId); |
| 5784 | if (phone == null) { |
| 5785 | try { |
| 5786 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5787 | } catch (RemoteException e) { |
| 5788 | // ignore |
| 5789 | } |
| 5790 | return; |
| 5791 | } |
| 5792 | |
| 5793 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 5794 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5795 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5796 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5797 | } finally { |
| 5798 | Binder.restoreCallingIdentity(identity); |
| 5799 | } |
| 5800 | } |
| 5801 | |
| 5802 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5803 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5804 | */ |
| 5805 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5806 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5807 | enforceModifyPermission(); |
| 5808 | long identity = Binder.clearCallingIdentity(); |
| 5809 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5810 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 5811 | |
| 5812 | Phone phone = getPhone(subId); |
| 5813 | if (phone == null) { |
| 5814 | try { |
| 5815 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5816 | } catch (RemoteException e) { |
| 5817 | // ignore |
| 5818 | } |
| 5819 | return; |
| 5820 | } |
| 5821 | |
| 5822 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 5823 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5824 | |
| 5825 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5826 | } finally { |
| 5827 | Binder.restoreCallingIdentity(identity); |
| 5828 | } |
| 5829 | } |
| 5830 | |
| 5831 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5832 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5833 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5834 | * @param subId id of the subscription |
| 5835 | * @param request contains the radio access networks with bands/channels to scan |
| 5836 | * @param messenger callback messenger for scan results or errors |
| 5837 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5838 | * @return the id of the requested scan which can be used to stop the scan. |
| 5839 | */ |
| 5840 | @Override |
| 5841 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5842 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5843 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5844 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5845 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5846 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5847 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5848 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5849 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5850 | .setCallingPid(Binder.getCallingPid()) |
| 5851 | .setCallingUid(Binder.getCallingUid()) |
| 5852 | .setMethod("requestNetworkScan") |
| 5853 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
James.cf Lin | 1d4d739 | 2020-07-03 18:22:53 +0800 | [diff] [blame] | 5854 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5855 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5856 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5857 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5858 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 5859 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5860 | if (e != null) { |
| 5861 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5862 | throw e; |
| 5863 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5864 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5865 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5866 | } |
| 5867 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5868 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5869 | int callingUid = Binder.getCallingUid(); |
| 5870 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5871 | final long identity = Binder.clearCallingIdentity(); |
| 5872 | try { |
| 5873 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5874 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5875 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5876 | } finally { |
| 5877 | Binder.restoreCallingIdentity(identity); |
| 5878 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5879 | } |
| 5880 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5881 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5882 | NetworkScanRequest request, int subId, String callingPackage) { |
| 5883 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5884 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5885 | boolean hasNetworkScanPermission = |
| 5886 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5887 | == PERMISSION_GRANTED; |
| 5888 | |
| 5889 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5890 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5891 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5892 | } |
| 5893 | |
| 5894 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5895 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5896 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5897 | return new SecurityException("Specific channels must not be" |
| 5898 | + " scanned without location access."); |
| 5899 | } |
| 5900 | } |
| 5901 | } |
| 5902 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5903 | return null; |
| 5904 | } |
| 5905 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5906 | /** |
| 5907 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5908 | * |
| 5909 | * @param subId id of the subscription |
| 5910 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5911 | */ |
| 5912 | @Override |
| 5913 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5914 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5915 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5916 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5917 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5918 | final long identity = Binder.clearCallingIdentity(); |
| 5919 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5920 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5921 | } finally { |
| 5922 | Binder.restoreCallingIdentity(identity); |
| 5923 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5924 | } |
| 5925 | |
| 5926 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5927 | * Get the calculated preferred network type. |
| 5928 | * Used for debugging incorrect network type. |
| 5929 | * |
| 5930 | * @return the preferred network type, defined in RILConstants.java. |
| 5931 | */ |
| 5932 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5933 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5934 | final Phone defaultPhone = getDefaultPhone(); |
| 5935 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5936 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5937 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5938 | } |
| 5939 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5940 | final long identity = Binder.clearCallingIdentity(); |
| 5941 | try { |
| 5942 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5943 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5944 | } finally { |
| 5945 | Binder.restoreCallingIdentity(identity); |
| 5946 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5947 | } |
| 5948 | |
| 5949 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5950 | * Get the preferred network type. |
| 5951 | * Used for device configuration by some CDMA operators. |
| 5952 | * |
| 5953 | * @return the preferred network type, defined in RILConstants.java. |
| 5954 | */ |
| 5955 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5956 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5957 | TelephonyPermissions |
| 5958 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5959 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5960 | |
| 5961 | final long identity = Binder.clearCallingIdentity(); |
| 5962 | try { |
| 5963 | if (DBG) log("getPreferredNetworkType"); |
| 5964 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5965 | int networkType = (result != null ? result[0] : -1); |
| 5966 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5967 | return networkType; |
| 5968 | } finally { |
| 5969 | Binder.restoreCallingIdentity(identity); |
| 5970 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5971 | } |
| 5972 | |
| 5973 | /** |
| 5974 | * Set the preferred network type. |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5975 | * |
| 5976 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5977 | * @return true on success; false on any failure. |
| 5978 | */ |
| 5979 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5980 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5981 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5982 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5983 | |
| 5984 | final long identity = Binder.clearCallingIdentity(); |
| 5985 | try { |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5986 | Boolean success = (Boolean) sendRequest( |
| 5987 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
calvinpan | 03641a7 | 2020-08-18 16:53:59 +0800 | [diff] [blame] | 5988 | |
| 5989 | if (success) { |
| 5990 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5991 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 5992 | } |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5993 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 5994 | return success; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5995 | } finally { |
| 5996 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5997 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5998 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5999 | |
| 6000 | /** |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 6001 | * Get the allowed network types that store in the telephony provider. |
| 6002 | * |
| 6003 | * @param subId the id of the subscription. |
| 6004 | * @return allowedNetworkTypes the allowed network types. |
| 6005 | */ |
| 6006 | @Override |
| 6007 | public long getAllowedNetworkTypes(int subId) { |
| 6008 | TelephonyPermissions |
| 6009 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6010 | mApp, subId, "getAllowedNetworkTypes"); |
| 6011 | |
| 6012 | final long identity = Binder.clearCallingIdentity(); |
| 6013 | try { |
| 6014 | return SubscriptionManager.getLongSubscriptionProperty( |
| 6015 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 6016 | } finally { |
| 6017 | Binder.restoreCallingIdentity(identity); |
| 6018 | } |
| 6019 | } |
| 6020 | |
| 6021 | /** |
| 6022 | * Set the allowed network types. |
| 6023 | * |
| 6024 | * @param subId the id of the subscription. |
| 6025 | * @param allowedNetworkTypes the allowed network types. |
| 6026 | * @return true on success; false on any failure. |
| 6027 | */ |
| 6028 | @Override |
| 6029 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 6030 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6031 | mApp, subId, "setAllowedNetworkTypes"); |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 6032 | |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 6033 | SubscriptionManager.setSubscriptionProperty(subId, |
| 6034 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 6035 | String.valueOf(allowedNetworkTypes)); |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 6036 | |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 6037 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 6038 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 6039 | RILConstants.PREFERRED_NETWORK_MODE); |
| 6040 | return setPreferredNetworkType(subId, preferredNetworkMode); |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 6041 | } |
| 6042 | |
| 6043 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6044 | * Get the allowed network types for certain reason. |
| 6045 | * |
| 6046 | * @param subId the id of the subscription. |
| 6047 | * @param reason the reason the allowed network type change is taking place |
| 6048 | * @return the allowed network types. |
| 6049 | */ |
| 6050 | @Override |
| 6051 | public long getAllowedNetworkTypesForReason(int subId, |
| 6052 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
| 6053 | TelephonyPermissions |
| 6054 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6055 | mApp, subId, "getAllowedNetworkTypesForReason"); |
| 6056 | final long identity = Binder.clearCallingIdentity(); |
| 6057 | try { |
| 6058 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6059 | } finally { |
| 6060 | Binder.restoreCallingIdentity(identity); |
| 6061 | } |
| 6062 | } |
| 6063 | |
| 6064 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6065 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6066 | * @param subId subscription id of the sim card |
| 6067 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6068 | * This can be passed following states |
| 6069 | * <ol> |
| 6070 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6071 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6072 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6073 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6074 | * </ol> |
| 6075 | * @return operation result. |
| 6076 | */ |
| 6077 | @Override |
| 6078 | public int setNrDualConnectivityState(int subId, |
| 6079 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6080 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6081 | mApp, subId, "enableNRDualConnectivity"); |
| 6082 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6083 | final long identity = Binder.clearCallingIdentity(); |
| 6084 | try { |
| 6085 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6086 | nrDualConnectivityState, subId, |
| 6087 | workSource); |
| 6088 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6089 | return result; |
| 6090 | } finally { |
| 6091 | Binder.restoreCallingIdentity(identity); |
| 6092 | } |
| 6093 | } |
| 6094 | |
| 6095 | /** |
| 6096 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6097 | * @return true if dual connectivity is enabled else false |
| 6098 | */ |
| 6099 | @Override |
| 6100 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6101 | TelephonyPermissions |
| 6102 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6103 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6104 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6105 | final long identity = Binder.clearCallingIdentity(); |
| 6106 | try { |
| 6107 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6108 | null, subId, workSource); |
| 6109 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6110 | return isEnabled; |
| 6111 | } finally { |
| 6112 | Binder.restoreCallingIdentity(identity); |
| 6113 | } |
| 6114 | } |
| 6115 | |
| 6116 | /** |
Sooraj Sasindran | 4deb887 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 6117 | * get carrier bandwidth per primary and secondary carrier |
| 6118 | * @param subId subscription id of the sim card |
| 6119 | * @return CarrierBandwidth with bandwidth of both primary and secondary carrier.. |
| 6120 | */ |
| 6121 | @Override |
| 6122 | public CarrierBandwidth getCarrierBandwidth(int subId) { |
| 6123 | TelephonyPermissions |
| 6124 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6125 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6126 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6127 | final long identity = Binder.clearCallingIdentity(); |
| 6128 | try { |
| 6129 | CarrierBandwidth carrierBandwidth = |
| 6130 | getPhoneFromSubId(subId).getCarrierBandwidth(); |
| 6131 | if (DBG) log("getCarrierBandwidth: " + carrierBandwidth); |
| 6132 | return carrierBandwidth; |
| 6133 | } finally { |
| 6134 | Binder.restoreCallingIdentity(identity); |
| 6135 | } |
| 6136 | } |
| 6137 | |
| 6138 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6139 | * Get the effective allowed network types on the device. |
| 6140 | * This API will return an intersection of allowed network types for all reasons, |
| 6141 | * including the configuration done through setAllowedNetworkTypes |
| 6142 | * |
| 6143 | * @param subId the id of the subscription. |
| 6144 | * @return the allowed network types |
| 6145 | */ |
| 6146 | @Override |
| 6147 | public long getEffectiveAllowedNetworkTypes(int subId) { |
| 6148 | TelephonyPermissions |
| 6149 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6150 | mApp, subId, "getEffectiveAllowedNetworkTypes"); |
| 6151 | final long identity = Binder.clearCallingIdentity(); |
| 6152 | try { |
| 6153 | return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes(); |
| 6154 | } finally { |
| 6155 | Binder.restoreCallingIdentity(identity); |
| 6156 | } |
| 6157 | } |
| 6158 | |
| 6159 | /** |
| 6160 | * Set the allowed network types of the device and |
| 6161 | * provide the reason triggering the allowed network change. |
| 6162 | * |
| 6163 | * @param subId the id of the subscription. |
| 6164 | * @param reason the reason the allowed network type change is taking place |
| 6165 | * @param allowedNetworkTypes the allowed network types. |
| 6166 | * @return true on success; false on any failure. |
| 6167 | */ |
| 6168 | @Override |
| 6169 | public boolean setAllowedNetworkTypesForReason(int subId, |
| 6170 | @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) { |
| 6171 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6172 | mApp, subId, "setAllowedNetworkTypesForReason"); |
| 6173 | final long identity = Binder.clearCallingIdentity(); |
| 6174 | try { |
| 6175 | getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes); |
| 6176 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 6177 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 6178 | RILConstants.PREFERRED_NETWORK_MODE); |
| 6179 | return setPreferredNetworkType(subId, preferredNetworkMode); |
| 6180 | } finally { |
| 6181 | Binder.restoreCallingIdentity(identity); |
| 6182 | } |
| 6183 | } |
| 6184 | |
| 6185 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6186 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6187 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6188 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6189 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6190 | * @hide |
| 6191 | */ |
| 6192 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6193 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6194 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6195 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6196 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6197 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6198 | if (phone != null) { |
| 6199 | return phone.hasMatchedTetherApnSetting(); |
| 6200 | } else { |
| 6201 | return false; |
| 6202 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6203 | } finally { |
| 6204 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6205 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6206 | } |
| 6207 | |
| 6208 | /** |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6209 | * Enable or disable always reporting signal strength changes from radio. |
| 6210 | * |
| 6211 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6212 | */ |
| 6213 | @Override |
| 6214 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6215 | enforceModifyPermission(); |
| 6216 | enforceSystemCaller(); |
| 6217 | |
| 6218 | final long identity = Binder.clearCallingIdentity(); |
| 6219 | final Phone phone = getPhone(subId); |
| 6220 | try { |
| 6221 | if (phone != null) { |
| 6222 | if (DBG) { |
| 6223 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6224 | + " isEnable=" + isEnable); |
| 6225 | } |
| 6226 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6227 | } else { |
| 6228 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6229 | + subId); |
| 6230 | } |
| 6231 | } finally { |
| 6232 | Binder.restoreCallingIdentity(identity); |
| 6233 | } |
| 6234 | } |
| 6235 | |
| 6236 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6237 | * Get the user enabled state of Mobile Data. |
| 6238 | * |
| 6239 | * TODO: remove and use isUserDataEnabled. |
| 6240 | * This can't be removed now because some vendor codes |
| 6241 | * calls through ITelephony directly while they should |
| 6242 | * use TelephonyManager. |
| 6243 | * |
| 6244 | * @return true on enabled |
| 6245 | */ |
| 6246 | @Override |
| 6247 | public boolean getDataEnabled(int subId) { |
| 6248 | return isUserDataEnabled(subId); |
| 6249 | } |
| 6250 | |
| 6251 | /** |
| 6252 | * Get whether mobile data is enabled per user setting. |
| 6253 | * |
| 6254 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6255 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6256 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6257 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6258 | * |
| 6259 | * @return {@code true} if data is enabled else {@code false} |
| 6260 | */ |
| 6261 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6262 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6263 | try { |
| 6264 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6265 | null); |
| 6266 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6267 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6268 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6269 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6270 | |
| 6271 | final long identity = Binder.clearCallingIdentity(); |
| 6272 | try { |
| 6273 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6274 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6275 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6276 | if (phone != null) { |
| 6277 | boolean retVal = phone.isUserDataEnabled(); |
| 6278 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6279 | return retVal; |
| 6280 | } else { |
| 6281 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6282 | return false; |
| 6283 | } |
| 6284 | } finally { |
| 6285 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6286 | } |
| 6287 | } |
| 6288 | |
| 6289 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6290 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6291 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6292 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6293 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6294 | * @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] | 6295 | */ |
| 6296 | @Override |
| 6297 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6298 | try { |
| 6299 | try { |
| 6300 | mApp.enforceCallingOrSelfPermission( |
| 6301 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6302 | null); |
| 6303 | } catch (Exception e) { |
| 6304 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6305 | "isDataEnabled"); |
| 6306 | } |
| 6307 | } catch (Exception e) { |
| 6308 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6309 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6310 | |
| 6311 | final long identity = Binder.clearCallingIdentity(); |
| 6312 | try { |
| 6313 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6314 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6315 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6316 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6317 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6318 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6319 | return retVal; |
| 6320 | } else { |
| 6321 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6322 | return false; |
| 6323 | } |
| 6324 | } finally { |
| 6325 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6326 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6327 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6328 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6329 | /** |
| 6330 | * Check if data is enabled for a specific reason |
| 6331 | * @param subId Subscription index |
| 6332 | * @param reason the reason the data enable change is taking place |
| 6333 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6334 | */ |
| 6335 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6336 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6337 | @TelephonyManager.DataEnabledReason int reason) { |
| 6338 | try { |
| 6339 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6340 | null); |
| 6341 | } catch (Exception e) { |
| 6342 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6343 | "isDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6344 | } |
| 6345 | |
| 6346 | |
| 6347 | final long identity = Binder.clearCallingIdentity(); |
| 6348 | try { |
| 6349 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6350 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6351 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6352 | + " reason=" + reason); |
| 6353 | } |
| 6354 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6355 | if (phone != null) { |
| 6356 | boolean retVal; |
| 6357 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6358 | retVal = phone.isUserDataEnabled(); |
| 6359 | } else { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6360 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6361 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6362 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6363 | return retVal; |
| 6364 | } else { |
| 6365 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6366 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6367 | + subId + " retVal=false"); |
| 6368 | } |
| 6369 | return false; |
| 6370 | } |
| 6371 | } finally { |
| 6372 | Binder.restoreCallingIdentity(identity); |
| 6373 | } |
| 6374 | } |
| 6375 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6376 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6377 | Phone phone) { |
Hall Liu | 54a2a0c | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6378 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 6379 | // Skip the check if it's one of these special uids |
| 6380 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6381 | } |
| 6382 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6383 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6384 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6385 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6386 | || subController == null) return privilegeFromSim; |
| 6387 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6388 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6389 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6390 | |
| 6391 | final long identity = Binder.clearCallingIdentity(); |
| 6392 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6393 | int subId = phone.getSubId(); |
| 6394 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6395 | // A test override is in place for the privileges for this subId, so don't try to |
| 6396 | // read the subscription privileges. |
| 6397 | return privilegeFromSim; |
| 6398 | } |
| 6399 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6400 | SubscriptionManager subManager = (SubscriptionManager) |
| 6401 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6402 | for (String pkg : packages) { |
| 6403 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6404 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6405 | } |
| 6406 | } |
| 6407 | return privilegeFromSim; |
| 6408 | } finally { |
| 6409 | Binder.restoreCallingIdentity(identity); |
| 6410 | } |
| 6411 | } |
| 6412 | |
| 6413 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6414 | String pkgName) { |
| 6415 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6416 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6417 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6418 | || subController == null) return privilegeFromSim; |
| 6419 | |
| 6420 | final long identity = Binder.clearCallingIdentity(); |
| 6421 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6422 | int subId = phone.getSubId(); |
| 6423 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6424 | // A test override is in place for the privileges for this subId, so don't try to |
| 6425 | // read the subscription privileges. |
| 6426 | return privilegeFromSim; |
| 6427 | } |
| 6428 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6429 | SubscriptionManager subManager = (SubscriptionManager) |
| 6430 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6431 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6432 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6433 | } finally { |
| 6434 | Binder.restoreCallingIdentity(identity); |
| 6435 | } |
| 6436 | } |
| 6437 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6438 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6439 | public int getCarrierPrivilegeStatus(int subId) { |
| 6440 | final Phone phone = getPhone(subId); |
| 6441 | if (phone == null) { |
| 6442 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6443 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6444 | } |
| 6445 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6446 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6447 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [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 | |
| 6451 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6452 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6453 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6454 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6455 | |
| 6456 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6457 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6458 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6459 | final Phone phone = getPhone(subId); |
| 6460 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6461 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6462 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6463 | } |
| 6464 | UiccProfile profile = |
| 6465 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6466 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6467 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6468 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6469 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6470 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6471 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6472 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6473 | } |
| 6474 | |
| 6475 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6476 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6477 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6478 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6479 | } |
| 6480 | |
| 6481 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6482 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6483 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6484 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6485 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6486 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6487 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6488 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6489 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6490 | } |
| 6491 | |
| 6492 | @Override |
| 6493 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6494 | if (TextUtils.isEmpty(pkgName)) |
| 6495 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6496 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6497 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6498 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6499 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6500 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6501 | continue; |
| 6502 | } |
| 6503 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6504 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6505 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6506 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6507 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6508 | break; |
| 6509 | } |
| 6510 | } |
| 6511 | |
| 6512 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6513 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6514 | |
| 6515 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6516 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6517 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6518 | loge("phoneId " + phoneId + " is not valid."); |
| 6519 | return null; |
| 6520 | } |
| 6521 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6522 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6523 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6524 | return null ; |
| 6525 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6526 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6527 | } |
| 6528 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6529 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6530 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6531 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6532 | List<String> privilegedPackages = new ArrayList<>(); |
| 6533 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6534 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6535 | // has UICC in that slot. |
| 6536 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6537 | if (card.hasCarrierPrivilegeRules()) { |
| 6538 | if (packages == null) { |
| 6539 | // Only check packages in user 0 for now |
| 6540 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6541 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6542 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6543 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6544 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6545 | } |
| 6546 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6547 | PackageInfo pkgInfo = packages.get(p); |
| 6548 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6549 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6550 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6551 | privilegedPackages.add(pkgInfo.packageName); |
| 6552 | } |
| 6553 | } |
| 6554 | } |
| 6555 | } |
| 6556 | return privilegedPackages; |
| 6557 | } |
| 6558 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6559 | @Override |
| 6560 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6561 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6562 | |
| 6563 | final long identity = Binder.clearCallingIdentity(); |
| 6564 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6565 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6566 | try { |
| 6567 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6568 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6569 | } |
| 6570 | } finally { |
| 6571 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6572 | } |
| 6573 | return privilegedPackages; |
| 6574 | } |
| 6575 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6576 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6577 | final Phone phone = getPhone(subId); |
| 6578 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6579 | if (card == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6580 | return null; |
| 6581 | } |
| 6582 | String iccId = card.getIccId(); |
| 6583 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6584 | return null; |
| 6585 | } |
| 6586 | return iccId; |
| 6587 | } |
| 6588 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6589 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6590 | public void setCallComposerStatus(int subId, int status) { |
| 6591 | enforceModifyPermission(); |
| 6592 | |
| 6593 | final long identity = Binder.clearCallingIdentity(); |
| 6594 | try { |
| 6595 | Phone phone = getPhone(subId); |
| 6596 | if (phone != null) { |
| 6597 | Phone defaultPhone = phone.getImsPhone(); |
| 6598 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6599 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6600 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6601 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6602 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6603 | } |
| 6604 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6605 | } catch (ImsException e) { |
| 6606 | throw new ServiceSpecificException(e.getCode()); |
| 6607 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6608 | Binder.restoreCallingIdentity(identity); |
| 6609 | } |
| 6610 | } |
| 6611 | |
| 6612 | @Override |
| 6613 | public int getCallComposerStatus(int subId) { |
| 6614 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6615 | |
| 6616 | final long identity = Binder.clearCallingIdentity(); |
| 6617 | try { |
| 6618 | Phone phone = getPhone(subId); |
| 6619 | if (phone != null) { |
| 6620 | Phone defaultPhone = phone.getImsPhone(); |
| 6621 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6622 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6623 | return imsPhone.getCallComposerStatus(); |
| 6624 | } |
| 6625 | } |
| 6626 | } finally { |
| 6627 | Binder.restoreCallingIdentity(identity); |
| 6628 | } |
| 6629 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6630 | } |
| 6631 | |
| 6632 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6633 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6634 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6635 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6636 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6637 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6638 | final long identity = Binder.clearCallingIdentity(); |
| 6639 | try { |
| 6640 | final String iccId = getIccId(subId); |
| 6641 | final Phone phone = getPhone(subId); |
| 6642 | if (phone == null) { |
| 6643 | return false; |
| 6644 | } |
| 6645 | final String subscriberId = phone.getSubscriberId(); |
| 6646 | |
| 6647 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6648 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6649 | + subscriberId + " to " + number); |
| 6650 | } |
| 6651 | |
| 6652 | if (TextUtils.isEmpty(iccId)) { |
| 6653 | return false; |
| 6654 | } |
| 6655 | |
| 6656 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6657 | |
| 6658 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6659 | if (alphaTag == null) { |
| 6660 | editor.remove(alphaTagPrefKey); |
| 6661 | } else { |
| 6662 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6663 | } |
| 6664 | |
| 6665 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6666 | // track all merged IMSIs based on line number |
| 6667 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6668 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6669 | if (number == null) { |
| 6670 | editor.remove(numberPrefKey); |
| 6671 | editor.remove(subscriberPrefKey); |
| 6672 | } else { |
| 6673 | editor.putString(numberPrefKey, number); |
| 6674 | editor.putString(subscriberPrefKey, subscriberId); |
| 6675 | } |
| 6676 | |
| 6677 | editor.commit(); |
| 6678 | return true; |
| 6679 | } finally { |
| 6680 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6681 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6682 | } |
| 6683 | |
| 6684 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6685 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6686 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6687 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6688 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6689 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6690 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6691 | return null; |
| 6692 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6693 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6694 | final long identity = Binder.clearCallingIdentity(); |
| 6695 | try { |
| 6696 | String iccId = getIccId(subId); |
| 6697 | if (iccId != null) { |
| 6698 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6699 | if (DBG_MERGE) { |
| 6700 | log("getLine1NumberForDisplay returning " |
| 6701 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6702 | } |
| 6703 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6704 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6705 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6706 | return null; |
| 6707 | } finally { |
| 6708 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6709 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6710 | } |
| 6711 | |
| 6712 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6713 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6714 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6715 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6716 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6717 | return null; |
| 6718 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6719 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6720 | final long identity = Binder.clearCallingIdentity(); |
| 6721 | try { |
| 6722 | String iccId = getIccId(subId); |
| 6723 | if (iccId != null) { |
| 6724 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6725 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6726 | } |
| 6727 | return null; |
| 6728 | } finally { |
| 6729 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6730 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6731 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6732 | |
| 6733 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6734 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6735 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6736 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6737 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6738 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6739 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6740 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6741 | return null; |
| 6742 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6743 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6744 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6745 | // the process, where TelephonyManager was instantiated. |
| 6746 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6747 | final long identity = Binder.clearCallingIdentity(); |
| 6748 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6749 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6750 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6751 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6752 | |
| 6753 | // Figure out what subscribers are currently active |
| 6754 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6755 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6756 | // Only consider subs which match the current subId |
| 6757 | // This logic can be simplified. See b/131189269 for progress. |
| 6758 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6759 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6760 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6761 | |
| 6762 | // First pass, find a number override for an active subscriber |
| 6763 | String mergeNumber = null; |
| 6764 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6765 | for (String key : prefs.keySet()) { |
| 6766 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6767 | final String subscriberId = (String) prefs.get(key); |
| 6768 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6769 | final String iccId = key.substring( |
| 6770 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6771 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6772 | mergeNumber = (String) prefs.get(numberKey); |
| 6773 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6774 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6775 | + " for active subscriber " + subscriberId); |
| 6776 | } |
| 6777 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6778 | break; |
| 6779 | } |
| 6780 | } |
| 6781 | } |
| 6782 | } |
| 6783 | |
| 6784 | // Shortcut when no active merged subscribers |
| 6785 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6786 | return null; |
| 6787 | } |
| 6788 | |
| 6789 | // Second pass, find all subscribers under that line override |
| 6790 | final ArraySet<String> result = new ArraySet<>(); |
| 6791 | for (String key : prefs.keySet()) { |
| 6792 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6793 | final String number = (String) prefs.get(key); |
| 6794 | if (mergeNumber.equals(number)) { |
| 6795 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6796 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6797 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6798 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6799 | result.add(subscriberId); |
| 6800 | } |
| 6801 | } |
| 6802 | } |
| 6803 | } |
| 6804 | |
| 6805 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6806 | Arrays.sort(resultArray); |
| 6807 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6808 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6809 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6810 | } |
| 6811 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6812 | } finally { |
| 6813 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6814 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6815 | } |
| 6816 | |
| 6817 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6818 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6819 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6820 | |
| 6821 | final long identity = Binder.clearCallingIdentity(); |
| 6822 | try { |
| 6823 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6824 | TelephonyManager.class); |
| 6825 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6826 | if (subscriberId == null) { |
| 6827 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6828 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6829 | + subId); |
| 6830 | } |
| 6831 | return null; |
| 6832 | } |
| 6833 | |
| 6834 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6835 | .getSubscriptionInfo(subId); |
| 6836 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6837 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6838 | if (groupUuid == null) { |
| 6839 | return new String[]{subscriberId}; |
| 6840 | } |
| 6841 | |
| 6842 | // Get all subscriberIds from the group. |
| 6843 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6844 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6845 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6846 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6847 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6848 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6849 | if (subscriberId != null) { |
| 6850 | mergedSubscriberIds.add(subscriberId); |
| 6851 | } |
| 6852 | } |
| 6853 | |
| 6854 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6855 | } finally { |
| 6856 | Binder.restoreCallingIdentity(identity); |
| 6857 | |
| 6858 | } |
| 6859 | } |
| 6860 | |
| 6861 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6862 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6863 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6864 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6865 | |
| 6866 | final long identity = Binder.clearCallingIdentity(); |
| 6867 | try { |
| 6868 | final Phone phone = getPhone(subId); |
| 6869 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6870 | } finally { |
| 6871 | Binder.restoreCallingIdentity(identity); |
| 6872 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6873 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6874 | |
| 6875 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6876 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6877 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6878 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6879 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6880 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6881 | |
| 6882 | final long identity = Binder.clearCallingIdentity(); |
| 6883 | try { |
| 6884 | final Phone phone = getPhone(subId); |
| 6885 | if (phone == null) { |
| 6886 | return false; |
| 6887 | } |
| 6888 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6889 | cdmaNonRoamingList); |
| 6890 | } finally { |
| 6891 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6892 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6893 | } |
| 6894 | |
| 6895 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6896 | @Deprecated |
| 6897 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6898 | enforceModifyPermission(); |
| 6899 | |
| 6900 | int returnValue = 0; |
| 6901 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6902 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6903 | if(result.exception == null) { |
| 6904 | if (result.result != null) { |
| 6905 | byte[] responseData = (byte[])(result.result); |
| 6906 | if(responseData.length > oemResp.length) { |
| 6907 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6908 | responseData.length + "bytes. Buffer Size is " + |
| 6909 | oemResp.length + "bytes."); |
| 6910 | } |
| 6911 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6912 | returnValue = responseData.length; |
| 6913 | } |
| 6914 | } else { |
| 6915 | CommandException ex = (CommandException) result.exception; |
| 6916 | returnValue = ex.getCommandError().ordinal(); |
| 6917 | if(returnValue > 0) returnValue *= -1; |
| 6918 | } |
| 6919 | } catch (RuntimeException e) { |
| 6920 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6921 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6922 | if(returnValue > 0) returnValue *= -1; |
| 6923 | } |
| 6924 | |
| 6925 | return returnValue; |
| 6926 | } |
| 6927 | |
| 6928 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6929 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6930 | try { |
| 6931 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6932 | } catch (RuntimeException e) { |
| 6933 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6934 | } |
| 6935 | } |
| 6936 | |
| 6937 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6938 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6939 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 6940 | try { |
| 6941 | TelephonyPermissions |
| 6942 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6943 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6944 | } catch (SecurityException e) { |
| 6945 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 6946 | throw e; |
| 6947 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6948 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6949 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6950 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6951 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6952 | final long identity = Binder.clearCallingIdentity(); |
| 6953 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6954 | TelephonyPermissions |
| 6955 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6956 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6957 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6958 | } finally { |
| 6959 | Binder.restoreCallingIdentity(identity); |
| 6960 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6961 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6962 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6963 | |
| 6964 | @Override |
| 6965 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6966 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6967 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6968 | |
| 6969 | final long identity = Binder.clearCallingIdentity(); |
| 6970 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6971 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6972 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6973 | } finally { |
| 6974 | Binder.restoreCallingIdentity(identity); |
| 6975 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6976 | } |
| 6977 | |
| 6978 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6979 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6980 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6981 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6982 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6983 | return false; |
| 6984 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6985 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6986 | final long identity = Binder.clearCallingIdentity(); |
| 6987 | try { |
| 6988 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6989 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6990 | // In the long run, we may instead need to check if there exists a connection service |
| 6991 | // which can support video calling. |
| 6992 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6993 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6994 | return imsManager.isVtEnabledByPlatform() |
| 6995 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6996 | && imsManager.isVtEnabledByUser(); |
| 6997 | } finally { |
| 6998 | Binder.restoreCallingIdentity(identity); |
| 6999 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7000 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7001 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7002 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7003 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7004 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7005 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7006 | mApp, subId, callingPackage, callingFeatureId, |
| 7007 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7008 | return false; |
| 7009 | } |
| 7010 | |
| 7011 | final long identity = Binder.clearCallingIdentity(); |
| 7012 | try { |
| 7013 | CarrierConfigManager configManager = |
| 7014 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7015 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7016 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7017 | } finally { |
| 7018 | Binder.restoreCallingIdentity(identity); |
| 7019 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7020 | } |
| 7021 | |
| 7022 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7023 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7024 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7025 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7026 | return false; |
| 7027 | } |
| 7028 | |
| 7029 | final long identity = Binder.clearCallingIdentity(); |
| 7030 | try { |
| 7031 | CarrierConfigManager configManager = |
| 7032 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7033 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7034 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7035 | } finally { |
| 7036 | Binder.restoreCallingIdentity(identity); |
| 7037 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7038 | } |
| 7039 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7040 | @Override |
| 7041 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7042 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7043 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7044 | } |
| 7045 | |
| 7046 | @Override |
| 7047 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7048 | final long identity = Binder.clearCallingIdentity(); |
| 7049 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7050 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7051 | } finally { |
| 7052 | Binder.restoreCallingIdentity(identity); |
| 7053 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7054 | } |
| 7055 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7056 | /** |
| 7057 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7058 | * support for the feature and device firmware support. |
| 7059 | * |
| 7060 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7061 | */ |
| 7062 | @Override |
| 7063 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7064 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7065 | final Phone phone = getPhone(subscriptionId); |
| 7066 | if (phone == null) { |
| 7067 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7068 | return false; |
| 7069 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7070 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7071 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7072 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7073 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7074 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7075 | return isCarrierSupported && isDeviceSupported; |
| 7076 | } finally { |
| 7077 | Binder.restoreCallingIdentity(identity); |
| 7078 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7079 | } |
| 7080 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7081 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7082 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7083 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7084 | * 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] | 7085 | */ |
| 7086 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7087 | final long identity = Binder.clearCallingIdentity(); |
| 7088 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7089 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7090 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7091 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7092 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7093 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7094 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7095 | } finally { |
| 7096 | Binder.restoreCallingIdentity(identity); |
| 7097 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7098 | } |
| 7099 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7100 | @Deprecated |
| 7101 | @Override |
| 7102 | public String getDeviceId(String callingPackage) { |
| 7103 | return getDeviceIdWithFeature(callingPackage, null); |
| 7104 | } |
| 7105 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7106 | /** |
| 7107 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7108 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7109 | * |
| 7110 | * <p>Requires Permission: |
| 7111 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7112 | */ |
| 7113 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7114 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7115 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7116 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7117 | return null; |
| 7118 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7119 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7120 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7121 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7122 | return null; |
| 7123 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7124 | |
| 7125 | final long identity = Binder.clearCallingIdentity(); |
| 7126 | try { |
| 7127 | return phone.getDeviceId(); |
| 7128 | } finally { |
| 7129 | Binder.restoreCallingIdentity(identity); |
| 7130 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7131 | } |
| 7132 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7133 | /** |
| 7134 | * {@hide} |
| 7135 | * Returns the IMS Registration Status on a particular subid |
| 7136 | * |
| 7137 | * @param subId |
| 7138 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7139 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7140 | Phone phone = getPhone(subId); |
| 7141 | if (phone != null) { |
| 7142 | return phone.isImsRegistered(); |
| 7143 | } else { |
| 7144 | return false; |
| 7145 | } |
| 7146 | } |
| 7147 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7148 | @Override |
| 7149 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7150 | final long identity = Binder.clearCallingIdentity(); |
| 7151 | try { |
| 7152 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 7153 | } finally { |
| 7154 | Binder.restoreCallingIdentity(identity); |
| 7155 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7156 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7157 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7158 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7159 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7160 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7161 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7162 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7163 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7164 | } |
| 7165 | final long identity = Binder.clearCallingIdentity(); |
| 7166 | try { |
| 7167 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7168 | } finally { |
| 7169 | Binder.restoreCallingIdentity(identity); |
| 7170 | } |
| 7171 | } |
| 7172 | |
| 7173 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7174 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 7175 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 7176 | + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7177 | final long identity = Binder.clearCallingIdentity(); |
| 7178 | try { |
| 7179 | Phone phone = getPhone(subscriptionId); |
| 7180 | if (phone == null) { |
| 7181 | return null; |
| 7182 | } |
| 7183 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7184 | } finally { |
| 7185 | Binder.restoreCallingIdentity(identity); |
| 7186 | } |
| 7187 | } |
| 7188 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7189 | /** |
| 7190 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7191 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7192 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7193 | final long identity = Binder.clearCallingIdentity(); |
| 7194 | try { |
| 7195 | Phone phone = getPhone(subId); |
| 7196 | if (phone != null) { |
| 7197 | return phone.isWifiCallingEnabled(); |
| 7198 | } else { |
| 7199 | return false; |
| 7200 | } |
| 7201 | } finally { |
| 7202 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7203 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7204 | } |
| 7205 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7206 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7207 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7208 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7209 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7210 | final long identity = Binder.clearCallingIdentity(); |
| 7211 | try { |
| 7212 | Phone phone = getPhone(subId); |
| 7213 | if (phone != null) { |
| 7214 | return phone.isVideoEnabled(); |
| 7215 | } else { |
| 7216 | return false; |
| 7217 | } |
| 7218 | } finally { |
| 7219 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7220 | } |
| 7221 | } |
| 7222 | |
| 7223 | /** |
| 7224 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7225 | * defined in {@link ImsRegistrationImplBase}. |
| 7226 | */ |
| 7227 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7228 | final long identity = Binder.clearCallingIdentity(); |
| 7229 | try { |
| 7230 | Phone phone = getPhone(subId); |
| 7231 | if (phone != null) { |
| 7232 | return phone.getImsRegistrationTech(); |
| 7233 | } else { |
| 7234 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7235 | } |
| 7236 | } finally { |
| 7237 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7238 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7239 | } |
| 7240 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7241 | @Override |
| 7242 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7243 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7244 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7245 | return; |
| 7246 | } |
| 7247 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7248 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7249 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7250 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7251 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7252 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7253 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7254 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7255 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7256 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7257 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 7258 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7259 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7260 | // There has been issues when Sms raw table somehow stores orphan |
| 7261 | // fragments. They lead to garbled message when new fragments come |
| 7262 | // in and combined with those stale ones. In case this happens again, |
| 7263 | // user can reset all network settings which will clean up this table. |
| 7264 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7265 | // Clean up IMS settings as well here. |
| 7266 | int slotId = getSlotIndex(subId); |
| 7267 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7268 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7269 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7270 | |
| 7271 | // Erase modem config if erase modem on network setting is enabled. |
| 7272 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7273 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7274 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 7275 | sendEraseModemConfig(getDefaultPhone()); |
| 7276 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7277 | } finally { |
| 7278 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7279 | } |
| 7280 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7281 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7282 | private void cleanUpSmsRawTable(Context context) { |
| 7283 | ContentResolver resolver = context.getContentResolver(); |
| 7284 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7285 | resolver.delete(uri, null, null); |
| 7286 | } |
| 7287 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7288 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7289 | public String getSimLocaleForSubscriber(int subId) { |
| 7290 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7291 | final Phone phone = getPhone(subId); |
| 7292 | if (phone == null) { |
| 7293 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7294 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7295 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7296 | final long identity = Binder.clearCallingIdentity(); |
| 7297 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7298 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7299 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7300 | if (info == null) { |
| 7301 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7302 | return null; |
| 7303 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7304 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7305 | // preferences (EF-PL and EF-LI)... |
| 7306 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7307 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7308 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7309 | if (localeFromDefaultSim != null) { |
| 7310 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7311 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7312 | + localeFromDefaultSim); |
| 7313 | return localeFromDefaultSim.toLanguageTag(); |
| 7314 | } else { |
| 7315 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7316 | } |
| 7317 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7318 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7319 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7320 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7321 | // the SIM and carrier preferences does not include a country we add the country |
| 7322 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7323 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7324 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7325 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7326 | return mccLocale.toLanguageTag(); |
| 7327 | } |
| 7328 | |
| 7329 | if (DBG) log("No locale found - returning null"); |
| 7330 | return null; |
| 7331 | } finally { |
| 7332 | Binder.restoreCallingIdentity(identity); |
| 7333 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7334 | } |
| 7335 | |
| 7336 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7337 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7338 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7339 | } |
| 7340 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7341 | /** |
| 7342 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7343 | */ |
| 7344 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7345 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7346 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7347 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7348 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7349 | private final ModemActivityInfo mLastModemActivityInfo = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7350 | new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7351 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7352 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7353 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7354 | * representing the state of the modem. |
| 7355 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7356 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7357 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7358 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7359 | */ |
| 7360 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7361 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7362 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7363 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7364 | |
| 7365 | final long identity = Binder.clearCallingIdentity(); |
| 7366 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7367 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7368 | } finally { |
| 7369 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7370 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7371 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7372 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7373 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7374 | // less than total activity duration. |
| 7375 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7376 | if (info == null) { |
| 7377 | return false; |
| 7378 | } |
| 7379 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7380 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7381 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7382 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7383 | return (info.isValid() |
| 7384 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7385 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7386 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7387 | && (totalTxTimeMs <= activityDurationMs)); |
| 7388 | } |
| 7389 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7390 | /** |
| 7391 | * {@hide} |
| 7392 | * Returns the service state information on specified subscription. |
| 7393 | */ |
| 7394 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7395 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7396 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7397 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7398 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7399 | return null; |
| 7400 | } |
| 7401 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7402 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7403 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7404 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7405 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7406 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7407 | .setCallingPid(Binder.getCallingPid()) |
| 7408 | .setCallingUid(Binder.getCallingUid()) |
| 7409 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7410 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7411 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7412 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7413 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7414 | .build()); |
| 7415 | |
| 7416 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7417 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7418 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7419 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7420 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7421 | .setCallingPid(Binder.getCallingPid()) |
| 7422 | .setCallingUid(Binder.getCallingUid()) |
| 7423 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7424 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7425 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7426 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7427 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7428 | .build()); |
| 7429 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7430 | boolean hasFinePermission = |
| 7431 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7432 | boolean hasCoarsePermission = |
| 7433 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7434 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7435 | final Phone phone = getPhone(subId); |
| 7436 | if (phone == null) { |
| 7437 | return null; |
| 7438 | } |
| 7439 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 7440 | final long identity = Binder.clearCallingIdentity(); |
| 7441 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7442 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7443 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7444 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7445 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7446 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7447 | Rlog.d(LOG_TAG, |
| 7448 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7449 | return null; |
| 7450 | } |
| 7451 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7452 | ServiceState ss = phone.getServiceState(); |
| 7453 | |
| 7454 | // Scrub out the location info in ServiceState depending on what level of access |
| 7455 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7456 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7457 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7458 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7459 | } finally { |
| 7460 | Binder.restoreCallingIdentity(identity); |
| 7461 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7462 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7463 | |
| 7464 | /** |
| 7465 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7466 | * |
| 7467 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7468 | * voicemail ringtone. |
| 7469 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7470 | * PhoneAccount. |
| 7471 | */ |
| 7472 | @Override |
| 7473 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7474 | final long identity = Binder.clearCallingIdentity(); |
| 7475 | try { |
| 7476 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7477 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7478 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7479 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7480 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7481 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7482 | } finally { |
| 7483 | Binder.restoreCallingIdentity(identity); |
| 7484 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7485 | } |
| 7486 | |
| 7487 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7488 | * Sets the per-account voicemail ringtone. |
| 7489 | * |
| 7490 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7491 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7492 | * |
| 7493 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7494 | * voicemail ringtone. |
| 7495 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7496 | * PhoneAccount. |
| 7497 | */ |
| 7498 | @Override |
| 7499 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7500 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7501 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7502 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7503 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7504 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7505 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7506 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7507 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7508 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7509 | |
| 7510 | final long identity = Binder.clearCallingIdentity(); |
| 7511 | try { |
| 7512 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7513 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7514 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7515 | } |
| 7516 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7517 | } finally { |
| 7518 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7519 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7520 | } |
| 7521 | |
| 7522 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7523 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7524 | * |
| 7525 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7526 | * voicemail vibration setting. |
| 7527 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7528 | */ |
| 7529 | @Override |
| 7530 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7531 | final long identity = Binder.clearCallingIdentity(); |
| 7532 | try { |
| 7533 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7534 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7535 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7536 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7537 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7538 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7539 | } finally { |
| 7540 | Binder.restoreCallingIdentity(identity); |
| 7541 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7542 | } |
| 7543 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7544 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7545 | * Sets the per-account voicemail vibration. |
| 7546 | * |
| 7547 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7548 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7549 | * |
| 7550 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7551 | * voicemail vibration setting. |
| 7552 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7553 | * specific PhoneAccount. |
| 7554 | */ |
| 7555 | @Override |
| 7556 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7557 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7558 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7559 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7560 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7561 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7562 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7563 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7564 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7565 | } |
| 7566 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7567 | final long identity = Binder.clearCallingIdentity(); |
| 7568 | try { |
| 7569 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7570 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7571 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7572 | } |
| 7573 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7574 | } finally { |
| 7575 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7576 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7577 | } |
| 7578 | |
| 7579 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7580 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7581 | * |
| 7582 | * @throws SecurityException if the caller does not have the required permission |
| 7583 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7584 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7585 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7586 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7587 | } |
| 7588 | |
| 7589 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7590 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7591 | * permission. |
| 7592 | * |
| 7593 | * @throws SecurityException if the caller does not have the required permission |
| 7594 | */ |
| 7595 | private void enforceSendSmsPermission() { |
| 7596 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7597 | } |
| 7598 | |
| 7599 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7600 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7601 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7602 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7603 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7604 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7605 | final long identity = Binder.clearCallingIdentity(); |
| 7606 | try { |
| 7607 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7608 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7609 | if (componentName == null) { |
| 7610 | throw new SecurityException( |
| 7611 | "Caller not current active visual voicemail package[null]"); |
| 7612 | } |
| 7613 | String vvmPackage = componentName.getPackageName(); |
| 7614 | if (!callingPackage.equals(vvmPackage)) { |
| 7615 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7616 | + vvmPackage + "]"); |
| 7617 | } |
| 7618 | } finally { |
| 7619 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7620 | } |
| 7621 | } |
| 7622 | |
| 7623 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7624 | * Return the application ID for the app type. |
| 7625 | * |
| 7626 | * @param subId the subscription ID that this request applies to. |
| 7627 | * @param appType the uicc app type. |
| 7628 | * @return Application ID for specificied app type, or null if no uicc. |
| 7629 | */ |
| 7630 | @Override |
| 7631 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7632 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7633 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7634 | |
| 7635 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7636 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7637 | if (phone == null) { |
| 7638 | return null; |
| 7639 | } |
| 7640 | String aid = null; |
| 7641 | try { |
| 7642 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7643 | .getApplicationByType(appType).getAid(); |
| 7644 | } catch (Exception e) { |
| 7645 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7646 | } |
| 7647 | return aid; |
| 7648 | } finally { |
| 7649 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7650 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7651 | } |
| 7652 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7653 | /** |
| 7654 | * Return the Electronic Serial Number. |
| 7655 | * |
| 7656 | * @param subId the subscription ID that this request applies to. |
| 7657 | * @return ESN or null if error. |
| 7658 | */ |
| 7659 | @Override |
| 7660 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7661 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7662 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7663 | |
| 7664 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7665 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7666 | if (phone == null) { |
| 7667 | return null; |
| 7668 | } |
| 7669 | String esn = null; |
| 7670 | try { |
| 7671 | esn = phone.getEsn(); |
| 7672 | } catch (Exception e) { |
| 7673 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7674 | } |
| 7675 | return esn; |
| 7676 | } finally { |
| 7677 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7678 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7679 | } |
| 7680 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7681 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7682 | * Return the Preferred Roaming List Version. |
| 7683 | * |
| 7684 | * @param subId the subscription ID that this request applies to. |
| 7685 | * @return PRLVersion or null if error. |
| 7686 | */ |
| 7687 | @Override |
| 7688 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7689 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7690 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7691 | |
| 7692 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7693 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7694 | if (phone == null) { |
| 7695 | return null; |
| 7696 | } |
| 7697 | String cdmaPrlVersion = null; |
| 7698 | try { |
| 7699 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7700 | } catch (Exception e) { |
| 7701 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7702 | } |
| 7703 | return cdmaPrlVersion; |
| 7704 | } finally { |
| 7705 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7706 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7707 | } |
| 7708 | |
| 7709 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7710 | * Get snapshot of Telephony histograms |
| 7711 | * @return List of Telephony histograms |
| 7712 | * @hide |
| 7713 | */ |
| 7714 | @Override |
| 7715 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7716 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7717 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7718 | |
| 7719 | final long identity = Binder.clearCallingIdentity(); |
| 7720 | try { |
| 7721 | return RIL.getTelephonyRILTimingHistograms(); |
| 7722 | } finally { |
| 7723 | Binder.restoreCallingIdentity(identity); |
| 7724 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7725 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7726 | |
| 7727 | /** |
| 7728 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7729 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7730 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7731 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7732 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7733 | * @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] | 7734 | */ |
| 7735 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7736 | @TelephonyManager.SetCarrierRestrictionResult |
| 7737 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7738 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7739 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7740 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7741 | if (carrierRestrictionRules == null) { |
| 7742 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7743 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7744 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7745 | final long identity = Binder.clearCallingIdentity(); |
| 7746 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7747 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7748 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7749 | } finally { |
| 7750 | Binder.restoreCallingIdentity(identity); |
| 7751 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7752 | } |
| 7753 | |
| 7754 | /** |
| 7755 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7756 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7757 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7758 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7759 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7760 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7761 | */ |
| 7762 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7763 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7764 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7765 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7766 | |
| 7767 | final long identity = Binder.clearCallingIdentity(); |
| 7768 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7769 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7770 | if (response instanceof CarrierRestrictionRules) { |
| 7771 | return (CarrierRestrictionRules) response; |
| 7772 | } |
| 7773 | // Response is an Exception of some kind, |
| 7774 | // which is signalled to the user as a NULL retval |
| 7775 | return null; |
| 7776 | } catch (Exception e) { |
| 7777 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7778 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7779 | } finally { |
| 7780 | Binder.restoreCallingIdentity(identity); |
| 7781 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7782 | } |
| 7783 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7784 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7785 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7786 | * @param subId the subscription ID that this action applies to. |
| 7787 | * @param enabled control enable or disable radio. |
| 7788 | * {@hide} |
| 7789 | */ |
| 7790 | @Override |
| 7791 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7792 | enforceModifyPermission(); |
| 7793 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7794 | |
| 7795 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7796 | if (phone == null) { |
| 7797 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7798 | return; |
| 7799 | } |
| 7800 | try { |
| 7801 | phone.carrierActionSetRadioEnabled(enabled); |
| 7802 | } catch (Exception e) { |
| 7803 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7804 | } finally { |
| 7805 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7806 | } |
| 7807 | } |
| 7808 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7809 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7810 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7811 | * network status based on which carrier apps could apply actions accordingly, |
| 7812 | * enable/disable default url handler for example. |
| 7813 | * |
| 7814 | * @param subId the subscription ID that this action applies to. |
| 7815 | * @param report control start/stop reporting the default network status. |
| 7816 | * {@hide} |
| 7817 | */ |
| 7818 | @Override |
| 7819 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7820 | enforceModifyPermission(); |
| 7821 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7822 | |
| 7823 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7824 | if (phone == null) { |
| 7825 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7826 | return; |
| 7827 | } |
| 7828 | try { |
| 7829 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7830 | } catch (Exception e) { |
| 7831 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7832 | } finally { |
| 7833 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7834 | } |
| 7835 | } |
| 7836 | |
| 7837 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7838 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7839 | * @param subId the subscription ID that this action applies to. |
| 7840 | * {@hide} |
| 7841 | */ |
| 7842 | @Override |
| 7843 | public void carrierActionResetAll(int subId) { |
| 7844 | enforceModifyPermission(); |
| 7845 | final Phone phone = getPhone(subId); |
| 7846 | if (phone == null) { |
| 7847 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7848 | return; |
| 7849 | } |
| 7850 | try { |
| 7851 | phone.carrierActionResetAll(); |
| 7852 | } catch (Exception e) { |
| 7853 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7854 | } |
| 7855 | } |
| 7856 | |
| 7857 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7858 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7859 | * bug report is being generated. |
| 7860 | */ |
| 7861 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7862 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7863 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7864 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7865 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7866 | + Binder.getCallingPid() |
| 7867 | + ", uid=" + Binder.getCallingUid() |
| 7868 | + "without permission " |
| 7869 | + android.Manifest.permission.DUMP); |
| 7870 | return; |
| 7871 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7872 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7873 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7874 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7875 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7876 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7877 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7878 | @NonNull String[] args) { |
| 7879 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 7880 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 7881 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7882 | } |
| 7883 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7884 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7885 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 7886 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7887 | * @param reason the reason the data enable change is taking place |
| 7888 | * @param enabled True if enabling the data, otherwise disabling. |
| 7889 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7890 | */ |
| 7891 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7892 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7893 | boolean enabled) { |
| 7894 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 7895 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7896 | try { |
| 7897 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7898 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7899 | } catch (SecurityException se) { |
| 7900 | enforceModifyPermission(); |
| 7901 | } |
| 7902 | } else { |
| 7903 | enforceModifyPermission(); |
| 7904 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7905 | |
| 7906 | final long identity = Binder.clearCallingIdentity(); |
| 7907 | try { |
| 7908 | Phone phone = getPhone(subId); |
| 7909 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7910 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7911 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7912 | } else { |
| 7913 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 7914 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7915 | } |
| 7916 | } finally { |
| 7917 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7918 | } |
| 7919 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7920 | |
| 7921 | /** |
| 7922 | * Get Client request stats |
| 7923 | * @return List of Client Request Stats |
| 7924 | * @hide |
| 7925 | */ |
| 7926 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7927 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7928 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7929 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7930 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7931 | return null; |
| 7932 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7933 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7934 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7935 | final long identity = Binder.clearCallingIdentity(); |
| 7936 | try { |
| 7937 | if (phone != null) { |
| 7938 | return phone.getClientRequestStats(); |
| 7939 | } |
| 7940 | |
| 7941 | return null; |
| 7942 | } finally { |
| 7943 | Binder.restoreCallingIdentity(identity); |
| 7944 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7945 | } |
| 7946 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7947 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7948 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7949 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7950 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7951 | |
| 7952 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7953 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7954 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7955 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7956 | * @param state State of SIM (power down, power up, pass through) |
| 7957 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7958 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7959 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7960 | * |
| 7961 | **/ |
| 7962 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7963 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7964 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7965 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7966 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7967 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7968 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7969 | final long identity = Binder.clearCallingIdentity(); |
| 7970 | try { |
| 7971 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 7972 | phone.setSimPowerState(state, null, workSource); |
| 7973 | } |
| 7974 | } finally { |
| 7975 | Binder.restoreCallingIdentity(identity); |
| 7976 | } |
| 7977 | } |
| 7978 | |
| 7979 | /** |
| 7980 | * Set SIM card power state. |
| 7981 | * |
| 7982 | * @param slotIndex SIM slot id. |
| 7983 | * @param state State of SIM (power down, power up, pass through) |
| 7984 | * @param callback callback to trigger after success or failure |
| 7985 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7986 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7987 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 7988 | * |
| 7989 | **/ |
| 7990 | @Override |
| 7991 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 7992 | IIntegerConsumer callback) { |
| 7993 | enforceModifyPermission(); |
| 7994 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7995 | |
| 7996 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7997 | |
| 7998 | final long identity = Binder.clearCallingIdentity(); |
| 7999 | try { |
| 8000 | if (phone != null) { |
| 8001 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8002 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8003 | } |
| 8004 | } finally { |
| 8005 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8006 | } |
| 8007 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8008 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8009 | private boolean isUssdApiAllowed(int subId) { |
| 8010 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8011 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8012 | if (configManager == null) { |
| 8013 | return false; |
| 8014 | } |
| 8015 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8016 | if (pb == null) { |
| 8017 | return false; |
| 8018 | } |
| 8019 | return pb.getBoolean( |
| 8020 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8021 | } |
| 8022 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8023 | /** |
| 8024 | * Check if phone is in emergency callback mode |
| 8025 | * @return true if phone is in emergency callback mode |
| 8026 | * @param subId sub id |
| 8027 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8028 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8029 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8030 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8031 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8032 | |
| 8033 | final long identity = Binder.clearCallingIdentity(); |
| 8034 | try { |
| 8035 | if (phone != null) { |
| 8036 | return phone.isInEcm(); |
| 8037 | } else { |
| 8038 | return false; |
| 8039 | } |
| 8040 | } finally { |
| 8041 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8042 | } |
| 8043 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8044 | |
| 8045 | /** |
| 8046 | * Get the current signal strength information for the given subscription. |
| 8047 | * Because this information is not updated when the device is in a low power state |
| 8048 | * it should not be relied-upon to be current. |
| 8049 | * @param subId Subscription index |
| 8050 | * @return the most recent cached signal strength info from the modem |
| 8051 | */ |
| 8052 | @Override |
| 8053 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8054 | final long identity = Binder.clearCallingIdentity(); |
| 8055 | try { |
| 8056 | Phone p = getPhone(subId); |
| 8057 | if (p == null) { |
| 8058 | return null; |
| 8059 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8060 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8061 | return p.getSignalStrength(); |
| 8062 | } finally { |
| 8063 | Binder.restoreCallingIdentity(identity); |
| 8064 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8065 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8066 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8067 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8068 | * Get the current modem radio state for the given slot. |
| 8069 | * @param slotIndex slot index. |
| 8070 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8071 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8072 | * @return the current radio power state from the modem |
| 8073 | */ |
| 8074 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8075 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8076 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8077 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8078 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8079 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8080 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8081 | } |
| 8082 | |
| 8083 | final long identity = Binder.clearCallingIdentity(); |
| 8084 | try { |
| 8085 | return phone.getRadioPowerState(); |
| 8086 | } finally { |
| 8087 | Binder.restoreCallingIdentity(identity); |
| 8088 | } |
| 8089 | } |
| 8090 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8091 | } |
| 8092 | |
| 8093 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8094 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8095 | * |
| 8096 | * <p>Requires one of the following permissions: |
| 8097 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 8098 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8099 | * privileges. |
| 8100 | * |
| 8101 | * @param subId subscription id |
| 8102 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8103 | * {@code false}. |
| 8104 | */ |
| 8105 | @Override |
| 8106 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8107 | try { |
| 8108 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8109 | null); |
| 8110 | } catch (Exception e) { |
| 8111 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 8112 | mApp, subId, "isDataRoamingEnabled"); |
| 8113 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8114 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8115 | boolean isEnabled = false; |
| 8116 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8117 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8118 | Phone phone = getPhone(subId); |
| 8119 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8120 | } finally { |
| 8121 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8122 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8123 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8124 | } |
| 8125 | |
| 8126 | |
| 8127 | /** |
| 8128 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8129 | * |
| 8130 | * <p> Requires permission: |
| 8131 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8132 | * privileges. |
| 8133 | * |
| 8134 | * @param subId subscription id |
| 8135 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8136 | */ |
| 8137 | @Override |
| 8138 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8139 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8140 | mApp, subId, "setDataRoamingEnabled"); |
| 8141 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8142 | final long identity = Binder.clearCallingIdentity(); |
| 8143 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8144 | Phone phone = getPhone(subId); |
| 8145 | if (phone != null) { |
| 8146 | phone.setDataRoamingEnabled(isEnabled); |
| 8147 | } |
| 8148 | } finally { |
| 8149 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8150 | } |
| 8151 | } |
| 8152 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8153 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8154 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8155 | TelephonyPermissions |
| 8156 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8157 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8158 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8159 | boolean isAllowed = true; |
| 8160 | final long identity = Binder.clearCallingIdentity(); |
| 8161 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8162 | Phone phone = getPhone(subId); |
| 8163 | if (phone != null) { |
| 8164 | isAllowed = phone.isCspPlmnEnabled(); |
| 8165 | } |
| 8166 | } finally { |
| 8167 | Binder.restoreCallingIdentity(identity); |
| 8168 | } |
| 8169 | return isAllowed; |
| 8170 | } |
| 8171 | |
| 8172 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8173 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8174 | // Verify that tha callingPackage belongs to the calling UID |
| 8175 | mApp.getSystemService(AppOpsManager.class) |
| 8176 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8177 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8178 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8179 | try { |
| 8180 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8181 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8182 | } catch (SecurityException e) { |
| 8183 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8184 | // has carrier privileges on an active UICC |
| 8185 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8186 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8187 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8188 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8189 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8190 | |
| 8191 | final long identity = Binder.clearCallingIdentity(); |
| 8192 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8193 | UiccController uiccController = UiccController.getInstance(); |
| 8194 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8195 | if (hasReadPermission) { |
| 8196 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8197 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8198 | |
| 8199 | // Remove private info if the caller doesn't have access |
| 8200 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8201 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8202 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8203 | // is available |
| 8204 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 8205 | if (card == null || card.getUiccProfile() == null) { |
| 8206 | // assume no access if the card or profile is unavailable |
| 8207 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8208 | continue; |
| 8209 | } |
| 8210 | UiccProfile profile = card.getUiccProfile(); |
| 8211 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8212 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8213 | filteredInfos.add(cardInfo); |
| 8214 | } else { |
| 8215 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8216 | } |
| 8217 | } |
| 8218 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8219 | } finally { |
| 8220 | Binder.restoreCallingIdentity(identity); |
| 8221 | } |
| 8222 | } |
| 8223 | |
| 8224 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8225 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8226 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8227 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8228 | final long identity = Binder.clearCallingIdentity(); |
| 8229 | try { |
| 8230 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8231 | if (slots == null) { |
| 8232 | Rlog.i(LOG_TAG, "slots is null."); |
| 8233 | return null; |
| 8234 | } |
| 8235 | |
| 8236 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8237 | for (int i = 0; i < slots.length; i++) { |
| 8238 | UiccSlot slot = slots[i]; |
| 8239 | if (slot == null) { |
| 8240 | continue; |
| 8241 | } |
| 8242 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8243 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8244 | UiccCard card = slot.getUiccCard(); |
| 8245 | if (card != null) { |
| 8246 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8247 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8248 | cardId = slot.getEid(); |
| 8249 | if (TextUtils.isEmpty(cardId)) { |
| 8250 | cardId = slot.getIccId(); |
| 8251 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8252 | } |
| 8253 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8254 | if (cardId != null) { |
| 8255 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8256 | // if cardId is an EID, it's all digits so this is fine |
| 8257 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8258 | } |
| 8259 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8260 | int cardState = 0; |
| 8261 | switch (slot.getCardState()) { |
| 8262 | case CARDSTATE_ABSENT: |
| 8263 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8264 | break; |
| 8265 | case CARDSTATE_PRESENT: |
| 8266 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8267 | break; |
| 8268 | case CARDSTATE_ERROR: |
| 8269 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8270 | break; |
| 8271 | case CARDSTATE_RESTRICTED: |
| 8272 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8273 | break; |
| 8274 | default: |
| 8275 | break; |
| 8276 | |
| 8277 | } |
| 8278 | |
| 8279 | infos[i] = new UiccSlotInfo( |
| 8280 | slot.isActive(), |
| 8281 | slot.isEuicc(), |
| 8282 | cardId, |
| 8283 | cardState, |
| 8284 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8285 | slot.isExtendedApduSupported(), |
| 8286 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8287 | } |
| 8288 | return infos; |
| 8289 | } finally { |
| 8290 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8291 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8292 | } |
| 8293 | |
| 8294 | @Override |
| 8295 | public boolean switchSlots(int[] physicalSlots) { |
| 8296 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8297 | |
| 8298 | final long identity = Binder.clearCallingIdentity(); |
| 8299 | try { |
| 8300 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8301 | } finally { |
| 8302 | Binder.restoreCallingIdentity(identity); |
| 8303 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8304 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8305 | |
| 8306 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8307 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8308 | final long identity = Binder.clearCallingIdentity(); |
| 8309 | try { |
| 8310 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8311 | } finally { |
| 8312 | Binder.restoreCallingIdentity(identity); |
| 8313 | } |
| 8314 | } |
| 8315 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8316 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8317 | * A test API to reload the UICC profile. |
| 8318 | * |
| 8319 | * <p>Requires that the calling app has permission |
| 8320 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8321 | * @hide |
| 8322 | */ |
| 8323 | @Override |
| 8324 | public void refreshUiccProfile(int subId) { |
| 8325 | enforceModifyPermission(); |
| 8326 | |
| 8327 | final long identity = Binder.clearCallingIdentity(); |
| 8328 | try { |
| 8329 | Phone phone = getPhone(subId); |
| 8330 | if (phone == null) { |
| 8331 | return; |
| 8332 | } |
| 8333 | UiccCard uiccCard = phone.getUiccCard(); |
| 8334 | if (uiccCard == null) { |
| 8335 | return; |
| 8336 | } |
| 8337 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8338 | if (uiccProfile == null) { |
| 8339 | return; |
| 8340 | } |
| 8341 | uiccProfile.refresh(); |
| 8342 | } finally { |
| 8343 | Binder.restoreCallingIdentity(identity); |
| 8344 | } |
| 8345 | } |
| 8346 | |
| 8347 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8348 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8349 | */ |
| 8350 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8351 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8352 | } |
| 8353 | |
| 8354 | /** |
| 8355 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8356 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8357 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8358 | */ |
| 8359 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8360 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8361 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8362 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8363 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8364 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8365 | return isDataRoamingEnabled; |
| 8366 | } |
| 8367 | |
| 8368 | /** |
| 8369 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8370 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8371 | */ |
| 8372 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8373 | List<Integer> list = TelephonyProperties.default_network(); |
| 8374 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8375 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8376 | return list.get(phoneId); |
| 8377 | } |
| 8378 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8379 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8380 | |
| 8381 | @Override |
| 8382 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8383 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8384 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8385 | |
| 8386 | final long identity = Binder.clearCallingIdentity(); |
| 8387 | try { |
| 8388 | final Phone phone = getPhone(subId); |
| 8389 | if (phone == null) { |
| 8390 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8391 | return; |
| 8392 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8393 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8394 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8395 | if (carrierPrivilegeRules == null) { |
| 8396 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8397 | } else { |
| 8398 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8399 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8400 | } finally { |
| 8401 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8402 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8403 | } |
| 8404 | |
| 8405 | @Override |
| 8406 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8407 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8408 | |
| 8409 | final long identity = Binder.clearCallingIdentity(); |
| 8410 | try { |
| 8411 | final Phone phone = getPhone(subId); |
| 8412 | if (phone == null) { |
| 8413 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8414 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8415 | } |
| 8416 | return phone.getCarrierIdListVersion(); |
| 8417 | } finally { |
| 8418 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8419 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8420 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8421 | |
| 8422 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8423 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8424 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8425 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8426 | mApp, subId, callingPackage, callingFeatureId, |
| 8427 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8428 | return -1; |
| 8429 | } |
| 8430 | |
| 8431 | final long identity = Binder.clearCallingIdentity(); |
| 8432 | try { |
| 8433 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8434 | } finally { |
| 8435 | Binder.restoreCallingIdentity(identity); |
| 8436 | } |
| 8437 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8438 | |
| 8439 | @Override |
| 8440 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8441 | TelephonyPermissions |
| 8442 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8443 | mApp, subId, "getCdmaRoamingMode"); |
| 8444 | |
| 8445 | final long identity = Binder.clearCallingIdentity(); |
| 8446 | try { |
| 8447 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8448 | } finally { |
| 8449 | Binder.restoreCallingIdentity(identity); |
| 8450 | } |
| 8451 | } |
| 8452 | |
| 8453 | @Override |
| 8454 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8455 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8456 | mApp, subId, "setCdmaRoamingMode"); |
| 8457 | |
| 8458 | final long identity = Binder.clearCallingIdentity(); |
| 8459 | try { |
| 8460 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8461 | } finally { |
| 8462 | Binder.restoreCallingIdentity(identity); |
| 8463 | } |
| 8464 | } |
| 8465 | |
| 8466 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8467 | public int getCdmaSubscriptionMode(int subId) { |
| 8468 | TelephonyPermissions |
| 8469 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8470 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8471 | |
| 8472 | final long identity = Binder.clearCallingIdentity(); |
| 8473 | try { |
| 8474 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8475 | } finally { |
| 8476 | Binder.restoreCallingIdentity(identity); |
| 8477 | } |
| 8478 | } |
| 8479 | |
| 8480 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8481 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8482 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8483 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8484 | |
| 8485 | final long identity = Binder.clearCallingIdentity(); |
| 8486 | try { |
| 8487 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8488 | } finally { |
| 8489 | Binder.restoreCallingIdentity(identity); |
| 8490 | } |
| 8491 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8492 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8493 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8494 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8495 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8496 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8497 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8498 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8499 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8500 | } |
| 8501 | final long identity = Binder.clearCallingIdentity(); |
| 8502 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8503 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8504 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8505 | if (phone.getEmergencyNumberTracker() != null |
| 8506 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8507 | emergencyNumberListInternal.put( |
| 8508 | phone.getSubId(), |
| 8509 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8510 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8511 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8512 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8513 | } finally { |
| 8514 | Binder.restoreCallingIdentity(identity); |
| 8515 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8516 | } |
| 8517 | |
| 8518 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8519 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8520 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8521 | if (!exactMatch) { |
| 8522 | TelephonyPermissions |
| 8523 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8524 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8525 | } |
| 8526 | final long identity = Binder.clearCallingIdentity(); |
| 8527 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8528 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8529 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8530 | && phone.getEmergencyNumberTracker() |
| 8531 | .isEmergencyNumber(number, exactMatch)) { |
| 8532 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8533 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8534 | } |
| 8535 | return false; |
| 8536 | } finally { |
| 8537 | Binder.restoreCallingIdentity(identity); |
| 8538 | } |
| 8539 | } |
| 8540 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8541 | /** |
| 8542 | * Update emergency number list for test mode. |
| 8543 | */ |
| 8544 | @Override |
| 8545 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8546 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8547 | "updateEmergencyNumberListTestMode"); |
| 8548 | |
| 8549 | final long identity = Binder.clearCallingIdentity(); |
| 8550 | try { |
| 8551 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8552 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8553 | if (tracker != null) { |
| 8554 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8555 | } |
| 8556 | } |
| 8557 | } finally { |
| 8558 | Binder.restoreCallingIdentity(identity); |
| 8559 | } |
| 8560 | } |
| 8561 | |
| 8562 | /** |
| 8563 | * Get the full emergency number list for test mode. |
| 8564 | */ |
| 8565 | @Override |
| 8566 | public List<String> getEmergencyNumberListTestMode() { |
| 8567 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8568 | "getEmergencyNumberListTestMode"); |
| 8569 | |
| 8570 | final long identity = Binder.clearCallingIdentity(); |
| 8571 | try { |
| 8572 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8573 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8574 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8575 | if (tracker != null) { |
| 8576 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8577 | emergencyNumbers.add(num.getNumber()); |
| 8578 | } |
| 8579 | } |
| 8580 | } |
| 8581 | return new ArrayList<>(emergencyNumbers); |
| 8582 | } finally { |
| 8583 | Binder.restoreCallingIdentity(identity); |
| 8584 | } |
| 8585 | } |
| 8586 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8587 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8588 | public int getEmergencyNumberDbVersion(int subId) { |
| 8589 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8590 | |
| 8591 | final long identity = Binder.clearCallingIdentity(); |
| 8592 | try { |
| 8593 | final Phone phone = getPhone(subId); |
| 8594 | if (phone == null) { |
| 8595 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8596 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8597 | } |
| 8598 | return phone.getEmergencyNumberDbVersion(); |
| 8599 | } finally { |
| 8600 | Binder.restoreCallingIdentity(identity); |
| 8601 | } |
| 8602 | } |
| 8603 | |
| 8604 | @Override |
| 8605 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8606 | enforceModifyPermission(); |
| 8607 | |
| 8608 | final long identity = Binder.clearCallingIdentity(); |
| 8609 | try { |
| 8610 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8611 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8612 | if (tracker != null) { |
| 8613 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8614 | } |
| 8615 | } |
| 8616 | } finally { |
| 8617 | Binder.restoreCallingIdentity(identity); |
| 8618 | } |
| 8619 | } |
| 8620 | |
| 8621 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8622 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8623 | enforceActiveEmergencySessionPermission(); |
| 8624 | |
| 8625 | final long identity = Binder.clearCallingIdentity(); |
| 8626 | try { |
| 8627 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8628 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8629 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8630 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8631 | } |
| 8632 | } |
| 8633 | } finally { |
| 8634 | Binder.restoreCallingIdentity(identity); |
| 8635 | } |
| 8636 | } |
| 8637 | |
| 8638 | @Override |
| 8639 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8640 | enforceActiveEmergencySessionPermission(); |
| 8641 | |
| 8642 | final long identity = Binder.clearCallingIdentity(); |
| 8643 | try { |
| 8644 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8645 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8646 | if (tracker != null) { |
| 8647 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8648 | } |
| 8649 | } |
| 8650 | } finally { |
| 8651 | Binder.restoreCallingIdentity(identity); |
| 8652 | } |
| 8653 | } |
| 8654 | |
| 8655 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8656 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8657 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8658 | Phone phone = getPhone(subId); |
| 8659 | if (phone == null) { |
| 8660 | return null; |
| 8661 | } |
| 8662 | final long identity = Binder.clearCallingIdentity(); |
| 8663 | try { |
| 8664 | UiccProfile profile = UiccController.getInstance() |
| 8665 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8666 | if (profile != null) { |
| 8667 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8668 | } |
| 8669 | } finally { |
| 8670 | Binder.restoreCallingIdentity(identity); |
| 8671 | } |
| 8672 | return null; |
| 8673 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8674 | |
| 8675 | /** |
| 8676 | * Enable or disable a modem stack. |
| 8677 | */ |
| 8678 | @Override |
| 8679 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8680 | enforceModifyPermission(); |
| 8681 | |
| 8682 | final long identity = Binder.clearCallingIdentity(); |
| 8683 | try { |
| 8684 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8685 | if (phone == null) { |
| 8686 | return false; |
| 8687 | } else { |
| 8688 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8689 | } |
| 8690 | } finally { |
| 8691 | Binder.restoreCallingIdentity(identity); |
| 8692 | } |
| 8693 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8694 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8695 | /** |
| 8696 | * Whether a modem stack is enabled or not. |
| 8697 | */ |
| 8698 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8699 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8700 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8701 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8702 | if (phone == null) return false; |
| 8703 | |
| 8704 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8705 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8706 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8707 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8708 | } |
| 8709 | |
| 8710 | final long identity = Binder.clearCallingIdentity(); |
| 8711 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8712 | try { |
| 8713 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8714 | } catch (NoSuchElementException ex) { |
| 8715 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8716 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8717 | } finally { |
| 8718 | Binder.restoreCallingIdentity(identity); |
| 8719 | } |
| 8720 | } |
| 8721 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8722 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8723 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8724 | enforceModifyPermission(); |
| 8725 | |
| 8726 | final long identity = Binder.clearCallingIdentity(); |
| 8727 | try { |
| 8728 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8729 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8730 | .commit(); |
| 8731 | } finally { |
| 8732 | Binder.restoreCallingIdentity(identity); |
| 8733 | } |
| 8734 | } |
| 8735 | |
| 8736 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8737 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8738 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8739 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8740 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8741 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8742 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8743 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8744 | |
| 8745 | final long identity = Binder.clearCallingIdentity(); |
| 8746 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8747 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8748 | } finally { |
| 8749 | Binder.restoreCallingIdentity(identity); |
| 8750 | } |
| 8751 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8752 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8753 | @TelephonyManager.IsMultiSimSupportedResult |
| 8754 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8755 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8756 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8757 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8758 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8759 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8760 | } |
| 8761 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8762 | // supported by the modem, indicate that it is restricted. |
| 8763 | PhoneCapability staticCapability = |
| 8764 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8765 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8766 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8767 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8768 | } |
Sarah Chin | 7caee49 | 2020-02-18 20:49:02 +0000 | [diff] [blame] | 8769 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8770 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8771 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8772 | } |
| 8773 | // Check if support of multiple SIMs is restricted by carrier |
| 8774 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8775 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8776 | } |
| 8777 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8778 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8779 | } |
| 8780 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8781 | /** |
| 8782 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8783 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8784 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8785 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8786 | * @param numOfSims number of active sims we want to switch to |
| 8787 | */ |
| 8788 | @Override |
| 8789 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8790 | if (numOfSims == 1) { |
| 8791 | enforceModifyPermission(); |
| 8792 | } else { |
| 8793 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8794 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8795 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8796 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8797 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8798 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8799 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8800 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8801 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8802 | return; |
| 8803 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8804 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8805 | } finally { |
| 8806 | Binder.restoreCallingIdentity(identity); |
| 8807 | } |
| 8808 | } |
| 8809 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8810 | @Override |
| 8811 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8812 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8813 | Phone phone = getPhone(subId); |
| 8814 | if (phone == null) { |
| 8815 | return false; |
| 8816 | } |
| 8817 | final long identity = Binder.clearCallingIdentity(); |
| 8818 | try { |
| 8819 | UiccCard uiccCard = phone.getUiccCard(); |
| 8820 | if (uiccCard == null) { |
| 8821 | return false; |
| 8822 | } |
| 8823 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8824 | if (uiccProfile == null) { |
| 8825 | return false; |
| 8826 | } |
| 8827 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8828 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8829 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8830 | } |
| 8831 | return false; |
| 8832 | } finally { |
| 8833 | Binder.restoreCallingIdentity(identity); |
| 8834 | } |
| 8835 | } |
| 8836 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8837 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8838 | * Get whether making changes to modem configurations will trigger reboot. |
| 8839 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8840 | */ |
| 8841 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8842 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8843 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8844 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8845 | mApp, subId, callingPackage, callingFeatureId, |
| 8846 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8847 | return false; |
| 8848 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8849 | final long identity = Binder.clearCallingIdentity(); |
| 8850 | try { |
| 8851 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8852 | } finally { |
| 8853 | Binder.restoreCallingIdentity(identity); |
| 8854 | } |
| 8855 | } |
| 8856 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8857 | private void updateModemStateMetrics() { |
| 8858 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8859 | // TODO: check the state for each modem if the api is ready. |
| 8860 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8861 | } |
| 8862 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8863 | @Override |
| 8864 | public int[] getSlotsMapping() { |
| 8865 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8866 | |
| 8867 | final long identity = Binder.clearCallingIdentity(); |
| 8868 | try { |
| 8869 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8870 | // All logical slots should have a mapping to a physical slot. |
| 8871 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8872 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8873 | for (int i = 0; i < slotInfos.length; i++) { |
| 8874 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8875 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8876 | } |
| 8877 | } |
| 8878 | return logicalSlotsMapping; |
| 8879 | } finally { |
| 8880 | Binder.restoreCallingIdentity(identity); |
| 8881 | } |
| 8882 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8883 | |
| 8884 | /** |
| 8885 | * Get the IRadio HAL Version |
| 8886 | */ |
| 8887 | @Override |
| 8888 | public int getRadioHalVersion() { |
| 8889 | Phone phone = getDefaultPhone(); |
| 8890 | if (phone == null) return -1; |
| 8891 | HalVersion hv = phone.getHalVersion(); |
| 8892 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8893 | return hv.major * 100 + hv.minor; |
| 8894 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8895 | |
| 8896 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8897 | * Get the current calling package name. |
| 8898 | * @return the current calling package name |
| 8899 | */ |
| 8900 | @Override |
| 8901 | public String getCurrentPackageName() { |
| 8902 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8903 | } |
| 8904 | |
| 8905 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8906 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8907 | * corresponding network requests on a subId. |
| 8908 | * |
| 8909 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8910 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8911 | * 2) APN is un-metered for this subscription, or |
| 8912 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8913 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8914 | * |
| 8915 | * @return whether data is allowed for a apn type. |
| 8916 | * |
| 8917 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8918 | */ |
| 8919 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8920 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8921 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8922 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8923 | |
| 8924 | // Now that all security checks passes, perform the operation as ourselves. |
| 8925 | final long identity = Binder.clearCallingIdentity(); |
| 8926 | try { |
| 8927 | Phone phone = getPhone(subId); |
| 8928 | if (phone == null) return false; |
| 8929 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8930 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8931 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8932 | } finally { |
| 8933 | Binder.restoreCallingIdentity(identity); |
| 8934 | } |
| 8935 | } |
| 8936 | |
| 8937 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8938 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8939 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8940 | |
| 8941 | // Now that all security checks passes, perform the operation as ourselves. |
| 8942 | final long identity = Binder.clearCallingIdentity(); |
| 8943 | try { |
| 8944 | Phone phone = getPhone(subId); |
| 8945 | if (phone == null) return true; // By default return true. |
| 8946 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8947 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8948 | } finally { |
| 8949 | Binder.restoreCallingIdentity(identity); |
| 8950 | } |
| 8951 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8952 | |
| 8953 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8954 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8955 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8956 | enforceModifyPermission(); |
| 8957 | long token = Binder.clearCallingIdentity(); |
| 8958 | try { |
| 8959 | Phone phone = getPhone(subscriptionId); |
| 8960 | if (phone == null) { |
| 8961 | try { |
| 8962 | if (resultCallback != null) { |
| 8963 | resultCallback.accept(false); |
| 8964 | } |
| 8965 | } catch (RemoteException e) { |
| 8966 | // ignore |
| 8967 | } |
| 8968 | return; |
| 8969 | } |
| 8970 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 8971 | Pair.create(specifiers, (x) -> { |
| 8972 | try { |
| 8973 | if (resultCallback != null) { |
| 8974 | resultCallback.accept(x); |
| 8975 | } |
| 8976 | } catch (RemoteException e) { |
| 8977 | // ignore |
| 8978 | } |
| 8979 | }); |
| 8980 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 8981 | } finally { |
| 8982 | Binder.restoreCallingIdentity(token); |
| 8983 | } |
| 8984 | } |
| 8985 | |
| 8986 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 8987 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 8988 | TelephonyPermissions |
| 8989 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8990 | mApp, subId, "getSystemSelectionChannels"); |
| 8991 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8992 | final long identity = Binder.clearCallingIdentity(); |
| 8993 | try { |
| 8994 | List<RadioAccessSpecifier> specifiers = |
| 8995 | (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, |
| 8996 | null, subId, workSource); |
| 8997 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 8998 | return specifiers; |
| 8999 | } finally { |
| 9000 | Binder.restoreCallingIdentity(identity); |
| 9001 | } |
| 9002 | } |
| 9003 | |
| 9004 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9005 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9006 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9007 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9008 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9009 | if (iccRecords == null) { |
| 9010 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9011 | return false; |
| 9012 | } |
| 9013 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9014 | } |
| 9015 | |
| 9016 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9017 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9018 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9019 | if (callingPackage == null) { |
| 9020 | callingPackage = getCurrentPackageName(); |
| 9021 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9022 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9023 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9024 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9025 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9026 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9027 | } |
| 9028 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9029 | Intent intent = new Intent(); |
| 9030 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9031 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9032 | // Bring up choose default SMS subscription dialog right now |
| 9033 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9034 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9035 | mApp.startActivity(intent); |
| 9036 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9037 | |
| 9038 | @Override |
| 9039 | public String getMmsUAProfUrl(int subId) { |
| 9040 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9041 | final long identity = Binder.clearCallingIdentity(); |
| 9042 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9043 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9044 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9045 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9046 | return carrierUAProfUrl; |
| 9047 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9048 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9049 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9050 | } finally { |
| 9051 | Binder.restoreCallingIdentity(identity); |
| 9052 | } |
| 9053 | } |
| 9054 | |
| 9055 | @Override |
| 9056 | public String getMmsUserAgent(int subId) { |
| 9057 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9058 | final long identity = Binder.clearCallingIdentity(); |
| 9059 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9060 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9061 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9062 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9063 | return carrierUserAgent; |
| 9064 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9065 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9066 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9067 | } finally { |
| 9068 | Binder.restoreCallingIdentity(identity); |
| 9069 | } |
| 9070 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9071 | |
| 9072 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9073 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9074 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9075 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9076 | final long identity = Binder.clearCallingIdentity(); |
| 9077 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9078 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9079 | if (phone == null) return false; |
| 9080 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9081 | switch (policy) { |
| 9082 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9083 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9084 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9085 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9086 | default: |
| 9087 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9088 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9089 | } finally { |
| 9090 | Binder.restoreCallingIdentity(identity); |
| 9091 | } |
| 9092 | } |
| 9093 | |
| 9094 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9095 | public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy, |
| 9096 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9097 | enforceModifyPermission(); |
| 9098 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9099 | final long identity = Binder.clearCallingIdentity(); |
| 9100 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9101 | Phone phone = getPhone(subscriptionId); |
| 9102 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9103 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9104 | switch (policy) { |
| 9105 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9106 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9107 | break; |
| 9108 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9109 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9110 | break; |
| 9111 | default: |
| 9112 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9113 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9114 | } finally { |
| 9115 | Binder.restoreCallingIdentity(identity); |
| 9116 | } |
| 9117 | } |
| 9118 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9119 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9120 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9121 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9122 | * otherwise. |
| 9123 | */ |
| 9124 | @Override |
| 9125 | public void setCepEnabled(boolean isCepEnabled) { |
| 9126 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9127 | |
| 9128 | final long identity = Binder.clearCallingIdentity(); |
| 9129 | try { |
| 9130 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9131 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9132 | Phone defaultPhone = phone.getImsPhone(); |
| 9133 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9134 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9135 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9136 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9137 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9138 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9139 | + imsPhone.getMsisdn()); |
| 9140 | } |
| 9141 | } |
| 9142 | } finally { |
| 9143 | Binder.restoreCallingIdentity(identity); |
| 9144 | } |
| 9145 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9146 | |
| 9147 | /** |
| 9148 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9149 | * |
| 9150 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9151 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9152 | * before being read. |
| 9153 | */ |
| 9154 | @Override |
| 9155 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9156 | isCompressed) { |
| 9157 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9158 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9159 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9160 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9161 | } |
| 9162 | if (!isImsAvailableOnDevice()) { |
| 9163 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9164 | "IMS not available on device."); |
| 9165 | } |
| 9166 | |
| 9167 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9168 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9169 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9170 | } finally { |
| 9171 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9172 | } |
| 9173 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9174 | |
| 9175 | @Override |
| 9176 | public boolean isIccLockEnabled(int subId) { |
| 9177 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9178 | |
| 9179 | // Now that all security checks passes, perform the operation as ourselves. |
| 9180 | final long identity = Binder.clearCallingIdentity(); |
| 9181 | try { |
| 9182 | Phone phone = getPhone(subId); |
| 9183 | if (phone != null && phone.getIccCard() != null) { |
| 9184 | return phone.getIccCard().getIccLockEnabled(); |
| 9185 | } else { |
| 9186 | return false; |
| 9187 | } |
| 9188 | } finally { |
| 9189 | Binder.restoreCallingIdentity(identity); |
| 9190 | } |
| 9191 | } |
| 9192 | |
| 9193 | /** |
| 9194 | * Set the ICC pin lock enabled or disabled. |
| 9195 | * |
| 9196 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9197 | * three cases: |
| 9198 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9199 | * successfully. |
| 9200 | * - Positive number and zero for remaining password attempts. |
| 9201 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9202 | * |
| 9203 | */ |
| 9204 | @Override |
| 9205 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9206 | enforceModifyPermission(); |
| 9207 | |
| 9208 | Phone phone = getPhone(subId); |
| 9209 | if (phone == null) { |
| 9210 | return 0; |
| 9211 | } |
| 9212 | // Now that all security checks passes, perform the operation as ourselves. |
| 9213 | final long identity = Binder.clearCallingIdentity(); |
| 9214 | try { |
| 9215 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9216 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9217 | return attemptsRemaining; |
| 9218 | |
| 9219 | } catch (Exception e) { |
| 9220 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9221 | } finally { |
| 9222 | Binder.restoreCallingIdentity(identity); |
| 9223 | } |
| 9224 | return 0; |
| 9225 | } |
| 9226 | |
| 9227 | /** |
| 9228 | * Change the ICC password used in ICC pin lock. |
| 9229 | * |
| 9230 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9231 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9232 | * - Positive number and zero for remaining password attempts. |
| 9233 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9234 | * |
| 9235 | */ |
| 9236 | @Override |
| 9237 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9238 | enforceModifyPermission(); |
| 9239 | |
| 9240 | Phone phone = getPhone(subId); |
| 9241 | if (phone == null) { |
| 9242 | return 0; |
| 9243 | } |
| 9244 | // Now that all security checks passes, perform the operation as ourselves. |
| 9245 | final long identity = Binder.clearCallingIdentity(); |
| 9246 | try { |
| 9247 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9248 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9249 | return attemptsRemaining; |
| 9250 | |
| 9251 | } catch (Exception e) { |
| 9252 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9253 | } finally { |
| 9254 | Binder.restoreCallingIdentity(identity); |
| 9255 | } |
| 9256 | return 0; |
| 9257 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9258 | |
| 9259 | /** |
| 9260 | * Request for receiving user activity notification |
| 9261 | */ |
| 9262 | @Override |
| 9263 | public void requestUserActivityNotification() { |
| 9264 | if (!mNotifyUserActivity.get() |
| 9265 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9266 | mNotifyUserActivity.set(true); |
| 9267 | } |
| 9268 | } |
| 9269 | |
| 9270 | /** |
| 9271 | * Called when userActivity is signalled in the power manager. |
| 9272 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9273 | */ |
| 9274 | @Override |
| 9275 | public void userActivity() { |
| 9276 | // *************************************** |
| 9277 | // * Inherited from PhoneWindowManager * |
| 9278 | // *************************************** |
| 9279 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9280 | // WITH ITS LOCKS HELD. |
| 9281 | // |
| 9282 | // This code must be VERY careful about the locks |
| 9283 | // it acquires. |
| 9284 | // In fact, the current code acquires way too many, |
| 9285 | // and probably has lurking deadlocks. |
| 9286 | |
| 9287 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9288 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9289 | } |
| 9290 | |
| 9291 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9292 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9293 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9294 | } |
| 9295 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9296 | |
| 9297 | @Override |
| 9298 | public boolean canConnectTo5GInDsdsMode() { |
| 9299 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9300 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9301 | |
| 9302 | @Override |
| 9303 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9304 | String callingFeatureId) { |
| 9305 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9306 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9307 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9308 | } |
| 9309 | |
| 9310 | Phone phone = getPhone(subId); |
| 9311 | if (phone == null) { |
| 9312 | throw new RuntimeException("phone is not available"); |
| 9313 | } |
| 9314 | // Now that all security checks passes, perform the operation as ourselves. |
| 9315 | final long identity = Binder.clearCallingIdentity(); |
| 9316 | try { |
| 9317 | return phone.getEquivalentHomePlmns(); |
| 9318 | } finally { |
| 9319 | Binder.restoreCallingIdentity(identity); |
| 9320 | } |
| 9321 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9322 | |
| 9323 | @Override |
| 9324 | public boolean isRadioInterfaceCapabilitySupported( |
| 9325 | @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 9326 | RadioInterfaceCapabilities radioInterfaceCapabilities = |
| 9327 | mPhoneConfigurationManager.getRadioInterfaceCapabilities(); |
| 9328 | if (radioInterfaceCapabilities == null) { |
| 9329 | throw new RuntimeException("radio interface capabilities are not available"); |
| 9330 | } else { |
| 9331 | return radioInterfaceCapabilities.isSupported(capability); |
| 9332 | } |
| 9333 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9334 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9335 | @Override |
| 9336 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 9337 | UaSecurityProtocolIdentifier securityProtocol, |
| 9338 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) |
| 9339 | throws RemoteException { |
| 9340 | enforceModifyPermission(); |
| 9341 | if (DBG) { |
| 9342 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 9343 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 9344 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 9345 | } |
| 9346 | |
| 9347 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 9348 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 9349 | || appType > TelephonyManager.APPTYPE_ISIM |
| 9350 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 9351 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 9352 | if (callback != null) { |
| 9353 | try { |
| 9354 | callback.onAuthenticationFailure( |
| 9355 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 9356 | } catch (RemoteException exception) { |
| 9357 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 9358 | } |
| 9359 | return; |
| 9360 | } |
| 9361 | } |
| 9362 | |
| 9363 | final long token = Binder.clearCallingIdentity(); |
| 9364 | try { |
| 9365 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 9366 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 9367 | forceBootStrapping, callback)); |
| 9368 | } finally { |
| 9369 | Binder.restoreCallingIdentity(token); |
| 9370 | } |
| 9371 | } |
| 9372 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9373 | /** |
| 9374 | * Attempts to set the radio power state for thermal reason. This does not guarantee that the |
| 9375 | * requested radio power state will actually be set. See {@link |
| 9376 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9377 | * |
| 9378 | * @param subId the subscription ID of the phone requesting to set the radio power state. |
| 9379 | * @param enable {@code true} if trying to turn radio on. |
| 9380 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9381 | * false}. |
| 9382 | */ |
| 9383 | private boolean setRadioPowerForThermal(int subId, boolean enable) { |
| 9384 | Phone phone = getPhone(subId); |
| 9385 | if (phone != null) { |
| 9386 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 9387 | return true; |
| 9388 | } |
| 9389 | return false; |
| 9390 | } |
| 9391 | |
| 9392 | private int handleDataThrottlingRequest(int subId, |
| 9393 | DataThrottlingRequest dataThrottlingRequest) { |
| 9394 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 9395 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9396 | if (!setRadioPowerForThermal(subId, true)) { |
| 9397 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9398 | } |
| 9399 | |
| 9400 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 9401 | |
| 9402 | int thermalMitigationResult = |
| 9403 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
| 9404 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 9405 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 9406 | } |
| 9407 | return thermalMitigationResult; |
| 9408 | } |
| 9409 | |
| 9410 | /** |
| 9411 | * Thermal mitigation request to control functionalities at modem. |
| 9412 | * |
| 9413 | * @param subId the id of the subscription. |
| 9414 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
| 9415 | * |
| 9416 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 9417 | */ |
| 9418 | @Override |
| 9419 | @ThermalMitigationResult |
| 9420 | public int sendThermalMitigationRequest( |
| 9421 | int subId, |
| 9422 | ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException { |
| 9423 | enforceModifyPermission(); |
| 9424 | |
| 9425 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9426 | final long identity = Binder.clearCallingIdentity(); |
| 9427 | |
| 9428 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 9429 | try { |
| 9430 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 9431 | switch (thermalMitigationAction) { |
| 9432 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 9433 | thermalMitigationResult = |
| 9434 | handleDataThrottlingRequest(subId, |
| 9435 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 9436 | break; |
| 9437 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 9438 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9439 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 9440 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 9441 | } |
| 9442 | |
| 9443 | // Ensure that radio is on. If not able to power on due to phone being |
| 9444 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9445 | if (!setRadioPowerForThermal(subId, true)) { |
| 9446 | thermalMitigationResult = |
| 9447 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9448 | break; |
| 9449 | } |
| 9450 | |
| 9451 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 9452 | false); |
| 9453 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9454 | break; |
| 9455 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 9456 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9457 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 9458 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 9459 | } |
| 9460 | |
| 9461 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 9462 | if (registry != null) { |
| 9463 | TelephonyConnectionService service = |
| 9464 | registry.getTelephonyConnectionService(); |
| 9465 | Phone phone = getPhone(subId); |
| 9466 | if (phone == null) { |
| 9467 | thermalMitigationResult = |
| 9468 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9469 | break; |
| 9470 | } |
| 9471 | |
| 9472 | if (PhoneConstantConversions.convertCallState(phone.getState()) |
| 9473 | != TelephonyManager.CALL_STATE_IDLE |
| 9474 | || phone.isInEmergencySmsMode() || phone.isInEcm() |
| 9475 | || (service != null && service.isEmergencyCallPending())) { |
| 9476 | String errorMessage = "Phone state is not valid. call state = " |
| 9477 | + PhoneConstantConversions.convertCallState(phone.getState()) |
| 9478 | + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode() |
| 9479 | + " isInEmergencyCallbackMode = " + phone.isInEcm(); |
| 9480 | errorMessage += service == null |
| 9481 | ? " TelephonyConnectionService is null" |
| 9482 | : " isEmergencyCallPending = " |
| 9483 | + service.isEmergencyCallPending(); |
| 9484 | Log.e(LOG_TAG, errorMessage); |
| 9485 | thermalMitigationResult = |
| 9486 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 9487 | break; |
| 9488 | } |
| 9489 | } else { |
| 9490 | thermalMitigationResult = |
| 9491 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9492 | break; |
| 9493 | } |
| 9494 | |
| 9495 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 9496 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9497 | if (!setRadioPowerForThermal(subId, false)) { |
| 9498 | thermalMitigationResult = |
| 9499 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9500 | break; |
| 9501 | } |
| 9502 | thermalMitigationResult = |
| 9503 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9504 | break; |
| 9505 | default: |
| 9506 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 9507 | + "not exist. Requested action: " + thermalMitigationAction); |
| 9508 | } |
| 9509 | } catch (IllegalArgumentException e) { |
| 9510 | throw e; |
| 9511 | } catch (Exception e) { |
| 9512 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 9513 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 9514 | } finally { |
| 9515 | Binder.restoreCallingIdentity(identity); |
| 9516 | } |
| 9517 | |
| 9518 | if (DBG) { |
| 9519 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 9520 | + thermalMitigationResult); |
| 9521 | } |
| 9522 | |
| 9523 | return thermalMitigationResult; |
| 9524 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9525 | |
| 9526 | /** |
| 9527 | * Set the GbaService Package Name that Telephony will bind to. |
| 9528 | * |
| 9529 | * @param subId The sim that the GbaService is associated with. |
| 9530 | * @param packageName The name of the package to be replaced with. |
| 9531 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9532 | */ |
| 9533 | @Override |
| 9534 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 9535 | enforceModifyPermission(); |
| 9536 | |
| 9537 | final long identity = Binder.clearCallingIdentity(); |
| 9538 | try { |
| 9539 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 9540 | } finally { |
| 9541 | Binder.restoreCallingIdentity(identity); |
| 9542 | } |
| 9543 | } |
| 9544 | |
| 9545 | /** |
| 9546 | * Return the package name of the currently bound GbaService. |
| 9547 | * |
| 9548 | * @param subId The sim that the GbaService is associated with. |
| 9549 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 9550 | */ |
| 9551 | @Override |
| 9552 | public String getBoundGbaService(int subId) { |
| 9553 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 9554 | |
| 9555 | final long identity = Binder.clearCallingIdentity(); |
| 9556 | try { |
| 9557 | return getGbaManager(subId).getServicePackage(); |
| 9558 | } finally { |
| 9559 | Binder.restoreCallingIdentity(identity); |
| 9560 | } |
| 9561 | } |
| 9562 | |
| 9563 | /** |
| 9564 | * Set the release time for telephony to unbind GbaService. |
| 9565 | * |
| 9566 | * @param subId The sim that the GbaService is associated with. |
| 9567 | * @param interval The release time to unbind GbaService by millisecond. |
| 9568 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9569 | */ |
| 9570 | @Override |
| 9571 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 9572 | enforceModifyPermission(); |
| 9573 | |
| 9574 | final long identity = Binder.clearCallingIdentity(); |
| 9575 | try { |
| 9576 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 9577 | } finally { |
| 9578 | Binder.restoreCallingIdentity(identity); |
| 9579 | } |
| 9580 | } |
| 9581 | |
| 9582 | /** |
| 9583 | * Return the release time for telephony to unbind GbaService. |
| 9584 | * |
| 9585 | * @param subId The sim that the GbaService is associated with. |
| 9586 | * @return The release time to unbind GbaService by millisecond. |
| 9587 | */ |
| 9588 | @Override |
| 9589 | public int getGbaReleaseTime(int subId) { |
| 9590 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 9591 | |
| 9592 | final long identity = Binder.clearCallingIdentity(); |
| 9593 | try { |
| 9594 | return getGbaManager(subId).getReleaseTime(); |
| 9595 | } finally { |
| 9596 | Binder.restoreCallingIdentity(identity); |
| 9597 | } |
| 9598 | } |
| 9599 | |
| 9600 | private GbaManager getGbaManager(int subId) { |
| 9601 | GbaManager instance = GbaManager.getInstance(subId); |
| 9602 | if (instance == null) { |
| 9603 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 9604 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 9605 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 9606 | } |
| 9607 | return instance; |
| 9608 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9609 | |
| 9610 | /** |
| 9611 | * indicate whether the device and the carrier can support |
| 9612 | * RCS VoLTE single registration. |
| 9613 | */ |
| 9614 | @Override |
| 9615 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
| 9616 | enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable"); |
| 9617 | |
| 9618 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9619 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9620 | } |
| 9621 | |
| 9622 | final long identity = Binder.clearCallingIdentity(); |
| 9623 | try { |
| 9624 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 9625 | if (rpm != null) { |
| 9626 | return rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 9627 | } |
| 9628 | return false; |
| 9629 | } finally { |
| 9630 | Binder.restoreCallingIdentity(identity); |
| 9631 | } |
| 9632 | } |
| 9633 | |
| 9634 | /** |
| 9635 | * Register RCS provisioning callback. |
| 9636 | */ |
| 9637 | @Override |
| 9638 | public void registerRcsProvisioningChangedCallback(int subId, |
| 9639 | IRcsConfigCallback callback) { |
| 9640 | enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback"); |
| 9641 | |
| 9642 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9643 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9644 | } |
| 9645 | if (!isImsAvailableOnDevice()) { |
| 9646 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9647 | "IMS not available on device."); |
| 9648 | } |
| 9649 | |
| 9650 | final long identity = Binder.clearCallingIdentity(); |
| 9651 | try { |
| 9652 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 9653 | .addRcsProvisioningCallbackForSubscription(callback, subId); |
| 9654 | } catch (ImsException e) { |
| 9655 | throw new ServiceSpecificException(e.getCode()); |
| 9656 | } finally { |
| 9657 | Binder.restoreCallingIdentity(identity); |
| 9658 | } |
| 9659 | } |
| 9660 | |
| 9661 | /** |
| 9662 | * Unregister RCS provisioning callback. |
| 9663 | */ |
| 9664 | @Override |
| 9665 | public void unregisterRcsProvisioningChangedCallback(int subId, |
| 9666 | IRcsConfigCallback callback) { |
| 9667 | enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback"); |
| 9668 | |
| 9669 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9670 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9671 | } |
| 9672 | if (!isImsAvailableOnDevice()) { |
| 9673 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9674 | "IMS not available on device."); |
| 9675 | } |
| 9676 | |
| 9677 | final long identity = Binder.clearCallingIdentity(); |
| 9678 | try { |
| 9679 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 9680 | .removeRcsProvisioningCallbackForSubscription(callback, subId); |
| 9681 | } catch (ImsException e) { |
| 9682 | Log.i(LOG_TAG, "unregisterRcsProvisioningChangedCallback: " + subId |
| 9683 | + "is inactive, ignoring unregister."); |
| 9684 | } finally { |
| 9685 | Binder.restoreCallingIdentity(identity); |
| 9686 | } |
| 9687 | } |
| 9688 | |
| 9689 | /** |
| 9690 | * trigger RCS reconfiguration. |
| 9691 | */ |
| 9692 | public void triggerRcsReconfiguration(int subId) { |
| 9693 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9694 | mApp, subId, "triggerRcsReconfiguration"); |
| 9695 | |
| 9696 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9697 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9698 | } |
| 9699 | if (!isImsAvailableOnDevice()) { |
| 9700 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9701 | "IMS not available on device."); |
| 9702 | } |
| 9703 | |
| 9704 | final long identity = Binder.clearCallingIdentity(); |
| 9705 | try { |
| 9706 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 9707 | } finally { |
| 9708 | Binder.restoreCallingIdentity(identity); |
| 9709 | } |
| 9710 | } |
| 9711 | |
| 9712 | /** |
| 9713 | * Provide the client configuration parameters of the RCS application. |
| 9714 | */ |
| 9715 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
| 9716 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9717 | mApp, subId, "setRcsClientConfiguration"); |
| 9718 | |
| 9719 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9720 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9721 | } |
| 9722 | if (!isImsAvailableOnDevice()) { |
| 9723 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9724 | "IMS not available on device."); |
| 9725 | } |
| 9726 | |
| 9727 | final long identity = Binder.clearCallingIdentity(); |
| 9728 | |
| 9729 | try { |
| 9730 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 9731 | if (configBinder == null) { |
| 9732 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
| 9733 | } else { |
| 9734 | configBinder.setRcsClientConfiguration(rcc); |
| 9735 | } |
| 9736 | } catch (RemoteException e) { |
| 9737 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
| 9738 | } finally { |
| 9739 | Binder.restoreCallingIdentity(identity); |
| 9740 | } |
| 9741 | } |
| 9742 | |
| 9743 | /** |
| 9744 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 9745 | */ |
| 9746 | @Override |
| 9747 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 9748 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9749 | "setDeviceSingleRegistrationEnabledOverride"); |
| 9750 | enforceModifyPermission(); |
| 9751 | |
| 9752 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9753 | : Boolean.parseBoolean(enabledStr); |
| 9754 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
| 9755 | } |
| 9756 | |
| 9757 | /** |
| 9758 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 9759 | */ |
| 9760 | @Override |
| 9761 | public boolean getDeviceSingleRegistrationEnabled() { |
| 9762 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 9763 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 9764 | } |
| 9765 | |
| 9766 | /** |
| 9767 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9768 | */ |
| 9769 | @Override |
| 9770 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 9771 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9772 | "setCarrierSingleRegistrationEnabledOverride"); |
| 9773 | enforceModifyPermission(); |
| 9774 | |
| 9775 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9776 | : Boolean.parseBoolean(enabledStr); |
| 9777 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 9778 | subId, enabled); |
| 9779 | } |
| 9780 | |
| 9781 | /** |
| 9782 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9783 | */ |
| 9784 | @Override |
| 9785 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 9786 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 9787 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 9788 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 9789 | |
| 9790 | /** |
| 9791 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 9792 | * their mobile plan. |
| 9793 | */ |
| 9794 | @Override |
| 9795 | public String getMobileProvisioningUrl() { |
| 9796 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 9797 | final long identity = Binder.clearCallingIdentity(); |
| 9798 | try { |
| 9799 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 9800 | } finally { |
| 9801 | Binder.restoreCallingIdentity(identity); |
| 9802 | } |
| 9803 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 9804 | } |