Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
| 20 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 22 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 23 | |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 24 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 25 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 26 | import android.annotation.Nullable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 27 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 28 | import android.app.PendingIntent; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 29 | import android.app.role.RoleManager; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 30 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 31 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 32 | import android.content.Context; |
| 33 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 34 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 35 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 36 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 37 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 38 | import android.net.Uri; |
| 39 | import android.os.AsyncResult; |
| 40 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 41 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.os.Bundle; |
| 43 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 44 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.os.Looper; |
| 46 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 47 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 48 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 49 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 50 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 51 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 52 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 53 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 54 | import android.os.ServiceSpecificException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 55 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 56 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 57 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 58 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 59 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 60 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 61 | import android.provider.Telephony; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 62 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 63 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 64 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 65 | import android.telecom.TelecomManager; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 66 | import android.telephony.Annotation.ApnType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 67 | import android.telephony.Annotation.ThermalMitigationResult; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 68 | import android.telephony.CallForwardingInfo; |
Sooraj Sasindran | 4deb887 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 69 | import android.telephony.CarrierBandwidth; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 70 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 71 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 72 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 73 | import android.telephony.CellIdentityCdma; |
| 74 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 75 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 76 | import android.telephony.CellInfoGsm; |
| 77 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 78 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 79 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 80 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 81 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 82 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 83 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 84 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 85 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 86 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 87 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 88 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 89 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 90 | import android.telephony.RadioAccessSpecifier; |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 91 | import android.telephony.RadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 92 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 93 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 94 | import android.telephony.SignalStrengthUpdateRequest; |
| 95 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 96 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 97 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 98 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 99 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 100 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 101 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 102 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 103 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 104 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 105 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 106 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 107 | import android.telephony.data.ApnSetting; |
| 108 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 109 | import android.telephony.gba.GbaAuthRequest; |
| 110 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 111 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 112 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 113 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 114 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 115 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 116 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 117 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 118 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 119 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 120 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 121 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 122 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 123 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 124 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 125 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 126 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 127 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 128 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 129 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 130 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 131 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 132 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 133 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 134 | import com.android.ims.rcs.uce.eab.EabUtil; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 135 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 139 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 142 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.GbaManager; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 145 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 146 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 149 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 151 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 157 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.RIL; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 165 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 166 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 169 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 171 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 173 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 174 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 175 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 177 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 179 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 181 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 183 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 184 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 185 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 186 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 187 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 188 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 189 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 190 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 191 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 192 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 193 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 194 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 195 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 196 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 197 | import com.android.services.telephony.TelecomAccountRegistry; |
| 198 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 199 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 200 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 201 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 202 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 203 | import java.io.IOException; |
| 204 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 205 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 206 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 207 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 208 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 209 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 210 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 211 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 212 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 213 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 214 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 215 | import java.util.Set; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 216 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 217 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 218 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 219 | |
| 220 | /** |
| 221 | * Implementation of the ITelephony interface. |
| 222 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 223 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 224 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 225 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 226 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 227 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 228 | |
| 229 | // Message codes used with mMainThreadHandler |
| 230 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 231 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 232 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 233 | private static final int CMD_OPEN_CHANNEL = 9; |
| 234 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 235 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 236 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 237 | private static final int CMD_NV_READ_ITEM = 13; |
| 238 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 239 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 240 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 241 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 242 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 243 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 244 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 245 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 246 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 247 | private static final int CMD_SEND_ENVELOPE = 25; |
| 248 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 249 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 250 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 251 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 252 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 253 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 254 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 255 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 256 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 257 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 258 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 259 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 260 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 261 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 262 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 263 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 264 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 265 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 266 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 267 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 268 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 269 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 270 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 271 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 272 | private static final int CMD_SWITCH_SLOTS = 50; |
| 273 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 274 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 275 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 276 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 277 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 278 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 279 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 280 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 281 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 282 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 283 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 284 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 285 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 286 | private static final int CMD_MODEM_REBOOT = 64; |
| 287 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 288 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 289 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 290 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 291 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 292 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 293 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 294 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 295 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 296 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 297 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 298 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 299 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 300 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 301 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 302 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 303 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 304 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 305 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 306 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 307 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 308 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 309 | private static final int CMD_GET_CALL_WAITING = 87; |
| 310 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 311 | private static final int CMD_SET_CALL_WAITING = 89; |
| 312 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 313 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 314 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 315 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 316 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 317 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 318 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 319 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 320 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 321 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 322 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 323 | private static final int CMD_SET_SIM_POWER = 101; |
| 324 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 325 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 326 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 327 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 328 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 329 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 330 | private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 331 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 332 | // Parameters of select command. |
| 333 | private static final int SELECT_COMMAND = 0xA4; |
| 334 | private static final int SELECT_P1 = 0x04; |
| 335 | private static final int SELECT_P2 = 0; |
| 336 | private static final int SELECT_P3 = 0x10; |
| 337 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 338 | /** The singleton instance. */ |
| 339 | private static PhoneInterfaceManager sInstance; |
| 340 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 341 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 342 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 343 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 344 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 345 | private AppOpsManager mAppOps; |
| 346 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 347 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 348 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 349 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 350 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 351 | /** User Activity */ |
| 352 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 353 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 354 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 355 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 356 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 357 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 358 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 359 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 360 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 361 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 362 | // String to store multi SIM allowed |
| 363 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 364 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 365 | // The AID of ISD-R. |
| 366 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 367 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 368 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 369 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 370 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 371 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 372 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 373 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
| 374 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 375 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 376 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 377 | */ |
| 378 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 379 | "reset_network_erase_modem_config_enabled"; |
| 380 | |
| 381 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 382 | * A request object to use for transmitting data to an ICC. |
| 383 | */ |
| 384 | private static final class IccAPDUArgument { |
| 385 | public int channel, cla, command, p1, p2, p3; |
| 386 | public String data; |
| 387 | |
| 388 | public IccAPDUArgument(int channel, int cla, int command, |
| 389 | int p1, int p2, int p3, String data) { |
| 390 | this.channel = channel; |
| 391 | this.cla = cla; |
| 392 | this.command = command; |
| 393 | this.p1 = p1; |
| 394 | this.p2 = p2; |
| 395 | this.p3 = p3; |
| 396 | this.data = data; |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 401 | * A request object to use for transmitting data to an ICC. |
| 402 | */ |
| 403 | private static final class ManualNetworkSelectionArgument { |
| 404 | public OperatorInfo operatorInfo; |
| 405 | public boolean persistSelection; |
| 406 | |
| 407 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 408 | this.operatorInfo = operatorInfo; |
| 409 | this.persistSelection = persistSelection; |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 414 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 415 | * request after sending. The main thread will notify the request when it is complete. |
| 416 | */ |
| 417 | private static final class MainThreadRequest { |
| 418 | /** The argument to use for the request */ |
| 419 | public Object argument; |
| 420 | /** The result of the request that is run on the main thread */ |
| 421 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 422 | // The subscriber id that this request applies to. Defaults to |
| 423 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 424 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 425 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 426 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 427 | public Phone phone; |
| 428 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 429 | public WorkSource workSource; |
| 430 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 431 | public MainThreadRequest(Object argument) { |
| 432 | this.argument = argument; |
| 433 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 434 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 435 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 436 | this.argument = argument; |
| 437 | if (phone != null) { |
| 438 | this.phone = phone; |
| 439 | } |
| 440 | this.workSource = workSource; |
| 441 | } |
| 442 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 443 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 444 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 445 | if (subId != null) { |
| 446 | this.subId = subId; |
| 447 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 448 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 449 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 450 | } |
| 451 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 452 | private static final class IncomingThirdPartyCallArgs { |
| 453 | public final ComponentName component; |
| 454 | public final String callId; |
| 455 | public final String callerDisplayName; |
| 456 | |
| 457 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 458 | String callerDisplayName) { |
| 459 | this.component = component; |
| 460 | this.callId = callId; |
| 461 | this.callerDisplayName = callerDisplayName; |
| 462 | } |
| 463 | } |
| 464 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 465 | /** |
| 466 | * A handler that processes messages on the main thread in the phone process. Since many |
| 467 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 468 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 469 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 470 | * on, which will be notified when the operation completes and will contain the result of the |
| 471 | * request. |
| 472 | * |
| 473 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 474 | * note that request.result must be set to something non-null for the calling thread to |
| 475 | * unblock. |
| 476 | */ |
| 477 | private final class MainThreadHandler extends Handler { |
| 478 | @Override |
| 479 | public void handleMessage(Message msg) { |
| 480 | MainThreadRequest request; |
| 481 | Message onCompleted; |
| 482 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 483 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 484 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 485 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 486 | |
| 487 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 488 | case CMD_HANDLE_USSD_REQUEST: { |
| 489 | request = (MainThreadRequest) msg.obj; |
| 490 | final Phone phone = getPhoneFromRequest(request); |
| 491 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 492 | String ussdRequest = ussdObject.first; |
| 493 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 494 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 495 | if (!isUssdApiAllowed(request.subId)) { |
| 496 | // Carrier does not support use of this API, return failure. |
| 497 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 498 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 499 | Bundle returnData = new Bundle(); |
| 500 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 501 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 502 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 503 | request.result = true; |
| 504 | notifyRequester(request); |
| 505 | return; |
| 506 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 507 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 508 | try { |
| 509 | request.result = phone != null |
| 510 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 511 | } catch (CallStateException cse) { |
| 512 | request.result = false; |
| 513 | } |
| 514 | // Wake up the requesting thread |
| 515 | notifyRequester(request); |
| 516 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 517 | } |
| 518 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 519 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 520 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 521 | final Phone phone = getPhoneFromRequest(request); |
| 522 | request.result = phone != null ? |
| 523 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 524 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 525 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 526 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 527 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 528 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 529 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 530 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 531 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 532 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 533 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 534 | if (uiccCard == null) { |
| 535 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 536 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 537 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 538 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 539 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 540 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 541 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 542 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 543 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 544 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 545 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 546 | break; |
| 547 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 548 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 549 | ar = (AsyncResult) msg.obj; |
| 550 | request = (MainThreadRequest) ar.userObj; |
| 551 | if (ar.exception == null && ar.result != null) { |
| 552 | request.result = ar.result; |
| 553 | } else { |
| 554 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 555 | if (ar.result == null) { |
| 556 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 557 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 558 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 559 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 560 | } else { |
| 561 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 562 | } |
| 563 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 564 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 565 | break; |
| 566 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 567 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 568 | request = (MainThreadRequest) msg.obj; |
| 569 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 570 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 571 | if (uiccCard == null) { |
| 572 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 573 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 574 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 575 | } else { |
| 576 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 577 | request); |
| 578 | uiccCard.iccTransmitApduBasicChannel( |
| 579 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 580 | iccArgument.p3, iccArgument.data, onCompleted); |
| 581 | } |
| 582 | break; |
| 583 | |
| 584 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 585 | ar = (AsyncResult) msg.obj; |
| 586 | request = (MainThreadRequest) ar.userObj; |
| 587 | if (ar.exception == null && ar.result != null) { |
| 588 | request.result = ar.result; |
| 589 | } else { |
| 590 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 591 | if (ar.result == null) { |
| 592 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 593 | } else if (ar.exception instanceof CommandException) { |
| 594 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 595 | ar.exception); |
| 596 | } else { |
| 597 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 598 | } |
| 599 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 600 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 601 | break; |
| 602 | |
| 603 | case CMD_EXCHANGE_SIM_IO: |
| 604 | request = (MainThreadRequest) msg.obj; |
| 605 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 606 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 607 | if (uiccCard == null) { |
| 608 | loge("iccExchangeSimIO: No UICC"); |
| 609 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 610 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 611 | } else { |
| 612 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 613 | request); |
| 614 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 615 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 616 | iccArgument.data, onCompleted); |
| 617 | } |
| 618 | break; |
| 619 | |
| 620 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 621 | ar = (AsyncResult) msg.obj; |
| 622 | request = (MainThreadRequest) ar.userObj; |
| 623 | if (ar.exception == null && ar.result != null) { |
| 624 | request.result = ar.result; |
| 625 | } else { |
| 626 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 627 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 628 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 629 | break; |
| 630 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 631 | case CMD_SEND_ENVELOPE: |
| 632 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 633 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 634 | if (uiccCard == null) { |
| 635 | loge("sendEnvelopeWithStatus: No UICC"); |
| 636 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 637 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 638 | } else { |
| 639 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 640 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 641 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 642 | break; |
| 643 | |
| 644 | case EVENT_SEND_ENVELOPE_DONE: |
| 645 | ar = (AsyncResult) msg.obj; |
| 646 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 647 | if (ar.exception == null && ar.result != null) { |
| 648 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 649 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 650 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 651 | if (ar.result == null) { |
| 652 | loge("sendEnvelopeWithStatus: Empty response"); |
| 653 | } else if (ar.exception instanceof CommandException) { |
| 654 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 655 | ar.exception); |
| 656 | } else { |
| 657 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 658 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 659 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 660 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 661 | break; |
| 662 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 663 | case CMD_OPEN_CHANNEL: |
| 664 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 665 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 666 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 667 | if (uiccCard == null) { |
| 668 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 669 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 670 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 671 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 672 | } else { |
| 673 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 674 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 675 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 676 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 677 | break; |
| 678 | |
| 679 | case EVENT_OPEN_CHANNEL_DONE: |
| 680 | ar = (AsyncResult) msg.obj; |
| 681 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 682 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 683 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 684 | int[] result = (int[]) ar.result; |
| 685 | int channelId = result[0]; |
| 686 | byte[] selectResponse = null; |
| 687 | if (result.length > 1) { |
| 688 | selectResponse = new byte[result.length - 1]; |
| 689 | for (int i = 1; i < result.length; ++i) { |
| 690 | selectResponse[i - 1] = (byte) result[i]; |
| 691 | } |
| 692 | } |
| 693 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 694 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 695 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 696 | if (ar.result == null) { |
| 697 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 698 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 699 | if (ar.exception != null) { |
| 700 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 701 | } |
| 702 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 703 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 704 | if (ar.exception instanceof CommandException) { |
| 705 | CommandException.Error error = |
| 706 | ((CommandException) (ar.exception)).getCommandError(); |
| 707 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 708 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 709 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 710 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 711 | } |
| 712 | } |
| 713 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 714 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 715 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 716 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 717 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 718 | break; |
| 719 | |
| 720 | case CMD_CLOSE_CHANNEL: |
| 721 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 722 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 723 | if (uiccCard == null) { |
| 724 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 725 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 726 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 727 | } else { |
| 728 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 729 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 730 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 731 | break; |
| 732 | |
| 733 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 734 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 735 | break; |
| 736 | |
| 737 | case CMD_NV_READ_ITEM: |
| 738 | request = (MainThreadRequest) msg.obj; |
| 739 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 740 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 741 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 742 | break; |
| 743 | |
| 744 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 745 | ar = (AsyncResult) msg.obj; |
| 746 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 747 | if (ar.exception == null && ar.result != null) { |
| 748 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 749 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 750 | request.result = ""; |
| 751 | if (ar.result == null) { |
| 752 | loge("nvReadItem: Empty response"); |
| 753 | } else if (ar.exception instanceof CommandException) { |
| 754 | loge("nvReadItem: CommandException: " + |
| 755 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 756 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 757 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 758 | } |
| 759 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 760 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 761 | break; |
| 762 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 763 | case CMD_NV_WRITE_ITEM: |
| 764 | request = (MainThreadRequest) msg.obj; |
| 765 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 766 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 767 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 768 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 769 | break; |
| 770 | |
| 771 | case EVENT_NV_WRITE_ITEM_DONE: |
| 772 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 773 | break; |
| 774 | |
| 775 | case CMD_NV_WRITE_CDMA_PRL: |
| 776 | request = (MainThreadRequest) msg.obj; |
| 777 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 778 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 779 | break; |
| 780 | |
| 781 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 782 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 783 | break; |
| 784 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 785 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 786 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 787 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 788 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 789 | break; |
| 790 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 791 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 792 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 793 | break; |
| 794 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 795 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 796 | request = (MainThreadRequest) msg.obj; |
| 797 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 798 | request); |
| 799 | Phone phone = getPhoneFromRequest(request); |
| 800 | if (phone != null) { |
| 801 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 802 | } else { |
| 803 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 804 | request.result = false; |
| 805 | notifyRequester(request); |
| 806 | } |
| 807 | break; |
| 808 | } |
| 809 | |
| 810 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 811 | ar = (AsyncResult) msg.obj; |
| 812 | request = (MainThreadRequest) ar.userObj; |
| 813 | if (ar.exception == null && ar.result != null) { |
| 814 | request.result = ar.result; |
| 815 | } else { |
| 816 | // request.result must be set to something non-null |
| 817 | // for the calling thread to unblock |
| 818 | if (request.result != null) { |
| 819 | request.result = ar.result; |
| 820 | } else { |
| 821 | request.result = false; |
| 822 | } |
| 823 | if (ar.result == null) { |
| 824 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 825 | } else if (ar.exception instanceof CommandException) { |
| 826 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 827 | + ar.exception); |
| 828 | } else { |
| 829 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 830 | } |
| 831 | } |
| 832 | notifyRequester(request); |
| 833 | break; |
| 834 | |
| 835 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 836 | request = (MainThreadRequest) msg.obj; |
| 837 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 838 | Phone phone = getPhoneFromRequest(request); |
| 839 | if (phone != null) { |
| 840 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 841 | request.workSource); |
| 842 | } else { |
| 843 | loge("enableNrDualConnectivity: No phone object"); |
| 844 | request.result = |
| 845 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 846 | notifyRequester(request); |
| 847 | } |
| 848 | break; |
| 849 | } |
| 850 | |
| 851 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 852 | ar = (AsyncResult) msg.obj; |
| 853 | request = (MainThreadRequest) ar.userObj; |
| 854 | if (ar.exception == null) { |
| 855 | request.result = |
| 856 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 857 | } else { |
| 858 | request.result = |
| 859 | TelephonyManager |
| 860 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 861 | if (ar.exception instanceof CommandException) { |
| 862 | CommandException.Error error = |
| 863 | ((CommandException) (ar.exception)).getCommandError(); |
| 864 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 865 | request.result = |
| 866 | TelephonyManager |
| 867 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 868 | } |
| 869 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 870 | + ar.exception); |
| 871 | } else { |
| 872 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 873 | } |
| 874 | } |
| 875 | notifyRequester(request); |
| 876 | break; |
| 877 | } |
| 878 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 879 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 880 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 881 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 882 | request); |
| 883 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 884 | break; |
| 885 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 886 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 887 | ar = (AsyncResult) msg.obj; |
| 888 | request = (MainThreadRequest) ar.userObj; |
| 889 | if (ar.exception == null && ar.result != null) { |
| 890 | request.result = ar.result; // Integer |
| 891 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 892 | // request.result must be set to something non-null |
| 893 | // for the calling thread to unblock |
| 894 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 895 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 896 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 897 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 898 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 899 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 900 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 901 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 902 | } |
| 903 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 904 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 905 | break; |
| 906 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 907 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 908 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 909 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 910 | request); |
| 911 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 912 | (Pair<Integer, Long>) request.argument; |
| 913 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 914 | reasonWithNetworkTypes.first, |
| 915 | reasonWithNetworkTypes.second, |
| 916 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 917 | break; |
| 918 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 919 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 920 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 921 | break; |
| 922 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 923 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 924 | request = (MainThreadRequest)msg.obj; |
| 925 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 926 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 927 | break; |
| 928 | |
| 929 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 930 | ar = (AsyncResult)msg.obj; |
| 931 | request = (MainThreadRequest)ar.userObj; |
| 932 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 933 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 934 | break; |
| 935 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 936 | case CMD_SET_VOICEMAIL_NUMBER: |
| 937 | request = (MainThreadRequest) msg.obj; |
| 938 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 939 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 940 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 941 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 942 | break; |
| 943 | |
| 944 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 945 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 946 | break; |
| 947 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 948 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 949 | request = (MainThreadRequest) msg.obj; |
| 950 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 951 | request); |
| 952 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 953 | break; |
| 954 | |
| 955 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 956 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 957 | break; |
| 958 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 959 | case CMD_PERFORM_NETWORK_SCAN: |
| 960 | request = (MainThreadRequest) msg.obj; |
| 961 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 962 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 963 | break; |
| 964 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 965 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 966 | request = (MainThreadRequest) msg.obj; |
| 967 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 968 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 969 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 970 | request.argument; |
| 971 | int callForwardingReason = args.first; |
| 972 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 973 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 974 | } |
| 975 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 976 | ar = (AsyncResult) msg.obj; |
| 977 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 978 | TelephonyManager.CallForwardingInfoCallback callback = |
| 979 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 980 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 981 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 982 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 983 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 984 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 985 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 986 | // any service for voice call. |
| 987 | if ((callForwardInfo.serviceClass |
| 988 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 989 | callForwardingInfo = new CallForwardingInfo(true, |
| 990 | callForwardInfo.reason, |
| 991 | callForwardInfo.number, |
| 992 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 993 | break; |
| 994 | } |
| 995 | } |
| 996 | // Didn't find a call forward info for voice call. |
| 997 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 998 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 999 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1000 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1001 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1002 | } else { |
| 1003 | if (ar.result == null) { |
| 1004 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1005 | } |
| 1006 | if (ar.exception != null) { |
| 1007 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1008 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1009 | int errorCode = TelephonyManager |
| 1010 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1011 | if (ar.exception instanceof CommandException) { |
| 1012 | CommandException.Error error = |
| 1013 | ((CommandException) (ar.exception)).getCommandError(); |
| 1014 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1015 | errorCode = TelephonyManager |
| 1016 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1017 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1018 | errorCode = TelephonyManager |
| 1019 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1020 | } |
| 1021 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1022 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1023 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1024 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1025 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1026 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1027 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1028 | request = (MainThreadRequest) msg.obj; |
| 1029 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1030 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1031 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1032 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1033 | request.argument).first; |
| 1034 | request.phone.setCallForwardingOption( |
| 1035 | callForwardingInfoToSet.isEnabled() |
| 1036 | ? CommandsInterface.CF_ACTION_ENABLE |
| 1037 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1038 | callForwardingInfoToSet.getReason(), |
| 1039 | callForwardingInfoToSet.getNumber(), |
| 1040 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1041 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1042 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1043 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1044 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1045 | ar = (AsyncResult) msg.obj; |
| 1046 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1047 | Consumer<Integer> callback = |
| 1048 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1049 | request.argument).second; |
| 1050 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1051 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1052 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1053 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1054 | if (ar.exception instanceof CommandException) { |
| 1055 | CommandException.Error error = |
| 1056 | ((CommandException) (ar.exception)).getCommandError(); |
| 1057 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1058 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1059 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1060 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1061 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1062 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1063 | } |
| 1064 | } |
| 1065 | callback.accept(errorCode); |
| 1066 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1067 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1068 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1069 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1070 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1071 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1072 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1073 | request = (MainThreadRequest) msg.obj; |
| 1074 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1075 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1076 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1077 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1078 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1079 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1080 | ar = (AsyncResult) msg.obj; |
| 1081 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1082 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1083 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1084 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1085 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1086 | // Service Class is a bit mask per 3gpp 27.007. |
| 1087 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1088 | if (callForwardResults.length > 1 |
| 1089 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1090 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1091 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1092 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1093 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1094 | } else { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1095 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1096 | } |
| 1097 | } else { |
| 1098 | if (ar.result == null) { |
| 1099 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1100 | } |
| 1101 | if (ar.exception != null) { |
| 1102 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1103 | } |
| 1104 | if (ar.exception instanceof CommandException) { |
| 1105 | CommandException.Error error = |
| 1106 | ((CommandException) (ar.exception)).getCommandError(); |
| 1107 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1108 | callForwardingStatus = |
| 1109 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1110 | } |
| 1111 | } |
| 1112 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1113 | callback.accept(callForwardingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1114 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1115 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1116 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1117 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1118 | request = (MainThreadRequest) msg.obj; |
| 1119 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1120 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1121 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1122 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1123 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1124 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1125 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1126 | ar = (AsyncResult) msg.obj; |
| 1127 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1128 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1129 | Consumer<Integer> callback = |
| 1130 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1131 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1132 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1133 | if (ar.exception instanceof CommandException) { |
| 1134 | CommandException.Error error = |
| 1135 | ((CommandException) (ar.exception)).getCommandError(); |
| 1136 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1137 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1138 | } else { |
| 1139 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1140 | } |
| 1141 | } else { |
| 1142 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1143 | } |
| 1144 | } else { |
| 1145 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1146 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1147 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1148 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1149 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1150 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1151 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1152 | ar = (AsyncResult) msg.obj; |
| 1153 | request = (MainThreadRequest) ar.userObj; |
| 1154 | CellNetworkScanResult cellScanResult; |
| 1155 | if (ar.exception == null && ar.result != null) { |
| 1156 | cellScanResult = new CellNetworkScanResult( |
| 1157 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1158 | (List<OperatorInfo>) ar.result); |
| 1159 | } else { |
| 1160 | if (ar.result == null) { |
| 1161 | loge("getCellNetworkScanResults: Empty response"); |
| 1162 | } |
| 1163 | if (ar.exception != null) { |
| 1164 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1165 | } |
| 1166 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1167 | if (ar.exception instanceof CommandException) { |
| 1168 | CommandException.Error error = |
| 1169 | ((CommandException) (ar.exception)).getCommandError(); |
| 1170 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1171 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1172 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1173 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1174 | } |
| 1175 | } |
| 1176 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1177 | } |
| 1178 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1179 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1180 | break; |
| 1181 | |
| 1182 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1183 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1184 | ManualNetworkSelectionArgument selArg = |
| 1185 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1186 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1187 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1188 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1189 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1190 | break; |
| 1191 | |
| 1192 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1193 | ar = (AsyncResult) msg.obj; |
| 1194 | request = (MainThreadRequest) ar.userObj; |
| 1195 | if (ar.exception == null) { |
| 1196 | request.result = true; |
| 1197 | } else { |
| 1198 | request.result = false; |
| 1199 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1200 | } |
| 1201 | notifyRequester(request); |
| 1202 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1203 | break; |
| 1204 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1205 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1206 | request = (MainThreadRequest) msg.obj; |
| 1207 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1208 | if (defaultPhone != null) { |
| 1209 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1210 | } else { |
| 1211 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1212 | Bundle bundle = new Bundle(); |
| 1213 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1214 | new ModemActivityInfo(0, 0, 0, |
| 1215 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1216 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1217 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1218 | break; |
| 1219 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1220 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1221 | ar = (AsyncResult) msg.obj; |
| 1222 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1223 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1224 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1225 | ModemActivityInfo ret = null; |
| 1226 | int error = 0; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1227 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1228 | // Update the last modem activity info and the result of the request. |
| 1229 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1230 | if (isModemActivityInfoValid(info)) { |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1231 | int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()]; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1232 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1233 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1234 | .getTransmitTimeMillis(); |
| 1235 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1236 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1237 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1238 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1239 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1240 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1241 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1242 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1243 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1244 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1245 | info.getReceiveTimeMillis() |
| 1246 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1247 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1248 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(), |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1249 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1250 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1251 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1252 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1253 | } else { |
| 1254 | if (ar.result == null) { |
| 1255 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1256 | error = TelephonyManager.ModemActivityInfoException |
| 1257 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1258 | } else if (ar.exception instanceof CommandException) { |
| 1259 | loge("queryModemActivityInfo: CommandException: " + |
| 1260 | ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1261 | error = TelephonyManager.ModemActivityInfoException |
| 1262 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1263 | } else { |
| 1264 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1265 | error = TelephonyManager.ModemActivityInfoException |
| 1266 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1267 | } |
| 1268 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1269 | Bundle bundle = new Bundle(); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1270 | if (ret != null) { |
| 1271 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1272 | } else { |
| 1273 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1274 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1275 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1276 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1277 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1278 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1279 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1280 | case CMD_SET_ALLOWED_CARRIERS: |
| 1281 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1282 | CarrierRestrictionRules argument = |
| 1283 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1284 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1285 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1286 | break; |
| 1287 | |
| 1288 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1289 | ar = (AsyncResult) msg.obj; |
| 1290 | request = (MainThreadRequest) ar.userObj; |
| 1291 | if (ar.exception == null && ar.result != null) { |
| 1292 | request.result = ar.result; |
| 1293 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1294 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1295 | if (ar.exception instanceof CommandException) { |
| 1296 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1297 | CommandException.Error error = |
| 1298 | ((CommandException) (ar.exception)).getCommandError(); |
| 1299 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1300 | request.result = |
| 1301 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1302 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1303 | } else { |
| 1304 | loge("setAllowedCarriers: Unknown exception"); |
| 1305 | } |
| 1306 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1307 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1308 | break; |
| 1309 | |
| 1310 | case CMD_GET_ALLOWED_CARRIERS: |
| 1311 | request = (MainThreadRequest) msg.obj; |
| 1312 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1313 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1314 | break; |
| 1315 | |
| 1316 | case EVENT_GET_ALLOWED_CARRIERS_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 { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1322 | request.result = new IllegalStateException( |
| 1323 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1324 | if (ar.result == null) { |
| 1325 | loge("getAllowedCarriers: Empty response"); |
| 1326 | } else if (ar.exception instanceof CommandException) { |
| 1327 | loge("getAllowedCarriers: CommandException: " + |
| 1328 | ar.exception); |
| 1329 | } else { |
| 1330 | loge("getAllowedCarriers: Unknown exception"); |
| 1331 | } |
| 1332 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1333 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1334 | break; |
| 1335 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1336 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1337 | ar = (AsyncResult) msg.obj; |
| 1338 | request = (MainThreadRequest) ar.userObj; |
| 1339 | if (ar.exception == null && ar.result != null) { |
| 1340 | request.result = ar.result; |
| 1341 | } else { |
| 1342 | request.result = new IllegalArgumentException( |
| 1343 | "Failed to retrieve Forbidden Plmns"); |
| 1344 | if (ar.result == null) { |
| 1345 | loge("getForbiddenPlmns: Empty response"); |
| 1346 | } else { |
| 1347 | loge("getForbiddenPlmns: Unknown exception"); |
| 1348 | } |
| 1349 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1350 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1351 | break; |
| 1352 | |
| 1353 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1354 | request = (MainThreadRequest) msg.obj; |
| 1355 | uiccCard = getUiccCardFromRequest(request); |
| 1356 | if (uiccCard == null) { |
| 1357 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1358 | request.result = new IllegalArgumentException( |
| 1359 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1360 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1361 | break; |
| 1362 | } |
| 1363 | Integer appType = (Integer) request.argument; |
| 1364 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1365 | if (uiccApp == null) { |
| 1366 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1367 | + appType); |
| 1368 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1369 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1370 | break; |
| 1371 | } else { |
| 1372 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1373 | + " specified type -- " + appType); |
| 1374 | } |
| 1375 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1376 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1377 | onCompleted); |
| 1378 | break; |
| 1379 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1380 | case CMD_SWITCH_SLOTS: |
| 1381 | request = (MainThreadRequest) msg.obj; |
| 1382 | int[] physicalSlots = (int[]) request.argument; |
| 1383 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1384 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1385 | break; |
| 1386 | |
| 1387 | case EVENT_SWITCH_SLOTS_DONE: |
| 1388 | ar = (AsyncResult) msg.obj; |
| 1389 | request = (MainThreadRequest) ar.userObj; |
| 1390 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1391 | notifyRequester(request); |
| 1392 | break; |
| 1393 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1394 | request = (MainThreadRequest) msg.obj; |
| 1395 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1396 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1397 | break; |
| 1398 | |
| 1399 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1400 | ar = (AsyncResult) msg.obj; |
| 1401 | request = (MainThreadRequest) ar.userObj; |
| 1402 | if (ar.exception != null) { |
| 1403 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1404 | } else { |
| 1405 | int mode = ((int[]) ar.result)[0]; |
| 1406 | if (mode == 0) { |
| 1407 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1408 | } else { |
| 1409 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1410 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1411 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1412 | notifyRequester(request); |
| 1413 | break; |
| 1414 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1415 | request = (MainThreadRequest) msg.obj; |
| 1416 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1417 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1418 | break; |
| 1419 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1420 | ar = (AsyncResult) msg.obj; |
| 1421 | request = (MainThreadRequest) ar.userObj; |
| 1422 | if (ar.exception != null) { |
| 1423 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1424 | } else { |
| 1425 | request.result = ((int[]) ar.result)[0]; |
| 1426 | } |
| 1427 | notifyRequester(request); |
| 1428 | break; |
| 1429 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1430 | request = (MainThreadRequest) msg.obj; |
| 1431 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1432 | int mode = (int) request.argument; |
| 1433 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1434 | break; |
| 1435 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1436 | ar = (AsyncResult) msg.obj; |
| 1437 | request = (MainThreadRequest) ar.userObj; |
| 1438 | request.result = ar.exception == null; |
| 1439 | notifyRequester(request); |
| 1440 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1441 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1442 | request = (MainThreadRequest) msg.obj; |
| 1443 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1444 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1445 | break; |
| 1446 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1447 | ar = (AsyncResult) msg.obj; |
| 1448 | request = (MainThreadRequest) ar.userObj; |
| 1449 | if (ar.exception != null) { |
| 1450 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1451 | } else { |
| 1452 | request.result = ((int[]) ar.result)[0]; |
| 1453 | } |
| 1454 | notifyRequester(request); |
| 1455 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1456 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1457 | request = (MainThreadRequest) msg.obj; |
| 1458 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1459 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1460 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1461 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1462 | break; |
| 1463 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1464 | ar = (AsyncResult) msg.obj; |
| 1465 | request = (MainThreadRequest) ar.userObj; |
| 1466 | request.result = ar.exception == null; |
| 1467 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1468 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1469 | case CMD_GET_ALL_CELL_INFO: |
| 1470 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1471 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1472 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1473 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1474 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1475 | ar = (AsyncResult) msg.obj; |
| 1476 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1477 | // If a timeout occurs, the response will be null |
| 1478 | request.result = (ar.exception == null && ar.result != null) |
| 1479 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1480 | synchronized (request) { |
| 1481 | request.notifyAll(); |
| 1482 | } |
| 1483 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1484 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1485 | request = (MainThreadRequest) msg.obj; |
| 1486 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1487 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1488 | break; |
| 1489 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1490 | ar = (AsyncResult) msg.obj; |
| 1491 | request = (MainThreadRequest) ar.userObj; |
| 1492 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1493 | try { |
| 1494 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1495 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1496 | cb.onError( |
| 1497 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1498 | ar.exception.getClass().getName(), |
| 1499 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1500 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1501 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1502 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1503 | } else { |
| 1504 | // use the result as returned |
| 1505 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1506 | } |
| 1507 | } catch (RemoteException re) { |
| 1508 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1509 | } |
| 1510 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1511 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1512 | request = (MainThreadRequest) msg.obj; |
| 1513 | WorkSource ws = (WorkSource) request.argument; |
| 1514 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1515 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1516 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1517 | } |
| 1518 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1519 | ar = (AsyncResult) msg.obj; |
| 1520 | request = (MainThreadRequest) ar.userObj; |
| 1521 | if (ar.exception == null) { |
| 1522 | request.result = ar.result; |
| 1523 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1524 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1525 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1526 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1527 | } |
| 1528 | |
| 1529 | synchronized (request) { |
| 1530 | request.notifyAll(); |
| 1531 | } |
| 1532 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1533 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1534 | case CMD_MODEM_REBOOT: |
| 1535 | request = (MainThreadRequest) msg.obj; |
| 1536 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1537 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1538 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1539 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1540 | handleNullReturnEvent(msg, "rebootModem"); |
| 1541 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1542 | case CMD_REQUEST_ENABLE_MODEM: |
| 1543 | request = (MainThreadRequest) msg.obj; |
| 1544 | boolean enable = (boolean) request.argument; |
| 1545 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1546 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1547 | PhoneConfigurationManager.getInstance() |
| 1548 | .enablePhone(request.phone, enable, onCompleted); |
| 1549 | break; |
| 1550 | case EVENT_ENABLE_MODEM_DONE: |
| 1551 | ar = (AsyncResult) msg.obj; |
| 1552 | request = (MainThreadRequest) ar.userObj; |
| 1553 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1554 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1555 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1556 | if ((boolean) request.result) { |
| 1557 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1558 | updateModemStateMetrics(); |
| 1559 | } else { |
| 1560 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1561 | + ar.exception); |
| 1562 | } |
| 1563 | notifyRequester(request); |
| 1564 | break; |
| 1565 | case CMD_GET_MODEM_STATUS: |
| 1566 | request = (MainThreadRequest) msg.obj; |
| 1567 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1568 | PhoneConfigurationManager.getInstance() |
| 1569 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1570 | break; |
| 1571 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1572 | ar = (AsyncResult) msg.obj; |
| 1573 | request = (MainThreadRequest) ar.userObj; |
| 1574 | int id = request.phone.getPhoneId(); |
| 1575 | if (ar.exception == null && ar.result != null) { |
| 1576 | request.result = ar.result; |
| 1577 | //update the cache as modem status has changed |
| 1578 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1579 | (boolean) request.result); |
| 1580 | } else { |
| 1581 | // Return true if modem status cannot be retrieved. For most cases, |
| 1582 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1583 | // and disable modem are not supported. Modem is always on. |
| 1584 | // TODO: this should be fixed in R to support a third |
| 1585 | // status UNKNOWN b/131631629 |
| 1586 | request.result = true; |
| 1587 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1588 | + ar.exception); |
| 1589 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1590 | notifyRequester(request); |
| 1591 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1592 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1593 | request = (MainThreadRequest) msg.obj; |
| 1594 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1595 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1596 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1597 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1598 | break; |
| 1599 | } |
| 1600 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1601 | ar = (AsyncResult) msg.obj; |
| 1602 | request = (MainThreadRequest) ar.userObj; |
| 1603 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1604 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1605 | args.second.accept(ar.exception == null); |
| 1606 | notifyRequester(request); |
| 1607 | break; |
| 1608 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1609 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1610 | request = (MainThreadRequest) msg.obj; |
| 1611 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1612 | Phone phone = getPhoneFromRequest(request); |
| 1613 | if (phone != null) { |
| 1614 | phone.getSystemSelectionChannels(onCompleted); |
| 1615 | } else { |
| 1616 | loge("getSystemSelectionChannels: No phone object"); |
| 1617 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1618 | notifyRequester(request); |
| 1619 | } |
| 1620 | break; |
| 1621 | } |
| 1622 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1623 | ar = (AsyncResult) msg.obj; |
| 1624 | request = (MainThreadRequest) ar.userObj; |
| 1625 | if (ar.exception == null && ar.result != null) { |
| 1626 | request.result = ar.result; |
| 1627 | } else { |
| 1628 | request.result = new IllegalArgumentException( |
| 1629 | "Failed to retrieve system selection channels"); |
| 1630 | if (ar.result == null) { |
| 1631 | loge("getSystemSelectionChannels: Empty response"); |
| 1632 | } else { |
| 1633 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1634 | } |
| 1635 | } |
| 1636 | notifyRequester(request); |
| 1637 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1638 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1639 | ar = (AsyncResult) msg.obj; |
| 1640 | request = (MainThreadRequest) ar.userObj; |
| 1641 | if (ar.exception == null && ar.result != null) { |
| 1642 | request.result = ar.result; |
| 1643 | } else { |
| 1644 | request.result = -1; |
| 1645 | loge("Failed to set Forbidden Plmns"); |
| 1646 | if (ar.result == null) { |
| 1647 | loge("setForbidenPlmns: Empty response"); |
| 1648 | } else if (ar.exception != null) { |
| 1649 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1650 | request.result = -1; |
| 1651 | } else { |
| 1652 | loge("setForbiddenPlmns: Unknown exception"); |
| 1653 | } |
| 1654 | } |
| 1655 | notifyRequester(request); |
| 1656 | break; |
| 1657 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1658 | request = (MainThreadRequest) msg.obj; |
| 1659 | uiccCard = getUiccCardFromRequest(request); |
| 1660 | if (uiccCard == null) { |
| 1661 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1662 | request.result = -1; |
| 1663 | notifyRequester(request); |
| 1664 | break; |
| 1665 | } |
| 1666 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1667 | (Pair<Integer, List<String>>) request.argument; |
| 1668 | appType = setFplmnsArgs.first; |
| 1669 | List<String> fplmns = setFplmnsArgs.second; |
| 1670 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1671 | if (uiccApp == null) { |
| 1672 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1673 | request.result = -1; |
| 1674 | loge("Failed to get UICC App"); |
| 1675 | notifyRequester(request); |
| 1676 | } else { |
| 1677 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1678 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1679 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1680 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1681 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1682 | case CMD_ERASE_MODEM_CONFIG: |
| 1683 | request = (MainThreadRequest) msg.obj; |
| 1684 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1685 | defaultPhone.eraseModemConfig(onCompleted); |
| 1686 | break; |
| 1687 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1688 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1689 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1690 | |
| 1691 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1692 | request = (MainThreadRequest) msg.obj; |
| 1693 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1694 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1695 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1696 | changed.first, changed.second, onCompleted); |
| 1697 | break; |
| 1698 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1699 | ar = (AsyncResult) msg.obj; |
| 1700 | request = (MainThreadRequest) ar.userObj; |
| 1701 | if (ar.exception == null) { |
| 1702 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1703 | } else { |
| 1704 | request.result = msg.arg1; |
| 1705 | } |
| 1706 | notifyRequester(request); |
| 1707 | break; |
| 1708 | |
| 1709 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1710 | request = (MainThreadRequest) msg.obj; |
| 1711 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1712 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1713 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1714 | enabled.first, enabled.second, onCompleted); |
| 1715 | break; |
| 1716 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1717 | ar = (AsyncResult) msg.obj; |
| 1718 | request = (MainThreadRequest) ar.userObj; |
| 1719 | if (ar.exception == null) { |
| 1720 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1721 | } else { |
| 1722 | request.result = msg.arg1; |
| 1723 | } |
| 1724 | notifyRequester(request); |
| 1725 | break; |
| 1726 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1727 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1728 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1729 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1730 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1731 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1732 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1733 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1734 | |
| 1735 | case CMD_SET_DATA_THROTTLING: { |
| 1736 | request = (MainThreadRequest) msg.obj; |
| 1737 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1738 | DataThrottlingRequest dataThrottlingRequest = |
| 1739 | (DataThrottlingRequest) request.argument; |
| 1740 | Phone phone = getPhoneFromRequest(request); |
| 1741 | if (phone != null) { |
| 1742 | phone.setDataThrottling(onCompleted, |
| 1743 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1744 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1745 | } else { |
| 1746 | loge("setDataThrottling: No phone object"); |
| 1747 | request.result = |
| 1748 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1749 | notifyRequester(request); |
| 1750 | } |
| 1751 | |
| 1752 | break; |
| 1753 | } |
| 1754 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1755 | ar = (AsyncResult) msg.obj; |
| 1756 | request = (MainThreadRequest) ar.userObj; |
| 1757 | |
| 1758 | if (ar.exception == null) { |
| 1759 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1760 | } else if (ar.exception instanceof CommandException) { |
| 1761 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1762 | CommandException.Error error = |
| 1763 | ((CommandException) (ar.exception)).getCommandError(); |
| 1764 | |
| 1765 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1766 | request.result = TelephonyManager |
| 1767 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1768 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1769 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
| 1770 | } else { |
| 1771 | request.result = |
| 1772 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1773 | } |
| 1774 | } else { |
| 1775 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1776 | } |
| 1777 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1778 | notifyRequester(request); |
| 1779 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1780 | |
| 1781 | case CMD_SET_SIM_POWER: { |
| 1782 | request = (MainThreadRequest) msg.obj; |
| 1783 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1784 | request = (MainThreadRequest) msg.obj; |
| 1785 | int stateToSet = |
| 1786 | ((Pair<Integer, IIntegerConsumer>) |
| 1787 | request.argument).first; |
| 1788 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1789 | break; |
| 1790 | } |
| 1791 | case EVENT_SET_SIM_POWER_DONE: { |
| 1792 | ar = (AsyncResult) msg.obj; |
| 1793 | request = (MainThreadRequest) ar.userObj; |
| 1794 | IIntegerConsumer callback = |
| 1795 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1796 | if (ar.exception != null) { |
| 1797 | loge("setSimPower exception: " + ar.exception); |
| 1798 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1799 | .RESULT_ERROR_UNKNOWN; |
| 1800 | if (ar.exception instanceof CommandException) { |
| 1801 | CommandException.Error error = |
| 1802 | ((CommandException) (ar.exception)).getCommandError(); |
| 1803 | if (error == CommandException.Error.SIM_ERR) { |
| 1804 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1805 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1806 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1807 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1808 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1809 | } else { |
| 1810 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1811 | } |
| 1812 | } |
| 1813 | try { |
| 1814 | callback.accept(errorCode); |
| 1815 | } catch (RemoteException e) { |
| 1816 | // Ignore if the remote process is no longer available to call back. |
| 1817 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1818 | } |
| 1819 | } else { |
| 1820 | try { |
| 1821 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1822 | } catch (RemoteException e) { |
| 1823 | // Ignore if the remote process is no longer available to call back. |
| 1824 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1825 | } |
| 1826 | } |
| 1827 | break; |
| 1828 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1829 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1830 | request = (MainThreadRequest) msg.obj; |
| 1831 | |
| 1832 | final Phone phone = getPhoneFromRequest(request); |
| 1833 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1834 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1835 | notifyRequester(request); |
| 1836 | break; |
| 1837 | } |
| 1838 | |
| 1839 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1840 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1841 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1842 | request); |
| 1843 | phone.getServiceStateTracker().setSignalStrengthUpdateRequest( |
| 1844 | request.subId, pair.first /*callingUid*/, |
| 1845 | pair.second /*request*/, onCompleted); |
| 1846 | break; |
| 1847 | } |
| 1848 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1849 | ar = (AsyncResult) msg.obj; |
| 1850 | request = (MainThreadRequest) ar.userObj; |
| 1851 | // request.result will be the exception of ar if present, true otherwise. |
| 1852 | // Be cautious not to leave result null which will wait() forever |
| 1853 | request.result = ar.exception != null ? ar.exception : true; |
| 1854 | notifyRequester(request); |
| 1855 | break; |
| 1856 | } |
| 1857 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1858 | request = (MainThreadRequest) msg.obj; |
| 1859 | |
| 1860 | Phone phone = getPhoneFromRequest(request); |
| 1861 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1862 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1863 | notifyRequester(request); |
| 1864 | break; |
| 1865 | } |
| 1866 | |
| 1867 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1868 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1869 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1870 | request); |
| 1871 | phone.getServiceStateTracker().clearSignalStrengthUpdateRequest( |
| 1872 | request.subId, pair.first /*callingUid*/, |
| 1873 | pair.second /*request*/, onCompleted); |
| 1874 | break; |
| 1875 | } |
| 1876 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1877 | ar = (AsyncResult) msg.obj; |
| 1878 | request = (MainThreadRequest) ar.userObj; |
| 1879 | request.result = ar.exception != null ? ar.exception : true; |
| 1880 | notifyRequester(request); |
| 1881 | break; |
| 1882 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1883 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1884 | default: |
| 1885 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1886 | break; |
| 1887 | } |
| 1888 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1889 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1890 | private void notifyRequester(MainThreadRequest request) { |
| 1891 | synchronized (request) { |
| 1892 | request.notifyAll(); |
| 1893 | } |
| 1894 | } |
| 1895 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1896 | private void handleNullReturnEvent(Message msg, String command) { |
| 1897 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1898 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1899 | if (ar.exception == null) { |
| 1900 | request.result = true; |
| 1901 | } else { |
| 1902 | request.result = false; |
| 1903 | if (ar.exception instanceof CommandException) { |
| 1904 | loge(command + ": CommandException: " + ar.exception); |
| 1905 | } else { |
| 1906 | loge(command + ": Unknown exception"); |
| 1907 | } |
| 1908 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1909 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1910 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1911 | } |
| 1912 | |
| 1913 | /** |
| 1914 | * Posts the specified command to be executed on the main thread, |
| 1915 | * waits for the request to complete, and returns the result. |
| 1916 | * @see #sendRequestAsync |
| 1917 | */ |
| 1918 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1919 | return sendRequest( |
| 1920 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1921 | } |
| 1922 | |
| 1923 | /** |
| 1924 | * Posts the specified command to be executed on the main thread, |
| 1925 | * waits for the request to complete, and returns the result. |
| 1926 | * @see #sendRequestAsync |
| 1927 | */ |
| 1928 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1929 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1930 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1931 | } |
| 1932 | |
| 1933 | /** |
| 1934 | * Posts the specified command to be executed on the main thread, |
| 1935 | * waits for the request to complete, and returns the result. |
| 1936 | * @see #sendRequestAsync |
| 1937 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1938 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1939 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1940 | } |
| 1941 | |
| 1942 | /** |
| 1943 | * Posts the specified command to be executed on the main thread, |
| 1944 | * waits for the request to complete, and returns the result. |
| 1945 | * @see #sendRequestAsync |
| 1946 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1947 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1948 | return sendRequest(command, argument, subId, null, workSource); |
| 1949 | } |
| 1950 | |
| 1951 | /** |
| 1952 | * Posts the specified command to be executed on the main thread, |
| 1953 | * waits for the request to complete, and returns the result. |
| 1954 | * @see #sendRequestAsync |
| 1955 | */ |
| 1956 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1957 | return sendRequest( |
| 1958 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1959 | } |
| 1960 | |
| 1961 | /** |
| 1962 | * Posts the specified command to be executed on the main thread, |
| 1963 | * waits for the request to complete, and returns the result. |
| 1964 | * @see #sendRequestAsync |
| 1965 | */ |
| 1966 | private Object sendRequest( |
| 1967 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1968 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1969 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1970 | } |
| 1971 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1972 | MainThreadRequest request = null; |
| 1973 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1974 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1975 | } else if (phone != null) { |
| 1976 | request = new MainThreadRequest(argument, phone, workSource); |
| 1977 | } else { |
| 1978 | request = new MainThreadRequest(argument, subId, workSource); |
| 1979 | } |
| 1980 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1981 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1982 | msg.sendToTarget(); |
| 1983 | |
| 1984 | // Wait for the request to complete |
| 1985 | synchronized (request) { |
| 1986 | while (request.result == null) { |
| 1987 | try { |
| 1988 | request.wait(); |
| 1989 | } catch (InterruptedException e) { |
| 1990 | // Do nothing, go back and wait until the request is complete |
| 1991 | } |
| 1992 | } |
| 1993 | } |
| 1994 | return request.result; |
| 1995 | } |
| 1996 | |
| 1997 | /** |
| 1998 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1999 | * Posts the specified command to be executed on the main thread, and |
| 2000 | * returns immediately. |
| 2001 | * @see #sendRequest |
| 2002 | */ |
| 2003 | private void sendRequestAsync(int command) { |
| 2004 | mMainThreadHandler.sendEmptyMessage(command); |
| 2005 | } |
| 2006 | |
| 2007 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2008 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2009 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2010 | */ |
| 2011 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2012 | sendRequestAsync(command, argument, null, null); |
| 2013 | } |
| 2014 | |
| 2015 | /** |
| 2016 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2017 | * @see {@link #sendRequest(int,Object)} |
| 2018 | */ |
| 2019 | private void sendRequestAsync( |
| 2020 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2021 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2022 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2023 | msg.sendToTarget(); |
| 2024 | } |
| 2025 | |
| 2026 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2027 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2028 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2029 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2030 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2031 | synchronized (PhoneInterfaceManager.class) { |
| 2032 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2033 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2034 | } else { |
| 2035 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2036 | } |
| 2037 | return sInstance; |
| 2038 | } |
| 2039 | } |
| 2040 | |
| 2041 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2042 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2043 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2044 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 2045 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2046 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2047 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2048 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2049 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2050 | mTelephonySharedPreferences = |
| 2051 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2052 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2053 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2054 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2055 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2056 | publish(); |
| 2057 | } |
| 2058 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2059 | private Phone getDefaultPhone() { |
| 2060 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2061 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2062 | } |
| 2063 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2064 | private void publish() { |
| 2065 | if (DBG) log("publish: " + this); |
| 2066 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2067 | TelephonyFrameworkInitializer |
| 2068 | .getTelephonyServiceManager() |
| 2069 | .getTelephonyServiceRegisterer() |
| 2070 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2071 | } |
| 2072 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2073 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2074 | if (request.phone != null) { |
| 2075 | return request.phone; |
| 2076 | } else { |
| 2077 | return getPhoneFromSubId(request.subId); |
| 2078 | } |
| 2079 | } |
| 2080 | |
| 2081 | private Phone getPhoneFromSubId(int subId) { |
| 2082 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2083 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2084 | } |
| 2085 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2086 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 2087 | Phone phone = getPhoneFromRequest(request); |
| 2088 | return phone == null ? null : |
| 2089 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 2090 | } |
| 2091 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2092 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2093 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2094 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2095 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2096 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2097 | private void sendEraseModemConfig(Phone phone) { |
| 2098 | if (phone != null) { |
| 2099 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2100 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 2101 | final long identity = Binder.clearCallingIdentity(); |
| 2102 | try { |
| 2103 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2104 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2105 | } finally { |
| 2106 | Binder.restoreCallingIdentity(identity); |
| 2107 | } |
| 2108 | } |
| 2109 | } |
| 2110 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2111 | private boolean isImsAvailableOnDevice() { |
| 2112 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2113 | if (pm == null) { |
| 2114 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2115 | // so do not throw error and allow. |
| 2116 | return true; |
| 2117 | } |
| 2118 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2119 | } |
| 2120 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2121 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2122 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2123 | } |
| 2124 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2125 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2126 | if (DBG) log("dial: " + number); |
| 2127 | // No permission check needed here: This is just a wrapper around the |
| 2128 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2129 | // the UI before it does anything. |
| 2130 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2131 | final long identity = Binder.clearCallingIdentity(); |
| 2132 | try { |
| 2133 | String url = createTelUrl(number); |
| 2134 | if (url == null) { |
| 2135 | return; |
| 2136 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2137 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2138 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2139 | PhoneConstants.State state = mCM.getState(subId); |
| 2140 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2141 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2142 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2143 | mApp.startActivity(intent); |
| 2144 | } |
| 2145 | } finally { |
| 2146 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2147 | } |
| 2148 | } |
| 2149 | |
| 2150 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2151 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2152 | } |
| 2153 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2154 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2155 | if (DBG) log("call: " + number); |
| 2156 | |
| 2157 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2158 | // need to do a permission check since we're calling startActivity() |
| 2159 | // from the context of the phone app. |
| 2160 | enforceCallPermission(); |
| 2161 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2162 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2163 | != AppOpsManager.MODE_ALLOWED) { |
| 2164 | return; |
| 2165 | } |
| 2166 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2167 | final long identity = Binder.clearCallingIdentity(); |
| 2168 | try { |
| 2169 | String url = createTelUrl(number); |
| 2170 | if (url == null) { |
| 2171 | return; |
| 2172 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2173 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2174 | boolean isValid = false; |
| 2175 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2176 | if (slist != null) { |
| 2177 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2178 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2179 | isValid = true; |
| 2180 | break; |
| 2181 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2182 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2183 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2184 | if (!isValid) { |
| 2185 | return; |
| 2186 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2187 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2188 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2189 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2190 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2191 | mApp.startActivity(intent); |
| 2192 | } finally { |
| 2193 | Binder.restoreCallingIdentity(identity); |
| 2194 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2195 | } |
| 2196 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2197 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2198 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2199 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2200 | } |
| 2201 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2202 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2203 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2204 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2205 | } |
| 2206 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2207 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2208 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2209 | |
| 2210 | final long identity = Binder.clearCallingIdentity(); |
| 2211 | try { |
| 2212 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 2213 | checkSimPin.start(); |
| 2214 | return checkSimPin.unlockSim(null, pin); |
| 2215 | } finally { |
| 2216 | Binder.restoreCallingIdentity(identity); |
| 2217 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2218 | } |
| 2219 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2220 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2221 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2222 | |
| 2223 | final long identity = Binder.clearCallingIdentity(); |
| 2224 | try { |
| 2225 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 2226 | checkSimPuk.start(); |
| 2227 | return checkSimPuk.unlockSim(puk, pin); |
| 2228 | } finally { |
| 2229 | Binder.restoreCallingIdentity(identity); |
| 2230 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2231 | } |
| 2232 | |
| 2233 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2234 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2235 | * a synchronous one. |
| 2236 | */ |
| 2237 | private static class UnlockSim extends Thread { |
| 2238 | |
| 2239 | private final IccCard mSimCard; |
| 2240 | |
| 2241 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2242 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2243 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2244 | |
| 2245 | // For replies from SimCard interface |
| 2246 | private Handler mHandler; |
| 2247 | |
| 2248 | // For async handler to identify request type |
| 2249 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2250 | |
| 2251 | public UnlockSim(IccCard simCard) { |
| 2252 | mSimCard = simCard; |
| 2253 | } |
| 2254 | |
| 2255 | @Override |
| 2256 | public void run() { |
| 2257 | Looper.prepare(); |
| 2258 | synchronized (UnlockSim.this) { |
| 2259 | mHandler = new Handler() { |
| 2260 | @Override |
| 2261 | public void handleMessage(Message msg) { |
| 2262 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2263 | switch (msg.what) { |
| 2264 | case SUPPLY_PIN_COMPLETE: |
| 2265 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2266 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2267 | mRetryCount = msg.arg1; |
| 2268 | if (ar.exception != null) { |
| 2269 | if (ar.exception instanceof CommandException && |
| 2270 | ((CommandException)(ar.exception)).getCommandError() |
| 2271 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2272 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2273 | } //When UiccCardApp dispose,handle message and return exception |
| 2274 | else if (ar.exception instanceof CommandException && |
| 2275 | ((CommandException) (ar.exception)).getCommandError() |
| 2276 | == CommandException.Error.ABORTED) { |
| 2277 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2278 | } else { |
| 2279 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2280 | } |
| 2281 | } else { |
| 2282 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2283 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2284 | mDone = true; |
| 2285 | UnlockSim.this.notifyAll(); |
| 2286 | } |
| 2287 | break; |
| 2288 | } |
| 2289 | } |
| 2290 | }; |
| 2291 | UnlockSim.this.notifyAll(); |
| 2292 | } |
| 2293 | Looper.loop(); |
| 2294 | } |
| 2295 | |
| 2296 | /* |
| 2297 | * Use PIN or PUK to unlock SIM card |
| 2298 | * |
| 2299 | * If PUK is null, unlock SIM card with PIN |
| 2300 | * |
| 2301 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2302 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2303 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2304 | |
| 2305 | while (mHandler == null) { |
| 2306 | try { |
| 2307 | wait(); |
| 2308 | } catch (InterruptedException e) { |
| 2309 | Thread.currentThread().interrupt(); |
| 2310 | } |
| 2311 | } |
| 2312 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2313 | |
| 2314 | if (puk == null) { |
| 2315 | mSimCard.supplyPin(pin, callback); |
| 2316 | } else { |
| 2317 | mSimCard.supplyPuk(puk, pin, callback); |
| 2318 | } |
| 2319 | |
| 2320 | while (!mDone) { |
| 2321 | try { |
| 2322 | Log.d(LOG_TAG, "wait for done"); |
| 2323 | wait(); |
| 2324 | } catch (InterruptedException e) { |
| 2325 | // Restore the interrupted status |
| 2326 | Thread.currentThread().interrupt(); |
| 2327 | } |
| 2328 | } |
| 2329 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2330 | int[] resultArray = new int[2]; |
| 2331 | resultArray[0] = mResult; |
| 2332 | resultArray[1] = mRetryCount; |
| 2333 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2334 | } |
| 2335 | } |
| 2336 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2337 | /** |
| 2338 | * This method has been removed due to privacy and stability concerns. |
| 2339 | */ |
| 2340 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2341 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2342 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2343 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2344 | } |
| 2345 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2346 | @Override |
| 2347 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2348 | mApp.getSystemService(AppOpsManager.class) |
| 2349 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2350 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2351 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2352 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2353 | // Callers targeting S have no business invoking this method. |
| 2354 | return; |
| 2355 | } |
| 2356 | |
| 2357 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2358 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2359 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2360 | .setCallingPackage(callingPackage) |
| 2361 | .setCallingFeatureId(null) |
| 2362 | .setCallingPid(Binder.getCallingPid()) |
| 2363 | .setCallingUid(Binder.getCallingUid()) |
| 2364 | .setMethod("updateServiceLocation") |
| 2365 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2366 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2367 | .build()); |
| 2368 | // Apps that lack location permission have no business calling this method; |
| 2369 | // however, because no permission was declared in the public API, denials must |
| 2370 | // all be "soft". |
| 2371 | switch (locationResult) { |
| 2372 | case DENIED_HARD: /* fall through */ |
| 2373 | case DENIED_SOFT: |
| 2374 | return; |
| 2375 | } |
| 2376 | |
| 2377 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2378 | final long identity = Binder.clearCallingIdentity(); |
| 2379 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2380 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2381 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2382 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2383 | } |
| 2384 | } finally { |
| 2385 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2386 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2387 | } |
| 2388 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2389 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2390 | @Override |
| 2391 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2392 | return isRadioOnWithFeature(callingPackage, null); |
| 2393 | } |
| 2394 | |
| 2395 | |
| 2396 | @Override |
| 2397 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2398 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2399 | callingFeatureId); |
| 2400 | } |
| 2401 | |
| 2402 | @Deprecated |
| 2403 | @Override |
| 2404 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2405 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2406 | } |
| 2407 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2408 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2409 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2410 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2411 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2412 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2413 | return false; |
| 2414 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2415 | |
| 2416 | final long identity = Binder.clearCallingIdentity(); |
| 2417 | try { |
| 2418 | return isRadioOnForSubscriber(subId); |
| 2419 | } finally { |
| 2420 | Binder.restoreCallingIdentity(identity); |
| 2421 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2422 | } |
| 2423 | |
| 2424 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2425 | final long identity = Binder.clearCallingIdentity(); |
| 2426 | try { |
| 2427 | final Phone phone = getPhone(subId); |
| 2428 | if (phone != null) { |
| 2429 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2430 | } else { |
| 2431 | return false; |
| 2432 | } |
| 2433 | } finally { |
| 2434 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2435 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2436 | } |
| 2437 | |
| 2438 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2439 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2440 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2441 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2442 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2443 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2444 | |
| 2445 | final long identity = Binder.clearCallingIdentity(); |
| 2446 | try { |
| 2447 | final Phone phone = getPhone(subId); |
| 2448 | if (phone != null) { |
| 2449 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2450 | } |
| 2451 | } finally { |
| 2452 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2453 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2454 | } |
| 2455 | |
| 2456 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2457 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2458 | } |
| 2459 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2460 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2461 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2462 | |
| 2463 | final long identity = Binder.clearCallingIdentity(); |
| 2464 | try { |
| 2465 | final Phone phone = getPhone(subId); |
| 2466 | if (phone == null) { |
| 2467 | return false; |
| 2468 | } |
| 2469 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2470 | toggleRadioOnOffForSubscriber(subId); |
| 2471 | } |
| 2472 | return true; |
| 2473 | } finally { |
| 2474 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2475 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2476 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2477 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2478 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2479 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2480 | /* |
| 2481 | * If any of the Radios are available, it will need to be |
| 2482 | * shutdown. So return true if any Radio is available. |
| 2483 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2484 | final long identity = Binder.clearCallingIdentity(); |
| 2485 | try { |
| 2486 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2487 | Phone phone = PhoneFactory.getPhone(i); |
| 2488 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2489 | } |
| 2490 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2491 | return false; |
| 2492 | } finally { |
| 2493 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2494 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2495 | } |
| 2496 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2497 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2498 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2499 | enforceModifyPermission(); |
| 2500 | |
| 2501 | final long identity = Binder.clearCallingIdentity(); |
| 2502 | try { |
| 2503 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2504 | logv("Shutting down Phone " + i); |
| 2505 | shutdownRadioUsingPhoneId(i); |
| 2506 | } |
| 2507 | } finally { |
| 2508 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2509 | } |
| 2510 | } |
| 2511 | |
| 2512 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2513 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2514 | if (phone != null && phone.isRadioAvailable()) { |
| 2515 | phone.shutdownRadio(); |
| 2516 | } |
| 2517 | } |
| 2518 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2519 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2520 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2521 | |
| 2522 | final long identity = Binder.clearCallingIdentity(); |
| 2523 | try { |
| 2524 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2525 | if (defaultPhone != null) { |
| 2526 | defaultPhone.setRadioPower(turnOn); |
| 2527 | return true; |
| 2528 | } else { |
| 2529 | loge("There's no default phone."); |
| 2530 | return false; |
| 2531 | } |
| 2532 | } finally { |
| 2533 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2534 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2535 | } |
| 2536 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2537 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2538 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2539 | |
| 2540 | final long identity = Binder.clearCallingIdentity(); |
| 2541 | try { |
| 2542 | final Phone phone = getPhone(subId); |
| 2543 | if (phone != null) { |
| 2544 | phone.setRadioPower(turnOn); |
| 2545 | return true; |
| 2546 | } else { |
| 2547 | return false; |
| 2548 | } |
| 2549 | } finally { |
| 2550 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2551 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2552 | } |
| 2553 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2554 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2555 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2556 | public boolean enableDataConnectivity() { |
| 2557 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2558 | |
| 2559 | final long identity = Binder.clearCallingIdentity(); |
| 2560 | try { |
| 2561 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2562 | final Phone phone = getPhone(subId); |
| 2563 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2564 | phone.getDataEnabledSettings().setDataEnabled( |
| 2565 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2566 | return true; |
| 2567 | } else { |
| 2568 | return false; |
| 2569 | } |
| 2570 | } finally { |
| 2571 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2572 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2573 | } |
| 2574 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2575 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2576 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2577 | public boolean disableDataConnectivity() { |
| 2578 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2579 | |
| 2580 | final long identity = Binder.clearCallingIdentity(); |
| 2581 | try { |
| 2582 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2583 | final Phone phone = getPhone(subId); |
| 2584 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2585 | phone.getDataEnabledSettings().setDataEnabled( |
| 2586 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2587 | return true; |
| 2588 | } else { |
| 2589 | return false; |
| 2590 | } |
| 2591 | } finally { |
| 2592 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2593 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2594 | } |
| 2595 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2596 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2597 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2598 | final long identity = Binder.clearCallingIdentity(); |
| 2599 | try { |
| 2600 | final Phone phone = getPhone(subId); |
| 2601 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2602 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2603 | } else { |
| 2604 | return false; |
| 2605 | } |
| 2606 | } finally { |
| 2607 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2608 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2609 | } |
| 2610 | |
| 2611 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2612 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2613 | } |
| 2614 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2615 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2616 | enforceCallPermission(); |
| 2617 | |
| 2618 | final long identity = Binder.clearCallingIdentity(); |
| 2619 | try { |
| 2620 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2621 | return; |
| 2622 | } |
| 2623 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2624 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2625 | } finally { |
| 2626 | Binder.restoreCallingIdentity(identity); |
| 2627 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2628 | }; |
| 2629 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2630 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2631 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2632 | |
| 2633 | final long identity = Binder.clearCallingIdentity(); |
| 2634 | try { |
| 2635 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2636 | return false; |
| 2637 | } |
| 2638 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2639 | } finally { |
| 2640 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2641 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2642 | } |
| 2643 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2644 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2645 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2646 | } |
| 2647 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2648 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2649 | final long identity = Binder.clearCallingIdentity(); |
| 2650 | try { |
| 2651 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2652 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2653 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2654 | } finally { |
| 2655 | Binder.restoreCallingIdentity(identity); |
| 2656 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2657 | } |
| 2658 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2659 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2660 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2661 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2662 | } |
| 2663 | |
| 2664 | @Override |
| 2665 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2666 | final long identity = Binder.clearCallingIdentity(); |
| 2667 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2668 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2669 | if (phone != null) { |
| 2670 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2671 | } else { |
| 2672 | return PhoneConstantConversions.convertDataState( |
| 2673 | PhoneConstants.DataState.DISCONNECTED); |
| 2674 | } |
| 2675 | } finally { |
| 2676 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2677 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2678 | } |
| 2679 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2680 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2681 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2682 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2683 | } |
| 2684 | |
| 2685 | @Override |
| 2686 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2687 | final long identity = Binder.clearCallingIdentity(); |
| 2688 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2689 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2690 | if (phone != null) { |
| 2691 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2692 | } else { |
| 2693 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2694 | } |
| 2695 | } finally { |
| 2696 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2697 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2698 | } |
| 2699 | |
| 2700 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2701 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2702 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2703 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2704 | |
| 2705 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2706 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2707 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2708 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2709 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2710 | .setCallingPid(Binder.getCallingPid()) |
| 2711 | .setCallingUid(Binder.getCallingUid()) |
| 2712 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2713 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2714 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2715 | .build()); |
| 2716 | switch (locationResult) { |
| 2717 | case DENIED_HARD: |
| 2718 | throw new SecurityException("Not allowed to access cell location"); |
| 2719 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2720 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2721 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2722 | } |
| 2723 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2724 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2725 | final long identity = Binder.clearCallingIdentity(); |
| 2726 | try { |
| 2727 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2728 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2729 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2730 | } finally { |
| 2731 | Binder.restoreCallingIdentity(identity); |
| 2732 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2733 | } |
| 2734 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2735 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2736 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2737 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2738 | // registered cell info, so return a NULL country instead. |
| 2739 | final long identity = Binder.clearCallingIdentity(); |
| 2740 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2741 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2742 | // Get default phone in this case. |
| 2743 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2744 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2745 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2746 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2747 | if (phone == null) return ""; |
| 2748 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2749 | if (sst == null) return ""; |
| 2750 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2751 | if (lt == null) return ""; |
| 2752 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2753 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2754 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2755 | } finally { |
| 2756 | Binder.restoreCallingIdentity(identity); |
| 2757 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2758 | } |
| 2759 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2760 | /** |
| 2761 | * This method was removed due to potential issues caused by performing partial |
| 2762 | * updates of service state, and lack of a credible use case. |
| 2763 | * |
| 2764 | * This has the ability to break the telephony implementation by disabling notification of |
| 2765 | * changes in device connectivity. DO NOT USE THIS! |
| 2766 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2767 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2768 | public void enableLocationUpdates() { |
| 2769 | mApp.enforceCallingOrSelfPermission( |
| 2770 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2771 | } |
| 2772 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2773 | /** |
| 2774 | * This method was removed due to potential issues caused by performing partial |
| 2775 | * updates of service state, and lack of a credible use case. |
| 2776 | * |
| 2777 | * This has the ability to break the telephony implementation by disabling notification of |
| 2778 | * changes in device connectivity. DO NOT USE THIS! |
| 2779 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2780 | @Override |
| 2781 | public void disableLocationUpdates() { |
| 2782 | mApp.enforceCallingOrSelfPermission( |
| 2783 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2784 | } |
| 2785 | |
| 2786 | @Override |
| 2787 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2788 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2789 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2790 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2791 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2792 | throw new SecurityException( |
| 2793 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2794 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2795 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2796 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2797 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2798 | return null; |
| 2799 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2800 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2801 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2802 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2803 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2804 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2805 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2806 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2807 | for (CellInfo ci : info) { |
| 2808 | if (ci instanceof CellInfoGsm) { |
| 2809 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2810 | } else if (ci instanceof CellInfoWcdma) { |
| 2811 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2812 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2813 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2814 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2815 | } |
| 2816 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2817 | private List<CellInfo> getCachedCellInfo() { |
| 2818 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2819 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2820 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2821 | if (info != null) cellInfos.addAll(info); |
| 2822 | } |
| 2823 | return cellInfos; |
| 2824 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2825 | |
| 2826 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2827 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2828 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2829 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2830 | |
| 2831 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2832 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2833 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2834 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2835 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2836 | .setCallingPid(Binder.getCallingPid()) |
| 2837 | .setCallingUid(Binder.getCallingUid()) |
| 2838 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2839 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2840 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2841 | .build()); |
| 2842 | switch (locationResult) { |
| 2843 | case DENIED_HARD: |
| 2844 | throw new SecurityException("Not allowed to access cell info"); |
| 2845 | case DENIED_SOFT: |
| 2846 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2847 | } |
| 2848 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2849 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2850 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2851 | return getCachedCellInfo(); |
| 2852 | } |
| 2853 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2854 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2855 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2856 | final long identity = Binder.clearCallingIdentity(); |
| 2857 | try { |
| 2858 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2859 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2860 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2861 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2862 | if (info != null) cellInfos.addAll(info); |
| 2863 | } |
| 2864 | return cellInfos; |
| 2865 | } finally { |
| 2866 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2867 | } |
| 2868 | } |
| 2869 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2870 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2871 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2872 | String callingFeatureId) { |
| 2873 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2874 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2875 | } |
| 2876 | |
| 2877 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2878 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2879 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2880 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2881 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2882 | } |
| 2883 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2884 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2885 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2886 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2887 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2888 | |
| 2889 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2890 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2891 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2892 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2893 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2894 | .setCallingPid(Binder.getCallingPid()) |
| 2895 | .setCallingUid(Binder.getCallingUid()) |
| 2896 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2897 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2898 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2899 | .build()); |
| 2900 | switch (locationResult) { |
| 2901 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2902 | if (TelephonyPermissions |
| 2903 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2904 | // Safetynet logging for b/154934934 |
| 2905 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2906 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2907 | throw new SecurityException("Not allowed to access cell info"); |
| 2908 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2909 | if (TelephonyPermissions |
| 2910 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2911 | // Safetynet logging for b/154934934 |
| 2912 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2913 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2914 | try { |
| 2915 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2916 | } catch (RemoteException re) { |
| 2917 | // Drop without consequences |
| 2918 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2919 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2920 | } |
| 2921 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2922 | |
| 2923 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2924 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2925 | |
| 2926 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2927 | } |
| 2928 | |
| 2929 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2930 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2931 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2932 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2933 | |
| 2934 | final long identity = Binder.clearCallingIdentity(); |
| 2935 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2936 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2937 | } finally { |
| 2938 | Binder.restoreCallingIdentity(identity); |
| 2939 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2940 | } |
| 2941 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2942 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2943 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2944 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2945 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2946 | return null; |
| 2947 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2948 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2949 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2950 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2951 | return null; |
| 2952 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2953 | |
| 2954 | final long identity = Binder.clearCallingIdentity(); |
| 2955 | try { |
| 2956 | return phone.getImei(); |
| 2957 | } finally { |
| 2958 | Binder.restoreCallingIdentity(identity); |
| 2959 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2960 | } |
| 2961 | |
| 2962 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2963 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2964 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2965 | String tac = null; |
| 2966 | if (phone != null) { |
| 2967 | String imei = phone.getImei(); |
| 2968 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2969 | } |
| 2970 | return tac; |
| 2971 | } |
| 2972 | |
| 2973 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2974 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2975 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2976 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2977 | return null; |
| 2978 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2979 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2980 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2981 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2982 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2983 | return null; |
| 2984 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2985 | |
| 2986 | final long identity = Binder.clearCallingIdentity(); |
| 2987 | try { |
| 2988 | return phone.getMeid(); |
| 2989 | } finally { |
| 2990 | Binder.restoreCallingIdentity(identity); |
| 2991 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2992 | } |
| 2993 | |
| 2994 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2995 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2996 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2997 | String manufacturerCode = null; |
| 2998 | if (phone != null) { |
| 2999 | String meid = phone.getMeid(); |
| 3000 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3001 | } |
| 3002 | return manufacturerCode; |
| 3003 | } |
| 3004 | |
| 3005 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3006 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3007 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3008 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3009 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3010 | return null; |
| 3011 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3012 | int subId = phone.getSubId(); |
| 3013 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3014 | mApp, subId, callingPackage, callingFeatureId, |
| 3015 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3016 | return null; |
| 3017 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3018 | |
| 3019 | final long identity = Binder.clearCallingIdentity(); |
| 3020 | try { |
| 3021 | return phone.getDeviceSvn(); |
| 3022 | } finally { |
| 3023 | Binder.restoreCallingIdentity(identity); |
| 3024 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3025 | } |
| 3026 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3027 | @Override |
| 3028 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3029 | final long identity = Binder.clearCallingIdentity(); |
| 3030 | try { |
| 3031 | final Phone phone = getPhone(subId); |
| 3032 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3033 | } finally { |
| 3034 | Binder.restoreCallingIdentity(identity); |
| 3035 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3036 | } |
| 3037 | |
| 3038 | @Override |
| 3039 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3040 | final long identity = Binder.clearCallingIdentity(); |
| 3041 | try { |
| 3042 | final Phone phone = getPhone(subId); |
| 3043 | return phone == null ? null : phone.getCarrierName(); |
| 3044 | } finally { |
| 3045 | Binder.restoreCallingIdentity(identity); |
| 3046 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3047 | } |
| 3048 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3049 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3050 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3051 | final long identity = Binder.clearCallingIdentity(); |
| 3052 | try { |
| 3053 | final Phone phone = getPhone(subId); |
| 3054 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3055 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3056 | } finally { |
| 3057 | Binder.restoreCallingIdentity(identity); |
| 3058 | } |
| 3059 | } |
| 3060 | |
| 3061 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3062 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3063 | final long identity = Binder.clearCallingIdentity(); |
| 3064 | try { |
| 3065 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3066 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3067 | } finally { |
| 3068 | Binder.restoreCallingIdentity(identity); |
| 3069 | } |
| 3070 | } |
| 3071 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3072 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3073 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3074 | if (!isSubscriptionMccMnc) { |
| 3075 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3076 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3077 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3078 | if (phone == null) { |
| 3079 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3080 | } |
| 3081 | final long identity = Binder.clearCallingIdentity(); |
| 3082 | try { |
| 3083 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3084 | } finally { |
| 3085 | Binder.restoreCallingIdentity(identity); |
| 3086 | } |
| 3087 | } |
| 3088 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3089 | // |
| 3090 | // Internal helper methods. |
| 3091 | // |
| 3092 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3093 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3094 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3095 | * |
| 3096 | * @throws SecurityException if the caller does not have the required permission |
| 3097 | */ |
| 3098 | private void enforceModifyPermission() { |
| 3099 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3100 | } |
| 3101 | |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3102 | /** |
| 3103 | * Make sure the caller is system. |
| 3104 | * |
| 3105 | * @throws SecurityException if the caller is not system. |
| 3106 | */ |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 3107 | private static void enforceSystemCaller() { |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3108 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 3109 | throw new SecurityException("Caller must be system"); |
| 3110 | } |
| 3111 | } |
| 3112 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3113 | private void enforceActiveEmergencySessionPermission() { |
| 3114 | mApp.enforceCallingOrSelfPermission( |
| 3115 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3116 | } |
| 3117 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3118 | /** |
| 3119 | * Make sure the caller has the CALL_PHONE permission. |
| 3120 | * |
| 3121 | * @throws SecurityException if the caller does not have the required permission |
| 3122 | */ |
| 3123 | private void enforceCallPermission() { |
| 3124 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3125 | } |
| 3126 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3127 | private void enforceSettingsPermission() { |
| 3128 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3129 | } |
| 3130 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3131 | private String createTelUrl(String number) { |
| 3132 | if (TextUtils.isEmpty(number)) { |
| 3133 | return null; |
| 3134 | } |
| 3135 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3136 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3137 | } |
| 3138 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3139 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3140 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3141 | } |
| 3142 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3143 | private static void logv(String msg) { |
| 3144 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3145 | } |
| 3146 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3147 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3148 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3149 | } |
| 3150 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3151 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3152 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3153 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
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 |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3157 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3158 | final long identity = Binder.clearCallingIdentity(); |
| 3159 | try { |
| 3160 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3161 | if (phone == null) { |
| 3162 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3163 | } else { |
| 3164 | return phone.getPhoneType(); |
| 3165 | } |
| 3166 | } finally { |
| 3167 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3168 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3169 | } |
| 3170 | |
| 3171 | /** |
| 3172 | * Returns the CDMA ERI icon index to display |
| 3173 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3174 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3175 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3176 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3177 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3178 | } |
| 3179 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3180 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3181 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3182 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3183 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3184 | mApp, subId, callingPackage, callingFeatureId, |
| 3185 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3186 | return -1; |
| 3187 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3188 | |
| 3189 | final long identity = Binder.clearCallingIdentity(); |
| 3190 | try { |
| 3191 | final Phone phone = getPhone(subId); |
| 3192 | if (phone != null) { |
| 3193 | return phone.getCdmaEriIconIndex(); |
| 3194 | } else { |
| 3195 | return -1; |
| 3196 | } |
| 3197 | } finally { |
| 3198 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3199 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3200 | } |
| 3201 | |
| 3202 | /** |
| 3203 | * Returns the CDMA ERI icon mode, |
| 3204 | * 0 - ON |
| 3205 | * 1 - FLASHING |
| 3206 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3207 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3208 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3209 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3210 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3211 | } |
| 3212 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3213 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3214 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3215 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3216 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3217 | mApp, subId, callingPackage, callingFeatureId, |
| 3218 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3219 | return -1; |
| 3220 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3221 | |
| 3222 | final long identity = Binder.clearCallingIdentity(); |
| 3223 | try { |
| 3224 | final Phone phone = getPhone(subId); |
| 3225 | if (phone != null) { |
| 3226 | return phone.getCdmaEriIconMode(); |
| 3227 | } else { |
| 3228 | return -1; |
| 3229 | } |
| 3230 | } finally { |
| 3231 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3232 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3233 | } |
| 3234 | |
| 3235 | /** |
| 3236 | * Returns the CDMA ERI text, |
| 3237 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3238 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3239 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3240 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3241 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3242 | } |
| 3243 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3244 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3245 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3246 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3247 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3248 | mApp, subId, callingPackage, callingFeatureId, |
| 3249 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3250 | return null; |
| 3251 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3252 | |
| 3253 | final long identity = Binder.clearCallingIdentity(); |
| 3254 | try { |
| 3255 | final Phone phone = getPhone(subId); |
| 3256 | if (phone != null) { |
| 3257 | return phone.getCdmaEriText(); |
| 3258 | } else { |
| 3259 | return null; |
| 3260 | } |
| 3261 | } finally { |
| 3262 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3263 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3264 | } |
| 3265 | |
| 3266 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3267 | * Returns the CDMA MDN. |
| 3268 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3269 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3270 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3271 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3272 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3273 | |
| 3274 | final long identity = Binder.clearCallingIdentity(); |
| 3275 | try { |
| 3276 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3277 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3278 | return phone.getLine1Number(); |
| 3279 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3280 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3281 | return null; |
| 3282 | } |
| 3283 | } finally { |
| 3284 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3285 | } |
| 3286 | } |
| 3287 | |
| 3288 | /** |
| 3289 | * Returns the CDMA MIN. |
| 3290 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3291 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3292 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3293 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3294 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3295 | |
| 3296 | final long identity = Binder.clearCallingIdentity(); |
| 3297 | try { |
| 3298 | final Phone phone = getPhone(subId); |
| 3299 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3300 | return phone.getCdmaMin(); |
| 3301 | } else { |
| 3302 | return null; |
| 3303 | } |
| 3304 | } finally { |
| 3305 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3306 | } |
| 3307 | } |
| 3308 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3309 | @Override |
| 3310 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3311 | INumberVerificationCallback callback, String callingPackage) { |
| 3312 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3313 | != PERMISSION_GRANTED) { |
| 3314 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3315 | } |
| 3316 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3317 | |
| 3318 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3319 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3320 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3321 | + "calling package: " + callingPackage |
| 3322 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3323 | } |
| 3324 | |
| 3325 | if (range == null) { |
| 3326 | throw new NullPointerException("Range must be non-null"); |
| 3327 | } |
| 3328 | |
| 3329 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3330 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3331 | |
| 3332 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3333 | } |
| 3334 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3335 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3336 | * Returns true if CDMA provisioning needs to run. |
| 3337 | */ |
| 3338 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3339 | final long identity = Binder.clearCallingIdentity(); |
| 3340 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3341 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3342 | } finally { |
| 3343 | Binder.restoreCallingIdentity(identity); |
| 3344 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3345 | } |
| 3346 | |
| 3347 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3348 | * Sets the voice mail number of a given subId. |
| 3349 | */ |
| 3350 | @Override |
| 3351 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3352 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3353 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3354 | |
| 3355 | final long identity = Binder.clearCallingIdentity(); |
| 3356 | try { |
| 3357 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3358 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3359 | return success; |
| 3360 | } finally { |
| 3361 | Binder.restoreCallingIdentity(identity); |
| 3362 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3363 | } |
| 3364 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3365 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3366 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3367 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3368 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3369 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3370 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3371 | throw new SecurityException("caller must be system dialer"); |
| 3372 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3373 | |
| 3374 | final long identity = Binder.clearCallingIdentity(); |
| 3375 | try { |
| 3376 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3377 | if (phoneAccountHandle == null) { |
| 3378 | return null; |
| 3379 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3380 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3381 | } finally { |
| 3382 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3383 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3384 | } |
| 3385 | |
| 3386 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3387 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3388 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3389 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3390 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3391 | mApp, subId, callingPackage, callingFeatureId, |
| 3392 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3393 | return null; |
| 3394 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3395 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3396 | final long identity = Binder.clearCallingIdentity(); |
| 3397 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3398 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3399 | } finally { |
| 3400 | Binder.restoreCallingIdentity(identity); |
| 3401 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3402 | } |
| 3403 | |
| 3404 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3405 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3406 | VisualVoicemailSmsFilterSettings settings) { |
| 3407 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3408 | |
| 3409 | final long identity = Binder.clearCallingIdentity(); |
| 3410 | try { |
| 3411 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3412 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3413 | } finally { |
| 3414 | Binder.restoreCallingIdentity(identity); |
| 3415 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3416 | } |
| 3417 | |
| 3418 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3419 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3420 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3421 | |
| 3422 | final long identity = Binder.clearCallingIdentity(); |
| 3423 | try { |
| 3424 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3425 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3426 | } finally { |
| 3427 | Binder.restoreCallingIdentity(identity); |
| 3428 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3429 | } |
| 3430 | |
| 3431 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3432 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3433 | String callingPackage, int subId) { |
| 3434 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3435 | |
| 3436 | final long identity = Binder.clearCallingIdentity(); |
| 3437 | try { |
| 3438 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3439 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3440 | } finally { |
| 3441 | Binder.restoreCallingIdentity(identity); |
| 3442 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3443 | } |
| 3444 | |
| 3445 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3446 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3447 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3448 | |
| 3449 | final long identity = Binder.clearCallingIdentity(); |
| 3450 | try { |
| 3451 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3452 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3453 | } finally { |
| 3454 | Binder.restoreCallingIdentity(identity); |
| 3455 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3456 | } |
| 3457 | |
| 3458 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3459 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3460 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3461 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3462 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3463 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3464 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3465 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3466 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3467 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3468 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3469 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3470 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3471 | * Sets the voice activation state of a given subId. |
| 3472 | */ |
| 3473 | @Override |
| 3474 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3475 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3476 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3477 | |
| 3478 | final long identity = Binder.clearCallingIdentity(); |
| 3479 | try { |
| 3480 | final Phone phone = getPhone(subId); |
| 3481 | if (phone != null) { |
| 3482 | phone.setVoiceActivationState(activationState); |
| 3483 | } else { |
| 3484 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3485 | } |
| 3486 | } finally { |
| 3487 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3488 | } |
| 3489 | } |
| 3490 | |
| 3491 | /** |
| 3492 | * Sets the data activation state of a given subId. |
| 3493 | */ |
| 3494 | @Override |
| 3495 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3496 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3497 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3498 | |
| 3499 | final long identity = Binder.clearCallingIdentity(); |
| 3500 | try { |
| 3501 | final Phone phone = getPhone(subId); |
| 3502 | if (phone != null) { |
| 3503 | phone.setDataActivationState(activationState); |
| 3504 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3505 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3506 | } |
| 3507 | } finally { |
| 3508 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3509 | } |
| 3510 | } |
| 3511 | |
| 3512 | /** |
| 3513 | * Returns the voice activation state of a given subId. |
| 3514 | */ |
| 3515 | @Override |
| 3516 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3517 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3518 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3519 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3520 | final long identity = Binder.clearCallingIdentity(); |
| 3521 | try { |
| 3522 | if (phone != null) { |
| 3523 | return phone.getVoiceActivationState(); |
| 3524 | } else { |
| 3525 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3526 | } |
| 3527 | } finally { |
| 3528 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3529 | } |
| 3530 | } |
| 3531 | |
| 3532 | /** |
| 3533 | * Returns the data activation state of a given subId. |
| 3534 | */ |
| 3535 | @Override |
| 3536 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3537 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3538 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3539 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3540 | final long identity = Binder.clearCallingIdentity(); |
| 3541 | try { |
| 3542 | if (phone != null) { |
| 3543 | return phone.getDataActivationState(); |
| 3544 | } else { |
| 3545 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3546 | } |
| 3547 | } finally { |
| 3548 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3549 | } |
| 3550 | } |
| 3551 | |
| 3552 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3553 | * Returns the unread count of voicemails for a subId |
| 3554 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3555 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3556 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3557 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3558 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3559 | mApp, subId, callingPackage, callingFeatureId, |
| 3560 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3561 | return 0; |
| 3562 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3563 | final long identity = Binder.clearCallingIdentity(); |
| 3564 | try { |
| 3565 | final Phone phone = getPhone(subId); |
| 3566 | if (phone != null) { |
| 3567 | return phone.getVoiceMessageCount(); |
| 3568 | } else { |
| 3569 | return 0; |
| 3570 | } |
| 3571 | } finally { |
| 3572 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3573 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3574 | } |
| 3575 | |
| 3576 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3577 | * returns true, if the device is in a state where both voice and data |
| 3578 | * are supported simultaneously. This can change based on location or network condition. |
| 3579 | */ |
| 3580 | @Override |
| 3581 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3582 | final long identity = Binder.clearCallingIdentity(); |
| 3583 | try { |
| 3584 | final Phone phone = getPhone(subId); |
| 3585 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3586 | } finally { |
| 3587 | Binder.restoreCallingIdentity(identity); |
| 3588 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3589 | } |
| 3590 | |
| 3591 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3592 | * Send the dialer code if called from the current default dialer or the caller has |
| 3593 | * carrier privilege. |
| 3594 | * @param inputCode The dialer code to send |
| 3595 | */ |
| 3596 | @Override |
| 3597 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3598 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3599 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3600 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3601 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3602 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3603 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3604 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3605 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3606 | |
| 3607 | final long identity = Binder.clearCallingIdentity(); |
| 3608 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3609 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3610 | } finally { |
| 3611 | Binder.restoreCallingIdentity(identity); |
| 3612 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3613 | } |
| 3614 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3615 | @Override |
| 3616 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3617 | TelephonyPermissions |
| 3618 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3619 | mApp, subId, "getNetworkSelectionMode"); |
| 3620 | final long identity = Binder.clearCallingIdentity(); |
| 3621 | try { |
| 3622 | if (!isActiveSubscription(subId)) { |
| 3623 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3624 | } |
| 3625 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3626 | } finally { |
| 3627 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3628 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3629 | } |
| 3630 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3631 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3632 | public boolean isInEmergencySmsMode() { |
| 3633 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3634 | final long identity = Binder.clearCallingIdentity(); |
| 3635 | try { |
| 3636 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3637 | if (phone.isInEmergencySmsMode()) { |
| 3638 | return true; |
| 3639 | } |
| 3640 | } |
| 3641 | } finally { |
| 3642 | Binder.restoreCallingIdentity(identity); |
| 3643 | } |
| 3644 | return false; |
| 3645 | } |
| 3646 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3647 | /** |
| 3648 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3649 | * @param subId The subscription to use to check the configuration. |
| 3650 | * @param c The callback that will be used to send the result. |
| 3651 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3652 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3653 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3654 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3655 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3656 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3657 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3658 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3659 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3660 | "IMS not available on device."); |
| 3661 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3662 | final long token = Binder.clearCallingIdentity(); |
| 3663 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3664 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3665 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3666 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3667 | } catch (ImsException e) { |
| 3668 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3669 | } finally { |
| 3670 | Binder.restoreCallingIdentity(token); |
| 3671 | } |
| 3672 | } |
| 3673 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3674 | /** |
| 3675 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3676 | * @param subId The subscription to use to check the configuration. |
| 3677 | * @param c The callback that will be used to send the result. |
| 3678 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3679 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3680 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3681 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3682 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3683 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3684 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3685 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3686 | final long token = Binder.clearCallingIdentity(); |
| 3687 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3688 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3689 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3690 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3691 | } catch (ImsException e) { |
| 3692 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3693 | + "is inactive, ignoring unregister."); |
| 3694 | // If the subscription is no longer active, just return, since the callback |
| 3695 | // will already have been removed internally. |
| 3696 | } finally { |
| 3697 | Binder.restoreCallingIdentity(token); |
| 3698 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3699 | } |
| 3700 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3701 | /** |
| 3702 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3703 | */ |
| 3704 | @Override |
| 3705 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3706 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3707 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3708 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3709 | "IMS not available on device."); |
| 3710 | } |
| 3711 | final long token = Binder.clearCallingIdentity(); |
| 3712 | try { |
| 3713 | Phone phone = getPhone(subId); |
| 3714 | if (phone == null) { |
| 3715 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3716 | + subId + "'"); |
| 3717 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3718 | } |
| 3719 | phone.getImsRegistrationState(regState -> { |
| 3720 | try { |
| 3721 | consumer.accept((regState == null) |
| 3722 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3723 | } catch (RemoteException e) { |
| 3724 | // Ignore if the remote process is no longer available to call back. |
| 3725 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3726 | } |
| 3727 | }); |
| 3728 | } finally { |
| 3729 | Binder.restoreCallingIdentity(token); |
| 3730 | } |
| 3731 | } |
| 3732 | |
| 3733 | /** |
| 3734 | * Get the transport type for the IMS service registration state. |
| 3735 | */ |
| 3736 | @Override |
| 3737 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3738 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3739 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3740 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3741 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3742 | "IMS not available on device."); |
| 3743 | } |
| 3744 | final long token = Binder.clearCallingIdentity(); |
| 3745 | try { |
| 3746 | Phone phone = getPhone(subId); |
| 3747 | if (phone == null) { |
| 3748 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3749 | + subId + "'"); |
| 3750 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3751 | } |
| 3752 | phone.getImsRegistrationTech(regTech -> { |
| 3753 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3754 | int regTechConverted = (regTech == null) |
| 3755 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3756 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3757 | regTechConverted); |
| 3758 | try { |
| 3759 | consumer.accept(regTechConverted); |
| 3760 | } catch (RemoteException e) { |
| 3761 | // Ignore if the remote process is no longer available to call back. |
| 3762 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3763 | } |
| 3764 | }); |
| 3765 | } finally { |
| 3766 | Binder.restoreCallingIdentity(token); |
| 3767 | } |
| 3768 | } |
| 3769 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3770 | /** |
| 3771 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3772 | * @param subId The subscription to use to check the configuration. |
| 3773 | * @param c The callback that will be used to send the result. |
| 3774 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3775 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3776 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3777 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3778 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3779 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3780 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3781 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3782 | "IMS not available on device."); |
| 3783 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3784 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3785 | final long token = Binder.clearCallingIdentity(); |
| 3786 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3787 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3788 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3789 | } catch (ImsException e) { |
| 3790 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3791 | } finally { |
| 3792 | Binder.restoreCallingIdentity(token); |
| 3793 | } |
| 3794 | } |
| 3795 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3796 | /** |
| 3797 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3798 | * @param subId The subscription to use to check the configuration. |
| 3799 | * @param c The callback that will be used to send the result. |
| 3800 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3801 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3802 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3803 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3804 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3805 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3806 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3807 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3808 | |
| 3809 | final long token = Binder.clearCallingIdentity(); |
| 3810 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3811 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3812 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3813 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3814 | } catch (ImsException e) { |
| 3815 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3816 | + "is inactive, ignoring unregister."); |
| 3817 | // If the subscription is no longer active, just return, since the callback |
| 3818 | // will already have been removed internally. |
| 3819 | } finally { |
| 3820 | Binder.restoreCallingIdentity(token); |
| 3821 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3822 | } |
| 3823 | |
| 3824 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3825 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3826 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3827 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3828 | final long token = Binder.clearCallingIdentity(); |
| 3829 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3830 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3831 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3832 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3833 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3834 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3835 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3836 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3837 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3838 | } finally { |
| 3839 | Binder.restoreCallingIdentity(token); |
| 3840 | } |
| 3841 | } |
| 3842 | |
| 3843 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3844 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3845 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3846 | final long token = Binder.clearCallingIdentity(); |
| 3847 | try { |
| 3848 | Phone phone = getPhone(subId); |
| 3849 | if (phone == null) return false; |
| 3850 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3851 | } catch (com.android.ims.ImsException e) { |
| 3852 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3853 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3854 | } finally { |
| 3855 | Binder.restoreCallingIdentity(token); |
| 3856 | } |
| 3857 | } |
| 3858 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3859 | /** |
| 3860 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3861 | * subscription. |
| 3862 | * @param subId The subscription to use to check the configuration. |
| 3863 | * @param callback The callback that will be used to send the result. |
| 3864 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3865 | * @param transportType The transport type of the MmTelFeature capability. |
| 3866 | */ |
| 3867 | @Override |
| 3868 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3869 | int transportType) { |
| 3870 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3871 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3872 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3873 | "IMS not available on device."); |
| 3874 | } |
| 3875 | final long token = Binder.clearCallingIdentity(); |
| 3876 | try { |
| 3877 | int slotId = getSlotIndex(subId); |
| 3878 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3879 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3880 | + subId + "'"); |
| 3881 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3882 | } |
| 3883 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3884 | transportType, aBoolean -> { |
| 3885 | try { |
| 3886 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3887 | } catch (RemoteException e) { |
| 3888 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3889 | + "running. Ignore"); |
| 3890 | } |
| 3891 | }); |
| 3892 | } finally { |
| 3893 | Binder.restoreCallingIdentity(token); |
| 3894 | } |
| 3895 | } |
| 3896 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3897 | /** |
| 3898 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3899 | * @param subId The subscription to use to check the configuration. |
| 3900 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3901 | @Override |
| 3902 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3903 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3904 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3905 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3906 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3907 | final long token = Binder.clearCallingIdentity(); |
| 3908 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3909 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3910 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3911 | } catch (ImsException e) { |
| 3912 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3913 | } finally { |
| 3914 | Binder.restoreCallingIdentity(token); |
| 3915 | } |
| 3916 | } |
| 3917 | |
| 3918 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3919 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3920 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3921 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3922 | final long identity = Binder.clearCallingIdentity(); |
| 3923 | try { |
| 3924 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3925 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3926 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3927 | } catch (ImsException e) { |
| 3928 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3929 | } finally { |
| 3930 | Binder.restoreCallingIdentity(identity); |
| 3931 | } |
| 3932 | } |
| 3933 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3934 | /** |
| 3935 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3936 | * @param subId The subscription to use to check the configuration. |
| 3937 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3938 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3939 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3940 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3941 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3942 | final long identity = Binder.clearCallingIdentity(); |
| 3943 | try { |
| 3944 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3945 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3946 | } catch (ImsException e) { |
| 3947 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3948 | } finally { |
| 3949 | Binder.restoreCallingIdentity(identity); |
| 3950 | } |
| 3951 | } |
| 3952 | |
| 3953 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3954 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3955 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3956 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3957 | final long identity = Binder.clearCallingIdentity(); |
| 3958 | try { |
| 3959 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3960 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3961 | } catch (ImsException e) { |
| 3962 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3963 | } finally { |
| 3964 | Binder.restoreCallingIdentity(identity); |
| 3965 | } |
| 3966 | } |
| 3967 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3968 | /** |
| 3969 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3970 | * @param subId The subscription to use to check the configuration. |
| 3971 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3972 | @Override |
| 3973 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3974 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3975 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3976 | final long identity = Binder.clearCallingIdentity(); |
| 3977 | try { |
| 3978 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3979 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3980 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3981 | } catch (ImsException e) { |
| 3982 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3983 | } finally { |
| 3984 | Binder.restoreCallingIdentity(identity); |
| 3985 | } |
| 3986 | } |
| 3987 | |
| 3988 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3989 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3990 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3991 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3992 | final long identity = Binder.clearCallingIdentity(); |
| 3993 | try { |
| 3994 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3995 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3996 | } catch (ImsException e) { |
| 3997 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3998 | } finally { |
| 3999 | Binder.restoreCallingIdentity(identity); |
| 4000 | } |
| 4001 | } |
| 4002 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4003 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4004 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4005 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4006 | * @param subId The subscription to use to check the configuration. |
| 4007 | */ |
| 4008 | @Override |
| 4009 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
| 4010 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4011 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4012 | final long identity = Binder.clearCallingIdentity(); |
| 4013 | try { |
| 4014 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4015 | return ImsManager.getInstance(mApp, |
| 4016 | getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser(); |
| 4017 | } catch (ImsException e) { |
| 4018 | throw new ServiceSpecificException(e.getCode()); |
| 4019 | } finally { |
| 4020 | Binder.restoreCallingIdentity(identity); |
| 4021 | } |
| 4022 | } |
| 4023 | |
| 4024 | /** |
| 4025 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4026 | * Requires MODIFY_PHONE_STATE permission. |
| 4027 | * @param subId The subscription to use to check the configuration. |
| 4028 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4029 | * false otherwise |
| 4030 | */ |
| 4031 | @Override |
| 4032 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4033 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4034 | "setCrossSimCallingEnabled"); |
| 4035 | final long identity = Binder.clearCallingIdentity(); |
| 4036 | try { |
| 4037 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4038 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 4039 | .setCrossSimCallingEnabled(isEnabled); |
| 4040 | } catch (ImsException e) { |
| 4041 | throw new ServiceSpecificException(e.getCode()); |
| 4042 | } finally { |
| 4043 | Binder.restoreCallingIdentity(identity); |
| 4044 | } |
| 4045 | } |
| 4046 | |
| 4047 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4048 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4049 | * @param subId The subscription to use to check the configuration. |
| 4050 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4051 | @Override |
| 4052 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4053 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4054 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4055 | final long identity = Binder.clearCallingIdentity(); |
| 4056 | try { |
| 4057 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4058 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4059 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4060 | } catch (ImsException e) { |
| 4061 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4062 | } finally { |
| 4063 | Binder.restoreCallingIdentity(identity); |
| 4064 | } |
| 4065 | } |
| 4066 | |
| 4067 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4068 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4069 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4070 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4071 | final long identity = Binder.clearCallingIdentity(); |
| 4072 | try { |
| 4073 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4074 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4075 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4076 | } catch (ImsException e) { |
| 4077 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4078 | } finally { |
| 4079 | Binder.restoreCallingIdentity(identity); |
| 4080 | } |
| 4081 | } |
| 4082 | |
| 4083 | @Override |
| 4084 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4085 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4086 | "setVoWiFiNonPersistent"); |
| 4087 | final long identity = Binder.clearCallingIdentity(); |
| 4088 | try { |
| 4089 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4090 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 4091 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4092 | } catch (ImsException e) { |
| 4093 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4094 | } finally { |
| 4095 | Binder.restoreCallingIdentity(identity); |
| 4096 | } |
| 4097 | } |
| 4098 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4099 | /** |
| 4100 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4101 | * @param subId The subscription to use to check the configuration. |
| 4102 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4103 | @Override |
| 4104 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4105 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4106 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4107 | final long identity = Binder.clearCallingIdentity(); |
| 4108 | try { |
| 4109 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4110 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4111 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4112 | } catch (ImsException e) { |
| 4113 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4114 | } finally { |
| 4115 | Binder.restoreCallingIdentity(identity); |
| 4116 | } |
| 4117 | } |
| 4118 | |
| 4119 | @Override |
| 4120 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4121 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4122 | "setVoWiFiModeSetting"); |
| 4123 | final long identity = Binder.clearCallingIdentity(); |
| 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, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4127 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4128 | } catch (ImsException e) { |
| 4129 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4130 | } finally { |
| 4131 | Binder.restoreCallingIdentity(identity); |
| 4132 | } |
| 4133 | } |
| 4134 | |
| 4135 | @Override |
| 4136 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4137 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4138 | final long identity = Binder.clearCallingIdentity(); |
| 4139 | try { |
| 4140 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4141 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4142 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4143 | } catch (ImsException e) { |
| 4144 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4145 | } finally { |
| 4146 | Binder.restoreCallingIdentity(identity); |
| 4147 | } |
| 4148 | } |
| 4149 | |
| 4150 | @Override |
| 4151 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4152 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4153 | "setVoWiFiRoamingModeSetting"); |
| 4154 | final long identity = Binder.clearCallingIdentity(); |
| 4155 | try { |
| 4156 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4157 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4158 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4159 | } catch (ImsException e) { |
| 4160 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4161 | } finally { |
| 4162 | Binder.restoreCallingIdentity(identity); |
| 4163 | } |
| 4164 | } |
| 4165 | |
| 4166 | @Override |
| 4167 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4168 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4169 | "setRttCapabilityEnabled"); |
| 4170 | final long identity = Binder.clearCallingIdentity(); |
| 4171 | try { |
| 4172 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4173 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 4174 | } catch (ImsException e) { |
| 4175 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4176 | } finally { |
| 4177 | Binder.restoreCallingIdentity(identity); |
| 4178 | } |
| 4179 | } |
| 4180 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4181 | /** |
| 4182 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4183 | * @param subId The subscription to use to check the configuration. |
| 4184 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4185 | @Override |
| 4186 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4187 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4188 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4189 | final long identity = Binder.clearCallingIdentity(); |
| 4190 | try { |
| 4191 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4192 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4193 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4194 | } catch (ImsException e) { |
| 4195 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4196 | } finally { |
| 4197 | Binder.restoreCallingIdentity(identity); |
| 4198 | } |
| 4199 | } |
| 4200 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4201 | @Override |
| 4202 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4203 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4204 | final long identity = Binder.clearCallingIdentity(); |
| 4205 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4206 | if (!isImsAvailableOnDevice()) { |
| 4207 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4208 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4209 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4210 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4211 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4212 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4213 | } catch (ImsException e) { |
| 4214 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4215 | } finally { |
| 4216 | Binder.restoreCallingIdentity(identity); |
| 4217 | } |
| 4218 | } |
| 4219 | |
| 4220 | @Override |
| 4221 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4222 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4223 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4224 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4225 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4226 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4227 | try { |
| 4228 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4229 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4230 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4231 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4232 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4233 | + "is inactive, ignoring unregister."); |
| 4234 | // If the subscription is no longer active, just return, since the callback will already |
| 4235 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4236 | } finally { |
| 4237 | Binder.restoreCallingIdentity(identity); |
| 4238 | } |
| 4239 | } |
| 4240 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4241 | |
| 4242 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4243 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4244 | message); |
| 4245 | } |
| 4246 | |
| 4247 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4248 | boolean isMmtelCapability) { |
| 4249 | Phone phone = getPhone(subId); |
| 4250 | if (phone == null) { |
| 4251 | loge("phone instance null for subid " + subId); |
| 4252 | return false; |
| 4253 | } |
| 4254 | if (isMmtelCapability) { |
| 4255 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4256 | return false; |
| 4257 | } |
| 4258 | } else { |
| 4259 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4260 | return false; |
| 4261 | } |
| 4262 | } |
| 4263 | return true; |
| 4264 | } |
| 4265 | |
| 4266 | @Override |
| 4267 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4268 | boolean isProvisioned) { |
| 4269 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4270 | |
| 4271 | final long identity = Binder.clearCallingIdentity(); |
| 4272 | try { |
| 4273 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4274 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4275 | return; |
| 4276 | } |
| 4277 | |
| 4278 | // this capability requires provisioning, route to the correct API. |
| 4279 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4280 | switch (capability) { |
| 4281 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4282 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4283 | ims.setEabProvisioned(isProvisioned); |
| 4284 | break; |
| 4285 | default: { |
| 4286 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4287 | + "rcs capability '" + capability + "', which does not require " |
| 4288 | + "provisioning."); |
| 4289 | } |
| 4290 | } |
| 4291 | } finally { |
| 4292 | Binder.restoreCallingIdentity(identity); |
| 4293 | } |
| 4294 | |
| 4295 | } |
| 4296 | |
| 4297 | |
| 4298 | @Override |
| 4299 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4300 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4301 | final long identity = Binder.clearCallingIdentity(); |
| 4302 | try { |
| 4303 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4304 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4305 | return true; |
| 4306 | } |
| 4307 | |
| 4308 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4309 | switch (capability) { |
| 4310 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4311 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4312 | return ims.isEabProvisionedOnDevice(); |
| 4313 | |
| 4314 | default: { |
| 4315 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4316 | + "capability '" + capability + "', which does not require " |
| 4317 | + "provisioning."); |
| 4318 | } |
| 4319 | } |
| 4320 | |
| 4321 | } finally { |
| 4322 | Binder.restoreCallingIdentity(identity); |
| 4323 | } |
| 4324 | } |
| 4325 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4326 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4327 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4328 | boolean isProvisioned) { |
| 4329 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4330 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4331 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4332 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4333 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4334 | final long identity = Binder.clearCallingIdentity(); |
| 4335 | try { |
| 4336 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4337 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4338 | return; |
| 4339 | } |
| 4340 | |
| 4341 | // this capability requires provisioning, route to the correct API. |
| 4342 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4343 | switch (capability) { |
| 4344 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4345 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4346 | ims.setVolteProvisioned(isProvisioned); |
| 4347 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4348 | ims.setWfcProvisioned(isProvisioned); |
| 4349 | } |
| 4350 | break; |
| 4351 | } |
| 4352 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4353 | // There is currently no difference in VT provisioning type. |
| 4354 | ims.setVtProvisioned(isProvisioned); |
| 4355 | break; |
| 4356 | } |
| 4357 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4358 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4359 | // change the capability of the feature instead if needed. |
| 4360 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4361 | == isProvisioned) { |
| 4362 | // No change in provisioning. |
| 4363 | return; |
| 4364 | } |
| 4365 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4366 | try { |
| 4367 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4368 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4369 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4370 | + ", Exception" + e.getMessage()); |
| 4371 | } |
| 4372 | break; |
| 4373 | } |
| 4374 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4375 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4376 | + "MmTel capability '" + capability + "', which does not require " |
| 4377 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4378 | } |
| 4379 | } |
| 4380 | |
| 4381 | } finally { |
| 4382 | Binder.restoreCallingIdentity(identity); |
| 4383 | } |
| 4384 | } |
| 4385 | |
| 4386 | @Override |
| 4387 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4388 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4389 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4390 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4391 | } |
| 4392 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4393 | final long identity = Binder.clearCallingIdentity(); |
| 4394 | try { |
| 4395 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4396 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4397 | return true; |
| 4398 | } |
| 4399 | |
| 4400 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4401 | switch (capability) { |
| 4402 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4403 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4404 | return ims.isVolteProvisionedOnDevice(); |
| 4405 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4406 | return ims.isWfcProvisionedOnDevice(); |
| 4407 | } |
| 4408 | // This should never happen, since we are checking tech above to make sure it |
| 4409 | // is either LTE or IWLAN. |
| 4410 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4411 | + "capability."); |
| 4412 | } |
| 4413 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4414 | // There is currently no difference in VT provisioning type. |
| 4415 | return ims.isVtProvisionedOnDevice(); |
| 4416 | } |
| 4417 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4418 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4419 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4420 | } |
| 4421 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4422 | throw new IllegalArgumentException( |
| 4423 | "Tried to get provisioning for MmTel capability '" + capability |
| 4424 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4425 | } |
| 4426 | } |
| 4427 | |
| 4428 | } finally { |
| 4429 | Binder.restoreCallingIdentity(identity); |
| 4430 | } |
| 4431 | } |
| 4432 | |
| 4433 | @Override |
| 4434 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4435 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4436 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4437 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4438 | } |
| 4439 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4440 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4441 | return (provisionedBits & capability) > 0; |
| 4442 | } |
| 4443 | |
| 4444 | @Override |
| 4445 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4446 | boolean isProvisioned) { |
| 4447 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4448 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4449 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4450 | } |
| 4451 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4452 | "setProvisioningStatusForCapability"); |
| 4453 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4454 | // If the current provisioning status for capability already matches isProvisioned, |
| 4455 | // do nothing. |
| 4456 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4457 | return; |
| 4458 | } |
| 4459 | if (isProvisioned) { |
| 4460 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4461 | } else { |
| 4462 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4463 | } |
| 4464 | } |
| 4465 | |
| 4466 | /** |
| 4467 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4468 | * technology. The bitfield should mirror the bitfield defined by |
| 4469 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4470 | */ |
| 4471 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4472 | String key = getMmTelProvisioningKey(subId, tech); |
| 4473 | // Default is no capabilities are provisioned. |
| 4474 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4475 | } |
| 4476 | |
| 4477 | /** |
| 4478 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4479 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4480 | * technology specified. |
| 4481 | * |
| 4482 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4483 | */ |
| 4484 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4485 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4486 | String key = getMmTelProvisioningKey(subId, tech); |
| 4487 | editor.putInt(key, newField); |
| 4488 | editor.commit(); |
| 4489 | } |
| 4490 | |
| 4491 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4492 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4493 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4494 | } |
| 4495 | |
| 4496 | /** |
| 4497 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4498 | * carrier associated with the subscription id. |
| 4499 | */ |
| 4500 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4501 | int capability) { |
| 4502 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4503 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4504 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4505 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4506 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4507 | false); |
| 4508 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4509 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4510 | |
| 4511 | // First check to make sure that the capability requires provisioning. |
| 4512 | switch (capability) { |
| 4513 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4514 | // intentional fallthrough |
| 4515 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4516 | if (requireVoiceVtProvisioning) { |
| 4517 | // Voice and Video requires provisioning |
| 4518 | return true; |
| 4519 | } |
| 4520 | break; |
| 4521 | } |
| 4522 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4523 | if (requireUtProvisioning) { |
| 4524 | // UT requires provisioning |
| 4525 | return true; |
| 4526 | } |
| 4527 | break; |
| 4528 | } |
| 4529 | } |
| 4530 | return false; |
| 4531 | } |
| 4532 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4533 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4534 | int capability) { |
| 4535 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4536 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4537 | |
| 4538 | boolean requireRcsProvisioning = c.getBoolean( |
| 4539 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4540 | |
| 4541 | // First check to make sure that the capability requires provisioning. |
| 4542 | switch (capability) { |
| 4543 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4544 | // intentional fallthrough |
| 4545 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4546 | if (requireRcsProvisioning) { |
| 4547 | // OPTION or PRESENCE requires provisioning |
| 4548 | return true; |
| 4549 | } |
| 4550 | break; |
| 4551 | } |
| 4552 | } |
| 4553 | return false; |
| 4554 | } |
| 4555 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4556 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4557 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4558 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4559 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4560 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4561 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4562 | final long identity = Binder.clearCallingIdentity(); |
| 4563 | try { |
| 4564 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4565 | int slotId = getSlotIndex(subId); |
| 4566 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4567 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4568 | + subId + "' for key:" + key); |
| 4569 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4570 | } |
| 4571 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4572 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4573 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4574 | + subId + "' for key:" + key); |
| 4575 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4576 | } finally { |
| 4577 | Binder.restoreCallingIdentity(identity); |
| 4578 | } |
| 4579 | } |
| 4580 | |
| 4581 | @Override |
| 4582 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4583 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4584 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4585 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4586 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4587 | final long identity = Binder.clearCallingIdentity(); |
| 4588 | try { |
| 4589 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4590 | int slotId = getSlotIndex(subId); |
| 4591 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4592 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4593 | + subId + "' for key:" + key); |
| 4594 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4595 | } |
| 4596 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4597 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4598 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4599 | + subId + "' for key:" + key); |
| 4600 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4601 | } finally { |
| 4602 | Binder.restoreCallingIdentity(identity); |
| 4603 | } |
| 4604 | } |
| 4605 | |
| 4606 | @Override |
| 4607 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4608 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4609 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4610 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4611 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4612 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4613 | final long identity = Binder.clearCallingIdentity(); |
| 4614 | try { |
| 4615 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4616 | int slotId = getSlotIndex(subId); |
| 4617 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4618 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4619 | + subId + "' for key:" + key); |
| 4620 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4621 | } |
| 4622 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4623 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4624 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4625 | + "' for key:" + key); |
| 4626 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4627 | } finally { |
| 4628 | Binder.restoreCallingIdentity(identity); |
| 4629 | } |
| 4630 | } |
| 4631 | |
| 4632 | @Override |
| 4633 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4634 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4635 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4636 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4637 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4638 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4639 | final long identity = Binder.clearCallingIdentity(); |
| 4640 | try { |
| 4641 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4642 | int slotId = getSlotIndex(subId); |
| 4643 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4644 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4645 | + subId + "' for key:" + key); |
| 4646 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4647 | } |
| 4648 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4649 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4650 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4651 | + "' for key:" + key); |
| 4652 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4653 | } finally { |
| 4654 | Binder.restoreCallingIdentity(identity); |
| 4655 | } |
| 4656 | } |
| 4657 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4658 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4659 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4660 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4661 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4662 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4663 | } |
| 4664 | return slotId; |
| 4665 | } |
| 4666 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4667 | private int getSlotIndex(int subId) { |
| 4668 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4669 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4670 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4671 | } |
| 4672 | return slotId; |
| 4673 | } |
| 4674 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4675 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4676 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4677 | */ |
| 4678 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4679 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4680 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4681 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4682 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4683 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4684 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4685 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4686 | mApp, subId, callingPackage, callingFeatureId, |
| 4687 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4688 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4689 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4690 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4691 | final long identity = Binder.clearCallingIdentity(); |
| 4692 | try { |
| 4693 | final Phone phone = getPhone(subId); |
| 4694 | if (phone != null) { |
| 4695 | return phone.getServiceState().getDataNetworkType(); |
| 4696 | } else { |
| 4697 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4698 | } |
| 4699 | } finally { |
| 4700 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4701 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4702 | } |
| 4703 | |
| 4704 | /** |
| 4705 | * Returns the data network type |
| 4706 | */ |
| 4707 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4708 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4709 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4710 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4711 | } |
| 4712 | |
| 4713 | /** |
| 4714 | * Returns the data network type for a subId |
| 4715 | */ |
| 4716 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4717 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4718 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4719 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4720 | mApp, subId, callingPackage, callingFeatureId, |
| 4721 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4722 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4723 | } |
| 4724 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4725 | final long identity = Binder.clearCallingIdentity(); |
| 4726 | try { |
| 4727 | final Phone phone = getPhone(subId); |
| 4728 | if (phone != null) { |
| 4729 | return phone.getServiceState().getDataNetworkType(); |
| 4730 | } else { |
| 4731 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4732 | } |
| 4733 | } finally { |
| 4734 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4735 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4736 | } |
| 4737 | |
| 4738 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4739 | * Returns the Voice network type for a subId |
| 4740 | */ |
| 4741 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4742 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4743 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4744 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4745 | mApp, subId, callingPackage, callingFeatureId, |
| 4746 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4747 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4748 | } |
| 4749 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4750 | final long identity = Binder.clearCallingIdentity(); |
| 4751 | try { |
| 4752 | final Phone phone = getPhone(subId); |
| 4753 | if (phone != null) { |
| 4754 | return phone.getServiceState().getVoiceNetworkType(); |
| 4755 | } else { |
| 4756 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4757 | } |
| 4758 | } finally { |
| 4759 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4760 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4761 | } |
| 4762 | |
| 4763 | /** |
| 4764 | * @return true if a ICC card is present |
| 4765 | */ |
| 4766 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4767 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4768 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4769 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4770 | } |
| 4771 | |
| 4772 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4773 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4774 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4775 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4776 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4777 | final long identity = Binder.clearCallingIdentity(); |
| 4778 | try { |
| 4779 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4780 | if (phone != null) { |
| 4781 | return phone.getIccCard().hasIccCard(); |
| 4782 | } else { |
| 4783 | return false; |
| 4784 | } |
| 4785 | } finally { |
| 4786 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4787 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4788 | } |
| 4789 | |
| 4790 | /** |
| 4791 | * Return if the current radio is LTE on CDMA. This |
| 4792 | * is a tri-state return value as for a period of time |
| 4793 | * the mode may be unknown. |
| 4794 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4795 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4796 | * @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] | 4797 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4798 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4799 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4800 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4801 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4802 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4803 | } |
| 4804 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4805 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4806 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4807 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4808 | try { |
| 4809 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4810 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4811 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4812 | } |
| 4813 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4814 | final long identity = Binder.clearCallingIdentity(); |
| 4815 | try { |
| 4816 | final Phone phone = getPhone(subId); |
| 4817 | if (phone == null) { |
| 4818 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4819 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4820 | return TelephonyProperties.lte_on_cdma_device() |
| 4821 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4822 | } |
| 4823 | } finally { |
| 4824 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4825 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4826 | } |
| 4827 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4828 | /** |
| 4829 | * {@hide} |
| 4830 | * Returns Default subId, 0 in the case of single standby. |
| 4831 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4832 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4833 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4834 | } |
| 4835 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4836 | private int getSlotForDefaultSubscription() { |
| 4837 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4838 | } |
| 4839 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4840 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4841 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4842 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4843 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4844 | private boolean isActiveSubscription(int subId) { |
| 4845 | return mSubscriptionController.isActiveSubId(subId); |
| 4846 | } |
| 4847 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4848 | /** |
| 4849 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4850 | */ |
| 4851 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4852 | final long identity = Binder.clearCallingIdentity(); |
| 4853 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4854 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4855 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4856 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4857 | } finally { |
| 4858 | Binder.restoreCallingIdentity(identity); |
| 4859 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4860 | } |
| 4861 | |
| 4862 | /** |
| 4863 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4864 | */ |
| 4865 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4866 | final long identity = Binder.clearCallingIdentity(); |
| 4867 | try { |
| 4868 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4869 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4870 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4871 | } finally { |
| 4872 | Binder.restoreCallingIdentity(identity); |
| 4873 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4874 | } |
| 4875 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4876 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4877 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4878 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4879 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4880 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4881 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4882 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4883 | if (phoneId == -1) { |
| 4884 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4885 | + " does not correspond to an active phone"); |
| 4886 | } |
| 4887 | return PhoneFactory.getPhone(phoneId); |
| 4888 | } |
| 4889 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4890 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4891 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4892 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4893 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4894 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4895 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4896 | if (DBG) { |
| 4897 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4898 | } |
| 4899 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4900 | p2); |
| 4901 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4902 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4903 | |
| 4904 | @Override |
| 4905 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4906 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4907 | enforceModifyPermission(); |
| 4908 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4909 | if (DBG) { |
| 4910 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4911 | } |
| 4912 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4913 | callingPackage, aid, p2); |
| 4914 | } |
| 4915 | |
| 4916 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4917 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4918 | final long identity = Binder.clearCallingIdentity(); |
| 4919 | try { |
| 4920 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4921 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4922 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4923 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4924 | if (bestComponent == null |
| 4925 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4926 | loge("The calling package is not allowed to access ISD-R."); |
| 4927 | throw new SecurityException( |
| 4928 | "The calling package is not allowed to access ISD-R."); |
| 4929 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4930 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4931 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4932 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4933 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4934 | null /* workSource */); |
| 4935 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4936 | return response; |
| 4937 | } finally { |
| 4938 | Binder.restoreCallingIdentity(identity); |
| 4939 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4940 | } |
| 4941 | |
| 4942 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4943 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4944 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4945 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4946 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4947 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4948 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4949 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4950 | @Override |
| 4951 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4952 | enforceModifyPermission(); |
| 4953 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4954 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4955 | channel); |
| 4956 | } |
| 4957 | |
| 4958 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4959 | final long identity = Binder.clearCallingIdentity(); |
| 4960 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4961 | if (channel < 0) { |
| 4962 | return false; |
| 4963 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4964 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4965 | null /* workSource */); |
| 4966 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4967 | return success; |
| 4968 | } finally { |
| 4969 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4970 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4971 | } |
| 4972 | |
| 4973 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4974 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4975 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4976 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4977 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4978 | if (DBG) { |
| 4979 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4980 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4981 | + p3 + " data=" + data); |
| 4982 | } |
| 4983 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4984 | command, p1, p2, p3, data); |
| 4985 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4986 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4987 | @Override |
| 4988 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4989 | int command, int p1, int p2, int p3, String data) { |
| 4990 | enforceModifyPermission(); |
| 4991 | if (DBG) { |
| 4992 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4993 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4994 | + p3 + " data=" + data); |
| 4995 | } |
| 4996 | return iccTransmitApduLogicalChannelWithPermission( |
| 4997 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4998 | data); |
| 4999 | } |
| 5000 | |
| 5001 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5002 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5003 | final long identity = Binder.clearCallingIdentity(); |
| 5004 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5005 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5006 | return ""; |
| 5007 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5008 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5009 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5010 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5011 | null /* workSource */); |
| 5012 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5013 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5014 | // Append the returned status code to the end of the response payload. |
| 5015 | String s = Integer.toHexString( |
| 5016 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5017 | if (response.payload != null) { |
| 5018 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5019 | } |
| 5020 | return s; |
| 5021 | } finally { |
| 5022 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5023 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5024 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5025 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5026 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5027 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5028 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5029 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5030 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5031 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5032 | if (DBG) { |
| 5033 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5034 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5035 | } |
| 5036 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5037 | cla, command, p1, p2, p3, data); |
| 5038 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5039 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5040 | @Override |
| 5041 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 5042 | int command, int p1, int p2, int p3, String data) { |
| 5043 | enforceModifyPermission(); |
| 5044 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5045 | if (DBG) { |
| 5046 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 5047 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 5048 | + " data=" + data); |
| 5049 | } |
| 5050 | |
| 5051 | return iccTransmitApduBasicChannelWithPermission( |
| 5052 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 5053 | p2, p3, data); |
| 5054 | } |
| 5055 | |
| 5056 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5057 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5058 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5059 | final long identity = Binder.clearCallingIdentity(); |
| 5060 | try { |
| 5061 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5062 | && TextUtils.equals(ISDR_AID, data)) { |
| 5063 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5064 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5065 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5066 | if (bestComponent == null |
| 5067 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5068 | loge("The calling package is not allowed to select ISD-R."); |
| 5069 | throw new SecurityException( |
| 5070 | "The calling package is not allowed to select ISD-R."); |
| 5071 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5072 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5073 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5074 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5075 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5076 | null /* workSource */); |
| 5077 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5078 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5079 | // Append the returned status code to the end of the response payload. |
| 5080 | String s = Integer.toHexString( |
| 5081 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5082 | if (response.payload != null) { |
| 5083 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5084 | } |
| 5085 | return s; |
| 5086 | } finally { |
| 5087 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5088 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5089 | } |
| 5090 | |
| 5091 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5092 | 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] | 5093 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5094 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5095 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5096 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5097 | final long identity = Binder.clearCallingIdentity(); |
| 5098 | try { |
| 5099 | if (DBG) { |
| 5100 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5101 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5102 | } |
| 5103 | |
| 5104 | IccIoResult response = |
| 5105 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5106 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5107 | subId); |
| 5108 | |
| 5109 | if (DBG) { |
| 5110 | log("Exchange SIM_IO [R]" + response); |
| 5111 | } |
| 5112 | |
| 5113 | byte[] result = null; |
| 5114 | int length = 2; |
| 5115 | if (response.payload != null) { |
| 5116 | length = 2 + response.payload.length; |
| 5117 | result = new byte[length]; |
| 5118 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5119 | } else { |
| 5120 | result = new byte[length]; |
| 5121 | } |
| 5122 | |
| 5123 | result[length - 1] = (byte) response.sw2; |
| 5124 | result[length - 2] = (byte) response.sw1; |
| 5125 | return result; |
| 5126 | } finally { |
| 5127 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5128 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5129 | } |
| 5130 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5131 | /** |
| 5132 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5133 | * on a particular subscription |
| 5134 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5135 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5136 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5137 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5138 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5139 | return null; |
| 5140 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5141 | |
| 5142 | final long identity = Binder.clearCallingIdentity(); |
| 5143 | try { |
| 5144 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5145 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5146 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5147 | return null; |
| 5148 | } |
| 5149 | Object response = sendRequest( |
| 5150 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5151 | if (response instanceof String[]) { |
| 5152 | return (String[]) response; |
| 5153 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5154 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5155 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5156 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5157 | } finally { |
| 5158 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5159 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5160 | } |
| 5161 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5162 | /** |
| 5163 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5164 | * subscription. |
| 5165 | * |
| 5166 | * @param subId the id of the subscription. |
| 5167 | * @param appType the uicc app type, must be USIM or SIM. |
| 5168 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5169 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5170 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5171 | * @return number of fplmns that is successfully written to the SIM. |
| 5172 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5173 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5174 | String callingFeatureId) { |
| 5175 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 5176 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5177 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 5178 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 5179 | } |
| 5180 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5181 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5182 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5183 | } |
| 5184 | if (fplmns == null) { |
| 5185 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5186 | } |
| 5187 | for (String fplmn : fplmns) { |
| 5188 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5189 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5190 | } |
| 5191 | } |
| 5192 | final long identity = Binder.clearCallingIdentity(); |
| 5193 | try { |
| 5194 | Object response = sendRequest( |
| 5195 | CMD_SET_FORBIDDEN_PLMNS, |
| 5196 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5197 | subId); |
| 5198 | return (int) response; |
| 5199 | } finally { |
| 5200 | Binder.restoreCallingIdentity(identity); |
| 5201 | } |
| 5202 | } |
| 5203 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5204 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5205 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5206 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5207 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5208 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5209 | final long identity = Binder.clearCallingIdentity(); |
| 5210 | try { |
| 5211 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5212 | if (response.payload == null) { |
| 5213 | return ""; |
| 5214 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5215 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5216 | // Append the returned status code to the end of the response payload. |
| 5217 | String s = Integer.toHexString( |
| 5218 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5219 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5220 | return s; |
| 5221 | } finally { |
| 5222 | Binder.restoreCallingIdentity(identity); |
| 5223 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5224 | } |
| 5225 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5226 | /** |
| 5227 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5228 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5229 | * |
| 5230 | * @param itemID the ID of the item to read |
| 5231 | * @return the NV item as a String, or null on error. |
| 5232 | */ |
| 5233 | @Override |
| 5234 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5235 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5236 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5237 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5238 | |
| 5239 | final long identity = Binder.clearCallingIdentity(); |
| 5240 | try { |
| 5241 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5242 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5243 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5244 | return value; |
| 5245 | } finally { |
| 5246 | Binder.restoreCallingIdentity(identity); |
| 5247 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5248 | } |
| 5249 | |
| 5250 | /** |
| 5251 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5252 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5253 | * |
| 5254 | * @param itemID the ID of the item to read |
| 5255 | * @param itemValue the value to write, as a String |
| 5256 | * @return true on success; false on any failure |
| 5257 | */ |
| 5258 | @Override |
| 5259 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5260 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5261 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5262 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5263 | |
| 5264 | final long identity = Binder.clearCallingIdentity(); |
| 5265 | try { |
| 5266 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5267 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5268 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5269 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5270 | return success; |
| 5271 | } finally { |
| 5272 | Binder.restoreCallingIdentity(identity); |
| 5273 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5274 | } |
| 5275 | |
| 5276 | /** |
| 5277 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5278 | * Used for device configuration by some CDMA operators. |
| 5279 | * |
| 5280 | * @param preferredRoamingList byte array containing the new PRL |
| 5281 | * @return true on success; false on any failure |
| 5282 | */ |
| 5283 | @Override |
| 5284 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5285 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5286 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5287 | |
| 5288 | final long identity = Binder.clearCallingIdentity(); |
| 5289 | try { |
| 5290 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5291 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5292 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5293 | return success; |
| 5294 | } finally { |
| 5295 | Binder.restoreCallingIdentity(identity); |
| 5296 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5297 | } |
| 5298 | |
| 5299 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5300 | * 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] | 5301 | * Used for device configuration by some CDMA operators. |
| 5302 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5303 | * @param slotIndex - device slot. |
| 5304 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5305 | * @return true on success; false on any failure |
| 5306 | */ |
| 5307 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5308 | public boolean resetModemConfig(int slotIndex) { |
| 5309 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5310 | if (phone != null) { |
| 5311 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5312 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5313 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5314 | final long identity = Binder.clearCallingIdentity(); |
| 5315 | try { |
| 5316 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5317 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5318 | return success; |
| 5319 | } finally { |
| 5320 | Binder.restoreCallingIdentity(identity); |
| 5321 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5322 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5323 | return false; |
| 5324 | } |
| 5325 | |
| 5326 | /** |
| 5327 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5328 | * |
| 5329 | * @param slotIndex - device slot. |
| 5330 | * |
| 5331 | * @return true on success; false on any failure |
| 5332 | */ |
| 5333 | @Override |
| 5334 | public boolean rebootModem(int slotIndex) { |
| 5335 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5336 | if (phone != null) { |
| 5337 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5338 | mApp, phone.getSubId(), "rebootModem"); |
| 5339 | |
| 5340 | final long identity = Binder.clearCallingIdentity(); |
| 5341 | try { |
| 5342 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5343 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5344 | return success; |
| 5345 | } finally { |
| 5346 | Binder.restoreCallingIdentity(identity); |
| 5347 | } |
| 5348 | } |
| 5349 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5350 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5351 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5352 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5353 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5354 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5355 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5356 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5357 | return new String[0]; |
| 5358 | } |
| 5359 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5360 | final long identity = Binder.clearCallingIdentity(); |
| 5361 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5362 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5363 | } finally { |
| 5364 | Binder.restoreCallingIdentity(identity); |
| 5365 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5366 | } |
| 5367 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5368 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5369 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5370 | * {@link #disableIms(int)}. |
| 5371 | * @param slotIndex device slot. |
| 5372 | */ |
| 5373 | public void resetIms(int slotIndex) { |
| 5374 | enforceModifyPermission(); |
| 5375 | |
| 5376 | final long identity = Binder.clearCallingIdentity(); |
| 5377 | try { |
| 5378 | if (mImsResolver == null) { |
| 5379 | // may happen if the does not support IMS. |
| 5380 | return; |
| 5381 | } |
| 5382 | mImsResolver.disableIms(slotIndex); |
| 5383 | mImsResolver.enableIms(slotIndex); |
| 5384 | } finally { |
| 5385 | Binder.restoreCallingIdentity(identity); |
| 5386 | } |
| 5387 | } |
| 5388 | |
| 5389 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5390 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5391 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5392 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5393 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5394 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5395 | |
| 5396 | final long identity = Binder.clearCallingIdentity(); |
| 5397 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5398 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5399 | // may happen if the device does not support IMS. |
| 5400 | return; |
| 5401 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5402 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5403 | } finally { |
| 5404 | Binder.restoreCallingIdentity(identity); |
| 5405 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5406 | } |
| 5407 | |
| 5408 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5409 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5410 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5411 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5412 | public void disableIms(int slotId) { |
| 5413 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5414 | |
| 5415 | final long identity = Binder.clearCallingIdentity(); |
| 5416 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5417 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5418 | // may happen if the device does not support IMS. |
| 5419 | return; |
| 5420 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5421 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5422 | } finally { |
| 5423 | Binder.restoreCallingIdentity(identity); |
| 5424 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5425 | } |
| 5426 | |
| 5427 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5428 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5429 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5430 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5431 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5432 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5433 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5434 | |
| 5435 | final long identity = Binder.clearCallingIdentity(); |
| 5436 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5437 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5438 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5439 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5440 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5441 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5442 | } finally { |
| 5443 | Binder.restoreCallingIdentity(identity); |
| 5444 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5445 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5446 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5447 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5448 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5449 | @Override |
| 5450 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5451 | enforceModifyPermission(); |
| 5452 | |
| 5453 | final long identity = Binder.clearCallingIdentity(); |
| 5454 | try { |
| 5455 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5456 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5457 | } finally { |
| 5458 | Binder.restoreCallingIdentity(identity); |
| 5459 | } |
| 5460 | } |
| 5461 | |
| 5462 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5463 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5464 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5465 | */ |
| 5466 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5467 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5468 | |
| 5469 | final long identity = Binder.clearCallingIdentity(); |
| 5470 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5471 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5472 | // may happen if the device does not support IMS. |
| 5473 | return null; |
| 5474 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5475 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5476 | } finally { |
| 5477 | Binder.restoreCallingIdentity(identity); |
| 5478 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5479 | } |
| 5480 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5481 | /** |
| 5482 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5483 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5484 | */ |
| 5485 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5486 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5487 | |
| 5488 | final long identity = Binder.clearCallingIdentity(); |
| 5489 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5490 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5491 | // may happen if the device does not support IMS. |
| 5492 | return null; |
| 5493 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5494 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5495 | } finally { |
| 5496 | Binder.restoreCallingIdentity(identity); |
| 5497 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5498 | } |
| 5499 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5500 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5501 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5502 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5503 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5504 | * @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] | 5505 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5506 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5507 | * @param packageName The name of the package that the current configuration will be replaced |
| 5508 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5509 | * @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] | 5510 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5511 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5512 | int[] featureTypes, String packageName) { |
| 5513 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5514 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5515 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5516 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5517 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5518 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5519 | final long identity = Binder.clearCallingIdentity(); |
| 5520 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5521 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5522 | // may happen if the device does not support IMS. |
| 5523 | return false; |
| 5524 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5525 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5526 | for (int featureType : featureTypes) { |
| 5527 | featureConfig.put(featureType, packageName); |
| 5528 | } |
| 5529 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5530 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5531 | } finally { |
| 5532 | Binder.restoreCallingIdentity(identity); |
| 5533 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5534 | } |
| 5535 | |
| 5536 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5537 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5538 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5539 | * |
| 5540 | * This should only be used for testing. |
| 5541 | * |
| 5542 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5543 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5544 | */ |
| 5545 | @Override |
| 5546 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5547 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5548 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5549 | "clearCarrierImsServiceOverride"); |
| 5550 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5551 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5552 | "clearCarrierImsServiceOverride"); |
| 5553 | |
| 5554 | final long identity = Binder.clearCallingIdentity(); |
| 5555 | try { |
| 5556 | if (mImsResolver == null) { |
| 5557 | // may happen if the device does not support IMS. |
| 5558 | return false; |
| 5559 | } |
| 5560 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5561 | } finally { |
| 5562 | Binder.restoreCallingIdentity(identity); |
| 5563 | } |
| 5564 | } |
| 5565 | |
| 5566 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5567 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5568 | * |
| 5569 | * @param slotId The slot that the ImsService is associated with. |
| 5570 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5571 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5572 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5573 | * @return the package name of the ImsService configuration. |
| 5574 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5575 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5576 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5577 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5578 | TelephonyPermissions |
| 5579 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5580 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5581 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5582 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5583 | final long identity = Binder.clearCallingIdentity(); |
| 5584 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5585 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5586 | // may happen if the device does not support IMS. |
| 5587 | return ""; |
| 5588 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5589 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5590 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5591 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5592 | } finally { |
| 5593 | Binder.restoreCallingIdentity(identity); |
| 5594 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5595 | } |
| 5596 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5597 | /** |
| 5598 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5599 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5600 | * @param callback A callback with an integer containing the |
| 5601 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5602 | */ |
| 5603 | @Override |
| 5604 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5605 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5606 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5607 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5608 | "IMS not available on device."); |
| 5609 | } |
| 5610 | final long token = Binder.clearCallingIdentity(); |
| 5611 | try { |
| 5612 | int slotId = getSlotIndex(subId); |
| 5613 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5614 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5615 | + subId + "'"); |
| 5616 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5617 | } |
| 5618 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5619 | try { |
| 5620 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5621 | } catch (RemoteException e) { |
| 5622 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5623 | + "Ignore"); |
| 5624 | } |
| 5625 | }); |
| 5626 | } finally { |
| 5627 | Binder.restoreCallingIdentity(token); |
| 5628 | } |
| 5629 | } |
| 5630 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5631 | /** |
| 5632 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5633 | */ |
| 5634 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5635 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5636 | |
| 5637 | final long identity = Binder.clearCallingIdentity(); |
| 5638 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5639 | // NOTE: Before S, this method only set the default phone. |
| 5640 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5641 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5642 | phone.setImsRegistrationState(registered); |
| 5643 | } |
| 5644 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5645 | } finally { |
| 5646 | Binder.restoreCallingIdentity(identity); |
| 5647 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5648 | } |
| 5649 | |
| 5650 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5651 | * Set the network selection mode to automatic. |
| 5652 | * |
| 5653 | */ |
| 5654 | @Override |
| 5655 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5656 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5657 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5658 | |
| 5659 | final long identity = Binder.clearCallingIdentity(); |
| 5660 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5661 | if (!isActiveSubscription(subId)) { |
| 5662 | return; |
| 5663 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5664 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5665 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5666 | } finally { |
| 5667 | Binder.restoreCallingIdentity(identity); |
| 5668 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5669 | } |
| 5670 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5671 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5672 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5673 | * |
| 5674 | * @param subId the id of the subscription. |
| 5675 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5676 | * the operator to attach to. |
| 5677 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5678 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5679 | * normal network selection next time. |
| 5680 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5681 | */ |
| 5682 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5683 | public boolean setNetworkSelectionModeManual( |
| 5684 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5685 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5686 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5687 | |
| 5688 | if (!isActiveSubscription(subId)) { |
| 5689 | return false; |
| 5690 | } |
| 5691 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5692 | final long identity = Binder.clearCallingIdentity(); |
| 5693 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5694 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5695 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5696 | if (DBG) { |
| 5697 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5698 | + " operator: " + operatorInfo); |
| 5699 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5700 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5701 | } finally { |
| 5702 | Binder.restoreCallingIdentity(identity); |
| 5703 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5704 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5705 | /** |
| 5706 | * Get the manual network selection |
| 5707 | * |
| 5708 | * @param subId the id of the subscription. |
| 5709 | * |
| 5710 | * @return the previously saved user selected PLMN |
| 5711 | */ |
| 5712 | @Override |
| 5713 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5714 | TelephonyPermissions |
| 5715 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5716 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5717 | |
| 5718 | final long identity = Binder.clearCallingIdentity(); |
| 5719 | try { |
| 5720 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5721 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5722 | } |
| 5723 | |
| 5724 | final Phone phone = getPhone(subId); |
| 5725 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5726 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5727 | } |
| 5728 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5729 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5730 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5731 | } finally { |
| 5732 | Binder.restoreCallingIdentity(identity); |
| 5733 | } |
| 5734 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5735 | |
| 5736 | /** |
| 5737 | * Scans for available networks. |
| 5738 | */ |
| 5739 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5740 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5741 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5742 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5743 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5744 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5745 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5746 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5747 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5748 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5749 | .setCallingPid(Binder.getCallingPid()) |
| 5750 | .setCallingUid(Binder.getCallingUid()) |
| 5751 | .setMethod("getCellNetworkScanResults") |
| 5752 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 5753 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5754 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5755 | .build()); |
| 5756 | switch (locationResult) { |
| 5757 | case DENIED_HARD: |
| 5758 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5759 | case DENIED_SOFT: |
| 5760 | return null; |
| 5761 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5762 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5763 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5764 | try { |
| 5765 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5766 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5767 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5768 | } finally { |
| 5769 | Binder.restoreCallingIdentity(identity); |
| 5770 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5771 | } |
| 5772 | |
| 5773 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5774 | * Get the call forwarding info, given the call forwarding reason. |
| 5775 | */ |
| 5776 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5777 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5778 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5779 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5780 | long identity = Binder.clearCallingIdentity(); |
| 5781 | try { |
| 5782 | if (DBG) { |
| 5783 | log("getCallForwarding: subId " + subId |
| 5784 | + " callForwardingReason" + callForwardingReason); |
| 5785 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5786 | |
| 5787 | Phone phone = getPhone(subId); |
| 5788 | if (phone == null) { |
| 5789 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5790 | callback.onError( |
| 5791 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5792 | } catch (RemoteException e) { |
| 5793 | // ignore |
| 5794 | } |
| 5795 | return; |
| 5796 | } |
| 5797 | |
| 5798 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 5799 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 5800 | @Override |
| 5801 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 5802 | try { |
| 5803 | callback.onCallForwardingInfoAvailable(info); |
| 5804 | } catch (RemoteException e) { |
| 5805 | // ignore |
| 5806 | } |
| 5807 | } |
| 5808 | |
| 5809 | @Override |
| 5810 | public void onError(int error) { |
| 5811 | try { |
| 5812 | callback.onError(error); |
| 5813 | } catch (RemoteException e) { |
| 5814 | // ignore |
| 5815 | } |
| 5816 | } |
| 5817 | }); |
| 5818 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5819 | } finally { |
| 5820 | Binder.restoreCallingIdentity(identity); |
| 5821 | } |
| 5822 | } |
| 5823 | |
| 5824 | /** |
| 5825 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5826 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5827 | */ |
| 5828 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5829 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 5830 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5831 | enforceModifyPermission(); |
| 5832 | long identity = Binder.clearCallingIdentity(); |
| 5833 | try { |
| 5834 | if (DBG) { |
| 5835 | log("setCallForwarding: subId " + subId |
| 5836 | + " callForwardingInfo" + callForwardingInfo); |
| 5837 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5838 | |
| 5839 | Phone phone = getPhone(subId); |
| 5840 | if (phone == null) { |
| 5841 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5842 | callback.accept( |
| 5843 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5844 | } catch (RemoteException e) { |
| 5845 | // ignore |
| 5846 | } |
| 5847 | return; |
| 5848 | } |
| 5849 | |
| 5850 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 5851 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5852 | |
| 5853 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5854 | } finally { |
| 5855 | Binder.restoreCallingIdentity(identity); |
| 5856 | } |
| 5857 | } |
| 5858 | |
| 5859 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5860 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5861 | */ |
| 5862 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5863 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5864 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5865 | long identity = Binder.clearCallingIdentity(); |
| 5866 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5867 | |
| 5868 | Phone phone = getPhone(subId); |
| 5869 | if (phone == null) { |
| 5870 | try { |
| 5871 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5872 | } catch (RemoteException e) { |
| 5873 | // ignore |
| 5874 | } |
| 5875 | return; |
| 5876 | } |
| 5877 | |
| 5878 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 5879 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5880 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5881 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5882 | } finally { |
| 5883 | Binder.restoreCallingIdentity(identity); |
| 5884 | } |
| 5885 | } |
| 5886 | |
| 5887 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5888 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5889 | */ |
| 5890 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5891 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5892 | enforceModifyPermission(); |
| 5893 | long identity = Binder.clearCallingIdentity(); |
| 5894 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5895 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 5896 | |
| 5897 | Phone phone = getPhone(subId); |
| 5898 | if (phone == null) { |
| 5899 | try { |
| 5900 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5901 | } catch (RemoteException e) { |
| 5902 | // ignore |
| 5903 | } |
| 5904 | return; |
| 5905 | } |
| 5906 | |
| 5907 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 5908 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5909 | |
| 5910 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5911 | } finally { |
| 5912 | Binder.restoreCallingIdentity(identity); |
| 5913 | } |
| 5914 | } |
| 5915 | |
| 5916 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5917 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5918 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5919 | * @param subId id of the subscription |
| 5920 | * @param request contains the radio access networks with bands/channels to scan |
| 5921 | * @param messenger callback messenger for scan results or errors |
| 5922 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5923 | * @return the id of the requested scan which can be used to stop the scan. |
| 5924 | */ |
| 5925 | @Override |
| 5926 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5927 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5928 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5929 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5930 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5931 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5932 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5933 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5934 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5935 | .setCallingPid(Binder.getCallingPid()) |
| 5936 | .setCallingUid(Binder.getCallingUid()) |
| 5937 | .setMethod("requestNetworkScan") |
| 5938 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
James.cf Lin | 1d4d739 | 2020-07-03 18:22:53 +0800 | [diff] [blame] | 5939 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5940 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5941 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5942 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5943 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 5944 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5945 | if (e != null) { |
| 5946 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5947 | throw e; |
| 5948 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5949 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5950 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5951 | } |
| 5952 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5953 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5954 | int callingUid = Binder.getCallingUid(); |
| 5955 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5956 | final long identity = Binder.clearCallingIdentity(); |
| 5957 | try { |
| 5958 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5959 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5960 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5961 | } finally { |
| 5962 | Binder.restoreCallingIdentity(identity); |
| 5963 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5964 | } |
| 5965 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5966 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5967 | NetworkScanRequest request, int subId, String callingPackage) { |
| 5968 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5969 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5970 | boolean hasNetworkScanPermission = |
| 5971 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5972 | == PERMISSION_GRANTED; |
| 5973 | |
| 5974 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5975 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5976 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5977 | } |
| 5978 | |
| 5979 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5980 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5981 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5982 | return new SecurityException("Specific channels must not be" |
| 5983 | + " scanned without location access."); |
| 5984 | } |
| 5985 | } |
| 5986 | } |
| 5987 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5988 | return null; |
| 5989 | } |
| 5990 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5991 | /** |
| 5992 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5993 | * |
| 5994 | * @param subId id of the subscription |
| 5995 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5996 | */ |
| 5997 | @Override |
| 5998 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5999 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6000 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6001 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6002 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6003 | final long identity = Binder.clearCallingIdentity(); |
| 6004 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6005 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6006 | } finally { |
| 6007 | Binder.restoreCallingIdentity(identity); |
| 6008 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6009 | } |
| 6010 | |
| 6011 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6012 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6013 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6014 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6015 | */ |
| 6016 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6017 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6018 | TelephonyPermissions |
| 6019 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6020 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6021 | |
| 6022 | final long identity = Binder.clearCallingIdentity(); |
| 6023 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6024 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6025 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6026 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6027 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6028 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6029 | } finally { |
| 6030 | Binder.restoreCallingIdentity(identity); |
| 6031 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6032 | } |
| 6033 | |
| 6034 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6035 | * Get the allowed network types for certain reason. |
| 6036 | * |
| 6037 | * @param subId the id of the subscription. |
| 6038 | * @param reason the reason the allowed network type change is taking place |
| 6039 | * @return the allowed network types. |
| 6040 | */ |
| 6041 | @Override |
| 6042 | public long getAllowedNetworkTypesForReason(int subId, |
| 6043 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
| 6044 | TelephonyPermissions |
| 6045 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6046 | mApp, subId, "getAllowedNetworkTypesForReason"); |
| 6047 | final long identity = Binder.clearCallingIdentity(); |
| 6048 | try { |
| 6049 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6050 | } finally { |
| 6051 | Binder.restoreCallingIdentity(identity); |
| 6052 | } |
| 6053 | } |
| 6054 | |
| 6055 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6056 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6057 | * @param subId subscription id of the sim card |
| 6058 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6059 | * This can be passed following states |
| 6060 | * <ol> |
| 6061 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6062 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6063 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6064 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6065 | * </ol> |
| 6066 | * @return operation result. |
| 6067 | */ |
| 6068 | @Override |
| 6069 | public int setNrDualConnectivityState(int subId, |
| 6070 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6071 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6072 | mApp, subId, "enableNRDualConnectivity"); |
| 6073 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6074 | final long identity = Binder.clearCallingIdentity(); |
| 6075 | try { |
| 6076 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6077 | nrDualConnectivityState, subId, |
| 6078 | workSource); |
| 6079 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6080 | return result; |
| 6081 | } finally { |
| 6082 | Binder.restoreCallingIdentity(identity); |
| 6083 | } |
| 6084 | } |
| 6085 | |
| 6086 | /** |
| 6087 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6088 | * @return true if dual connectivity is enabled else false |
| 6089 | */ |
| 6090 | @Override |
| 6091 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6092 | TelephonyPermissions |
| 6093 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6094 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6095 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6096 | final long identity = Binder.clearCallingIdentity(); |
| 6097 | try { |
| 6098 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6099 | null, subId, workSource); |
| 6100 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6101 | return isEnabled; |
| 6102 | } finally { |
| 6103 | Binder.restoreCallingIdentity(identity); |
| 6104 | } |
| 6105 | } |
| 6106 | |
| 6107 | /** |
Sooraj Sasindran | 4deb887 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 6108 | * get carrier bandwidth per primary and secondary carrier |
| 6109 | * @param subId subscription id of the sim card |
| 6110 | * @return CarrierBandwidth with bandwidth of both primary and secondary carrier.. |
| 6111 | */ |
| 6112 | @Override |
| 6113 | public CarrierBandwidth getCarrierBandwidth(int subId) { |
| 6114 | TelephonyPermissions |
| 6115 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6116 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6117 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6118 | final long identity = Binder.clearCallingIdentity(); |
| 6119 | try { |
| 6120 | CarrierBandwidth carrierBandwidth = |
| 6121 | getPhoneFromSubId(subId).getCarrierBandwidth(); |
| 6122 | if (DBG) log("getCarrierBandwidth: " + carrierBandwidth); |
| 6123 | return carrierBandwidth; |
| 6124 | } finally { |
| 6125 | Binder.restoreCallingIdentity(identity); |
| 6126 | } |
| 6127 | } |
| 6128 | |
| 6129 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6130 | * Set the allowed network types of the device and |
| 6131 | * provide the reason triggering the allowed network change. |
| 6132 | * |
| 6133 | * @param subId the id of the subscription. |
| 6134 | * @param reason the reason the allowed network type change is taking place |
| 6135 | * @param allowedNetworkTypes the allowed network types. |
| 6136 | * @return true on success; false on any failure. |
| 6137 | */ |
| 6138 | @Override |
| 6139 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6140 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6141 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6142 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6143 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6144 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
| 6145 | Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason); |
| 6146 | return false; |
| 6147 | } |
| 6148 | |
| 6149 | if (DBG) { |
| 6150 | log("setAllowedNetworkTypesForReason: " + reason |
| 6151 | + " value: " + allowedNetworkTypes); |
| 6152 | } |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6153 | final long identity = Binder.clearCallingIdentity(); |
| 6154 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6155 | Boolean success = (Boolean) sendRequest( |
| 6156 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6157 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6158 | |
| 6159 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6160 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6161 | } finally { |
| 6162 | Binder.restoreCallingIdentity(identity); |
| 6163 | } |
| 6164 | } |
| 6165 | |
| 6166 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6167 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6168 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6169 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6170 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6171 | * @hide |
| 6172 | */ |
| 6173 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6174 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6175 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6176 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6177 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6178 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6179 | if (phone != null) { |
| 6180 | return phone.hasMatchedTetherApnSetting(); |
| 6181 | } else { |
| 6182 | return false; |
| 6183 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6184 | } finally { |
| 6185 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6186 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6187 | } |
| 6188 | |
| 6189 | /** |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6190 | * Enable or disable always reporting signal strength changes from radio. |
| 6191 | * |
| 6192 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6193 | */ |
| 6194 | @Override |
| 6195 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6196 | enforceModifyPermission(); |
| 6197 | enforceSystemCaller(); |
| 6198 | |
| 6199 | final long identity = Binder.clearCallingIdentity(); |
| 6200 | final Phone phone = getPhone(subId); |
| 6201 | try { |
| 6202 | if (phone != null) { |
| 6203 | if (DBG) { |
| 6204 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6205 | + " isEnable=" + isEnable); |
| 6206 | } |
| 6207 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6208 | } else { |
| 6209 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6210 | + subId); |
| 6211 | } |
| 6212 | } finally { |
| 6213 | Binder.restoreCallingIdentity(identity); |
| 6214 | } |
| 6215 | } |
| 6216 | |
| 6217 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6218 | * Get the user enabled state of Mobile Data. |
| 6219 | * |
| 6220 | * TODO: remove and use isUserDataEnabled. |
| 6221 | * This can't be removed now because some vendor codes |
| 6222 | * calls through ITelephony directly while they should |
| 6223 | * use TelephonyManager. |
| 6224 | * |
| 6225 | * @return true on enabled |
| 6226 | */ |
| 6227 | @Override |
| 6228 | public boolean getDataEnabled(int subId) { |
| 6229 | return isUserDataEnabled(subId); |
| 6230 | } |
| 6231 | |
| 6232 | /** |
| 6233 | * Get whether mobile data is enabled per user setting. |
| 6234 | * |
| 6235 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6236 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6237 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6238 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6239 | * |
| 6240 | * @return {@code true} if data is enabled else {@code false} |
| 6241 | */ |
| 6242 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6243 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6244 | try { |
| 6245 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6246 | null); |
| 6247 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6248 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6249 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6250 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6251 | |
| 6252 | final long identity = Binder.clearCallingIdentity(); |
| 6253 | try { |
| 6254 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6255 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6256 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6257 | if (phone != null) { |
| 6258 | boolean retVal = phone.isUserDataEnabled(); |
| 6259 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6260 | return retVal; |
| 6261 | } else { |
| 6262 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6263 | return false; |
| 6264 | } |
| 6265 | } finally { |
| 6266 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6267 | } |
| 6268 | } |
| 6269 | |
| 6270 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6271 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6272 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6273 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6274 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6275 | * @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] | 6276 | */ |
| 6277 | @Override |
| 6278 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6279 | try { |
| 6280 | try { |
| 6281 | mApp.enforceCallingOrSelfPermission( |
| 6282 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6283 | null); |
| 6284 | } catch (Exception e) { |
| 6285 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6286 | "isDataEnabled"); |
| 6287 | } |
| 6288 | } catch (Exception e) { |
| 6289 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6290 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6291 | |
| 6292 | final long identity = Binder.clearCallingIdentity(); |
| 6293 | try { |
| 6294 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6295 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6296 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6297 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6298 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6299 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6300 | return retVal; |
| 6301 | } else { |
| 6302 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6303 | return false; |
| 6304 | } |
| 6305 | } finally { |
| 6306 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6307 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6308 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6309 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6310 | /** |
| 6311 | * Check if data is enabled for a specific reason |
| 6312 | * @param subId Subscription index |
| 6313 | * @param reason the reason the data enable change is taking place |
| 6314 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6315 | */ |
| 6316 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6317 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6318 | @TelephonyManager.DataEnabledReason int reason) { |
| 6319 | try { |
| 6320 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6321 | null); |
| 6322 | } catch (Exception e) { |
| 6323 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6324 | "isDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6325 | } |
| 6326 | |
| 6327 | |
| 6328 | final long identity = Binder.clearCallingIdentity(); |
| 6329 | try { |
| 6330 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6331 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6332 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6333 | + " reason=" + reason); |
| 6334 | } |
| 6335 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6336 | if (phone != null) { |
| 6337 | boolean retVal; |
| 6338 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6339 | retVal = phone.isUserDataEnabled(); |
| 6340 | } else { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6341 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6342 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6343 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6344 | return retVal; |
| 6345 | } else { |
| 6346 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6347 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6348 | + subId + " retVal=false"); |
| 6349 | } |
| 6350 | return false; |
| 6351 | } |
| 6352 | } finally { |
| 6353 | Binder.restoreCallingIdentity(identity); |
| 6354 | } |
| 6355 | } |
| 6356 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6357 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6358 | Phone phone) { |
Hall Liu | 54a2a0c | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6359 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 6360 | // Skip the check if it's one of these special uids |
| 6361 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6362 | } |
| 6363 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6364 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6365 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6366 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6367 | || subController == null) return privilegeFromSim; |
| 6368 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6369 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6370 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6371 | |
| 6372 | final long identity = Binder.clearCallingIdentity(); |
| 6373 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6374 | int subId = phone.getSubId(); |
| 6375 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6376 | // A test override is in place for the privileges for this subId, so don't try to |
| 6377 | // read the subscription privileges. |
| 6378 | return privilegeFromSim; |
| 6379 | } |
| 6380 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6381 | SubscriptionManager subManager = (SubscriptionManager) |
| 6382 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6383 | for (String pkg : packages) { |
| 6384 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6385 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6386 | } |
| 6387 | } |
| 6388 | return privilegeFromSim; |
| 6389 | } finally { |
| 6390 | Binder.restoreCallingIdentity(identity); |
| 6391 | } |
| 6392 | } |
| 6393 | |
| 6394 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6395 | String pkgName) { |
| 6396 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6397 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6398 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6399 | || subController == null) return privilegeFromSim; |
| 6400 | |
| 6401 | final long identity = Binder.clearCallingIdentity(); |
| 6402 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6403 | int subId = phone.getSubId(); |
| 6404 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6405 | // A test override is in place for the privileges for this subId, so don't try to |
| 6406 | // read the subscription privileges. |
| 6407 | return privilegeFromSim; |
| 6408 | } |
| 6409 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6410 | SubscriptionManager subManager = (SubscriptionManager) |
| 6411 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6412 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6413 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6414 | } finally { |
| 6415 | Binder.restoreCallingIdentity(identity); |
| 6416 | } |
| 6417 | } |
| 6418 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6419 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6420 | public int getCarrierPrivilegeStatus(int subId) { |
| 6421 | final Phone phone = getPhone(subId); |
| 6422 | if (phone == null) { |
| 6423 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6424 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6425 | } |
| 6426 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6427 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6428 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6429 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6430 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6431 | |
| 6432 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6433 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6434 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6435 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6436 | |
| 6437 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6438 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6439 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6440 | final Phone phone = getPhone(subId); |
| 6441 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6442 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6443 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6444 | } |
| 6445 | UiccProfile profile = |
| 6446 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6447 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6448 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6449 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6450 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6451 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6452 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6453 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6454 | } |
| 6455 | |
| 6456 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6457 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6458 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6459 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6460 | } |
| 6461 | |
| 6462 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6463 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6464 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6465 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6466 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6467 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6468 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6469 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6470 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6471 | } |
| 6472 | |
| 6473 | @Override |
| 6474 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6475 | if (TextUtils.isEmpty(pkgName)) |
| 6476 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6477 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6478 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6479 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6480 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6481 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6482 | continue; |
| 6483 | } |
| 6484 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6485 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6486 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6487 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6488 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6489 | break; |
| 6490 | } |
| 6491 | } |
| 6492 | |
| 6493 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6494 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6495 | |
| 6496 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6497 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6498 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6499 | loge("phoneId " + phoneId + " is not valid."); |
| 6500 | return null; |
| 6501 | } |
| 6502 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6503 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6504 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6505 | return null ; |
| 6506 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6507 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6508 | } |
| 6509 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6510 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6511 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6512 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6513 | List<String> privilegedPackages = new ArrayList<>(); |
| 6514 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6515 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6516 | // has UICC in that slot. |
| 6517 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6518 | if (card.hasCarrierPrivilegeRules()) { |
| 6519 | if (packages == null) { |
| 6520 | // Only check packages in user 0 for now |
| 6521 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6522 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6523 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6524 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6525 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6526 | } |
| 6527 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6528 | PackageInfo pkgInfo = packages.get(p); |
| 6529 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6530 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6531 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6532 | privilegedPackages.add(pkgInfo.packageName); |
| 6533 | } |
| 6534 | } |
| 6535 | } |
| 6536 | } |
| 6537 | return privilegedPackages; |
| 6538 | } |
| 6539 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6540 | @Override |
| 6541 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6542 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6543 | |
| 6544 | final long identity = Binder.clearCallingIdentity(); |
| 6545 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6546 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6547 | try { |
| 6548 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6549 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6550 | } |
| 6551 | } finally { |
| 6552 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6553 | } |
| 6554 | return privilegedPackages; |
| 6555 | } |
| 6556 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6557 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6558 | final Phone phone = getPhone(subId); |
| 6559 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6560 | if (card == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6561 | return null; |
| 6562 | } |
| 6563 | String iccId = card.getIccId(); |
| 6564 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6565 | return null; |
| 6566 | } |
| 6567 | return iccId; |
| 6568 | } |
| 6569 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6570 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6571 | public void setCallComposerStatus(int subId, int status) { |
| 6572 | enforceModifyPermission(); |
| 6573 | |
| 6574 | final long identity = Binder.clearCallingIdentity(); |
| 6575 | try { |
| 6576 | Phone phone = getPhone(subId); |
| 6577 | if (phone != null) { |
| 6578 | Phone defaultPhone = phone.getImsPhone(); |
| 6579 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6580 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6581 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6582 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6583 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6584 | } |
| 6585 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6586 | } catch (ImsException e) { |
| 6587 | throw new ServiceSpecificException(e.getCode()); |
| 6588 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6589 | Binder.restoreCallingIdentity(identity); |
| 6590 | } |
| 6591 | } |
| 6592 | |
| 6593 | @Override |
| 6594 | public int getCallComposerStatus(int subId) { |
| 6595 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6596 | |
| 6597 | final long identity = Binder.clearCallingIdentity(); |
| 6598 | try { |
| 6599 | Phone phone = getPhone(subId); |
| 6600 | if (phone != null) { |
| 6601 | Phone defaultPhone = phone.getImsPhone(); |
| 6602 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6603 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6604 | return imsPhone.getCallComposerStatus(); |
| 6605 | } |
| 6606 | } |
| 6607 | } finally { |
| 6608 | Binder.restoreCallingIdentity(identity); |
| 6609 | } |
| 6610 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6611 | } |
| 6612 | |
| 6613 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6614 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6615 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6616 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6617 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6618 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6619 | final long identity = Binder.clearCallingIdentity(); |
| 6620 | try { |
| 6621 | final String iccId = getIccId(subId); |
| 6622 | final Phone phone = getPhone(subId); |
| 6623 | if (phone == null) { |
| 6624 | return false; |
| 6625 | } |
| 6626 | final String subscriberId = phone.getSubscriberId(); |
| 6627 | |
| 6628 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6629 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6630 | + subscriberId + " to " + number); |
| 6631 | } |
| 6632 | |
| 6633 | if (TextUtils.isEmpty(iccId)) { |
| 6634 | return false; |
| 6635 | } |
| 6636 | |
| 6637 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6638 | |
| 6639 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6640 | if (alphaTag == null) { |
| 6641 | editor.remove(alphaTagPrefKey); |
| 6642 | } else { |
| 6643 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6644 | } |
| 6645 | |
| 6646 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6647 | // track all merged IMSIs based on line number |
| 6648 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6649 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6650 | if (number == null) { |
| 6651 | editor.remove(numberPrefKey); |
| 6652 | editor.remove(subscriberPrefKey); |
| 6653 | } else { |
| 6654 | editor.putString(numberPrefKey, number); |
| 6655 | editor.putString(subscriberPrefKey, subscriberId); |
| 6656 | } |
| 6657 | |
| 6658 | editor.commit(); |
| 6659 | return true; |
| 6660 | } finally { |
| 6661 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6662 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6663 | } |
| 6664 | |
| 6665 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6666 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6667 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6668 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6669 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6670 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6671 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6672 | return null; |
| 6673 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6674 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6675 | final long identity = Binder.clearCallingIdentity(); |
| 6676 | try { |
| 6677 | String iccId = getIccId(subId); |
| 6678 | if (iccId != null) { |
| 6679 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6680 | if (DBG_MERGE) { |
| 6681 | log("getLine1NumberForDisplay returning " |
| 6682 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6683 | } |
| 6684 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6685 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6686 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6687 | return null; |
| 6688 | } finally { |
| 6689 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6690 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6691 | } |
| 6692 | |
| 6693 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6694 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6695 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6696 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6697 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6698 | return null; |
| 6699 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6700 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6701 | final long identity = Binder.clearCallingIdentity(); |
| 6702 | try { |
| 6703 | String iccId = getIccId(subId); |
| 6704 | if (iccId != null) { |
| 6705 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6706 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6707 | } |
| 6708 | return null; |
| 6709 | } finally { |
| 6710 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6711 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6712 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6713 | |
| 6714 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6715 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6716 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6717 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6718 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6719 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6720 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6721 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6722 | return null; |
| 6723 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6724 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6725 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6726 | // the process, where TelephonyManager was instantiated. |
| 6727 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6728 | final long identity = Binder.clearCallingIdentity(); |
| 6729 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6730 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6731 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6732 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6733 | |
| 6734 | // Figure out what subscribers are currently active |
| 6735 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6736 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6737 | // Only consider subs which match the current subId |
| 6738 | // This logic can be simplified. See b/131189269 for progress. |
| 6739 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6740 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6741 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6742 | |
| 6743 | // First pass, find a number override for an active subscriber |
| 6744 | String mergeNumber = null; |
| 6745 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6746 | for (String key : prefs.keySet()) { |
| 6747 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6748 | final String subscriberId = (String) prefs.get(key); |
| 6749 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6750 | final String iccId = key.substring( |
| 6751 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6752 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6753 | mergeNumber = (String) prefs.get(numberKey); |
| 6754 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6755 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6756 | + " for active subscriber " + subscriberId); |
| 6757 | } |
| 6758 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6759 | break; |
| 6760 | } |
| 6761 | } |
| 6762 | } |
| 6763 | } |
| 6764 | |
| 6765 | // Shortcut when no active merged subscribers |
| 6766 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6767 | return null; |
| 6768 | } |
| 6769 | |
| 6770 | // Second pass, find all subscribers under that line override |
| 6771 | final ArraySet<String> result = new ArraySet<>(); |
| 6772 | for (String key : prefs.keySet()) { |
| 6773 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6774 | final String number = (String) prefs.get(key); |
| 6775 | if (mergeNumber.equals(number)) { |
| 6776 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6777 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6778 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6779 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6780 | result.add(subscriberId); |
| 6781 | } |
| 6782 | } |
| 6783 | } |
| 6784 | } |
| 6785 | |
| 6786 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6787 | Arrays.sort(resultArray); |
| 6788 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6789 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6790 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6791 | } |
| 6792 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6793 | } finally { |
| 6794 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6795 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6796 | } |
| 6797 | |
| 6798 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6799 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6800 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6801 | |
| 6802 | final long identity = Binder.clearCallingIdentity(); |
| 6803 | try { |
| 6804 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6805 | TelephonyManager.class); |
| 6806 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6807 | if (subscriberId == null) { |
| 6808 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6809 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6810 | + subId); |
| 6811 | } |
| 6812 | return null; |
| 6813 | } |
| 6814 | |
| 6815 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6816 | .getSubscriptionInfo(subId); |
| 6817 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6818 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6819 | if (groupUuid == null) { |
| 6820 | return new String[]{subscriberId}; |
| 6821 | } |
| 6822 | |
| 6823 | // Get all subscriberIds from the group. |
| 6824 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6825 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6826 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6827 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6828 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6829 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6830 | if (subscriberId != null) { |
| 6831 | mergedSubscriberIds.add(subscriberId); |
| 6832 | } |
| 6833 | } |
| 6834 | |
| 6835 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6836 | } finally { |
| 6837 | Binder.restoreCallingIdentity(identity); |
| 6838 | |
| 6839 | } |
| 6840 | } |
| 6841 | |
| 6842 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6843 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6844 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6845 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6846 | |
| 6847 | final long identity = Binder.clearCallingIdentity(); |
| 6848 | try { |
| 6849 | final Phone phone = getPhone(subId); |
| 6850 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6851 | } finally { |
| 6852 | Binder.restoreCallingIdentity(identity); |
| 6853 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6854 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6855 | |
| 6856 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6857 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6858 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6859 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6860 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6861 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6862 | |
| 6863 | final long identity = Binder.clearCallingIdentity(); |
| 6864 | try { |
| 6865 | final Phone phone = getPhone(subId); |
| 6866 | if (phone == null) { |
| 6867 | return false; |
| 6868 | } |
| 6869 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6870 | cdmaNonRoamingList); |
| 6871 | } finally { |
| 6872 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6873 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6874 | } |
| 6875 | |
| 6876 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6877 | @Deprecated |
| 6878 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6879 | enforceModifyPermission(); |
| 6880 | |
| 6881 | int returnValue = 0; |
| 6882 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6883 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6884 | if(result.exception == null) { |
| 6885 | if (result.result != null) { |
| 6886 | byte[] responseData = (byte[])(result.result); |
| 6887 | if(responseData.length > oemResp.length) { |
| 6888 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6889 | responseData.length + "bytes. Buffer Size is " + |
| 6890 | oemResp.length + "bytes."); |
| 6891 | } |
| 6892 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6893 | returnValue = responseData.length; |
| 6894 | } |
| 6895 | } else { |
| 6896 | CommandException ex = (CommandException) result.exception; |
| 6897 | returnValue = ex.getCommandError().ordinal(); |
| 6898 | if(returnValue > 0) returnValue *= -1; |
| 6899 | } |
| 6900 | } catch (RuntimeException e) { |
| 6901 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6902 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6903 | if(returnValue > 0) returnValue *= -1; |
| 6904 | } |
| 6905 | |
| 6906 | return returnValue; |
| 6907 | } |
| 6908 | |
| 6909 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6910 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6911 | try { |
| 6912 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6913 | } catch (RuntimeException e) { |
| 6914 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6915 | } |
| 6916 | } |
| 6917 | |
| 6918 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6919 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6920 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 6921 | try { |
| 6922 | TelephonyPermissions |
| 6923 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6924 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6925 | } catch (SecurityException e) { |
| 6926 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 6927 | throw e; |
| 6928 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6929 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6930 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6931 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6932 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6933 | final long identity = Binder.clearCallingIdentity(); |
| 6934 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6935 | TelephonyPermissions |
| 6936 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6937 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6938 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6939 | } finally { |
| 6940 | Binder.restoreCallingIdentity(identity); |
| 6941 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6942 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6943 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6944 | |
| 6945 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 6946 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 6947 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 6948 | try { |
| 6949 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 6950 | Binder.getCallingUid())) { |
| 6951 | throw new SecurityException("Package uid and package name do not match: " |
| 6952 | + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage); |
| 6953 | } |
| 6954 | } catch (PackageManager.NameNotFoundException e) { |
| 6955 | throw new SecurityException("Package name invalid:" + callingPackage); |
| 6956 | } |
| 6957 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 6958 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 6959 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 6960 | throw new SecurityException("App must be the dialer role holder to" |
| 6961 | + " upload a call composer pic"); |
| 6962 | } |
| 6963 | |
| 6964 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6965 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 6966 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 6967 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 6968 | boolean readUntilEnd = false; |
| 6969 | int totalBytesRead = 0; |
| 6970 | byte[] buffer = new byte[16 * 1024]; |
| 6971 | while (true) { |
| 6972 | int numRead; |
| 6973 | try { |
| 6974 | numRead = input.read(buffer); |
| 6975 | } catch (IOException e) { |
| 6976 | try { |
| 6977 | fd.checkError(); |
| 6978 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 6979 | null); |
| 6980 | } catch (IOException e1) { |
| 6981 | // This means that the other side closed explicitly with an error. If this |
| 6982 | // happens, log and ignore. |
| 6983 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 6984 | } |
| 6985 | break; |
| 6986 | } |
| 6987 | if (numRead == -1) { |
| 6988 | readUntilEnd = true; |
| 6989 | break; |
| 6990 | } |
| 6991 | totalBytesRead += numRead; |
| 6992 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 6993 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 6994 | try { |
| 6995 | input.close(); |
| 6996 | } catch (IOException e) { |
| 6997 | // ignore |
| 6998 | } |
| 6999 | break; |
| 7000 | } |
| 7001 | output.write(buffer, 0, numRead); |
| 7002 | } |
| 7003 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7004 | // close is above, where the picture size is too big. |
| 7005 | |
| 7006 | try { |
| 7007 | fd.checkError(); |
| 7008 | } catch (IOException e) { |
| 7009 | loge("Remote end for call composer closed with an error: " + e); |
| 7010 | return; |
| 7011 | } |
| 7012 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7013 | if (!readUntilEnd) { |
| 7014 | loge("Did not finish reading entire image; aborting"); |
| 7015 | return; |
| 7016 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7017 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7018 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7019 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7020 | new CallComposerPictureTransfer.Factory() {}, |
| 7021 | imageData, |
| 7022 | (result) -> { |
| 7023 | if (result.first != null) { |
| 7024 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7025 | Bundle outputResult = new Bundle(); |
| 7026 | outputResult.putParcelable( |
| 7027 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7028 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7029 | outputResult); |
| 7030 | } else { |
| 7031 | callback.send(result.second, null); |
| 7032 | } |
| 7033 | } |
| 7034 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7035 | }); |
| 7036 | } |
| 7037 | |
| 7038 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7039 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7040 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7041 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7042 | |
| 7043 | final long identity = Binder.clearCallingIdentity(); |
| 7044 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7045 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7046 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7047 | } finally { |
| 7048 | Binder.restoreCallingIdentity(identity); |
| 7049 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7050 | } |
| 7051 | |
| 7052 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7053 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7054 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7055 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7056 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7057 | return false; |
| 7058 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7059 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7060 | final long identity = Binder.clearCallingIdentity(); |
| 7061 | try { |
| 7062 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7063 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7064 | // In the long run, we may instead need to check if there exists a connection service |
| 7065 | // which can support video calling. |
| 7066 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7067 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7068 | return imsManager.isVtEnabledByPlatform() |
| 7069 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7070 | && imsManager.isVtEnabledByUser(); |
| 7071 | } finally { |
| 7072 | Binder.restoreCallingIdentity(identity); |
| 7073 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7074 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7075 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7076 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7077 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7078 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7079 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7080 | mApp, subId, callingPackage, callingFeatureId, |
| 7081 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7082 | return false; |
| 7083 | } |
| 7084 | |
| 7085 | final long identity = Binder.clearCallingIdentity(); |
| 7086 | try { |
| 7087 | CarrierConfigManager configManager = |
| 7088 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7089 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7090 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7091 | } finally { |
| 7092 | Binder.restoreCallingIdentity(identity); |
| 7093 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7094 | } |
| 7095 | |
| 7096 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7097 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7098 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7099 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7100 | return false; |
| 7101 | } |
| 7102 | |
| 7103 | final long identity = Binder.clearCallingIdentity(); |
| 7104 | try { |
| 7105 | CarrierConfigManager configManager = |
| 7106 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7107 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7108 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7109 | } finally { |
| 7110 | Binder.restoreCallingIdentity(identity); |
| 7111 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7112 | } |
| 7113 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7114 | @Override |
| 7115 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7116 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7117 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7118 | } |
| 7119 | |
| 7120 | @Override |
| 7121 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7122 | final long identity = Binder.clearCallingIdentity(); |
| 7123 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7124 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7125 | } finally { |
| 7126 | Binder.restoreCallingIdentity(identity); |
| 7127 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7128 | } |
| 7129 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7130 | /** |
| 7131 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7132 | * support for the feature and device firmware support. |
| 7133 | * |
| 7134 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7135 | */ |
| 7136 | @Override |
| 7137 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7138 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7139 | final Phone phone = getPhone(subscriptionId); |
| 7140 | if (phone == null) { |
| 7141 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7142 | return false; |
| 7143 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7144 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7145 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7146 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7147 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7148 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7149 | return isCarrierSupported && isDeviceSupported; |
| 7150 | } finally { |
| 7151 | Binder.restoreCallingIdentity(identity); |
| 7152 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7153 | } |
| 7154 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7155 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7156 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7157 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7158 | * 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] | 7159 | */ |
| 7160 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7161 | final long identity = Binder.clearCallingIdentity(); |
| 7162 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7163 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7164 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7165 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7166 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7167 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7168 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7169 | } finally { |
| 7170 | Binder.restoreCallingIdentity(identity); |
| 7171 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7172 | } |
| 7173 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7174 | @Deprecated |
| 7175 | @Override |
| 7176 | public String getDeviceId(String callingPackage) { |
| 7177 | return getDeviceIdWithFeature(callingPackage, null); |
| 7178 | } |
| 7179 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7180 | /** |
| 7181 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7182 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7183 | * |
| 7184 | * <p>Requires Permission: |
| 7185 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7186 | */ |
| 7187 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7188 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7189 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7190 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7191 | return null; |
| 7192 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7193 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7194 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7195 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7196 | return null; |
| 7197 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7198 | |
| 7199 | final long identity = Binder.clearCallingIdentity(); |
| 7200 | try { |
| 7201 | return phone.getDeviceId(); |
| 7202 | } finally { |
| 7203 | Binder.restoreCallingIdentity(identity); |
| 7204 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7205 | } |
| 7206 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7207 | /** |
| 7208 | * {@hide} |
| 7209 | * Returns the IMS Registration Status on a particular subid |
| 7210 | * |
| 7211 | * @param subId |
| 7212 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7213 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7214 | Phone phone = getPhone(subId); |
| 7215 | if (phone != null) { |
| 7216 | return phone.isImsRegistered(); |
| 7217 | } else { |
| 7218 | return false; |
| 7219 | } |
| 7220 | } |
| 7221 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7222 | @Override |
| 7223 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7224 | final long identity = Binder.clearCallingIdentity(); |
| 7225 | try { |
| 7226 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 7227 | } finally { |
| 7228 | Binder.restoreCallingIdentity(identity); |
| 7229 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7230 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7231 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7232 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7233 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7234 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7235 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7236 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7237 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7238 | } |
| 7239 | final long identity = Binder.clearCallingIdentity(); |
| 7240 | try { |
| 7241 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7242 | } finally { |
| 7243 | Binder.restoreCallingIdentity(identity); |
| 7244 | } |
| 7245 | } |
| 7246 | |
| 7247 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7248 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 7249 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 7250 | + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7251 | final long identity = Binder.clearCallingIdentity(); |
| 7252 | try { |
| 7253 | Phone phone = getPhone(subscriptionId); |
| 7254 | if (phone == null) { |
| 7255 | return null; |
| 7256 | } |
| 7257 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7258 | } finally { |
| 7259 | Binder.restoreCallingIdentity(identity); |
| 7260 | } |
| 7261 | } |
| 7262 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7263 | /** |
| 7264 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7265 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7266 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7267 | final long identity = Binder.clearCallingIdentity(); |
| 7268 | try { |
| 7269 | Phone phone = getPhone(subId); |
| 7270 | if (phone != null) { |
| 7271 | return phone.isWifiCallingEnabled(); |
| 7272 | } else { |
| 7273 | return false; |
| 7274 | } |
| 7275 | } finally { |
| 7276 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7277 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7278 | } |
| 7279 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7280 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7281 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7282 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7283 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7284 | final long identity = Binder.clearCallingIdentity(); |
| 7285 | try { |
| 7286 | Phone phone = getPhone(subId); |
| 7287 | if (phone != null) { |
| 7288 | return phone.isVideoEnabled(); |
| 7289 | } else { |
| 7290 | return false; |
| 7291 | } |
| 7292 | } finally { |
| 7293 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7294 | } |
| 7295 | } |
| 7296 | |
| 7297 | /** |
| 7298 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7299 | * defined in {@link ImsRegistrationImplBase}. |
| 7300 | */ |
| 7301 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7302 | final long identity = Binder.clearCallingIdentity(); |
| 7303 | try { |
| 7304 | Phone phone = getPhone(subId); |
| 7305 | if (phone != null) { |
| 7306 | return phone.getImsRegistrationTech(); |
| 7307 | } else { |
| 7308 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7309 | } |
| 7310 | } finally { |
| 7311 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7312 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7313 | } |
| 7314 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7315 | @Override |
| 7316 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7317 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7318 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7319 | return; |
| 7320 | } |
| 7321 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7322 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7323 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7324 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7325 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7326 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7327 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7328 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7329 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7330 | setAllowedNetworkTypesForReason(subId, |
| 7331 | TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7332 | RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId))); |
| 7333 | setAllowedNetworkTypesForReason(subId, |
| 7334 | TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER, |
| 7335 | RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId))); |
| 7336 | setAllowedNetworkTypesForReason(subId, |
| 7337 | TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER, |
| 7338 | RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId))); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7339 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 7340 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7341 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7342 | // There has been issues when Sms raw table somehow stores orphan |
| 7343 | // fragments. They lead to garbled message when new fragments come |
| 7344 | // in and combined with those stale ones. In case this happens again, |
| 7345 | // user can reset all network settings which will clean up this table. |
| 7346 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7347 | // Clean up IMS settings as well here. |
| 7348 | int slotId = getSlotIndex(subId); |
| 7349 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7350 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7351 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7352 | |
| 7353 | // Erase modem config if erase modem on network setting is enabled. |
| 7354 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7355 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7356 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 7357 | sendEraseModemConfig(getDefaultPhone()); |
| 7358 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7359 | } finally { |
| 7360 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7361 | } |
| 7362 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7363 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7364 | private void cleanUpSmsRawTable(Context context) { |
| 7365 | ContentResolver resolver = context.getContentResolver(); |
| 7366 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7367 | resolver.delete(uri, null, null); |
| 7368 | } |
| 7369 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7370 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7371 | public String getSimLocaleForSubscriber(int subId) { |
| 7372 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7373 | final Phone phone = getPhone(subId); |
| 7374 | if (phone == null) { |
| 7375 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7376 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7377 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7378 | final long identity = Binder.clearCallingIdentity(); |
| 7379 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7380 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7381 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7382 | if (info == null) { |
| 7383 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7384 | return null; |
| 7385 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7386 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7387 | // preferences (EF-PL and EF-LI)... |
| 7388 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7389 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7390 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7391 | if (localeFromDefaultSim != null) { |
| 7392 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7393 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7394 | + localeFromDefaultSim); |
| 7395 | return localeFromDefaultSim.toLanguageTag(); |
| 7396 | } else { |
| 7397 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7398 | } |
| 7399 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7400 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7401 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7402 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7403 | // the SIM and carrier preferences does not include a country we add the country |
| 7404 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7405 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7406 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7407 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7408 | return mccLocale.toLanguageTag(); |
| 7409 | } |
| 7410 | |
| 7411 | if (DBG) log("No locale found - returning null"); |
| 7412 | return null; |
| 7413 | } finally { |
| 7414 | Binder.restoreCallingIdentity(identity); |
| 7415 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7416 | } |
| 7417 | |
| 7418 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7419 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7420 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7421 | } |
| 7422 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7423 | /** |
| 7424 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7425 | */ |
| 7426 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7427 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7428 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7429 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7430 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7431 | private final ModemActivityInfo mLastModemActivityInfo = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7432 | new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7433 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7434 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7435 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7436 | * representing the state of the modem. |
| 7437 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7438 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7439 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7440 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7441 | */ |
| 7442 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7443 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7444 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7445 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7446 | |
| 7447 | final long identity = Binder.clearCallingIdentity(); |
| 7448 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7449 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7450 | } finally { |
| 7451 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7452 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7453 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7454 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7455 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7456 | // less than total activity duration. |
| 7457 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7458 | if (info == null) { |
| 7459 | return false; |
| 7460 | } |
| 7461 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7462 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7463 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7464 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7465 | return (info.isValid() |
| 7466 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7467 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7468 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7469 | && (totalTxTimeMs <= activityDurationMs)); |
| 7470 | } |
| 7471 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7472 | /** |
| 7473 | * {@hide} |
| 7474 | * Returns the service state information on specified subscription. |
| 7475 | */ |
| 7476 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7477 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7478 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7479 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7480 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7481 | return null; |
| 7482 | } |
| 7483 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7484 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7485 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7486 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7487 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7488 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7489 | .setCallingPid(Binder.getCallingPid()) |
| 7490 | .setCallingUid(Binder.getCallingUid()) |
| 7491 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7492 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7493 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7494 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7495 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7496 | .build()); |
| 7497 | |
| 7498 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7499 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7500 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7501 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7502 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7503 | .setCallingPid(Binder.getCallingPid()) |
| 7504 | .setCallingUid(Binder.getCallingUid()) |
| 7505 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7506 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7507 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7508 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7509 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7510 | .build()); |
| 7511 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7512 | boolean hasFinePermission = |
| 7513 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7514 | boolean hasCoarsePermission = |
| 7515 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7516 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7517 | final Phone phone = getPhone(subId); |
| 7518 | if (phone == null) { |
| 7519 | return null; |
| 7520 | } |
| 7521 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 7522 | final long identity = Binder.clearCallingIdentity(); |
| 7523 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7524 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7525 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7526 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7527 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7528 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7529 | Rlog.d(LOG_TAG, |
| 7530 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7531 | return null; |
| 7532 | } |
| 7533 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7534 | ServiceState ss = phone.getServiceState(); |
| 7535 | |
| 7536 | // Scrub out the location info in ServiceState depending on what level of access |
| 7537 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7538 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7539 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7540 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7541 | } finally { |
| 7542 | Binder.restoreCallingIdentity(identity); |
| 7543 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7544 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7545 | |
| 7546 | /** |
| 7547 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7548 | * |
| 7549 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7550 | * voicemail ringtone. |
| 7551 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7552 | * PhoneAccount. |
| 7553 | */ |
| 7554 | @Override |
| 7555 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7556 | final long identity = Binder.clearCallingIdentity(); |
| 7557 | try { |
| 7558 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7559 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7560 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7561 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7562 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7563 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7564 | } finally { |
| 7565 | Binder.restoreCallingIdentity(identity); |
| 7566 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7567 | } |
| 7568 | |
| 7569 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7570 | * Sets the per-account voicemail ringtone. |
| 7571 | * |
| 7572 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7573 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7574 | * |
| 7575 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7576 | * voicemail ringtone. |
| 7577 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7578 | * PhoneAccount. |
| 7579 | */ |
| 7580 | @Override |
| 7581 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7582 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7583 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7584 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7585 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7586 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7587 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7588 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7589 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7590 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7591 | |
| 7592 | final long identity = Binder.clearCallingIdentity(); |
| 7593 | try { |
| 7594 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7595 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7596 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7597 | } |
| 7598 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7599 | } finally { |
| 7600 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7601 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7602 | } |
| 7603 | |
| 7604 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7605 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7606 | * |
| 7607 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7608 | * voicemail vibration setting. |
| 7609 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7610 | */ |
| 7611 | @Override |
| 7612 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7613 | final long identity = Binder.clearCallingIdentity(); |
| 7614 | try { |
| 7615 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7616 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7617 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7618 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7619 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7620 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7621 | } finally { |
| 7622 | Binder.restoreCallingIdentity(identity); |
| 7623 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7624 | } |
| 7625 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7626 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7627 | * Sets the per-account voicemail vibration. |
| 7628 | * |
| 7629 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7630 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7631 | * |
| 7632 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7633 | * voicemail vibration setting. |
| 7634 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7635 | * specific PhoneAccount. |
| 7636 | */ |
| 7637 | @Override |
| 7638 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7639 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7640 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7641 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7642 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7643 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7644 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7645 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7646 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7647 | } |
| 7648 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7649 | final long identity = Binder.clearCallingIdentity(); |
| 7650 | try { |
| 7651 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7652 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7653 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7654 | } |
| 7655 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7656 | } finally { |
| 7657 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7658 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7659 | } |
| 7660 | |
| 7661 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7662 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7663 | * |
| 7664 | * @throws SecurityException if the caller does not have the required permission |
| 7665 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7666 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7667 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7668 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7669 | } |
| 7670 | |
| 7671 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7672 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7673 | * permission. |
| 7674 | * |
| 7675 | * @throws SecurityException if the caller does not have the required permission |
| 7676 | */ |
| 7677 | private void enforceSendSmsPermission() { |
| 7678 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7679 | } |
| 7680 | |
| 7681 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7682 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7683 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7684 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7685 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7686 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7687 | final long identity = Binder.clearCallingIdentity(); |
| 7688 | try { |
| 7689 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7690 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7691 | if (componentName == null) { |
| 7692 | throw new SecurityException( |
| 7693 | "Caller not current active visual voicemail package[null]"); |
| 7694 | } |
| 7695 | String vvmPackage = componentName.getPackageName(); |
| 7696 | if (!callingPackage.equals(vvmPackage)) { |
| 7697 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7698 | + vvmPackage + "]"); |
| 7699 | } |
| 7700 | } finally { |
| 7701 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7702 | } |
| 7703 | } |
| 7704 | |
| 7705 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7706 | * Return the application ID for the app type. |
| 7707 | * |
| 7708 | * @param subId the subscription ID that this request applies to. |
| 7709 | * @param appType the uicc app type. |
| 7710 | * @return Application ID for specificied app type, or null if no uicc. |
| 7711 | */ |
| 7712 | @Override |
| 7713 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7714 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7715 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7716 | |
| 7717 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7718 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7719 | if (phone == null) { |
| 7720 | return null; |
| 7721 | } |
| 7722 | String aid = null; |
| 7723 | try { |
| 7724 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7725 | .getApplicationByType(appType).getAid(); |
| 7726 | } catch (Exception e) { |
| 7727 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7728 | } |
| 7729 | return aid; |
| 7730 | } finally { |
| 7731 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7732 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7733 | } |
| 7734 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7735 | /** |
| 7736 | * Return the Electronic Serial Number. |
| 7737 | * |
| 7738 | * @param subId the subscription ID that this request applies to. |
| 7739 | * @return ESN or null if error. |
| 7740 | */ |
| 7741 | @Override |
| 7742 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7743 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7744 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7745 | |
| 7746 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7747 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7748 | if (phone == null) { |
| 7749 | return null; |
| 7750 | } |
| 7751 | String esn = null; |
| 7752 | try { |
| 7753 | esn = phone.getEsn(); |
| 7754 | } catch (Exception e) { |
| 7755 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7756 | } |
| 7757 | return esn; |
| 7758 | } finally { |
| 7759 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7760 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7761 | } |
| 7762 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7763 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7764 | * Return the Preferred Roaming List Version. |
| 7765 | * |
| 7766 | * @param subId the subscription ID that this request applies to. |
| 7767 | * @return PRLVersion or null if error. |
| 7768 | */ |
| 7769 | @Override |
| 7770 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7771 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7772 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7773 | |
| 7774 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7775 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7776 | if (phone == null) { |
| 7777 | return null; |
| 7778 | } |
| 7779 | String cdmaPrlVersion = null; |
| 7780 | try { |
| 7781 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7782 | } catch (Exception e) { |
| 7783 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7784 | } |
| 7785 | return cdmaPrlVersion; |
| 7786 | } finally { |
| 7787 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7788 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7789 | } |
| 7790 | |
| 7791 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7792 | * Get snapshot of Telephony histograms |
| 7793 | * @return List of Telephony histograms |
| 7794 | * @hide |
| 7795 | */ |
| 7796 | @Override |
| 7797 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7798 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7799 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7800 | |
| 7801 | final long identity = Binder.clearCallingIdentity(); |
| 7802 | try { |
| 7803 | return RIL.getTelephonyRILTimingHistograms(); |
| 7804 | } finally { |
| 7805 | Binder.restoreCallingIdentity(identity); |
| 7806 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7807 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7808 | |
| 7809 | /** |
| 7810 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7811 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7812 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7813 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7814 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7815 | * @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] | 7816 | */ |
| 7817 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7818 | @TelephonyManager.SetCarrierRestrictionResult |
| 7819 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7820 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7821 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7822 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7823 | if (carrierRestrictionRules == null) { |
| 7824 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7825 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7826 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7827 | final long identity = Binder.clearCallingIdentity(); |
| 7828 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7829 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7830 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7831 | } finally { |
| 7832 | Binder.restoreCallingIdentity(identity); |
| 7833 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7834 | } |
| 7835 | |
| 7836 | /** |
| 7837 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7838 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7839 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7840 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7841 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7842 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7843 | */ |
| 7844 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7845 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7846 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7847 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7848 | |
| 7849 | final long identity = Binder.clearCallingIdentity(); |
| 7850 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7851 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7852 | if (response instanceof CarrierRestrictionRules) { |
| 7853 | return (CarrierRestrictionRules) response; |
| 7854 | } |
| 7855 | // Response is an Exception of some kind, |
| 7856 | // which is signalled to the user as a NULL retval |
| 7857 | return null; |
| 7858 | } catch (Exception e) { |
| 7859 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7860 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7861 | } finally { |
| 7862 | Binder.restoreCallingIdentity(identity); |
| 7863 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7864 | } |
| 7865 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7866 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7867 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7868 | * @param subId the subscription ID that this action applies to. |
| 7869 | * @param enabled control enable or disable radio. |
| 7870 | * {@hide} |
| 7871 | */ |
| 7872 | @Override |
| 7873 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7874 | enforceModifyPermission(); |
| 7875 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7876 | |
| 7877 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7878 | if (phone == null) { |
| 7879 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7880 | return; |
| 7881 | } |
| 7882 | try { |
| 7883 | phone.carrierActionSetRadioEnabled(enabled); |
| 7884 | } catch (Exception e) { |
| 7885 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7886 | } finally { |
| 7887 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7888 | } |
| 7889 | } |
| 7890 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7891 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7892 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7893 | * network status based on which carrier apps could apply actions accordingly, |
| 7894 | * enable/disable default url handler for example. |
| 7895 | * |
| 7896 | * @param subId the subscription ID that this action applies to. |
| 7897 | * @param report control start/stop reporting the default network status. |
| 7898 | * {@hide} |
| 7899 | */ |
| 7900 | @Override |
| 7901 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7902 | enforceModifyPermission(); |
| 7903 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7904 | |
| 7905 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7906 | if (phone == null) { |
| 7907 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7908 | return; |
| 7909 | } |
| 7910 | try { |
| 7911 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7912 | } catch (Exception e) { |
| 7913 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7914 | } finally { |
| 7915 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7916 | } |
| 7917 | } |
| 7918 | |
| 7919 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7920 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7921 | * @param subId the subscription ID that this action applies to. |
| 7922 | * {@hide} |
| 7923 | */ |
| 7924 | @Override |
| 7925 | public void carrierActionResetAll(int subId) { |
| 7926 | enforceModifyPermission(); |
| 7927 | final Phone phone = getPhone(subId); |
| 7928 | if (phone == null) { |
| 7929 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7930 | return; |
| 7931 | } |
| 7932 | try { |
| 7933 | phone.carrierActionResetAll(); |
| 7934 | } catch (Exception e) { |
| 7935 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7936 | } |
| 7937 | } |
| 7938 | |
| 7939 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7940 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7941 | * bug report is being generated. |
| 7942 | */ |
| 7943 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7944 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7945 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7946 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7947 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7948 | + Binder.getCallingPid() |
| 7949 | + ", uid=" + Binder.getCallingUid() |
| 7950 | + "without permission " |
| 7951 | + android.Manifest.permission.DUMP); |
| 7952 | return; |
| 7953 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7954 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7955 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7956 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7957 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7958 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7959 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7960 | @NonNull String[] args) { |
| 7961 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 7962 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 7963 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7964 | } |
| 7965 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7966 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7967 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 7968 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7969 | * @param reason the reason the data enable change is taking place |
| 7970 | * @param enabled True if enabling the data, otherwise disabling. |
| 7971 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7972 | */ |
| 7973 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7974 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7975 | boolean enabled) { |
| 7976 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 7977 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7978 | try { |
| 7979 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7980 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7981 | } catch (SecurityException se) { |
| 7982 | enforceModifyPermission(); |
| 7983 | } |
| 7984 | } else { |
| 7985 | enforceModifyPermission(); |
| 7986 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7987 | |
| 7988 | final long identity = Binder.clearCallingIdentity(); |
| 7989 | try { |
| 7990 | Phone phone = getPhone(subId); |
| 7991 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7992 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7993 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7994 | } else { |
| 7995 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 7996 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7997 | } |
| 7998 | } finally { |
| 7999 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8000 | } |
| 8001 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8002 | |
| 8003 | /** |
| 8004 | * Get Client request stats |
| 8005 | * @return List of Client Request Stats |
| 8006 | * @hide |
| 8007 | */ |
| 8008 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8009 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8010 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8011 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8012 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8013 | return null; |
| 8014 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8015 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8016 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8017 | final long identity = Binder.clearCallingIdentity(); |
| 8018 | try { |
| 8019 | if (phone != null) { |
| 8020 | return phone.getClientRequestStats(); |
| 8021 | } |
| 8022 | |
| 8023 | return null; |
| 8024 | } finally { |
| 8025 | Binder.restoreCallingIdentity(identity); |
| 8026 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8027 | } |
| 8028 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8029 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8030 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8031 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8032 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8033 | |
| 8034 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8035 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8036 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8037 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8038 | * @param state State of SIM (power down, power up, pass through) |
| 8039 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8040 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8041 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8042 | * |
| 8043 | **/ |
| 8044 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8045 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8046 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8047 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8048 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8049 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8050 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8051 | final long identity = Binder.clearCallingIdentity(); |
| 8052 | try { |
| 8053 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8054 | phone.setSimPowerState(state, null, workSource); |
| 8055 | } |
| 8056 | } finally { |
| 8057 | Binder.restoreCallingIdentity(identity); |
| 8058 | } |
| 8059 | } |
| 8060 | |
| 8061 | /** |
| 8062 | * Set SIM card power state. |
| 8063 | * |
| 8064 | * @param slotIndex SIM slot id. |
| 8065 | * @param state State of SIM (power down, power up, pass through) |
| 8066 | * @param callback callback to trigger after success or failure |
| 8067 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8068 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8069 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8070 | * |
| 8071 | **/ |
| 8072 | @Override |
| 8073 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8074 | IIntegerConsumer callback) { |
| 8075 | enforceModifyPermission(); |
| 8076 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8077 | |
| 8078 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8079 | |
| 8080 | final long identity = Binder.clearCallingIdentity(); |
| 8081 | try { |
| 8082 | if (phone != null) { |
| 8083 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8084 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8085 | } |
| 8086 | } finally { |
| 8087 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8088 | } |
| 8089 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8090 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8091 | private boolean isUssdApiAllowed(int subId) { |
| 8092 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8093 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8094 | if (configManager == null) { |
| 8095 | return false; |
| 8096 | } |
| 8097 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8098 | if (pb == null) { |
| 8099 | return false; |
| 8100 | } |
| 8101 | return pb.getBoolean( |
| 8102 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8103 | } |
| 8104 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8105 | /** |
| 8106 | * Check if phone is in emergency callback mode |
| 8107 | * @return true if phone is in emergency callback mode |
| 8108 | * @param subId sub id |
| 8109 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8110 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8111 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8112 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8113 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8114 | |
| 8115 | final long identity = Binder.clearCallingIdentity(); |
| 8116 | try { |
| 8117 | if (phone != null) { |
| 8118 | return phone.isInEcm(); |
| 8119 | } else { |
| 8120 | return false; |
| 8121 | } |
| 8122 | } finally { |
| 8123 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8124 | } |
| 8125 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8126 | |
| 8127 | /** |
| 8128 | * Get the current signal strength information for the given subscription. |
| 8129 | * Because this information is not updated when the device is in a low power state |
| 8130 | * it should not be relied-upon to be current. |
| 8131 | * @param subId Subscription index |
| 8132 | * @return the most recent cached signal strength info from the modem |
| 8133 | */ |
| 8134 | @Override |
| 8135 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8136 | final long identity = Binder.clearCallingIdentity(); |
| 8137 | try { |
| 8138 | Phone p = getPhone(subId); |
| 8139 | if (p == null) { |
| 8140 | return null; |
| 8141 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8142 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8143 | return p.getSignalStrength(); |
| 8144 | } finally { |
| 8145 | Binder.restoreCallingIdentity(identity); |
| 8146 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8147 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8148 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8149 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8150 | * Get the current modem radio state for the given slot. |
| 8151 | * @param slotIndex slot index. |
| 8152 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8153 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8154 | * @return the current radio power state from the modem |
| 8155 | */ |
| 8156 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8157 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8158 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8159 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8160 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8161 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8162 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8163 | } |
| 8164 | |
| 8165 | final long identity = Binder.clearCallingIdentity(); |
| 8166 | try { |
| 8167 | return phone.getRadioPowerState(); |
| 8168 | } finally { |
| 8169 | Binder.restoreCallingIdentity(identity); |
| 8170 | } |
| 8171 | } |
| 8172 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8173 | } |
| 8174 | |
| 8175 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8176 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8177 | * |
| 8178 | * <p>Requires one of the following permissions: |
| 8179 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 8180 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8181 | * privileges. |
| 8182 | * |
| 8183 | * @param subId subscription id |
| 8184 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8185 | * {@code false}. |
| 8186 | */ |
| 8187 | @Override |
| 8188 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8189 | try { |
| 8190 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8191 | null); |
| 8192 | } catch (Exception e) { |
| 8193 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 8194 | mApp, subId, "isDataRoamingEnabled"); |
| 8195 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8196 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8197 | boolean isEnabled = false; |
| 8198 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8199 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8200 | Phone phone = getPhone(subId); |
| 8201 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8202 | } finally { |
| 8203 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8204 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8205 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8206 | } |
| 8207 | |
| 8208 | |
| 8209 | /** |
| 8210 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8211 | * |
| 8212 | * <p> Requires permission: |
| 8213 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8214 | * privileges. |
| 8215 | * |
| 8216 | * @param subId subscription id |
| 8217 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8218 | */ |
| 8219 | @Override |
| 8220 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8221 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8222 | mApp, subId, "setDataRoamingEnabled"); |
| 8223 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8224 | final long identity = Binder.clearCallingIdentity(); |
| 8225 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8226 | Phone phone = getPhone(subId); |
| 8227 | if (phone != null) { |
| 8228 | phone.setDataRoamingEnabled(isEnabled); |
| 8229 | } |
| 8230 | } finally { |
| 8231 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8232 | } |
| 8233 | } |
| 8234 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8235 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8236 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8237 | TelephonyPermissions |
| 8238 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8239 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8240 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8241 | boolean isAllowed = true; |
| 8242 | final long identity = Binder.clearCallingIdentity(); |
| 8243 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8244 | Phone phone = getPhone(subId); |
| 8245 | if (phone != null) { |
| 8246 | isAllowed = phone.isCspPlmnEnabled(); |
| 8247 | } |
| 8248 | } finally { |
| 8249 | Binder.restoreCallingIdentity(identity); |
| 8250 | } |
| 8251 | return isAllowed; |
| 8252 | } |
| 8253 | |
| 8254 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8255 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8256 | // Verify that tha callingPackage belongs to the calling UID |
| 8257 | mApp.getSystemService(AppOpsManager.class) |
| 8258 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8259 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8260 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8261 | try { |
| 8262 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8263 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8264 | } catch (SecurityException e) { |
| 8265 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8266 | // has carrier privileges on an active UICC |
| 8267 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8268 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8269 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8270 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8271 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8272 | |
| 8273 | final long identity = Binder.clearCallingIdentity(); |
| 8274 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8275 | UiccController uiccController = UiccController.getInstance(); |
| 8276 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8277 | if (hasReadPermission) { |
| 8278 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8279 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8280 | |
| 8281 | // Remove private info if the caller doesn't have access |
| 8282 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8283 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8284 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8285 | // is available |
| 8286 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 8287 | if (card == null || card.getUiccProfile() == null) { |
| 8288 | // assume no access if the card or profile is unavailable |
| 8289 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8290 | continue; |
| 8291 | } |
| 8292 | UiccProfile profile = card.getUiccProfile(); |
| 8293 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8294 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8295 | filteredInfos.add(cardInfo); |
| 8296 | } else { |
| 8297 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8298 | } |
| 8299 | } |
| 8300 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8301 | } finally { |
| 8302 | Binder.restoreCallingIdentity(identity); |
| 8303 | } |
| 8304 | } |
| 8305 | |
| 8306 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8307 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8308 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8309 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8310 | final long identity = Binder.clearCallingIdentity(); |
| 8311 | try { |
| 8312 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8313 | if (slots == null) { |
| 8314 | Rlog.i(LOG_TAG, "slots is null."); |
| 8315 | return null; |
| 8316 | } |
| 8317 | |
| 8318 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8319 | for (int i = 0; i < slots.length; i++) { |
| 8320 | UiccSlot slot = slots[i]; |
| 8321 | if (slot == null) { |
| 8322 | continue; |
| 8323 | } |
| 8324 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8325 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8326 | UiccCard card = slot.getUiccCard(); |
| 8327 | if (card != null) { |
| 8328 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8329 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8330 | cardId = slot.getEid(); |
| 8331 | if (TextUtils.isEmpty(cardId)) { |
| 8332 | cardId = slot.getIccId(); |
| 8333 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8334 | } |
| 8335 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8336 | if (cardId != null) { |
| 8337 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8338 | // if cardId is an EID, it's all digits so this is fine |
| 8339 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8340 | } |
| 8341 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8342 | int cardState = 0; |
| 8343 | switch (slot.getCardState()) { |
| 8344 | case CARDSTATE_ABSENT: |
| 8345 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8346 | break; |
| 8347 | case CARDSTATE_PRESENT: |
| 8348 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8349 | break; |
| 8350 | case CARDSTATE_ERROR: |
| 8351 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8352 | break; |
| 8353 | case CARDSTATE_RESTRICTED: |
| 8354 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8355 | break; |
| 8356 | default: |
| 8357 | break; |
| 8358 | |
| 8359 | } |
| 8360 | |
| 8361 | infos[i] = new UiccSlotInfo( |
| 8362 | slot.isActive(), |
| 8363 | slot.isEuicc(), |
| 8364 | cardId, |
| 8365 | cardState, |
| 8366 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8367 | slot.isExtendedApduSupported(), |
| 8368 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8369 | } |
| 8370 | return infos; |
| 8371 | } finally { |
| 8372 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8373 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8374 | } |
| 8375 | |
| 8376 | @Override |
| 8377 | public boolean switchSlots(int[] physicalSlots) { |
| 8378 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8379 | |
| 8380 | final long identity = Binder.clearCallingIdentity(); |
| 8381 | try { |
| 8382 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8383 | } finally { |
| 8384 | Binder.restoreCallingIdentity(identity); |
| 8385 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8386 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8387 | |
| 8388 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8389 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8390 | final long identity = Binder.clearCallingIdentity(); |
| 8391 | try { |
| 8392 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8393 | } finally { |
| 8394 | Binder.restoreCallingIdentity(identity); |
| 8395 | } |
| 8396 | } |
| 8397 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8398 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8399 | * A test API to reload the UICC profile. |
| 8400 | * |
| 8401 | * <p>Requires that the calling app has permission |
| 8402 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8403 | * @hide |
| 8404 | */ |
| 8405 | @Override |
| 8406 | public void refreshUiccProfile(int subId) { |
| 8407 | enforceModifyPermission(); |
| 8408 | |
| 8409 | final long identity = Binder.clearCallingIdentity(); |
| 8410 | try { |
| 8411 | Phone phone = getPhone(subId); |
| 8412 | if (phone == null) { |
| 8413 | return; |
| 8414 | } |
| 8415 | UiccCard uiccCard = phone.getUiccCard(); |
| 8416 | if (uiccCard == null) { |
| 8417 | return; |
| 8418 | } |
| 8419 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8420 | if (uiccProfile == null) { |
| 8421 | return; |
| 8422 | } |
| 8423 | uiccProfile.refresh(); |
| 8424 | } finally { |
| 8425 | Binder.restoreCallingIdentity(identity); |
| 8426 | } |
| 8427 | } |
| 8428 | |
| 8429 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8430 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8431 | */ |
| 8432 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8433 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8434 | } |
| 8435 | |
| 8436 | /** |
| 8437 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8438 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8439 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8440 | */ |
| 8441 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8442 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8443 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8444 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8445 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8446 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8447 | return isDataRoamingEnabled; |
| 8448 | } |
| 8449 | |
| 8450 | /** |
| 8451 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8452 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8453 | */ |
| 8454 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8455 | List<Integer> list = TelephonyProperties.default_network(); |
| 8456 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8457 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8458 | return list.get(phoneId); |
| 8459 | } |
| 8460 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8461 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8462 | |
| 8463 | @Override |
| 8464 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8465 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8466 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8467 | |
| 8468 | final long identity = Binder.clearCallingIdentity(); |
| 8469 | try { |
| 8470 | final Phone phone = getPhone(subId); |
| 8471 | if (phone == null) { |
| 8472 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8473 | return; |
| 8474 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8475 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8476 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8477 | if (carrierPrivilegeRules == null) { |
| 8478 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8479 | } else { |
| 8480 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8481 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8482 | } finally { |
| 8483 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8484 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8485 | } |
| 8486 | |
| 8487 | @Override |
| 8488 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8489 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8490 | |
| 8491 | final long identity = Binder.clearCallingIdentity(); |
| 8492 | try { |
| 8493 | final Phone phone = getPhone(subId); |
| 8494 | if (phone == null) { |
| 8495 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8496 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8497 | } |
| 8498 | return phone.getCarrierIdListVersion(); |
| 8499 | } finally { |
| 8500 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8501 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8502 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8503 | |
| 8504 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8505 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8506 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8507 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8508 | mApp, subId, callingPackage, callingFeatureId, |
| 8509 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8510 | return -1; |
| 8511 | } |
| 8512 | |
| 8513 | final long identity = Binder.clearCallingIdentity(); |
| 8514 | try { |
| 8515 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8516 | } finally { |
| 8517 | Binder.restoreCallingIdentity(identity); |
| 8518 | } |
| 8519 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8520 | |
| 8521 | @Override |
| 8522 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8523 | TelephonyPermissions |
| 8524 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8525 | mApp, subId, "getCdmaRoamingMode"); |
| 8526 | |
| 8527 | final long identity = Binder.clearCallingIdentity(); |
| 8528 | try { |
| 8529 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8530 | } finally { |
| 8531 | Binder.restoreCallingIdentity(identity); |
| 8532 | } |
| 8533 | } |
| 8534 | |
| 8535 | @Override |
| 8536 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8537 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8538 | mApp, subId, "setCdmaRoamingMode"); |
| 8539 | |
| 8540 | final long identity = Binder.clearCallingIdentity(); |
| 8541 | try { |
| 8542 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8543 | } finally { |
| 8544 | Binder.restoreCallingIdentity(identity); |
| 8545 | } |
| 8546 | } |
| 8547 | |
| 8548 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8549 | public int getCdmaSubscriptionMode(int subId) { |
| 8550 | TelephonyPermissions |
| 8551 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8552 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8553 | |
| 8554 | final long identity = Binder.clearCallingIdentity(); |
| 8555 | try { |
| 8556 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8557 | } finally { |
| 8558 | Binder.restoreCallingIdentity(identity); |
| 8559 | } |
| 8560 | } |
| 8561 | |
| 8562 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8563 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8564 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8565 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8566 | |
| 8567 | final long identity = Binder.clearCallingIdentity(); |
| 8568 | try { |
| 8569 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8570 | } finally { |
| 8571 | Binder.restoreCallingIdentity(identity); |
| 8572 | } |
| 8573 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8574 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8575 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8576 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8577 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8578 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8579 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8580 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8581 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8582 | } |
| 8583 | final long identity = Binder.clearCallingIdentity(); |
| 8584 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8585 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8586 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8587 | if (phone.getEmergencyNumberTracker() != null |
| 8588 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8589 | emergencyNumberListInternal.put( |
| 8590 | phone.getSubId(), |
| 8591 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8592 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8593 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8594 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8595 | } finally { |
| 8596 | Binder.restoreCallingIdentity(identity); |
| 8597 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8598 | } |
| 8599 | |
| 8600 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8601 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8602 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8603 | if (!exactMatch) { |
| 8604 | TelephonyPermissions |
| 8605 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8606 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8607 | } |
| 8608 | final long identity = Binder.clearCallingIdentity(); |
| 8609 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8610 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8611 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8612 | && phone.getEmergencyNumberTracker() |
| 8613 | .isEmergencyNumber(number, exactMatch)) { |
| 8614 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8615 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8616 | } |
| 8617 | return false; |
| 8618 | } finally { |
| 8619 | Binder.restoreCallingIdentity(identity); |
| 8620 | } |
| 8621 | } |
| 8622 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8623 | /** |
| 8624 | * Update emergency number list for test mode. |
| 8625 | */ |
| 8626 | @Override |
| 8627 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8628 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8629 | "updateEmergencyNumberListTestMode"); |
| 8630 | |
| 8631 | final long identity = Binder.clearCallingIdentity(); |
| 8632 | try { |
| 8633 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8634 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8635 | if (tracker != null) { |
| 8636 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8637 | } |
| 8638 | } |
| 8639 | } finally { |
| 8640 | Binder.restoreCallingIdentity(identity); |
| 8641 | } |
| 8642 | } |
| 8643 | |
| 8644 | /** |
| 8645 | * Get the full emergency number list for test mode. |
| 8646 | */ |
| 8647 | @Override |
| 8648 | public List<String> getEmergencyNumberListTestMode() { |
| 8649 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8650 | "getEmergencyNumberListTestMode"); |
| 8651 | |
| 8652 | final long identity = Binder.clearCallingIdentity(); |
| 8653 | try { |
| 8654 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8655 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8656 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8657 | if (tracker != null) { |
| 8658 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8659 | emergencyNumbers.add(num.getNumber()); |
| 8660 | } |
| 8661 | } |
| 8662 | } |
| 8663 | return new ArrayList<>(emergencyNumbers); |
| 8664 | } finally { |
| 8665 | Binder.restoreCallingIdentity(identity); |
| 8666 | } |
| 8667 | } |
| 8668 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8669 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8670 | public int getEmergencyNumberDbVersion(int subId) { |
| 8671 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8672 | |
| 8673 | final long identity = Binder.clearCallingIdentity(); |
| 8674 | try { |
| 8675 | final Phone phone = getPhone(subId); |
| 8676 | if (phone == null) { |
| 8677 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8678 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8679 | } |
| 8680 | return phone.getEmergencyNumberDbVersion(); |
| 8681 | } finally { |
| 8682 | Binder.restoreCallingIdentity(identity); |
| 8683 | } |
| 8684 | } |
| 8685 | |
| 8686 | @Override |
| 8687 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8688 | enforceModifyPermission(); |
| 8689 | |
| 8690 | final long identity = Binder.clearCallingIdentity(); |
| 8691 | try { |
| 8692 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8693 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8694 | if (tracker != null) { |
| 8695 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8696 | } |
| 8697 | } |
| 8698 | } finally { |
| 8699 | Binder.restoreCallingIdentity(identity); |
| 8700 | } |
| 8701 | } |
| 8702 | |
| 8703 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8704 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8705 | enforceActiveEmergencySessionPermission(); |
| 8706 | |
| 8707 | final long identity = Binder.clearCallingIdentity(); |
| 8708 | try { |
| 8709 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8710 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8711 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8712 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8713 | } |
| 8714 | } |
| 8715 | } finally { |
| 8716 | Binder.restoreCallingIdentity(identity); |
| 8717 | } |
| 8718 | } |
| 8719 | |
| 8720 | @Override |
| 8721 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8722 | enforceActiveEmergencySessionPermission(); |
| 8723 | |
| 8724 | final long identity = Binder.clearCallingIdentity(); |
| 8725 | try { |
| 8726 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8727 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8728 | if (tracker != null) { |
| 8729 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8730 | } |
| 8731 | } |
| 8732 | } finally { |
| 8733 | Binder.restoreCallingIdentity(identity); |
| 8734 | } |
| 8735 | } |
| 8736 | |
| 8737 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8738 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8739 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8740 | Phone phone = getPhone(subId); |
| 8741 | if (phone == null) { |
| 8742 | return null; |
| 8743 | } |
| 8744 | final long identity = Binder.clearCallingIdentity(); |
| 8745 | try { |
| 8746 | UiccProfile profile = UiccController.getInstance() |
| 8747 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8748 | if (profile != null) { |
| 8749 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8750 | } |
| 8751 | } finally { |
| 8752 | Binder.restoreCallingIdentity(identity); |
| 8753 | } |
| 8754 | return null; |
| 8755 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8756 | |
| 8757 | /** |
| 8758 | * Enable or disable a modem stack. |
| 8759 | */ |
| 8760 | @Override |
| 8761 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8762 | enforceModifyPermission(); |
| 8763 | |
| 8764 | final long identity = Binder.clearCallingIdentity(); |
| 8765 | try { |
| 8766 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8767 | if (phone == null) { |
| 8768 | return false; |
| 8769 | } else { |
| 8770 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8771 | } |
| 8772 | } finally { |
| 8773 | Binder.restoreCallingIdentity(identity); |
| 8774 | } |
| 8775 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8776 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8777 | /** |
| 8778 | * Whether a modem stack is enabled or not. |
| 8779 | */ |
| 8780 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8781 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8782 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8783 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8784 | if (phone == null) return false; |
| 8785 | |
| 8786 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8787 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8788 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8789 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8790 | } |
| 8791 | |
| 8792 | final long identity = Binder.clearCallingIdentity(); |
| 8793 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8794 | try { |
| 8795 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8796 | } catch (NoSuchElementException ex) { |
| 8797 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8798 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8799 | } finally { |
| 8800 | Binder.restoreCallingIdentity(identity); |
| 8801 | } |
| 8802 | } |
| 8803 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8804 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8805 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8806 | enforceModifyPermission(); |
| 8807 | |
| 8808 | final long identity = Binder.clearCallingIdentity(); |
| 8809 | try { |
| 8810 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8811 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8812 | .commit(); |
| 8813 | } finally { |
| 8814 | Binder.restoreCallingIdentity(identity); |
| 8815 | } |
| 8816 | } |
| 8817 | |
| 8818 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8819 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8820 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8821 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8822 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8823 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8824 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8825 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8826 | |
| 8827 | final long identity = Binder.clearCallingIdentity(); |
| 8828 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8829 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8830 | } finally { |
| 8831 | Binder.restoreCallingIdentity(identity); |
| 8832 | } |
| 8833 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8834 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8835 | @TelephonyManager.IsMultiSimSupportedResult |
| 8836 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8837 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8838 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8839 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8840 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8841 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8842 | } |
| 8843 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8844 | // supported by the modem, indicate that it is restricted. |
| 8845 | PhoneCapability staticCapability = |
| 8846 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8847 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8848 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8849 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8850 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 8851 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8852 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8853 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8854 | } |
| 8855 | // Check if support of multiple SIMs is restricted by carrier |
| 8856 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8857 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8858 | } |
| 8859 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8860 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8861 | } |
| 8862 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8863 | /** |
| 8864 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8865 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8866 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8867 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8868 | * @param numOfSims number of active sims we want to switch to |
| 8869 | */ |
| 8870 | @Override |
| 8871 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8872 | if (numOfSims == 1) { |
| 8873 | enforceModifyPermission(); |
| 8874 | } else { |
| 8875 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8876 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8877 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8878 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8879 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8880 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8881 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8882 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8883 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8884 | return; |
| 8885 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8886 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8887 | } finally { |
| 8888 | Binder.restoreCallingIdentity(identity); |
| 8889 | } |
| 8890 | } |
| 8891 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8892 | @Override |
| 8893 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8894 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8895 | Phone phone = getPhone(subId); |
| 8896 | if (phone == null) { |
| 8897 | return false; |
| 8898 | } |
| 8899 | final long identity = Binder.clearCallingIdentity(); |
| 8900 | try { |
| 8901 | UiccCard uiccCard = phone.getUiccCard(); |
| 8902 | if (uiccCard == null) { |
| 8903 | return false; |
| 8904 | } |
| 8905 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8906 | if (uiccProfile == null) { |
| 8907 | return false; |
| 8908 | } |
| 8909 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8910 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8911 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8912 | } |
| 8913 | return false; |
| 8914 | } finally { |
| 8915 | Binder.restoreCallingIdentity(identity); |
| 8916 | } |
| 8917 | } |
| 8918 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8919 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8920 | * Get whether making changes to modem configurations will trigger reboot. |
| 8921 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8922 | */ |
| 8923 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8924 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8925 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8926 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8927 | mApp, subId, callingPackage, callingFeatureId, |
| 8928 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8929 | return false; |
| 8930 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8931 | final long identity = Binder.clearCallingIdentity(); |
| 8932 | try { |
| 8933 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8934 | } finally { |
| 8935 | Binder.restoreCallingIdentity(identity); |
| 8936 | } |
| 8937 | } |
| 8938 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8939 | private void updateModemStateMetrics() { |
| 8940 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8941 | // TODO: check the state for each modem if the api is ready. |
| 8942 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8943 | } |
| 8944 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8945 | @Override |
| 8946 | public int[] getSlotsMapping() { |
| 8947 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8948 | |
| 8949 | final long identity = Binder.clearCallingIdentity(); |
| 8950 | try { |
| 8951 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8952 | // All logical slots should have a mapping to a physical slot. |
| 8953 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8954 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8955 | for (int i = 0; i < slotInfos.length; i++) { |
| 8956 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8957 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8958 | } |
| 8959 | } |
| 8960 | return logicalSlotsMapping; |
| 8961 | } finally { |
| 8962 | Binder.restoreCallingIdentity(identity); |
| 8963 | } |
| 8964 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8965 | |
| 8966 | /** |
| 8967 | * Get the IRadio HAL Version |
| 8968 | */ |
| 8969 | @Override |
| 8970 | public int getRadioHalVersion() { |
| 8971 | Phone phone = getDefaultPhone(); |
| 8972 | if (phone == null) return -1; |
| 8973 | HalVersion hv = phone.getHalVersion(); |
| 8974 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8975 | return hv.major * 100 + hv.minor; |
| 8976 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8977 | |
| 8978 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8979 | * Get the current calling package name. |
| 8980 | * @return the current calling package name |
| 8981 | */ |
| 8982 | @Override |
| 8983 | public String getCurrentPackageName() { |
| 8984 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8985 | } |
| 8986 | |
| 8987 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8988 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8989 | * corresponding network requests on a subId. |
| 8990 | * |
| 8991 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8992 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8993 | * 2) APN is un-metered for this subscription, or |
| 8994 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8995 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8996 | * |
| 8997 | * @return whether data is allowed for a apn type. |
| 8998 | * |
| 8999 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9000 | */ |
| 9001 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9002 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9003 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9004 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9005 | |
| 9006 | // Now that all security checks passes, perform the operation as ourselves. |
| 9007 | final long identity = Binder.clearCallingIdentity(); |
| 9008 | try { |
| 9009 | Phone phone = getPhone(subId); |
| 9010 | if (phone == null) return false; |
| 9011 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9012 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9013 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 9014 | } finally { |
| 9015 | Binder.restoreCallingIdentity(identity); |
| 9016 | } |
| 9017 | } |
| 9018 | |
| 9019 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9020 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9021 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9022 | |
| 9023 | // Now that all security checks passes, perform the operation as ourselves. |
| 9024 | final long identity = Binder.clearCallingIdentity(); |
| 9025 | try { |
| 9026 | Phone phone = getPhone(subId); |
| 9027 | if (phone == null) return true; // By default return true. |
| 9028 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9029 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9030 | } finally { |
| 9031 | Binder.restoreCallingIdentity(identity); |
| 9032 | } |
| 9033 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9034 | |
| 9035 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9036 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9037 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9038 | enforceModifyPermission(); |
| 9039 | long token = Binder.clearCallingIdentity(); |
| 9040 | try { |
| 9041 | Phone phone = getPhone(subscriptionId); |
| 9042 | if (phone == null) { |
| 9043 | try { |
| 9044 | if (resultCallback != null) { |
| 9045 | resultCallback.accept(false); |
| 9046 | } |
| 9047 | } catch (RemoteException e) { |
| 9048 | // ignore |
| 9049 | } |
| 9050 | return; |
| 9051 | } |
| 9052 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9053 | Pair.create(specifiers, (x) -> { |
| 9054 | try { |
| 9055 | if (resultCallback != null) { |
| 9056 | resultCallback.accept(x); |
| 9057 | } |
| 9058 | } catch (RemoteException e) { |
| 9059 | // ignore |
| 9060 | } |
| 9061 | }); |
| 9062 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9063 | } finally { |
| 9064 | Binder.restoreCallingIdentity(token); |
| 9065 | } |
| 9066 | } |
| 9067 | |
| 9068 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9069 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9070 | TelephonyPermissions |
| 9071 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 9072 | mApp, subId, "getSystemSelectionChannels"); |
| 9073 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9074 | final long identity = Binder.clearCallingIdentity(); |
| 9075 | try { |
| 9076 | List<RadioAccessSpecifier> specifiers = |
| 9077 | (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, |
| 9078 | null, subId, workSource); |
| 9079 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9080 | return specifiers; |
| 9081 | } finally { |
| 9082 | Binder.restoreCallingIdentity(identity); |
| 9083 | } |
| 9084 | } |
| 9085 | |
| 9086 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9087 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9088 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9089 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9090 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9091 | if (iccRecords == null) { |
| 9092 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9093 | return false; |
| 9094 | } |
| 9095 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9096 | } |
| 9097 | |
| 9098 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9099 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9100 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9101 | if (callingPackage == null) { |
| 9102 | callingPackage = getCurrentPackageName(); |
| 9103 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9104 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9105 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9106 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9107 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9108 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9109 | } |
| 9110 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9111 | Intent intent = new Intent(); |
| 9112 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9113 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9114 | // Bring up choose default SMS subscription dialog right now |
| 9115 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9116 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9117 | mApp.startActivity(intent); |
| 9118 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9119 | |
| 9120 | @Override |
| 9121 | public String getMmsUAProfUrl(int subId) { |
| 9122 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9123 | final long identity = Binder.clearCallingIdentity(); |
| 9124 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9125 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9126 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9127 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9128 | return carrierUAProfUrl; |
| 9129 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9130 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9131 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9132 | } finally { |
| 9133 | Binder.restoreCallingIdentity(identity); |
| 9134 | } |
| 9135 | } |
| 9136 | |
| 9137 | @Override |
| 9138 | public String getMmsUserAgent(int subId) { |
| 9139 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9140 | final long identity = Binder.clearCallingIdentity(); |
| 9141 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9142 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9143 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9144 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9145 | return carrierUserAgent; |
| 9146 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9147 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9148 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9149 | } finally { |
| 9150 | Binder.restoreCallingIdentity(identity); |
| 9151 | } |
| 9152 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9153 | |
| 9154 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9155 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9156 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9157 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9158 | final long identity = Binder.clearCallingIdentity(); |
| 9159 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9160 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9161 | if (phone == null) return false; |
| 9162 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9163 | switch (policy) { |
| 9164 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9165 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9166 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9167 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9168 | default: |
| 9169 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9170 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9171 | } finally { |
| 9172 | Binder.restoreCallingIdentity(identity); |
| 9173 | } |
| 9174 | } |
| 9175 | |
| 9176 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9177 | public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy, |
| 9178 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9179 | enforceModifyPermission(); |
| 9180 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9181 | final long identity = Binder.clearCallingIdentity(); |
| 9182 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9183 | Phone phone = getPhone(subscriptionId); |
| 9184 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9185 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9186 | switch (policy) { |
| 9187 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9188 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9189 | break; |
| 9190 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9191 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9192 | break; |
| 9193 | default: |
| 9194 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9195 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9196 | } finally { |
| 9197 | Binder.restoreCallingIdentity(identity); |
| 9198 | } |
| 9199 | } |
| 9200 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9201 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9202 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9203 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9204 | * otherwise. |
| 9205 | */ |
| 9206 | @Override |
| 9207 | public void setCepEnabled(boolean isCepEnabled) { |
| 9208 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9209 | |
| 9210 | final long identity = Binder.clearCallingIdentity(); |
| 9211 | try { |
| 9212 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9213 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9214 | Phone defaultPhone = phone.getImsPhone(); |
| 9215 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9216 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9217 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9218 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9219 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9220 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9221 | + imsPhone.getMsisdn()); |
| 9222 | } |
| 9223 | } |
| 9224 | } finally { |
| 9225 | Binder.restoreCallingIdentity(identity); |
| 9226 | } |
| 9227 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9228 | |
| 9229 | /** |
| 9230 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9231 | * |
| 9232 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9233 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9234 | * before being read. |
| 9235 | */ |
| 9236 | @Override |
| 9237 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9238 | isCompressed) { |
| 9239 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9240 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9241 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9242 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9243 | } |
| 9244 | if (!isImsAvailableOnDevice()) { |
| 9245 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9246 | "IMS not available on device."); |
| 9247 | } |
| 9248 | |
| 9249 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9250 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9251 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9252 | } finally { |
| 9253 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9254 | } |
| 9255 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9256 | |
| 9257 | @Override |
| 9258 | public boolean isIccLockEnabled(int subId) { |
| 9259 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9260 | |
| 9261 | // Now that all security checks passes, perform the operation as ourselves. |
| 9262 | final long identity = Binder.clearCallingIdentity(); |
| 9263 | try { |
| 9264 | Phone phone = getPhone(subId); |
| 9265 | if (phone != null && phone.getIccCard() != null) { |
| 9266 | return phone.getIccCard().getIccLockEnabled(); |
| 9267 | } else { |
| 9268 | return false; |
| 9269 | } |
| 9270 | } finally { |
| 9271 | Binder.restoreCallingIdentity(identity); |
| 9272 | } |
| 9273 | } |
| 9274 | |
| 9275 | /** |
| 9276 | * Set the ICC pin lock enabled or disabled. |
| 9277 | * |
| 9278 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9279 | * three cases: |
| 9280 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9281 | * successfully. |
| 9282 | * - Positive number and zero for remaining password attempts. |
| 9283 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9284 | * |
| 9285 | */ |
| 9286 | @Override |
| 9287 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9288 | enforceModifyPermission(); |
| 9289 | |
| 9290 | Phone phone = getPhone(subId); |
| 9291 | if (phone == null) { |
| 9292 | return 0; |
| 9293 | } |
| 9294 | // Now that all security checks passes, perform the operation as ourselves. |
| 9295 | final long identity = Binder.clearCallingIdentity(); |
| 9296 | try { |
| 9297 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9298 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9299 | return attemptsRemaining; |
| 9300 | |
| 9301 | } catch (Exception e) { |
| 9302 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9303 | } finally { |
| 9304 | Binder.restoreCallingIdentity(identity); |
| 9305 | } |
| 9306 | return 0; |
| 9307 | } |
| 9308 | |
| 9309 | /** |
| 9310 | * Change the ICC password used in ICC pin lock. |
| 9311 | * |
| 9312 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9313 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9314 | * - Positive number and zero for remaining password attempts. |
| 9315 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9316 | * |
| 9317 | */ |
| 9318 | @Override |
| 9319 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9320 | enforceModifyPermission(); |
| 9321 | |
| 9322 | Phone phone = getPhone(subId); |
| 9323 | if (phone == null) { |
| 9324 | return 0; |
| 9325 | } |
| 9326 | // Now that all security checks passes, perform the operation as ourselves. |
| 9327 | final long identity = Binder.clearCallingIdentity(); |
| 9328 | try { |
| 9329 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9330 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9331 | return attemptsRemaining; |
| 9332 | |
| 9333 | } catch (Exception e) { |
| 9334 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9335 | } finally { |
| 9336 | Binder.restoreCallingIdentity(identity); |
| 9337 | } |
| 9338 | return 0; |
| 9339 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9340 | |
| 9341 | /** |
| 9342 | * Request for receiving user activity notification |
| 9343 | */ |
| 9344 | @Override |
| 9345 | public void requestUserActivityNotification() { |
| 9346 | if (!mNotifyUserActivity.get() |
| 9347 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9348 | mNotifyUserActivity.set(true); |
| 9349 | } |
| 9350 | } |
| 9351 | |
| 9352 | /** |
| 9353 | * Called when userActivity is signalled in the power manager. |
| 9354 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9355 | */ |
| 9356 | @Override |
| 9357 | public void userActivity() { |
| 9358 | // *************************************** |
| 9359 | // * Inherited from PhoneWindowManager * |
| 9360 | // *************************************** |
| 9361 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9362 | // WITH ITS LOCKS HELD. |
| 9363 | // |
| 9364 | // This code must be VERY careful about the locks |
| 9365 | // it acquires. |
| 9366 | // In fact, the current code acquires way too many, |
| 9367 | // and probably has lurking deadlocks. |
| 9368 | |
| 9369 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9370 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9371 | } |
| 9372 | |
| 9373 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9374 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9375 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9376 | } |
| 9377 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9378 | |
| 9379 | @Override |
| 9380 | public boolean canConnectTo5GInDsdsMode() { |
| 9381 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9382 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9383 | |
| 9384 | @Override |
| 9385 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9386 | String callingFeatureId) { |
| 9387 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9388 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9389 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9390 | } |
| 9391 | |
| 9392 | Phone phone = getPhone(subId); |
| 9393 | if (phone == null) { |
| 9394 | throw new RuntimeException("phone is not available"); |
| 9395 | } |
| 9396 | // Now that all security checks passes, perform the operation as ourselves. |
| 9397 | final long identity = Binder.clearCallingIdentity(); |
| 9398 | try { |
| 9399 | return phone.getEquivalentHomePlmns(); |
| 9400 | } finally { |
| 9401 | Binder.restoreCallingIdentity(identity); |
| 9402 | } |
| 9403 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9404 | |
| 9405 | @Override |
| 9406 | public boolean isRadioInterfaceCapabilitySupported( |
| 9407 | @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 9408 | RadioInterfaceCapabilities radioInterfaceCapabilities = |
| 9409 | mPhoneConfigurationManager.getRadioInterfaceCapabilities(); |
| 9410 | if (radioInterfaceCapabilities == null) { |
| 9411 | throw new RuntimeException("radio interface capabilities are not available"); |
| 9412 | } else { |
| 9413 | return radioInterfaceCapabilities.isSupported(capability); |
| 9414 | } |
| 9415 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9416 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9417 | @Override |
| 9418 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 9419 | UaSecurityProtocolIdentifier securityProtocol, |
| 9420 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) |
| 9421 | throws RemoteException { |
| 9422 | enforceModifyPermission(); |
| 9423 | if (DBG) { |
| 9424 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 9425 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 9426 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 9427 | } |
| 9428 | |
| 9429 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 9430 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 9431 | || appType > TelephonyManager.APPTYPE_ISIM |
| 9432 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 9433 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 9434 | if (callback != null) { |
| 9435 | try { |
| 9436 | callback.onAuthenticationFailure( |
| 9437 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 9438 | } catch (RemoteException exception) { |
| 9439 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 9440 | } |
| 9441 | return; |
| 9442 | } |
| 9443 | } |
| 9444 | |
| 9445 | final long token = Binder.clearCallingIdentity(); |
| 9446 | try { |
| 9447 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 9448 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 9449 | forceBootStrapping, callback)); |
| 9450 | } finally { |
| 9451 | Binder.restoreCallingIdentity(token); |
| 9452 | } |
| 9453 | } |
| 9454 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9455 | /** |
| 9456 | * Attempts to set the radio power state for thermal reason. This does not guarantee that the |
| 9457 | * requested radio power state will actually be set. See {@link |
| 9458 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9459 | * |
| 9460 | * @param subId the subscription ID of the phone requesting to set the radio power state. |
| 9461 | * @param enable {@code true} if trying to turn radio on. |
| 9462 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9463 | * false}. |
| 9464 | */ |
| 9465 | private boolean setRadioPowerForThermal(int subId, boolean enable) { |
| 9466 | Phone phone = getPhone(subId); |
| 9467 | if (phone != null) { |
| 9468 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 9469 | return true; |
| 9470 | } |
| 9471 | return false; |
| 9472 | } |
| 9473 | |
| 9474 | private int handleDataThrottlingRequest(int subId, |
| 9475 | DataThrottlingRequest dataThrottlingRequest) { |
| 9476 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 9477 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9478 | if (!setRadioPowerForThermal(subId, true)) { |
| 9479 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9480 | } |
| 9481 | |
| 9482 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 9483 | |
| 9484 | int thermalMitigationResult = |
| 9485 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
| 9486 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 9487 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 9488 | } |
| 9489 | return thermalMitigationResult; |
| 9490 | } |
| 9491 | |
| 9492 | /** |
| 9493 | * Thermal mitigation request to control functionalities at modem. |
| 9494 | * |
| 9495 | * @param subId the id of the subscription. |
| 9496 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
| 9497 | * |
| 9498 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 9499 | */ |
| 9500 | @Override |
| 9501 | @ThermalMitigationResult |
| 9502 | public int sendThermalMitigationRequest( |
| 9503 | int subId, |
| 9504 | ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException { |
| 9505 | enforceModifyPermission(); |
| 9506 | |
| 9507 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9508 | final long identity = Binder.clearCallingIdentity(); |
| 9509 | |
| 9510 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 9511 | try { |
| 9512 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 9513 | switch (thermalMitigationAction) { |
| 9514 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 9515 | thermalMitigationResult = |
| 9516 | handleDataThrottlingRequest(subId, |
| 9517 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 9518 | break; |
| 9519 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 9520 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9521 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 9522 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 9523 | } |
| 9524 | |
| 9525 | // Ensure that radio is on. If not able to power on due to phone being |
| 9526 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9527 | if (!setRadioPowerForThermal(subId, true)) { |
| 9528 | thermalMitigationResult = |
| 9529 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9530 | break; |
| 9531 | } |
| 9532 | |
| 9533 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 9534 | false); |
| 9535 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9536 | break; |
| 9537 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 9538 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9539 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 9540 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 9541 | } |
| 9542 | |
| 9543 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 9544 | if (registry != null) { |
| 9545 | TelephonyConnectionService service = |
| 9546 | registry.getTelephonyConnectionService(); |
| 9547 | Phone phone = getPhone(subId); |
| 9548 | if (phone == null) { |
| 9549 | thermalMitigationResult = |
| 9550 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9551 | break; |
| 9552 | } |
| 9553 | |
| 9554 | if (PhoneConstantConversions.convertCallState(phone.getState()) |
| 9555 | != TelephonyManager.CALL_STATE_IDLE |
| 9556 | || phone.isInEmergencySmsMode() || phone.isInEcm() |
| 9557 | || (service != null && service.isEmergencyCallPending())) { |
| 9558 | String errorMessage = "Phone state is not valid. call state = " |
| 9559 | + PhoneConstantConversions.convertCallState(phone.getState()) |
| 9560 | + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode() |
| 9561 | + " isInEmergencyCallbackMode = " + phone.isInEcm(); |
| 9562 | errorMessage += service == null |
| 9563 | ? " TelephonyConnectionService is null" |
| 9564 | : " isEmergencyCallPending = " |
| 9565 | + service.isEmergencyCallPending(); |
| 9566 | Log.e(LOG_TAG, errorMessage); |
| 9567 | thermalMitigationResult = |
| 9568 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 9569 | break; |
| 9570 | } |
| 9571 | } else { |
| 9572 | thermalMitigationResult = |
| 9573 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9574 | break; |
| 9575 | } |
| 9576 | |
| 9577 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 9578 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9579 | if (!setRadioPowerForThermal(subId, false)) { |
| 9580 | thermalMitigationResult = |
| 9581 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9582 | break; |
| 9583 | } |
| 9584 | thermalMitigationResult = |
| 9585 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9586 | break; |
| 9587 | default: |
| 9588 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 9589 | + "not exist. Requested action: " + thermalMitigationAction); |
| 9590 | } |
| 9591 | } catch (IllegalArgumentException e) { |
| 9592 | throw e; |
| 9593 | } catch (Exception e) { |
| 9594 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 9595 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 9596 | } finally { |
| 9597 | Binder.restoreCallingIdentity(identity); |
| 9598 | } |
| 9599 | |
| 9600 | if (DBG) { |
| 9601 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 9602 | + thermalMitigationResult); |
| 9603 | } |
| 9604 | |
| 9605 | return thermalMitigationResult; |
| 9606 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9607 | |
| 9608 | /** |
| 9609 | * Set the GbaService Package Name that Telephony will bind to. |
| 9610 | * |
| 9611 | * @param subId The sim that the GbaService is associated with. |
| 9612 | * @param packageName The name of the package to be replaced with. |
| 9613 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9614 | */ |
| 9615 | @Override |
| 9616 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 9617 | enforceModifyPermission(); |
| 9618 | |
| 9619 | final long identity = Binder.clearCallingIdentity(); |
| 9620 | try { |
| 9621 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 9622 | } finally { |
| 9623 | Binder.restoreCallingIdentity(identity); |
| 9624 | } |
| 9625 | } |
| 9626 | |
| 9627 | /** |
| 9628 | * Return the package name of the currently bound GbaService. |
| 9629 | * |
| 9630 | * @param subId The sim that the GbaService is associated with. |
| 9631 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 9632 | */ |
| 9633 | @Override |
| 9634 | public String getBoundGbaService(int subId) { |
| 9635 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 9636 | |
| 9637 | final long identity = Binder.clearCallingIdentity(); |
| 9638 | try { |
| 9639 | return getGbaManager(subId).getServicePackage(); |
| 9640 | } finally { |
| 9641 | Binder.restoreCallingIdentity(identity); |
| 9642 | } |
| 9643 | } |
| 9644 | |
| 9645 | /** |
| 9646 | * Set the release time for telephony to unbind GbaService. |
| 9647 | * |
| 9648 | * @param subId The sim that the GbaService is associated with. |
| 9649 | * @param interval The release time to unbind GbaService by millisecond. |
| 9650 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9651 | */ |
| 9652 | @Override |
| 9653 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 9654 | enforceModifyPermission(); |
| 9655 | |
| 9656 | final long identity = Binder.clearCallingIdentity(); |
| 9657 | try { |
| 9658 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 9659 | } finally { |
| 9660 | Binder.restoreCallingIdentity(identity); |
| 9661 | } |
| 9662 | } |
| 9663 | |
| 9664 | /** |
| 9665 | * Return the release time for telephony to unbind GbaService. |
| 9666 | * |
| 9667 | * @param subId The sim that the GbaService is associated with. |
| 9668 | * @return The release time to unbind GbaService by millisecond. |
| 9669 | */ |
| 9670 | @Override |
| 9671 | public int getGbaReleaseTime(int subId) { |
| 9672 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 9673 | |
| 9674 | final long identity = Binder.clearCallingIdentity(); |
| 9675 | try { |
| 9676 | return getGbaManager(subId).getReleaseTime(); |
| 9677 | } finally { |
| 9678 | Binder.restoreCallingIdentity(identity); |
| 9679 | } |
| 9680 | } |
| 9681 | |
| 9682 | private GbaManager getGbaManager(int subId) { |
| 9683 | GbaManager instance = GbaManager.getInstance(subId); |
| 9684 | if (instance == null) { |
| 9685 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 9686 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 9687 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 9688 | } |
| 9689 | return instance; |
| 9690 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9691 | |
| 9692 | /** |
| 9693 | * indicate whether the device and the carrier can support |
| 9694 | * RCS VoLTE single registration. |
| 9695 | */ |
| 9696 | @Override |
| 9697 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
| 9698 | enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable"); |
| 9699 | |
| 9700 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9701 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9702 | } |
| 9703 | |
| 9704 | final long identity = Binder.clearCallingIdentity(); |
| 9705 | try { |
| 9706 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 9707 | if (rpm != null) { |
| 9708 | return rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 9709 | } |
| 9710 | return false; |
| 9711 | } finally { |
| 9712 | Binder.restoreCallingIdentity(identity); |
| 9713 | } |
| 9714 | } |
| 9715 | |
| 9716 | /** |
| 9717 | * Register RCS provisioning callback. |
| 9718 | */ |
| 9719 | @Override |
| 9720 | public void registerRcsProvisioningChangedCallback(int subId, |
| 9721 | IRcsConfigCallback callback) { |
| 9722 | enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback"); |
| 9723 | |
| 9724 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9725 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9726 | } |
| 9727 | if (!isImsAvailableOnDevice()) { |
| 9728 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9729 | "IMS not available on device."); |
| 9730 | } |
| 9731 | |
| 9732 | final long identity = Binder.clearCallingIdentity(); |
| 9733 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9734 | if (!RcsProvisioningMonitor.getInstance() |
| 9735 | .registerRcsProvisioningChangedCallback(subId, callback)) { |
| 9736 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9737 | "Service not available for the subscription."); |
| 9738 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9739 | } finally { |
| 9740 | Binder.restoreCallingIdentity(identity); |
| 9741 | } |
| 9742 | } |
| 9743 | |
| 9744 | /** |
| 9745 | * Unregister RCS provisioning callback. |
| 9746 | */ |
| 9747 | @Override |
| 9748 | public void unregisterRcsProvisioningChangedCallback(int subId, |
| 9749 | IRcsConfigCallback callback) { |
| 9750 | enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback"); |
| 9751 | |
| 9752 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9753 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9754 | } |
| 9755 | if (!isImsAvailableOnDevice()) { |
| 9756 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9757 | "IMS not available on device."); |
| 9758 | } |
| 9759 | |
| 9760 | final long identity = Binder.clearCallingIdentity(); |
| 9761 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9762 | RcsProvisioningMonitor.getInstance() |
| 9763 | .unregisterRcsProvisioningChangedCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9764 | } finally { |
| 9765 | Binder.restoreCallingIdentity(identity); |
| 9766 | } |
| 9767 | } |
| 9768 | |
| 9769 | /** |
| 9770 | * trigger RCS reconfiguration. |
| 9771 | */ |
| 9772 | public void triggerRcsReconfiguration(int subId) { |
| 9773 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9774 | mApp, subId, "triggerRcsReconfiguration"); |
| 9775 | |
| 9776 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9777 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9778 | } |
| 9779 | if (!isImsAvailableOnDevice()) { |
| 9780 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9781 | "IMS not available on device."); |
| 9782 | } |
| 9783 | |
| 9784 | final long identity = Binder.clearCallingIdentity(); |
| 9785 | try { |
| 9786 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 9787 | } finally { |
| 9788 | Binder.restoreCallingIdentity(identity); |
| 9789 | } |
| 9790 | } |
| 9791 | |
| 9792 | /** |
| 9793 | * Provide the client configuration parameters of the RCS application. |
| 9794 | */ |
| 9795 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
| 9796 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9797 | mApp, subId, "setRcsClientConfiguration"); |
| 9798 | |
| 9799 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9800 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9801 | } |
| 9802 | if (!isImsAvailableOnDevice()) { |
| 9803 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9804 | "IMS not available on device."); |
| 9805 | } |
| 9806 | |
| 9807 | final long identity = Binder.clearCallingIdentity(); |
| 9808 | |
| 9809 | try { |
| 9810 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 9811 | if (configBinder == null) { |
| 9812 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
| 9813 | } else { |
| 9814 | configBinder.setRcsClientConfiguration(rcc); |
| 9815 | } |
| 9816 | } catch (RemoteException e) { |
| 9817 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
| 9818 | } finally { |
| 9819 | Binder.restoreCallingIdentity(identity); |
| 9820 | } |
| 9821 | } |
| 9822 | |
| 9823 | /** |
| 9824 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 9825 | */ |
| 9826 | @Override |
| 9827 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 9828 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9829 | "setDeviceSingleRegistrationEnabledOverride"); |
| 9830 | enforceModifyPermission(); |
| 9831 | |
| 9832 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9833 | : Boolean.parseBoolean(enabledStr); |
| 9834 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
| 9835 | } |
| 9836 | |
| 9837 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 9838 | * Sends a device to device communication message. Only usable via shell. |
| 9839 | * @param message message to send. |
| 9840 | * @param value message value. |
| 9841 | */ |
| 9842 | @Override |
| 9843 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 9844 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9845 | "setCarrierSingleRegistrationEnabledOverride"); |
| 9846 | enforceModifyPermission(); |
| 9847 | |
| 9848 | final long identity = Binder.clearCallingIdentity(); |
| 9849 | try { |
| 9850 | TelephonyConnectionService service = |
| 9851 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 9852 | if (service == null) { |
| 9853 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 9854 | return; |
| 9855 | } |
| 9856 | service.sendTestDeviceToDeviceMessage(message, value); |
| 9857 | } finally { |
| 9858 | Binder.restoreCallingIdentity(identity); |
| 9859 | } |
| 9860 | } |
| 9861 | |
| 9862 | |
| 9863 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9864 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 9865 | */ |
| 9866 | @Override |
| 9867 | public boolean getDeviceSingleRegistrationEnabled() { |
| 9868 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 9869 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 9870 | } |
| 9871 | |
| 9872 | /** |
| 9873 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9874 | */ |
| 9875 | @Override |
| 9876 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 9877 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9878 | "setCarrierSingleRegistrationEnabledOverride"); |
| 9879 | enforceModifyPermission(); |
| 9880 | |
| 9881 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9882 | : Boolean.parseBoolean(enabledStr); |
| 9883 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 9884 | subId, enabled); |
| 9885 | } |
| 9886 | |
| 9887 | /** |
| 9888 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9889 | */ |
| 9890 | @Override |
| 9891 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 9892 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 9893 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 9894 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 9895 | |
| 9896 | /** |
| 9897 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 9898 | * their mobile plan. |
| 9899 | */ |
| 9900 | @Override |
| 9901 | public String getMobileProvisioningUrl() { |
| 9902 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 9903 | final long identity = Binder.clearCallingIdentity(); |
| 9904 | try { |
| 9905 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 9906 | } finally { |
| 9907 | Binder.restoreCallingIdentity(identity); |
| 9908 | } |
| 9909 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 9910 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 9911 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 9912 | * Get the EAB contact from the EAB database. |
| 9913 | */ |
| 9914 | @Override |
| 9915 | public String getContactFromEab(String contact) { |
| 9916 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 9917 | enforceModifyPermission(); |
| 9918 | final long identity = Binder.clearCallingIdentity(); |
| 9919 | try { |
| 9920 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 9921 | } finally { |
| 9922 | Binder.restoreCallingIdentity(identity); |
| 9923 | } |
| 9924 | } |
| 9925 | |
| 9926 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 9927 | * Remove the EAB contacts from the EAB database. |
| 9928 | */ |
| 9929 | @Override |
| 9930 | public int removeContactFromEab(int subId, String contacts) { |
| 9931 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 9932 | enforceModifyPermission(); |
| 9933 | final long identity = Binder.clearCallingIdentity(); |
| 9934 | try { |
| 9935 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 9936 | } finally { |
| 9937 | Binder.restoreCallingIdentity(identity); |
| 9938 | } |
| 9939 | } |
| 9940 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 9941 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 9942 | public boolean getDeviceUceEnabled() { |
| 9943 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 9944 | final long identity = Binder.clearCallingIdentity(); |
| 9945 | try { |
| 9946 | return mApp.getDeviceUceEnabled(); |
| 9947 | } finally { |
| 9948 | Binder.restoreCallingIdentity(identity); |
| 9949 | } |
| 9950 | } |
| 9951 | |
| 9952 | @Override |
| 9953 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 9954 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 9955 | final long identity = Binder.clearCallingIdentity(); |
| 9956 | try { |
| 9957 | mApp.setDeviceUceEnabled(isEnabled); |
| 9958 | } finally { |
| 9959 | Binder.restoreCallingIdentity(identity); |
| 9960 | } |
| 9961 | } |
| 9962 | |
| 9963 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 9964 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 9965 | String callingPackage) { |
| 9966 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9967 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 9968 | |
| 9969 | final int callingUid = Binder.getCallingUid(); |
| 9970 | // Verify that tha callingPackage belongs to the calling UID |
| 9971 | mApp.getSystemService(AppOpsManager.class) |
| 9972 | .checkPackage(callingUid, callingPackage); |
| 9973 | |
| 9974 | validateSignalStrengthUpdateRequest(request, callingUid); |
| 9975 | |
| 9976 | final long identity = Binder.clearCallingIdentity(); |
| 9977 | try { |
| 9978 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 9979 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 9980 | |
| 9981 | if (result instanceof IllegalStateException) { |
| 9982 | throw (IllegalStateException) result; |
| 9983 | } |
| 9984 | } finally { |
| 9985 | Binder.restoreCallingIdentity(identity); |
| 9986 | } |
| 9987 | } |
| 9988 | |
| 9989 | @Override |
| 9990 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 9991 | String callingPackage) { |
| 9992 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9993 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 9994 | |
| 9995 | final int callingUid = Binder.getCallingUid(); |
| 9996 | // Verify that tha callingPackage belongs to the calling UID |
| 9997 | mApp.getSystemService(AppOpsManager.class) |
| 9998 | .checkPackage(callingUid, callingPackage); |
| 9999 | |
| 10000 | final long identity = Binder.clearCallingIdentity(); |
| 10001 | try { |
| 10002 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10003 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10004 | |
| 10005 | if (result instanceof IllegalStateException) { |
| 10006 | throw (IllegalStateException) result; |
| 10007 | } |
| 10008 | } finally { |
| 10009 | Binder.restoreCallingIdentity(identity); |
| 10010 | } |
| 10011 | } |
| 10012 | |
| 10013 | private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request, |
| 10014 | int callingUid) { |
| 10015 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 10016 | // phone/system process do not have further restriction on request |
| 10017 | return; |
| 10018 | } |
| 10019 | |
| 10020 | // Applications has restrictions on how to use the request: |
| 10021 | // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle |
| 10022 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
| 10023 | // This is not system caller which has been checked above |
| 10024 | throw new IllegalArgumentException( |
| 10025 | "Only system can set isSystemThresholdReportingRequestedWhileIdle"); |
| 10026 | } |
| 10027 | |
| 10028 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 10029 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 10030 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 10031 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 10032 | || info.isEnabled()) { |
| 10033 | throw new IllegalArgumentException( |
| 10034 | "Only system can set hide fields in SignalThresholdInfo"); |
| 10035 | } |
| 10036 | |
| 10037 | // Thresholds length for each RAN need in range. This has been validated in |
| 10038 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 10039 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 10040 | final int[] thresholds = info.getThresholds(); |
| 10041 | Objects.requireNonNull(thresholds); |
| 10042 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 10043 | || thresholds.length |
| 10044 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 10045 | throw new IllegalArgumentException( |
| 10046 | "thresholds length is out of range: " + thresholds.length); |
| 10047 | } |
| 10048 | } |
| 10049 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10050 | |
| 10051 | /** |
| 10052 | * Gets the current phone capability. |
| 10053 | * |
| 10054 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 10055 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 10056 | * It's used to evaluate possible phone config change, for example from single |
| 10057 | * SIM device to multi-SIM device. |
| 10058 | */ |
| 10059 | @Override |
| 10060 | public PhoneCapability getPhoneCapability() { |
| 10061 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 10062 | final long identity = Binder.clearCallingIdentity(); |
| 10063 | try { |
| 10064 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 10065 | } finally { |
| 10066 | Binder.restoreCallingIdentity(identity); |
| 10067 | } |
| 10068 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 10069 | } |