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 | |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 24 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 25 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 26 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 27 | import android.annotation.Nullable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 28 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 29 | import android.app.PendingIntent; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 30 | import android.app.role.RoleManager; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 31 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 32 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 33 | import android.content.Context; |
| 34 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 35 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 36 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 37 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 38 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 39 | import android.net.Uri; |
| 40 | import android.os.AsyncResult; |
| 41 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 42 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 43 | import android.os.Bundle; |
| 44 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 45 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 46 | import android.os.Looper; |
| 47 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 48 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 49 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 50 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 51 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 52 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 53 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 54 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 55 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 56 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 57 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 58 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 59 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 60 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 61 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 62 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 63 | import android.provider.Telephony; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 64 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 65 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 66 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 67 | import android.telecom.TelecomManager; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 68 | import android.telephony.Annotation.ApnType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 69 | import android.telephony.Annotation.ThermalMitigationResult; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 70 | import android.telephony.CallForwardingInfo; |
Sooraj Sasindran | 4deb887 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 71 | import android.telephony.CarrierBandwidth; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 72 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 73 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 74 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 75 | import android.telephony.CellIdentityCdma; |
| 76 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 77 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 78 | import android.telephony.CellInfoGsm; |
| 79 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 80 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 81 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 82 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 83 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 84 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 85 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 86 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 87 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 88 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 89 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 90 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 91 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 92 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 93 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 94 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 95 | import android.telephony.SignalStrengthUpdateRequest; |
| 96 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 97 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 98 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 99 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 100 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 101 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 102 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 103 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 104 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 105 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 106 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 107 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 108 | import android.telephony.data.ApnSetting; |
| 109 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 110 | import android.telephony.gba.GbaAuthRequest; |
| 111 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 112 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 113 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 114 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 115 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 116 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 117 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 118 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 119 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 120 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 121 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 122 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 123 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 124 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 125 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 126 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 127 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 128 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 129 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 130 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 131 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 132 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 133 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 134 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 135 | import com.android.ims.rcs.uce.eab.EabUtil; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 136 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 140 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 143 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.GbaManager; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 146 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 147 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 150 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 158 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.RIL; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 167 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 168 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 170 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 172 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 174 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 175 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 178 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 179 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 180 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 181 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 182 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 183 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 184 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 185 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 186 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 187 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 188 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 189 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 190 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 191 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 192 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 193 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 194 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 195 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 196 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 197 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 198 | import com.android.services.telephony.TelecomAccountRegistry; |
| 199 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 200 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 201 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 202 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 203 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 204 | import java.io.IOException; |
| 205 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 206 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 207 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 208 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 209 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 210 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 211 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 212 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 213 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 214 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 215 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 216 | import java.util.Set; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 217 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 218 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 219 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 220 | |
| 221 | /** |
| 222 | * Implementation of the ITelephony interface. |
| 223 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 224 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 225 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 226 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 227 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 228 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 229 | |
| 230 | // Message codes used with mMainThreadHandler |
| 231 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 232 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 233 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 234 | private static final int CMD_OPEN_CHANNEL = 9; |
| 235 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 236 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 237 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 238 | private static final int CMD_NV_READ_ITEM = 13; |
| 239 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 240 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 241 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 242 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 243 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 244 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 245 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 246 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 247 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 248 | private static final int CMD_SEND_ENVELOPE = 25; |
| 249 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 250 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 251 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 252 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 253 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 254 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 255 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 256 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 257 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 258 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 259 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 260 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 261 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 262 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 263 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 264 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 265 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 266 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 267 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 268 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 269 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 270 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 271 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 272 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 273 | private static final int CMD_SWITCH_SLOTS = 50; |
| 274 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 275 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 276 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 277 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 278 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 279 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 280 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 281 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 282 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 283 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 284 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 285 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 286 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 287 | private static final int CMD_MODEM_REBOOT = 64; |
| 288 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 289 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 290 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 291 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 292 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 293 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 294 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 295 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 296 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 297 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 298 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 299 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 300 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 301 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 302 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 303 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 304 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 305 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 306 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 307 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 308 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 309 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 310 | private static final int CMD_GET_CALL_WAITING = 87; |
| 311 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 312 | private static final int CMD_SET_CALL_WAITING = 89; |
| 313 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 314 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 315 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 316 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 317 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 318 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 319 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 320 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 321 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 322 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 323 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 324 | private static final int CMD_SET_SIM_POWER = 101; |
| 325 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 326 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 327 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 328 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 329 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 330 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 331 | private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 332 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 333 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 334 | // Parameters of select command. |
| 335 | private static final int SELECT_COMMAND = 0xA4; |
| 336 | private static final int SELECT_P1 = 0x04; |
| 337 | private static final int SELECT_P2 = 0; |
| 338 | private static final int SELECT_P3 = 0x10; |
| 339 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 340 | /** The singleton instance. */ |
| 341 | private static PhoneInterfaceManager sInstance; |
| 342 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 343 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 344 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 345 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 346 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 347 | private AppOpsManager mAppOps; |
| 348 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 349 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 350 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 351 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 352 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 353 | /** User Activity */ |
| 354 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 355 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 356 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 357 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 358 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 359 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 360 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 361 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 362 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 363 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 364 | // String to store multi SIM allowed |
| 365 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 366 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 367 | // The AID of ISD-R. |
| 368 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 369 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 370 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 371 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 372 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 373 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 374 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 375 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
| 376 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 377 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 378 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 379 | */ |
| 380 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 381 | "reset_network_erase_modem_config_enabled"; |
| 382 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 383 | private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds |
| 384 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 385 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 386 | * A request object to use for transmitting data to an ICC. |
| 387 | */ |
| 388 | private static final class IccAPDUArgument { |
| 389 | public int channel, cla, command, p1, p2, p3; |
| 390 | public String data; |
| 391 | |
| 392 | public IccAPDUArgument(int channel, int cla, int command, |
| 393 | int p1, int p2, int p3, String data) { |
| 394 | this.channel = channel; |
| 395 | this.cla = cla; |
| 396 | this.command = command; |
| 397 | this.p1 = p1; |
| 398 | this.p2 = p2; |
| 399 | this.p3 = p3; |
| 400 | this.data = data; |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 405 | * A request object to use for transmitting data to an ICC. |
| 406 | */ |
| 407 | private static final class ManualNetworkSelectionArgument { |
| 408 | public OperatorInfo operatorInfo; |
| 409 | public boolean persistSelection; |
| 410 | |
| 411 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 412 | this.operatorInfo = operatorInfo; |
| 413 | this.persistSelection = persistSelection; |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 418 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 419 | * request after sending. The main thread will notify the request when it is complete. |
| 420 | */ |
| 421 | private static final class MainThreadRequest { |
| 422 | /** The argument to use for the request */ |
| 423 | public Object argument; |
| 424 | /** The result of the request that is run on the main thread */ |
| 425 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 426 | // The subscriber id that this request applies to. Defaults to |
| 427 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 428 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 429 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 430 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 431 | public Phone phone; |
| 432 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 433 | public WorkSource workSource; |
| 434 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 435 | public MainThreadRequest(Object argument) { |
| 436 | this.argument = argument; |
| 437 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 438 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 439 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 440 | this.argument = argument; |
| 441 | if (phone != null) { |
| 442 | this.phone = phone; |
| 443 | } |
| 444 | this.workSource = workSource; |
| 445 | } |
| 446 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 447 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 448 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 449 | if (subId != null) { |
| 450 | this.subId = subId; |
| 451 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 452 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 453 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 456 | private static final class IncomingThirdPartyCallArgs { |
| 457 | public final ComponentName component; |
| 458 | public final String callId; |
| 459 | public final String callerDisplayName; |
| 460 | |
| 461 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 462 | String callerDisplayName) { |
| 463 | this.component = component; |
| 464 | this.callId = callId; |
| 465 | this.callerDisplayName = callerDisplayName; |
| 466 | } |
| 467 | } |
| 468 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 469 | /** |
| 470 | * A handler that processes messages on the main thread in the phone process. Since many |
| 471 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 472 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 473 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 474 | * on, which will be notified when the operation completes and will contain the result of the |
| 475 | * request. |
| 476 | * |
| 477 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 478 | * note that request.result must be set to something non-null for the calling thread to |
| 479 | * unblock. |
| 480 | */ |
| 481 | private final class MainThreadHandler extends Handler { |
| 482 | @Override |
| 483 | public void handleMessage(Message msg) { |
| 484 | MainThreadRequest request; |
| 485 | Message onCompleted; |
| 486 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 487 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 488 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 489 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 490 | |
| 491 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 492 | case CMD_HANDLE_USSD_REQUEST: { |
| 493 | request = (MainThreadRequest) msg.obj; |
| 494 | final Phone phone = getPhoneFromRequest(request); |
| 495 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 496 | String ussdRequest = ussdObject.first; |
| 497 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 498 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 499 | if (!isUssdApiAllowed(request.subId)) { |
| 500 | // Carrier does not support use of this API, return failure. |
| 501 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 502 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 503 | Bundle returnData = new Bundle(); |
| 504 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 505 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 506 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 507 | request.result = true; |
| 508 | notifyRequester(request); |
| 509 | return; |
| 510 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 511 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 512 | try { |
| 513 | request.result = phone != null |
| 514 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 515 | } catch (CallStateException cse) { |
| 516 | request.result = false; |
| 517 | } |
| 518 | // Wake up the requesting thread |
| 519 | notifyRequester(request); |
| 520 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 521 | } |
| 522 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 523 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 524 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 525 | final Phone phone = getPhoneFromRequest(request); |
| 526 | request.result = phone != null ? |
| 527 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 528 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 529 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 530 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 531 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 532 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 533 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 534 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 535 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 536 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 537 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 538 | if (uiccCard == null) { |
| 539 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 540 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 541 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 542 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 543 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 544 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 545 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 546 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 547 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 548 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 549 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 550 | break; |
| 551 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 552 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 553 | ar = (AsyncResult) msg.obj; |
| 554 | request = (MainThreadRequest) ar.userObj; |
| 555 | if (ar.exception == null && ar.result != null) { |
| 556 | request.result = ar.result; |
| 557 | } else { |
| 558 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 559 | if (ar.result == null) { |
| 560 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 561 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 562 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 563 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 564 | } else { |
| 565 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 566 | } |
| 567 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 568 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 569 | break; |
| 570 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 571 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 572 | request = (MainThreadRequest) msg.obj; |
| 573 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 574 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 575 | if (uiccCard == null) { |
| 576 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 577 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 578 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 579 | } else { |
| 580 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 581 | request); |
| 582 | uiccCard.iccTransmitApduBasicChannel( |
| 583 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 584 | iccArgument.p3, iccArgument.data, onCompleted); |
| 585 | } |
| 586 | break; |
| 587 | |
| 588 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 589 | ar = (AsyncResult) msg.obj; |
| 590 | request = (MainThreadRequest) ar.userObj; |
| 591 | if (ar.exception == null && ar.result != null) { |
| 592 | request.result = ar.result; |
| 593 | } else { |
| 594 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 595 | if (ar.result == null) { |
| 596 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 597 | } else if (ar.exception instanceof CommandException) { |
| 598 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 599 | ar.exception); |
| 600 | } else { |
| 601 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 602 | } |
| 603 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 604 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 605 | break; |
| 606 | |
| 607 | case CMD_EXCHANGE_SIM_IO: |
| 608 | request = (MainThreadRequest) msg.obj; |
| 609 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 610 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 611 | if (uiccCard == null) { |
| 612 | loge("iccExchangeSimIO: No UICC"); |
| 613 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 614 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 615 | } else { |
| 616 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 617 | request); |
| 618 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 619 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 620 | iccArgument.data, onCompleted); |
| 621 | } |
| 622 | break; |
| 623 | |
| 624 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 625 | ar = (AsyncResult) msg.obj; |
| 626 | request = (MainThreadRequest) ar.userObj; |
| 627 | if (ar.exception == null && ar.result != null) { |
| 628 | request.result = ar.result; |
| 629 | } else { |
| 630 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 631 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 632 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 633 | break; |
| 634 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 635 | case CMD_SEND_ENVELOPE: |
| 636 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 637 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 638 | if (uiccCard == null) { |
| 639 | loge("sendEnvelopeWithStatus: No UICC"); |
| 640 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 641 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 642 | } else { |
| 643 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 644 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 645 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 646 | break; |
| 647 | |
| 648 | case EVENT_SEND_ENVELOPE_DONE: |
| 649 | ar = (AsyncResult) msg.obj; |
| 650 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 651 | if (ar.exception == null && ar.result != null) { |
| 652 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 653 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 654 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 655 | if (ar.result == null) { |
| 656 | loge("sendEnvelopeWithStatus: Empty response"); |
| 657 | } else if (ar.exception instanceof CommandException) { |
| 658 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 659 | ar.exception); |
| 660 | } else { |
| 661 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 662 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 663 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 664 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 665 | break; |
| 666 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 667 | case CMD_OPEN_CHANNEL: |
| 668 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 669 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 670 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 671 | if (uiccCard == null) { |
| 672 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 673 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 674 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 675 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 676 | } else { |
| 677 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 678 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 679 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 680 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 681 | break; |
| 682 | |
| 683 | case EVENT_OPEN_CHANNEL_DONE: |
| 684 | ar = (AsyncResult) msg.obj; |
| 685 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 686 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 687 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 688 | int[] result = (int[]) ar.result; |
| 689 | int channelId = result[0]; |
| 690 | byte[] selectResponse = null; |
| 691 | if (result.length > 1) { |
| 692 | selectResponse = new byte[result.length - 1]; |
| 693 | for (int i = 1; i < result.length; ++i) { |
| 694 | selectResponse[i - 1] = (byte) result[i]; |
| 695 | } |
| 696 | } |
| 697 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 698 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 699 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 700 | if (ar.result == null) { |
| 701 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 702 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 703 | if (ar.exception != null) { |
| 704 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 705 | } |
| 706 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 707 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 708 | if (ar.exception instanceof CommandException) { |
| 709 | CommandException.Error error = |
| 710 | ((CommandException) (ar.exception)).getCommandError(); |
| 711 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 712 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 713 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 714 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 715 | } |
| 716 | } |
| 717 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 718 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 719 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 720 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 721 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 722 | break; |
| 723 | |
| 724 | case CMD_CLOSE_CHANNEL: |
| 725 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 726 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 727 | if (uiccCard == null) { |
| 728 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 729 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 730 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 731 | } else { |
| 732 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 733 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 734 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 735 | break; |
| 736 | |
| 737 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 738 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 739 | break; |
| 740 | |
| 741 | case CMD_NV_READ_ITEM: |
| 742 | request = (MainThreadRequest) msg.obj; |
| 743 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 744 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 745 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 746 | break; |
| 747 | |
| 748 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 749 | ar = (AsyncResult) msg.obj; |
| 750 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 751 | if (ar.exception == null && ar.result != null) { |
| 752 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 753 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 754 | request.result = ""; |
| 755 | if (ar.result == null) { |
| 756 | loge("nvReadItem: Empty response"); |
| 757 | } else if (ar.exception instanceof CommandException) { |
| 758 | loge("nvReadItem: CommandException: " + |
| 759 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 760 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 761 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 762 | } |
| 763 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 764 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 765 | break; |
| 766 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 767 | case CMD_NV_WRITE_ITEM: |
| 768 | request = (MainThreadRequest) msg.obj; |
| 769 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 770 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 771 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 772 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 773 | break; |
| 774 | |
| 775 | case EVENT_NV_WRITE_ITEM_DONE: |
| 776 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 777 | break; |
| 778 | |
| 779 | case CMD_NV_WRITE_CDMA_PRL: |
| 780 | request = (MainThreadRequest) msg.obj; |
| 781 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 782 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 783 | break; |
| 784 | |
| 785 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 786 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 787 | break; |
| 788 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 789 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 790 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 791 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 792 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 793 | break; |
| 794 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 795 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 796 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 797 | break; |
| 798 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 799 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 800 | request = (MainThreadRequest) msg.obj; |
| 801 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 802 | request); |
| 803 | Phone phone = getPhoneFromRequest(request); |
| 804 | if (phone != null) { |
| 805 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 806 | } else { |
| 807 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 808 | request.result = false; |
| 809 | notifyRequester(request); |
| 810 | } |
| 811 | break; |
| 812 | } |
| 813 | |
| 814 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 815 | ar = (AsyncResult) msg.obj; |
| 816 | request = (MainThreadRequest) ar.userObj; |
| 817 | if (ar.exception == null && ar.result != null) { |
| 818 | request.result = ar.result; |
| 819 | } else { |
| 820 | // request.result must be set to something non-null |
| 821 | // for the calling thread to unblock |
| 822 | if (request.result != null) { |
| 823 | request.result = ar.result; |
| 824 | } else { |
| 825 | request.result = false; |
| 826 | } |
| 827 | if (ar.result == null) { |
| 828 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 829 | } else if (ar.exception instanceof CommandException) { |
| 830 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 831 | + ar.exception); |
| 832 | } else { |
| 833 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 834 | } |
| 835 | } |
| 836 | notifyRequester(request); |
| 837 | break; |
| 838 | |
| 839 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 840 | request = (MainThreadRequest) msg.obj; |
| 841 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 842 | Phone phone = getPhoneFromRequest(request); |
| 843 | if (phone != null) { |
| 844 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 845 | request.workSource); |
| 846 | } else { |
| 847 | loge("enableNrDualConnectivity: No phone object"); |
| 848 | request.result = |
| 849 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 850 | notifyRequester(request); |
| 851 | } |
| 852 | break; |
| 853 | } |
| 854 | |
| 855 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 856 | ar = (AsyncResult) msg.obj; |
| 857 | request = (MainThreadRequest) ar.userObj; |
| 858 | if (ar.exception == null) { |
| 859 | request.result = |
| 860 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 861 | } else { |
| 862 | request.result = |
| 863 | TelephonyManager |
| 864 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 865 | if (ar.exception instanceof CommandException) { |
| 866 | CommandException.Error error = |
| 867 | ((CommandException) (ar.exception)).getCommandError(); |
| 868 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 869 | request.result = |
| 870 | TelephonyManager |
| 871 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 872 | } |
| 873 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 874 | + ar.exception); |
| 875 | } else { |
| 876 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 877 | } |
| 878 | } |
| 879 | notifyRequester(request); |
| 880 | break; |
| 881 | } |
| 882 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 883 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 884 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 885 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 886 | request); |
| 887 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 888 | break; |
| 889 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 890 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 891 | ar = (AsyncResult) msg.obj; |
| 892 | request = (MainThreadRequest) ar.userObj; |
| 893 | if (ar.exception == null && ar.result != null) { |
| 894 | request.result = ar.result; // Integer |
| 895 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 896 | // request.result must be set to something non-null |
| 897 | // for the calling thread to unblock |
| 898 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 899 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 900 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 901 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 902 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 903 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 904 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 905 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 906 | } |
| 907 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 908 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 909 | break; |
| 910 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 911 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 912 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 913 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 914 | request); |
| 915 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 916 | (Pair<Integer, Long>) request.argument; |
| 917 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 918 | reasonWithNetworkTypes.first, |
| 919 | reasonWithNetworkTypes.second, |
| 920 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 921 | break; |
| 922 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 923 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 924 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 925 | break; |
| 926 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 927 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 928 | request = (MainThreadRequest)msg.obj; |
| 929 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 930 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 931 | break; |
| 932 | |
| 933 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 934 | ar = (AsyncResult)msg.obj; |
| 935 | request = (MainThreadRequest)ar.userObj; |
| 936 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 937 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 938 | break; |
| 939 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 940 | case CMD_SET_VOICEMAIL_NUMBER: |
| 941 | request = (MainThreadRequest) msg.obj; |
| 942 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 943 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 944 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 945 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 946 | break; |
| 947 | |
| 948 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 949 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 950 | break; |
| 951 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 952 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 953 | request = (MainThreadRequest) msg.obj; |
| 954 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 955 | request); |
| 956 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 957 | break; |
| 958 | |
| 959 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 960 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 961 | break; |
| 962 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 963 | case CMD_PERFORM_NETWORK_SCAN: |
| 964 | request = (MainThreadRequest) msg.obj; |
| 965 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 966 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 967 | break; |
| 968 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 969 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 970 | request = (MainThreadRequest) msg.obj; |
| 971 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 972 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 973 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 974 | request.argument; |
| 975 | int callForwardingReason = args.first; |
| 976 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 977 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 978 | } |
| 979 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 980 | ar = (AsyncResult) msg.obj; |
| 981 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 982 | TelephonyManager.CallForwardingInfoCallback callback = |
| 983 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 984 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 985 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 986 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 987 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 988 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 989 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 990 | // any service for voice call. |
| 991 | if ((callForwardInfo.serviceClass |
| 992 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 993 | callForwardingInfo = new CallForwardingInfo(true, |
| 994 | callForwardInfo.reason, |
| 995 | callForwardInfo.number, |
| 996 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 997 | break; |
| 998 | } |
| 999 | } |
| 1000 | // Didn't find a call forward info for voice call. |
| 1001 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1002 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1003 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1004 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1005 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1006 | } else { |
| 1007 | if (ar.result == null) { |
| 1008 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1009 | } |
| 1010 | if (ar.exception != null) { |
| 1011 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1012 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1013 | int errorCode = TelephonyManager |
| 1014 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1015 | if (ar.exception instanceof CommandException) { |
| 1016 | CommandException.Error error = |
| 1017 | ((CommandException) (ar.exception)).getCommandError(); |
| 1018 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1019 | errorCode = TelephonyManager |
| 1020 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1021 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1022 | errorCode = TelephonyManager |
| 1023 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1024 | } |
| 1025 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1026 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1027 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1028 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1029 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1030 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1031 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1032 | request = (MainThreadRequest) msg.obj; |
| 1033 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1034 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1035 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1036 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1037 | request.argument).first; |
| 1038 | request.phone.setCallForwardingOption( |
| 1039 | callForwardingInfoToSet.isEnabled() |
| 1040 | ? CommandsInterface.CF_ACTION_ENABLE |
| 1041 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1042 | callForwardingInfoToSet.getReason(), |
| 1043 | callForwardingInfoToSet.getNumber(), |
| 1044 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1045 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1046 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1047 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1048 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1049 | ar = (AsyncResult) msg.obj; |
| 1050 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1051 | Consumer<Integer> callback = |
| 1052 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1053 | request.argument).second; |
| 1054 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1055 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1056 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1057 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1058 | if (ar.exception instanceof CommandException) { |
| 1059 | CommandException.Error error = |
| 1060 | ((CommandException) (ar.exception)).getCommandError(); |
| 1061 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1062 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1063 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1064 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1065 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1066 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1067 | } |
| 1068 | } |
| 1069 | callback.accept(errorCode); |
| 1070 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1071 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1072 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1073 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1074 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1075 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1076 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1077 | request = (MainThreadRequest) msg.obj; |
| 1078 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1079 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1080 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1081 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1082 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1083 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1084 | ar = (AsyncResult) msg.obj; |
| 1085 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1086 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1087 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1088 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1089 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1090 | // Service Class is a bit mask per 3gpp 27.007. |
| 1091 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1092 | if (callForwardResults.length > 1 |
| 1093 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1094 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1095 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1096 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1097 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1098 | } else { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1099 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1100 | } |
| 1101 | } else { |
| 1102 | if (ar.result == null) { |
| 1103 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1104 | } |
| 1105 | if (ar.exception != null) { |
| 1106 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1107 | } |
| 1108 | if (ar.exception instanceof CommandException) { |
| 1109 | CommandException.Error error = |
| 1110 | ((CommandException) (ar.exception)).getCommandError(); |
| 1111 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1112 | callForwardingStatus = |
| 1113 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1114 | } |
| 1115 | } |
| 1116 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1117 | callback.accept(callForwardingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1118 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1119 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1120 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1121 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1122 | request = (MainThreadRequest) msg.obj; |
| 1123 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1124 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1125 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1126 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1127 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1128 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1129 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1130 | ar = (AsyncResult) msg.obj; |
| 1131 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1132 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1133 | Consumer<Integer> callback = |
| 1134 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1135 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1136 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1137 | if (ar.exception instanceof CommandException) { |
| 1138 | CommandException.Error error = |
| 1139 | ((CommandException) (ar.exception)).getCommandError(); |
| 1140 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1141 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1142 | } else { |
| 1143 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1144 | } |
| 1145 | } else { |
| 1146 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1147 | } |
| 1148 | } else { |
| 1149 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1150 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1151 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1152 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1153 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1154 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1155 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1156 | ar = (AsyncResult) msg.obj; |
| 1157 | request = (MainThreadRequest) ar.userObj; |
| 1158 | CellNetworkScanResult cellScanResult; |
| 1159 | if (ar.exception == null && ar.result != null) { |
| 1160 | cellScanResult = new CellNetworkScanResult( |
| 1161 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1162 | (List<OperatorInfo>) ar.result); |
| 1163 | } else { |
| 1164 | if (ar.result == null) { |
| 1165 | loge("getCellNetworkScanResults: Empty response"); |
| 1166 | } |
| 1167 | if (ar.exception != null) { |
| 1168 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1169 | } |
| 1170 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1171 | if (ar.exception instanceof CommandException) { |
| 1172 | CommandException.Error error = |
| 1173 | ((CommandException) (ar.exception)).getCommandError(); |
| 1174 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1175 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1176 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1177 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1178 | } |
| 1179 | } |
| 1180 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1181 | } |
| 1182 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1183 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1184 | break; |
| 1185 | |
| 1186 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1187 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1188 | ManualNetworkSelectionArgument selArg = |
| 1189 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1190 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1191 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1192 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1193 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1194 | break; |
| 1195 | |
| 1196 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1197 | ar = (AsyncResult) msg.obj; |
| 1198 | request = (MainThreadRequest) ar.userObj; |
| 1199 | if (ar.exception == null) { |
| 1200 | request.result = true; |
| 1201 | } else { |
| 1202 | request.result = false; |
| 1203 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1204 | } |
| 1205 | notifyRequester(request); |
| 1206 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1207 | break; |
| 1208 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1209 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1210 | request = (MainThreadRequest) msg.obj; |
| 1211 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1212 | if (defaultPhone != null) { |
| 1213 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1214 | } else { |
| 1215 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1216 | Bundle bundle = new Bundle(); |
| 1217 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1218 | new ModemActivityInfo(0, 0, 0, |
| 1219 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1220 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1221 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1222 | break; |
| 1223 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1224 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1225 | ar = (AsyncResult) msg.obj; |
| 1226 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1227 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1228 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1229 | ModemActivityInfo ret = null; |
| 1230 | int error = 0; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1231 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1232 | // Update the last modem activity info and the result of the request. |
| 1233 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1234 | if (isModemActivityInfoValid(info)) { |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1235 | int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()]; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1236 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1237 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1238 | .getTransmitTimeMillis(); |
| 1239 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1240 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1241 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1242 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1243 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1244 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1245 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1246 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1247 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1248 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1249 | info.getReceiveTimeMillis() |
| 1250 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1251 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1252 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(), |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1253 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1254 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1255 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1256 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1257 | } else { |
| 1258 | if (ar.result == null) { |
| 1259 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1260 | error = TelephonyManager.ModemActivityInfoException |
| 1261 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1262 | } else if (ar.exception instanceof CommandException) { |
| 1263 | loge("queryModemActivityInfo: CommandException: " + |
| 1264 | ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1265 | error = TelephonyManager.ModemActivityInfoException |
| 1266 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1267 | } else { |
| 1268 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1269 | error = TelephonyManager.ModemActivityInfoException |
| 1270 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1271 | } |
| 1272 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1273 | Bundle bundle = new Bundle(); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1274 | if (ret != null) { |
| 1275 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1276 | } else { |
| 1277 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1278 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1279 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1280 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1281 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1282 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1283 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1284 | case CMD_SET_ALLOWED_CARRIERS: |
| 1285 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1286 | CarrierRestrictionRules argument = |
| 1287 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1288 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1289 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1290 | break; |
| 1291 | |
| 1292 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1293 | ar = (AsyncResult) msg.obj; |
| 1294 | request = (MainThreadRequest) ar.userObj; |
| 1295 | if (ar.exception == null && ar.result != null) { |
| 1296 | request.result = ar.result; |
| 1297 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1298 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1299 | if (ar.exception instanceof CommandException) { |
| 1300 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1301 | CommandException.Error error = |
| 1302 | ((CommandException) (ar.exception)).getCommandError(); |
| 1303 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1304 | request.result = |
| 1305 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1306 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1307 | } else { |
| 1308 | loge("setAllowedCarriers: Unknown exception"); |
| 1309 | } |
| 1310 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1311 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1312 | break; |
| 1313 | |
| 1314 | case CMD_GET_ALLOWED_CARRIERS: |
| 1315 | request = (MainThreadRequest) msg.obj; |
| 1316 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1317 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1318 | break; |
| 1319 | |
| 1320 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1321 | ar = (AsyncResult) msg.obj; |
| 1322 | request = (MainThreadRequest) ar.userObj; |
| 1323 | if (ar.exception == null && ar.result != null) { |
| 1324 | request.result = ar.result; |
| 1325 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1326 | request.result = new IllegalStateException( |
| 1327 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1328 | if (ar.result == null) { |
| 1329 | loge("getAllowedCarriers: Empty response"); |
| 1330 | } else if (ar.exception instanceof CommandException) { |
| 1331 | loge("getAllowedCarriers: CommandException: " + |
| 1332 | ar.exception); |
| 1333 | } else { |
| 1334 | loge("getAllowedCarriers: Unknown exception"); |
| 1335 | } |
| 1336 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1337 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1338 | break; |
| 1339 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1340 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1341 | ar = (AsyncResult) msg.obj; |
| 1342 | request = (MainThreadRequest) ar.userObj; |
| 1343 | if (ar.exception == null && ar.result != null) { |
| 1344 | request.result = ar.result; |
| 1345 | } else { |
| 1346 | request.result = new IllegalArgumentException( |
| 1347 | "Failed to retrieve Forbidden Plmns"); |
| 1348 | if (ar.result == null) { |
| 1349 | loge("getForbiddenPlmns: Empty response"); |
| 1350 | } else { |
| 1351 | loge("getForbiddenPlmns: Unknown exception"); |
| 1352 | } |
| 1353 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1354 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1355 | break; |
| 1356 | |
| 1357 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1358 | request = (MainThreadRequest) msg.obj; |
| 1359 | uiccCard = getUiccCardFromRequest(request); |
| 1360 | if (uiccCard == null) { |
| 1361 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1362 | request.result = new IllegalArgumentException( |
| 1363 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1364 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1365 | break; |
| 1366 | } |
| 1367 | Integer appType = (Integer) request.argument; |
| 1368 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1369 | if (uiccApp == null) { |
| 1370 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1371 | + appType); |
| 1372 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1373 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1374 | break; |
| 1375 | } else { |
| 1376 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1377 | + " specified type -- " + appType); |
| 1378 | } |
| 1379 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1380 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1381 | onCompleted); |
| 1382 | break; |
| 1383 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1384 | case CMD_SWITCH_SLOTS: |
| 1385 | request = (MainThreadRequest) msg.obj; |
| 1386 | int[] physicalSlots = (int[]) request.argument; |
| 1387 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1388 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1389 | break; |
| 1390 | |
| 1391 | case EVENT_SWITCH_SLOTS_DONE: |
| 1392 | ar = (AsyncResult) msg.obj; |
| 1393 | request = (MainThreadRequest) ar.userObj; |
| 1394 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1395 | notifyRequester(request); |
| 1396 | break; |
| 1397 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1398 | request = (MainThreadRequest) msg.obj; |
| 1399 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1400 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1401 | break; |
| 1402 | |
| 1403 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1404 | ar = (AsyncResult) msg.obj; |
| 1405 | request = (MainThreadRequest) ar.userObj; |
| 1406 | if (ar.exception != null) { |
| 1407 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1408 | } else { |
| 1409 | int mode = ((int[]) ar.result)[0]; |
| 1410 | if (mode == 0) { |
| 1411 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1412 | } else { |
| 1413 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1414 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1415 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1416 | notifyRequester(request); |
| 1417 | break; |
| 1418 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1419 | request = (MainThreadRequest) msg.obj; |
| 1420 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1421 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1422 | break; |
| 1423 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1424 | ar = (AsyncResult) msg.obj; |
| 1425 | request = (MainThreadRequest) ar.userObj; |
| 1426 | if (ar.exception != null) { |
| 1427 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1428 | } else { |
| 1429 | request.result = ((int[]) ar.result)[0]; |
| 1430 | } |
| 1431 | notifyRequester(request); |
| 1432 | break; |
| 1433 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1434 | request = (MainThreadRequest) msg.obj; |
| 1435 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1436 | int mode = (int) request.argument; |
| 1437 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1438 | break; |
| 1439 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1440 | ar = (AsyncResult) msg.obj; |
| 1441 | request = (MainThreadRequest) ar.userObj; |
| 1442 | request.result = ar.exception == null; |
| 1443 | notifyRequester(request); |
| 1444 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1445 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1446 | request = (MainThreadRequest) msg.obj; |
| 1447 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1448 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1449 | break; |
| 1450 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1451 | ar = (AsyncResult) msg.obj; |
| 1452 | request = (MainThreadRequest) ar.userObj; |
| 1453 | if (ar.exception != null) { |
| 1454 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1455 | } else { |
| 1456 | request.result = ((int[]) ar.result)[0]; |
| 1457 | } |
| 1458 | notifyRequester(request); |
| 1459 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1460 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1461 | request = (MainThreadRequest) msg.obj; |
| 1462 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1463 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1464 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1465 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1466 | break; |
| 1467 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1468 | ar = (AsyncResult) msg.obj; |
| 1469 | request = (MainThreadRequest) ar.userObj; |
| 1470 | request.result = ar.exception == null; |
| 1471 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1472 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1473 | case CMD_GET_ALL_CELL_INFO: |
| 1474 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1475 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1476 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1477 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1478 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1479 | ar = (AsyncResult) msg.obj; |
| 1480 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1481 | // If a timeout occurs, the response will be null |
| 1482 | request.result = (ar.exception == null && ar.result != null) |
| 1483 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1484 | synchronized (request) { |
| 1485 | request.notifyAll(); |
| 1486 | } |
| 1487 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1488 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1489 | request = (MainThreadRequest) msg.obj; |
| 1490 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1491 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1492 | break; |
| 1493 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1494 | ar = (AsyncResult) msg.obj; |
| 1495 | request = (MainThreadRequest) ar.userObj; |
| 1496 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1497 | try { |
| 1498 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1499 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1500 | cb.onError( |
| 1501 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1502 | ar.exception.getClass().getName(), |
| 1503 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1504 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1505 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1506 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1507 | } else { |
| 1508 | // use the result as returned |
| 1509 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1510 | } |
| 1511 | } catch (RemoteException re) { |
| 1512 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1513 | } |
| 1514 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1515 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1516 | request = (MainThreadRequest) msg.obj; |
| 1517 | WorkSource ws = (WorkSource) request.argument; |
| 1518 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1519 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1520 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1521 | } |
| 1522 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1523 | ar = (AsyncResult) msg.obj; |
| 1524 | request = (MainThreadRequest) ar.userObj; |
| 1525 | if (ar.exception == null) { |
| 1526 | request.result = ar.result; |
| 1527 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1528 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1529 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1530 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1531 | } |
| 1532 | |
| 1533 | synchronized (request) { |
| 1534 | request.notifyAll(); |
| 1535 | } |
| 1536 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1537 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1538 | case CMD_MODEM_REBOOT: |
| 1539 | request = (MainThreadRequest) msg.obj; |
| 1540 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1541 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1542 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1543 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1544 | handleNullReturnEvent(msg, "rebootModem"); |
| 1545 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1546 | case CMD_REQUEST_ENABLE_MODEM: |
| 1547 | request = (MainThreadRequest) msg.obj; |
| 1548 | boolean enable = (boolean) request.argument; |
| 1549 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1550 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1551 | PhoneConfigurationManager.getInstance() |
| 1552 | .enablePhone(request.phone, enable, onCompleted); |
| 1553 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1554 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1555 | ar = (AsyncResult) msg.obj; |
| 1556 | request = (MainThreadRequest) ar.userObj; |
| 1557 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1558 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1559 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1560 | if ((boolean) request.result) { |
| 1561 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1562 | updateModemStateMetrics(); |
| 1563 | } else { |
| 1564 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1565 | + ar.exception); |
| 1566 | } |
| 1567 | notifyRequester(request); |
| 1568 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1569 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1570 | case CMD_GET_MODEM_STATUS: |
| 1571 | request = (MainThreadRequest) msg.obj; |
| 1572 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1573 | PhoneConfigurationManager.getInstance() |
| 1574 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1575 | break; |
| 1576 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1577 | ar = (AsyncResult) msg.obj; |
| 1578 | request = (MainThreadRequest) ar.userObj; |
| 1579 | int id = request.phone.getPhoneId(); |
| 1580 | if (ar.exception == null && ar.result != null) { |
| 1581 | request.result = ar.result; |
| 1582 | //update the cache as modem status has changed |
| 1583 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1584 | (boolean) request.result); |
| 1585 | } else { |
| 1586 | // Return true if modem status cannot be retrieved. For most cases, |
| 1587 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1588 | // and disable modem are not supported. Modem is always on. |
| 1589 | // TODO: this should be fixed in R to support a third |
| 1590 | // status UNKNOWN b/131631629 |
| 1591 | request.result = true; |
| 1592 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1593 | + ar.exception); |
| 1594 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1595 | notifyRequester(request); |
| 1596 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1597 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1598 | request = (MainThreadRequest) msg.obj; |
| 1599 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1600 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1601 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1602 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1603 | break; |
| 1604 | } |
| 1605 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1606 | ar = (AsyncResult) msg.obj; |
| 1607 | request = (MainThreadRequest) ar.userObj; |
| 1608 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1609 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1610 | args.second.accept(ar.exception == null); |
| 1611 | notifyRequester(request); |
| 1612 | break; |
| 1613 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1614 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1615 | request = (MainThreadRequest) msg.obj; |
| 1616 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1617 | Phone phone = getPhoneFromRequest(request); |
| 1618 | if (phone != null) { |
| 1619 | phone.getSystemSelectionChannels(onCompleted); |
| 1620 | } else { |
| 1621 | loge("getSystemSelectionChannels: No phone object"); |
| 1622 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1623 | notifyRequester(request); |
| 1624 | } |
| 1625 | break; |
| 1626 | } |
| 1627 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1628 | ar = (AsyncResult) msg.obj; |
| 1629 | request = (MainThreadRequest) ar.userObj; |
| 1630 | if (ar.exception == null && ar.result != null) { |
| 1631 | request.result = ar.result; |
| 1632 | } else { |
| 1633 | request.result = new IllegalArgumentException( |
| 1634 | "Failed to retrieve system selection channels"); |
| 1635 | if (ar.result == null) { |
| 1636 | loge("getSystemSelectionChannels: Empty response"); |
| 1637 | } else { |
| 1638 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1639 | } |
| 1640 | } |
| 1641 | notifyRequester(request); |
| 1642 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1643 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1644 | ar = (AsyncResult) msg.obj; |
| 1645 | request = (MainThreadRequest) ar.userObj; |
| 1646 | if (ar.exception == null && ar.result != null) { |
| 1647 | request.result = ar.result; |
| 1648 | } else { |
| 1649 | request.result = -1; |
| 1650 | loge("Failed to set Forbidden Plmns"); |
| 1651 | if (ar.result == null) { |
| 1652 | loge("setForbidenPlmns: Empty response"); |
| 1653 | } else if (ar.exception != null) { |
| 1654 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1655 | request.result = -1; |
| 1656 | } else { |
| 1657 | loge("setForbiddenPlmns: Unknown exception"); |
| 1658 | } |
| 1659 | } |
| 1660 | notifyRequester(request); |
| 1661 | break; |
| 1662 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1663 | request = (MainThreadRequest) msg.obj; |
| 1664 | uiccCard = getUiccCardFromRequest(request); |
| 1665 | if (uiccCard == null) { |
| 1666 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1667 | request.result = -1; |
| 1668 | notifyRequester(request); |
| 1669 | break; |
| 1670 | } |
| 1671 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1672 | (Pair<Integer, List<String>>) request.argument; |
| 1673 | appType = setFplmnsArgs.first; |
| 1674 | List<String> fplmns = setFplmnsArgs.second; |
| 1675 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1676 | if (uiccApp == null) { |
| 1677 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1678 | request.result = -1; |
| 1679 | loge("Failed to get UICC App"); |
| 1680 | notifyRequester(request); |
| 1681 | } else { |
| 1682 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1683 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1684 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1685 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1686 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1687 | case CMD_ERASE_MODEM_CONFIG: |
| 1688 | request = (MainThreadRequest) msg.obj; |
| 1689 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1690 | defaultPhone.eraseModemConfig(onCompleted); |
| 1691 | break; |
| 1692 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1693 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1694 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1695 | |
| 1696 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1697 | request = (MainThreadRequest) msg.obj; |
| 1698 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1699 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1700 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1701 | changed.first, changed.second, onCompleted); |
| 1702 | break; |
| 1703 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1704 | ar = (AsyncResult) msg.obj; |
| 1705 | request = (MainThreadRequest) ar.userObj; |
| 1706 | if (ar.exception == null) { |
| 1707 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1708 | // If the operation is successful, update the PIN storage |
| 1709 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1710 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1711 | UiccController.getInstance().getPinStorage() |
| 1712 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1713 | } else { |
| 1714 | request.result = msg.arg1; |
| 1715 | } |
| 1716 | notifyRequester(request); |
| 1717 | break; |
| 1718 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1719 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1720 | request = (MainThreadRequest) msg.obj; |
| 1721 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1722 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1723 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1724 | enabled.first, enabled.second, onCompleted); |
| 1725 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1726 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1727 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1728 | ar = (AsyncResult) msg.obj; |
| 1729 | request = (MainThreadRequest) ar.userObj; |
| 1730 | if (ar.exception == null) { |
| 1731 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1732 | // If the operation is successful, update the PIN storage |
| 1733 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1734 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1735 | if (enabled.first) { |
| 1736 | UiccController.getInstance().getPinStorage() |
| 1737 | .storePin(enabled.second, phoneId); |
| 1738 | } else { |
| 1739 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1740 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1741 | } else { |
| 1742 | request.result = msg.arg1; |
| 1743 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1744 | |
| 1745 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1746 | notifyRequester(request); |
| 1747 | break; |
| 1748 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1749 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1750 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1751 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1752 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1753 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1754 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1755 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1756 | |
| 1757 | case CMD_SET_DATA_THROTTLING: { |
| 1758 | request = (MainThreadRequest) msg.obj; |
| 1759 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1760 | DataThrottlingRequest dataThrottlingRequest = |
| 1761 | (DataThrottlingRequest) request.argument; |
| 1762 | Phone phone = getPhoneFromRequest(request); |
| 1763 | if (phone != null) { |
| 1764 | phone.setDataThrottling(onCompleted, |
| 1765 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1766 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1767 | } else { |
| 1768 | loge("setDataThrottling: No phone object"); |
| 1769 | request.result = |
| 1770 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1771 | notifyRequester(request); |
| 1772 | } |
| 1773 | |
| 1774 | break; |
| 1775 | } |
| 1776 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1777 | ar = (AsyncResult) msg.obj; |
| 1778 | request = (MainThreadRequest) ar.userObj; |
| 1779 | |
| 1780 | if (ar.exception == null) { |
| 1781 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1782 | } else if (ar.exception instanceof CommandException) { |
| 1783 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1784 | CommandException.Error error = |
| 1785 | ((CommandException) (ar.exception)).getCommandError(); |
| 1786 | |
| 1787 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1788 | request.result = TelephonyManager |
| 1789 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1790 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1791 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
| 1792 | } else { |
| 1793 | request.result = |
| 1794 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1795 | } |
| 1796 | } else { |
| 1797 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1798 | } |
| 1799 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1800 | notifyRequester(request); |
| 1801 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1802 | |
| 1803 | case CMD_SET_SIM_POWER: { |
| 1804 | request = (MainThreadRequest) msg.obj; |
| 1805 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1806 | request = (MainThreadRequest) msg.obj; |
| 1807 | int stateToSet = |
| 1808 | ((Pair<Integer, IIntegerConsumer>) |
| 1809 | request.argument).first; |
| 1810 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1811 | break; |
| 1812 | } |
| 1813 | case EVENT_SET_SIM_POWER_DONE: { |
| 1814 | ar = (AsyncResult) msg.obj; |
| 1815 | request = (MainThreadRequest) ar.userObj; |
| 1816 | IIntegerConsumer callback = |
| 1817 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1818 | if (ar.exception != null) { |
| 1819 | loge("setSimPower exception: " + ar.exception); |
| 1820 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1821 | .RESULT_ERROR_UNKNOWN; |
| 1822 | if (ar.exception instanceof CommandException) { |
| 1823 | CommandException.Error error = |
| 1824 | ((CommandException) (ar.exception)).getCommandError(); |
| 1825 | if (error == CommandException.Error.SIM_ERR) { |
| 1826 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1827 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1828 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1829 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1830 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1831 | } else { |
| 1832 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1833 | } |
| 1834 | } |
| 1835 | try { |
| 1836 | callback.accept(errorCode); |
| 1837 | } catch (RemoteException e) { |
| 1838 | // Ignore if the remote process is no longer available to call back. |
| 1839 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1840 | } |
| 1841 | } else { |
| 1842 | try { |
| 1843 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1844 | } catch (RemoteException e) { |
| 1845 | // Ignore if the remote process is no longer available to call back. |
| 1846 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1847 | } |
| 1848 | } |
| 1849 | break; |
| 1850 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1851 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1852 | request = (MainThreadRequest) msg.obj; |
| 1853 | |
| 1854 | final Phone phone = getPhoneFromRequest(request); |
| 1855 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1856 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1857 | notifyRequester(request); |
| 1858 | break; |
| 1859 | } |
| 1860 | |
| 1861 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1862 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1863 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1864 | request); |
| 1865 | phone.getServiceStateTracker().setSignalStrengthUpdateRequest( |
| 1866 | request.subId, pair.first /*callingUid*/, |
| 1867 | pair.second /*request*/, onCompleted); |
| 1868 | break; |
| 1869 | } |
| 1870 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1871 | ar = (AsyncResult) msg.obj; |
| 1872 | request = (MainThreadRequest) ar.userObj; |
| 1873 | // request.result will be the exception of ar if present, true otherwise. |
| 1874 | // Be cautious not to leave result null which will wait() forever |
| 1875 | request.result = ar.exception != null ? ar.exception : true; |
| 1876 | notifyRequester(request); |
| 1877 | break; |
| 1878 | } |
| 1879 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1880 | request = (MainThreadRequest) msg.obj; |
| 1881 | |
| 1882 | Phone phone = getPhoneFromRequest(request); |
| 1883 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1884 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1885 | notifyRequester(request); |
| 1886 | break; |
| 1887 | } |
| 1888 | |
| 1889 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1890 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1891 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1892 | request); |
| 1893 | phone.getServiceStateTracker().clearSignalStrengthUpdateRequest( |
| 1894 | request.subId, pair.first /*callingUid*/, |
| 1895 | pair.second /*request*/, onCompleted); |
| 1896 | break; |
| 1897 | } |
| 1898 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1899 | ar = (AsyncResult) msg.obj; |
| 1900 | request = (MainThreadRequest) ar.userObj; |
| 1901 | request.result = ar.exception != null ? ar.exception : true; |
| 1902 | notifyRequester(request); |
| 1903 | break; |
| 1904 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1905 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1906 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 1907 | request = (MainThreadRequest) msg.obj; |
| 1908 | request.result = |
| 1909 | UiccController.getInstance().getPinStorage().prepareUnattendedReboot(); |
| 1910 | notifyRequester(request); |
| 1911 | break; |
| 1912 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1913 | default: |
| 1914 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1915 | break; |
| 1916 | } |
| 1917 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1918 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1919 | private void notifyRequester(MainThreadRequest request) { |
| 1920 | synchronized (request) { |
| 1921 | request.notifyAll(); |
| 1922 | } |
| 1923 | } |
| 1924 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1925 | private void handleNullReturnEvent(Message msg, String command) { |
| 1926 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1927 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1928 | if (ar.exception == null) { |
| 1929 | request.result = true; |
| 1930 | } else { |
| 1931 | request.result = false; |
| 1932 | if (ar.exception instanceof CommandException) { |
| 1933 | loge(command + ": CommandException: " + ar.exception); |
| 1934 | } else { |
| 1935 | loge(command + ": Unknown exception"); |
| 1936 | } |
| 1937 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1938 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1939 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -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 | */ |
| 1947 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1948 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 1949 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1950 | } |
| 1951 | |
| 1952 | /** |
| 1953 | * Posts the specified command to be executed on the main thread, |
| 1954 | * waits for the request to complete, and returns the result. |
| 1955 | * @see #sendRequestAsync |
| 1956 | */ |
| 1957 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1958 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1959 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | /** |
| 1963 | * Posts the specified command to be executed on the main thread, |
| 1964 | * waits for the request to complete, and returns the result. |
| 1965 | * @see #sendRequestAsync |
| 1966 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1967 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1968 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 1969 | } |
| 1970 | |
| 1971 | /** |
| 1972 | * Posts the specified command to be executed on the main thread, |
| 1973 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 1974 | * if not timeout or null otherwise. |
| 1975 | * @see #sendRequestAsync |
| 1976 | */ |
| 1977 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 1978 | long timeoutInMs) { |
| 1979 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1980 | } |
| 1981 | |
| 1982 | /** |
| 1983 | * Posts the specified command to be executed on the main thread, |
| 1984 | * waits for the request to complete, and returns the result. |
| 1985 | * @see #sendRequestAsync |
| 1986 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1987 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1988 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1989 | } |
| 1990 | |
| 1991 | /** |
| 1992 | * Posts the specified command to be executed on the main thread, |
| 1993 | * waits for the request to complete, and returns the result. |
| 1994 | * @see #sendRequestAsync |
| 1995 | */ |
| 1996 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1997 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 1998 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2002 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2003 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2004 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2005 | * @see #sendRequestAsync |
| 2006 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2007 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2008 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2009 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2010 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2011 | } |
| 2012 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2013 | MainThreadRequest request = null; |
| 2014 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2015 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2016 | } else if (phone != null) { |
| 2017 | request = new MainThreadRequest(argument, phone, workSource); |
| 2018 | } else { |
| 2019 | request = new MainThreadRequest(argument, subId, workSource); |
| 2020 | } |
| 2021 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2022 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2023 | msg.sendToTarget(); |
| 2024 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2025 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2026 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2027 | if (timeoutInMs >= 0) { |
| 2028 | // Wait for at least timeoutInMs before returning null request result |
| 2029 | long now = SystemClock.elapsedRealtime(); |
| 2030 | long deadline = now + timeoutInMs; |
| 2031 | while (request == null && now < deadline) { |
| 2032 | try { |
| 2033 | request.wait(deadline - now); |
| 2034 | } catch (InterruptedException e) { |
| 2035 | // Do nothing, go back and check if request is completed or timeout |
| 2036 | } finally { |
| 2037 | now = SystemClock.elapsedRealtime(); |
| 2038 | } |
| 2039 | } |
| 2040 | } else { |
| 2041 | // Wait for the request to complete |
| 2042 | while (request.result == null) { |
| 2043 | try { |
| 2044 | request.wait(); |
| 2045 | } catch (InterruptedException e) { |
| 2046 | // Do nothing, go back and wait until the request is complete |
| 2047 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2048 | } |
| 2049 | } |
| 2050 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2051 | if (request.result == null) { |
| 2052 | Log.wtf(LOG_TAG, |
| 2053 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2054 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2055 | return request.result; |
| 2056 | } |
| 2057 | |
| 2058 | /** |
| 2059 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2060 | * Posts the specified command to be executed on the main thread, and |
| 2061 | * returns immediately. |
| 2062 | * @see #sendRequest |
| 2063 | */ |
| 2064 | private void sendRequestAsync(int command) { |
| 2065 | mMainThreadHandler.sendEmptyMessage(command); |
| 2066 | } |
| 2067 | |
| 2068 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2069 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2070 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2071 | */ |
| 2072 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2073 | sendRequestAsync(command, argument, null, null); |
| 2074 | } |
| 2075 | |
| 2076 | /** |
| 2077 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2078 | * @see {@link #sendRequest(int,Object)} |
| 2079 | */ |
| 2080 | private void sendRequestAsync( |
| 2081 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2082 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2083 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2084 | msg.sendToTarget(); |
| 2085 | } |
| 2086 | |
| 2087 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2088 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2089 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2090 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2091 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2092 | synchronized (PhoneInterfaceManager.class) { |
| 2093 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2094 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2095 | } else { |
| 2096 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2097 | } |
| 2098 | return sInstance; |
| 2099 | } |
| 2100 | } |
| 2101 | |
| 2102 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2103 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2104 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2105 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 2106 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2107 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2108 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2109 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2110 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2111 | mTelephonySharedPreferences = |
| 2112 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2113 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2114 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2115 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2116 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2117 | publish(); |
| 2118 | } |
| 2119 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2120 | private Phone getDefaultPhone() { |
| 2121 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2122 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2123 | } |
| 2124 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2125 | private void publish() { |
| 2126 | if (DBG) log("publish: " + this); |
| 2127 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2128 | TelephonyFrameworkInitializer |
| 2129 | .getTelephonyServiceManager() |
| 2130 | .getTelephonyServiceRegisterer() |
| 2131 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2132 | } |
| 2133 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2134 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2135 | if (request.phone != null) { |
| 2136 | return request.phone; |
| 2137 | } else { |
| 2138 | return getPhoneFromSubId(request.subId); |
| 2139 | } |
| 2140 | } |
| 2141 | |
| 2142 | private Phone getPhoneFromSubId(int subId) { |
| 2143 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2144 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2145 | } |
| 2146 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2147 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 2148 | Phone phone = getPhoneFromRequest(request); |
| 2149 | return phone == null ? null : |
| 2150 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 2151 | } |
| 2152 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2153 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2154 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2155 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2156 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2157 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2158 | private void sendEraseModemConfig(Phone phone) { |
| 2159 | if (phone != null) { |
| 2160 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2161 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 2162 | final long identity = Binder.clearCallingIdentity(); |
| 2163 | try { |
| 2164 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2165 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2166 | } finally { |
| 2167 | Binder.restoreCallingIdentity(identity); |
| 2168 | } |
| 2169 | } |
| 2170 | } |
| 2171 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2172 | private boolean isImsAvailableOnDevice() { |
| 2173 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2174 | if (pm == null) { |
| 2175 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2176 | // so do not throw error and allow. |
| 2177 | return true; |
| 2178 | } |
| 2179 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2180 | } |
| 2181 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2182 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2183 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2184 | } |
| 2185 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2186 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2187 | if (DBG) log("dial: " + number); |
| 2188 | // No permission check needed here: This is just a wrapper around the |
| 2189 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2190 | // the UI before it does anything. |
| 2191 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2192 | final long identity = Binder.clearCallingIdentity(); |
| 2193 | try { |
| 2194 | String url = createTelUrl(number); |
| 2195 | if (url == null) { |
| 2196 | return; |
| 2197 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2198 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2199 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2200 | PhoneConstants.State state = mCM.getState(subId); |
| 2201 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2202 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2203 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2204 | mApp.startActivity(intent); |
| 2205 | } |
| 2206 | } finally { |
| 2207 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2208 | } |
| 2209 | } |
| 2210 | |
| 2211 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2212 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2213 | } |
| 2214 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2215 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2216 | if (DBG) log("call: " + number); |
| 2217 | |
| 2218 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2219 | // need to do a permission check since we're calling startActivity() |
| 2220 | // from the context of the phone app. |
| 2221 | enforceCallPermission(); |
| 2222 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2223 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2224 | != AppOpsManager.MODE_ALLOWED) { |
| 2225 | return; |
| 2226 | } |
| 2227 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2228 | final long identity = Binder.clearCallingIdentity(); |
| 2229 | try { |
| 2230 | String url = createTelUrl(number); |
| 2231 | if (url == null) { |
| 2232 | return; |
| 2233 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2234 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2235 | boolean isValid = false; |
| 2236 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2237 | if (slist != null) { |
| 2238 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2239 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2240 | isValid = true; |
| 2241 | break; |
| 2242 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2243 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2244 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2245 | if (!isValid) { |
| 2246 | return; |
| 2247 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2248 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2249 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2250 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2251 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2252 | mApp.startActivity(intent); |
| 2253 | } finally { |
| 2254 | Binder.restoreCallingIdentity(identity); |
| 2255 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2256 | } |
| 2257 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2258 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2259 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2260 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2261 | } |
| 2262 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2263 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2264 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2265 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2266 | } |
| 2267 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2268 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2269 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2270 | |
| 2271 | final long identity = Binder.clearCallingIdentity(); |
| 2272 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2273 | Phone phone = getPhone(subId); |
| 2274 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2275 | checkSimPin.start(); |
| 2276 | return checkSimPin.unlockSim(null, pin); |
| 2277 | } finally { |
| 2278 | Binder.restoreCallingIdentity(identity); |
| 2279 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2280 | } |
| 2281 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2282 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2283 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2284 | |
| 2285 | final long identity = Binder.clearCallingIdentity(); |
| 2286 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2287 | Phone phone = getPhone(subId); |
| 2288 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2289 | checkSimPuk.start(); |
| 2290 | return checkSimPuk.unlockSim(puk, pin); |
| 2291 | } finally { |
| 2292 | Binder.restoreCallingIdentity(identity); |
| 2293 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2294 | } |
| 2295 | |
| 2296 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2297 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2298 | * a synchronous one. |
| 2299 | */ |
| 2300 | private static class UnlockSim extends Thread { |
| 2301 | |
| 2302 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2303 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2304 | |
| 2305 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2306 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2307 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2308 | |
| 2309 | // For replies from SimCard interface |
| 2310 | private Handler mHandler; |
| 2311 | |
| 2312 | // For async handler to identify request type |
| 2313 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2314 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2315 | UnlockSim(int phoneId, IccCard simCard) { |
| 2316 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2317 | mSimCard = simCard; |
| 2318 | } |
| 2319 | |
| 2320 | @Override |
| 2321 | public void run() { |
| 2322 | Looper.prepare(); |
| 2323 | synchronized (UnlockSim.this) { |
| 2324 | mHandler = new Handler() { |
| 2325 | @Override |
| 2326 | public void handleMessage(Message msg) { |
| 2327 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2328 | switch (msg.what) { |
| 2329 | case SUPPLY_PIN_COMPLETE: |
| 2330 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2331 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2332 | mRetryCount = msg.arg1; |
| 2333 | if (ar.exception != null) { |
| 2334 | if (ar.exception instanceof CommandException && |
| 2335 | ((CommandException)(ar.exception)).getCommandError() |
| 2336 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2337 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2338 | } //When UiccCardApp dispose,handle message and return exception |
| 2339 | else if (ar.exception instanceof CommandException && |
| 2340 | ((CommandException) (ar.exception)).getCommandError() |
| 2341 | == CommandException.Error.ABORTED) { |
| 2342 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2343 | } else { |
| 2344 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2345 | } |
| 2346 | } else { |
| 2347 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2348 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2349 | mDone = true; |
| 2350 | UnlockSim.this.notifyAll(); |
| 2351 | } |
| 2352 | break; |
| 2353 | } |
| 2354 | } |
| 2355 | }; |
| 2356 | UnlockSim.this.notifyAll(); |
| 2357 | } |
| 2358 | Looper.loop(); |
| 2359 | } |
| 2360 | |
| 2361 | /* |
| 2362 | * Use PIN or PUK to unlock SIM card |
| 2363 | * |
| 2364 | * If PUK is null, unlock SIM card with PIN |
| 2365 | * |
| 2366 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2367 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2368 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2369 | |
| 2370 | while (mHandler == null) { |
| 2371 | try { |
| 2372 | wait(); |
| 2373 | } catch (InterruptedException e) { |
| 2374 | Thread.currentThread().interrupt(); |
| 2375 | } |
| 2376 | } |
| 2377 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2378 | |
| 2379 | if (puk == null) { |
| 2380 | mSimCard.supplyPin(pin, callback); |
| 2381 | } else { |
| 2382 | mSimCard.supplyPuk(puk, pin, callback); |
| 2383 | } |
| 2384 | |
| 2385 | while (!mDone) { |
| 2386 | try { |
| 2387 | Log.d(LOG_TAG, "wait for done"); |
| 2388 | wait(); |
| 2389 | } catch (InterruptedException e) { |
| 2390 | // Restore the interrupted status |
| 2391 | Thread.currentThread().interrupt(); |
| 2392 | } |
| 2393 | } |
| 2394 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2395 | int[] resultArray = new int[2]; |
| 2396 | resultArray[0] = mResult; |
| 2397 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2398 | |
| 2399 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
| 2400 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
| 2401 | } |
| 2402 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2403 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2404 | } |
| 2405 | } |
| 2406 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2407 | /** |
| 2408 | * This method has been removed due to privacy and stability concerns. |
| 2409 | */ |
| 2410 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2411 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2412 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2413 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2414 | } |
| 2415 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2416 | @Override |
| 2417 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2418 | mApp.getSystemService(AppOpsManager.class) |
| 2419 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2420 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2421 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2422 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2423 | // Callers targeting S have no business invoking this method. |
| 2424 | return; |
| 2425 | } |
| 2426 | |
| 2427 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2428 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2429 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2430 | .setCallingPackage(callingPackage) |
| 2431 | .setCallingFeatureId(null) |
| 2432 | .setCallingPid(Binder.getCallingPid()) |
| 2433 | .setCallingUid(Binder.getCallingUid()) |
| 2434 | .setMethod("updateServiceLocation") |
| 2435 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2436 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2437 | .build()); |
| 2438 | // Apps that lack location permission have no business calling this method; |
| 2439 | // however, because no permission was declared in the public API, denials must |
| 2440 | // all be "soft". |
| 2441 | switch (locationResult) { |
| 2442 | case DENIED_HARD: /* fall through */ |
| 2443 | case DENIED_SOFT: |
| 2444 | return; |
| 2445 | } |
| 2446 | |
| 2447 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2448 | final long identity = Binder.clearCallingIdentity(); |
| 2449 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2450 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2451 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2452 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2453 | } |
| 2454 | } finally { |
| 2455 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2456 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2457 | } |
| 2458 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2459 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2460 | @Override |
| 2461 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2462 | return isRadioOnWithFeature(callingPackage, null); |
| 2463 | } |
| 2464 | |
| 2465 | |
| 2466 | @Override |
| 2467 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2468 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2469 | callingFeatureId); |
| 2470 | } |
| 2471 | |
| 2472 | @Deprecated |
| 2473 | @Override |
| 2474 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2475 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2476 | } |
| 2477 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2478 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2479 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2480 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2481 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2482 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2483 | return false; |
| 2484 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2485 | |
| 2486 | final long identity = Binder.clearCallingIdentity(); |
| 2487 | try { |
| 2488 | return isRadioOnForSubscriber(subId); |
| 2489 | } finally { |
| 2490 | Binder.restoreCallingIdentity(identity); |
| 2491 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2492 | } |
| 2493 | |
| 2494 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2495 | final long identity = Binder.clearCallingIdentity(); |
| 2496 | try { |
| 2497 | final Phone phone = getPhone(subId); |
| 2498 | if (phone != null) { |
| 2499 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2500 | } else { |
| 2501 | return false; |
| 2502 | } |
| 2503 | } finally { |
| 2504 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2505 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2506 | } |
| 2507 | |
| 2508 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2509 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2510 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2511 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2512 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2513 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2514 | |
| 2515 | final long identity = Binder.clearCallingIdentity(); |
| 2516 | try { |
| 2517 | final Phone phone = getPhone(subId); |
| 2518 | if (phone != null) { |
| 2519 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2520 | } |
| 2521 | } finally { |
| 2522 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2523 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2524 | } |
| 2525 | |
| 2526 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2527 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2528 | } |
| 2529 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2530 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2531 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2532 | |
| 2533 | final long identity = Binder.clearCallingIdentity(); |
| 2534 | try { |
| 2535 | final Phone phone = getPhone(subId); |
| 2536 | if (phone == null) { |
| 2537 | return false; |
| 2538 | } |
| 2539 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2540 | toggleRadioOnOffForSubscriber(subId); |
| 2541 | } |
| 2542 | return true; |
| 2543 | } finally { |
| 2544 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2545 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2546 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2547 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2548 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2549 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2550 | /* |
| 2551 | * If any of the Radios are available, it will need to be |
| 2552 | * shutdown. So return true if any Radio is available. |
| 2553 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2554 | final long identity = Binder.clearCallingIdentity(); |
| 2555 | try { |
| 2556 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2557 | Phone phone = PhoneFactory.getPhone(i); |
| 2558 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2559 | } |
| 2560 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2561 | return false; |
| 2562 | } finally { |
| 2563 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2564 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2565 | } |
| 2566 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2567 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2568 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2569 | enforceModifyPermission(); |
| 2570 | |
| 2571 | final long identity = Binder.clearCallingIdentity(); |
| 2572 | try { |
| 2573 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2574 | logv("Shutting down Phone " + i); |
| 2575 | shutdownRadioUsingPhoneId(i); |
| 2576 | } |
| 2577 | } finally { |
| 2578 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2579 | } |
| 2580 | } |
| 2581 | |
| 2582 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2583 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2584 | if (phone != null && phone.isRadioAvailable()) { |
| 2585 | phone.shutdownRadio(); |
| 2586 | } |
| 2587 | } |
| 2588 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2589 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2590 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2591 | |
| 2592 | final long identity = Binder.clearCallingIdentity(); |
| 2593 | try { |
| 2594 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2595 | if (defaultPhone != null) { |
| 2596 | defaultPhone.setRadioPower(turnOn); |
| 2597 | return true; |
| 2598 | } else { |
| 2599 | loge("There's no default phone."); |
| 2600 | return false; |
| 2601 | } |
| 2602 | } finally { |
| 2603 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2604 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2605 | } |
| 2606 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2607 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2608 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2609 | |
| 2610 | final long identity = Binder.clearCallingIdentity(); |
| 2611 | try { |
| 2612 | final Phone phone = getPhone(subId); |
| 2613 | if (phone != null) { |
| 2614 | phone.setRadioPower(turnOn); |
| 2615 | return true; |
| 2616 | } else { |
| 2617 | return false; |
| 2618 | } |
| 2619 | } finally { |
| 2620 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2621 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2622 | } |
| 2623 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2624 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2625 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2626 | public boolean enableDataConnectivity() { |
| 2627 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2628 | |
| 2629 | final long identity = Binder.clearCallingIdentity(); |
| 2630 | try { |
| 2631 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2632 | final Phone phone = getPhone(subId); |
| 2633 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2634 | phone.getDataEnabledSettings().setDataEnabled( |
| 2635 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2636 | return true; |
| 2637 | } else { |
| 2638 | return false; |
| 2639 | } |
| 2640 | } finally { |
| 2641 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2642 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2643 | } |
| 2644 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2645 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2646 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2647 | public boolean disableDataConnectivity() { |
| 2648 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2649 | |
| 2650 | final long identity = Binder.clearCallingIdentity(); |
| 2651 | try { |
| 2652 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2653 | final Phone phone = getPhone(subId); |
| 2654 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2655 | phone.getDataEnabledSettings().setDataEnabled( |
| 2656 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2657 | return true; |
| 2658 | } else { |
| 2659 | return false; |
| 2660 | } |
| 2661 | } finally { |
| 2662 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2663 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2664 | } |
| 2665 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2666 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2667 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2668 | final long identity = Binder.clearCallingIdentity(); |
| 2669 | try { |
| 2670 | final Phone phone = getPhone(subId); |
| 2671 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2672 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2673 | } else { |
| 2674 | return false; |
| 2675 | } |
| 2676 | } finally { |
| 2677 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2678 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2679 | } |
| 2680 | |
| 2681 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2682 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2683 | } |
| 2684 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2685 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2686 | enforceCallPermission(); |
| 2687 | |
| 2688 | final long identity = Binder.clearCallingIdentity(); |
| 2689 | try { |
| 2690 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2691 | return; |
| 2692 | } |
| 2693 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2694 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2695 | } finally { |
| 2696 | Binder.restoreCallingIdentity(identity); |
| 2697 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2698 | }; |
| 2699 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2700 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2701 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2702 | |
| 2703 | final long identity = Binder.clearCallingIdentity(); |
| 2704 | try { |
| 2705 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2706 | return false; |
| 2707 | } |
| 2708 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2709 | } finally { |
| 2710 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2711 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2712 | } |
| 2713 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2714 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2715 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2716 | } |
| 2717 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2718 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2719 | final long identity = Binder.clearCallingIdentity(); |
| 2720 | try { |
| 2721 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2722 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2723 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2724 | } finally { |
| 2725 | Binder.restoreCallingIdentity(identity); |
| 2726 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2727 | } |
| 2728 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2729 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2730 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2731 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2732 | } |
| 2733 | |
| 2734 | @Override |
| 2735 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2736 | final long identity = Binder.clearCallingIdentity(); |
| 2737 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2738 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2739 | if (phone != null) { |
| 2740 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2741 | } else { |
| 2742 | return PhoneConstantConversions.convertDataState( |
| 2743 | PhoneConstants.DataState.DISCONNECTED); |
| 2744 | } |
| 2745 | } finally { |
| 2746 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2747 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2748 | } |
| 2749 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2750 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2751 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2752 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2753 | } |
| 2754 | |
| 2755 | @Override |
| 2756 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2757 | final long identity = Binder.clearCallingIdentity(); |
| 2758 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2759 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2760 | if (phone != null) { |
| 2761 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2762 | } else { |
| 2763 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2764 | } |
| 2765 | } finally { |
| 2766 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2767 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2768 | } |
| 2769 | |
| 2770 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2771 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2772 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2773 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2774 | |
| 2775 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2776 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2777 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2778 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2779 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2780 | .setCallingPid(Binder.getCallingPid()) |
| 2781 | .setCallingUid(Binder.getCallingUid()) |
| 2782 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2783 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2784 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2785 | .build()); |
| 2786 | switch (locationResult) { |
| 2787 | case DENIED_HARD: |
| 2788 | throw new SecurityException("Not allowed to access cell location"); |
| 2789 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2790 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2791 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2792 | } |
| 2793 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2794 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2795 | final long identity = Binder.clearCallingIdentity(); |
| 2796 | try { |
| 2797 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2798 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2799 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2800 | } finally { |
| 2801 | Binder.restoreCallingIdentity(identity); |
| 2802 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2803 | } |
| 2804 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2805 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2806 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2807 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2808 | // registered cell info, so return a NULL country instead. |
| 2809 | final long identity = Binder.clearCallingIdentity(); |
| 2810 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2811 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2812 | // Get default phone in this case. |
| 2813 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2814 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2815 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2816 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2817 | if (phone == null) return ""; |
| 2818 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2819 | if (sst == null) return ""; |
| 2820 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2821 | if (lt == null) return ""; |
| 2822 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2823 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2824 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2825 | } finally { |
| 2826 | Binder.restoreCallingIdentity(identity); |
| 2827 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2828 | } |
| 2829 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2830 | /** |
| 2831 | * This method was removed due to potential issues caused by performing partial |
| 2832 | * updates of service state, and lack of a credible use case. |
| 2833 | * |
| 2834 | * This has the ability to break the telephony implementation by disabling notification of |
| 2835 | * changes in device connectivity. DO NOT USE THIS! |
| 2836 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2837 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2838 | public void enableLocationUpdates() { |
| 2839 | mApp.enforceCallingOrSelfPermission( |
| 2840 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2841 | } |
| 2842 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2843 | /** |
| 2844 | * This method was removed due to potential issues caused by performing partial |
| 2845 | * updates of service state, and lack of a credible use case. |
| 2846 | * |
| 2847 | * This has the ability to break the telephony implementation by disabling notification of |
| 2848 | * changes in device connectivity. DO NOT USE THIS! |
| 2849 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2850 | @Override |
| 2851 | public void disableLocationUpdates() { |
| 2852 | mApp.enforceCallingOrSelfPermission( |
| 2853 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2854 | } |
| 2855 | |
| 2856 | @Override |
| 2857 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2858 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2859 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2860 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2861 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2862 | throw new SecurityException( |
| 2863 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2864 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2865 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2866 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2867 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2868 | return null; |
| 2869 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2870 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2871 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2872 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2873 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2874 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2875 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2876 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2877 | for (CellInfo ci : info) { |
| 2878 | if (ci instanceof CellInfoGsm) { |
| 2879 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2880 | } else if (ci instanceof CellInfoWcdma) { |
| 2881 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2882 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2883 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2884 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2885 | } |
| 2886 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2887 | private List<CellInfo> getCachedCellInfo() { |
| 2888 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2889 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2890 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2891 | if (info != null) cellInfos.addAll(info); |
| 2892 | } |
| 2893 | return cellInfos; |
| 2894 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2895 | |
| 2896 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2897 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2898 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2899 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2900 | |
| 2901 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2902 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2903 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2904 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2905 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2906 | .setCallingPid(Binder.getCallingPid()) |
| 2907 | .setCallingUid(Binder.getCallingUid()) |
| 2908 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2909 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2910 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2911 | .build()); |
| 2912 | switch (locationResult) { |
| 2913 | case DENIED_HARD: |
| 2914 | throw new SecurityException("Not allowed to access cell info"); |
| 2915 | case DENIED_SOFT: |
| 2916 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2917 | } |
| 2918 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2919 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2920 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2921 | return getCachedCellInfo(); |
| 2922 | } |
| 2923 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2924 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2925 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2926 | final long identity = Binder.clearCallingIdentity(); |
| 2927 | try { |
| 2928 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2929 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2930 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2931 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2932 | if (info != null) cellInfos.addAll(info); |
| 2933 | } |
| 2934 | return cellInfos; |
| 2935 | } finally { |
| 2936 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2937 | } |
| 2938 | } |
| 2939 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2940 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2941 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2942 | String callingFeatureId) { |
| 2943 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2944 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2945 | } |
| 2946 | |
| 2947 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2948 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2949 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2950 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2951 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2952 | } |
| 2953 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2954 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2955 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2956 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2957 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2958 | |
| 2959 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2960 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2961 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2962 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2963 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2964 | .setCallingPid(Binder.getCallingPid()) |
| 2965 | .setCallingUid(Binder.getCallingUid()) |
| 2966 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2967 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2968 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2969 | .build()); |
| 2970 | switch (locationResult) { |
| 2971 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2972 | if (TelephonyPermissions |
| 2973 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2974 | // Safetynet logging for b/154934934 |
| 2975 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2976 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2977 | throw new SecurityException("Not allowed to access cell info"); |
| 2978 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2979 | if (TelephonyPermissions |
| 2980 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2981 | // Safetynet logging for b/154934934 |
| 2982 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2983 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2984 | try { |
| 2985 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2986 | } catch (RemoteException re) { |
| 2987 | // Drop without consequences |
| 2988 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2989 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2990 | } |
| 2991 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2992 | |
| 2993 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2994 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2995 | |
| 2996 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2997 | } |
| 2998 | |
| 2999 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3000 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3001 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3002 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3003 | |
| 3004 | final long identity = Binder.clearCallingIdentity(); |
| 3005 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3006 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3007 | } finally { |
| 3008 | Binder.restoreCallingIdentity(identity); |
| 3009 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3010 | } |
| 3011 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3012 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3013 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3014 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3015 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3016 | return null; |
| 3017 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3018 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3019 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3020 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3021 | return null; |
| 3022 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3023 | |
| 3024 | final long identity = Binder.clearCallingIdentity(); |
| 3025 | try { |
| 3026 | return phone.getImei(); |
| 3027 | } finally { |
| 3028 | Binder.restoreCallingIdentity(identity); |
| 3029 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3030 | } |
| 3031 | |
| 3032 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3033 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3034 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3035 | String tac = null; |
| 3036 | if (phone != null) { |
| 3037 | String imei = phone.getImei(); |
| 3038 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3039 | } |
| 3040 | return tac; |
| 3041 | } |
| 3042 | |
| 3043 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3044 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3045 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3046 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3047 | return null; |
| 3048 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3049 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3050 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3051 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3052 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3053 | return null; |
| 3054 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3055 | |
| 3056 | final long identity = Binder.clearCallingIdentity(); |
| 3057 | try { |
| 3058 | return phone.getMeid(); |
| 3059 | } finally { |
| 3060 | Binder.restoreCallingIdentity(identity); |
| 3061 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3062 | } |
| 3063 | |
| 3064 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3065 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3066 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3067 | String manufacturerCode = null; |
| 3068 | if (phone != null) { |
| 3069 | String meid = phone.getMeid(); |
| 3070 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3071 | } |
| 3072 | return manufacturerCode; |
| 3073 | } |
| 3074 | |
| 3075 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3076 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3077 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3078 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3079 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3080 | return null; |
| 3081 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3082 | int subId = phone.getSubId(); |
| 3083 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3084 | mApp, subId, callingPackage, callingFeatureId, |
| 3085 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3086 | return null; |
| 3087 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3088 | |
| 3089 | final long identity = Binder.clearCallingIdentity(); |
| 3090 | try { |
| 3091 | return phone.getDeviceSvn(); |
| 3092 | } finally { |
| 3093 | Binder.restoreCallingIdentity(identity); |
| 3094 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3095 | } |
| 3096 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3097 | @Override |
| 3098 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3099 | final long identity = Binder.clearCallingIdentity(); |
| 3100 | try { |
| 3101 | final Phone phone = getPhone(subId); |
| 3102 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3103 | } finally { |
| 3104 | Binder.restoreCallingIdentity(identity); |
| 3105 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3106 | } |
| 3107 | |
| 3108 | @Override |
| 3109 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3110 | final long identity = Binder.clearCallingIdentity(); |
| 3111 | try { |
| 3112 | final Phone phone = getPhone(subId); |
| 3113 | return phone == null ? null : phone.getCarrierName(); |
| 3114 | } finally { |
| 3115 | Binder.restoreCallingIdentity(identity); |
| 3116 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3117 | } |
| 3118 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3119 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3120 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3121 | final long identity = Binder.clearCallingIdentity(); |
| 3122 | try { |
| 3123 | final Phone phone = getPhone(subId); |
| 3124 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3125 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3126 | } finally { |
| 3127 | Binder.restoreCallingIdentity(identity); |
| 3128 | } |
| 3129 | } |
| 3130 | |
| 3131 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3132 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3133 | final long identity = Binder.clearCallingIdentity(); |
| 3134 | try { |
| 3135 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3136 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3137 | } finally { |
| 3138 | Binder.restoreCallingIdentity(identity); |
| 3139 | } |
| 3140 | } |
| 3141 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3142 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3143 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3144 | if (!isSubscriptionMccMnc) { |
| 3145 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3146 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3147 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3148 | if (phone == null) { |
| 3149 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3150 | } |
| 3151 | final long identity = Binder.clearCallingIdentity(); |
| 3152 | try { |
| 3153 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3154 | } finally { |
| 3155 | Binder.restoreCallingIdentity(identity); |
| 3156 | } |
| 3157 | } |
| 3158 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3159 | // |
| 3160 | // Internal helper methods. |
| 3161 | // |
| 3162 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3163 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3164 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3165 | * |
| 3166 | * @throws SecurityException if the caller does not have the required permission |
| 3167 | */ |
| 3168 | private void enforceModifyPermission() { |
| 3169 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3170 | } |
| 3171 | |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3172 | /** |
| 3173 | * Make sure the caller is system. |
| 3174 | * |
| 3175 | * @throws SecurityException if the caller is not system. |
| 3176 | */ |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 3177 | private static void enforceSystemCaller() { |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3178 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 3179 | throw new SecurityException("Caller must be system"); |
| 3180 | } |
| 3181 | } |
| 3182 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3183 | private void enforceActiveEmergencySessionPermission() { |
| 3184 | mApp.enforceCallingOrSelfPermission( |
| 3185 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3186 | } |
| 3187 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3188 | /** |
| 3189 | * Make sure the caller has the CALL_PHONE permission. |
| 3190 | * |
| 3191 | * @throws SecurityException if the caller does not have the required permission |
| 3192 | */ |
| 3193 | private void enforceCallPermission() { |
| 3194 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3195 | } |
| 3196 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3197 | private void enforceSettingsPermission() { |
| 3198 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3199 | } |
| 3200 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3201 | private void enforceRebootPermission() { |
| 3202 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3203 | } |
| 3204 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3205 | private String createTelUrl(String number) { |
| 3206 | if (TextUtils.isEmpty(number)) { |
| 3207 | return null; |
| 3208 | } |
| 3209 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3210 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3211 | } |
| 3212 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3213 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3214 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3215 | } |
| 3216 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3217 | private static void logv(String msg) { |
| 3218 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3219 | } |
| 3220 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3221 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3222 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3223 | } |
| 3224 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3225 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3226 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3227 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3228 | } |
| 3229 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3230 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3231 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3232 | final long identity = Binder.clearCallingIdentity(); |
| 3233 | try { |
| 3234 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3235 | if (phone == null) { |
| 3236 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3237 | } else { |
| 3238 | return phone.getPhoneType(); |
| 3239 | } |
| 3240 | } finally { |
| 3241 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3242 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3243 | } |
| 3244 | |
| 3245 | /** |
| 3246 | * Returns the CDMA ERI icon index to display |
| 3247 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3248 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3249 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3250 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3251 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3252 | } |
| 3253 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3254 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3255 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3256 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3257 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3258 | mApp, subId, callingPackage, callingFeatureId, |
| 3259 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3260 | return -1; |
| 3261 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3262 | |
| 3263 | final long identity = Binder.clearCallingIdentity(); |
| 3264 | try { |
| 3265 | final Phone phone = getPhone(subId); |
| 3266 | if (phone != null) { |
| 3267 | return phone.getCdmaEriIconIndex(); |
| 3268 | } else { |
| 3269 | return -1; |
| 3270 | } |
| 3271 | } finally { |
| 3272 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3273 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3274 | } |
| 3275 | |
| 3276 | /** |
| 3277 | * Returns the CDMA ERI icon mode, |
| 3278 | * 0 - ON |
| 3279 | * 1 - FLASHING |
| 3280 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3281 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3282 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3283 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3284 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3285 | } |
| 3286 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3287 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3288 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3289 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3290 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3291 | mApp, subId, callingPackage, callingFeatureId, |
| 3292 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3293 | return -1; |
| 3294 | } |
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) { |
| 3300 | return phone.getCdmaEriIconMode(); |
| 3301 | } else { |
| 3302 | return -1; |
| 3303 | } |
| 3304 | } finally { |
| 3305 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3306 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3307 | } |
| 3308 | |
| 3309 | /** |
| 3310 | * Returns the CDMA ERI text, |
| 3311 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3312 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3313 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3314 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3315 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3316 | } |
| 3317 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3318 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3319 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3320 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3321 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3322 | mApp, subId, callingPackage, callingFeatureId, |
| 3323 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3324 | return null; |
| 3325 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3326 | |
| 3327 | final long identity = Binder.clearCallingIdentity(); |
| 3328 | try { |
| 3329 | final Phone phone = getPhone(subId); |
| 3330 | if (phone != null) { |
| 3331 | return phone.getCdmaEriText(); |
| 3332 | } else { |
| 3333 | return null; |
| 3334 | } |
| 3335 | } finally { |
| 3336 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3337 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3338 | } |
| 3339 | |
| 3340 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3341 | * Returns the CDMA MDN. |
| 3342 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3343 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3344 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3345 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3346 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3347 | |
| 3348 | final long identity = Binder.clearCallingIdentity(); |
| 3349 | try { |
| 3350 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3351 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3352 | return phone.getLine1Number(); |
| 3353 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3354 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3355 | return null; |
| 3356 | } |
| 3357 | } finally { |
| 3358 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3359 | } |
| 3360 | } |
| 3361 | |
| 3362 | /** |
| 3363 | * Returns the CDMA MIN. |
| 3364 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3365 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3366 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3367 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3368 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3369 | |
| 3370 | final long identity = Binder.clearCallingIdentity(); |
| 3371 | try { |
| 3372 | final Phone phone = getPhone(subId); |
| 3373 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3374 | return phone.getCdmaMin(); |
| 3375 | } else { |
| 3376 | return null; |
| 3377 | } |
| 3378 | } finally { |
| 3379 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3380 | } |
| 3381 | } |
| 3382 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3383 | @Override |
| 3384 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3385 | INumberVerificationCallback callback, String callingPackage) { |
| 3386 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3387 | != PERMISSION_GRANTED) { |
| 3388 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3389 | } |
| 3390 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3391 | |
| 3392 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3393 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3394 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3395 | + "calling package: " + callingPackage |
| 3396 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3397 | } |
| 3398 | |
| 3399 | if (range == null) { |
| 3400 | throw new NullPointerException("Range must be non-null"); |
| 3401 | } |
| 3402 | |
| 3403 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3404 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3405 | |
| 3406 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3407 | } |
| 3408 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3409 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3410 | * Returns true if CDMA provisioning needs to run. |
| 3411 | */ |
| 3412 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3413 | final long identity = Binder.clearCallingIdentity(); |
| 3414 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3415 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3416 | } finally { |
| 3417 | Binder.restoreCallingIdentity(identity); |
| 3418 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3419 | } |
| 3420 | |
| 3421 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3422 | * Sets the voice mail number of a given subId. |
| 3423 | */ |
| 3424 | @Override |
| 3425 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3426 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3427 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3428 | |
| 3429 | final long identity = Binder.clearCallingIdentity(); |
| 3430 | try { |
| 3431 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3432 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3433 | return success; |
| 3434 | } finally { |
| 3435 | Binder.restoreCallingIdentity(identity); |
| 3436 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3437 | } |
| 3438 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3439 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3440 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3441 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3442 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3443 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3444 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3445 | throw new SecurityException("caller must be system dialer"); |
| 3446 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3447 | |
| 3448 | final long identity = Binder.clearCallingIdentity(); |
| 3449 | try { |
| 3450 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3451 | if (phoneAccountHandle == null) { |
| 3452 | return null; |
| 3453 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3454 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3455 | } finally { |
| 3456 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3457 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3458 | } |
| 3459 | |
| 3460 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3461 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3462 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3463 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3464 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3465 | mApp, subId, callingPackage, callingFeatureId, |
| 3466 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3467 | return null; |
| 3468 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3469 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3470 | final long identity = Binder.clearCallingIdentity(); |
| 3471 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3472 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3473 | } finally { |
| 3474 | Binder.restoreCallingIdentity(identity); |
| 3475 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3476 | } |
| 3477 | |
| 3478 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3479 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3480 | VisualVoicemailSmsFilterSettings settings) { |
| 3481 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3482 | |
| 3483 | final long identity = Binder.clearCallingIdentity(); |
| 3484 | try { |
| 3485 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3486 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3487 | } finally { |
| 3488 | Binder.restoreCallingIdentity(identity); |
| 3489 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3490 | } |
| 3491 | |
| 3492 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3493 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3494 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3495 | |
| 3496 | final long identity = Binder.clearCallingIdentity(); |
| 3497 | try { |
| 3498 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3499 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3500 | } finally { |
| 3501 | Binder.restoreCallingIdentity(identity); |
| 3502 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3503 | } |
| 3504 | |
| 3505 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3506 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3507 | String callingPackage, int subId) { |
| 3508 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3509 | |
| 3510 | final long identity = Binder.clearCallingIdentity(); |
| 3511 | try { |
| 3512 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3513 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3514 | } finally { |
| 3515 | Binder.restoreCallingIdentity(identity); |
| 3516 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3517 | } |
| 3518 | |
| 3519 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3520 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3521 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3522 | |
| 3523 | final long identity = Binder.clearCallingIdentity(); |
| 3524 | try { |
| 3525 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3526 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3527 | } finally { |
| 3528 | Binder.restoreCallingIdentity(identity); |
| 3529 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3530 | } |
| 3531 | |
| 3532 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3533 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3534 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3535 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3536 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3537 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3538 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3539 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3540 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3541 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3542 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3543 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3544 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3545 | * Sets the voice activation state of a given subId. |
| 3546 | */ |
| 3547 | @Override |
| 3548 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3549 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3550 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3551 | |
| 3552 | final long identity = Binder.clearCallingIdentity(); |
| 3553 | try { |
| 3554 | final Phone phone = getPhone(subId); |
| 3555 | if (phone != null) { |
| 3556 | phone.setVoiceActivationState(activationState); |
| 3557 | } else { |
| 3558 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3559 | } |
| 3560 | } finally { |
| 3561 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3562 | } |
| 3563 | } |
| 3564 | |
| 3565 | /** |
| 3566 | * Sets the data activation state of a given subId. |
| 3567 | */ |
| 3568 | @Override |
| 3569 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3570 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3571 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3572 | |
| 3573 | final long identity = Binder.clearCallingIdentity(); |
| 3574 | try { |
| 3575 | final Phone phone = getPhone(subId); |
| 3576 | if (phone != null) { |
| 3577 | phone.setDataActivationState(activationState); |
| 3578 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3579 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3580 | } |
| 3581 | } finally { |
| 3582 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3583 | } |
| 3584 | } |
| 3585 | |
| 3586 | /** |
| 3587 | * Returns the voice activation state of a given subId. |
| 3588 | */ |
| 3589 | @Override |
| 3590 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3591 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3592 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3593 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3594 | final long identity = Binder.clearCallingIdentity(); |
| 3595 | try { |
| 3596 | if (phone != null) { |
| 3597 | return phone.getVoiceActivationState(); |
| 3598 | } else { |
| 3599 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3600 | } |
| 3601 | } finally { |
| 3602 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3603 | } |
| 3604 | } |
| 3605 | |
| 3606 | /** |
| 3607 | * Returns the data activation state of a given subId. |
| 3608 | */ |
| 3609 | @Override |
| 3610 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3611 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3612 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3613 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3614 | final long identity = Binder.clearCallingIdentity(); |
| 3615 | try { |
| 3616 | if (phone != null) { |
| 3617 | return phone.getDataActivationState(); |
| 3618 | } else { |
| 3619 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3620 | } |
| 3621 | } finally { |
| 3622 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3623 | } |
| 3624 | } |
| 3625 | |
| 3626 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3627 | * Returns the unread count of voicemails for a subId |
| 3628 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3629 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3630 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3631 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3632 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3633 | mApp, subId, callingPackage, callingFeatureId, |
| 3634 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3635 | return 0; |
| 3636 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3637 | final long identity = Binder.clearCallingIdentity(); |
| 3638 | try { |
| 3639 | final Phone phone = getPhone(subId); |
| 3640 | if (phone != null) { |
| 3641 | return phone.getVoiceMessageCount(); |
| 3642 | } else { |
| 3643 | return 0; |
| 3644 | } |
| 3645 | } finally { |
| 3646 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3647 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3648 | } |
| 3649 | |
| 3650 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3651 | * returns true, if the device is in a state where both voice and data |
| 3652 | * are supported simultaneously. This can change based on location or network condition. |
| 3653 | */ |
| 3654 | @Override |
| 3655 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3656 | final long identity = Binder.clearCallingIdentity(); |
| 3657 | try { |
| 3658 | final Phone phone = getPhone(subId); |
| 3659 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3660 | } finally { |
| 3661 | Binder.restoreCallingIdentity(identity); |
| 3662 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3663 | } |
| 3664 | |
| 3665 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3666 | * Send the dialer code if called from the current default dialer or the caller has |
| 3667 | * carrier privilege. |
| 3668 | * @param inputCode The dialer code to send |
| 3669 | */ |
| 3670 | @Override |
| 3671 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3672 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3673 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3674 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3675 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3676 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3677 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3678 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3679 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3680 | |
| 3681 | final long identity = Binder.clearCallingIdentity(); |
| 3682 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3683 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3684 | } finally { |
| 3685 | Binder.restoreCallingIdentity(identity); |
| 3686 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3687 | } |
| 3688 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3689 | @Override |
| 3690 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3691 | TelephonyPermissions |
| 3692 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3693 | mApp, subId, "getNetworkSelectionMode"); |
| 3694 | final long identity = Binder.clearCallingIdentity(); |
| 3695 | try { |
| 3696 | if (!isActiveSubscription(subId)) { |
| 3697 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3698 | } |
| 3699 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3700 | } finally { |
| 3701 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3702 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3703 | } |
| 3704 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3705 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3706 | public boolean isInEmergencySmsMode() { |
| 3707 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3708 | final long identity = Binder.clearCallingIdentity(); |
| 3709 | try { |
| 3710 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3711 | if (phone.isInEmergencySmsMode()) { |
| 3712 | return true; |
| 3713 | } |
| 3714 | } |
| 3715 | } finally { |
| 3716 | Binder.restoreCallingIdentity(identity); |
| 3717 | } |
| 3718 | return false; |
| 3719 | } |
| 3720 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3721 | /** |
| 3722 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3723 | * @param subId The subscription to use to check the configuration. |
| 3724 | * @param c The callback that will be used to send the result. |
| 3725 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3726 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3727 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3728 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3729 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3730 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3731 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3732 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3733 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3734 | "IMS not available on device."); |
| 3735 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3736 | final long token = Binder.clearCallingIdentity(); |
| 3737 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3738 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3739 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3740 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3741 | } catch (ImsException e) { |
| 3742 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3743 | } finally { |
| 3744 | Binder.restoreCallingIdentity(token); |
| 3745 | } |
| 3746 | } |
| 3747 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3748 | /** |
| 3749 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3750 | * @param subId The subscription to use to check the configuration. |
| 3751 | * @param c The callback that will be used to send the result. |
| 3752 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3753 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3754 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3755 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3756 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3757 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3758 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3759 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3760 | final long token = Binder.clearCallingIdentity(); |
| 3761 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3762 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3763 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3764 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3765 | } catch (ImsException e) { |
| 3766 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3767 | + "is inactive, ignoring unregister."); |
| 3768 | // If the subscription is no longer active, just return, since the callback |
| 3769 | // will already have been removed internally. |
| 3770 | } finally { |
| 3771 | Binder.restoreCallingIdentity(token); |
| 3772 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3773 | } |
| 3774 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3775 | /** |
| 3776 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3777 | */ |
| 3778 | @Override |
| 3779 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3780 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3781 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3782 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3783 | "IMS not available on device."); |
| 3784 | } |
| 3785 | final long token = Binder.clearCallingIdentity(); |
| 3786 | try { |
| 3787 | Phone phone = getPhone(subId); |
| 3788 | if (phone == null) { |
| 3789 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3790 | + subId + "'"); |
| 3791 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3792 | } |
| 3793 | phone.getImsRegistrationState(regState -> { |
| 3794 | try { |
| 3795 | consumer.accept((regState == null) |
| 3796 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3797 | } catch (RemoteException e) { |
| 3798 | // Ignore if the remote process is no longer available to call back. |
| 3799 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3800 | } |
| 3801 | }); |
| 3802 | } finally { |
| 3803 | Binder.restoreCallingIdentity(token); |
| 3804 | } |
| 3805 | } |
| 3806 | |
| 3807 | /** |
| 3808 | * Get the transport type for the IMS service registration state. |
| 3809 | */ |
| 3810 | @Override |
| 3811 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3812 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3813 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3814 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3815 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3816 | "IMS not available on device."); |
| 3817 | } |
| 3818 | final long token = Binder.clearCallingIdentity(); |
| 3819 | try { |
| 3820 | Phone phone = getPhone(subId); |
| 3821 | if (phone == null) { |
| 3822 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3823 | + subId + "'"); |
| 3824 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3825 | } |
| 3826 | phone.getImsRegistrationTech(regTech -> { |
| 3827 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3828 | int regTechConverted = (regTech == null) |
| 3829 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3830 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3831 | regTechConverted); |
| 3832 | try { |
| 3833 | consumer.accept(regTechConverted); |
| 3834 | } catch (RemoteException e) { |
| 3835 | // Ignore if the remote process is no longer available to call back. |
| 3836 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3837 | } |
| 3838 | }); |
| 3839 | } finally { |
| 3840 | Binder.restoreCallingIdentity(token); |
| 3841 | } |
| 3842 | } |
| 3843 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3844 | /** |
| 3845 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3846 | * @param subId The subscription to use to check the configuration. |
| 3847 | * @param c The callback that will be used to send the result. |
| 3848 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3849 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3850 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3851 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3852 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3853 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3854 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3855 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3856 | "IMS not available on device."); |
| 3857 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3858 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3859 | final long token = Binder.clearCallingIdentity(); |
| 3860 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3861 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3862 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3863 | } catch (ImsException e) { |
| 3864 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3865 | } finally { |
| 3866 | Binder.restoreCallingIdentity(token); |
| 3867 | } |
| 3868 | } |
| 3869 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3870 | /** |
| 3871 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3872 | * @param subId The subscription to use to check the configuration. |
| 3873 | * @param c The callback that will be used to send the result. |
| 3874 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3875 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3876 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3877 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3878 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3879 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3880 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3881 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3882 | |
| 3883 | final long token = Binder.clearCallingIdentity(); |
| 3884 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3885 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3886 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3887 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3888 | } catch (ImsException e) { |
| 3889 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3890 | + "is inactive, ignoring unregister."); |
| 3891 | // If the subscription is no longer active, just return, since the callback |
| 3892 | // will already have been removed internally. |
| 3893 | } finally { |
| 3894 | Binder.restoreCallingIdentity(token); |
| 3895 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3896 | } |
| 3897 | |
| 3898 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3899 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3900 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3901 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3902 | final long token = Binder.clearCallingIdentity(); |
| 3903 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3904 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3905 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3906 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3907 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3908 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3909 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3910 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3911 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3912 | } finally { |
| 3913 | Binder.restoreCallingIdentity(token); |
| 3914 | } |
| 3915 | } |
| 3916 | |
| 3917 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3918 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3919 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3920 | final long token = Binder.clearCallingIdentity(); |
| 3921 | try { |
| 3922 | Phone phone = getPhone(subId); |
| 3923 | if (phone == null) return false; |
| 3924 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3925 | } catch (com.android.ims.ImsException e) { |
| 3926 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3927 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3928 | } finally { |
| 3929 | Binder.restoreCallingIdentity(token); |
| 3930 | } |
| 3931 | } |
| 3932 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3933 | /** |
| 3934 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3935 | * subscription. |
| 3936 | * @param subId The subscription to use to check the configuration. |
| 3937 | * @param callback The callback that will be used to send the result. |
| 3938 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3939 | * @param transportType The transport type of the MmTelFeature capability. |
| 3940 | */ |
| 3941 | @Override |
| 3942 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3943 | int transportType) { |
| 3944 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3945 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3946 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3947 | "IMS not available on device."); |
| 3948 | } |
| 3949 | final long token = Binder.clearCallingIdentity(); |
| 3950 | try { |
| 3951 | int slotId = getSlotIndex(subId); |
| 3952 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3953 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3954 | + subId + "'"); |
| 3955 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3956 | } |
| 3957 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3958 | transportType, aBoolean -> { |
| 3959 | try { |
| 3960 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3961 | } catch (RemoteException e) { |
| 3962 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3963 | + "running. Ignore"); |
| 3964 | } |
| 3965 | }); |
| 3966 | } finally { |
| 3967 | Binder.restoreCallingIdentity(token); |
| 3968 | } |
| 3969 | } |
| 3970 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3971 | /** |
| 3972 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3973 | * @param subId The subscription to use to check the configuration. |
| 3974 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3975 | @Override |
| 3976 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3977 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3978 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3979 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3980 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3981 | final long token = Binder.clearCallingIdentity(); |
| 3982 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3983 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3984 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3985 | } catch (ImsException e) { |
| 3986 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3987 | } finally { |
| 3988 | Binder.restoreCallingIdentity(token); |
| 3989 | } |
| 3990 | } |
| 3991 | |
| 3992 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3993 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3994 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3995 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3996 | final long identity = Binder.clearCallingIdentity(); |
| 3997 | try { |
| 3998 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3999 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4000 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4001 | } catch (ImsException e) { |
| 4002 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4003 | } finally { |
| 4004 | Binder.restoreCallingIdentity(identity); |
| 4005 | } |
| 4006 | } |
| 4007 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4008 | /** |
| 4009 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4010 | * @param subId The subscription to use to check the configuration. |
| 4011 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4012 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4013 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4014 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4015 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4016 | final long identity = Binder.clearCallingIdentity(); |
| 4017 | try { |
| 4018 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4019 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 4020 | } catch (ImsException e) { |
| 4021 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4022 | } finally { |
| 4023 | Binder.restoreCallingIdentity(identity); |
| 4024 | } |
| 4025 | } |
| 4026 | |
| 4027 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4028 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4029 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4030 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4031 | final long identity = Binder.clearCallingIdentity(); |
| 4032 | try { |
| 4033 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4034 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4035 | } catch (ImsException e) { |
| 4036 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4037 | } finally { |
| 4038 | Binder.restoreCallingIdentity(identity); |
| 4039 | } |
| 4040 | } |
| 4041 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4042 | /** |
| 4043 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4044 | * @param subId The subscription to use to check the configuration. |
| 4045 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4046 | @Override |
| 4047 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4048 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4049 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4050 | final long identity = Binder.clearCallingIdentity(); |
| 4051 | try { |
| 4052 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4053 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4054 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4055 | } catch (ImsException e) { |
| 4056 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4057 | } finally { |
| 4058 | Binder.restoreCallingIdentity(identity); |
| 4059 | } |
| 4060 | } |
| 4061 | |
| 4062 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4063 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4064 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4065 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4066 | final long identity = Binder.clearCallingIdentity(); |
| 4067 | try { |
| 4068 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4069 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4070 | } catch (ImsException e) { |
| 4071 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4072 | } finally { |
| 4073 | Binder.restoreCallingIdentity(identity); |
| 4074 | } |
| 4075 | } |
| 4076 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4077 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4078 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4079 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4080 | * @param subId The subscription to use to check the configuration. |
| 4081 | */ |
| 4082 | @Override |
| 4083 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
| 4084 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4085 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4086 | final long identity = Binder.clearCallingIdentity(); |
| 4087 | try { |
| 4088 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4089 | return ImsManager.getInstance(mApp, |
| 4090 | getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser(); |
| 4091 | } catch (ImsException e) { |
| 4092 | throw new ServiceSpecificException(e.getCode()); |
| 4093 | } finally { |
| 4094 | Binder.restoreCallingIdentity(identity); |
| 4095 | } |
| 4096 | } |
| 4097 | |
| 4098 | /** |
| 4099 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4100 | * Requires MODIFY_PHONE_STATE permission. |
| 4101 | * @param subId The subscription to use to check the configuration. |
| 4102 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4103 | * false otherwise |
| 4104 | */ |
| 4105 | @Override |
| 4106 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4107 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4108 | "setCrossSimCallingEnabled"); |
| 4109 | final long identity = Binder.clearCallingIdentity(); |
| 4110 | try { |
| 4111 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4112 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 4113 | .setCrossSimCallingEnabled(isEnabled); |
| 4114 | } catch (ImsException e) { |
| 4115 | throw new ServiceSpecificException(e.getCode()); |
| 4116 | } finally { |
| 4117 | Binder.restoreCallingIdentity(identity); |
| 4118 | } |
| 4119 | } |
| 4120 | |
| 4121 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4122 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4123 | * @param subId The subscription to use to check the configuration. |
| 4124 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4125 | @Override |
| 4126 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4127 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4128 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4129 | final long identity = Binder.clearCallingIdentity(); |
| 4130 | try { |
| 4131 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4132 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4133 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4134 | } catch (ImsException e) { |
| 4135 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4136 | } finally { |
| 4137 | Binder.restoreCallingIdentity(identity); |
| 4138 | } |
| 4139 | } |
| 4140 | |
| 4141 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4142 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4143 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4144 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4145 | final long identity = Binder.clearCallingIdentity(); |
| 4146 | try { |
| 4147 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4148 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4149 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4150 | } catch (ImsException e) { |
| 4151 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4152 | } finally { |
| 4153 | Binder.restoreCallingIdentity(identity); |
| 4154 | } |
| 4155 | } |
| 4156 | |
| 4157 | @Override |
| 4158 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4159 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4160 | "setVoWiFiNonPersistent"); |
| 4161 | final long identity = Binder.clearCallingIdentity(); |
| 4162 | try { |
| 4163 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4164 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 4165 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4166 | } catch (ImsException e) { |
| 4167 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4168 | } finally { |
| 4169 | Binder.restoreCallingIdentity(identity); |
| 4170 | } |
| 4171 | } |
| 4172 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4173 | /** |
| 4174 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4175 | * @param subId The subscription to use to check the configuration. |
| 4176 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4177 | @Override |
| 4178 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4179 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4180 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4181 | final long identity = Binder.clearCallingIdentity(); |
| 4182 | try { |
| 4183 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4184 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4185 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4186 | } catch (ImsException e) { |
| 4187 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4188 | } finally { |
| 4189 | Binder.restoreCallingIdentity(identity); |
| 4190 | } |
| 4191 | } |
| 4192 | |
| 4193 | @Override |
| 4194 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4195 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4196 | "setVoWiFiModeSetting"); |
| 4197 | final long identity = Binder.clearCallingIdentity(); |
| 4198 | try { |
| 4199 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4200 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4201 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4202 | } catch (ImsException e) { |
| 4203 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4204 | } finally { |
| 4205 | Binder.restoreCallingIdentity(identity); |
| 4206 | } |
| 4207 | } |
| 4208 | |
| 4209 | @Override |
| 4210 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4211 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4212 | final long identity = Binder.clearCallingIdentity(); |
| 4213 | try { |
| 4214 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4215 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4216 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4217 | } catch (ImsException e) { |
| 4218 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4219 | } finally { |
| 4220 | Binder.restoreCallingIdentity(identity); |
| 4221 | } |
| 4222 | } |
| 4223 | |
| 4224 | @Override |
| 4225 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4226 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4227 | "setVoWiFiRoamingModeSetting"); |
| 4228 | final long identity = Binder.clearCallingIdentity(); |
| 4229 | try { |
| 4230 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4231 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4232 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4233 | } catch (ImsException e) { |
| 4234 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4235 | } finally { |
| 4236 | Binder.restoreCallingIdentity(identity); |
| 4237 | } |
| 4238 | } |
| 4239 | |
| 4240 | @Override |
| 4241 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4242 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4243 | "setRttCapabilityEnabled"); |
| 4244 | final long identity = Binder.clearCallingIdentity(); |
| 4245 | try { |
| 4246 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4247 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 4248 | } catch (ImsException e) { |
| 4249 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4250 | } finally { |
| 4251 | Binder.restoreCallingIdentity(identity); |
| 4252 | } |
| 4253 | } |
| 4254 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4255 | /** |
| 4256 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4257 | * @param subId The subscription to use to check the configuration. |
| 4258 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4259 | @Override |
| 4260 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4261 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4262 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4263 | final long identity = Binder.clearCallingIdentity(); |
| 4264 | try { |
| 4265 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4266 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4267 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4268 | } catch (ImsException e) { |
| 4269 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4270 | } finally { |
| 4271 | Binder.restoreCallingIdentity(identity); |
| 4272 | } |
| 4273 | } |
| 4274 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4275 | @Override |
| 4276 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4277 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4278 | final long identity = Binder.clearCallingIdentity(); |
| 4279 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4280 | if (!isImsAvailableOnDevice()) { |
| 4281 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4282 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4283 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4284 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4285 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4286 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4287 | } catch (ImsException e) { |
| 4288 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4289 | } finally { |
| 4290 | Binder.restoreCallingIdentity(identity); |
| 4291 | } |
| 4292 | } |
| 4293 | |
| 4294 | @Override |
| 4295 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4296 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4297 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4298 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4299 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4300 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4301 | try { |
| 4302 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4303 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4304 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4305 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4306 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4307 | + "is inactive, ignoring unregister."); |
| 4308 | // If the subscription is no longer active, just return, since the callback will already |
| 4309 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4310 | } finally { |
| 4311 | Binder.restoreCallingIdentity(identity); |
| 4312 | } |
| 4313 | } |
| 4314 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4315 | |
| 4316 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4317 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4318 | message); |
| 4319 | } |
| 4320 | |
| 4321 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4322 | boolean isMmtelCapability) { |
| 4323 | Phone phone = getPhone(subId); |
| 4324 | if (phone == null) { |
| 4325 | loge("phone instance null for subid " + subId); |
| 4326 | return false; |
| 4327 | } |
| 4328 | if (isMmtelCapability) { |
| 4329 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4330 | return false; |
| 4331 | } |
| 4332 | } else { |
| 4333 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4334 | return false; |
| 4335 | } |
| 4336 | } |
| 4337 | return true; |
| 4338 | } |
| 4339 | |
| 4340 | @Override |
| 4341 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4342 | boolean isProvisioned) { |
| 4343 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4344 | |
| 4345 | final long identity = Binder.clearCallingIdentity(); |
| 4346 | try { |
| 4347 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4348 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4349 | return; |
| 4350 | } |
| 4351 | |
| 4352 | // this capability requires provisioning, route to the correct API. |
| 4353 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4354 | switch (capability) { |
| 4355 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4356 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4357 | ims.setEabProvisioned(isProvisioned); |
| 4358 | break; |
| 4359 | default: { |
| 4360 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4361 | + "rcs capability '" + capability + "', which does not require " |
| 4362 | + "provisioning."); |
| 4363 | } |
| 4364 | } |
| 4365 | } finally { |
| 4366 | Binder.restoreCallingIdentity(identity); |
| 4367 | } |
| 4368 | |
| 4369 | } |
| 4370 | |
| 4371 | |
| 4372 | @Override |
| 4373 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4374 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4375 | final long identity = Binder.clearCallingIdentity(); |
| 4376 | try { |
| 4377 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4378 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4379 | return true; |
| 4380 | } |
| 4381 | |
| 4382 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4383 | switch (capability) { |
| 4384 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4385 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4386 | return ims.isEabProvisionedOnDevice(); |
| 4387 | |
| 4388 | default: { |
| 4389 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4390 | + "capability '" + capability + "', which does not require " |
| 4391 | + "provisioning."); |
| 4392 | } |
| 4393 | } |
| 4394 | |
| 4395 | } finally { |
| 4396 | Binder.restoreCallingIdentity(identity); |
| 4397 | } |
| 4398 | } |
| 4399 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4400 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4401 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4402 | boolean isProvisioned) { |
| 4403 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4404 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4405 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4406 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4407 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4408 | final long identity = Binder.clearCallingIdentity(); |
| 4409 | try { |
| 4410 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4411 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4412 | return; |
| 4413 | } |
| 4414 | |
| 4415 | // this capability requires provisioning, route to the correct API. |
| 4416 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4417 | switch (capability) { |
| 4418 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4419 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4420 | ims.setVolteProvisioned(isProvisioned); |
| 4421 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4422 | ims.setWfcProvisioned(isProvisioned); |
| 4423 | } |
| 4424 | break; |
| 4425 | } |
| 4426 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4427 | // There is currently no difference in VT provisioning type. |
| 4428 | ims.setVtProvisioned(isProvisioned); |
| 4429 | break; |
| 4430 | } |
| 4431 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4432 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4433 | // change the capability of the feature instead if needed. |
| 4434 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4435 | == isProvisioned) { |
| 4436 | // No change in provisioning. |
| 4437 | return; |
| 4438 | } |
| 4439 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4440 | try { |
| 4441 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4442 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4443 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4444 | + ", Exception" + e.getMessage()); |
| 4445 | } |
| 4446 | break; |
| 4447 | } |
| 4448 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4449 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4450 | + "MmTel capability '" + capability + "', which does not require " |
| 4451 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4452 | } |
| 4453 | } |
| 4454 | |
| 4455 | } finally { |
| 4456 | Binder.restoreCallingIdentity(identity); |
| 4457 | } |
| 4458 | } |
| 4459 | |
| 4460 | @Override |
| 4461 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4462 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4463 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4464 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4465 | } |
| 4466 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4467 | final long identity = Binder.clearCallingIdentity(); |
| 4468 | try { |
| 4469 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4470 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4471 | return true; |
| 4472 | } |
| 4473 | |
| 4474 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4475 | switch (capability) { |
| 4476 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4477 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4478 | return ims.isVolteProvisionedOnDevice(); |
| 4479 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4480 | return ims.isWfcProvisionedOnDevice(); |
| 4481 | } |
| 4482 | // This should never happen, since we are checking tech above to make sure it |
| 4483 | // is either LTE or IWLAN. |
| 4484 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4485 | + "capability."); |
| 4486 | } |
| 4487 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4488 | // There is currently no difference in VT provisioning type. |
| 4489 | return ims.isVtProvisionedOnDevice(); |
| 4490 | } |
| 4491 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4492 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4493 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4494 | } |
| 4495 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4496 | throw new IllegalArgumentException( |
| 4497 | "Tried to get provisioning for MmTel capability '" + capability |
| 4498 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4499 | } |
| 4500 | } |
| 4501 | |
| 4502 | } finally { |
| 4503 | Binder.restoreCallingIdentity(identity); |
| 4504 | } |
| 4505 | } |
| 4506 | |
| 4507 | @Override |
| 4508 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4509 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4510 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4511 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4512 | } |
| 4513 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4514 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4515 | return (provisionedBits & capability) > 0; |
| 4516 | } |
| 4517 | |
| 4518 | @Override |
| 4519 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4520 | boolean isProvisioned) { |
| 4521 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4522 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4523 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4524 | } |
| 4525 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4526 | "setProvisioningStatusForCapability"); |
| 4527 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4528 | // If the current provisioning status for capability already matches isProvisioned, |
| 4529 | // do nothing. |
| 4530 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4531 | return; |
| 4532 | } |
| 4533 | if (isProvisioned) { |
| 4534 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4535 | } else { |
| 4536 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4537 | } |
| 4538 | } |
| 4539 | |
| 4540 | /** |
| 4541 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4542 | * technology. The bitfield should mirror the bitfield defined by |
| 4543 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4544 | */ |
| 4545 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4546 | String key = getMmTelProvisioningKey(subId, tech); |
| 4547 | // Default is no capabilities are provisioned. |
| 4548 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4549 | } |
| 4550 | |
| 4551 | /** |
| 4552 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4553 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4554 | * technology specified. |
| 4555 | * |
| 4556 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4557 | */ |
| 4558 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4559 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4560 | String key = getMmTelProvisioningKey(subId, tech); |
| 4561 | editor.putInt(key, newField); |
| 4562 | editor.commit(); |
| 4563 | } |
| 4564 | |
| 4565 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4566 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4567 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4568 | } |
| 4569 | |
| 4570 | /** |
| 4571 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4572 | * carrier associated with the subscription id. |
| 4573 | */ |
| 4574 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4575 | int capability) { |
| 4576 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4577 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4578 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4579 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4580 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4581 | false); |
| 4582 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4583 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4584 | |
| 4585 | // First check to make sure that the capability requires provisioning. |
| 4586 | switch (capability) { |
| 4587 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4588 | // intentional fallthrough |
| 4589 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4590 | if (requireVoiceVtProvisioning) { |
| 4591 | // Voice and Video requires provisioning |
| 4592 | return true; |
| 4593 | } |
| 4594 | break; |
| 4595 | } |
| 4596 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4597 | if (requireUtProvisioning) { |
| 4598 | // UT requires provisioning |
| 4599 | return true; |
| 4600 | } |
| 4601 | break; |
| 4602 | } |
| 4603 | } |
| 4604 | return false; |
| 4605 | } |
| 4606 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4607 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4608 | int capability) { |
| 4609 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4610 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4611 | |
| 4612 | boolean requireRcsProvisioning = c.getBoolean( |
| 4613 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4614 | |
| 4615 | // First check to make sure that the capability requires provisioning. |
| 4616 | switch (capability) { |
| 4617 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4618 | // intentional fallthrough |
| 4619 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4620 | if (requireRcsProvisioning) { |
| 4621 | // OPTION or PRESENCE requires provisioning |
| 4622 | return true; |
| 4623 | } |
| 4624 | break; |
| 4625 | } |
| 4626 | } |
| 4627 | return false; |
| 4628 | } |
| 4629 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4630 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4631 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4632 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4633 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4634 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4635 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4636 | final long identity = Binder.clearCallingIdentity(); |
| 4637 | try { |
| 4638 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4639 | int slotId = getSlotIndex(subId); |
| 4640 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4641 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4642 | + subId + "' for key:" + key); |
| 4643 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4644 | } |
| 4645 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4646 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4647 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4648 | + subId + "' for key:" + key); |
| 4649 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4650 | } finally { |
| 4651 | Binder.restoreCallingIdentity(identity); |
| 4652 | } |
| 4653 | } |
| 4654 | |
| 4655 | @Override |
| 4656 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4657 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4658 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4659 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4660 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4661 | final long identity = Binder.clearCallingIdentity(); |
| 4662 | try { |
| 4663 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4664 | int slotId = getSlotIndex(subId); |
| 4665 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4666 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4667 | + subId + "' for key:" + key); |
| 4668 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4669 | } |
| 4670 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4671 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4672 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4673 | + subId + "' for key:" + key); |
| 4674 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4675 | } finally { |
| 4676 | Binder.restoreCallingIdentity(identity); |
| 4677 | } |
| 4678 | } |
| 4679 | |
| 4680 | @Override |
| 4681 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4682 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4683 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4684 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4685 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4686 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4687 | final long identity = Binder.clearCallingIdentity(); |
| 4688 | try { |
| 4689 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4690 | int slotId = getSlotIndex(subId); |
| 4691 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4692 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4693 | + subId + "' for key:" + key); |
| 4694 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4695 | } |
| 4696 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4697 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4698 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4699 | + "' for key:" + key); |
| 4700 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4701 | } finally { |
| 4702 | Binder.restoreCallingIdentity(identity); |
| 4703 | } |
| 4704 | } |
| 4705 | |
| 4706 | @Override |
| 4707 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4708 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4709 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4710 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4711 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4712 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4713 | final long identity = Binder.clearCallingIdentity(); |
| 4714 | try { |
| 4715 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4716 | int slotId = getSlotIndex(subId); |
| 4717 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4718 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4719 | + subId + "' for key:" + key); |
| 4720 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4721 | } |
| 4722 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4723 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4724 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4725 | + "' for key:" + key); |
| 4726 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4727 | } finally { |
| 4728 | Binder.restoreCallingIdentity(identity); |
| 4729 | } |
| 4730 | } |
| 4731 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4732 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4733 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4734 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4735 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4736 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4737 | } |
| 4738 | return slotId; |
| 4739 | } |
| 4740 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4741 | private int getSlotIndex(int subId) { |
| 4742 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4743 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4744 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4745 | } |
| 4746 | return slotId; |
| 4747 | } |
| 4748 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4749 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4750 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4751 | */ |
| 4752 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4753 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4754 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4755 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4756 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4757 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4758 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4759 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4760 | mApp, subId, callingPackage, callingFeatureId, |
| 4761 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4762 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4763 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4764 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4765 | final long identity = Binder.clearCallingIdentity(); |
| 4766 | try { |
| 4767 | final Phone phone = getPhone(subId); |
| 4768 | if (phone != null) { |
| 4769 | return phone.getServiceState().getDataNetworkType(); |
| 4770 | } else { |
| 4771 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4772 | } |
| 4773 | } finally { |
| 4774 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4775 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4776 | } |
| 4777 | |
| 4778 | /** |
| 4779 | * Returns the data network type |
| 4780 | */ |
| 4781 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4782 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4783 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4784 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4785 | } |
| 4786 | |
| 4787 | /** |
| 4788 | * Returns the data network type for a subId |
| 4789 | */ |
| 4790 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4791 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4792 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4793 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4794 | mApp, subId, callingPackage, callingFeatureId, |
| 4795 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4796 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4797 | } |
| 4798 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4799 | final long identity = Binder.clearCallingIdentity(); |
| 4800 | try { |
| 4801 | final Phone phone = getPhone(subId); |
| 4802 | if (phone != null) { |
| 4803 | return phone.getServiceState().getDataNetworkType(); |
| 4804 | } else { |
| 4805 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4806 | } |
| 4807 | } finally { |
| 4808 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4809 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4810 | } |
| 4811 | |
| 4812 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4813 | * Returns the Voice network type for a subId |
| 4814 | */ |
| 4815 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4816 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4817 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4818 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4819 | mApp, subId, callingPackage, callingFeatureId, |
| 4820 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4821 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4822 | } |
| 4823 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4824 | final long identity = Binder.clearCallingIdentity(); |
| 4825 | try { |
| 4826 | final Phone phone = getPhone(subId); |
| 4827 | if (phone != null) { |
| 4828 | return phone.getServiceState().getVoiceNetworkType(); |
| 4829 | } else { |
| 4830 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4831 | } |
| 4832 | } finally { |
| 4833 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4834 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4835 | } |
| 4836 | |
| 4837 | /** |
| 4838 | * @return true if a ICC card is present |
| 4839 | */ |
| 4840 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4841 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4842 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4843 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4844 | } |
| 4845 | |
| 4846 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4847 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4848 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4849 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4850 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4851 | final long identity = Binder.clearCallingIdentity(); |
| 4852 | try { |
| 4853 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4854 | if (phone != null) { |
| 4855 | return phone.getIccCard().hasIccCard(); |
| 4856 | } else { |
| 4857 | return false; |
| 4858 | } |
| 4859 | } finally { |
| 4860 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4861 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4862 | } |
| 4863 | |
| 4864 | /** |
| 4865 | * Return if the current radio is LTE on CDMA. This |
| 4866 | * is a tri-state return value as for a period of time |
| 4867 | * the mode may be unknown. |
| 4868 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4869 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4870 | * @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] | 4871 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4872 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4873 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4874 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4875 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4876 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4877 | } |
| 4878 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4879 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4880 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4881 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4882 | try { |
| 4883 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4884 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4885 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4886 | } |
| 4887 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4888 | final long identity = Binder.clearCallingIdentity(); |
| 4889 | try { |
| 4890 | final Phone phone = getPhone(subId); |
| 4891 | if (phone == null) { |
| 4892 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4893 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4894 | return TelephonyProperties.lte_on_cdma_device() |
| 4895 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4896 | } |
| 4897 | } finally { |
| 4898 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4899 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4900 | } |
| 4901 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4902 | /** |
| 4903 | * {@hide} |
| 4904 | * Returns Default subId, 0 in the case of single standby. |
| 4905 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4906 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4907 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4908 | } |
| 4909 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4910 | private int getSlotForDefaultSubscription() { |
| 4911 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4912 | } |
| 4913 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4914 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4915 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4916 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4917 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4918 | private boolean isActiveSubscription(int subId) { |
| 4919 | return mSubscriptionController.isActiveSubId(subId); |
| 4920 | } |
| 4921 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4922 | /** |
| 4923 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4924 | */ |
| 4925 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4926 | final long identity = Binder.clearCallingIdentity(); |
| 4927 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4928 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4929 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4930 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4931 | } finally { |
| 4932 | Binder.restoreCallingIdentity(identity); |
| 4933 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4934 | } |
| 4935 | |
| 4936 | /** |
| 4937 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4938 | */ |
| 4939 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4940 | final long identity = Binder.clearCallingIdentity(); |
| 4941 | try { |
| 4942 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4943 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4944 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4945 | } finally { |
| 4946 | Binder.restoreCallingIdentity(identity); |
| 4947 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4948 | } |
| 4949 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4950 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4951 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4952 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4953 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4954 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4955 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4956 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4957 | if (phoneId == -1) { |
| 4958 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4959 | + " does not correspond to an active phone"); |
| 4960 | } |
| 4961 | return PhoneFactory.getPhone(phoneId); |
| 4962 | } |
| 4963 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4964 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4965 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4966 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4967 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4968 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4969 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4970 | if (DBG) { |
| 4971 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4972 | } |
| 4973 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4974 | p2); |
| 4975 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4976 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4977 | |
| 4978 | @Override |
| 4979 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4980 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4981 | enforceModifyPermission(); |
| 4982 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4983 | if (DBG) { |
| 4984 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4985 | } |
| 4986 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4987 | callingPackage, aid, p2); |
| 4988 | } |
| 4989 | |
| 4990 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4991 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4992 | final long identity = Binder.clearCallingIdentity(); |
| 4993 | try { |
| 4994 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4995 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4996 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4997 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4998 | if (bestComponent == null |
| 4999 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5000 | loge("The calling package is not allowed to access ISD-R."); |
| 5001 | throw new SecurityException( |
| 5002 | "The calling package is not allowed to access ISD-R."); |
| 5003 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5004 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5005 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5006 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5007 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 5008 | null /* workSource */); |
| 5009 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5010 | return response; |
| 5011 | } finally { |
| 5012 | Binder.restoreCallingIdentity(identity); |
| 5013 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5014 | } |
| 5015 | |
| 5016 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5017 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5018 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5019 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5020 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 5021 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 5022 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5023 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5024 | @Override |
| 5025 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 5026 | enforceModifyPermission(); |
| 5027 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 5028 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 5029 | channel); |
| 5030 | } |
| 5031 | |
| 5032 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5033 | final long identity = Binder.clearCallingIdentity(); |
| 5034 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5035 | if (channel < 0) { |
| 5036 | return false; |
| 5037 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5038 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 5039 | null /* workSource */); |
| 5040 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5041 | return success; |
| 5042 | } finally { |
| 5043 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5044 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5045 | } |
| 5046 | |
| 5047 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5048 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5049 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5050 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5051 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5052 | if (DBG) { |
| 5053 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5054 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5055 | + p3 + " data=" + data); |
| 5056 | } |
| 5057 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5058 | command, p1, p2, p3, data); |
| 5059 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5060 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5061 | @Override |
| 5062 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 5063 | int command, int p1, int p2, int p3, String data) { |
| 5064 | enforceModifyPermission(); |
| 5065 | if (DBG) { |
| 5066 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 5067 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5068 | + p3 + " data=" + data); |
| 5069 | } |
| 5070 | return iccTransmitApduLogicalChannelWithPermission( |
| 5071 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 5072 | data); |
| 5073 | } |
| 5074 | |
| 5075 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5076 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5077 | final long identity = Binder.clearCallingIdentity(); |
| 5078 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5079 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5080 | return ""; |
| 5081 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5082 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5083 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5084 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5085 | null /* workSource */); |
| 5086 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5087 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5088 | // Append the returned status code to the end of the response payload. |
| 5089 | String s = Integer.toHexString( |
| 5090 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5091 | if (response.payload != null) { |
| 5092 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5093 | } |
| 5094 | return s; |
| 5095 | } finally { |
| 5096 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5097 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5098 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5099 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5100 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5101 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5102 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5103 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5104 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5105 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5106 | if (DBG) { |
| 5107 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5108 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5109 | } |
| 5110 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5111 | cla, command, p1, p2, p3, data); |
| 5112 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5113 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5114 | @Override |
| 5115 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 5116 | int command, int p1, int p2, int p3, String data) { |
| 5117 | enforceModifyPermission(); |
| 5118 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5119 | if (DBG) { |
| 5120 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 5121 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 5122 | + " data=" + data); |
| 5123 | } |
| 5124 | |
| 5125 | return iccTransmitApduBasicChannelWithPermission( |
| 5126 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 5127 | p2, p3, data); |
| 5128 | } |
| 5129 | |
| 5130 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5131 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5132 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5133 | final long identity = Binder.clearCallingIdentity(); |
| 5134 | try { |
| 5135 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5136 | && TextUtils.equals(ISDR_AID, data)) { |
| 5137 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5138 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5139 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5140 | if (bestComponent == null |
| 5141 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5142 | loge("The calling package is not allowed to select ISD-R."); |
| 5143 | throw new SecurityException( |
| 5144 | "The calling package is not allowed to select ISD-R."); |
| 5145 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5146 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5147 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5148 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5149 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5150 | null /* workSource */); |
| 5151 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5152 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5153 | // Append the returned status code to the end of the response payload. |
| 5154 | String s = Integer.toHexString( |
| 5155 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5156 | if (response.payload != null) { |
| 5157 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5158 | } |
| 5159 | return s; |
| 5160 | } finally { |
| 5161 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5162 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5163 | } |
| 5164 | |
| 5165 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5166 | 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] | 5167 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5168 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5169 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5170 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5171 | final long identity = Binder.clearCallingIdentity(); |
| 5172 | try { |
| 5173 | if (DBG) { |
| 5174 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5175 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5176 | } |
| 5177 | |
| 5178 | IccIoResult response = |
| 5179 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5180 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5181 | subId); |
| 5182 | |
| 5183 | if (DBG) { |
| 5184 | log("Exchange SIM_IO [R]" + response); |
| 5185 | } |
| 5186 | |
| 5187 | byte[] result = null; |
| 5188 | int length = 2; |
| 5189 | if (response.payload != null) { |
| 5190 | length = 2 + response.payload.length; |
| 5191 | result = new byte[length]; |
| 5192 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5193 | } else { |
| 5194 | result = new byte[length]; |
| 5195 | } |
| 5196 | |
| 5197 | result[length - 1] = (byte) response.sw2; |
| 5198 | result[length - 2] = (byte) response.sw1; |
| 5199 | return result; |
| 5200 | } finally { |
| 5201 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5202 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5203 | } |
| 5204 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5205 | /** |
| 5206 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5207 | * on a particular subscription |
| 5208 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5209 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5210 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5211 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5212 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5213 | return null; |
| 5214 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5215 | |
| 5216 | final long identity = Binder.clearCallingIdentity(); |
| 5217 | try { |
| 5218 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5219 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5220 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5221 | return null; |
| 5222 | } |
| 5223 | Object response = sendRequest( |
| 5224 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5225 | if (response instanceof String[]) { |
| 5226 | return (String[]) response; |
| 5227 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5228 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5229 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5230 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5231 | } finally { |
| 5232 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5233 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5234 | } |
| 5235 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5236 | /** |
| 5237 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5238 | * subscription. |
| 5239 | * |
| 5240 | * @param subId the id of the subscription. |
| 5241 | * @param appType the uicc app type, must be USIM or SIM. |
| 5242 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5243 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5244 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5245 | * @return number of fplmns that is successfully written to the SIM. |
| 5246 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5247 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5248 | String callingFeatureId) { |
| 5249 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 5250 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5251 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 5252 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 5253 | } |
| 5254 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5255 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5256 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5257 | } |
| 5258 | if (fplmns == null) { |
| 5259 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5260 | } |
| 5261 | for (String fplmn : fplmns) { |
| 5262 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5263 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5264 | } |
| 5265 | } |
| 5266 | final long identity = Binder.clearCallingIdentity(); |
| 5267 | try { |
| 5268 | Object response = sendRequest( |
| 5269 | CMD_SET_FORBIDDEN_PLMNS, |
| 5270 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5271 | subId); |
| 5272 | return (int) response; |
| 5273 | } finally { |
| 5274 | Binder.restoreCallingIdentity(identity); |
| 5275 | } |
| 5276 | } |
| 5277 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5278 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5279 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5280 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5281 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5282 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5283 | final long identity = Binder.clearCallingIdentity(); |
| 5284 | try { |
| 5285 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5286 | if (response.payload == null) { |
| 5287 | return ""; |
| 5288 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5289 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5290 | // Append the returned status code to the end of the response payload. |
| 5291 | String s = Integer.toHexString( |
| 5292 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5293 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5294 | return s; |
| 5295 | } finally { |
| 5296 | Binder.restoreCallingIdentity(identity); |
| 5297 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5298 | } |
| 5299 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5300 | /** |
| 5301 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5302 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5303 | * |
| 5304 | * @param itemID the ID of the item to read |
| 5305 | * @return the NV item as a String, or null on error. |
| 5306 | */ |
| 5307 | @Override |
| 5308 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5309 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5310 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5311 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5312 | |
| 5313 | final long identity = Binder.clearCallingIdentity(); |
| 5314 | try { |
| 5315 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5316 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5317 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5318 | return value; |
| 5319 | } finally { |
| 5320 | Binder.restoreCallingIdentity(identity); |
| 5321 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5322 | } |
| 5323 | |
| 5324 | /** |
| 5325 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5326 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5327 | * |
| 5328 | * @param itemID the ID of the item to read |
| 5329 | * @param itemValue the value to write, as a String |
| 5330 | * @return true on success; false on any failure |
| 5331 | */ |
| 5332 | @Override |
| 5333 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5334 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5335 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5336 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5337 | |
| 5338 | final long identity = Binder.clearCallingIdentity(); |
| 5339 | try { |
| 5340 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5341 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5342 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5343 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5344 | return success; |
| 5345 | } finally { |
| 5346 | Binder.restoreCallingIdentity(identity); |
| 5347 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5348 | } |
| 5349 | |
| 5350 | /** |
| 5351 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5352 | * Used for device configuration by some CDMA operators. |
| 5353 | * |
| 5354 | * @param preferredRoamingList byte array containing the new PRL |
| 5355 | * @return true on success; false on any failure |
| 5356 | */ |
| 5357 | @Override |
| 5358 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5359 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5360 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5361 | |
| 5362 | final long identity = Binder.clearCallingIdentity(); |
| 5363 | try { |
| 5364 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5365 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5366 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5367 | return success; |
| 5368 | } finally { |
| 5369 | Binder.restoreCallingIdentity(identity); |
| 5370 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5371 | } |
| 5372 | |
| 5373 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5374 | * 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] | 5375 | * Used for device configuration by some CDMA operators. |
| 5376 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5377 | * @param slotIndex - device slot. |
| 5378 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5379 | * @return true on success; false on any failure |
| 5380 | */ |
| 5381 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5382 | public boolean resetModemConfig(int slotIndex) { |
| 5383 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5384 | if (phone != null) { |
| 5385 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5386 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5387 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5388 | final long identity = Binder.clearCallingIdentity(); |
| 5389 | try { |
| 5390 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5391 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5392 | return success; |
| 5393 | } finally { |
| 5394 | Binder.restoreCallingIdentity(identity); |
| 5395 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5396 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5397 | return false; |
| 5398 | } |
| 5399 | |
| 5400 | /** |
| 5401 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5402 | * |
| 5403 | * @param slotIndex - device slot. |
| 5404 | * |
| 5405 | * @return true on success; false on any failure |
| 5406 | */ |
| 5407 | @Override |
| 5408 | public boolean rebootModem(int slotIndex) { |
| 5409 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5410 | if (phone != null) { |
| 5411 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5412 | mApp, phone.getSubId(), "rebootModem"); |
| 5413 | |
| 5414 | final long identity = Binder.clearCallingIdentity(); |
| 5415 | try { |
| 5416 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5417 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5418 | return success; |
| 5419 | } finally { |
| 5420 | Binder.restoreCallingIdentity(identity); |
| 5421 | } |
| 5422 | } |
| 5423 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5424 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5425 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5426 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5427 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5428 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5429 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5430 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5431 | return new String[0]; |
| 5432 | } |
| 5433 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5434 | final long identity = Binder.clearCallingIdentity(); |
| 5435 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5436 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5437 | } finally { |
| 5438 | Binder.restoreCallingIdentity(identity); |
| 5439 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5440 | } |
| 5441 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5442 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5443 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5444 | * {@link #disableIms(int)}. |
| 5445 | * @param slotIndex device slot. |
| 5446 | */ |
| 5447 | public void resetIms(int slotIndex) { |
| 5448 | enforceModifyPermission(); |
| 5449 | |
| 5450 | final long identity = Binder.clearCallingIdentity(); |
| 5451 | try { |
| 5452 | if (mImsResolver == null) { |
| 5453 | // may happen if the does not support IMS. |
| 5454 | return; |
| 5455 | } |
| 5456 | mImsResolver.disableIms(slotIndex); |
| 5457 | mImsResolver.enableIms(slotIndex); |
| 5458 | } finally { |
| 5459 | Binder.restoreCallingIdentity(identity); |
| 5460 | } |
| 5461 | } |
| 5462 | |
| 5463 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5464 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5465 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5466 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5467 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5468 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5469 | |
| 5470 | final long identity = Binder.clearCallingIdentity(); |
| 5471 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5472 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5473 | // may happen if the device does not support IMS. |
| 5474 | return; |
| 5475 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5476 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5477 | } finally { |
| 5478 | Binder.restoreCallingIdentity(identity); |
| 5479 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5480 | } |
| 5481 | |
| 5482 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5483 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5484 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5485 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5486 | public void disableIms(int slotId) { |
| 5487 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5488 | |
| 5489 | final long identity = Binder.clearCallingIdentity(); |
| 5490 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5491 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5492 | // may happen if the device does not support IMS. |
| 5493 | return; |
| 5494 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5495 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5496 | } finally { |
| 5497 | Binder.restoreCallingIdentity(identity); |
| 5498 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5499 | } |
| 5500 | |
| 5501 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5502 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5503 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5504 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5505 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5506 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5507 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5508 | |
| 5509 | final long identity = Binder.clearCallingIdentity(); |
| 5510 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5511 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5512 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5513 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5514 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5515 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5516 | } finally { |
| 5517 | Binder.restoreCallingIdentity(identity); |
| 5518 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5519 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5520 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5521 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5522 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5523 | @Override |
| 5524 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5525 | enforceModifyPermission(); |
| 5526 | |
| 5527 | final long identity = Binder.clearCallingIdentity(); |
| 5528 | try { |
| 5529 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5530 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5531 | } finally { |
| 5532 | Binder.restoreCallingIdentity(identity); |
| 5533 | } |
| 5534 | } |
| 5535 | |
| 5536 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5537 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5538 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5539 | */ |
| 5540 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5541 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5542 | |
| 5543 | final long identity = Binder.clearCallingIdentity(); |
| 5544 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5545 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5546 | // may happen if the device does not support IMS. |
| 5547 | return null; |
| 5548 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5549 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5550 | } finally { |
| 5551 | Binder.restoreCallingIdentity(identity); |
| 5552 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5553 | } |
| 5554 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5555 | /** |
| 5556 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5557 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5558 | */ |
| 5559 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5560 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5561 | |
| 5562 | final long identity = Binder.clearCallingIdentity(); |
| 5563 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5564 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5565 | // may happen if the device does not support IMS. |
| 5566 | return null; |
| 5567 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5568 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5569 | } finally { |
| 5570 | Binder.restoreCallingIdentity(identity); |
| 5571 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5572 | } |
| 5573 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5574 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5575 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5576 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5577 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5578 | * @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] | 5579 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5580 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5581 | * @param packageName The name of the package that the current configuration will be replaced |
| 5582 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5583 | * @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] | 5584 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5585 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5586 | int[] featureTypes, String packageName) { |
| 5587 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5588 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5589 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5590 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5591 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5592 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5593 | final long identity = Binder.clearCallingIdentity(); |
| 5594 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5595 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5596 | // may happen if the device does not support IMS. |
| 5597 | return false; |
| 5598 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5599 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5600 | for (int featureType : featureTypes) { |
| 5601 | featureConfig.put(featureType, packageName); |
| 5602 | } |
| 5603 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5604 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5605 | } finally { |
| 5606 | Binder.restoreCallingIdentity(identity); |
| 5607 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5608 | } |
| 5609 | |
| 5610 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5611 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5612 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5613 | * |
| 5614 | * This should only be used for testing. |
| 5615 | * |
| 5616 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5617 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5618 | */ |
| 5619 | @Override |
| 5620 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5621 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5622 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5623 | "clearCarrierImsServiceOverride"); |
| 5624 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5625 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5626 | "clearCarrierImsServiceOverride"); |
| 5627 | |
| 5628 | final long identity = Binder.clearCallingIdentity(); |
| 5629 | try { |
| 5630 | if (mImsResolver == null) { |
| 5631 | // may happen if the device does not support IMS. |
| 5632 | return false; |
| 5633 | } |
| 5634 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5635 | } finally { |
| 5636 | Binder.restoreCallingIdentity(identity); |
| 5637 | } |
| 5638 | } |
| 5639 | |
| 5640 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5641 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5642 | * |
| 5643 | * @param slotId The slot that the ImsService is associated with. |
| 5644 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5645 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5646 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5647 | * @return the package name of the ImsService configuration. |
| 5648 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5649 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5650 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5651 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5652 | TelephonyPermissions |
| 5653 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5654 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5655 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5656 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5657 | final long identity = Binder.clearCallingIdentity(); |
| 5658 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5659 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5660 | // may happen if the device does not support IMS. |
| 5661 | return ""; |
| 5662 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5663 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5664 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5665 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5666 | } finally { |
| 5667 | Binder.restoreCallingIdentity(identity); |
| 5668 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5669 | } |
| 5670 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5671 | /** |
| 5672 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5673 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5674 | * @param callback A callback with an integer containing the |
| 5675 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5676 | */ |
| 5677 | @Override |
| 5678 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5679 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5680 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5681 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5682 | "IMS not available on device."); |
| 5683 | } |
| 5684 | final long token = Binder.clearCallingIdentity(); |
| 5685 | try { |
| 5686 | int slotId = getSlotIndex(subId); |
| 5687 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5688 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5689 | + subId + "'"); |
| 5690 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5691 | } |
| 5692 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5693 | try { |
| 5694 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5695 | } catch (RemoteException e) { |
| 5696 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5697 | + "Ignore"); |
| 5698 | } |
| 5699 | }); |
| 5700 | } finally { |
| 5701 | Binder.restoreCallingIdentity(token); |
| 5702 | } |
| 5703 | } |
| 5704 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5705 | /** |
| 5706 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5707 | */ |
| 5708 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5709 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5710 | |
| 5711 | final long identity = Binder.clearCallingIdentity(); |
| 5712 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5713 | // NOTE: Before S, this method only set the default phone. |
| 5714 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5715 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5716 | phone.setImsRegistrationState(registered); |
| 5717 | } |
| 5718 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5719 | } finally { |
| 5720 | Binder.restoreCallingIdentity(identity); |
| 5721 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5722 | } |
| 5723 | |
| 5724 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5725 | * Set the network selection mode to automatic. |
| 5726 | * |
| 5727 | */ |
| 5728 | @Override |
| 5729 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5730 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5731 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5732 | |
| 5733 | final long identity = Binder.clearCallingIdentity(); |
| 5734 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5735 | if (!isActiveSubscription(subId)) { |
| 5736 | return; |
| 5737 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5738 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 5739 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 5740 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5741 | } finally { |
| 5742 | Binder.restoreCallingIdentity(identity); |
| 5743 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5744 | } |
| 5745 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5746 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5747 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5748 | * |
| 5749 | * @param subId the id of the subscription. |
| 5750 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5751 | * the operator to attach to. |
| 5752 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5753 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5754 | * normal network selection next time. |
| 5755 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5756 | */ |
| 5757 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5758 | public boolean setNetworkSelectionModeManual( |
| 5759 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5760 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5761 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5762 | |
| 5763 | if (!isActiveSubscription(subId)) { |
| 5764 | return false; |
| 5765 | } |
| 5766 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5767 | final long identity = Binder.clearCallingIdentity(); |
| 5768 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5769 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5770 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5771 | if (DBG) { |
| 5772 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5773 | + " operator: " + operatorInfo); |
| 5774 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5775 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5776 | } finally { |
| 5777 | Binder.restoreCallingIdentity(identity); |
| 5778 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5779 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5780 | /** |
| 5781 | * Get the manual network selection |
| 5782 | * |
| 5783 | * @param subId the id of the subscription. |
| 5784 | * |
| 5785 | * @return the previously saved user selected PLMN |
| 5786 | */ |
| 5787 | @Override |
| 5788 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5789 | TelephonyPermissions |
| 5790 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5791 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5792 | |
| 5793 | final long identity = Binder.clearCallingIdentity(); |
| 5794 | try { |
| 5795 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5796 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5797 | } |
| 5798 | |
| 5799 | final Phone phone = getPhone(subId); |
| 5800 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5801 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5802 | } |
| 5803 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5804 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5805 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5806 | } finally { |
| 5807 | Binder.restoreCallingIdentity(identity); |
| 5808 | } |
| 5809 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5810 | |
| 5811 | /** |
| 5812 | * Scans for available networks. |
| 5813 | */ |
| 5814 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5815 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5816 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5817 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5818 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5819 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5820 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5821 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5822 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5823 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5824 | .setCallingPid(Binder.getCallingPid()) |
| 5825 | .setCallingUid(Binder.getCallingUid()) |
| 5826 | .setMethod("getCellNetworkScanResults") |
| 5827 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 5828 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5829 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5830 | .build()); |
| 5831 | switch (locationResult) { |
| 5832 | case DENIED_HARD: |
| 5833 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5834 | case DENIED_SOFT: |
| 5835 | return null; |
| 5836 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5837 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5838 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5839 | try { |
| 5840 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5841 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5842 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5843 | } finally { |
| 5844 | Binder.restoreCallingIdentity(identity); |
| 5845 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5846 | } |
| 5847 | |
| 5848 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5849 | * Get the call forwarding info, given the call forwarding reason. |
| 5850 | */ |
| 5851 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5852 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5853 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5854 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5855 | long identity = Binder.clearCallingIdentity(); |
| 5856 | try { |
| 5857 | if (DBG) { |
| 5858 | log("getCallForwarding: subId " + subId |
| 5859 | + " callForwardingReason" + callForwardingReason); |
| 5860 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5861 | |
| 5862 | Phone phone = getPhone(subId); |
| 5863 | if (phone == null) { |
| 5864 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5865 | callback.onError( |
| 5866 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5867 | } catch (RemoteException e) { |
| 5868 | // ignore |
| 5869 | } |
| 5870 | return; |
| 5871 | } |
| 5872 | |
| 5873 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 5874 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 5875 | @Override |
| 5876 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 5877 | try { |
| 5878 | callback.onCallForwardingInfoAvailable(info); |
| 5879 | } catch (RemoteException e) { |
| 5880 | // ignore |
| 5881 | } |
| 5882 | } |
| 5883 | |
| 5884 | @Override |
| 5885 | public void onError(int error) { |
| 5886 | try { |
| 5887 | callback.onError(error); |
| 5888 | } catch (RemoteException e) { |
| 5889 | // ignore |
| 5890 | } |
| 5891 | } |
| 5892 | }); |
| 5893 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5894 | } finally { |
| 5895 | Binder.restoreCallingIdentity(identity); |
| 5896 | } |
| 5897 | } |
| 5898 | |
| 5899 | /** |
| 5900 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5901 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5902 | */ |
| 5903 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5904 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 5905 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5906 | enforceModifyPermission(); |
| 5907 | long identity = Binder.clearCallingIdentity(); |
| 5908 | try { |
| 5909 | if (DBG) { |
| 5910 | log("setCallForwarding: subId " + subId |
| 5911 | + " callForwardingInfo" + callForwardingInfo); |
| 5912 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5913 | |
| 5914 | Phone phone = getPhone(subId); |
| 5915 | if (phone == null) { |
| 5916 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5917 | callback.accept( |
| 5918 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5919 | } catch (RemoteException e) { |
| 5920 | // ignore |
| 5921 | } |
| 5922 | return; |
| 5923 | } |
| 5924 | |
| 5925 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 5926 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5927 | |
| 5928 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5929 | } finally { |
| 5930 | Binder.restoreCallingIdentity(identity); |
| 5931 | } |
| 5932 | } |
| 5933 | |
| 5934 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5935 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5936 | */ |
| 5937 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5938 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5939 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5940 | long identity = Binder.clearCallingIdentity(); |
| 5941 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5942 | |
| 5943 | Phone phone = getPhone(subId); |
| 5944 | if (phone == null) { |
| 5945 | try { |
| 5946 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5947 | } catch (RemoteException e) { |
| 5948 | // ignore |
| 5949 | } |
| 5950 | return; |
| 5951 | } |
| 5952 | |
| 5953 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 5954 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5955 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5956 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5957 | } finally { |
| 5958 | Binder.restoreCallingIdentity(identity); |
| 5959 | } |
| 5960 | } |
| 5961 | |
| 5962 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5963 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5964 | */ |
| 5965 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5966 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5967 | enforceModifyPermission(); |
| 5968 | long identity = Binder.clearCallingIdentity(); |
| 5969 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5970 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 5971 | |
| 5972 | Phone phone = getPhone(subId); |
| 5973 | if (phone == null) { |
| 5974 | try { |
| 5975 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5976 | } catch (RemoteException e) { |
| 5977 | // ignore |
| 5978 | } |
| 5979 | return; |
| 5980 | } |
| 5981 | |
| 5982 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 5983 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5984 | |
| 5985 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5986 | } finally { |
| 5987 | Binder.restoreCallingIdentity(identity); |
| 5988 | } |
| 5989 | } |
| 5990 | |
| 5991 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5992 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5993 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5994 | * @param subId id of the subscription |
| 5995 | * @param request contains the radio access networks with bands/channels to scan |
| 5996 | * @param messenger callback messenger for scan results or errors |
| 5997 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5998 | * @return the id of the requested scan which can be used to stop the scan. |
| 5999 | */ |
| 6000 | @Override |
| 6001 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6002 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6003 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6004 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6005 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6006 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6007 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6008 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6009 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6010 | .setCallingPid(Binder.getCallingPid()) |
| 6011 | .setCallingUid(Binder.getCallingUid()) |
| 6012 | .setMethod("requestNetworkScan") |
| 6013 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
James.cf Lin | 1d4d739 | 2020-07-03 18:22:53 +0800 | [diff] [blame] | 6014 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6015 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6016 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6017 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6018 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6019 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6020 | if (e != null) { |
| 6021 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6022 | throw e; |
| 6023 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6024 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6025 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6026 | } |
| 6027 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6028 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6029 | int callingUid = Binder.getCallingUid(); |
| 6030 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6031 | final long identity = Binder.clearCallingIdentity(); |
| 6032 | try { |
| 6033 | return mNetworkScanRequestTracker.startNetworkScan( |
| 6034 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6035 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6036 | } finally { |
| 6037 | Binder.restoreCallingIdentity(identity); |
| 6038 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6039 | } |
| 6040 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6041 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6042 | NetworkScanRequest request, int subId, String callingPackage) { |
| 6043 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6044 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6045 | boolean hasNetworkScanPermission = |
| 6046 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6047 | == PERMISSION_GRANTED; |
| 6048 | |
| 6049 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6050 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6051 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6052 | } |
| 6053 | |
| 6054 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6055 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6056 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6057 | return new SecurityException("Specific channels must not be" |
| 6058 | + " scanned without location access."); |
| 6059 | } |
| 6060 | } |
| 6061 | } |
| 6062 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6063 | return null; |
| 6064 | } |
| 6065 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6066 | /** |
| 6067 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6068 | * |
| 6069 | * @param subId id of the subscription |
| 6070 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6071 | */ |
| 6072 | @Override |
| 6073 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6074 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6075 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6076 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6077 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6078 | final long identity = Binder.clearCallingIdentity(); |
| 6079 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6080 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6081 | } finally { |
| 6082 | Binder.restoreCallingIdentity(identity); |
| 6083 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6084 | } |
| 6085 | |
| 6086 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6087 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6088 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6089 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6090 | */ |
| 6091 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6092 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6093 | TelephonyPermissions |
| 6094 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6095 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6096 | |
| 6097 | final long identity = Binder.clearCallingIdentity(); |
| 6098 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6099 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6100 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6101 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6102 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6103 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6104 | } finally { |
| 6105 | Binder.restoreCallingIdentity(identity); |
| 6106 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6107 | } |
| 6108 | |
| 6109 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6110 | * Get the allowed network types for certain reason. |
| 6111 | * |
| 6112 | * @param subId the id of the subscription. |
| 6113 | * @param reason the reason the allowed network type change is taking place |
| 6114 | * @return the allowed network types. |
| 6115 | */ |
| 6116 | @Override |
| 6117 | public long getAllowedNetworkTypesForReason(int subId, |
| 6118 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
| 6119 | TelephonyPermissions |
| 6120 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6121 | mApp, subId, "getAllowedNetworkTypesForReason"); |
| 6122 | final long identity = Binder.clearCallingIdentity(); |
| 6123 | try { |
| 6124 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6125 | } finally { |
| 6126 | Binder.restoreCallingIdentity(identity); |
| 6127 | } |
| 6128 | } |
| 6129 | |
| 6130 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6131 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6132 | * @param subId subscription id of the sim card |
| 6133 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6134 | * This can be passed following states |
| 6135 | * <ol> |
| 6136 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6137 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6138 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6139 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6140 | * </ol> |
| 6141 | * @return operation result. |
| 6142 | */ |
| 6143 | @Override |
| 6144 | public int setNrDualConnectivityState(int subId, |
| 6145 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6146 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6147 | mApp, subId, "enableNRDualConnectivity"); |
| 6148 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6149 | final long identity = Binder.clearCallingIdentity(); |
| 6150 | try { |
| 6151 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6152 | nrDualConnectivityState, subId, |
| 6153 | workSource); |
| 6154 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6155 | return result; |
| 6156 | } finally { |
| 6157 | Binder.restoreCallingIdentity(identity); |
| 6158 | } |
| 6159 | } |
| 6160 | |
| 6161 | /** |
| 6162 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6163 | * @return true if dual connectivity is enabled else false |
| 6164 | */ |
| 6165 | @Override |
| 6166 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6167 | TelephonyPermissions |
| 6168 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6169 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6170 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6171 | final long identity = Binder.clearCallingIdentity(); |
| 6172 | try { |
| 6173 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6174 | null, subId, workSource); |
| 6175 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6176 | return isEnabled; |
| 6177 | } finally { |
| 6178 | Binder.restoreCallingIdentity(identity); |
| 6179 | } |
| 6180 | } |
| 6181 | |
| 6182 | /** |
Sooraj Sasindran | 4deb887 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 6183 | * get carrier bandwidth per primary and secondary carrier |
| 6184 | * @param subId subscription id of the sim card |
| 6185 | * @return CarrierBandwidth with bandwidth of both primary and secondary carrier.. |
| 6186 | */ |
| 6187 | @Override |
| 6188 | public CarrierBandwidth getCarrierBandwidth(int subId) { |
| 6189 | TelephonyPermissions |
| 6190 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6191 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6192 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6193 | final long identity = Binder.clearCallingIdentity(); |
| 6194 | try { |
| 6195 | CarrierBandwidth carrierBandwidth = |
| 6196 | getPhoneFromSubId(subId).getCarrierBandwidth(); |
| 6197 | if (DBG) log("getCarrierBandwidth: " + carrierBandwidth); |
| 6198 | return carrierBandwidth; |
| 6199 | } finally { |
| 6200 | Binder.restoreCallingIdentity(identity); |
| 6201 | } |
| 6202 | } |
| 6203 | |
| 6204 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6205 | * Set the allowed network types of the device and |
| 6206 | * provide the reason triggering the allowed network change. |
| 6207 | * |
| 6208 | * @param subId the id of the subscription. |
| 6209 | * @param reason the reason the allowed network type change is taking place |
| 6210 | * @param allowedNetworkTypes the allowed network types. |
| 6211 | * @return true on success; false on any failure. |
| 6212 | */ |
| 6213 | @Override |
| 6214 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6215 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6216 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6217 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6218 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6219 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
| 6220 | Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason); |
| 6221 | return false; |
| 6222 | } |
| 6223 | |
| 6224 | if (DBG) { |
| 6225 | log("setAllowedNetworkTypesForReason: " + reason |
| 6226 | + " value: " + allowedNetworkTypes); |
| 6227 | } |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6228 | final long identity = Binder.clearCallingIdentity(); |
| 6229 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6230 | Boolean success = (Boolean) sendRequest( |
| 6231 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6232 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6233 | |
| 6234 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6235 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6236 | } finally { |
| 6237 | Binder.restoreCallingIdentity(identity); |
| 6238 | } |
| 6239 | } |
| 6240 | |
| 6241 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6242 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6243 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6244 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6245 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6246 | * @hide |
| 6247 | */ |
| 6248 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6249 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6250 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6251 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6252 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6253 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6254 | if (phone != null) { |
| 6255 | return phone.hasMatchedTetherApnSetting(); |
| 6256 | } else { |
| 6257 | return false; |
| 6258 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6259 | } finally { |
| 6260 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6261 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6262 | } |
| 6263 | |
| 6264 | /** |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6265 | * Enable or disable always reporting signal strength changes from radio. |
| 6266 | * |
| 6267 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6268 | */ |
| 6269 | @Override |
| 6270 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6271 | enforceModifyPermission(); |
| 6272 | enforceSystemCaller(); |
| 6273 | |
| 6274 | final long identity = Binder.clearCallingIdentity(); |
| 6275 | final Phone phone = getPhone(subId); |
| 6276 | try { |
| 6277 | if (phone != null) { |
| 6278 | if (DBG) { |
| 6279 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6280 | + " isEnable=" + isEnable); |
| 6281 | } |
| 6282 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6283 | } else { |
| 6284 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6285 | + subId); |
| 6286 | } |
| 6287 | } finally { |
| 6288 | Binder.restoreCallingIdentity(identity); |
| 6289 | } |
| 6290 | } |
| 6291 | |
| 6292 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6293 | * Get the user enabled state of Mobile Data. |
| 6294 | * |
| 6295 | * TODO: remove and use isUserDataEnabled. |
| 6296 | * This can't be removed now because some vendor codes |
| 6297 | * calls through ITelephony directly while they should |
| 6298 | * use TelephonyManager. |
| 6299 | * |
| 6300 | * @return true on enabled |
| 6301 | */ |
| 6302 | @Override |
| 6303 | public boolean getDataEnabled(int subId) { |
| 6304 | return isUserDataEnabled(subId); |
| 6305 | } |
| 6306 | |
| 6307 | /** |
| 6308 | * Get whether mobile data is enabled per user setting. |
| 6309 | * |
| 6310 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6311 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6312 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6313 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6314 | * |
| 6315 | * @return {@code true} if data is enabled else {@code false} |
| 6316 | */ |
| 6317 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6318 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6319 | try { |
| 6320 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6321 | null); |
| 6322 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6323 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6324 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6325 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6326 | |
| 6327 | final long identity = Binder.clearCallingIdentity(); |
| 6328 | try { |
| 6329 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6330 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6331 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6332 | if (phone != null) { |
| 6333 | boolean retVal = phone.isUserDataEnabled(); |
| 6334 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6335 | return retVal; |
| 6336 | } else { |
| 6337 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6338 | return false; |
| 6339 | } |
| 6340 | } finally { |
| 6341 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6342 | } |
| 6343 | } |
| 6344 | |
| 6345 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6346 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6347 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6348 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6349 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6350 | * @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] | 6351 | */ |
| 6352 | @Override |
| 6353 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6354 | try { |
| 6355 | try { |
| 6356 | mApp.enforceCallingOrSelfPermission( |
| 6357 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6358 | null); |
| 6359 | } catch (Exception e) { |
| 6360 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6361 | "isDataEnabled"); |
| 6362 | } |
| 6363 | } catch (Exception e) { |
| 6364 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6365 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6366 | |
| 6367 | final long identity = Binder.clearCallingIdentity(); |
| 6368 | try { |
| 6369 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6370 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6371 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6372 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6373 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6374 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6375 | return retVal; |
| 6376 | } else { |
| 6377 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6378 | return false; |
| 6379 | } |
| 6380 | } finally { |
| 6381 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6382 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6383 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6384 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6385 | /** |
| 6386 | * Check if data is enabled for a specific reason |
| 6387 | * @param subId Subscription index |
| 6388 | * @param reason the reason the data enable change is taking place |
| 6389 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6390 | */ |
| 6391 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6392 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6393 | @TelephonyManager.DataEnabledReason int reason) { |
| 6394 | try { |
| 6395 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6396 | null); |
| 6397 | } catch (Exception e) { |
| 6398 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6399 | "isDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6400 | } |
| 6401 | |
| 6402 | |
| 6403 | final long identity = Binder.clearCallingIdentity(); |
| 6404 | try { |
| 6405 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6406 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6407 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6408 | + " reason=" + reason); |
| 6409 | } |
| 6410 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6411 | if (phone != null) { |
| 6412 | boolean retVal; |
| 6413 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6414 | retVal = phone.isUserDataEnabled(); |
| 6415 | } else { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6416 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6417 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6418 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6419 | return retVal; |
| 6420 | } else { |
| 6421 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6422 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6423 | + subId + " retVal=false"); |
| 6424 | } |
| 6425 | return false; |
| 6426 | } |
| 6427 | } finally { |
| 6428 | Binder.restoreCallingIdentity(identity); |
| 6429 | } |
| 6430 | } |
| 6431 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6432 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6433 | Phone phone) { |
Hall Liu | 54a2a0c | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6434 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 6435 | // Skip the check if it's one of these special uids |
| 6436 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6437 | } |
| 6438 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6439 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6440 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6441 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6442 | || subController == null) return privilegeFromSim; |
| 6443 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6444 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6445 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6446 | |
| 6447 | final long identity = Binder.clearCallingIdentity(); |
| 6448 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6449 | int subId = phone.getSubId(); |
| 6450 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6451 | // A test override is in place for the privileges for this subId, so don't try to |
| 6452 | // read the subscription privileges. |
| 6453 | return privilegeFromSim; |
| 6454 | } |
| 6455 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6456 | SubscriptionManager subManager = (SubscriptionManager) |
| 6457 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6458 | for (String pkg : packages) { |
| 6459 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6460 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6461 | } |
| 6462 | } |
| 6463 | return privilegeFromSim; |
| 6464 | } finally { |
| 6465 | Binder.restoreCallingIdentity(identity); |
| 6466 | } |
| 6467 | } |
| 6468 | |
| 6469 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6470 | String pkgName) { |
| 6471 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6472 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6473 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6474 | || subController == null) return privilegeFromSim; |
| 6475 | |
| 6476 | final long identity = Binder.clearCallingIdentity(); |
| 6477 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6478 | int subId = phone.getSubId(); |
| 6479 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6480 | // A test override is in place for the privileges for this subId, so don't try to |
| 6481 | // read the subscription privileges. |
| 6482 | return privilegeFromSim; |
| 6483 | } |
| 6484 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6485 | SubscriptionManager subManager = (SubscriptionManager) |
| 6486 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6487 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6488 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6489 | } finally { |
| 6490 | Binder.restoreCallingIdentity(identity); |
| 6491 | } |
| 6492 | } |
| 6493 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6494 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6495 | public int getCarrierPrivilegeStatus(int subId) { |
| 6496 | final Phone phone = getPhone(subId); |
| 6497 | if (phone == null) { |
| 6498 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6499 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6500 | } |
| 6501 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6502 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6503 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6504 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6505 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6506 | |
| 6507 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6508 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6509 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6510 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6511 | |
| 6512 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6513 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6514 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6515 | final Phone phone = getPhone(subId); |
| 6516 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6517 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6518 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6519 | } |
| 6520 | UiccProfile profile = |
| 6521 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6522 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6523 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6524 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6525 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6526 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6527 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6528 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6529 | } |
| 6530 | |
| 6531 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6532 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6533 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6534 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6535 | } |
| 6536 | |
| 6537 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6538 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6539 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6540 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6541 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6542 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6543 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6544 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6545 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6546 | } |
| 6547 | |
| 6548 | @Override |
| 6549 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6550 | if (TextUtils.isEmpty(pkgName)) |
| 6551 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6552 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6553 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6554 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6555 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6556 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6557 | continue; |
| 6558 | } |
| 6559 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6560 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6561 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6562 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6563 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6564 | break; |
| 6565 | } |
| 6566 | } |
| 6567 | |
| 6568 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6569 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6570 | |
| 6571 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6572 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6573 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6574 | loge("phoneId " + phoneId + " is not valid."); |
| 6575 | return null; |
| 6576 | } |
| 6577 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6578 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6579 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6580 | return null ; |
| 6581 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6582 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6583 | } |
| 6584 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6585 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6586 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6587 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6588 | List<String> privilegedPackages = new ArrayList<>(); |
| 6589 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6590 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6591 | // has UICC in that slot. |
| 6592 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6593 | if (card.hasCarrierPrivilegeRules()) { |
| 6594 | if (packages == null) { |
| 6595 | // Only check packages in user 0 for now |
| 6596 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6597 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6598 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6599 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6600 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6601 | } |
| 6602 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6603 | PackageInfo pkgInfo = packages.get(p); |
| 6604 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6605 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6606 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6607 | privilegedPackages.add(pkgInfo.packageName); |
| 6608 | } |
| 6609 | } |
| 6610 | } |
| 6611 | } |
| 6612 | return privilegedPackages; |
| 6613 | } |
| 6614 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6615 | @Override |
| 6616 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6617 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6618 | |
| 6619 | final long identity = Binder.clearCallingIdentity(); |
| 6620 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6621 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6622 | try { |
| 6623 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6624 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6625 | } |
| 6626 | } finally { |
| 6627 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6628 | } |
| 6629 | return privilegedPackages; |
| 6630 | } |
| 6631 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6632 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6633 | final Phone phone = getPhone(subId); |
| 6634 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6635 | if (card == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6636 | return null; |
| 6637 | } |
| 6638 | String iccId = card.getIccId(); |
| 6639 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6640 | return null; |
| 6641 | } |
| 6642 | return iccId; |
| 6643 | } |
| 6644 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6645 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6646 | public void setCallComposerStatus(int subId, int status) { |
| 6647 | enforceModifyPermission(); |
| 6648 | |
| 6649 | final long identity = Binder.clearCallingIdentity(); |
| 6650 | try { |
| 6651 | Phone phone = getPhone(subId); |
| 6652 | if (phone != null) { |
| 6653 | Phone defaultPhone = phone.getImsPhone(); |
| 6654 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6655 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6656 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6657 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6658 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6659 | } |
| 6660 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6661 | } catch (ImsException e) { |
| 6662 | throw new ServiceSpecificException(e.getCode()); |
| 6663 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6664 | Binder.restoreCallingIdentity(identity); |
| 6665 | } |
| 6666 | } |
| 6667 | |
| 6668 | @Override |
| 6669 | public int getCallComposerStatus(int subId) { |
| 6670 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6671 | |
| 6672 | final long identity = Binder.clearCallingIdentity(); |
| 6673 | try { |
| 6674 | Phone phone = getPhone(subId); |
| 6675 | if (phone != null) { |
| 6676 | Phone defaultPhone = phone.getImsPhone(); |
| 6677 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6678 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6679 | return imsPhone.getCallComposerStatus(); |
| 6680 | } |
| 6681 | } |
| 6682 | } finally { |
| 6683 | Binder.restoreCallingIdentity(identity); |
| 6684 | } |
| 6685 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6686 | } |
| 6687 | |
| 6688 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6689 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6690 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6691 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6692 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6693 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6694 | final long identity = Binder.clearCallingIdentity(); |
| 6695 | try { |
| 6696 | final String iccId = getIccId(subId); |
| 6697 | final Phone phone = getPhone(subId); |
| 6698 | if (phone == null) { |
| 6699 | return false; |
| 6700 | } |
| 6701 | final String subscriberId = phone.getSubscriberId(); |
| 6702 | |
| 6703 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6704 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6705 | + subscriberId + " to " + number); |
| 6706 | } |
| 6707 | |
| 6708 | if (TextUtils.isEmpty(iccId)) { |
| 6709 | return false; |
| 6710 | } |
| 6711 | |
| 6712 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6713 | |
| 6714 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6715 | if (alphaTag == null) { |
| 6716 | editor.remove(alphaTagPrefKey); |
| 6717 | } else { |
| 6718 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6719 | } |
| 6720 | |
| 6721 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6722 | // track all merged IMSIs based on line number |
| 6723 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6724 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6725 | if (number == null) { |
| 6726 | editor.remove(numberPrefKey); |
| 6727 | editor.remove(subscriberPrefKey); |
| 6728 | } else { |
| 6729 | editor.putString(numberPrefKey, number); |
| 6730 | editor.putString(subscriberPrefKey, subscriberId); |
| 6731 | } |
| 6732 | |
| 6733 | editor.commit(); |
| 6734 | return true; |
| 6735 | } finally { |
| 6736 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6737 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6738 | } |
| 6739 | |
| 6740 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6741 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6742 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6743 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6744 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6745 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6746 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6747 | return null; |
| 6748 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6749 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6750 | final long identity = Binder.clearCallingIdentity(); |
| 6751 | try { |
| 6752 | String iccId = getIccId(subId); |
| 6753 | if (iccId != null) { |
| 6754 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6755 | if (DBG_MERGE) { |
| 6756 | log("getLine1NumberForDisplay returning " |
| 6757 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6758 | } |
| 6759 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6760 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6761 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6762 | return null; |
| 6763 | } finally { |
| 6764 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6765 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6766 | } |
| 6767 | |
| 6768 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6769 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6770 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6771 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6772 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6773 | return null; |
| 6774 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6775 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6776 | final long identity = Binder.clearCallingIdentity(); |
| 6777 | try { |
| 6778 | String iccId = getIccId(subId); |
| 6779 | if (iccId != null) { |
| 6780 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6781 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6782 | } |
| 6783 | return null; |
| 6784 | } finally { |
| 6785 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6786 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6787 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6788 | |
| 6789 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6790 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6791 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6792 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6793 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6794 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6795 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6796 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6797 | return null; |
| 6798 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6799 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6800 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6801 | // the process, where TelephonyManager was instantiated. |
| 6802 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6803 | final long identity = Binder.clearCallingIdentity(); |
| 6804 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6805 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6806 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6807 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6808 | |
| 6809 | // Figure out what subscribers are currently active |
| 6810 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6811 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6812 | // Only consider subs which match the current subId |
| 6813 | // This logic can be simplified. See b/131189269 for progress. |
| 6814 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6815 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6816 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6817 | |
| 6818 | // First pass, find a number override for an active subscriber |
| 6819 | String mergeNumber = null; |
| 6820 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6821 | for (String key : prefs.keySet()) { |
| 6822 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6823 | final String subscriberId = (String) prefs.get(key); |
| 6824 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6825 | final String iccId = key.substring( |
| 6826 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6827 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6828 | mergeNumber = (String) prefs.get(numberKey); |
| 6829 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6830 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6831 | + " for active subscriber " + subscriberId); |
| 6832 | } |
| 6833 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6834 | break; |
| 6835 | } |
| 6836 | } |
| 6837 | } |
| 6838 | } |
| 6839 | |
| 6840 | // Shortcut when no active merged subscribers |
| 6841 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6842 | return null; |
| 6843 | } |
| 6844 | |
| 6845 | // Second pass, find all subscribers under that line override |
| 6846 | final ArraySet<String> result = new ArraySet<>(); |
| 6847 | for (String key : prefs.keySet()) { |
| 6848 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6849 | final String number = (String) prefs.get(key); |
| 6850 | if (mergeNumber.equals(number)) { |
| 6851 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6852 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6853 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6854 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6855 | result.add(subscriberId); |
| 6856 | } |
| 6857 | } |
| 6858 | } |
| 6859 | } |
| 6860 | |
| 6861 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6862 | Arrays.sort(resultArray); |
| 6863 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6864 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6865 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6866 | } |
| 6867 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6868 | } finally { |
| 6869 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6870 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6871 | } |
| 6872 | |
| 6873 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6874 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6875 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6876 | |
| 6877 | final long identity = Binder.clearCallingIdentity(); |
| 6878 | try { |
| 6879 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6880 | TelephonyManager.class); |
| 6881 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6882 | if (subscriberId == null) { |
| 6883 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6884 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6885 | + subId); |
| 6886 | } |
| 6887 | return null; |
| 6888 | } |
| 6889 | |
| 6890 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6891 | .getSubscriptionInfo(subId); |
| 6892 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6893 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6894 | if (groupUuid == null) { |
| 6895 | return new String[]{subscriberId}; |
| 6896 | } |
| 6897 | |
| 6898 | // Get all subscriberIds from the group. |
| 6899 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6900 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6901 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6902 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6903 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6904 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6905 | if (subscriberId != null) { |
| 6906 | mergedSubscriberIds.add(subscriberId); |
| 6907 | } |
| 6908 | } |
| 6909 | |
| 6910 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6911 | } finally { |
| 6912 | Binder.restoreCallingIdentity(identity); |
| 6913 | |
| 6914 | } |
| 6915 | } |
| 6916 | |
| 6917 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6918 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6919 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6920 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6921 | |
| 6922 | final long identity = Binder.clearCallingIdentity(); |
| 6923 | try { |
| 6924 | final Phone phone = getPhone(subId); |
| 6925 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6926 | } finally { |
| 6927 | Binder.restoreCallingIdentity(identity); |
| 6928 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6929 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6930 | |
| 6931 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6932 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6933 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6934 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6935 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6936 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6937 | |
| 6938 | final long identity = Binder.clearCallingIdentity(); |
| 6939 | try { |
| 6940 | final Phone phone = getPhone(subId); |
| 6941 | if (phone == null) { |
| 6942 | return false; |
| 6943 | } |
| 6944 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6945 | cdmaNonRoamingList); |
| 6946 | } finally { |
| 6947 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6948 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6949 | } |
| 6950 | |
| 6951 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6952 | @Deprecated |
| 6953 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6954 | enforceModifyPermission(); |
| 6955 | |
| 6956 | int returnValue = 0; |
| 6957 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6958 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6959 | if(result.exception == null) { |
| 6960 | if (result.result != null) { |
| 6961 | byte[] responseData = (byte[])(result.result); |
| 6962 | if(responseData.length > oemResp.length) { |
| 6963 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6964 | responseData.length + "bytes. Buffer Size is " + |
| 6965 | oemResp.length + "bytes."); |
| 6966 | } |
| 6967 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6968 | returnValue = responseData.length; |
| 6969 | } |
| 6970 | } else { |
| 6971 | CommandException ex = (CommandException) result.exception; |
| 6972 | returnValue = ex.getCommandError().ordinal(); |
| 6973 | if(returnValue > 0) returnValue *= -1; |
| 6974 | } |
| 6975 | } catch (RuntimeException e) { |
| 6976 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6977 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6978 | if(returnValue > 0) returnValue *= -1; |
| 6979 | } |
| 6980 | |
| 6981 | return returnValue; |
| 6982 | } |
| 6983 | |
| 6984 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6985 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6986 | try { |
| 6987 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6988 | } catch (RuntimeException e) { |
| 6989 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6990 | } |
| 6991 | } |
| 6992 | |
| 6993 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6994 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6995 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 6996 | try { |
| 6997 | TelephonyPermissions |
| 6998 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6999 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7000 | } catch (SecurityException e) { |
| 7001 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7002 | throw e; |
| 7003 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7004 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7005 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7006 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7007 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7008 | final long identity = Binder.clearCallingIdentity(); |
| 7009 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7010 | TelephonyPermissions |
| 7011 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 7012 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7013 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7014 | } finally { |
| 7015 | Binder.restoreCallingIdentity(identity); |
| 7016 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7017 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7018 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7019 | |
| 7020 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7021 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7022 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7023 | try { |
| 7024 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7025 | Binder.getCallingUid())) { |
| 7026 | throw new SecurityException("Package uid and package name do not match: " |
| 7027 | + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage); |
| 7028 | } |
| 7029 | } catch (PackageManager.NameNotFoundException e) { |
| 7030 | throw new SecurityException("Package name invalid:" + callingPackage); |
| 7031 | } |
| 7032 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7033 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7034 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7035 | throw new SecurityException("App must be the dialer role holder to" |
| 7036 | + " upload a call composer pic"); |
| 7037 | } |
| 7038 | |
| 7039 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7040 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7041 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7042 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7043 | boolean readUntilEnd = false; |
| 7044 | int totalBytesRead = 0; |
| 7045 | byte[] buffer = new byte[16 * 1024]; |
| 7046 | while (true) { |
| 7047 | int numRead; |
| 7048 | try { |
| 7049 | numRead = input.read(buffer); |
| 7050 | } catch (IOException e) { |
| 7051 | try { |
| 7052 | fd.checkError(); |
| 7053 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7054 | null); |
| 7055 | } catch (IOException e1) { |
| 7056 | // This means that the other side closed explicitly with an error. If this |
| 7057 | // happens, log and ignore. |
| 7058 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7059 | } |
| 7060 | break; |
| 7061 | } |
| 7062 | if (numRead == -1) { |
| 7063 | readUntilEnd = true; |
| 7064 | break; |
| 7065 | } |
| 7066 | totalBytesRead += numRead; |
| 7067 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7068 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7069 | try { |
| 7070 | input.close(); |
| 7071 | } catch (IOException e) { |
| 7072 | // ignore |
| 7073 | } |
| 7074 | break; |
| 7075 | } |
| 7076 | output.write(buffer, 0, numRead); |
| 7077 | } |
| 7078 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7079 | // close is above, where the picture size is too big. |
| 7080 | |
| 7081 | try { |
| 7082 | fd.checkError(); |
| 7083 | } catch (IOException e) { |
| 7084 | loge("Remote end for call composer closed with an error: " + e); |
| 7085 | return; |
| 7086 | } |
| 7087 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7088 | if (!readUntilEnd) { |
| 7089 | loge("Did not finish reading entire image; aborting"); |
| 7090 | return; |
| 7091 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7092 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7093 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7094 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7095 | new CallComposerPictureTransfer.Factory() {}, |
| 7096 | imageData, |
| 7097 | (result) -> { |
| 7098 | if (result.first != null) { |
| 7099 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7100 | Bundle outputResult = new Bundle(); |
| 7101 | outputResult.putParcelable( |
| 7102 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7103 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7104 | outputResult); |
| 7105 | } else { |
| 7106 | callback.send(result.second, null); |
| 7107 | } |
| 7108 | } |
| 7109 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7110 | }); |
| 7111 | } |
| 7112 | |
| 7113 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7114 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7115 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7116 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7117 | |
| 7118 | final long identity = Binder.clearCallingIdentity(); |
| 7119 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7120 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7121 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7122 | } finally { |
| 7123 | Binder.restoreCallingIdentity(identity); |
| 7124 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7125 | } |
| 7126 | |
| 7127 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7128 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7129 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7130 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7131 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7132 | return false; |
| 7133 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7134 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7135 | final long identity = Binder.clearCallingIdentity(); |
| 7136 | try { |
| 7137 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7138 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7139 | // In the long run, we may instead need to check if there exists a connection service |
| 7140 | // which can support video calling. |
| 7141 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7142 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7143 | return imsManager.isVtEnabledByPlatform() |
| 7144 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7145 | && imsManager.isVtEnabledByUser(); |
| 7146 | } finally { |
| 7147 | Binder.restoreCallingIdentity(identity); |
| 7148 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7149 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7150 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7151 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7152 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7153 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7154 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7155 | mApp, subId, callingPackage, callingFeatureId, |
| 7156 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7157 | return false; |
| 7158 | } |
| 7159 | |
| 7160 | final long identity = Binder.clearCallingIdentity(); |
| 7161 | try { |
| 7162 | CarrierConfigManager configManager = |
| 7163 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7164 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7165 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7166 | } finally { |
| 7167 | Binder.restoreCallingIdentity(identity); |
| 7168 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7169 | } |
| 7170 | |
| 7171 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7172 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7173 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7174 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7175 | return false; |
| 7176 | } |
| 7177 | |
| 7178 | final long identity = Binder.clearCallingIdentity(); |
| 7179 | try { |
| 7180 | CarrierConfigManager configManager = |
| 7181 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7182 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7183 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7184 | } finally { |
| 7185 | Binder.restoreCallingIdentity(identity); |
| 7186 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7187 | } |
| 7188 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7189 | @Override |
| 7190 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7191 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7192 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7193 | } |
| 7194 | |
| 7195 | @Override |
| 7196 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7197 | final long identity = Binder.clearCallingIdentity(); |
| 7198 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7199 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7200 | } finally { |
| 7201 | Binder.restoreCallingIdentity(identity); |
| 7202 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7203 | } |
| 7204 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7205 | /** |
| 7206 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7207 | * support for the feature and device firmware support. |
| 7208 | * |
| 7209 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7210 | */ |
| 7211 | @Override |
| 7212 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7213 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7214 | final Phone phone = getPhone(subscriptionId); |
| 7215 | if (phone == null) { |
| 7216 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7217 | return false; |
| 7218 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7219 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7220 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7221 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7222 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7223 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7224 | return isCarrierSupported && isDeviceSupported; |
| 7225 | } finally { |
| 7226 | Binder.restoreCallingIdentity(identity); |
| 7227 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7228 | } |
| 7229 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7230 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7231 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7232 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7233 | * 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] | 7234 | */ |
| 7235 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7236 | final long identity = Binder.clearCallingIdentity(); |
| 7237 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7238 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7239 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7240 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7241 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7242 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7243 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7244 | } finally { |
| 7245 | Binder.restoreCallingIdentity(identity); |
| 7246 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7247 | } |
| 7248 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7249 | @Deprecated |
| 7250 | @Override |
| 7251 | public String getDeviceId(String callingPackage) { |
| 7252 | return getDeviceIdWithFeature(callingPackage, null); |
| 7253 | } |
| 7254 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7255 | /** |
| 7256 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7257 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7258 | * |
| 7259 | * <p>Requires Permission: |
| 7260 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7261 | */ |
| 7262 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7263 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7264 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7265 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7266 | return null; |
| 7267 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7268 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7269 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7270 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7271 | return null; |
| 7272 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7273 | |
| 7274 | final long identity = Binder.clearCallingIdentity(); |
| 7275 | try { |
| 7276 | return phone.getDeviceId(); |
| 7277 | } finally { |
| 7278 | Binder.restoreCallingIdentity(identity); |
| 7279 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7280 | } |
| 7281 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7282 | /** |
| 7283 | * {@hide} |
| 7284 | * Returns the IMS Registration Status on a particular subid |
| 7285 | * |
| 7286 | * @param subId |
| 7287 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7288 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7289 | Phone phone = getPhone(subId); |
| 7290 | if (phone != null) { |
| 7291 | return phone.isImsRegistered(); |
| 7292 | } else { |
| 7293 | return false; |
| 7294 | } |
| 7295 | } |
| 7296 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7297 | @Override |
| 7298 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7299 | final long identity = Binder.clearCallingIdentity(); |
| 7300 | try { |
| 7301 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 7302 | } finally { |
| 7303 | Binder.restoreCallingIdentity(identity); |
| 7304 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7305 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7306 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7307 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7308 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7309 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7310 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7311 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7312 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7313 | } |
| 7314 | final long identity = Binder.clearCallingIdentity(); |
| 7315 | try { |
| 7316 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7317 | } finally { |
| 7318 | Binder.restoreCallingIdentity(identity); |
| 7319 | } |
| 7320 | } |
| 7321 | |
| 7322 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7323 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 7324 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 7325 | + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7326 | final long identity = Binder.clearCallingIdentity(); |
| 7327 | try { |
| 7328 | Phone phone = getPhone(subscriptionId); |
| 7329 | if (phone == null) { |
| 7330 | return null; |
| 7331 | } |
| 7332 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7333 | } finally { |
| 7334 | Binder.restoreCallingIdentity(identity); |
| 7335 | } |
| 7336 | } |
| 7337 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7338 | /** |
| 7339 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7340 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7341 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7342 | final long identity = Binder.clearCallingIdentity(); |
| 7343 | try { |
| 7344 | Phone phone = getPhone(subId); |
| 7345 | if (phone != null) { |
| 7346 | return phone.isWifiCallingEnabled(); |
| 7347 | } else { |
| 7348 | return false; |
| 7349 | } |
| 7350 | } finally { |
| 7351 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7352 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7353 | } |
| 7354 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7355 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7356 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7357 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7358 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7359 | final long identity = Binder.clearCallingIdentity(); |
| 7360 | try { |
| 7361 | Phone phone = getPhone(subId); |
| 7362 | if (phone != null) { |
| 7363 | return phone.isVideoEnabled(); |
| 7364 | } else { |
| 7365 | return false; |
| 7366 | } |
| 7367 | } finally { |
| 7368 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7369 | } |
| 7370 | } |
| 7371 | |
| 7372 | /** |
| 7373 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7374 | * defined in {@link ImsRegistrationImplBase}. |
| 7375 | */ |
| 7376 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7377 | final long identity = Binder.clearCallingIdentity(); |
| 7378 | try { |
| 7379 | Phone phone = getPhone(subId); |
| 7380 | if (phone != null) { |
| 7381 | return phone.getImsRegistrationTech(); |
| 7382 | } else { |
| 7383 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7384 | } |
| 7385 | } finally { |
| 7386 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7387 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7388 | } |
| 7389 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7390 | @Override |
| 7391 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7392 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7393 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7394 | return; |
| 7395 | } |
| 7396 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7397 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7398 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7399 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7400 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7401 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7402 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7403 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7404 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7405 | setAllowedNetworkTypesForReason(subId, |
| 7406 | TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7407 | RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId))); |
| 7408 | setAllowedNetworkTypesForReason(subId, |
| 7409 | TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER, |
| 7410 | RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId))); |
| 7411 | setAllowedNetworkTypesForReason(subId, |
| 7412 | TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER, |
| 7413 | RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId))); |
Yomna Nasser | 3f777b6 | 2021-02-17 03:38:52 +0000 | [diff] [blame] | 7414 | setAllowedNetworkTypesForReason(subId, |
| 7415 | TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G, |
| 7416 | RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId))); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7417 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 7418 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7419 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7420 | // There has been issues when Sms raw table somehow stores orphan |
| 7421 | // fragments. They lead to garbled message when new fragments come |
| 7422 | // in and combined with those stale ones. In case this happens again, |
| 7423 | // user can reset all network settings which will clean up this table. |
| 7424 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7425 | // Clean up IMS settings as well here. |
| 7426 | int slotId = getSlotIndex(subId); |
| 7427 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7428 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7429 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7430 | |
| 7431 | // Erase modem config if erase modem on network setting is enabled. |
| 7432 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7433 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7434 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 7435 | sendEraseModemConfig(getDefaultPhone()); |
| 7436 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7437 | } finally { |
| 7438 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7439 | } |
| 7440 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7441 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7442 | private void cleanUpSmsRawTable(Context context) { |
| 7443 | ContentResolver resolver = context.getContentResolver(); |
| 7444 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7445 | resolver.delete(uri, null, null); |
| 7446 | } |
| 7447 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7448 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7449 | public String getSimLocaleForSubscriber(int subId) { |
| 7450 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7451 | final Phone phone = getPhone(subId); |
| 7452 | if (phone == null) { |
| 7453 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7454 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7455 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7456 | final long identity = Binder.clearCallingIdentity(); |
| 7457 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7458 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7459 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7460 | if (info == null) { |
| 7461 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7462 | return null; |
| 7463 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7464 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7465 | // preferences (EF-PL and EF-LI)... |
| 7466 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7467 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7468 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7469 | if (localeFromDefaultSim != null) { |
| 7470 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7471 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7472 | + localeFromDefaultSim); |
| 7473 | return localeFromDefaultSim.toLanguageTag(); |
| 7474 | } else { |
| 7475 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7476 | } |
| 7477 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7478 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7479 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7480 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7481 | // the SIM and carrier preferences does not include a country we add the country |
| 7482 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7483 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7484 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7485 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7486 | return mccLocale.toLanguageTag(); |
| 7487 | } |
| 7488 | |
| 7489 | if (DBG) log("No locale found - returning null"); |
| 7490 | return null; |
| 7491 | } finally { |
| 7492 | Binder.restoreCallingIdentity(identity); |
| 7493 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7494 | } |
| 7495 | |
| 7496 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7497 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7498 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7499 | } |
| 7500 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7501 | /** |
| 7502 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7503 | */ |
| 7504 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7505 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7506 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7507 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7508 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7509 | private final ModemActivityInfo mLastModemActivityInfo = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7510 | new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7511 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7512 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7513 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7514 | * representing the state of the modem. |
| 7515 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7516 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7517 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7518 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7519 | */ |
| 7520 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7521 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7522 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7523 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7524 | |
| 7525 | final long identity = Binder.clearCallingIdentity(); |
| 7526 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7527 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7528 | } finally { |
| 7529 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7530 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7531 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7532 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7533 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7534 | // less than total activity duration. |
| 7535 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7536 | if (info == null) { |
| 7537 | return false; |
| 7538 | } |
| 7539 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7540 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7541 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7542 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7543 | return (info.isValid() |
| 7544 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7545 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7546 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7547 | && (totalTxTimeMs <= activityDurationMs)); |
| 7548 | } |
| 7549 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7550 | /** |
| 7551 | * {@hide} |
| 7552 | * Returns the service state information on specified subscription. |
| 7553 | */ |
| 7554 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7555 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7556 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7557 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7558 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7559 | return null; |
| 7560 | } |
| 7561 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7562 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7563 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7564 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7565 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7566 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7567 | .setCallingPid(Binder.getCallingPid()) |
| 7568 | .setCallingUid(Binder.getCallingUid()) |
| 7569 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7570 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7571 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7572 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7573 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7574 | .build()); |
| 7575 | |
| 7576 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7577 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7578 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7579 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7580 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7581 | .setCallingPid(Binder.getCallingPid()) |
| 7582 | .setCallingUid(Binder.getCallingUid()) |
| 7583 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7584 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7585 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7586 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7587 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7588 | .build()); |
| 7589 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7590 | boolean hasFinePermission = |
| 7591 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7592 | boolean hasCoarsePermission = |
| 7593 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7594 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7595 | final Phone phone = getPhone(subId); |
| 7596 | if (phone == null) { |
| 7597 | return null; |
| 7598 | } |
| 7599 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 7600 | final long identity = Binder.clearCallingIdentity(); |
| 7601 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7602 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7603 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7604 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7605 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7606 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7607 | Rlog.d(LOG_TAG, |
| 7608 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7609 | return null; |
| 7610 | } |
| 7611 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7612 | ServiceState ss = phone.getServiceState(); |
| 7613 | |
| 7614 | // Scrub out the location info in ServiceState depending on what level of access |
| 7615 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7616 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7617 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7618 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7619 | } finally { |
| 7620 | Binder.restoreCallingIdentity(identity); |
| 7621 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7622 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7623 | |
| 7624 | /** |
| 7625 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7626 | * |
| 7627 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7628 | * voicemail ringtone. |
| 7629 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7630 | * PhoneAccount. |
| 7631 | */ |
| 7632 | @Override |
| 7633 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7634 | final long identity = Binder.clearCallingIdentity(); |
| 7635 | try { |
| 7636 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7637 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7638 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7639 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7640 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7641 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7642 | } finally { |
| 7643 | Binder.restoreCallingIdentity(identity); |
| 7644 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7645 | } |
| 7646 | |
| 7647 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7648 | * Sets the per-account voicemail ringtone. |
| 7649 | * |
| 7650 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7651 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7652 | * |
| 7653 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7654 | * voicemail ringtone. |
| 7655 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7656 | * PhoneAccount. |
| 7657 | */ |
| 7658 | @Override |
| 7659 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7660 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7661 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7662 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7663 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7664 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7665 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7666 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7667 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7668 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7669 | |
| 7670 | final long identity = Binder.clearCallingIdentity(); |
| 7671 | try { |
| 7672 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7673 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7674 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7675 | } |
| 7676 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7677 | } finally { |
| 7678 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7679 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7680 | } |
| 7681 | |
| 7682 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7683 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7684 | * |
| 7685 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7686 | * voicemail vibration setting. |
| 7687 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7688 | */ |
| 7689 | @Override |
| 7690 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7691 | final long identity = Binder.clearCallingIdentity(); |
| 7692 | try { |
| 7693 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7694 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7695 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7696 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7697 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7698 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7699 | } finally { |
| 7700 | Binder.restoreCallingIdentity(identity); |
| 7701 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7702 | } |
| 7703 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7704 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7705 | * Sets the per-account voicemail vibration. |
| 7706 | * |
| 7707 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7708 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7709 | * |
| 7710 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7711 | * voicemail vibration setting. |
| 7712 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7713 | * specific PhoneAccount. |
| 7714 | */ |
| 7715 | @Override |
| 7716 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7717 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7718 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7719 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7720 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7721 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7722 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7723 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7724 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7725 | } |
| 7726 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7727 | final long identity = Binder.clearCallingIdentity(); |
| 7728 | try { |
| 7729 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7730 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7731 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7732 | } |
| 7733 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7734 | } finally { |
| 7735 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7736 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7737 | } |
| 7738 | |
| 7739 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7740 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7741 | * |
| 7742 | * @throws SecurityException if the caller does not have the required permission |
| 7743 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7744 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7745 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7746 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7747 | } |
| 7748 | |
| 7749 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7750 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7751 | * permission. |
| 7752 | * |
| 7753 | * @throws SecurityException if the caller does not have the required permission |
| 7754 | */ |
| 7755 | private void enforceSendSmsPermission() { |
| 7756 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7757 | } |
| 7758 | |
| 7759 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7760 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7761 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7762 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7763 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7764 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7765 | final long identity = Binder.clearCallingIdentity(); |
| 7766 | try { |
| 7767 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7768 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7769 | if (componentName == null) { |
| 7770 | throw new SecurityException( |
| 7771 | "Caller not current active visual voicemail package[null]"); |
| 7772 | } |
| 7773 | String vvmPackage = componentName.getPackageName(); |
| 7774 | if (!callingPackage.equals(vvmPackage)) { |
| 7775 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7776 | + vvmPackage + "]"); |
| 7777 | } |
| 7778 | } finally { |
| 7779 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7780 | } |
| 7781 | } |
| 7782 | |
| 7783 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7784 | * Return the application ID for the app type. |
| 7785 | * |
| 7786 | * @param subId the subscription ID that this request applies to. |
| 7787 | * @param appType the uicc app type. |
| 7788 | * @return Application ID for specificied app type, or null if no uicc. |
| 7789 | */ |
| 7790 | @Override |
| 7791 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7792 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7793 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7794 | |
| 7795 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7796 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7797 | if (phone == null) { |
| 7798 | return null; |
| 7799 | } |
| 7800 | String aid = null; |
| 7801 | try { |
| 7802 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7803 | .getApplicationByType(appType).getAid(); |
| 7804 | } catch (Exception e) { |
| 7805 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7806 | } |
| 7807 | return aid; |
| 7808 | } finally { |
| 7809 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7810 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7811 | } |
| 7812 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7813 | /** |
| 7814 | * Return the Electronic Serial Number. |
| 7815 | * |
| 7816 | * @param subId the subscription ID that this request applies to. |
| 7817 | * @return ESN or null if error. |
| 7818 | */ |
| 7819 | @Override |
| 7820 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7821 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7822 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7823 | |
| 7824 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7825 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7826 | if (phone == null) { |
| 7827 | return null; |
| 7828 | } |
| 7829 | String esn = null; |
| 7830 | try { |
| 7831 | esn = phone.getEsn(); |
| 7832 | } catch (Exception e) { |
| 7833 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7834 | } |
| 7835 | return esn; |
| 7836 | } finally { |
| 7837 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7838 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7839 | } |
| 7840 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7841 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7842 | * Return the Preferred Roaming List Version. |
| 7843 | * |
| 7844 | * @param subId the subscription ID that this request applies to. |
| 7845 | * @return PRLVersion or null if error. |
| 7846 | */ |
| 7847 | @Override |
| 7848 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7849 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7850 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7851 | |
| 7852 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7853 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7854 | if (phone == null) { |
| 7855 | return null; |
| 7856 | } |
| 7857 | String cdmaPrlVersion = null; |
| 7858 | try { |
| 7859 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7860 | } catch (Exception e) { |
| 7861 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7862 | } |
| 7863 | return cdmaPrlVersion; |
| 7864 | } finally { |
| 7865 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7866 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7867 | } |
| 7868 | |
| 7869 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7870 | * Get snapshot of Telephony histograms |
| 7871 | * @return List of Telephony histograms |
| 7872 | * @hide |
| 7873 | */ |
| 7874 | @Override |
| 7875 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7876 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7877 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7878 | |
| 7879 | final long identity = Binder.clearCallingIdentity(); |
| 7880 | try { |
| 7881 | return RIL.getTelephonyRILTimingHistograms(); |
| 7882 | } finally { |
| 7883 | Binder.restoreCallingIdentity(identity); |
| 7884 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7885 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7886 | |
| 7887 | /** |
| 7888 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7889 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7890 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7891 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7892 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7893 | * @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] | 7894 | */ |
| 7895 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7896 | @TelephonyManager.SetCarrierRestrictionResult |
| 7897 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7898 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7899 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7900 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7901 | if (carrierRestrictionRules == null) { |
| 7902 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7903 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7904 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7905 | final long identity = Binder.clearCallingIdentity(); |
| 7906 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7907 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7908 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7909 | } finally { |
| 7910 | Binder.restoreCallingIdentity(identity); |
| 7911 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7912 | } |
| 7913 | |
| 7914 | /** |
| 7915 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7916 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7917 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7918 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7919 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7920 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7921 | */ |
| 7922 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7923 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7924 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7925 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7926 | |
| 7927 | final long identity = Binder.clearCallingIdentity(); |
| 7928 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7929 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7930 | if (response instanceof CarrierRestrictionRules) { |
| 7931 | return (CarrierRestrictionRules) response; |
| 7932 | } |
| 7933 | // Response is an Exception of some kind, |
| 7934 | // which is signalled to the user as a NULL retval |
| 7935 | return null; |
| 7936 | } catch (Exception e) { |
| 7937 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7938 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7939 | } finally { |
| 7940 | Binder.restoreCallingIdentity(identity); |
| 7941 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7942 | } |
| 7943 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7944 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7945 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7946 | * @param subId the subscription ID that this action applies to. |
| 7947 | * @param enabled control enable or disable radio. |
| 7948 | * {@hide} |
| 7949 | */ |
| 7950 | @Override |
| 7951 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7952 | enforceModifyPermission(); |
| 7953 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7954 | |
| 7955 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7956 | if (phone == null) { |
| 7957 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7958 | return; |
| 7959 | } |
| 7960 | try { |
| 7961 | phone.carrierActionSetRadioEnabled(enabled); |
| 7962 | } catch (Exception e) { |
| 7963 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7964 | } finally { |
| 7965 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7966 | } |
| 7967 | } |
| 7968 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7969 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7970 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7971 | * network status based on which carrier apps could apply actions accordingly, |
| 7972 | * enable/disable default url handler for example. |
| 7973 | * |
| 7974 | * @param subId the subscription ID that this action applies to. |
| 7975 | * @param report control start/stop reporting the default network status. |
| 7976 | * {@hide} |
| 7977 | */ |
| 7978 | @Override |
| 7979 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7980 | enforceModifyPermission(); |
| 7981 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7982 | |
| 7983 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7984 | if (phone == null) { |
| 7985 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7986 | return; |
| 7987 | } |
| 7988 | try { |
| 7989 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7990 | } catch (Exception e) { |
| 7991 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7992 | } finally { |
| 7993 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7994 | } |
| 7995 | } |
| 7996 | |
| 7997 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7998 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7999 | * @param subId the subscription ID that this action applies to. |
| 8000 | * {@hide} |
| 8001 | */ |
| 8002 | @Override |
| 8003 | public void carrierActionResetAll(int subId) { |
| 8004 | enforceModifyPermission(); |
| 8005 | final Phone phone = getPhone(subId); |
| 8006 | if (phone == null) { |
| 8007 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8008 | return; |
| 8009 | } |
| 8010 | try { |
| 8011 | phone.carrierActionResetAll(); |
| 8012 | } catch (Exception e) { |
| 8013 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8014 | } |
| 8015 | } |
| 8016 | |
| 8017 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8018 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8019 | * bug report is being generated. |
| 8020 | */ |
| 8021 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8022 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8023 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8024 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8025 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8026 | + Binder.getCallingPid() |
| 8027 | + ", uid=" + Binder.getCallingUid() |
| 8028 | + "without permission " |
| 8029 | + android.Manifest.permission.DUMP); |
| 8030 | return; |
| 8031 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8032 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8033 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8034 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8035 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8036 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8037 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8038 | @NonNull String[] args) { |
| 8039 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8040 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8041 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8042 | } |
| 8043 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8044 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8045 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8046 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8047 | * @param reason the reason the data enable change is taking place |
| 8048 | * @param enabled True if enabling the data, otherwise disabling. |
| 8049 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8050 | */ |
| 8051 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8052 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8053 | boolean enabled) { |
| 8054 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8055 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8056 | try { |
| 8057 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8058 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8059 | } catch (SecurityException se) { |
| 8060 | enforceModifyPermission(); |
| 8061 | } |
| 8062 | } else { |
| 8063 | enforceModifyPermission(); |
| 8064 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8065 | |
| 8066 | final long identity = Binder.clearCallingIdentity(); |
| 8067 | try { |
| 8068 | Phone phone = getPhone(subId); |
| 8069 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8070 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8071 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8072 | } else { |
| 8073 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 8074 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8075 | } |
| 8076 | } finally { |
| 8077 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8078 | } |
| 8079 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8080 | |
| 8081 | /** |
| 8082 | * Get Client request stats |
| 8083 | * @return List of Client Request Stats |
| 8084 | * @hide |
| 8085 | */ |
| 8086 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8087 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8088 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8089 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8090 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8091 | return null; |
| 8092 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8093 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8094 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8095 | final long identity = Binder.clearCallingIdentity(); |
| 8096 | try { |
| 8097 | if (phone != null) { |
| 8098 | return phone.getClientRequestStats(); |
| 8099 | } |
| 8100 | |
| 8101 | return null; |
| 8102 | } finally { |
| 8103 | Binder.restoreCallingIdentity(identity); |
| 8104 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8105 | } |
| 8106 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8107 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8108 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8109 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8110 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8111 | |
| 8112 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8113 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8114 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8115 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8116 | * @param state State of SIM (power down, power up, pass through) |
| 8117 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8118 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8119 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8120 | * |
| 8121 | **/ |
| 8122 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8123 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8124 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8125 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8126 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8127 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8128 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8129 | final long identity = Binder.clearCallingIdentity(); |
| 8130 | try { |
| 8131 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8132 | phone.setSimPowerState(state, null, workSource); |
| 8133 | } |
| 8134 | } finally { |
| 8135 | Binder.restoreCallingIdentity(identity); |
| 8136 | } |
| 8137 | } |
| 8138 | |
| 8139 | /** |
| 8140 | * Set SIM card power state. |
| 8141 | * |
| 8142 | * @param slotIndex SIM slot id. |
| 8143 | * @param state State of SIM (power down, power up, pass through) |
| 8144 | * @param callback callback to trigger after success or failure |
| 8145 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8146 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8147 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8148 | * |
| 8149 | **/ |
| 8150 | @Override |
| 8151 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8152 | IIntegerConsumer callback) { |
| 8153 | enforceModifyPermission(); |
| 8154 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8155 | |
| 8156 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8157 | |
| 8158 | final long identity = Binder.clearCallingIdentity(); |
| 8159 | try { |
| 8160 | if (phone != null) { |
| 8161 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8162 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8163 | } |
| 8164 | } finally { |
| 8165 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8166 | } |
| 8167 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8168 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8169 | private boolean isUssdApiAllowed(int subId) { |
| 8170 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8171 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8172 | if (configManager == null) { |
| 8173 | return false; |
| 8174 | } |
| 8175 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8176 | if (pb == null) { |
| 8177 | return false; |
| 8178 | } |
| 8179 | return pb.getBoolean( |
| 8180 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8181 | } |
| 8182 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8183 | /** |
| 8184 | * Check if phone is in emergency callback mode |
| 8185 | * @return true if phone is in emergency callback mode |
| 8186 | * @param subId sub id |
| 8187 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8188 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8189 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8190 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8191 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8192 | |
| 8193 | final long identity = Binder.clearCallingIdentity(); |
| 8194 | try { |
| 8195 | if (phone != null) { |
| 8196 | return phone.isInEcm(); |
| 8197 | } else { |
| 8198 | return false; |
| 8199 | } |
| 8200 | } finally { |
| 8201 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8202 | } |
| 8203 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8204 | |
| 8205 | /** |
| 8206 | * Get the current signal strength information for the given subscription. |
| 8207 | * Because this information is not updated when the device is in a low power state |
| 8208 | * it should not be relied-upon to be current. |
| 8209 | * @param subId Subscription index |
| 8210 | * @return the most recent cached signal strength info from the modem |
| 8211 | */ |
| 8212 | @Override |
| 8213 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8214 | final long identity = Binder.clearCallingIdentity(); |
| 8215 | try { |
| 8216 | Phone p = getPhone(subId); |
| 8217 | if (p == null) { |
| 8218 | return null; |
| 8219 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8220 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8221 | return p.getSignalStrength(); |
| 8222 | } finally { |
| 8223 | Binder.restoreCallingIdentity(identity); |
| 8224 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8225 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8226 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8227 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8228 | * Get the current modem radio state for the given slot. |
| 8229 | * @param slotIndex slot index. |
| 8230 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8231 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8232 | * @return the current radio power state from the modem |
| 8233 | */ |
| 8234 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8235 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8236 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8237 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8238 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8239 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8240 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8241 | } |
| 8242 | |
| 8243 | final long identity = Binder.clearCallingIdentity(); |
| 8244 | try { |
| 8245 | return phone.getRadioPowerState(); |
| 8246 | } finally { |
| 8247 | Binder.restoreCallingIdentity(identity); |
| 8248 | } |
| 8249 | } |
| 8250 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8251 | } |
| 8252 | |
| 8253 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8254 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8255 | * |
| 8256 | * <p>Requires one of the following permissions: |
| 8257 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 8258 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8259 | * privileges. |
| 8260 | * |
| 8261 | * @param subId subscription id |
| 8262 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8263 | * {@code false}. |
| 8264 | */ |
| 8265 | @Override |
| 8266 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8267 | try { |
| 8268 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8269 | null); |
| 8270 | } catch (Exception e) { |
| 8271 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 8272 | mApp, subId, "isDataRoamingEnabled"); |
| 8273 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8274 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8275 | boolean isEnabled = false; |
| 8276 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8277 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8278 | Phone phone = getPhone(subId); |
| 8279 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8280 | } finally { |
| 8281 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8282 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8283 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8284 | } |
| 8285 | |
| 8286 | |
| 8287 | /** |
| 8288 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8289 | * |
| 8290 | * <p> Requires permission: |
| 8291 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8292 | * privileges. |
| 8293 | * |
| 8294 | * @param subId subscription id |
| 8295 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8296 | */ |
| 8297 | @Override |
| 8298 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8299 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8300 | mApp, subId, "setDataRoamingEnabled"); |
| 8301 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8302 | final long identity = Binder.clearCallingIdentity(); |
| 8303 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8304 | Phone phone = getPhone(subId); |
| 8305 | if (phone != null) { |
| 8306 | phone.setDataRoamingEnabled(isEnabled); |
| 8307 | } |
| 8308 | } finally { |
| 8309 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8310 | } |
| 8311 | } |
| 8312 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8313 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8314 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8315 | TelephonyPermissions |
| 8316 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8317 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8318 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8319 | boolean isAllowed = true; |
| 8320 | final long identity = Binder.clearCallingIdentity(); |
| 8321 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8322 | Phone phone = getPhone(subId); |
| 8323 | if (phone != null) { |
| 8324 | isAllowed = phone.isCspPlmnEnabled(); |
| 8325 | } |
| 8326 | } finally { |
| 8327 | Binder.restoreCallingIdentity(identity); |
| 8328 | } |
| 8329 | return isAllowed; |
| 8330 | } |
| 8331 | |
| 8332 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8333 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8334 | // Verify that tha callingPackage belongs to the calling UID |
| 8335 | mApp.getSystemService(AppOpsManager.class) |
| 8336 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8337 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8338 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8339 | try { |
| 8340 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8341 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8342 | } catch (SecurityException e) { |
| 8343 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8344 | // has carrier privileges on an active UICC |
| 8345 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8346 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8347 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8348 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8349 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8350 | |
| 8351 | final long identity = Binder.clearCallingIdentity(); |
| 8352 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8353 | UiccController uiccController = UiccController.getInstance(); |
| 8354 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8355 | if (hasReadPermission) { |
| 8356 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8357 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8358 | |
| 8359 | // Remove private info if the caller doesn't have access |
| 8360 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8361 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8362 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8363 | // is available |
| 8364 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 8365 | if (card == null || card.getUiccProfile() == null) { |
| 8366 | // assume no access if the card or profile is unavailable |
| 8367 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8368 | continue; |
| 8369 | } |
| 8370 | UiccProfile profile = card.getUiccProfile(); |
| 8371 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8372 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8373 | filteredInfos.add(cardInfo); |
| 8374 | } else { |
| 8375 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8376 | } |
| 8377 | } |
| 8378 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8379 | } finally { |
| 8380 | Binder.restoreCallingIdentity(identity); |
| 8381 | } |
| 8382 | } |
| 8383 | |
| 8384 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8385 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8386 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8387 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8388 | final long identity = Binder.clearCallingIdentity(); |
| 8389 | try { |
| 8390 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8391 | if (slots == null) { |
| 8392 | Rlog.i(LOG_TAG, "slots is null."); |
| 8393 | return null; |
| 8394 | } |
| 8395 | |
| 8396 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8397 | for (int i = 0; i < slots.length; i++) { |
| 8398 | UiccSlot slot = slots[i]; |
| 8399 | if (slot == null) { |
| 8400 | continue; |
| 8401 | } |
| 8402 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8403 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8404 | UiccCard card = slot.getUiccCard(); |
| 8405 | if (card != null) { |
| 8406 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8407 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8408 | cardId = slot.getEid(); |
| 8409 | if (TextUtils.isEmpty(cardId)) { |
| 8410 | cardId = slot.getIccId(); |
| 8411 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8412 | } |
| 8413 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8414 | if (cardId != null) { |
| 8415 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8416 | // if cardId is an EID, it's all digits so this is fine |
| 8417 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8418 | } |
| 8419 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8420 | int cardState = 0; |
| 8421 | switch (slot.getCardState()) { |
| 8422 | case CARDSTATE_ABSENT: |
| 8423 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8424 | break; |
| 8425 | case CARDSTATE_PRESENT: |
| 8426 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8427 | break; |
| 8428 | case CARDSTATE_ERROR: |
| 8429 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8430 | break; |
| 8431 | case CARDSTATE_RESTRICTED: |
| 8432 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8433 | break; |
| 8434 | default: |
| 8435 | break; |
| 8436 | |
| 8437 | } |
| 8438 | |
| 8439 | infos[i] = new UiccSlotInfo( |
| 8440 | slot.isActive(), |
| 8441 | slot.isEuicc(), |
| 8442 | cardId, |
| 8443 | cardState, |
| 8444 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8445 | slot.isExtendedApduSupported(), |
| 8446 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8447 | } |
| 8448 | return infos; |
| 8449 | } finally { |
| 8450 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8451 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8452 | } |
| 8453 | |
| 8454 | @Override |
| 8455 | public boolean switchSlots(int[] physicalSlots) { |
| 8456 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8457 | |
| 8458 | final long identity = Binder.clearCallingIdentity(); |
| 8459 | try { |
| 8460 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8461 | } finally { |
| 8462 | Binder.restoreCallingIdentity(identity); |
| 8463 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8464 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8465 | |
| 8466 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8467 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8468 | final long identity = Binder.clearCallingIdentity(); |
| 8469 | try { |
| 8470 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8471 | } finally { |
| 8472 | Binder.restoreCallingIdentity(identity); |
| 8473 | } |
| 8474 | } |
| 8475 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8476 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8477 | * A test API to reload the UICC profile. |
| 8478 | * |
| 8479 | * <p>Requires that the calling app has permission |
| 8480 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8481 | * @hide |
| 8482 | */ |
| 8483 | @Override |
| 8484 | public void refreshUiccProfile(int subId) { |
| 8485 | enforceModifyPermission(); |
| 8486 | |
| 8487 | final long identity = Binder.clearCallingIdentity(); |
| 8488 | try { |
| 8489 | Phone phone = getPhone(subId); |
| 8490 | if (phone == null) { |
| 8491 | return; |
| 8492 | } |
| 8493 | UiccCard uiccCard = phone.getUiccCard(); |
| 8494 | if (uiccCard == null) { |
| 8495 | return; |
| 8496 | } |
| 8497 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8498 | if (uiccProfile == null) { |
| 8499 | return; |
| 8500 | } |
| 8501 | uiccProfile.refresh(); |
| 8502 | } finally { |
| 8503 | Binder.restoreCallingIdentity(identity); |
| 8504 | } |
| 8505 | } |
| 8506 | |
| 8507 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8508 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8509 | */ |
| 8510 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8511 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8512 | } |
| 8513 | |
| 8514 | /** |
| 8515 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8516 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8517 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8518 | */ |
| 8519 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8520 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8521 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8522 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8523 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8524 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8525 | return isDataRoamingEnabled; |
| 8526 | } |
| 8527 | |
| 8528 | /** |
| 8529 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8530 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8531 | */ |
| 8532 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8533 | List<Integer> list = TelephonyProperties.default_network(); |
| 8534 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8535 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8536 | return list.get(phoneId); |
| 8537 | } |
| 8538 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8539 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8540 | |
| 8541 | @Override |
| 8542 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8543 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8544 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8545 | |
| 8546 | final long identity = Binder.clearCallingIdentity(); |
| 8547 | try { |
| 8548 | final Phone phone = getPhone(subId); |
| 8549 | if (phone == null) { |
| 8550 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8551 | return; |
| 8552 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8553 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8554 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8555 | if (carrierPrivilegeRules == null) { |
| 8556 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8557 | } else { |
| 8558 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8559 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8560 | } finally { |
| 8561 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8562 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8563 | } |
| 8564 | |
| 8565 | @Override |
| 8566 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8567 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8568 | |
| 8569 | final long identity = Binder.clearCallingIdentity(); |
| 8570 | try { |
| 8571 | final Phone phone = getPhone(subId); |
| 8572 | if (phone == null) { |
| 8573 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8574 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8575 | } |
| 8576 | return phone.getCarrierIdListVersion(); |
| 8577 | } finally { |
| 8578 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8579 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8580 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8581 | |
| 8582 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8583 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8584 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8585 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8586 | mApp, subId, callingPackage, callingFeatureId, |
| 8587 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8588 | return -1; |
| 8589 | } |
| 8590 | |
| 8591 | final long identity = Binder.clearCallingIdentity(); |
| 8592 | try { |
| 8593 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8594 | } finally { |
| 8595 | Binder.restoreCallingIdentity(identity); |
| 8596 | } |
| 8597 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8598 | |
| 8599 | @Override |
| 8600 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8601 | TelephonyPermissions |
| 8602 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8603 | mApp, subId, "getCdmaRoamingMode"); |
| 8604 | |
| 8605 | final long identity = Binder.clearCallingIdentity(); |
| 8606 | try { |
| 8607 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8608 | } finally { |
| 8609 | Binder.restoreCallingIdentity(identity); |
| 8610 | } |
| 8611 | } |
| 8612 | |
| 8613 | @Override |
| 8614 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8615 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8616 | mApp, subId, "setCdmaRoamingMode"); |
| 8617 | |
| 8618 | final long identity = Binder.clearCallingIdentity(); |
| 8619 | try { |
| 8620 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8621 | } finally { |
| 8622 | Binder.restoreCallingIdentity(identity); |
| 8623 | } |
| 8624 | } |
| 8625 | |
| 8626 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8627 | public int getCdmaSubscriptionMode(int subId) { |
| 8628 | TelephonyPermissions |
| 8629 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8630 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8631 | |
| 8632 | final long identity = Binder.clearCallingIdentity(); |
| 8633 | try { |
| 8634 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8635 | } finally { |
| 8636 | Binder.restoreCallingIdentity(identity); |
| 8637 | } |
| 8638 | } |
| 8639 | |
| 8640 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8641 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8642 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8643 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8644 | |
| 8645 | final long identity = Binder.clearCallingIdentity(); |
| 8646 | try { |
| 8647 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8648 | } finally { |
| 8649 | Binder.restoreCallingIdentity(identity); |
| 8650 | } |
| 8651 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8652 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8653 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8654 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8655 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8656 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8657 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8658 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8659 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8660 | } |
| 8661 | final long identity = Binder.clearCallingIdentity(); |
| 8662 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8663 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8664 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8665 | if (phone.getEmergencyNumberTracker() != null |
| 8666 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8667 | emergencyNumberListInternal.put( |
| 8668 | phone.getSubId(), |
| 8669 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8670 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8671 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8672 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8673 | } finally { |
| 8674 | Binder.restoreCallingIdentity(identity); |
| 8675 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8676 | } |
| 8677 | |
| 8678 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8679 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8680 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8681 | if (!exactMatch) { |
| 8682 | TelephonyPermissions |
| 8683 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8684 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8685 | } |
| 8686 | final long identity = Binder.clearCallingIdentity(); |
| 8687 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8688 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8689 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8690 | && phone.getEmergencyNumberTracker() |
| 8691 | .isEmergencyNumber(number, exactMatch)) { |
| 8692 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8693 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8694 | } |
| 8695 | return false; |
| 8696 | } finally { |
| 8697 | Binder.restoreCallingIdentity(identity); |
| 8698 | } |
| 8699 | } |
| 8700 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8701 | /** |
| 8702 | * Update emergency number list for test mode. |
| 8703 | */ |
| 8704 | @Override |
| 8705 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8706 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8707 | "updateEmergencyNumberListTestMode"); |
| 8708 | |
| 8709 | final long identity = Binder.clearCallingIdentity(); |
| 8710 | try { |
| 8711 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8712 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8713 | if (tracker != null) { |
| 8714 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8715 | } |
| 8716 | } |
| 8717 | } finally { |
| 8718 | Binder.restoreCallingIdentity(identity); |
| 8719 | } |
| 8720 | } |
| 8721 | |
| 8722 | /** |
| 8723 | * Get the full emergency number list for test mode. |
| 8724 | */ |
| 8725 | @Override |
| 8726 | public List<String> getEmergencyNumberListTestMode() { |
| 8727 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8728 | "getEmergencyNumberListTestMode"); |
| 8729 | |
| 8730 | final long identity = Binder.clearCallingIdentity(); |
| 8731 | try { |
| 8732 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8733 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8734 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8735 | if (tracker != null) { |
| 8736 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8737 | emergencyNumbers.add(num.getNumber()); |
| 8738 | } |
| 8739 | } |
| 8740 | } |
| 8741 | return new ArrayList<>(emergencyNumbers); |
| 8742 | } finally { |
| 8743 | Binder.restoreCallingIdentity(identity); |
| 8744 | } |
| 8745 | } |
| 8746 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8747 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8748 | public int getEmergencyNumberDbVersion(int subId) { |
| 8749 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8750 | |
| 8751 | final long identity = Binder.clearCallingIdentity(); |
| 8752 | try { |
| 8753 | final Phone phone = getPhone(subId); |
| 8754 | if (phone == null) { |
| 8755 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8756 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8757 | } |
| 8758 | return phone.getEmergencyNumberDbVersion(); |
| 8759 | } finally { |
| 8760 | Binder.restoreCallingIdentity(identity); |
| 8761 | } |
| 8762 | } |
| 8763 | |
| 8764 | @Override |
| 8765 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8766 | enforceModifyPermission(); |
| 8767 | |
| 8768 | final long identity = Binder.clearCallingIdentity(); |
| 8769 | try { |
| 8770 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8771 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8772 | if (tracker != null) { |
| 8773 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8774 | } |
| 8775 | } |
| 8776 | } finally { |
| 8777 | Binder.restoreCallingIdentity(identity); |
| 8778 | } |
| 8779 | } |
| 8780 | |
| 8781 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8782 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8783 | enforceActiveEmergencySessionPermission(); |
| 8784 | |
| 8785 | final long identity = Binder.clearCallingIdentity(); |
| 8786 | try { |
| 8787 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8788 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8789 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8790 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8791 | } |
| 8792 | } |
| 8793 | } finally { |
| 8794 | Binder.restoreCallingIdentity(identity); |
| 8795 | } |
| 8796 | } |
| 8797 | |
| 8798 | @Override |
| 8799 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8800 | enforceActiveEmergencySessionPermission(); |
| 8801 | |
| 8802 | final long identity = Binder.clearCallingIdentity(); |
| 8803 | try { |
| 8804 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8805 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8806 | if (tracker != null) { |
| 8807 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8808 | } |
| 8809 | } |
| 8810 | } finally { |
| 8811 | Binder.restoreCallingIdentity(identity); |
| 8812 | } |
| 8813 | } |
| 8814 | |
| 8815 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8816 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8817 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8818 | Phone phone = getPhone(subId); |
| 8819 | if (phone == null) { |
| 8820 | return null; |
| 8821 | } |
| 8822 | final long identity = Binder.clearCallingIdentity(); |
| 8823 | try { |
| 8824 | UiccProfile profile = UiccController.getInstance() |
| 8825 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8826 | if (profile != null) { |
| 8827 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8828 | } |
| 8829 | } finally { |
| 8830 | Binder.restoreCallingIdentity(identity); |
| 8831 | } |
| 8832 | return null; |
| 8833 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8834 | |
| 8835 | /** |
| 8836 | * Enable or disable a modem stack. |
| 8837 | */ |
| 8838 | @Override |
| 8839 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8840 | enforceModifyPermission(); |
| 8841 | |
| 8842 | final long identity = Binder.clearCallingIdentity(); |
| 8843 | try { |
| 8844 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8845 | if (phone == null) { |
| 8846 | return false; |
| 8847 | } else { |
| 8848 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8849 | } |
| 8850 | } finally { |
| 8851 | Binder.restoreCallingIdentity(identity); |
| 8852 | } |
| 8853 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8854 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8855 | /** |
| 8856 | * Whether a modem stack is enabled or not. |
| 8857 | */ |
| 8858 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8859 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8860 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8861 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8862 | if (phone == null) return false; |
| 8863 | |
| 8864 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8865 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8866 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8867 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8868 | } |
| 8869 | |
| 8870 | final long identity = Binder.clearCallingIdentity(); |
| 8871 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8872 | try { |
| 8873 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8874 | } catch (NoSuchElementException ex) { |
| 8875 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8876 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8877 | } finally { |
| 8878 | Binder.restoreCallingIdentity(identity); |
| 8879 | } |
| 8880 | } |
| 8881 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8882 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8883 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8884 | enforceModifyPermission(); |
| 8885 | |
| 8886 | final long identity = Binder.clearCallingIdentity(); |
| 8887 | try { |
| 8888 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8889 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8890 | .commit(); |
| 8891 | } finally { |
| 8892 | Binder.restoreCallingIdentity(identity); |
| 8893 | } |
| 8894 | } |
| 8895 | |
| 8896 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8897 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8898 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8899 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8900 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8901 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8902 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8903 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8904 | |
| 8905 | final long identity = Binder.clearCallingIdentity(); |
| 8906 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8907 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8908 | } finally { |
| 8909 | Binder.restoreCallingIdentity(identity); |
| 8910 | } |
| 8911 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8912 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8913 | @TelephonyManager.IsMultiSimSupportedResult |
| 8914 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8915 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8916 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8917 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8918 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8919 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8920 | } |
| 8921 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8922 | // supported by the modem, indicate that it is restricted. |
| 8923 | PhoneCapability staticCapability = |
| 8924 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8925 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8926 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8927 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8928 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 8929 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8930 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8931 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8932 | } |
| 8933 | // Check if support of multiple SIMs is restricted by carrier |
| 8934 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8935 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8936 | } |
| 8937 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8938 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8939 | } |
| 8940 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8941 | /** |
| 8942 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8943 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8944 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8945 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8946 | * @param numOfSims number of active sims we want to switch to |
| 8947 | */ |
| 8948 | @Override |
| 8949 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8950 | if (numOfSims == 1) { |
| 8951 | enforceModifyPermission(); |
| 8952 | } else { |
| 8953 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8954 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8955 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8956 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8957 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8958 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8959 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8960 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8961 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8962 | return; |
| 8963 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8964 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8965 | } finally { |
| 8966 | Binder.restoreCallingIdentity(identity); |
| 8967 | } |
| 8968 | } |
| 8969 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8970 | @Override |
| 8971 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8972 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8973 | Phone phone = getPhone(subId); |
| 8974 | if (phone == null) { |
| 8975 | return false; |
| 8976 | } |
| 8977 | final long identity = Binder.clearCallingIdentity(); |
| 8978 | try { |
| 8979 | UiccCard uiccCard = phone.getUiccCard(); |
| 8980 | if (uiccCard == null) { |
| 8981 | return false; |
| 8982 | } |
| 8983 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8984 | if (uiccProfile == null) { |
| 8985 | return false; |
| 8986 | } |
| 8987 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8988 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8989 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8990 | } |
| 8991 | return false; |
| 8992 | } finally { |
| 8993 | Binder.restoreCallingIdentity(identity); |
| 8994 | } |
| 8995 | } |
| 8996 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8997 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8998 | * Get whether making changes to modem configurations will trigger reboot. |
| 8999 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9000 | */ |
| 9001 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9002 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9003 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9004 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9005 | mApp, subId, callingPackage, callingFeatureId, |
| 9006 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9007 | return false; |
| 9008 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9009 | final long identity = Binder.clearCallingIdentity(); |
| 9010 | try { |
| 9011 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9012 | } finally { |
| 9013 | Binder.restoreCallingIdentity(identity); |
| 9014 | } |
| 9015 | } |
| 9016 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9017 | private void updateModemStateMetrics() { |
| 9018 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9019 | // TODO: check the state for each modem if the api is ready. |
| 9020 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9021 | } |
| 9022 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9023 | @Override |
| 9024 | public int[] getSlotsMapping() { |
| 9025 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 9026 | |
| 9027 | final long identity = Binder.clearCallingIdentity(); |
| 9028 | try { |
| 9029 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 9030 | // All logical slots should have a mapping to a physical slot. |
| 9031 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 9032 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 9033 | for (int i = 0; i < slotInfos.length; i++) { |
| 9034 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 9035 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 9036 | } |
| 9037 | } |
| 9038 | return logicalSlotsMapping; |
| 9039 | } finally { |
| 9040 | Binder.restoreCallingIdentity(identity); |
| 9041 | } |
| 9042 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9043 | |
| 9044 | /** |
| 9045 | * Get the IRadio HAL Version |
| 9046 | */ |
| 9047 | @Override |
| 9048 | public int getRadioHalVersion() { |
| 9049 | Phone phone = getDefaultPhone(); |
| 9050 | if (phone == null) return -1; |
| 9051 | HalVersion hv = phone.getHalVersion(); |
| 9052 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9053 | return hv.major * 100 + hv.minor; |
| 9054 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9055 | |
| 9056 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9057 | * Get the current calling package name. |
| 9058 | * @return the current calling package name |
| 9059 | */ |
| 9060 | @Override |
| 9061 | public String getCurrentPackageName() { |
| 9062 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9063 | } |
| 9064 | |
| 9065 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9066 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9067 | * corresponding network requests on a subId. |
| 9068 | * |
| 9069 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9070 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9071 | * 2) APN is un-metered for this subscription, or |
| 9072 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9073 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9074 | * |
| 9075 | * @return whether data is allowed for a apn type. |
| 9076 | * |
| 9077 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9078 | */ |
| 9079 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9080 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9081 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9082 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9083 | |
| 9084 | // Now that all security checks passes, perform the operation as ourselves. |
| 9085 | final long identity = Binder.clearCallingIdentity(); |
| 9086 | try { |
| 9087 | Phone phone = getPhone(subId); |
| 9088 | if (phone == null) return false; |
| 9089 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9090 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9091 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 9092 | } finally { |
| 9093 | Binder.restoreCallingIdentity(identity); |
| 9094 | } |
| 9095 | } |
| 9096 | |
| 9097 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9098 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9099 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9100 | |
| 9101 | // Now that all security checks passes, perform the operation as ourselves. |
| 9102 | final long identity = Binder.clearCallingIdentity(); |
| 9103 | try { |
| 9104 | Phone phone = getPhone(subId); |
| 9105 | if (phone == null) return true; // By default return true. |
| 9106 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9107 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9108 | } finally { |
| 9109 | Binder.restoreCallingIdentity(identity); |
| 9110 | } |
| 9111 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9112 | |
| 9113 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9114 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9115 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9116 | enforceModifyPermission(); |
| 9117 | long token = Binder.clearCallingIdentity(); |
| 9118 | try { |
| 9119 | Phone phone = getPhone(subscriptionId); |
| 9120 | if (phone == null) { |
| 9121 | try { |
| 9122 | if (resultCallback != null) { |
| 9123 | resultCallback.accept(false); |
| 9124 | } |
| 9125 | } catch (RemoteException e) { |
| 9126 | // ignore |
| 9127 | } |
| 9128 | return; |
| 9129 | } |
| 9130 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9131 | Pair.create(specifiers, (x) -> { |
| 9132 | try { |
| 9133 | if (resultCallback != null) { |
| 9134 | resultCallback.accept(x); |
| 9135 | } |
| 9136 | } catch (RemoteException e) { |
| 9137 | // ignore |
| 9138 | } |
| 9139 | }); |
| 9140 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9141 | } finally { |
| 9142 | Binder.restoreCallingIdentity(token); |
| 9143 | } |
| 9144 | } |
| 9145 | |
| 9146 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9147 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9148 | TelephonyPermissions |
| 9149 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 9150 | mApp, subId, "getSystemSelectionChannels"); |
| 9151 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9152 | final long identity = Binder.clearCallingIdentity(); |
| 9153 | try { |
| 9154 | List<RadioAccessSpecifier> specifiers = |
| 9155 | (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, |
| 9156 | null, subId, workSource); |
| 9157 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9158 | return specifiers; |
| 9159 | } finally { |
| 9160 | Binder.restoreCallingIdentity(identity); |
| 9161 | } |
| 9162 | } |
| 9163 | |
| 9164 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9165 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9166 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9167 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9168 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9169 | if (iccRecords == null) { |
| 9170 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9171 | return false; |
| 9172 | } |
| 9173 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9174 | } |
| 9175 | |
| 9176 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9177 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9178 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9179 | if (callingPackage == null) { |
| 9180 | callingPackage = getCurrentPackageName(); |
| 9181 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9182 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9183 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9184 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9185 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9186 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9187 | } |
| 9188 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9189 | Intent intent = new Intent(); |
| 9190 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9191 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9192 | // Bring up choose default SMS subscription dialog right now |
| 9193 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9194 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9195 | mApp.startActivity(intent); |
| 9196 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9197 | |
| 9198 | @Override |
| 9199 | public String getMmsUAProfUrl(int subId) { |
| 9200 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9201 | final long identity = Binder.clearCallingIdentity(); |
| 9202 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9203 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9204 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9205 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9206 | return carrierUAProfUrl; |
| 9207 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9208 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9209 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9210 | } finally { |
| 9211 | Binder.restoreCallingIdentity(identity); |
| 9212 | } |
| 9213 | } |
| 9214 | |
| 9215 | @Override |
| 9216 | public String getMmsUserAgent(int subId) { |
| 9217 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9218 | final long identity = Binder.clearCallingIdentity(); |
| 9219 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9220 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9221 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9222 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9223 | return carrierUserAgent; |
| 9224 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9225 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9226 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9227 | } finally { |
| 9228 | Binder.restoreCallingIdentity(identity); |
| 9229 | } |
| 9230 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9231 | |
| 9232 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9233 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9234 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9235 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9236 | final long identity = Binder.clearCallingIdentity(); |
| 9237 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9238 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9239 | if (phone == null) return false; |
| 9240 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9241 | switch (policy) { |
| 9242 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9243 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9244 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9245 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9246 | default: |
| 9247 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9248 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9249 | } finally { |
| 9250 | Binder.restoreCallingIdentity(identity); |
| 9251 | } |
| 9252 | } |
| 9253 | |
| 9254 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 9255 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9256 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9257 | enforceModifyPermission(); |
| 9258 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9259 | final long identity = Binder.clearCallingIdentity(); |
| 9260 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9261 | Phone phone = getPhone(subscriptionId); |
| 9262 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9263 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9264 | switch (policy) { |
| 9265 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9266 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9267 | break; |
| 9268 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9269 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9270 | break; |
| 9271 | default: |
| 9272 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9273 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9274 | } finally { |
| 9275 | Binder.restoreCallingIdentity(identity); |
| 9276 | } |
| 9277 | } |
| 9278 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9279 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9280 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9281 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9282 | * otherwise. |
| 9283 | */ |
| 9284 | @Override |
| 9285 | public void setCepEnabled(boolean isCepEnabled) { |
| 9286 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9287 | |
| 9288 | final long identity = Binder.clearCallingIdentity(); |
| 9289 | try { |
| 9290 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9291 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9292 | Phone defaultPhone = phone.getImsPhone(); |
| 9293 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9294 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9295 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9296 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9297 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9298 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9299 | + imsPhone.getMsisdn()); |
| 9300 | } |
| 9301 | } |
| 9302 | } finally { |
| 9303 | Binder.restoreCallingIdentity(identity); |
| 9304 | } |
| 9305 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9306 | |
| 9307 | /** |
| 9308 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9309 | * |
| 9310 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9311 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9312 | * before being read. |
| 9313 | */ |
| 9314 | @Override |
| 9315 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9316 | isCompressed) { |
| 9317 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9318 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9319 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9320 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9321 | } |
| 9322 | if (!isImsAvailableOnDevice()) { |
| 9323 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9324 | "IMS not available on device."); |
| 9325 | } |
| 9326 | |
| 9327 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9328 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9329 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9330 | } finally { |
| 9331 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9332 | } |
| 9333 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9334 | |
| 9335 | @Override |
| 9336 | public boolean isIccLockEnabled(int subId) { |
| 9337 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9338 | |
| 9339 | // Now that all security checks passes, perform the operation as ourselves. |
| 9340 | final long identity = Binder.clearCallingIdentity(); |
| 9341 | try { |
| 9342 | Phone phone = getPhone(subId); |
| 9343 | if (phone != null && phone.getIccCard() != null) { |
| 9344 | return phone.getIccCard().getIccLockEnabled(); |
| 9345 | } else { |
| 9346 | return false; |
| 9347 | } |
| 9348 | } finally { |
| 9349 | Binder.restoreCallingIdentity(identity); |
| 9350 | } |
| 9351 | } |
| 9352 | |
| 9353 | /** |
| 9354 | * Set the ICC pin lock enabled or disabled. |
| 9355 | * |
| 9356 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9357 | * three cases: |
| 9358 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9359 | * successfully. |
| 9360 | * - Positive number and zero for remaining password attempts. |
| 9361 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9362 | * |
| 9363 | */ |
| 9364 | @Override |
| 9365 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9366 | enforceModifyPermission(); |
| 9367 | |
| 9368 | Phone phone = getPhone(subId); |
| 9369 | if (phone == null) { |
| 9370 | return 0; |
| 9371 | } |
| 9372 | // Now that all security checks passes, perform the operation as ourselves. |
| 9373 | final long identity = Binder.clearCallingIdentity(); |
| 9374 | try { |
| 9375 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9376 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9377 | return attemptsRemaining; |
| 9378 | |
| 9379 | } catch (Exception e) { |
| 9380 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9381 | } finally { |
| 9382 | Binder.restoreCallingIdentity(identity); |
| 9383 | } |
| 9384 | return 0; |
| 9385 | } |
| 9386 | |
| 9387 | /** |
| 9388 | * Change the ICC password used in ICC pin lock. |
| 9389 | * |
| 9390 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9391 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9392 | * - Positive number and zero for remaining password attempts. |
| 9393 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9394 | * |
| 9395 | */ |
| 9396 | @Override |
| 9397 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9398 | enforceModifyPermission(); |
| 9399 | |
| 9400 | Phone phone = getPhone(subId); |
| 9401 | if (phone == null) { |
| 9402 | return 0; |
| 9403 | } |
| 9404 | // Now that all security checks passes, perform the operation as ourselves. |
| 9405 | final long identity = Binder.clearCallingIdentity(); |
| 9406 | try { |
| 9407 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9408 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9409 | return attemptsRemaining; |
| 9410 | |
| 9411 | } catch (Exception e) { |
| 9412 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9413 | } finally { |
| 9414 | Binder.restoreCallingIdentity(identity); |
| 9415 | } |
| 9416 | return 0; |
| 9417 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9418 | |
| 9419 | /** |
| 9420 | * Request for receiving user activity notification |
| 9421 | */ |
| 9422 | @Override |
| 9423 | public void requestUserActivityNotification() { |
| 9424 | if (!mNotifyUserActivity.get() |
| 9425 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9426 | mNotifyUserActivity.set(true); |
| 9427 | } |
| 9428 | } |
| 9429 | |
| 9430 | /** |
| 9431 | * Called when userActivity is signalled in the power manager. |
| 9432 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9433 | */ |
| 9434 | @Override |
| 9435 | public void userActivity() { |
| 9436 | // *************************************** |
| 9437 | // * Inherited from PhoneWindowManager * |
| 9438 | // *************************************** |
| 9439 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9440 | // WITH ITS LOCKS HELD. |
| 9441 | // |
| 9442 | // This code must be VERY careful about the locks |
| 9443 | // it acquires. |
| 9444 | // In fact, the current code acquires way too many, |
| 9445 | // and probably has lurking deadlocks. |
| 9446 | |
| 9447 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9448 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9449 | } |
| 9450 | |
| 9451 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9452 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9453 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9454 | } |
| 9455 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9456 | |
| 9457 | @Override |
| 9458 | public boolean canConnectTo5GInDsdsMode() { |
| 9459 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9460 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9461 | |
| 9462 | @Override |
| 9463 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9464 | String callingFeatureId) { |
| 9465 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9466 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9467 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9468 | } |
| 9469 | |
| 9470 | Phone phone = getPhone(subId); |
| 9471 | if (phone == null) { |
| 9472 | throw new RuntimeException("phone is not available"); |
| 9473 | } |
| 9474 | // Now that all security checks passes, perform the operation as ourselves. |
| 9475 | final long identity = Binder.clearCallingIdentity(); |
| 9476 | try { |
| 9477 | return phone.getEquivalentHomePlmns(); |
| 9478 | } finally { |
| 9479 | Binder.restoreCallingIdentity(identity); |
| 9480 | } |
| 9481 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9482 | |
| 9483 | @Override |
| 9484 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 9485 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 9486 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9487 | mPhoneConfigurationManager.getRadioInterfaceCapabilities(); |
| 9488 | if (radioInterfaceCapabilities == null) { |
| 9489 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9490 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 9491 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9492 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9493 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9494 | @Override |
| 9495 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 9496 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9497 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 9498 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9499 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 9500 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9501 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9502 | if (DBG) { |
| 9503 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 9504 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 9505 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 9506 | } |
| 9507 | |
| 9508 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 9509 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 9510 | || appType > TelephonyManager.APPTYPE_ISIM |
| 9511 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 9512 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 9513 | if (callback != null) { |
| 9514 | try { |
| 9515 | callback.onAuthenticationFailure( |
| 9516 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 9517 | } catch (RemoteException exception) { |
| 9518 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 9519 | } |
| 9520 | return; |
| 9521 | } |
| 9522 | } |
| 9523 | |
| 9524 | final long token = Binder.clearCallingIdentity(); |
| 9525 | try { |
| 9526 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 9527 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 9528 | forceBootStrapping, callback)); |
| 9529 | } finally { |
| 9530 | Binder.restoreCallingIdentity(token); |
| 9531 | } |
| 9532 | } |
| 9533 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9534 | /** |
| 9535 | * Attempts to set the radio power state for thermal reason. This does not guarantee that the |
| 9536 | * requested radio power state will actually be set. See {@link |
| 9537 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9538 | * |
| 9539 | * @param subId the subscription ID of the phone requesting to set the radio power state. |
| 9540 | * @param enable {@code true} if trying to turn radio on. |
| 9541 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9542 | * false}. |
| 9543 | */ |
| 9544 | private boolean setRadioPowerForThermal(int subId, boolean enable) { |
| 9545 | Phone phone = getPhone(subId); |
| 9546 | if (phone != null) { |
| 9547 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 9548 | return true; |
| 9549 | } |
| 9550 | return false; |
| 9551 | } |
| 9552 | |
| 9553 | private int handleDataThrottlingRequest(int subId, |
| 9554 | DataThrottlingRequest dataThrottlingRequest) { |
| 9555 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 9556 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9557 | if (!setRadioPowerForThermal(subId, true)) { |
| 9558 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9559 | } |
| 9560 | |
| 9561 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 9562 | |
| 9563 | int thermalMitigationResult = |
| 9564 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
| 9565 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 9566 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 9567 | } |
| 9568 | return thermalMitigationResult; |
| 9569 | } |
| 9570 | |
| 9571 | /** |
| 9572 | * Thermal mitigation request to control functionalities at modem. |
| 9573 | * |
| 9574 | * @param subId the id of the subscription. |
| 9575 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
| 9576 | * |
| 9577 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 9578 | */ |
| 9579 | @Override |
| 9580 | @ThermalMitigationResult |
| 9581 | public int sendThermalMitigationRequest( |
| 9582 | int subId, |
| 9583 | ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException { |
| 9584 | enforceModifyPermission(); |
| 9585 | |
| 9586 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9587 | final long identity = Binder.clearCallingIdentity(); |
| 9588 | |
| 9589 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 9590 | try { |
| 9591 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 9592 | switch (thermalMitigationAction) { |
| 9593 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 9594 | thermalMitigationResult = |
| 9595 | handleDataThrottlingRequest(subId, |
| 9596 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 9597 | break; |
| 9598 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 9599 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9600 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 9601 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 9602 | } |
| 9603 | |
| 9604 | // Ensure that radio is on. If not able to power on due to phone being |
| 9605 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9606 | if (!setRadioPowerForThermal(subId, true)) { |
| 9607 | thermalMitigationResult = |
| 9608 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9609 | break; |
| 9610 | } |
| 9611 | |
| 9612 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 9613 | false); |
| 9614 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9615 | break; |
| 9616 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 9617 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9618 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 9619 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 9620 | } |
| 9621 | |
| 9622 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 9623 | if (registry != null) { |
| 9624 | TelephonyConnectionService service = |
| 9625 | registry.getTelephonyConnectionService(); |
| 9626 | Phone phone = getPhone(subId); |
| 9627 | if (phone == null) { |
| 9628 | thermalMitigationResult = |
| 9629 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9630 | break; |
| 9631 | } |
| 9632 | |
| 9633 | if (PhoneConstantConversions.convertCallState(phone.getState()) |
| 9634 | != TelephonyManager.CALL_STATE_IDLE |
| 9635 | || phone.isInEmergencySmsMode() || phone.isInEcm() |
| 9636 | || (service != null && service.isEmergencyCallPending())) { |
| 9637 | String errorMessage = "Phone state is not valid. call state = " |
| 9638 | + PhoneConstantConversions.convertCallState(phone.getState()) |
| 9639 | + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode() |
| 9640 | + " isInEmergencyCallbackMode = " + phone.isInEcm(); |
| 9641 | errorMessage += service == null |
| 9642 | ? " TelephonyConnectionService is null" |
| 9643 | : " isEmergencyCallPending = " |
| 9644 | + service.isEmergencyCallPending(); |
| 9645 | Log.e(LOG_TAG, errorMessage); |
| 9646 | thermalMitigationResult = |
| 9647 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 9648 | break; |
| 9649 | } |
| 9650 | } else { |
| 9651 | thermalMitigationResult = |
| 9652 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9653 | break; |
| 9654 | } |
| 9655 | |
| 9656 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 9657 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9658 | if (!setRadioPowerForThermal(subId, false)) { |
| 9659 | thermalMitigationResult = |
| 9660 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9661 | break; |
| 9662 | } |
| 9663 | thermalMitigationResult = |
| 9664 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9665 | break; |
| 9666 | default: |
| 9667 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 9668 | + "not exist. Requested action: " + thermalMitigationAction); |
| 9669 | } |
| 9670 | } catch (IllegalArgumentException e) { |
| 9671 | throw e; |
| 9672 | } catch (Exception e) { |
| 9673 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 9674 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 9675 | } finally { |
| 9676 | Binder.restoreCallingIdentity(identity); |
| 9677 | } |
| 9678 | |
| 9679 | if (DBG) { |
| 9680 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 9681 | + thermalMitigationResult); |
| 9682 | } |
| 9683 | |
| 9684 | return thermalMitigationResult; |
| 9685 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9686 | |
| 9687 | /** |
| 9688 | * Set the GbaService Package Name that Telephony will bind to. |
| 9689 | * |
| 9690 | * @param subId The sim that the GbaService is associated with. |
| 9691 | * @param packageName The name of the package to be replaced with. |
| 9692 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9693 | */ |
| 9694 | @Override |
| 9695 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 9696 | enforceModifyPermission(); |
| 9697 | |
| 9698 | final long identity = Binder.clearCallingIdentity(); |
| 9699 | try { |
| 9700 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 9701 | } finally { |
| 9702 | Binder.restoreCallingIdentity(identity); |
| 9703 | } |
| 9704 | } |
| 9705 | |
| 9706 | /** |
| 9707 | * Return the package name of the currently bound GbaService. |
| 9708 | * |
| 9709 | * @param subId The sim that the GbaService is associated with. |
| 9710 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 9711 | */ |
| 9712 | @Override |
| 9713 | public String getBoundGbaService(int subId) { |
| 9714 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 9715 | |
| 9716 | final long identity = Binder.clearCallingIdentity(); |
| 9717 | try { |
| 9718 | return getGbaManager(subId).getServicePackage(); |
| 9719 | } finally { |
| 9720 | Binder.restoreCallingIdentity(identity); |
| 9721 | } |
| 9722 | } |
| 9723 | |
| 9724 | /** |
| 9725 | * Set the release time for telephony to unbind GbaService. |
| 9726 | * |
| 9727 | * @param subId The sim that the GbaService is associated with. |
| 9728 | * @param interval The release time to unbind GbaService by millisecond. |
| 9729 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9730 | */ |
| 9731 | @Override |
| 9732 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 9733 | enforceModifyPermission(); |
| 9734 | |
| 9735 | final long identity = Binder.clearCallingIdentity(); |
| 9736 | try { |
| 9737 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 9738 | } finally { |
| 9739 | Binder.restoreCallingIdentity(identity); |
| 9740 | } |
| 9741 | } |
| 9742 | |
| 9743 | /** |
| 9744 | * Return the release time for telephony to unbind GbaService. |
| 9745 | * |
| 9746 | * @param subId The sim that the GbaService is associated with. |
| 9747 | * @return The release time to unbind GbaService by millisecond. |
| 9748 | */ |
| 9749 | @Override |
| 9750 | public int getGbaReleaseTime(int subId) { |
| 9751 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 9752 | |
| 9753 | final long identity = Binder.clearCallingIdentity(); |
| 9754 | try { |
| 9755 | return getGbaManager(subId).getReleaseTime(); |
| 9756 | } finally { |
| 9757 | Binder.restoreCallingIdentity(identity); |
| 9758 | } |
| 9759 | } |
| 9760 | |
| 9761 | private GbaManager getGbaManager(int subId) { |
| 9762 | GbaManager instance = GbaManager.getInstance(subId); |
| 9763 | if (instance == null) { |
| 9764 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 9765 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 9766 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 9767 | } |
| 9768 | return instance; |
| 9769 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9770 | |
| 9771 | /** |
| 9772 | * indicate whether the device and the carrier can support |
| 9773 | * RCS VoLTE single registration. |
| 9774 | */ |
| 9775 | @Override |
| 9776 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9777 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9778 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 9779 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9780 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9781 | |
| 9782 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9783 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9784 | } |
| 9785 | |
| 9786 | final long identity = Binder.clearCallingIdentity(); |
| 9787 | try { |
| 9788 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 9789 | if (rpm != null) { |
| 9790 | return rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 9791 | } |
| 9792 | return false; |
| 9793 | } finally { |
| 9794 | Binder.restoreCallingIdentity(identity); |
| 9795 | } |
| 9796 | } |
| 9797 | |
| 9798 | /** |
| 9799 | * Register RCS provisioning callback. |
| 9800 | */ |
| 9801 | @Override |
| 9802 | public void registerRcsProvisioningChangedCallback(int subId, |
| 9803 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9804 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9805 | Binder.getCallingUid(), "registerRcsProvisioningChangedCallback", |
| 9806 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9807 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9808 | |
| 9809 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9810 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9811 | } |
| 9812 | if (!isImsAvailableOnDevice()) { |
| 9813 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9814 | "IMS not available on device."); |
| 9815 | } |
| 9816 | |
| 9817 | final long identity = Binder.clearCallingIdentity(); |
| 9818 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9819 | if (!RcsProvisioningMonitor.getInstance() |
| 9820 | .registerRcsProvisioningChangedCallback(subId, callback)) { |
| 9821 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9822 | "Service not available for the subscription."); |
| 9823 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9824 | } finally { |
| 9825 | Binder.restoreCallingIdentity(identity); |
| 9826 | } |
| 9827 | } |
| 9828 | |
| 9829 | /** |
| 9830 | * Unregister RCS provisioning callback. |
| 9831 | */ |
| 9832 | @Override |
| 9833 | public void unregisterRcsProvisioningChangedCallback(int subId, |
| 9834 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9835 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9836 | Binder.getCallingUid(), "unregisterRcsProvisioningChangedCallback", |
| 9837 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9838 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9839 | |
| 9840 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9841 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9842 | } |
| 9843 | if (!isImsAvailableOnDevice()) { |
| 9844 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9845 | "IMS not available on device."); |
| 9846 | } |
| 9847 | |
| 9848 | final long identity = Binder.clearCallingIdentity(); |
| 9849 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9850 | RcsProvisioningMonitor.getInstance() |
| 9851 | .unregisterRcsProvisioningChangedCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9852 | } finally { |
| 9853 | Binder.restoreCallingIdentity(identity); |
| 9854 | } |
| 9855 | } |
| 9856 | |
| 9857 | /** |
| 9858 | * trigger RCS reconfiguration. |
| 9859 | */ |
| 9860 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9861 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 9862 | "triggerRcsReconfiguration", |
| 9863 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9864 | |
| 9865 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9866 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9867 | } |
| 9868 | if (!isImsAvailableOnDevice()) { |
| 9869 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9870 | "IMS not available on device."); |
| 9871 | } |
| 9872 | |
| 9873 | final long identity = Binder.clearCallingIdentity(); |
| 9874 | try { |
| 9875 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 9876 | } finally { |
| 9877 | Binder.restoreCallingIdentity(identity); |
| 9878 | } |
| 9879 | } |
| 9880 | |
| 9881 | /** |
| 9882 | * Provide the client configuration parameters of the RCS application. |
| 9883 | */ |
| 9884 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9885 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 9886 | "setRcsClientConfiguration", |
| 9887 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9888 | |
| 9889 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9890 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9891 | } |
| 9892 | if (!isImsAvailableOnDevice()) { |
| 9893 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9894 | "IMS not available on device."); |
| 9895 | } |
| 9896 | |
| 9897 | final long identity = Binder.clearCallingIdentity(); |
| 9898 | |
| 9899 | try { |
| 9900 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 9901 | if (configBinder == null) { |
| 9902 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
| 9903 | } else { |
| 9904 | configBinder.setRcsClientConfiguration(rcc); |
| 9905 | } |
| 9906 | } catch (RemoteException e) { |
| 9907 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
| 9908 | } finally { |
| 9909 | Binder.restoreCallingIdentity(identity); |
| 9910 | } |
| 9911 | } |
| 9912 | |
| 9913 | /** |
| 9914 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 9915 | */ |
| 9916 | @Override |
| 9917 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 9918 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9919 | "setDeviceSingleRegistrationEnabledOverride"); |
| 9920 | enforceModifyPermission(); |
| 9921 | |
| 9922 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9923 | : Boolean.parseBoolean(enabledStr); |
| 9924 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 9925 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9926 | } |
| 9927 | |
| 9928 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 9929 | * Sends a device to device communication message. Only usable via shell. |
| 9930 | * @param message message to send. |
| 9931 | * @param value message value. |
| 9932 | */ |
| 9933 | @Override |
| 9934 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 9935 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 9936 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 9937 | enforceModifyPermission(); |
| 9938 | |
| 9939 | final long identity = Binder.clearCallingIdentity(); |
| 9940 | try { |
| 9941 | TelephonyConnectionService service = |
| 9942 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 9943 | if (service == null) { |
| 9944 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 9945 | return; |
| 9946 | } |
| 9947 | service.sendTestDeviceToDeviceMessage(message, value); |
| 9948 | } finally { |
| 9949 | Binder.restoreCallingIdentity(identity); |
| 9950 | } |
| 9951 | } |
| 9952 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 9953 | /** |
| 9954 | * Sets the specified device to device transport active. |
| 9955 | * @param transport The transport to set active. |
| 9956 | */ |
| 9957 | @Override |
| 9958 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 9959 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9960 | "setActiveDeviceToDeviceTransport"); |
| 9961 | enforceModifyPermission(); |
| 9962 | |
| 9963 | final long identity = Binder.clearCallingIdentity(); |
| 9964 | try { |
| 9965 | TelephonyConnectionService service = |
| 9966 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 9967 | if (service == null) { |
| 9968 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 9969 | return; |
| 9970 | } |
| 9971 | service.setActiveDeviceToDeviceTransport(transport); |
| 9972 | } finally { |
| 9973 | Binder.restoreCallingIdentity(identity); |
| 9974 | } |
| 9975 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 9976 | |
| 9977 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9978 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 9979 | */ |
| 9980 | @Override |
| 9981 | public boolean getDeviceSingleRegistrationEnabled() { |
| 9982 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 9983 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 9984 | } |
| 9985 | |
| 9986 | /** |
| 9987 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9988 | */ |
| 9989 | @Override |
| 9990 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 9991 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9992 | "setCarrierSingleRegistrationEnabledOverride"); |
| 9993 | enforceModifyPermission(); |
| 9994 | |
| 9995 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9996 | : Boolean.parseBoolean(enabledStr); |
| 9997 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 9998 | subId, enabled); |
| 9999 | } |
| 10000 | |
| 10001 | /** |
| 10002 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10003 | */ |
| 10004 | @Override |
| 10005 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10006 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 10007 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 10008 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10009 | |
| 10010 | /** |
| 10011 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 10012 | * their mobile plan. |
| 10013 | */ |
| 10014 | @Override |
| 10015 | public String getMobileProvisioningUrl() { |
| 10016 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 10017 | final long identity = Binder.clearCallingIdentity(); |
| 10018 | try { |
| 10019 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 10020 | } finally { |
| 10021 | Binder.restoreCallingIdentity(identity); |
| 10022 | } |
| 10023 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10024 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10025 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 10026 | * Get the EAB contact from the EAB database. |
| 10027 | */ |
| 10028 | @Override |
| 10029 | public String getContactFromEab(String contact) { |
| 10030 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 10031 | enforceModifyPermission(); |
| 10032 | final long identity = Binder.clearCallingIdentity(); |
| 10033 | try { |
| 10034 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 10035 | } finally { |
| 10036 | Binder.restoreCallingIdentity(identity); |
| 10037 | } |
| 10038 | } |
| 10039 | |
| 10040 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10041 | * Remove the EAB contacts from the EAB database. |
| 10042 | */ |
| 10043 | @Override |
| 10044 | public int removeContactFromEab(int subId, String contacts) { |
| 10045 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 10046 | enforceModifyPermission(); |
| 10047 | final long identity = Binder.clearCallingIdentity(); |
| 10048 | try { |
| 10049 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 10050 | } finally { |
| 10051 | Binder.restoreCallingIdentity(identity); |
| 10052 | } |
| 10053 | } |
| 10054 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10055 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10056 | public boolean getDeviceUceEnabled() { |
| 10057 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 10058 | final long identity = Binder.clearCallingIdentity(); |
| 10059 | try { |
| 10060 | return mApp.getDeviceUceEnabled(); |
| 10061 | } finally { |
| 10062 | Binder.restoreCallingIdentity(identity); |
| 10063 | } |
| 10064 | } |
| 10065 | |
| 10066 | @Override |
| 10067 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 10068 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 10069 | final long identity = Binder.clearCallingIdentity(); |
| 10070 | try { |
| 10071 | mApp.setDeviceUceEnabled(isEnabled); |
| 10072 | } finally { |
| 10073 | Binder.restoreCallingIdentity(identity); |
| 10074 | } |
| 10075 | } |
| 10076 | |
| 10077 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10078 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10079 | String callingPackage) { |
| 10080 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10081 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 10082 | |
| 10083 | final int callingUid = Binder.getCallingUid(); |
| 10084 | // Verify that tha callingPackage belongs to the calling UID |
| 10085 | mApp.getSystemService(AppOpsManager.class) |
| 10086 | .checkPackage(callingUid, callingPackage); |
| 10087 | |
| 10088 | validateSignalStrengthUpdateRequest(request, callingUid); |
| 10089 | |
| 10090 | final long identity = Binder.clearCallingIdentity(); |
| 10091 | try { |
| 10092 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10093 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10094 | |
| 10095 | if (result instanceof IllegalStateException) { |
| 10096 | throw (IllegalStateException) result; |
| 10097 | } |
| 10098 | } finally { |
| 10099 | Binder.restoreCallingIdentity(identity); |
| 10100 | } |
| 10101 | } |
| 10102 | |
| 10103 | @Override |
| 10104 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10105 | String callingPackage) { |
| 10106 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10107 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 10108 | |
| 10109 | final int callingUid = Binder.getCallingUid(); |
| 10110 | // Verify that tha callingPackage belongs to the calling UID |
| 10111 | mApp.getSystemService(AppOpsManager.class) |
| 10112 | .checkPackage(callingUid, callingPackage); |
| 10113 | |
| 10114 | final long identity = Binder.clearCallingIdentity(); |
| 10115 | try { |
| 10116 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10117 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10118 | |
| 10119 | if (result instanceof IllegalStateException) { |
| 10120 | throw (IllegalStateException) result; |
| 10121 | } |
| 10122 | } finally { |
| 10123 | Binder.restoreCallingIdentity(identity); |
| 10124 | } |
| 10125 | } |
| 10126 | |
| 10127 | private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request, |
| 10128 | int callingUid) { |
| 10129 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 10130 | // phone/system process do not have further restriction on request |
| 10131 | return; |
| 10132 | } |
| 10133 | |
| 10134 | // Applications has restrictions on how to use the request: |
| 10135 | // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle |
| 10136 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
| 10137 | // This is not system caller which has been checked above |
| 10138 | throw new IllegalArgumentException( |
| 10139 | "Only system can set isSystemThresholdReportingRequestedWhileIdle"); |
| 10140 | } |
| 10141 | |
| 10142 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 10143 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 10144 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 10145 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 10146 | || info.isEnabled()) { |
| 10147 | throw new IllegalArgumentException( |
| 10148 | "Only system can set hide fields in SignalThresholdInfo"); |
| 10149 | } |
| 10150 | |
| 10151 | // Thresholds length for each RAN need in range. This has been validated in |
| 10152 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 10153 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 10154 | final int[] thresholds = info.getThresholds(); |
| 10155 | Objects.requireNonNull(thresholds); |
| 10156 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 10157 | || thresholds.length |
| 10158 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 10159 | throw new IllegalArgumentException( |
| 10160 | "thresholds length is out of range: " + thresholds.length); |
| 10161 | } |
| 10162 | } |
| 10163 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10164 | |
| 10165 | /** |
| 10166 | * Gets the current phone capability. |
| 10167 | * |
| 10168 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 10169 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 10170 | * It's used to evaluate possible phone config change, for example from single |
| 10171 | * SIM device to multi-SIM device. |
| 10172 | */ |
| 10173 | @Override |
| 10174 | public PhoneCapability getPhoneCapability() { |
| 10175 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 10176 | final long identity = Binder.clearCallingIdentity(); |
| 10177 | try { |
| 10178 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 10179 | } finally { |
| 10180 | Binder.restoreCallingIdentity(identity); |
| 10181 | } |
| 10182 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 10183 | |
| 10184 | /** |
| 10185 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 10186 | * required to be done shortly after the API is invoked. |
| 10187 | */ |
| 10188 | @Override |
| 10189 | @TelephonyManager.PrepareUnattendedRebootResult |
| 10190 | public int prepareForUnattendedReboot() { |
| 10191 | enforceRebootPermission(); |
| 10192 | |
| 10193 | final long identity = Binder.clearCallingIdentity(); |
| 10194 | try { |
| 10195 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null); |
| 10196 | } finally { |
| 10197 | Binder.restoreCallingIdentity(identity); |
| 10198 | } |
| 10199 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 10200 | } |