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; |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 34 | import android.content.pm.ApplicationInfo; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 35 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 36 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 37 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 38 | import android.net.Uri; |
| 39 | import android.os.AsyncResult; |
| 40 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 41 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.os.Bundle; |
| 43 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 44 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.os.Looper; |
| 46 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 47 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 48 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 49 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 50 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 51 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 52 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 53 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 54 | import android.os.ServiceSpecificException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 55 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 56 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 57 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 58 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 59 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 60 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 61 | import android.provider.Telephony; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 62 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 63 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 64 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 65 | import android.telecom.TelecomManager; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 66 | import android.telephony.Annotation.ApnType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 67 | import android.telephony.Annotation.ThermalMitigationResult; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 68 | import android.telephony.CallForwardingInfo; |
Sooraj Sasindran | 4deb887 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 69 | import android.telephony.CarrierBandwidth; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 70 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 71 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 72 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 73 | import android.telephony.CellIdentityCdma; |
| 74 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 75 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 76 | import android.telephony.CellInfoGsm; |
| 77 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 78 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 79 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 80 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 81 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 82 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 83 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 84 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 85 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 86 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 87 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 88 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 89 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 90 | import android.telephony.RadioAccessSpecifier; |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 91 | import android.telephony.RadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 92 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 93 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 94 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 95 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 96 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 97 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 98 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 99 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 100 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 101 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 102 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 103 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 104 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 105 | import android.telephony.data.ApnSetting; |
| 106 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 107 | import android.telephony.gba.GbaAuthRequest; |
| 108 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 109 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 110 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame^] | 111 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 112 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 113 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 114 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 115 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 116 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 117 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame^] | 118 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 119 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 120 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 121 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 122 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 123 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 124 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 125 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 126 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 127 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 128 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 129 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 130 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 131 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 132 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 136 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 139 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.GbaManager; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 142 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 143 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 146 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 148 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 163 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 164 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 165 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 166 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 169 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 171 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 172 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 175 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 177 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 179 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 181 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 182 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 183 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 184 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 185 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 186 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 187 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 188 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 189 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 190 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 191 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 192 | import com.android.services.telephony.TelecomAccountRegistry; |
| 193 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 194 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 195 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 196 | import java.io.FileDescriptor; |
| 197 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 198 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 199 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 200 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 201 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 202 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 203 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 204 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 205 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 206 | import java.util.Set; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 207 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 208 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 209 | |
| 210 | /** |
| 211 | * Implementation of the ITelephony interface. |
| 212 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 213 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 214 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 215 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 216 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 217 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 218 | |
| 219 | // Message codes used with mMainThreadHandler |
| 220 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 221 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 222 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 223 | private static final int CMD_OPEN_CHANNEL = 9; |
| 224 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 225 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 226 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 227 | private static final int CMD_NV_READ_ITEM = 13; |
| 228 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 229 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 230 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 231 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 232 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 233 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 234 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 235 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 236 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 237 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 238 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 239 | private static final int CMD_SEND_ENVELOPE = 25; |
| 240 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 241 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 242 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 243 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 244 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 245 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 246 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 247 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 248 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 249 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 250 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 251 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 252 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 253 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 254 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 255 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 256 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 257 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 258 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 259 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 260 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 261 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 262 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 263 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 264 | private static final int CMD_SWITCH_SLOTS = 50; |
| 265 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 266 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 267 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 268 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 269 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 270 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 271 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 272 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 273 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 274 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 275 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 276 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 277 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 278 | private static final int CMD_MODEM_REBOOT = 64; |
| 279 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 280 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 281 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 282 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 283 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 284 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 285 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 286 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 287 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 288 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 289 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 290 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 291 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 292 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 293 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 294 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 295 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 296 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 297 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 298 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 299 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 300 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 301 | private static final int CMD_GET_CALL_WAITING = 87; |
| 302 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 303 | private static final int CMD_SET_CALL_WAITING = 89; |
| 304 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 305 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 306 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 307 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 308 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 309 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 310 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 311 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 312 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 313 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 314 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 315 | private static final int CMD_SET_SIM_POWER = 101; |
| 316 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 317 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 318 | // Parameters of select command. |
| 319 | private static final int SELECT_COMMAND = 0xA4; |
| 320 | private static final int SELECT_P1 = 0x04; |
| 321 | private static final int SELECT_P2 = 0; |
| 322 | private static final int SELECT_P3 = 0x10; |
| 323 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 324 | /** The singleton instance. */ |
| 325 | private static PhoneInterfaceManager sInstance; |
| 326 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 327 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 328 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 329 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 330 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 331 | private AppOpsManager mAppOps; |
| 332 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 333 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 334 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 335 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 336 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 337 | /** User Activity */ |
| 338 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 339 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 340 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 341 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 342 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 343 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 344 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 345 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 346 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 347 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 348 | // String to store multi SIM allowed |
| 349 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 350 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 351 | // The AID of ISD-R. |
| 352 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 353 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 354 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 355 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 356 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 357 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 358 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 359 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
| 360 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 361 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 362 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 363 | */ |
| 364 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 365 | "reset_network_erase_modem_config_enabled"; |
| 366 | |
| 367 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 368 | * A request object to use for transmitting data to an ICC. |
| 369 | */ |
| 370 | private static final class IccAPDUArgument { |
| 371 | public int channel, cla, command, p1, p2, p3; |
| 372 | public String data; |
| 373 | |
| 374 | public IccAPDUArgument(int channel, int cla, int command, |
| 375 | int p1, int p2, int p3, String data) { |
| 376 | this.channel = channel; |
| 377 | this.cla = cla; |
| 378 | this.command = command; |
| 379 | this.p1 = p1; |
| 380 | this.p2 = p2; |
| 381 | this.p3 = p3; |
| 382 | this.data = data; |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 387 | * A request object to use for transmitting data to an ICC. |
| 388 | */ |
| 389 | private static final class ManualNetworkSelectionArgument { |
| 390 | public OperatorInfo operatorInfo; |
| 391 | public boolean persistSelection; |
| 392 | |
| 393 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 394 | this.operatorInfo = operatorInfo; |
| 395 | this.persistSelection = persistSelection; |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 400 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 401 | * request after sending. The main thread will notify the request when it is complete. |
| 402 | */ |
| 403 | private static final class MainThreadRequest { |
| 404 | /** The argument to use for the request */ |
| 405 | public Object argument; |
| 406 | /** The result of the request that is run on the main thread */ |
| 407 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 408 | // The subscriber id that this request applies to. Defaults to |
| 409 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 410 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 411 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 412 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 413 | public Phone phone; |
| 414 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 415 | public WorkSource workSource; |
| 416 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 417 | public MainThreadRequest(Object argument) { |
| 418 | this.argument = argument; |
| 419 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 420 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 421 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 422 | this.argument = argument; |
| 423 | if (phone != null) { |
| 424 | this.phone = phone; |
| 425 | } |
| 426 | this.workSource = workSource; |
| 427 | } |
| 428 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 429 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 430 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 431 | if (subId != null) { |
| 432 | this.subId = subId; |
| 433 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 434 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 435 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 436 | } |
| 437 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 438 | private static final class IncomingThirdPartyCallArgs { |
| 439 | public final ComponentName component; |
| 440 | public final String callId; |
| 441 | public final String callerDisplayName; |
| 442 | |
| 443 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 444 | String callerDisplayName) { |
| 445 | this.component = component; |
| 446 | this.callId = callId; |
| 447 | this.callerDisplayName = callerDisplayName; |
| 448 | } |
| 449 | } |
| 450 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 451 | /** |
| 452 | * A handler that processes messages on the main thread in the phone process. Since many |
| 453 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 454 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 455 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 456 | * on, which will be notified when the operation completes and will contain the result of the |
| 457 | * request. |
| 458 | * |
| 459 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 460 | * note that request.result must be set to something non-null for the calling thread to |
| 461 | * unblock. |
| 462 | */ |
| 463 | private final class MainThreadHandler extends Handler { |
| 464 | @Override |
| 465 | public void handleMessage(Message msg) { |
| 466 | MainThreadRequest request; |
| 467 | Message onCompleted; |
| 468 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 469 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 470 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 471 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 472 | |
| 473 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 474 | case CMD_HANDLE_USSD_REQUEST: { |
| 475 | request = (MainThreadRequest) msg.obj; |
| 476 | final Phone phone = getPhoneFromRequest(request); |
| 477 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 478 | String ussdRequest = ussdObject.first; |
| 479 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 480 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 481 | if (!isUssdApiAllowed(request.subId)) { |
| 482 | // Carrier does not support use of this API, return failure. |
| 483 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 484 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 485 | Bundle returnData = new Bundle(); |
| 486 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 487 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 488 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 489 | request.result = true; |
| 490 | notifyRequester(request); |
| 491 | return; |
| 492 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 493 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 494 | try { |
| 495 | request.result = phone != null |
| 496 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 497 | } catch (CallStateException cse) { |
| 498 | request.result = false; |
| 499 | } |
| 500 | // Wake up the requesting thread |
| 501 | notifyRequester(request); |
| 502 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 503 | } |
| 504 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 505 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 506 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 507 | final Phone phone = getPhoneFromRequest(request); |
| 508 | request.result = phone != null ? |
| 509 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 510 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 511 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 512 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 513 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 514 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 515 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 516 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 517 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 518 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 519 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 520 | if (uiccCard == null) { |
| 521 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 522 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 523 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 524 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 525 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 526 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 527 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 528 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 529 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 530 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 531 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 532 | break; |
| 533 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 534 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 535 | ar = (AsyncResult) msg.obj; |
| 536 | request = (MainThreadRequest) ar.userObj; |
| 537 | if (ar.exception == null && ar.result != null) { |
| 538 | request.result = ar.result; |
| 539 | } else { |
| 540 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 541 | if (ar.result == null) { |
| 542 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 543 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 544 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 545 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 546 | } else { |
| 547 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 548 | } |
| 549 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 550 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 551 | break; |
| 552 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 553 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 554 | request = (MainThreadRequest) msg.obj; |
| 555 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 556 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 557 | if (uiccCard == null) { |
| 558 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 559 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 560 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 561 | } else { |
| 562 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 563 | request); |
| 564 | uiccCard.iccTransmitApduBasicChannel( |
| 565 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 566 | iccArgument.p3, iccArgument.data, onCompleted); |
| 567 | } |
| 568 | break; |
| 569 | |
| 570 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 571 | ar = (AsyncResult) msg.obj; |
| 572 | request = (MainThreadRequest) ar.userObj; |
| 573 | if (ar.exception == null && ar.result != null) { |
| 574 | request.result = ar.result; |
| 575 | } else { |
| 576 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 577 | if (ar.result == null) { |
| 578 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 579 | } else if (ar.exception instanceof CommandException) { |
| 580 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 581 | ar.exception); |
| 582 | } else { |
| 583 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 584 | } |
| 585 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 586 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 587 | break; |
| 588 | |
| 589 | case CMD_EXCHANGE_SIM_IO: |
| 590 | request = (MainThreadRequest) msg.obj; |
| 591 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 592 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 593 | if (uiccCard == null) { |
| 594 | loge("iccExchangeSimIO: No UICC"); |
| 595 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 596 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 597 | } else { |
| 598 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 599 | request); |
| 600 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 601 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 602 | iccArgument.data, onCompleted); |
| 603 | } |
| 604 | break; |
| 605 | |
| 606 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 607 | ar = (AsyncResult) msg.obj; |
| 608 | request = (MainThreadRequest) ar.userObj; |
| 609 | if (ar.exception == null && ar.result != null) { |
| 610 | request.result = ar.result; |
| 611 | } else { |
| 612 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 613 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 614 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 615 | break; |
| 616 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 617 | case CMD_SEND_ENVELOPE: |
| 618 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 619 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 620 | if (uiccCard == null) { |
| 621 | loge("sendEnvelopeWithStatus: No UICC"); |
| 622 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 623 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 624 | } else { |
| 625 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 626 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 627 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 628 | break; |
| 629 | |
| 630 | case EVENT_SEND_ENVELOPE_DONE: |
| 631 | ar = (AsyncResult) msg.obj; |
| 632 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 633 | if (ar.exception == null && ar.result != null) { |
| 634 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 635 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 636 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 637 | if (ar.result == null) { |
| 638 | loge("sendEnvelopeWithStatus: Empty response"); |
| 639 | } else if (ar.exception instanceof CommandException) { |
| 640 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 641 | ar.exception); |
| 642 | } else { |
| 643 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 644 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 645 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 646 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 647 | break; |
| 648 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 649 | case CMD_OPEN_CHANNEL: |
| 650 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 651 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 652 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 653 | if (uiccCard == null) { |
| 654 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 655 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 656 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 657 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 658 | } else { |
| 659 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 660 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 661 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 662 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 663 | break; |
| 664 | |
| 665 | case EVENT_OPEN_CHANNEL_DONE: |
| 666 | ar = (AsyncResult) msg.obj; |
| 667 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 668 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 669 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 670 | int[] result = (int[]) ar.result; |
| 671 | int channelId = result[0]; |
| 672 | byte[] selectResponse = null; |
| 673 | if (result.length > 1) { |
| 674 | selectResponse = new byte[result.length - 1]; |
| 675 | for (int i = 1; i < result.length; ++i) { |
| 676 | selectResponse[i - 1] = (byte) result[i]; |
| 677 | } |
| 678 | } |
| 679 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 680 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 681 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 682 | if (ar.result == null) { |
| 683 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 684 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 685 | if (ar.exception != null) { |
| 686 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 687 | } |
| 688 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 689 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 690 | if (ar.exception instanceof CommandException) { |
| 691 | CommandException.Error error = |
| 692 | ((CommandException) (ar.exception)).getCommandError(); |
| 693 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 694 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 695 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 696 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 697 | } |
| 698 | } |
| 699 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 700 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 701 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 702 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 703 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 704 | break; |
| 705 | |
| 706 | case CMD_CLOSE_CHANNEL: |
| 707 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 708 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 709 | if (uiccCard == null) { |
| 710 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 711 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 712 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 713 | } else { |
| 714 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 715 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 716 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 717 | break; |
| 718 | |
| 719 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 720 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 721 | break; |
| 722 | |
| 723 | case CMD_NV_READ_ITEM: |
| 724 | request = (MainThreadRequest) msg.obj; |
| 725 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 726 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 727 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 728 | break; |
| 729 | |
| 730 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 731 | ar = (AsyncResult) msg.obj; |
| 732 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 733 | if (ar.exception == null && ar.result != null) { |
| 734 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 735 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 736 | request.result = ""; |
| 737 | if (ar.result == null) { |
| 738 | loge("nvReadItem: Empty response"); |
| 739 | } else if (ar.exception instanceof CommandException) { |
| 740 | loge("nvReadItem: CommandException: " + |
| 741 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 742 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 743 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 744 | } |
| 745 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 746 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 747 | break; |
| 748 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 749 | case CMD_NV_WRITE_ITEM: |
| 750 | request = (MainThreadRequest) msg.obj; |
| 751 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 752 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 753 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 754 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 755 | break; |
| 756 | |
| 757 | case EVENT_NV_WRITE_ITEM_DONE: |
| 758 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 759 | break; |
| 760 | |
| 761 | case CMD_NV_WRITE_CDMA_PRL: |
| 762 | request = (MainThreadRequest) msg.obj; |
| 763 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 764 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 765 | break; |
| 766 | |
| 767 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 768 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 769 | break; |
| 770 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 771 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 772 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 773 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 774 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 775 | break; |
| 776 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 777 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 778 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 779 | break; |
| 780 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 781 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 782 | request = (MainThreadRequest) msg.obj; |
| 783 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 784 | request); |
| 785 | Phone phone = getPhoneFromRequest(request); |
| 786 | if (phone != null) { |
| 787 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 788 | } else { |
| 789 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 790 | request.result = false; |
| 791 | notifyRequester(request); |
| 792 | } |
| 793 | break; |
| 794 | } |
| 795 | |
| 796 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 797 | ar = (AsyncResult) msg.obj; |
| 798 | request = (MainThreadRequest) ar.userObj; |
| 799 | if (ar.exception == null && ar.result != null) { |
| 800 | request.result = ar.result; |
| 801 | } else { |
| 802 | // request.result must be set to something non-null |
| 803 | // for the calling thread to unblock |
| 804 | if (request.result != null) { |
| 805 | request.result = ar.result; |
| 806 | } else { |
| 807 | request.result = false; |
| 808 | } |
| 809 | if (ar.result == null) { |
| 810 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 811 | } else if (ar.exception instanceof CommandException) { |
| 812 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 813 | + ar.exception); |
| 814 | } else { |
| 815 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 816 | } |
| 817 | } |
| 818 | notifyRequester(request); |
| 819 | break; |
| 820 | |
| 821 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 822 | request = (MainThreadRequest) msg.obj; |
| 823 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 824 | Phone phone = getPhoneFromRequest(request); |
| 825 | if (phone != null) { |
| 826 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 827 | request.workSource); |
| 828 | } else { |
| 829 | loge("enableNrDualConnectivity: No phone object"); |
| 830 | request.result = |
| 831 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 832 | notifyRequester(request); |
| 833 | } |
| 834 | break; |
| 835 | } |
| 836 | |
| 837 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 838 | ar = (AsyncResult) msg.obj; |
| 839 | request = (MainThreadRequest) ar.userObj; |
| 840 | if (ar.exception == null) { |
| 841 | request.result = |
| 842 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 843 | } else { |
| 844 | request.result = |
| 845 | TelephonyManager |
| 846 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 847 | if (ar.exception instanceof CommandException) { |
| 848 | CommandException.Error error = |
| 849 | ((CommandException) (ar.exception)).getCommandError(); |
| 850 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 851 | request.result = |
| 852 | TelephonyManager |
| 853 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 854 | } |
| 855 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 856 | + ar.exception); |
| 857 | } else { |
| 858 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 859 | } |
| 860 | } |
| 861 | notifyRequester(request); |
| 862 | break; |
| 863 | } |
| 864 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 865 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 866 | request = (MainThreadRequest) msg.obj; |
| 867 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 868 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 869 | break; |
| 870 | |
| 871 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 872 | ar = (AsyncResult) msg.obj; |
| 873 | request = (MainThreadRequest) ar.userObj; |
| 874 | if (ar.exception == null && ar.result != null) { |
| 875 | request.result = ar.result; // Integer |
| 876 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 877 | // request.result must be set to something non-null |
| 878 | // for the calling thread to unblock |
| 879 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 880 | if (ar.result == null) { |
| 881 | loge("getPreferredNetworkType: Empty response"); |
| 882 | } else if (ar.exception instanceof CommandException) { |
| 883 | loge("getPreferredNetworkType: CommandException: " + |
| 884 | ar.exception); |
| 885 | } else { |
| 886 | loge("getPreferredNetworkType: Unknown exception"); |
| 887 | } |
| 888 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 889 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 890 | break; |
| 891 | |
| 892 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 893 | request = (MainThreadRequest) msg.obj; |
| 894 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 895 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 896 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 897 | break; |
| 898 | |
| 899 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 900 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 901 | break; |
| 902 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 903 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 904 | request = (MainThreadRequest)msg.obj; |
| 905 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 906 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 907 | break; |
| 908 | |
| 909 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 910 | ar = (AsyncResult)msg.obj; |
| 911 | request = (MainThreadRequest)ar.userObj; |
| 912 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 913 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 914 | break; |
| 915 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 916 | case CMD_SET_VOICEMAIL_NUMBER: |
| 917 | request = (MainThreadRequest) msg.obj; |
| 918 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 919 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 920 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 921 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 922 | break; |
| 923 | |
| 924 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 925 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 926 | break; |
| 927 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 928 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 929 | request = (MainThreadRequest) msg.obj; |
| 930 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 931 | request); |
| 932 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 933 | break; |
| 934 | |
| 935 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 936 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 937 | break; |
| 938 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 939 | case CMD_PERFORM_NETWORK_SCAN: |
| 940 | request = (MainThreadRequest) msg.obj; |
| 941 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 942 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 943 | break; |
| 944 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 945 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 946 | request = (MainThreadRequest) msg.obj; |
| 947 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 948 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 949 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 950 | request.argument; |
| 951 | int callForwardingReason = args.first; |
| 952 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 953 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 954 | } |
| 955 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 956 | ar = (AsyncResult) msg.obj; |
| 957 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 958 | TelephonyManager.CallForwardingInfoCallback callback = |
| 959 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 960 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 961 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 962 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 963 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 964 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 965 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 966 | // any service for voice call. |
| 967 | if ((callForwardInfo.serviceClass |
| 968 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 969 | callForwardingInfo = new CallForwardingInfo(true, |
| 970 | callForwardInfo.reason, |
| 971 | callForwardInfo.number, |
| 972 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 973 | break; |
| 974 | } |
| 975 | } |
| 976 | // Didn't find a call forward info for voice call. |
| 977 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 978 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 979 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 980 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 981 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 982 | } else { |
| 983 | if (ar.result == null) { |
| 984 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 985 | } |
| 986 | if (ar.exception != null) { |
| 987 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 988 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 989 | int errorCode = TelephonyManager |
| 990 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 991 | if (ar.exception instanceof CommandException) { |
| 992 | CommandException.Error error = |
| 993 | ((CommandException) (ar.exception)).getCommandError(); |
| 994 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 995 | errorCode = TelephonyManager |
| 996 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 997 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 998 | errorCode = TelephonyManager |
| 999 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1000 | } |
| 1001 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1002 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1003 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1004 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1005 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1006 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1007 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1008 | request = (MainThreadRequest) msg.obj; |
| 1009 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1010 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1011 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1012 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1013 | request.argument).first; |
| 1014 | request.phone.setCallForwardingOption( |
| 1015 | callForwardingInfoToSet.isEnabled() |
| 1016 | ? CommandsInterface.CF_ACTION_ENABLE |
| 1017 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1018 | callForwardingInfoToSet.getReason(), |
| 1019 | callForwardingInfoToSet.getNumber(), |
| 1020 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1021 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1022 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1023 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1024 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1025 | ar = (AsyncResult) msg.obj; |
| 1026 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1027 | Consumer<Integer> callback = |
| 1028 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1029 | request.argument).second; |
| 1030 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1031 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1032 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1033 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1034 | if (ar.exception instanceof CommandException) { |
| 1035 | CommandException.Error error = |
| 1036 | ((CommandException) (ar.exception)).getCommandError(); |
| 1037 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1038 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1039 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1040 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1041 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1042 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1043 | } |
| 1044 | } |
| 1045 | callback.accept(errorCode); |
| 1046 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1047 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1048 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1049 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1050 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1051 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1052 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1053 | request = (MainThreadRequest) msg.obj; |
| 1054 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1055 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1056 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1057 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1058 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1059 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1060 | ar = (AsyncResult) msg.obj; |
| 1061 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1062 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1063 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1064 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1065 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1066 | // Service Class is a bit mask per 3gpp 27.007. |
| 1067 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1068 | if (callForwardResults.length > 1 |
| 1069 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1070 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1071 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1072 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1073 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1074 | } else { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1075 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1076 | } |
| 1077 | } else { |
| 1078 | if (ar.result == null) { |
| 1079 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1080 | } |
| 1081 | if (ar.exception != null) { |
| 1082 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1083 | } |
| 1084 | if (ar.exception instanceof CommandException) { |
| 1085 | CommandException.Error error = |
| 1086 | ((CommandException) (ar.exception)).getCommandError(); |
| 1087 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1088 | callForwardingStatus = |
| 1089 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1090 | } |
| 1091 | } |
| 1092 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1093 | callback.accept(callForwardingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1094 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1095 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1096 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1097 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1098 | request = (MainThreadRequest) msg.obj; |
| 1099 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1100 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1101 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1102 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1103 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1104 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1105 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1106 | ar = (AsyncResult) msg.obj; |
| 1107 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1108 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1109 | Consumer<Integer> callback = |
| 1110 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1111 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1112 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1113 | if (ar.exception instanceof CommandException) { |
| 1114 | CommandException.Error error = |
| 1115 | ((CommandException) (ar.exception)).getCommandError(); |
| 1116 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1117 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1118 | } else { |
| 1119 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1120 | } |
| 1121 | } else { |
| 1122 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1123 | } |
| 1124 | } else { |
| 1125 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1126 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1127 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1128 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1129 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1130 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1131 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1132 | ar = (AsyncResult) msg.obj; |
| 1133 | request = (MainThreadRequest) ar.userObj; |
| 1134 | CellNetworkScanResult cellScanResult; |
| 1135 | if (ar.exception == null && ar.result != null) { |
| 1136 | cellScanResult = new CellNetworkScanResult( |
| 1137 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1138 | (List<OperatorInfo>) ar.result); |
| 1139 | } else { |
| 1140 | if (ar.result == null) { |
| 1141 | loge("getCellNetworkScanResults: Empty response"); |
| 1142 | } |
| 1143 | if (ar.exception != null) { |
| 1144 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1145 | } |
| 1146 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1147 | if (ar.exception instanceof CommandException) { |
| 1148 | CommandException.Error error = |
| 1149 | ((CommandException) (ar.exception)).getCommandError(); |
| 1150 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1151 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1152 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1153 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1154 | } |
| 1155 | } |
| 1156 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1157 | } |
| 1158 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1159 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1160 | break; |
| 1161 | |
| 1162 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1163 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1164 | ManualNetworkSelectionArgument selArg = |
| 1165 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1166 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1167 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1168 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1169 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1170 | break; |
| 1171 | |
| 1172 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1173 | ar = (AsyncResult) msg.obj; |
| 1174 | request = (MainThreadRequest) ar.userObj; |
| 1175 | if (ar.exception == null) { |
| 1176 | request.result = true; |
| 1177 | } else { |
| 1178 | request.result = false; |
| 1179 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1180 | } |
| 1181 | notifyRequester(request); |
| 1182 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1183 | break; |
| 1184 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1185 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1186 | request = (MainThreadRequest) msg.obj; |
| 1187 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1188 | if (defaultPhone != null) { |
| 1189 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1190 | } else { |
| 1191 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1192 | Bundle bundle = new Bundle(); |
| 1193 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1194 | new ModemActivityInfo(0, 0, 0, |
| 1195 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1196 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1197 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1198 | break; |
| 1199 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1200 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1201 | ar = (AsyncResult) msg.obj; |
| 1202 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1203 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1204 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1205 | ModemActivityInfo ret = null; |
| 1206 | int error = 0; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1207 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1208 | // Update the last modem activity info and the result of the request. |
| 1209 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1210 | if (isModemActivityInfoValid(info)) { |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1211 | int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()]; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1212 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1213 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1214 | .getTransmitTimeMillis(); |
| 1215 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1216 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1217 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1218 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1219 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1220 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1221 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1222 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1223 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1224 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1225 | info.getReceiveTimeMillis() |
| 1226 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1227 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1228 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(), |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1229 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1230 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1231 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1232 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1233 | } else { |
| 1234 | if (ar.result == null) { |
| 1235 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1236 | error = TelephonyManager.ModemActivityInfoException |
| 1237 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1238 | } else if (ar.exception instanceof CommandException) { |
| 1239 | loge("queryModemActivityInfo: CommandException: " + |
| 1240 | ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1241 | error = TelephonyManager.ModemActivityInfoException |
| 1242 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1243 | } else { |
| 1244 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1245 | error = TelephonyManager.ModemActivityInfoException |
| 1246 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1247 | } |
| 1248 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1249 | Bundle bundle = new Bundle(); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1250 | if (ret != null) { |
| 1251 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1252 | } else { |
| 1253 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1254 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1255 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1256 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1257 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1258 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1259 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1260 | case CMD_SET_ALLOWED_CARRIERS: |
| 1261 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1262 | CarrierRestrictionRules argument = |
| 1263 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1264 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1265 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1266 | break; |
| 1267 | |
| 1268 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1269 | ar = (AsyncResult) msg.obj; |
| 1270 | request = (MainThreadRequest) ar.userObj; |
| 1271 | if (ar.exception == null && ar.result != null) { |
| 1272 | request.result = ar.result; |
| 1273 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1274 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1275 | if (ar.exception instanceof CommandException) { |
| 1276 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1277 | CommandException.Error error = |
| 1278 | ((CommandException) (ar.exception)).getCommandError(); |
| 1279 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1280 | request.result = |
| 1281 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1282 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1283 | } else { |
| 1284 | loge("setAllowedCarriers: Unknown exception"); |
| 1285 | } |
| 1286 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1287 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1288 | break; |
| 1289 | |
| 1290 | case CMD_GET_ALLOWED_CARRIERS: |
| 1291 | request = (MainThreadRequest) msg.obj; |
| 1292 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1293 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1294 | break; |
| 1295 | |
| 1296 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1297 | ar = (AsyncResult) msg.obj; |
| 1298 | request = (MainThreadRequest) ar.userObj; |
| 1299 | if (ar.exception == null && ar.result != null) { |
| 1300 | request.result = ar.result; |
| 1301 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1302 | request.result = new IllegalStateException( |
| 1303 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1304 | if (ar.result == null) { |
| 1305 | loge("getAllowedCarriers: Empty response"); |
| 1306 | } else if (ar.exception instanceof CommandException) { |
| 1307 | loge("getAllowedCarriers: CommandException: " + |
| 1308 | ar.exception); |
| 1309 | } else { |
| 1310 | loge("getAllowedCarriers: Unknown exception"); |
| 1311 | } |
| 1312 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1313 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1314 | break; |
| 1315 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1316 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1317 | ar = (AsyncResult) msg.obj; |
| 1318 | request = (MainThreadRequest) ar.userObj; |
| 1319 | if (ar.exception == null && ar.result != null) { |
| 1320 | request.result = ar.result; |
| 1321 | } else { |
| 1322 | request.result = new IllegalArgumentException( |
| 1323 | "Failed to retrieve Forbidden Plmns"); |
| 1324 | if (ar.result == null) { |
| 1325 | loge("getForbiddenPlmns: Empty response"); |
| 1326 | } else { |
| 1327 | loge("getForbiddenPlmns: Unknown exception"); |
| 1328 | } |
| 1329 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1330 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1331 | break; |
| 1332 | |
| 1333 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1334 | request = (MainThreadRequest) msg.obj; |
| 1335 | uiccCard = getUiccCardFromRequest(request); |
| 1336 | if (uiccCard == null) { |
| 1337 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1338 | request.result = new IllegalArgumentException( |
| 1339 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1340 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1341 | break; |
| 1342 | } |
| 1343 | Integer appType = (Integer) request.argument; |
| 1344 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1345 | if (uiccApp == null) { |
| 1346 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1347 | + appType); |
| 1348 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1349 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1350 | break; |
| 1351 | } else { |
| 1352 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1353 | + " specified type -- " + appType); |
| 1354 | } |
| 1355 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1356 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1357 | onCompleted); |
| 1358 | break; |
| 1359 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1360 | case CMD_SWITCH_SLOTS: |
| 1361 | request = (MainThreadRequest) msg.obj; |
| 1362 | int[] physicalSlots = (int[]) request.argument; |
| 1363 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1364 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1365 | break; |
| 1366 | |
| 1367 | case EVENT_SWITCH_SLOTS_DONE: |
| 1368 | ar = (AsyncResult) msg.obj; |
| 1369 | request = (MainThreadRequest) ar.userObj; |
| 1370 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1371 | notifyRequester(request); |
| 1372 | break; |
| 1373 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1374 | request = (MainThreadRequest) msg.obj; |
| 1375 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1376 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1377 | break; |
| 1378 | |
| 1379 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1380 | ar = (AsyncResult) msg.obj; |
| 1381 | request = (MainThreadRequest) ar.userObj; |
| 1382 | if (ar.exception != null) { |
| 1383 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1384 | } else { |
| 1385 | int mode = ((int[]) ar.result)[0]; |
| 1386 | if (mode == 0) { |
| 1387 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1388 | } else { |
| 1389 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1390 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1391 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1392 | notifyRequester(request); |
| 1393 | break; |
| 1394 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1395 | request = (MainThreadRequest) msg.obj; |
| 1396 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1397 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1398 | break; |
| 1399 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1400 | ar = (AsyncResult) msg.obj; |
| 1401 | request = (MainThreadRequest) ar.userObj; |
| 1402 | if (ar.exception != null) { |
| 1403 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1404 | } else { |
| 1405 | request.result = ((int[]) ar.result)[0]; |
| 1406 | } |
| 1407 | notifyRequester(request); |
| 1408 | break; |
| 1409 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1410 | request = (MainThreadRequest) msg.obj; |
| 1411 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1412 | int mode = (int) request.argument; |
| 1413 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1414 | break; |
| 1415 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1416 | ar = (AsyncResult) msg.obj; |
| 1417 | request = (MainThreadRequest) ar.userObj; |
| 1418 | request.result = ar.exception == null; |
| 1419 | notifyRequester(request); |
| 1420 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1421 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1422 | request = (MainThreadRequest) msg.obj; |
| 1423 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1424 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1425 | break; |
| 1426 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1427 | ar = (AsyncResult) msg.obj; |
| 1428 | request = (MainThreadRequest) ar.userObj; |
| 1429 | if (ar.exception != null) { |
| 1430 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1431 | } else { |
| 1432 | request.result = ((int[]) ar.result)[0]; |
| 1433 | } |
| 1434 | notifyRequester(request); |
| 1435 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1436 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1437 | request = (MainThreadRequest) msg.obj; |
| 1438 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1439 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1440 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1441 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1442 | break; |
| 1443 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1444 | ar = (AsyncResult) msg.obj; |
| 1445 | request = (MainThreadRequest) ar.userObj; |
| 1446 | request.result = ar.exception == null; |
| 1447 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1448 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1449 | case CMD_GET_ALL_CELL_INFO: |
| 1450 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1451 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1452 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1453 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1454 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1455 | ar = (AsyncResult) msg.obj; |
| 1456 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1457 | // If a timeout occurs, the response will be null |
| 1458 | request.result = (ar.exception == null && ar.result != null) |
| 1459 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1460 | synchronized (request) { |
| 1461 | request.notifyAll(); |
| 1462 | } |
| 1463 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1464 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1465 | request = (MainThreadRequest) msg.obj; |
| 1466 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1467 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1468 | break; |
| 1469 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1470 | ar = (AsyncResult) msg.obj; |
| 1471 | request = (MainThreadRequest) ar.userObj; |
| 1472 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1473 | try { |
| 1474 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1475 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1476 | cb.onError( |
| 1477 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1478 | ar.exception.getClass().getName(), |
| 1479 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1480 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1481 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1482 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1483 | } else { |
| 1484 | // use the result as returned |
| 1485 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1486 | } |
| 1487 | } catch (RemoteException re) { |
| 1488 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1489 | } |
| 1490 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1491 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1492 | request = (MainThreadRequest) msg.obj; |
| 1493 | WorkSource ws = (WorkSource) request.argument; |
| 1494 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1495 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1496 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1497 | } |
| 1498 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1499 | ar = (AsyncResult) msg.obj; |
| 1500 | request = (MainThreadRequest) ar.userObj; |
| 1501 | if (ar.exception == null) { |
| 1502 | request.result = ar.result; |
| 1503 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1504 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1505 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1506 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1507 | } |
| 1508 | |
| 1509 | synchronized (request) { |
| 1510 | request.notifyAll(); |
| 1511 | } |
| 1512 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1513 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1514 | case CMD_MODEM_REBOOT: |
| 1515 | request = (MainThreadRequest) msg.obj; |
| 1516 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1517 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1518 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1519 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1520 | handleNullReturnEvent(msg, "rebootModem"); |
| 1521 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1522 | case CMD_REQUEST_ENABLE_MODEM: |
| 1523 | request = (MainThreadRequest) msg.obj; |
| 1524 | boolean enable = (boolean) request.argument; |
| 1525 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1526 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1527 | PhoneConfigurationManager.getInstance() |
| 1528 | .enablePhone(request.phone, enable, onCompleted); |
| 1529 | break; |
| 1530 | case EVENT_ENABLE_MODEM_DONE: |
| 1531 | ar = (AsyncResult) msg.obj; |
| 1532 | request = (MainThreadRequest) ar.userObj; |
| 1533 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1534 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1535 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1536 | if ((boolean) request.result) { |
| 1537 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1538 | updateModemStateMetrics(); |
| 1539 | } else { |
| 1540 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1541 | + ar.exception); |
| 1542 | } |
| 1543 | notifyRequester(request); |
| 1544 | break; |
| 1545 | case CMD_GET_MODEM_STATUS: |
| 1546 | request = (MainThreadRequest) msg.obj; |
| 1547 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1548 | PhoneConfigurationManager.getInstance() |
| 1549 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1550 | break; |
| 1551 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1552 | ar = (AsyncResult) msg.obj; |
| 1553 | request = (MainThreadRequest) ar.userObj; |
| 1554 | int id = request.phone.getPhoneId(); |
| 1555 | if (ar.exception == null && ar.result != null) { |
| 1556 | request.result = ar.result; |
| 1557 | //update the cache as modem status has changed |
| 1558 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1559 | (boolean) request.result); |
| 1560 | } else { |
| 1561 | // Return true if modem status cannot be retrieved. For most cases, |
| 1562 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1563 | // and disable modem are not supported. Modem is always on. |
| 1564 | // TODO: this should be fixed in R to support a third |
| 1565 | // status UNKNOWN b/131631629 |
| 1566 | request.result = true; |
| 1567 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1568 | + ar.exception); |
| 1569 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1570 | notifyRequester(request); |
| 1571 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1572 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1573 | request = (MainThreadRequest) msg.obj; |
| 1574 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1575 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1576 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1577 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1578 | break; |
| 1579 | } |
| 1580 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1581 | ar = (AsyncResult) msg.obj; |
| 1582 | request = (MainThreadRequest) ar.userObj; |
| 1583 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1584 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1585 | args.second.accept(ar.exception == null); |
| 1586 | notifyRequester(request); |
| 1587 | break; |
| 1588 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1589 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1590 | request = (MainThreadRequest) msg.obj; |
| 1591 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1592 | Phone phone = getPhoneFromRequest(request); |
| 1593 | if (phone != null) { |
| 1594 | phone.getSystemSelectionChannels(onCompleted); |
| 1595 | } else { |
| 1596 | loge("getSystemSelectionChannels: No phone object"); |
| 1597 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1598 | notifyRequester(request); |
| 1599 | } |
| 1600 | break; |
| 1601 | } |
| 1602 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1603 | ar = (AsyncResult) msg.obj; |
| 1604 | request = (MainThreadRequest) ar.userObj; |
| 1605 | if (ar.exception == null && ar.result != null) { |
| 1606 | request.result = ar.result; |
| 1607 | } else { |
| 1608 | request.result = new IllegalArgumentException( |
| 1609 | "Failed to retrieve system selection channels"); |
| 1610 | if (ar.result == null) { |
| 1611 | loge("getSystemSelectionChannels: Empty response"); |
| 1612 | } else { |
| 1613 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1614 | } |
| 1615 | } |
| 1616 | notifyRequester(request); |
| 1617 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1618 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1619 | ar = (AsyncResult) msg.obj; |
| 1620 | request = (MainThreadRequest) ar.userObj; |
| 1621 | if (ar.exception == null && ar.result != null) { |
| 1622 | request.result = ar.result; |
| 1623 | } else { |
| 1624 | request.result = -1; |
| 1625 | loge("Failed to set Forbidden Plmns"); |
| 1626 | if (ar.result == null) { |
| 1627 | loge("setForbidenPlmns: Empty response"); |
| 1628 | } else if (ar.exception != null) { |
| 1629 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1630 | request.result = -1; |
| 1631 | } else { |
| 1632 | loge("setForbiddenPlmns: Unknown exception"); |
| 1633 | } |
| 1634 | } |
| 1635 | notifyRequester(request); |
| 1636 | break; |
| 1637 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1638 | request = (MainThreadRequest) msg.obj; |
| 1639 | uiccCard = getUiccCardFromRequest(request); |
| 1640 | if (uiccCard == null) { |
| 1641 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1642 | request.result = -1; |
| 1643 | notifyRequester(request); |
| 1644 | break; |
| 1645 | } |
| 1646 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1647 | (Pair<Integer, List<String>>) request.argument; |
| 1648 | appType = setFplmnsArgs.first; |
| 1649 | List<String> fplmns = setFplmnsArgs.second; |
| 1650 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1651 | if (uiccApp == null) { |
| 1652 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1653 | request.result = -1; |
| 1654 | loge("Failed to get UICC App"); |
| 1655 | notifyRequester(request); |
| 1656 | } else { |
| 1657 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1658 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1659 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1660 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1661 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1662 | case CMD_ERASE_MODEM_CONFIG: |
| 1663 | request = (MainThreadRequest) msg.obj; |
| 1664 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1665 | defaultPhone.eraseModemConfig(onCompleted); |
| 1666 | break; |
| 1667 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1668 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1669 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1670 | |
| 1671 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1672 | request = (MainThreadRequest) msg.obj; |
| 1673 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1674 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1675 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1676 | changed.first, changed.second, onCompleted); |
| 1677 | break; |
| 1678 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1679 | ar = (AsyncResult) msg.obj; |
| 1680 | request = (MainThreadRequest) ar.userObj; |
| 1681 | if (ar.exception == null) { |
| 1682 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1683 | } else { |
| 1684 | request.result = msg.arg1; |
| 1685 | } |
| 1686 | notifyRequester(request); |
| 1687 | break; |
| 1688 | |
| 1689 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1690 | request = (MainThreadRequest) msg.obj; |
| 1691 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1692 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1693 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1694 | enabled.first, enabled.second, onCompleted); |
| 1695 | break; |
| 1696 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1697 | ar = (AsyncResult) msg.obj; |
| 1698 | request = (MainThreadRequest) ar.userObj; |
| 1699 | if (ar.exception == null) { |
| 1700 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1701 | } else { |
| 1702 | request.result = msg.arg1; |
| 1703 | } |
| 1704 | notifyRequester(request); |
| 1705 | break; |
| 1706 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1707 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1708 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1709 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1710 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1711 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1712 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1713 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1714 | |
| 1715 | case CMD_SET_DATA_THROTTLING: { |
| 1716 | request = (MainThreadRequest) msg.obj; |
| 1717 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1718 | DataThrottlingRequest dataThrottlingRequest = |
| 1719 | (DataThrottlingRequest) request.argument; |
| 1720 | Phone phone = getPhoneFromRequest(request); |
| 1721 | if (phone != null) { |
| 1722 | phone.setDataThrottling(onCompleted, |
| 1723 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1724 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1725 | } else { |
| 1726 | loge("setDataThrottling: No phone object"); |
| 1727 | request.result = |
| 1728 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1729 | notifyRequester(request); |
| 1730 | } |
| 1731 | |
| 1732 | break; |
| 1733 | } |
| 1734 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1735 | ar = (AsyncResult) msg.obj; |
| 1736 | request = (MainThreadRequest) ar.userObj; |
| 1737 | |
| 1738 | if (ar.exception == null) { |
| 1739 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1740 | } else if (ar.exception instanceof CommandException) { |
| 1741 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1742 | CommandException.Error error = |
| 1743 | ((CommandException) (ar.exception)).getCommandError(); |
| 1744 | |
| 1745 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1746 | request.result = TelephonyManager |
| 1747 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1748 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1749 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
| 1750 | } else { |
| 1751 | request.result = |
| 1752 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1753 | } |
| 1754 | } else { |
| 1755 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1756 | } |
| 1757 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1758 | notifyRequester(request); |
| 1759 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1760 | |
| 1761 | case CMD_SET_SIM_POWER: { |
| 1762 | request = (MainThreadRequest) msg.obj; |
| 1763 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1764 | request = (MainThreadRequest) msg.obj; |
| 1765 | int stateToSet = |
| 1766 | ((Pair<Integer, IIntegerConsumer>) |
| 1767 | request.argument).first; |
| 1768 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1769 | break; |
| 1770 | } |
| 1771 | case EVENT_SET_SIM_POWER_DONE: { |
| 1772 | ar = (AsyncResult) msg.obj; |
| 1773 | request = (MainThreadRequest) ar.userObj; |
| 1774 | IIntegerConsumer callback = |
| 1775 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1776 | if (ar.exception != null) { |
| 1777 | loge("setSimPower exception: " + ar.exception); |
| 1778 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1779 | .RESULT_ERROR_UNKNOWN; |
| 1780 | if (ar.exception instanceof CommandException) { |
| 1781 | CommandException.Error error = |
| 1782 | ((CommandException) (ar.exception)).getCommandError(); |
| 1783 | if (error == CommandException.Error.SIM_ERR) { |
| 1784 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1785 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1786 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1787 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1788 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1789 | } else { |
| 1790 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1791 | } |
| 1792 | } |
| 1793 | try { |
| 1794 | callback.accept(errorCode); |
| 1795 | } catch (RemoteException e) { |
| 1796 | // Ignore if the remote process is no longer available to call back. |
| 1797 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1798 | } |
| 1799 | } else { |
| 1800 | try { |
| 1801 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1802 | } catch (RemoteException e) { |
| 1803 | // Ignore if the remote process is no longer available to call back. |
| 1804 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1805 | } |
| 1806 | } |
| 1807 | break; |
| 1808 | } |
| 1809 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1810 | default: |
| 1811 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1812 | break; |
| 1813 | } |
| 1814 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1815 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1816 | private void notifyRequester(MainThreadRequest request) { |
| 1817 | synchronized (request) { |
| 1818 | request.notifyAll(); |
| 1819 | } |
| 1820 | } |
| 1821 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1822 | private void handleNullReturnEvent(Message msg, String command) { |
| 1823 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1824 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1825 | if (ar.exception == null) { |
| 1826 | request.result = true; |
| 1827 | } else { |
| 1828 | request.result = false; |
| 1829 | if (ar.exception instanceof CommandException) { |
| 1830 | loge(command + ": CommandException: " + ar.exception); |
| 1831 | } else { |
| 1832 | loge(command + ": Unknown exception"); |
| 1833 | } |
| 1834 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1835 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1836 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1837 | } |
| 1838 | |
| 1839 | /** |
| 1840 | * Posts the specified command to be executed on the main thread, |
| 1841 | * waits for the request to complete, and returns the result. |
| 1842 | * @see #sendRequestAsync |
| 1843 | */ |
| 1844 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1845 | return sendRequest( |
| 1846 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1847 | } |
| 1848 | |
| 1849 | /** |
| 1850 | * Posts the specified command to be executed on the main thread, |
| 1851 | * waits for the request to complete, and returns the result. |
| 1852 | * @see #sendRequestAsync |
| 1853 | */ |
| 1854 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1855 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1856 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1857 | } |
| 1858 | |
| 1859 | /** |
| 1860 | * Posts the specified command to be executed on the main thread, |
| 1861 | * waits for the request to complete, and returns the result. |
| 1862 | * @see #sendRequestAsync |
| 1863 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1864 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1865 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1866 | } |
| 1867 | |
| 1868 | /** |
| 1869 | * Posts the specified command to be executed on the main thread, |
| 1870 | * waits for the request to complete, and returns the result. |
| 1871 | * @see #sendRequestAsync |
| 1872 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1873 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1874 | return sendRequest(command, argument, subId, null, workSource); |
| 1875 | } |
| 1876 | |
| 1877 | /** |
| 1878 | * Posts the specified command to be executed on the main thread, |
| 1879 | * waits for the request to complete, and returns the result. |
| 1880 | * @see #sendRequestAsync |
| 1881 | */ |
| 1882 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1883 | return sendRequest( |
| 1884 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1885 | } |
| 1886 | |
| 1887 | /** |
| 1888 | * Posts the specified command to be executed on the main thread, |
| 1889 | * waits for the request to complete, and returns the result. |
| 1890 | * @see #sendRequestAsync |
| 1891 | */ |
| 1892 | private Object sendRequest( |
| 1893 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1894 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1895 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1896 | } |
| 1897 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1898 | MainThreadRequest request = null; |
| 1899 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1900 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1901 | } else if (phone != null) { |
| 1902 | request = new MainThreadRequest(argument, phone, workSource); |
| 1903 | } else { |
| 1904 | request = new MainThreadRequest(argument, subId, workSource); |
| 1905 | } |
| 1906 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1907 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1908 | msg.sendToTarget(); |
| 1909 | |
| 1910 | // Wait for the request to complete |
| 1911 | synchronized (request) { |
| 1912 | while (request.result == null) { |
| 1913 | try { |
| 1914 | request.wait(); |
| 1915 | } catch (InterruptedException e) { |
| 1916 | // Do nothing, go back and wait until the request is complete |
| 1917 | } |
| 1918 | } |
| 1919 | } |
| 1920 | return request.result; |
| 1921 | } |
| 1922 | |
| 1923 | /** |
| 1924 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1925 | * Posts the specified command to be executed on the main thread, and |
| 1926 | * returns immediately. |
| 1927 | * @see #sendRequest |
| 1928 | */ |
| 1929 | private void sendRequestAsync(int command) { |
| 1930 | mMainThreadHandler.sendEmptyMessage(command); |
| 1931 | } |
| 1932 | |
| 1933 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1934 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1935 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1936 | */ |
| 1937 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1938 | sendRequestAsync(command, argument, null, null); |
| 1939 | } |
| 1940 | |
| 1941 | /** |
| 1942 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1943 | * @see {@link #sendRequest(int,Object)} |
| 1944 | */ |
| 1945 | private void sendRequestAsync( |
| 1946 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1947 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1948 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1949 | msg.sendToTarget(); |
| 1950 | } |
| 1951 | |
| 1952 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1953 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1954 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1955 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1956 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1957 | synchronized (PhoneInterfaceManager.class) { |
| 1958 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1959 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1960 | } else { |
| 1961 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1962 | } |
| 1963 | return sInstance; |
| 1964 | } |
| 1965 | } |
| 1966 | |
| 1967 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 1968 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1969 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1970 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1971 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1972 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1973 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1974 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1975 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1976 | mTelephonySharedPreferences = |
| 1977 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1978 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1979 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 1980 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1981 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1982 | publish(); |
| 1983 | } |
| 1984 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1985 | private Phone getDefaultPhone() { |
| 1986 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1987 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1988 | } |
| 1989 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1990 | private void publish() { |
| 1991 | if (DBG) log("publish: " + this); |
| 1992 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 1993 | TelephonyFrameworkInitializer |
| 1994 | .getTelephonyServiceManager() |
| 1995 | .getTelephonyServiceRegisterer() |
| 1996 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1997 | } |
| 1998 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1999 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2000 | if (request.phone != null) { |
| 2001 | return request.phone; |
| 2002 | } else { |
| 2003 | return getPhoneFromSubId(request.subId); |
| 2004 | } |
| 2005 | } |
| 2006 | |
| 2007 | private Phone getPhoneFromSubId(int subId) { |
| 2008 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2009 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2010 | } |
| 2011 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2012 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 2013 | Phone phone = getPhoneFromRequest(request); |
| 2014 | return phone == null ? null : |
| 2015 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 2016 | } |
| 2017 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2018 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2019 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2020 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2021 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2022 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2023 | private void sendEraseModemConfig(Phone phone) { |
| 2024 | if (phone != null) { |
| 2025 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2026 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 2027 | final long identity = Binder.clearCallingIdentity(); |
| 2028 | try { |
| 2029 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2030 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2031 | } finally { |
| 2032 | Binder.restoreCallingIdentity(identity); |
| 2033 | } |
| 2034 | } |
| 2035 | } |
| 2036 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2037 | private boolean isImsAvailableOnDevice() { |
| 2038 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2039 | if (pm == null) { |
| 2040 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2041 | // so do not throw error and allow. |
| 2042 | return true; |
| 2043 | } |
| 2044 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2045 | } |
| 2046 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2047 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2048 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2049 | } |
| 2050 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2051 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2052 | if (DBG) log("dial: " + number); |
| 2053 | // No permission check needed here: This is just a wrapper around the |
| 2054 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2055 | // the UI before it does anything. |
| 2056 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2057 | final long identity = Binder.clearCallingIdentity(); |
| 2058 | try { |
| 2059 | String url = createTelUrl(number); |
| 2060 | if (url == null) { |
| 2061 | return; |
| 2062 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2063 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2064 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2065 | PhoneConstants.State state = mCM.getState(subId); |
| 2066 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2067 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2068 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2069 | mApp.startActivity(intent); |
| 2070 | } |
| 2071 | } finally { |
| 2072 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2073 | } |
| 2074 | } |
| 2075 | |
| 2076 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2077 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2078 | } |
| 2079 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2080 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2081 | if (DBG) log("call: " + number); |
| 2082 | |
| 2083 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2084 | // need to do a permission check since we're calling startActivity() |
| 2085 | // from the context of the phone app. |
| 2086 | enforceCallPermission(); |
| 2087 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2088 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2089 | != AppOpsManager.MODE_ALLOWED) { |
| 2090 | return; |
| 2091 | } |
| 2092 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2093 | final long identity = Binder.clearCallingIdentity(); |
| 2094 | try { |
| 2095 | String url = createTelUrl(number); |
| 2096 | if (url == null) { |
| 2097 | return; |
| 2098 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2099 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2100 | boolean isValid = false; |
| 2101 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2102 | if (slist != null) { |
| 2103 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2104 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2105 | isValid = true; |
| 2106 | break; |
| 2107 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2108 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2109 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2110 | if (!isValid) { |
| 2111 | return; |
| 2112 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2113 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2114 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2115 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2116 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2117 | mApp.startActivity(intent); |
| 2118 | } finally { |
| 2119 | Binder.restoreCallingIdentity(identity); |
| 2120 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2121 | } |
| 2122 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2123 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2124 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2125 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2126 | } |
| 2127 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2128 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2129 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2130 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2131 | } |
| 2132 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2133 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2134 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2135 | |
| 2136 | final long identity = Binder.clearCallingIdentity(); |
| 2137 | try { |
| 2138 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 2139 | checkSimPin.start(); |
| 2140 | return checkSimPin.unlockSim(null, pin); |
| 2141 | } finally { |
| 2142 | Binder.restoreCallingIdentity(identity); |
| 2143 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2144 | } |
| 2145 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2146 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2147 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2148 | |
| 2149 | final long identity = Binder.clearCallingIdentity(); |
| 2150 | try { |
| 2151 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 2152 | checkSimPuk.start(); |
| 2153 | return checkSimPuk.unlockSim(puk, pin); |
| 2154 | } finally { |
| 2155 | Binder.restoreCallingIdentity(identity); |
| 2156 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2157 | } |
| 2158 | |
| 2159 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2160 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2161 | * a synchronous one. |
| 2162 | */ |
| 2163 | private static class UnlockSim extends Thread { |
| 2164 | |
| 2165 | private final IccCard mSimCard; |
| 2166 | |
| 2167 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2168 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2169 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2170 | |
| 2171 | // For replies from SimCard interface |
| 2172 | private Handler mHandler; |
| 2173 | |
| 2174 | // For async handler to identify request type |
| 2175 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2176 | |
| 2177 | public UnlockSim(IccCard simCard) { |
| 2178 | mSimCard = simCard; |
| 2179 | } |
| 2180 | |
| 2181 | @Override |
| 2182 | public void run() { |
| 2183 | Looper.prepare(); |
| 2184 | synchronized (UnlockSim.this) { |
| 2185 | mHandler = new Handler() { |
| 2186 | @Override |
| 2187 | public void handleMessage(Message msg) { |
| 2188 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2189 | switch (msg.what) { |
| 2190 | case SUPPLY_PIN_COMPLETE: |
| 2191 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2192 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2193 | mRetryCount = msg.arg1; |
| 2194 | if (ar.exception != null) { |
| 2195 | if (ar.exception instanceof CommandException && |
| 2196 | ((CommandException)(ar.exception)).getCommandError() |
| 2197 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2198 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2199 | } //When UiccCardApp dispose,handle message and return exception |
| 2200 | else if (ar.exception instanceof CommandException && |
| 2201 | ((CommandException) (ar.exception)).getCommandError() |
| 2202 | == CommandException.Error.ABORTED) { |
| 2203 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2204 | } else { |
| 2205 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2206 | } |
| 2207 | } else { |
| 2208 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2209 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2210 | mDone = true; |
| 2211 | UnlockSim.this.notifyAll(); |
| 2212 | } |
| 2213 | break; |
| 2214 | } |
| 2215 | } |
| 2216 | }; |
| 2217 | UnlockSim.this.notifyAll(); |
| 2218 | } |
| 2219 | Looper.loop(); |
| 2220 | } |
| 2221 | |
| 2222 | /* |
| 2223 | * Use PIN or PUK to unlock SIM card |
| 2224 | * |
| 2225 | * If PUK is null, unlock SIM card with PIN |
| 2226 | * |
| 2227 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2228 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2229 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2230 | |
| 2231 | while (mHandler == null) { |
| 2232 | try { |
| 2233 | wait(); |
| 2234 | } catch (InterruptedException e) { |
| 2235 | Thread.currentThread().interrupt(); |
| 2236 | } |
| 2237 | } |
| 2238 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2239 | |
| 2240 | if (puk == null) { |
| 2241 | mSimCard.supplyPin(pin, callback); |
| 2242 | } else { |
| 2243 | mSimCard.supplyPuk(puk, pin, callback); |
| 2244 | } |
| 2245 | |
| 2246 | while (!mDone) { |
| 2247 | try { |
| 2248 | Log.d(LOG_TAG, "wait for done"); |
| 2249 | wait(); |
| 2250 | } catch (InterruptedException e) { |
| 2251 | // Restore the interrupted status |
| 2252 | Thread.currentThread().interrupt(); |
| 2253 | } |
| 2254 | } |
| 2255 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2256 | int[] resultArray = new int[2]; |
| 2257 | resultArray[0] = mResult; |
| 2258 | resultArray[1] = mRetryCount; |
| 2259 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2260 | } |
| 2261 | } |
| 2262 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2263 | /** |
| 2264 | * This method has been removed due to privacy and stability concerns. |
| 2265 | */ |
| 2266 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2267 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2268 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2269 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2270 | } |
| 2271 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2272 | @Override |
| 2273 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2274 | mApp.getSystemService(AppOpsManager.class) |
| 2275 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2276 | |
| 2277 | final int targetSdk = getTargetSdk(callingPackage); |
| 2278 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2279 | // Callers targeting S have no business invoking this method. |
| 2280 | return; |
| 2281 | } |
| 2282 | |
| 2283 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2284 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2285 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2286 | .setCallingPackage(callingPackage) |
| 2287 | .setCallingFeatureId(null) |
| 2288 | .setCallingPid(Binder.getCallingPid()) |
| 2289 | .setCallingUid(Binder.getCallingUid()) |
| 2290 | .setMethod("updateServiceLocation") |
| 2291 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2292 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2293 | .build()); |
| 2294 | // Apps that lack location permission have no business calling this method; |
| 2295 | // however, because no permission was declared in the public API, denials must |
| 2296 | // all be "soft". |
| 2297 | switch (locationResult) { |
| 2298 | case DENIED_HARD: /* fall through */ |
| 2299 | case DENIED_SOFT: |
| 2300 | return; |
| 2301 | } |
| 2302 | |
| 2303 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2304 | final long identity = Binder.clearCallingIdentity(); |
| 2305 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2306 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2307 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2308 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2309 | } |
| 2310 | } finally { |
| 2311 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2312 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2313 | } |
| 2314 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2315 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2316 | @Override |
| 2317 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2318 | return isRadioOnWithFeature(callingPackage, null); |
| 2319 | } |
| 2320 | |
| 2321 | |
| 2322 | @Override |
| 2323 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2324 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2325 | callingFeatureId); |
| 2326 | } |
| 2327 | |
| 2328 | @Deprecated |
| 2329 | @Override |
| 2330 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2331 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2332 | } |
| 2333 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2334 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2335 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2336 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2337 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2338 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2339 | return false; |
| 2340 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2341 | |
| 2342 | final long identity = Binder.clearCallingIdentity(); |
| 2343 | try { |
| 2344 | return isRadioOnForSubscriber(subId); |
| 2345 | } finally { |
| 2346 | Binder.restoreCallingIdentity(identity); |
| 2347 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2348 | } |
| 2349 | |
| 2350 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2351 | final long identity = Binder.clearCallingIdentity(); |
| 2352 | try { |
| 2353 | final Phone phone = getPhone(subId); |
| 2354 | if (phone != null) { |
| 2355 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2356 | } else { |
| 2357 | return false; |
| 2358 | } |
| 2359 | } finally { |
| 2360 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2361 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2362 | } |
| 2363 | |
| 2364 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2365 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2366 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2367 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2368 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2369 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2370 | |
| 2371 | final long identity = Binder.clearCallingIdentity(); |
| 2372 | try { |
| 2373 | final Phone phone = getPhone(subId); |
| 2374 | if (phone != null) { |
| 2375 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2376 | } |
| 2377 | } finally { |
| 2378 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2379 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2380 | } |
| 2381 | |
| 2382 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2383 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2384 | } |
| 2385 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2386 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2387 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2388 | |
| 2389 | final long identity = Binder.clearCallingIdentity(); |
| 2390 | try { |
| 2391 | final Phone phone = getPhone(subId); |
| 2392 | if (phone == null) { |
| 2393 | return false; |
| 2394 | } |
| 2395 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2396 | toggleRadioOnOffForSubscriber(subId); |
| 2397 | } |
| 2398 | return true; |
| 2399 | } finally { |
| 2400 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2401 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2402 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2403 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2404 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2405 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2406 | /* |
| 2407 | * If any of the Radios are available, it will need to be |
| 2408 | * shutdown. So return true if any Radio is available. |
| 2409 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2410 | final long identity = Binder.clearCallingIdentity(); |
| 2411 | try { |
| 2412 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2413 | Phone phone = PhoneFactory.getPhone(i); |
| 2414 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2415 | } |
| 2416 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2417 | return false; |
| 2418 | } finally { |
| 2419 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2420 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2421 | } |
| 2422 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2423 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2424 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2425 | enforceModifyPermission(); |
| 2426 | |
| 2427 | final long identity = Binder.clearCallingIdentity(); |
| 2428 | try { |
| 2429 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2430 | logv("Shutting down Phone " + i); |
| 2431 | shutdownRadioUsingPhoneId(i); |
| 2432 | } |
| 2433 | } finally { |
| 2434 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2435 | } |
| 2436 | } |
| 2437 | |
| 2438 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2439 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2440 | if (phone != null && phone.isRadioAvailable()) { |
| 2441 | phone.shutdownRadio(); |
| 2442 | } |
| 2443 | } |
| 2444 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2445 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2446 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2447 | |
| 2448 | final long identity = Binder.clearCallingIdentity(); |
| 2449 | try { |
| 2450 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2451 | if (defaultPhone != null) { |
| 2452 | defaultPhone.setRadioPower(turnOn); |
| 2453 | return true; |
| 2454 | } else { |
| 2455 | loge("There's no default phone."); |
| 2456 | return false; |
| 2457 | } |
| 2458 | } finally { |
| 2459 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2460 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2461 | } |
| 2462 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2463 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2464 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2465 | |
| 2466 | final long identity = Binder.clearCallingIdentity(); |
| 2467 | try { |
| 2468 | final Phone phone = getPhone(subId); |
| 2469 | if (phone != null) { |
| 2470 | phone.setRadioPower(turnOn); |
| 2471 | return true; |
| 2472 | } else { |
| 2473 | return false; |
| 2474 | } |
| 2475 | } finally { |
| 2476 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2477 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2478 | } |
| 2479 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2480 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2481 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2482 | public boolean enableDataConnectivity() { |
| 2483 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2484 | |
| 2485 | final long identity = Binder.clearCallingIdentity(); |
| 2486 | try { |
| 2487 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2488 | final Phone phone = getPhone(subId); |
| 2489 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2490 | phone.getDataEnabledSettings().setDataEnabled( |
| 2491 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2492 | return true; |
| 2493 | } else { |
| 2494 | return false; |
| 2495 | } |
| 2496 | } finally { |
| 2497 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2498 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2499 | } |
| 2500 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2501 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2502 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2503 | public boolean disableDataConnectivity() { |
| 2504 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2505 | |
| 2506 | final long identity = Binder.clearCallingIdentity(); |
| 2507 | try { |
| 2508 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2509 | final Phone phone = getPhone(subId); |
| 2510 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2511 | phone.getDataEnabledSettings().setDataEnabled( |
| 2512 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2513 | return true; |
| 2514 | } else { |
| 2515 | return false; |
| 2516 | } |
| 2517 | } finally { |
| 2518 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2519 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2520 | } |
| 2521 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2522 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2523 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2524 | final long identity = Binder.clearCallingIdentity(); |
| 2525 | try { |
| 2526 | final Phone phone = getPhone(subId); |
| 2527 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2528 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2529 | } else { |
| 2530 | return false; |
| 2531 | } |
| 2532 | } finally { |
| 2533 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2534 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2535 | } |
| 2536 | |
| 2537 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2538 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2539 | } |
| 2540 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2541 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2542 | enforceCallPermission(); |
| 2543 | |
| 2544 | final long identity = Binder.clearCallingIdentity(); |
| 2545 | try { |
| 2546 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2547 | return; |
| 2548 | } |
| 2549 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2550 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2551 | } finally { |
| 2552 | Binder.restoreCallingIdentity(identity); |
| 2553 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2554 | }; |
| 2555 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2556 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2557 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2558 | |
| 2559 | final long identity = Binder.clearCallingIdentity(); |
| 2560 | try { |
| 2561 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2562 | return false; |
| 2563 | } |
| 2564 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2565 | } finally { |
| 2566 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2567 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2568 | } |
| 2569 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2570 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2571 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2572 | } |
| 2573 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2574 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2575 | final long identity = Binder.clearCallingIdentity(); |
| 2576 | try { |
| 2577 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2578 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2579 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2580 | } finally { |
| 2581 | Binder.restoreCallingIdentity(identity); |
| 2582 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2583 | } |
| 2584 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2585 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2586 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2587 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2588 | } |
| 2589 | |
| 2590 | @Override |
| 2591 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2592 | final long identity = Binder.clearCallingIdentity(); |
| 2593 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2594 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2595 | if (phone != null) { |
| 2596 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2597 | } else { |
| 2598 | return PhoneConstantConversions.convertDataState( |
| 2599 | PhoneConstants.DataState.DISCONNECTED); |
| 2600 | } |
| 2601 | } finally { |
| 2602 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2603 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2604 | } |
| 2605 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2606 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2607 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2608 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2609 | } |
| 2610 | |
| 2611 | @Override |
| 2612 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2613 | final long identity = Binder.clearCallingIdentity(); |
| 2614 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2615 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2616 | if (phone != null) { |
| 2617 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2618 | } else { |
| 2619 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2620 | } |
| 2621 | } finally { |
| 2622 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2623 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2624 | } |
| 2625 | |
| 2626 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2627 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2628 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2629 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2630 | |
| 2631 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2632 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2633 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2634 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2635 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2636 | .setCallingPid(Binder.getCallingPid()) |
| 2637 | .setCallingUid(Binder.getCallingUid()) |
| 2638 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2639 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2640 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2641 | .build()); |
| 2642 | switch (locationResult) { |
| 2643 | case DENIED_HARD: |
| 2644 | throw new SecurityException("Not allowed to access cell location"); |
| 2645 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2646 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2647 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2648 | } |
| 2649 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2650 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2651 | final long identity = Binder.clearCallingIdentity(); |
| 2652 | try { |
| 2653 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2654 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2655 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2656 | } finally { |
| 2657 | Binder.restoreCallingIdentity(identity); |
| 2658 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2659 | } |
| 2660 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2661 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2662 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2663 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2664 | // registered cell info, so return a NULL country instead. |
| 2665 | final long identity = Binder.clearCallingIdentity(); |
| 2666 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2667 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2668 | // Get default phone in this case. |
| 2669 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2670 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2671 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2672 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2673 | if (phone == null) return ""; |
| 2674 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2675 | if (sst == null) return ""; |
| 2676 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2677 | if (lt == null) return ""; |
| 2678 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2679 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2680 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2681 | } finally { |
| 2682 | Binder.restoreCallingIdentity(identity); |
| 2683 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2684 | } |
| 2685 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2686 | /** |
| 2687 | * This method was removed due to potential issues caused by performing partial |
| 2688 | * updates of service state, and lack of a credible use case. |
| 2689 | * |
| 2690 | * This has the ability to break the telephony implementation by disabling notification of |
| 2691 | * changes in device connectivity. DO NOT USE THIS! |
| 2692 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2693 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2694 | public void enableLocationUpdates() { |
| 2695 | mApp.enforceCallingOrSelfPermission( |
| 2696 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2697 | } |
| 2698 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2699 | /** |
| 2700 | * This method was removed due to potential issues caused by performing partial |
| 2701 | * updates of service state, and lack of a credible use case. |
| 2702 | * |
| 2703 | * This has the ability to break the telephony implementation by disabling notification of |
| 2704 | * changes in device connectivity. DO NOT USE THIS! |
| 2705 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2706 | @Override |
| 2707 | public void disableLocationUpdates() { |
| 2708 | mApp.enforceCallingOrSelfPermission( |
| 2709 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2710 | } |
| 2711 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2712 | /** |
| 2713 | * Returns the target SDK version number for a given package name. |
| 2714 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2715 | * This call MUST be invoked before clearing the calling UID. |
| 2716 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2717 | * @return target SDK if the package is found or INT_MAX. |
| 2718 | */ |
| 2719 | private int getTargetSdk(String packageName) { |
| 2720 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2721 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 0150f0e | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2722 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2723 | if (ai != null) return ai.targetSdkVersion; |
| 2724 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2725 | loge("Failed to get package info for pkg=" |
| 2726 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2727 | } |
| 2728 | return Integer.MAX_VALUE; |
| 2729 | } |
| 2730 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2731 | @Override |
| 2732 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2733 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2734 | String callingFeatureId) { |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2735 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2736 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2737 | throw new SecurityException( |
| 2738 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2739 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2740 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2741 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2742 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2743 | return null; |
| 2744 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2745 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2746 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2747 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2748 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2749 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2750 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2751 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2752 | for (CellInfo ci : info) { |
| 2753 | if (ci instanceof CellInfoGsm) { |
| 2754 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2755 | } else if (ci instanceof CellInfoWcdma) { |
| 2756 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2757 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2758 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2759 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2760 | } |
| 2761 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2762 | private List<CellInfo> getCachedCellInfo() { |
| 2763 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2764 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2765 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2766 | if (info != null) cellInfos.addAll(info); |
| 2767 | } |
| 2768 | return cellInfos; |
| 2769 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2770 | |
| 2771 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2772 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2773 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2774 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2775 | |
| 2776 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2777 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2778 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2779 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2780 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2781 | .setCallingPid(Binder.getCallingPid()) |
| 2782 | .setCallingUid(Binder.getCallingUid()) |
| 2783 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2784 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2785 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2786 | .build()); |
| 2787 | switch (locationResult) { |
| 2788 | case DENIED_HARD: |
| 2789 | throw new SecurityException("Not allowed to access cell info"); |
| 2790 | case DENIED_SOFT: |
| 2791 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2792 | } |
| 2793 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2794 | final int targetSdk = getTargetSdk(callingPackage); |
| 2795 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2796 | return getCachedCellInfo(); |
| 2797 | } |
| 2798 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2799 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2800 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2801 | final long identity = Binder.clearCallingIdentity(); |
| 2802 | try { |
| 2803 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2804 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2805 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2806 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2807 | if (info != null) cellInfos.addAll(info); |
| 2808 | } |
| 2809 | return cellInfos; |
| 2810 | } finally { |
| 2811 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2812 | } |
| 2813 | } |
| 2814 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2815 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2816 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2817 | String callingFeatureId) { |
| 2818 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2819 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2820 | } |
| 2821 | |
| 2822 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2823 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2824 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2825 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2826 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2827 | } |
| 2828 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2829 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2830 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2831 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2832 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2833 | |
| 2834 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2835 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2836 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2837 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2838 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2839 | .setCallingPid(Binder.getCallingPid()) |
| 2840 | .setCallingUid(Binder.getCallingUid()) |
| 2841 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2842 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2843 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2844 | .build()); |
| 2845 | switch (locationResult) { |
| 2846 | case DENIED_HARD: |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2847 | if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) { |
| 2848 | // Safetynet logging for b/154934934 |
| 2849 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2850 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2851 | throw new SecurityException("Not allowed to access cell info"); |
| 2852 | case DENIED_SOFT: |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2853 | if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) { |
| 2854 | // Safetynet logging for b/154934934 |
| 2855 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2856 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2857 | try { |
| 2858 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2859 | } catch (RemoteException re) { |
| 2860 | // Drop without consequences |
| 2861 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2862 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2863 | } |
| 2864 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2865 | |
| 2866 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2867 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2868 | |
| 2869 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2870 | } |
| 2871 | |
| 2872 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2873 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2874 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2875 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2876 | |
| 2877 | final long identity = Binder.clearCallingIdentity(); |
| 2878 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2879 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2880 | } finally { |
| 2881 | Binder.restoreCallingIdentity(identity); |
| 2882 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2883 | } |
| 2884 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2885 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2886 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2887 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2888 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2889 | return null; |
| 2890 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2891 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2892 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2893 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2894 | return null; |
| 2895 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2896 | |
| 2897 | final long identity = Binder.clearCallingIdentity(); |
| 2898 | try { |
| 2899 | return phone.getImei(); |
| 2900 | } finally { |
| 2901 | Binder.restoreCallingIdentity(identity); |
| 2902 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2903 | } |
| 2904 | |
| 2905 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2906 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2907 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2908 | String tac = null; |
| 2909 | if (phone != null) { |
| 2910 | String imei = phone.getImei(); |
| 2911 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2912 | } |
| 2913 | return tac; |
| 2914 | } |
| 2915 | |
| 2916 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2917 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2918 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2919 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2920 | return null; |
| 2921 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2922 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2923 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2924 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2925 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2926 | return null; |
| 2927 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2928 | |
| 2929 | final long identity = Binder.clearCallingIdentity(); |
| 2930 | try { |
| 2931 | return phone.getMeid(); |
| 2932 | } finally { |
| 2933 | Binder.restoreCallingIdentity(identity); |
| 2934 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2935 | } |
| 2936 | |
| 2937 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2938 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2939 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2940 | String manufacturerCode = null; |
| 2941 | if (phone != null) { |
| 2942 | String meid = phone.getMeid(); |
| 2943 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2944 | } |
| 2945 | return manufacturerCode; |
| 2946 | } |
| 2947 | |
| 2948 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2949 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2950 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2951 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2952 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2953 | return null; |
| 2954 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2955 | int subId = phone.getSubId(); |
| 2956 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2957 | mApp, subId, callingPackage, callingFeatureId, |
| 2958 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2959 | return null; |
| 2960 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2961 | |
| 2962 | final long identity = Binder.clearCallingIdentity(); |
| 2963 | try { |
| 2964 | return phone.getDeviceSvn(); |
| 2965 | } finally { |
| 2966 | Binder.restoreCallingIdentity(identity); |
| 2967 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2968 | } |
| 2969 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2970 | @Override |
| 2971 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2972 | final long identity = Binder.clearCallingIdentity(); |
| 2973 | try { |
| 2974 | final Phone phone = getPhone(subId); |
| 2975 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2976 | } finally { |
| 2977 | Binder.restoreCallingIdentity(identity); |
| 2978 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2979 | } |
| 2980 | |
| 2981 | @Override |
| 2982 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2983 | final long identity = Binder.clearCallingIdentity(); |
| 2984 | try { |
| 2985 | final Phone phone = getPhone(subId); |
| 2986 | return phone == null ? null : phone.getCarrierName(); |
| 2987 | } finally { |
| 2988 | Binder.restoreCallingIdentity(identity); |
| 2989 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2990 | } |
| 2991 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2992 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2993 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2994 | final long identity = Binder.clearCallingIdentity(); |
| 2995 | try { |
| 2996 | final Phone phone = getPhone(subId); |
| 2997 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2998 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2999 | } finally { |
| 3000 | Binder.restoreCallingIdentity(identity); |
| 3001 | } |
| 3002 | } |
| 3003 | |
| 3004 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3005 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3006 | final long identity = Binder.clearCallingIdentity(); |
| 3007 | try { |
| 3008 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3009 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3010 | } finally { |
| 3011 | Binder.restoreCallingIdentity(identity); |
| 3012 | } |
| 3013 | } |
| 3014 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3015 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3016 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3017 | if (!isSubscriptionMccMnc) { |
| 3018 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3019 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3020 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3021 | if (phone == null) { |
| 3022 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3023 | } |
| 3024 | final long identity = Binder.clearCallingIdentity(); |
| 3025 | try { |
| 3026 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3027 | } finally { |
| 3028 | Binder.restoreCallingIdentity(identity); |
| 3029 | } |
| 3030 | } |
| 3031 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3032 | // |
| 3033 | // Internal helper methods. |
| 3034 | // |
| 3035 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3036 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3037 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3038 | * |
| 3039 | * @throws SecurityException if the caller does not have the required permission |
| 3040 | */ |
| 3041 | private void enforceModifyPermission() { |
| 3042 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3043 | } |
| 3044 | |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3045 | /** |
| 3046 | * Make sure the caller is system. |
| 3047 | * |
| 3048 | * @throws SecurityException if the caller is not system. |
| 3049 | */ |
| 3050 | private void enforceSystemCaller() { |
| 3051 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 3052 | throw new SecurityException("Caller must be system"); |
| 3053 | } |
| 3054 | } |
| 3055 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3056 | private void enforceActiveEmergencySessionPermission() { |
| 3057 | mApp.enforceCallingOrSelfPermission( |
| 3058 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3059 | } |
| 3060 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3061 | /** |
| 3062 | * Make sure the caller has the CALL_PHONE permission. |
| 3063 | * |
| 3064 | * @throws SecurityException if the caller does not have the required permission |
| 3065 | */ |
| 3066 | private void enforceCallPermission() { |
| 3067 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3068 | } |
| 3069 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3070 | private void enforceSettingsPermission() { |
| 3071 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3072 | } |
| 3073 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3074 | private String createTelUrl(String number) { |
| 3075 | if (TextUtils.isEmpty(number)) { |
| 3076 | return null; |
| 3077 | } |
| 3078 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3079 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3080 | } |
| 3081 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3082 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3083 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3084 | } |
| 3085 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3086 | private static void logv(String msg) { |
| 3087 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3088 | } |
| 3089 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3090 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3091 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3092 | } |
| 3093 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3094 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3095 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3096 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3097 | } |
| 3098 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3099 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3100 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3101 | final long identity = Binder.clearCallingIdentity(); |
| 3102 | try { |
| 3103 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3104 | if (phone == null) { |
| 3105 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3106 | } else { |
| 3107 | return phone.getPhoneType(); |
| 3108 | } |
| 3109 | } finally { |
| 3110 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3111 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3112 | } |
| 3113 | |
| 3114 | /** |
| 3115 | * Returns the CDMA ERI icon index to display |
| 3116 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3117 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3118 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3119 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3120 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3121 | } |
| 3122 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3123 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3124 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3125 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3126 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3127 | mApp, subId, callingPackage, callingFeatureId, |
| 3128 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3129 | return -1; |
| 3130 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3131 | |
| 3132 | final long identity = Binder.clearCallingIdentity(); |
| 3133 | try { |
| 3134 | final Phone phone = getPhone(subId); |
| 3135 | if (phone != null) { |
| 3136 | return phone.getCdmaEriIconIndex(); |
| 3137 | } else { |
| 3138 | return -1; |
| 3139 | } |
| 3140 | } finally { |
| 3141 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3142 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3143 | } |
| 3144 | |
| 3145 | /** |
| 3146 | * Returns the CDMA ERI icon mode, |
| 3147 | * 0 - ON |
| 3148 | * 1 - FLASHING |
| 3149 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3150 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3151 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3152 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3153 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3154 | } |
| 3155 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3156 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3157 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3158 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3159 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3160 | mApp, subId, callingPackage, callingFeatureId, |
| 3161 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3162 | return -1; |
| 3163 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3164 | |
| 3165 | final long identity = Binder.clearCallingIdentity(); |
| 3166 | try { |
| 3167 | final Phone phone = getPhone(subId); |
| 3168 | if (phone != null) { |
| 3169 | return phone.getCdmaEriIconMode(); |
| 3170 | } else { |
| 3171 | return -1; |
| 3172 | } |
| 3173 | } finally { |
| 3174 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3175 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3176 | } |
| 3177 | |
| 3178 | /** |
| 3179 | * Returns the CDMA ERI text, |
| 3180 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3181 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3182 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3183 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3184 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3185 | } |
| 3186 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3187 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3188 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3189 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3190 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3191 | mApp, subId, callingPackage, callingFeatureId, |
| 3192 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3193 | return null; |
| 3194 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3195 | |
| 3196 | final long identity = Binder.clearCallingIdentity(); |
| 3197 | try { |
| 3198 | final Phone phone = getPhone(subId); |
| 3199 | if (phone != null) { |
| 3200 | return phone.getCdmaEriText(); |
| 3201 | } else { |
| 3202 | return null; |
| 3203 | } |
| 3204 | } finally { |
| 3205 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3206 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3207 | } |
| 3208 | |
| 3209 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3210 | * Returns the CDMA MDN. |
| 3211 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3212 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3213 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3214 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3215 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3216 | |
| 3217 | final long identity = Binder.clearCallingIdentity(); |
| 3218 | try { |
| 3219 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3220 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3221 | return phone.getLine1Number(); |
| 3222 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3223 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3224 | return null; |
| 3225 | } |
| 3226 | } finally { |
| 3227 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3228 | } |
| 3229 | } |
| 3230 | |
| 3231 | /** |
| 3232 | * Returns the CDMA MIN. |
| 3233 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3234 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3235 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3236 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3237 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3238 | |
| 3239 | final long identity = Binder.clearCallingIdentity(); |
| 3240 | try { |
| 3241 | final Phone phone = getPhone(subId); |
| 3242 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3243 | return phone.getCdmaMin(); |
| 3244 | } else { |
| 3245 | return null; |
| 3246 | } |
| 3247 | } finally { |
| 3248 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3249 | } |
| 3250 | } |
| 3251 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3252 | @Override |
| 3253 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3254 | INumberVerificationCallback callback, String callingPackage) { |
| 3255 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3256 | != PERMISSION_GRANTED) { |
| 3257 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3258 | } |
| 3259 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3260 | |
| 3261 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3262 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 3263 | throw new SecurityException("Calling package must be configured in the device config"); |
| 3264 | } |
| 3265 | |
| 3266 | if (range == null) { |
| 3267 | throw new NullPointerException("Range must be non-null"); |
| 3268 | } |
| 3269 | |
| 3270 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3271 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3272 | |
| 3273 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3274 | } |
| 3275 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3276 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3277 | * Returns true if CDMA provisioning needs to run. |
| 3278 | */ |
| 3279 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3280 | final long identity = Binder.clearCallingIdentity(); |
| 3281 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3282 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3283 | } finally { |
| 3284 | Binder.restoreCallingIdentity(identity); |
| 3285 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3286 | } |
| 3287 | |
| 3288 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3289 | * Sets the voice mail number of a given subId. |
| 3290 | */ |
| 3291 | @Override |
| 3292 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3293 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3294 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3295 | |
| 3296 | final long identity = Binder.clearCallingIdentity(); |
| 3297 | try { |
| 3298 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3299 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3300 | return success; |
| 3301 | } finally { |
| 3302 | Binder.restoreCallingIdentity(identity); |
| 3303 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3304 | } |
| 3305 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3306 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3307 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3308 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3309 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3310 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3311 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3312 | throw new SecurityException("caller must be system dialer"); |
| 3313 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3314 | |
| 3315 | final long identity = Binder.clearCallingIdentity(); |
| 3316 | try { |
| 3317 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3318 | if (phoneAccountHandle == null) { |
| 3319 | return null; |
| 3320 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3321 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3322 | } finally { |
| 3323 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3324 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3325 | } |
| 3326 | |
| 3327 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3328 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3329 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3330 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3331 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3332 | mApp, subId, callingPackage, callingFeatureId, |
| 3333 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3334 | return null; |
| 3335 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3336 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3337 | final long identity = Binder.clearCallingIdentity(); |
| 3338 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3339 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3340 | } finally { |
| 3341 | Binder.restoreCallingIdentity(identity); |
| 3342 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3343 | } |
| 3344 | |
| 3345 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3346 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3347 | VisualVoicemailSmsFilterSettings settings) { |
| 3348 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3349 | |
| 3350 | final long identity = Binder.clearCallingIdentity(); |
| 3351 | try { |
| 3352 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3353 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3354 | } finally { |
| 3355 | Binder.restoreCallingIdentity(identity); |
| 3356 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3357 | } |
| 3358 | |
| 3359 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3360 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3361 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3362 | |
| 3363 | final long identity = Binder.clearCallingIdentity(); |
| 3364 | try { |
| 3365 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3366 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3367 | } finally { |
| 3368 | Binder.restoreCallingIdentity(identity); |
| 3369 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3370 | } |
| 3371 | |
| 3372 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3373 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3374 | String callingPackage, int subId) { |
| 3375 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3376 | |
| 3377 | final long identity = Binder.clearCallingIdentity(); |
| 3378 | try { |
| 3379 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3380 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3381 | } finally { |
| 3382 | Binder.restoreCallingIdentity(identity); |
| 3383 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3384 | } |
| 3385 | |
| 3386 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3387 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3388 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3389 | |
| 3390 | final long identity = Binder.clearCallingIdentity(); |
| 3391 | try { |
| 3392 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3393 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3394 | } finally { |
| 3395 | Binder.restoreCallingIdentity(identity); |
| 3396 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3397 | } |
| 3398 | |
| 3399 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3400 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3401 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3402 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3403 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3404 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3405 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3406 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3407 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3408 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3409 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3410 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3411 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3412 | * Sets the voice activation state of a given subId. |
| 3413 | */ |
| 3414 | @Override |
| 3415 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3416 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3417 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3418 | |
| 3419 | final long identity = Binder.clearCallingIdentity(); |
| 3420 | try { |
| 3421 | final Phone phone = getPhone(subId); |
| 3422 | if (phone != null) { |
| 3423 | phone.setVoiceActivationState(activationState); |
| 3424 | } else { |
| 3425 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3426 | } |
| 3427 | } finally { |
| 3428 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3429 | } |
| 3430 | } |
| 3431 | |
| 3432 | /** |
| 3433 | * Sets the data activation state of a given subId. |
| 3434 | */ |
| 3435 | @Override |
| 3436 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3437 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3438 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3439 | |
| 3440 | final long identity = Binder.clearCallingIdentity(); |
| 3441 | try { |
| 3442 | final Phone phone = getPhone(subId); |
| 3443 | if (phone != null) { |
| 3444 | phone.setDataActivationState(activationState); |
| 3445 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3446 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3447 | } |
| 3448 | } finally { |
| 3449 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3450 | } |
| 3451 | } |
| 3452 | |
| 3453 | /** |
| 3454 | * Returns the voice activation state of a given subId. |
| 3455 | */ |
| 3456 | @Override |
| 3457 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3458 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3459 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3460 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3461 | final long identity = Binder.clearCallingIdentity(); |
| 3462 | try { |
| 3463 | if (phone != null) { |
| 3464 | return phone.getVoiceActivationState(); |
| 3465 | } else { |
| 3466 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3467 | } |
| 3468 | } finally { |
| 3469 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3470 | } |
| 3471 | } |
| 3472 | |
| 3473 | /** |
| 3474 | * Returns the data activation state of a given subId. |
| 3475 | */ |
| 3476 | @Override |
| 3477 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3478 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3479 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3480 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3481 | final long identity = Binder.clearCallingIdentity(); |
| 3482 | try { |
| 3483 | if (phone != null) { |
| 3484 | return phone.getDataActivationState(); |
| 3485 | } else { |
| 3486 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3487 | } |
| 3488 | } finally { |
| 3489 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3490 | } |
| 3491 | } |
| 3492 | |
| 3493 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3494 | * Returns the unread count of voicemails for a subId |
| 3495 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3496 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3497 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3498 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3499 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3500 | mApp, subId, callingPackage, callingFeatureId, |
| 3501 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3502 | return 0; |
| 3503 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3504 | final long identity = Binder.clearCallingIdentity(); |
| 3505 | try { |
| 3506 | final Phone phone = getPhone(subId); |
| 3507 | if (phone != null) { |
| 3508 | return phone.getVoiceMessageCount(); |
| 3509 | } else { |
| 3510 | return 0; |
| 3511 | } |
| 3512 | } finally { |
| 3513 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3514 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3515 | } |
| 3516 | |
| 3517 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3518 | * returns true, if the device is in a state where both voice and data |
| 3519 | * are supported simultaneously. This can change based on location or network condition. |
| 3520 | */ |
| 3521 | @Override |
| 3522 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3523 | final long identity = Binder.clearCallingIdentity(); |
| 3524 | try { |
| 3525 | final Phone phone = getPhone(subId); |
| 3526 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3527 | } finally { |
| 3528 | Binder.restoreCallingIdentity(identity); |
| 3529 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3530 | } |
| 3531 | |
| 3532 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3533 | * Send the dialer code if called from the current default dialer or the caller has |
| 3534 | * carrier privilege. |
| 3535 | * @param inputCode The dialer code to send |
| 3536 | */ |
| 3537 | @Override |
| 3538 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3539 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3540 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3541 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3542 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3543 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3544 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3545 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3546 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3547 | |
| 3548 | final long identity = Binder.clearCallingIdentity(); |
| 3549 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3550 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3551 | } finally { |
| 3552 | Binder.restoreCallingIdentity(identity); |
| 3553 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3554 | } |
| 3555 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3556 | @Override |
| 3557 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3558 | TelephonyPermissions |
| 3559 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3560 | mApp, subId, "getNetworkSelectionMode"); |
| 3561 | final long identity = Binder.clearCallingIdentity(); |
| 3562 | try { |
| 3563 | if (!isActiveSubscription(subId)) { |
| 3564 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3565 | } |
| 3566 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3567 | } finally { |
| 3568 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3569 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3570 | } |
| 3571 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3572 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3573 | public boolean isInEmergencySmsMode() { |
| 3574 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3575 | final long identity = Binder.clearCallingIdentity(); |
| 3576 | try { |
| 3577 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3578 | if (phone.isInEmergencySmsMode()) { |
| 3579 | return true; |
| 3580 | } |
| 3581 | } |
| 3582 | } finally { |
| 3583 | Binder.restoreCallingIdentity(identity); |
| 3584 | } |
| 3585 | return false; |
| 3586 | } |
| 3587 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3588 | /** |
| 3589 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3590 | * @param subId The subscription to use to check the configuration. |
| 3591 | * @param c The callback that will be used to send the result. |
| 3592 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3593 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3594 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3595 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3596 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3597 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3598 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3599 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3600 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3601 | "IMS not available on device."); |
| 3602 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3603 | final long token = Binder.clearCallingIdentity(); |
| 3604 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3605 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3606 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3607 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3608 | } catch (ImsException e) { |
| 3609 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3610 | } finally { |
| 3611 | Binder.restoreCallingIdentity(token); |
| 3612 | } |
| 3613 | } |
| 3614 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3615 | /** |
| 3616 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3617 | * @param subId The subscription to use to check the configuration. |
| 3618 | * @param c The callback that will be used to send the result. |
| 3619 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3620 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3621 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3622 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3623 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3624 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3625 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3626 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3627 | final long token = Binder.clearCallingIdentity(); |
| 3628 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3629 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3630 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3631 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3632 | } catch (ImsException e) { |
| 3633 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3634 | + "is inactive, ignoring unregister."); |
| 3635 | // If the subscription is no longer active, just return, since the callback |
| 3636 | // will already have been removed internally. |
| 3637 | } finally { |
| 3638 | Binder.restoreCallingIdentity(token); |
| 3639 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3640 | } |
| 3641 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3642 | /** |
| 3643 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3644 | */ |
| 3645 | @Override |
| 3646 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3647 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3648 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3649 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3650 | "IMS not available on device."); |
| 3651 | } |
| 3652 | final long token = Binder.clearCallingIdentity(); |
| 3653 | try { |
| 3654 | Phone phone = getPhone(subId); |
| 3655 | if (phone == null) { |
| 3656 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3657 | + subId + "'"); |
| 3658 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3659 | } |
| 3660 | phone.getImsRegistrationState(regState -> { |
| 3661 | try { |
| 3662 | consumer.accept((regState == null) |
| 3663 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3664 | } catch (RemoteException e) { |
| 3665 | // Ignore if the remote process is no longer available to call back. |
| 3666 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3667 | } |
| 3668 | }); |
| 3669 | } finally { |
| 3670 | Binder.restoreCallingIdentity(token); |
| 3671 | } |
| 3672 | } |
| 3673 | |
| 3674 | /** |
| 3675 | * Get the transport type for the IMS service registration state. |
| 3676 | */ |
| 3677 | @Override |
| 3678 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3679 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3680 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3681 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3682 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3683 | "IMS not available on device."); |
| 3684 | } |
| 3685 | final long token = Binder.clearCallingIdentity(); |
| 3686 | try { |
| 3687 | Phone phone = getPhone(subId); |
| 3688 | if (phone == null) { |
| 3689 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3690 | + subId + "'"); |
| 3691 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3692 | } |
| 3693 | phone.getImsRegistrationTech(regTech -> { |
| 3694 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3695 | int regTechConverted = (regTech == null) |
| 3696 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3697 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3698 | regTechConverted); |
| 3699 | try { |
| 3700 | consumer.accept(regTechConverted); |
| 3701 | } catch (RemoteException e) { |
| 3702 | // Ignore if the remote process is no longer available to call back. |
| 3703 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3704 | } |
| 3705 | }); |
| 3706 | } finally { |
| 3707 | Binder.restoreCallingIdentity(token); |
| 3708 | } |
| 3709 | } |
| 3710 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3711 | /** |
| 3712 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3713 | * @param subId The subscription to use to check the configuration. |
| 3714 | * @param c The callback that will be used to send the result. |
| 3715 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3716 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3717 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3718 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3719 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3720 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3721 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3722 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3723 | "IMS not available on device."); |
| 3724 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3725 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3726 | final long token = Binder.clearCallingIdentity(); |
| 3727 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3728 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3729 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3730 | } catch (ImsException e) { |
| 3731 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3732 | } finally { |
| 3733 | Binder.restoreCallingIdentity(token); |
| 3734 | } |
| 3735 | } |
| 3736 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3737 | /** |
| 3738 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3739 | * @param subId The subscription to use to check the configuration. |
| 3740 | * @param c The callback that will be used to send the result. |
| 3741 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3742 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3743 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3744 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3745 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3746 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3747 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3748 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3749 | |
| 3750 | final long token = Binder.clearCallingIdentity(); |
| 3751 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3752 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3753 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3754 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3755 | } catch (ImsException e) { |
| 3756 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3757 | + "is inactive, ignoring unregister."); |
| 3758 | // If the subscription is no longer active, just return, since the callback |
| 3759 | // will already have been removed internally. |
| 3760 | } finally { |
| 3761 | Binder.restoreCallingIdentity(token); |
| 3762 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3763 | } |
| 3764 | |
| 3765 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3766 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3767 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3768 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3769 | final long token = Binder.clearCallingIdentity(); |
| 3770 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3771 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3772 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3773 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3774 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3775 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3776 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3777 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3778 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3779 | } finally { |
| 3780 | Binder.restoreCallingIdentity(token); |
| 3781 | } |
| 3782 | } |
| 3783 | |
| 3784 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3785 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3786 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3787 | final long token = Binder.clearCallingIdentity(); |
| 3788 | try { |
| 3789 | Phone phone = getPhone(subId); |
| 3790 | if (phone == null) return false; |
| 3791 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3792 | } catch (com.android.ims.ImsException e) { |
| 3793 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3794 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3795 | } finally { |
| 3796 | Binder.restoreCallingIdentity(token); |
| 3797 | } |
| 3798 | } |
| 3799 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3800 | /** |
| 3801 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3802 | * subscription. |
| 3803 | * @param subId The subscription to use to check the configuration. |
| 3804 | * @param callback The callback that will be used to send the result. |
| 3805 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3806 | * @param transportType The transport type of the MmTelFeature capability. |
| 3807 | */ |
| 3808 | @Override |
| 3809 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3810 | int transportType) { |
| 3811 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3812 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3813 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3814 | "IMS not available on device."); |
| 3815 | } |
| 3816 | final long token = Binder.clearCallingIdentity(); |
| 3817 | try { |
| 3818 | int slotId = getSlotIndex(subId); |
| 3819 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3820 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3821 | + subId + "'"); |
| 3822 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3823 | } |
| 3824 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3825 | transportType, aBoolean -> { |
| 3826 | try { |
| 3827 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3828 | } catch (RemoteException e) { |
| 3829 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3830 | + "running. Ignore"); |
| 3831 | } |
| 3832 | }); |
| 3833 | } finally { |
| 3834 | Binder.restoreCallingIdentity(token); |
| 3835 | } |
| 3836 | } |
| 3837 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3838 | /** |
| 3839 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3840 | * @param subId The subscription to use to check the configuration. |
| 3841 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3842 | @Override |
| 3843 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3844 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3845 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3846 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3847 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3848 | final long token = Binder.clearCallingIdentity(); |
| 3849 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3850 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3851 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3852 | } catch (ImsException e) { |
| 3853 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3854 | } finally { |
| 3855 | Binder.restoreCallingIdentity(token); |
| 3856 | } |
| 3857 | } |
| 3858 | |
| 3859 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3860 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3861 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3862 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3863 | final long identity = Binder.clearCallingIdentity(); |
| 3864 | try { |
| 3865 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3866 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3867 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3868 | } catch (ImsException e) { |
| 3869 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3870 | } finally { |
| 3871 | Binder.restoreCallingIdentity(identity); |
| 3872 | } |
| 3873 | } |
| 3874 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3875 | /** |
| 3876 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3877 | * @param subId The subscription to use to check the configuration. |
| 3878 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3879 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3880 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3881 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3882 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3883 | final long identity = Binder.clearCallingIdentity(); |
| 3884 | try { |
| 3885 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3886 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3887 | } catch (ImsException e) { |
| 3888 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3889 | } finally { |
| 3890 | Binder.restoreCallingIdentity(identity); |
| 3891 | } |
| 3892 | } |
| 3893 | |
| 3894 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3895 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3896 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3897 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3898 | final long identity = Binder.clearCallingIdentity(); |
| 3899 | try { |
| 3900 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3901 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3902 | } catch (ImsException e) { |
| 3903 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3904 | } finally { |
| 3905 | Binder.restoreCallingIdentity(identity); |
| 3906 | } |
| 3907 | } |
| 3908 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3909 | /** |
| 3910 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3911 | * @param subId The subscription to use to check the configuration. |
| 3912 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3913 | @Override |
| 3914 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3915 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3916 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3917 | final long identity = Binder.clearCallingIdentity(); |
| 3918 | try { |
| 3919 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3920 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3921 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3922 | } catch (ImsException e) { |
| 3923 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3924 | } finally { |
| 3925 | Binder.restoreCallingIdentity(identity); |
| 3926 | } |
| 3927 | } |
| 3928 | |
| 3929 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3930 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3931 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3932 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3933 | final long identity = Binder.clearCallingIdentity(); |
| 3934 | try { |
| 3935 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3936 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3937 | } catch (ImsException e) { |
| 3938 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3939 | } finally { |
| 3940 | Binder.restoreCallingIdentity(identity); |
| 3941 | } |
| 3942 | } |
| 3943 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3944 | /** |
| 3945 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3946 | * @param subId The subscription to use to check the configuration. |
| 3947 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3948 | @Override |
| 3949 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3950 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3951 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3952 | final long identity = Binder.clearCallingIdentity(); |
| 3953 | try { |
| 3954 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3955 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3956 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3957 | } catch (ImsException e) { |
| 3958 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3959 | } finally { |
| 3960 | Binder.restoreCallingIdentity(identity); |
| 3961 | } |
| 3962 | } |
| 3963 | |
| 3964 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3965 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3966 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3967 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3968 | final long identity = Binder.clearCallingIdentity(); |
| 3969 | try { |
| 3970 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3971 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3972 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3973 | } catch (ImsException e) { |
| 3974 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3975 | } finally { |
| 3976 | Binder.restoreCallingIdentity(identity); |
| 3977 | } |
| 3978 | } |
| 3979 | |
| 3980 | @Override |
| 3981 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3982 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3983 | "setVoWiFiNonPersistent"); |
| 3984 | final long identity = Binder.clearCallingIdentity(); |
| 3985 | try { |
| 3986 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3987 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3988 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3989 | } catch (ImsException e) { |
| 3990 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3991 | } finally { |
| 3992 | Binder.restoreCallingIdentity(identity); |
| 3993 | } |
| 3994 | } |
| 3995 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3996 | /** |
| 3997 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3998 | * @param subId The subscription to use to check the configuration. |
| 3999 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4000 | @Override |
| 4001 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4002 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4003 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4004 | final long identity = Binder.clearCallingIdentity(); |
| 4005 | try { |
| 4006 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4007 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4008 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4009 | } catch (ImsException e) { |
| 4010 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4011 | } finally { |
| 4012 | Binder.restoreCallingIdentity(identity); |
| 4013 | } |
| 4014 | } |
| 4015 | |
| 4016 | @Override |
| 4017 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4018 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4019 | "setVoWiFiModeSetting"); |
| 4020 | final long identity = Binder.clearCallingIdentity(); |
| 4021 | try { |
| 4022 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4023 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4024 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4025 | } catch (ImsException e) { |
| 4026 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4027 | } finally { |
| 4028 | Binder.restoreCallingIdentity(identity); |
| 4029 | } |
| 4030 | } |
| 4031 | |
| 4032 | @Override |
| 4033 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4034 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4035 | final long identity = Binder.clearCallingIdentity(); |
| 4036 | try { |
| 4037 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4038 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4039 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4040 | } catch (ImsException e) { |
| 4041 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4042 | } finally { |
| 4043 | Binder.restoreCallingIdentity(identity); |
| 4044 | } |
| 4045 | } |
| 4046 | |
| 4047 | @Override |
| 4048 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4049 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4050 | "setVoWiFiRoamingModeSetting"); |
| 4051 | final long identity = Binder.clearCallingIdentity(); |
| 4052 | try { |
| 4053 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4054 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4055 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4056 | } catch (ImsException e) { |
| 4057 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4058 | } finally { |
| 4059 | Binder.restoreCallingIdentity(identity); |
| 4060 | } |
| 4061 | } |
| 4062 | |
| 4063 | @Override |
| 4064 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4065 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4066 | "setRttCapabilityEnabled"); |
| 4067 | final long identity = Binder.clearCallingIdentity(); |
| 4068 | try { |
| 4069 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4070 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 4071 | } catch (ImsException e) { |
| 4072 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4073 | } finally { |
| 4074 | Binder.restoreCallingIdentity(identity); |
| 4075 | } |
| 4076 | } |
| 4077 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4078 | /** |
| 4079 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4080 | * @param subId The subscription to use to check the configuration. |
| 4081 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4082 | @Override |
| 4083 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4084 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4085 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4086 | final long identity = Binder.clearCallingIdentity(); |
| 4087 | try { |
| 4088 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4089 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4090 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4091 | } catch (ImsException e) { |
| 4092 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4093 | } finally { |
| 4094 | Binder.restoreCallingIdentity(identity); |
| 4095 | } |
| 4096 | } |
| 4097 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4098 | @Override |
| 4099 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4100 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4101 | final long identity = Binder.clearCallingIdentity(); |
| 4102 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4103 | if (!isImsAvailableOnDevice()) { |
| 4104 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4105 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4106 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4107 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4108 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4109 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4110 | } catch (ImsException e) { |
| 4111 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4112 | } finally { |
| 4113 | Binder.restoreCallingIdentity(identity); |
| 4114 | } |
| 4115 | } |
| 4116 | |
| 4117 | @Override |
| 4118 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4119 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4120 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4121 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4122 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4123 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4124 | try { |
| 4125 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4126 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4127 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4128 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4129 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4130 | + "is inactive, ignoring unregister."); |
| 4131 | // If the subscription is no longer active, just return, since the callback will already |
| 4132 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4133 | } finally { |
| 4134 | Binder.restoreCallingIdentity(identity); |
| 4135 | } |
| 4136 | } |
| 4137 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4138 | |
| 4139 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4140 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4141 | message); |
| 4142 | } |
| 4143 | |
| 4144 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4145 | boolean isMmtelCapability) { |
| 4146 | Phone phone = getPhone(subId); |
| 4147 | if (phone == null) { |
| 4148 | loge("phone instance null for subid " + subId); |
| 4149 | return false; |
| 4150 | } |
| 4151 | if (isMmtelCapability) { |
| 4152 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4153 | return false; |
| 4154 | } |
| 4155 | } else { |
| 4156 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4157 | return false; |
| 4158 | } |
| 4159 | } |
| 4160 | return true; |
| 4161 | } |
| 4162 | |
| 4163 | @Override |
| 4164 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4165 | boolean isProvisioned) { |
| 4166 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4167 | |
| 4168 | final long identity = Binder.clearCallingIdentity(); |
| 4169 | try { |
| 4170 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4171 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4172 | return; |
| 4173 | } |
| 4174 | |
| 4175 | // this capability requires provisioning, route to the correct API. |
| 4176 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4177 | switch (capability) { |
| 4178 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4179 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4180 | ims.setEabProvisioned(isProvisioned); |
| 4181 | break; |
| 4182 | default: { |
| 4183 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4184 | + "rcs capability '" + capability + "', which does not require " |
| 4185 | + "provisioning."); |
| 4186 | } |
| 4187 | } |
| 4188 | } finally { |
| 4189 | Binder.restoreCallingIdentity(identity); |
| 4190 | } |
| 4191 | |
| 4192 | } |
| 4193 | |
| 4194 | |
| 4195 | @Override |
| 4196 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4197 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4198 | final long identity = Binder.clearCallingIdentity(); |
| 4199 | try { |
| 4200 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4201 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4202 | return true; |
| 4203 | } |
| 4204 | |
| 4205 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4206 | switch (capability) { |
| 4207 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4208 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4209 | return ims.isEabProvisionedOnDevice(); |
| 4210 | |
| 4211 | default: { |
| 4212 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4213 | + "capability '" + capability + "', which does not require " |
| 4214 | + "provisioning."); |
| 4215 | } |
| 4216 | } |
| 4217 | |
| 4218 | } finally { |
| 4219 | Binder.restoreCallingIdentity(identity); |
| 4220 | } |
| 4221 | } |
| 4222 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4223 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4224 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4225 | boolean isProvisioned) { |
| 4226 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4227 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4228 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4229 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4230 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4231 | final long identity = Binder.clearCallingIdentity(); |
| 4232 | try { |
| 4233 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4234 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4235 | return; |
| 4236 | } |
| 4237 | |
| 4238 | // this capability requires provisioning, route to the correct API. |
| 4239 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4240 | switch (capability) { |
| 4241 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4242 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4243 | ims.setVolteProvisioned(isProvisioned); |
| 4244 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4245 | ims.setWfcProvisioned(isProvisioned); |
| 4246 | } |
| 4247 | break; |
| 4248 | } |
| 4249 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4250 | // There is currently no difference in VT provisioning type. |
| 4251 | ims.setVtProvisioned(isProvisioned); |
| 4252 | break; |
| 4253 | } |
| 4254 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4255 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4256 | // change the capability of the feature instead if needed. |
| 4257 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4258 | == isProvisioned) { |
| 4259 | // No change in provisioning. |
| 4260 | return; |
| 4261 | } |
| 4262 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4263 | try { |
| 4264 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4265 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4266 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4267 | + ", Exception" + e.getMessage()); |
| 4268 | } |
| 4269 | break; |
| 4270 | } |
| 4271 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4272 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4273 | + "MmTel capability '" + capability + "', which does not require " |
| 4274 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4275 | } |
| 4276 | } |
| 4277 | |
| 4278 | } finally { |
| 4279 | Binder.restoreCallingIdentity(identity); |
| 4280 | } |
| 4281 | } |
| 4282 | |
| 4283 | @Override |
| 4284 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4285 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4286 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4287 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4288 | } |
| 4289 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4290 | final long identity = Binder.clearCallingIdentity(); |
| 4291 | try { |
| 4292 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4293 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4294 | return true; |
| 4295 | } |
| 4296 | |
| 4297 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4298 | switch (capability) { |
| 4299 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4300 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4301 | return ims.isVolteProvisionedOnDevice(); |
| 4302 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4303 | return ims.isWfcProvisionedOnDevice(); |
| 4304 | } |
| 4305 | // This should never happen, since we are checking tech above to make sure it |
| 4306 | // is either LTE or IWLAN. |
| 4307 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4308 | + "capability."); |
| 4309 | } |
| 4310 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4311 | // There is currently no difference in VT provisioning type. |
| 4312 | return ims.isVtProvisionedOnDevice(); |
| 4313 | } |
| 4314 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4315 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4316 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4317 | } |
| 4318 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4319 | throw new IllegalArgumentException( |
| 4320 | "Tried to get provisioning for MmTel capability '" + capability |
| 4321 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4322 | } |
| 4323 | } |
| 4324 | |
| 4325 | } finally { |
| 4326 | Binder.restoreCallingIdentity(identity); |
| 4327 | } |
| 4328 | } |
| 4329 | |
| 4330 | @Override |
| 4331 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4332 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4333 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4334 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4335 | } |
| 4336 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4337 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4338 | return (provisionedBits & capability) > 0; |
| 4339 | } |
| 4340 | |
| 4341 | @Override |
| 4342 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4343 | boolean isProvisioned) { |
| 4344 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4345 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4346 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4347 | } |
| 4348 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4349 | "setProvisioningStatusForCapability"); |
| 4350 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4351 | // If the current provisioning status for capability already matches isProvisioned, |
| 4352 | // do nothing. |
| 4353 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4354 | return; |
| 4355 | } |
| 4356 | if (isProvisioned) { |
| 4357 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4358 | } else { |
| 4359 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4360 | } |
| 4361 | } |
| 4362 | |
| 4363 | /** |
| 4364 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4365 | * technology. The bitfield should mirror the bitfield defined by |
| 4366 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4367 | */ |
| 4368 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4369 | String key = getMmTelProvisioningKey(subId, tech); |
| 4370 | // Default is no capabilities are provisioned. |
| 4371 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4372 | } |
| 4373 | |
| 4374 | /** |
| 4375 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4376 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4377 | * technology specified. |
| 4378 | * |
| 4379 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4380 | */ |
| 4381 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4382 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4383 | String key = getMmTelProvisioningKey(subId, tech); |
| 4384 | editor.putInt(key, newField); |
| 4385 | editor.commit(); |
| 4386 | } |
| 4387 | |
| 4388 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4389 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4390 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4391 | } |
| 4392 | |
| 4393 | /** |
| 4394 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4395 | * carrier associated with the subscription id. |
| 4396 | */ |
| 4397 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4398 | int capability) { |
| 4399 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4400 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4401 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4402 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4403 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4404 | false); |
| 4405 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4406 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4407 | |
| 4408 | // First check to make sure that the capability requires provisioning. |
| 4409 | switch (capability) { |
| 4410 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4411 | // intentional fallthrough |
| 4412 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4413 | if (requireVoiceVtProvisioning) { |
| 4414 | // Voice and Video requires provisioning |
| 4415 | return true; |
| 4416 | } |
| 4417 | break; |
| 4418 | } |
| 4419 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4420 | if (requireUtProvisioning) { |
| 4421 | // UT requires provisioning |
| 4422 | return true; |
| 4423 | } |
| 4424 | break; |
| 4425 | } |
| 4426 | } |
| 4427 | return false; |
| 4428 | } |
| 4429 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4430 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4431 | int capability) { |
| 4432 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4433 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4434 | |
| 4435 | boolean requireRcsProvisioning = c.getBoolean( |
| 4436 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4437 | |
| 4438 | // First check to make sure that the capability requires provisioning. |
| 4439 | switch (capability) { |
| 4440 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4441 | // intentional fallthrough |
| 4442 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4443 | if (requireRcsProvisioning) { |
| 4444 | // OPTION or PRESENCE requires provisioning |
| 4445 | return true; |
| 4446 | } |
| 4447 | break; |
| 4448 | } |
| 4449 | } |
| 4450 | return false; |
| 4451 | } |
| 4452 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4453 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4454 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4455 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4456 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4457 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4458 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4459 | final long identity = Binder.clearCallingIdentity(); |
| 4460 | try { |
| 4461 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4462 | int slotId = getSlotIndex(subId); |
| 4463 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4464 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4465 | + subId + "' for key:" + key); |
| 4466 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4467 | } |
| 4468 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4469 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4470 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4471 | + subId + "' for key:" + key); |
| 4472 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4473 | } finally { |
| 4474 | Binder.restoreCallingIdentity(identity); |
| 4475 | } |
| 4476 | } |
| 4477 | |
| 4478 | @Override |
| 4479 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4480 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4481 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4482 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4483 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4484 | final long identity = Binder.clearCallingIdentity(); |
| 4485 | try { |
| 4486 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4487 | int slotId = getSlotIndex(subId); |
| 4488 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4489 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4490 | + subId + "' for key:" + key); |
| 4491 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4492 | } |
| 4493 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4494 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4495 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4496 | + subId + "' for key:" + key); |
| 4497 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4498 | } finally { |
| 4499 | Binder.restoreCallingIdentity(identity); |
| 4500 | } |
| 4501 | } |
| 4502 | |
| 4503 | @Override |
| 4504 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4505 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4506 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4507 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4508 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4509 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 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, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4516 | + subId + "' for key:" + key); |
| 4517 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4518 | } |
| 4519 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
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, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4522 | + "' for key:" + key); |
| 4523 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
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 setImsProvisioningString(int subId, int key, String 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 | "setImsProvisioningString"); |
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, "setImsProvisioningString: 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, "setImsProvisioningString: 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 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4555 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4556 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4557 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4558 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4559 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4560 | } |
| 4561 | return slotId; |
| 4562 | } |
| 4563 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4564 | private int getSlotIndex(int subId) { |
| 4565 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4566 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4567 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4568 | } |
| 4569 | return slotId; |
| 4570 | } |
| 4571 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4572 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4573 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4574 | */ |
| 4575 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4576 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4577 | String callingFeatureId) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4578 | final int targetSdk = getTargetSdk(callingPackage); |
| 4579 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4580 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4581 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4582 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4583 | mApp, subId, callingPackage, callingFeatureId, |
| 4584 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4585 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4586 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4587 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4588 | final long identity = Binder.clearCallingIdentity(); |
| 4589 | try { |
| 4590 | final Phone phone = getPhone(subId); |
| 4591 | if (phone != null) { |
| 4592 | return phone.getServiceState().getDataNetworkType(); |
| 4593 | } else { |
| 4594 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4595 | } |
| 4596 | } finally { |
| 4597 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4598 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4599 | } |
| 4600 | |
| 4601 | /** |
| 4602 | * Returns the data network type |
| 4603 | */ |
| 4604 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4605 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4606 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4607 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4608 | } |
| 4609 | |
| 4610 | /** |
| 4611 | * Returns the data network type for a subId |
| 4612 | */ |
| 4613 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4614 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4615 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4616 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4617 | mApp, subId, callingPackage, callingFeatureId, |
| 4618 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4619 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4620 | } |
| 4621 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4622 | final long identity = Binder.clearCallingIdentity(); |
| 4623 | try { |
| 4624 | final Phone phone = getPhone(subId); |
| 4625 | if (phone != null) { |
| 4626 | return phone.getServiceState().getDataNetworkType(); |
| 4627 | } else { |
| 4628 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4629 | } |
| 4630 | } finally { |
| 4631 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4632 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4633 | } |
| 4634 | |
| 4635 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4636 | * Returns the Voice network type for a subId |
| 4637 | */ |
| 4638 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4639 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4640 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4641 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4642 | mApp, subId, callingPackage, callingFeatureId, |
| 4643 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4644 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4645 | } |
| 4646 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4647 | final long identity = Binder.clearCallingIdentity(); |
| 4648 | try { |
| 4649 | final Phone phone = getPhone(subId); |
| 4650 | if (phone != null) { |
| 4651 | return phone.getServiceState().getVoiceNetworkType(); |
| 4652 | } else { |
| 4653 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4654 | } |
| 4655 | } finally { |
| 4656 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4657 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4658 | } |
| 4659 | |
| 4660 | /** |
| 4661 | * @return true if a ICC card is present |
| 4662 | */ |
| 4663 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4664 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4665 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4666 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4667 | } |
| 4668 | |
| 4669 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4670 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4671 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4672 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4673 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4674 | final long identity = Binder.clearCallingIdentity(); |
| 4675 | try { |
| 4676 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4677 | if (phone != null) { |
| 4678 | return phone.getIccCard().hasIccCard(); |
| 4679 | } else { |
| 4680 | return false; |
| 4681 | } |
| 4682 | } finally { |
| 4683 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4684 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4685 | } |
| 4686 | |
| 4687 | /** |
| 4688 | * Return if the current radio is LTE on CDMA. This |
| 4689 | * is a tri-state return value as for a period of time |
| 4690 | * the mode may be unknown. |
| 4691 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4692 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4693 | * @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] | 4694 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4695 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4696 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4697 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4698 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4699 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4700 | } |
| 4701 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4702 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4703 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4704 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4705 | try { |
| 4706 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4707 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4708 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4709 | } |
| 4710 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4711 | final long identity = Binder.clearCallingIdentity(); |
| 4712 | try { |
| 4713 | final Phone phone = getPhone(subId); |
| 4714 | if (phone == null) { |
| 4715 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4716 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4717 | return TelephonyProperties.lte_on_cdma_device() |
| 4718 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4719 | } |
| 4720 | } finally { |
| 4721 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4722 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4723 | } |
| 4724 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4725 | /** |
| 4726 | * {@hide} |
| 4727 | * Returns Default subId, 0 in the case of single standby. |
| 4728 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4729 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4730 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4731 | } |
| 4732 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4733 | private int getSlotForDefaultSubscription() { |
| 4734 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4735 | } |
| 4736 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4737 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4738 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4739 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4740 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4741 | private boolean isActiveSubscription(int subId) { |
| 4742 | return mSubscriptionController.isActiveSubId(subId); |
| 4743 | } |
| 4744 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4745 | /** |
| 4746 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4747 | */ |
| 4748 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4749 | final long identity = Binder.clearCallingIdentity(); |
| 4750 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4751 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4752 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4753 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4754 | } finally { |
| 4755 | Binder.restoreCallingIdentity(identity); |
| 4756 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4757 | } |
| 4758 | |
| 4759 | /** |
| 4760 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4761 | */ |
| 4762 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4763 | final long identity = Binder.clearCallingIdentity(); |
| 4764 | try { |
| 4765 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4766 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4767 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4768 | } finally { |
| 4769 | Binder.restoreCallingIdentity(identity); |
| 4770 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4771 | } |
| 4772 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4773 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4774 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4775 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4776 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4777 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4778 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4779 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4780 | if (phoneId == -1) { |
| 4781 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4782 | + " does not correspond to an active phone"); |
| 4783 | } |
| 4784 | return PhoneFactory.getPhone(phoneId); |
| 4785 | } |
| 4786 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4787 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4788 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4789 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4790 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4791 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4792 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4793 | if (DBG) { |
| 4794 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4795 | } |
| 4796 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4797 | p2); |
| 4798 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4799 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4800 | |
| 4801 | @Override |
| 4802 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4803 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4804 | enforceModifyPermission(); |
| 4805 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4806 | if (DBG) { |
| 4807 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4808 | } |
| 4809 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4810 | callingPackage, aid, p2); |
| 4811 | } |
| 4812 | |
| 4813 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4814 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4815 | final long identity = Binder.clearCallingIdentity(); |
| 4816 | try { |
| 4817 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4818 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4819 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4820 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4821 | if (bestComponent == null |
| 4822 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4823 | loge("The calling package is not allowed to access ISD-R."); |
| 4824 | throw new SecurityException( |
| 4825 | "The calling package is not allowed to access ISD-R."); |
| 4826 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4827 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4828 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4829 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4830 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4831 | null /* workSource */); |
| 4832 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4833 | return response; |
| 4834 | } finally { |
| 4835 | Binder.restoreCallingIdentity(identity); |
| 4836 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4837 | } |
| 4838 | |
| 4839 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4840 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4841 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4842 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4843 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4844 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4845 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4846 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4847 | @Override |
| 4848 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4849 | enforceModifyPermission(); |
| 4850 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4851 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4852 | channel); |
| 4853 | } |
| 4854 | |
| 4855 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4856 | final long identity = Binder.clearCallingIdentity(); |
| 4857 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4858 | if (channel < 0) { |
| 4859 | return false; |
| 4860 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4861 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4862 | null /* workSource */); |
| 4863 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4864 | return success; |
| 4865 | } finally { |
| 4866 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4867 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4868 | } |
| 4869 | |
| 4870 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4871 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4872 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4873 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4874 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4875 | if (DBG) { |
| 4876 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4877 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4878 | + p3 + " data=" + data); |
| 4879 | } |
| 4880 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4881 | command, p1, p2, p3, data); |
| 4882 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4883 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4884 | @Override |
| 4885 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4886 | int command, int p1, int p2, int p3, String data) { |
| 4887 | enforceModifyPermission(); |
| 4888 | if (DBG) { |
| 4889 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4890 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4891 | + p3 + " data=" + data); |
| 4892 | } |
| 4893 | return iccTransmitApduLogicalChannelWithPermission( |
| 4894 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4895 | data); |
| 4896 | } |
| 4897 | |
| 4898 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4899 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4900 | final long identity = Binder.clearCallingIdentity(); |
| 4901 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4902 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4903 | return ""; |
| 4904 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4905 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4906 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4907 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4908 | null /* workSource */); |
| 4909 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4910 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4911 | // Append the returned status code to the end of the response payload. |
| 4912 | String s = Integer.toHexString( |
| 4913 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4914 | if (response.payload != null) { |
| 4915 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4916 | } |
| 4917 | return s; |
| 4918 | } finally { |
| 4919 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4920 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4921 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4922 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4923 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4924 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4925 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4926 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4927 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4928 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4929 | if (DBG) { |
| 4930 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4931 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4932 | } |
| 4933 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4934 | cla, command, p1, p2, p3, data); |
| 4935 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4936 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4937 | @Override |
| 4938 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4939 | int command, int p1, int p2, int p3, String data) { |
| 4940 | enforceModifyPermission(); |
| 4941 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4942 | if (DBG) { |
| 4943 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4944 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4945 | + " data=" + data); |
| 4946 | } |
| 4947 | |
| 4948 | return iccTransmitApduBasicChannelWithPermission( |
| 4949 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4950 | p2, p3, data); |
| 4951 | } |
| 4952 | |
| 4953 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4954 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4955 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4956 | final long identity = Binder.clearCallingIdentity(); |
| 4957 | try { |
| 4958 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4959 | && TextUtils.equals(ISDR_AID, data)) { |
| 4960 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4961 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4962 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4963 | if (bestComponent == null |
| 4964 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4965 | loge("The calling package is not allowed to select ISD-R."); |
| 4966 | throw new SecurityException( |
| 4967 | "The calling package is not allowed to select ISD-R."); |
| 4968 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4969 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4970 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4971 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4972 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4973 | null /* workSource */); |
| 4974 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4975 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4976 | // Append the returned status code to the end of the response payload. |
| 4977 | String s = Integer.toHexString( |
| 4978 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4979 | if (response.payload != null) { |
| 4980 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4981 | } |
| 4982 | return s; |
| 4983 | } finally { |
| 4984 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4985 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4986 | } |
| 4987 | |
| 4988 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4989 | 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] | 4990 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4991 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4992 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4993 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4994 | final long identity = Binder.clearCallingIdentity(); |
| 4995 | try { |
| 4996 | if (DBG) { |
| 4997 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4998 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4999 | } |
| 5000 | |
| 5001 | IccIoResult response = |
| 5002 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5003 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5004 | subId); |
| 5005 | |
| 5006 | if (DBG) { |
| 5007 | log("Exchange SIM_IO [R]" + response); |
| 5008 | } |
| 5009 | |
| 5010 | byte[] result = null; |
| 5011 | int length = 2; |
| 5012 | if (response.payload != null) { |
| 5013 | length = 2 + response.payload.length; |
| 5014 | result = new byte[length]; |
| 5015 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5016 | } else { |
| 5017 | result = new byte[length]; |
| 5018 | } |
| 5019 | |
| 5020 | result[length - 1] = (byte) response.sw2; |
| 5021 | result[length - 2] = (byte) response.sw1; |
| 5022 | return result; |
| 5023 | } finally { |
| 5024 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5025 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5026 | } |
| 5027 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5028 | /** |
| 5029 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5030 | * on a particular subscription |
| 5031 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5032 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5033 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5034 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5035 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5036 | return null; |
| 5037 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5038 | |
| 5039 | final long identity = Binder.clearCallingIdentity(); |
| 5040 | try { |
| 5041 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5042 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5043 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5044 | return null; |
| 5045 | } |
| 5046 | Object response = sendRequest( |
| 5047 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5048 | if (response instanceof String[]) { |
| 5049 | return (String[]) response; |
| 5050 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5051 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5052 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5053 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5054 | } finally { |
| 5055 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5056 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5057 | } |
| 5058 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5059 | /** |
| 5060 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5061 | * subscription. |
| 5062 | * |
| 5063 | * @param subId the id of the subscription. |
| 5064 | * @param appType the uicc app type, must be USIM or SIM. |
| 5065 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5066 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5067 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5068 | * @return number of fplmns that is successfully written to the SIM. |
| 5069 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5070 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5071 | String callingFeatureId) { |
| 5072 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 5073 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5074 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 5075 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 5076 | } |
| 5077 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5078 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5079 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5080 | } |
| 5081 | if (fplmns == null) { |
| 5082 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5083 | } |
| 5084 | for (String fplmn : fplmns) { |
| 5085 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5086 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5087 | } |
| 5088 | } |
| 5089 | final long identity = Binder.clearCallingIdentity(); |
| 5090 | try { |
| 5091 | Object response = sendRequest( |
| 5092 | CMD_SET_FORBIDDEN_PLMNS, |
| 5093 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5094 | subId); |
| 5095 | return (int) response; |
| 5096 | } finally { |
| 5097 | Binder.restoreCallingIdentity(identity); |
| 5098 | } |
| 5099 | } |
| 5100 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5101 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5102 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5103 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5104 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5105 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5106 | final long identity = Binder.clearCallingIdentity(); |
| 5107 | try { |
| 5108 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5109 | if (response.payload == null) { |
| 5110 | return ""; |
| 5111 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5112 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5113 | // Append the returned status code to the end of the response payload. |
| 5114 | String s = Integer.toHexString( |
| 5115 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5116 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5117 | return s; |
| 5118 | } finally { |
| 5119 | Binder.restoreCallingIdentity(identity); |
| 5120 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5121 | } |
| 5122 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5123 | /** |
| 5124 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5125 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5126 | * |
| 5127 | * @param itemID the ID of the item to read |
| 5128 | * @return the NV item as a String, or null on error. |
| 5129 | */ |
| 5130 | @Override |
| 5131 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5132 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5133 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5134 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5135 | |
| 5136 | final long identity = Binder.clearCallingIdentity(); |
| 5137 | try { |
| 5138 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5139 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5140 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5141 | return value; |
| 5142 | } finally { |
| 5143 | Binder.restoreCallingIdentity(identity); |
| 5144 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5145 | } |
| 5146 | |
| 5147 | /** |
| 5148 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5149 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5150 | * |
| 5151 | * @param itemID the ID of the item to read |
| 5152 | * @param itemValue the value to write, as a String |
| 5153 | * @return true on success; false on any failure |
| 5154 | */ |
| 5155 | @Override |
| 5156 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5157 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5158 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5159 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5160 | |
| 5161 | final long identity = Binder.clearCallingIdentity(); |
| 5162 | try { |
| 5163 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5164 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5165 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5166 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5167 | return success; |
| 5168 | } finally { |
| 5169 | Binder.restoreCallingIdentity(identity); |
| 5170 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5171 | } |
| 5172 | |
| 5173 | /** |
| 5174 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5175 | * Used for device configuration by some CDMA operators. |
| 5176 | * |
| 5177 | * @param preferredRoamingList byte array containing the new PRL |
| 5178 | * @return true on success; false on any failure |
| 5179 | */ |
| 5180 | @Override |
| 5181 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5182 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5183 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5184 | |
| 5185 | final long identity = Binder.clearCallingIdentity(); |
| 5186 | try { |
| 5187 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5188 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5189 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5190 | return success; |
| 5191 | } finally { |
| 5192 | Binder.restoreCallingIdentity(identity); |
| 5193 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5194 | } |
| 5195 | |
| 5196 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5197 | * 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] | 5198 | * Used for device configuration by some CDMA operators. |
| 5199 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5200 | * @param slotIndex - device slot. |
| 5201 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5202 | * @return true on success; false on any failure |
| 5203 | */ |
| 5204 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5205 | public boolean resetModemConfig(int slotIndex) { |
| 5206 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5207 | if (phone != null) { |
| 5208 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5209 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5210 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5211 | final long identity = Binder.clearCallingIdentity(); |
| 5212 | try { |
| 5213 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5214 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5215 | return success; |
| 5216 | } finally { |
| 5217 | Binder.restoreCallingIdentity(identity); |
| 5218 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5219 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5220 | return false; |
| 5221 | } |
| 5222 | |
| 5223 | /** |
| 5224 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5225 | * |
| 5226 | * @param slotIndex - device slot. |
| 5227 | * |
| 5228 | * @return true on success; false on any failure |
| 5229 | */ |
| 5230 | @Override |
| 5231 | public boolean rebootModem(int slotIndex) { |
| 5232 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5233 | if (phone != null) { |
| 5234 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5235 | mApp, phone.getSubId(), "rebootModem"); |
| 5236 | |
| 5237 | final long identity = Binder.clearCallingIdentity(); |
| 5238 | try { |
| 5239 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5240 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5241 | return success; |
| 5242 | } finally { |
| 5243 | Binder.restoreCallingIdentity(identity); |
| 5244 | } |
| 5245 | } |
| 5246 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5247 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5248 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5249 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5250 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5251 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5252 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5253 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5254 | return new String[0]; |
| 5255 | } |
| 5256 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5257 | final long identity = Binder.clearCallingIdentity(); |
| 5258 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5259 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5260 | } finally { |
| 5261 | Binder.restoreCallingIdentity(identity); |
| 5262 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5263 | } |
| 5264 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5265 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5266 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5267 | * {@link #disableIms(int)}. |
| 5268 | * @param slotIndex device slot. |
| 5269 | */ |
| 5270 | public void resetIms(int slotIndex) { |
| 5271 | enforceModifyPermission(); |
| 5272 | |
| 5273 | final long identity = Binder.clearCallingIdentity(); |
| 5274 | try { |
| 5275 | if (mImsResolver == null) { |
| 5276 | // may happen if the does not support IMS. |
| 5277 | return; |
| 5278 | } |
| 5279 | mImsResolver.disableIms(slotIndex); |
| 5280 | mImsResolver.enableIms(slotIndex); |
| 5281 | } finally { |
| 5282 | Binder.restoreCallingIdentity(identity); |
| 5283 | } |
| 5284 | } |
| 5285 | |
| 5286 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5287 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5288 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5289 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5290 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5291 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5292 | |
| 5293 | final long identity = Binder.clearCallingIdentity(); |
| 5294 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5295 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5296 | // may happen if the device does not support IMS. |
| 5297 | return; |
| 5298 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5299 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5300 | } finally { |
| 5301 | Binder.restoreCallingIdentity(identity); |
| 5302 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5303 | } |
| 5304 | |
| 5305 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5306 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5307 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5308 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5309 | public void disableIms(int slotId) { |
| 5310 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5311 | |
| 5312 | final long identity = Binder.clearCallingIdentity(); |
| 5313 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5314 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5315 | // may happen if the device does not support IMS. |
| 5316 | return; |
| 5317 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5318 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5319 | } finally { |
| 5320 | Binder.restoreCallingIdentity(identity); |
| 5321 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5322 | } |
| 5323 | |
| 5324 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5325 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5326 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5327 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5328 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5329 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5330 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5331 | |
| 5332 | final long identity = Binder.clearCallingIdentity(); |
| 5333 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5334 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5335 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5336 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5337 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5338 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5339 | } finally { |
| 5340 | Binder.restoreCallingIdentity(identity); |
| 5341 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5342 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5343 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5344 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5345 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5346 | @Override |
| 5347 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5348 | enforceModifyPermission(); |
| 5349 | |
| 5350 | final long identity = Binder.clearCallingIdentity(); |
| 5351 | try { |
| 5352 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5353 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5354 | } finally { |
| 5355 | Binder.restoreCallingIdentity(identity); |
| 5356 | } |
| 5357 | } |
| 5358 | |
| 5359 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5360 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5361 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5362 | */ |
| 5363 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5364 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5365 | |
| 5366 | final long identity = Binder.clearCallingIdentity(); |
| 5367 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5368 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5369 | // may happen if the device does not support IMS. |
| 5370 | return null; |
| 5371 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5372 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5373 | } finally { |
| 5374 | Binder.restoreCallingIdentity(identity); |
| 5375 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5376 | } |
| 5377 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5378 | /** |
| 5379 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5380 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5381 | */ |
| 5382 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5383 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5384 | |
| 5385 | final long identity = Binder.clearCallingIdentity(); |
| 5386 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5387 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5388 | // may happen if the device does not support IMS. |
| 5389 | return null; |
| 5390 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5391 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5392 | } finally { |
| 5393 | Binder.restoreCallingIdentity(identity); |
| 5394 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5395 | } |
| 5396 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5397 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5398 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5399 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5400 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5401 | * @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] | 5402 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5403 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5404 | * @param packageName The name of the package that the current configuration will be replaced |
| 5405 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5406 | * @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] | 5407 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5408 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5409 | int[] featureTypes, String packageName) { |
| 5410 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5411 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5412 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5413 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5414 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5415 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5416 | final long identity = Binder.clearCallingIdentity(); |
| 5417 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5418 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5419 | // may happen if the device does not support IMS. |
| 5420 | return false; |
| 5421 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5422 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5423 | for (int featureType : featureTypes) { |
| 5424 | featureConfig.put(featureType, packageName); |
| 5425 | } |
| 5426 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5427 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5428 | } finally { |
| 5429 | Binder.restoreCallingIdentity(identity); |
| 5430 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5431 | } |
| 5432 | |
| 5433 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5434 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5435 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5436 | * |
| 5437 | * This should only be used for testing. |
| 5438 | * |
| 5439 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5440 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5441 | */ |
| 5442 | @Override |
| 5443 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5444 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5445 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5446 | "clearCarrierImsServiceOverride"); |
| 5447 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5448 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5449 | "clearCarrierImsServiceOverride"); |
| 5450 | |
| 5451 | final long identity = Binder.clearCallingIdentity(); |
| 5452 | try { |
| 5453 | if (mImsResolver == null) { |
| 5454 | // may happen if the device does not support IMS. |
| 5455 | return false; |
| 5456 | } |
| 5457 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5458 | } finally { |
| 5459 | Binder.restoreCallingIdentity(identity); |
| 5460 | } |
| 5461 | } |
| 5462 | |
| 5463 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5464 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5465 | * |
| 5466 | * @param slotId The slot that the ImsService is associated with. |
| 5467 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5468 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5469 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5470 | * @return the package name of the ImsService configuration. |
| 5471 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5472 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5473 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5474 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5475 | TelephonyPermissions |
| 5476 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5477 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5478 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5479 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5480 | final long identity = Binder.clearCallingIdentity(); |
| 5481 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5482 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5483 | // may happen if the device does not support IMS. |
| 5484 | return ""; |
| 5485 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5486 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5487 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5488 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5489 | } finally { |
| 5490 | Binder.restoreCallingIdentity(identity); |
| 5491 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5492 | } |
| 5493 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5494 | /** |
| 5495 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5496 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5497 | * @param callback A callback with an integer containing the |
| 5498 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5499 | */ |
| 5500 | @Override |
| 5501 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5502 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5503 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5504 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5505 | "IMS not available on device."); |
| 5506 | } |
| 5507 | final long token = Binder.clearCallingIdentity(); |
| 5508 | try { |
| 5509 | int slotId = getSlotIndex(subId); |
| 5510 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5511 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5512 | + subId + "'"); |
| 5513 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5514 | } |
| 5515 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5516 | try { |
| 5517 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5518 | } catch (RemoteException e) { |
| 5519 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5520 | + "Ignore"); |
| 5521 | } |
| 5522 | }); |
| 5523 | } finally { |
| 5524 | Binder.restoreCallingIdentity(token); |
| 5525 | } |
| 5526 | } |
| 5527 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5528 | public void setImsRegistrationState(boolean registered) { |
| 5529 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5530 | |
| 5531 | final long identity = Binder.clearCallingIdentity(); |
| 5532 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5533 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5534 | } finally { |
| 5535 | Binder.restoreCallingIdentity(identity); |
| 5536 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5537 | } |
| 5538 | |
| 5539 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5540 | * Set the network selection mode to automatic. |
| 5541 | * |
| 5542 | */ |
| 5543 | @Override |
| 5544 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5545 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5546 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5547 | |
| 5548 | final long identity = Binder.clearCallingIdentity(); |
| 5549 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5550 | if (!isActiveSubscription(subId)) { |
| 5551 | return; |
| 5552 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5553 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5554 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5555 | } finally { |
| 5556 | Binder.restoreCallingIdentity(identity); |
| 5557 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5558 | } |
| 5559 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5560 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5561 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5562 | * |
| 5563 | * @param subId the id of the subscription. |
| 5564 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5565 | * the operator to attach to. |
| 5566 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5567 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5568 | * normal network selection next time. |
| 5569 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5570 | */ |
| 5571 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5572 | public boolean setNetworkSelectionModeManual( |
| 5573 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5574 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5575 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5576 | |
| 5577 | if (!isActiveSubscription(subId)) { |
| 5578 | return false; |
| 5579 | } |
| 5580 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5581 | final long identity = Binder.clearCallingIdentity(); |
| 5582 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5583 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5584 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5585 | if (DBG) { |
| 5586 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5587 | + " operator: " + operatorInfo); |
| 5588 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5589 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5590 | } finally { |
| 5591 | Binder.restoreCallingIdentity(identity); |
| 5592 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5593 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5594 | /** |
| 5595 | * Get the manual network selection |
| 5596 | * |
| 5597 | * @param subId the id of the subscription. |
| 5598 | * |
| 5599 | * @return the previously saved user selected PLMN |
| 5600 | */ |
| 5601 | @Override |
| 5602 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5603 | TelephonyPermissions |
| 5604 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5605 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5606 | |
| 5607 | final long identity = Binder.clearCallingIdentity(); |
| 5608 | try { |
| 5609 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5610 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5611 | } |
| 5612 | |
| 5613 | final Phone phone = getPhone(subId); |
| 5614 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5615 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5616 | } |
| 5617 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5618 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5619 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5620 | } finally { |
| 5621 | Binder.restoreCallingIdentity(identity); |
| 5622 | } |
| 5623 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5624 | |
| 5625 | /** |
| 5626 | * Scans for available networks. |
| 5627 | */ |
| 5628 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5629 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5630 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5631 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5632 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5633 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5634 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5635 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5636 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5637 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5638 | .setCallingPid(Binder.getCallingPid()) |
| 5639 | .setCallingUid(Binder.getCallingUid()) |
| 5640 | .setMethod("getCellNetworkScanResults") |
| 5641 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 5642 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5643 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5644 | .build()); |
| 5645 | switch (locationResult) { |
| 5646 | case DENIED_HARD: |
| 5647 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5648 | case DENIED_SOFT: |
| 5649 | return null; |
| 5650 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5651 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5652 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5653 | try { |
| 5654 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5655 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5656 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5657 | } finally { |
| 5658 | Binder.restoreCallingIdentity(identity); |
| 5659 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5660 | } |
| 5661 | |
| 5662 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5663 | * Get the call forwarding info, given the call forwarding reason. |
| 5664 | */ |
| 5665 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5666 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5667 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5668 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5669 | long identity = Binder.clearCallingIdentity(); |
| 5670 | try { |
| 5671 | if (DBG) { |
| 5672 | log("getCallForwarding: subId " + subId |
| 5673 | + " callForwardingReason" + callForwardingReason); |
| 5674 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5675 | |
| 5676 | Phone phone = getPhone(subId); |
| 5677 | if (phone == null) { |
| 5678 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5679 | callback.onError( |
| 5680 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5681 | } catch (RemoteException e) { |
| 5682 | // ignore |
| 5683 | } |
| 5684 | return; |
| 5685 | } |
| 5686 | |
| 5687 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 5688 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 5689 | @Override |
| 5690 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 5691 | try { |
| 5692 | callback.onCallForwardingInfoAvailable(info); |
| 5693 | } catch (RemoteException e) { |
| 5694 | // ignore |
| 5695 | } |
| 5696 | } |
| 5697 | |
| 5698 | @Override |
| 5699 | public void onError(int error) { |
| 5700 | try { |
| 5701 | callback.onError(error); |
| 5702 | } catch (RemoteException e) { |
| 5703 | // ignore |
| 5704 | } |
| 5705 | } |
| 5706 | }); |
| 5707 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5708 | } finally { |
| 5709 | Binder.restoreCallingIdentity(identity); |
| 5710 | } |
| 5711 | } |
| 5712 | |
| 5713 | /** |
| 5714 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5715 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5716 | */ |
| 5717 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5718 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 5719 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5720 | enforceModifyPermission(); |
| 5721 | long identity = Binder.clearCallingIdentity(); |
| 5722 | try { |
| 5723 | if (DBG) { |
| 5724 | log("setCallForwarding: subId " + subId |
| 5725 | + " callForwardingInfo" + callForwardingInfo); |
| 5726 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5727 | |
| 5728 | Phone phone = getPhone(subId); |
| 5729 | if (phone == null) { |
| 5730 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5731 | callback.accept( |
| 5732 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5733 | } catch (RemoteException e) { |
| 5734 | // ignore |
| 5735 | } |
| 5736 | return; |
| 5737 | } |
| 5738 | |
| 5739 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 5740 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5741 | |
| 5742 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5743 | } finally { |
| 5744 | Binder.restoreCallingIdentity(identity); |
| 5745 | } |
| 5746 | } |
| 5747 | |
| 5748 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5749 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5750 | */ |
| 5751 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5752 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5753 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5754 | long identity = Binder.clearCallingIdentity(); |
| 5755 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5756 | |
| 5757 | Phone phone = getPhone(subId); |
| 5758 | if (phone == null) { |
| 5759 | try { |
| 5760 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5761 | } catch (RemoteException e) { |
| 5762 | // ignore |
| 5763 | } |
| 5764 | return; |
| 5765 | } |
| 5766 | |
| 5767 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 5768 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5769 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5770 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5771 | } finally { |
| 5772 | Binder.restoreCallingIdentity(identity); |
| 5773 | } |
| 5774 | } |
| 5775 | |
| 5776 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5777 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5778 | */ |
| 5779 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5780 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5781 | enforceModifyPermission(); |
| 5782 | long identity = Binder.clearCallingIdentity(); |
| 5783 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5784 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 5785 | |
| 5786 | Phone phone = getPhone(subId); |
| 5787 | if (phone == null) { |
| 5788 | try { |
| 5789 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5790 | } catch (RemoteException e) { |
| 5791 | // ignore |
| 5792 | } |
| 5793 | return; |
| 5794 | } |
| 5795 | |
| 5796 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 5797 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5798 | |
| 5799 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5800 | } finally { |
| 5801 | Binder.restoreCallingIdentity(identity); |
| 5802 | } |
| 5803 | } |
| 5804 | |
| 5805 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5806 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5807 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5808 | * @param subId id of the subscription |
| 5809 | * @param request contains the radio access networks with bands/channels to scan |
| 5810 | * @param messenger callback messenger for scan results or errors |
| 5811 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5812 | * @return the id of the requested scan which can be used to stop the scan. |
| 5813 | */ |
| 5814 | @Override |
| 5815 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5816 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5817 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5818 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5819 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5820 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5821 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5822 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5823 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5824 | .setCallingPid(Binder.getCallingPid()) |
| 5825 | .setCallingUid(Binder.getCallingUid()) |
| 5826 | .setMethod("requestNetworkScan") |
| 5827 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
James.cf Lin | 1d4d739 | 2020-07-03 18:22:53 +0800 | [diff] [blame] | 5828 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5829 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5830 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5831 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5832 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 5833 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5834 | if (e != null) { |
| 5835 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5836 | throw e; |
| 5837 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5838 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5839 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5840 | } |
| 5841 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5842 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5843 | int callingUid = Binder.getCallingUid(); |
| 5844 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5845 | final long identity = Binder.clearCallingIdentity(); |
| 5846 | try { |
| 5847 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5848 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5849 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5850 | } finally { |
| 5851 | Binder.restoreCallingIdentity(identity); |
| 5852 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5853 | } |
| 5854 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5855 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5856 | NetworkScanRequest request, int subId, String callingPackage) { |
| 5857 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5858 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5859 | boolean hasNetworkScanPermission = |
| 5860 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5861 | == PERMISSION_GRANTED; |
| 5862 | |
| 5863 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5864 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5865 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5866 | } |
| 5867 | |
| 5868 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5869 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5870 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5871 | return new SecurityException("Specific channels must not be" |
| 5872 | + " scanned without location access."); |
| 5873 | } |
| 5874 | } |
| 5875 | } |
| 5876 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5877 | return null; |
| 5878 | } |
| 5879 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5880 | /** |
| 5881 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5882 | * |
| 5883 | * @param subId id of the subscription |
| 5884 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5885 | */ |
| 5886 | @Override |
| 5887 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5888 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5889 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5890 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5891 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5892 | final long identity = Binder.clearCallingIdentity(); |
| 5893 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5894 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5895 | } finally { |
| 5896 | Binder.restoreCallingIdentity(identity); |
| 5897 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5898 | } |
| 5899 | |
| 5900 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5901 | * Get the calculated preferred network type. |
| 5902 | * Used for debugging incorrect network type. |
| 5903 | * |
| 5904 | * @return the preferred network type, defined in RILConstants.java. |
| 5905 | */ |
| 5906 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5907 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5908 | final Phone defaultPhone = getDefaultPhone(); |
| 5909 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5910 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5911 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5912 | } |
| 5913 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5914 | final long identity = Binder.clearCallingIdentity(); |
| 5915 | try { |
| 5916 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5917 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5918 | } finally { |
| 5919 | Binder.restoreCallingIdentity(identity); |
| 5920 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5921 | } |
| 5922 | |
| 5923 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5924 | * Get the preferred network type. |
| 5925 | * Used for device configuration by some CDMA operators. |
| 5926 | * |
| 5927 | * @return the preferred network type, defined in RILConstants.java. |
| 5928 | */ |
| 5929 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5930 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5931 | TelephonyPermissions |
| 5932 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5933 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5934 | |
| 5935 | final long identity = Binder.clearCallingIdentity(); |
| 5936 | try { |
| 5937 | if (DBG) log("getPreferredNetworkType"); |
| 5938 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5939 | int networkType = (result != null ? result[0] : -1); |
| 5940 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5941 | return networkType; |
| 5942 | } finally { |
| 5943 | Binder.restoreCallingIdentity(identity); |
| 5944 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5945 | } |
| 5946 | |
| 5947 | /** |
| 5948 | * Set the preferred network type. |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5949 | * |
| 5950 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5951 | * @return true on success; false on any failure. |
| 5952 | */ |
| 5953 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5954 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5955 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5956 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5957 | |
| 5958 | final long identity = Binder.clearCallingIdentity(); |
| 5959 | try { |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5960 | Boolean success = (Boolean) sendRequest( |
| 5961 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
calvinpan | 03641a7 | 2020-08-18 16:53:59 +0800 | [diff] [blame] | 5962 | |
| 5963 | if (success) { |
| 5964 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5965 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 5966 | } |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5967 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 5968 | return success; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5969 | } finally { |
| 5970 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5971 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5972 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5973 | |
| 5974 | /** |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5975 | * Get the allowed network types that store in the telephony provider. |
| 5976 | * |
| 5977 | * @param subId the id of the subscription. |
| 5978 | * @return allowedNetworkTypes the allowed network types. |
| 5979 | */ |
| 5980 | @Override |
| 5981 | public long getAllowedNetworkTypes(int subId) { |
| 5982 | TelephonyPermissions |
| 5983 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5984 | mApp, subId, "getAllowedNetworkTypes"); |
| 5985 | |
| 5986 | final long identity = Binder.clearCallingIdentity(); |
| 5987 | try { |
| 5988 | return SubscriptionManager.getLongSubscriptionProperty( |
| 5989 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5990 | } finally { |
| 5991 | Binder.restoreCallingIdentity(identity); |
| 5992 | } |
| 5993 | } |
| 5994 | |
| 5995 | /** |
| 5996 | * Set the allowed network types. |
| 5997 | * |
| 5998 | * @param subId the id of the subscription. |
| 5999 | * @param allowedNetworkTypes the allowed network types. |
| 6000 | * @return true on success; false on any failure. |
| 6001 | */ |
| 6002 | @Override |
| 6003 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 6004 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6005 | mApp, subId, "setAllowedNetworkTypes"); |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 6006 | |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 6007 | SubscriptionManager.setSubscriptionProperty(subId, |
| 6008 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 6009 | String.valueOf(allowedNetworkTypes)); |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 6010 | |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 6011 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 6012 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 6013 | RILConstants.PREFERRED_NETWORK_MODE); |
| 6014 | return setPreferredNetworkType(subId, preferredNetworkMode); |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 6015 | } |
| 6016 | |
| 6017 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6018 | * Get the allowed network types for certain reason. |
| 6019 | * |
| 6020 | * @param subId the id of the subscription. |
| 6021 | * @param reason the reason the allowed network type change is taking place |
| 6022 | * @return the allowed network types. |
| 6023 | */ |
| 6024 | @Override |
| 6025 | public long getAllowedNetworkTypesForReason(int subId, |
| 6026 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
| 6027 | TelephonyPermissions |
| 6028 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6029 | mApp, subId, "getAllowedNetworkTypesForReason"); |
| 6030 | final long identity = Binder.clearCallingIdentity(); |
| 6031 | try { |
| 6032 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6033 | } finally { |
| 6034 | Binder.restoreCallingIdentity(identity); |
| 6035 | } |
| 6036 | } |
| 6037 | |
| 6038 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6039 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6040 | * @param subId subscription id of the sim card |
| 6041 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6042 | * This can be passed following states |
| 6043 | * <ol> |
| 6044 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6045 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6046 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6047 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6048 | * </ol> |
| 6049 | * @return operation result. |
| 6050 | */ |
| 6051 | @Override |
| 6052 | public int setNrDualConnectivityState(int subId, |
| 6053 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6054 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6055 | mApp, subId, "enableNRDualConnectivity"); |
| 6056 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6057 | final long identity = Binder.clearCallingIdentity(); |
| 6058 | try { |
| 6059 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6060 | nrDualConnectivityState, subId, |
| 6061 | workSource); |
| 6062 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6063 | return result; |
| 6064 | } finally { |
| 6065 | Binder.restoreCallingIdentity(identity); |
| 6066 | } |
| 6067 | } |
| 6068 | |
| 6069 | /** |
| 6070 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6071 | * @return true if dual connectivity is enabled else false |
| 6072 | */ |
| 6073 | @Override |
| 6074 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6075 | TelephonyPermissions |
| 6076 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6077 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6078 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6079 | final long identity = Binder.clearCallingIdentity(); |
| 6080 | try { |
| 6081 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6082 | null, subId, workSource); |
| 6083 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6084 | return isEnabled; |
| 6085 | } finally { |
| 6086 | Binder.restoreCallingIdentity(identity); |
| 6087 | } |
| 6088 | } |
| 6089 | |
| 6090 | /** |
Sooraj Sasindran | 4deb887 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 6091 | * get carrier bandwidth per primary and secondary carrier |
| 6092 | * @param subId subscription id of the sim card |
| 6093 | * @return CarrierBandwidth with bandwidth of both primary and secondary carrier.. |
| 6094 | */ |
| 6095 | @Override |
| 6096 | public CarrierBandwidth getCarrierBandwidth(int subId) { |
| 6097 | TelephonyPermissions |
| 6098 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6099 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6100 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6101 | final long identity = Binder.clearCallingIdentity(); |
| 6102 | try { |
| 6103 | CarrierBandwidth carrierBandwidth = |
| 6104 | getPhoneFromSubId(subId).getCarrierBandwidth(); |
| 6105 | if (DBG) log("getCarrierBandwidth: " + carrierBandwidth); |
| 6106 | return carrierBandwidth; |
| 6107 | } finally { |
| 6108 | Binder.restoreCallingIdentity(identity); |
| 6109 | } |
| 6110 | } |
| 6111 | |
| 6112 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6113 | * Get the effective allowed network types on the device. |
| 6114 | * This API will return an intersection of allowed network types for all reasons, |
| 6115 | * including the configuration done through setAllowedNetworkTypes |
| 6116 | * |
| 6117 | * @param subId the id of the subscription. |
| 6118 | * @return the allowed network types |
| 6119 | */ |
| 6120 | @Override |
| 6121 | public long getEffectiveAllowedNetworkTypes(int subId) { |
| 6122 | TelephonyPermissions |
| 6123 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6124 | mApp, subId, "getEffectiveAllowedNetworkTypes"); |
| 6125 | final long identity = Binder.clearCallingIdentity(); |
| 6126 | try { |
| 6127 | return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes(); |
| 6128 | } finally { |
| 6129 | Binder.restoreCallingIdentity(identity); |
| 6130 | } |
| 6131 | } |
| 6132 | |
| 6133 | /** |
| 6134 | * Set the allowed network types of the device and |
| 6135 | * provide the reason triggering the allowed network change. |
| 6136 | * |
| 6137 | * @param subId the id of the subscription. |
| 6138 | * @param reason the reason the allowed network type change is taking place |
| 6139 | * @param allowedNetworkTypes the allowed network types. |
| 6140 | * @return true on success; false on any failure. |
| 6141 | */ |
| 6142 | @Override |
| 6143 | public boolean setAllowedNetworkTypesForReason(int subId, |
| 6144 | @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) { |
| 6145 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6146 | mApp, subId, "setAllowedNetworkTypesForReason"); |
| 6147 | final long identity = Binder.clearCallingIdentity(); |
| 6148 | try { |
| 6149 | getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes); |
| 6150 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 6151 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 6152 | RILConstants.PREFERRED_NETWORK_MODE); |
| 6153 | return setPreferredNetworkType(subId, preferredNetworkMode); |
| 6154 | } finally { |
| 6155 | Binder.restoreCallingIdentity(identity); |
| 6156 | } |
| 6157 | } |
| 6158 | |
| 6159 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6160 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6161 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6162 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6163 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6164 | * @hide |
| 6165 | */ |
| 6166 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6167 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6168 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6169 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6170 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6171 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6172 | if (phone != null) { |
| 6173 | return phone.hasMatchedTetherApnSetting(); |
| 6174 | } else { |
| 6175 | return false; |
| 6176 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6177 | } finally { |
| 6178 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6179 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6180 | } |
| 6181 | |
| 6182 | /** |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6183 | * Enable or disable always reporting signal strength changes from radio. |
| 6184 | * |
| 6185 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6186 | */ |
| 6187 | @Override |
| 6188 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6189 | enforceModifyPermission(); |
| 6190 | enforceSystemCaller(); |
| 6191 | |
| 6192 | final long identity = Binder.clearCallingIdentity(); |
| 6193 | final Phone phone = getPhone(subId); |
| 6194 | try { |
| 6195 | if (phone != null) { |
| 6196 | if (DBG) { |
| 6197 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6198 | + " isEnable=" + isEnable); |
| 6199 | } |
| 6200 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6201 | } else { |
| 6202 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6203 | + subId); |
| 6204 | } |
| 6205 | } finally { |
| 6206 | Binder.restoreCallingIdentity(identity); |
| 6207 | } |
| 6208 | } |
| 6209 | |
| 6210 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6211 | * Get the user enabled state of Mobile Data. |
| 6212 | * |
| 6213 | * TODO: remove and use isUserDataEnabled. |
| 6214 | * This can't be removed now because some vendor codes |
| 6215 | * calls through ITelephony directly while they should |
| 6216 | * use TelephonyManager. |
| 6217 | * |
| 6218 | * @return true on enabled |
| 6219 | */ |
| 6220 | @Override |
| 6221 | public boolean getDataEnabled(int subId) { |
| 6222 | return isUserDataEnabled(subId); |
| 6223 | } |
| 6224 | |
| 6225 | /** |
| 6226 | * Get whether mobile data is enabled per user setting. |
| 6227 | * |
| 6228 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6229 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6230 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6231 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6232 | * |
| 6233 | * @return {@code true} if data is enabled else {@code false} |
| 6234 | */ |
| 6235 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6236 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6237 | try { |
| 6238 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6239 | null); |
| 6240 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6241 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6242 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6243 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6244 | |
| 6245 | final long identity = Binder.clearCallingIdentity(); |
| 6246 | try { |
| 6247 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6248 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6249 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6250 | if (phone != null) { |
| 6251 | boolean retVal = phone.isUserDataEnabled(); |
| 6252 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6253 | return retVal; |
| 6254 | } else { |
| 6255 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6256 | return false; |
| 6257 | } |
| 6258 | } finally { |
| 6259 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6260 | } |
| 6261 | } |
| 6262 | |
| 6263 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6264 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6265 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6266 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6267 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6268 | * @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] | 6269 | */ |
| 6270 | @Override |
| 6271 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6272 | try { |
| 6273 | try { |
| 6274 | mApp.enforceCallingOrSelfPermission( |
| 6275 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6276 | null); |
| 6277 | } catch (Exception e) { |
| 6278 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6279 | "isDataEnabled"); |
| 6280 | } |
| 6281 | } catch (Exception e) { |
| 6282 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6283 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6284 | |
| 6285 | final long identity = Binder.clearCallingIdentity(); |
| 6286 | try { |
| 6287 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6288 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6289 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6290 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6291 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6292 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6293 | return retVal; |
| 6294 | } else { |
| 6295 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6296 | return false; |
| 6297 | } |
| 6298 | } finally { |
| 6299 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6300 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6301 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6302 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6303 | /** |
| 6304 | * Check if data is enabled for a specific reason |
| 6305 | * @param subId Subscription index |
| 6306 | * @param reason the reason the data enable change is taking place |
| 6307 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6308 | */ |
| 6309 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6310 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6311 | @TelephonyManager.DataEnabledReason int reason) { |
| 6312 | try { |
| 6313 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6314 | null); |
| 6315 | } catch (Exception e) { |
| 6316 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6317 | "isDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6318 | } |
| 6319 | |
| 6320 | |
| 6321 | final long identity = Binder.clearCallingIdentity(); |
| 6322 | try { |
| 6323 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6324 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6325 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6326 | + " reason=" + reason); |
| 6327 | } |
| 6328 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6329 | if (phone != null) { |
| 6330 | boolean retVal; |
| 6331 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6332 | retVal = phone.isUserDataEnabled(); |
| 6333 | } else { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6334 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6335 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6336 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6337 | return retVal; |
| 6338 | } else { |
| 6339 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6340 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6341 | + subId + " retVal=false"); |
| 6342 | } |
| 6343 | return false; |
| 6344 | } |
| 6345 | } finally { |
| 6346 | Binder.restoreCallingIdentity(identity); |
| 6347 | } |
| 6348 | } |
| 6349 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6350 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6351 | Phone phone) { |
Hall Liu | 54a2a0c | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6352 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 6353 | // Skip the check if it's one of these special uids |
| 6354 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6355 | } |
| 6356 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6357 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6358 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6359 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6360 | || subController == null) return privilegeFromSim; |
| 6361 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6362 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6363 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6364 | |
| 6365 | final long identity = Binder.clearCallingIdentity(); |
| 6366 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6367 | int subId = phone.getSubId(); |
| 6368 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6369 | // A test override is in place for the privileges for this subId, so don't try to |
| 6370 | // read the subscription privileges. |
| 6371 | return privilegeFromSim; |
| 6372 | } |
| 6373 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6374 | SubscriptionManager subManager = (SubscriptionManager) |
| 6375 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6376 | for (String pkg : packages) { |
| 6377 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6378 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6379 | } |
| 6380 | } |
| 6381 | return privilegeFromSim; |
| 6382 | } finally { |
| 6383 | Binder.restoreCallingIdentity(identity); |
| 6384 | } |
| 6385 | } |
| 6386 | |
| 6387 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6388 | String pkgName) { |
| 6389 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6390 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6391 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6392 | || subController == null) return privilegeFromSim; |
| 6393 | |
| 6394 | final long identity = Binder.clearCallingIdentity(); |
| 6395 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6396 | int subId = phone.getSubId(); |
| 6397 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6398 | // A test override is in place for the privileges for this subId, so don't try to |
| 6399 | // read the subscription privileges. |
| 6400 | return privilegeFromSim; |
| 6401 | } |
| 6402 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6403 | SubscriptionManager subManager = (SubscriptionManager) |
| 6404 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6405 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6406 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6407 | } finally { |
| 6408 | Binder.restoreCallingIdentity(identity); |
| 6409 | } |
| 6410 | } |
| 6411 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6412 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6413 | public int getCarrierPrivilegeStatus(int subId) { |
| 6414 | final Phone phone = getPhone(subId); |
| 6415 | if (phone == null) { |
| 6416 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6417 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6418 | } |
| 6419 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6420 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6421 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6422 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6423 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6424 | |
| 6425 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6426 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6427 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6428 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6429 | |
| 6430 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6431 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6432 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6433 | final Phone phone = getPhone(subId); |
| 6434 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6435 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6436 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6437 | } |
| 6438 | UiccProfile profile = |
| 6439 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6440 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6441 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6442 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6443 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6444 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6445 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6446 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6447 | } |
| 6448 | |
| 6449 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6450 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6451 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6452 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6453 | } |
| 6454 | |
| 6455 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6456 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6457 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6458 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6459 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6460 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6461 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6462 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6463 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6464 | } |
| 6465 | |
| 6466 | @Override |
| 6467 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6468 | if (TextUtils.isEmpty(pkgName)) |
| 6469 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6470 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6471 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6472 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6473 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6474 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6475 | continue; |
| 6476 | } |
| 6477 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6478 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6479 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6480 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6481 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6482 | break; |
| 6483 | } |
| 6484 | } |
| 6485 | |
| 6486 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6487 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6488 | |
| 6489 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6490 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6491 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6492 | loge("phoneId " + phoneId + " is not valid."); |
| 6493 | return null; |
| 6494 | } |
| 6495 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6496 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6497 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6498 | return null ; |
| 6499 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6500 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6501 | } |
| 6502 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6503 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6504 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6505 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6506 | List<String> privilegedPackages = new ArrayList<>(); |
| 6507 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6508 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6509 | // has UICC in that slot. |
| 6510 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6511 | if (card.hasCarrierPrivilegeRules()) { |
| 6512 | if (packages == null) { |
| 6513 | // Only check packages in user 0 for now |
| 6514 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6515 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6516 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6517 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6518 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6519 | } |
| 6520 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6521 | PackageInfo pkgInfo = packages.get(p); |
| 6522 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6523 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6524 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6525 | privilegedPackages.add(pkgInfo.packageName); |
| 6526 | } |
| 6527 | } |
| 6528 | } |
| 6529 | } |
| 6530 | return privilegedPackages; |
| 6531 | } |
| 6532 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6533 | @Override |
| 6534 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6535 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6536 | |
| 6537 | final long identity = Binder.clearCallingIdentity(); |
| 6538 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6539 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6540 | try { |
| 6541 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6542 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6543 | } |
| 6544 | } finally { |
| 6545 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6546 | } |
| 6547 | return privilegedPackages; |
| 6548 | } |
| 6549 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6550 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6551 | final Phone phone = getPhone(subId); |
| 6552 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6553 | if (card == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6554 | return null; |
| 6555 | } |
| 6556 | String iccId = card.getIccId(); |
| 6557 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6558 | return null; |
| 6559 | } |
| 6560 | return iccId; |
| 6561 | } |
| 6562 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6563 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6564 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6565 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6566 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6567 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6568 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6569 | final long identity = Binder.clearCallingIdentity(); |
| 6570 | try { |
| 6571 | final String iccId = getIccId(subId); |
| 6572 | final Phone phone = getPhone(subId); |
| 6573 | if (phone == null) { |
| 6574 | return false; |
| 6575 | } |
| 6576 | final String subscriberId = phone.getSubscriberId(); |
| 6577 | |
| 6578 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6579 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6580 | + subscriberId + " to " + number); |
| 6581 | } |
| 6582 | |
| 6583 | if (TextUtils.isEmpty(iccId)) { |
| 6584 | return false; |
| 6585 | } |
| 6586 | |
| 6587 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6588 | |
| 6589 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6590 | if (alphaTag == null) { |
| 6591 | editor.remove(alphaTagPrefKey); |
| 6592 | } else { |
| 6593 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6594 | } |
| 6595 | |
| 6596 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6597 | // track all merged IMSIs based on line number |
| 6598 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6599 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6600 | if (number == null) { |
| 6601 | editor.remove(numberPrefKey); |
| 6602 | editor.remove(subscriberPrefKey); |
| 6603 | } else { |
| 6604 | editor.putString(numberPrefKey, number); |
| 6605 | editor.putString(subscriberPrefKey, subscriberId); |
| 6606 | } |
| 6607 | |
| 6608 | editor.commit(); |
| 6609 | return true; |
| 6610 | } finally { |
| 6611 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6612 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6613 | } |
| 6614 | |
| 6615 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6616 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6617 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6618 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6619 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6620 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6621 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6622 | return null; |
| 6623 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6624 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6625 | final long identity = Binder.clearCallingIdentity(); |
| 6626 | try { |
| 6627 | String iccId = getIccId(subId); |
| 6628 | if (iccId != null) { |
| 6629 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6630 | if (DBG_MERGE) { |
| 6631 | log("getLine1NumberForDisplay returning " |
| 6632 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6633 | } |
| 6634 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6635 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6636 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6637 | return null; |
| 6638 | } finally { |
| 6639 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6640 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6641 | } |
| 6642 | |
| 6643 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6644 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6645 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6646 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6647 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6648 | return null; |
| 6649 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6650 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6651 | final long identity = Binder.clearCallingIdentity(); |
| 6652 | try { |
| 6653 | String iccId = getIccId(subId); |
| 6654 | if (iccId != null) { |
| 6655 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6656 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6657 | } |
| 6658 | return null; |
| 6659 | } finally { |
| 6660 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6661 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6662 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6663 | |
| 6664 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6665 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6666 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6667 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6668 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6669 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6670 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6671 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6672 | return null; |
| 6673 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6674 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6675 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6676 | // the process, where TelephonyManager was instantiated. |
| 6677 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6678 | final long identity = Binder.clearCallingIdentity(); |
| 6679 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6680 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6681 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6682 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6683 | |
| 6684 | // Figure out what subscribers are currently active |
| 6685 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6686 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6687 | // Only consider subs which match the current subId |
| 6688 | // This logic can be simplified. See b/131189269 for progress. |
| 6689 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6690 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6691 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6692 | |
| 6693 | // First pass, find a number override for an active subscriber |
| 6694 | String mergeNumber = null; |
| 6695 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6696 | for (String key : prefs.keySet()) { |
| 6697 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6698 | final String subscriberId = (String) prefs.get(key); |
| 6699 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6700 | final String iccId = key.substring( |
| 6701 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6702 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6703 | mergeNumber = (String) prefs.get(numberKey); |
| 6704 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6705 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6706 | + " for active subscriber " + subscriberId); |
| 6707 | } |
| 6708 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6709 | break; |
| 6710 | } |
| 6711 | } |
| 6712 | } |
| 6713 | } |
| 6714 | |
| 6715 | // Shortcut when no active merged subscribers |
| 6716 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6717 | return null; |
| 6718 | } |
| 6719 | |
| 6720 | // Second pass, find all subscribers under that line override |
| 6721 | final ArraySet<String> result = new ArraySet<>(); |
| 6722 | for (String key : prefs.keySet()) { |
| 6723 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6724 | final String number = (String) prefs.get(key); |
| 6725 | if (mergeNumber.equals(number)) { |
| 6726 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6727 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6728 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6729 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6730 | result.add(subscriberId); |
| 6731 | } |
| 6732 | } |
| 6733 | } |
| 6734 | } |
| 6735 | |
| 6736 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6737 | Arrays.sort(resultArray); |
| 6738 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6739 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6740 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6741 | } |
| 6742 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6743 | } finally { |
| 6744 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6745 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6746 | } |
| 6747 | |
| 6748 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6749 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6750 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6751 | |
| 6752 | final long identity = Binder.clearCallingIdentity(); |
| 6753 | try { |
| 6754 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6755 | TelephonyManager.class); |
| 6756 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6757 | if (subscriberId == null) { |
| 6758 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6759 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6760 | + subId); |
| 6761 | } |
| 6762 | return null; |
| 6763 | } |
| 6764 | |
| 6765 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6766 | .getSubscriptionInfo(subId); |
| 6767 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6768 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6769 | if (groupUuid == null) { |
| 6770 | return new String[]{subscriberId}; |
| 6771 | } |
| 6772 | |
| 6773 | // Get all subscriberIds from the group. |
| 6774 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6775 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6776 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6777 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6778 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6779 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6780 | if (subscriberId != null) { |
| 6781 | mergedSubscriberIds.add(subscriberId); |
| 6782 | } |
| 6783 | } |
| 6784 | |
| 6785 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6786 | } finally { |
| 6787 | Binder.restoreCallingIdentity(identity); |
| 6788 | |
| 6789 | } |
| 6790 | } |
| 6791 | |
| 6792 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6793 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6794 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6795 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6796 | |
| 6797 | final long identity = Binder.clearCallingIdentity(); |
| 6798 | try { |
| 6799 | final Phone phone = getPhone(subId); |
| 6800 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6801 | } finally { |
| 6802 | Binder.restoreCallingIdentity(identity); |
| 6803 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6804 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6805 | |
| 6806 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6807 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6808 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6809 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6810 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6811 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6812 | |
| 6813 | final long identity = Binder.clearCallingIdentity(); |
| 6814 | try { |
| 6815 | final Phone phone = getPhone(subId); |
| 6816 | if (phone == null) { |
| 6817 | return false; |
| 6818 | } |
| 6819 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6820 | cdmaNonRoamingList); |
| 6821 | } finally { |
| 6822 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6823 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6824 | } |
| 6825 | |
| 6826 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6827 | @Deprecated |
| 6828 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6829 | enforceModifyPermission(); |
| 6830 | |
| 6831 | int returnValue = 0; |
| 6832 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6833 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6834 | if(result.exception == null) { |
| 6835 | if (result.result != null) { |
| 6836 | byte[] responseData = (byte[])(result.result); |
| 6837 | if(responseData.length > oemResp.length) { |
| 6838 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6839 | responseData.length + "bytes. Buffer Size is " + |
| 6840 | oemResp.length + "bytes."); |
| 6841 | } |
| 6842 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6843 | returnValue = responseData.length; |
| 6844 | } |
| 6845 | } else { |
| 6846 | CommandException ex = (CommandException) result.exception; |
| 6847 | returnValue = ex.getCommandError().ordinal(); |
| 6848 | if(returnValue > 0) returnValue *= -1; |
| 6849 | } |
| 6850 | } catch (RuntimeException e) { |
| 6851 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6852 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6853 | if(returnValue > 0) returnValue *= -1; |
| 6854 | } |
| 6855 | |
| 6856 | return returnValue; |
| 6857 | } |
| 6858 | |
| 6859 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6860 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6861 | try { |
| 6862 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6863 | } catch (RuntimeException e) { |
| 6864 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6865 | } |
| 6866 | } |
| 6867 | |
| 6868 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6869 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6870 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 6871 | try { |
| 6872 | TelephonyPermissions |
| 6873 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6874 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6875 | } catch (SecurityException e) { |
| 6876 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 6877 | throw e; |
| 6878 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6879 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6880 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6881 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6882 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6883 | final long identity = Binder.clearCallingIdentity(); |
| 6884 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6885 | TelephonyPermissions |
| 6886 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6887 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6888 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6889 | } finally { |
| 6890 | Binder.restoreCallingIdentity(identity); |
| 6891 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6892 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6893 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6894 | |
| 6895 | @Override |
| 6896 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6897 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6898 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6899 | |
| 6900 | final long identity = Binder.clearCallingIdentity(); |
| 6901 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6902 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6903 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6904 | } finally { |
| 6905 | Binder.restoreCallingIdentity(identity); |
| 6906 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6907 | } |
| 6908 | |
| 6909 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6910 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6911 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6912 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6913 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6914 | return false; |
| 6915 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6916 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6917 | final long identity = Binder.clearCallingIdentity(); |
| 6918 | try { |
| 6919 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6920 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6921 | // In the long run, we may instead need to check if there exists a connection service |
| 6922 | // which can support video calling. |
| 6923 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6924 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6925 | return imsManager.isVtEnabledByPlatform() |
| 6926 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6927 | && imsManager.isVtEnabledByUser(); |
| 6928 | } finally { |
| 6929 | Binder.restoreCallingIdentity(identity); |
| 6930 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6931 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6932 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6933 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6934 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6935 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6936 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6937 | mApp, subId, callingPackage, callingFeatureId, |
| 6938 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6939 | return false; |
| 6940 | } |
| 6941 | |
| 6942 | final long identity = Binder.clearCallingIdentity(); |
| 6943 | try { |
| 6944 | CarrierConfigManager configManager = |
| 6945 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6946 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6947 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 6948 | } finally { |
| 6949 | Binder.restoreCallingIdentity(identity); |
| 6950 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6951 | } |
| 6952 | |
| 6953 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6954 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6955 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6956 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6957 | return false; |
| 6958 | } |
| 6959 | |
| 6960 | final long identity = Binder.clearCallingIdentity(); |
| 6961 | try { |
| 6962 | CarrierConfigManager configManager = |
| 6963 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6964 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6965 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 6966 | } finally { |
| 6967 | Binder.restoreCallingIdentity(identity); |
| 6968 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6969 | } |
| 6970 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6971 | @Override |
| 6972 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6973 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 6974 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6975 | } |
| 6976 | |
| 6977 | @Override |
| 6978 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6979 | final long identity = Binder.clearCallingIdentity(); |
| 6980 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6981 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6982 | } finally { |
| 6983 | Binder.restoreCallingIdentity(identity); |
| 6984 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6985 | } |
| 6986 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6987 | /** |
| 6988 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 6989 | * support for the feature and device firmware support. |
| 6990 | * |
| 6991 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 6992 | */ |
| 6993 | @Override |
| 6994 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6995 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6996 | final Phone phone = getPhone(subscriptionId); |
| 6997 | if (phone == null) { |
| 6998 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 6999 | return false; |
| 7000 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7001 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7002 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7003 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7004 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7005 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7006 | return isCarrierSupported && isDeviceSupported; |
| 7007 | } finally { |
| 7008 | Binder.restoreCallingIdentity(identity); |
| 7009 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7010 | } |
| 7011 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7012 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7013 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7014 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7015 | * 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] | 7016 | */ |
| 7017 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7018 | final long identity = Binder.clearCallingIdentity(); |
| 7019 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7020 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7021 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7022 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7023 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7024 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7025 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7026 | } finally { |
| 7027 | Binder.restoreCallingIdentity(identity); |
| 7028 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7029 | } |
| 7030 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7031 | @Deprecated |
| 7032 | @Override |
| 7033 | public String getDeviceId(String callingPackage) { |
| 7034 | return getDeviceIdWithFeature(callingPackage, null); |
| 7035 | } |
| 7036 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7037 | /** |
| 7038 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7039 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7040 | * |
| 7041 | * <p>Requires Permission: |
| 7042 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7043 | */ |
| 7044 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7045 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7046 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7047 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7048 | return null; |
| 7049 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7050 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7051 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7052 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7053 | return null; |
| 7054 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7055 | |
| 7056 | final long identity = Binder.clearCallingIdentity(); |
| 7057 | try { |
| 7058 | return phone.getDeviceId(); |
| 7059 | } finally { |
| 7060 | Binder.restoreCallingIdentity(identity); |
| 7061 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7062 | } |
| 7063 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7064 | /** |
| 7065 | * {@hide} |
| 7066 | * Returns the IMS Registration Status on a particular subid |
| 7067 | * |
| 7068 | * @param subId |
| 7069 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7070 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7071 | Phone phone = getPhone(subId); |
| 7072 | if (phone != null) { |
| 7073 | return phone.isImsRegistered(); |
| 7074 | } else { |
| 7075 | return false; |
| 7076 | } |
| 7077 | } |
| 7078 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7079 | @Override |
| 7080 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7081 | final long identity = Binder.clearCallingIdentity(); |
| 7082 | try { |
| 7083 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 7084 | } finally { |
| 7085 | Binder.restoreCallingIdentity(identity); |
| 7086 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7087 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7088 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7089 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7090 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7091 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7092 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7093 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7094 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7095 | } |
| 7096 | final long identity = Binder.clearCallingIdentity(); |
| 7097 | try { |
| 7098 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7099 | } finally { |
| 7100 | Binder.restoreCallingIdentity(identity); |
| 7101 | } |
| 7102 | } |
| 7103 | |
| 7104 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7105 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 7106 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 7107 | + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7108 | final long identity = Binder.clearCallingIdentity(); |
| 7109 | try { |
| 7110 | Phone phone = getPhone(subscriptionId); |
| 7111 | if (phone == null) { |
| 7112 | return null; |
| 7113 | } |
| 7114 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7115 | } finally { |
| 7116 | Binder.restoreCallingIdentity(identity); |
| 7117 | } |
| 7118 | } |
| 7119 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7120 | /** |
| 7121 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7122 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7123 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7124 | final long identity = Binder.clearCallingIdentity(); |
| 7125 | try { |
| 7126 | Phone phone = getPhone(subId); |
| 7127 | if (phone != null) { |
| 7128 | return phone.isWifiCallingEnabled(); |
| 7129 | } else { |
| 7130 | return false; |
| 7131 | } |
| 7132 | } finally { |
| 7133 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7134 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7135 | } |
| 7136 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7137 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7138 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7139 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7140 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7141 | final long identity = Binder.clearCallingIdentity(); |
| 7142 | try { |
| 7143 | Phone phone = getPhone(subId); |
| 7144 | if (phone != null) { |
| 7145 | return phone.isVideoEnabled(); |
| 7146 | } else { |
| 7147 | return false; |
| 7148 | } |
| 7149 | } finally { |
| 7150 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7151 | } |
| 7152 | } |
| 7153 | |
| 7154 | /** |
| 7155 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7156 | * defined in {@link ImsRegistrationImplBase}. |
| 7157 | */ |
| 7158 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7159 | final long identity = Binder.clearCallingIdentity(); |
| 7160 | try { |
| 7161 | Phone phone = getPhone(subId); |
| 7162 | if (phone != null) { |
| 7163 | return phone.getImsRegistrationTech(); |
| 7164 | } else { |
| 7165 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7166 | } |
| 7167 | } finally { |
| 7168 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7169 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7170 | } |
| 7171 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7172 | @Override |
| 7173 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7174 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7175 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7176 | return; |
| 7177 | } |
| 7178 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7179 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7180 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7181 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7182 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7183 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7184 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7185 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7186 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7187 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7188 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 7189 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7190 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7191 | // There has been issues when Sms raw table somehow stores orphan |
| 7192 | // fragments. They lead to garbled message when new fragments come |
| 7193 | // in and combined with those stale ones. In case this happens again, |
| 7194 | // user can reset all network settings which will clean up this table. |
| 7195 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7196 | // Clean up IMS settings as well here. |
| 7197 | int slotId = getSlotIndex(subId); |
| 7198 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7199 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7200 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7201 | |
| 7202 | // Erase modem config if erase modem on network setting is enabled. |
| 7203 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7204 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7205 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 7206 | sendEraseModemConfig(getDefaultPhone()); |
| 7207 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7208 | } finally { |
| 7209 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7210 | } |
| 7211 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7212 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7213 | private void cleanUpSmsRawTable(Context context) { |
| 7214 | ContentResolver resolver = context.getContentResolver(); |
| 7215 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7216 | resolver.delete(uri, null, null); |
| 7217 | } |
| 7218 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7219 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7220 | public String getSimLocaleForSubscriber(int subId) { |
| 7221 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7222 | final Phone phone = getPhone(subId); |
| 7223 | if (phone == null) { |
| 7224 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7225 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7226 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7227 | final long identity = Binder.clearCallingIdentity(); |
| 7228 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7229 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7230 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7231 | if (info == null) { |
| 7232 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7233 | return null; |
| 7234 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7235 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7236 | // preferences (EF-PL and EF-LI)... |
| 7237 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7238 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7239 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7240 | if (localeFromDefaultSim != null) { |
| 7241 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7242 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7243 | + localeFromDefaultSim); |
| 7244 | return localeFromDefaultSim.toLanguageTag(); |
| 7245 | } else { |
| 7246 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7247 | } |
| 7248 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7249 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7250 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7251 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7252 | // the SIM and carrier preferences does not include a country we add the country |
| 7253 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7254 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7255 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7256 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7257 | return mccLocale.toLanguageTag(); |
| 7258 | } |
| 7259 | |
| 7260 | if (DBG) log("No locale found - returning null"); |
| 7261 | return null; |
| 7262 | } finally { |
| 7263 | Binder.restoreCallingIdentity(identity); |
| 7264 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7265 | } |
| 7266 | |
| 7267 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7268 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7269 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7270 | } |
| 7271 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7272 | /** |
| 7273 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7274 | */ |
| 7275 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7276 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7277 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7278 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7279 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7280 | private final ModemActivityInfo mLastModemActivityInfo = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7281 | new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7282 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7283 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7284 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7285 | * representing the state of the modem. |
| 7286 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7287 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7288 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7289 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7290 | */ |
| 7291 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7292 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7293 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7294 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7295 | |
| 7296 | final long identity = Binder.clearCallingIdentity(); |
| 7297 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7298 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7299 | } finally { |
| 7300 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7301 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7302 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7303 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7304 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7305 | // less than total activity duration. |
| 7306 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7307 | if (info == null) { |
| 7308 | return false; |
| 7309 | } |
| 7310 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7311 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7312 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7313 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7314 | return (info.isValid() |
| 7315 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7316 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7317 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7318 | && (totalTxTimeMs <= activityDurationMs)); |
| 7319 | } |
| 7320 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7321 | /** |
| 7322 | * {@hide} |
| 7323 | * Returns the service state information on specified subscription. |
| 7324 | */ |
| 7325 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7326 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7327 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7328 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7329 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7330 | return null; |
| 7331 | } |
| 7332 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7333 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7334 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7335 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7336 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7337 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7338 | .setCallingPid(Binder.getCallingPid()) |
| 7339 | .setCallingUid(Binder.getCallingUid()) |
| 7340 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7341 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7342 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7343 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7344 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7345 | .build()); |
| 7346 | |
| 7347 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7348 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7349 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7350 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7351 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7352 | .setCallingPid(Binder.getCallingPid()) |
| 7353 | .setCallingUid(Binder.getCallingUid()) |
| 7354 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7355 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7356 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7357 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7358 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7359 | .build()); |
| 7360 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7361 | boolean hasFinePermission = |
| 7362 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7363 | boolean hasCoarsePermission = |
| 7364 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7365 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7366 | final Phone phone = getPhone(subId); |
| 7367 | if (phone == null) { |
| 7368 | return null; |
| 7369 | } |
| 7370 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 7371 | final long identity = Binder.clearCallingIdentity(); |
| 7372 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7373 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7374 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7375 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7376 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7377 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7378 | Rlog.d(LOG_TAG, |
| 7379 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7380 | return null; |
| 7381 | } |
| 7382 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7383 | ServiceState ss = phone.getServiceState(); |
| 7384 | |
| 7385 | // Scrub out the location info in ServiceState depending on what level of access |
| 7386 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7387 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7388 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7389 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7390 | } finally { |
| 7391 | Binder.restoreCallingIdentity(identity); |
| 7392 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7393 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7394 | |
| 7395 | /** |
| 7396 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7397 | * |
| 7398 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7399 | * voicemail ringtone. |
| 7400 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7401 | * PhoneAccount. |
| 7402 | */ |
| 7403 | @Override |
| 7404 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7405 | final long identity = Binder.clearCallingIdentity(); |
| 7406 | try { |
| 7407 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7408 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7409 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7410 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7411 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7412 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7413 | } finally { |
| 7414 | Binder.restoreCallingIdentity(identity); |
| 7415 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7416 | } |
| 7417 | |
| 7418 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7419 | * Sets the per-account voicemail ringtone. |
| 7420 | * |
| 7421 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7422 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7423 | * |
| 7424 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7425 | * voicemail ringtone. |
| 7426 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7427 | * PhoneAccount. |
| 7428 | */ |
| 7429 | @Override |
| 7430 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7431 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7432 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7433 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7434 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7435 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7436 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7437 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7438 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7439 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7440 | |
| 7441 | final long identity = Binder.clearCallingIdentity(); |
| 7442 | try { |
| 7443 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7444 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7445 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7446 | } |
| 7447 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7448 | } finally { |
| 7449 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7450 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7451 | } |
| 7452 | |
| 7453 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7454 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7455 | * |
| 7456 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7457 | * voicemail vibration setting. |
| 7458 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7459 | */ |
| 7460 | @Override |
| 7461 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7462 | final long identity = Binder.clearCallingIdentity(); |
| 7463 | try { |
| 7464 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7465 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7466 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7467 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7468 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7469 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7470 | } finally { |
| 7471 | Binder.restoreCallingIdentity(identity); |
| 7472 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7473 | } |
| 7474 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7475 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7476 | * Sets the per-account voicemail vibration. |
| 7477 | * |
| 7478 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7479 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7480 | * |
| 7481 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7482 | * voicemail vibration setting. |
| 7483 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7484 | * specific PhoneAccount. |
| 7485 | */ |
| 7486 | @Override |
| 7487 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7488 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7489 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7490 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7491 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7492 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7493 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7494 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7495 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7496 | } |
| 7497 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7498 | final long identity = Binder.clearCallingIdentity(); |
| 7499 | try { |
| 7500 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7501 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7502 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7503 | } |
| 7504 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7505 | } finally { |
| 7506 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7507 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7508 | } |
| 7509 | |
| 7510 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7511 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7512 | * |
| 7513 | * @throws SecurityException if the caller does not have the required permission |
| 7514 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7515 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7516 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7517 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7518 | } |
| 7519 | |
| 7520 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7521 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7522 | * permission. |
| 7523 | * |
| 7524 | * @throws SecurityException if the caller does not have the required permission |
| 7525 | */ |
| 7526 | private void enforceSendSmsPermission() { |
| 7527 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7528 | } |
| 7529 | |
| 7530 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7531 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7532 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7533 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7534 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7535 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7536 | final long identity = Binder.clearCallingIdentity(); |
| 7537 | try { |
| 7538 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7539 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7540 | if (componentName == null) { |
| 7541 | throw new SecurityException( |
| 7542 | "Caller not current active visual voicemail package[null]"); |
| 7543 | } |
| 7544 | String vvmPackage = componentName.getPackageName(); |
| 7545 | if (!callingPackage.equals(vvmPackage)) { |
| 7546 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7547 | + vvmPackage + "]"); |
| 7548 | } |
| 7549 | } finally { |
| 7550 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7551 | } |
| 7552 | } |
| 7553 | |
| 7554 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7555 | * Return the application ID for the app type. |
| 7556 | * |
| 7557 | * @param subId the subscription ID that this request applies to. |
| 7558 | * @param appType the uicc app type. |
| 7559 | * @return Application ID for specificied app type, or null if no uicc. |
| 7560 | */ |
| 7561 | @Override |
| 7562 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7563 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7564 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7565 | |
| 7566 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7567 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7568 | if (phone == null) { |
| 7569 | return null; |
| 7570 | } |
| 7571 | String aid = null; |
| 7572 | try { |
| 7573 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7574 | .getApplicationByType(appType).getAid(); |
| 7575 | } catch (Exception e) { |
| 7576 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7577 | } |
| 7578 | return aid; |
| 7579 | } finally { |
| 7580 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7581 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7582 | } |
| 7583 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7584 | /** |
| 7585 | * Return the Electronic Serial Number. |
| 7586 | * |
| 7587 | * @param subId the subscription ID that this request applies to. |
| 7588 | * @return ESN or null if error. |
| 7589 | */ |
| 7590 | @Override |
| 7591 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7592 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7593 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7594 | |
| 7595 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7596 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7597 | if (phone == null) { |
| 7598 | return null; |
| 7599 | } |
| 7600 | String esn = null; |
| 7601 | try { |
| 7602 | esn = phone.getEsn(); |
| 7603 | } catch (Exception e) { |
| 7604 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7605 | } |
| 7606 | return esn; |
| 7607 | } finally { |
| 7608 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7609 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7610 | } |
| 7611 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7612 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7613 | * Return the Preferred Roaming List Version. |
| 7614 | * |
| 7615 | * @param subId the subscription ID that this request applies to. |
| 7616 | * @return PRLVersion or null if error. |
| 7617 | */ |
| 7618 | @Override |
| 7619 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7620 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7621 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7622 | |
| 7623 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7624 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7625 | if (phone == null) { |
| 7626 | return null; |
| 7627 | } |
| 7628 | String cdmaPrlVersion = null; |
| 7629 | try { |
| 7630 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7631 | } catch (Exception e) { |
| 7632 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7633 | } |
| 7634 | return cdmaPrlVersion; |
| 7635 | } finally { |
| 7636 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7637 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7638 | } |
| 7639 | |
| 7640 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7641 | * Get snapshot of Telephony histograms |
| 7642 | * @return List of Telephony histograms |
| 7643 | * @hide |
| 7644 | */ |
| 7645 | @Override |
| 7646 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7647 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7648 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7649 | |
| 7650 | final long identity = Binder.clearCallingIdentity(); |
| 7651 | try { |
| 7652 | return RIL.getTelephonyRILTimingHistograms(); |
| 7653 | } finally { |
| 7654 | Binder.restoreCallingIdentity(identity); |
| 7655 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7656 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7657 | |
| 7658 | /** |
| 7659 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7660 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7661 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7662 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7663 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7664 | * @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] | 7665 | */ |
| 7666 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7667 | @TelephonyManager.SetCarrierRestrictionResult |
| 7668 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7669 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7670 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7671 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7672 | if (carrierRestrictionRules == null) { |
| 7673 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7674 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7675 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7676 | final long identity = Binder.clearCallingIdentity(); |
| 7677 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7678 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7679 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7680 | } finally { |
| 7681 | Binder.restoreCallingIdentity(identity); |
| 7682 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7683 | } |
| 7684 | |
| 7685 | /** |
| 7686 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7687 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7688 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7689 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7690 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7691 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7692 | */ |
| 7693 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7694 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7695 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7696 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7697 | |
| 7698 | final long identity = Binder.clearCallingIdentity(); |
| 7699 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7700 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7701 | if (response instanceof CarrierRestrictionRules) { |
| 7702 | return (CarrierRestrictionRules) response; |
| 7703 | } |
| 7704 | // Response is an Exception of some kind, |
| 7705 | // which is signalled to the user as a NULL retval |
| 7706 | return null; |
| 7707 | } catch (Exception e) { |
| 7708 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7709 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7710 | } finally { |
| 7711 | Binder.restoreCallingIdentity(identity); |
| 7712 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7713 | } |
| 7714 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7715 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7716 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7717 | * @param subId the subscription ID that this action applies to. |
| 7718 | * @param enabled control enable or disable radio. |
| 7719 | * {@hide} |
| 7720 | */ |
| 7721 | @Override |
| 7722 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7723 | enforceModifyPermission(); |
| 7724 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7725 | |
| 7726 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7727 | if (phone == null) { |
| 7728 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7729 | return; |
| 7730 | } |
| 7731 | try { |
| 7732 | phone.carrierActionSetRadioEnabled(enabled); |
| 7733 | } catch (Exception e) { |
| 7734 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7735 | } finally { |
| 7736 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7737 | } |
| 7738 | } |
| 7739 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7740 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7741 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7742 | * network status based on which carrier apps could apply actions accordingly, |
| 7743 | * enable/disable default url handler for example. |
| 7744 | * |
| 7745 | * @param subId the subscription ID that this action applies to. |
| 7746 | * @param report control start/stop reporting the default network status. |
| 7747 | * {@hide} |
| 7748 | */ |
| 7749 | @Override |
| 7750 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7751 | enforceModifyPermission(); |
| 7752 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7753 | |
| 7754 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7755 | if (phone == null) { |
| 7756 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7757 | return; |
| 7758 | } |
| 7759 | try { |
| 7760 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7761 | } catch (Exception e) { |
| 7762 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7763 | } finally { |
| 7764 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7765 | } |
| 7766 | } |
| 7767 | |
| 7768 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7769 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7770 | * @param subId the subscription ID that this action applies to. |
| 7771 | * {@hide} |
| 7772 | */ |
| 7773 | @Override |
| 7774 | public void carrierActionResetAll(int subId) { |
| 7775 | enforceModifyPermission(); |
| 7776 | final Phone phone = getPhone(subId); |
| 7777 | if (phone == null) { |
| 7778 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7779 | return; |
| 7780 | } |
| 7781 | try { |
| 7782 | phone.carrierActionResetAll(); |
| 7783 | } catch (Exception e) { |
| 7784 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7785 | } |
| 7786 | } |
| 7787 | |
| 7788 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7789 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7790 | * bug report is being generated. |
| 7791 | */ |
| 7792 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7793 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7794 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7795 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7796 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7797 | + Binder.getCallingPid() |
| 7798 | + ", uid=" + Binder.getCallingUid() |
| 7799 | + "without permission " |
| 7800 | + android.Manifest.permission.DUMP); |
| 7801 | return; |
| 7802 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7803 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7804 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7805 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7806 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7807 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7808 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7809 | @NonNull String[] args) { |
| 7810 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 7811 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 7812 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7813 | } |
| 7814 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7815 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7816 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 7817 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7818 | * @param reason the reason the data enable change is taking place |
| 7819 | * @param enabled True if enabling the data, otherwise disabling. |
| 7820 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7821 | */ |
| 7822 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7823 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7824 | boolean enabled) { |
| 7825 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 7826 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7827 | try { |
| 7828 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7829 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7830 | } catch (SecurityException se) { |
| 7831 | enforceModifyPermission(); |
| 7832 | } |
| 7833 | } else { |
| 7834 | enforceModifyPermission(); |
| 7835 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7836 | |
| 7837 | final long identity = Binder.clearCallingIdentity(); |
| 7838 | try { |
| 7839 | Phone phone = getPhone(subId); |
| 7840 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7841 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7842 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7843 | } else { |
| 7844 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 7845 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7846 | } |
| 7847 | } finally { |
| 7848 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7849 | } |
| 7850 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7851 | |
| 7852 | /** |
| 7853 | * Get Client request stats |
| 7854 | * @return List of Client Request Stats |
| 7855 | * @hide |
| 7856 | */ |
| 7857 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7858 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7859 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7860 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7861 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7862 | return null; |
| 7863 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7864 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7865 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7866 | final long identity = Binder.clearCallingIdentity(); |
| 7867 | try { |
| 7868 | if (phone != null) { |
| 7869 | return phone.getClientRequestStats(); |
| 7870 | } |
| 7871 | |
| 7872 | return null; |
| 7873 | } finally { |
| 7874 | Binder.restoreCallingIdentity(identity); |
| 7875 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7876 | } |
| 7877 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7878 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7879 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7880 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7881 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7882 | |
| 7883 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7884 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7885 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7886 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7887 | * @param state State of SIM (power down, power up, pass through) |
| 7888 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7889 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7890 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7891 | * |
| 7892 | **/ |
| 7893 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7894 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7895 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7896 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7897 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7898 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7899 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7900 | final long identity = Binder.clearCallingIdentity(); |
| 7901 | try { |
| 7902 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 7903 | phone.setSimPowerState(state, null, workSource); |
| 7904 | } |
| 7905 | } finally { |
| 7906 | Binder.restoreCallingIdentity(identity); |
| 7907 | } |
| 7908 | } |
| 7909 | |
| 7910 | /** |
| 7911 | * Set SIM card power state. |
| 7912 | * |
| 7913 | * @param slotIndex SIM slot id. |
| 7914 | * @param state State of SIM (power down, power up, pass through) |
| 7915 | * @param callback callback to trigger after success or failure |
| 7916 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7917 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7918 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 7919 | * |
| 7920 | **/ |
| 7921 | @Override |
| 7922 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 7923 | IIntegerConsumer callback) { |
| 7924 | enforceModifyPermission(); |
| 7925 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7926 | |
| 7927 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7928 | |
| 7929 | final long identity = Binder.clearCallingIdentity(); |
| 7930 | try { |
| 7931 | if (phone != null) { |
| 7932 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 7933 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7934 | } |
| 7935 | } finally { |
| 7936 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7937 | } |
| 7938 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7939 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7940 | private boolean isUssdApiAllowed(int subId) { |
| 7941 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7942 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7943 | if (configManager == null) { |
| 7944 | return false; |
| 7945 | } |
| 7946 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 7947 | if (pb == null) { |
| 7948 | return false; |
| 7949 | } |
| 7950 | return pb.getBoolean( |
| 7951 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 7952 | } |
| 7953 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7954 | /** |
| 7955 | * Check if phone is in emergency callback mode |
| 7956 | * @return true if phone is in emergency callback mode |
| 7957 | * @param subId sub id |
| 7958 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7959 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7960 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7961 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7962 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7963 | |
| 7964 | final long identity = Binder.clearCallingIdentity(); |
| 7965 | try { |
| 7966 | if (phone != null) { |
| 7967 | return phone.isInEcm(); |
| 7968 | } else { |
| 7969 | return false; |
| 7970 | } |
| 7971 | } finally { |
| 7972 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7973 | } |
| 7974 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7975 | |
| 7976 | /** |
| 7977 | * Get the current signal strength information for the given subscription. |
| 7978 | * Because this information is not updated when the device is in a low power state |
| 7979 | * it should not be relied-upon to be current. |
| 7980 | * @param subId Subscription index |
| 7981 | * @return the most recent cached signal strength info from the modem |
| 7982 | */ |
| 7983 | @Override |
| 7984 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7985 | final long identity = Binder.clearCallingIdentity(); |
| 7986 | try { |
| 7987 | Phone p = getPhone(subId); |
| 7988 | if (p == null) { |
| 7989 | return null; |
| 7990 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7991 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7992 | return p.getSignalStrength(); |
| 7993 | } finally { |
| 7994 | Binder.restoreCallingIdentity(identity); |
| 7995 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7996 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7997 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7998 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7999 | * Get the current modem radio state for the given slot. |
| 8000 | * @param slotIndex slot index. |
| 8001 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8002 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8003 | * @return the current radio power state from the modem |
| 8004 | */ |
| 8005 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8006 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8007 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8008 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8009 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8010 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8011 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8012 | } |
| 8013 | |
| 8014 | final long identity = Binder.clearCallingIdentity(); |
| 8015 | try { |
| 8016 | return phone.getRadioPowerState(); |
| 8017 | } finally { |
| 8018 | Binder.restoreCallingIdentity(identity); |
| 8019 | } |
| 8020 | } |
| 8021 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8022 | } |
| 8023 | |
| 8024 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8025 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8026 | * |
| 8027 | * <p>Requires one of the following permissions: |
| 8028 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 8029 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8030 | * privileges. |
| 8031 | * |
| 8032 | * @param subId subscription id |
| 8033 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8034 | * {@code false}. |
| 8035 | */ |
| 8036 | @Override |
| 8037 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8038 | try { |
| 8039 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8040 | null); |
| 8041 | } catch (Exception e) { |
| 8042 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 8043 | mApp, subId, "isDataRoamingEnabled"); |
| 8044 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8045 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8046 | boolean isEnabled = false; |
| 8047 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8048 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8049 | Phone phone = getPhone(subId); |
| 8050 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8051 | } finally { |
| 8052 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8053 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8054 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8055 | } |
| 8056 | |
| 8057 | |
| 8058 | /** |
| 8059 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8060 | * |
| 8061 | * <p> Requires permission: |
| 8062 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8063 | * privileges. |
| 8064 | * |
| 8065 | * @param subId subscription id |
| 8066 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8067 | */ |
| 8068 | @Override |
| 8069 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8070 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8071 | mApp, subId, "setDataRoamingEnabled"); |
| 8072 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8073 | final long identity = Binder.clearCallingIdentity(); |
| 8074 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8075 | Phone phone = getPhone(subId); |
| 8076 | if (phone != null) { |
| 8077 | phone.setDataRoamingEnabled(isEnabled); |
| 8078 | } |
| 8079 | } finally { |
| 8080 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8081 | } |
| 8082 | } |
| 8083 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8084 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8085 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8086 | TelephonyPermissions |
| 8087 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8088 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8089 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8090 | boolean isAllowed = true; |
| 8091 | final long identity = Binder.clearCallingIdentity(); |
| 8092 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8093 | Phone phone = getPhone(subId); |
| 8094 | if (phone != null) { |
| 8095 | isAllowed = phone.isCspPlmnEnabled(); |
| 8096 | } |
| 8097 | } finally { |
| 8098 | Binder.restoreCallingIdentity(identity); |
| 8099 | } |
| 8100 | return isAllowed; |
| 8101 | } |
| 8102 | |
| 8103 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8104 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8105 | // Verify that tha callingPackage belongs to the calling UID |
| 8106 | mApp.getSystemService(AppOpsManager.class) |
| 8107 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8108 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8109 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8110 | try { |
| 8111 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8112 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8113 | } catch (SecurityException e) { |
| 8114 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8115 | // has carrier privileges on an active UICC |
| 8116 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8117 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8118 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8119 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8120 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8121 | |
| 8122 | final long identity = Binder.clearCallingIdentity(); |
| 8123 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8124 | UiccController uiccController = UiccController.getInstance(); |
| 8125 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8126 | if (hasReadPermission) { |
| 8127 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8128 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8129 | |
| 8130 | // Remove private info if the caller doesn't have access |
| 8131 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8132 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8133 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8134 | // is available |
| 8135 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 8136 | if (card == null || card.getUiccProfile() == null) { |
| 8137 | // assume no access if the card or profile is unavailable |
| 8138 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8139 | continue; |
| 8140 | } |
| 8141 | UiccProfile profile = card.getUiccProfile(); |
| 8142 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8143 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8144 | filteredInfos.add(cardInfo); |
| 8145 | } else { |
| 8146 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8147 | } |
| 8148 | } |
| 8149 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8150 | } finally { |
| 8151 | Binder.restoreCallingIdentity(identity); |
| 8152 | } |
| 8153 | } |
| 8154 | |
| 8155 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8156 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8157 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8158 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8159 | final long identity = Binder.clearCallingIdentity(); |
| 8160 | try { |
| 8161 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8162 | if (slots == null) { |
| 8163 | Rlog.i(LOG_TAG, "slots is null."); |
| 8164 | return null; |
| 8165 | } |
| 8166 | |
| 8167 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8168 | for (int i = 0; i < slots.length; i++) { |
| 8169 | UiccSlot slot = slots[i]; |
| 8170 | if (slot == null) { |
| 8171 | continue; |
| 8172 | } |
| 8173 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8174 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8175 | UiccCard card = slot.getUiccCard(); |
| 8176 | if (card != null) { |
| 8177 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8178 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8179 | cardId = slot.getEid(); |
| 8180 | if (TextUtils.isEmpty(cardId)) { |
| 8181 | cardId = slot.getIccId(); |
| 8182 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8183 | } |
| 8184 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8185 | if (cardId != null) { |
| 8186 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8187 | // if cardId is an EID, it's all digits so this is fine |
| 8188 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8189 | } |
| 8190 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8191 | int cardState = 0; |
| 8192 | switch (slot.getCardState()) { |
| 8193 | case CARDSTATE_ABSENT: |
| 8194 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8195 | break; |
| 8196 | case CARDSTATE_PRESENT: |
| 8197 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8198 | break; |
| 8199 | case CARDSTATE_ERROR: |
| 8200 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8201 | break; |
| 8202 | case CARDSTATE_RESTRICTED: |
| 8203 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8204 | break; |
| 8205 | default: |
| 8206 | break; |
| 8207 | |
| 8208 | } |
| 8209 | |
| 8210 | infos[i] = new UiccSlotInfo( |
| 8211 | slot.isActive(), |
| 8212 | slot.isEuicc(), |
| 8213 | cardId, |
| 8214 | cardState, |
| 8215 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8216 | slot.isExtendedApduSupported(), |
| 8217 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8218 | } |
| 8219 | return infos; |
| 8220 | } finally { |
| 8221 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8222 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8223 | } |
| 8224 | |
| 8225 | @Override |
| 8226 | public boolean switchSlots(int[] physicalSlots) { |
| 8227 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8228 | |
| 8229 | final long identity = Binder.clearCallingIdentity(); |
| 8230 | try { |
| 8231 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8232 | } finally { |
| 8233 | Binder.restoreCallingIdentity(identity); |
| 8234 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8235 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8236 | |
| 8237 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8238 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8239 | final long identity = Binder.clearCallingIdentity(); |
| 8240 | try { |
| 8241 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8242 | } finally { |
| 8243 | Binder.restoreCallingIdentity(identity); |
| 8244 | } |
| 8245 | } |
| 8246 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8247 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8248 | * A test API to reload the UICC profile. |
| 8249 | * |
| 8250 | * <p>Requires that the calling app has permission |
| 8251 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8252 | * @hide |
| 8253 | */ |
| 8254 | @Override |
| 8255 | public void refreshUiccProfile(int subId) { |
| 8256 | enforceModifyPermission(); |
| 8257 | |
| 8258 | final long identity = Binder.clearCallingIdentity(); |
| 8259 | try { |
| 8260 | Phone phone = getPhone(subId); |
| 8261 | if (phone == null) { |
| 8262 | return; |
| 8263 | } |
| 8264 | UiccCard uiccCard = phone.getUiccCard(); |
| 8265 | if (uiccCard == null) { |
| 8266 | return; |
| 8267 | } |
| 8268 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8269 | if (uiccProfile == null) { |
| 8270 | return; |
| 8271 | } |
| 8272 | uiccProfile.refresh(); |
| 8273 | } finally { |
| 8274 | Binder.restoreCallingIdentity(identity); |
| 8275 | } |
| 8276 | } |
| 8277 | |
| 8278 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8279 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8280 | */ |
| 8281 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8282 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8283 | } |
| 8284 | |
| 8285 | /** |
| 8286 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8287 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8288 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8289 | */ |
| 8290 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8291 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8292 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8293 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8294 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8295 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8296 | return isDataRoamingEnabled; |
| 8297 | } |
| 8298 | |
| 8299 | /** |
| 8300 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8301 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8302 | */ |
| 8303 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8304 | List<Integer> list = TelephonyProperties.default_network(); |
| 8305 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8306 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8307 | return list.get(phoneId); |
| 8308 | } |
| 8309 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8310 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8311 | |
| 8312 | @Override |
| 8313 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8314 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8315 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8316 | |
| 8317 | final long identity = Binder.clearCallingIdentity(); |
| 8318 | try { |
| 8319 | final Phone phone = getPhone(subId); |
| 8320 | if (phone == null) { |
| 8321 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8322 | return; |
| 8323 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8324 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8325 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8326 | if (carrierPrivilegeRules == null) { |
| 8327 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8328 | } else { |
| 8329 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8330 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8331 | } finally { |
| 8332 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8333 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8334 | } |
| 8335 | |
| 8336 | @Override |
| 8337 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8338 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8339 | |
| 8340 | final long identity = Binder.clearCallingIdentity(); |
| 8341 | try { |
| 8342 | final Phone phone = getPhone(subId); |
| 8343 | if (phone == null) { |
| 8344 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8345 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8346 | } |
| 8347 | return phone.getCarrierIdListVersion(); |
| 8348 | } finally { |
| 8349 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8350 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8351 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8352 | |
| 8353 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8354 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8355 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8356 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8357 | mApp, subId, callingPackage, callingFeatureId, |
| 8358 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8359 | return -1; |
| 8360 | } |
| 8361 | |
| 8362 | final long identity = Binder.clearCallingIdentity(); |
| 8363 | try { |
| 8364 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8365 | } finally { |
| 8366 | Binder.restoreCallingIdentity(identity); |
| 8367 | } |
| 8368 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8369 | |
| 8370 | @Override |
| 8371 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8372 | TelephonyPermissions |
| 8373 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8374 | mApp, subId, "getCdmaRoamingMode"); |
| 8375 | |
| 8376 | final long identity = Binder.clearCallingIdentity(); |
| 8377 | try { |
| 8378 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8379 | } finally { |
| 8380 | Binder.restoreCallingIdentity(identity); |
| 8381 | } |
| 8382 | } |
| 8383 | |
| 8384 | @Override |
| 8385 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8386 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8387 | mApp, subId, "setCdmaRoamingMode"); |
| 8388 | |
| 8389 | final long identity = Binder.clearCallingIdentity(); |
| 8390 | try { |
| 8391 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8392 | } finally { |
| 8393 | Binder.restoreCallingIdentity(identity); |
| 8394 | } |
| 8395 | } |
| 8396 | |
| 8397 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8398 | public int getCdmaSubscriptionMode(int subId) { |
| 8399 | TelephonyPermissions |
| 8400 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8401 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8402 | |
| 8403 | final long identity = Binder.clearCallingIdentity(); |
| 8404 | try { |
| 8405 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8406 | } finally { |
| 8407 | Binder.restoreCallingIdentity(identity); |
| 8408 | } |
| 8409 | } |
| 8410 | |
| 8411 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8412 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8413 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8414 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8415 | |
| 8416 | final long identity = Binder.clearCallingIdentity(); |
| 8417 | try { |
| 8418 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8419 | } finally { |
| 8420 | Binder.restoreCallingIdentity(identity); |
| 8421 | } |
| 8422 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8423 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8424 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8425 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8426 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8427 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8428 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8429 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8430 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8431 | } |
| 8432 | final long identity = Binder.clearCallingIdentity(); |
| 8433 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8434 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8435 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8436 | if (phone.getEmergencyNumberTracker() != null |
| 8437 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8438 | emergencyNumberListInternal.put( |
| 8439 | phone.getSubId(), |
| 8440 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8441 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8442 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8443 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8444 | } finally { |
| 8445 | Binder.restoreCallingIdentity(identity); |
| 8446 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8447 | } |
| 8448 | |
| 8449 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8450 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8451 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8452 | if (!exactMatch) { |
| 8453 | TelephonyPermissions |
| 8454 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8455 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8456 | } |
| 8457 | final long identity = Binder.clearCallingIdentity(); |
| 8458 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8459 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8460 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8461 | && phone.getEmergencyNumberTracker() |
| 8462 | .isEmergencyNumber(number, exactMatch)) { |
| 8463 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8464 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8465 | } |
| 8466 | return false; |
| 8467 | } finally { |
| 8468 | Binder.restoreCallingIdentity(identity); |
| 8469 | } |
| 8470 | } |
| 8471 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8472 | /** |
| 8473 | * Update emergency number list for test mode. |
| 8474 | */ |
| 8475 | @Override |
| 8476 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8477 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8478 | "updateEmergencyNumberListTestMode"); |
| 8479 | |
| 8480 | final long identity = Binder.clearCallingIdentity(); |
| 8481 | try { |
| 8482 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8483 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8484 | if (tracker != null) { |
| 8485 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8486 | } |
| 8487 | } |
| 8488 | } finally { |
| 8489 | Binder.restoreCallingIdentity(identity); |
| 8490 | } |
| 8491 | } |
| 8492 | |
| 8493 | /** |
| 8494 | * Get the full emergency number list for test mode. |
| 8495 | */ |
| 8496 | @Override |
| 8497 | public List<String> getEmergencyNumberListTestMode() { |
| 8498 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8499 | "getEmergencyNumberListTestMode"); |
| 8500 | |
| 8501 | final long identity = Binder.clearCallingIdentity(); |
| 8502 | try { |
| 8503 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8504 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8505 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8506 | if (tracker != null) { |
| 8507 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8508 | emergencyNumbers.add(num.getNumber()); |
| 8509 | } |
| 8510 | } |
| 8511 | } |
| 8512 | return new ArrayList<>(emergencyNumbers); |
| 8513 | } finally { |
| 8514 | Binder.restoreCallingIdentity(identity); |
| 8515 | } |
| 8516 | } |
| 8517 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8518 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8519 | public int getEmergencyNumberDbVersion(int subId) { |
| 8520 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8521 | |
| 8522 | final long identity = Binder.clearCallingIdentity(); |
| 8523 | try { |
| 8524 | final Phone phone = getPhone(subId); |
| 8525 | if (phone == null) { |
| 8526 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8527 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8528 | } |
| 8529 | return phone.getEmergencyNumberDbVersion(); |
| 8530 | } finally { |
| 8531 | Binder.restoreCallingIdentity(identity); |
| 8532 | } |
| 8533 | } |
| 8534 | |
| 8535 | @Override |
| 8536 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8537 | enforceModifyPermission(); |
| 8538 | |
| 8539 | final long identity = Binder.clearCallingIdentity(); |
| 8540 | try { |
| 8541 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8542 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8543 | if (tracker != null) { |
| 8544 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8545 | } |
| 8546 | } |
| 8547 | } finally { |
| 8548 | Binder.restoreCallingIdentity(identity); |
| 8549 | } |
| 8550 | } |
| 8551 | |
| 8552 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8553 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8554 | enforceActiveEmergencySessionPermission(); |
| 8555 | |
| 8556 | final long identity = Binder.clearCallingIdentity(); |
| 8557 | try { |
| 8558 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8559 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8560 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8561 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8562 | } |
| 8563 | } |
| 8564 | } finally { |
| 8565 | Binder.restoreCallingIdentity(identity); |
| 8566 | } |
| 8567 | } |
| 8568 | |
| 8569 | @Override |
| 8570 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8571 | enforceActiveEmergencySessionPermission(); |
| 8572 | |
| 8573 | final long identity = Binder.clearCallingIdentity(); |
| 8574 | try { |
| 8575 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8576 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8577 | if (tracker != null) { |
| 8578 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8579 | } |
| 8580 | } |
| 8581 | } finally { |
| 8582 | Binder.restoreCallingIdentity(identity); |
| 8583 | } |
| 8584 | } |
| 8585 | |
| 8586 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8587 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8588 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8589 | Phone phone = getPhone(subId); |
| 8590 | if (phone == null) { |
| 8591 | return null; |
| 8592 | } |
| 8593 | final long identity = Binder.clearCallingIdentity(); |
| 8594 | try { |
| 8595 | UiccProfile profile = UiccController.getInstance() |
| 8596 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8597 | if (profile != null) { |
| 8598 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8599 | } |
| 8600 | } finally { |
| 8601 | Binder.restoreCallingIdentity(identity); |
| 8602 | } |
| 8603 | return null; |
| 8604 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8605 | |
| 8606 | /** |
| 8607 | * Enable or disable a modem stack. |
| 8608 | */ |
| 8609 | @Override |
| 8610 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8611 | enforceModifyPermission(); |
| 8612 | |
| 8613 | final long identity = Binder.clearCallingIdentity(); |
| 8614 | try { |
| 8615 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8616 | if (phone == null) { |
| 8617 | return false; |
| 8618 | } else { |
| 8619 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8620 | } |
| 8621 | } finally { |
| 8622 | Binder.restoreCallingIdentity(identity); |
| 8623 | } |
| 8624 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8625 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8626 | /** |
| 8627 | * Whether a modem stack is enabled or not. |
| 8628 | */ |
| 8629 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8630 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8631 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8632 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8633 | if (phone == null) return false; |
| 8634 | |
| 8635 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8636 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8637 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8638 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8639 | } |
| 8640 | |
| 8641 | final long identity = Binder.clearCallingIdentity(); |
| 8642 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8643 | try { |
| 8644 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8645 | } catch (NoSuchElementException ex) { |
| 8646 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8647 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8648 | } finally { |
| 8649 | Binder.restoreCallingIdentity(identity); |
| 8650 | } |
| 8651 | } |
| 8652 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8653 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8654 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8655 | enforceModifyPermission(); |
| 8656 | |
| 8657 | final long identity = Binder.clearCallingIdentity(); |
| 8658 | try { |
| 8659 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8660 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8661 | .commit(); |
| 8662 | } finally { |
| 8663 | Binder.restoreCallingIdentity(identity); |
| 8664 | } |
| 8665 | } |
| 8666 | |
| 8667 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8668 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8669 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8670 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8671 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8672 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8673 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8674 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8675 | |
| 8676 | final long identity = Binder.clearCallingIdentity(); |
| 8677 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8678 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8679 | } finally { |
| 8680 | Binder.restoreCallingIdentity(identity); |
| 8681 | } |
| 8682 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8683 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8684 | @TelephonyManager.IsMultiSimSupportedResult |
| 8685 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8686 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8687 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8688 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8689 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8690 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8691 | } |
| 8692 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8693 | // supported by the modem, indicate that it is restricted. |
| 8694 | PhoneCapability staticCapability = |
| 8695 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8696 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8697 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8698 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8699 | } |
Sarah Chin | 7caee49 | 2020-02-18 20:49:02 +0000 | [diff] [blame] | 8700 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8701 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8702 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8703 | } |
| 8704 | // Check if support of multiple SIMs is restricted by carrier |
| 8705 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8706 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8707 | } |
| 8708 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8709 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8710 | } |
| 8711 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8712 | /** |
| 8713 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8714 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8715 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8716 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8717 | * @param numOfSims number of active sims we want to switch to |
| 8718 | */ |
| 8719 | @Override |
| 8720 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8721 | if (numOfSims == 1) { |
| 8722 | enforceModifyPermission(); |
| 8723 | } else { |
| 8724 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8725 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8726 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8727 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8728 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8729 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8730 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8731 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8732 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8733 | return; |
| 8734 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8735 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8736 | } finally { |
| 8737 | Binder.restoreCallingIdentity(identity); |
| 8738 | } |
| 8739 | } |
| 8740 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8741 | @Override |
| 8742 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8743 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8744 | Phone phone = getPhone(subId); |
| 8745 | if (phone == null) { |
| 8746 | return false; |
| 8747 | } |
| 8748 | final long identity = Binder.clearCallingIdentity(); |
| 8749 | try { |
| 8750 | UiccCard uiccCard = phone.getUiccCard(); |
| 8751 | if (uiccCard == null) { |
| 8752 | return false; |
| 8753 | } |
| 8754 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8755 | if (uiccProfile == null) { |
| 8756 | return false; |
| 8757 | } |
| 8758 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8759 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8760 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8761 | } |
| 8762 | return false; |
| 8763 | } finally { |
| 8764 | Binder.restoreCallingIdentity(identity); |
| 8765 | } |
| 8766 | } |
| 8767 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8768 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8769 | * Get whether making changes to modem configurations will trigger reboot. |
| 8770 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8771 | */ |
| 8772 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8773 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8774 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8775 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8776 | mApp, subId, callingPackage, callingFeatureId, |
| 8777 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8778 | return false; |
| 8779 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8780 | final long identity = Binder.clearCallingIdentity(); |
| 8781 | try { |
| 8782 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8783 | } finally { |
| 8784 | Binder.restoreCallingIdentity(identity); |
| 8785 | } |
| 8786 | } |
| 8787 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8788 | private void updateModemStateMetrics() { |
| 8789 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8790 | // TODO: check the state for each modem if the api is ready. |
| 8791 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8792 | } |
| 8793 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8794 | @Override |
| 8795 | public int[] getSlotsMapping() { |
| 8796 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8797 | |
| 8798 | final long identity = Binder.clearCallingIdentity(); |
| 8799 | try { |
| 8800 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8801 | // All logical slots should have a mapping to a physical slot. |
| 8802 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8803 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8804 | for (int i = 0; i < slotInfos.length; i++) { |
| 8805 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8806 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8807 | } |
| 8808 | } |
| 8809 | return logicalSlotsMapping; |
| 8810 | } finally { |
| 8811 | Binder.restoreCallingIdentity(identity); |
| 8812 | } |
| 8813 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8814 | |
| 8815 | /** |
| 8816 | * Get the IRadio HAL Version |
| 8817 | */ |
| 8818 | @Override |
| 8819 | public int getRadioHalVersion() { |
| 8820 | Phone phone = getDefaultPhone(); |
| 8821 | if (phone == null) return -1; |
| 8822 | HalVersion hv = phone.getHalVersion(); |
| 8823 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8824 | return hv.major * 100 + hv.minor; |
| 8825 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8826 | |
| 8827 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8828 | * Get the current calling package name. |
| 8829 | * @return the current calling package name |
| 8830 | */ |
| 8831 | @Override |
| 8832 | public String getCurrentPackageName() { |
| 8833 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8834 | } |
| 8835 | |
| 8836 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8837 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8838 | * corresponding network requests on a subId. |
| 8839 | * |
| 8840 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8841 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8842 | * 2) APN is un-metered for this subscription, or |
| 8843 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8844 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8845 | * |
| 8846 | * @return whether data is allowed for a apn type. |
| 8847 | * |
| 8848 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8849 | */ |
| 8850 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8851 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8852 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8853 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8854 | |
| 8855 | // Now that all security checks passes, perform the operation as ourselves. |
| 8856 | final long identity = Binder.clearCallingIdentity(); |
| 8857 | try { |
| 8858 | Phone phone = getPhone(subId); |
| 8859 | if (phone == null) return false; |
| 8860 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8861 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8862 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8863 | } finally { |
| 8864 | Binder.restoreCallingIdentity(identity); |
| 8865 | } |
| 8866 | } |
| 8867 | |
| 8868 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8869 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8870 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8871 | |
| 8872 | // Now that all security checks passes, perform the operation as ourselves. |
| 8873 | final long identity = Binder.clearCallingIdentity(); |
| 8874 | try { |
| 8875 | Phone phone = getPhone(subId); |
| 8876 | if (phone == null) return true; // By default return true. |
| 8877 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8878 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8879 | } finally { |
| 8880 | Binder.restoreCallingIdentity(identity); |
| 8881 | } |
| 8882 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8883 | |
| 8884 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8885 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8886 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8887 | enforceModifyPermission(); |
| 8888 | long token = Binder.clearCallingIdentity(); |
| 8889 | try { |
| 8890 | Phone phone = getPhone(subscriptionId); |
| 8891 | if (phone == null) { |
| 8892 | try { |
| 8893 | if (resultCallback != null) { |
| 8894 | resultCallback.accept(false); |
| 8895 | } |
| 8896 | } catch (RemoteException e) { |
| 8897 | // ignore |
| 8898 | } |
| 8899 | return; |
| 8900 | } |
| 8901 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 8902 | Pair.create(specifiers, (x) -> { |
| 8903 | try { |
| 8904 | if (resultCallback != null) { |
| 8905 | resultCallback.accept(x); |
| 8906 | } |
| 8907 | } catch (RemoteException e) { |
| 8908 | // ignore |
| 8909 | } |
| 8910 | }); |
| 8911 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 8912 | } finally { |
| 8913 | Binder.restoreCallingIdentity(token); |
| 8914 | } |
| 8915 | } |
| 8916 | |
| 8917 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 8918 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 8919 | TelephonyPermissions |
| 8920 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8921 | mApp, subId, "getSystemSelectionChannels"); |
| 8922 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8923 | final long identity = Binder.clearCallingIdentity(); |
| 8924 | try { |
| 8925 | List<RadioAccessSpecifier> specifiers = |
| 8926 | (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, |
| 8927 | null, subId, workSource); |
| 8928 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 8929 | return specifiers; |
| 8930 | } finally { |
| 8931 | Binder.restoreCallingIdentity(identity); |
| 8932 | } |
| 8933 | } |
| 8934 | |
| 8935 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8936 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 8937 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8938 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 8939 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 8940 | if (iccRecords == null) { |
| 8941 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 8942 | return false; |
| 8943 | } |
| 8944 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 8945 | } |
| 8946 | |
| 8947 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8948 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 8949 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8950 | if (callingPackage == null) { |
| 8951 | callingPackage = getCurrentPackageName(); |
| 8952 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8953 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 8954 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8955 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 8956 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8957 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 8958 | } |
| 8959 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 8960 | Intent intent = new Intent(); |
| 8961 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 8962 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 8963 | // Bring up choose default SMS subscription dialog right now |
| 8964 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 8965 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 8966 | mApp.startActivity(intent); |
| 8967 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8968 | |
| 8969 | @Override |
| 8970 | public String getMmsUAProfUrl(int subId) { |
| 8971 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8972 | final long identity = Binder.clearCallingIdentity(); |
| 8973 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 8974 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 8975 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 8976 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 8977 | return carrierUAProfUrl; |
| 8978 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 8979 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8980 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8981 | } finally { |
| 8982 | Binder.restoreCallingIdentity(identity); |
| 8983 | } |
| 8984 | } |
| 8985 | |
| 8986 | @Override |
| 8987 | public String getMmsUserAgent(int subId) { |
| 8988 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8989 | final long identity = Binder.clearCallingIdentity(); |
| 8990 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 8991 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 8992 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 8993 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 8994 | return carrierUserAgent; |
| 8995 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 8996 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8997 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8998 | } finally { |
| 8999 | Binder.restoreCallingIdentity(identity); |
| 9000 | } |
| 9001 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9002 | |
| 9003 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9004 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9005 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9006 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9007 | final long identity = Binder.clearCallingIdentity(); |
| 9008 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9009 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9010 | if (phone == null) return false; |
| 9011 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9012 | switch (policy) { |
| 9013 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9014 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9015 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9016 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9017 | default: |
| 9018 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9019 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9020 | } finally { |
| 9021 | Binder.restoreCallingIdentity(identity); |
| 9022 | } |
| 9023 | } |
| 9024 | |
| 9025 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9026 | public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy, |
| 9027 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9028 | enforceModifyPermission(); |
| 9029 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9030 | final long identity = Binder.clearCallingIdentity(); |
| 9031 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9032 | Phone phone = getPhone(subscriptionId); |
| 9033 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9034 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9035 | switch (policy) { |
| 9036 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9037 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9038 | break; |
| 9039 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9040 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9041 | break; |
| 9042 | default: |
| 9043 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9044 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9045 | } finally { |
| 9046 | Binder.restoreCallingIdentity(identity); |
| 9047 | } |
| 9048 | } |
| 9049 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9050 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9051 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9052 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9053 | * otherwise. |
| 9054 | */ |
| 9055 | @Override |
| 9056 | public void setCepEnabled(boolean isCepEnabled) { |
| 9057 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9058 | |
| 9059 | final long identity = Binder.clearCallingIdentity(); |
| 9060 | try { |
| 9061 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9062 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9063 | Phone defaultPhone = phone.getImsPhone(); |
| 9064 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9065 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9066 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9067 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9068 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9069 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9070 | + imsPhone.getMsisdn()); |
| 9071 | } |
| 9072 | } |
| 9073 | } finally { |
| 9074 | Binder.restoreCallingIdentity(identity); |
| 9075 | } |
| 9076 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9077 | |
| 9078 | /** |
| 9079 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9080 | * |
| 9081 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9082 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9083 | * before being read. |
| 9084 | */ |
| 9085 | @Override |
| 9086 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9087 | isCompressed) { |
| 9088 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9089 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame^] | 9090 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9091 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9092 | } |
| 9093 | if (!isImsAvailableOnDevice()) { |
| 9094 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9095 | "IMS not available on device."); |
| 9096 | } |
| 9097 | |
| 9098 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9099 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame^] | 9100 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9101 | } finally { |
| 9102 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9103 | } |
| 9104 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9105 | |
| 9106 | @Override |
| 9107 | public boolean isIccLockEnabled(int subId) { |
| 9108 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9109 | |
| 9110 | // Now that all security checks passes, perform the operation as ourselves. |
| 9111 | final long identity = Binder.clearCallingIdentity(); |
| 9112 | try { |
| 9113 | Phone phone = getPhone(subId); |
| 9114 | if (phone != null && phone.getIccCard() != null) { |
| 9115 | return phone.getIccCard().getIccLockEnabled(); |
| 9116 | } else { |
| 9117 | return false; |
| 9118 | } |
| 9119 | } finally { |
| 9120 | Binder.restoreCallingIdentity(identity); |
| 9121 | } |
| 9122 | } |
| 9123 | |
| 9124 | /** |
| 9125 | * Set the ICC pin lock enabled or disabled. |
| 9126 | * |
| 9127 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9128 | * three cases: |
| 9129 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9130 | * successfully. |
| 9131 | * - Positive number and zero for remaining password attempts. |
| 9132 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9133 | * |
| 9134 | */ |
| 9135 | @Override |
| 9136 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9137 | enforceModifyPermission(); |
| 9138 | |
| 9139 | Phone phone = getPhone(subId); |
| 9140 | if (phone == null) { |
| 9141 | return 0; |
| 9142 | } |
| 9143 | // Now that all security checks passes, perform the operation as ourselves. |
| 9144 | final long identity = Binder.clearCallingIdentity(); |
| 9145 | try { |
| 9146 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9147 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9148 | return attemptsRemaining; |
| 9149 | |
| 9150 | } catch (Exception e) { |
| 9151 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9152 | } finally { |
| 9153 | Binder.restoreCallingIdentity(identity); |
| 9154 | } |
| 9155 | return 0; |
| 9156 | } |
| 9157 | |
| 9158 | /** |
| 9159 | * Change the ICC password used in ICC pin lock. |
| 9160 | * |
| 9161 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9162 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9163 | * - Positive number and zero for remaining password attempts. |
| 9164 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9165 | * |
| 9166 | */ |
| 9167 | @Override |
| 9168 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9169 | enforceModifyPermission(); |
| 9170 | |
| 9171 | Phone phone = getPhone(subId); |
| 9172 | if (phone == null) { |
| 9173 | return 0; |
| 9174 | } |
| 9175 | // Now that all security checks passes, perform the operation as ourselves. |
| 9176 | final long identity = Binder.clearCallingIdentity(); |
| 9177 | try { |
| 9178 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9179 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9180 | return attemptsRemaining; |
| 9181 | |
| 9182 | } catch (Exception e) { |
| 9183 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9184 | } finally { |
| 9185 | Binder.restoreCallingIdentity(identity); |
| 9186 | } |
| 9187 | return 0; |
| 9188 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9189 | |
| 9190 | /** |
| 9191 | * Request for receiving user activity notification |
| 9192 | */ |
| 9193 | @Override |
| 9194 | public void requestUserActivityNotification() { |
| 9195 | if (!mNotifyUserActivity.get() |
| 9196 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9197 | mNotifyUserActivity.set(true); |
| 9198 | } |
| 9199 | } |
| 9200 | |
| 9201 | /** |
| 9202 | * Called when userActivity is signalled in the power manager. |
| 9203 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9204 | */ |
| 9205 | @Override |
| 9206 | public void userActivity() { |
| 9207 | // *************************************** |
| 9208 | // * Inherited from PhoneWindowManager * |
| 9209 | // *************************************** |
| 9210 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9211 | // WITH ITS LOCKS HELD. |
| 9212 | // |
| 9213 | // This code must be VERY careful about the locks |
| 9214 | // it acquires. |
| 9215 | // In fact, the current code acquires way too many, |
| 9216 | // and probably has lurking deadlocks. |
| 9217 | |
| 9218 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9219 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9220 | } |
| 9221 | |
| 9222 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9223 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9224 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9225 | } |
| 9226 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9227 | |
| 9228 | @Override |
| 9229 | public boolean canConnectTo5GInDsdsMode() { |
| 9230 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9231 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9232 | |
| 9233 | @Override |
| 9234 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9235 | String callingFeatureId) { |
| 9236 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9237 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9238 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9239 | } |
| 9240 | |
| 9241 | Phone phone = getPhone(subId); |
| 9242 | if (phone == null) { |
| 9243 | throw new RuntimeException("phone is not available"); |
| 9244 | } |
| 9245 | // Now that all security checks passes, perform the operation as ourselves. |
| 9246 | final long identity = Binder.clearCallingIdentity(); |
| 9247 | try { |
| 9248 | return phone.getEquivalentHomePlmns(); |
| 9249 | } finally { |
| 9250 | Binder.restoreCallingIdentity(identity); |
| 9251 | } |
| 9252 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9253 | |
| 9254 | @Override |
| 9255 | public boolean isRadioInterfaceCapabilitySupported( |
| 9256 | @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 9257 | RadioInterfaceCapabilities radioInterfaceCapabilities = |
| 9258 | mPhoneConfigurationManager.getRadioInterfaceCapabilities(); |
| 9259 | if (radioInterfaceCapabilities == null) { |
| 9260 | throw new RuntimeException("radio interface capabilities are not available"); |
| 9261 | } else { |
| 9262 | return radioInterfaceCapabilities.isSupported(capability); |
| 9263 | } |
| 9264 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9265 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9266 | @Override |
| 9267 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 9268 | UaSecurityProtocolIdentifier securityProtocol, |
| 9269 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) |
| 9270 | throws RemoteException { |
| 9271 | enforceModifyPermission(); |
| 9272 | if (DBG) { |
| 9273 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 9274 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 9275 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 9276 | } |
| 9277 | |
| 9278 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 9279 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 9280 | || appType > TelephonyManager.APPTYPE_ISIM |
| 9281 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 9282 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 9283 | if (callback != null) { |
| 9284 | try { |
| 9285 | callback.onAuthenticationFailure( |
| 9286 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 9287 | } catch (RemoteException exception) { |
| 9288 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 9289 | } |
| 9290 | return; |
| 9291 | } |
| 9292 | } |
| 9293 | |
| 9294 | final long token = Binder.clearCallingIdentity(); |
| 9295 | try { |
| 9296 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 9297 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 9298 | forceBootStrapping, callback)); |
| 9299 | } finally { |
| 9300 | Binder.restoreCallingIdentity(token); |
| 9301 | } |
| 9302 | } |
| 9303 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9304 | /** |
| 9305 | * Attempts to set the radio power state for thermal reason. This does not guarantee that the |
| 9306 | * requested radio power state will actually be set. See {@link |
| 9307 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9308 | * |
| 9309 | * @param subId the subscription ID of the phone requesting to set the radio power state. |
| 9310 | * @param enable {@code true} if trying to turn radio on. |
| 9311 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9312 | * false}. |
| 9313 | */ |
| 9314 | private boolean setRadioPowerForThermal(int subId, boolean enable) { |
| 9315 | Phone phone = getPhone(subId); |
| 9316 | if (phone != null) { |
| 9317 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 9318 | return true; |
| 9319 | } |
| 9320 | return false; |
| 9321 | } |
| 9322 | |
| 9323 | private int handleDataThrottlingRequest(int subId, |
| 9324 | DataThrottlingRequest dataThrottlingRequest) { |
| 9325 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 9326 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9327 | if (!setRadioPowerForThermal(subId, true)) { |
| 9328 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9329 | } |
| 9330 | |
| 9331 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 9332 | |
| 9333 | int thermalMitigationResult = |
| 9334 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
| 9335 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 9336 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 9337 | } |
| 9338 | return thermalMitigationResult; |
| 9339 | } |
| 9340 | |
| 9341 | /** |
| 9342 | * Thermal mitigation request to control functionalities at modem. |
| 9343 | * |
| 9344 | * @param subId the id of the subscription. |
| 9345 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
| 9346 | * |
| 9347 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 9348 | */ |
| 9349 | @Override |
| 9350 | @ThermalMitigationResult |
| 9351 | public int sendThermalMitigationRequest( |
| 9352 | int subId, |
| 9353 | ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException { |
| 9354 | enforceModifyPermission(); |
| 9355 | |
| 9356 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9357 | final long identity = Binder.clearCallingIdentity(); |
| 9358 | |
| 9359 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 9360 | try { |
| 9361 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 9362 | switch (thermalMitigationAction) { |
| 9363 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 9364 | thermalMitigationResult = |
| 9365 | handleDataThrottlingRequest(subId, |
| 9366 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 9367 | break; |
| 9368 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 9369 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9370 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 9371 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 9372 | } |
| 9373 | |
| 9374 | // Ensure that radio is on. If not able to power on due to phone being |
| 9375 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9376 | if (!setRadioPowerForThermal(subId, true)) { |
| 9377 | thermalMitigationResult = |
| 9378 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9379 | break; |
| 9380 | } |
| 9381 | |
| 9382 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 9383 | false); |
| 9384 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9385 | break; |
| 9386 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 9387 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9388 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 9389 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 9390 | } |
| 9391 | |
| 9392 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 9393 | if (registry != null) { |
| 9394 | TelephonyConnectionService service = |
| 9395 | registry.getTelephonyConnectionService(); |
| 9396 | Phone phone = getPhone(subId); |
| 9397 | if (phone == null) { |
| 9398 | thermalMitigationResult = |
| 9399 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9400 | break; |
| 9401 | } |
| 9402 | |
| 9403 | if (PhoneConstantConversions.convertCallState(phone.getState()) |
| 9404 | != TelephonyManager.CALL_STATE_IDLE |
| 9405 | || phone.isInEmergencySmsMode() || phone.isInEcm() |
| 9406 | || (service != null && service.isEmergencyCallPending())) { |
| 9407 | String errorMessage = "Phone state is not valid. call state = " |
| 9408 | + PhoneConstantConversions.convertCallState(phone.getState()) |
| 9409 | + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode() |
| 9410 | + " isInEmergencyCallbackMode = " + phone.isInEcm(); |
| 9411 | errorMessage += service == null |
| 9412 | ? " TelephonyConnectionService is null" |
| 9413 | : " isEmergencyCallPending = " |
| 9414 | + service.isEmergencyCallPending(); |
| 9415 | Log.e(LOG_TAG, errorMessage); |
| 9416 | thermalMitigationResult = |
| 9417 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 9418 | break; |
| 9419 | } |
| 9420 | } else { |
| 9421 | thermalMitigationResult = |
| 9422 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9423 | break; |
| 9424 | } |
| 9425 | |
| 9426 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 9427 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9428 | if (!setRadioPowerForThermal(subId, false)) { |
| 9429 | thermalMitigationResult = |
| 9430 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9431 | break; |
| 9432 | } |
| 9433 | thermalMitigationResult = |
| 9434 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9435 | break; |
| 9436 | default: |
| 9437 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 9438 | + "not exist. Requested action: " + thermalMitigationAction); |
| 9439 | } |
| 9440 | } catch (IllegalArgumentException e) { |
| 9441 | throw e; |
| 9442 | } catch (Exception e) { |
| 9443 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 9444 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 9445 | } finally { |
| 9446 | Binder.restoreCallingIdentity(identity); |
| 9447 | } |
| 9448 | |
| 9449 | if (DBG) { |
| 9450 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 9451 | + thermalMitigationResult); |
| 9452 | } |
| 9453 | |
| 9454 | return thermalMitigationResult; |
| 9455 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9456 | |
| 9457 | /** |
| 9458 | * Set the GbaService Package Name that Telephony will bind to. |
| 9459 | * |
| 9460 | * @param subId The sim that the GbaService is associated with. |
| 9461 | * @param packageName The name of the package to be replaced with. |
| 9462 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9463 | */ |
| 9464 | @Override |
| 9465 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 9466 | enforceModifyPermission(); |
| 9467 | |
| 9468 | final long identity = Binder.clearCallingIdentity(); |
| 9469 | try { |
| 9470 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 9471 | } finally { |
| 9472 | Binder.restoreCallingIdentity(identity); |
| 9473 | } |
| 9474 | } |
| 9475 | |
| 9476 | /** |
| 9477 | * Return the package name of the currently bound GbaService. |
| 9478 | * |
| 9479 | * @param subId The sim that the GbaService is associated with. |
| 9480 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 9481 | */ |
| 9482 | @Override |
| 9483 | public String getBoundGbaService(int subId) { |
| 9484 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 9485 | |
| 9486 | final long identity = Binder.clearCallingIdentity(); |
| 9487 | try { |
| 9488 | return getGbaManager(subId).getServicePackage(); |
| 9489 | } finally { |
| 9490 | Binder.restoreCallingIdentity(identity); |
| 9491 | } |
| 9492 | } |
| 9493 | |
| 9494 | /** |
| 9495 | * Set the release time for telephony to unbind GbaService. |
| 9496 | * |
| 9497 | * @param subId The sim that the GbaService is associated with. |
| 9498 | * @param interval The release time to unbind GbaService by millisecond. |
| 9499 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9500 | */ |
| 9501 | @Override |
| 9502 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 9503 | enforceModifyPermission(); |
| 9504 | |
| 9505 | final long identity = Binder.clearCallingIdentity(); |
| 9506 | try { |
| 9507 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 9508 | } finally { |
| 9509 | Binder.restoreCallingIdentity(identity); |
| 9510 | } |
| 9511 | } |
| 9512 | |
| 9513 | /** |
| 9514 | * Return the release time for telephony to unbind GbaService. |
| 9515 | * |
| 9516 | * @param subId The sim that the GbaService is associated with. |
| 9517 | * @return The release time to unbind GbaService by millisecond. |
| 9518 | */ |
| 9519 | @Override |
| 9520 | public int getGbaReleaseTime(int subId) { |
| 9521 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 9522 | |
| 9523 | final long identity = Binder.clearCallingIdentity(); |
| 9524 | try { |
| 9525 | return getGbaManager(subId).getReleaseTime(); |
| 9526 | } finally { |
| 9527 | Binder.restoreCallingIdentity(identity); |
| 9528 | } |
| 9529 | } |
| 9530 | |
| 9531 | private GbaManager getGbaManager(int subId) { |
| 9532 | GbaManager instance = GbaManager.getInstance(subId); |
| 9533 | if (instance == null) { |
| 9534 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 9535 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 9536 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 9537 | } |
| 9538 | return instance; |
| 9539 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame^] | 9540 | |
| 9541 | /** |
| 9542 | * indicate whether the device and the carrier can support |
| 9543 | * RCS VoLTE single registration. |
| 9544 | */ |
| 9545 | @Override |
| 9546 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
| 9547 | enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable"); |
| 9548 | |
| 9549 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9550 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9551 | } |
| 9552 | |
| 9553 | final long identity = Binder.clearCallingIdentity(); |
| 9554 | try { |
| 9555 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 9556 | if (rpm != null) { |
| 9557 | return rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 9558 | } |
| 9559 | return false; |
| 9560 | } finally { |
| 9561 | Binder.restoreCallingIdentity(identity); |
| 9562 | } |
| 9563 | } |
| 9564 | |
| 9565 | /** |
| 9566 | * Register RCS provisioning callback. |
| 9567 | */ |
| 9568 | @Override |
| 9569 | public void registerRcsProvisioningChangedCallback(int subId, |
| 9570 | IRcsConfigCallback callback) { |
| 9571 | enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback"); |
| 9572 | |
| 9573 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9574 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9575 | } |
| 9576 | if (!isImsAvailableOnDevice()) { |
| 9577 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9578 | "IMS not available on device."); |
| 9579 | } |
| 9580 | |
| 9581 | final long identity = Binder.clearCallingIdentity(); |
| 9582 | try { |
| 9583 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 9584 | .addRcsProvisioningCallbackForSubscription(callback, subId); |
| 9585 | } catch (ImsException e) { |
| 9586 | throw new ServiceSpecificException(e.getCode()); |
| 9587 | } finally { |
| 9588 | Binder.restoreCallingIdentity(identity); |
| 9589 | } |
| 9590 | } |
| 9591 | |
| 9592 | /** |
| 9593 | * Unregister RCS provisioning callback. |
| 9594 | */ |
| 9595 | @Override |
| 9596 | public void unregisterRcsProvisioningChangedCallback(int subId, |
| 9597 | IRcsConfigCallback callback) { |
| 9598 | enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback"); |
| 9599 | |
| 9600 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9601 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9602 | } |
| 9603 | if (!isImsAvailableOnDevice()) { |
| 9604 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9605 | "IMS not available on device."); |
| 9606 | } |
| 9607 | |
| 9608 | final long identity = Binder.clearCallingIdentity(); |
| 9609 | try { |
| 9610 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 9611 | .removeRcsProvisioningCallbackForSubscription(callback, subId); |
| 9612 | } catch (ImsException e) { |
| 9613 | Log.i(LOG_TAG, "unregisterRcsProvisioningChangedCallback: " + subId |
| 9614 | + "is inactive, ignoring unregister."); |
| 9615 | } finally { |
| 9616 | Binder.restoreCallingIdentity(identity); |
| 9617 | } |
| 9618 | } |
| 9619 | |
| 9620 | /** |
| 9621 | * trigger RCS reconfiguration. |
| 9622 | */ |
| 9623 | public void triggerRcsReconfiguration(int subId) { |
| 9624 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9625 | mApp, subId, "triggerRcsReconfiguration"); |
| 9626 | |
| 9627 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9628 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9629 | } |
| 9630 | if (!isImsAvailableOnDevice()) { |
| 9631 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9632 | "IMS not available on device."); |
| 9633 | } |
| 9634 | |
| 9635 | final long identity = Binder.clearCallingIdentity(); |
| 9636 | try { |
| 9637 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 9638 | } finally { |
| 9639 | Binder.restoreCallingIdentity(identity); |
| 9640 | } |
| 9641 | } |
| 9642 | |
| 9643 | /** |
| 9644 | * Provide the client configuration parameters of the RCS application. |
| 9645 | */ |
| 9646 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
| 9647 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9648 | mApp, subId, "setRcsClientConfiguration"); |
| 9649 | |
| 9650 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9651 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9652 | } |
| 9653 | if (!isImsAvailableOnDevice()) { |
| 9654 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9655 | "IMS not available on device."); |
| 9656 | } |
| 9657 | |
| 9658 | final long identity = Binder.clearCallingIdentity(); |
| 9659 | |
| 9660 | try { |
| 9661 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 9662 | if (configBinder == null) { |
| 9663 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
| 9664 | } else { |
| 9665 | configBinder.setRcsClientConfiguration(rcc); |
| 9666 | } |
| 9667 | } catch (RemoteException e) { |
| 9668 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
| 9669 | } finally { |
| 9670 | Binder.restoreCallingIdentity(identity); |
| 9671 | } |
| 9672 | } |
| 9673 | |
| 9674 | /** |
| 9675 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 9676 | */ |
| 9677 | @Override |
| 9678 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 9679 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9680 | "setDeviceSingleRegistrationEnabledOverride"); |
| 9681 | enforceModifyPermission(); |
| 9682 | |
| 9683 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9684 | : Boolean.parseBoolean(enabledStr); |
| 9685 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
| 9686 | } |
| 9687 | |
| 9688 | /** |
| 9689 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 9690 | */ |
| 9691 | @Override |
| 9692 | public boolean getDeviceSingleRegistrationEnabled() { |
| 9693 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 9694 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 9695 | } |
| 9696 | |
| 9697 | /** |
| 9698 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9699 | */ |
| 9700 | @Override |
| 9701 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 9702 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9703 | "setCarrierSingleRegistrationEnabledOverride"); |
| 9704 | enforceModifyPermission(); |
| 9705 | |
| 9706 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9707 | : Boolean.parseBoolean(enabledStr); |
| 9708 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 9709 | subId, enabled); |
| 9710 | } |
| 9711 | |
| 9712 | /** |
| 9713 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9714 | */ |
| 9715 | @Override |
| 9716 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 9717 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 9718 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 9719 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 9720 | } |